1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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();
}
);
|