Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 // This verifies that add-on update check correctly fills in the
6 // %COMPATIBILITY_MODE% token in the update URL.
9 // The test extension uses an insecure update url.
10 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
12 Components.utils.import("resource://testing-common/httpd.js");
13 var testserver = new HttpServer();
14 testserver.start(-1);
15 gPort = testserver.identity.primaryPort;
16 mapFile("/data/test_updatecompatmode_ignore.rdf", testserver);
17 mapFile("/data/test_updatecompatmode_normal.rdf", testserver);
18 mapFile("/data/test_updatecompatmode_strict.rdf", testserver);
19 testserver.registerDirectory("/addons/", do_get_file("addons"));
21 const profileDir = gProfD.clone();
22 profileDir.append("extensions");
24 function run_test() {
25 do_test_pending();
26 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
28 writeInstallRDFForExtension({
29 id: "compatmode-normal@tests.mozilla.org",
30 version: "1.0",
31 updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
32 targetApplications: [{
33 id: "xpcshell@tests.mozilla.org",
34 minVersion: "1",
35 maxVersion: "1"
36 }],
37 name: "Test Addon - normal"
38 }, profileDir);
40 writeInstallRDFForExtension({
41 id: "compatmode-strict@tests.mozilla.org",
42 version: "1.0",
43 updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
44 targetApplications: [{
45 id: "xpcshell@tests.mozilla.org",
46 minVersion: "1",
47 maxVersion: "1"
48 }],
49 name: "Test Addon - strict"
50 }, profileDir);
52 writeInstallRDFForExtension({
53 id: "compatmode-strict-optin@tests.mozilla.org",
54 version: "1.0",
55 updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
56 targetApplications: [{
57 id: "xpcshell@tests.mozilla.org",
58 minVersion: "1",
59 maxVersion: "1"
60 }],
61 name: "Test Addon - strict opt-in",
62 strictCompatibility: true
63 }, profileDir);
65 writeInstallRDFForExtension({
66 id: "compatmode-ignore@tests.mozilla.org",
67 version: "1.0",
68 updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
69 targetApplications: [{
70 id: "xpcshell@tests.mozilla.org",
71 minVersion: "1",
72 maxVersion: "1"
73 }],
74 name: "Test Addon - ignore",
75 }, profileDir);
77 startupManager();
78 run_test_1();
79 }
81 function end_test() {
82 testserver.stop(do_test_finished);
83 }
86 // Strict compatibility checking disabled.
87 function run_test_1() {
88 do_print("Testing with strict compatibility checking disabled");
89 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
90 AddonManager.getAddonByID("compatmode-normal@tests.mozilla.org", function(addon) {
91 do_check_neq(addon, null);
92 addon.findUpdates({
93 onCompatibilityUpdateAvailable: function() {
94 do_throw("Should have not have seen compatibility information");
95 },
97 onNoUpdateAvailable: function() {
98 do_throw("Should have seen an available update");
99 },
101 onUpdateAvailable: function(addon, install) {
102 do_check_eq(install.version, "2.0")
103 },
105 onUpdateFinished: function() {
106 run_test_2();
107 }
108 }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
109 });
110 }
112 // Strict compatibility checking enabled.
113 function run_test_2() {
114 do_print("Testing with strict compatibility checking enabled");
115 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true);
116 AddonManager.getAddonByID("compatmode-strict@tests.mozilla.org", function(addon) {
117 do_check_neq(addon, null);
118 addon.findUpdates({
119 onCompatibilityUpdateAvailable: function() {
120 do_throw("Should have not have seen compatibility information");
121 },
123 onNoUpdateAvailable: function() {
124 do_throw("Should have seen an available update");
125 },
127 onUpdateAvailable: function(addon, install) {
128 do_check_eq(install.version, "2.0")
129 },
131 onUpdateFinished: function() {
132 run_test_3();
133 }
134 }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
135 });
136 }
138 // Strict compatibility checking opt-in.
139 function run_test_3() {
140 do_print("Testing with strict compatibility disabled, but addon opt-in");
141 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
142 AddonManager.getAddonByID("compatmode-strict-optin@tests.mozilla.org", function(addon) {
143 do_check_neq(addon, null);
144 addon.findUpdates({
145 onCompatibilityUpdateAvailable: function() {
146 do_throw("Should have not have seen compatibility information");
147 },
149 onUpdateAvailable: function(addon, install) {
150 do_throw("Should not have seen an available update");
151 },
153 onUpdateFinished: function() {
154 run_test_4();
155 }
156 }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
157 });
158 }
160 // Compatibility checking disabled.
161 function run_test_4() {
162 do_print("Testing with all compatibility checking disabled");
163 AddonManager.checkCompatibility = false;
164 AddonManager.getAddonByID("compatmode-ignore@tests.mozilla.org", function(addon) {
165 do_check_neq(addon, null);
166 addon.findUpdates({
167 onCompatibilityUpdateAvailable: function() {
168 do_throw("Should have not have seen compatibility information");
169 },
171 onNoUpdateAvailable: function() {
172 do_throw("Should have seen an available update");
173 },
175 onUpdateAvailable: function(addon, install) {
176 do_check_eq(install.version, "2.0")
177 },
179 onUpdateFinished: function() {
180 end_test();
181 }
182 }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
183 });
184 }