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