Bug 854028 - New mochitests for Power API. r=kchen
authorLuqman Aden <laden@mozilla.com>
Mon, 25 Mar 2013 10:57:26 -0700
changeset 126418 d5bd0c5a4cba12823444fdfdee52cfe032b2ddcc
parent 126417 3d8fa6b4235410280a4c7afb1efeebd3077188ae
child 126419 f63ce344becaf0c34affea72553de2df313f79aa
push id25454
push userryanvm@gmail.com
push dateWed, 27 Mar 2013 15:18:59 +0000
treeherdermozilla-inbound@d5bd0c5a4cba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskchen
bugs854028
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 854028 - New mochitests for Power API. r=kchen
dom/power/test/Makefile.in
dom/power/test/browser_bug697132.js
dom/power/test/browser_wakelocks.js
dom/power/test/test_power_set_cpusleepallowed.html
dom/power/test/test_power_set_screen_brightness.html
dom/power/test/test_power_set_screen_enabled.html
--- a/dom/power/test/Makefile.in
+++ b/dom/power/test/Makefile.in
@@ -8,15 +8,18 @@ srcdir           = @srcdir@
 VPATH            = @srcdir@
 
 relativesrcdir   = @relativesrcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MOCHITEST_FILES = \
   test_power_basics.html \
+  test_power_set_cpusleepallowed.html \
+  test_power_set_screen_brightness.html \
+  test_power_set_screen_enabled.html \
   $(NULL)
 
 MOCHITEST_BROWSER_FILES = \
-  browser_bug697132.js \
+  browser_wakelocks.js \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
rename from dom/power/test/browser_bug697132.js
rename to dom/power/test/browser_wakelocks.js
new file mode 100644
--- /dev/null
+++ b/dom/power/test/test_power_set_cpusleepallowed.html
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test Enabling/Disabling CPU Sleep with Power Management API</title>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+  <script type="application/javascript">
+
+  "use strict";
+
+  function testEnableSleep() {
+    try {
+      navigator.mozPower.cpuSleepAllowed = true;
+      ok(navigator.mozPower.cpuSleepAllowed === true, "Allow entering suspend state.");
+    } catch (e) {
+      ok(false, "Unexpected exception trying to enable entering suspend state.");
+    }
+  }
+
+  function testDisableSleep() {
+    try {
+      navigator.mozPower.cpuSleepAllowed = false;
+      ok(navigator.mozPower.cpuSleepAllowed === false, "Deny entering suspend state.");
+    } catch (e) {
+      ok(false, "Unexpected exception trying to disable entering suspend state.");
+    }
+  }
+
+  function startTests() {
+    testDisableSleep();
+    testEnableSleep();
+
+    SimpleTest.finish();
+  }
+
+  SimpleTest.expectAssertions(0, 9);
+  SimpleTest.waitForExplicitFinish();
+  if (SpecialPowers.hasPermission("power", document)) {
+    // Currently only applicable on FxOS
+    if (navigator.userAgent.indexOf("Mobile") != -1 &&
+        navigator.appVersion.indexOf("Android") == -1) {
+      startTests();
+    } else {
+      ok(true, "mozPower on Firefox OS only.");
+      SimpleTest.finish();
+    }
+  } else {
+    // Add the permission and reload so it's propogated
+    SpecialPowers.addPermission("power", true, document);
+    window.location.reload();
+  }
+  </script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/power/test/test_power_set_screen_brightness.html
@@ -0,0 +1,76 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test Setting Screen Brightness with Power Management API</title>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+  <script type="application/javascript">
+
+  "use strict";
+
+  // Test setting brightness to a value < 0
+  function testInvalidBrightness1() {
+    try {
+      navigator.mozPower.screenBrightness = -1;
+    } catch (e) {
+      return ok(true, "Invalid brightness level results in exception.");
+    }
+    ok(false, "Exeception not thrown for invalid brightness level.");
+  }
+
+  // Test setting brightness to a value > 1
+  function testInvalidBrightness2() {
+    try {
+      navigator.mozPower.screenBrightness = 2;
+    } catch (e) {
+      return ok(true, "Invalid brightness level results in exception.");
+    }
+    ok(false, "Exeception not thrown for invalid brightness level.");
+  }
+
+  function testSettingBrightness() {
+    var newBright = 0.312;
+    navigator.mozPower.screenBrightness = newBright;
+    ok(fuzzyEq(newBright, navigator.mozPower.screenBrightness),
+       "Set new brightness value.");
+  }
+
+  function startTests() {
+    testInvalidBrightness1();
+    testInvalidBrightness2();
+    testSettingBrightness();
+
+    SimpleTest.finish();
+  }
+
+  function fuzzyEq(a, b) {
+    var epsilon = 0.002;
+    return Math.abs(a - b) < epsilon;
+  }
+
+  SimpleTest.expectAssertions(0, 9);
+  SimpleTest.waitForExplicitFinish();
+  if (SpecialPowers.hasPermission("power", document)) {
+    // Currently only applicable on FxOS
+    if (navigator.userAgent.indexOf("Mobile") != -1 &&
+        navigator.appVersion.indexOf("Android") == -1) {
+      startTests();
+    } else {
+      ok(true, "mozPower on Firefox OS only.");
+      SimpleTest.finish();
+    }
+  } else {
+    // Add the permission and reload so it's propogated
+    SpecialPowers.addPermission("power", true, document);
+    window.location.reload();
+  }
+  </script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/power/test/test_power_set_screen_enabled.html
@@ -0,0 +1,65 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test Enabling/Disabling Screen with Power Management API</title>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+  <script type="application/javascript">
+
+  "use strict";
+
+  function testEnableScreen() {
+    try {
+      navigator.mozPower.screenEnabled = true;
+      ok(navigator.mozPower.screenEnabled === true, "Enabled screen.");
+    } catch (e) {
+      ok(false, "Unexpected exception trying to enable screen.");
+    }
+  }
+
+  function testDisableScreen() {
+    try {
+      navigator.mozPower.screenEnabled = false;
+      ok(navigator.mozPower.screenEnabled === false, "Disabled screen.");
+    } catch (e) {
+      ok(false, "Unexpected exception trying to disable screen.");
+    }
+  }
+
+  function startTests() {
+
+    // Make sure we don't suspend
+    navigator.mozPower.cpuSleepAllowed = false;
+
+    testDisableScreen();
+    testEnableScreen();
+
+    SimpleTest.finish();
+  }
+
+  SimpleTest.expectAssertions(0, 9);
+  SimpleTest.waitForExplicitFinish();
+  if (SpecialPowers.hasPermission("power", document)) {
+    // Currently only applicable on FxOS
+    if (navigator.userAgent.indexOf("Mobile") != -1 &&
+        navigator.appVersion.indexOf("Android") == -1) {
+      startTests();
+    } else {
+      ok(true, "mozPower on Firefox OS only.");
+      SimpleTest.finish();
+    }
+  } else {
+    // Add the permission and reload so it's propogated
+    SpecialPowers.addPermission("power", true, document);
+    window.location.reload();
+  }
+  </script>
+</pre>
+</body>
+</html>