summaryrefslogtreecommitdiffstats
path: root/layout/style/test/unprefixing_service_utils.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /layout/style/test/unprefixing_service_utils.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'layout/style/test/unprefixing_service_utils.js')
-rw-r--r--layout/style/test/unprefixing_service_utils.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/layout/style/test/unprefixing_service_utils.js b/layout/style/test/unprefixing_service_utils.js
new file mode 100644
index 000000000..cd17d20d0
--- /dev/null
+++ b/layout/style/test/unprefixing_service_utils.js
@@ -0,0 +1,87 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Shared data & functionality used in tests for CSS Unprefixing Service.
+
+// Whitelisted hosts:
+// (per implementation of nsPrincipal::IsOnCSSUnprefixingWhitelist())
+var gWhitelistedHosts = [
+ // test1.example.org is on the whitelist.
+ "test1.example.org",
+ // test2.example.org is on the "allow all subdomains" whitelist.
+ "test2.example.org",
+ "sub1.test2.example.org",
+ "sub2.test2.example.org"
+];
+
+// *NOT* whitelisted hosts:
+var gNotWhitelistedHosts = [
+ // Though test1.example.org is on the whitelist, its subdomains are not.
+ "sub1.test1.example.org",
+ // mochi.test is not on the whitelist.
+ "mochi.test:8888"
+];
+
+// Names of prefs:
+const PREF_UNPREFIXING_SERVICE =
+ "layout.css.unprefixing-service.enabled";
+const PREF_INCLUDE_TEST_DOMAINS =
+ "layout.css.unprefixing-service.include-test-domains";
+
+// Helper-function to make unique URLs in testHost():
+var gCounter = 0;
+function getIncreasingCounter() {
+ return gCounter++;
+}
+
+// This function tests a particular host in our iframe.
+// @param aHost The host to be tested
+// @param aExpectEnabled Should we expect unprefixing to be enabled for host?
+function testHost(aHost, aExpectEnabled) {
+ // Build the URL:
+ let url = window.location.protocol; // "http:" or "https:"
+ url += "//";
+ url += aHost;
+
+ // Append the path-name, up to the actual filename (the final "/"):
+ const re = /(.*\/).*/;
+ url += window.location.pathname.replace(re, "$1");
+ url += IFRAME_TESTFILE;
+ // In case this is the same URL as last time, we add "?N" for some unique N,
+ // to make each URL different, so that the iframe actually (re)loads:
+ url += "?" + getIncreasingCounter();
+ // We give the URL a #suffix to indicate to the test whether it should expect
+ // that unprefixing is enabled or disabled:
+ url += (aExpectEnabled ? "#expectEnabled" : "#expectDisabled");
+
+ let iframe = document.getElementById("testIframe");
+ iframe.contentWindow.location = url;
+ // The iframe will report its results back via postMessage.
+ // Our caller had better have set up a postMessage listener.
+}
+
+// Register a postMessage() handler, to allow our cross-origin iframe to
+// communicate back to the main page's mochitest functionality.
+// The handler expects postMessage to be called with an object like:
+// { type: ["is"|"ok"|"testComplete"], ... }
+// The "is" and "ok" types will trigger the corresponding function to be
+// called in the main page, with named arguments provided in the payload.
+// The "testComplete" type will trigger the passed-in aTestCompleteCallback
+// function to be invoked (e.g. to advance to the next testcase, or to finish
+// the overall test, as-appropriate).
+function registerPostMessageListener(aTestCompleteCallback) {
+ let receiveMessage = function(event) {
+ if (event.data.type === "is") {
+ is(event.data.actual, event.data.expected, event.data.desc);
+ } else if (event.data.type === "ok") {
+ ok(event.data.condition, event.data.desc);
+ } else if (event.data.type === "testComplete") {
+ aTestCompleteCallback();
+ } else {
+ ok(false, "unrecognized data in postMessage call");
+ }
+ };
+
+ window.addEventListener("message", receiveMessage, false);
+}