summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/focus/support/focus-next-tick-before-iframe-loaded-same-site-outer.html
blob: a68d34039db5dd07b656f49ababe7ae4c45613e3 (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
<!DOCTYPE html>
<html>
<head>
<title>focus() from next tick before iframe loaded same site</title>
</head>
<body>
<script>
var pendingTimeout = false;
window.onmessage = function(e) {
    if (e.data == "tick") {
        iframe.focus();
        if (document.activeElement != iframe) {
            if (pendingTimeout) {
                clearTimeout(pendingTimeout);
            }
            pendingTimeout = true;
            opener.postMessage("FAIL activeElement", "*");
        }
        return;
    }

    if (e.data == "onload") {
        if (pendingTimeout) {
            return;
        }
        pendingTimeout = opener.step_timeout(function() {
            opener.postMessage("FAIL missing onfocus", "*");
        }, 2000);
        return;
    }
    if (pendingTimeout) {
        clearTimeout(pendingTimeout);
    }
    pendingTimeout = true;
    if (e.data == "onfocus") {
        // Test not upstreamed, because this even is a Firefoxism
        // https://github.com/whatwg/html/issues/6209
        opener.postMessage("PASS", "*");
        return;
    }
    opener.postMessage("FAIL " + e.data, "*");
}

var iframe = document.createElement("iframe");
iframe.src = "focus-next-tick-before-iframe-loaded-same-site-inner.html";
document.body.appendChild(iframe);
window.postMessage("tick", "*");
</script>
</body>
</html>