tor-browser

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

test_computed_style_prefs.html (2773B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test that preffed off properties do not appear in computed style</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      7 </head>
      8 <body>
      9 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=919594">Mozilla Bug 919594</a>
     10 <p id="display"></p>
     11 <div id="content" style="display: none">
     12  
     13 </div>
     14 <pre id="test">
     15 <script type="application/javascript">
     16 
     17 /** Test that preffed off properties do not appear in computed style */
     18 
     19 function testWithAllPrefsDisabled() {
     20  let exposedProperties = Object.keys(gCS).map(i => gCS[i]);
     21 
     22  // Store the number of properties for later tests to use.
     23  gLengthWithAllPrefsDisabled = gCS.length;
     24 
     25  // Check that all of the properties behind the prefs are not exposed.
     26  for (let pref in gProps) {
     27    for (let prop of gProps[pref]) {
     28      ok(!exposedProperties.includes(prop), prop + " not exposed when prefs are false");
     29    }
     30  }
     31 }
     32 
     33 function testWithOnePrefEnabled(aPref) {
     34  let exposedProperties = Object.keys(gCS).map(i => gCS[i]);
     35 
     36  // Check that the number of properties on the object is as expected.
     37  is(gCS.length, gLengthWithAllPrefsDisabled + gProps[aPref].length, "length when " + aPref + " is true");
     38 
     39  // Check that the properties corresponding to aPref are exposed.
     40  for (let prop of gProps[aPref]) {
     41    ok(exposedProperties.includes(prop), prop + " exposed when " + aPref + " is true");
     42  }
     43 }
     44 
     45 function step() {
     46  if (gTestIndex == gTests.length) {
     47    // Reached the end of the tests.
     48    SimpleTest.finish();
     49    return;
     50  }
     51 
     52  if (gPrefsPushed) {
     53    // We've just finished running one tests.  Pop the prefs and go on to
     54    // the next test.
     55    gTestIndex++;
     56    gPrefsPushed = false;
     57    SpecialPowers.popPrefEnv(step);
     58    return;
     59  }
     60 
     61  // About to run one test.  Push the prefs and run it.
     62  let fn = gTests[gTestIndex].fn;
     63  gPrefsPushed = true;
     64  SpecialPowers.pushPrefEnv(gTests[gTestIndex].settings,
     65                            function() { fn(); SimpleTest.executeSoon(step); });
     66 }
     67 
     68 // ----
     69 
     70 var gProps = {
     71  "layout.css.backdrop-filter.enabled": ["backdrop-filter"],
     72 };
     73 
     74 var gCS = getComputedStyle(document.body, "");
     75 var gLengthWithAllPrefsDisabled;
     76 
     77 var gTestIndex = 0;
     78 var gPrefsPushed = false;
     79 var gTests = [
     80  // First, test when all of the prefs are disabled.
     81  { settings: { set: Object.keys(gProps).map(x => [x, false]) },
     82    fn:       testWithAllPrefsDisabled },
     83  // Then, test each pref enabled individually.
     84  ...Object.keys(gProps).map(p =>
     85    ({ settings: { set: Object.keys(gProps).map(x => [x, x == p]) },
     86       fn:       testWithOnePrefEnabled.bind(null, p) }))
     87 ];
     88 
     89 SimpleTest.waitForExplicitFinish();
     90 step();
     91 </script>
     92 </pre>
     93 </body>
     94 </html>