summaryrefslogtreecommitdiffstats
path: root/dom/power/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 /dom/power/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 'dom/power/test')
-rw-r--r--dom/power/test/browser.ini4
-rw-r--r--dom/power/test/browser_wakelocks.js232
-rw-r--r--dom/power/test/chrome.ini1
-rw-r--r--dom/power/test/mochitest.ini3
-rw-r--r--dom/power/test/test_bug957893.html24
-rw-r--r--dom/power/test/test_bug957899.html20
-rw-r--r--dom/power/test/test_power_basics.html40
-rw-r--r--dom/power/test/test_wakelock_not_exposed.html17
8 files changed, 341 insertions, 0 deletions
diff --git a/dom/power/test/browser.ini b/dom/power/test/browser.ini
new file mode 100644
index 000000000..e8dd8c4b1
--- /dev/null
+++ b/dom/power/test/browser.ini
@@ -0,0 +1,4 @@
+[DEFAULT]
+
+[browser_wakelocks.js]
+skip-if = e10s # Bug ?????? - SpecialPowers issues ({file: "chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js" line: 759}]'[JavaScript Error: "content.window is undefined" {file: "chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js" line: 759}]' when calling method: [nsIObserver::observe]")
diff --git a/dom/power/test/browser_wakelocks.js b/dom/power/test/browser_wakelocks.js
new file mode 100644
index 000000000..5bd4de67c
--- /dev/null
+++ b/dom/power/test/browser_wakelocks.js
@@ -0,0 +1,232 @@
+/* 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";
+
+waitForExplicitFinish();
+
+var kUrlSource = "http://mochi.test:8888/";
+var kDataSource = "data:text/html,";
+
+var gOldPref;
+var gWin, gWin1, gWin2;
+var gTab, gTab1, gTab2;
+var gLock, gLock1, gLock2;
+var gCurStepIndex = -1;
+var gSteps = [
+ function basicWakeLock() {
+ gTab = gBrowser.addTab(kUrlSource);
+ gWin = gBrowser.getBrowserForTab(gTab).contentWindow;
+ let browser = gBrowser.getBrowserForTab(gTab);
+
+ browser.addEventListener("load", function onLoad(e) {
+ browser.removeEventListener("load", onLoad, true);
+ let nav = gWin.navigator;
+ let power = nav.mozPower;
+ gLock = nav.requestWakeLock("test");
+
+ ok(gLock != null,
+ "navigator.requestWakeLock should return a wake lock");
+ is(gLock.topic, "test",
+ "wake lock should remember the locked topic");
+ isnot(power.getWakeLockState("test"), "unlocked",
+ "topic is locked");
+
+ gLock.unlock();
+
+ is(gLock.topic, "test",
+ "wake lock should remember the locked topic even after unlock");
+ is(power.getWakeLockState("test"), "unlocked",
+ "topic is unlocked");
+
+ try {
+ gLock.unlock();
+ ok(false, "Should have thrown an error.");
+ } catch (e) {
+ is(e.name, "InvalidStateError", "double unlock should throw InvalidStateError");
+ is(e.code, DOMException.INVALID_STATE_ERR, "double unlock should throw InvalidStateError");
+ }
+
+ gBrowser.removeTab(gTab);
+
+ executeSoon(runNextStep);
+ }, true);
+ },
+ function multiWakeLock() {
+ gTab = gBrowser.addTab(kUrlSource);
+ gWin = gBrowser.getBrowserForTab(gTab).contentWindow;
+ let browser = gBrowser.getBrowserForTab(gTab);
+
+ browser.addEventListener("load", function onLoad(e) {
+ browser.removeEventListener("load", onLoad, true);
+ let nav = gWin.navigator;
+ let power = nav.mozPower;
+ let count = 0;
+ power.addWakeLockListener(function onWakeLockEvent(topic, state) {
+ is(topic, "test", "gLock topic is test");
+ ok(state == "unlocked" ||
+ state == "locked-foreground" ||
+ state == "locked-background",
+ "wake lock should be either locked or unlocked");
+ count++;
+ if (state == "locked-foreground" ||
+ state == "locked-background") {
+ is(count, 1,
+ "wake lock should be locked and the listener should only fire once");
+ }
+ if (state == "unlocked") {
+ is(count, 2,
+ "wake lock should be unlocked and the listener should only fire once");
+
+ ok(power.getWakeLockState("test") == "unlocked",
+ "topic is unlocked");
+ power.removeWakeLockListener(onWakeLockEvent);
+ gBrowser.removeTab(gTab);
+ executeSoon(runNextStep);
+ }
+ });
+
+ gLock1 = nav.requestWakeLock("test");
+ isnot(power.getWakeLockState("test"), "unlocked",
+ "topic is locked");
+
+ gLock2 = nav.requestWakeLock("test");
+ isnot(power.getWakeLockState("test"), "unlocked",
+ "topic is locked");
+
+ gLock1.unlock();
+ isnot(power.getWakeLockState("test"), "unlocked",
+ "topic is locked");
+
+ gLock2.unlock();
+ }, true);
+ },
+ function crossTabWakeLock1() {
+ gTab1 = gBrowser.addTab(kUrlSource);
+ gWin1 = gBrowser.getBrowserForTab(gTab1).contentWindow;
+ gTab2 = gBrowser.addTab(kUrlSource);
+ gWin2 = gBrowser.getBrowserForTab(gTab2).contentWindow;
+
+ gBrowser.selectedTab = gTab1;
+ let browser = gBrowser.getBrowserForTab(gTab2);
+
+ browser.addEventListener("load", function onLoad(e) {
+ browser.removeEventListener("load", onLoad, true);
+ gLock2 = gWin2.navigator.requestWakeLock("test");
+ is(gWin2.document.hidden, true,
+ "window is background")
+ is(gWin2.navigator.mozPower.getWakeLockState("test"), "locked-background",
+ "wake lock is background");
+ let doc2 = gWin2.document;
+ doc2.addEventListener("visibilitychange", function onVisibilityChange(e) {
+ if (!doc2.hidden) {
+ doc2.removeEventListener("visibilitychange", onVisibilityChange);
+ executeSoon(runNextStep);
+ }
+ });
+ gBrowser.selectedTab = gTab2;
+ }, true);
+ },
+ function crossTabWakeLock2() {
+ is(gWin2.document.hidden, false,
+ "window is foreground")
+ is(gWin2.navigator.mozPower.getWakeLockState("test"), "locked-foreground",
+ "wake lock is foreground");
+ gWin2.addEventListener("pagehide", function onPageHide(e) {
+ gWin2.removeEventListener("pagehide", onPageHide, true);
+ executeSoon(runNextStep);
+ }, true);
+ gWin2.addEventListener("pageshow", function onPageShow(e) {
+ gWin2.removeEventListener("pageshow", onPageShow, true);
+ executeSoon(runNextStep);
+ }, true);
+ gWin2.location = kDataSource;
+ },
+ function crossTabWakeLock3() {
+ is(gWin1.navigator.mozPower.getWakeLockState("test"), "unlocked",
+ "wake lock should auto-unlock when page is unloaded");
+ gWin2.back();
+ // runNextStep called in onPageShow
+ },
+ function crossTabWakeLock4() {
+ is(gWin1.navigator.mozPower.getWakeLockState("test"), "locked-foreground",
+ "wake lock should auto-reacquire when page is available again");
+ gBrowser.selectedTab = gTab1;
+ executeSoon(runNextStep);
+ },
+ function crossTabWakeLock5() {
+ // Test again in background tab
+ is(gWin2.document.hidden, true,
+ "window is background")
+ is(gWin2.navigator.mozPower.getWakeLockState("test"), "locked-background",
+ "wake lock is background");
+ gWin2.addEventListener("pagehide", function onPageHide(e) {
+ gWin2.removeEventListener("pagehide", onPageHide, true);
+ executeSoon(runNextStep);
+ }, true);
+ gWin2.addEventListener("pageshow", function onPageShow(e) {
+ gWin2.removeEventListener("pageshow", onPageShow, true);
+ executeSoon(runNextStep);
+ }, true);
+ gWin2.location = kDataSource;
+ },
+ function crossTabWakeLock6() {
+ is(gWin1.navigator.mozPower.getWakeLockState("test"), "unlocked",
+ "wake lock should auto-unlock when page is unloaded");
+ gWin2.back();
+ // runNextStep called in onPageShow
+ },
+ function crossTabWakeLock7() {
+ is(gWin1.navigator.mozPower.getWakeLockState("test"), "locked-background",
+ "wake lock should auto-reacquire when page is available again");
+ gLock2.unlock();
+ gBrowser.selectedTab = gTab2;
+ executeSoon(runNextStep);
+ },
+ function crossTabWakeLock8() {
+ is(gWin1.document.hidden, true,
+ "gWin1 is background");
+ is(gWin2.document.hidden, false,
+ "gWin2 is foreground");
+
+ gLock1 = gWin1.navigator.requestWakeLock("test");
+ gLock2 = gWin2.navigator.requestWakeLock("test");
+
+ is(gWin1.navigator.mozPower.getWakeLockState("test"), "locked-foreground",
+ "topic is locked-foreground when one page is foreground and one is background");
+
+ gLock2.unlock();
+
+ is(gWin1.navigator.mozPower.getWakeLockState("test"), "locked-background",
+ "topic is locked-background when all locks are background");
+
+ gLock2 = gWin2.navigator.requestWakeLock("test");
+
+ is(gWin1.navigator.mozPower.getWakeLockState("test"), "locked-foreground",
+ "topic is locked-foreground when one page is foreground and one is background");
+
+ gLock1.unlock();
+
+ is(gWin1.navigator.mozPower.getWakeLockState("test"), "locked-foreground",
+ "topic is locked-foreground");
+
+ gBrowser.removeTab(gTab1);
+ gBrowser.removeTab(gTab2);
+ executeSoon(runNextStep);
+ },
+];
+
+function runNextStep() {
+ gCurStepIndex++;
+ if (gCurStepIndex < gSteps.length) {
+ gSteps[gCurStepIndex]();
+ } else {
+ finish();
+ }
+}
+
+function test() {
+ SpecialPowers.pushPrefEnv({"set": [["dom.wakelock.enabled", true]]},
+ runNextStep);
+}
diff --git a/dom/power/test/chrome.ini b/dom/power/test/chrome.ini
new file mode 100644
index 000000000..2a88cc576
--- /dev/null
+++ b/dom/power/test/chrome.ini
@@ -0,0 +1 @@
+[test_power_basics.html]
diff --git a/dom/power/test/mochitest.ini b/dom/power/test/mochitest.ini
new file mode 100644
index 000000000..5a82b286e
--- /dev/null
+++ b/dom/power/test/mochitest.ini
@@ -0,0 +1,3 @@
+[test_bug957893.html]
+[test_bug957899.html]
+[test_wakelock_not_exposed.html]
diff --git a/dom/power/test/test_bug957893.html b/dom/power/test/test_bug957893.html
new file mode 100644
index 000000000..c8c86a36d
--- /dev/null
+++ b/dom/power/test/test_bug957893.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test bug 957893 - Crash in WakeLock</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+ <script type="application/javascript">
+ SimpleTest.waitForExplicitFinish();
+ function test() {
+ try {
+ var wl = navigator.requestWakeLock('');
+ ok(false, "RequestWakeLock throws an exception!");
+ } catch(e) {
+ ok(true, "RequestWakeLock throws an exception!");
+ }
+ info("Still alive!");
+ SimpleTest.finish();
+ }
+ SpecialPowers.pushPrefEnv({"set": [["dom.wakelock.enabled", true]]}, test);
+ </script>
+</body>
+</html>
diff --git a/dom/power/test/test_bug957899.html b/dom/power/test/test_bug957899.html
new file mode 100644
index 000000000..8d5b9a872
--- /dev/null
+++ b/dom/power/test/test_bug957899.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test bug 957899 - Crash in WakeLock</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+ <script type="application/javascript">
+ SimpleTest.waitForExplicitFinish();
+ function test() {
+ var wl = navigator.requestWakeLock('a');
+ ok(wl, "WakeLock created!");
+ ok(!(wl instanceof XPathEvaluator), "Crashing?");
+ SimpleTest.finish();
+ }
+ SpecialPowers.pushPrefEnv({"set": [["dom.wakelock.enabled", true]]}, test);
+ </script>
+</body>
+</html>
diff --git a/dom/power/test/test_power_basics.html b/dom/power/test/test_power_basics.html
new file mode 100644
index 000000000..b78c99f48
--- /dev/null
+++ b/dom/power/test/test_power_basics.html
@@ -0,0 +1,40 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Power API</title>
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+<script type="application/javascript">
+
+/** Test for Power API **/
+
+SimpleTest.waitForExplicitFinish();
+
+function startTest() {
+ doTest1();
+}
+
+function doTest1() {
+ window.frames[0].frameElement.setAttribute('onload', 'doTest3()');
+ power = window.frames[0].navigator.mozPower;
+ ok(power, "Should be able to access power manager with permission.");
+
+ window.frames[0].location.reload();
+}
+
+function doTest3() {
+ power = window.frames[0].navigator.mozPower;
+ ok(power, "Should be able to access power manager with permission.");
+ SimpleTest.finish();
+}
+</script>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<iframe onload="startTest()"></iframe>
+<pre id="test">
+</pre>
+</body>
+</html>
diff --git a/dom/power/test/test_wakelock_not_exposed.html b/dom/power/test/test_wakelock_not_exposed.html
new file mode 100644
index 000000000..1f88993b4
--- /dev/null
+++ b/dom/power/test/test_wakelock_not_exposed.html
@@ -0,0 +1,17 @@
+<!--
+ https://bugzilla.mozilla.org/show_bug.cgi?id=963366
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test navigator.requestWakeLock is not exposed to non-B2G platform</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+ <script type="application/javascript">
+ ok(navigator.requestWakeLock === undefined,
+ "navigator.requestWakeLock is not exposed to non-B2G platform");
+ </script>
+</body>
+</html>