dom/power/test/test_power_set_screen_enabled.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/power/test/test_power_set_screen_enabled.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,65 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <meta charset="utf-8">
     1.8 +  <title>Test Enabling/Disabling Screen with Power Management API</title>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.10 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.11 +</head>
    1.12 +<body>
    1.13 +<p id="display"></p>
    1.14 +<div id="content" style="display: none"></div>
    1.15 +<pre id="test">
    1.16 +  <script type="application/javascript">
    1.17 +
    1.18 +  "use strict";
    1.19 +
    1.20 +  function testEnableScreen() {
    1.21 +    try {
    1.22 +      navigator.mozPower.screenEnabled = true;
    1.23 +      ok(navigator.mozPower.screenEnabled === true, "Enabled screen.");
    1.24 +    } catch (e) {
    1.25 +      ok(false, "Unexpected exception trying to enable screen.");
    1.26 +    }
    1.27 +  }
    1.28 +
    1.29 +  function testDisableScreen() {
    1.30 +    try {
    1.31 +      navigator.mozPower.screenEnabled = false;
    1.32 +      ok(navigator.mozPower.screenEnabled === false, "Disabled screen.");
    1.33 +    } catch (e) {
    1.34 +      ok(false, "Unexpected exception trying to disable screen.");
    1.35 +    }
    1.36 +  }
    1.37 +
    1.38 +  function startTests() {
    1.39 +
    1.40 +    // Make sure we don't suspend
    1.41 +    navigator.mozPower.cpuSleepAllowed = false;
    1.42 +
    1.43 +    testDisableScreen();
    1.44 +    testEnableScreen();
    1.45 +
    1.46 +    SimpleTest.finish();
    1.47 +  }
    1.48 +
    1.49 +  SimpleTest.expectAssertions(0, 9);
    1.50 +  SimpleTest.waitForExplicitFinish();
    1.51 +  if (SpecialPowers.hasPermission("power", document)) {
    1.52 +    // Currently only applicable on FxOS
    1.53 +    if (navigator.userAgent.indexOf("Mobile") != -1 &&
    1.54 +        navigator.appVersion.indexOf("Android") == -1) {
    1.55 +      startTests();
    1.56 +    } else {
    1.57 +      ok(true, "mozPower on Firefox OS only.");
    1.58 +      SimpleTest.finish();
    1.59 +    }
    1.60 +  } else {
    1.61 +    // Add the permission and reload so it's propogated
    1.62 +    SpecialPowers.addPermission("power", true, document);
    1.63 +    window.location.reload();
    1.64 +  }
    1.65 +  </script>
    1.66 +</pre>
    1.67 +</body>
    1.68 +</html>

mercurial