summaryrefslogtreecommitdiffstats
path: root/dom/power/tests/test_wakelock_on_initial_about_blank.html
blob: eefa6c6fb74638144a4d5cdd3ffdd715132f4d0f (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test requesting lock on the initial about:blank</title>
  <link rel="help" href="https://bugzilla.mozilla.org/1882344"/>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
  <script>

    add_task(async function test() {
      const iframe = document.createElement('iframe');
      iframe.src = "file_empty.html";
      document.documentElement.appendChild(iframe);

      // https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-window-object:initialise-the-document-object
      is(iframe.contentWindow.location.href, "about:blank", "Initial about:blank is loaded");

      let lock;
      try {
        // request lock on initial about:blank
        lock = await iframe.contentWindow.navigator.wakeLock.request();
      } catch (err) {
        // This could happen if the initial about:blank document is inactive
        // once the async code in .request runs.
        ok(true, "request was rejected");
        return;
      }

      if (iframe.contentWindow.location.href == "about:blank") {
        await new Promise((res, _rej) => { iframe.onload = res; });
      }
      isnot(iframe.contentWindow.location.href, "about:blank", "Target document is loaded");

      is(lock.released, true, "lock was released by load of target doc");

      // window and wakeLock object stayed the same, but document changed
      await iframe.contentWindow.navigator.wakeLock.request();
      ok(true, "Was able to request lock on target document");
    });

  </script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>