fune/browser/components/sessionstore/test/browser_423132.js
Kris Maglione 80327d3561 Bug 1484496: Part 5a - Convert browser/ nsISimpleEnumerator users to use JS iteration. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D3729

--HG--
extra : rebase_source : e187b8e9a6b6db7ebc762adda5e489b25c7a7e43
extra : histedit_source : 868cb99d09954a51d6be321fcb516475ef70eb33
2018-08-18 19:27:33 -07:00

50 lines
1.5 KiB
JavaScript

"use strict";
/**
* Tests that cookies are stored and restored correctly
* by sessionstore (bug 423132).
*/
add_task(async 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
await SpecialPowers.pushPrefEnv({
set: [["browser.sessionstore.interval", 0]]
});
let tab = BrowserTestUtils.addTab(gBrowser, testURL);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
await TabStateFlusher.flush(tab.linkedBrowser);
// get the sessionstore state for the window
let state = ss.getBrowserState();
// verify our cookie got set during pageload
let i = 0;
for (var cookie of Services.cookies.enumerator) {
i++;
}
Assert.equal(i, 1, "expected one cookie");
// remove the cookie
Services.cookies.removeAll();
// restore the window state
await setBrowserState(state);
// at this point, the cookie should be restored...
for (var cookie2 of Services.cookies.enumerator) {
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();
BrowserTestUtils.removeTab(gBrowser.tabs[1]);
});