summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/pointerlock/test_pointerlock_target_not_in_active_document.html
blob: 8629230b6b1943c6cb725535c4b6db627c7050b5 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Bug 1646493 - test_pointerlock_target_not_in_active_document.html</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body style="width: 100vw; height: 100vh; margin: 0;">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1646493">Mozilla Bug 1646493</a><br>
<iframe></iframe>
<script>
if (!opener) {
  SimpleTest.waitForExplicitFinish();
}

var newwin = null;
function finish() {
  newwin.close()
  setTimeout(function() {
    SimpleTest.finish();
  }, 0);
}

function testUnfocusedDocument() {
  opener.document.addEventListener("pointerlockchange", function() {
    opener.ok(false, "Check we have locked the pointer");
    opener.document.exitPointerLock();
    opener.testInactiveTopLevelDocument();
  }, {once: true});

  opener.document.addEventListener("pointerlockerror", function() {
    opener.ok(true, "Fail to lock pointer");
    opener.testInactiveTopLevelDocument();
  }, {once: true});

  SpecialPowers.wrap(opener.document).notifyUserGestureActivation();
  opener.document.body.requestPointerLock();
}

function testInactiveTopLevelDocument() {
  let iframeWin = newwin.frames[0];
  let iframeDoc = iframeWin.document;

  iframeDoc.addEventListener("pointerlockchange", function() {
    ok(false, "Check we have locked the pointer");
    iframeDoc.exitPointerLock();
    finish();
  }, {once: true});

  iframeDoc.addEventListener("pointerlockerror", function() {
    ok(true, "Fail to lock pointer");
    finish();
  }, {once: true});

  SpecialPowers.wrap(iframeDoc).notifyUserGestureActivation();

  newwin.addEventListener("pagehide", function() {
    iframeDoc.body.requestPointerLock();
  }, {once: true});
  newwin.location = "iframe_differentDOM.html";
}

addLoadEvent(async function() {
  await SimpleTest.promiseFocus();

  if (!opener) {
    newwin = window.open(location);
    return;
  }

  testUnfocusedDocument();
});
</script>
</body>
</html>