diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /toolkit/components/search/tests/xpcshell/test_webextensions_startup.js | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/search/tests/xpcshell/test_webextensions_startup.js')
-rw-r--r-- | toolkit/components/search/tests/xpcshell/test_webextensions_startup.js | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/toolkit/components/search/tests/xpcshell/test_webextensions_startup.js b/toolkit/components/search/tests/xpcshell/test_webextensions_startup.js new file mode 100644 index 0000000000..0f106a2495 --- /dev/null +++ b/toolkit/components/search/tests/xpcshell/test_webextensions_startup.js @@ -0,0 +1,111 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests to ensure that WebExtensions correctly load on startup without errors. + */ + +"use strict"; + +const lazy = {}; + +ChromeUtils.defineESModuleGetters(lazy, { + ExtensionTestUtils: + "resource://testing-common/ExtensionXPCShellUtils.sys.mjs", +}); + +const { promiseShutdownManager, promiseStartupManager } = AddonTestUtils; + +let extension; + +add_setup(async function () { + let server = useHttpServer(); + server.registerContentType("sjs", "sjs"); + await SearchTestUtils.useTestEngines("test-extensions"); + await promiseStartupManager(); + + registerCleanupFunction(async () => { + await promiseShutdownManager(); + }); +}); + +add_task(async function test_startup_with_new_addon() { + // Although rare, handling loading an add-on on startup should work. + // Additionally, this sub-test allows us to pre-fill the search settings + // for the subsequent tests. + + // Do not use SearchTestUtils.installSearchExtension, as we need to manually + // start the search service after installing the extension. + let extensionInfo = { + useAddonManager: "permanent", + files: {}, + manifest: SearchTestUtils.createEngineManifest({ + name: "startup", + search_url: "https://example.com/", + }), + }; + + extension = lazy.ExtensionTestUtils.loadExtension(extensionInfo); + await extension.startup(); + + let settingsWritten = promiseAfterSettings(); + await Services.search.init(); + + await AddonTestUtils.waitForSearchProviderStartup(extension); + await settingsWritten; + + let engine = await Services.search.getEngineByName("startup"); + Assert.ok(engine, "Should have loaded the engine"); + let submission = engine.getSubmission("foo"); + Assert.equal( + submission.uri.spec, + "https://example.com/?q=foo", + "Should have the expected search url." + ); +}); + +add_task(async function test_startup_with_existing_addon_from_settings() { + Services.search.wrappedJSObject.reset(); + + let settingsWritten = promiseAfterSettings(); + await Services.search.init(); + await settingsWritten; + + let engine = await Services.search.getEngineByName("startup"); + Assert.ok(engine, "Should have loaded the engine"); + let submission = engine.getSubmission("foo"); + Assert.equal( + submission.uri.spec, + "https://example.com/?q=foo", + "Should have the expected search url." + ); +}); + +add_task( + async function test_startup_with_existing_addon_with_startup_notification() { + // Checks that we correctly load the add-on on startup when we are notified + // about it from the add-on manager before search has initialised. Also + // ensures that we don't raise an error when loading it from settings + // when the add-on is already there. The console check is handled by + // TestUtils.listenForConsoleMessages() in head_search.js. + + Services.search.wrappedJSObject.reset(); + + await Services.search.addEnginesFromExtension(extension.extension); + + let settingsWritten = promiseAfterSettings(); + await Services.search.init(); + await settingsWritten; + + let engine = await Services.search.getEngineByName("startup"); + Assert.ok(engine, "Should have loaded the engine"); + let submission = engine.getSubmission("foo"); + Assert.equal( + submission.uri.spec, + "https://example.com/?q=foo", + "Should have the expected search url." + ); + + await extension.unload(); + } +); |