[Curl] Fix r222147
[WebKit-https.git] / LayoutTests / http / wpt / resource-timing / rt-resources-per-frame.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Resource Timing - Entries per Frame</title>
6 <link rel="help" href="https://w3c.github.io/resource-timing/#processing-model">
7 <script src="/resources/testharness.js"></script>
8 <script src="/resources/testharnessreport.js"></script>
9 <script src="resources/rt-utilities.sub.js"></script>
10 </head>
11 <body>
12 <h1>Resource Timing: Entries per Frame</h1>
13 <div id="log"></div>
14 <iframe id="iframe1" src="resources/rt-iframe-1.html"></iframe>
15 <iframe id="iframe2" src="resources/rt-iframe-2.html"></iframe>
16 <script>
17 setup({explicit_done: true});
18
19 window.addEventListener("load", function() {
20     let mainFrameWindow = window;
21     let iframe1Window = document.getElementById("iframe1").contentWindow;
22     let iframe2Window = document.getElementById("iframe2").contentWindow;
23
24     let promises = [];
25
26     mainFrameWindow.performance.clearResourceTimings();
27     promises.push(mainFrameWindow.loadResources(3));
28
29     wait(); // Ensure a DOMHighResTimeStamp change.
30
31     iframe1Window.performance.clearResourceTimings();
32     promises.push(iframe1Window.loadResources(2));
33
34     wait(); // Ensure a DOMHighResTimeStamp change.
35
36     iframe2Window.performance.clearResourceTimings();
37     promises.push(iframe2Window.loadResources(15));
38
39     Promise.all(promises).then(function() {
40         let mainFrameEntries = mainFrameWindow.performance.getEntriesByType("resource");
41         let iframe1Entries = iframe1Window.performance.getEntriesByType("resource");
42         let iframe2Entries = iframe2Window.performance.getEntriesByType("resource");
43
44         function checkContainsURL(url, list) {
45             for (let entry of list) {
46                 if (entry.name === url)
47                     return true;
48             }
49             return false;
50         }
51
52         function assertDisjointEntries(list, otherList1, otherList2) {
53             for (let entry of list) {
54                 assert_false(checkContainsURL(entry.name, otherList1), "a resource that should have been unique was not unique across contexts");
55                 assert_false(checkContainsURL(entry.name, otherList2), "a resource that should have been unique was not unique across contexts");
56             }
57         }
58
59         test(function(t) {
60             assert_equals(mainFrameEntries.length, 3, "window should have 3 resource entries");
61             assertDisjointEntries(mainFrameEntries, iframe1Entries, iframe2Entries);
62         }, "main frame resources differ from other frames");
63
64         test(function(t) {
65             assert_equals(iframe1Entries.length, 2, "iframe1 should have 2 resource entries");
66             assertDisjointEntries(iframe1Entries, mainFrameEntries, iframe2Entries);
67         }, "iframe1 resources differ from other frames");
68
69         test(function(t) {
70             assert_equals(iframe2Entries.length, 15, "iframe2 should have 15 resource entries");
71             assertDisjointEntries(iframe2Entries, iframe1Entries, mainFrameEntries);
72         }, "iframe2 resources differ from other frames");
73
74         done();
75     });
76 });
77 </script>
78 </body>
79 </html>