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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// This verifies that add-on update check correctly fills in the
// %COMPATIBILITY_MODE% token in the update URL.
// The test extension uses an insecure update url.
Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
Components.utils.import("resource://testing-common/httpd.js");
var testserver = new HttpServer();
testserver.start(-1);
gPort = testserver.identity.primaryPort;
mapFile("/data/test_updatecompatmode_ignore.rdf", testserver);
mapFile("/data/test_updatecompatmode_normal.rdf", testserver);
mapFile("/data/test_updatecompatmode_strict.rdf", testserver);
testserver.registerDirectory("/addons/", do_get_file("addons"));
const profileDir = gProfD.clone();
profileDir.append("extensions");
function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
writeInstallRDFForExtension({
id: "compatmode-normal@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Addon - normal"
}, profileDir);
writeInstallRDFForExtension({
id: "compatmode-strict@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Addon - strict"
}, profileDir);
writeInstallRDFForExtension({
id: "compatmode-strict-optin@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Addon - strict opt-in",
strictCompatibility: true
}, profileDir);
writeInstallRDFForExtension({
id: "compatmode-ignore@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Addon - ignore",
}, profileDir);
startupManager();
run_test_1();
}
function end_test() {
testserver.stop(do_test_finished);
}
// Strict compatibility checking disabled.
function run_test_1() {
do_print("Testing with strict compatibility checking disabled");
Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
AddonManager.getAddonByID("compatmode-normal@tests.mozilla.org", function(addon) {
do_check_neq(addon, null);
addon.findUpdates({
onCompatibilityUpdateAvailable: function() {
do_throw("Should have not have seen compatibility information");
},
onNoUpdateAvailable: function() {
do_throw("Should have seen an available update");
},
onUpdateAvailable: function(addon, install) {
do_check_eq(install.version, "2.0")
},
onUpdateFinished: function() {
run_test_2();
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
});
}
// Strict compatibility checking enabled.
function run_test_2() {
do_print("Testing with strict compatibility checking enabled");
Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true);
AddonManager.getAddonByID("compatmode-strict@tests.mozilla.org", function(addon) {
do_check_neq(addon, null);
addon.findUpdates({
onCompatibilityUpdateAvailable: function() {
do_throw("Should have not have seen compatibility information");
},
onNoUpdateAvailable: function() {
do_throw("Should have seen an available update");
},
onUpdateAvailable: function(addon, install) {
do_check_eq(install.version, "2.0")
},
onUpdateFinished: function() {
run_test_3();
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
});
}
// Strict compatibility checking opt-in.
function run_test_3() {
do_print("Testing with strict compatibility disabled, but addon opt-in");
Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
AddonManager.getAddonByID("compatmode-strict-optin@tests.mozilla.org", function(addon) {
do_check_neq(addon, null);
addon.findUpdates({
onCompatibilityUpdateAvailable: function() {
do_throw("Should have not have seen compatibility information");
},
onUpdateAvailable: function(addon, install) {
do_throw("Should not have seen an available update");
},
onUpdateFinished: function() {
run_test_4();
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
});
}
// Compatibility checking disabled.
function run_test_4() {
do_print("Testing with all compatibility checking disabled");
AddonManager.checkCompatibility = false;
AddonManager.getAddonByID("compatmode-ignore@tests.mozilla.org", function(addon) {
do_check_neq(addon, null);
addon.findUpdates({
onCompatibilityUpdateAvailable: function() {
do_throw("Should have not have seen compatibility information");
},
onNoUpdateAvailable: function() {
do_throw("Should have seen an available update");
},
onUpdateAvailable: function(addon, install) {
do_check_eq(install.version, "2.0")
},
onUpdateFinished: function() {
end_test();
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
});
}
|