browser/components/sessionstore/test/browser_423132.js

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

mercurial