test_unprefixing_service.html 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=1107378
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 1107378</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=1107378">Mozilla Bug 1107378</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 unprefixing is enabled for whitelisted domains, and
  24. * that it's disabled for non-whitelisted domains.
  25. *
  26. * We do this using an iframe, in which we load a test file at a test domain,
  27. * and we have the iframe report back to us (using postMessage) about
  28. * whether unprefixing is working.
  29. *
  30. * High-level overview of the process here:
  31. * - First, we tweak prefs to enable unprefixing & enable the test-only
  32. * entries in our unprefixing whitelist.
  33. * - The rest of this test is driven by the "startNextTest()" method.
  34. * This method pops a hostname to test and loads a URL from that host
  35. * in the iframe.
  36. * - We then listen for test-results from the iframe, using the postMessage
  37. * handler in unprefixing_service_utils.js.
  38. * - When the iframe indicates that it's done, we call "startNextTest()"
  39. * again to pop the next host & load *that* in the iframe.
  40. * - When nothing remains to be popped, we're done.
  41. */
  42. const IFRAME_TESTFILE = "unprefixing_service_iframe.html";
  43. // This function gets invoked when our iframe finishes a given round of testing.
  44. function startNextTest()
  45. {
  46. // Test the next whitelisted host, if any remain.
  47. if (gWhitelistedHosts.length > 0) {
  48. let host = gWhitelistedHosts.pop();
  49. info("Verifying that CSS Unprefixing Service is active, " +
  50. "at whitelisted test-host '" + host + "'");
  51. testHost(host, true);
  52. return;
  53. }
  54. // Test the next not-whitelisted host, if any remain.
  55. if (gNotWhitelistedHosts.length > 0) {
  56. let host = gNotWhitelistedHosts.pop();
  57. info("Verifying that CSS Unprefixing Service is inactive, " +
  58. "at non-whitelisted test-host '" + host + "'");
  59. testHost(host, false);
  60. return;
  61. }
  62. // Both arrays empty --> we're done.
  63. SimpleTest.finish();
  64. }
  65. function begin()
  66. {
  67. // Before we start loading things in iframes, set up postMessage handler.
  68. registerPostMessageListener(startNextTest);
  69. // Turn on prefs & start the first test!
  70. SpecialPowers.pushPrefEnv(
  71. { set: [[PREF_UNPREFIXING_SERVICE, true],
  72. [PREF_INCLUDE_TEST_DOMAINS, true],
  73. // Make sure *native* -webkit prefix support is turned off. It's
  74. // not whitelist-restricted, so if we left it enabled, it'd prevent
  75. // us from being able to detect CSSUnprefixingService's domain
  76. // whitelisting in this test.
  77. ["layout.css.prefixes.webkit", false]]},
  78. startNextTest);
  79. }
  80. begin();
  81. </script>
  82. </pre>
  83. </body>
  84. </html>