summaryrefslogtreecommitdiffstats
path: root/dom/system/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/system/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/system/tests')
-rw-r--r--dom/system/tests/chrome.ini4
-rw-r--r--dom/system/tests/file_bug1197901.html16
-rw-r--r--dom/system/tests/marionette/manifest.ini5
-rw-r--r--dom/system/tests/marionette/test_proximity_change.js83
-rw-r--r--dom/system/tests/marionette/test_proximity_init.js70
-rw-r--r--dom/system/tests/mochitest.ini8
-rw-r--r--dom/system/tests/preload-SystemUpdateManager-jsm.js80
-rw-r--r--dom/system/tests/test_bug1197901.html96
-rw-r--r--dom/system/tests/test_constants.xul141
-rw-r--r--dom/system/tests/test_system_update_enabled.html175
-rw-r--r--dom/system/tests/worker_constants.js82
11 files changed, 760 insertions, 0 deletions
diff --git a/dom/system/tests/chrome.ini b/dom/system/tests/chrome.ini
new file mode 100644
index 000000000..79441b157
--- /dev/null
+++ b/dom/system/tests/chrome.ini
@@ -0,0 +1,4 @@
+[DEFAULT]
+support-files = worker_constants.js
+
+[test_constants.xul]
diff --git a/dom/system/tests/file_bug1197901.html b/dom/system/tests/file_bug1197901.html
new file mode 100644
index 000000000..44e63c3c1
--- /dev/null
+++ b/dom/system/tests/file_bug1197901.html
@@ -0,0 +1,16 @@
+<pre>Sensor events testing</pre>
+<script>
+
+window.onmessage = function (event) {
+ if (event.data.command == "addEventListener") {
+ window.addEventListener(
+ "devicemotion", function() {
+ event.source.postMessage({ result: event.data.expected,
+ message: event.data.message },
+ "*");
+ }
+ );
+ }
+}
+
+</script>
diff --git a/dom/system/tests/marionette/manifest.ini b/dom/system/tests/marionette/manifest.ini
new file mode 100644
index 000000000..a8458c450
--- /dev/null
+++ b/dom/system/tests/marionette/manifest.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+run-if = buildapp == 'b2g'
+
+[test_proximity_init.js]
+[test_proximity_change.js]
diff --git a/dom/system/tests/marionette/test_proximity_change.js b/dom/system/tests/marionette/test_proximity_change.js
new file mode 100644
index 000000000..a4c54f12b
--- /dev/null
+++ b/dom/system/tests/marionette/test_proximity_change.js
@@ -0,0 +1,83 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 10000;
+
+var receivedEvent = false;
+var expectedEvent;
+
+function enableProximityListener() {
+ // Setup device proximity event listener, expect defaults
+ log("Enabling 'deviceproximity' event listener.");
+
+ // Bug 814043: Device proximity event 'min' and 'max' attributes incorrect
+ // Until that is fixed, expect 1:0:1 instead of 1:0:0
+ // expectedEvent = new DeviceProximityEvent("deviceproximity",
+ // {value:1, min:0, max:0});
+ expectedEvent = new DeviceProximityEvent("deviceproximity",
+ {value:1, min:0, max:1});
+
+ window.addEventListener('deviceproximity', listener);
+ log("Waiting for device proximity event.");
+ waitFor(changeProximity, function() {
+ return(receivedEvent);
+ });
+}
+
+function listener(event) {
+ // Received proximity update
+ log("Received 'deviceproximity' event via listener (value:"
+ + event.value + " min:" + event.min + " max:" + event.max + ").");
+ // Verify event values are as expected
+ is(event.value, expectedEvent.value, "value");
+ is(event.min, expectedEvent.min, "min");
+ is(event.max, expectedEvent.max, "max");
+ receivedEvent = true;
+}
+
+function changeProximity() {
+ // Change emulator's proximity and verify event attributes
+ let newValue = "7:3:15";
+
+ // Bug 814043: Device proximity event 'min' and 'max' attributes won't change
+ // Until fixed, expect proximity event min to be '0' and max to be '1' always
+ // expectedEvent = new DeviceProximityEvent("deviceproximity",
+ // {value: 7, min: 3, max: 15});
+ expectedEvent = new DeviceProximityEvent("deviceproximity",
+ {value:7, min:0, max:1});
+
+ // Setup handler and verify 'ondeviceproximity' event
+ window.ondeviceproximity = function(event) {
+ log("Received 'ondeviceproximity' event via handler (value:"
+ + event.value + " min:" + event.min + " max:"
+ + event.max + ").");
+ is(event.value, expectedEvent.value, "value");
+ is(event.min, expectedEvent.min, "min");
+ is(event.max, expectedEvent.max, "max");
+ // Turn off event handler and listener
+ window.ondeviceproximity = null;
+ window.removeEventListener('deviceproximity', listener);
+ restoreProximity();
+ };
+
+ log("Sending emulator command to fake proximity change (" + newValue + ").");
+ runEmulatorCmd("sensor set proximity " + newValue, function(result) {
+ log("Emulator callback.");
+ });
+}
+
+function restoreProximity() {
+ // Set the emulator's proximity value back to original
+ newValue = "1:0:0";
+ log("Sending emulator command to restore proximity (" + newValue + ").");
+ runEmulatorCmd("sensor set proximity " + newValue, function(result) {
+ cleanUp();
+ });
+}
+
+function cleanUp() {
+ finish();
+}
+
+// Start the test
+enableProximityListener();
diff --git a/dom/system/tests/marionette/test_proximity_init.js b/dom/system/tests/marionette/test_proximity_init.js
new file mode 100644
index 000000000..1a56e6e46
--- /dev/null
+++ b/dom/system/tests/marionette/test_proximity_init.js
@@ -0,0 +1,70 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 10000;
+
+function testEventInit() {
+ let initValue = 7;
+ let initMin = 1;
+ let initMax = 30;
+
+ // Test DeviceProximityEvent initialization
+ log("Verifying DeviceProximityEvent constructor.");
+ let event = new DeviceProximityEvent("deviceproximity",
+ {value: initValue, min: initMin, max: initMax});
+ is(event.type, "deviceproximity", "event type");
+ is(event.value, initValue, "value");
+ is(event.min, initMin, "min");
+ is(event.max, initMax, "max");
+ if (event.value !== initValue ||
+ event.min !== initMin ||
+ event.max !== initMax) {
+ log("DeviceProximityEvent not initialized correctly.");
+ }
+
+ // Test UserProximityEvent initialization
+ log("Verifying UserProximityEvent constructor.");
+ event = new UserProximityEvent("userproximity", {near: true});
+ is(event.type, "userproximity", "event type");
+ ok(event.near, "Initialization of UserProximityEvent");
+ verifyDefaultStatus();
+}
+
+function verifyDefaultStatus() {
+ let emulatorDone = false;
+
+ // Ensure that device proximity is enabled by default
+ log("Getting sensor status from emulator.");
+
+ runEmulatorCmd("sensor status", function(result) {
+ log("Received sensor status (" + result[4] + ").");
+ is(result[4], "proximity: enabled.", "Proximity sensor enabled by default");
+ emulatorDone = true;
+ });
+
+ // Have this here so test doesn't drop out if emulator callback is slow
+ waitFor(getDefaultProximity, function() {
+ return(emulatorDone);
+ });
+}
+
+function getDefaultProximity() {
+ let expected = "1:0:0";
+
+ // Get and verify the default emulator proximity value
+ log("Getting device proximity from emulator.");
+
+ runEmulatorCmd("sensor get proximity", function(result) {
+ let values = result[0].split(" ")[2];
+ log("Received emulator proximity (" + values + ").");
+ is(values, "1:0:0", "Default proximity values");
+ cleanUp();
+ });
+}
+
+function cleanUp() {
+ finish();
+}
+
+// Start the test
+testEventInit();
diff --git a/dom/system/tests/mochitest.ini b/dom/system/tests/mochitest.ini
new file mode 100644
index 000000000..72bdf5cf6
--- /dev/null
+++ b/dom/system/tests/mochitest.ini
@@ -0,0 +1,8 @@
+[DEFAULT]
+support-files =
+ preload-SystemUpdateManager-jsm.js
+ file_bug1197901.html
+
+[test_bug1197901.html]
+[test_system_update_enabled.html]
+skip-if = true # Tests only ran on B2G
diff --git a/dom/system/tests/preload-SystemUpdateManager-jsm.js b/dom/system/tests/preload-SystemUpdateManager-jsm.js
new file mode 100644
index 000000000..005b70461
--- /dev/null
+++ b/dom/system/tests/preload-SystemUpdateManager-jsm.js
@@ -0,0 +1,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/. */
+
+'use strict';
+
+const {classes: Cc, interfaces: Ci, utils: Cu, manager: Cm} = Components;
+
+Cu.import('resource://gre/modules/XPCOMUtils.jsm');
+
+const cid = '{17a84227-28f4-453d-9b80-9ae75a5682e0}';
+const contractId = '@mozilla.org/test-update-provider;1';
+
+function TestUpdateProvider() {}
+TestUpdateProvider.prototype = {
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemUpdateProvider]),
+
+ checkForUpdate: function() {
+ dump('check for update');
+ this._listener.onUpdateAvailable('test-type', 'test-version', 'test-description', Date.now().valueOf(), 5566);
+ },
+
+ startDownload: function() {
+ dump('test start download');
+ this._listener.onProgress(10, 100);
+ },
+
+ stopDownload: function() {
+ dump('test stop download');
+ },
+
+ applyUpdate: function() {
+ dump('apply update');
+ },
+
+ setParameter: function(name, value) {
+ dump('set parameter');
+ return (name === 'dummy' && value === 'dummy-value');
+ },
+
+ getParameter: function(name) {
+ dump('get parameter');
+ if (name === 'dummy') {
+ return 'dummy-value';
+ }
+ },
+
+ setListener: function(listener) {
+ this._listener = listener;
+ },
+
+ unsetListener: function() {
+ this._listener = null;
+ },
+};
+
+var factory = {
+ createInstance: function(outer, iid) {
+ if (outer) {
+ throw Components.results.NS_ERROR_NO_AGGREGATION;
+ }
+
+ return new TestUpdateProvider().QueryInterface(iid);
+ },
+ lockFactory: function(aLock) {
+ throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+ },
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory])
+};
+
+Cm.nsIComponentRegistrar.registerFactory(Components.ID(cid), '', contractId, factory);
+
+var cm = Cc['@mozilla.org/categorymanager;1'].getService(Ci.nsICategoryManager);
+cm.addCategoryEntry('system-update-provider', 'DummyProvider',
+ contractId + ',' + cid, false, true);
+
+Cu.import('resource://gre/modules/SystemUpdateService.jsm');
+this.SystemUpdateService.addProvider('{17a84227-28f4-453d-9b80-9ae75a5682e0}',
+ '@mozilla.org/test-update-provider;1',
+ 'DummyProvider'); \ No newline at end of file
diff --git a/dom/system/tests/test_bug1197901.html b/dom/system/tests/test_bug1197901.html
new file mode 100644
index 000000000..938943b66
--- /dev/null
+++ b/dom/system/tests/test_bug1197901.html
@@ -0,0 +1,96 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1197901
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1197901</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+ <script type="application/javascript">
+
+ /** Test for Bug 1197901 **/
+ SimpleTest.requestFlakyTimeout("requestFlakyTimeout is silly");
+ SimpleTest.waitForExplicitFinish();
+ window.onload = function() {
+ SimpleTest.waitForFocus(function() {
+ SpecialPowers.pushPrefEnv({"set": [['device.sensors.test.events', true]]},
+ doTest);
+ }, window);
+ }
+
+ function doTest() {
+ window.onmessage = function(event) {
+ ok(event.data.result, event.data.message);
+ }
+
+ // Only same-origin iframe should get the events.
+ var xo = document.getElementById("cross-origin");
+ xo.contentWindow.postMessage(
+ { command: "addEventListener",
+ expected: false,
+ message: "Cross-origin iframe shouldn't get the sensor events."},
+ "*");
+
+ var so = document.getElementById("same-origin");
+ so.contentWindow.postMessage(
+ { command: "addEventListener",
+ expected: true,
+ message: "Same-origin iframe should get the sensor events." },
+ "*");
+
+ // We need a timeout here to check that something does not happen.
+ setTimeout(function() {
+ so.parentNode.removeChild(so);
+ xo.parentNode.removeChild(xo);
+ doWindowTest();
+ }, 500);
+ }
+
+ function doWindowTest() {
+ var win = window.open("file_bug1197901.html", "w1", "height=100,width=100");
+ win.onload = function() {
+ win.focus();
+ SimpleTest.waitForFocus(function() {
+ var win2 = window.open("file_bug1197901.html", "w2", "height=100,width=100,left=100");
+ win2.onload = function() {
+ win2.focus();
+ SimpleTest.waitForFocus(function() {
+ // Only focused window should get the events.
+ win.postMessage(
+ { command: "addEventListener",
+ expected: false,
+ message: "Only focused window should get the sensor events." },
+ "*");
+ win2.postMessage(
+ { command: "addEventListener",
+ expected: true,
+ message: "Focused window should get the sensor events." },
+ "*");
+ setTimeout(function() {
+ window.onmessage = null;
+ win.close();
+ win2.close();
+ SimpleTest.finish();
+ }, 500);
+ }, win2);
+ }
+ }, win);
+ }
+ }
+
+ </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+<iframe src="file_bug1197901.html" id="same-origin"></iframe>
+<iframe src="http://example.com/tests/dom/system/tests/file_bug1197901.html" id="cross-origin"></iframe>
+</body>
+</html>
diff --git a/dom/system/tests/test_constants.xul b/dom/system/tests/test_constants.xul
new file mode 100644
index 000000000..b4b1c3dc5
--- /dev/null
+++ b/dom/system/tests/test_constants.xul
@@ -0,0 +1,141 @@
+<?xml version="1.0"?>
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<window title="Testing constants on a chrome worker thread"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script type="application/javascript"
+ src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script type="application/javascript"
+ src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+ <script type="application/javascript">
+ <![CDATA[
+
+let worker;
+
+function test_xul() {
+ let lib;
+ isnot(null, OS.Constants.Path.libxul, "libxulpath is defined");
+ try {
+ lib = ctypes.open(OS.Constants.Path.libxul);
+ lib.declare("DumpJSStack", ctypes.default_abi, ctypes.void_t);
+ } catch (x) {
+ success = false;
+ ok(false, "Could not open libxul " + x);
+ }
+ if (lib) {
+ lib.close();
+ }
+ ok(true, "test_xul: opened libxul successfully");
+}
+
+// Test that OS.Constants.libc is defined
+function test_libc() {
+ isnot(null, OS.Constants.libc, "OS.Constants.libc is defined");
+ is(0001, OS.Constants.libc.S_IXOTH, "OS.Constants.libc.S_IXOTH is defined");
+ is(0002, OS.Constants.libc.S_IWOTH, "OS.Constants.libc.S_IWOTH is defined");
+ is(0007, OS.Constants.libc.S_IRWXO, "OS.Constants.libc.S_IRWXO is defined");
+ is(0010, OS.Constants.libc.S_IXGRP, "OS.Constants.libc.S_IXGRP is defined");
+ is(0020, OS.Constants.libc.S_IWGRP, "OS.Constants.libc.S_IWGRP is defined");
+ is(0040, OS.Constants.libc.S_IRGRP, "OS.Constants.libc.S_IRGRP is defined");
+ is(0070, OS.Constants.libc.S_IRWXG, "OS.Constants.libc.S_IRWXG is defined");
+ is(0100, OS.Constants.libc.S_IXUSR, "OS.Constants.libc.S_IXUSR is defined");
+ is(0200, OS.Constants.libc.S_IWUSR, "OS.Constants.libc.S_IWUSR is defined");
+ is(0400, OS.Constants.libc.S_IRUSR, "OS.Constants.libc.S_IRUSR is defined");
+ is(0700, OS.Constants.libc.S_IRWXU, "OS.Constants.libc.S_IRWXU is defined");
+}
+
+// Test that OS.Constants.Win is defined
+function test_Win() {
+ var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"]
+ .getService(Components.interfaces.nsIXULRuntime);
+ if(xulRuntime.OS == "Windows") {
+ ok("Win" in OS.Constants, "OS.Constants.Win is defined");
+ is(OS.Constants.Win.INVALID_HANDLE_VALUE, -1,
+ "OS.Constants.Win.INVALID_HANDLE_VALUE is defined and correct");
+ }
+}
+
+// Test that OS.Constants.Sys.DEBUG is set properly on main thread
+function test_debugBuildMainThread(isDebugBuild) {
+ is(isDebugBuild, !!OS.Constants.Sys.DEBUG, "OS.Constants.Sys.DEBUG is set properly on main thread");
+}
+
+// Test that OS.Constants.Sys.umask is set properly on main thread
+function test_umaskMainThread(umask) {
+ is(umask, OS.Constants.Sys.umask,
+ "OS.Constants.Sys.umask is set properly on main thread: " +
+ ("0000"+umask.toString(8)).slice(-4));
+}
+
+
+function test() {
+ ok(true, "test_constants.xul: Starting test");
+
+ // Test 1: Load libxul from main thread
+ Components.classes["@mozilla.org/net/osfileconstantsservice;1"].
+ getService(Components.interfaces.nsIOSFileConstantsService).
+ init();
+ Components.utils.import("resource://gre/modules/ctypes.jsm");
+ test_xul();
+ test_libc();
+ test_Win();
+
+ let isDebugBuild = Components.classes["@mozilla.org/xpcom/debug;1"]
+ .getService(Components.interfaces.nsIDebug2).isDebugBuild;
+ test_debugBuildMainThread(isDebugBuild);
+
+ let umask = Components.classes["@mozilla.org/system-info;1"].
+ getService(Components.interfaces.nsIPropertyBag2).
+ getProperty("umask");
+ test_umaskMainThread(umask);
+
+ // Test 2: Load libxul from chrome thread
+ worker = new ChromeWorker("worker_constants.js");
+ SimpleTest.waitForExplicitFinish();
+ ok(true, "test_constants.xul: Chrome worker created");
+ worker.onerror = function onerror(error) {
+ error.preventDefault();
+ ok(false, "error " + error);
+ }
+ worker.onmessage = function onmessage(msg) {
+ switch (msg.data.kind) {
+ case "is":
+ SimpleTest.is(msg.data.a, msg.data.b, msg.data.description);
+ return;
+ case "isnot":
+ SimpleTest.isnot(msg.data.a, msg.data.b, msg.data.description);
+ return;
+ case "ok":
+ SimpleTest.ok(msg.data.condition, msg.data.description);
+ return;
+ case "finish":
+ SimpleTest.finish();
+ return;
+ default:
+ SimpleTest.ok(false, "test_constants.xul: wrong message " + JSON.stringify(msg.data));
+ return;
+ }
+ };
+
+ // pass expected values that are unavailable off-main-thread
+ // to the worker
+ worker.postMessage({
+ isDebugBuild: isDebugBuild,
+ umask: umask
+ });
+ ok(true, "test_constants.xul: Test in progress");
+};
+]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+ <label id="test-result"/>
+</window>
diff --git a/dom/system/tests/test_system_update_enabled.html b/dom/system/tests/test_system_update_enabled.html
new file mode 100644
index 000000000..1d820d37d
--- /dev/null
+++ b/dom/system/tests/test_system_update_enabled.html
@@ -0,0 +1,175 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1037329
+-->
+<head>
+ <meta charset="utf-8">
+ <title>System Update API Test</title>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1037329">Test System Update API</a>
+<script type="application/javascript;version=1.8">
+
+'use strict';
+
+SimpleTest.waitForExplicitFinish();
+
+function setup() {
+ window.gUrl = SimpleTest.getTestFileURL('preload-SystemUpdateManager-jsm.js');
+ window.gScript = SpecialPowers.loadChromeScript(gUrl);
+ return Promise.resolve();
+}
+
+function testGetProviders() {
+ return new Promise(function(resolve, reject) {
+ navigator.updateManager.getProviders().then(function(providerInfos) {
+ info('num of providers: ' + providerInfos.length);
+ for (let providerInfo of providerInfos) {
+ info('provider info: ' + JSON.stringify(providerInfo));
+ }
+ resolve(providerInfos);
+ });
+ });
+}
+
+function testSetActiveProvider(providerInfos) {
+ return new Promise(function(resolve, reject) {
+ //Find the mock provider for our testing provider instead.
+ //Set the mock provider as active provider.
+ let targetProvider = providerInfos[0];
+ for(let provider of providerInfos) {
+ if(provider.uuid == "{17a84227-28f4-453d-9b80-9ae75a5682e0}") {
+ info('target provider uuid: ' + provider.uuid);
+ targetProvider = provider;
+ break;
+ }
+ }
+ is("{17a84227-28f4-453d-9b80-9ae75a5682e0}", targetProvider.uuid, 'get the dynamically added provider');
+ navigator.updateManager.setActiveProvider(targetProvider.uuid).then(function(activeProvider) {
+ info('active provider info: ' + JSON.stringify(activeProvider.info));
+ is(activeProvider.name, targetProvider.name, 'expected name of active provider');
+ is(activeProvider.uuid, targetProvider.uuid, 'expected uuid of active provider');
+ resolve({name : activeProvider.name, uuid : activeProvider.uuid});
+ });
+ });
+}
+
+function testGetActiveProvider(providerInfo) {
+ info('test GetActiveProvider');
+ return new Promise(function(resolve, reject) {
+ navigator.updateManager.getActiveProvider().then(function(activeProvider) {
+ is(activeProvider.name, providerInfo.name, 'expected name of active provider');
+ is(activeProvider.uuid, providerInfo.uuid, 'expected uuid of active provider');
+ resolve(activeProvider);
+ });
+ });
+}
+
+function testCheckForUpdate(provider) {
+ info('test CheckForUpdate');
+ return new Promise(function(resolve, reject) {
+ provider.addEventListener('updateavailable', function(event) {
+ ok(true, 'receive updateavailable event');
+ info('event: ' + JSON.stringify(event.detail));
+ resolve(provider);
+ });
+ provider.checkForUpdate();
+ });
+}
+
+function testStartDownload(provider) {
+ info('test StartDownload');
+ return new Promise(function(resolve, reject) {
+ provider.addEventListener('progress', function(event) {
+ ok(true, 'receive progress event');
+ is(event.loaded, 10, 'expected loaded');
+ is(event.total, 100, 'expected total');
+ resolve(provider);
+ });
+ provider.startDownload();
+ });
+}
+function testStopDownload(provider) {
+ info('test StopDownload');
+ return new Promise(function(resolve, reject) {
+ provider.stopDownload();
+ resolve(provider);
+ });
+}
+function testApplyUpdate(provider) {
+ info('test ApplyUpdate');
+ return new Promise(function(resolve, reject) {
+ provider.applyUpdate();
+ resolve(provider);
+ });
+}
+function testGetParameter(provider) {
+ info('test GetParameter');
+ return new Promise(function(resolve, reject) {
+ let dummy = provider.getParameter('dummy');
+ is(dummy, 'dummy-value', 'expected parameter');
+ resolve(provider);
+ });
+}
+function testSetParameter(provider) {
+ info('test SetParameter');
+ return new Promise(function(resolve, reject) {
+ provider.setParameter('dummy', 'dummy-value');
+ resolve();
+ });
+}
+function testSetActiveProviderError() {
+ info('test setActiveProvider error');
+ return new Promise(function(resolve, reject) {
+ navigator.updateManager.setActiveProvider('something not exsited').then(function(provider) {
+ ok(false, 'should not success');
+ resolve();
+ }, function(reason) {
+ info('error message: ' + reason);
+ ok(true, 'expected error while setActiveProvider');
+ resolve();
+ });
+ });
+}
+
+
+function runTest() {
+ ok(navigator.updateManager, 'should have navigator.updateManager');
+
+ setup()
+ .then(testGetProviders)
+ .then(testSetActiveProvider)
+ .then(testGetActiveProvider)
+ .then(testCheckForUpdate)
+ .then(testStartDownload)
+ .then(testStopDownload)
+ .then(testApplyUpdate)
+ .then(testGetParameter)
+ .then(testSetParameter)
+ .then(testSetActiveProviderError)
+ .then(function() {
+ info('test finished');
+ gScript.destroy();
+ SimpleTest.finish();
+ });
+}
+
+SpecialPowers.pushPermissions([
+ {type: 'system-update', allow: true, context: document},
+ ], function() {
+ SpecialPowers.pushPrefEnv({
+ 'set': [
+ ['dom.system_update.enabled', true],
+ ['dom.system_update.debug', true],
+ ['dom.system_update.active', '@mozilla.org/test-update-provider;1'],
+ ]
+ }, runTest);
+ }
+);
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/system/tests/worker_constants.js b/dom/system/tests/worker_constants.js
new file mode 100644
index 000000000..62d79fe54
--- /dev/null
+++ b/dom/system/tests/worker_constants.js
@@ -0,0 +1,82 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function log(text) {
+ dump("WORKER "+text+"\n");
+}
+
+function send(message) {
+ self.postMessage(message);
+}
+
+self.onmessage = function(msg) {
+ self.onmessage = function(msg) {
+ log("ignored message "+JSON.stringify(msg.data));
+ };
+ let { isDebugBuild, umask } = msg.data;
+ try {
+ test_name();
+ test_xul();
+ test_debugBuildWorkerThread(isDebugBuild);
+ test_umaskWorkerThread(umask);
+ test_bits();
+ } catch (x) {
+ log("Catching error: " + x);
+ log("Stack: " + x.stack);
+ log("Source: " + x.toSource());
+ ok(false, x.toString() + "\n" + x.stack);
+ }
+ finish();
+};
+
+function finish() {
+ send({kind: "finish"});
+}
+
+function ok(condition, description) {
+ send({kind: "ok", condition: condition, description:description});
+}
+function is(a, b, description) {
+ send({kind: "is", a: a, b:b, description:description});
+}
+function isnot(a, b, description) {
+ send({kind: "isnot", a: a, b:b, description:description});
+}
+
+// Test that OS.Constants.Sys.Name is defined
+function test_name() {
+ isnot(null, OS.Constants.Sys.Name, "OS.Constants.Sys.Name is defined");
+}
+
+// Test that OS.Constants.Sys.DEBUG is set properly in ChromeWorker thread
+function test_debugBuildWorkerThread(isDebugBuild) {
+ is(isDebugBuild, !!OS.Constants.Sys.DEBUG, "OS.Constants.Sys.DEBUG is set properly on worker thread");
+}
+
+// Test that OS.Constants.Sys.umask is set properly in ChromeWorker thread
+function test_umaskWorkerThread(umask) {
+ is(umask, OS.Constants.Sys.umask,
+ "OS.Constants.Sys.umask is set properly on worker thread: " +
+ ("0000"+umask.toString(8)).slice(-4));
+}
+
+// Test that OS.Constants.Path.libxul lets us open libxul
+function test_xul() {
+ let lib;
+ isnot(null, OS.Constants.Path.libxul, "libxul is defined");
+ try {
+ lib = ctypes.open(OS.Constants.Path.libxul);
+ lib.declare("DumpJSStack", ctypes.default_abi, ctypes.void_t);
+ } catch (x) {
+ ok(false, "test_xul: Could not open libxul: " + x);
+ }
+ if (lib) {
+ lib.close();
+ }
+ ok(true, "test_xul: opened libxul successfully");
+}
+
+// Check if the value of OS.Constants.Sys.bits is 32 or 64
+function test_bits(){
+ is(OS.Constants.Sys.bits, ctypes.int.ptr.size * 8, "OS.Constants.Sys.bits is either 32 or 64");
+}