summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_423132.js
blob: 584002cff842541de1579a76123d89a50201d076 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"use strict";

/**
 * Tests that cookies are stored and restored correctly
 * by sessionstore (bug 423132).
 */
add_task(function*() {
  const testURL = "http://mochi.test:8888/browser/" +
    "browser/components/sessionstore/test/browser_423132_sample.html";

  Services.cookies.removeAll();
  // make sure that sessionstore.js can be forced to be created by setting
  // the interval pref to 0
  yield SpecialPowers.pushPrefEnv({
    set: [["browser.sessionstore.interval", 0]]
  });

  let win = yield BrowserTestUtils.openNewBrowserWindow();
  let browser = win.gBrowser.selectedBrowser;
  browser.loadURI(testURL);
  yield BrowserTestUtils.browserLoaded(browser);

  yield TabStateFlusher.flush(browser);

  // get the sessionstore state for the window
  let state = ss.getWindowState(win);

  // verify our cookie got set during pageload
  let enumerator = Services.cookies.enumerator;
  let cookie;
  let i = 0;
  while (enumerator.hasMoreElements()) {
    cookie = enumerator.getNext().QueryInterface(Ci.nsICookie);
    i++;
  }
  Assert.equal(i, 1, "expected one cookie");

  // remove the cookie
  Services.cookies.removeAll();

  // restore the window state
  ss.setWindowState(win, state, true);

  // at this point, the cookie should be restored...
  enumerator = Services.cookies.enumerator;
  let cookie2;
  while (enumerator.hasMoreElements()) {
    cookie2 = enumerator.getNext().QueryInterface(Ci.nsICookie);
    if (cookie.name == cookie2.name)
      break;
  }
  is(cookie.name, cookie2.name, "cookie name successfully restored");
  is(cookie.value, cookie2.value, "cookie value successfully restored");
  is(cookie.path, cookie2.path, "cookie path successfully restored");

  // clean up
  Services.cookies.removeAll();
  yield BrowserTestUtils.closeWindow(win);
});