Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | function test() { |
michael@0 | 6 | // test that cookies are stored and restored correctly by sessionstore, |
michael@0 | 7 | // bug 423132. |
michael@0 | 8 | |
michael@0 | 9 | waitForExplicitFinish(); |
michael@0 | 10 | |
michael@0 | 11 | let cs = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2); |
michael@0 | 12 | cs.removeAll(); |
michael@0 | 13 | |
michael@0 | 14 | // make sure that sessionstore.js can be forced to be created by setting |
michael@0 | 15 | // the interval pref to 0 |
michael@0 | 16 | gPrefService.setIntPref("browser.sessionstore.interval", 0); |
michael@0 | 17 | |
michael@0 | 18 | const testURL = "http://mochi.test:8888/browser/" + |
michael@0 | 19 | "browser/components/sessionstore/test/browser_423132_sample.html"; |
michael@0 | 20 | |
michael@0 | 21 | // open a new window |
michael@0 | 22 | let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", "about:blank"); |
michael@0 | 23 | |
michael@0 | 24 | // make sure sessionstore saves the cookie data, then close the window |
michael@0 | 25 | newWin.addEventListener("load", function (aEvent) { |
michael@0 | 26 | newWin.removeEventListener("load", arguments.callee, false); |
michael@0 | 27 | |
michael@0 | 28 | newWin.gBrowser.loadURI(testURL, null, null); |
michael@0 | 29 | |
michael@0 | 30 | whenBrowserLoaded(newWin.gBrowser.selectedBrowser, function() { |
michael@0 | 31 | // get the sessionstore state for the window |
michael@0 | 32 | SyncHandlers.get(newWin.gBrowser.selectedBrowser).flush(); |
michael@0 | 33 | let state = ss.getWindowState(newWin); |
michael@0 | 34 | |
michael@0 | 35 | // verify our cookie got set during pageload |
michael@0 | 36 | let e = cs.enumerator; |
michael@0 | 37 | let cookie; |
michael@0 | 38 | let i = 0; |
michael@0 | 39 | while (e.hasMoreElements()) { |
michael@0 | 40 | cookie = e.getNext().QueryInterface(Ci.nsICookie); |
michael@0 | 41 | i++; |
michael@0 | 42 | } |
michael@0 | 43 | is(i, 1, "expected one cookie"); |
michael@0 | 44 | |
michael@0 | 45 | // remove the cookie |
michael@0 | 46 | cs.removeAll(); |
michael@0 | 47 | |
michael@0 | 48 | // restore the window state |
michael@0 | 49 | ss.setWindowState(newWin, state, true); |
michael@0 | 50 | |
michael@0 | 51 | // at this point, the cookie should be restored... |
michael@0 | 52 | e = cs.enumerator; |
michael@0 | 53 | let cookie2; |
michael@0 | 54 | while (e.hasMoreElements()) { |
michael@0 | 55 | cookie2 = e.getNext().QueryInterface(Ci.nsICookie); |
michael@0 | 56 | if (cookie.name == cookie2.name) |
michael@0 | 57 | break; |
michael@0 | 58 | } |
michael@0 | 59 | is(cookie.name, cookie2.name, "cookie name successfully restored"); |
michael@0 | 60 | is(cookie.value, cookie2.value, "cookie value successfully restored"); |
michael@0 | 61 | is(cookie.path, cookie2.path, "cookie path successfully restored"); |
michael@0 | 62 | |
michael@0 | 63 | // clean up |
michael@0 | 64 | if (gPrefService.prefHasUserValue("browser.sessionstore.interval")) |
michael@0 | 65 | gPrefService.clearUserPref("browser.sessionstore.interval"); |
michael@0 | 66 | cs.removeAll(); |
michael@0 | 67 | newWin.close(); |
michael@0 | 68 | finish(); |
michael@0 | 69 | }); |
michael@0 | 70 | }, false); |
michael@0 | 71 | } |
michael@0 | 72 |