Resource Load Statistics: Make it possible exclude localhost from classification
[WebKit-https.git] / LayoutTests / http / tests / resourceLoadStatistics / non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4     <script src="/js-test-resources/js-test.js"></script>
5     <script src="resources/util.js"></script>
6     <script>
7         description("Tests that redirects for a non-sandboxed iframe get counted properly.");
8         jsTestIsAsync = true;
9         window.addEventListener("message", receiveMessage, false);
10
11         function finishTest() {
12             setEnableFeature(false, finishJSTest);
13         }
14
15         var lastPageInRedirectChainLoaded = false;
16         var statsChecked = false;
17
18         function receiveMessage(event) {
19             if (event.origin === "http://127.0.0.1:8000") {
20                 if (event.data.indexOf("PASS") === -1)
21                     testFailed(event.data.replace("FAIL ", ""));
22             } else
23                 testFailed("Received a message from an unexpected origin: " + event.origin);
24
25             lastPageInRedirectChainLoaded = true;
26             if (statsChecked)
27                 finishTest();
28             else
29                 testRunner.statisticsNotifyObserver();
30         }
31
32         function checkStats() {
33             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
34             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
35             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
36
37             statsChecked = true;
38             if (lastPageInRedirectChainLoaded)
39                 finishTest();
40         }
41
42         if (testRunner) {
43             setEnableFeature(true, function() {
44                 testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
45             });
46         }
47     </script>
48 </head>
49 <body>
50 <iframe src="http://127.0.0.1:8000/resourceLoadStatistics/resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/redirect.php/?redirectTo=http://127.0.0.1:8000/resourceLoadStatistics/resources/iframe-report-back-loaded.html">
51 </iframe>
52 </body>
53 </html>