Bug 1501244 - Preserve privateBrowsingId OA when userContextId is set r=Gijs
authorRob Wu <rob@robwu.nl>
Wed, 24 Oct 2018 21:23:17 +0000
changeset 512708 4b9c119d25c3
parent 512707 d0b51a908bec
child 512709 f4fc0e5c9d4a
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1501244
milestone66.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 1501244 - Preserve privateBrowsingId OA when userContextId is set r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D9535
browser/base/content/browser.js
browser/components/contextualidentity/test/browser/browser.ini
browser/components/contextualidentity/test/browser/browser_usercontextid_new_window.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1061,17 +1061,20 @@ function _loadURI(browser, uri, params =
 
   // !requiredRemoteType means we're loading in the parent/this process.
   if (!requiredRemoteType) {
     browser.inLoadURI = true;
   }
   try {
     if (!mustChangeProcess) {
       if (userContextId) {
-        browser.webNavigation.setOriginAttributesBeforeLoading({ userContextId });
+        browser.webNavigation.setOriginAttributesBeforeLoading({
+          userContextId,
+          privateBrowsingId: PrivateBrowsingUtils.isBrowserPrivate(browser) ? 1 : 0,
+        });
       }
 
       browser.webNavigation.loadURIWithOptions(uri, flags,
                                                referrerURI, referrerPolicy,
                                                postData, null, null, triggeringPrincipal);
     } else {
       // Check if the current browser is allowed to unload.
       let {permitUnload, timedOut} = browser.permitUnload();
@@ -1108,17 +1111,20 @@ function _loadURI(browser, uri, params =
     // We might lose history that way but at least the browser loaded a page.
     // This might be necessary if SessionStore wasn't initialized yet i.e.
     // when the homepage is a non-remote page.
     if (mustChangeProcess) {
       Cu.reportError(e);
       gBrowser.updateBrowserRemotenessByURL(browser, uri);
 
       if (userContextId) {
-        browser.webNavigation.setOriginAttributesBeforeLoading({ userContextId });
+        browser.webNavigation.setOriginAttributesBeforeLoading({
+          userContextId,
+          privateBrowsingId: PrivateBrowsingUtils.isBrowserPrivate(browser) ? 1 : 0,
+        });
       }
 
       browser.webNavigation.loadURIWithOptions(uri, flags, referrerURI, referrerPolicy,
                                                postData, null, null, triggeringPrincipal);
     } else {
       throw e;
     }
   } finally {
--- a/browser/components/contextualidentity/test/browser/browser.ini
+++ b/browser/components/contextualidentity/test/browser/browser.ini
@@ -13,16 +13,17 @@ support-files =
 [browser_forgetaboutsite.js]
 [browser_forgetAPI_cookie_getCookiesWithOriginAttributes.js]
 [browser_restore_getCookiesWithOriginAttributes.js]
 [browser_forgetAPI_EME_forgetThisSite.js]
 [browser_forgetAPI_quota_clearStoragesForPrincipal.js]
 skip-if = verify
 [browser_newtabButton.js]
 [browser_usercontext.js]
+[browser_usercontextid_new_window.js]
 [browser_usercontextid_tabdrop.js]
 skip-if = os == "mac" || os == "win" # Intermittent failure - bug 1268276
 [browser_windowName.js]
 tags = openwindow
 [browser_windowOpen.js]
 tags = openwindow
 [browser_serviceworkers.js]
 [browser_broadcastchannel.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/contextualidentity/test/browser/browser_usercontextid_new_window.js
@@ -0,0 +1,71 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test that the content of new browser windows have the expected
+// userContextId when it passed as the window arguments.
+
+const TEST_URI = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://mochi.test:8888") + "empty_file.html";
+
+function openWindowWithUserContextId(userContextId, isPrivate) {
+  let flags = "chrome,dialog=no,all";
+  if (isPrivate) {
+    flags += ",private";
+  }
+
+  let args = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
+
+  let urlSupports = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
+  urlSupports.data = TEST_URI;
+  args.appendElement(urlSupports);
+
+  args.appendElement(null);
+  args.appendElement(null);
+  args.appendElement(null);
+  args.appendElement(null);
+  args.appendElement(null);
+
+  let userContextIdSupports = Cc["@mozilla.org/supports-PRUint32;1"].createInstance(Ci.nsISupportsPRUint32);
+  userContextIdSupports.data = userContextId;
+  args.appendElement(userContextIdSupports);
+
+  args.appendElement(Services.scriptSecurityManager.getSystemPrincipal());
+  args.appendElement(Services.scriptSecurityManager.getSystemPrincipal());
+
+  let windowPromise = BrowserTestUtils.waitForNewWindow({url: TEST_URI});
+  Services.ww.openWindow(null, AppConstants.BROWSER_CHROME_URL, "_blank", flags, args);
+  return windowPromise;
+}
+
+add_task(async function setup() {
+  await SpecialPowers.pushPrefEnv({"set": [
+    ["privacy.userContext.enabled", true],
+  ]});
+});
+
+add_task(async function test_new_window() {
+  let win = await openWindowWithUserContextId(1, false);
+
+  await ContentTask.spawn(win.gBrowser.selectedBrowser, TEST_URI, (url) => {
+    Assert.equal(content.document.URL, url, "expected document URL");
+    let {originAttributes} = content.document.nodePrincipal;
+    Assert.equal(originAttributes.userContextId, 1, "expected userContextId");
+    Assert.equal(originAttributes.privateBrowsingId, 0, "expected non-private context");
+  });
+
+  await BrowserTestUtils.closeWindow(win);
+});
+
+add_task(async function test_new_private_window() {
+  let win = await openWindowWithUserContextId(1, true);
+
+  await ContentTask.spawn(win.gBrowser.selectedBrowser, TEST_URI, (url) => {
+    Assert.equal(content.document.URL, url, "expected document URL");
+    let {originAttributes} = content.document.nodePrincipal;
+    Assert.equal(originAttributes.userContextId, 1, "expected userContextId");
+    Assert.equal(originAttributes.privateBrowsingId, 1, "expected private context");
+  });
+
+  await BrowserTestUtils.closeWindow(win);
+});