2013-04-15 05:38:48 -07:00
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head>
|
|
|
|
<title>cookie per-session only test</title>
|
|
|
|
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
/*
|
|
|
|
Set cookie access to be just per session and store to the sessionStorage.
|
|
|
|
Content stored must prevail only for session of the browser, so it must
|
|
|
|
be accessible in another window we try to access that key in the same
|
|
|
|
storage.
|
|
|
|
*/
|
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
function pushCookie(aValue, aNext) {
|
|
|
|
SpecialPowers.pushPermissions([{'type': 'cookie', 'allow': aValue, 'context': document}], pushPermissionAndTest);
|
|
|
|
}
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
function pushPermissionAndTest() {
|
|
|
|
var test = tests.shift();
|
|
|
|
if (test) {
|
|
|
|
document.getElementById('testframe').onload = test;
|
|
|
|
/* After every permission change, an iframe has to be reloaded,
|
|
|
|
otherwise this test causes failures in b2g (oop) mochitest, because
|
|
|
|
the permission changes don't seem to be always picked up
|
|
|
|
by the code that excercises it */
|
|
|
|
document.getElementById('testframe').contentWindow.location.reload();
|
|
|
|
} else {
|
|
|
|
ok(false, 'should not be reached');
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
}
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
function startTest() {
|
|
|
|
pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT);
|
|
|
|
}
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
var tests = [
|
|
|
|
function test1() {
|
|
|
|
sessionStorage.setItem("persistent1", "persistent value 1");
|
|
|
|
sessionStorage.setItem("persistent2", "persistent value 2");
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION);
|
|
|
|
},
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
function test2() {
|
|
|
|
sessionStorage.setItem("session only", "session value");
|
|
|
|
is(sessionStorage.getItem("session only"), "session value", "Value present when cookies in session-only mode");
|
|
|
|
is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present");
|
|
|
|
is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present");
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
sessionStorage.setItem("persistent1", "changed persistent value 1");
|
|
|
|
sessionStorage.removeItem("persistent2");
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
is(sessionStorage.getItem("session only"), "session value", "Value present when cookies in session-only mode");
|
|
|
|
is(sessionStorage.getItem("persistent1"), "changed persistent value 1", "Persistent value present");
|
|
|
|
is(sessionStorage.getItem("persistent2"), null, "Persistent value removed");
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
// This clear has to delete only changes made in session only mode
|
|
|
|
sessionStorage.clear();
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete");
|
|
|
|
is(sessionStorage.getItem("persistent1"), null, "Persistent value not present in session only after delete");
|
|
|
|
is(sessionStorage.getItem("persistent2"), null, "Persistent value not present in session only after delete");
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
sessionStorage.setItem("session only 2", "must be deleted on drop of session-only cookies permissions");
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT);
|
|
|
|
},
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
function test3() {
|
|
|
|
is(sessionStorage.getItem("session only"), null, "No value when cookies are in default mode");
|
|
|
|
is(sessionStorage.getItem("session only 2"), null, "No value when cookies are in default mode");
|
|
|
|
is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present");
|
|
|
|
is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present");
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION);
|
|
|
|
},
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
function test4() {
|
|
|
|
is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete");
|
|
|
|
is(sessionStorage.getItem("session only 2"), null, "Value not present when cookies in session-only mode after delete");
|
|
|
|
is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present again");
|
|
|
|
is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present again");
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT);
|
|
|
|
},
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
function test5() {
|
|
|
|
sessionStorage.clear();
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
is(sessionStorage.getItem("session only"), null, "No value when cookies are in default mode");
|
|
|
|
is(sessionStorage.getItem("persistent1"), null, "Persistent value not present after delete");
|
|
|
|
is(sessionStorage.getItem("persistent2"), null, "Persistent value not present after delete");
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION);
|
|
|
|
},
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
function test6() {
|
|
|
|
is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete");
|
|
|
|
is(sessionStorage.getItem("session only 2"), null, "No value when cookies are in default mode");
|
|
|
|
is(sessionStorage.getItem("persistent1"), null, "Persistent value not present in session only after delete");
|
|
|
|
is(sessionStorage.getItem("persistent2"), null, "Persistent value not present in session only after delete");
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT);
|
|
|
|
},
|
2013-04-15 05:38:48 -07:00
|
|
|
|
2013-09-16 08:15:22 -07:00
|
|
|
function test7() {
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
];
|
2013-04-15 05:38:48 -07:00
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="startTest();">
|
2013-09-16 08:15:22 -07:00
|
|
|
<iframe id="testframe" src="data:text/html;charset=utf-8,"></iframe>
|
2013-04-15 05:38:48 -07:00
|
|
|
</body>
|
|
|
|
</html>
|