browser_cookies_partitioned.js (2035B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Bug 1922193 - Test that session restore can restore partitioned cookies 8 * without the isPartitioned flag in the session cookie state. And verify the 9 * isPartitioned flag is correctly set on the restored cookie. 10 */ 11 12 const TEST_HOST = "example.com"; 13 const TEST_URL = `https://${TEST_HOST}`; 14 const MAX_EXPIRY = Math.pow(2, 62); 15 16 add_setup(async function () { 17 // Make sure that sessionstore.js can be forced to be created by setting 18 // the interval pref to 0. 19 await SpecialPowers.pushPrefEnv({ 20 set: [["browser.sessionstore.interval", 0]], 21 }); 22 }); 23 24 add_task(async function runTest() { 25 Services.cookies.removeAll(); 26 27 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL); 28 29 // Add a partitioned cookie. 30 const cv = Services.cookies.add( 31 TEST_HOST, 32 "/", 33 "foo", 34 "bar", 35 true, 36 false, 37 true, 38 MAX_EXPIRY, 39 { partitionKey: "(https,example.com)" }, 40 Ci.nsICookie.SAMESITE_NONE, 41 Ci.nsICookie.SCHEME_HTTPS, 42 true 43 ); 44 is(cv.result, Ci.nsICookieValidation.eOK, "Valid cookie"); 45 46 await TabStateFlusher.flush(tab.linkedBrowser); 47 48 // Get the sessionstore state for the window. 49 let state = ss.getBrowserState(); 50 51 // Remove the isPartitioned flag from the stored cookie. 52 state = JSON.parse(state); 53 delete state.cookies[0].isPartitioned; 54 state = JSON.stringify(state); 55 56 // Remove the cookie. 57 Services.cookies.removeAll(); 58 59 // Restore the window state. 60 await setBrowserState(state); 61 62 // One cookie should be restored. 63 is(Services.cookies.cookies.length, 1, "One cookie should be restored."); 64 65 let cookie = Services.cookies.cookies[0]; 66 is(cookie.name, "foo", "The cookie name should be foo."); 67 is(cookie.value, "bar", "The cookie value should be bar."); 68 ok(cookie.isPartitioned, "The isPartitioned flag should be set."); 69 70 // Clean up. 71 Services.cookies.removeAll(); 72 BrowserTestUtils.removeTab(tab); 73 });