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