From 95cbce1a65509e85b27382e443d86bc0c2c586a3 Mon Sep 17 00:00:00 2001 From: Robert Strong Date: Tue, 14 Sep 2010 18:48:57 -0700 Subject: [PATCH 1/2] Bug 568904 - Don't perform a shell refresh when there are no shortcuts for the installation when updating app modal id's. r=jmathies, a=approval2.0 --- browser/installer/windows/nsis/installer.nsi | 2 +- browser/installer/windows/nsis/shared.nsh | 2 +- .../mozapps/installer/windows/nsis/common.nsh | 20 +++++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/browser/installer/windows/nsis/installer.nsi b/browser/installer/windows/nsis/installer.nsi index 9cb66039891..3915450f16a 100755 --- a/browser/installer/windows/nsis/installer.nsi +++ b/browser/installer/windows/nsis/installer.nsi @@ -458,7 +458,7 @@ Section "-InstallEndCleanup" ${EndUnless} ; Win7 taskbar and start menu link maintenance - ${UpdateShortcutAppModelIDs} "$INSTDIR\${FileMainEXE}" "${AppUserModelID}" + ${UpdateShortcutAppModelIDs} "$INSTDIR\${FileMainEXE}" "${AppUserModelID}" $0 ; Refresh desktop icons System::Call "shell32::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)" diff --git a/browser/installer/windows/nsis/shared.nsh b/browser/installer/windows/nsis/shared.nsh index 1f6c3244565..b2233347ea7 100755 --- a/browser/installer/windows/nsis/shared.nsh +++ b/browser/installer/windows/nsis/shared.nsh @@ -85,7 +85,7 @@ ${SetUninstallKeys} ; Win7 taskbar and start menu link maintenance - ${UpdateShortcutAppModelIDs} "$INSTDIR\${FileMainEXE}" "${AppUserModelID}" + ${UpdateShortcutAppModelIDs} "$INSTDIR\${FileMainEXE}" "${AppUserModelID}" $0 ; Remove files that may be left behind by the application in the ; VirtualStore directory. diff --git a/toolkit/mozapps/installer/windows/nsis/common.nsh b/toolkit/mozapps/installer/windows/nsis/common.nsh index 8ee02f6e6f8..103c019401e 100755 --- a/toolkit/mozapps/installer/windows/nsis/common.nsh +++ b/toolkit/mozapps/installer/windows/nsis/common.nsh @@ -4771,8 +4771,9 @@ ClearErrors ${GetOptions} "$R0" "/UpdateShortcutAppUserModelIds" $R2 IfErrors hideshortcuts +1 - ${UpdateShortcutAppModelIDs} "$INSTDIR\${FileMainEXE}" "${AppUserModelID}" - GoTo finish + ${UpdateShortcutAppModelIDs} "$INSTDIR\${FileMainEXE}" "${AppUserModelID}" $R2 + StrCmp "$R2" "true" finish +1 ; true indicates that shortcuts have been updated + Quit ; Nothing initialized so no need to call OnEndCommon ; Require elevation if the user can elevate hideshortcuts: @@ -6131,6 +6132,9 @@ * The install path of the app * @param _APP_ID * The application user model ID for the current install + * @return _RESULT + * false if no shotcuts were found for this install location. + * true if shotcuts were found for this install location. */ !macro UpdateShortcutAppModelIDs @@ -6149,9 +6153,11 @@ Push $R7 ; stack: $R7, $R8, $R9 Push $R6 Push $R5 - Push $R4 ; stack: $R4, $R5, $R6, $R7, $R8, $R9 + Push $R4 + Push $R3 ; stack: $R3, $R5, $R6, $R7, $R8, $R9 StrCpy $R7 "$QUICKLAUNCH\User Pinned" + StrCpy $R3 "false" ClearErrors @@ -6171,6 +6177,7 @@ ${If} "$R4" == "$R9" ; link path == install path ApplicationID::Set "$R7\TaskBar\$R5" "$R8" Pop $R4 ; pop Set result off the stack + StrCpy $R3 "true" ${EndIf} ${EndIf} ClearErrors @@ -6191,6 +6198,7 @@ ${If} "$R4" == "$R9" ; link path == install path ApplicationID::Set "$R7\StartMenu\$R5" "$R8" Pop $R4 ; pop Set result off the stack + StrCpy $R3 "true" ${EndIf} ${EndIf} ClearErrors @@ -6200,6 +6208,9 @@ ${EndUnless} FindClose $R6 + StrCpy $R9 $R3 + + Pop $R3 ; stack: $R4, $R5, $R6, $R7, $R8, $R9 Pop $R4 ; stack: $R5, $R6, $R7, $R8, $R9 Pop $R5 ; stack: $R6, $R7, $R8, $R9 Pop $R6 ; stack: $R7, $R8, $R9 @@ -6213,11 +6224,12 @@ !endif !macroend -!macro UpdateShortcutAppModelIDsCall _INSTALL_PATH _APP_ID +!macro UpdateShortcutAppModelIDsCall _INSTALL_PATH _APP_ID _RESULT !verbose push !verbose ${_MOZFUNC_VERBOSE} Push "${_APP_ID}" Push "${_INSTALL_PATH}" Call UpdateShortcutAppModelIDs + Pop ${_RESULT} !verbose pop !macroend From 3233b7968efff9497fc2baa7d6bbd3f505194cb9 Mon Sep 17 00:00:00 2001 From: Robert Strong Date: Tue, 14 Sep 2010 18:49:10 -0700 Subject: [PATCH 2/2] Bug 595455 - After several background update check failures notify the user that they should check if there is a new version available. r=dtownsend, a=blocking2.0-beta7 --- browser/app/profile/firefox.js | 5 ++ toolkit/mozapps/update/content/updates.js | 22 ++++-- toolkit/mozapps/update/content/updates.xul | 2 +- toolkit/mozapps/update/nsUpdateService.js | 36 +++++++--- .../mozapps/update/test/chrome/Makefile.in | 1 + ...t_0131_check_invalidCertAttrs_noUpdate.xul | 3 +- ..._0132_check_invalidCertAttrs_hasUpdate.xul | 3 +- ..._0141_notify_invalidCertAttrs_noUpdate.xul | 6 +- ...0142_notify_invalidCertAttrs_hasUpdate.xul | 6 +- .../test_0151_notify_backgroundCheckError.xul | 53 ++++++++++++++ toolkit/mozapps/update/test/chrome/utils.js | 72 +++++++++++++------ toolkit/mozapps/update/test/shared.js | 2 + 12 files changed, 169 insertions(+), 42 deletions(-) create mode 100644 toolkit/mozapps/update/test/chrome/test_0151_notify_backgroundCheckError.xul diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 1242fe30e56..58050502e67 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -91,6 +91,11 @@ pref("app.update.timer", 600000); // Enables some extra Application Update Logging (can reduce performance) pref("app.update.log", false); +// The number of general background check failures to allow before notifying the +// user of the failure. User initiated update checks always notify the user of +// the failure. +pref("app.update.backgroundMaxErrors", 10); + // When |app.update.cert.requireBuiltIn| is true or not specified the // final certificate and all certificates the connection is redirected to before // the final certificate for the url specified in the |app.update.url| diff --git a/toolkit/mozapps/update/content/updates.js b/toolkit/mozapps/update/content/updates.js index 9c1a7bee84a..4eefa71e4ed 100644 --- a/toolkit/mozapps/update/content/updates.js +++ b/toolkit/mozapps/update/content/updates.js @@ -50,6 +50,7 @@ const CoR = Components.results; const XMLNS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; +const PREF_APP_UPDATE_BACKGROUNDERRORS = "app.update.backgroundErrors"; const PREF_APP_UPDATE_BILLBOARD_TEST_URL = "app.update.billboard.test_url"; const PREF_APP_UPDATE_CERT_ERRORS = "app.update.cert.errors"; const PREF_APP_UPDATE_ENABLED = "app.update.enabled"; @@ -75,6 +76,7 @@ const SRCEVT_BACKGROUND = 2; const CERT_ATTR_CHECK_FAILED_NO_UPDATE = 100; const CERT_ATTR_CHECK_FAILED_HAS_UPDATE = 101; +const BACKGROUNDCHECK_MULTIPLE_FAILURES = 110; var gLogEnabled = false; var gUpdatesFoundPageId; @@ -404,7 +406,8 @@ var gUpdates = { // their permission to install, and it's ready for download. this.setUpdate(arg0); if (this.update.errorCode == CERT_ATTR_CHECK_FAILED_NO_UPDATE || - this.update.errorCode == CERT_ATTR_CHECK_FAILED_HAS_UPDATE) { + this.update.errorCode == CERT_ATTR_CHECK_FAILED_HAS_UPDATE || + this.update.errorCode == BACKGROUNDCHECK_MULTIPLE_FAILURES) { aCallback("errorextra"); return; } @@ -591,6 +594,11 @@ var gCheckingPage = { // notifications will never happen. Services.prefs.deleteBranch(PREF_APP_UPDATE_NEVER_BRANCH); + // The user will be notified if there is an error so clear the background + // check error count. + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_BACKGROUNDERRORS)) + Services.prefs.clearUserPref(PREF_APP_UPDATE_BACKGROUNDERRORS); + this._checker = CoC["@mozilla.org/updates/update-checker;1"]. createInstance(CoI.nsIUpdateChecker); this._checker.checkForUpdates(this.updateListener, true); @@ -666,7 +674,7 @@ var gCheckingPage = { gUpdates.setUpdate(update); if (update.errorCode && (update.errorCode == CERT_ATTR_CHECK_FAILED_NO_UPDATE || - update.errorCode == CERT_ATTR_CHECK_FAILED_HAS_UPDATE )) { + update.errorCode == CERT_ATTR_CHECK_FAILED_HAS_UPDATE)) { gUpdates.wiz.goTo("errorextra"); } else { @@ -1624,13 +1632,19 @@ var gErrorExtraPage = { if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CERT_ERRORS)) Services.prefs.clearUserPref(PREF_APP_UPDATE_CERT_ERRORS); + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_BACKGROUNDERRORS)) + Services.prefs.clearUserPref(PREF_APP_UPDATE_BACKGROUNDERRORS); + if (gUpdates.update.errorCode == CERT_ATTR_CHECK_FAILED_HAS_UPDATE) { document.getElementById("errorCertAttrHasUpdateLabel").hidden = false; } else { - document.getElementById("errorCertCheckNoUpdateLabel").hidden = false; + if (gUpdates.update.errorCode == CERT_ATTR_CHECK_FAILED_NO_UPDATE) + document.getElementById("errorCertCheckNoUpdateLabel").hidden = false; + else + document.getElementById("genericBackgroundErrorLabel").hidden = false; var manualURL = Services.urlFormatter.formatURLPref(PREF_APP_UPDATE_MANUAL_URL); - var errorLinkLabel = document.getElementById("errorCertAttrLinkLabel"); + var errorLinkLabel = document.getElementById("errorExtraLinkLabel"); errorLinkLabel.value = manualURL; errorLinkLabel.setAttribute("url", manualURL); errorLinkLabel.hidden = false; diff --git a/toolkit/mozapps/update/content/updates.xul b/toolkit/mozapps/update/content/updates.xul index 28894e1aa8a..b0407f617f0 100644 --- a/toolkit/mozapps/update/content/updates.xul +++ b/toolkit/mozapps/update/content/updates.xul @@ -242,7 +242,7 @@ - diff --git a/toolkit/mozapps/update/nsUpdateService.js b/toolkit/mozapps/update/nsUpdateService.js index 5e8f6828288..b113256bdeb 100644 --- a/toolkit/mozapps/update/nsUpdateService.js +++ b/toolkit/mozapps/update/nsUpdateService.js @@ -53,6 +53,8 @@ const Cr = Components.results; const PREF_APP_UPDATE_AUTO = "app.update.auto"; const PREF_APP_UPDATE_BACKGROUND_INTERVAL = "app.update.download.backgroundInterval"; +const PREF_APP_UPDATE_BACKGROUNDERRORS = "app.update.backgroundErrors"; +const PREF_APP_UPDATE_BACKGROUNDMAXERRORS = "app.update.backgroundMaxErrors"; const PREF_APP_UPDATE_CERTS_BRANCH = "app.update.certs."; const PREF_APP_UPDATE_CERT_CHECKATTRS = "app.update.cert.checkAttributes"; const PREF_APP_UPDATE_CERT_ERRORS = "app.update.cert.errors"; @@ -124,6 +126,7 @@ const ELEVATION_CANCELED = 9; const CERT_ATTR_CHECK_FAILED_NO_UPDATE = 100; const CERT_ATTR_CHECK_FAILED_HAS_UPDATE = 101; +const BACKGROUNDCHECK_MULTIPLE_FAILURES = 110; const DOWNLOAD_CHUNK_SIZE = 300000; // bytes const DOWNLOAD_BACKGROUND_INTERVAL = 600; // seconds @@ -1286,16 +1289,25 @@ UpdateService.prototype = { LOG("UpdateService:notify:listener - error during background update: " + update.statusText); - if (!update.errorCode || - update.errorCode != CERT_ATTR_CHECK_FAILED_NO_UPDATE && - update.errorCode != CERT_ATTR_CHECK_FAILED_HAS_UPDATE) - return; + var maxErrors; + var errCount; + if (update.errorCode == CERT_ATTR_CHECK_FAILED_NO_UPDATE || + update.errorCode == CERT_ATTR_CHECK_FAILED_HAS_UPDATE) { + errCount = getPref("getIntPref", PREF_APP_UPDATE_CERT_ERRORS, 0); + errCount++; + Services.prefs.setIntPref(PREF_APP_UPDATE_CERT_ERRORS, errCount); + maxErrors = getPref("getIntPref", PREF_APP_UPDATE_CERT_MAXERRORS, 5); + } + else { + update.errorCode = BACKGROUNDCHECK_MULTIPLE_FAILURES; + errCount = getPref("getIntPref", PREF_APP_UPDATE_BACKGROUNDERRORS, 0); + errCount++; + Services.prefs.setIntPref(PREF_APP_UPDATE_BACKGROUNDERRORS, errCount); + maxErrors = getPref("getIntPref", PREF_APP_UPDATE_BACKGROUNDMAXERRORS, + 10); + } - var errCount = getPref("getIntPref", PREF_APP_UPDATE_CERT_ERRORS, 0); - errCount++; - Services.prefs.setIntPref(PREF_APP_UPDATE_CERT_ERRORS, errCount); - - if (errCount >= getPref("getIntPref", PREF_APP_UPDATE_CERT_MAXERRORS, 5)) { + if (errCount >= maxErrors) { var prompter = Cc["@mozilla.org/updates/update-prompt;1"]. createInstance(Ci.nsIUpdatePrompt); prompter.showUpdateError(update); @@ -2157,6 +2169,9 @@ Checker.prototype = { if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CERT_ERRORS)) Services.prefs.clearUserPref(PREF_APP_UPDATE_CERT_ERRORS); + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_BACKGROUNDERRORS)) + Services.prefs.clearUserPref(PREF_APP_UPDATE_BACKGROUNDERRORS); + // Tell the Update Service about the updates this._callback.onCheckComplete(event.target, updates, updates.length); } @@ -2834,7 +2849,8 @@ UpdatePrompt.prototype = { } if (update.errorCode == CERT_ATTR_CHECK_FAILED_NO_UPDATE || - update.errorCode == CERT_ATTR_CHECK_FAILED_HAS_UPDATE) { + update.errorCode == CERT_ATTR_CHECK_FAILED_HAS_UPDATE || + update.errorCode == BACKGROUNDCHECK_MULTIPLE_FAILURES) { this._showUIWhenIdle(null, URI_UPDATE_PROMPT_DIALOG, null, UPDATE_WINDOW_NAME, null, update); return; diff --git a/toolkit/mozapps/update/test/chrome/Makefile.in b/toolkit/mozapps/update/test/chrome/Makefile.in index 3fdf3f62e65..14bb0294a7f 100644 --- a/toolkit/mozapps/update/test/chrome/Makefile.in +++ b/toolkit/mozapps/update/test/chrome/Makefile.in @@ -100,6 +100,7 @@ _CHROME_FILES = \ test_0132_check_invalidCertAttrs_hasUpdate.xul \ test_0141_notify_invalidCertAttrs_noUpdate.xul \ test_0142_notify_invalidCertAttrs_hasUpdate.xul \ + test_0151_notify_backgroundCheckError.xul \ test_9999_cleanup.xul \ $(NULL) diff --git a/toolkit/mozapps/update/test/chrome/test_0131_check_invalidCertAttrs_noUpdate.xul b/toolkit/mozapps/update/test/chrome/test_0131_check_invalidCertAttrs_noUpdate.xul index d2a4fba74b2..1e8a2ec75ec 100644 --- a/toolkit/mozapps/update/test/chrome/test_0131_check_invalidCertAttrs_noUpdate.xul +++ b/toolkit/mozapps/update/test/chrome/test_0131_check_invalidCertAttrs_noUpdate.xul @@ -25,8 +25,9 @@ const TESTS = [ { pageid: PAGEID_CHECKING }, { pageid: PAGEID_ERROR_EXTRA, - extraDelayedCheckFunction: checkCertErrorPage, + extraDelayedCheckFunction: checkErrorExtraPage, shouldBeHidden: false, + displayedTextElem: "errorCertCheckNoUpdateLabel", buttonClick: "finish" } ]; diff --git a/toolkit/mozapps/update/test/chrome/test_0132_check_invalidCertAttrs_hasUpdate.xul b/toolkit/mozapps/update/test/chrome/test_0132_check_invalidCertAttrs_hasUpdate.xul index a182bad2fcc..2265c6c4f13 100644 --- a/toolkit/mozapps/update/test/chrome/test_0132_check_invalidCertAttrs_hasUpdate.xul +++ b/toolkit/mozapps/update/test/chrome/test_0132_check_invalidCertAttrs_hasUpdate.xul @@ -25,8 +25,9 @@ const TESTS = [ { pageid: PAGEID_CHECKING }, { pageid: PAGEID_ERROR_EXTRA, - extraDelayedCheckFunction: checkCertErrorPage, + extraDelayedCheckFunction: checkErrorExtraPage, shouldBeHidden: true, + displayedTextElem: "errorCertAttrHasUpdateLabel", buttonClick: "finish" } ]; diff --git a/toolkit/mozapps/update/test/chrome/test_0141_notify_invalidCertAttrs_noUpdate.xul b/toolkit/mozapps/update/test/chrome/test_0141_notify_invalidCertAttrs_noUpdate.xul index 88d4ded95b7..fbe72888b3e 100644 --- a/toolkit/mozapps/update/test/chrome/test_0141_notify_invalidCertAttrs_noUpdate.xul +++ b/toolkit/mozapps/update/test/chrome/test_0141_notify_invalidCertAttrs_noUpdate.xul @@ -23,8 +23,9 @@ const TESTS = [ { pageid: PAGEID_ERROR_EXTRA, - extraDelayedCheckFunction: checkCertErrorPage, + extraDelayedCheckFunction: checkErrorExtraPage, shouldBeHidden: false, + displayedTextElem: "errorCertCheckNoUpdateLabel", buttonClick: "finish" } ]; @@ -39,7 +40,8 @@ function runTest() { gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_URL, url); debugDump("Default Update URL: " + url); - certErrorsPrefObserver.init(); + errorsPrefObserver.init(PREF_APP_UPDATE_CERT_ERRORS, + PREF_APP_UPDATE_CERT_MAXERRORS); gAUS.notify(null); } diff --git a/toolkit/mozapps/update/test/chrome/test_0142_notify_invalidCertAttrs_hasUpdate.xul b/toolkit/mozapps/update/test/chrome/test_0142_notify_invalidCertAttrs_hasUpdate.xul index 44c9c8cc6cd..0aa7d2520d1 100644 --- a/toolkit/mozapps/update/test/chrome/test_0142_notify_invalidCertAttrs_hasUpdate.xul +++ b/toolkit/mozapps/update/test/chrome/test_0142_notify_invalidCertAttrs_hasUpdate.xul @@ -23,8 +23,9 @@ const TESTS = [ { pageid: PAGEID_ERROR_EXTRA, - extraDelayedCheckFunction: checkCertErrorPage, + extraDelayedCheckFunction: checkErrorExtraPage, shouldBeHidden: true, + displayedTextElem: "errorCertAttrHasUpdateLabel", buttonClick: "finish" } ]; @@ -40,7 +41,8 @@ function runTest() { gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_URL, url); debugDump("Default Update URL: " + url); - certErrorsPrefObserver.init(); + errorsPrefObserver.init(PREF_APP_UPDATE_CERT_ERRORS, + PREF_APP_UPDATE_CERT_MAXERRORS); gAUS.notify(null); } diff --git a/toolkit/mozapps/update/test/chrome/test_0151_notify_backgroundCheckError.xul b/toolkit/mozapps/update/test/chrome/test_0151_notify_backgroundCheckError.xul new file mode 100644 index 00000000000..7bdf3e6c753 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0151_notify_backgroundCheckError.xul @@ -0,0 +1,53 @@ + + + + + + + + + + +

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/utils.js b/toolkit/mozapps/update/test/chrome/utils.js index 18eb517a30c..250c5e00dcd 100644 --- a/toolkit/mozapps/update/test/chrome/utils.js +++ b/toolkit/mozapps/update/test/chrome/utils.js @@ -609,9 +609,10 @@ function checkPrefHasUserValue(aPrefHasValue) { } /** - * Checks whether the link is hidden (certificate attribute check error with an - * update) or not (certificate attribute check error without an update) on the - * errorcertcheck page and that the app.update.cert.errors preference does note + * Checks whether the link is hidden (general background update check error or + * a certificate attribute check error with an update) or not (certificate + * attribute check error without an update) on the errorextra page and that the + * app.update.cert.errors and app.update.backgroundErrors preferences do not & have a user value. * * @param aShouldBeHidden (optional) @@ -619,16 +620,23 @@ function checkPrefHasUserValue(aPrefHasValue) { * aShouldBeHidden is undefined the value of the current test's * shouldBeHidden property will be used. */ -function checkCertErrorPage(aShouldBeHidden) { +function checkErrorExtraPage(aShouldBeHidden) { let shouldBeHidden = aShouldBeHidden === undefined ? gTest.shouldBeHidden : aShouldBeHidden; - is(gWin.document.getElementById("errorCertAttrLinkLabel").hidden, shouldBeHidden, - "Checking errorCertAttrLinkLabel hidden attribute equals " + + is(gWin.document.getElementById("errorExtraLinkLabel").hidden, shouldBeHidden, + "Checking errorExtraLinkLabel hidden attribute equals " + (shouldBeHidden ? "true" : "false")); + is(gWin.document.getElementById(gTest.displayedTextElem).hidden, false, + "Checking " + gTest.displayedTextElem + " should not be hidden"); + ok(!Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CERT_ERRORS), "Preference " + PREF_APP_UPDATE_CERT_ERRORS + " should not have a " + "user value"); + + ok(!Services.prefs.prefHasUserValue(PREF_APP_UPDATE_BACKGROUNDERRORS), + "Preference " + PREF_APP_UPDATE_BACKGROUNDERRORS + " should not have a " + + "user value"); } /** @@ -786,10 +794,22 @@ function resetPrefs() { Services.prefs.clearUserPref(PREF_APP_UPDATE_LOG); } + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CERT_ERRORS)) { + Services.prefs.clearUserPref(PREF_APP_UPDATE_CERT_ERRORS); + } + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CERT_MAXERRORS)) { Services.prefs.clearUserPref(PREF_APP_UPDATE_CERT_MAXERRORS); } + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_BACKGROUNDERRORS)) { + Services.prefs.clearUserPref(PREF_APP_UPDATE_BACKGROUNDERRORS); + } + + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_BACKGROUNDMAXERRORS)) { + Services.prefs.clearUserPref(PREF_APP_UPDATE_BACKGROUNDMAXERRORS); + } + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CERT_INVALID_ATTR_NAME)) { Services.prefs.clearUserPref(PREF_APP_UPDATE_CERT_INVALID_ATTR_NAME); } @@ -1105,35 +1125,45 @@ function getUpdateWindow() { } /** - * Helper for certificate attribute check errors. + * Helper for background check errors. */ -var certErrorsPrefObserver = { +var errorsPrefObserver = { + observedPref: null, + maxErrorPref: null, + /** - * Sets up the app.update.cert.errors preference observer and sets the - * app.update.cert.maxErrors preference. + * Sets up a preference observer and sets the associated maximum errors + * preference used for background notification. * - * @param aMaxErrors + * @param aObservePref + * The preference to observe. + * @param aMaxErrorPref + * The maximum errors preference. + * @param aMaxErrorCount * The value to set the app.update.cert.maxErrors preference to. */ - init: function(aMaxErrors) { - let maxErrors = aMaxErrors ? aMaxErrors : 5; - Services.prefs.setIntPref(PREF_APP_UPDATE_CERT_MAXERRORS, maxErrors); - Services.prefs.addObserver(PREF_APP_UPDATE_CERT_ERRORS, this, false); + init: function(aObservePref, aMaxErrorPref, aMaxErrorCount) { + this.observedPref = aObservePref; + this.maxErrorPref = aMaxErrorPref; + + let maxErrors = aMaxErrorCount ? aMaxErrorCount : 5; + Services.prefs.setIntPref(aMaxErrorPref, maxErrors); + Services.prefs.addObserver(aObservePref, this, false); }, /** * Preference observer for the app.update.cert.errors preference. */ observe: function XPI_observe(aSubject, aTopic, aData) { - if (aData == PREF_APP_UPDATE_CERT_ERRORS) { - let errCount = Services.prefs.getIntPref(PREF_APP_UPDATE_CERT_ERRORS); - let errMax = Services.prefs.getIntPref(PREF_APP_UPDATE_CERT_MAXERRORS); + if (aData == this.observedPref) { + let errCount = Services.prefs.getIntPref(this.observedPref); + let errMax = Services.prefs.getIntPref(this.maxErrorPref); if (errCount >= errMax) { - debugDump("prefObserver - removing pref observer"); - Services.prefs.removeObserver(PREF_APP_UPDATE_CERT_ERRORS, this); + debugDump("errorsPrefObserver - removing pref observer"); + Services.prefs.removeObserver(this.observedPref, this); } else { - debugDump("prefObserver - notifying AUS"); + debugDump("errorsPrefObserver - notifying AUS"); SimpleTest.executeSoon(function() { gAUS.notify(null); }); diff --git a/toolkit/mozapps/update/test/shared.js b/toolkit/mozapps/update/test/shared.js index 93e0b3ede8b..70bcc91fcee 100644 --- a/toolkit/mozapps/update/test/shared.js +++ b/toolkit/mozapps/update/test/shared.js @@ -44,6 +44,8 @@ const AUS_Ci = Components.interfaces; const AUS_Cr = Components.results; const AUS_Cu = Components.utils; +const PREF_APP_UPDATE_BACKGROUNDERRORS = "app.update.backgroundErrors"; +const PREF_APP_UPDATE_BACKGROUNDMAXERRORS = "app.update.backgroundMaxErrors"; const PREF_APP_UPDATE_CERTS_BRANCH = "app.update.certs."; const PREF_APP_UPDATE_CERT_CHECKATTRS = "app.update.cert.checkAttributes"; const PREF_APP_UPDATE_CERT_ERRORS = "app.update.cert.errors";