From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- ...t_extension_permissions_migrate_kvstore_path.js | 234 +++++++++++++++++++++ 1 file changed, 234 insertions(+) create mode 100644 toolkit/components/extensions/test/xpcshell/test_extension_permissions_migrate_kvstore_path.js (limited to 'toolkit/components/extensions/test/xpcshell/test_extension_permissions_migrate_kvstore_path.js') diff --git a/toolkit/components/extensions/test/xpcshell/test_extension_permissions_migrate_kvstore_path.js b/toolkit/components/extensions/test/xpcshell/test_extension_permissions_migrate_kvstore_path.js new file mode 100644 index 0000000000..5f1c73dd3b --- /dev/null +++ b/toolkit/components/extensions/test/xpcshell/test_extension_permissions_migrate_kvstore_path.js @@ -0,0 +1,234 @@ +"use strict"; + +const { + ExtensionPermissions, + OLD_RKV_DIRNAME, + RKV_DIRNAME, + VERSION_KEY, + VERSION_VALUE, +} = ChromeUtils.importESModule( + "resource://gre/modules/ExtensionPermissions.sys.mjs" +); +const { FileTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/FileTestUtils.sys.mjs" +); +const { FileUtils } = ChromeUtils.importESModule( + "resource://gre/modules/FileUtils.sys.mjs" +); +const { KeyValueService } = ChromeUtils.importESModule( + "resource://gre/modules/kvstore.sys.mjs" +); + +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). + ExtensionPermissions._useLegacyStorageBackend = false; + await ExtensionPermissions._uninit(); +}); + +// NOTE: this test lives in its own test file to make sure it is isolated +// from other tests that would be creating the kvstore instance and +// would prevent this test to properly simulate the kvstore path migration. +add_task(async function test_migrate_to_separate_kvstore_store_path() { + const ADDON_ID_01 = "test-addon-01@test-extension"; + const ADDON_ID_02 = "test-addon-02@test-extension"; + // This third test extension is only used as the one that should + // have some content scripts stored in ExtensionScriptingStore. + const ADDON_ID_03 = "test-addon-03@test-extension"; + + const oldStorePath = FileUtils.getDir("ProfD", [OLD_RKV_DIRNAME]).path; + const newStorePath = FileUtils.getDir("ProfD", [RKV_DIRNAME]).path; + + // Verify that we are going to be using the expected backend, and that + // the rkv path migration is only enabled by default in Nightly builds. + info("Verify test environment match the expected pre-conditions"); + + const permsStore = ExtensionPermissions._getStore(); + equal( + permsStore.constructor.name, + "PermissionStore", + "active ExtensionPermissions store should be an instance of PermissionStore" + ); + + equal( + permsStore._shouldMigrateFromOldKVStorePath, + AppConstants.NIGHTLY_BUILD, + "ExtensionPermissions rkv migration expected to be enabled by default only in Nightly" + ); + + info( + "Uninitialize ExtensionPermissions and make sure no existing kvstore dir" + ); + await ExtensionPermissions._uninit({ recreateStore: false }); + equal( + ExtensionPermissions._getStore(), + null, + "PermissionStore has been nullified" + ); + await IOUtils.remove(oldStorePath, { ignoreAbsent: true, recursive: true }); + await IOUtils.remove(newStorePath, { ignoreAbsent: true, recursive: true }); + + info("Create an existing kvstore dir on the old path"); + + // Populated the kvstore with some expected permissions. + const expectedPermsAddon01 = { + permissions: ["tabs"], + origins: ["http://*/*"], + }; + const expectedPermsAddon02 = { + permissions: ["proxy"], + origins: ["https://*/*"], + }; + + const expectedScriptAddon01 = { + id: "script-addon-01", + allFrames: false, + matches: [""], + js: ["/test-script-addon-01.js"], + persistAcrossSessions: true, + runAt: "document_end", + }; + + const expectedScriptAddon02 = { + id: "script-addon-02", + allFrames: false, + matches: ["