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