From f65845c1c5d79c4e33fea08fdff5ec6e562f7870 Mon Sep 17 00:00:00 2001 From: Robert Strong Date: Wed, 3 Mar 2010 10:57:09 -0800 Subject: [PATCH] 4. mochitest chrome tests for app update - Bug 530872. r=dtownsend --- toolkit/mozapps/update/test/Makefile.in | 4 + .../mozapps/update/test/chrome/Makefile.in | 84 ++++ ...011_check_billboard_noLicense_noAddons.xul | 234 +++++++++ .../test_0012_check_billboard_noAddons.xul | 473 ++++++++++++++++++ ...1_check_noBillboard_noLicense_noAddons.xul | 193 +++++++ .../test_0022_check_noBillboard_noAddons.xul | 428 ++++++++++++++++ ...available_billboard_noLicense_noAddons.xul | 158 ++++++ ...test_0032_available_billboard_noAddons.xul | 229 +++++++++ ...ailable_noBillboard_noLicense_noAddons.xul | 130 +++++ ...st_0042_available_noBillboard_noAddons.xul | 201 ++++++++ .../test_0051_check_error_xml_malformed.xul | 125 +++++ .../chrome/test_0052_check_no_updates.xul | 125 +++++ ...1_error_patchApplyFailure_partial_only.xul | 114 +++++ ..._error_patchApplyFailure_complete_only.xul | 114 +++++ ...ror_patchApplyFailure_partial_complete.xul | 134 +++++ ..._error_patchApplyFailure_verify_failed.xul | 136 +++++ .../test/chrome/test_0091_installed.xul | 114 +++++ .../chrome/test_0092_finishedBackground.xul | 116 +++++ .../test_0111_neverButton_billboard.xul | 142 ++++++ .../test_0112_neverButton_noBillboard.xul | 121 +++++ .../update/test/chrome/test_9999_cleanup.xul | 106 ++++ toolkit/mozapps/update/test/chrome/update.sjs | 81 +++ toolkit/mozapps/update/test/chrome/utils.js | 192 +++++++ toolkit/mozapps/update/test/shared.js | 2 + 24 files changed, 3756 insertions(+) create mode 100644 toolkit/mozapps/update/test/chrome/Makefile.in create mode 100644 toolkit/mozapps/update/test/chrome/test_0011_check_billboard_noLicense_noAddons.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0012_check_billboard_noAddons.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0021_check_noBillboard_noLicense_noAddons.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0022_check_noBillboard_noAddons.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0031_available_billboard_noLicense_noAddons.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0032_available_billboard_noAddons.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0041_available_noBillboard_noLicense_noAddons.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0042_available_noBillboard_noAddons.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0051_check_error_xml_malformed.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0052_check_no_updates.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0081_error_patchApplyFailure_partial_only.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0082_error_patchApplyFailure_complete_only.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0083_error_patchApplyFailure_partial_complete.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0084_error_patchApplyFailure_verify_failed.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0091_installed.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0092_finishedBackground.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0111_neverButton_billboard.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_0112_neverButton_noBillboard.xul create mode 100644 toolkit/mozapps/update/test/chrome/test_9999_cleanup.xul create mode 100644 toolkit/mozapps/update/test/chrome/update.sjs create mode 100644 toolkit/mozapps/update/test/chrome/utils.js diff --git a/toolkit/mozapps/update/test/Makefile.in b/toolkit/mozapps/update/test/Makefile.in index b24a3a79a0db..d0d2d93cd9c3 100644 --- a/toolkit/mozapps/update/test/Makefile.in +++ b/toolkit/mozapps/update/test/Makefile.in @@ -44,6 +44,10 @@ include $(DEPTH)/config/autoconf.mk MODULE = test_update +DIRS = \ + chrome \ + $(NULL) + XPCSHELL_TESTS = \ unit \ $(NULL) diff --git a/toolkit/mozapps/update/test/chrome/Makefile.in b/toolkit/mozapps/update/test/chrome/Makefile.in new file mode 100644 index 000000000000..b061a85af598 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/Makefile.in @@ -0,0 +1,84 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is +# the Mozilla Foundation. +# Portions created by the Initial Developer are Copyright (C) 2010 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Robert Strong (Original Author) +# +# Alternatively, the contents of this file may be used under the terms of +# either of the GNU General Public License Version 2 or later (the "GPL"), +# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ +relativesrcdir = toolkit/mozapps/update/test/chrome + +include $(DEPTH)/config/autoconf.mk + +_OTHER_FILES = \ + ../unit/data/empty.mar \ + $(NULL) + +_CHROME_FILES = \ + test_0011_check_billboard_noLicense_noAddons.xul \ + test_0012_check_billboard_noAddons.xul \ + test_0021_check_noBillboard_noLicense_noAddons.xul \ + test_0022_check_noBillboard_noAddons.xul \ + test_0031_available_billboard_noLicense_noAddons.xul \ + test_0032_available_billboard_noAddons.xul \ + test_0041_available_noBillboard_noLicense_noAddons.xul \ + test_0042_available_noBillboard_noAddons.xul \ + test_0051_check_error_xml_malformed.xul \ + test_0052_check_no_updates.xul \ + test_0081_error_patchApplyFailure_partial_only.xul \ + test_0082_error_patchApplyFailure_complete_only.xul \ + test_0083_error_patchApplyFailure_partial_complete.xul \ + test_0084_error_patchApplyFailure_verify_failed.xul \ + test_0091_installed.xul \ + test_0092_finishedBackground.xul \ + test_0111_neverButton_billboard.xul \ + test_0112_neverButton_noBillboard.xul \ + test_9999_cleanup.xul \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + +libs:: $(_OTHER_FILES) + $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir) + +libs:: $(_CHROME_FILES) + $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir) + +libs:: + $(PYTHON) $(MOZILLA_DIR)/config/Preprocessor.py -Fsubstitution $(DEFINES) $(ACDEFINES) $(srcdir)/utils.js > \ + $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)/utils.js + $(PYTHON) $(MOZILLA_DIR)/config/Preprocessor.py -Fsubstitution $(DEFINES) $(ACDEFINES) $(srcdir)/update.sjs > \ + $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)/update.sjs diff --git a/toolkit/mozapps/update/test/chrome/test_0011_check_billboard_noLicense_noAddons.xul b/toolkit/mozapps/update/test/chrome/test_0011_check_billboard_noLicense_noAddons.xul new file mode 100644 index 000000000000..403c348daa6e --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0011_check_billboard_noLicense_noAddons.xul @@ -0,0 +1,234 @@ + + + + + + + + + + +

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/test_0012_check_billboard_noAddons.xul b/toolkit/mozapps/update/test/chrome/test_0012_check_billboard_noAddons.xul new file mode 100644 index 000000000000..1673ef1d63b7 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0012_check_billboard_noAddons.xul @@ -0,0 +1,473 @@ + + + + + + + + + + +

+ +

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

+ +

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

+ +

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

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/test_0032_available_billboard_noAddons.xul b/toolkit/mozapps/update/test/chrome/test_0032_available_billboard_noAddons.xul new file mode 100644 index 000000000000..0345527b1c29 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0032_available_billboard_noAddons.xul @@ -0,0 +1,229 @@ + + + + + + + + + + +

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/test_0041_available_noBillboard_noLicense_noAddons.xul b/toolkit/mozapps/update/test/chrome/test_0041_available_noBillboard_noLicense_noAddons.xul new file mode 100644 index 000000000000..7ec2c5b5e98a --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0041_available_noBillboard_noLicense_noAddons.xul @@ -0,0 +1,130 @@ + + + + + + + + + + +

+ +

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

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/test_0051_check_error_xml_malformed.xul b/toolkit/mozapps/update/test/chrome/test_0051_check_error_xml_malformed.xul new file mode 100644 index 000000000000..139284e8e6eb --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0051_check_error_xml_malformed.xul @@ -0,0 +1,125 @@ + + + + + + + + + + +

+ +

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

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/test_0081_error_patchApplyFailure_partial_only.xul b/toolkit/mozapps/update/test/chrome/test_0081_error_patchApplyFailure_partial_only.xul new file mode 100644 index 000000000000..95c04d2c756d --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0081_error_patchApplyFailure_partial_only.xul @@ -0,0 +1,114 @@ + + + + + + + + + + +

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/test_0082_error_patchApplyFailure_complete_only.xul b/toolkit/mozapps/update/test/chrome/test_0082_error_patchApplyFailure_complete_only.xul new file mode 100644 index 000000000000..8a8a162cb0d7 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0082_error_patchApplyFailure_complete_only.xul @@ -0,0 +1,114 @@ + + + + + + + + + + +

+ +

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

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/test_0084_error_patchApplyFailure_verify_failed.xul b/toolkit/mozapps/update/test/chrome/test_0084_error_patchApplyFailure_verify_failed.xul new file mode 100644 index 000000000000..9b1055193965 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0084_error_patchApplyFailure_verify_failed.xul @@ -0,0 +1,136 @@ + + + + + + + + + + +

+ +

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

+ +

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

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/test_0111_neverButton_billboard.xul b/toolkit/mozapps/update/test/chrome/test_0111_neverButton_billboard.xul new file mode 100644 index 000000000000..8ce33a4f1e10 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_0111_neverButton_billboard.xul @@ -0,0 +1,142 @@ + + + + + + + + + + +

+ +

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

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/test_9999_cleanup.xul b/toolkit/mozapps/update/test/chrome/test_9999_cleanup.xul new file mode 100644 index 000000000000..44cb510dc828 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/test_9999_cleanup.xul @@ -0,0 +1,106 @@ + + + + + + + + + + +

+ +

+
+
diff --git a/toolkit/mozapps/update/test/chrome/update.sjs b/toolkit/mozapps/update/test/chrome/update.sjs new file mode 100644 index 000000000000..93ad7706ae80 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/update.sjs @@ -0,0 +1,81 @@ +#include ../shared.js + +const URL_HOST = "http://example.com/"; +const URL_PATH = "chrome/toolkit/mozapps/update/test/chrome/"; +const URL_UPDATE = URL_HOST + URL_PATH + "update.sjs"; +const SHA512_HASH = "1d2307e309587ddd04299423b34762639ce6af3ee17cfdaa8fdd4e6" + + "6b5a61bfb6555b6e40a82604908d6d68d3e42f318f82e22b6f5e111" + + "8b4222e3417a2fa2d0"; +const SERVICE_URL = URL_HOST + URL_PATH + "empty.mar"; + + +function handleRequest(request, response) { + response.setStatusLine(request.httpVersion, 200, "OK"); + response.setHeader("Cache-Control", "no-cache", false); + if (request.queryString.match(/^uiURL=/)) { + var uiURL = decodeURIComponent(request.queryString.substring(6)); + response.write("" + uiURL + + "

this is a test mar that will not affect your " + + "build."); + return; + } + + var params = { }; + if (request.queryString) + params = parseQueryString(request.queryString); + + if (params.xmlMalformed) { + response.write("xml error"); + return; + } + + if (params.noUpdates) { + response.write(getRemoteUpdatesXMLString("")); + return; + } + + var patches = getRemotePatchString("complete", SERVICE_URL, "SHA512", + SHA512_HASH, "775"); + + if (!params.completePatchOnly) + patches += getRemotePatchString("partial", SERVICE_URL, "SHA512", + SHA512_HASH, "775"); + var type = params.type ? params.type : "major"; + var name = params.name ? params.name : "App Update Test"; + var appVersion = params.appVersion ? params.appVersion : "99.9"; + var displayVersion = params.displayVersion ? params.displayVersion : "version " + appVersion; + var platformVersion = params.platformVersion ? params.platformVersion : "99.8"; + var buildID = params.buildID ? params.buildID : "01234567890123"; + // XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244 +// var detailsURL = params.showDetails ? URL_UPDATE + "?uiURL=DETAILS" : null; + var detailsURL = URL_UPDATE + "?uiURL=DETAILS"; + var billboardURL = params.showBillboard ? URL_UPDATE + "?uiURL=BILLBOARD" : null; + var licenseURL = params.showLicense ? URL_UPDATE + "?uiURL=LICENSE" : null; + var showPrompt = params.showPrompt ? "true" : null; + var showNever = params.showNever ? "true" : null; + var showSurvey = params.showSurvey ? "true" : null; + var extra1 = params.extra1 ? params.extra1 : null; + var updates = getRemoteUpdateString(patches, type, "App Update Test", + displayVersion, appVersion, + platformVersion, buildID, + detailsURL, billboardURL, + licenseURL, showPrompt, + showNever, showSurvey, "test extra1"); + + response.write(getRemoteUpdatesXMLString(updates)); +} + +function parseQueryString(str) { + var paramArray = str.split("&"); + var regex = /^([^=]+)=(.*)$/; + var params = {}; + for (var i = 0, sz = paramArray.length; i < sz; i++) { + var match = regex.exec(paramArray[i]); + if (!match) + throw "Bad parameter in queryString! '" + paramArray[i] + "'"; + params[decodeURIComponent(match[1])] = decodeURIComponent(match[2]); + } + + return params; +} diff --git a/toolkit/mozapps/update/test/chrome/utils.js b/toolkit/mozapps/update/test/chrome/utils.js new file mode 100644 index 000000000000..2d7ecd3047a6 --- /dev/null +++ b/toolkit/mozapps/update/test/chrome/utils.js @@ -0,0 +1,192 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * the Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Robert Strong (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** + */ + +// The tests have to use the pageid due to the wizard's access method being +// random. +const PAGEID_CHECKING = "checking"; // Done +const PAGEID_PLUGIN_UPDATES = "pluginupdatesfound"; +const PAGEID_NO_UPDATES_FOUND = "noupdatesfound"; // Done +const PAGEID_MANUAL_UPDATE = "manualUpdate"; // Can't test? Requires restricted access +const PAGEID_INCOMPAT_CHECK = "incompatibleCheck"; // Bug 546595 +const PAGEID_FOUND_BASIC = "updatesfoundbasic"; // Done +const PAGEID_FOUND_BILLBOARD = "updatesfoundbillboard"; // Done +const PAGEID_LICENSE = "license"; // Done +const PAGEID_INCOMPAT_LIST = "incompatibleList"; // Bug 546595 +const PAGEID_DOWNLOADING = "downloading"; // Done +const PAGEID_ERRORS = "errors"; // Done +const PAGEID_ERROR_PATCHING = "errorpatching"; // Done +const PAGEID_FINISHED = "finished"; // Done +const PAGEID_FINISHED_BKGRD = "finishedBackground"; // Done +const PAGEID_INSTALLED = "installed"; // Done + +const URL_HOST = "http://example.com/"; +const URL_PATH = "chrome/toolkit/mozapps/update/test/chrome"; +const URL_UPDATE = URL_HOST + URL_PATH + "/update.sjs"; + +const URI_UPDATE_PROMPT_DIALOG = "chrome://mozapps/content/update/updates.xul"; + +const CRC_ERROR = 4; + +var qUpdateChannel; +var gWin; +var gDocElem; +var gPageId; +var gNextFunc; + +#include ../shared.js + +/** + * Default run function that can be used by most tests + */ +function runTestDefault() { + ok(true, "Entering runTestDefault"); + + closeUpdateWindow(); + + gWW.registerNotification(gWindowObserver); + setUpdateChannel(); + test01(); +} + +/** + * Default finish function that can be used by most tests + */ +function finishTestDefault() { + ok(true, "Entering finishTestDefault"); + + gWW.unregisterNotification(gWindowObserver); + + resetPrefs(); + removeUpdateDirsAndFiles(); + reloadUpdateManagerData(); + SimpleTest.finish(); +} + +__defineGetter__("gWW", function() { + delete this.gWW; + return this.gWW = AUS_Cc["@mozilla.org/embedcomp/window-watcher;1"]. + getService(AUS_Ci.nsIWindowWatcher); +}); + + +/** + * Closes the update window in case a previous test failed to do so. + */ +function closeUpdateWindow() { + var updateWindow = getUpdateWindow(); + if (!updateWindow) + return; + + ok(true, "Found Update Window!!! Attempting to close it."); + updateWindow.close(); +} + +/** + * Returns the update window if it is open. + */ +function getUpdateWindow() { + var wm = AUS_Cc["@mozilla.org/appshell/window-mediator;1"]. + getService(AUS_Ci.nsIWindowMediator); + return wm.getMostRecentWindow("Update:Wizard"); +} + +var gWindowObserver = { + observe: function(aSubject, aTopic, aData) { + var win = aSubject.QueryInterface(AUS_Ci.nsIDOMEventTarget); + + if (aTopic == "domwindowclosed") { + if (win.location == URI_UPDATE_PROMPT_DIALOG) + gNextFunc(); + return; + } + + win.addEventListener("load", function onLoad() { + if (win.location != URI_UPDATE_PROMPT_DIALOG) + return; + + gWin = win; + gWin.removeEventListener("load", onLoad, false); + gDocElem = gWin.document.documentElement; + + // If the page loaded is the same as the page to be tested call the next + // function (e.g. the page shown is the wizard page the test is interested + // in) otherwise add an event listener to run the next function (e.g. the + // page will automatically advance to the wizard page the test is + // interested in). + if (gDocElem.currentPage && gDocElem.currentPage.pageid == gPageId) + gNextFunc(); + else + addPageShowListener(); + }, false); + } +}; + +function nextFuncListener(aEvent) { + gNextFunc(aEvent); +} + +function addPageShowListener() { + var page = gDocElem.getPageById(gPageId); + page.addEventListener("pageshow", function onPageShow(aEvent) { + page.removeEventListener("pageshow", onPageShow, false); + // Let the page initialize + SimpleTest.executeSoon(gNextFunc); + }, false); +} + +function resetPrefs() { + if (qUpdateChannel) + setUpdateChannel(qUpdateChannel); + if (gPref.prefHasUserValue(PREF_APP_UPDATE_IDLETIME)) + gPref.clearUserPref(PREF_APP_UPDATE_IDLETIME); + if (gPref.prefHasUserValue(PREF_APP_UPDATE_ENABLED)) + gPref.clearUserPref(PREF_APP_UPDATE_ENABLED); + if (gPref.prefHasUserValue(PREF_APP_UPDATE_LOG)) + gPref.clearUserPref(PREF_APP_UPDATE_LOG); + if (gPref.prefHasUserValue(PREF_APP_UPDATE_SHOW_INSTALLED_UI)) + gPref.clearUserPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI); + if (gPref.prefHasUserValue(PREF_APP_UPDATE_URL_DETAILS)) + gPref.clearUserPref(PREF_APP_UPDATE_URL_DETAILS); + if (gPref.prefHasUserValue(PREF_APP_UPDATE_URL_OVERRIDE)) + gPref.clearUserPref(PREF_APP_UPDATE_URL_OVERRIDE); + try { + gPref.deleteBranch(PREF_APP_UPDATE_NEVER_BRANCH); + } + catch(e) { + } +} diff --git a/toolkit/mozapps/update/test/shared.js b/toolkit/mozapps/update/test/shared.js index 9d12f4671fb6..f39dcd0bd879 100644 --- a/toolkit/mozapps/update/test/shared.js +++ b/toolkit/mozapps/update/test/shared.js @@ -45,6 +45,7 @@ const AUS_Cr = Components.results; 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_DETAILS = "app.update.url.details"; @@ -99,6 +100,7 @@ __defineGetter__("gAUS", function() { delete this.gAUS; return this.gAUS = AUS_Cc["@mozilla.org/updates/update-service;1"]. getService(AUS_Ci.nsIApplicationUpdateService). + QueryInterface(AUS_Ci.nsITimerCallback). QueryInterface(AUS_Ci.nsIObserver); });