Backed out 2 changesets (bug 1881078, bug 1879806) for causing dt failures @ devtools...
[gecko.git] / netwerk / test / browser / browser_cookie_sync_across_tabs.js
blob483169ed44503679a1b9d130e259438609c1b0f1
1 /*
2  * Any copyright is dedicated to the Public Domain.
3  * http://creativecommons.org/publicdomain/zero/1.0/
4  */
6 "use strict";
8 add_task(async function () {
9   info("Make sure cookie changes in one process are visible in the other");
11   const kRoot = getRootDirectory(gTestPath).replace(
12     "chrome://mochitests/content/",
13     "https://example.com/"
14   );
15   const kTestPage = kRoot + "dummy.html";
17   Services.cookies.removeAll();
19   let tab1 = await BrowserTestUtils.openNewForegroundTab({
20     gBrowser,
21     url: kTestPage,
22     forceNewProcess: true,
23   });
24   let tab2 = await BrowserTestUtils.openNewForegroundTab({
25     gBrowser,
26     url: kTestPage,
27     forceNewProcess: true,
28   });
30   let browser1 = gBrowser.getBrowserForTab(tab1);
31   let browser2 = gBrowser.getBrowserForTab(tab2);
33   let pid1 = browser1.frameLoader.remoteTab.osPid;
34   let pid2 = browser2.frameLoader.remoteTab.osPid;
36   // Note, this might not be true once fission is implemented (Bug 1451850)
37   Assert.notEqual(pid1, pid2, "We should have different processes here.");
39   await SpecialPowers.spawn(browser1, [], async function () {
40     is(content.document.cookie, "", "Expecting no cookies");
41   });
43   await SpecialPowers.spawn(browser2, [], async function () {
44     is(content.document.cookie, "", "Expecting no cookies");
45   });
47   await SpecialPowers.spawn(browser1, [], async function () {
48     content.document.cookie = "a1=test";
49   });
51   await SpecialPowers.spawn(browser2, [], async function () {
52     is(content.document.cookie, "a1=test", "Cookie should be set");
53     content.document.cookie = "a1=other_test";
54   });
56   await SpecialPowers.spawn(browser1, [], async function () {
57     is(content.document.cookie, "a1=other_test", "Cookie should be set");
58     content.document.cookie = "a2=again";
59   });
61   await SpecialPowers.spawn(browser2, [], async function () {
62     is(
63       content.document.cookie,
64       "a1=other_test; a2=again",
65       "Cookie should be set"
66     );
67     content.document.cookie = "a1=; expires=Thu, 01-Jan-1970 00:00:01 GMT;";
68     content.document.cookie = "a2=; expires=Thu, 01-Jan-1970 00:00:01 GMT;";
69   });
71   await SpecialPowers.spawn(browser1, [], async function () {
72     is(content.document.cookie, "", "Cookies should be cleared");
73   });
75   BrowserTestUtils.removeTab(tab1);
76   BrowserTestUtils.removeTab(tab2);
78   ok(true, "Got to the end of the test!");
79 });