| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="/js-test-resources/js-test.js"></script> |
| <script src="/cookies/resources/cookie-utilities.js"></script> |
| <script src="resources/util.js"></script> |
| </head> |
| <body onload="setTimeout('runTest()', 0)"> |
| <script> |
| description("Check that cookies created by JavaScript after a cross-site navigation without link decoration don't get capped to 24 hours."); |
| jsTestIsAsync = true; |
| |
| function testCookies() { |
| let passedTests = 0; |
| |
| function checkThatCookieDoesExpireAfter(cookieData, maxAgeInSeconds) { |
| let now = new Date(); |
| let maxExpiryDateInMilliseconds = now.getTime() + (maxAgeInSeconds * 1000); |
| |
| if (maxExpiryDateInMilliseconds < cookieData["expires"]) |
| ++passedTests; |
| else |
| testFailed("Cookie named " + cookieData["name"] + " expires in less than " + maxAgeInSeconds + " seconds."); |
| } |
| |
| const oneDayInSeconds = 24 * 60 * 60; |
| const twoDaysInSeconds = 2 * oneDayInSeconds; |
| const longLivedCookieMaxAge = { name : "longLivedCookieMaxAge", lifetime : "Max-Age=" + twoDaysInSeconds + ";" }; |
| document.cookie = longLivedCookieMaxAge.name + "=foobar; " + longLivedCookieMaxAge.lifetime + " path=/"; |
| |
| const twoDaysAsExpiresDate = createExpiresDateFromMaxAge(twoDaysInSeconds); |
| const longLivedCookieExpires = { name : "longLivedCookieExpires", lifetime : "Expires=" + twoDaysAsExpiresDate + ";" }; |
| document.cookie = longLivedCookieExpires.name + "=foobar; " + longLivedCookieExpires.lifetime + " path=/"; |
| |
| const overOneDayInSeconds = oneDayInSeconds + 30; |
| if (internals) { |
| let cookies = internals.getCookies(); |
| if (!cookies.length) |
| testFailed("No cookies found."); |
| for (let cookie of cookies) { |
| switch (cookie.name) { |
| case longLivedCookieMaxAge.name: |
| checkThatCookieDoesExpireAfter(cookie, overOneDayInSeconds); |
| break; |
| case longLivedCookieExpires.name: |
| checkThatCookieDoesExpireAfter(cookie, overOneDayInSeconds); |
| break; |
| } |
| } |
| |
| resetCookiesForCurrentOrigin(); |
| |
| if (passedTests === 2) { |
| testPassed("The two long-lived cookies expire after more than " + overOneDayInSeconds + " seconds."); |
| } else |
| testFailed("At least one cookie's expiry attribute was below the test thresholds."); |
| } else |
| testFailed("No internals object."); |
| |
| setEnableFeature(false, finishJSTest); |
| } |
| |
| function navigateCrossOrigin() { |
| document.location.href = destinationOrigin + "/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource.html"; |
| } |
| |
| const destinationOrigin = "http://localhost:8000"; |
| const prevalentResourceOrigin = "http://127.0.0.1:8000"; |
| function runTest() { |
| if (document.location.origin === prevalentResourceOrigin) { |
| setEnableFeature(true, function () { |
| testRunner.setStatisticsPrevalentResource(prevalentResourceOrigin, true, function() { |
| if (!testRunner.isStatisticsPrevalentResource(prevalentResourceOrigin)) |
| testFailed("Host did not get set as prevalent resource."); |
| testRunner.statisticsUpdateCookieBlocking(navigateCrossOrigin); |
| }); |
| |
| }); |
| } else { |
| testCookies(); |
| } |
| } |
| </script> |
| </body> |
| </html> |