From 51e8ac6bd8e552f5733c39c0de60040f41992077 Mon Sep 17 00:00:00 2001 From: Robert Strong Date: Wed, 1 Sep 2010 16:27:21 -0700 Subject: [PATCH] Patch 2 (tests only) - Bug 583408 - Notify user when the certificate attribute check fails. r=dtownsend, a=blocking2.0-beta6 --- .../mozapps/update/test/chrome/Makefile.in | 9 +- ...=> test_0121_check_requireBuiltinCert.xul} | 19 +--- ...eck_allowNonBuiltinCert_validCertAttrs.xul | 102 +++++++++++++++++ ...k_allowNonBuiltinCert_noCertAttrsCheck.xul | 60 ++++++++++ ...t_0131_check_invalidCertAttrs_noUpdate.xul | 56 +++++++++ ...0132_check_invalidCertAttrs_hasUpdate.xul} | 26 ++--- ..._0141_notify_invalidCertAttrs_noUpdate.xul | 55 +++++++++ ...0142_notify_invalidCertAttrs_hasUpdate.xul | 56 +++++++++ toolkit/mozapps/update/test/chrome/utils.js | 107 +++++++++++++++++- toolkit/mozapps/update/test/shared.js | 33 +++--- 10 files changed, 468 insertions(+), 55 deletions(-) rename toolkit/mozapps/update/test/chrome/{test_0120_cert_valid_attributes_not_builtin.xul => test_0121_check_requireBuiltinCert.xul} (81%) create mode 100644 toolkit/mozapps/update/test/chrome/test_0122_check_allowNonBuiltinCert_validCertAttrs.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0123_check_allowNonBuiltinCert_noCertAttrsCheck.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0131_check_invalidCertAttrs_noUpdate.xul rename toolkit/mozapps/update/test/chrome/{test_0121_cert_invalid_attribute_name.xul => test_0132_check_invalidCertAttrs_hasUpdate.xul} (62%) create mode 100644 toolkit/mozapps/update/test/chrome/test_0141_notify_invalidCertAttrs_noUpdate.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0142_notify_invalidCertAttrs_hasUpdate.xul diff --git a/toolkit/mozapps/update/test/chrome/Makefile.in b/toolkit/mozapps/update/test/chrome/Makefile.in index 9165cbaede7a..9951d8832b4d 100644 --- a/toolkit/mozapps/update/test/chrome/Makefile.in +++ b/toolkit/mozapps/update/test/chrome/Makefile.in @@ -85,8 +85,13 @@ _CHROME_FILES = \ test_0111_neverButton_basic.xul \ test_0112_neverButton_billboard.xul \ test_0113_showNeverForVersionRemovedWithPref.xul \ - test_0120_cert_valid_attributes_not_builtin.xul \ - test_0121_cert_invalid_attribute_name.xul \ + test_0121_check_requireBuiltinCert.xul \ + test_0122_check_allowNonBuiltinCert_validCertAttrs.xul \ + test_0123_check_allowNonBuiltinCert_noCertAttrsCheck.xul \ + test_0131_check_invalidCertAttrs_noUpdate.xul \ + test_0132_check_invalidCertAttrs_hasUpdate.xul \ + test_0141_notify_invalidCertAttrs_noUpdate.xul \ + test_0142_notify_invalidCertAttrs_hasUpdate.xul \ test_9999_cleanup.xul \ $(NULL) diff --git a/toolkit/mozapps/update/test/chrome/test_0120_cert_valid_attributes_not_builtin.xul b/toolkit/mozapps/update/test/chrome/test_0121_check_requireBuiltinCert.xul similarity index 81% rename from toolkit/mozapps/update/test/chrome/test_0120_cert_valid_attributes_not_builtin.xul rename to toolkit/mozapps/update/test/chrome/test_0121_check_requireBuiltinCert.xul index 57bfe278e2c8..743b24fa7285 100644 --- a/toolkit/mozapps/update/test/chrome/test_0120_cert_valid_attributes_not_builtin.xul +++ b/toolkit/mozapps/update/test/chrome/test_0121_check_requireBuiltinCert.xul @@ -8,7 +8,7 @@ - diff --git a/toolkit/mozapps/update/test/chrome/test_0122_check_allowNonBuiltinCert_validCertAttrs.xul b/toolkit/mozapps/update/test/chrome/test_0122_check_allowNonBuiltinCert_validCertAttrs.xul new file mode 100644 index 000000000000..43c219ad91db --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0122_check_allowNonBuiltinCert_validCertAttrs.xul @@ -0,0 +1,102 @@ + + + + + + + + + + +

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/test_0123_check_allowNonBuiltinCert_noCertAttrsCheck.xul b/toolkit/mozapps/update/test/chrome/test_0123_check_allowNonBuiltinCert_noCertAttrsCheck.xul new file mode 100644 index 000000000000..a7243507de49 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0123_check_allowNonBuiltinCert_noCertAttrsCheck.xul @@ -0,0 +1,60 @@ + + + + + + + + + + +

+ +

+
+
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 new file mode 100644 index 000000000000..3d226d776e66 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0131_check_invalidCertAttrs_noUpdate.xul @@ -0,0 +1,56 @@ + + + + + + + + + + +

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/test_0121_cert_invalid_attribute_name.xul b/toolkit/mozapps/update/test/chrome/test_0132_check_invalidCertAttrs_hasUpdate.xul similarity index 62% rename from toolkit/mozapps/update/test/chrome/test_0121_cert_invalid_attribute_name.xul rename to toolkit/mozapps/update/test/chrome/test_0132_check_invalidCertAttrs_hasUpdate.xul index c82f9d2191b9..c465a39a6a53 100644 --- a/toolkit/mozapps/update/test/chrome/test_0121_cert_invalid_attribute_name.xul +++ b/toolkit/mozapps/update/test/chrome/test_0132_check_invalidCertAttrs_hasUpdate.xul @@ -8,7 +8,7 @@ - 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 new file mode 100644 index 000000000000..295ade65d830 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0141_notify_invalidCertAttrs_noUpdate.xul @@ -0,0 +1,55 @@ + + + + + + + + + + +

+ +

+
+
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 new file mode 100644 index 000000000000..60a0352bac54 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0142_notify_invalidCertAttrs_hasUpdate.xul @@ -0,0 +1,56 @@ + + + + + + + + + + +

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/utils.js b/toolkit/mozapps/update/test/chrome/utils.js index a1642cfe12c6..e5121d086eac 100644 --- a/toolkit/mozapps/update/test/chrome/utils.js +++ b/toolkit/mozapps/update/test/chrome/utils.js @@ -127,6 +127,7 @@ const PAGEID_LICENSE = "license"; // Done const PAGEID_INCOMPAT_LIST = "incompatibleList"; // Done const PAGEID_DOWNLOADING = "downloading"; // Done const PAGEID_ERRORS = "errors"; // Done +const PAGEID_ERROR_CERT_CHECK = "errorcertcheck"; // Done const PAGEID_ERROR_PATCHING = "errorpatching"; // Done const PAGEID_FINISHED = "finished"; // Done const PAGEID_FINISHED_BKGRD = "finishedBackground"; // Done @@ -142,6 +143,9 @@ const URI_UPDATE_PROMPT_DIALOG = "chrome://mozapps/content/update/updates.xul"; const CRC_ERROR = 4; +const PREF_APP_UPDATE_CERT_INVALID_ATTR_NAME = PREF_APP_UPDATE_CERTS_BRANCH + + "1.invalidName"; + const ADDON_ID_SUFFIX = "@appupdatetest.mozilla.org"; const ADDON_PREP_DIR = "appupdateprep"; // Preference for storing add-ons that are disabled by the tests to prevent them @@ -161,10 +165,11 @@ var gTimeoutTimer; // The following vars are for restoring previous preference values (if present) // when the test finishes. -var gAppUpdateChannel; // app.update.channel (default prefbranch) -var gAppUpdateEnabled; // app.update.enabled -var gAppUpdateURL; // app.update.url.override -var gExtUpdateURL; // extensions.update.url +var gAppUpdateChannel; // app.update.channel (default prefbranch) +var gAppUpdateEnabled; // app.update.enabled +var gAppUpdateURLDefault; // app.update.url (default prefbranch) +var gAppUpdateURL; // app.update.url.override +var gExtUpdateURL; // extensions.update.url var gTestCounter = -1; var gWin; @@ -454,6 +459,7 @@ function getExpectedButtonStates() { case PAGEID_NO_UPDATES_FOUND: case PAGEID_MANUAL_UPDATE: case PAGEID_ERRORS: + case PAGEID_ERROR_CERT_CHECK: case PAGEID_INSTALLED: return { finish: { disabled: false, hidden: false } }; case PAGEID_ERROR_PATCHING: @@ -607,6 +613,29 @@ function checkPrefHasUserValue(aPrefHasValue) { (prefHasUserValue ? "true" : "false")); } +/** + * 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 + & have a user value. + * + * @param aShouldBeHidden (optional) + * The expected value for the label's hidden attribute for the link. If + * aShouldBeHidden is undefined the value of the current test's + * shouldBeHidden property will be used. + */ +function checkCertErrorPage(aShouldBeHidden) { + let shouldBeHidden = aShouldBeHidden === undefined ? gTest.shouldBeHidden + : aShouldBeHidden; + is(gWin.document.getElementById("errorCertAttrLinkLabel").hidden, shouldBeHidden, + "Checking errorCertAttrLinkLabel hidden attribute equals " + + (shouldBeHidden ? "true" : "false")); + + ok(!Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CERT_ERRORS), + "Preference " + PREF_APP_UPDATE_CERT_ERRORS + " should not have a " + + "user value"); +} + /** * Gets the update version info for the update url parameters to send to * update.sjs. @@ -684,6 +713,9 @@ function setupPrefs() { gAppUpdateChannel = gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_CHANNEL); setUpdateChannel(); + // Uncomment for debugging +// Services.prefs.setBoolPref(PREF_APP_UPDATE_LOG, true) + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_URL_OVERRIDE)) { gAppUpdateURL = Services.prefs.setIntPref(PREF_APP_UPDATE_URL_OVERRIDE); } @@ -715,6 +747,10 @@ function resetPrefs() { Services.prefs.clearUserPref(PREF_APP_UPDATE_URL_OVERRIDE); } + if (gAppUpdateURLDefault) { + gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_URL, gAppUpdateURLDefault); + } + if (gAppUpdateChannel !== undefined) { setUpdateChannel(gAppUpdateChannel); } @@ -749,6 +785,31 @@ function resetPrefs() { Services.prefs.clearUserPref(PREF_APP_UPDATE_LOG); } + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CERT_MAXERRORS)) { + Services.prefs.clearUserPref(PREF_APP_UPDATE_CERT_MAXERRORS); + } + + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CERT_INVALID_ATTR_NAME)) { + Services.prefs.clearUserPref(PREF_APP_UPDATE_CERT_INVALID_ATTR_NAME); + } + + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CERT_REQUIREBUILTIN)) { + Services.prefs.clearUserPref(PREF_APP_UPDATE_CERT_REQUIREBUILTIN); + } + + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CERT_CHECKATTRS)) { + Services.prefs.clearUserPref(PREF_APP_UPDATE_CERT_CHECKATTRS); + } + + try { + CERT_ATTRS.forEach(function(aCertAttrName) { + Services.prefs.clearUserPref(PREF_APP_UPDATE_CERTS_BRANCH + "1." + + aCertAttrName); + }); + } + catch (e) { + } + try { Services.prefs.deleteBranch(PREF_APP_UPDATE_NEVER_BRANCH); } @@ -1042,6 +1103,44 @@ function getUpdateWindow() { return Services.wm.getMostRecentWindow(UPDATE_WINDOW_NAME); } +/** + * Helper for certificate attribute check errors. + */ +var certErrorsPrefObserver = { + /** + * Sets up the app.update.cert.errors preference observer and sets the + * app.update.cert.maxErrors preference. + * + * @param aMaxErrors + * 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); + }, + + /** + * 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 (errCount >= errMax) { + debugDump("prefObserver - removing pref observer"); + Services.prefs.removeObserver(PREF_APP_UPDATE_CERT_ERRORS, this); + } + else { + debugDump("prefObserver - notifying AUS"); + SimpleTest.executeSoon(function() { + gAUS.notify(null); + }); + } + } + } +}; + /** * nsIObserver for receiving window open and close notifications. */ diff --git a/toolkit/mozapps/update/test/shared.js b/toolkit/mozapps/update/test/shared.js index 5ecdfe30cfed..d1b43d5bf8ad 100644 --- a/toolkit/mozapps/update/test/shared.js +++ b/toolkit/mozapps/update/test/shared.js @@ -44,23 +44,26 @@ const AUS_Ci = Components.interfaces; const AUS_Cr = Components.results; const AUS_Cu = Components.utils; -const PREF_APP_UPDATE_CERTS_BRANCH = "app.update.certs."; -const PREF_APP_UPDATE_CHANNEL = "app.update.channel"; -const PREF_APP_UPDATE_ENABLED = "app.update.enabled"; -const PREF_APP_UPDATE_IDLETIME = "app.update.idletime"; -const PREF_APP_UPDATE_LOG = "app.update.log"; -const PREF_APP_UPDATE_SHOW_INSTALLED_UI = "app.update.showInstalledUI"; -const PREF_APP_UPDATE_URL = "app.update.url"; -const PREF_APP_UPDATE_URL_DETAILS = "app.update.url.details"; -const PREF_APP_UPDATE_URL_OVERRIDE = "app.update.url.override"; +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"; +const PREF_APP_UPDATE_CERT_MAXERRORS = "app.update.cert.maxErrors"; +const PREF_APP_UPDATE_CERT_REQUIREBUILTIN = "app.update.cert.requireBuiltIn"; +const PREF_APP_UPDATE_CHANNEL = "app.update.channel"; +const PREF_APP_UPDATE_ENABLED = "app.update.enabled"; +const PREF_APP_UPDATE_IDLETIME = "app.update.idletime"; +const PREF_APP_UPDATE_LOG = "app.update.log"; +const PREF_APP_UPDATE_NEVER_BRANCH = "app.update.never."; +const PREF_APP_UPDATE_SHOW_INSTALLED_UI = "app.update.showInstalledUI"; +const PREF_APP_UPDATE_URL = "app.update.url"; +const PREF_APP_UPDATE_URL_DETAILS = "app.update.url.details"; +const PREF_APP_UPDATE_URL_OVERRIDE = "app.update.url.override"; -const PREF_APP_UPDATE_NEVER_BRANCH = "app.update.never."; +const PREF_APP_PARTNER_BRANCH = "app.partner."; +const PREF_DISTRIBUTION_ID = "distribution.id"; +const PREF_DISTRIBUTION_VERSION = "distribution.version"; -const PREF_APP_PARTNER_BRANCH = "app.partner."; -const PREF_DISTRIBUTION_ID = "distribution.id"; -const PREF_DISTRIBUTION_VERSION = "distribution.version"; - -const PREF_EXTENSIONS_UPDATE_URL = "extensions.update.url"; +const PREF_EXTENSIONS_UPDATE_URL = "extensions.update.url"; const NS_APP_PROFILE_DIR_STARTUP = "ProfDS"; const NS_APP_USER_PROFILE_50_DIR = "ProfD";