summaryrefslogtreecommitdiffstats
path: root/dom/power/tests/test_dynamic_pref_change.html
blob: c6aba762463a435672b6a0cc6040ba21f37d0767 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test Screen Wake Lock responds to dynamic pref changes</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
  <script type="application/javascript">
    /* globals SpecialPowers */
    'use strict';

    function spinEventLoop() {
        return new Promise(resolve => {
            setTimeout(resolve, 0);
        });
    }

    add_task(async function my_test() {
      const lock = await navigator.wakeLock.request("screen");
      await SpecialPowers.pushPrefEnv({
        set: [["dom.screenwakelock.enabled", false]],
      });
      await spinEventLoop();
      ok(lock.released, "Lock was released once pref was deactivated");
      await SpecialPowers.popPrefEnv();
    });
  </script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>