File: display-contents-blockify-dynamic.html

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (72 lines) | stat: -rw-r--r-- 3,477 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!doctype html>
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1561283">
<link rel="help" href="https://drafts.csswg.org/css-display/#valdef-display-contents">
<link rel="help" href="https://drafts.csswg.org/css-grid/#grid-item-display">
<link rel="author" href="https://mozilla.org" title="Mozilla">
<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
<link rel="author" href="mailto:obrufau@igalia.com" title="Oriol Brufau">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
  .grid { display: grid }
</style>
<div style="display: grid">
  <span id="grid-child">
    <span></span>
  </div>
</div>
<div id="grid-to-block" style="display: grid">
  <div style="display: contents">
    <div style="display: contents">
      <button>button1</button>
      <button id="deblockified">button2</button>
    </div>
  </div>
</div>
<div id="block-to-grid" style="display: block">
  <div style="display: contents">
    <div style="display: contents">
      <button>button1</button>
      <button id="blockified">button2</button>
    </div>
  </div>
</div>
<script>
function display(el) {
  return getComputedStyle(el).display;
}
test(function() {
  let child = document.getElementById("grid-child");
  let grandChild = child.firstElementChild;
  assert_equals(display(child), "block", "Grid child should get blockified");
  assert_equals(display(grandChild), "inline", "Grid grand-child should not get initially blockified");
  child.style.display = "contents";
  assert_equals(display(child), "contents", "No reason for it not to become display: contents");
  assert_equals(display(grandChild), "block", "Grid grand-child with display: contents parent should get blockified");
  child.style.display = "";
  assert_equals(display(child), "block", "Grid child should get blockified");
  assert_equals(display(grandChild), "inline", "Grid grand-child should get un-blockified when its parent's display stops being `contents`");
}, "Dynamic changes to `display` causing blockification of children are handled correctly");

test(() => {
  let gridToBlock = document.getElementById("grid-to-block");
  let itemGrandChild = document.getElementById("deblockified");

  assert_equals(display(gridToBlock), "grid", "Container should be a grid");
  assert_equals(display(itemGrandChild), "block", "Item should have been blockified");
  gridToBlock.style.display = "block";
  assert_equals(display(gridToBlock), "block", "Container should become a block");
  assert_equals(display(itemGrandChild), "inline-block", "Item should get de-blockified");
}, "Dynamic changes to `display` from `grid` to `block` should cause children to get de-blockified despite being children of `display: contents` elements");

test(() => {
  let blockToGrid = document.getElementById("block-to-grid");
  let itemGrandChild = document.getElementById("blockified");

  assert_equals(display(blockToGrid), "block", "Container should be a block");
  assert_equals(display(itemGrandChild), "inline-block", "Item should not have been blockified");
  blockToGrid.style.display = "grid";
  assert_equals(display(blockToGrid), "grid", "Container should become a grid");
  assert_equals(display(itemGrandChild), "block", "Item should get blockified");
}, "Dynamic changes to `display` from `block` to `grid` should cause children to get blockified despite being children of `display: contents` elements")
</script>