|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <meta charset="utf-8"> |
|
5 <title>Test Enabling/Disabling CPU Sleep with Power Management API</title> |
|
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
7 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
8 </head> |
|
9 <body> |
|
10 <p id="display"></p> |
|
11 <div id="content" style="display: none"></div> |
|
12 <pre id="test"> |
|
13 <script type="application/javascript"> |
|
14 |
|
15 "use strict"; |
|
16 |
|
17 function testEnableSleep() { |
|
18 try { |
|
19 navigator.mozPower.cpuSleepAllowed = true; |
|
20 ok(navigator.mozPower.cpuSleepAllowed === true, "Allow entering suspend state."); |
|
21 } catch (e) { |
|
22 ok(false, "Unexpected exception trying to enable entering suspend state."); |
|
23 } |
|
24 } |
|
25 |
|
26 function testDisableSleep() { |
|
27 try { |
|
28 navigator.mozPower.cpuSleepAllowed = false; |
|
29 ok(navigator.mozPower.cpuSleepAllowed === false, "Deny entering suspend state."); |
|
30 } catch (e) { |
|
31 ok(false, "Unexpected exception trying to disable entering suspend state."); |
|
32 } |
|
33 } |
|
34 |
|
35 function startTests() { |
|
36 testDisableSleep(); |
|
37 testEnableSleep(); |
|
38 |
|
39 SimpleTest.finish(); |
|
40 } |
|
41 |
|
42 SimpleTest.expectAssertions(0, 9); |
|
43 SimpleTest.waitForExplicitFinish(); |
|
44 if (SpecialPowers.hasPermission("power", document)) { |
|
45 // Currently only applicable on FxOS |
|
46 if (navigator.userAgent.indexOf("Mobile") != -1 && |
|
47 navigator.appVersion.indexOf("Android") == -1) { |
|
48 startTests(); |
|
49 } else { |
|
50 ok(true, "mozPower on Firefox OS only."); |
|
51 SimpleTest.finish(); |
|
52 } |
|
53 } else { |
|
54 // Add the permission and reload so it's propogated |
|
55 SpecialPowers.addPermission("power", true, document); |
|
56 window.location.reload(); |
|
57 } |
|
58 </script> |
|
59 </pre> |
|
60 </body> |
|
61 </html> |