summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/dom-level0/test_background_loading_iframes.html
blob: 62488557ece3b7f4b82b632282a0239ea913d444 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for background loading iframes</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<pre id="test">

<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();

var myLoadTime;
var receivedPostMessage = [];

window.addEventListener('message', function(event) {
  receivedPostMessage.push(parseInt(event.data));
  if (receivedPostMessage.length == 3) {
    if (!myLoadTime){
      ok(false, "Child iframes are loaded earlier than the parent document");
    } else {
      receivedPostMessage.forEach(function(iframeLoadTime, index) {
        ok(iframeLoadTime, "Iframe load time should not be null");
        ok(iframeLoadTime >= myLoadTime, "Parent document should be loaded earlier than child iframes");
      })
    }
    SimpleTest.finish();
  }
})

window.onload = function() {
  myLoadTime = performance.now();
}

SpecialPowers.pushPrefEnv({"set":[["dom.background_loading_iframe", true]]}).then(async function () {
  await SpecialPowers.promiseTimeout(0);

  var iframe1 = document.createElement("iframe");
  var iframe2 = document.createElement("iframe");
  var iframe3 = document.createElement("iframe");

  iframe1.src = "http://example.org:80/tests/dom/tests/mochitest/dom-level0/file_test_background_loading_iframes.html";
  iframe2.src = "http://example.org:80/tests/dom/tests/mochitest/dom-level0/file_test_background_loading_iframes.html";
  iframe3.src = "http://example.org:80/tests/dom/tests/mochitest/dom-level0/file_test_background_loading_iframes.html";

  iframe1.onload = function() {
    iframe1.contentWindow.postMessage("test", "*");
  }

  iframe2.onload = function() {
    iframe2.contentWindow.postMessage("test", "*");
  }

  iframe3.onload = function() {
    iframe3.contentWindow.postMessage("test", "*");
  }

  document.body.append(iframe1);
  document.body.append(iframe2);
  document.body.append(iframe3);

});

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