summaryrefslogtreecommitdiffstats
path: root/toolkit/components/contextualidentity/tests/unit/test_migratedFile.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /toolkit/components/contextualidentity/tests/unit/test_migratedFile.js
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/contextualidentity/tests/unit/test_migratedFile.js')
-rw-r--r--toolkit/components/contextualidentity/tests/unit/test_migratedFile.js121
1 files changed, 121 insertions, 0 deletions
diff --git a/toolkit/components/contextualidentity/tests/unit/test_migratedFile.js b/toolkit/components/contextualidentity/tests/unit/test_migratedFile.js
new file mode 100644
index 0000000000..dd05581342
--- /dev/null
+++ b/toolkit/components/contextualidentity/tests/unit/test_migratedFile.js
@@ -0,0 +1,121 @@
+"use strict";
+
+const profileDir = do_get_profile();
+
+const { ContextualIdentityService } = ChromeUtils.importESModule(
+ "resource://gre/modules/ContextualIdentityService.sys.mjs"
+);
+
+const TEST_STORE_FILE_PATH = PathUtils.join(
+ profileDir.path,
+ "test-containers.json"
+);
+
+// Test the containers JSON file migrations.
+add_task(async function migratedFile() {
+ // Let's create a file that has to be migrated.
+ const oldFileData = {
+ version: 2,
+ lastUserContextId: 6,
+ identities: [
+ {
+ userContextId: 1,
+ public: true,
+ icon: "fingerprint",
+ color: "blue",
+ l10nID: "userContextPersonal.label",
+ accessKey: "userContextPersonal.accesskey",
+ },
+ {
+ userContextId: 2,
+ public: true,
+ icon: "briefcase",
+ color: "orange",
+ l10nID: "userContextWork.label",
+ accessKey: "userContextWork.accesskey",
+ },
+ {
+ userContextId: 3,
+ public: true,
+ icon: "dollar",
+ color: "green",
+ l10nID: "userContextBanking.label",
+ accessKey: "userContextBanking.accesskey",
+ },
+ {
+ userContextId: 4,
+ public: true,
+ icon: "cart",
+ color: "pink",
+ l10nID: "userContextShopping.label",
+ accessKey: "userContextShopping.accesskey",
+ },
+ {
+ userContextId: 5,
+ public: false,
+ icon: "",
+ color: "",
+ name: "userContextIdInternal.thumbnail",
+ accessKey: "",
+ },
+ {
+ userContextId: 6,
+ public: true,
+ icon: "cart",
+ color: "ping",
+ name: "Custom user-created identity",
+ },
+ ],
+ };
+
+ await IOUtils.writeJSON(TEST_STORE_FILE_PATH, oldFileData, {
+ tmpPath: TEST_STORE_FILE_PATH + ".tmp",
+ });
+
+ let cis =
+ ContextualIdentityService.createNewInstanceForTesting(TEST_STORE_FILE_PATH);
+ ok(!!cis, "We have our instance of ContextualIdentityService");
+
+ // Check that the custom user-created identity exists.
+
+ const expectedPublicLength = oldFileData.identities.filter(
+ identity => identity.public
+ ).length;
+ const publicIdentities = cis.getPublicIdentities();
+ const oldLastIdentity =
+ oldFileData.identities[oldFileData.identities.length - 1];
+ const customUserCreatedIdentity = publicIdentities
+ .filter(identity => identity.name === oldLastIdentity.name)
+ .pop();
+
+ equal(
+ publicIdentities.length,
+ expectedPublicLength,
+ "We should have the expected number of public identities"
+ );
+ ok(!!customUserCreatedIdentity, "Got the custom user-created identity");
+
+ Assert.deepEqual(
+ cis.getPublicUserContextIds(),
+ cis.getPublicIdentities().map(identity => identity.userContextId),
+ "getPublicUserContextIds has matching user context IDs"
+ );
+
+ // Check that the reserved userContextIdInternal.webextStorageLocal identity exists.
+
+ const webextStorageLocalPrivateId =
+ ContextualIdentityService._defaultIdentities
+ .filter(
+ identity => identity.name === "userContextIdInternal.webextStorageLocal"
+ )
+ .pop().userContextId;
+
+ const privWebExtStorageLocal = cis.getPrivateIdentity(
+ "userContextIdInternal.webextStorageLocal"
+ );
+ equal(
+ privWebExtStorageLocal && privWebExtStorageLocal.userContextId,
+ webextStorageLocalPrivateId,
+ "We should have the default userContextIdInternal.webextStorageLocal private identity"
+ );
+});