summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_unprefixing_service_prefs.html
blob: 329dce2a63464759c79600a1ee66a47f8bd7e46d (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1132743
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1132743</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript;version=1.7" src="unprefixing_service_utils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1132743">Mozilla Bug 1132743</a>
<div id="display">
  <iframe id="testIframe"></iframe>
</div>
<pre id="test">
<script type="application/javascript;version=1.7">
"use strict";
SimpleTest.waitForExplicitFinish();

/**
 * This test checks that our CSS unprefixing prefs are effective.
 *
 * We do this using an iframe, in which we load a test file at a test domain
 * (whose whitelist-status depends on a pref), and we have the iframe report
 * back to us (using postMessage) about whether unprefixing is working.
 *
 * High-level overview of the process here (starting with begin()):
 *  - First, we ensure that the pref...
 *      "layout.css.unprefixing-service.include-test-domains"
 *    ...is *unset* by default. (No point exposing it in about:config).
 *  - Then, we test that (as a result of this pref being unset) the
 *    unprefixing service is *inactive* at our test-domain, by default.
 *  - Then, via a series of calls to "startNextTest()"/"testHost()", we re-test
 *    the same test-domain with a variety of pref configurations, to ensure
 *     that unprefixing only happens there when we've preffed on the service
 *     *and* we've enabled the testing entries in the whiteslist.
 */

const IFRAME_TESTFILE = "unprefixing_service_iframe.html";

// Just test the first host in our known-whitelisted-hosts list.
const WHITELISTED_TEST_HOST = gWhitelistedHosts[0];

// Configurations of our prefs to test.
// Each is a 3-entry array, whose entries mean:
// (1) should we enable the CSS Unprefixing Service pref?
// (2) should we enable the "include test domains in whitelist" pref?
// (3) in this pref-configuration, should we expect to see unprefixing active
//     on our whitelisted test-domain?
//
// As you can see, the only configuration which should produce unprefixing
// activity is when *both* prefs are enabled.
let gTestConfigs = [
 [false, false, false],
 [false, true,  false],
 [true,  false, false],
 [true,  true,  true],
];

// Test that a particular configuration of prefs will activate or inactivate
// the CSS unprefixing service, for styles loaded from WHITELISTED_TEST_HOST.
// aTestConfig is described above, in documentation for gTestConfigs.
function testConfig(aTestConfig)
{
  if (aTestConfig.length != 3) {
    ok(false, "bug in test; need 3 entries. see gTestConfigs documentation");
  }

  info("Verifying that CSS Unprefixing Service is " +
       (aTestConfig[2] ? "active" : "inactive") +
       " at test host, with prefs: " +
       PREF_UNPREFIXING_SERVICE + "=" + aTestConfig[0] + ", " +
       PREF_INCLUDE_TEST_DOMAINS + "=" + aTestConfig[1]);

  SpecialPowers.pushPrefEnv(
    { set:
        [[PREF_UNPREFIXING_SERVICE,  aTestConfig[0]],
         [PREF_INCLUDE_TEST_DOMAINS, aTestConfig[1]]]
    },
    function() {
      testHost(WHITELISTED_TEST_HOST, aTestConfig[2]);
    });
}

// This function gets invoked when our iframe finishes a given round of testing.
function startNextTest()
{
  if (gTestConfigs.length > 0) {
    // Grab the next test-config, and kick off a test for it.
    testConfig(gTestConfigs.pop());
    return;
  }

  // Array empty --> we're done.
  SimpleTest.finish();
}

function begin()
{
  // First, check that PREF_INCLUDE_TEST_DOMAINS is unset:
  try {
    let val = SpecialPowers.getBoolPref(PREF_INCLUDE_TEST_DOMAINS);
    ok(false, "The test pref '" + PREF_INCLUDE_TEST_DOMAINS +
               "' should be unspecified by default");
  } catch(e) { /* Good, we threw; pref is unset. */ }

  // Before we start loading things in iframes, set up postMessage handler.
  registerPostMessageListener(startNextTest);

  // To kick things off, we don't set any prefs; we just test the default state
  // (which should have the "include test domains" pref implicitly disabled, &
  // hence unprefixing should end up being disabled in our iframe). Subsequent
  // tests are kicked off via postMessage-triggered calls to startNextTest(),
  // which will tweak prefs and re-test.
  info("Verifying that CSS Unprefixing Service is inactive at test host, " +
       "with default pref configuration");
  testHost(WHITELISTED_TEST_HOST, false);
}

// Before we start, make sure *native* -webkit prefix support is turned off.
// It's not whitelist-restricted (and behaves slightly differently), so if we
// left it enabled, it'd prevent us from being able to detect
// CSSUnprefixingService's domain whitelisting in this test.
SpecialPowers.pushPrefEnv({ set: [["layout.css.prefixes.webkit", false]]},
                          begin);
</script>
</pre>
</body>
</html>