| <!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-site iframe can request and be granted storage access under general third-party cookie blocking."); |
| jsTestIsAsync = true; |
| testRunner.setUseITPDatabase(true); |
| |
| const firstPartyUrl = "http://127.0.0.1:8000"; |
| const thirdPartyUrl = "http://localhost:8000"; |
| |
| function receiveMessage(event) { |
| if (event.origin === "http://localhost:8000") { |
| if (event.data.indexOf("PASS ") !== -1) |
| testPassed(event.data.replace("PASS ", "")); |
| else |
| testFailed(event.data.replace("FAIL ", "")); |
| } else |
| testFailed("Received a message from an unexpected origin: " + event.origin); |
| testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() { |
| setEnableFeature(false, finishJSTest); |
| }); |
| } |
| |
| window.addEventListener("message", receiveMessage, false); |
| |
| 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."); |
| testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() { |
| setEnableFeature(false, finishJSTest); |
| }); |
| } |
| }, |
| function () { |
| testFailed("Promise rejected."); |
| testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() { |
| setEnableFeature(false, finishJSTest); |
| }); |
| } |
| ); |
| } |
| |
| function runTest() { |
| if (document.location.hash !== "#cookieSet") { |
| setEnableFeature(true, function() { |
| document.location.href = thirdPartyUrl + "/storageAccess/resources/set-cookie.php?name=firstPartyCookie&value=value#" + firstPartyUrl + "/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking-database.html#cookieSet"; |
| }); |
| } else { |
| testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() { |
| if (testRunner.isStatisticsPrevalentResource(thirdPartyUrl)) |
| testFailed("Third-party set as prevalent resource."); |
| testRunner.setStatisticsHasHadUserInteraction(firstPartyUrl, true, function() { |
| if (!testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl)) |
| testFailed("First-party did not get logged for user interaction."); |
| testRunner.setStatisticsHasHadUserInteraction(thirdPartyUrl, true, function() { |
| if (!testRunner.isStatisticsHasHadUserInteraction(thirdPartyUrl)) |
| testFailed("Third-party did not get logged for user interaction."); |
| let iframeElement = document.createElement("iframe"); |
| iframeElement.onload = function() { |
| activateElement("TheIframeThatRequestsStorageAccess"); |
| }; |
| iframeElement.id = "TheIframeThatRequestsStorageAccess"; |
| iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html#userShouldGrantAccess,userShouldBeConsulted,policyShouldGrantAccess,isNotSameOriginIframe"; |
| document.body.appendChild(iframeElement); |
| }); |
| }); |
| }); |
| } |
| } |
| </script> |
| </head> |
| <body onload="runTest()"> |
| </body> |
| </html> |