summaryrefslogtreecommitdiffstats
path: root/browser/components/contextualidentity/test/browser/browser_tab_color_update.js
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/contextualidentity/test/browser/browser_tab_color_update.js')
-rw-r--r--browser/components/contextualidentity/test/browser/browser_tab_color_update.js42
1 files changed, 42 insertions, 0 deletions
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);
+});