e8b7f09d5c664dd63e82d9a0c717bdb5a89f7d9a
[WebKit-https.git] / LayoutTests / http / tests / resourceLoadStatistics / strip-referrer-to-origin-for-prevalent-subresource-redirects.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4     <script src="/js-test-resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8     description("Tests that only the origin is sent as referrer in redirects to prevalent resources without user interaction.");
9     jsTestIsAsync = true;
10     testRunner.dumpChildFramesAsText();
11
12     function setEnableFeature(enable, completionHandler) {
13         internals.setResourceLoadStatisticsEnabled(enable);
14         testRunner.setCookieStoragePartitioningEnabled(enable);
15         if (!enable)
16             testRunner.statisticsResetToConsistentState(completionHandler);
17         else
18             completionHandler();
19     }
20
21     function openIframe(url, onLoadHandler) {
22         const element = document.createElement("iframe");
23         element.src = url;
24         if (onLoadHandler) {
25             element.onload = onLoadHandler;
26         }
27         document.body.appendChild(element);
28     }
29
30     var referrer;
31     setEnableFeature(true, function() {
32         if (testRunner.isStatisticsPrevalentResource("http://localhost"))
33             testFailed("Localhost was classified as prevalent resource before the test started.");
34
35         fetch("resources/echo-referrer.php").then(function(response) {
36             return response.text();
37         }).then(function(data) {
38             referrer = data;
39             shouldBeEqualToString("referrer", "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html");
40
41             testRunner.setStatisticsPrevalentResource("http://localhost", true, function() {
42                 if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
43                     testFailed("Host did not get set as prevalent resource.");
44
45                 testRunner.statisticsUpdateCookiePartitioning(function() {
46                     openIframe("resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php", function() {
47                         setEnableFeature(false, finishJSTest);
48                     });
49                 });
50             });
51         }).catch(function(error) {
52             console.log(error.message);
53             setEnableFeature(false, finishJSTest);
54         });
55     });
56 </script>
57 </body>
58 </html>