summaryrefslogtreecommitdiffstats
path: root/browser/components/contextualidentity/test/browser/browser_count_and_remove.js
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/contextualidentity/test/browser/browser_count_and_remove.js')
-rw-r--r--browser/components/contextualidentity/test/browser/browser_count_and_remove.js107
1 files changed, 107 insertions, 0 deletions
diff --git a/browser/components/contextualidentity/test/browser/browser_count_and_remove.js b/browser/components/contextualidentity/test/browser/browser_count_and_remove.js
new file mode 100644
index 0000000000..8f044db94e
--- /dev/null
+++ b/browser/components/contextualidentity/test/browser/browser_count_and_remove.js
@@ -0,0 +1,107 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function openTabInUserContext(userContextId) {
+ let tab = BrowserTestUtils.addTab(gBrowser, "about:blank", { userContextId });
+ gBrowser.selectedTab = tab;
+}
+
+add_setup(async function () {
+ // make sure userContext is enabled.
+ await SpecialPowers.pushPrefEnv({
+ set: [["privacy.userContext.enabled", true]],
+ });
+});
+
+add_task(async function test() {
+ is(
+ ContextualIdentityService.countContainerTabs(),
+ 0,
+ "0 container tabs by default."
+ );
+
+ openTabInUserContext(1);
+ is(
+ ContextualIdentityService.countContainerTabs(),
+ 1,
+ "1 container tab created"
+ );
+ is(
+ ContextualIdentityService.countContainerTabs(1),
+ 1,
+ "1 container tab created with id 1"
+ );
+ is(
+ ContextualIdentityService.countContainerTabs(2),
+ 0,
+ "0 container tabs created with id 2"
+ );
+
+ openTabInUserContext(1);
+ is(
+ ContextualIdentityService.countContainerTabs(),
+ 2,
+ "2 container tabs created"
+ );
+ is(
+ ContextualIdentityService.countContainerTabs(1),
+ 2,
+ "2 container tabs created with id 1"
+ );
+ is(
+ ContextualIdentityService.countContainerTabs(2),
+ 0,
+ "0 container tabs created with id 2"
+ );
+
+ openTabInUserContext(2);
+ is(
+ ContextualIdentityService.countContainerTabs(),
+ 3,
+ "3 container tab created"
+ );
+ is(
+ ContextualIdentityService.countContainerTabs(1),
+ 2,
+ "2 container tabs created with id 1"
+ );
+ is(
+ ContextualIdentityService.countContainerTabs(2),
+ 1,
+ "1 container tab created with id 2"
+ );
+
+ await ContextualIdentityService.closeContainerTabs(1);
+ is(
+ ContextualIdentityService.countContainerTabs(),
+ 1,
+ "1 container tab created"
+ );
+ is(
+ ContextualIdentityService.countContainerTabs(1),
+ 0,
+ "0 container tabs created with id 1"
+ );
+ is(
+ ContextualIdentityService.countContainerTabs(2),
+ 1,
+ "1 container tab created with id 2"
+ );
+
+ await ContextualIdentityService.closeContainerTabs();
+ is(
+ ContextualIdentityService.countContainerTabs(),
+ 0,
+ "0 container tabs at the end."
+ );
+ is(
+ ContextualIdentityService.countContainerTabs(1),
+ 0,
+ "0 container tabs at the end with id 1."
+ );
+ is(
+ ContextualIdentityService.countContainerTabs(2),
+ 0,
+ "0 container tabs at the end with id 2."
+ );
+});