Bug 452317 - FeedConverter.js: QueryInterface should throw NS_ERROR_NO_INTERFACE...
[wine-gecko.git] / toolkit / mozapps / update / test / unit / test_0040_general.js.in
blob0054489b00dd0562fb3c1f6cb6e9032d9cba2938
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Application Update Service.
16 * The Initial Developer of the Original Code is
17 * Robert Strong <robert.bugzilla@gmail.com>.
19 * Portions created by the Initial Developer are Copyright (C) 2008
20 * the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK *****
39 /* General URL Construction Tests */
41 const DIR_DATA = "data"
42 const URL_PREFIX = "http://localhost:4444/" + DIR_DATA + "/";
44 const PREF_APP_UPDATE_CHANNEL = "app.update.channel";
45 const PREF_APP_UPDATE_URL_OVERRIDE = "app.update.url.override";
46 const PREF_PARTNER_BRANCH = "app.partner.";
47 const PREF_APP_DISTRIBUTION = "distribution.id";
48 const PREF_APP_DISTRIBUTION_VERSION = "distribution.version";
50 var gAppInfo;
51 var gCheckFunc;
52 var gInstallationLocale = "@AB_CD@";
54 function run_test() {
55 do_test_pending();
56 startAUS();
57 gAppInfo = AUS_Cc["@mozilla.org/xre/app-info;1"]
58 .getService(AUS_Ci.nsIXULAppInfo)
59 .QueryInterface(AUS_Ci.nsIXULRuntime);
60 start_httpserver(DIR_DATA);
61 do_timeout(0, "run_test_pt1()");
64 function end_test() {
65 do_test_finished();
66 stop_httpserver();
69 // Helper function for parsing the result from the contructed url
70 function getResult(url) {
71 return url.substr(URL_PREFIX.length).split("/")[0];
74 // url constructed with %PRODUCT%
75 function run_test_pt1() {
76 gCheckFunc = check_test_pt1;
77 var url = URL_PREFIX + "%PRODUCT%/";
78 dump("Testing: url constructed with %PRODUCT% - " + url + "\n");
79 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
80 gUpdateChecker.checkForUpdates(updateCheckListener, true);
83 function check_test_pt1(aResult) {
84 do_check_eq(aResult, gAppInfo.name);
85 run_test_pt2();
88 // url constructed with %VERSION%
89 function run_test_pt2() {
90 gCheckFunc = check_test_pt2;
91 var url = URL_PREFIX + "%VERSION%/";
92 dump("Testing: url constructed with %VERSION% - " + url + "\n");
93 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
94 gUpdateChecker.checkForUpdates(updateCheckListener, true);
97 function check_test_pt2(aResult) {
98 do_check_eq(aResult, gAppInfo.version);
99 run_test_pt3();
102 // url constructed with %BUILD_ID%
103 function run_test_pt3() {
104 gCheckFunc = check_test_pt3;
105 var url = URL_PREFIX + "%BUILD_ID%/";
106 dump("Testing: url constructed with %BUILD_ID% - " + url + "\n");
107 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
108 gUpdateChecker.checkForUpdates(updateCheckListener, true);
111 function check_test_pt3(aResult) {
112 do_check_eq(aResult, gAppInfo.appBuildID);
113 run_test_pt4();
116 // url constructed with %BUILD_TARGET%
117 // XXX TODO - it might be nice if we tested the actual ABI
118 function run_test_pt4() {
119 gCheckFunc = check_test_pt4;
120 var url = URL_PREFIX + "%BUILD_TARGET%/";
121 dump("Testing: url constructed with %BUILD_TARGET% - " + url + "\n");
122 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
123 gUpdateChecker.checkForUpdates(updateCheckListener, true);
126 function check_test_pt4(aResult) {
127 try {
128 abi = gAppInfo.XPCOMABI;
130 catch (e) {
131 do_throw("nsIXULAppInfo:XPCOMABI not defined\n");
134 #ifdef XP_MACOSX
135 // Mac universal build should report a different ABI than either macppc
136 // or mactel. This is necessary since nsUpdateService.js will set the ABI to
137 // Universal-gcc3 for Mac universal builds.
138 var macutils = AUS_Cc["@mozilla.org/xpcom/mac-utils;1"]
139 .getService(AUS_Ci.nsIMacUtils);
141 if (macutils.isUniversalBinary)
142 abi = "Universal-gcc3";
143 #endif
145 do_check_eq(aResult, gAppInfo.OS + "_" + abi);
146 run_test_pt5();
149 // url constructed with %LOCALE%
150 // Bug 446527 added the locale to the updater.ini
151 function run_test_pt5() {
152 gCheckFunc = check_test_pt5;
153 var url = URL_PREFIX + "%LOCALE%/";
154 dump("Testing: url constructed with %LOCALE% - " + url + "\n");
155 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
156 gUpdateChecker.checkForUpdates(updateCheckListener, true);
159 function check_test_pt5(aResult) {
160 do_check_eq(aResult, gInstallationLocale);
161 run_test_pt6();
164 // url constructed with %CHANNEL%
165 function run_test_pt6() {
166 gCheckFunc = check_test_pt6;
167 var url = URL_PREFIX + "%CHANNEL%/";
168 dump("Testing: url constructed with %CHANNEL% - " + url + "\n");
169 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
170 var defaults = gPrefs.QueryInterface(AUS_Ci.nsIPrefService)
171 .getDefaultBranch(null);
172 defaults.setCharPref(PREF_APP_UPDATE_CHANNEL, "bogus_channel");
173 gUpdateChecker.checkForUpdates(updateCheckListener, true);
176 function check_test_pt6(aResult) {
177 do_check_eq(aResult, "bogus_channel");
178 run_test_pt7();
181 // url constructed with %CHANNEL% with distribution partners
182 function run_test_pt7() {
183 gCheckFunc = check_test_pt7;
184 var url = URL_PREFIX + "%CHANNEL%/";
185 dump("Testing: url constructed with %CHANNEL% - " + url + "\n");
186 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
187 var defaults = gPrefs.QueryInterface(AUS_Ci.nsIPrefService)
188 .getDefaultBranch(null);
189 defaults.setCharPref(PREF_PARTNER_BRANCH + "bogus_partner1", "bogus_partner1");
190 defaults.setCharPref(PREF_PARTNER_BRANCH + "bogus_partner2", "bogus_partner2");
191 gUpdateChecker.checkForUpdates(updateCheckListener, true);
194 function check_test_pt7(aResult) {
195 do_check_eq(aResult, "bogus_channel-cck-bogus_partner1-bogus_partner2");
196 run_test_pt8();
199 // url constructed with %PLATFORM_VERSION%
200 function run_test_pt8() {
201 gCheckFunc = check_test_pt8;
202 var url = URL_PREFIX + "%PLATFORM_VERSION%/";
203 dump("Testing: url constructed with %PLATFORM_VERSION% - " + url + "\n");
204 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
205 gUpdateChecker.checkForUpdates(updateCheckListener, true);
208 function check_test_pt8(aResult) {
209 do_check_eq(aResult, gAppInfo.platformVersion);
210 run_test_pt9();
213 // url constructed with %OS_VERSION%
214 function run_test_pt9() {
215 gCheckFunc = check_test_pt9;
216 var url = URL_PREFIX + "%OS_VERSION%/";
217 dump("Testing: url constructed with %OS_VERSION% - " + url + "\n");
218 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
219 gUpdateChecker.checkForUpdates(updateCheckListener, true);
222 function check_test_pt9(aResult) {
223 var osVersion;
224 var sysInfo = AUS_Cc["@mozilla.org/system-info;1"]
225 .getService(AUS_Ci.nsIPropertyBag2);
226 osVersion = sysInfo.getProperty("name") + " " + sysInfo.getProperty("version");
228 if (osVersion) {
229 try {
230 osVersion += " (" + sysInfo.getProperty("secondaryLibrary") + ")";
232 catch (e) {
233 // Not all platforms have a secondary widget library, so an error is nothing to worry about.
235 osVersion = encodeURIComponent(osVersion);
238 do_check_eq(aResult, osVersion);
239 run_test_pt10();
242 // url constructed with %DISTRIBUTION%
243 function run_test_pt10() {
244 gCheckFunc = check_test_pt10;
245 var url = URL_PREFIX + "%DISTRIBUTION%/";
246 dump("Testing: url constructed with %DISTRIBUTION% - " + url + "\n");
247 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
248 var defaults = gPrefs.QueryInterface(AUS_Ci.nsIPrefService)
249 .getDefaultBranch(null);
250 defaults.setCharPref(PREF_APP_DISTRIBUTION, "bogus_distro");
251 gUpdateChecker.checkForUpdates(updateCheckListener, true);
254 function check_test_pt10(aResult) {
255 do_check_eq(aResult, "bogus_distro");
256 run_test_pt11();
259 // url constructed with %DISTRIBUTION_VERSION%
260 function run_test_pt11() {
261 gCheckFunc = check_test_pt11;
262 var url = URL_PREFIX + "%DISTRIBUTION_VERSION%/";
263 dump("Testing: url constructed with %DISTRIBUTION_VERSION% - " + url + "\n");
264 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
265 var defaults = gPrefs.QueryInterface(AUS_Ci.nsIPrefService)
266 .getDefaultBranch(null);
267 defaults.setCharPref(PREF_APP_DISTRIBUTION_VERSION, "bogus_distro_version");
268 gUpdateChecker.checkForUpdates(updateCheckListener, true);
271 function check_test_pt11(aResult) {
272 do_check_eq(aResult, "bogus_distro_version");
273 run_test_pt12();
276 // url constructed that doesn't have a parameter - bug 454357
277 function run_test_pt12() {
278 gCheckFunc = check_test_pt12;
279 var url = URL_PREFIX;
280 dump("Testing: url constructed that doesn't have a parameter - " + url + "\n");
281 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
282 gUpdateChecker.checkForUpdates(updateCheckListener, true);
285 function check_test_pt12(aResult) {
286 do_check_eq(aResult, "?force=1");
287 run_test_pt13();
290 // url constructed that has a parameter - bug 454357
291 function run_test_pt13() {
292 gCheckFunc = check_test_pt13;
293 var url = URL_PREFIX + "?bogus=param";
294 dump("Testing: url constructed that has a parameter - " + url + "\n");
295 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
296 gUpdateChecker.checkForUpdates(updateCheckListener, true);
299 function check_test_pt13(aResult) {
300 do_check_eq(aResult, "?bogus=param&force=1");
301 end_test();
304 // Update check listener
305 const updateCheckListener = {
306 onProgress: function(request, position, totalSize) {
309 onCheckComplete: function(request, updates, updateCount) {
310 var url = request.channel.originalURI.spec;
311 dump("onCheckComplete url = " + url + "\n\n");
312 var result = getResult(url);
313 // Use a timeout to allow the XHR to complete
314 do_timeout(0, "gCheckFunc('" + result + "')");
317 onError: function(request, update) {
318 var url = request.channel.originalURI.spec;
319 dump("onError url = " + url + "\n\n");
320 var result = getResult(url);
321 // Use a timeout to allow the XHR to complete
322 do_timeout(0, "gCheckFunc('" + result + "')");
325 QueryInterface: function(aIID) {
326 if (!aIID.equals(AUS_Ci.nsIUpdateCheckListener) &&
327 !aIID.equals(AUS_Ci.nsISupports))
328 throw AUS_Cr.NS_ERROR_NO_INTERFACE;
329 return this;