Move non-upstreamed Resource Timing tests out of web-platform-tests
[WebKit-https.git] / LayoutTests / http / wpt / resource-timing / rt-shared-resource-in-frames.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Resource Timing - Shared Entry has Distinct Entry 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: Shared Entry has Distinct Entry 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     let sharedResourceURL = uniqueImageURL("shared");
26
27     mainFrameWindow.performance.clearResourceTimings();
28     promises.push(mainFrameWindow.fetch(sharedResourceURL));
29
30     wait(); // Ensure a DOMHighResTimeStamp change.
31
32     iframe1Window.performance.clearResourceTimings();
33     promises.push(iframe1Window.fetch(sharedResourceURL));
34
35     wait(); // Ensure a DOMHighResTimeStamp change.
36
37     iframe2Window.performance.clearResourceTimings();
38     promises.push(iframe2Window.fetch(sharedResourceURL));
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 assertSharedEntryIsDifferent(sharedEntry, list) {
54             for (let entry of list) {
55                 if (entry.name === sharedResourceURL) {
56                     assert_not_equals(sharedEntry.startTime, entry.startTime, "shared entry should be different between contexts");
57                     return;
58                 }
59             }
60         }
61
62         test(function(t) {
63             assert_true(checkContainsURL(sharedResourceURL, mainFrameEntries), "main frame should have an entry for the shared resource");
64             assert_equals(mainFrameEntries.length, 1, "window should have 1 resource entry");
65             assertSharedEntryIsDifferent(mainFrameEntries[0], iframe1Entries);
66             assertSharedEntryIsDifferent(mainFrameEntries[0], iframe2Entries);
67         }, "main frame has shared resource entry");
68
69         test(function(t) {
70             assert_true(checkContainsURL(sharedResourceURL, iframe1Entries), "iframe1 should have an entry for the shared resource");
71             assert_equals(iframe1Entries.length, 1, "iframe1 should have 1 resource entry");
72             assertSharedEntryIsDifferent(iframe1Entries[0], mainFrameEntries);
73             assertSharedEntryIsDifferent(iframe1Entries[0], iframe2Entries);
74         }, "iframe1 has shared resource entry");
75
76         test(function(t) {
77             assert_true(checkContainsURL(sharedResourceURL, iframe2Entries), "iframe2 should have an entry for the shared resource");
78             assert_equals(iframe2Entries.length, 1, "iframe2 should have 1 resource entry");
79             assertSharedEntryIsDifferent(iframe2Entries[0], iframe1Entries);
80             assertSharedEntryIsDifferent(iframe2Entries[0], mainFrameEntries);
81         }, "iframe2 has shared resource entry");
82
83         done();
84     });
85 });
86 </script>
87 </body>
88 </html>