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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { AddonTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/AddonTestUtils.sys.mjs"
);
const { AddonManager } = ChromeUtils.importESModule(
"resource://gre/modules/AddonManager.sys.mjs"
);
const { ExtensionTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/ExtensionXPCShellUtils.sys.mjs"
);
AddonTestUtils.init(this);
AddonTestUtils.overrideCertDB();
AddonTestUtils.appInfo = getAppInfo();
ExtensionTestUtils.init(this);
const server = AddonTestUtils.createHttpServer({ hosts: ["example.com"] });
const BASE_URL = `http://example.com/data`;
let TEST_NAME = "updatable.xpi";
/* Test that when a local file addon is updated,
the new version gets installed. */
add_task(async function test_local_addon_update() {
await AddonTestUtils.promiseStartupManager();
let tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
let id = "updatable1@test";
let xpi1 = AddonTestUtils.createTempWebExtensionFile({
manifest: {
version: "1.0",
browser_specific_settings: {
gecko: { id },
},
},
});
xpi1.copyTo(tmpDir, TEST_NAME);
let extension = ExtensionTestUtils.expectExtension(id);
await Promise.all([
extension.awaitStartup(),
setupPolicyEngineWithJson({
policies: {
ExtensionSettings: {
"updatable1@test": {
installation_mode: "force_installed",
install_url: Services.io.newFileURI(tmpDir).spec + "/" + TEST_NAME,
},
},
},
}),
]);
let addon = await AddonManager.getAddonByID(id);
notEqual(addon, null, "Addon should not be null");
equal(addon.version, "1.0", "Addon 1.0 installed");
let xpi2 = AddonTestUtils.createTempWebExtensionFile({
manifest: {
version: "2.0",
browser_specific_settings: {
gecko: { id },
},
},
});
// overwrite the test file
xpi2.copyTo(tmpDir, TEST_NAME);
extension = ExtensionTestUtils.expectExtension(id);
await Promise.all([
extension.awaitStartup(),
setupPolicyEngineWithJson({
policies: {
ExtensionSettings: {
"updatable1@test": {
installation_mode: "force_installed",
install_url: Services.io.newFileURI(tmpDir).spec + "/" + TEST_NAME,
},
},
},
}),
]);
addon = await AddonManager.getAddonByID(id);
equal(addon.version, "2.0", "Addon 2.0 installed");
let xpifile = tmpDir.clone();
xpifile.append(TEST_NAME);
xpifile.remove(false);
});
/* Test that when the url changes,
the new version gets installed. */
add_task(async function test_newurl_addon_update() {
let id = "updatable2@test";
let xpi1 = AddonTestUtils.createTempWebExtensionFile({
manifest: {
version: "1.0",
browser_specific_settings: {
gecko: { id },
},
},
});
server.registerFile("/data/policy_test1.xpi", xpi1);
let xpi2 = AddonTestUtils.createTempWebExtensionFile({
manifest: {
version: "2.0",
browser_specific_settings: {
gecko: { id },
},
},
});
server.registerFile("/data/policy_test2.xpi", xpi2);
let extension = ExtensionTestUtils.expectExtension(id);
await Promise.all([
extension.awaitStartup(),
setupPolicyEngineWithJson({
policies: {
ExtensionSettings: {
"updatable2@test": {
installation_mode: "force_installed",
install_url: `${BASE_URL}/policy_test1.xpi`,
},
},
},
}),
]);
let addon = await AddonManager.getAddonByID(id);
notEqual(addon, null, "Addon should not be null");
equal(addon.version, "1.0", "Addon 1.0 installed");
extension = ExtensionTestUtils.expectExtension(id);
await Promise.all([
extension.awaitStartup(),
setupPolicyEngineWithJson({
policies: {
ExtensionSettings: {
"updatable2@test": {
installation_mode: "force_installed",
install_url: `${BASE_URL}/policy_test2.xpi`,
},
},
},
}),
]);
addon = await AddonManager.getAddonByID(id);
equal(addon.version, "2.0", "Addon 2.0 installed");
await AddonTestUtils.promiseShutdownManager();
});
|