summaryrefslogtreecommitdiffstats
path: root/dom/permission/tests
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 /dom/permission/tests
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 'dom/permission/tests')
-rw-r--r--dom/permission/tests/file_empty.html2
-rw-r--r--dom/permission/tests/file_framework.js224
-rw-r--r--dom/permission/tests/file_shim.html99
-rw-r--r--dom/permission/tests/mochitest-time.ini1
-rw-r--r--dom/permission/tests/mochitest.ini31
-rw-r--r--dom/permission/tests/test_browser.html49
-rw-r--r--dom/permission/tests/test_embed-apps.html61
-rw-r--r--dom/permission/tests/test_idle.html46
-rw-r--r--dom/permission/tests/test_input-manage.html69
-rw-r--r--dom/permission/tests/test_keyboard.html51
-rw-r--r--dom/permission/tests/test_networkstats-manage.html31
-rw-r--r--dom/permission/tests/test_permissions.html31
-rw-r--r--dom/permission/tests/test_permissions_api.html206
-rw-r--r--dom/permission/tests/test_power.html30
-rw-r--r--dom/permission/tests/test_presentation-device-manage.html38
-rw-r--r--dom/permission/tests/test_systemXHR.html38
-rw-r--r--dom/permission/tests/test_tcp-socket.html52
-rw-r--r--dom/permission/tests/test_time.html30
-rw-r--r--dom/permission/tests/test_udp-socket.html47
-rw-r--r--dom/permission/tests/test_wifi-manage.html41
-rw-r--r--dom/permission/tests/unit/test_bug808734.js73
-rw-r--r--dom/permission/tests/unit/xpcshell.ini5
22 files changed, 1255 insertions, 0 deletions
diff --git a/dom/permission/tests/file_empty.html b/dom/permission/tests/file_empty.html
new file mode 100644
index 000000000..bc98b4d2e
--- /dev/null
+++ b/dom/permission/tests/file_empty.html
@@ -0,0 +1,2 @@
+<h1>I'm just a support file</h1>
+<p>I get loaded to do permission testing.</p> \ No newline at end of file
diff --git a/dom/permission/tests/file_framework.js b/dom/permission/tests/file_framework.js
new file mode 100644
index 000000000..27624f91e
--- /dev/null
+++ b/dom/permission/tests/file_framework.js
@@ -0,0 +1,224 @@
+/** Test for Bug 815105 **/
+/*
+ * gData is an array of object that tests using this framework must pass in
+ * The current tests only pass in a single element array. Each test in
+ * gData is executed by the framework for a given file
+ *
+ * Fields in gData object
+ * perms (required) Array of Strings
+ * list of permissions that this test will need. See
+ * http://dxr.mozilla.org/mozilla-central/source/dom/apps/src/PermissionsTable.jsm
+ * These permissions are added after a sanity check and removed at
+ * test conclusion
+ *
+ * obj (required for default verifier) String
+ * The name of the window.navigator object used for accessing the
+ * WebAPI during the tests
+ *
+ * webidl (required for default verifier) String
+ * idl (required for default verifier) String
+ * Only one of webidl / idl is required
+ * The IDL describing the navigator object. The returned object
+ * during tests /must/ be an instanceof this
+ *
+ * skip (optional) Array of Strings
+ * A list of navigator.userAgent's to skip the second part of tests
+ * on. The tests still verify that you can't get obj on those
+ * platforms without permissions, however it is expected that adding
+ * the permission still won't allow access to those objects
+ *
+ * settings (optional) Array of preference tuples
+ * A list of settings that need to be set before this API is
+ * enabled. Note the settings are set before the sanity check is
+ * performed. If an API gates access only by preferences, then it
+ * will fail the initial test
+ *
+ * verifier (optional) Function
+ * A function used to test whether a WebAPI is accessible or not.
+ * The function takes a success and failure callback which both
+ * accept a msg argument. msg is surfaced up to the top level tests
+ * A default verifier is provided which only attempts to access
+ * the navigator object.
+ *
+ * needParentPerm (optional) Boolean
+ * Whether or not the parent frame requires these permissions as
+ * well. Otherwise the test process may be killed.
+ */
+
+SimpleTest.waitForExplicitFinish();
+var expand = SpecialPowers.Cu.import("resource://gre/modules/PermissionsTable.jsm").expandPermissions;
+const permTable = SpecialPowers.Cu.import("resource://gre/modules/PermissionsTable.jsm").PermissionsTable;
+
+const TEST_DOMAIN = "http://example.org";
+const SHIM_PATH = "/tests/dom/permission/tests/file_shim.html"
+var gContent = document.getElementById('content');
+
+//var gData; defined in external files
+var gCurrentTest = 0;
+var gRemainingTests;
+var pendingTests = {};
+
+function PermTest(aData) {
+ var self = this;
+ var skip = aData.skip || false;
+ this.step = 0;
+ this.data = aData;
+ this.isSkip = skip &&
+ skip.some(function (el) {
+ return navigator.
+ userAgent.toLowerCase().
+ indexOf(el.toLowerCase()) != -1;
+ });
+
+ this.setupParent = false;
+ this.perms = expandPermissions(aData.perm);
+ this.id = gCurrentTest++;
+ this.iframe = null;
+
+ // keep a reference to this for eventhandler
+ pendingTests[this.id] = this;
+
+ this.createFrame = function() {
+ if (self.iframe) {
+ gContent.removeChild(self.iframe);
+ }
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('id', 'testframe' + self.step + self.perms)
+ iframe.setAttribute('remote', true);
+ iframe.src = TEST_DOMAIN + SHIM_PATH;
+ iframe.addEventListener('load', function _iframeLoad() {
+ iframe.removeEventListener('load', _iframeLoad);
+
+ // check permissions are correct
+ var allow = (self.step == 0 ? false : true);
+ self.perms.forEach(function (el) {
+ try {
+ var res = SpecialPowers.hasPermission(el, SpecialPowers.wrap(iframe)
+ .contentDocument);
+ is(res, allow, (allow ? "Has " : "Doesn't have ") + el);
+ } catch(e) {
+ ok(false, "failed " + e);
+ }
+ });
+
+ var msg = {
+ id: self.id,
+ step: self.step++,
+ testdata: self.data,
+ }
+ // start the tests
+ iframe.contentWindow.postMessage(msg, "*");
+ });
+
+ self.iframe = iframe;
+ gContent.appendChild(iframe);
+ }
+
+ this.next = function () {
+ switch(self.step) {
+ case 0:
+ self.createFrame();
+ break;
+ case 1:
+ // add permissions
+ addPermissions(self.perms, SpecialPowers.
+ wrap(self.iframe).
+ contentDocument,
+ self.createFrame.bind(self));
+ break;
+ case 2:
+ if (self.iframe) {
+ gContent.removeChild(self.iframe);
+ }
+ checkFinish();
+ break;
+ default:
+ ok(false, "Should not be reached");
+ break
+ }
+ }
+
+ this.start = function() {
+ // some permissions need parent to have permission as well
+ if (!self.setupParent && self.data.needParentPerm &&
+ !SpecialPowers.isMainProcess()) {
+ self.setupParent = true;
+ addPermissions(self.perms, window.document, self.start.bind(self));
+ } else if (self.data.settings && self.data.settings.length) {
+ SpecialPowers.pushPrefEnv({'set': self.data.settings.slice(0)},
+ self.next.bind(self));
+ } else {
+ self.next();
+ }
+ }
+}
+
+function addPermissions(aPerms, aDoc, aCallback) {
+ var permList = [];
+ aPerms.forEach(function (el) {
+ var obj = {'type': el,
+ 'allow': 1,
+ 'context': aDoc};
+ permList.push(obj);
+ });
+ SpecialPowers.pushPermissions(permList, aCallback);
+}
+
+function expandPermissions(aPerms) {
+ var perms = [];
+ aPerms.forEach(function(el) {
+ var access = permTable[el].access ? "readwrite" : null;
+ var expanded = expand(el, access);
+ for (let i = 0; i < expanded.length; i++) {
+ perms.push(SpecialPowers.unwrap(expanded[i]));
+ }
+ });
+
+ return perms;
+}
+
+function msgHandler(evt) {
+ var data = evt.data;
+ var test = pendingTests[data.id];
+
+ /*
+ * step 2 of tests should fail on
+ * platforms which are skipped
+ */
+ if (test.isSkip && test.step == 2) {
+ todo(data.result, data.msg);
+ } else {
+ ok(data.result, data.msg);
+ }
+
+ if (test) {
+ test.next();
+ } else {
+ ok(false, "Received unknown id " + data.id);
+ checkFinish();
+ }
+}
+
+function checkFinish() {
+ if (--gRemainingTests) {
+ gTestRunner.next();
+ } else {
+ window.removeEventListener('message', msgHandler);
+ SimpleTest.finish();
+ }
+}
+
+function runTest() {
+ gRemainingTests = Object.keys(gData).length;
+
+ for (var test in gData) {
+ var test = new PermTest(gData[test]);
+ test.start();
+ yield undefined;
+ }
+}
+
+var gTestRunner = runTest();
+
+window.addEventListener('load', function() { gTestRunner.next(); }, false);
+window.addEventListener('message', msgHandler, false);
diff --git a/dom/permission/tests/file_shim.html b/dom/permission/tests/file_shim.html
new file mode 100644
index 000000000..7791eba65
--- /dev/null
+++ b/dom/permission/tests/file_shim.html
@@ -0,0 +1,99 @@
+<html>
+<head>
+<script type="application/javascript;version=1.8">
+function TestData(aOpts) {
+ for (var opt in aOpts) {
+ if (aOpts.hasOwnProperty(opt)) {
+ this[opt] = aOpts[opt];
+ }
+ }
+}
+
+TestData.prototype = {
+ getObj: function() {
+ if (!this.obj) {
+ return null;
+ }
+
+ // only one of the 2 should be set
+ if ((this.idl && this.webidl) ||
+ (!this.idl && !this.webidl)) {
+ return null;
+ }
+
+ // split on . to allow nested props
+ var props = this.obj.split(".");
+ var obj = window.navigator;
+
+ for (var i = 0; i < props.length && obj !== undefined; i++) {
+ obj = obj[props[i]];
+ }
+
+ if ((this.webidl && obj instanceof window[this.webidl]) ||
+ (this.idl && obj instanceof SpecialPowers.Ci[this.idl])) {
+ return obj;
+ } else {
+ return null;
+ }
+ },
+
+ // default verifier
+ verifier: function(success, failure) {
+ try {
+ if (this.getObj()) {
+ success(this.perm);
+ } else {
+ failure("Did not receive proper object");
+ }
+ } catch (e) {
+ failure("Received exception!: " + e);
+ }
+ },
+}
+
+function receiveMessage(e) {
+ var src = e.source;
+ var step = e.data.step;
+ var id = e.data.id;
+ var data = new TestData(e.data.testdata);
+ var success, failure;
+
+ function reply(res, msg) {
+ window.removeEventListener("message", receiveMessage, false);
+ src.postMessage({result: res, msg: msg,
+ id: id}, "*");
+ }
+
+ function _success(msg) {
+ reply(true, msg);
+ }
+
+ function _failure(msg) {
+ reply(false, msg);
+ }
+
+ // flip success and failure around for precheck
+ if (step == 0) {
+ success = _failure;
+ failure = _success;
+ } else {
+ success = _success;
+ failure = _failure;
+ }
+
+ if (data.verifier instanceof Function) {
+ data.verifier(success, failure);
+ } else {
+ // import toSource() function to global
+ eval(data.verifier);
+ verifier.bind(data, success, failure)();
+ }
+}
+
+window.addEventListener("message", receiveMessage, false);
+</script>
+</head>
+<body>
+<div id="content" style="display: none"></div>
+</body>
+</html>
diff --git a/dom/permission/tests/mochitest-time.ini b/dom/permission/tests/mochitest-time.ini
new file mode 100644
index 000000000..24f65b2a4
--- /dev/null
+++ b/dom/permission/tests/mochitest-time.ini
@@ -0,0 +1 @@
+[test_time.html]
diff --git a/dom/permission/tests/mochitest.ini b/dom/permission/tests/mochitest.ini
new file mode 100644
index 000000000..58fd048ca
--- /dev/null
+++ b/dom/permission/tests/mochitest.ini
@@ -0,0 +1,31 @@
+[DEFAULT]
+support-files =
+ file_framework.js
+ file_shim.html
+ file_empty.html
+
+[test_browser.html]
+skip-if = true
+[test_idle.html]
+# skip-if = (toolkit == 'gonk' && debug) #debug-only failure
+skip-if = true
+[test_permissions.html]
+skip-if = true
+[test_permissions_api.html]
+[test_power.html]
+skip-if = true
+[test_presentation-device-manage.html]
+skip-if = true
+[test_systemXHR.html]
+[test_tcp-socket.html]
+skip-if = true
+[test_udp-socket.html]
+skip-if = true
+[test_keyboard.html]
+# skip-if = toolkit == 'android'
+skip-if = true
+[test_input-manage.html]
+# skip-if = toolkit == 'android'
+skip-if = true
+[test_wifi-manage.html]
+skip-if = true
diff --git a/dom/permission/tests/test_browser.html b/dom/permission/tests/test_browser.html
new file mode 100644
index 000000000..0e6f44d58
--- /dev/null
+++ b/dom/permission/tests/test_browser.html
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=815105
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 815105 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=815105">Mozilla Bug 815105 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+function verifier(success, failure) {
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', 'true');
+ iframe.src = "http://example.org/";
+ iframe.addEventListener('load', function() {
+ iframe.removeEventListener('load', arguments.callee);
+
+ if (iframe.getScreenshot && typeof iframe.getScreenshot == "function") {
+ success("Got mozbrowser");
+ } else {
+ failure("Didn't get mozbrowser") ;
+ }
+ });
+
+ document.getElementById('content').appendChild(iframe);
+}
+
+var gData = [
+ {
+ perm: ["browser"],
+ needParentPerm: true,
+ settings: [["dom.mozBrowserFramesEnabled", true],
+ ["network.disable.ipc.security", true]],
+ verifier: verifier.toSource(),
+ }
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_embed-apps.html b/dom/permission/tests/test_embed-apps.html
new file mode 100644
index 000000000..69d4725c7
--- /dev/null
+++ b/dom/permission/tests/test_embed-apps.html
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=815105
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 815105 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=815105">Mozilla Bug 815105 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+/*
+ * embed-apps allows us to create app iframes,
+ * creator must also have the browser permission
+ */
+function verifier(success, failure) {
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', '');
+ iframe.setAttribute('mozapp', 'http://example.org/manifest.webapp');
+ iframe.src = "http://example.org/";
+ iframe.addEventListener('load', function() {
+ var appStatus = SpecialPowers.wrap(iframe)
+ .contentDocument.nodePrincipal.appStatus;
+
+ if (appStatus != SpecialPowers.Ci
+ .nsIPrincipal.APP_STATUS_NOT_INSTALLED) {
+ success("Got mozapp");
+ } else {
+ failure("Didn't get mozapp") ;
+ }
+ });
+
+ document.getElementById('content').appendChild(iframe);
+}
+
+var gData = [
+ {
+ perm: ["embed-apps", "browser"],
+ /*
+ * Android doesn't have working apps
+ * Mobile is for B2G which has a weird testing setup
+ * the app iframe gets embed in the test-container iframe
+ * which returns APP_STATUS_NOT_INSTALLED
+ */
+ skip: ["Android", "Mobile"],
+ settings: [["dom.mozBrowserFramesEnabled", true]],
+ verifier: verifier.toSource(),
+ }
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_idle.html b/dom/permission/tests/test_idle.html
new file mode 100644
index 000000000..ef37c3efd
--- /dev/null
+++ b/dom/permission/tests/test_idle.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=815105
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 815105 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=815105">Mozilla Bug 815105 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+function verifier(success, failure) {
+ try {
+ var obs = {
+ time: 1,
+ onidle: function() {
+ window.navigator.removeIdleObserver(obs);
+ },
+ }
+
+ // addIdleObserver throws if prinicpal doesn't have the permission
+ window.navigator.addIdleObserver(obs);
+ success("idle");
+ } catch (e) {
+ failure("Got an exception " + e);
+ }
+}
+
+var gData = [
+ {
+ perm: ["idle"],
+ verifier: verifier.toSource(),
+ }
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_input-manage.html b/dom/permission/tests/test_input-manage.html
new file mode 100644
index 000000000..a60a19467
--- /dev/null
+++ b/dom/permission/tests/test_input-manage.html
@@ -0,0 +1,69 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=920977
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 920977 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=920977">Mozilla Bug 920977 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+function verifier(success, failure) {
+ try {
+ if (!this.getObj()) {
+ failure("Did not receive proper object");
+ return;
+ }
+ } catch (e) {
+ failure("Received exception!: " + e);
+ return;
+ }
+
+ try {
+ this.getObj().removeFocus();
+ } catch (e) {
+ failure("Received exception!: " + e);
+ return;
+ }
+
+ var iframe = document.createElement("iframe");
+ iframe.setAttribute("mozbrowser", true);
+ iframe.src = "http://example.org/";
+ iframe.addEventListener("load", function() {
+ iframe.removeEventListener("load", arguments.callee);
+ if (iframe.setInputMethodActive &&
+ typeof iframe.setInputMethodActive == "function") {
+ success("Got setInputMethodActive");
+ } else {
+ failure("Didn't get setInputMethodActive") ;
+ }
+ });
+
+ document.getElementById('content').appendChild(iframe);
+}
+
+var gData = [
+ {
+ perm: ["input-manage", "browser"],
+ needParentPerm: true,
+ obj: "mozInputMethod",
+ webidl: "MozInputMethod",
+ settings: [["dom.mozInputMethod.enabled", true],
+ ["dom.mozBrowserFramesEnabled", true],
+ ["network.disable.ipc.security", true]],
+ verifier: verifier.toSource()
+ }
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_keyboard.html b/dom/permission/tests/test_keyboard.html
new file mode 100644
index 000000000..f7916afc6
--- /dev/null
+++ b/dom/permission/tests/test_keyboard.html
@@ -0,0 +1,51 @@
+-<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=920977
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 920977 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=920977">Mozilla Bug 920977 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+function verifier(success, failure) {
+ try {
+ if (!this.getObj()) {
+ failure("Did not receive proper object");
+ return;
+ }
+ } catch (e) {
+ failure("Received exception!: " + e);
+ return;
+ }
+
+ try {
+ this.getObj().removeFocus();
+ failure("Should receive exception when accessing system only method.!");
+ } catch (e) {
+ success(this.perm);
+ }
+}
+
+var gData = [
+ {
+ perm: ["input"],
+ obj: "mozInputMethod",
+ webidl: "MozInputMethod",
+ settings: [["dom.mozInputMethod.enabled", true]],
+ verifier: verifier.toSource()
+ }
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_networkstats-manage.html b/dom/permission/tests/test_networkstats-manage.html
new file mode 100644
index 000000000..4fdc84771
--- /dev/null
+++ b/dom/permission/tests/test_networkstats-manage.html
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=815105
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 815105 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=815105">Mozilla Bug 815105 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+var gData = [
+ {
+ perm: ["networkstats-manage"],
+ obj: "mozNetworkStats",
+ webidl: "MozNetworkStatsManager",
+ settings: [["dom.mozNetworkStats.enabled", true]],
+ },
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_permissions.html b/dom/permission/tests/test_permissions.html
new file mode 100644
index 000000000..8d629c3da
--- /dev/null
+++ b/dom/permission/tests/test_permissions.html
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=815105
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 815105 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=815105">Mozilla Bug 815105 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+var gData = [
+ {
+ perm: ["permissions"],
+ obj: "mozPermissionSettings",
+ webidl: "PermissionSettings",
+ settings: [["dom.mozPermissionSettings.enabled", true]],
+ },
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_permissions_api.html b/dom/permission/tests/test_permissions_api.html
new file mode 100644
index 000000000..ded74753c
--- /dev/null
+++ b/dom/permission/tests/test_permissions_api.html
@@ -0,0 +1,206 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+
+<head>
+ <meta charset="utf-8">
+ <title>Test for Permissions API</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" href="/tests/SimpleTest/test.css">
+</head>
+
+<body>
+ <pre id="test"></pre>
+ <script type="application/javascript;version=1.8">
+ /*globals SpecialPowers, SimpleTest, is, ok, */
+ 'use strict';
+
+ const {
+ UNKNOWN_ACTION,
+ PROMPT_ACTION,
+ ALLOW_ACTION,
+ DENY_ACTION
+ } = SpecialPowers.Ci.nsIPermissionManager;
+
+ SimpleTest.waitForExplicitFinish();
+
+ const PERMISSIONS = [{
+ name: 'geolocation',
+ type: 'geo'
+ }, {
+ name: 'notifications',
+ type: 'desktop-notification'
+ }, {
+ name: 'push',
+ type: 'desktop-notification'
+ }, ];
+
+ const UNSUPPORTED_PERMISSIONS = [
+ 'foobarbaz', // Not in spec, for testing only.
+ 'midi',
+ ];
+
+ // Create a closure, so that tests are run on the correct window object.
+ function createPermissionTester(aWindow) {
+ return {
+ setPermissions(allow) {
+ const permissions = PERMISSIONS.map(({ type }) => {
+ return {
+ type,
+ allow,
+ 'context': aWindow.document
+ };
+ });
+ return new Promise((resolve) => {
+ SpecialPowers.popPermissions(() => {
+ SpecialPowers.pushPermissions(permissions, resolve);
+ });
+ });
+ },
+ revokePermissions() {
+ const promisesToRevoke = PERMISSIONS.map(({ name }) => {
+ return aWindow.navigator.permissions
+ .revoke({ name })
+ .then(
+ ({ state }) => is(state, 'prompt', `correct state for '${name}'`),
+ () => ok(false, `revoke should not have rejected for '${name}'`)
+ );
+ });
+ return Promise.all(promisesToRevoke);
+ },
+ revokeUnsupportedPermissions() {
+ const promisesToRevoke = UNSUPPORTED_PERMISSIONS.map(({ name }) => {
+ return aWindow.navigator.permissions
+ .revoke({ name })
+ .then(
+ () => ok(false, `revoke should not have resolved for '${name}'`),
+ error => is(error.name, 'TypeError', `revoke should have thrown TypeError for '${name}'`)
+ );
+ });
+ return Promise.all(promisesToRevoke);
+ },
+ checkPermissions(state) {
+ const promisesToQuery = PERMISSIONS.map(({ name }) => {
+ return aWindow.navigator.permissions
+ .query({ name })
+ .then(
+ () => is(state, state, `correct state for '${name}'`),
+ () => ok(false, `query should not have rejected for '${name}'`)
+ );
+ });
+ return Promise.all(promisesToQuery);
+ },
+ checkUnsupportedPermissions() {
+ const promisesToQuery = UNSUPPORTED_PERMISSIONS.map(({ name }) => {
+ return aWindow.navigator.permissions
+ .query({ name })
+ .then(
+ () => ok(false, `query should not have resolved for '${name}'`),
+ error => {
+ is(error.name, 'TypeError',
+ `query should have thrown TypeError for '${name}'`);
+ }
+ );
+ });
+ return Promise.all(promisesToQuery);
+ },
+ promiseStateChanged(name, state) {
+ return aWindow.navigator.permissions
+ .query({ name })
+ .then(status => {
+ return new Promise( resolve => {
+ status.onchange = () => {
+ status.onchange = null;
+ is(status.state, state, `state changed for '${name}'`);
+ resolve();
+ };
+ });
+ },
+ () => ok(false, `query should not have rejected for '${name}'`));
+ },
+ testStatusOnChange() {
+ return new Promise((resolve) => {
+ SpecialPowers.popPermissions(() => {
+ const permission = 'geolocation';
+ const promiseGranted = this.promiseStateChanged(permission, 'granted');
+ this.setPermissions(ALLOW_ACTION);
+ promiseGranted.then(() => {
+ const promisePrompt = this.promiseStateChanged(permission, 'prompt');
+ SpecialPowers.popPermissions();
+ return promisePrompt;
+ }).then(resolve);
+ });
+ });
+ },
+ testInvalidQuery() {
+ return aWindow.navigator.permissions
+ .query({ name: 'invalid' })
+ .then(
+ () => ok(false, 'invalid query should not have resolved'),
+ () => ok(true, 'invalid query should have rejected')
+ );
+ },
+ testInvalidRevoke() {
+ return aWindow.navigator.permissions
+ .revoke({ name: 'invalid' })
+ .then(
+ () => ok(false, 'invalid revoke should not have resolved'),
+ () => ok(true, 'invalid revoke should have rejected')
+ );
+ },
+ };
+ }
+
+ function enablePrefs() {
+ const ops = {
+ 'set': [
+ ['dom.permissions.revoke.enable', true],
+ ],
+ };
+ return SpecialPowers.pushPrefEnv(ops);
+ }
+
+ function createIframe() {
+ return new Promise((resolve) => {
+ const iframe = document.createElement('iframe');
+ iframe.src = 'file_empty.html';
+ iframe.onload = () => resolve(iframe.contentWindow);
+ document.body.appendChild(iframe);
+ });
+ }
+ debugger;
+ window.onload = () => {
+ enablePrefs()
+ .then(createIframe)
+ .then(createPermissionTester)
+ .then((tester) => {
+ return tester
+ .checkUnsupportedPermissions()
+ .then(() => tester.setPermissions(UNKNOWN_ACTION))
+ .then(() => tester.checkPermissions('prompt'))
+ .then(() => tester.setPermissions(PROMPT_ACTION))
+ .then(() => tester.checkPermissions('prompt'))
+ .then(() => tester.setPermissions(ALLOW_ACTION))
+ .then(() => tester.checkPermissions('granted'))
+ .then(() => tester.setPermissions(DENY_ACTION))
+ .then(() => tester.checkPermissions('denied'))
+ .then(() => tester.testStatusOnChange())
+ .then(() => tester.testInvalidQuery())
+ .then(() => tester.revokeUnsupportedPermissions())
+ .then(() => tester.revokePermissions())
+ .then(() => tester.checkPermissions('prompt'))
+ .then(() => tester.testInvalidRevoke());
+ })
+ .then(SimpleTest.finish)
+ .catch((e) => {
+ ok(false, `Unexpected error ${e}`);
+ SimpleTest.finish();
+ });
+ };
+ </script>
+</body>
+
+</html>
diff --git a/dom/permission/tests/test_power.html b/dom/permission/tests/test_power.html
new file mode 100644
index 000000000..51c2e8b53
--- /dev/null
+++ b/dom/permission/tests/test_power.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=815105
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 815105 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=815105">Mozilla Bug 815105 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+var gData = [
+ {
+ perm: ["power"],
+ obj: "mozPower",
+ webidl: "MozPowerManager",
+ },
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_presentation-device-manage.html b/dom/permission/tests/test_presentation-device-manage.html
new file mode 100644
index 000000000..67904030a
--- /dev/null
+++ b/dom/permission/tests/test_presentation-device-manage.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1080474
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for presentation-device-manage permission</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=1080474">test presentation-device-manage</a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+function verifier(success, failure) {
+ if (window.navigator.mozPresentationDeviceInfo) {
+ success("Got mozPresentationDeviceInfo object!");
+ } else {
+ failure("Failed to get mozPresentationDeviceInfo object!");
+ }
+}
+var gData = [
+ {
+ perm: ["presentation-device-manage"],
+ settings: [["dom.presentation.enabled", true]],
+ obj: "mozPresentationDeviceInfo",
+ webidl: "PresentationDeviceInfoManager"
+ }
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_systemXHR.html b/dom/permission/tests/test_systemXHR.html
new file mode 100644
index 000000000..dd16fddfa
--- /dev/null
+++ b/dom/permission/tests/test_systemXHR.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=815105
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 815105 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=815105">Mozilla Bug 815105 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+function verifier(success, failure) {
+ var xhr = new XMLHttpRequest({mozSystem: true});
+ if (xhr.mozSystem === true) {
+ success("systemXHR");
+ } else {
+ failure("Couldn't create systemXHR");
+ }
+}
+
+var gData = [
+ {
+ perm: ["systemXHR"],
+ verifier: verifier.toSource(),
+ }
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_tcp-socket.html b/dom/permission/tests/test_tcp-socket.html
new file mode 100644
index 000000000..5a80cff85
--- /dev/null
+++ b/dom/permission/tests/test_tcp-socket.html
@@ -0,0 +1,52 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=815105
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 815105 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=815105">Mozilla Bug 815105 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+/* mozTCPSocket only returns null on window init
+ * if the permission isn't set
+ */
+function verifier(success, failure) {
+ try {
+ var conn = navigator.mozTCPSocket.open("http://mochi.test/", 80);
+
+ if (conn) {
+ if (conn instanceof window.TCPSocket) {
+ success("Opened connection");
+ } else {
+ failure("connection didn't match interface");
+ }
+ } else {
+ failure("failed to open connection");
+ }
+ } catch (e) {
+ failure("Got an exception " + e);
+ }
+}
+
+var gData = [
+ {
+ perm: ["tcp-socket"],
+ needParentPerm: true,
+ settings: [["dom.mozTCPSocket.enabled", true]],
+ verifier: verifier.toSource(),
+ }
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_time.html b/dom/permission/tests/test_time.html
new file mode 100644
index 000000000..d7fea7031
--- /dev/null
+++ b/dom/permission/tests/test_time.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=815105
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 815105 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=815105">Mozilla Bug 815105 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+var gData = [
+ {
+ perm: ["time"],
+ obj: "mozTime",
+ webidl: "MozTimeManager",
+ },
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_udp-socket.html b/dom/permission/tests/test_udp-socket.html
new file mode 100644
index 000000000..566e7a876
--- /dev/null
+++ b/dom/permission/tests/test_udp-socket.html
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=745283
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 745283 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=745283">Mozilla Bug 745283 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+function verifier(success, failure) {
+ try {
+ var socket = new UDPSocket();
+
+ if (socket) {
+ success("Opened socket");
+ } else {
+ failure("failed to open socket");
+ }
+ } catch (e) {
+ failure("Got an exception " + e);
+ }
+}
+
+var gData = [
+ {
+ perm: ["udp-socket"],
+ needParentPerm: true,
+ obj: "UDPSocket",
+ webidl: "UDPSocket",
+ settings: [["dom.udpsocket.enabled", true]],
+ verifier: verifier.toSource(),
+ }
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/test_wifi-manage.html b/dom/permission/tests/test_wifi-manage.html
new file mode 100644
index 000000000..94d17b682
--- /dev/null
+++ b/dom/permission/tests/test_wifi-manage.html
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=815105
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 815105 </title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=815105">Mozilla Bug 815105 </a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript;version=1.8" src="file_framework.js"></script>
+<script type="application/javascript;version=1.8">
+function verifier(success, failure) {
+ try {
+ this.getObj().enabled;
+ success("Got wifi");
+ } catch (e) {
+ failure("Got an exception " + e);
+ }
+}
+
+var gData = [
+ {
+ perm: ["wifi-manage"],
+ needParentPerm: true,
+ obj: "mozWifiManager",
+ webidl: "MozWifiManager",
+ verifier: verifier.toSource(),
+ },
+]
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/permission/tests/unit/test_bug808734.js b/dom/permission/tests/unit/test_bug808734.js
new file mode 100644
index 000000000..8dfbd9458
--- /dev/null
+++ b/dom/permission/tests/unit/test_bug808734.js
@@ -0,0 +1,73 @@
+var Cu = Components.utils;
+const READWRITE = "readwrite";
+const UNKNOWN = "foobar";
+
+var gData = [
+// test normal expansion
+{
+ permission: "contacts",
+ access: READWRITE,
+ expected: ["contacts-read", "contacts-create",
+ "contacts-write"]
+},
+// test additional expansion and access not having read+create+write
+{
+ permission: "settings",
+ access: READWRITE,
+ expected: ["settings-read", "settings-write",
+ "settings-api-read", "settings-api-write",
+ "indexedDB-chrome-settings-read",
+ "indexedDB-chrome-settings-write"]
+},
+// test unknown access
+{
+ permission: "contacts",
+ access: UNKNOWN,
+ expected: []
+},
+// test unknown permission
+{
+ permission: UNKNOWN,
+ access: READWRITE,
+ expected: []
+}
+];
+
+// check if 2 arrays contain the same elements
+function do_check_set_eq(a1, a2) {
+ do_check_eq(a1.length, a2.length)
+
+ Array.sort(a1);
+ Array.sort(a2);
+
+ for (let i = 0; i < a1.length; ++i) {
+ do_check_eq(a1[i], a2[i])
+ }
+}
+
+function test_substitute_does_not_break_substituted(scope) {
+ const Ci = Components.interfaces;
+
+ // geolocation-noprompt substitutes for geolocation ...
+ do_check_eq(scope.PermissionsTable["geolocation-noprompt"].substitute[0],
+ "geolocation");
+ // ... and sets silent allow ...
+ do_check_eq(scope.PermissionsTable["geolocation-noprompt"].certified,
+ Ci.nsIPermissionManager.ALLOW_ACTION)
+ // ... which works ...
+ do_check_false(scope.isExplicitInPermissionsTable("geolocation-noprompt", Ci.nsIPrincipal.APP_STATUS_CERTIFIED));
+ // ... but does not interfere with geolocation's PROMPT value
+ do_check_true(scope.isExplicitInPermissionsTable("geolocation", Ci.nsIPrincipal.APP_STATUS_CERTIFIED));
+}
+
+function run_test() {
+ var scope = {};
+ Cu.import("resource://gre/modules/PermissionsTable.jsm", scope);
+
+ for (var i = 0; i < gData.length; i++) {
+ var perms = scope.expandPermissions(gData[i].permission,
+ gData[i].access);
+ do_check_set_eq(perms, gData[i].expected);
+ }
+ test_substitute_does_not_break_substituted(scope);
+}
diff --git a/dom/permission/tests/unit/xpcshell.ini b/dom/permission/tests/unit/xpcshell.ini
new file mode 100644
index 000000000..1c296a77c
--- /dev/null
+++ b/dom/permission/tests/unit/xpcshell.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+head =
+tail =
+
+[test_bug808734.js]