summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/shim/test
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 /devtools/client/shared/shim/test
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 'devtools/client/shared/shim/test')
-rw-r--r--devtools/client/shared/shim/test/.eslintrc.js6
-rw-r--r--devtools/client/shared/shim/test/file_service_wm.html20
-rw-r--r--devtools/client/shared/shim/test/mochitest.ini10
-rw-r--r--devtools/client/shared/shim/test/prefs-wrapper.js80
-rw-r--r--devtools/client/shared/shim/test/test_service_appinfo.html29
-rw-r--r--devtools/client/shared/shim/test/test_service_focus.html78
-rw-r--r--devtools/client/shared/shim/test/test_service_prefs.html244
-rw-r--r--devtools/client/shared/shim/test/test_service_prefs_defaults.html71
-rw-r--r--devtools/client/shared/shim/test/test_service_wm.html36
9 files changed, 574 insertions, 0 deletions
diff --git a/devtools/client/shared/shim/test/.eslintrc.js b/devtools/client/shared/shim/test/.eslintrc.js
new file mode 100644
index 000000000..698ae9181
--- /dev/null
+++ b/devtools/client/shared/shim/test/.eslintrc.js
@@ -0,0 +1,6 @@
+"use strict";
+
+module.exports = {
+ // Extend from the shared list of defined globals for mochitests.
+ "extends": "../../../../.eslintrc.mochitests.js"
+};
diff --git a/devtools/client/shared/shim/test/file_service_wm.html b/devtools/client/shared/shim/test/file_service_wm.html
new file mode 100644
index 000000000..24753e710
--- /dev/null
+++ b/devtools/client/shared/shim/test/file_service_wm.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script>
+// Silence eslint complaint about the onload below.
+/* eslint-disable no-unused-vars */
+
+"use strict";
+
+function load() {
+ (window.opener || window.parent).hurray();
+ window.close();
+}
+</script>
+</head>
+
+<body onload='load()'>
+</body>
+
+</html>
diff --git a/devtools/client/shared/shim/test/mochitest.ini b/devtools/client/shared/shim/test/mochitest.ini
new file mode 100644
index 000000000..4ba5cd6c1
--- /dev/null
+++ b/devtools/client/shared/shim/test/mochitest.ini
@@ -0,0 +1,10 @@
+[DEFAULT]
+support-files =
+ file_service_wm.html
+ prefs-wrapper.js
+
+[test_service_appinfo.html]
+[test_service_focus.html]
+[test_service_prefs.html]
+[test_service_prefs_defaults.html]
+[test_service_wm.html]
diff --git a/devtools/client/shared/shim/test/prefs-wrapper.js b/devtools/client/shared/shim/test/prefs-wrapper.js
new file mode 100644
index 000000000..057e12d17
--- /dev/null
+++ b/devtools/client/shared/shim/test/prefs-wrapper.js
@@ -0,0 +1,80 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* 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/. */
+
+// A wrapper for Services.prefs that compares our shim content
+// implementation with the real service.
+
+// We assume we're loaded in a global where Services was already loaded.
+/* globals isDeeply, Services */
+
+"use strict";
+
+function setMethod(methodName, prefName, value) {
+ let savedException;
+ let prefThrew = false;
+ try {
+ Services.prefs[methodName](prefName, value);
+ } catch (e) {
+ prefThrew = true;
+ savedException = e;
+ }
+
+ let realThrew = false;
+ try {
+ SpecialPowers[methodName](prefName, value);
+ } catch (e) {
+ realThrew = true;
+ savedException = e;
+ }
+
+ is(prefThrew, realThrew, methodName + " [throw check]");
+ if (prefThrew || realThrew) {
+ throw savedException;
+ }
+}
+
+function getMethod(methodName, prefName) {
+ let prefThrew = false;
+ let prefValue = undefined;
+ let savedException;
+ try {
+ prefValue = Services.prefs[methodName](prefName);
+ } catch (e) {
+ prefThrew = true;
+ savedException = e;
+ }
+
+ let realValue = undefined;
+ let realThrew = false;
+ try {
+ realValue = SpecialPowers[methodName](prefName);
+ } catch (e) {
+ realThrew = true;
+ savedException = e;
+ }
+
+ is(prefThrew, realThrew, methodName + " [throw check]");
+ isDeeply(prefValue, realValue, methodName + " [equality]");
+ if (prefThrew || realThrew) {
+ throw savedException;
+ }
+
+ return prefValue;
+}
+
+var WrappedPrefs = {};
+
+for (let method of ["getPrefType", "getBoolPref", "getCharPref", "getIntPref",
+ "clearUserPref"]) {
+ WrappedPrefs[method] = getMethod.bind(null, method);
+}
+
+for (let method of ["setBoolPref", "setCharPref", "setIntPref"]) {
+ WrappedPrefs[method] = setMethod.bind(null, method);
+}
+
+// Silence eslint.
+exports.WrappedPrefs = WrappedPrefs;
diff --git a/devtools/client/shared/shim/test/test_service_appinfo.html b/devtools/client/shared/shim/test/test_service_appinfo.html
new file mode 100644
index 000000000..bc659cb42
--- /dev/null
+++ b/devtools/client/shared/shim/test/test_service_appinfo.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1265802
+-->
+<head>
+ <title>Test for Bug 1265802 - replace Services.appinfo</title>
+ <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css"
+ href="chrome://mochikit/content/tests/SimpleTest/test.css">
+
+ <script type="application/javascript;version=1.8">
+ "use strict";
+ var exports = {}
+ var module = {exports};
+ </script>
+
+ <script type="application/javascript;version=1.8"
+ src="resource://devtools/client/shared/shim/Services.js"></script>
+</head>
+<body>
+<script type="application/javascript;version=1.8">
+"use strict";
+
+is(Services.appinfo.OS, SpecialPowers.Services.appinfo.OS,
+ "check that Services.appinfo.OS shim matches platform");
+</script>
+</body>
diff --git a/devtools/client/shared/shim/test/test_service_focus.html b/devtools/client/shared/shim/test/test_service_focus.html
new file mode 100644
index 000000000..d720e0b53
--- /dev/null
+++ b/devtools/client/shared/shim/test/test_service_focus.html
@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1278473
+-->
+<head>
+ <title>Test for Bug 1278473 - replace Services.focus</title>
+ <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css"
+ href="chrome://mochikit/content/tests/SimpleTest/test.css">
+
+ <script type="application/javascript;version=1.8">
+ "use strict";
+ var exports = {}
+ var module = {exports};
+ </script>
+
+ <script type="application/javascript;version=1.8"
+ src="resource://devtools/client/shared/shim/Services.js"></script>
+</head>
+<body>
+ <span>
+ <span id="start" testvalue="0" tabindex="0"> </span>
+ <label>
+ <input testvalue="1" type="radio">Hi</input>
+ </label>
+ <label>
+ <input type="radio" tabindex="-1">Bye</input>
+ </label>
+ <label style="display: none">
+ <input id="button3" type="radio" tabindex="-1">Invisible</input>
+ </label>
+ <input id="button4" type="radio" disabled="true">Disabled</input>
+ <span testvalue="2" tabindex="0"> </span>
+ </span>
+
+<script type="application/javascript;version=1.8">
+ "use strict";
+
+ // The test assumes these are identical, so assert it here.
+ is(Services.focus.MOVEFOCUS_BACKWARD, SpecialPowers.Services.focus.MOVEFOCUS_BACKWARD,
+ "check MOVEFOCUS_BACKWARD");
+ is(Services.focus.MOVEFOCUS_FORWARD, SpecialPowers.Services.focus.MOVEFOCUS_FORWARD,
+ "check MOVEFOCUS_FORWARD");
+
+ function moveFocus(element, type, expect) {
+ let current = document.activeElement;
+ const suffix = "(type=" + type + ", to=" + expect + ")";
+
+ // First try with the platform implementation.
+ SpecialPowers.Services.focus.moveFocus(window, element, type, 0);
+ is(document.activeElement.getAttribute("testvalue"), expect,
+ "platform moveFocus " + suffix);
+
+ // Reset the focus and try again with the shim.
+ current.focus();
+ is(document.activeElement, current, "reset " + suffix);
+
+ Services.focus.moveFocus(window, element, type, 0);
+ is(document.activeElement.getAttribute("testvalue"), expect,
+ "shim moveFocus " + suffix);
+ }
+
+ let start = document.querySelector("#start");
+ start.focus();
+ is(document.activeElement.getAttribute("testvalue"), "0", "initial focus");
+
+ moveFocus(null, Services.focus.MOVEFOCUS_FORWARD, "1");
+ moveFocus(null, Services.focus.MOVEFOCUS_FORWARD, "2");
+ let end = document.activeElement;
+ moveFocus(null, Services.focus.MOVEFOCUS_BACKWARD, "1");
+ moveFocus(null, Services.focus.MOVEFOCUS_BACKWARD, "0");
+
+ moveFocus(start, Services.focus.MOVEFOCUS_FORWARD, "1");
+ moveFocus(end, Services.focus.MOVEFOCUS_BACKWARD, "1");
+</script>
+</body>
diff --git a/devtools/client/shared/shim/test/test_service_prefs.html b/devtools/client/shared/shim/test/test_service_prefs.html
new file mode 100644
index 000000000..99e827dfd
--- /dev/null
+++ b/devtools/client/shared/shim/test/test_service_prefs.html
@@ -0,0 +1,244 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1265808
+-->
+<head>
+ <title>Test for Bug 1265808 - replace Services.prefs</title>
+ <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css"
+ href="chrome://mochikit/content/tests/SimpleTest/test.css">
+
+<script type="application/javascript;version=1.8">
+"use strict";
+var exports = {}
+var module = {exports};
+
+ // Add some starter prefs.
+localStorage.setItem("Services.prefs:devtools.branch1.somebool", JSON.stringify({
+ // bool
+ type: 128,
+ defaultValue: false,
+ hasUserValue: false,
+ userValue: false
+}));
+
+localStorage.setItem("Services.prefs:devtools.branch1.somestring", JSON.stringify({
+ // string
+ type: 32,
+ defaultValue: "dinosaurs",
+ hasUserValue: true,
+ userValue: "elephants"
+}));
+
+localStorage.setItem("Services.prefs:devtools.branch2.someint", JSON.stringify({
+ // string
+ type: 64,
+ defaultValue: -16,
+ hasUserValue: false,
+ userValue: null
+}));
+
+</script>
+
+ <script type="application/javascript;version=1.8"
+ src="prefs-wrapper.js"></script>
+ <script type="application/javascript;version=1.8"
+ src="resource://devtools/client/shared/shim/Services.js"></script>
+</head>
+<body>
+<script type="application/javascript;version=1.8">
+"use strict";
+
+function do_tests() {
+ // We can't load the defaults in this context.
+ Services._defaultPrefsEnabled = false;
+
+ is(Services.prefs.getBoolPref("devtools.branch1.somebool"), false,
+ "bool pref value");
+ Services.prefs.setBoolPref("devtools.branch1.somebool", true);
+ is(Services.prefs.getBoolPref("devtools.branch1.somebool"), true,
+ "bool pref value after setting");
+
+ let threw;
+
+ try {
+ threw = false;
+ WrappedPrefs.getIntPref("devtools.branch1.somebool");
+ } catch (e) {
+ threw = true;
+ }
+ ok(threw, "type-checking for bool pref");
+
+ try {
+ threw = false;
+ Services.prefs.setIntPref("devtools.branch1.somebool", 27);
+ } catch (e) {
+ threw = true;
+ }
+ ok(threw, "type-checking for setting bool pref");
+
+ try {
+ threw = false;
+ Services.prefs.setBoolPref("devtools.branch1.somebool", 27);
+ } catch (e) {
+ threw = true;
+ }
+ ok(threw, "setting bool pref to wrong type");
+
+ try {
+ threw = false;
+ Services.prefs.getCharPref("devtools.branch2.someint");
+ } catch (e) {
+ threw = true;
+ }
+ ok(threw, "type-checking for int pref");
+
+ try {
+ threw = false;
+ Services.prefs.setCharPref("devtools.branch2.someint", "whatever");
+ } catch (e) {
+ threw = true;
+ }
+ ok(threw, "type-checking for setting int pref");
+
+ try {
+ threw = false;
+ Services.prefs.setIntPref("devtools.branch2.someint", "whatever");
+ } catch (e) {
+ threw = true;
+ }
+ ok(threw, "setting int pref to wrong type");
+
+ try {
+ threw = false;
+ Services.prefs.getBoolPref("devtools.branch1.somestring");
+ } catch (e) {
+ threw = true;
+ }
+ ok(threw, "type-checking for char pref");
+
+ try {
+ threw = false;
+ Services.prefs.setBoolPref("devtools.branch1.somestring", true);
+ } catch (e) {
+ threw = true;
+ }
+ ok(threw, "type-checking for setting char pref");
+
+ try {
+ threw = false;
+ Services.prefs.setCharPref("devtools.branch1.somestring", true);
+ } catch (e) {
+ threw = true;
+ }
+ ok(threw, "setting char pref to wrong type");
+
+ is(Services.prefs.getPrefType("devtools.branch1.somebool"),
+ Services.prefs.PREF_BOOL, "type of bool pref");
+ is(Services.prefs.getPrefType("devtools.branch2.someint"),
+ Services.prefs.PREF_INT, "type of int pref");
+ is(Services.prefs.getPrefType("devtools.branch1.somestring"),
+ Services.prefs.PREF_STRING, "type of string pref");
+
+ WrappedPrefs.setBoolPref("devtools.branch1.somebool", true);
+ ok(WrappedPrefs.getBoolPref("devtools.branch1.somebool"), "set bool pref");
+ WrappedPrefs.setIntPref("devtools.branch2.someint", -93);
+ is(WrappedPrefs.getIntPref("devtools.branch2.someint"), -93, "set int pref");
+ WrappedPrefs.setCharPref("devtools.branch1.somestring", "hello");
+ is(WrappedPrefs.getCharPref("devtools.branch1.somestring"), "hello",
+ "set string pref");
+
+ Services.prefs.clearUserPref("devtools.branch1.somestring");
+ is(Services.prefs.getCharPref("devtools.branch1.somestring"), "dinosaurs",
+ "clear string pref");
+
+ ok(Services.prefs.prefHasUserValue("devtools.branch1.somebool"),
+ "bool pref has user value");
+ ok(!Services.prefs.prefHasUserValue("devtools.branch1.somestring"),
+ "string pref does not have user value");
+
+
+ Services.prefs.savePrefFile(null);
+ ok(true, "saved pref file without error");
+
+
+ let branch0 = Services.prefs.getBranch(null);
+ let branch1 = Services.prefs.getBranch("devtools.branch1.");
+
+ branch1.setCharPref("somestring", "octopus");
+ Services.prefs.setCharPref("devtools.branch1.somestring", "octopus");
+ is(Services.prefs.getCharPref("devtools.branch1.somestring"), "octopus",
+ "set correctly via branch");
+ is(branch0.getCharPref("devtools.branch1.somestring"), "octopus",
+ "get via base branch");
+ is(branch1.getCharPref("somestring"), "octopus", "get via branch");
+
+
+ let notifications = {};
+ let clearNotificationList = () => { notifications = {}; }
+ let observer = {
+ observe: function (subject, topic, data) {
+ notifications[data] = true;
+ }
+ };
+
+ branch0.addObserver("devtools.branch1", null, null);
+ branch0.addObserver("devtools.branch1.", observer, false);
+ branch1.addObserver("", observer, false);
+
+ Services.prefs.setCharPref("devtools.branch1.somestring", "elf owl");
+ isDeeply(notifications, {
+ "devtools.branch1.somestring": true,
+ "somestring": true
+ }, "notifications sent to two listeners");
+
+ clearNotificationList();
+ Services.prefs.setIntPref("devtools.branch2.someint", 1729);
+ isDeeply(notifications, {}, "no notifications sent");
+
+ clearNotificationList();
+ branch0.removeObserver("devtools.branch1.", observer);
+ Services.prefs.setCharPref("devtools.branch1.somestring", "tapir");
+ isDeeply(notifications, {
+ "somestring": true
+ }, "removeObserver worked");
+
+ clearNotificationList();
+ branch0.addObserver("devtools.branch1.somestring", observer, false);
+ Services.prefs.setCharPref("devtools.branch1.somestring", "northern shoveler");
+ isDeeply(notifications, {
+ "devtools.branch1.somestring": true,
+ "somestring": true
+ }, "notifications sent to two listeners");
+ branch0.removeObserver("devtools.branch1.somestring", observer);
+
+ // Make sure we update if the pref change comes from somewhere else.
+ clearNotificationList();
+ pref("devtools.branch1.someotherstring", "lazuli bunting");
+ isDeeply(notifications, {
+ "someotherstring": true
+ }, "pref worked");
+
+ // Regression test for bug 1296427.
+ pref("devtools.hud.loglimit", 1000);
+ pref("devtools.hud.loglimit.network", 1000);
+
+ // Clean up.
+ localStorage.clear();
+
+ SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+SpecialPowers.pushPrefEnv(
+ {"set": [
+ ["devtools.branch1.somestring", "elephants"],
+ ["devtools.branch1.somebool", false],
+ ["devtools.branch2.someint", "-16"],
+ ]},
+ do_tests);
+
+</script>
+</body>
diff --git a/devtools/client/shared/shim/test/test_service_prefs_defaults.html b/devtools/client/shared/shim/test/test_service_prefs_defaults.html
new file mode 100644
index 000000000..d8933b74a
--- /dev/null
+++ b/devtools/client/shared/shim/test/test_service_prefs_defaults.html
@@ -0,0 +1,71 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1309384
+-->
+<head>
+ <title>Test for Bug 1309384 - Services.prefs replacement defaults handling</title>
+ <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css"
+ href="chrome://mochikit/content/tests/SimpleTest/test.css">
+
+<script type="application/javascript;version=1.8">
+"use strict";
+var exports = {}
+var module = {exports};
+
+// Allow one require("raw!prefs...") to return some defaults, with the
+// others being ignored.
+var firstTime = true;
+function require(something) {
+ if (!something.startsWith("raw!prefs!")) {
+ throw new Error("whoops");
+ }
+ if (!firstTime) {
+ return "";
+ }
+ firstTime = false;
+ return "pref('pref1', 'pref1default');\n" +
+ "pref('pref2', 'pref2default');\n" +
+ "pref('pref3', 'pref3default');\n";
+}
+
+// Pretend that one of the prefs was modifed by the user in an earlier session.
+localStorage.setItem("Services.prefs:pref3", JSON.stringify({
+ // string
+ type: 32,
+ defaultValue: "pref3default",
+ hasUserValue: true,
+ userValue: "glass winged butterfly"
+}));
+
+</script>
+
+ <script type="application/javascript;version=1.8"
+ src="resource://devtools/client/shared/shim/Services.js"></script>
+</head>
+<body>
+<script type="application/javascript;version=1.8">
+"use strict";
+
+is(Services.prefs.getCharPref("pref1"), "pref1default", "pref1 value");
+is(Services.prefs.getCharPref("pref2"), "pref2default", "pref2 value");
+is(Services.prefs.getCharPref("pref3"), "glass winged butterfly", "pref3 value");
+
+// Only pref3 should be in local storage at this point.
+is(localStorage.length, 1, "local storage is correct");
+
+Services.prefs.setCharPref("pref2", "pref2override");
+
+// Check that a default pref can be overridden properly
+
+// Workaround to reset the prefs helper and force it to read defaults & overrides again.
+Services._prefs = null;
+is(Services.prefs.getCharPref("pref2"), "pref2override", "pref2 value overridden");
+
+// Clean up.
+localStorage.clear();
+
+</script>
+</body>
diff --git a/devtools/client/shared/shim/test/test_service_wm.html b/devtools/client/shared/shim/test/test_service_wm.html
new file mode 100644
index 000000000..4db602f7e
--- /dev/null
+++ b/devtools/client/shared/shim/test/test_service_wm.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1310279
+-->
+<head>
+ <title>Test for Bug 1310279 - replace Services.wm</title>
+ <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css"
+ href="chrome://mochikit/content/tests/SimpleTest/test.css">
+
+ <script type="application/javascript;version=1.8">
+ "use strict";
+ var exports = {}
+ var module = {exports};
+ </script>
+
+ <script type="application/javascript;version=1.8"
+ src="resource://devtools/client/shared/shim/Services.js"></script>
+</head>
+<body>
+
+<script type="application/javascript;version=1.8">
+ "use strict";
+
+ function hurray(window) {
+ ok(true, "window loaded");
+ SimpleTest.finish();
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ Services.wm.getMostRecentWindow().openUILinkIn("file_service_wm.html");
+
+</script>
+</body>