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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 /**
     6  * Test that nsIUpdatePrompt doesn't display UI for showUpdateInstalled and
     7  * showUpdateAvailable when there is already an application update window open.
     8  */
    10 function run_test() {
    11   setupTestCommon();
    13   logTestInfo("testing nsIUpdatePrompt notifications should not be seen when " +
    14               "there is already an application update window open");
    16   Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, false);
    18   let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
    19   registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
    20                             "Fake Window Watcher",
    21                             "@mozilla.org/embedcomp/window-watcher;1",
    22                             WindowWatcherFactory);
    23   registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"),
    24                             "Fake Window Mediator",
    25                             "@mozilla.org/appshell/window-mediator;1",
    26                             WindowMediatorFactory);
    28   standardInit();
    30   logTestInfo("testing showUpdateInstalled should not call openWindow");
    31   Services.prefs.setBoolPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI, true);
    33   gCheckFunc = check_showUpdateInstalled;
    34   gUP.showUpdateInstalled();
    35   // Report a successful check after the call to showUpdateInstalled since it
    36   // didn't throw and otherwise it would report no tests run.
    37   do_check_true(true);
    39   logTestInfo("testing showUpdateAvailable should not call openWindow");
    40   writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false);
    41   let patches = getLocalPatchString(null, null, null, null, null, null,
    42                                     STATE_FAILED);
    43   let updates = getLocalUpdateString(patches);
    44   writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true);
    45   writeStatusFile(STATE_FAILED);
    46   reloadUpdateManagerData();
    48   gCheckFunc = check_showUpdateAvailable;
    49   let update = gUpdateManager.activeUpdate;
    50   gUP.showUpdateAvailable(update);
    51   // Report a successful check after the call to showUpdateAvailable since it
    52   // didn't throw and otherwise it would report no tests run.
    53   do_check_true(true);
    55   let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
    56   registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
    57                               WindowWatcherFactory);
    58   registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"),
    59                               WindowMediatorFactory);
    61   doTestFinish();
    62 }
    64 function check_showUpdateInstalled() {
    65   do_throw("showUpdateInstalled should not have called openWindow!");
    66 }
    68 function check_showUpdateAvailable() {
    69   do_throw("showUpdateAvailable should not have called openWindow!");
    70 }
    72 var WindowWatcher = {
    73   openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) {
    74     gCheckFunc();
    75   },
    77   QueryInterface: function(aIID) {
    78     if (aIID.equals(AUS_Ci.nsIWindowWatcher) ||
    79         aIID.equals(AUS_Ci.nsISupports))
    80       return this;
    82     throw AUS_Cr.NS_ERROR_NO_INTERFACE;
    83   }
    84 }
    86 var WindowWatcherFactory = {
    87   createInstance: function createInstance(aOuter, aIID) {
    88     if (aOuter != null)
    89       throw AUS_Cr.NS_ERROR_NO_AGGREGATION;
    90     return WindowWatcher.QueryInterface(aIID);
    91   }
    92 };
    94 var WindowMediator = {
    95   getMostRecentWindow: function(aWindowType) {
    96     return { getInterface: XPCOMUtils.generateQI([AUS_Ci.nsIDOMWindow]) };
    97   },
    99   QueryInterface: function(aIID) {
   100     if (aIID.equals(AUS_Ci.nsIWindowMediator) ||
   101         aIID.equals(AUS_Ci.nsISupports))
   102       return this;
   104     throw AUS_Cr.NS_ERROR_NO_INTERFACE;
   105   }
   106 }
   108 var WindowMediatorFactory = {
   109   createInstance: function createInstance(aOuter, aIID) {
   110     if (aOuter != null)
   111       throw AUS_Cr.NS_ERROR_NO_AGGREGATION;
   112     return WindowMediator.QueryInterface(aIID);
   113   }
   114 };

mercurial