1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/update/tests/unit_aus_update/uiUnsupportedAlreadyNotified.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,124 @@ 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 nsIUpdatePrompt notifications should not be displayed " + 1.12 + "when showUpdateAvailable is called for an unsupported system " + 1.13 + "update when the unsupported notification has already been " + 1.14 + "shown (bug 843497)"); 1.15 + 1.16 + setUpdateURLOverride(); 1.17 + // The mock XMLHttpRequest is MUCH faster 1.18 + overrideXHR(callHandleEvent); 1.19 + standardInit(); 1.20 + // The HTTP server is only used for the mar file downloads which is slow 1.21 + start_httpserver(); 1.22 + 1.23 + let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar); 1.24 + registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), 1.25 + "Fake Window Watcher", 1.26 + "@mozilla.org/embedcomp/window-watcher;1", 1.27 + WindowWatcherFactory); 1.28 + registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"), 1.29 + "Fake Window Mediator", 1.30 + "@mozilla.org/appshell/window-mediator;1", 1.31 + WindowMediatorFactory); 1.32 + 1.33 + Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, false); 1.34 + Services.prefs.setBoolPref(PREF_APP_UPDATE_NOTIFIEDUNSUPPORTED, true); 1.35 + // This preference is used to determine when the background update check has 1.36 + // completed since a successful check will clear the preference. 1.37 + Services.prefs.setIntPref(PREF_APP_UPDATE_BACKGROUNDERRORS, 1); 1.38 + 1.39 + gResponseBody = getRemoteUpdatesXMLString(" <update type=\"major\" " + 1.40 + "name=\"Unsupported Update\" " + 1.41 + "unsupported=\"true\" " + 1.42 + "detailsURL=\"" + URL_HOST + 1.43 + "\"></update>\n"); 1.44 + gAUS.notify(null); 1.45 + do_execute_soon(check_test); 1.46 +} 1.47 + 1.48 +function check_test() { 1.49 + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_BACKGROUNDERRORS)) { 1.50 + do_execute_soon(check_test); 1.51 + return; 1.52 + } 1.53 + do_check_true(true); 1.54 + 1.55 + doTestFinish(); 1.56 +} 1.57 + 1.58 +function end_test() { 1.59 + let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar); 1.60 + registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), 1.61 + WindowWatcherFactory); 1.62 + registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"), 1.63 + WindowMediatorFactory); 1.64 +} 1.65 + 1.66 +// Callback function used by the custom XMLHttpRequest implementation to 1.67 +// call the nsIDOMEventListener's handleEvent method for onload. 1.68 +function callHandleEvent() { 1.69 + gXHR.status = 400; 1.70 + gXHR.responseText = gResponseBody; 1.71 + try { 1.72 + var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"]. 1.73 + createInstance(AUS_Ci.nsIDOMParser); 1.74 + gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); 1.75 + } catch (e) { 1.76 + } 1.77 + var e = { target: gXHR }; 1.78 + gXHR.onload(e); 1.79 +} 1.80 + 1.81 +function check_showUpdateAvailable() { 1.82 + do_throw("showUpdateAvailable should not have called openWindow!"); 1.83 +} 1.84 + 1.85 +var WindowWatcher = { 1.86 + openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) { 1.87 + check_showUpdateAvailable(); 1.88 + }, 1.89 + 1.90 + QueryInterface: function(aIID) { 1.91 + if (aIID.equals(AUS_Ci.nsIWindowWatcher) || 1.92 + aIID.equals(AUS_Ci.nsISupports)) 1.93 + return this; 1.94 + 1.95 + throw AUS_Cr.NS_ERROR_NO_INTERFACE; 1.96 + } 1.97 +} 1.98 + 1.99 +var WindowWatcherFactory = { 1.100 + createInstance: function createInstance(aOuter, aIID) { 1.101 + if (aOuter != null) 1.102 + throw AUS_Cr.NS_ERROR_NO_AGGREGATION; 1.103 + return WindowWatcher.QueryInterface(aIID); 1.104 + } 1.105 +}; 1.106 + 1.107 +var WindowMediator = { 1.108 + getMostRecentWindow: function(aWindowType) { 1.109 + return null; 1.110 + }, 1.111 + 1.112 + QueryInterface: function(aIID) { 1.113 + if (aIID.equals(AUS_Ci.nsIWindowMediator) || 1.114 + aIID.equals(AUS_Ci.nsISupports)) 1.115 + return this; 1.116 + 1.117 + throw AUS_Cr.NS_ERROR_NO_INTERFACE; 1.118 + } 1.119 +} 1.120 + 1.121 +var WindowMediatorFactory = { 1.122 + createInstance: function createInstance(aOuter, aIID) { 1.123 + if (aOuter != null) 1.124 + throw AUS_Cr.NS_ERROR_NO_AGGREGATION; 1.125 + return WindowMediator.QueryInterface(aIID); 1.126 + } 1.127 +};