tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_cookie_sync_across_tabs.js (2365B)


      1 /*
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 "use strict";
      7 
      8 add_task(async function () {
      9  info("Make sure cookie changes in one process are visible in the other");
     10 
     11  const kRoot = getRootDirectory(gTestPath).replace(
     12    "chrome://mochitests/content/",
     13    "https://example.com/"
     14  );
     15  const kTestPage = kRoot + "dummy.html";
     16 
     17  Services.cookies.removeAll();
     18 
     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  });
     29 
     30  let browser1 = gBrowser.getBrowserForTab(tab1);
     31  let browser2 = gBrowser.getBrowserForTab(tab2);
     32 
     33  let pid1 = browser1.frameLoader.remoteTab.osPid;
     34  let pid2 = browser2.frameLoader.remoteTab.osPid;
     35 
     36  // Note, this might not be true once fission is implemented (Bug 1451850)
     37  Assert.notEqual(pid1, pid2, "We should have different processes here.");
     38 
     39  await SpecialPowers.spawn(browser1, [], async function () {
     40    is(content.document.cookie, "", "Expecting no cookies");
     41  });
     42 
     43  await SpecialPowers.spawn(browser2, [], async function () {
     44    is(content.document.cookie, "", "Expecting no cookies");
     45  });
     46 
     47  await SpecialPowers.spawn(browser1, [], async function () {
     48    content.document.cookie = "a1=test";
     49  });
     50 
     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  });
     55 
     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  });
     60 
     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  });
     70 
     71  await SpecialPowers.spawn(browser1, [], async function () {
     72    is(content.document.cookie, "", "Cookies should be cleared");
     73  });
     74 
     75  BrowserTestUtils.removeTab(tab1);
     76  BrowserTestUtils.removeTab(tab2);
     77 
     78  ok(true, "Got to the end of the test!");
     79 });