| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <script src="/js-test-resources/js-test.js"></script> |
| <script src="resources/util.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/cookie-deletion-database.html"; |
| const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + thirdPartyCookieName; |
| |
| 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 setAsNonPrevalentAndContinue() { |
| testRunner.setStatisticsPrevalentResource(thirdPartyOrigin, false, function() { |
| if (testRunner.isStatisticsPrevalentResource(thirdPartyOrigin)) |
| testFailed("Host still set as prevalent resource."); |
| testRunner.statisticsUpdateCookieBlocking(runTest); |
| }); |
| } |
| |
| function runTest() { |
| switch (document.location.hash) { |
| case "#step1": |
| // Set first-party cookie for localhost. |
| document.location.href = thirdPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + fragmentWithReturnUrl + "#step2"; |
| break; |
| case "#step2": |
| // Check that the third-party has access to its first-party cookies. |
| document.location.hash = "step3"; |
| openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", runTest); |
| break; |
| case "#step3": |
| // Classify localhost as prevalent. |
| document.location.hash = "step4"; |
| testRunner.setStatisticsPrevalentResource(thirdPartyOrigin, true, function() { |
| if (!testRunner.isStatisticsPrevalentResource(thirdPartyOrigin)) |
| testFailed("Host did not get set as prevalent resource."); |
| testRunner.statisticsUpdateCookieBlocking(runTest); |
| }); |
| break; |
| case "#step4": |
| // Check that the third-party no longer has access to its first-party cookies. |
| document.location.hash = "step5"; |
| openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive no cookies.", runTest); |
| break; |
| case "#step5": |
| // Try setting a cookie as third-party. |
| document.location.hash = "step6"; |
| openIframe(thirdPartyBaseUrl + subPathToSetThirdPartyCookie + "&message=Try to set third party cookie.", runTest); |
| break; |
| case "#step6": |
| // Check that the third-party still has no access to cookies and then fire data record removal. |
| document.location.hash = "step7"; |
| openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive no cookies.", fireDataModificationHandlerAndContinue); |
| break; |
| case "#step7": |
| // Check that the third-party still has no access to cookies and then declassify localhost. |
| document.location.hash = "step8"; |
| openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After removal, should receive no cookies.", setAsNonPrevalentAndContinue); |
| break; |
| case "#step8": |
| // Check that the third-party still has no access to cookies. |
| openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After declassified, should receive no cookies.", finishTest); |
| break; |
| } |
| } |
| |
| if (document.location.host === partitionHost && document.location.hash === "" && window.testRunner && window.internals) { |
| testRunner.setUseITPDatabase(true); |
| setEnableFeature(true, function() { |
| testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false); |
| testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0); |
| |
| testRunner.dumpChildFramesAsText(); |
| document.location.hash = "step1"; |
| |
| runTest(); |
| }); |
| } else { |
| runTest(); |
| } |
| |
| </script> |
| </body> |
| </html> |