toolkit/mozapps/update/tests/unit_aus_update/uiSilentPref.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/uiSilentPref.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     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 +/**
     1.9 + * Test that nsIUpdatePrompt doesn't display UI for showUpdateInstalled,
    1.10 + * showUpdateAvailable, and showUpdateError when the app.update.silent
    1.11 + * preference is true.
    1.12 + */
    1.13 +
    1.14 +function run_test() {
    1.15 +  setupTestCommon();
    1.16 +
    1.17 +  logTestInfo("testing nsIUpdatePrompt notifications should not be seen " +
    1.18 +              "when the " + PREF_APP_UPDATE_SILENT + " preference is true");
    1.19 +
    1.20 +  Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, true);
    1.21 +
    1.22 +  let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
    1.23 +  registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
    1.24 +                            "Fake Window Watcher",
    1.25 +                            "@mozilla.org/embedcomp/window-watcher;1",
    1.26 +                            WindowWatcherFactory);
    1.27 +
    1.28 +  standardInit();
    1.29 +
    1.30 +  logTestInfo("testing showUpdateInstalled should not call openWindow");
    1.31 +  Services.prefs.setBoolPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI, true);
    1.32 +
    1.33 +  gCheckFunc = check_showUpdateInstalled;
    1.34 +  gUP.showUpdateInstalled();
    1.35 +  // Report a successful check after the call to showUpdateInstalled since it
    1.36 +  // didn't throw and otherwise it would report no tests run.
    1.37 +  do_check_true(true);
    1.38 +
    1.39 +  logTestInfo("testing showUpdateAvailable should not call openWindow");
    1.40 +  writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false);
    1.41 +  let patches = getLocalPatchString(null, null, null, null, null, null,
    1.42 +                                    STATE_FAILED);
    1.43 +  let updates = getLocalUpdateString(patches);
    1.44 +  writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true);
    1.45 +  writeStatusFile(STATE_FAILED);
    1.46 +  reloadUpdateManagerData();
    1.47 +
    1.48 +  gCheckFunc = check_showUpdateAvailable;
    1.49 +  let update = gUpdateManager.activeUpdate;
    1.50 +  gUP.showUpdateAvailable(update);
    1.51 +  // Report a successful check after the call to showUpdateAvailable since it
    1.52 +  // didn't throw and otherwise it would report no tests run.
    1.53 +  do_check_true(true);
    1.54 +
    1.55 +  logTestInfo("testing showUpdateError should not call getNewPrompter");
    1.56 +  gCheckFunc = check_showUpdateError;
    1.57 +  update.errorCode = WRITE_ERROR;
    1.58 +  gUP.showUpdateError(update);
    1.59 +  // Report a successful check after the call to showUpdateError since it
    1.60 +  // didn't throw and otherwise it would report no tests run.
    1.61 +  do_check_true(true);
    1.62 +
    1.63 +  let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
    1.64 +  registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
    1.65 +                              WindowWatcherFactory);
    1.66 +
    1.67 +  doTestFinish();
    1.68 +}
    1.69 +
    1.70 +function check_showUpdateInstalled() {
    1.71 +  do_throw("showUpdateInstalled should not have called openWindow!");
    1.72 +}
    1.73 +
    1.74 +function check_showUpdateAvailable() {
    1.75 +  do_throw("showUpdateAvailable should not have called openWindow!");
    1.76 +}
    1.77 +
    1.78 +function check_showUpdateError() {
    1.79 +  do_throw("showUpdateError should not have seen getNewPrompter!");
    1.80 +}
    1.81 +
    1.82 +var WindowWatcher = {
    1.83 +  openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) {
    1.84 +    gCheckFunc();
    1.85 +  },
    1.86 +
    1.87 +  getNewPrompter: function(aParent) {
    1.88 +    gCheckFunc();
    1.89 +  },
    1.90 +
    1.91 +  QueryInterface: function(aIID) {
    1.92 +    if (aIID.equals(AUS_Ci.nsIWindowWatcher) ||
    1.93 +        aIID.equals(AUS_Ci.nsISupports))
    1.94 +      return this;
    1.95 +
    1.96 +    throw AUS_Cr.NS_ERROR_NO_INTERFACE;
    1.97 +  }
    1.98 +}
    1.99 +
   1.100 +var WindowWatcherFactory = {
   1.101 +  createInstance: function createInstance(aOuter, aIID) {
   1.102 +    if (aOuter != null)
   1.103 +      throw AUS_Cr.NS_ERROR_NO_AGGREGATION;
   1.104 +    return WindowWatcher.QueryInterface(aIID);
   1.105 +  }
   1.106 +};

mercurial