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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 function run_test() {
     6   setupTestCommon();
     8   logTestInfo("testing nsIUpdatePrompt notifications should not be displayed " +
     9               "when showUpdateAvailable is called for an unsupported system " +
    10               "update when the unsupported notification has already been " +
    11               "shown (bug 843497)");
    13   setUpdateURLOverride();
    14   // The mock XMLHttpRequest is MUCH faster
    15   overrideXHR(callHandleEvent);
    16   standardInit();
    17   // The HTTP server is only used for the mar file downloads which is slow
    18   start_httpserver();
    20   let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
    21   registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
    22                             "Fake Window Watcher",
    23                             "@mozilla.org/embedcomp/window-watcher;1",
    24                             WindowWatcherFactory);
    25   registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"),
    26                             "Fake Window Mediator",
    27                             "@mozilla.org/appshell/window-mediator;1",
    28                             WindowMediatorFactory);
    30   Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, false);
    31   Services.prefs.setBoolPref(PREF_APP_UPDATE_NOTIFIEDUNSUPPORTED, true);
    32   // This preference is used to determine when the background update check has
    33   // completed since a successful check will clear the preference.
    34   Services.prefs.setIntPref(PREF_APP_UPDATE_BACKGROUNDERRORS, 1);
    36   gResponseBody = getRemoteUpdatesXMLString("  <update type=\"major\" " +
    37                                             "name=\"Unsupported Update\" " +
    38                                             "unsupported=\"true\" " +
    39                                             "detailsURL=\"" + URL_HOST +
    40                                             "\"></update>\n");
    41   gAUS.notify(null);
    42   do_execute_soon(check_test);
    43 }
    45 function check_test() {
    46   if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_BACKGROUNDERRORS)) {
    47     do_execute_soon(check_test);
    48     return;
    49   }
    50   do_check_true(true);
    52   doTestFinish();
    53 }
    55 function end_test() {
    56   let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
    57   registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
    58                               WindowWatcherFactory);
    59   registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"),
    60                               WindowMediatorFactory);
    61 }
    63 // Callback function used by the custom XMLHttpRequest implementation to
    64 // call the nsIDOMEventListener's handleEvent method for onload.
    65 function callHandleEvent() {
    66   gXHR.status = 400;
    67   gXHR.responseText = gResponseBody;
    68   try {
    69     var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"].
    70                  createInstance(AUS_Ci.nsIDOMParser);
    71     gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml");
    72   } catch (e) {
    73   }
    74   var e = { target: gXHR };
    75   gXHR.onload(e);
    76 }
    78 function check_showUpdateAvailable() {
    79   do_throw("showUpdateAvailable should not have called openWindow!");
    80 }
    82 var WindowWatcher = {
    83   openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) {
    84     check_showUpdateAvailable();
    85   },
    87   QueryInterface: function(aIID) {
    88     if (aIID.equals(AUS_Ci.nsIWindowWatcher) ||
    89         aIID.equals(AUS_Ci.nsISupports))
    90       return this;
    92     throw AUS_Cr.NS_ERROR_NO_INTERFACE;
    93   }
    94 }
    96 var WindowWatcherFactory = {
    97   createInstance: function createInstance(aOuter, aIID) {
    98     if (aOuter != null)
    99       throw AUS_Cr.NS_ERROR_NO_AGGREGATION;
   100     return WindowWatcher.QueryInterface(aIID);
   101   }
   102 };
   104 var WindowMediator = {
   105   getMostRecentWindow: function(aWindowType) {
   106     return null;
   107   },
   109   QueryInterface: function(aIID) {
   110     if (aIID.equals(AUS_Ci.nsIWindowMediator) ||
   111         aIID.equals(AUS_Ci.nsISupports))
   112       return this;
   114     throw AUS_Cr.NS_ERROR_NO_INTERFACE;
   115   }
   116 }
   118 var WindowMediatorFactory = {
   119   createInstance: function createInstance(aOuter, aIID) {
   120     if (aOuter != null)
   121       throw AUS_Cr.NS_ERROR_NO_AGGREGATION;
   122     return WindowMediator.QueryInterface(aIID);
   123   }
   124 };

mercurial