summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_cookies_legacy.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /browser/components/sessionstore/test/browser_cookies_legacy.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/sessionstore/test/browser_cookies_legacy.js')
-rw-r--r--browser/components/sessionstore/test/browser_cookies_legacy.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/browser/components/sessionstore/test/browser_cookies_legacy.js b/browser/components/sessionstore/test/browser_cookies_legacy.js
new file mode 100644
index 0000000000..087c2d516f
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_cookies_legacy.js
@@ -0,0 +1,75 @@
+"use strict";
+
+function createTestState() {
+ let r = Math.round(Math.random() * 100000);
+
+ let cookie = {
+ host: "http://example.com",
+ path: "/",
+ name: `name${r}`,
+ value: `value${r}`,
+ };
+
+ let state = {
+ windows: [
+ {
+ tabs: [
+ { entries: [{ url: "about:robots", triggeringPrincipal_base64 }] },
+ ],
+ cookies: [cookie],
+ },
+ ],
+ };
+
+ return [state, cookie];
+}
+
+function waitForNewCookie({ host, name, value }) {
+ info(`waiting for cookie ${name}=${value} from ${host}...`);
+
+ return new Promise(resolve => {
+ Services.obs.addObserver(function observer(subj, topic, data) {
+ if (data != "added") {
+ return;
+ }
+
+ let cookie = subj.QueryInterface(Ci.nsICookie);
+ if (cookie.host == host && cookie.name == name && cookie.value == value) {
+ ok(true, "cookie added by the cookie service");
+ Services.obs.removeObserver(observer, topic);
+ resolve();
+ }
+ }, "session-cookie-changed");
+ });
+}
+
+// Setup and cleanup.
+add_task(async function test_setup() {
+ Services.cookies.removeAll();
+
+ registerCleanupFunction(() => {
+ Services.cookies.removeAll();
+ });
+});
+
+// Test that calling ss.setWindowState() with a legacy state object that
+// contains cookies in the window state restores session cookies properly.
+add_task(async function test_window() {
+ let [state, cookie] = createTestState();
+ let win = await promiseNewWindowLoaded();
+
+ let promiseCookie = waitForNewCookie(cookie);
+ ss.setWindowState(win, JSON.stringify(state), true);
+ await promiseCookie;
+
+ await BrowserTestUtils.closeWindow(win);
+});
+
+// Test that calling ss.setBrowserState() with a legacy state object that
+// contains cookies in the window state restores session cookies properly.
+add_task(async function test_browser() {
+ let backupState = ss.getBrowserState();
+ let [state, cookie] = createTestState();
+ await Promise.all([waitForNewCookie(cookie), promiseBrowserState(state)]);
+ await promiseBrowserState(backupState);
+});