dom/tests/mochitest/sessionstorage/test_cookieSession.html

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 2 <head>
michael@0 3 <title>cookie per-session only test</title>
michael@0 4
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 7
michael@0 8 <script type="text/javascript">
michael@0 9
michael@0 10 /*
michael@0 11 Set cookie access to be just per session and store to the sessionStorage.
michael@0 12 Content stored must prevail only for session of the browser, so it must
michael@0 13 be accessible in another window we try to access that key in the same
michael@0 14 storage.
michael@0 15 */
michael@0 16
michael@0 17 function pushCookie(aValue, aNext) {
michael@0 18 SpecialPowers.pushPermissions([{'type': 'cookie', 'allow': aValue, 'context': document}], pushPermissionAndTest);
michael@0 19 }
michael@0 20
michael@0 21 function pushPermissionAndTest() {
michael@0 22 var test = tests.shift();
michael@0 23 if (test) {
michael@0 24 document.getElementById('testframe').onload = test;
michael@0 25 /* After every permission change, an iframe has to be reloaded,
michael@0 26 otherwise this test causes failures in b2g (oop) mochitest, because
michael@0 27 the permission changes don't seem to be always picked up
michael@0 28 by the code that excercises it */
michael@0 29 document.getElementById('testframe').contentWindow.location.reload();
michael@0 30 } else {
michael@0 31 ok(false, 'should not be reached');
michael@0 32 SimpleTest.finish();
michael@0 33 }
michael@0 34 }
michael@0 35
michael@0 36 function startTest() {
michael@0 37 pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT);
michael@0 38 }
michael@0 39
michael@0 40 var tests = [
michael@0 41 function test1() {
michael@0 42 sessionStorage.setItem("persistent1", "persistent value 1");
michael@0 43 sessionStorage.setItem("persistent2", "persistent value 2");
michael@0 44
michael@0 45 pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION);
michael@0 46 },
michael@0 47
michael@0 48 function test2() {
michael@0 49 sessionStorage.setItem("session only", "session value");
michael@0 50 is(sessionStorage.getItem("session only"), "session value", "Value present when cookies in session-only mode");
michael@0 51 is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present");
michael@0 52 is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present");
michael@0 53
michael@0 54 sessionStorage.setItem("persistent1", "changed persistent value 1");
michael@0 55 sessionStorage.removeItem("persistent2");
michael@0 56
michael@0 57 is(sessionStorage.getItem("session only"), "session value", "Value present when cookies in session-only mode");
michael@0 58 is(sessionStorage.getItem("persistent1"), "changed persistent value 1", "Persistent value present");
michael@0 59 is(sessionStorage.getItem("persistent2"), null, "Persistent value removed");
michael@0 60
michael@0 61 // This clear has to delete only changes made in session only mode
michael@0 62 sessionStorage.clear();
michael@0 63
michael@0 64 is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete");
michael@0 65 is(sessionStorage.getItem("persistent1"), null, "Persistent value not present in session only after delete");
michael@0 66 is(sessionStorage.getItem("persistent2"), null, "Persistent value not present in session only after delete");
michael@0 67
michael@0 68 sessionStorage.setItem("session only 2", "must be deleted on drop of session-only cookies permissions");
michael@0 69
michael@0 70 pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT);
michael@0 71 },
michael@0 72
michael@0 73 function test3() {
michael@0 74 is(sessionStorage.getItem("session only"), null, "No value when cookies are in default mode");
michael@0 75 is(sessionStorage.getItem("session only 2"), null, "No value when cookies are in default mode");
michael@0 76 is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present");
michael@0 77 is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present");
michael@0 78
michael@0 79 pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION);
michael@0 80 },
michael@0 81
michael@0 82 function test4() {
michael@0 83 is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete");
michael@0 84 is(sessionStorage.getItem("session only 2"), null, "Value not present when cookies in session-only mode after delete");
michael@0 85 is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present again");
michael@0 86 is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present again");
michael@0 87
michael@0 88 pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT);
michael@0 89 },
michael@0 90
michael@0 91 function test5() {
michael@0 92 sessionStorage.clear();
michael@0 93
michael@0 94 is(sessionStorage.getItem("session only"), null, "No value when cookies are in default mode");
michael@0 95 is(sessionStorage.getItem("persistent1"), null, "Persistent value not present after delete");
michael@0 96 is(sessionStorage.getItem("persistent2"), null, "Persistent value not present after delete");
michael@0 97
michael@0 98 pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION);
michael@0 99 },
michael@0 100
michael@0 101 function test6() {
michael@0 102 is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete");
michael@0 103 is(sessionStorage.getItem("session only 2"), null, "No value when cookies are in default mode");
michael@0 104 is(sessionStorage.getItem("persistent1"), null, "Persistent value not present in session only after delete");
michael@0 105 is(sessionStorage.getItem("persistent2"), null, "Persistent value not present in session only after delete");
michael@0 106
michael@0 107 pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT);
michael@0 108 },
michael@0 109
michael@0 110 function test7() {
michael@0 111 SimpleTest.finish();
michael@0 112 }
michael@0 113 ];
michael@0 114
michael@0 115 SimpleTest.waitForExplicitFinish();
michael@0 116
michael@0 117 </script>
michael@0 118
michael@0 119 </head>
michael@0 120
michael@0 121 <body onload="startTest();">
michael@0 122 <iframe id="testframe" src="data:text/html;charset=utf-8,"></iframe>
michael@0 123 </body>
michael@0 124 </html>

mercurial