Bug 1253538 - Window.open() should not reuse an existing window if it's running a different container - patch 1, r=bz
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 07 Mar 2016 13:59:47 +0100
changeset 324962 8511fae8a1cf23c3bec72f93ffa5d159c63e72bc
parent 324961 b380eca3966c37ed9a32c990c4991cf622e3dfde
child 324963 0c2cf128ceae933dd54fb078dbf69ee3c0f54cc7
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1253538
milestone47.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 1253538 - Window.open() should not reuse an existing window if it's running a different container - patch 1, r=bz
browser/components/contextualidentity/test/browser/browser.ini
browser/components/contextualidentity/test/browser/browser_windowName.js
browser/components/contextualidentity/test/browser/empty_file.html
--- a/browser/components/contextualidentity/test/browser/browser.ini
+++ b/browser/components/contextualidentity/test/browser/browser.ini
@@ -1,6 +1,8 @@
 [DEFAULT]
 skip-if = buildapp == "mulet"
 support-files =
+  empty_file.html
   file_reflect_cookie_into_title.html
 
 [browser_usercontext.js]
+[browser_windowName.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/contextualidentity/test/browser/browser_windowName.js
@@ -0,0 +1,79 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+
+const USER_CONTEXTS = [
+  "default",
+  "personal",
+  "work",
+];
+
+const BASE_URI = "http://mochi.test:8888/browser/browser/components/"
+  + "contextualidentity/test/browser/empty_file.html";
+
+add_task(function* setup() {
+  // make sure userContext is enabled.
+  SpecialPowers.pushPrefEnv({"set": [
+    ["privacy.userContext.enabled", true],
+    ["browser.link.open_newwindow", 3],
+  ]});
+});
+
+add_task(function* cleanup() {
+  // make sure we don't leave any prefs set for the next tests
+  registerCleanupFunction(function() {
+    SpecialPowers.popPrefEnv();
+  });
+});
+
+add_task(function* test() {
+  info("Creating first tab...");
+  let tab1 = gBrowser.addTab(BASE_URI + '?old', {userContextId: 1});
+  let browser1 = gBrowser.getBrowserForTab(tab1);
+  yield BrowserTestUtils.browserLoaded(browser1);
+  yield ContentTask.spawn(browser1, null, function(opts) {
+    content.window.name = 'tab-1';
+  });
+
+  info("Creating second tab...");
+  let tab2 = gBrowser.addTab(BASE_URI + '?old', {userContextId: 2});
+  let browser2 = gBrowser.getBrowserForTab(tab2);
+  yield BrowserTestUtils.browserLoaded(browser2);
+  yield ContentTask.spawn(browser2, null, function(opts) {
+    content.window.name = 'tab-2';
+  });
+
+  // Let's try to open a window from tab1 with a name 'tab-2'.
+  info("Opening a window from the first tab...");
+  yield ContentTask.spawn(browser1, { url: BASE_URI + '?new' }, function(opts) {
+    yield new content.window.wrappedJSObject.Promise(resolve => {
+      let w = content.window.wrappedJSObject.open(opts.url, 'tab-2');
+      w.onload = function() { resolve(); }
+    });
+  });
+
+  is(browser1.contentDocument.title, '?old', "Tab1 title must be 'old'");
+  is(browser1.contentDocument.nodePrincipal.userContextId, 1, "Tab1 UCI must be 1");
+
+  is(browser2.contentDocument.title, '?old', "Tab2 title must be 'old'");
+  is(browser2.contentDocument.nodePrincipal.userContextId, 2, "Tab2 UCI must be 2");
+
+  let found = false;
+  for (let i = 0; i < gBrowser.tabContainer.childNodes.length; ++i) {
+    let tab = gBrowser.tabContainer.childNodes[i];
+    let browser = gBrowser.getBrowserForTab(tab);
+    if (browser.contentDocument.title == '?new') {
+      is(browser.contentDocument.nodePrincipal.userContextId, 1, "Tab3 UCI must be 1");
+      isnot(browser, browser1, "Tab3 is not browser 1");
+      isnot(browser, browser2, "Tab3 is not browser 2");
+      gBrowser.removeTab(tab);
+      found = true;
+      break;
+    }
+  }
+
+  ok(found, "We have tab3");
+
+  gBrowser.removeTab(tab1);
+  gBrowser.removeTab(tab2);
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/contextualidentity/test/browser/empty_file.html
@@ -0,0 +1,5 @@
+<html><body>
+<script>
+document.title = window.location.search;
+</script>
+</body></html>