gecko-dev/browser/components/sessionstore/test/browser_423132.js
Dão Gottwald 39669a550b Bug 1054740 - Stop reusing tabs when restoring windows since at this point it's counterproductive rather than a useful optimization. r=mikedeboer
MozReview-Commit-ID: EuM08mEhDqZ

--HG--
extra : rebase_source : 43fc0410045f0efe48db2ae14d56994a90bded5f
2017-05-04 14:26:32 +02:00

56 lines
1.7 KiB
JavaScript

"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 tab = gBrowser.addTab(testURL);
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
yield TabStateFlusher.flush(tab.linkedBrowser);
// get the sessionstore state for the window
let state = ss.getBrowserState();
// 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.setBrowserState(state);
// 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 promiseRemoveTab(gBrowser.tabs[1]);
});