Resource Load Statistics: Make it possible exclude localhost from classification
[WebKit-https.git] / LayoutTests / http / tests / storageAccess / request-and-grant-access-cross-origin-sandboxed-iframe-from-prevalent-domain-with-user-interaction.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4     <script src="/js-test-resources/js-test.js"></script>
5     <script src="/js-test-resources/ui-helper.js"></script>
6     <script src="/resourceLoadStatistics/resources/util.js"></script>
7     <script>
8         description("Tests that cross-origin iframe storage access is granted if the iframe is sandboxed, has the allow token, the iframe origin is a prevalent resource, the iframe origin has had recent user interaction, and the user opts in.");
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);
19             } else
20                 testFailed("Received a message from an unexpected origin: " + event.origin);
21             setEnableFeature(false, finishJSTest);
22         }
23
24         function activateElement(elementId) {
25             var element = document.getElementById(elementId);
26             var centerX = element.offsetLeft + element.offsetWidth / 2;
27             var centerY = element.offsetTop + element.offsetHeight / 2;
28             UIHelper.activateAt(centerX, centerY).then(
29                 function () {
30                     if (window.eventSender)
31                         eventSender.keyDown("escape");
32                     else {
33                         testFailed("No eventSender.");
34                         setEnableFeature(false, finishJSTest);
35                     }
36                 },
37                 function () {
38                     testFailed("Promise rejected.");
39                     setEnableFeature(false, finishJSTest);
40                 }
41             );
42         }
43
44         function runTest() {
45             activateElement("TheIframeThatRequestsStorageAccess");
46         }
47
48         const hostUnderTest = "localhost:8000";
49         const statisticsUrl = "http://" + hostUnderTest + "/temp";
50         setEnableFeature(true, function() {
51             testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
52                 if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
53                     testFailed("Host did not get set as prevalent resource.");
54                 testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, true, function() {
55                     if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
56                         testFailed("Host did not get logged for user interaction.");
57                     let iframeElement = document.createElement("iframe");
58                     iframeElement.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-modals");
59                     iframeElement.onload = runTest;
60                     iframeElement.id = "TheIframeThatRequestsStorageAccess";
61                     iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html#userShouldGrantAccess,userShouldBeConsulted,policyShouldGrantAccess,isNotSameOriginIframe";
62                     document.body.appendChild(iframeElement);
63                 });
64             });
65         });
66     </script>
67 </head>
68 <body>
69 </body>
70 </html>