| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="/js-test-resources/js-test.js"></script> |
| <script src="/js-test-resources/ui-helper.js"></script> |
| <script src="/resourceLoadStatistics/resources/util.js"></script> |
| <script> |
| description("Tests that a cross-origin iframe from a prevalent domain that is granted storage access and then navigates itself same-site still has storage access."); |
| jsTestIsAsync = true; |
| |
| window.addEventListener("message", receiveMessage, false); |
| |
| function finishTest() { |
| setEnableFeature(false, finishJSTest); |
| } |
| |
| const expectedPassMessages = 2; |
| var passMessagesReceived = 0; |
| function receiveMessage(event) { |
| if (event.origin === "http://localhost:8000") { |
| if (event.data.indexOf("document.cookie") === 0) { |
| testPassed(event.data); |
| } else if (event.data.indexOf("PASS") !== -1) { |
| testPassed(event.data.replace("PASS ", "")); |
| passMessagesReceived++; |
| if (passMessagesReceived >= expectedPassMessages) |
| finishTest(); |
| } else { |
| testFailed(event.data); |
| finishTest(); |
| } |
| } else { |
| testFailed("Received a message from an unexpected origin: " + event.origin); |
| finishTest(); |
| } |
| } |
| |
| function activateElement(elementId) { |
| var element = document.getElementById(elementId); |
| var centerX = element.offsetLeft + element.offsetWidth / 2; |
| var centerY = element.offsetTop + element.offsetHeight / 2; |
| UIHelper.activateAt(centerX, centerY).then( |
| function () { |
| if (window.eventSender) |
| eventSender.keyDown("escape"); |
| else { |
| testFailed("No eventSender."); |
| finishTest(); |
| } |
| }, |
| function () { |
| testFailed("Promise rejected."); |
| finishTest(); |
| } |
| ); |
| } |
| |
| function runTest() { |
| activateElement("TheIframeThatRequestsStorageAccess"); |
| } |
| |
| const hostUnderTest = "localhost:8000"; |
| const statisticsUrl = "http://" + hostUnderTest; |
| testRunner.setUseITPDatabase(true); |
| if (document.location.hash !== "#firstPartyCookieSet") { |
| setEnableFeature(true, function() { |
| document.location.href = statisticsUrl + "/storageAccess/resources/set-cookie.php?name=firstPartyCookie&value=value#http://127.0.0.1:8000/storageAccess/request-and-grant-access-then-navigate-same-site-should-have-access.html#firstPartyCookieSet"; |
| }); |
| } else { |
| testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() { |
| if (!testRunner.isStatisticsPrevalentResource(statisticsUrl)) |
| testFailed("Host did not get set as prevalent resource."); |
| testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, true, function() { |
| if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl)) |
| testFailed("Host did not get logged for user interaction."); |
| testRunner.statisticsUpdateCookieBlocking(function() { |
| let iframeElement = document.createElement("iframe"); |
| iframeElement.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-modals"); |
| iframeElement.onload = runTest; |
| iframeElement.id = "TheIframeThatRequestsStorageAccess"; |
| iframeElement.src = "http://localhost:8000/storageAccess/resources/self-navigating-frame-after-granted-access.html#userShouldGrantAccess,userShouldBeConsulted,policyShouldGrantAccess,sameSiteNavigation"; |
| document.body.appendChild(iframeElement); |
| }); |
| }); |
| }); |
| } |
| </script> |
| </head> |
| <body> |
| </body> |
| </html> |