| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <script src="/js-test-resources/js-test.js"></script> |
| </head> |
| <body> |
| <script> |
| description("Test for partitioned and unpartitioned cookie deletion."); |
| jsTestIsAsync = true; |
| |
| const partitionHost = "127.0.0.1:8000"; |
| const thirdPartyOrigin = "http://localhost:8000"; |
| const thirdPartyBaseUrl = thirdPartyOrigin + "/resourceLoadStatistics/resources"; |
| const firstPartyCookieName = "firstPartyCookie"; |
| const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value"; |
| const thirdPartyCookieName = "thirdPartyCookie"; |
| const subPathToSetThirdPartyCookie = "/set-cookie.php?name=" + thirdPartyCookieName + "&value=value"; |
| const fragmentWithReturnUrl = "http://" + partitionHost + "/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html"; |
| const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + thirdPartyCookieName; |
| |
| function setEnableFeature(enable) { |
| if (!enable) { |
| testRunner.statisticsResetToConsistentState(); |
| } |
| testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(enable); |
| internals.setResourceLoadStatisticsEnabled(enable); |
| testRunner.setCookieStoragePartitioningEnabled(enable); |
| } |
| |
| function finishTest() { |
| setEnableFeature(false); |
| finishJSTest(); |
| } |
| |
| function openIframe(url, onLoadHandler) { |
| const element = document.createElement("iframe"); |
| element.src = url; |
| if (onLoadHandler) { |
| element.onload = onLoadHandler; |
| } |
| document.body.appendChild(element); |
| } |
| |
| |
| function fireDataModificationHandlerAndContinue() { |
| testRunner.installStatisticsDidScanDataRecordsCallback(function() { |
| setTimeout(runTest, 500); |
| }); |
| testRunner.statisticsProcessStatisticsAndDataRecords(); |
| } |
| |
| function setUserInteractionAndContinue() { |
| testRunner.setStatisticsHasHadUserInteraction(thirdPartyOrigin, true); |
| if (!testRunner.isStatisticsHasHadUserInteraction(thirdPartyOrigin)) |
| testFailed("Third party did not get logged for user interaction."); |
| runTest(); |
| } |
| |
| function runTest() { |
| switch (document.location.hash) { |
| case "#step1": |
| document.location.href = thirdPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + fragmentWithReturnUrl + "#step2"; |
| break; |
| case "#step2": |
| document.location.hash = "step3"; |
| openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive no cookies.", runTest); |
| break; |
| case "#step3": |
| document.location.hash = "step4"; |
| openIframe(thirdPartyBaseUrl + subPathToSetThirdPartyCookie + "&message=Setting partitioned, third party cookie.", runTest); |
| break; |
| case "#step4": |
| document.location.hash = "step5"; |
| openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should only receive partitioned, third party cookie.", fireDataModificationHandlerAndContinue); |
| break; |
| case "#step5": |
| document.location.hash = "step6"; |
| setTimeout(runTest, 10); |
| break; |
| case "#step6": |
| document.location.hash = "step7"; |
| openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After removal, should receive no cookies.", setUserInteractionAndContinue); |
| break; |
| case "#step7": |
| openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After user interaction, should receive no cookies.", finishTest); |
| break; |
| } |
| } |
| |
| if (document.location.host === partitionHost && document.location.hash === "" && window.testRunner && window.internals) { |
| setEnableFeature(true); |
| |
| testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false); |
| testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0); |
| |
| testRunner.dumpChildFramesAsText(); |
| document.location.hash = "step1"; |
| |
| testRunner.setStatisticsPrevalentResource("http://localhost", true); |
| if (!testRunner.isStatisticsPrevalentResource("http://localhost")) |
| testFailed("Host did not get set as prevalent resource."); |
| |
| testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true, runTest); |
| } else { |
| runTest(); |
| } |
| |
| </script> |
| </body> |
| </html> |