Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | const Cu = Components.utils; |
michael@0 | 2 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 3 | let tempScope = {}; |
michael@0 | 4 | Cu.import("resource://gre/modules/devtools/dbg-client.jsm", tempScope); |
michael@0 | 5 | Cu.import("resource://gre/modules/devtools/dbg-server.jsm", tempScope); |
michael@0 | 6 | Cu.import("resource://gre/modules/Promise.jsm", tempScope); |
michael@0 | 7 | let {DebuggerServer, DebuggerClient, Promise} = tempScope; |
michael@0 | 8 | tempScope = null; |
michael@0 | 9 | |
michael@0 | 10 | const {StorageFront} = require("devtools/server/actors/storage"); |
michael@0 | 11 | let gTests; |
michael@0 | 12 | let gExpected; |
michael@0 | 13 | let index = 0; |
michael@0 | 14 | |
michael@0 | 15 | const beforeReload = { |
michael@0 | 16 | cookies: ["test1.example.org", "sectest1.example.org"], |
michael@0 | 17 | localStorage: ["http://test1.example.org", "http://sectest1.example.org"], |
michael@0 | 18 | sessionStorage: ["http://test1.example.org", "http://sectest1.example.org"], |
michael@0 | 19 | }; |
michael@0 | 20 | |
michael@0 | 21 | function finishTests(client) { |
michael@0 | 22 | // Forcing GC/CC to get rid of docshells and windows created by this test. |
michael@0 | 23 | forceCollections(); |
michael@0 | 24 | client.close(() => { |
michael@0 | 25 | forceCollections(); |
michael@0 | 26 | DebuggerServer.destroy(); |
michael@0 | 27 | forceCollections(); |
michael@0 | 28 | DebuggerClient = DebuggerServer = gTests = null; |
michael@0 | 29 | finish(); |
michael@0 | 30 | }); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function markOutMatched(toBeEmptied, data, deleted) { |
michael@0 | 34 | if (!Object.keys(toBeEmptied).length) { |
michael@0 | 35 | info("Object empty") |
michael@0 | 36 | return; |
michael@0 | 37 | } |
michael@0 | 38 | ok(Object.keys(data).length, |
michael@0 | 39 | "Atleast some storage types should be present in deleted"); |
michael@0 | 40 | for (let storageType in toBeEmptied) { |
michael@0 | 41 | if (!data[storageType]) { |
michael@0 | 42 | continue; |
michael@0 | 43 | } |
michael@0 | 44 | info("Testing for " + storageType); |
michael@0 | 45 | for (let host in data[storageType]) { |
michael@0 | 46 | ok(toBeEmptied[storageType][host], "Host " + host + " found"); |
michael@0 | 47 | |
michael@0 | 48 | for (let item of data[storageType][host]) { |
michael@0 | 49 | let index = toBeEmptied[storageType][host].indexOf(item); |
michael@0 | 50 | ok(index > -1, "Item found - " + item); |
michael@0 | 51 | if (index > -1) { |
michael@0 | 52 | toBeEmptied[storageType][host].splice(index, 1); |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | if (!toBeEmptied[storageType][host].length) { |
michael@0 | 56 | delete toBeEmptied[storageType][host]; |
michael@0 | 57 | } |
michael@0 | 58 | } |
michael@0 | 59 | if (!Object.keys(toBeEmptied[storageType]).length) { |
michael@0 | 60 | delete toBeEmptied[storageType]; |
michael@0 | 61 | } |
michael@0 | 62 | } |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | function onStoresCleared(data) { |
michael@0 | 66 | if (data.sessionStorage || data.localStorage) { |
michael@0 | 67 | let hosts = data.sessionStorage || data.localStorage; |
michael@0 | 68 | info("Stores cleared required for session storage"); |
michael@0 | 69 | is(hosts.length, 1, "number of hosts is 1"); |
michael@0 | 70 | is(hosts[0], "http://test1.example.org", |
michael@0 | 71 | "host matches for " + Object.keys(data)[0]); |
michael@0 | 72 | gTests.next(); |
michael@0 | 73 | } |
michael@0 | 74 | else { |
michael@0 | 75 | ok(false, "Stores cleared should only be for local and sesion storage"); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | function onStoresUpdate({added, changed, deleted}) { |
michael@0 | 81 | info("inside stores update for index " + index); |
michael@0 | 82 | |
michael@0 | 83 | // Here, added, changed and deleted might be null even if they are required as |
michael@0 | 84 | // per gExpected. This is fine as they might come in the next stores-update |
michael@0 | 85 | // call or have already come in the previous one. |
michael@0 | 86 | if (added) { |
michael@0 | 87 | info("matching added object for index " + index); |
michael@0 | 88 | markOutMatched(gExpected.added, added); |
michael@0 | 89 | } |
michael@0 | 90 | if (changed) { |
michael@0 | 91 | info("matching changed object for index " + index); |
michael@0 | 92 | markOutMatched(gExpected.changed, changed); |
michael@0 | 93 | } |
michael@0 | 94 | if (deleted) { |
michael@0 | 95 | info("matching deleted object for index " + index); |
michael@0 | 96 | markOutMatched(gExpected.deleted, deleted); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | if ((!gExpected.added || !Object.keys(gExpected.added).length) && |
michael@0 | 100 | (!gExpected.changed || !Object.keys(gExpected.changed).length) && |
michael@0 | 101 | (!gExpected.deleted || !Object.keys(gExpected.deleted).length)) { |
michael@0 | 102 | info("Everything expected has been received for index " + index); |
michael@0 | 103 | index++; |
michael@0 | 104 | gTests.next(); |
michael@0 | 105 | } |
michael@0 | 106 | else { |
michael@0 | 107 | info("Still some updates pending for index " + index); |
michael@0 | 108 | } |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | function* UpdateTests(front, win, client) { |
michael@0 | 112 | front.on("stores-update", onStoresUpdate); |
michael@0 | 113 | |
michael@0 | 114 | // index 0 |
michael@0 | 115 | gExpected = { |
michael@0 | 116 | added: { |
michael@0 | 117 | cookies: { |
michael@0 | 118 | "test1.example.org": ["c1", "c2"] |
michael@0 | 119 | }, |
michael@0 | 120 | localStorage: { |
michael@0 | 121 | "http://test1.example.org": ["l1"] |
michael@0 | 122 | } |
michael@0 | 123 | } |
michael@0 | 124 | }; |
michael@0 | 125 | win.addCookie("c1", "foobar1"); |
michael@0 | 126 | win.addCookie("c2", "foobar2"); |
michael@0 | 127 | win.localStorage.setItem("l1", "foobar1"); |
michael@0 | 128 | yield undefined; |
michael@0 | 129 | |
michael@0 | 130 | // index 1 |
michael@0 | 131 | gExpected = { |
michael@0 | 132 | changed: { |
michael@0 | 133 | cookies: { |
michael@0 | 134 | "test1.example.org": ["c1"] |
michael@0 | 135 | } |
michael@0 | 136 | }, |
michael@0 | 137 | added: { |
michael@0 | 138 | localStorage: { |
michael@0 | 139 | "http://test1.example.org": ["l2"] |
michael@0 | 140 | } |
michael@0 | 141 | } |
michael@0 | 142 | }; |
michael@0 | 143 | win.addCookie("c1", "new_foobar1"); |
michael@0 | 144 | win.localStorage.setItem("l2", "foobar2"); |
michael@0 | 145 | yield undefined; |
michael@0 | 146 | |
michael@0 | 147 | // index 2 |
michael@0 | 148 | gExpected = { |
michael@0 | 149 | deleted: { |
michael@0 | 150 | cookies: { |
michael@0 | 151 | "test1.example.org": ["c2"] |
michael@0 | 152 | }, |
michael@0 | 153 | localStorage: { |
michael@0 | 154 | "http://test1.example.org": ["l1"] |
michael@0 | 155 | } |
michael@0 | 156 | }, |
michael@0 | 157 | added: { |
michael@0 | 158 | localStorage: { |
michael@0 | 159 | "http://test1.example.org": ["l3"] |
michael@0 | 160 | } |
michael@0 | 161 | } |
michael@0 | 162 | }; |
michael@0 | 163 | win.removeCookie("c2"); |
michael@0 | 164 | win.localStorage.removeItem("l1"); |
michael@0 | 165 | win.localStorage.setItem("l3", "foobar3"); |
michael@0 | 166 | yield undefined; |
michael@0 | 167 | |
michael@0 | 168 | // index 3 |
michael@0 | 169 | gExpected = { |
michael@0 | 170 | added: { |
michael@0 | 171 | cookies: { |
michael@0 | 172 | "test1.example.org": ["c3"] |
michael@0 | 173 | }, |
michael@0 | 174 | sessionStorage: { |
michael@0 | 175 | "http://test1.example.org": ["s1", "s2"] |
michael@0 | 176 | } |
michael@0 | 177 | }, |
michael@0 | 178 | changed: { |
michael@0 | 179 | localStorage: { |
michael@0 | 180 | "http://test1.example.org": ["l3"] |
michael@0 | 181 | } |
michael@0 | 182 | }, |
michael@0 | 183 | deleted: { |
michael@0 | 184 | cookies: { |
michael@0 | 185 | "test1.example.org": ["c1"] |
michael@0 | 186 | }, |
michael@0 | 187 | localStorage: { |
michael@0 | 188 | "http://test1.example.org": ["l2"] |
michael@0 | 189 | } |
michael@0 | 190 | } |
michael@0 | 191 | }; |
michael@0 | 192 | win.removeCookie("c1"); |
michael@0 | 193 | win.addCookie("c3", "foobar3"); |
michael@0 | 194 | win.localStorage.removeItem("l2"); |
michael@0 | 195 | win.sessionStorage.setItem("s1", "foobar1"); |
michael@0 | 196 | win.sessionStorage.setItem("s2", "foobar2"); |
michael@0 | 197 | win.localStorage.setItem("l3", "new_foobar3"); |
michael@0 | 198 | yield undefined; |
michael@0 | 199 | |
michael@0 | 200 | // index 4 |
michael@0 | 201 | gExpected = { |
michael@0 | 202 | deleted: { |
michael@0 | 203 | sessionStorage: { |
michael@0 | 204 | "http://test1.example.org": ["s1"] |
michael@0 | 205 | } |
michael@0 | 206 | } |
michael@0 | 207 | }; |
michael@0 | 208 | win.sessionStorage.removeItem("s1"); |
michael@0 | 209 | yield undefined; |
michael@0 | 210 | |
michael@0 | 211 | // index 5 |
michael@0 | 212 | gExpected = { |
michael@0 | 213 | deleted: { |
michael@0 | 214 | cookies: { |
michael@0 | 215 | "test1.example.org": ["c3"] |
michael@0 | 216 | } |
michael@0 | 217 | } |
michael@0 | 218 | }; |
michael@0 | 219 | front.on("stores-cleared", onStoresCleared); |
michael@0 | 220 | win.clear(); |
michael@0 | 221 | yield undefined; |
michael@0 | 222 | // Another 2 more yield undefined s so as to wait for the "stores-cleared" to |
michael@0 | 223 | // fire. One for Local Storage and other for Session Storage |
michael@0 | 224 | yield undefined; |
michael@0 | 225 | yield undefined; |
michael@0 | 226 | |
michael@0 | 227 | front.off("stores-cleared", onStoresCleared); |
michael@0 | 228 | front.off("stores-update", onStoresUpdate); |
michael@0 | 229 | finishTests(client); |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | |
michael@0 | 233 | function test() { |
michael@0 | 234 | waitForExplicitFinish(); |
michael@0 | 235 | addTab(MAIN_DOMAIN + "storage-updates.html", function(doc) { |
michael@0 | 236 | try { |
michael@0 | 237 | // Sometimes debugger server does not get destroyed correctly by previous |
michael@0 | 238 | // tests. |
michael@0 | 239 | DebuggerServer.destroy(); |
michael@0 | 240 | } catch (ex) { } |
michael@0 | 241 | DebuggerServer.init(function () { return true; }); |
michael@0 | 242 | DebuggerServer.addBrowserActors(); |
michael@0 | 243 | |
michael@0 | 244 | let client = new DebuggerClient(DebuggerServer.connectPipe()); |
michael@0 | 245 | client.connect(function onConnect() { |
michael@0 | 246 | client.listTabs(function onListTabs(aResponse) { |
michael@0 | 247 | let form = aResponse.tabs[aResponse.selected]; |
michael@0 | 248 | let front = StorageFront(client, form); |
michael@0 | 249 | gTests = UpdateTests(front, doc.defaultView.wrappedJSObject, |
michael@0 | 250 | client); |
michael@0 | 251 | // Make an initial call to initialize the actor |
michael@0 | 252 | front.listStores().then(() => gTests.next()); |
michael@0 | 253 | }); |
michael@0 | 254 | }); |
michael@0 | 255 | }) |
michael@0 | 256 | } |