summaryrefslogtreecommitdiffstats
path: root/dom/html/test/test_nestediframe.html
blob: bc3747a892b78ffabaa3bc82e92b39ebe698be73 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for same URLs nested iframes</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
  test_nestediframe body
<script>

SimpleTest.waitForExplicitFinish();

function reportState(msg) {
  if (location.href.includes("#")) {
    parent.postMessage(msg, "*");
    return;
  }

  if (msg == "OK 1") {
    ok(true, "First frame loaded");
  } else if (msg == "KO 2") {
    ok(true, "Second frame load failed");
    SimpleTest.finish();
  } else {
    ok(false, "Unknown message: " + msg);
  }
}

addEventListener("message", event => {
  reportState(event.data);
});

var recursion;
if (!location.href.includes("#")) {
  recursion = 1;
} else {
  recursion = parseInt(localStorage.recursion) + 1;
}
localStorage.recursion = "" + recursion;

var ifr = document.createElement('iframe');
ifr.src = location.href.split("#")[0] + "#" + recursion;

ifr.onload = function() {
  reportState("OK " + recursion);
}
ifr.onerror = function() {
  reportState("KO " + recursion);
}

document.body.appendChild(ifr);

</script>
</body>
</html>