browser/components/sessionstore/test/browser_423132.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 function test() {
     6   // test that cookies are stored and restored correctly by sessionstore,
     7   // bug 423132.
     9   waitForExplicitFinish();
    11   let cs = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2);
    12   cs.removeAll();
    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);
    18   const testURL = "http://mochi.test:8888/browser/" +
    19     "browser/components/sessionstore/test/browser_423132_sample.html";
    21   // open a new window
    22   let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", "about:blank");
    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);
    28     newWin.gBrowser.loadURI(testURL, null, null);
    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);
    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");
    45       // remove the cookie
    46       cs.removeAll();
    48       // restore the window state
    49       ss.setWindowState(newWin, state, true);
    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");
    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 }

mercurial