Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / layout / style / test / test_computed_style_prefs.html
blob0f297477d6672fdca2b0f26bb573090a1dc1f14d
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">
13 </div>
14 <pre id="test">
15 <script type="application/javascript">
17 /** Test that preffed off properties do not appear in computed style **/
19 function testWithAllPrefsDisabled() {
20 let exposedProperties = Object.keys(gCS).map(i => gCS[i]);
22 // Store the number of properties for later tests to use.
23 gLengthWithAllPrefsDisabled = gCS.length;
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");
33 function testWithOnePrefEnabled(aPref) {
34 let exposedProperties = Object.keys(gCS).map(i => gCS[i]);
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");
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");
45 function step() {
46 if (gTestIndex == gTests.length) {
47 // Reached the end of the tests.
48 SimpleTest.finish();
49 return;
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;
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); });
68 // ----
70 var gProps = {
71 "layout.css.backdrop-filter.enabled": ["backdrop-filter"],
74 var gCS = getComputedStyle(document.body, "");
75 var gLengthWithAllPrefsDisabled;
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) }))
89 SimpleTest.waitForExplicitFinish();
90 step();
91 </script>
92 </pre>
93 </body>
94 </html>