toolkit/mozapps/update/tests/unit_aus_update/downloadCompleteAfterPartialFailure.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/downloadCompleteAfterPartialFailure.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +function run_test() {
     1.9 +  setupTestCommon();
    1.10 +
    1.11 +  logTestInfo("testing download a complete on partial failure. Calling " +
    1.12 +              "nsIUpdatePrompt::showUpdateError should call getNewPrompter " +
    1.13 +              "and alert on the object returned by getNewPrompter when the " +
    1.14 +              "update.state == " + STATE_FAILED + " and the update.errorCode " +
    1.15 +              "== " + WRITE_ERROR + " (Bug 595059).");
    1.16 +
    1.17 +  Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, false);
    1.18 +
    1.19 +  let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
    1.20 +  registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
    1.21 +                            "Fake Window Watcher",
    1.22 +                            "@mozilla.org/embedcomp/window-watcher;1",
    1.23 +                            WindowWatcherFactory);
    1.24 +
    1.25 +  standardInit();
    1.26 +
    1.27 +  writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false);
    1.28 +  let url = URL_HOST + "/" + FILE_COMPLETE_MAR;
    1.29 +  let patches = getLocalPatchString("complete", url, null, null, null, null,
    1.30 +                                    STATE_FAILED);
    1.31 +  let updates = getLocalUpdateString(patches, null, null, "version 1.0", "1.0",
    1.32 +                                     null, null, null, null, url);
    1.33 +  writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true);
    1.34 +  writeStatusFile(STATE_FAILED);
    1.35 +
    1.36 +  reloadUpdateManagerData();
    1.37 +
    1.38 +  let update = gUpdateManager.activeUpdate;
    1.39 +  update.errorCode = WRITE_ERROR;
    1.40 +  let prompter = AUS_Cc["@mozilla.org/updates/update-prompt;1"].
    1.41 +                 createInstance(AUS_Ci.nsIUpdatePrompt);
    1.42 +  prompter.showUpdateError(update);
    1.43 +}
    1.44 +
    1.45 +function end_test() {
    1.46 +  let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
    1.47 +  registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
    1.48 +                              WindowWatcherFactory);
    1.49 +}
    1.50 +
    1.51 +var WindowWatcher = {
    1.52 +  getNewPrompter: function(aParent) {
    1.53 +    do_check_eq(aParent, null);
    1.54 +    return {
    1.55 +      alert: function(aTitle, aText) {
    1.56 +        let title = getString("updaterIOErrorTitle");
    1.57 +        do_check_eq(aTitle, title);
    1.58 +        let text = gUpdateBundle.formatStringFromName("updaterIOErrorMsg",
    1.59 +                                                      [Services.appinfo.name,
    1.60 +                                                       Services.appinfo.name], 2);
    1.61 +        do_check_eq(aText, text);
    1.62 +
    1.63 +        doTestFinish();
    1.64 +      }
    1.65 +    }; 
    1.66 +  },
    1.67 +
    1.68 +  QueryInterface: function(iid) {
    1.69 +    if (iid.equals(AUS_Ci.nsIWindowWatcher) ||
    1.70 +        iid.equals(AUS_Ci.nsISupports))
    1.71 +      return this;
    1.72 +
    1.73 +    throw AUS_Cr.NS_ERROR_NO_INTERFACE;
    1.74 +  }
    1.75 +}
    1.76 +
    1.77 +var WindowWatcherFactory = {
    1.78 +  createInstance: function createInstance(outer, iid) {
    1.79 +    if (outer != null)
    1.80 +      throw AUS_Cr.NS_ERROR_NO_AGGREGATION;
    1.81 +    return WindowWatcher.QueryInterface(iid);
    1.82 +  }
    1.83 +};

mercurial