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
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.
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 Update Check Tests */
41 const DIR_DATA = "data"
42 const URL_PREFIX = "http://localhost:4444/" + DIR_DATA + "/";
44 const PREF_APP_UPDATE_URL_OVERRIDE = "app.update.url.override";
56 start_httpserver(DIR_DATA);
57 do_timeout(0, "run_test_pt1()");
65 // Helper function for testing update counts returned from an update xml
66 function run_test_helper_pt1(aUpdateXML, aMsg, aExpectedCount, aNextRunFunc) {
70 gCheckFunc = check_test_helper_pt1;
71 gNextRunFunc = aNextRunFunc;
72 gExpectedCount = aExpectedCount;
73 var url = URL_PREFIX + aUpdateXML;
74 dump("Testing: " + aMsg + " - " + url + "\n");
75 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
76 gUpdateChecker.checkForUpdates(updateCheckListener, true);
79 function check_test_helper_pt1() {
80 do_check_eq(gUpdateCount, gExpectedCount);
84 // one update available and the update's property values
85 function run_test_pt1() {
89 gCheckFunc = check_test_pt1;
90 var url = URL_PREFIX + "aus-0020_general-1.xml";
91 dump("Testing: one update available and the update's property values - " +
93 gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
94 var defaults = gPrefs.QueryInterface(AUS_Ci.nsIPrefService)
95 .getDefaultBranch(null);
96 defaults.setCharPref("app.update.channel", "bogus_channel");
97 gUpdateChecker.checkForUpdates(updateCheckListener, true);
100 function check_test_pt1() {
101 do_check_eq(gUpdateCount, 1);
102 var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount);
103 do_check_eq(bestUpdate.type, "minor");
104 do_check_eq(bestUpdate.name, "XPCShell Test");
105 do_check_eq(bestUpdate.version, "1.1a1pre");
106 do_check_eq(bestUpdate.platformVersion, "2.1a1pre");
107 do_check_eq(bestUpdate.extensionVersion, "3.1a1pre");
108 do_check_eq(bestUpdate.buildID, "20080811053724");
109 do_check_eq(bestUpdate.detailsURL, "http://dummydetails/");
110 do_check_eq(bestUpdate.licenseURL, "http://dummylicense/");
111 do_check_eq(bestUpdate.serviceURL, URL_PREFIX + "aus-0020_general-1.xml?force=1");
112 do_check_eq(bestUpdate.channel, "bogus_channel");
113 do_check_false(bestUpdate.isCompleteUpdate);
114 do_check_false(bestUpdate.isSecurityUpdate);
115 do_check_eq(bestUpdate.installDate, 0);
116 do_check_eq(bestUpdate.statusText, null);
117 // nsIUpdate:state returns an empty string when no action has been performed
118 // on an available update
119 do_check_eq(bestUpdate.state, "");
120 do_check_eq(bestUpdate.errorCode, 0);
121 do_check_eq(bestUpdate.patchCount, 2);
122 //XXX TODO - test nsIUpdate:serialize
124 var type = "complete";
125 var patch = bestUpdate.getPatchAt(0);
126 do_check_eq(patch.type, type);
127 do_check_eq(patch.URL, "http://" + type + "/");
128 do_check_eq(patch.hashFunction, "SHA1");
129 do_check_eq(patch.hashValue, "98db9dad8e1d80eda7e1170d0187d6f53e477059");
130 do_check_eq(patch.size, 9856459);
131 // nsIUpdatePatch:state returns the string "null" when no action has been
132 // performed on an available update
133 do_check_eq(patch.state, "null");
134 do_check_false(patch.selected);
135 //XXX TODO - test nsIUpdatePatch:serialize
138 patch = bestUpdate.getPatchAt(1);
139 do_check_eq(patch.type, type);
140 do_check_eq(patch.URL, "http://" + type + "/");
141 do_check_eq(patch.hashFunction, "SHA1");
142 do_check_eq(patch.hashValue, "e6678ca40ae7582316acdeddf3c133c9c8577de4");
143 do_check_eq(patch.size, 1316138);
144 // nsIUpdatePatch:state returns the string "null" when no action has been
145 // performed on an available update
146 do_check_eq(patch.state, "null");
147 do_check_false(patch.selected);
148 //XXX TODO - test nsIUpdatePatch:serialize
154 function run_test_pt2() {
155 run_test_helper_pt1("aus-0020_general-2.xml",
160 // update xml not found
161 function run_test_pt3() {
162 run_test_helper_pt1("aus-0020_general-3.xml",
163 "update xml not available",
167 // no updates available
168 function run_test_pt4() {
169 run_test_helper_pt1("aus-0020_general-4.xml",
170 "no updates available",
174 // one update available with two patches
175 function run_test_pt5() {
176 run_test_helper_pt1("aus-0020_general-5.xml",
177 "one update available",
181 // three updates available each with two patches
182 function run_test_pt6() {
183 run_test_helper_pt1("aus-0020_general-6.xml",
184 "three updates available",
188 // one update with complete and partial patches with size 0 specified in the
190 function run_test_pt7() {
191 run_test_helper_pt1("aus-0020_general-7.xml",
192 "one update with complete and partial patches with size 0",
196 // one update with complete patch with size 0 specified in the update xml
197 function run_test_pt8() {
198 run_test_helper_pt1("aus-0020_general-8.xml",
199 "one update with complete patch with size 0",
203 // one update with partial patch with size 0 specified in the update xml
204 function run_test_pt9() {
205 run_test_helper_pt1("aus-0020_general-9.xml",
206 "one update with partial patch with size 0",
210 // Update check listener
211 const updateCheckListener = {
212 onProgress: function(request, position, totalSize) {
215 onCheckComplete: function(request, updates, updateCount) {
216 gUpdateCount = updateCount;
218 dump("onCheckComplete url = " + request.channel.originalURI.spec + "\n\n");
219 // Use a timeout to allow the XHR to complete
220 do_timeout(0, "gCheckFunc()");
223 onError: function(request, update) {
224 dump("onError url = " + request.channel.originalURI.spec + "\n\n");
225 // Use a timeout to allow the XHR to complete
226 do_timeout(0, "gCheckFunc()");
229 QueryInterface: function(aIID) {
230 if (!aIID.equals(AUS_Ci.nsIUpdateCheckListener) &&
231 !aIID.equals(AUS_Ci.nsISupports))
232 throw AUS_Cr.NS_ERROR_NO_INTERFACE;