summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_non_content_accessible_properties.html
blob: 220ddf2d2629a4c5758a275ca6fcf2bf13a5d563 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe></iframe>
<iframe srcdoc="Foo"></iframe>
<script>
const CHROME_ONLY_PROPERTIES = [
  "-moz-window-input-region-margin",
  "-moz-window-shadow",
  "-moz-window-opacity",
  "-moz-window-transform",
  "-moz-window-transform-origin",
  "-moz-default-appearance",
  "-moz-user-focus",
];

const UA_ONLY_PROPERTIES = [
  "-x-span",
  "-x-lang",
  "-x-text-scale",
  "-moz-control-character-visibility",
  "-moz-top-layer",
  "-moz-script-level",
  "-moz-math-display",
  "-moz-math-variant",
  "-moz-inert",
  "-moz-min-font-size-ratio",
  // TODO: This should ideally be in CHROME_ONLY_PROPERTIES, but due to how
  // [Pref] and [ChromeOnly] interact in WebIDL, the former wins.
  "-moz-context-properties",
];

function testInWin(win) {
  const doc = win.document;
  const sheet = doc.createElement("style");
  const div = doc.createElement("div");
  doc.documentElement.appendChild(sheet);
  doc.documentElement.appendChild(div);

  sheet.textContent = `div { color: initial }`;
  assert_equals(sheet.sheet.cssRules[0].style.length, 1, `sanity: ${doc.documentURI}`);

  for (const prop of CHROME_ONLY_PROPERTIES.concat(UA_ONLY_PROPERTIES)) {
    sheet.textContent = `div { ${prop}: initial }`;
    let block = sheet.sheet.cssRules[0].style;
    assert_false(prop in block, `${prop} shouldn't be exposed in CSS2Properties`);

    let isUAOnly = UA_ONLY_PROPERTIES.includes(prop);
    assert_equals(prop in SpecialPowers.wrap(block), !isUAOnly, `${prop} should be exposed to chrome code if needed`);

    assert_equals(
      block.length,
      0,
      `${prop} shouldn't be parsed in ${doc.documentURI}`
    );
    block.setProperty(prop, "initial");
    assert_equals(
      block.length,
      0,
      `${prop} shouldn't be settable via CSSOM in ${doc.documentURI}`
    );
    assert_equals(
      win.getComputedStyle(div).getPropertyValue(prop),
      "",
      `${prop} shouldn't be accessible via CSSOM in ${doc.documentURI}`
    );
    assert_false(
      win.CSS.supports(prop + ': initial'),
      `${prop} shouldn't be exposed in CSS.supports in ${doc.documentURI}`
    );
    assert_false(
      win.CSS.supports(prop, 'initial'),
      `${prop} shouldn't be exposed in CSS.supports in ${doc.documentURI} (2-value version)`
    );
  }
}

let t = async_test("test non-content-accessible props");
onload = t.step_func_done(function() {
  testInWin(window);
  for (let f of document.querySelectorAll("iframe")) {
    testInWin(f.contentWindow);
  }
});
</script>