tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_non_content_accessible_properties.html (2596B)


      1 <!doctype html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <iframe></iframe>
      5 <iframe srcdoc="Foo"></iframe>
      6 <script>
      7 const CHROME_ONLY_PROPERTIES = [
      8  "-moz-window-input-region-margin",
      9  "-moz-window-shadow",
     10  "-moz-window-opacity",
     11  "-moz-window-transform",
     12  "-moz-default-appearance",
     13  "-moz-user-focus",
     14  "-moz-window-dragging",
     15 ];
     16 
     17 const UA_ONLY_PROPERTIES = [
     18  "-x-span",
     19  "-x-lang",
     20  "-x-text-scale",
     21  "-moz-control-character-visibility",
     22  "-moz-top-layer",
     23  "-moz-script-level",
     24  "-moz-math-display",
     25  "-moz-math-variant",
     26  "-moz-inert",
     27  "-moz-min-font-size-ratio",
     28  // TODO: This should ideally be in CHROME_ONLY_PROPERTIES, but due to how
     29  // [Pref] and [ChromeOnly] interact in WebIDL, the former wins.
     30  "-moz-context-properties",
     31 ];
     32 
     33 function testInWin(win) {
     34  const doc = win.document;
     35  const sheet = doc.createElement("style");
     36  const div = doc.createElement("div");
     37  doc.documentElement.appendChild(sheet);
     38  doc.documentElement.appendChild(div);
     39 
     40  sheet.textContent = `div { color: initial }`;
     41  assert_equals(sheet.sheet.cssRules[0].style.length, 1, `sanity: ${doc.documentURI}`);
     42 
     43  for (const prop of CHROME_ONLY_PROPERTIES.concat(UA_ONLY_PROPERTIES)) {
     44    sheet.textContent = `div { ${prop}: initial }`;
     45    let block = sheet.sheet.cssRules[0].style;
     46    assert_false(prop in block, `${prop} shouldn't be exposed in CSSStyleProperties`);
     47 
     48    let isUAOnly = UA_ONLY_PROPERTIES.includes(prop);
     49    assert_equals(prop in SpecialPowers.wrap(block), !isUAOnly, `${prop} should be exposed to chrome code if needed`);
     50 
     51    assert_equals(
     52      block.length,
     53      0,
     54      `${prop} shouldn't be parsed in ${doc.documentURI}`
     55    );
     56    block.setProperty(prop, "initial");
     57    assert_equals(
     58      block.length,
     59      0,
     60      `${prop} shouldn't be settable via CSSOM in ${doc.documentURI}`
     61    );
     62    assert_equals(
     63      win.getComputedStyle(div).getPropertyValue(prop),
     64      "",
     65      `${prop} shouldn't be accessible via CSSOM in ${doc.documentURI}`
     66    );
     67    assert_false(
     68      win.CSS.supports(prop + ': initial'),
     69      `${prop} shouldn't be exposed in CSS.supports in ${doc.documentURI}`
     70    );
     71    assert_false(
     72      win.CSS.supports(prop, 'initial'),
     73      `${prop} shouldn't be exposed in CSS.supports in ${doc.documentURI} (2-value version)`
     74    );
     75  }
     76 }
     77 
     78 let t = async_test("test non-content-accessible props");
     79 onload = t.step_func_done(function() {
     80  testInWin(window);
     81  for (let f of document.querySelectorAll("iframe")) {
     82    testInWin(f.contentWindow);
     83  }
     84 });
     85 </script>