toolkit/mozapps/update/tests/unit_aus_update/remoteUpdateXML.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/update/tests/unit_aus_update/remoteUpdateXML.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,325 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 + */
     1.8 +
     1.9 +var gNextRunFunc;
    1.10 +var gExpectedCount;
    1.11 +
    1.12 +function run_test() {
    1.13 +  setupTestCommon();
    1.14 +
    1.15 +  logTestInfo("testing remote update xml attributes");
    1.16 +
    1.17 +  setUpdateURLOverride();
    1.18 +  setUpdateChannel("test_channel");
    1.19 +  // The mock XMLHttpRequest is MUCH faster
    1.20 +  overrideXHR(callHandleEvent);
    1.21 +  standardInit();
    1.22 +  do_execute_soon(run_test_pt01);
    1.23 +}
    1.24 +
    1.25 +// Helper function for testing update counts returned from an update xml
    1.26 +function run_test_helper_pt1(aMsg, aExpectedCount, aNextRunFunc) {
    1.27 +  gUpdates = null;
    1.28 +  gUpdateCount = null;
    1.29 +  gCheckFunc = check_test_helper_pt1;
    1.30 +  gNextRunFunc = aNextRunFunc;
    1.31 +  gExpectedCount = aExpectedCount;
    1.32 +  logTestInfo(aMsg, Components.stack.caller);
    1.33 +  gUpdateChecker.checkForUpdates(updateCheckListener, true);
    1.34 +}
    1.35 +
    1.36 +function check_test_helper_pt1() {
    1.37 +  do_check_eq(gUpdateCount, gExpectedCount);
    1.38 +  gNextRunFunc();
    1.39 +}
    1.40 +
    1.41 +// Callback function used by the custom XMLHttpRequest implementation to
    1.42 +// call the nsIDOMEventListener's handleEvent method for onload.
    1.43 +function callHandleEvent() {
    1.44 +  gXHR.status = 400;
    1.45 +  gXHR.responseText = gResponseBody;
    1.46 +  try {
    1.47 +    var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"].
    1.48 +                 createInstance(AUS_Ci.nsIDOMParser);
    1.49 +    gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml");
    1.50 +  } catch (e) {
    1.51 +    gXHR.responseXML = null;
    1.52 +  }
    1.53 +  var e = { target: gXHR };
    1.54 +  gXHR.onload(e);
    1.55 +}
    1.56 +
    1.57 +// update xml not found
    1.58 +function run_test_pt01() {
    1.59 +  run_test_helper_pt1("testing update xml not available",
    1.60 +                      null, run_test_pt02);
    1.61 +}
    1.62 +
    1.63 +// one update available and the update's property values
    1.64 +function run_test_pt02() {
    1.65 +  logTestInfo("testing one update available and the update's property values");
    1.66 +  gUpdates = null;
    1.67 +  gUpdateCount = null;
    1.68 +  gCheckFunc = check_test_pt02;
    1.69 +  var patches = getRemotePatchString("complete", "http://complete/", "SHA1",
    1.70 +                                     "98db9dad8e1d80eda7e1170d0187d6f53e477059",
    1.71 +                                     "9856459");
    1.72 +  patches += getRemotePatchString("partial", "http://partial/", "SHA1",
    1.73 +                                  "e6678ca40ae7582316acdeddf3c133c9c8577de4",
    1.74 +                                  "1316138");
    1.75 +  var updates = getRemoteUpdateString(patches, "minor", "Minor Test",
    1.76 +                                      "version 2.1a1pre", "2.1a1pre",
    1.77 +                                      "3.1a1pre", "20080811053724",
    1.78 +                                      "http://details/",
    1.79 +                                      "http://billboard/",
    1.80 +                                      "http://license/", "true",
    1.81 +                                      "true", "345600", "true", "4.1a1pre",
    1.82 +                                      "5.1a1pre",
    1.83 +                                      "custom1_attr=\"custom1 value\"",
    1.84 +                                      "custom2_attr=\"custom2 value\"");
    1.85 +  gResponseBody = getRemoteUpdatesXMLString(updates);
    1.86 +  gUpdateChecker.checkForUpdates(updateCheckListener, true);
    1.87 +}
    1.88 +
    1.89 +function check_test_pt02() {
    1.90 +  // XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244
    1.91 +  // and until this is fixed this will not test the value for detailsURL when it
    1.92 +  // isn't specified in the update xml.
    1.93 +//  var defaultDetailsURL;
    1.94 +//  try {
    1.95 +    // Try using a default details URL supplied by the distribution
    1.96 +    // if the update XML does not supply one.
    1.97 +//    var formatter = AUS_Cc["@mozilla.org/toolkit/URLFormatterService;1"].
    1.98 +//                    getService(AUS_Ci.nsIURLFormatter);
    1.99 +//    defaultDetailsURL = formatter.formatURLPref(PREF_APP_UPDATE_URL_DETAILS);
   1.100 +//  } catch (e) {
   1.101 +//    defaultDetailsURL = "";
   1.102 +//  }
   1.103 +
   1.104 +  do_check_eq(gUpdateCount, 1);
   1.105 +  var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount).QueryInterface(AUS_Ci.nsIPropertyBag);
   1.106 +  do_check_eq(bestUpdate.type, "minor");
   1.107 +  do_check_eq(bestUpdate.name, "Minor Test");
   1.108 +  do_check_eq(bestUpdate.displayVersion, "version 2.1a1pre");
   1.109 +  do_check_eq(bestUpdate.appVersion, "2.1a1pre");
   1.110 +  do_check_eq(bestUpdate.platformVersion, "3.1a1pre");
   1.111 +  do_check_eq(bestUpdate.buildID, "20080811053724");
   1.112 +  do_check_eq(bestUpdate.detailsURL, "http://details/");
   1.113 +  do_check_eq(bestUpdate.billboardURL, "http://billboard/");
   1.114 +  do_check_eq(bestUpdate.licenseURL, "http://license/");
   1.115 +  do_check_true(bestUpdate.showPrompt);
   1.116 +  do_check_true(bestUpdate.showNeverForVersion);
   1.117 +  do_check_eq(bestUpdate.promptWaitTime, "345600");
   1.118 +  do_check_eq(bestUpdate.serviceURL, URL_HOST + "/update.xml?force=1");
   1.119 +  do_check_eq(bestUpdate.channel, "test_channel");
   1.120 +  do_check_false(bestUpdate.isCompleteUpdate);
   1.121 +  do_check_false(bestUpdate.isSecurityUpdate);
   1.122 +  // Check that installDate is within 10 seconds of the current date.
   1.123 +  do_check_true((Date.now() - bestUpdate.installDate) < 10000);
   1.124 +  do_check_eq(bestUpdate.statusText, null);
   1.125 +  // nsIUpdate:state returns an empty string when no action has been performed
   1.126 +  // on an available update
   1.127 +  do_check_eq(bestUpdate.state, "");
   1.128 +  do_check_eq(bestUpdate.errorCode, 0);
   1.129 +  do_check_eq(bestUpdate.patchCount, 2);
   1.130 +  //XXX TODO - test nsIUpdate:serialize
   1.131 +
   1.132 +  do_check_eq(bestUpdate.getProperty("custom1_attr"), "custom1 value");
   1.133 +  do_check_eq(bestUpdate.getProperty("custom2_attr"), "custom2 value");
   1.134 +
   1.135 +  var patch = bestUpdate.getPatchAt(0);
   1.136 +  do_check_eq(patch.type, "complete");
   1.137 +  do_check_eq(patch.URL, "http://complete/");
   1.138 +  do_check_eq(patch.hashFunction, "SHA1");
   1.139 +  do_check_eq(patch.hashValue, "98db9dad8e1d80eda7e1170d0187d6f53e477059");
   1.140 +  do_check_eq(patch.size, 9856459);
   1.141 +  // The value for patch.state can be the string 'null' as a valid value. This
   1.142 +  // is confusing if it returns null which is an invalid value since the test
   1.143 +  // failure output will show a failure for null == null. To lessen the
   1.144 +  // confusion first check that the typeof for patch.state is string.
   1.145 +  do_check_eq(typeof(patch.state), "string");
   1.146 +  do_check_eq(patch.state, STATE_NONE);
   1.147 +  do_check_false(patch.selected);
   1.148 +  //XXX TODO - test nsIUpdatePatch:serialize
   1.149 +
   1.150 +  patch = bestUpdate.getPatchAt(1);
   1.151 +  do_check_eq(patch.type, "partial");
   1.152 +  do_check_eq(patch.URL, "http://partial/");
   1.153 +  do_check_eq(patch.hashFunction, "SHA1");
   1.154 +  do_check_eq(patch.hashValue, "e6678ca40ae7582316acdeddf3c133c9c8577de4");
   1.155 +  do_check_eq(patch.size, 1316138);
   1.156 +  do_check_eq(patch.state, STATE_NONE);
   1.157 +  do_check_false(patch.selected);
   1.158 +  //XXX TODO - test nsIUpdatePatch:serialize
   1.159 +
   1.160 +  run_test_pt03();
   1.161 +}
   1.162 +
   1.163 +// one update available and the update's property default values
   1.164 +function run_test_pt03() {
   1.165 +  logTestInfo("testing one update available and the update's property values " +
   1.166 +              "with the format prior to bug 530872");
   1.167 +  gUpdates = null;
   1.168 +  gUpdateCount = null;
   1.169 +  gCheckFunc = check_test_pt03;
   1.170 +  var patches = getRemotePatchString("complete", "http://complete/", "SHA1",
   1.171 +                                     "98db9dad8e1d80eda7e1170d0187d6f53e477059",
   1.172 +                                     "9856459");
   1.173 +  var updates = getRemoteUpdateString(patches, "major", "Major Test",
   1.174 +                                      null, null,
   1.175 +                                      "5.1a1pre", "20080811053724",
   1.176 +                                      "http://details/",
   1.177 +                                      null, null, null, null, "691200",
   1.178 +                                      null, "version 4.1a1pre", "4.1a1pre");
   1.179 +  gResponseBody = getRemoteUpdatesXMLString(updates);
   1.180 +  gUpdateChecker.checkForUpdates(updateCheckListener, true);
   1.181 +}
   1.182 +
   1.183 +function check_test_pt03() {
   1.184 +  do_check_eq(gUpdateCount, 1);
   1.185 +  var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount);
   1.186 +  do_check_eq(bestUpdate.type, "major");
   1.187 +  do_check_eq(bestUpdate.name, "Major Test");
   1.188 +  do_check_eq(bestUpdate.displayVersion, "version 4.1a1pre");
   1.189 +  do_check_eq(bestUpdate.appVersion, "4.1a1pre");
   1.190 +  do_check_eq(bestUpdate.platformVersion, "5.1a1pre");
   1.191 +  do_check_eq(bestUpdate.buildID, "20080811053724");
   1.192 +  do_check_eq(bestUpdate.detailsURL, "http://details/");
   1.193 +  do_check_eq(bestUpdate.billboardURL, "http://details/");
   1.194 +  do_check_eq(bestUpdate.licenseURL, null);
   1.195 +  do_check_true(bestUpdate.showPrompt);
   1.196 +  do_check_true(bestUpdate.showNeverForVersion);
   1.197 +  do_check_eq(bestUpdate.promptWaitTime, "691200");
   1.198 +  do_check_eq(bestUpdate.serviceURL, URL_HOST + "/update.xml?force=1");
   1.199 +  do_check_eq(bestUpdate.channel, "test_channel");
   1.200 +  do_check_false(bestUpdate.isCompleteUpdate);
   1.201 +  do_check_false(bestUpdate.isSecurityUpdate);
   1.202 +  // Check that installDate is within 10 seconds of the current date.
   1.203 +  do_check_true((Date.now() - bestUpdate.installDate) < 10000);
   1.204 +  do_check_eq(bestUpdate.statusText, null);
   1.205 +  // nsIUpdate:state returns an empty string when no action has been performed
   1.206 +  // on an available update
   1.207 +  do_check_eq(bestUpdate.state, "");
   1.208 +  do_check_eq(bestUpdate.errorCode, 0);
   1.209 +  do_check_eq(bestUpdate.patchCount, 1);
   1.210 +  //XXX TODO - test nsIUpdate:serialize
   1.211 +
   1.212 +  var patch = bestUpdate.getPatchAt(0);
   1.213 +  do_check_eq(patch.type, "complete");
   1.214 +  do_check_eq(patch.URL, "http://complete/");
   1.215 +  do_check_eq(patch.hashFunction, "SHA1");
   1.216 +  do_check_eq(patch.hashValue, "98db9dad8e1d80eda7e1170d0187d6f53e477059");
   1.217 +  do_check_eq(patch.size, 9856459);
   1.218 +  // The value for patch.state can be the string 'null' as a valid value. This
   1.219 +  // is confusing if it returns null which is an invalid value since the test
   1.220 +  // failure output will show a failure for null == null. To lessen the
   1.221 +  // confusion first check that the typeof for patch.state is string.
   1.222 +  do_check_eq(typeof(patch.state), "string");
   1.223 +  do_check_eq(patch.state, STATE_NONE);
   1.224 +  do_check_false(patch.selected);
   1.225 +  //XXX TODO - test nsIUpdatePatch:serialize
   1.226 +
   1.227 +  run_test_pt04();
   1.228 +}
   1.229 +
   1.230 +// Empty update xml
   1.231 +function run_test_pt04() {
   1.232 +  gResponseBody = "\n";
   1.233 +  run_test_helper_pt1("testing empty update xml",
   1.234 +                      null, run_test_pt05);
   1.235 +}
   1.236 +
   1.237 +// no updates available
   1.238 +function run_test_pt05() {
   1.239 +  gResponseBody = getRemoteUpdatesXMLString("");
   1.240 +  run_test_helper_pt1("testing no updates available",
   1.241 +                      0, run_test_pt06);
   1.242 +}
   1.243 +
   1.244 +// one update available with two patches
   1.245 +function run_test_pt06() {
   1.246 +  var patches = getRemotePatchString("complete");
   1.247 +  patches += getRemotePatchString("partial");
   1.248 +  var updates = getRemoteUpdateString(patches);
   1.249 +  gResponseBody = getRemoteUpdatesXMLString(updates);
   1.250 +  run_test_helper_pt1("testing one update available",
   1.251 +                      1, run_test_pt07);
   1.252 +}
   1.253 +
   1.254 +// three updates available each with two patches
   1.255 +function run_test_pt07() {
   1.256 +  var patches = getRemotePatchString("complete");
   1.257 +  patches += getRemotePatchString("partial");
   1.258 +  var updates = getRemoteUpdateString(patches);
   1.259 +  updates += getRemoteUpdateString(patches);
   1.260 +  updates += getRemoteUpdateString(patches);
   1.261 +  gResponseBody = getRemoteUpdatesXMLString(updates);
   1.262 +  run_test_helper_pt1("testing three updates available",
   1.263 +                      3, run_test_pt08);
   1.264 +}
   1.265 +
   1.266 +// one update with complete and partial patches with size 0 specified in the
   1.267 +// update xml
   1.268 +function run_test_pt08() {
   1.269 +  var patches = getRemotePatchString("complete", null, null, null, "0");
   1.270 +  patches += getRemotePatchString("partial", null, null, null, "0");
   1.271 +  var updates = getRemoteUpdateString(patches);
   1.272 +  gResponseBody = getRemoteUpdatesXMLString(updates);
   1.273 +  run_test_helper_pt1("testing one update with complete and partial " +
   1.274 +                      "patches with size 0", 0, run_test_pt09);
   1.275 +}
   1.276 +
   1.277 +// one update with complete patch with size 0 specified in the update xml
   1.278 +function run_test_pt09() {
   1.279 +  var patches = getRemotePatchString("complete", null, null, null, "0");
   1.280 +  var updates = getRemoteUpdateString(patches);
   1.281 +  gResponseBody = getRemoteUpdatesXMLString(updates);
   1.282 +  run_test_helper_pt1("testing one update with complete patch with size 0",
   1.283 +                      0, run_test_pt10);
   1.284 +}
   1.285 +
   1.286 +// one update with partial patch with size 0 specified in the update xml
   1.287 +function run_test_pt10() {
   1.288 +  var patches = getRemotePatchString("partial", null, null, null, "0");
   1.289 +  var updates = getRemoteUpdateString(patches);
   1.290 +  gResponseBody = getRemoteUpdatesXMLString(updates);
   1.291 +  run_test_helper_pt1("testing one update with partial patch with size 0",
   1.292 +                      0, run_test_pt11);
   1.293 +}
   1.294 +
   1.295 +// check that updates for older versions of the application aren't selected
   1.296 +function run_test_pt11() {
   1.297 +  var patches = getRemotePatchString("complete");
   1.298 +  patches += getRemotePatchString("partial");
   1.299 +  var updates = getRemoteUpdateString(patches, "minor", null, null, "1.0pre");
   1.300 +  updates += getRemoteUpdateString(patches, "minor", null, null, "1.0a");
   1.301 +  gResponseBody = getRemoteUpdatesXMLString(updates);
   1.302 +  run_test_helper_pt1("testing two updates older than the current version",
   1.303 +                      2, check_test_pt11);
   1.304 +}
   1.305 +
   1.306 +function check_test_pt11() {
   1.307 +  var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount);
   1.308 +  do_check_eq(bestUpdate, null);
   1.309 +  run_test_pt12();
   1.310 +}
   1.311 +
   1.312 +// check that updates for the current version of the application are selected
   1.313 +function run_test_pt12() {
   1.314 +  var patches = getRemotePatchString("complete");
   1.315 +  patches += getRemotePatchString("partial");
   1.316 +  var updates = getRemoteUpdateString(patches, "minor", null, "version 1.0");
   1.317 +  gResponseBody = getRemoteUpdatesXMLString(updates);
   1.318 +  run_test_helper_pt1("testing one update equal to the current version",
   1.319 +                      1, check_test_pt12);
   1.320 +}
   1.321 +
   1.322 +function check_test_pt12() {
   1.323 +  var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount);
   1.324 +  do_check_neq(bestUpdate, null);
   1.325 +  do_check_eq(bestUpdate.displayVersion, "version 1.0");
   1.326 +
   1.327 +  doTestFinish();
   1.328 +}

mercurial