michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test() { michael@0: // test that cookies are stored and restored correctly by sessionstore, michael@0: // bug 423132. michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: let cs = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2); michael@0: cs.removeAll(); michael@0: michael@0: // make sure that sessionstore.js can be forced to be created by setting michael@0: // the interval pref to 0 michael@0: gPrefService.setIntPref("browser.sessionstore.interval", 0); michael@0: michael@0: const testURL = "http://mochi.test:8888/browser/" + michael@0: "browser/components/sessionstore/test/browser_423132_sample.html"; michael@0: michael@0: // open a new window michael@0: let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", "about:blank"); michael@0: michael@0: // make sure sessionstore saves the cookie data, then close the window michael@0: newWin.addEventListener("load", function (aEvent) { michael@0: newWin.removeEventListener("load", arguments.callee, false); michael@0: michael@0: newWin.gBrowser.loadURI(testURL, null, null); michael@0: michael@0: whenBrowserLoaded(newWin.gBrowser.selectedBrowser, function() { michael@0: // get the sessionstore state for the window michael@0: SyncHandlers.get(newWin.gBrowser.selectedBrowser).flush(); michael@0: let state = ss.getWindowState(newWin); michael@0: michael@0: // verify our cookie got set during pageload michael@0: let e = cs.enumerator; michael@0: let cookie; michael@0: let i = 0; michael@0: while (e.hasMoreElements()) { michael@0: cookie = e.getNext().QueryInterface(Ci.nsICookie); michael@0: i++; michael@0: } michael@0: is(i, 1, "expected one cookie"); michael@0: michael@0: // remove the cookie michael@0: cs.removeAll(); michael@0: michael@0: // restore the window state michael@0: ss.setWindowState(newWin, state, true); michael@0: michael@0: // at this point, the cookie should be restored... michael@0: e = cs.enumerator; michael@0: let cookie2; michael@0: while (e.hasMoreElements()) { michael@0: cookie2 = e.getNext().QueryInterface(Ci.nsICookie); michael@0: if (cookie.name == cookie2.name) michael@0: break; michael@0: } michael@0: is(cookie.name, cookie2.name, "cookie name successfully restored"); michael@0: is(cookie.value, cookie2.value, "cookie value successfully restored"); michael@0: is(cookie.path, cookie2.path, "cookie path successfully restored"); michael@0: michael@0: // clean up michael@0: if (gPrefService.prefHasUserValue("browser.sessionstore.interval")) michael@0: gPrefService.clearUserPref("browser.sessionstore.interval"); michael@0: cs.removeAll(); michael@0: newWin.close(); michael@0: finish(); michael@0: }); michael@0: }, false); michael@0: } michael@0: