summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/test_extension_permissions_migration.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /toolkit/components/extensions/test/xpcshell/test_extension_permissions_migration.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/extensions/test/xpcshell/test_extension_permissions_migration.js')
-rw-r--r--toolkit/components/extensions/test/xpcshell/test_extension_permissions_migration.js112
1 files changed, 112 insertions, 0 deletions
diff --git a/toolkit/components/extensions/test/xpcshell/test_extension_permissions_migration.js b/toolkit/components/extensions/test/xpcshell/test_extension_permissions_migration.js
new file mode 100644
index 0000000000..aa05377e0e
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/test_extension_permissions_migration.js
@@ -0,0 +1,112 @@
+"use strict";
+
+const {
+ ExtensionPermissions,
+ OLD_JSON_FILENAME,
+ OLD_RKV_DIRNAME,
+ RKV_DIRNAME,
+} = ChromeUtils.importESModule(
+ "resource://gre/modules/ExtensionPermissions.sys.mjs"
+);
+
+const GOOD_JSON_FILE = {
+ "wikipedia@search.mozilla.org": {
+ permissions: ["internal:privateBrowsingAllowed"],
+ origins: [],
+ },
+ "amazon@search.mozilla.org": {
+ permissions: ["internal:privateBrowsingAllowed"],
+ origins: [],
+ },
+ "doh-rollout@mozilla.org": {
+ permissions: ["internal:privateBrowsingAllowed"],
+ origins: [],
+ },
+};
+
+const BAD_JSON_FILE = {
+ "test@example.org": "what",
+};
+
+const BAD_FILE = "what is this { } {";
+
+const gOldJSONPath = FileUtils.getDir("ProfD", [OLD_JSON_FILENAME]).path;
+const gOldRkvPath = FileUtils.getDir("ProfD", [OLD_RKV_DIRNAME]).path;
+const gNewRkvPath = FileUtils.getDir("ProfD", [RKV_DIRNAME]).path;
+
+async function test_file(json, extensionIds, expected, fileDeleted) {
+ await ExtensionPermissions._resetVersion();
+ await ExtensionPermissions._uninit();
+
+ await IOUtils.writeUTF8(gOldJSONPath, json);
+
+ for (let extensionId of extensionIds) {
+ let permissions = await ExtensionPermissions.get(extensionId);
+ Assert.deepEqual(permissions, expected, "permissions match");
+ }
+
+ Assert.equal(
+ await IOUtils.exists(gOldJSONPath),
+ !fileDeleted,
+ "old file was deleted"
+ );
+
+ Assert.ok(
+ await IOUtils.exists(gNewRkvPath),
+ "found the store at the new rkv path"
+ );
+
+ Assert.ok(
+ !(await IOUtils.exists(gOldRkvPath)),
+ "expect old rkv path to not exist"
+ );
+}
+
+add_setup(async () => {
+ // Bug 1646182: Force ExtensionPermissions to run in rkv mode, because this
+ // test does not make sense with the legacy method (which will be removed in
+ // the above bug).
+ await ExtensionPermissions._uninit();
+});
+
+add_task(async function test_migrate_good_json() {
+ let expected = {
+ permissions: ["internal:privateBrowsingAllowed"],
+ origins: [],
+ };
+
+ await test_file(
+ JSON.stringify(GOOD_JSON_FILE),
+ [
+ "wikipedia@search.mozilla.org",
+ "amazon@search.mozilla.org",
+ "doh-rollout@mozilla.org",
+ ],
+ expected,
+ /* fileDeleted */ true
+ );
+});
+
+add_task(async function test_migrate_bad_json() {
+ let expected = { permissions: [], origins: [] };
+
+ await test_file(
+ BAD_FILE,
+ ["test@example.org"],
+ expected,
+ /* fileDeleted */ false
+ );
+ await IOUtils.remove(gOldJSONPath);
+});
+
+add_task(async function test_migrate_bad_file() {
+ let expected = { permissions: [], origins: [] };
+
+ await test_file(
+ JSON.stringify(BAD_JSON_FILE),
+ ["test2@example.org"],
+ expected,
+ /* fileDeleted */ false
+ );
+ await IOUtils.remove(gOldJSONPath);
+});