summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-cascade/all-prop-revert-layer-noop.html
blob: 5c31c5803cc8be7e91bb0465480d9d340db8c0c1 (plain)
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
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Cascade: "all: revert-layer"</title>
<link rel="author" title="Oriol Brufau" href="mailto:obrufau@igalia.com">
<link rel="help" href="https://www.w3.org/TR/css-cascade-5/#revert-layer">
<meta name="assert" content="Checks that adding 'all: revert-layer' inside @layer has no effect on elements with no other author rules.">
<!-- Split into chunks to avoid timeouts. -->
<meta name="variant" content="?include=0">
<meta name="variant" content="?include=1">
<meta name="variant" content="?include=2">
<meta name="variant" content="?include=3">
<meta name="variant" content="?include=4">
<meta name="variant" content="?include=5">
<meta name="variant" content="?include=6">
<meta name="variant" content="?include=7">
<script>
  const CHUNKS = 8;
</script>

<style>
@layer {
  .revert-all {
    all: revert-layer;
  }
}
</style>

<div id="log"></div>
<div id="wrapper"></div>

<script src="/common/subset-tests-by-key.js"></script>
<script src="/html/resources/common.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function cloneStyle(style) {
  const clone = Object.create(null);
  for (let property of style) {
    clone[property] = style.getPropertyValue(property);
  }
  return clone;
}

function assertSameClones(clone1, clone2, callback) {
  for (let property in clone1) {
    const value1 = clone1[property];
    const value2 = clone2[property];
    // assert_equals is slow, so only call it if it's going to fail.
    if (value1 !== value2) {
      assert_equals(value1, value2, property);
    }
  }
}

const wrapper = document.getElementById("wrapper");
const elementNames = [...HTML5_ELEMENTS, "math", "svg", "z-custom"].sort();
for (let i = 0; i < elementNames.length; ++i) {
  let elementName = elementNames[i];
  let chunk = i % CHUNKS;
  subsetTestByKey(chunk.toString(), test, function() {
    const element = document.createElement(elementName);
    wrapper.appendChild(element);
    const style = getComputedStyle(element);
    const clonedBaseStyle = cloneStyle(style);
    element.classList.add("revert-all");
    const clonedRevertedStyle = cloneStyle(style);
    assertSameClones(clonedRevertedStyle, clonedBaseStyle);
  }, elementName);
}
</script>