dom/power/test/test_power_set_screen_brightness.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_brightness.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <meta charset="utf-8">
     1.8 +  <title>Test Setting Screen Brightness 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 +  // Test setting brightness to a value < 0
    1.21 +  function testInvalidBrightness1() {
    1.22 +    try {
    1.23 +      navigator.mozPower.screenBrightness = -1;
    1.24 +    } catch (e) {
    1.25 +      return ok(true, "Invalid brightness level results in exception.");
    1.26 +    }
    1.27 +    ok(false, "Exeception not thrown for invalid brightness level.");
    1.28 +  }
    1.29 +
    1.30 +  // Test setting brightness to a value > 1
    1.31 +  function testInvalidBrightness2() {
    1.32 +    try {
    1.33 +      navigator.mozPower.screenBrightness = 2;
    1.34 +    } catch (e) {
    1.35 +      return ok(true, "Invalid brightness level results in exception.");
    1.36 +    }
    1.37 +    ok(false, "Exeception not thrown for invalid brightness level.");
    1.38 +  }
    1.39 +
    1.40 +  function testSettingBrightness() {
    1.41 +    var newBright = 0.312;
    1.42 +    navigator.mozPower.screenBrightness = newBright;
    1.43 +    ok(fuzzyEq(newBright, navigator.mozPower.screenBrightness),
    1.44 +       "Set new brightness value.");
    1.45 +  }
    1.46 +
    1.47 +  function startTests() {
    1.48 +    testInvalidBrightness1();
    1.49 +    testInvalidBrightness2();
    1.50 +    testSettingBrightness();
    1.51 +
    1.52 +    SimpleTest.finish();
    1.53 +  }
    1.54 +
    1.55 +  function fuzzyEq(a, b) {
    1.56 +    var epsilon = 0.002;
    1.57 +    return Math.abs(a - b) < epsilon;
    1.58 +  }
    1.59 +
    1.60 +  SimpleTest.expectAssertions(0, 9);
    1.61 +  SimpleTest.waitForExplicitFinish();
    1.62 +  if (SpecialPowers.hasPermission("power", document)) {
    1.63 +    // Currently only applicable on FxOS
    1.64 +    if (navigator.userAgent.indexOf("Mobile") != -1 &&
    1.65 +        navigator.appVersion.indexOf("Android") == -1) {
    1.66 +      startTests();
    1.67 +    } else {
    1.68 +      ok(true, "mozPower on Firefox OS only.");
    1.69 +      SimpleTest.finish();
    1.70 +    }
    1.71 +  } else {
    1.72 +    // Add the permission and reload so it's propogated
    1.73 +    SpecialPowers.addPermission("power", true, document);
    1.74 +    window.location.reload();
    1.75 +  }
    1.76 +  </script>
    1.77 +</pre>
    1.78 +</body>
    1.79 +</html>

mercurial