blob: 3eb7cf4506e4db138dba9d6ea86fb718033bc24e [file] [log] [blame]
<!DOCTYPE html><!-- webkit-test-runner [ internal:IsInAppBrowserPrivacyEnabled=true applicationBundleIdentifier=inAppBrowserPrivacyTestIdentifier ] -->
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="/js-test-resources/js-test.js"></script>
<script src="/resourceLoadStatistics/resources/util.js"></script>
</head>
<body onload="runTest()">
<script>
description("Tests that the session is switched upon top frame navigation to an app-bound domain.");
jsTestIsAsync = true;
const appBoundOrigin = "http://127.0.0.1:8000";
const nonAppBoundOrigin = "http://localhost:8000";
const sessionCookieName = "sessionCookie";
const persistentCookieName = "persistentCookie";
const twoMinutesInSeconds = 120;
function finishTest() {
testRunner.setInAppBrowserPrivacyEnabled(false, finishJSTest);
}
function setSessionCookie() {
document.cookie = sessionCookieName + "=1; path=/";
}
function setPersistentCookie() {
document.cookie = persistentCookieName + "=1; path=/; Max-Age=" + twoMinutesInSeconds + ";";
}
function checkCookies(shouldHaveSessionCookie, shouldHavePersistentCookie) {
let hasSessionCookie = (document.cookie + "").includes(sessionCookieName),
hasPersistentCookie = (document.cookie + "").includes(persistentCookieName);
if (shouldHaveSessionCookie && hasSessionCookie)
testPassed("Should have and has the session cookie.");
else if (shouldHaveSessionCookie && !hasSessionCookie) {
testFailed("Should have but doesn't have the session cookie.");
setEnableFeature(false, finishTest);
} else if (!shouldHaveSessionCookie && hasSessionCookie) {
testFailed("Shouldn't have but has the session cookie.");
setEnableFeature(false, finishTest);
} else
testPassed("Shouldn't have and doesn't have the session cookie.");
if (shouldHavePersistentCookie && hasPersistentCookie)
testPassed("Should have and has the persistent cookie.");
else if (shouldHavePersistentCookie && !hasPersistentCookie) {
testFailed("Should have but doesn't have the persistent cookie.");
setEnableFeature(false, finishTest);
} else if (!shouldHavePersistentCookie && hasPersistentCookie) {
testFailed("Shouldn't have but has the persistent cookie.");
setEnableFeature(false, finishTest);
} else
testPassed("Shouldn't have and doesn't have the persistent cookie.");
}
function runTest() {
switch (document.location.hash) {
case "":
testRunner.setInAppBrowserPrivacyEnabled(true, function () {
if (document.location.origin !== appBoundOrigin)
testFailed("Test is not starting out on " + appBoundOrigin + ".");
setEnableFeature(true, function() {
// Since the test manually sets the inAppBrowserPrivacy flag in the
// Network process, we need to re-establish an app-bound session by
// navigating away then back to the app-bound Domain before setting cookies.
document.location.href = nonAppBoundOrigin + "/in-app-browser-privacy/switch-session-on-navigation-to-app-bound-domain.html#step1";
});
});
break;
case "#step1":
document.location.href = appBoundOrigin + "/in-app-browser-privacy/switch-session-on-navigation-to-app-bound-domain.html#step2";
break;
case "#step2":
if (document.location.origin !== appBoundOrigin)
testFailed("Step 2 is not on " + appBoundOrigin + ".");
testRunner.setStatisticsHasHadUserInteraction(appBoundOrigin, true, function() {
setSessionCookie();
setPersistentCookie();
checkCookies(true, true);
if (!testRunner.hasAppBoundSession()) {
testFailed("Origin did not start with app-bound session.");
setEnableFeature(false, finishTest);
} else
testPassed("Origin has app-bound session.");
document.location.href = nonAppBoundOrigin + "/in-app-browser-privacy/switch-session-on-navigation-to-app-bound-domain.html#step3";
});
break;
case "#step3":
document.location.hash = "#step4"
checkCookies(false, false);
if (document.location.origin !== nonAppBoundOrigin)
testFailed("Step 3 is not on " + nonAppBoundOrigin);
testRunner.statisticsUpdateCookieBlocking(runTest);
break;
case "#step4":
checkCookies(false, false);
document.location.href = appBoundOrigin + "/in-app-browser-privacy/switch-session-on-navigation-to-app-bound-domain.html#step5";
break;
case "#step5":
checkCookies(true, true);
if (testRunner.hasAppBoundSession())
testPassed("Origin has app-bound session after navigation.");
else
testFailed("Origin has no app-bound session after navigation.");
setEnableFeature(false, finishTest);
break;
default:
testFailed("Unknown hash.");
setEnableFeature(false, finishTest);
}
}
</script>
</body>
</html>