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);