test_unprefixing_service_prefs.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=1132743
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 1132743</title>
  9. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <script type="application/javascript;version=1.7" src="unprefixing_service_utils.js"></script>
  11. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  12. </head>
  13. <body>
  14. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1132743">Mozilla Bug 1132743</a>
  15. <div id="display">
  16. <iframe id="testIframe"></iframe>
  17. </div>
  18. <pre id="test">
  19. <script type="application/javascript;version=1.7">
  20. "use strict";
  21. SimpleTest.waitForExplicitFinish();
  22. /**
  23. * This test checks that our CSS unprefixing prefs are effective.
  24. *
  25. * We do this using an iframe, in which we load a test file at a test domain
  26. * (whose whitelist-status depends on a pref), and we have the iframe report
  27. * back to us (using postMessage) about whether unprefixing is working.
  28. *
  29. * High-level overview of the process here (starting with begin()):
  30. * - First, we ensure that the pref...
  31. * "layout.css.unprefixing-service.include-test-domains"
  32. * ...is *unset* by default. (No point exposing it in about:config).
  33. * - Then, we test that (as a result of this pref being unset) the
  34. * unprefixing service is *inactive* at our test-domain, by default.
  35. * - Then, via a series of calls to "startNextTest()"/"testHost()", we re-test
  36. * the same test-domain with a variety of pref configurations, to ensure
  37. * that unprefixing only happens there when we've preffed on the service
  38. * *and* we've enabled the testing entries in the whiteslist.
  39. */
  40. const IFRAME_TESTFILE = "unprefixing_service_iframe.html";
  41. // Just test the first host in our known-whitelisted-hosts list.
  42. const WHITELISTED_TEST_HOST = gWhitelistedHosts[0];
  43. // Configurations of our prefs to test.
  44. // Each is a 3-entry array, whose entries mean:
  45. // (1) should we enable the CSS Unprefixing Service pref?
  46. // (2) should we enable the "include test domains in whitelist" pref?
  47. // (3) in this pref-configuration, should we expect to see unprefixing active
  48. // on our whitelisted test-domain?
  49. //
  50. // As you can see, the only configuration which should produce unprefixing
  51. // activity is when *both* prefs are enabled.
  52. let gTestConfigs = [
  53. [false, false, false],
  54. [false, true, false],
  55. [true, false, false],
  56. [true, true, true],
  57. ];
  58. // Test that a particular configuration of prefs will activate or inactivate
  59. // the CSS unprefixing service, for styles loaded from WHITELISTED_TEST_HOST.
  60. // aTestConfig is described above, in documentation for gTestConfigs.
  61. function testConfig(aTestConfig)
  62. {
  63. if (aTestConfig.length != 3) {
  64. ok(false, "bug in test; need 3 entries. see gTestConfigs documentation");
  65. }
  66. info("Verifying that CSS Unprefixing Service is " +
  67. (aTestConfig[2] ? "active" : "inactive") +
  68. " at test host, with prefs: " +
  69. PREF_UNPREFIXING_SERVICE + "=" + aTestConfig[0] + ", " +
  70. PREF_INCLUDE_TEST_DOMAINS + "=" + aTestConfig[1]);
  71. SpecialPowers.pushPrefEnv(
  72. { set:
  73. [[PREF_UNPREFIXING_SERVICE, aTestConfig[0]],
  74. [PREF_INCLUDE_TEST_DOMAINS, aTestConfig[1]]]
  75. },
  76. function() {
  77. testHost(WHITELISTED_TEST_HOST, aTestConfig[2]);
  78. });
  79. }
  80. // This function gets invoked when our iframe finishes a given round of testing.
  81. function startNextTest()
  82. {
  83. if (gTestConfigs.length > 0) {
  84. // Grab the next test-config, and kick off a test for it.
  85. testConfig(gTestConfigs.pop());
  86. return;
  87. }
  88. // Array empty --> we're done.
  89. SimpleTest.finish();
  90. }
  91. function begin()
  92. {
  93. // First, check that PREF_INCLUDE_TEST_DOMAINS is unset:
  94. try {
  95. let val = SpecialPowers.getBoolPref(PREF_INCLUDE_TEST_DOMAINS);
  96. ok(false, "The test pref '" + PREF_INCLUDE_TEST_DOMAINS +
  97. "' should be unspecified by default");
  98. } catch(e) { /* Good, we threw; pref is unset. */ }
  99. // Before we start loading things in iframes, set up postMessage handler.
  100. registerPostMessageListener(startNextTest);
  101. // To kick things off, we don't set any prefs; we just test the default state
  102. // (which should have the "include test domains" pref implicitly disabled, &
  103. // hence unprefixing should end up being disabled in our iframe). Subsequent
  104. // tests are kicked off via postMessage-triggered calls to startNextTest(),
  105. // which will tweak prefs and re-test.
  106. info("Verifying that CSS Unprefixing Service is inactive at test host, " +
  107. "with default pref configuration");
  108. testHost(WHITELISTED_TEST_HOST, false);
  109. }
  110. // Before we start, make sure *native* -webkit prefix support is turned off.
  111. // It's not whitelist-restricted (and behaves slightly differently), so if we
  112. // left it enabled, it'd prevent us from being able to detect
  113. // CSSUnprefixingService's domain whitelisting in this test.
  114. SpecialPowers.pushPrefEnv({ set: [["layout.css.prefixes.webkit", false]]},
  115. begin);
  116. </script>
  117. </pre>
  118. </body>
  119. </html>