Many resourceLoadStatistics tests and storageAccess tests using the ITP
[WebKit-https.git] / LayoutTests / http / tests / storageAccess / has-storage-access-true-if-third-party-has-cookies-database.html
1 <!-- webkit-test-runner [ useEphemeralSession=true ] -->
2 <!DOCTYPE html>
3 <html>
4 <head>
5     <script src="/js-test-resources/js-test.js"></script>
6     <script src="/resourceLoadStatistics/resources/util.js"></script>
7     <script>
8         description("Tests that document.hasStorageAccess() returns true for a 3rd-party iframe if the 3rd-party has cookies set.");
9         jsTestIsAsync = true;
10
11         window.addEventListener("message", receiveMessage, false);
12
13         function receiveMessage(event) {
14             if (event.origin === "http://localhost:8000") {
15                 if (event.data.indexOf("PASS") !== -1)
16                     testPassed(event.data.replace("PASS ", ""));
17                 else
18                     testFailed(event.data.replace("FAIL ", ""));
19             } else
20                 testFailed("Received a message from an unexpected origin: " + event.origin);
21             setEnableFeature(false, finishJSTest);
22         }
23
24         const hostUnderTest = "localhost:8000";
25         const statisticsUrl = "http://" + hostUnderTest;
26         function runTest() {
27             if (document.location.hash !== "#firstPartyCookieSet") {
28                 setEnableFeature(false, function() {
29                     testRunner.setUseITPDatabase(true);
30                     document.location.href = statisticsUrl + "/storageAccess/resources/set-cookie.php?name=firstPartyCookie&value=value#http://127.0.0.1:8000/storageAccess/has-storage-access-true-if-third-party-has-cookies-database.html#firstPartyCookieSet";
31                 });
32             } else {
33                 let iframeElement = document.createElement("iframe");
34                 iframeElement.id = "TheIframeThatRequestsStorageAccess";
35                 iframeElement.src = "http://localhost:8000/storageAccess/resources/has-storage-access-iframe.html#policyShouldGrantAccess";
36                 document.body.appendChild(iframeElement);
37             }
38         }
39     </script>
40 </head>
41 <body onload="runTest()">
42 </body>
43 </html>