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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
SearchTestUtils.initXPCShellAddonManager(this, "system");
async function restart() {
Services.search.wrappedJSObject.reset();
await AddonTestUtils.promiseRestartManager();
await Services.search.init(false);
}
const CONFIG_DEFAULT = [
{
webExtension: { id: "plainengine@search.mozilla.org" },
appliesTo: [{ included: { everywhere: true } }],
},
];
const CONFIG_UPDATED = [
{
webExtension: { id: "plainengine@search.mozilla.org" },
appliesTo: [{ included: { everywhere: true } }],
},
{
webExtension: { id: "example@search.mozilla.org" },
appliesTo: [{ included: { everywhere: true } }],
},
];
async function getEngineNames() {
let engines = await Services.search.getAppProvidedEngines();
return engines.map(engine => engine._name);
}
add_task(async function setup() {
await SearchTestUtils.useTestEngines("test-extensions", null, CONFIG_DEFAULT);
await AddonTestUtils.promiseStartupManager();
registerCleanupFunction(AddonTestUtils.promiseShutdownManager);
SearchTestUtils.useMockIdleService();
await Services.search.init();
});
// Test the situation where we receive an updated configuration
// that references an engine that doesnt exist locally as it
// will be installed by Normandy.
add_task(async function test_config_before_normandy() {
// Ensure initial default setup.
await SearchTestUtils.updateRemoteSettingsConfig(CONFIG_DEFAULT);
await restart();
Assert.deepEqual(await getEngineNames(), ["Plain"]);
// Updated configuration references nonexistant engine.
await SearchTestUtils.updateRemoteSettingsConfig(CONFIG_UPDATED);
Assert.deepEqual(
await getEngineNames(),
["Plain"],
"Updated engine hasnt been installed yet"
);
// Normandy then installs the engine.
let addon = await SearchTestUtils.installSystemSearchExtension();
Assert.deepEqual(
await getEngineNames(),
["Plain", "Example"],
"Both engines are now enabled"
);
await addon.unload();
});
// Test the situation where we receive a newly installed
// engine from Normandy followed by the update to the
// configuration that uses that engine.
add_task(async function test_normandy_before_config() {
// Ensure initial default setup.
await SearchTestUtils.updateRemoteSettingsConfig(CONFIG_DEFAULT);
await restart();
Assert.deepEqual(await getEngineNames(), ["Plain"]);
// Normandy installs the enigne.
let addon = await SearchTestUtils.installSystemSearchExtension();
Assert.deepEqual(
await getEngineNames(),
["Plain"],
"Normandy engine ignored as not in config yet"
);
// Configuration is updated to use the engine.
await SearchTestUtils.updateRemoteSettingsConfig(CONFIG_UPDATED);
Assert.deepEqual(
await getEngineNames(),
["Plain", "Example"],
"Both engines are now enabled"
);
await addon.unload();
});
|