From 9d4ffbfc0164b2dbbcf9b21572a1afc4c356a698 Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Thu, 16 Jan 2020 13:54:21 +0000 Subject: [PATCH] Bug 1608545 - ensure userContextId inherited from relatedTab is used throughout addTab and test for it, r=dao Differential Revision: https://phabricator.services.mozilla.com/D60017 --HG-- extra : moz-landing-system : lando --- browser/base/content/tabbrowser.js | 14 ++++++------- .../test/browser/browser_relatedTab.js | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/browser/base/content/tabbrowser.js b/browser/base/content/tabbrowser.js index 3f4d5ca86c5f..9686e14ccdc9 100644 --- a/browser/base/content/tabbrowser.js +++ b/browser/base/content/tabbrowser.js @@ -2634,12 +2634,17 @@ this.tabContainer.getAttribute("overflow") != "true" && this.animationsEnabled; + // Related tab inherits current tab's user context unless a different + // usercontextid is specified + if (userContextId == null && openerTab) { + userContextId = openerTab.getAttribute("usercontextid") || 0; + } + this.setTabAttributes(t, { animate, noInitialLabel, aURI, userContextId, - openerTab, skipBackgroundNotify, pinned, skipAnimation, @@ -3111,7 +3116,6 @@ noInitialLabel, aURI, userContextId, - openerTab, skipBackgroundNotify, pinned, skipAnimation, @@ -3126,12 +3130,6 @@ } } - // Related tab inherits current tab's user context unless a different - // usercontextid is specified - if (userContextId == null && openerTab) { - userContextId = openerTab.getAttribute("usercontextid") || 0; - } - if (userContextId) { tab.setAttribute("usercontextid", userContextId); ContextualIdentityService.setTabStyle(tab); diff --git a/browser/components/contextualidentity/test/browser/browser_relatedTab.js b/browser/components/contextualidentity/test/browser/browser_relatedTab.js index e1024c94114e..207e73f37976 100644 --- a/browser/components/contextualidentity/test/browser/browser_relatedTab.js +++ b/browser/components/contextualidentity/test/browser/browser_relatedTab.js @@ -23,6 +23,11 @@ add_task(async function() { 1, "Related tab (relatedToCurrent) inherits current tab's usercontextid" ); + is( + relatedTab.linkedBrowser.contentPrincipal.userContextId, + 1, + "Related tab's browser actually inherits the current tab's usercontextid" + ); BrowserTestUtils.removeTab(relatedTab); gBrowser.selectedTab = tab; @@ -35,6 +40,11 @@ add_task(async function() { 2, "Related tab (relatedToCurrent) with overridden usercontextid" ); + is( + relatedTab.linkedBrowser.contentPrincipal.userContextId, + 2, + "Related tab's browser actually gets overridden usercontextid" + ); BrowserTestUtils.removeTab(relatedTab); gBrowser.selectedTab = tab; @@ -51,6 +61,11 @@ add_task(async function() { 1, "Related tab (referrer) inherits current tab's usercontextid" ); + is( + relatedTab.linkedBrowser.contentPrincipal.userContextId, + 1, + "Related tab's browser (referrer) actually inherits the current tab's usercontextid" + ); BrowserTestUtils.removeTab(relatedTab); gBrowser.selectedTab = tab; @@ -68,6 +83,11 @@ add_task(async function() { 2, "Related tab (referrer) with overridden usercontextid" ); + is( + relatedTab.linkedBrowser.contentPrincipal.userContextId, + 2, + "Related tab's browser (referrer) actually gets overridden usercontextid" + ); BrowserTestUtils.removeTab(relatedTab); BrowserTestUtils.removeTab(tab);