From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../test/browser/browser_tab_color_update.js | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 browser/components/contextualidentity/test/browser/browser_tab_color_update.js (limited to 'browser/components/contextualidentity/test/browser/browser_tab_color_update.js') diff --git a/browser/components/contextualidentity/test/browser/browser_tab_color_update.js b/browser/components/contextualidentity/test/browser/browser_tab_color_update.js new file mode 100644 index 0000000000..e4ae649d0a --- /dev/null +++ b/browser/components/contextualidentity/test/browser/browser_tab_color_update.js @@ -0,0 +1,42 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +async function openTabInUserContext(uri, userContextId) { + // open the tab in the correct userContextId + let tab = BrowserTestUtils.addTab(gBrowser, uri, { userContextId }); + + let browser = gBrowser.getBrowserForTab(tab); + await BrowserTestUtils.browserLoaded(browser, false, uri); + return { tab }; +} + +/** + * When a container's colour changes, the tab colour should update. + */ +add_task(async function test_tab_color_updates() { + const kId = 2; + let { tab } = await openTabInUserContext("https://example.com/", kId); + let contextIdInfo = ContextualIdentityService.getPublicIdentityFromId(kId); + ok( + tab.classList.contains("identity-color-" + contextIdInfo.color), + `Should use color ${contextIdInfo.color} for tab` + ); + + // The container has a localized name which isn't in the contextIdInfo object. + // We need to pass a valid name for the update to go through, so make one up. + let name = "Foo"; + // Don't hardcode a colour so changes in defaults won't cause the following + // test to fail or be a no-op. + let otherColor = contextIdInfo.color == "green" ? "orange" : "green"; + registerCleanupFunction(() => ContextualIdentityService.resetDefault()); + ContextualIdentityService.update(kId, name, contextIdInfo.icon, otherColor); + + ok( + tab.classList.contains("identity-color-" + otherColor), + `Should use color ${otherColor} for tab after update` + ); + + BrowserTestUtils.removeTab(tab); +}); -- cgit v1.2.3