browser/components/sessionstore/test/browser_423132.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/sessionstore/test/browser_423132.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +function test() {
     1.9 +  // test that cookies are stored and restored correctly by sessionstore,
    1.10 +  // bug 423132.
    1.11 +
    1.12 +  waitForExplicitFinish();
    1.13 +
    1.14 +  let cs = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2);
    1.15 +  cs.removeAll();
    1.16 +
    1.17 +  // make sure that sessionstore.js can be forced to be created by setting
    1.18 +  // the interval pref to 0
    1.19 +  gPrefService.setIntPref("browser.sessionstore.interval", 0);
    1.20 +
    1.21 +  const testURL = "http://mochi.test:8888/browser/" +
    1.22 +    "browser/components/sessionstore/test/browser_423132_sample.html";
    1.23 +
    1.24 +  // open a new window
    1.25 +  let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", "about:blank");
    1.26 +
    1.27 +  // make sure sessionstore saves the cookie data, then close the window
    1.28 +  newWin.addEventListener("load", function (aEvent) {
    1.29 +    newWin.removeEventListener("load", arguments.callee, false);
    1.30 +
    1.31 +    newWin.gBrowser.loadURI(testURL, null, null);
    1.32 +
    1.33 +    whenBrowserLoaded(newWin.gBrowser.selectedBrowser, function() {
    1.34 +      // get the sessionstore state for the window
    1.35 +      SyncHandlers.get(newWin.gBrowser.selectedBrowser).flush();
    1.36 +      let state = ss.getWindowState(newWin);
    1.37 +
    1.38 +      // verify our cookie got set during pageload
    1.39 +      let e = cs.enumerator;
    1.40 +      let cookie;
    1.41 +      let i = 0;
    1.42 +      while (e.hasMoreElements()) {
    1.43 +        cookie = e.getNext().QueryInterface(Ci.nsICookie);
    1.44 +        i++;
    1.45 +      }
    1.46 +      is(i, 1, "expected one cookie");
    1.47 +
    1.48 +      // remove the cookie
    1.49 +      cs.removeAll();
    1.50 +
    1.51 +      // restore the window state
    1.52 +      ss.setWindowState(newWin, state, true);
    1.53 +
    1.54 +      // at this point, the cookie should be restored...
    1.55 +      e = cs.enumerator;
    1.56 +      let cookie2;
    1.57 +      while (e.hasMoreElements()) {
    1.58 +        cookie2 = e.getNext().QueryInterface(Ci.nsICookie);
    1.59 +        if (cookie.name == cookie2.name)
    1.60 +          break;
    1.61 +      }
    1.62 +      is(cookie.name, cookie2.name, "cookie name successfully restored");
    1.63 +      is(cookie.value, cookie2.value, "cookie value successfully restored");
    1.64 +      is(cookie.path, cookie2.path, "cookie path successfully restored");
    1.65 +
    1.66 +      // clean up
    1.67 +      if (gPrefService.prefHasUserValue("browser.sessionstore.interval"))
    1.68 +        gPrefService.clearUserPref("browser.sessionstore.interval");
    1.69 +      cs.removeAll();
    1.70 +      newWin.close();
    1.71 +      finish();
    1.72 +    });
    1.73 +  }, false);
    1.74 +}
    1.75 +

mercurial