Bug 1455970 - Write test for cookies being synced across tabs r=Ehsan
authorValentin Gosu <valentin.gosu@gmail.com>
Sun, 22 Apr 2018 17:35:20 +0200
changeset 469121 a564665d8c0948fbc8c3bae884fc7b1118661b2f
parent 469120 707d5e397407bdee7cdfbb5ee6ff644126b778a9
child 469122 252a244dc3d4b91d81a2e170143aeaf2802a225e
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1455970, 1450199
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1455970 - Write test for cookies being synced across tabs r=Ehsan Adds a test for code landed in bug 1450199. Opens two tabs in different processes then sets cookies in one followed by checking the value in the other. MozReview-Commit-ID: 605k68Kl7nA
netwerk/test/browser/browser.ini
netwerk/test/browser/browser_cookie_sync_across_tabs.js
--- a/netwerk/test/browser/browser.ini
+++ b/netwerk/test/browser/browser.ini
@@ -5,8 +5,9 @@ support-files =
 [browser_about_cache.js]
 [browser_NetUtil.js]
 [browser_child_resource.js]
 skip-if = !crashreporter || (e10s && debug && os == "linux" && bits == 64) || debug # Bug 1370783
 [browser_post_file.js]
 [browser_nsIFormPOSTActionChannel.js]
 skip-if = e10s # protocol handler and channel does not work in content process
 [browser_resource_navigation.js]
+[browser_cookie_sync_across_tabs.js]
new file mode 100644
--- /dev/null
+++ b/netwerk/test/browser/browser_cookie_sync_across_tabs.js
@@ -0,0 +1,65 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+"use strict";
+
+add_task(async function() {
+  info("Make sure cookie changes in one process are visible in the other");
+
+  const kRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/",
+                                                    "https://example.com/");
+  const kTestPage = kRoot + "dummy.html";
+
+  Services.cookies.removeAll();
+
+  let tab1 = await BrowserTestUtils.openNewForegroundTab({ gBrowser, url: kTestPage, forceNewProcess: true });
+  let tab2 = await BrowserTestUtils.openNewForegroundTab({ gBrowser, url: kTestPage, forceNewProcess: true });
+
+  let browser1 = gBrowser.getBrowserForTab(tab1);
+  let browser2 = gBrowser.getBrowserForTab(tab2);
+
+  let pid1 = browser1.frameLoader.tabParent.osPid;
+  let pid2 = browser2.frameLoader.tabParent.osPid;
+
+  // Note, this might not be true once fission is implemented (Bug 1451850)
+  ok(pid1 != pid2, "We should have different processes here.");
+
+  await ContentTask.spawn(browser1, null, async function() {
+    is(content.document.cookie, "", "Expecting no cookies");
+  });
+
+  await ContentTask.spawn(browser2, null, async function() {
+    is(content.document.cookie, "", "Expecting no cookies");
+  });
+
+  await ContentTask.spawn(browser1, null, async function() {
+    content.document.cookie = "a1=test";
+  });
+
+  await ContentTask.spawn(browser2, null, async function() {
+    is(content.document.cookie, "a1=test", "Cookie should be set");
+    content.document.cookie = "a1=other_test";
+  });
+
+  await ContentTask.spawn(browser1, null, async function() {
+    is(content.document.cookie, "a1=other_test", "Cookie should be set");
+    content.document.cookie = "a2=again";
+  });
+
+  await ContentTask.spawn(browser2, null, async function() {
+    is(content.document.cookie, "a1=other_test; a2=again", "Cookie should be set");
+    content.document.cookie = "a1=; expires=Thu, 01-Jan-1970 00:00:01 GMT;";
+    content.document.cookie = "a2=; expires=Thu, 01-Jan-1970 00:00:01 GMT;";
+  });
+
+  await ContentTask.spawn(browser1, null, async function() {
+    is(content.document.cookie, "", "Cookies should be cleared");
+  });
+
+  BrowserTestUtils.removeTab(tab1);
+  BrowserTestUtils.removeTab(tab2);
+
+  ok(true, "Got to the end of the test!");
+});