Many resourceLoadStatistics tests and storageAccess tests using the ITP
[WebKit-https.git] / LayoutTests / http / tests / resourceLoadStatistics / downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4     <script src="/js-test-resources/js-test.js"></script>
5     <script src="/cookies/resources/cookie-utilities.js"></script>
6     <script src="resources/util.js"></script>
7 </head>
8 <body onload="setTimeout('runTest()', 0)">
9 <script>
10     description("Check that document.referrer is downgraded to the eTLD+1 after a cross-site navigation with link query.");
11     jsTestIsAsync = true;
12
13     let numberOfTries = 0;
14     function testReferrer() {
15         if (document.referrer === prevalentResourceOrigin + "/") {
16             testPassed("The referrer is downgraded.");
17             setEnableFeature(false, finishJSTest);
18         } else if (++numberOfTries <= 5)
19             setTimeout(testReferrer, 200);
20         else {
21             testFailed("The referrer is not downgraded: " + document.referrer);
22             setEnableFeature(false, finishJSTest);
23         }
24     }
25
26     function navigateSameOriginToAddQuery() {
27         document.location.href = prevalentResourceOrigin + "/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database.html?link=query";
28     }
29
30     function navigateCrossOrigin() {
31         document.location.href = destinationOrigin + "/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database.html";
32     }
33
34     const destinationOrigin = "http://localhost:8000";
35     const prevalentResourceOrigin = "http://127.0.0.1:8000";
36     function runTest() {
37         if (document.location.origin === prevalentResourceOrigin && document.location.search === "") {
38             navigateSameOriginToAddQuery();
39         } else if (document.location.origin === prevalentResourceOrigin) {
40             testRunner.setUseITPDatabase(true);
41             setEnableFeature(true, function () {
42                 testRunner.setStatisticsPrevalentResource(prevalentResourceOrigin, true, function() {
43                     if (!testRunner.isStatisticsPrevalentResource(prevalentResourceOrigin))
44                         testFailed("Host did not get set as prevalent resource.");
45                     testRunner.statisticsUpdateCookieBlocking(navigateCrossOrigin);
46                 });
47             });
48         } else {
49             testReferrer();
50         }
51     }
52 </script>
53 </body>
54 </html>