summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/pointer-lock/locked-element-removed-from-dom.html
blob: e2ef0dd9c4cfc3e48f824d1e13bbcfb589410375 (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
<!DOCTYPE HTML>
<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="../http/tests/resources/pointer-lock/pointer-lock-test-harness.js"></script>
</head>
<body>
<div>
  <iframe id="iframe1"></iframe>
  <div id="target2"></div>
</div>
<script>
    description("Test removing a locked element from a document causes lock to be released.")
    window.jsTestIsAsync = true;

    targetIframe1 = document.getElementById("iframe1");
    targetDiv2 = document.getElementById("target2");

    todo = [
        function () {
            // Load a blank iframe.
            targetIframe1.src = "about:blank";
            targetIframe1.onload = function () { doNextStepWithUserGesture(); }
        },
        function () {
            // Nest target element into iframe document.
            targetIframe1.contentDocument.body.innerHTML ="<div><div></div></div>";
            targetDiv1 = targetIframe1.contentDocument.body.firstChild.firstChild
            expectNoEvents("Lock target in iframe. (main document handler).");
            expectOnlyChangeEvent("Lock target in iframe. (iframe handler)", targetIframe1.contentDocument);
            targetDiv1.requestPointerLock();
            // doNextStep called by event handler.
        },
        function () {
            shouldBe("targetIframe1.contentDocument.pointerLockElement", "targetDiv1");
            shouldBe("targetDiv1.parentElement.parentElement", "targetIframe1.contentDocument.body");
            expectOnlyErrorEvent("Remove targetDiv1's parent from iframe & immediately lock target2. (main document handler)");
            expectOnlyChangeEvent("Remove targetDiv1's parent from iframe & immediately lock target2. (iframe handler)", targetIframe1.contentDocument);
            targetDiv1.parentElement.parentElement.removeChild(targetDiv1.parentElement);
            targetDiv2.requestPointerLock();
            shouldBe("document.pointerLockElement", "null");
            shouldBe("targetDiv1.parentElement.parentElement", "null");
            // doNextStep called by event handler.
        },
        function () {
            // Absorb an extra doNextStep() from previous event handlers.
        },
    ];
    doNextStep();
</script>
</body>
</html>