toolkit/mozapps/update/tests/unit_aus_update/downloadFileTooBig_gonk.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/downloadFileTooBig_gonk.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     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 +const KEY_UPDATE_ARCHIVE_DIR = "UpdArchD"
    1.10 +
    1.11 +let gActiveUpdate = null;
    1.12 +
    1.13 +function FakeDirProvider() {}
    1.14 +FakeDirProvider.prototype = {
    1.15 +  classID: Components.ID("{f30b43a7-2bfa-4e5f-8c4f-abc7dd4ac486}"),
    1.16 +  QueryInterface: XPCOMUtils.generateQI([AUS_Ci.nsIDirectoryServiceProvider]),
    1.17 +
    1.18 +  getFile: function(prop, persistent) {
    1.19 +    if (prop == KEY_UPDATE_ARCHIVE_DIR) {
    1.20 +      if (gActiveUpdate) {
    1.21 +        gActiveUpdate.errorCode = AUS_Cr.NS_ERROR_FILE_TOO_BIG;
    1.22 +      }
    1.23 +    }
    1.24 +    return null;
    1.25 +  }
    1.26 +};
    1.27 +
    1.28 +function run_test() {
    1.29 +  setupTestCommon();
    1.30 +
    1.31 +  setUpdateURLOverride();
    1.32 +  overrideXHR(xhr_pt1);
    1.33 +  standardInit();
    1.34 +
    1.35 +  logTestInfo("testing that error codes set from a directory provider propagate" +
    1.36 +              "up to AUS.downloadUpdate() correctly (Bug 794211).");
    1.37 +
    1.38 +  gDirProvider = new FakeDirProvider();
    1.39 +  gOldProvider = AUS_Cc["@mozilla.org/browser/directory-provider;1"]
    1.40 +                       .createInstance(AUS_Ci.nsIDirectoryServiceProvider);
    1.41 +
    1.42 +  gDirService = AUS_Cc["@mozilla.org/file/directory_service;1"]
    1.43 +                       .getService(AUS_Ci.nsIProperties);
    1.44 +
    1.45 +  gDirService.unregisterProvider(gOldProvider);
    1.46 +  gDirService.registerProvider(gDirProvider);
    1.47 +
    1.48 +  Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, true);
    1.49 +  do_execute_soon(run_test_pt1);
    1.50 +}
    1.51 +
    1.52 +function xhr_pt1() {
    1.53 +  gXHR.status = 200;
    1.54 +  gXHR.responseText = gResponseBody;
    1.55 +  try {
    1.56 +    var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"].
    1.57 +                 createInstance(AUS_Ci.nsIDOMParser);
    1.58 +    gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml");
    1.59 +  } catch (e) {
    1.60 +    gXHR.responseXML = null;
    1.61 +  }
    1.62 +  var e = { target: gXHR };
    1.63 +  gXHR.onload(e);
    1.64 +}
    1.65 +
    1.66 +function run_test_pt1() {
    1.67 +  gUpdates = null;
    1.68 +  gUpdateCount = null;
    1.69 +  gCheckFunc = check_test_pt1;
    1.70 +
    1.71 +
    1.72 +  let patches = getRemotePatchString();
    1.73 +  let updates = getRemoteUpdateString(patches);
    1.74 +  gResponseBody = getRemoteUpdatesXMLString(updates);
    1.75 +  gUpdateChecker.checkForUpdates(updateCheckListener, true);
    1.76 +}
    1.77 +
    1.78 +function check_test_pt1() {
    1.79 +  do_check_eq(gUpdateCount, 1);
    1.80 +
    1.81 +  gActiveUpdate = gUpdates[0];
    1.82 +  do_check_neq(gActiveUpdate, null);
    1.83 +
    1.84 +  let state = gAUS.downloadUpdate(gActiveUpdate, true);
    1.85 +  do_check_eq(state, "null");
    1.86 +  do_check_eq(gActiveUpdate.errorCode >>> 0 , AUS_Cr.NS_ERROR_FILE_TOO_BIG);
    1.87 +
    1.88 +  doTestFinish();
    1.89 +}
    1.90 +
    1.91 +function end_test() {
    1.92 +  gDirService.unregisterProvider(gDirProvider);
    1.93 +  gDirService.registerProvider(gOldProvider);
    1.94 +  gActiveUpdate = null;
    1.95 +  gDirService = null;
    1.96 +  gDirProvider = null;
    1.97 +}

mercurial