Bug 601518 - Need updater tests to cover nsUpdateDriver.cpp code. r=dtownsend, a=blocking2.0-final

This commit is contained in:
Robert Strong 2010-10-19 21:28:29 -07:00
Родитель 547d6997e8
Коммит 28f9560f91
86 изменённых файлов: 2086 добавлений и 870 удалений

Просмотреть файл

@ -4824,7 +4824,8 @@
IfErrors continue +1
; If the uninstall.log does not exist don't perform post update
; operations. This prevents updating the registry for zip builds.
IfFileExists "$EXEDIR\uninstall.log" +1 finish
IfFileExists "$EXEDIR\uninstall.log" +2 +1
Quit ; Nothing initialized so no need to call OnEndCommon
${PostUpdate}
ClearErrors
${GetOptions} "$R0" "/UninstallLog=" $R2

Просмотреть файл

@ -43,16 +43,24 @@ relativesrcdir = toolkit/mozapps/update/test
include $(DEPTH)/config/autoconf.mk
DIRS = \
chrome \
$(NULL)
XPCSHELL_TESTS = \
unit \
$(NULL)
TESTROOT = $(call core_abspath,$(DEPTH))/_tests/xpcshell/$(relativesrcdir)
DEFINES += \
-DAB_CD=$(AB_CD) \
-DMOZ_APP_NAME=$(MOZ_APP_NAME) \
-DBIN_SUFFIX=$(BIN_SUFFIX) \
-DNS_NO_XPCOM \
$(NULL)
ifndef ANDROID
DIRS = \
chrome \
$(NULL)
CPPSRCS = \
TestAUSReadStrings.cpp \
$(NULL)
@ -72,11 +80,6 @@ LOCAL_INCLUDES += \
MOZ_WINCONSOLE = 1
DEFINES += \
-DAB_CD=$(AB_CD) \
-DNS_NO_XPCOM \
$(NULL)
LIBS += \
../../readstrings/$(LIB_PREFIX)readstrings.$(LIB_SUFFIX) \
$(NULL)
@ -102,9 +105,6 @@ else
bug473417dir = test_bug473417
endif
libs:: unit/head_update.js.in
$(PYTHON) $(MOZILLA_DIR)/config/Preprocessor.py -Fsubstitution $(DEFINES) $(ACDEFINES) $^ > $(TESTROOT)/unit/head_update.js
check::
$(RM) -rf $(DEPTH)/_tests/updater/ && $(NSINSTALL) -D $(DEPTH)/_tests/updater/$(bug473417dir)/
for i in $(INI_TEST_FILES); do \
@ -112,3 +112,7 @@ check::
done
$(INSTALL) $(FINAL_TARGET)/TestAUSReadStrings$(BIN_SUFFIX) $(DEPTH)/_tests/updater/$(bug473417dir)/
@$(RUN_TEST_PROGRAM) $(DEPTH)/_tests/updater/$(bug473417dir)/TestAUSReadStrings$(BIN_SUFFIX)
endif # ANDROID
libs:: unit/head_update.js.in
$(PYTHON) $(MOZILLA_DIR)/config/Preprocessor.py -Fsubstitution $(DEFINES) $(ACDEFINES) $^ > $(TESTROOT)/unit/head_update.js

Просмотреть файл

@ -44,7 +44,7 @@ relativesrcdir = toolkit/mozapps/update/test/chrome
include $(DEPTH)/config/autoconf.mk
_OTHER_FILES = \
../unit/data/empty.mar \
../unit/data/simple.mar \
$(NULL)
_CHROME_FILES = \

Просмотреть файл

@ -34,11 +34,10 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showDetails=1" + getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -74,11 +74,10 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showLicense=1&showDetails=1" + getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -38,12 +38,11 @@ const TESTS = [ {
gDisableNoUpdateAddon = true;
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showDetails=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump(PREF_APP_UPDATE_URL_OVERRIDE + ": " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -78,12 +78,11 @@ const TESTS = [ {
gDisableNoUpdateAddon = true;
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showLicense=1&showDetails=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -47,12 +47,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showDetails=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump(PREF_APP_UPDATE_URL_OVERRIDE + ": " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -87,12 +87,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showLicense=1&showDetails=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump(PREF_APP_UPDATE_URL_OVERRIDE + ": " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -41,11 +41,10 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showDetails=1" + getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -83,12 +83,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showLicense=1&showDetails=1" +
getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -45,12 +45,11 @@ const TESTS = [ {
gDisableNoUpdateAddon = true;
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showDetails=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump(PREF_APP_UPDATE_URL_OVERRIDE + ": " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -87,12 +87,11 @@ const TESTS = [ {
gDisableNoUpdateAddon = true;
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showLicense=1&showDetails=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -56,12 +56,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showDetails=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump(PREF_APP_UPDATE_URL_OVERRIDE + ": " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -96,12 +96,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showLicense=1&showDetails=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump(PREF_APP_UPDATE_URL_OVERRIDE + ": " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -32,11 +32,10 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showDetails=1&showPrompt=1" + getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gAUS.notify(null);
}

Просмотреть файл

@ -72,12 +72,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showLicense=1&showDetails=1&showPrompt=1" +
getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gAUS.notify(null);
}

Просмотреть файл

@ -36,12 +36,11 @@ const TESTS = [ {
gDisableNoUpdateAddon = true;
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showDetails=1&showPrompt=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gAUS.notify(null);
}

Просмотреть файл

@ -76,12 +76,11 @@ const TESTS = [ {
gDisableNoUpdateAddon = true;
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showLicense=1&showDetails=1&showPrompt=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gAUS.notify(null);
}

Просмотреть файл

@ -45,12 +45,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showDetails=1&showPrompt=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gAUS.notify(null);
}

Просмотреть файл

@ -85,12 +85,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showLicense=1&showDetails=1&showPrompt=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gAUS.notify(null);
}

Просмотреть файл

@ -39,12 +39,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showDetails=1&showPrompt=1" +
getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gAUS.notify(null);
}

Просмотреть файл

@ -81,12 +81,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showLicense=1&showDetails=1" +
"&showPrompt=1" + getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gAUS.notify(null);
}

Просмотреть файл

@ -43,12 +43,11 @@ const TESTS = [ {
gDisableNoUpdateAddon = true;
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showPrompt=1&showDetails=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump(PREF_APP_UPDATE_URL_OVERRIDE + ": " + url);
gAUS.notify(null);
}

Просмотреть файл

@ -85,12 +85,11 @@ const TESTS = [ {
gDisableNoUpdateAddon = true;
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showLicense=1&showDetails=1&showPrompt=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gAUS.notify(null);
}

Просмотреть файл

@ -54,12 +54,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showDetails=1&showPrompt=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gAUS.notify(null);
}

Просмотреть файл

@ -94,12 +94,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showLicense=1&showDetails=1&showPrompt=1" +
getVersionParams(getNewerAppVersion(), getNewerPlatformVersion());
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gAUS.notify(null);
}

Просмотреть файл

@ -29,11 +29,10 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?xmlMalformed=1";
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -29,11 +29,10 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?noUpdates=1";
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -40,12 +40,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showLicense=1&remoteNoTypeAttr=1" +
"&showDetails=1" + getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -40,12 +40,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?billboard404=1&license404=1&showDetails=1" +
getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -34,12 +34,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showDetails=1&partialPatchOnly=1&invalidPartialHash=1" +
getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -34,12 +34,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showDetails=1&completePatchOnly=1&invalidCompleteHash=1" +
getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -34,12 +34,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showDetails=1&invalidPartialHash=1&invalidCompleteHash=1" +
getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -34,12 +34,11 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showDetails=1&invalidPartialHash=1" +
getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -27,7 +27,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let patches = getLocalPatchString("partial", null, null, "1234", null, null,
STATE_DOWNLOADING);

Просмотреть файл

@ -27,7 +27,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let patches = getLocalPatchString("complete", null, null, "1234", null, null,
STATE_DOWNLOADING);

Просмотреть файл

@ -27,7 +27,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let patches = getLocalPatchString("partial", null, null, "1234", null, null,
STATE_DOWNLOADING) +

Просмотреть файл

@ -27,7 +27,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let patches = getLocalPatchString("partial", null, null, "1234", null, null,
STATE_DOWNLOADING) +

Просмотреть файл

@ -27,7 +27,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let patches = getLocalPatchString("partial", null, null, null, null, null,
STATE_PENDING);

Просмотреть файл

@ -27,7 +27,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let patches = getLocalPatchString("complete", null, null, null, null, null,
STATE_PENDING);

Просмотреть файл

@ -32,7 +32,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
// Specify the url to update.sjs with a slowDownloadMar param so the ui can
// load before the download completes.

Просмотреть файл

@ -32,7 +32,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
// Specify the url to update.sjs with a slowDownloadMar param so the ui can
// load before the download completes.

Просмотреть файл

@ -27,7 +27,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
Services.prefs.setBoolPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI, true);
let patches = getLocalPatchString("complete", null, null, null, null, null,

Просмотреть файл

@ -27,7 +27,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let patches = getLocalPatchString("complete", null, null, null, null, null,
STATE_PENDING);

Просмотреть файл

@ -34,11 +34,10 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showNever=1&showDetails=1" + getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
// add the never preference for this version to verify that checking for
// updates clears the preference.

Просмотреть файл

@ -42,11 +42,10 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showBillboard=1&showNever=1" + getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
// add the never preference for this version to verify that checking for
// updates clears the preference.

Просмотреть файл

@ -31,11 +31,10 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?showDetails=1&showPrompt=1" + getVersionParams();
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
// add the never preference for this version to verify that checking for
// updates clears the preference.

Просмотреть файл

@ -36,20 +36,22 @@ const CERT_ATTRS = ["nickname", "emailAddress", "subjectName", "commonName",
"issuerCommonName", "issuerOrganization",
"issuerOrganizationUnit", "dbKey", "windowTitle"];
function runTest() {
debugDump("Entering runTest");
var gRequest;
var request = AUS_Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
createInstance(AUS_Ci.nsIXMLHttpRequest);
request.open("GET", "https://example.com/", true);
request.channel.notificationCallbacks = new BadCertHandler(true);
request.onload = function(event) { testXHRLoad(event); };
request.onerror = function(event) { testXHRError(event); };
request.send(null);
function runTest() {
debugDump("entering");
gRequest = AUS_Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
createInstance(AUS_Ci.nsIXMLHttpRequest);
gRequest.open("GET", "https://example.com/", true);
gRequest.channel.notificationCallbacks = new BadCertHandler(true);
gRequest.onload = function(event) { testXHRLoad(event); };
gRequest.onerror = function(event) { testXHRError(event); };
gRequest.send(null);
}
function testXHRError(aEvent) {
debugDump("Entering testXHRError");
debugDump("entering");
ok(true, "Entering testXHRError - something went wrong");
@ -66,11 +68,12 @@ function testXHRError(aEvent) {
ok(false, "XHR onerror called: " + status);
gRequest = null;
finishTestDefault();
}
function testXHRLoad(aEvent) {
debugDump("Entering testXHRLoad");
debugDump("entering");
var channel = aEvent.target.channel;
var cert = channel.securityInfo.QueryInterface(AUS_Ci.nsISSLStatusProvider).
@ -83,12 +86,21 @@ function testXHRLoad(aEvent) {
let url = "https://example.com/" + URL_PATH + "/update.sjs?showDetails=1" +
getVersionParams();
gAppUpdateURLDefault = gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_URL);
debugDump("setting default pref " + PREF_APP_UPDATE_URL + " to " + url);
gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_URL, url);
debugDump("Default Update URL: " + url);
gRequest = null;
gUP.checkForUpdates();
}
function finishTest() {
if (gRequest) {
gRequest.abort();
gRequest = null;
}
finishTestDefault();
}
]]>
</script>

Просмотреть файл

@ -36,20 +36,22 @@ const CERT_ATTRS = ["nickname", "emailAddress", "subjectName", "commonName",
"issuerCommonName", "issuerOrganization",
"issuerOrganizationUnit", "dbKey", "windowTitle"];
function runTest() {
debugDump("Entering runTest");
var gRequest;
var request = AUS_Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
createInstance(AUS_Ci.nsIXMLHttpRequest);
request.open("GET", "https://example.com/", true);
request.channel.notificationCallbacks = new BadCertHandler(true);
request.onload = function(event) { testXHRLoad(event); };
request.onerror = function(event) { testXHRError(event); };
request.send(null);
function runTest() {
debugDump("entering");
gRequest = AUS_Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
createInstance(AUS_Ci.nsIXMLHttpRequest);
gRequest.open("GET", "https://example.com/", true);
gRequest.channel.notificationCallbacks = new BadCertHandler(true);
gRequest.onload = function(event) { testXHRLoad(event); };
gRequest.onerror = function(event) { testXHRError(event); };
gRequest.send(null);
}
function testXHRError(aEvent) {
debugDump("Entering testXHRError");
debugDump("entering");
ok(true, "Entering testXHRError - something went wrong");
@ -66,11 +68,12 @@ function testXHRError(aEvent) {
ok(false, "XHR onerror called: " + status);
gRequest = null;
finishTestDefault();
}
function testXHRLoad(aEvent) {
debugDump("Entering testXHRLoad");
debugDump("entering");
var channel = aEvent.target.channel;
var cert = channel.securityInfo.QueryInterface(AUS_Ci.nsISSLStatusProvider).
@ -85,12 +88,21 @@ function testXHRLoad(aEvent) {
let url = "https://example.com/" + URL_PATH + "/update.sjs?showDetails=1" +
getVersionParams();
gAppUpdateURLDefault = gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_URL);
debugDump("setting default pref " + PREF_APP_UPDATE_URL + " to " + url);
gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_URL, url);
debugDump("Default Update URL: " + url);
gRequest = null;
gUP.checkForUpdates();
}
function finishTest() {
if (gRequest) {
gRequest.abort();
gRequest = null;
}
finishTestDefault();
}
]]>
</script>

Просмотреть файл

@ -31,7 +31,7 @@ const TESTS = [ {
Components.utils.import("resource://gre/modules/CertUtils.jsm");
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
Services.prefs.setCharPref(PREF_APP_UPDATE_CERT_INVALID_ATTR_NAME,
"Invalid Attribute Name");
@ -42,8 +42,8 @@ function runTest() {
let url = "https://example.com/" + URL_PATH + "/update.sjs?showDetails=1" +
getVersionParams();
gAppUpdateURLDefault = gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_URL);
debugDump("setting default pref " + PREF_APP_UPDATE_URL + " to " + url);
gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_URL, url);
debugDump("Default Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -32,7 +32,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
Services.prefs.setCharPref(PREF_APP_UPDATE_CERT_INVALID_ATTR_NAME,
"Invalid Attribute Name");
@ -40,8 +40,8 @@ function runTest() {
let url = "https://example.com/" + URL_PATH + "/update.sjs?noUpdates=1";
gAppUpdateURLDefault = gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_URL);
debugDump("setting default pref " + PREF_APP_UPDATE_URL + " to " + url);
gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_URL, url);
debugDump("Default Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -32,7 +32,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
Services.prefs.setCharPref(PREF_APP_UPDATE_CERT_INVALID_ATTR_NAME,
"Invalid Attribute Name");
@ -41,8 +41,8 @@ function runTest() {
let url = "https://example.com/" + URL_PATH + "/update.sjs?showDetails=1" +
getVersionParams();
gAppUpdateURLDefault = gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_URL);
debugDump("setting default pref " + PREF_APP_UPDATE_URL + " to " + url);
gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_URL, url);
debugDump("Default Update URL: " + url);
gUP.checkForUpdates();
}

Просмотреть файл

@ -30,15 +30,15 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
Services.prefs.setCharPref(PREF_APP_UPDATE_CERT_INVALID_ATTR_NAME,
"Invalid Attribute Name");
let url = "https://example.com/" + URL_PATH + "/update.sjs?noUpdates=1";
gAppUpdateURLDefault = gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_URL);
debugDump("setting default pref " + PREF_APP_UPDATE_URL + " to " + url);
gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_URL, url);
debugDump("Default Update URL: " + url);
errorsPrefObserver.init(PREF_APP_UPDATE_CERT_ERRORS,
PREF_APP_UPDATE_CERT_MAXERRORS);

Просмотреть файл

@ -30,7 +30,7 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
Services.prefs.setCharPref(PREF_APP_UPDATE_CERT_INVALID_ATTR_NAME,
"Invalid Attribute Name");
@ -38,8 +38,8 @@ function runTest() {
let url = "https://example.com/" + URL_PATH + "/update.sjs?showDetails=1" +
getVersionParams();
gAppUpdateURLDefault = gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_URL);
debugDump("setting default pref " + PREF_APP_UPDATE_URL + " to " + url);
gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_URL, url);
debugDump("Default Update URL: " + url);
errorsPrefObserver.init(PREF_APP_UPDATE_CERT_ERRORS,
PREF_APP_UPDATE_CERT_MAXERRORS);

Просмотреть файл

@ -30,11 +30,10 @@ const TESTS = [ {
} ];
function runTest() {
debugDump("Entering runTest");
debugDump("entering");
let url = URL_UPDATE + "?xmlMalformed=1";
setUpdateURLOverride(url);
debugDump("Update URL: " + url);
errorsPrefObserver.init(PREF_APP_UPDATE_BACKGROUNDERRORS,
PREF_APP_UPDATE_BACKGROUNDMAXERRORS);

Просмотреть файл

@ -34,7 +34,7 @@
* happening.
*/
function runTest() {
ok(true, "Entering runTest - cleanup");
debugDump("entering");
SimpleTest.waitForExplicitFinish();
@ -74,8 +74,9 @@ function runTest() {
removeDirRecursive(addonPrepDir);
}
catch (e) {
debugDump("removeDirRecursive failed to remove the " + ADDON_PREP_DIR +
" from the profile. " + e);
dump("Unable to remove directory\n" +
"path: " + addonPrepDir.path + "\n" +
"Exception: " + e + "\n");
}
resetAddons(SimpleTest.finish);

Просмотреть файл

@ -1,12 +1,23 @@
#include ../shared.js
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/**
* Server side http server script for application update tests.
*
* !IMPORTANT - Since xpcshell used by the http server is launched with -v 170
* this file must not use features greater than JavaScript 1.7.
*/
const AUS_Cc = Components.classes;
const AUS_Ci = Components.interfaces;
#include ../sharedUpdateXML.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";
const SERVICE_URL = URL_HOST + URL_PATH + FILE_SIMPLE_MAR;
const SLOW_MAR_DOWNLOAD_INTERVAL = 100;
@ -33,11 +44,11 @@ function handleRequest(aRequest, aResponse) {
if (params.slowDownloadMar) {
aResponse.processAsync();
aResponse.setHeader("Content-Type", "binary/octet-stream");
aResponse.setHeader("Content-Length", "775");
aResponse.setHeader("Content-Length", SIZE_SIMPLE_MAR);
var marFile = AUS_Cc["@mozilla.org/file/directory_service;1"].
getService(AUS_Ci.nsIProperties).
get("CurWorkD", AUS_Ci.nsILocalFile);
var path = URL_PATH + "empty.mar";
var path = URL_PATH + FILE_SIMPLE_MAR;
var pathParts = path.split("/");
for(var i = 0; i < pathParts.length; ++i)
marFile.append(pathParts[i]);
@ -54,8 +65,9 @@ function handleRequest(aRequest, aResponse) {
if (params.uiURL) {
var remoteType = "";
if (!params.remoteNoTypeAttr &&
(params.uiURL == "BILLBOARD" || params.uiURL == "LICENSE"))
(params.uiURL == "BILLBOARD" || params.uiURL == "LICENSE")) {
remoteType = " " + params.uiURL.toLowerCase() + "=\"1\"";
}
aResponse.write("<html><head><meta http-equiv=\"content-type\" content=" +
"\"text/html; charset=utf-8\"></head><body" +
remoteType + ">" + params.uiURL +
@ -77,15 +89,15 @@ function handleRequest(aRequest, aResponse) {
var hash;
var patches = "";
if (!params.partialPatchOnly) {
hash = SHA512_HASH + (params.invalidCompleteHash ? "e" : "");
hash = SHA512_HASH_SIMPLE_MAR + (params.invalidCompleteHash ? "e" : "");
patches += getRemotePatchString("complete", SERVICE_URL, "SHA512",
hash, "775");
hash, SIZE_SIMPLE_MAR);
}
if (!params.completePatchOnly) {
hash = SHA512_HASH + (params.invalidPartialHash ? "e" : "");
hash = SHA512_HASH_SIMPLE_MAR + (params.invalidPartialHash ? "e" : "");
patches += getRemotePatchString("partial", SERVICE_URL, "SHA512",
hash, "775");
hash, SIZE_SIMPLE_MAR);
}
var type = params.type ? params.type : "major";
@ -203,3 +215,31 @@ function getUpdateRDF(aParams) {
" </RDF:Description>\n" +
"</RDF:RDF>\n";
}
/**
* Reads the binary contents of a file and returns it as a string.
*
* @param aFile
* The file to read from.
* @return The contents of the file as a string.
*/
function readFileBytes(aFile) {
var fis = AUS_Cc["@mozilla.org/network/file-input-stream;1"].
createInstance(AUS_Ci.nsIFileInputStream);
fis.init(aFile, -1, -1, false);
var bis = AUS_Cc["@mozilla.org/binaryinputstream;1"].
createInstance(AUS_Ci.nsIBinaryInputStream);
bis.setInputStream(fis);
var data = [];
var count = fis.available();
while (count > 0) {
var bytes = bis.readByteArray(Math.min(65535, count));
data.push(String.fromCharCode.apply(null, bytes));
count -= bytes.length;
if (bytes.length == 0)
throw "Nothing read from input stream!";
}
data.join('');
fis.close();
return data.toString();
}

Просмотреть файл

@ -153,11 +153,17 @@ const TEST_ADDONS = [ "appdisabled_1", "appdisabled_2",
"updateversion_1", "updateversion_2",
"userdisabled_1", "userdisabled_2" ];
const DEBUG = false;
const TEST_TIMEOUT = 30000; // 30 seconds
const TEST_TIMEOUT = 20000; // 20 seconds
var gTimeoutTimer;
// The number of SimpleTest.executeSoon calls to perform when waiting on an
// update window to close before giving up.
const CLOSE_WINDOW_TIMEOUT_MAXCOUNT = 10;
// Counter for the SimpleTest.executeSoon when waiting on an update window to
// close before giving up.
var gCloseWindowTimeoutCounter = 0;
// The following vars are for restoring previous preference values (if present)
// when the test finishes.
var gAppUpdateChannel; // app.update.channel (default prefbranch)
@ -172,13 +178,12 @@ var gDocElem;
var gPrefToCheck;
var gDisableNoUpdateAddon = false;
#include ../shared.js
// Set to true to log additional information for debugging. To log additional
// information for an individual test set DEBUG_AUS_TEST to true in the test's
// onload function.
var DEBUG_AUS_TEST = false;
function debugDump(msg) {
if (DEBUG) {
dump("*** " + msg + "\n");
}
}
#include ../shared.js
/**
* The current test in TESTS array.
@ -237,10 +242,13 @@ __defineGetter__("gIncompatibleListbox", function() {
});
/**
* Default test run function that can be used by most tests.
* Default test run function that can be used by most tests. This function uses
* protective measures to prevent the test from failing provided by
* |runTestDefaultWaitForWindowClosed| helper functions to prevent failure due
* to a previous test failure.
*/
function runTestDefault() {
debugDump("Entering runTestDefault");
debugDump("entering");
if (!("@mozilla.org/zipwriter;1" in AUS_Cc)) {
ok(false, "nsIZipWriter is required to run these tests");
@ -249,22 +257,53 @@ function runTestDefault() {
SimpleTest.waitForExplicitFinish();
Services.ww.registerNotification(gWindowObserver);
setupPrefs();
removeUpdateDirsAndFiles();
reloadUpdateManagerData();
setupAddons(runTest);
runTestDefaultWaitForWindowClosed();
}
/**
* Default test finish function that can be used by most tests.
* If an update window is found SimpleTest.executeSoon can callback before the
* update window is fully closed especially with debug builds. If an update
* window is found this function will call itself using SimpleTest.executeSoon
* up to the amount declared in CLOSE_WINDOW_TIMEOUT_MAXCOUNT until the update
* window has closed before continuing the test.
*/
function runTestDefaultWaitForWindowClosed() {
gCloseWindowTimeoutCounter++;
if (gCloseWindowTimeoutCounter > CLOSE_WINDOW_TIMEOUT_MAXCOUNT) {
try {
finishTest();
}
catch (e) {
finishTestDefault();
}
return;
}
// The update window should not be open at this time. If it is the call to
// |closeUpdateWindow| will close it and cause the test to fail.
if (closeUpdateWindow()) {
SimpleTest.executeSoon(runTestDefaultWaitForWindowClosed);
}
else {
Services.ww.registerNotification(gWindowObserver);
gCloseWindowTimeoutCounter = 0;
setupPrefs();
removeUpdateDirsAndFiles();
reloadUpdateManagerData();
setupAddons(runTest);
}
}
/**
* Default test finish function that can be used by most tests. This function
* uses protective measures to prevent the next test from failing provided by
* |finishTestDefaultWaitForWindowClosed| helper functions to prevent failure
* due to an update window being left open.
*/
function finishTestDefault() {
debugDump("Entering finishTestDefault");
gDocElem.removeEventListener("pageshow", onPageShowDefault, false);
debugDump("entering");
if (gTimeoutTimer) {
gTimeoutTimer.cancel();
gTimeoutTimer = null;
@ -272,12 +311,16 @@ function finishTestDefault() {
verifyTestsRan();
Services.ww.unregisterNotification(gWindowObserver);
resetPrefs();
removeUpdateDirsAndFiles();
reloadUpdateManagerData();
SimpleTest.finish();
Services.ww.unregisterNotification(gWindowObserver);
if (gDocElem) {
gDocElem.removeEventListener("pageshow", onPageShowDefault, false);
}
finishTestDefaultWaitForWindowClosed();
}
/**
@ -289,10 +332,39 @@ function finishTestDefault() {
* The nsITimer that fired.
*/
function finishTestTimeout(aTimer) {
gTimeoutTimer = null;
ok(false, "Test timed out. Maximum time allowed is " + (TEST_TIMEOUT / 1000) +
" seconds");
gWin.close();
try {
finishTest();
}
catch (e) {
finishTestDefault();
}
}
/**
* If an update window is found SimpleTest.executeSoon can callback before the
* update window is fully closed especially with debug builds. If an update
* window is found this function will call itself using SimpleTest.executeSoon
* up to the amount declared in CLOSE_WINDOW_TIMEOUT_MAXCOUNT until the update
* window has closed before finishing the test.
*/
function finishTestDefaultWaitForWindowClosed() {
gCloseWindowTimeoutCounter++;
if (gCloseWindowTimeoutCounter > CLOSE_WINDOW_TIMEOUT_MAXCOUNT) {
SimpleTest.finish();
return;
}
// The update window should not be open at this time. If it is the call to
// |closeUpdateWindow| will close it and cause the test to fail.
if (closeUpdateWindow()) {
SimpleTest.executeSoon(finishTestDefaultWaitForWindowClosed);
}
else {
SimpleTest.finish();
}
}
/**
@ -301,12 +373,16 @@ function finishTestTimeout(aTimer) {
* wizardpage.
*/
function onPageShowDefault(aEvent) {
if (!gTimeoutTimer) {
debugDump("gTimeoutTimer is null... returning early");
return;
}
// Return early if the event's original target isn't for a wizardpage element.
// This check is necessary due to the remotecontent element firing pageshow.
if (aEvent.originalTarget.nodeName != "wizardpage") {
debugDump("onPageShowDefault - only handles events with an " +
"originalTarget nodeName of |wizardpage|. " +
"aEvent.originalTarget.nodeName = " +
debugDump("only handles events with an originalTarget nodeName of " +
"|wizardpage|. aEvent.originalTarget.nodeName = " +
aEvent.originalTarget.nodeName + "... returning early");
return;
}
@ -319,15 +395,19 @@ function onPageShowDefault(aEvent) {
* Default callback that can be used by most tests.
*/
function defaultCallback(aEvent) {
debugDump("Entering defaultCallback - TESTS[" + gTestCounter + "], " +
"pageid: " + gTest.pageid + ", " +
"aEvent.originalTarget.nodeName: " + aEvent.originalTarget.nodeName);
if (!gTimeoutTimer) {
debugDump("gTimeoutTimer is null... returning early");
return;
}
debugDump("entering - TESTS[" + gTestCounter + "], pageid: " + gTest.pageid +
", aEvent.originalTarget.nodeName: " +
aEvent.originalTarget.nodeName);
if (gTest && gTest.extraStartFunction) {
debugDump("defaultCallback - calling extraStartFunction " +
gTest.extraStartFunction.name);
debugDump("calling extraStartFunction " + gTest.extraStartFunction.name);
if (gTest.extraStartFunction(aEvent)) {
debugDump("defaultCallback - extraStartFunction early return");
debugDump("extraStartFunction early return");
return;
}
}
@ -337,8 +417,7 @@ function defaultCallback(aEvent) {
// Perform extra checks if specified by the test
if (gTest.extraCheckFunction) {
debugDump("delayedCallback - calling extraCheckFunction " +
gTest.extraCheckFunction.name);
debugDump("calling extraCheckFunction " + gTest.extraCheckFunction.name);
gTest.extraCheckFunction();
}
@ -354,8 +433,12 @@ function defaultCallback(aEvent) {
* before checking their values.
*/
function delayedDefaultCallback() {
debugDump("Entering delayedDefaultCallback - TESTS[" + gTestCounter + "], " +
"pageid: " + gTest.pageid);
if (!gTimeoutTimer) {
debugDump("gTimeoutTimer is null... returning early");
return;
}
debugDump("entering - TESTS[" + gTestCounter + "], pageid: " + gTest.pageid);
// Verify the pageid hasn't changed after executeSoon was called.
is(gDocElem.currentPage.pageid, gTest.pageid,
@ -366,7 +449,7 @@ function delayedDefaultCallback() {
// Perform delayed extra checks if specified by the test
if (gTest.extraDelayedCheckFunction) {
debugDump("delayedDefaultCallback - calling extraDelayedCheckFunction " +
debugDump("calling extraDelayedCheckFunction " +
gTest.extraDelayedCheckFunction.name);
gTest.extraDelayedCheckFunction();
}
@ -375,15 +458,14 @@ function delayedDefaultCallback() {
gTest.ranTest = true;
if (gTest.buttonClick) {
debugDump("delayedDefaultCallback - clicking " + gTest.buttonClick +
" button");
debugDump("clicking " + gTest.buttonClick + " button");
if(gTest.extraDelayedFinishFunction) {
throw("Tests cannot have a buttonClick and an extraDelayedFinishFunction property");
}
gDocElem.getButton(gTest.buttonClick).click();
}
else if (gTest.extraDelayedFinishFunction) {
debugDump("delayedDefaultCallback - calling extraDelayedFinishFunction " +
debugDump("calling extraDelayedFinishFunction " +
gTest.extraDelayedFinishFunction.name);
gTest.extraDelayedFinishFunction();
}
@ -395,8 +477,7 @@ function delayedDefaultCallback() {
* and hidden attribute value is true.
*/
function checkButtonStates() {
debugDump("Entering checkButtonStates - TESTS[" + gTestCounter + "], " +
"pageid: " + gTest.pageid);
debugDump("entering - TESTS[" + gTestCounter + "], pageid: " + gTest.pageid);
const buttonNames = ["extra1", "extra2", "back", "next", "finish", "cancel"];
let buttonStates = getExpectedButtonStates();
@ -471,8 +552,7 @@ function getExpectedButtonStates() {
* Adds a load event listener to the current remotecontent element.
*/
function addRemoteContentLoadListener() {
debugDump("Entering addRemoteContentLoadListener - TESTS[" + gTestCounter +
"], pageid: " + gTest.pageid);
debugDump("entering - TESTS[" + gTestCounter + "], pageid: " + gTest.pageid);
gRemoteContent.addEventListener("load", remoteContentLoadListener, false);
}
@ -483,9 +563,8 @@ function addRemoteContentLoadListener() {
function remoteContentLoadListener(aEvent) {
// Return early if the event's original target's nodeName isn't remotecontent.
if (aEvent.originalTarget.nodeName != "remotecontent") {
debugDump("remoteContentLoadListener - only handles events with an " +
"originalTarget nodeName of |remotecontent|. " +
"aEvent.originalTarget.nodeName = " +
debugDump("only handles events with an originalTarget nodeName of " +
"|remotecontent|. aEvent.originalTarget.nodeName = " +
aEvent.originalTarget.nodeName);
return;
}
@ -511,7 +590,7 @@ function waitForRemoteContentLoaded(aEvent) {
// expected or isn't the event's originalTarget.
if (gRemoteContentState != gTest.expectedRemoteContentState ||
!aEvent.originalTarget.isSameNode(gRemoteContent)) {
debugDump("waitForRemoteContentLoaded - returning early\n" +
debugDump("returning early\n" +
"gRemoteContentState: " + gRemoteContentState + "\n" +
"expectedRemoteContentState: " +
gTest.expectedRemoteContentState + "\n" +
@ -539,8 +618,7 @@ function checkRemoteContentState() {
* the radio element specified in the current test's radioClick property.
*/
function addRadioGroupSelectListenerAndClick() {
debugDump("Entering addRadioGroupSelectListenerAndClick - TESTS[" +
gTestCounter + "], pageid: " + gTest.pageid);
debugDump("entering - TESTS[" + gTestCounter + "], pageid: " + gTest.pageid);
gAcceptDeclineLicense.addEventListener("select", radioGroupSelectListener,
false);
@ -553,9 +631,8 @@ function addRadioGroupSelectListenerAndClick() {
function radioGroupSelectListener(aEvent) {
// Return early if the event's original target's nodeName isn't radiogroup.
if (aEvent.originalTarget.nodeName != "radiogroup") {
debugDump("remoteContentLoadListener - only handles events with an " +
"originalTarget nodeName of |radiogroup|. " +
"aEvent.originalTarget.nodeName = " +
debugDump("only handles events with an originalTarget nodeName of " +
"|radiogroup|. aEvent.originalTarget.nodeName = " +
aEvent.originalTarget.nodeName);
return;
}
@ -689,7 +766,7 @@ function getNewerPlatformVersion() {
* Verifies that all tests ran.
*/
function verifyTestsRan() {
debugDump("Entering verifyTestsRan");
debugDump("entering");
// Return early if there are no tests defined.
if (!TESTS) {
@ -716,12 +793,12 @@ function setupPrefs() {
gAppUpdateChannel = gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_CHANNEL);
setUpdateChannel();
if (DEBUG) {
if (DEBUG_AUS_TEST) {
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);
gAppUpdateURL = Services.prefs.getCharPref(PREF_APP_UPDATE_URL_OVERRIDE);
}
if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_ENABLED)) {
@ -849,7 +926,7 @@ function resetPrefs() {
* A callback to call after all operations have completed.
*/
function setupAddons(aCallback) {
debugDump("Entering setupAddons");
debugDump("entering");
// Sets the appropriate userDisabled value for the noupdate test add-ons based
// on the value of gDisableNoUpdateAddon and calls the callback specified in
@ -871,6 +948,12 @@ function setupAddons(aCallback) {
}
}
});
// Start the timout timer before the update window is displayed so it can
// clean up tests that don't successfully display the update window.
gTimeoutTimer = AUS_Cc["@mozilla.org/timer;1"].
createInstance(AUS_Ci.nsITimer);
gTimeoutTimer.initWithCallback(finishTestTimeout, TEST_TIMEOUT,
AUS_Ci.nsITimer.TYPE_ONE_SHOT);
aCallback();
});
}
@ -956,13 +1039,13 @@ function setupAddons(aCallback) {
* A callback to call after all operations have completed.
*/
function resetAddons(aCallback) {
debugDump("Entering resetAddons");
debugDump("entering");
// If test_9999_cleanup.xul is ran by itself then the test add-ons will not
// have been installed and any pre-existing add-ons will not have been
// disabled so return early.
if (!Services.prefs.prefHasUserValue(PREF_DISABLEDADDONS)) {
debugDump("resetAddons - preference " + PREF_DISABLEDADDONS + " doesn't " +
"exist... returning early");
debugDump("preference " + PREF_DISABLEDADDONS + " doesn't exist... " +
"returning early");
aCallback();
return;
}
@ -1102,16 +1185,20 @@ function getInstallRDFString(aName) {
}
/**
* Closes the update window if it is open.
* Closes the update window if it is open and causes the test to fail if an
* update window is found.
*
* @return true if an update window was found, otherwise false.
*/
function closeUpdateWindow() {
let updateWindow = getUpdateWindow();
if (!updateWindow)
return;
return false;
ok(false, "Found an existing Update Window from a previous test... " +
"attempting to close it.");
ok(false, "Found an existing Update Window from the current or a previous " +
"test... attempting to close it.");
updateWindow.close();
return true;
}
/**
@ -1146,24 +1233,24 @@ var errorsPrefObserver = {
this.observedPref = aObservePref;
this.maxErrorPref = aMaxErrorPref;
let maxErrors = aMaxErrorCount ? aMaxErrorCount : 5;
let maxErrors = aMaxErrorCount ? aMaxErrorCount : 2;
Services.prefs.setIntPref(aMaxErrorPref, maxErrors);
Services.prefs.addObserver(aObservePref, this, false);
},
/**
* Preference observer for the app.update.cert.errors preference.
* Preference observer for the preference specified in |this.observedPref|.
*/
observe: function XPI_observe(aSubject, aTopic, aData) {
if (aData == this.observedPref) {
let errCount = Services.prefs.getIntPref(this.observedPref);
let errMax = Services.prefs.getIntPref(this.maxErrorPref);
if (errCount >= errMax) {
debugDump("errorsPrefObserver - removing pref observer");
debugDump("removing pref observer");
Services.prefs.removeObserver(this.observedPref, this);
}
else {
debugDump("errorsPrefObserver - notifying AUS");
debugDump("notifying AUS");
SimpleTest.executeSoon(function() {
gAUS.notify(null);
});
@ -1181,9 +1268,8 @@ var gWindowObserver = {
if (aTopic == "domwindowclosed") {
if (win.location != URI_UPDATE_PROMPT_DIALOG) {
debugDump("gWindowObserver:observe - domwindowclosed event for " +
"window not being tested - location: " + win.location +
"... returning early");
debugDump("domwindowclosed event for window not being tested - " +
"location: " + win.location + "... returning early");
return;
}
// Allow tests the ability to provide their own function (it must be
@ -1197,13 +1283,12 @@ var gWindowObserver = {
return;
}
win.addEventListener("load", function onLoad() {
win.removeEventListener("load", onLoad, false);
win.addEventListener("load", function WO_observe_onLoad() {
win.removeEventListener("load", WO_observe_onLoad, false);
// Ignore windows other than the update UI window.
if (win.location != URI_UPDATE_PROMPT_DIALOG) {
debugDump("gWindowObserver:observe:onLoad - load event for window " +
"not being tested - location: " + win.location +
"... returning early");
debugDump("load event for window not being tested - location: " +
win.location + "... returning early");
return;
}
@ -1217,11 +1302,6 @@ var gWindowObserver = {
return;
}
gTimeoutTimer = AUS_Cc["@mozilla.org/timer;1"].
createInstance(AUS_Ci.nsITimer);
gTimeoutTimer.initWithCallback(finishTestTimeout, TEST_TIMEOUT,
AUS_Ci.nsITimer.TYPE_ONE_SHOT);
gWin = win;
gDocElem = gWin.document.documentElement;
gDocElem.addEventListener("pageshow", onPageShowDefault, false);

Просмотреть файл

@ -78,24 +78,18 @@ const NS_GRE_DIR = "GreD";
const NS_XPCOM_CURRENT_PROCESS_DIR = "XCurProcD";
const XRE_UPDATE_ROOT_DIR = "UpdRootD";
const STATE_NONE = "null";
const STATE_DOWNLOADING = "downloading";
const STATE_PENDING = "pending";
const STATE_APPLYING = "applying";
const STATE_SUCCEEDED = "succeeded";
const STATE_DOWNLOAD_FAILED = "download-failed";
const STATE_FAILED = "failed";
const CRC_ERROR = 4;
const WRITE_ERROR = 7;
const FILE_BACKUP_LOG = "backup-update.log";
const FILE_LAST_LOG = "last-update.log";
const FILE_UPDATER_INI = "updater.ini";
const FILE_UPDATES_DB = "updates.xml";
const FILE_UPDATE_ACTIVE = "active-update.xml";
const FILE_UPDATE_ARCHIVE = "update.mar";
const FILE_UPDATE_LOG = "update.log";
const FILE_UPDATE_STATUS = "update.status";
const FILE_UPDATE_VERSION = "update.version";
const MODE_RDONLY = 0x01;
const MODE_WRONLY = 0x02;
@ -113,48 +107,42 @@ const PR_EXCL = 0x80;
const PERMS_FILE = 0644;
const PERMS_DIRECTORY = 0755;
#include sharedUpdateXML.js
AUS_Cu.import("resource://gre/modules/Services.jsm");
AUS_Cu.import("resource://gre/modules/XPCOMUtils.jsm");
const URI_UPDATES_PROPERTIES = "chrome://mozapps/locale/update/updates.properties";
const gUpdateBundle = Services.strings.createBundle(URI_UPDATES_PROPERTIES);
__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);
XPCOMUtils.defineLazyGetter(this, "gAUS", function test_gAUS() {
return AUS_Cc["@mozilla.org/updates/update-service;1"].
getService(AUS_Ci.nsIApplicationUpdateService).
QueryInterface(AUS_Ci.nsITimerCallback).
QueryInterface(AUS_Ci.nsIObserver);
});
__defineGetter__("gUpdateManager", function() {
delete this.gUpdateManager;
return this.gUpdateManager = AUS_Cc["@mozilla.org/updates/update-manager;1"].
getService(AUS_Ci.nsIUpdateManager);
XPCOMUtils.defineLazyServiceGetter(this, "gUpdateManager",
"@mozilla.org/updates/update-manager;1",
"nsIUpdateManager");
XPCOMUtils.defineLazyGetter(this, "gUpdateChecker", function test_gUC() {
return AUS_Cc["@mozilla.org/updates/update-checker;1"].
createInstance(AUS_Ci.nsIUpdateChecker);
});
__defineGetter__("gUpdateChecker", function() {
delete this.gUpdateChecker;
return this.gUpdateChecker = AUS_Cc["@mozilla.org/updates/update-checker;1"].
createInstance(AUS_Ci.nsIUpdateChecker);
XPCOMUtils.defineLazyGetter(this, "gUP", function test_gUP() {
return AUS_Cc["@mozilla.org/updates/update-prompt;1"].
createInstance(AUS_Ci.nsIUpdatePrompt);
});
__defineGetter__("gUP", function() {
delete this.gUP;
return this.gUP = AUS_Cc["@mozilla.org/updates/update-prompt;1"].
createInstance(AUS_Ci.nsIUpdatePrompt);
XPCOMUtils.defineLazyGetter(this, "gDefaultPrefBranch", function test_gDPB() {
return Services.prefs.getDefaultBranch(null);
});
__defineGetter__("gDefaultPrefBranch", function() {
delete this.gDefaultPrefBranch;
return this.gDefaultPrefBranch = Services.prefs.getDefaultBranch(null);
});
__defineGetter__("gZipW", function() {
delete this.gZipW;
return this.gZipW = AUS_Cc["@mozilla.org/zipwriter;1"].
createInstance(AUS_Ci.nsIZipWriter);
XPCOMUtils.defineLazyGetter(this, "gZipW", function test_gZipW() {
return AUS_Cc["@mozilla.org/zipwriter;1"].
createInstance(AUS_Ci.nsIZipWriter);
});
/* Initializes the update service stub */
@ -175,8 +163,9 @@ function reloadUpdateManagerData() {
* The update channel. If not specified 'test_channel' will be used.
*/
function setUpdateChannel(aChannel) {
gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_CHANNEL,
aChannel ? aChannel : "test_channel");
let channel = aChannel ? aChannel : "test_channel";
debugDump("setting default pref " + PREF_APP_UPDATE_CHANNEL + " to " + channel);
gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_CHANNEL, channel);
}
/**
@ -186,292 +175,9 @@ function setUpdateChannel(aChannel) {
* used.
*/
function setUpdateURLOverride(aURL) {
Services.prefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE,
aURL ? aURL : URL_HOST + "update.xml");
}
/**
* Constructs a string representing a remote update xml file.
* @param aUpdates
* The string representing the update elements.
* @returns The string representing a remote update xml file.
*/
function getRemoteUpdatesXMLString(aUpdates) {
return "<?xml version=\"1.0\"?>\n" +
"<updates>\n" +
aUpdates +
"</updates>\n";
}
/**
* Constructs a string representing an update element for a remote update xml
* file.
* See getUpdateString
* @returns The string representing an update element for an update xml file.
*/
function getRemoteUpdateString(aPatches, aType, aName, aDisplayVersion,
aAppVersion, aPlatformVersion, aBuildID,
aDetailsURL, aBillboardURL, aLicenseURL,
aShowPrompt, aShowNeverForVersion, aShowSurvey,
aVersion, aExtensionVersion, aCustom1,
aCustom2) {
return getUpdateString(aType, aName, aDisplayVersion, aAppVersion,
aPlatformVersion, aBuildID, aDetailsURL,
aBillboardURL, aLicenseURL, aShowPrompt,
aShowNeverForVersion, aShowSurvey, aVersion,
aExtensionVersion, aCustom1, aCustom2) + ">\n" +
aPatches +
" </update>\n";
}
/**
* Constructs a string representing a patch element for a remote update xml
* file
* See getPatchString
* @returns The string representing a patch element for a remote update xml
* file.
*/
function getRemotePatchString(aType, aURL, aHashFunction, aHashValue, aSize) {
return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) +
"/>\n";
}
/**
* Constructs a string representing a local update xml file.
* @param aUpdates
* The string representing the update elements.
* @returns The string representing a local update xml file.
*/
function getLocalUpdatesXMLString(aUpdates) {
if (!aUpdates || aUpdates == "")
return "<updates xmlns=\"http://www.mozilla.org/2005/app-update\"/>"
return ("<updates xmlns=\"http://www.mozilla.org/2005/app-update\">" +
aUpdates +
"</updates>").replace(/>\s+\n*</g,'><');
}
/**
* Constructs a string representing an update element for a local update xml
* file.
* See getUpdateString
* @param aServiceURL
* The update's xml url.
* If null will default to 'http://test_service/'.
* @param aIsCompleteUpdate
* The string 'true' if this update was a complete update or the string
* 'false' if this update was a partial update.
* If null will default to 'true'.
* @param aChannel
* The update channel name.
* If null will default to 'test_channel'.
* @param aForegroundDownload
* The string 'true' if this update was manually downloaded or the
* string 'false' if this update was automatically downloaded.
* If null will default to 'true'.
* @param aPreviousAppVersion
* The application version prior to applying the update.
* If null will not be present.
* @returns The string representing an update element for an update xml file.
*/
function getLocalUpdateString(aPatches, aType, aName, aDisplayVersion,
aAppVersion, aPlatformVersion, aBuildID,
aDetailsURL, aBillboardURL, aLicenseURL,
aServiceURL, aInstallDate, aStatusText,
aIsCompleteUpdate, aChannel, aForegroundDownload,
aShowPrompt, aShowNeverForVersion, aShowSurvey,
aVersion, aExtensionVersion, aPreviousAppVersion,
aCustom1, aCustom2) {
var serviceURL = aServiceURL ? aServiceURL : "http://test_service/";
var installDate = aInstallDate ? aInstallDate : "1238441400314";
var statusText = aStatusText ? aStatusText : "Install Pending";
var isCompleteUpdate = typeof(aIsCompleteUpdate) == "string" ? aIsCompleteUpdate : "true";
var channel = aChannel ? aChannel : "test_channel";
var foregroundDownload =
typeof(aForegroundDownload) == "string" ? aForegroundDownload : "true";
var previousAppVersion = aPreviousAppVersion ? "previousAppVersion=\"" + aPreviousAppVersion + "\" " : "";
return getUpdateString(aType, aName, aDisplayVersion, aAppVersion,
aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL,
aLicenseURL, aShowPrompt, aShowNeverForVersion,
aShowSurvey, aVersion, aExtensionVersion, aCustom1,
aCustom2) +
" " +
previousAppVersion +
"serviceURL=\"" + serviceURL + "\" " +
"installDate=\"" + installDate + "\" " +
"statusText=\"" + statusText + "\" " +
"isCompleteUpdate=\"" + isCompleteUpdate + "\" " +
"channel=\"" + channel + "\" " +
"foregroundDownload=\"" + foregroundDownload + "\">" +
aPatches +
" </update>";
}
/**
* Constructs a string representing a patch element for a local update xml file.
* See getPatchString
* @param aSelected
* Whether this patch is selected represented or not. The string 'true'
* denotes selected and the string 'false' denotes not selected.
* If null will default to the string 'true'.
* @param aState
* The patch's state.
* If null will default to STATE_SUCCEEDED (e.g. 'succeeded').
* @returns The string representing a patch element for a local update xml file.
*/
function getLocalPatchString(aType, aURL, aHashFunction, aHashValue, aSize,
aSelected, aState) {
var selected = typeof(aSelected) == "string" ? aSelected : "true";
var state = aState ? aState : STATE_SUCCEEDED;
return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) + " " +
"selected=\"" + selected + "\" " +
"state=\"" + state + "\"/>\n";
}
/**
* Constructs a string representing an update element for a remote update xml
* file.
* @param aType
* The update's type which should be major or minor.
* If null will default to 'major'.
* @param aName
* The update's name.
* If null will default to 'App Update Test'.
* @param aDisplayVersion
* The update's display version.
* If null will default to 'version 99.0'.
* @param aAppVersion
* The update's application version.
* If null will default to '99.0'.
* @param aPlatformVersion
* The update's platform version.
* If null will default to '99.0'.
* @param aBuildID
* The update's build id.
* If null will default to '20080811053724'.
* @param aDetailsURL
* The update's details url.
* If null will default to 'http://test_details/' due to due to
* bug 470244.
* @param aBillboardURL
* The update's billboard url.
* If null it will not be added.
* @param aLicenseURL
* The update's license url.
* If null will not be added.
* @param aShowPrompt
* Whether to show the prompt for the update when auto update is
* enabled.
* If null will not be added and the backend will default to false.
* @param aShowNeverForVersion
* Whether to show the 'No Thanks' button in the update prompt.
* If null will not be added and the backend will default to false.
* @param aShowSurvey
* Whether to show the 'No Thanks' button in the update prompt.
* If null will not be added and the backend will default to false.
* @param aVersion
* The update's application version from 1.9.2.
* If null will not be present.
* @param aExtensionVersion
* The update's application version from 1.9.2.
* If null will not be present.
* @param aCustom1
* A custom attribute name AND attribute value to add to the xml.
* Example: custom1_attribute="custom1 value"
* If null will not be present.
* @param aCustom2
* A custom attribute name AND attribute value to add to the xml.
* Example: custom2_attribute="custom2 value"
* If null will not be present.
* @returns The string representing an update element for an update xml file.
*/
function getUpdateString(aType, aName, aDisplayVersion, aAppVersion,
aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL,
aLicenseURL, aShowPrompt, aShowNeverForVersion,
aShowSurvey, aVersion, aExtensionVersion, aCustom1,
aCustom2) {
var type = aType ? aType : "major";
var name = aName ? aName : "App Update Test";
var displayVersion = "";
if (aDisplayVersion || !aVersion) {
displayVersion = "displayVersion=\"" +
(aDisplayVersion ? aDisplayVersion
: "version 99.0") + "\" ";
}
// version has been deprecated in favor of displayVersion but it still needs
// to be tested for forward compatibility.
var version = aVersion ? "version=\"" + aVersion + "\" " : "";
var appVersion = "";
if (aAppVersion || !aExtensionVersion) {
appVersion = "appVersion=\"" + (aAppVersion ? aAppVersion : "99.0") + "\" ";
}
// extensionVersion has been deprecated in favor of appVersion but it still
// needs to be tested for forward compatibility.
var extensionVersion = aExtensionVersion ? "extensionVersion=\"" + aExtensionVersion + "\" " : "";
var platformVersion = "";
if (aPlatformVersion) {
platformVersion = "platformVersion=\"" + (aPlatformVersion ? aPlatformVersion : "99.0") + "\" ";
}
var buildID = aBuildID ? aBuildID : "20080811053724";
// XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244
// var detailsURL = aDetailsURL ? "detailsURL=\"" + aDetailsURL + "\" " : "";
var detailsURL = "detailsURL=\"" + (aDetailsURL ? aDetailsURL : "http://test_details/") + "\" ";
var billboardURL = aBillboardURL ? "billboardURL=\"" + aBillboardURL + "\" " : "";
var licenseURL = aLicenseURL ? "licenseURL=\"" + aLicenseURL + "\" " : "";
var showPrompt = aShowPrompt ? "showPrompt=\"" + aShowPrompt + "\" " : "";
var showNeverForVersion = aShowNeverForVersion ? "showNeverForVersion=\"" + aShowNeverForVersion + "\" " : "";
var showSurvey = aShowSurvey ? "showSurvey=\"" + aShowSurvey + "\" " : "";
var custom1 = aCustom1 ? aCustom1 + " " : "";
var custom2 = aCustom2 ? aCustom2 + " " : "";
return " <update type=\"" + type + "\" " +
"name=\"" + name + "\" " +
displayVersion +
version +
appVersion +
extensionVersion +
platformVersion +
detailsURL +
billboardURL +
licenseURL +
showPrompt +
showNeverForVersion +
showSurvey +
custom1 +
custom2 +
"buildID=\"" + buildID + "\"";
}
/**
* Constructs a string representing a patch element for an update xml file.
* @param aType
* The patch's type which should be complete or partial.
* If null will default to 'complete'.
* @param aURL
* The patch's url to the mar file.
* If null will default to 'http://localhost:4444/data/empty.mar'.
* @param aHashFunction
* The patch's hash function used to verify the mar file.
* If null will default to 'MD5'.
* @param aHashValue
* The patch's hash value used to verify the mar file.
* If null will default to '6232cd43a1c77e30191c53a329a3f99d'
* which is the MD5 hash value for the empty.mar.
* @param aSize
* The patch's file size for the mar file.
* If null will default to '775' which is the file size for the
* empty.mar.
* @returns The string representing a patch element for an update xml file.
*/
function getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) {
var type = aType ? aType : "complete";
var url = aURL ? aURL : URL_HOST + URL_PATH + "/empty.mar";
var hashFunction = aHashFunction ? aHashFunction : "MD5";
var hashValue = aHashValue ? aHashValue : "6232cd43a1c77e30191c53a329a3f99d";
var size = aSize ? aSize : "775";
return " <patch type=\"" + type + "\" " +
"URL=\"" + url + "\" " +
"hashFunction=\"" + hashFunction + "\" " +
"hashValue=\"" + hashValue + "\" " +
"size=\"" + size + "\"";
let url = aURL ? aURL : URL_HOST + "update.xml";
debugDump("setting " + PREF_APP_UPDATE_URL_OVERRIDE + " to " + url);
Services.prefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
}
/**
@ -504,6 +210,20 @@ function writeStatusFile(aStatus) {
writeFile(file, aStatus);
}
/**
* Writes the current update version to a file in the patch directory,
& indicating to the patching system the version of the update.
* @param aVersion
* The version value to write.
*/
function writeVersionFile(aVersion) {
var file = getUpdatesDir();
file.append("0");
file.append(FILE_UPDATE_VERSION);
aVersion += "\n";
writeFile(file, aVersion);
}
/**
* Gets the updates directory.
* @returns The updates directory.
@ -533,6 +253,28 @@ function writeFile(aFile, aText) {
fos.close();
}
/**
* Reads the current update operation/state in a file in the patch
* directory.
* @param aDir (optional)
* nsIFile to read the update status from. If not provided the
* application's update status file will be used.
* @returns The status value.
*/
function readStatusFile(aFile) {
var file;
if (aFile) {
file = aFile.clone();
file.append(FILE_UPDATE_STATUS);
}
else {
file = getUpdatesDir();
file.append("0");
file.append(FILE_UPDATE_STATUS);
}
return readFile(file).split("\n")[0];
}
/**
* Reads text from a file and returns the string.
* @param aFile
@ -554,7 +296,7 @@ function readFile(aFile) {
}
/**
* Reads the binary contents of a file and returns is as a string.
* Reads the binary contents of a file and returns it as a string.
* @param aFile
* The file to read from.
* @returns The contents of the file as a string.
@ -563,18 +305,18 @@ function readFileBytes(aFile) {
var fis = AUS_Cc["@mozilla.org/network/file-input-stream;1"].
createInstance(AUS_Ci.nsIFileInputStream);
fis.init(aFile, -1, -1, false);
var bis = AUS_Cc["@mozilla.org/binaryinputstream;1"].
createInstance(AUS_Ci.nsIBinaryInputStream);
bis.setInputStream(fis);
var data = [];
var count = fis.available();
while (count > 0) {
var bytes = bis.readByteArray(Math.min(65535, count));
data.push(String.fromCharCode.apply(null, bytes));
count -= bytes.length;
if (bytes.length == 0)
do_throw("Nothing read from input stream!");
}
var bis = AUS_Cc["@mozilla.org/binaryinputstream;1"].
createInstance(AUS_Ci.nsIBinaryInputStream);
bis.setInputStream(fis);
var data = [];
var count = fis.available();
while (count > 0) {
var bytes = bis.readByteArray(Math.min(65535, count));
data.push(String.fromCharCode.apply(null, bytes));
count -= bytes.length;
if (bytes.length == 0)
do_throw("Nothing read from input stream!");
}
data.join('');
fis.close();
return data.toString();
@ -737,3 +479,32 @@ function getCurrentProcessDir() {
function getGREDir() {
return Services.dirsvc.get(NS_GRE_DIR, AUS_Ci.nsIFile);
}
/**
* Logs TEST-INFO messages.
* @param aText
* The text to log.
* @param aCaller (optional)
* An optional Components.stack.caller. If not specified
* Components.stack.caller will be used.
*/
function logTestInfo(aText, aCaller) {
let caller = (aCaller ? aCaller : Components.stack.caller);
dump("TEST-INFO | " + caller.filename + " | [" + caller.name + " : " +
caller.lineNumber + "] " + aText + "\n");
}
/**
* Logs TEST-INFO messages when DEBUG_AUS_TEST evaluates to true.
* @param aText
* The text to log.
* @param aCaller (optional)
* An optional Components.stack.caller. If not specified
* Components.stack.caller will be used.
*/
function debugDump(aText, aCaller) {
if (DEBUG_AUS_TEST) {
let caller = aCaller ? aCaller : Components.stack.caller;
logTestInfo(aText, caller);
}
}

Просмотреть файл

@ -0,0 +1,343 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/**
* Helper functions for creating xml strings used by application update tests.
*
* !IMPORTANT - This file contains everything needed (along with dependencies)
* by the updates.sjs file used by the mochitest-chrome tests. Since xpcshell
* used by the http server is launched with -v 170 this file must not use
* features greater than JavaScript 1.7.
*/
const FILE_SIMPLE_MAR = "simple.mar";
const SIZE_SIMPLE_MAR = "351";
const MD5_HASH_SIMPLE_MAR = "d0a7f84dacc55a252ab916668a7cb216";
const SHA1_HASH_SIMPLE_MAR = "f5053f9552d087c6c6ed83f9b19405eccf1436fc";
const SHA256_HASH_SIMPLE_MAR = "663c7cbd11fe45b0a71438387db924d205997ab85ccf5" +
"b40aebbdaef179796ab";
const SHA384_HASH_SIMPLE_MAR = "a57250554755a9f42b91932993599bb6b05e063dcbd71" +
"846e350232945dbad2b0c83208a07810cf798b3d11393" +
"99c453";
const SHA512_HASH_SIMPLE_MAR = "55d3e2a86acaeb0abb7a444c13bba748846fcbac7ff05" +
"8f8ee9c9260ba01e6aef86fa4a6c46a3016b675ef94e7" +
"7e63fbe912f64d155bed9b1c341dd56e575a26";
const STATE_NONE = "null";
const STATE_DOWNLOADING = "downloading";
const STATE_PENDING = "pending";
const STATE_APPLYING = "applying";
const STATE_SUCCEEDED = "succeeded";
const STATE_DOWNLOAD_FAILED = "download-failed";
const STATE_FAILED = "failed";
/**
* Constructs a string representing a remote update xml file.
*
* @param aUpdates
* The string representing the update elements.
* @return The string representing a remote update xml file.
*/
function getRemoteUpdatesXMLString(aUpdates) {
return "<?xml version=\"1.0\"?>\n" +
"<updates>\n" +
aUpdates +
"</updates>\n";
}
/**
* Constructs a string representing an update element for a remote update xml
* file. See getUpdateString for parameter information not provided below.
*
* @param aPatches
* String representing the application update patches.
* @return The string representing an update element for an update xml file.
*/
function getRemoteUpdateString(aPatches, aType, aName, aDisplayVersion,
aAppVersion, aPlatformVersion, aBuildID,
aDetailsURL, aBillboardURL, aLicenseURL,
aShowPrompt, aShowNeverForVersion, aShowSurvey,
aVersion, aExtensionVersion, aCustom1,
aCustom2) {
return getUpdateString(aType, aName, aDisplayVersion, aAppVersion,
aPlatformVersion, aBuildID, aDetailsURL,
aBillboardURL, aLicenseURL, aShowPrompt,
aShowNeverForVersion, aShowSurvey, aVersion,
aExtensionVersion, aCustom1, aCustom2) + ">\n" +
aPatches +
" </update>\n";
}
/**
* Constructs a string representing a patch element for a remote update xml
* file. See getPatchString for parameter information not provided below.
*
* @return The string representing a patch element for a remote update xml file.
*/
function getRemotePatchString(aType, aURL, aHashFunction, aHashValue, aSize) {
return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) +
"/>\n";
}
/**
* Constructs a string representing a local update xml file.
*
* @param aUpdates
* The string representing the update elements.
* @return The string representing a local update xml file.
*/
function getLocalUpdatesXMLString(aUpdates) {
if (!aUpdates || aUpdates == "")
return "<updates xmlns=\"http://www.mozilla.org/2005/app-update\"/>"
return ("<updates xmlns=\"http://www.mozilla.org/2005/app-update\">" +
aUpdates +
"</updates>").replace(/>\s+\n*</g,'><');
}
/**
* Constructs a string representing an update element for a local update xml
* file. See getUpdateString for parameter information not provided below.
*
* @param aPatches
* String representing the application update patches.
* @param aServiceURL (optional)
* The update's xml url.
* If not specified it will default to 'http://test_service/'.
* @param aIsCompleteUpdate (optional)
* The string 'true' if this update was a complete update or the string
* 'false' if this update was a partial update.
* If not specified it will default to 'true'.
* @param aChannel (optional)
* The update channel name.
* If not specified it will default to 'test_channel'.
* @param aForegroundDownload (optional)
* The string 'true' if this update was manually downloaded or the
* string 'false' if this update was automatically downloaded.
* If not specified it will default to 'true'.
* @param aPreviousAppVersion (optional)
* The application version prior to applying the update.
* If not specified it will not be present.
* @return The string representing an update element for an update xml file.
*/
function getLocalUpdateString(aPatches, aType, aName, aDisplayVersion,
aAppVersion, aPlatformVersion, aBuildID,
aDetailsURL, aBillboardURL, aLicenseURL,
aServiceURL, aInstallDate, aStatusText,
aIsCompleteUpdate, aChannel, aForegroundDownload,
aShowPrompt, aShowNeverForVersion, aShowSurvey,
aVersion, aExtensionVersion, aPreviousAppVersion,
aCustom1, aCustom2) {
let serviceURL = aServiceURL ? aServiceURL : "http://test_service/";
let installDate = aInstallDate ? aInstallDate : "1238441400314";
let statusText = aStatusText ? aStatusText : "Install Pending";
let isCompleteUpdate =
typeof(aIsCompleteUpdate) == "string" ? aIsCompleteUpdate : "true";
let channel = aChannel ? aChannel : "test_channel";
let foregroundDownload =
typeof(aForegroundDownload) == "string" ? aForegroundDownload : "true";
let previousAppVersion = aPreviousAppVersion ? "previousAppVersion=\"" +
aPreviousAppVersion + "\" "
: "";
return getUpdateString(aType, aName, aDisplayVersion, aAppVersion,
aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL,
aLicenseURL, aShowPrompt, aShowNeverForVersion,
aShowSurvey, aVersion, aExtensionVersion, aCustom1,
aCustom2) +
" " +
previousAppVersion +
"serviceURL=\"" + serviceURL + "\" " +
"installDate=\"" + installDate + "\" " +
"statusText=\"" + statusText + "\" " +
"isCompleteUpdate=\"" + isCompleteUpdate + "\" " +
"channel=\"" + channel + "\" " +
"foregroundDownload=\"" + foregroundDownload + "\">" +
aPatches +
" </update>";
}
/**
* Constructs a string representing a patch element for a local update xml file.
* See getPatchString for parameter information not provided below.
*
* @param aSelected (optional)
* Whether this patch is selected represented or not. The string 'true'
* denotes selected and the string 'false' denotes not selected.
* If not specified it will default to the string 'true'.
* @param aState (optional)
* The patch's state.
* If not specified it will default to STATE_SUCCEEDED.
* @return The string representing a patch element for a local update xml file.
*/
function getLocalPatchString(aType, aURL, aHashFunction, aHashValue, aSize,
aSelected, aState) {
let selected = typeof(aSelected) == "string" ? aSelected : "true";
let state = aState ? aState : STATE_SUCCEEDED;
return getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) + " " +
"selected=\"" + selected + "\" " +
"state=\"" + state + "\"/>\n";
}
/**
* Constructs a string representing an update element for a remote update xml
* file.
*
* @param aType (optional)
* The update's type which should be major or minor. If not specified it
* will default to 'major'.
* @param aName (optional)
* The update's name.
* If not specified it will default to 'App Update Test'.
* @param aDisplayVersion (optional)
* The update's display version.
* If not specified it will default to 'version 99.0'.
* @param aAppVersion (optional)
* The update's application version.
* If not specified it will default to '99.0'.
* @param aPlatformVersion (optional)
* The update's platform version.
* If not specified it will default to '99.0'.
* @param aBuildID (optional)
* The update's build id.
* If not specified it will default to '20080811053724'.
* @param aDetailsURL (optional)
* The update's details url.
* If not specified it will default to 'http://test_details/' due to due
* to bug 470244.
* @param aBillboardURL (optional)
* The update's billboard url.
* If not specified it will not be present.
* @param aLicenseURL (optional)
* The update's license url.
* If not specified it will not be present.
* @param aShowPrompt (optional)
* Whether to show the prompt for the update when auto update is
* enabled.
* If not specified it will not be present and the update service will
* default to false.
* @param aShowNeverForVersion (optional)
* Whether to show the 'No Thanks' button in the update prompt.
* If not specified it will not be present and the update service will
* default to false.
* @param aShowSurvey (optional)
* Whether to show the 'No Thanks' button in the update prompt.
* If not specified it will not be present and the update service will
* default to false.
* @param aVersion (optional)
* The update's application version from 1.9.2.
* If not specified it will not be present.
* @param aExtensionVersion (optional)
* The update's application version from 1.9.2.
* If not specified it will not be present.
* @param aCustom1 (optional)
* A custom attribute name and attribute value to add to the xml.
* Example: custom1_attribute="custom1 value"
* If not specified it will not be present.
* @param aCustom2 (optional)
* A custom attribute name and attribute value to add to the xml.
* Example: custom2_attribute="custom2 value"
* If not specified it will not be present.
* @return The string representing an update element for an update xml file.
*/
function getUpdateString(aType, aName, aDisplayVersion, aAppVersion,
aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL,
aLicenseURL, aShowPrompt, aShowNeverForVersion,
aShowSurvey, aVersion, aExtensionVersion, aCustom1,
aCustom2) {
let type = aType ? aType : "major";
let name = aName ? aName : "App Update Test";
let displayVersion = "";
if (aDisplayVersion || !aVersion) {
displayVersion = "displayVersion=\"" +
(aDisplayVersion ? aDisplayVersion
: "version 99.0") + "\" ";
}
// version has been deprecated in favor of displayVersion but it still needs
// to be tested for forward compatibility.
let version = aVersion ? "version=\"" + aVersion + "\" " : "";
let appVersion = "";
if (aAppVersion || !aExtensionVersion) {
appVersion = "appVersion=\"" + (aAppVersion ? aAppVersion : "99.0") + "\" ";
}
// extensionVersion has been deprecated in favor of appVersion but it still
// needs to be tested for forward compatibility.
let extensionVersion = aExtensionVersion ? "extensionVersion=\"" +
aExtensionVersion + "\" "
: "";
let platformVersion = "";
if (aPlatformVersion) {
platformVersion = "platformVersion=\"" +
(aPlatformVersion ? aPlatformVersion : "99.0") + "\" ";
}
let buildID = aBuildID ? aBuildID : "20080811053724";
// XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244
// let detailsURL = aDetailsURL ? "detailsURL=\"" + aDetailsURL + "\" " : "";
let detailsURL = "detailsURL=\"" +
(aDetailsURL ? aDetailsURL
: "http://test_details/") + "\" ";
let billboardURL = aBillboardURL ? "billboardURL=\"" +
aBillboardURL + "\" "
: "";
let licenseURL = aLicenseURL ? "licenseURL=\"" + aLicenseURL + "\" " : "";
let showPrompt = aShowPrompt ? "showPrompt=\"" + aShowPrompt + "\" " : "";
let showNeverForVersion = aShowNeverForVersion ? "showNeverForVersion=\"" +
aShowNeverForVersion + "\" "
: "";
let showSurvey = aShowSurvey ? "showSurvey=\"" + aShowSurvey + "\" " : "";
let custom1 = aCustom1 ? aCustom1 + " " : "";
let custom2 = aCustom2 ? aCustom2 + " " : "";
return " <update type=\"" + type + "\" " +
"name=\"" + name + "\" " +
displayVersion +
version +
appVersion +
extensionVersion +
platformVersion +
detailsURL +
billboardURL +
licenseURL +
showPrompt +
showNeverForVersion +
showSurvey +
custom1 +
custom2 +
"buildID=\"" + buildID + "\"";
}
/**
* Constructs a string representing a patch element for an update xml file.
*
* @param aType (optional)
* The patch's type which should be complete or partial.
* If not specified it will default to 'complete'.
* @param aURL (optional)
* The patch's url to the mar file.
* If not specified it will default to the value of:
* URL_HOST + URL_PATH + "/" + FILE_SIMPLE_MAR
* @param aHashFunction (optional)
* The patch's hash function used to verify the mar file.
* If not specified it will default to 'MD5'.
* @param aHashValue (optional)
* The patch's hash value used to verify the mar file.
* If not specified it will default to the value of MD5_HASH_SIMPLE_MAR
* which is the MD5 hash value for the file specified by FILE_SIMPLE_MAR.
* @param aSize (optional)
* The patch's file size for the mar file.
* If not specified it will default to the file size for FILE_SIMPLE_MAR
* specified by SIZE_SIMPLE_MAR.
* @return The string representing a patch element for an update xml file.
*/
function getPatchString(aType, aURL, aHashFunction, aHashValue, aSize) {
let type = aType ? aType : "complete";
let url = aURL ? aURL : URL_HOST + URL_PATH + "/" + FILE_SIMPLE_MAR;
let hashFunction = aHashFunction ? aHashFunction : "MD5";
let hashValue = aHashValue ? aHashValue : MD5_HASH_SIMPLE_MAR;
let size = aSize ? aSize : SIZE_SIMPLE_MAR;
return " <patch type=\"" + type + "\" " +
"URL=\"" + url + "\" " +
"hashFunction=\"" + hashFunction + "\" " +
"hashValue=\"" + hashValue + "\" " +
"size=\"" + size + "\"";
}

Двоичные данные
toolkit/mozapps/update/test/unit/data/empty.mar

Двоичный файл не отображается.

Двоичные данные
toolkit/mozapps/update/test/unit/data/simple.mar Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -52,6 +52,11 @@ var gUpdates;
var gStatusCode;
var gStatusText;
// Set to true to log additional information for debugging. To log additional
// information for an individual test set DEBUG_AUS_TEST to true in the test's
// run_test function.
var DEBUG_AUS_TEST = true;
#include ../shared.js
/**
@ -121,13 +126,15 @@ function pathHandler(metadata, response) {
/**
* Launches the updater binary to apply a mar file using the current working
* directory for the location to apply the mar.
* @param aUpdatesDir
* The directory to copy the update mar, binary, etc.
* @param aUpdater
* The updater binary binary to copy to aUpdatesDir.
* @param aUpdatesDir
* The directory to copy the update mar, binary, etc.
* @param aApplyToDir
* The directory where the update will be applied.
* @returns The exit value returned from the updater binary.
*/
function runUpdate(aUpdatesDir, aUpdater) {
function runUpdate(aUpdater, aUpdatesDir, aApplyToDir) {
// Copy the updater binary to the update directory so the updater.ini is not
// in the same directory as it is. This prevents the PostUpdate executable
// which is defined in the updater.ini from launching and the updater ui from
@ -147,14 +154,14 @@ function runUpdate(aUpdatesDir, aUpdater) {
if (/ /.test(updatesDirPath))
updatesDirPath = '"' + updatesDirPath + '"';
var cwdPath = do_get_file("/", true).path;
if (/ /.test(cwdPath))
cwdPath = '"' + cwdPath + '"';
var applyToPath = aApplyToDir.path;
if (/ /.test(applyToPath))
applyToPath = '"' + applyToPath + '"';
var process = AUS_Cc["@mozilla.org/process/util;1"].
createInstance(AUS_Ci.nsIProcess);
process.init(updateBin);
var args = [updatesDirPath, cwdPath];
var args = [updatesDirPath, applyToPath];
process.run(true, args, args.length);
return process.exitValue;
}
@ -243,28 +250,28 @@ xhr.prototype = {
/* Update check listener */
const updateCheckListener = {
onProgress: function(request, position, totalSize) {
onProgress: function UCL_onProgress(request, position, totalSize) {
},
onCheckComplete: function(request, updates, updateCount) {
onCheckComplete: function UCL_onCheckComplete(request, updates, updateCount) {
gRequestURL = request.channel.originalURI.spec;
gUpdateCount = updateCount;
gUpdates = updates;
dump("onError: url = " + gRequestURL + ", " +
"request.status = " + request.status + ", " +
"update.statusText = " + request.statusText + ", " +
"updateCount = " + updateCount + "\n");
logTestInfo("onError: url = " + gRequestURL + ", " +
"request.status = " + request.status + ", " +
"update.statusText = " + request.statusText + ", " +
"updateCount = " + updateCount);
// Use a timeout to allow the XHR to complete
do_timeout(0, gCheckFunc);
},
onError: function(request, update) {
onError: function UCL_onError(request, update) {
gRequestURL = request.channel.originalURI.spec;
gStatusCode = request.status;
gStatusText = update.statusText;
dump("onError: url = " + gRequestURL + ", " +
"request.status = " + gStatusCode + ", " +
"update.statusText = " + gStatusText + "\n");
logTestInfo("onError: url = " + gRequestURL + ", " +
"request.status = " + gStatusCode + ", " +
"update.statusText = " + gStatusText);
// Use a timeout to allow the XHR to complete
do_timeout(0, gCheckFunc);
},
@ -358,7 +365,7 @@ function createAppInfo(id, name, version, platformVersion) {
// application directory. This will reroute it back to the one in the
// application directory.
var gDirProvider = {
getFile: function(prop, persistent) {
getFile: function DP_getFile(prop, persistent) {
persistent.value = true;
if (prop == XRE_UPDATE_ROOT_DIR)
return getCurrentProcessDir();
@ -377,12 +384,26 @@ const INSTALL_LOCALE = "@AB_CD@";
// These are placed at the end so they don't mess up line numbering
const APP_BIN_NAME = "@MOZ_APP_NAME@";
#ifdef XP_UNIX
const APP_BIN_SUFFIX = "-bin";
#else
const APP_BIN_SUFFIX = "@BIN_SUFFIX@";
#endif
#ifdef XP_WIN
const IS_WIN = true;
#else
const IS_WIN = false;
#endif
#ifdef WINCE
const IS_WINCE = true;
#else
const IS_WINCE = false;
#endif
#ifdef XP_OS2
const IS_OS2 = true;
#else
@ -394,3 +415,15 @@ const IS_MACOSX = true;
#else
const IS_MACOSX = false;
#endif
#ifdef XP_UNIX
const IS_UNIX = true;
#else
const IS_UNIX = false;
#endif
#ifdef ANDROID
const IS_ANDROID = true;
#else
const IS_ANDROID = false;
#endif

Просмотреть файл

@ -39,8 +39,11 @@
/* General Update Service Tests */
function run_test() {
do_test_pending();
do_register_cleanup(end_test);
// Verify write access to the custom app dir
dump("Testing: write access is required to the application directory\n");
logTestInfo("testing write access to the application directory");
removeUpdateDirsAndFiles();
var testFile = getCurrentProcessDir();
testFile.append("update_write_access_test");
@ -52,10 +55,15 @@ function run_test() {
standardInit();
// Check if available updates can be checked for
dump("Testing: nsIApplicationUpdateService:canCheckForUpdates\n");
logTestInfo("testing nsIApplicationUpdateService:canCheckForUpdates");
do_check_true(gAUS.canCheckForUpdates);
// Check if updates can be applied
dump("Testing: nsIApplicationUpdateService:canApplyUpdates\n");
logTestInfo("testing nsIApplicationUpdateService:canApplyUpdates");
do_check_true(gAUS.canApplyUpdates);
do_test_finished();
}
function end_test() {
cleanUp();
}

Просмотреть файл

@ -43,6 +43,7 @@ var gExpectedCount;
function run_test() {
do_test_pending();
do_register_cleanup(end_test);
removeUpdateDirsAndFiles();
setUpdateURLOverride();
setUpdateChannel();
@ -53,7 +54,6 @@ function run_test() {
}
function end_test() {
do_test_finished();
cleanUp();
}
@ -64,7 +64,7 @@ function run_test_helper_pt1(aMsg, aExpectedCount, aNextRunFunc) {
gCheckFunc = check_test_helper_pt1;
gNextRunFunc = aNextRunFunc;
gExpectedCount = aExpectedCount;
dump("Testing: " + aMsg + "\n");
logTestInfo(aMsg, Components.stack.caller);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
@ -92,14 +92,13 @@ function callHandleEvent() {
// update xml not found
function run_test_pt01() {
run_test_helper_pt1("run_test_pt01 - update xml not available",
run_test_helper_pt1("testing update xml not available",
null, run_test_pt02);
}
// one update available and the update's property values
function run_test_pt02() {
dump("Testing: run_test_pt02 - one update available and the update's " +
"property values\n");
logTestInfo("testing one update available and the update's property values");
gUpdates = null;
gUpdateCount = null;
gCheckFunc = check_test_pt02;
@ -199,8 +198,8 @@ function check_test_pt02() {
// one update available and the update's property default values
function run_test_pt03() {
dump("Testing: run_test_pt03 - one update available and the update's " +
"property default values with the format prior to bug 530872\n");
logTestInfo("testing one update available and the update's property values " +
"with the format prior to bug 530872");
gUpdates = null;
gUpdateCount = null;
gCheckFunc = check_test_pt03;
@ -267,14 +266,14 @@ function check_test_pt03() {
// Empty update xml
function run_test_pt04() {
gResponseBody = "\n";
run_test_helper_pt1("run_test_pt04 - empty update xml",
run_test_helper_pt1("testing empty update xml",
null, run_test_pt05);
}
// no updates available
function run_test_pt05() {
gResponseBody = getRemoteUpdatesXMLString("");
run_test_helper_pt1("run_test_pt05 - no updates available",
run_test_helper_pt1("testing no updates available",
0, run_test_pt06);
}
@ -284,7 +283,7 @@ function run_test_pt06() {
patches += getRemotePatchString("partial");
var updates = getRemoteUpdateString(patches);
gResponseBody = getRemoteUpdatesXMLString(updates);
run_test_helper_pt1("run_test_pt06 - one update available",
run_test_helper_pt1("testing one update available",
1, run_test_pt07);
}
@ -296,7 +295,7 @@ function run_test_pt07() {
updates += getRemoteUpdateString(patches);
updates += getRemoteUpdateString(patches);
gResponseBody = getRemoteUpdatesXMLString(updates);
run_test_helper_pt1("run_test_pt07 - three updates available",
run_test_helper_pt1("testing three updates available",
3, run_test_pt08);
}
@ -307,7 +306,7 @@ function run_test_pt08() {
patches += getRemotePatchString("partial", null, null, null, "0");
var updates = getRemoteUpdateString(patches);
gResponseBody = getRemoteUpdatesXMLString(updates);
run_test_helper_pt1("run_test_pt08 - one update with complete and partial " +
run_test_helper_pt1("testing one update with complete and partial " +
"patches with size 0", 0, run_test_pt09);
}
@ -316,7 +315,7 @@ function run_test_pt09() {
var patches = getRemotePatchString("complete", null, null, null, "0");
var updates = getRemoteUpdateString(patches);
gResponseBody = getRemoteUpdatesXMLString(updates);
run_test_helper_pt1("one update with complete patch with size 0",
run_test_helper_pt1("testing one update with complete patch with size 0",
0, run_test_pt10);
}
@ -325,7 +324,7 @@ function run_test_pt10() {
var patches = getRemotePatchString("partial", null, null, null, "0");
var updates = getRemoteUpdateString(patches);
gResponseBody = getRemoteUpdatesXMLString(updates);
run_test_helper_pt1("one update with partial patch with size 0",
run_test_helper_pt1("testing one update with partial patch with size 0",
0, run_test_pt11);
}
@ -336,7 +335,7 @@ function run_test_pt11() {
var updates = getRemoteUpdateString(patches, "minor", null, null, "1.0pre");
updates += getRemoteUpdateString(patches, "minor", null, null, "1.0a");
gResponseBody = getRemoteUpdatesXMLString(updates);
run_test_helper_pt1("two updates older than the current version",
run_test_helper_pt1("testing two updates older than the current version",
2, check_test_pt11);
}
@ -352,7 +351,7 @@ function run_test_pt12() {
patches += getRemotePatchString("partial");
var updates = getRemoteUpdateString(patches, "minor", null, "version 1.0");
gResponseBody = getRemoteUpdatesXMLString(updates);
run_test_helper_pt1("one update equal to the current version",
run_test_helper_pt1("testing one update equal to the current version",
1, check_test_pt12);
}
@ -360,5 +359,5 @@ function check_test_pt12() {
var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount);
do_check_neq(bestUpdate, null);
do_check_eq(bestUpdate.displayVersion, "version 1.0");
end_test();
do_test_finished();
}

Просмотреть файл

@ -44,6 +44,7 @@ var gExpectedStatusResult;
function run_test() {
do_test_pending();
do_register_cleanup(end_test);
removeUpdateDirsAndFiles();
setUpdateURLOverride();
// The mock XMLHttpRequest is MUCH faster
@ -54,8 +55,12 @@ function run_test() {
do_timeout(0, run_test_pt1);
}
function end_test() {
// The nsHttpServer must be stopped before calling do_test_finished
function finish_test() {
stop_httpserver(do_test_finished);
}
function end_test() {
cleanUp();
}
@ -84,7 +89,7 @@ function run_test_helper_pt1(aMsg, aExpectedStatusResult, aNextRunFunc) {
gCheckFunc = check_test_helper_pt1_1;
gNextRunFunc = aNextRunFunc;
gExpectedStatusResult = aExpectedStatusResult;
dump("Testing: " + aMsg + "\n");
logTestInfo(aMsg, Components.stack.caller);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
@ -112,84 +117,70 @@ function setResponseBody(aHashFunction, aHashValue) {
// mar download with a valid MD5 hash
function run_test_pt1() {
setResponseBody("MD5", "6232cd43a1c77e30191c53a329a3f99d");
setResponseBody("MD5", MD5_HASH_SIMPLE_MAR);
run_test_helper_pt1("run_test_pt1 - mar download with a valid MD5 hash",
AUS_Cr.NS_OK, run_test_pt2);
}
// mar download with an invalid MD5 hash
function run_test_pt2() {
setResponseBody("MD5", "6232cd43a1c77e30191c53a329a3f99e");
setResponseBody("MD5", MD5_HASH_SIMPLE_MAR + "0");
run_test_helper_pt1("run_test_pt2 - mar download with an invalid MD5 hash",
AUS_Cr.NS_ERROR_UNEXPECTED, run_test_pt3);
}
// mar download with a valid SHA1 hash
function run_test_pt3() {
setResponseBody("SHA1", "63A739284A1A73ECB515176B1A9D85B987E789CE");
setResponseBody("SHA1", SHA1_HASH_SIMPLE_MAR);
run_test_helper_pt1("run_test_pt3 - mar download with a valid SHA1 hash",
AUS_Cr.NS_OK, run_test_pt4);
}
// mar download with an invalid SHA1 hash
function run_test_pt4() {
setResponseBody("SHA1", "63A739284A1A73ECB515176B1A9D85B987E789CD");
setResponseBody("SHA1", SHA1_HASH_SIMPLE_MAR + "0");
run_test_helper_pt1("run_test_pt4 - mar download with an invalid SHA1 hash",
AUS_Cr.NS_ERROR_UNEXPECTED, run_test_pt5);
}
// mar download with a valid SHA256 hash
function run_test_pt5() {
var hashValue = "a8d9189f3978afd90dc7cd72e887ef22474c178e8314f23df2f779c881" +
"b872e2";
setResponseBody("SHA256", hashValue);
setResponseBody("SHA256", SHA256_HASH_SIMPLE_MAR);
run_test_helper_pt1("run_test_pt5 - mar download with a valid SHA256 hash",
AUS_Cr.NS_OK, run_test_pt6);
}
// mar download with an invalid SHA256 hash
function run_test_pt6() {
var hashValue = "a8d9189f3978afd90dc7cd72e887ef22474c178e8314f23df2f779c881" +
"b872e1";
setResponseBody("SHA256", hashValue);
setResponseBody("SHA256", SHA256_HASH_SIMPLE_MAR + "0");
run_test_helper_pt1("run_test_pt6 - mar download with an invalid SHA256 hash",
AUS_Cr.NS_ERROR_UNEXPECTED, run_test_pt7);
}
// mar download with a valid SHA384 hash
function run_test_pt7() {
var hashValue = "802c64f6caa6c356f7a5f8d9a008c08c54fe915c3ec7cf9e215c3bccc9" +
"e195c78b2669840d7b1d46ff3c1dfa751d72e1";
setResponseBody("SHA384", hashValue);
setResponseBody("SHA384", SHA384_HASH_SIMPLE_MAR);
run_test_helper_pt1("run_test_pt7 - mar download with a valid SHA384 hash",
AUS_Cr.NS_OK, run_test_pt8);
}
// mar download with an invalid SHA384 hash
function run_test_pt8() {
var hashValue = "802c64f6caa6c356f7a5f8d9a008c08c54fe915c3ec7cf9e215c3bccc9" +
"e195c78b2669840d7b1d46ff3c1dfa751d72e2";
setResponseBody("SHA384", hashValue);
setResponseBody("SHA384", SHA384_HASH_SIMPLE_MAR + "0");
run_test_helper_pt1("run_test_pt8 - mar download with an invalid SHA384 hash",
AUS_Cr.NS_ERROR_UNEXPECTED, run_test_pt9);
}
// mar download with a valid SHA512 hash
function run_test_pt9() {
var hashValue = "1d2307e309587ddd04299423b34762639ce6af3ee17cfdaa8fdd4e66b5" +
"a61bfb6555b6e40a82604908d6d68d3e42f318f82e22b6f5e1118b4222" +
"e3417a2fa2d0";
setResponseBody("SHA512", hashValue);
setResponseBody("SHA512", SHA512_HASH_SIMPLE_MAR);
run_test_helper_pt1("run_test_pt9 - mar download with a valid SHA512 hash",
AUS_Cr.NS_OK, run_test_pt10);
}
// mar download with an invalid SHA384 hash
function run_test_pt10() {
var hashValue = "1d2307e309587ddd04299423b34762639ce6af3ee17cfdaa8fdd4e66b5" +
"a61bfb6555b6e40a82604908d6d68d3e42f318f82e22b6f5e1118b4222" +
"e3417a2fa2d1";
setResponseBody("SHA512", hashValue);
setResponseBody("SHA512", SHA512_HASH_SIMPLE_MAR + "0");
run_test_helper_pt1("run_test_pt10 - mar download with an invalid SHA512 hash",
AUS_Cr.NS_ERROR_UNEXPECTED, run_test_pt11);
}
@ -200,7 +191,7 @@ function run_test_pt11() {
var updates = getRemoteUpdateString(patches);
gResponseBody = getRemoteUpdatesXMLString(updates);
run_test_helper_pt1("run_test_pt11 - mar download with the mar not found",
AUS_Cr.NS_ERROR_UNEXPECTED, end_test);
AUS_Cr.NS_ERROR_UNEXPECTED, finish_test);
}
/* Update download listener - nsIRequestObserver */

Просмотреть файл

@ -44,6 +44,7 @@ var gAppInfo;
function run_test() {
do_test_pending();
do_register_cleanup(end_test);
removeUpdateDirsAndFiles();
// The mock XMLHttpRequest is MUCH faster
overrideXHR(callHandleEvent);
@ -55,7 +56,6 @@ function run_test() {
}
function end_test() {
do_test_finished();
cleanUp();
}
@ -75,7 +75,7 @@ function getResult(url) {
function run_test_pt1() {
gCheckFunc = check_test_pt1;
var url = URL_PREFIX + "%PRODUCT%/";
dump("Testing: url constructed with %PRODUCT% - " + url + "\n");
logTestInfo("testing url constructed with %PRODUCT% - " + url);
setUpdateURLOverride(url);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
@ -89,7 +89,7 @@ function check_test_pt1() {
function run_test_pt2() {
gCheckFunc = check_test_pt2;
var url = URL_PREFIX + "%VERSION%/";
dump("Testing: url constructed with %VERSION% - " + url + "\n");
logTestInfo("testing url constructed with %VERSION% - " + url);
setUpdateURLOverride(url);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
@ -103,7 +103,7 @@ function check_test_pt2() {
function run_test_pt3() {
gCheckFunc = check_test_pt3;
var url = URL_PREFIX + "%BUILD_ID%/";
dump("Testing: url constructed with %BUILD_ID% - " + url + "\n");
logTestInfo("testing url constructed with %BUILD_ID% - " + url);
setUpdateURLOverride(url);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
@ -118,7 +118,7 @@ function check_test_pt3() {
function run_test_pt4() {
gCheckFunc = check_test_pt4;
var url = URL_PREFIX + "%BUILD_TARGET%/";
dump("Testing: url constructed with %BUILD_TARGET% - " + url + "\n");
logTestInfo("testing url constructed with %BUILD_TARGET% - " + url);
setUpdateURLOverride(url);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
@ -152,7 +152,7 @@ function check_test_pt4() {
function run_test_pt5() {
gCheckFunc = check_test_pt5;
var url = URL_PREFIX + "%LOCALE%/";
dump("Testing: url constructed with %LOCALE% - " + url + "\n");
logTestInfo("testing url constructed with %LOCALE% - " + url);
setUpdateURLOverride(url);
try {
gUpdateChecker.checkForUpdates(updateCheckListener, true);
@ -173,7 +173,7 @@ function check_test_pt5() {
function run_test_pt6() {
gCheckFunc = check_test_pt6;
var url = URL_PREFIX + "%CHANNEL%/";
dump("Testing: url constructed with %CHANNEL% - " + url + "\n");
logTestInfo("testing url constructed with %CHANNEL% - " + url);
setUpdateURLOverride(url);
setUpdateChannel();
gUpdateChecker.checkForUpdates(updateCheckListener, true);
@ -188,7 +188,7 @@ function check_test_pt6() {
function run_test_pt7() {
gCheckFunc = check_test_pt7;
var url = URL_PREFIX + "%CHANNEL%/";
dump("Testing: url constructed with %CHANNEL% - " + url + "\n");
logTestInfo("testing url constructed with %CHANNEL% - " + url);
setUpdateURLOverride(url);
gDefaultPrefBranch.setCharPref(PREF_APP_PARTNER_BRANCH + "test_partner1", "test_partner1");
gDefaultPrefBranch.setCharPref(PREF_APP_PARTNER_BRANCH + "test_partner2", "test_partner2");
@ -204,7 +204,7 @@ function check_test_pt7() {
function run_test_pt8() {
gCheckFunc = check_test_pt8;
var url = URL_PREFIX + "%PLATFORM_VERSION%/";
dump("Testing: url constructed with %PLATFORM_VERSION% - " + url + "\n");
logTestInfo("testing url constructed with %PLATFORM_VERSION% - " + url);
setUpdateURLOverride(url);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
@ -218,7 +218,7 @@ function check_test_pt8() {
function run_test_pt9() {
gCheckFunc = check_test_pt9;
var url = URL_PREFIX + "%OS_VERSION%/";
dump("Testing: url constructed with %OS_VERSION% - " + url + "\n");
logTestInfo("testing url constructed with %OS_VERSION% - " + url);
setUpdateURLOverride(url);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
@ -248,7 +248,7 @@ function check_test_pt9() {
function run_test_pt10() {
gCheckFunc = check_test_pt10;
var url = URL_PREFIX + "%DISTRIBUTION%/";
dump("Testing: url constructed with %DISTRIBUTION% - " + url + "\n");
logTestInfo("testing url constructed with %DISTRIBUTION% - " + url);
setUpdateURLOverride(url);
gDefaultPrefBranch.setCharPref(PREF_DISTRIBUTION_ID, "test_distro");
gUpdateChecker.checkForUpdates(updateCheckListener, true);
@ -263,7 +263,7 @@ function check_test_pt10() {
function run_test_pt11() {
gCheckFunc = check_test_pt11;
var url = URL_PREFIX + "%DISTRIBUTION_VERSION%/";
dump("Testing: url constructed with %DISTRIBUTION_VERSION% - " + url + "\n");
logTestInfo("testing url constructed with %DISTRIBUTION_VERSION% - " + url);
setUpdateURLOverride(url);
gDefaultPrefBranch.setCharPref(PREF_DISTRIBUTION_VERSION, "test_distro_version");
gUpdateChecker.checkForUpdates(updateCheckListener, true);
@ -278,7 +278,7 @@ function check_test_pt11() {
function run_test_pt12() {
gCheckFunc = check_test_pt12;
var url = URL_PREFIX;
dump("Testing: url constructed that doesn't have a parameter - " + url + "\n");
logTestInfo("testing url constructed that doesn't have a parameter - " + url);
setUpdateURLOverride(url);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
@ -292,12 +292,12 @@ function check_test_pt12() {
function run_test_pt13() {
gCheckFunc = check_test_pt13;
var url = URL_PREFIX + "?extra=param";
dump("Testing: url constructed that has a parameter - " + url + "\n");
logTestInfo("testing url constructed that has a parameter - " + url);
setUpdateURLOverride(url);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
function check_test_pt13() {
do_check_eq(getResult(gRequestURL), "?extra=param&force=1");
end_test();
do_test_finished();
}

Просмотреть файл

@ -50,6 +50,7 @@ var gExpectedStatusText;
function run_test() {
do_test_pending();
do_register_cleanup(end_test);
removeUpdateDirsAndFiles();
setUpdateURLOverride();
standardInit();
@ -59,7 +60,6 @@ function run_test() {
}
function end_test() {
do_test_finished();
cleanUp();
}
@ -78,7 +78,7 @@ function run_test_helper(aNextRunFunc, aExpectedStatusCode, aMsg) {
gCheckFunc = check_test_helper;
gNextRunFunc = aNextRunFunc;
gExpectedStatusCode = aExpectedStatusCode;
dump("Testing: " + aMsg + "\n");
logTestInfo(aMsg, Components.stack.caller);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
@ -99,7 +99,7 @@ function run_test_pt1() {
gStatusText = null;
gCheckFunc = check_test_pt1;
gExpectedStatusCode = 399;
dump("Testing: run_test_pt1 - default onerror error message\n");
logTestInfo("testing default onerror error message");
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
@ -113,95 +113,95 @@ function check_test_pt1() {
// file malformed - 200
function run_test_pt2() {
run_test_helper(run_test_pt3, 200,
"run_test_pt2 - file malformed");
"testing file malformed");
}
// access denied - 403
function run_test_pt3() {
run_test_helper(run_test_pt4, 403,
"run_test_pt3 - access denied");
"testing access denied");
}
// file not found - 404
function run_test_pt4() {
run_test_helper(run_test_pt5, 404,
"run_test_pt4 - file not found");
"testing file not found");
}
// internal server error - 500
function run_test_pt5() {
run_test_helper(run_test_pt6, 500,
"run_test_pt5 - internal server error");
"testing internal server error");
}
// failed (unknown reason) - NS_BINDING_FAILED (2152398849)
function run_test_pt6() {
run_test_helper(run_test_pt7, AUS_Cr.NS_BINDING_FAILED,
"run_test_pt6 - failed (unknown reason)");
"testing failed (unknown reason)");
}
// connection timed out - NS_ERROR_NET_TIMEOUT (2152398862)
function run_test_pt7() {
run_test_helper(run_test_pt8, AUS_Cr.NS_ERROR_NET_TIMEOUT,
"run_test_pt7 - connection timed out");
"testing connection timed out");
}
// network offline - NS_ERROR_OFFLINE (2152398864)
function run_test_pt8() {
run_test_helper(run_test_pt9, AUS_Cr.NS_ERROR_OFFLINE,
"run_test_pt8 - network offline");
"testing network offline");
}
// port not allowed - NS_ERROR_PORT_ACCESS_NOT_ALLOWED (2152398867)
function run_test_pt9() {
run_test_helper(run_test_pt10, AUS_Cr.NS_ERROR_PORT_ACCESS_NOT_ALLOWED,
"run_test_pt9 - port not allowed");
"testing port not allowed");
}
// no data was received - NS_ERROR_NET_RESET (2152398868)
function run_test_pt10() {
run_test_helper(run_test_pt11, AUS_Cr.NS_ERROR_NET_RESET,
"run_test_pt10 - no data was received");
"testing no data was received");
}
// update server not found - NS_ERROR_UNKNOWN_HOST (2152398878)
function run_test_pt11() {
run_test_helper(run_test_pt12, AUS_Cr.NS_ERROR_UNKNOWN_HOST,
"run_test_pt11 - update server not found");
"testing update server not found");
}
// proxy server not found - NS_ERROR_UNKNOWN_PROXY_HOST (2152398890)
function run_test_pt12() {
run_test_helper(run_test_pt13, AUS_Cr.NS_ERROR_UNKNOWN_PROXY_HOST,
"run_test_pt12 - proxy server not found");
"testing proxy server not found");
}
// data transfer interrupted - NS_ERROR_NET_INTERRUPT (2152398919)
function run_test_pt13() {
run_test_helper(run_test_pt14, AUS_Cr.NS_ERROR_NET_INTERRUPT,
"run_test_pt13 - data transfer interrupted");
"testing data transfer interrupted");
}
// proxy server connection refused - NS_ERROR_PROXY_CONNECTION_REFUSED (2152398920)
function run_test_pt14() {
run_test_helper(run_test_pt15, AUS_Cr.NS_ERROR_PROXY_CONNECTION_REFUSED,
"run_test_pt14 - proxy server connection refused");
"testing proxy server connection refused");
}
// server certificate expired - 2153390069
function run_test_pt15() {
run_test_helper(run_test_pt16, 2153390069,
"run_test_pt15 - server certificate expired");
"testing server certificate expired");
}
// network is offline - NS_ERROR_DOCUMENT_NOT_CACHED (2152398918)
function run_test_pt16() {
run_test_helper(run_test_pt17, AUS_Cr.NS_ERROR_DOCUMENT_NOT_CACHED,
"run_test_pt16 - network is offline");
"testing network is offline");
}
// connection refused - NS_ERROR_CONNECTION_REFUSED (2152398861)
function run_test_pt17() {
run_test_helper(end_test, AUS_Cr.NS_ERROR_CONNECTION_REFUSED,
"run_test_pt17 - connection refused");
run_test_helper(do_test_finished, AUS_Cr.NS_ERROR_CONNECTION_REFUSED,
"testing connection refused");
}

Просмотреть файл

@ -39,9 +39,12 @@
/* General Update Manager Tests */
function run_test() {
dump("Testing: addition of a successful update to " + FILE_UPDATES_DB +
" and verification of update properties with the format prior to " +
"bug 530872\n");
do_test_pending();
do_register_cleanup(end_test);
logTestInfo("testing addition of a successful update to " + FILE_UPDATES_DB +
" and verification of update properties with the format prior " +
"to bug 530872");
removeUpdateDirsAndFiles();
setUpdateChannel("test_channel");
@ -207,10 +210,10 @@ function run_test() {
patch = update.selectedPatch;
do_check_eq(patch.type, "complete");
do_check_eq(patch.URL, "http://localhost:4444/data/empty.mar");
do_check_eq(patch.URL, URL_HOST + URL_PATH + "/" + FILE_SIMPLE_MAR);
do_check_eq(patch.hashFunction, "MD5");
do_check_eq(patch.hashValue, "6232cd43a1c77e30191c53a329a3f99d");
do_check_eq(patch.size, "775");
do_check_eq(patch.hashValue, MD5_HASH_SIMPLE_MAR);
do_check_eq(patch.size, SIZE_SIMPLE_MAR);
do_check_true(patch.selected);
do_check_eq(patch.state, STATE_SUCCEEDED);
@ -237,12 +240,16 @@ function run_test() {
patch = update.selectedPatch;
do_check_eq(patch.type, "complete");
do_check_eq(patch.URL, "http://localhost:4444/data/empty.mar");
do_check_eq(patch.URL, URL_HOST + URL_PATH + "/" + FILE_SIMPLE_MAR);
do_check_eq(patch.hashFunction, "MD5");
do_check_eq(patch.hashValue, "6232cd43a1c77e30191c53a329a3f99d");
do_check_eq(patch.size, "775");
do_check_eq(patch.hashValue, MD5_HASH_SIMPLE_MAR);
do_check_eq(patch.size, SIZE_SIMPLE_MAR);
do_check_true(patch.selected);
do_check_eq(patch.state, STATE_FAILED);
do_test_finished();
}
function end_test() {
cleanUp();
}

Просмотреть файл

@ -39,8 +39,11 @@
/* General Update Manager Tests */
function run_test() {
dump("Testing: removal of an update download in progress for an older " +
"version of the application on startup - bug 485624\n");
do_test_pending();
do_register_cleanup(end_test);
logTestInfo("testing removal of an update download in progress for an " +
"older version of the application on startup (bug 485624)");
removeUpdateDirsAndFiles();
setUpdateChannel();
@ -58,5 +61,10 @@ function run_test() {
do_check_eq(gUpdateManager.activeUpdate, null);
do_check_eq(gUpdateManager.updateCount, 0);
do_test_finished();
}
function end_test() {
cleanUp();
}

Просмотреть файл

@ -39,8 +39,11 @@
/* General Update Manager Tests */
function run_test() {
dump("Testing: resuming an update download in progress for the same " +
"version of the application on startup - bug 485624\n");
do_test_pending();
do_register_cleanup(end_test);
logTestInfo("testing resuming an update download in progress for the same " +
"version of the application on startup (bug 485624)");
removeUpdateDirsAndFiles();
setUpdateChannel();
@ -48,9 +51,7 @@ function run_test() {
patches = getLocalPatchString(null, null, null, null, null, null,
STATE_DOWNLOADING);
updates = getLocalUpdateString(patches, null, null, "1.0", "1.0", null,
null, null, null,
URL_HOST + URL_PATH + "/empty.mar");
updates = getLocalUpdateString(patches, null, null, "1.0", "1.0");
writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true);
writeStatusFile(STATE_DOWNLOADING);
@ -60,5 +61,10 @@ function run_test() {
do_check_eq(gUpdateManager.updateCount, 1);
do_check_eq(gUpdateManager.activeUpdate.state, STATE_DOWNLOADING);
do_test_finished();
}
function end_test() {
cleanUp();
}

Просмотреть файл

@ -39,8 +39,11 @@
/* General Update Manager Tests */
function run_test() {
do_test_pending();
do_register_cleanup(end_test);
dump("Testing: removing an active update for a channel that is not valid " +
"due to switching channels - bug 486275\n");
"due to switching channels (bug 486275)");
removeUpdateDirsAndFiles();
setUpdateChannel("original_channel");
@ -48,9 +51,7 @@ function run_test() {
patches = getLocalPatchString(null, null, null, null, null, null,
STATE_DOWNLOADING);
updates = getLocalUpdateString(patches, null, null, "version 1.0", "1.0", null,
null, null, null,
URL_HOST + URL_PATH + "/empty.mar");
updates = getLocalUpdateString(patches, null, null, "version 1.0", "1.0");
writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true);
writeStatusFile(STATE_DOWNLOADING);
@ -72,7 +73,12 @@ function run_test() {
// channel removed.
file = getCurrentProcessDir();
file.append(FILE_UPDATE_ACTIVE);
dump("Testing: verifying contents of " + FILE_UPDATE_ACTIVE + "\n");
logTestInfo("verifying contents of " + FILE_UPDATE_ACTIVE);
do_check_eq(readFile(file), getLocalUpdatesXMLString(""));
do_test_finished();
}
function end_test() {
cleanUp();
}

Просмотреть файл

@ -39,9 +39,12 @@
/* General Update Manager Tests */
function run_test() {
dump("Testing: removal of an update download in progress for the same " +
"version of the application with the same application build id on " +
"startup - bug 536547\n");
do_test_pending();
do_register_cleanup(end_test);
logTestInfo("testing removal of an update download in progress for the " +
"same version of the application with the same application " +
"build id on startup (bug 536547)");
removeUpdateDirsAndFiles();
setUpdateChannel();
@ -60,5 +63,10 @@ function run_test() {
do_check_eq(gUpdateManager.activeUpdate, null);
do_check_eq(gUpdateManager.updateCount, 0);
do_test_finished();
}
function end_test() {
cleanUp();
}

Просмотреть файл

@ -39,6 +39,9 @@
/* General Update Directory Cleanup Tests */
function run_test() {
do_test_pending();
do_register_cleanup(end_test);
removeUpdateDirsAndFiles();
setUpdateChannel();
@ -57,25 +60,29 @@ function run_test() {
standardInit();
dump("Testing: " + FILE_UPDATE_LOG + " doesn't exist\n");
logTestInfo("testing " + log.path + " shouldn't exist");
do_check_false(log.exists());
dump("Testing: " + FILE_LAST_LOG + " exists\n");
log = dir.clone();
log.append(FILE_LAST_LOG);
logTestInfo("testing " + log.path + " should exist");
do_check_true(log.exists());
dump("Testing: " + FILE_LAST_LOG + " contents\n");
logTestInfo("testing " + log.path + " contents");
do_check_eq(readFile(log), "Last Update Log");
dump("Testing: " + FILE_BACKUP_LOG + " doesn't exist\n");
log = dir.clone();
log.append(FILE_BACKUP_LOG);
logTestInfo("testing " + log.path + " shouldn't exist");
do_check_false(log.exists());
dump("Testing: " + dir.path + " exists (bug 512994)\n");
dir.append("0");
dump("testing " + dir.path + " should exists (bug 512994)");
do_check_true(dir.exists());
do_test_finished();
}
function end_test() {
cleanUp();
}

Просмотреть файл

@ -39,6 +39,9 @@
/* General Update Directory Cleanup Tests */
function run_test() {
do_test_pending();
do_register_cleanup(end_test);
removeUpdateDirsAndFiles();
setUpdateChannel();
@ -65,28 +68,32 @@ function run_test() {
standardInit();
dump("Testing: " + FILE_UPDATE_LOG + " doesn't exist\n");
logTestInfo("testing " + log.path + " shouldn't exist");
do_check_false(log.exists());
dump("Testing: " + FILE_LAST_LOG + " exists\n");
log = dir.clone();
log.append(FILE_LAST_LOG);
logTestInfo("testing " + log.path + " should exist");
do_check_true(log.exists());
dump("Testing: " + FILE_LAST_LOG + " contents\n");
logTestInfo("testing " + log.path + " contents");
do_check_eq(readFile(log), "Last Update Log");
dump("Testing: " + FILE_BACKUP_LOG + " exists\n");
log = dir.clone();
log.append(FILE_BACKUP_LOG);
logTestInfo("testing " + log.path + " should exist");
do_check_true(log.exists());
dump("Testing: " + FILE_BACKUP_LOG + " contents (bug 470979)\n");
logTestInfo("testing " + log.path + " contents (bug 470979)");
do_check_eq(readFile(log), "Backup Update Log");
dump("Testing: " + dir.path + " exists (bug 512994)\n");
dir.append("0");
logTestInfo("testing " + dir.path + " should exist (bug 512994)");
do_check_true(dir.exists());
do_test_finished();
}
function end_test() {
cleanUp();
}

Просмотреть файл

@ -5,6 +5,9 @@
/* General Update Directory Cleanup Tests - Bug 539717 */
function run_test() {
do_test_pending();
do_register_cleanup(end_test);
removeUpdateDirsAndFiles();
setUpdateChannel();
@ -18,17 +21,21 @@ function run_test() {
standardInit();
var dir = getUpdatesDir();
dump("Testing: " + dir.path + " exists\n");
dir.append("0");
logTestInfo("testing " + dir.path + " should exist");
do_check_true(dir.exists());
var statusFile = dir.clone();
statusFile.append(FILE_UPDATE_STATUS);
dump("Testing: " + statusFile.path + " does not exist\n");
logTestInfo("testing " + statusFile.path + " should not exist");
do_check_false(statusFile.exists());
do_check_eq(gUpdateManager.activeUpdate, null);
do_check_eq(gUpdateManager.updateCount, 0);
do_test_finished();
}
function end_test() {
cleanUp();
}

Просмотреть файл

@ -11,8 +11,11 @@
var gCheckFunc;
function run_test() {
dump("Testing: nsIUpdatePrompt notifications should not be seen when the " +
PREF_APP_UPDATE_SILENT + " preference is true\n");
do_test_pending();
do_register_cleanup(end_test);
logTestInfo("testing nsIUpdatePrompt notifications should not be seen " +
"when the " + PREF_APP_UPDATE_SILENT + " preference is true");
removeUpdateDirsAndFiles();
setUpdateChannel();
@ -27,7 +30,7 @@ function run_test() {
standardInit();
dump("showUpdateInstalled should not call openWindow\n");
logTestInfo("testing showUpdateInstalled should not call openWindow");
Services.prefs.setBoolPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI, true);
gCheckFunc = check_showUpdateInstalled;
@ -36,7 +39,7 @@ function run_test() {
// didn't throw and otherwise it would report no tests run.
do_check_true(true);
dump("showUpdateAvailable should not call openWindow\n");
logTestInfo("testing showUpdateAvailable should not call openWindow");
writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false);
let patches = getLocalPatchString(null, null, null, null, null, null,
STATE_FAILED);
@ -52,7 +55,7 @@ function run_test() {
// didn't throw and otherwise it would report no tests run.
do_check_true(true);
dump("showUpdateError should not call getNewPrompter\n");
logTestInfo("testing showUpdateError should not call getNewPrompter");
gCheckFunc = check_showUpdateError;
update.errorCode = WRITE_ERROR;
gUP.showUpdateError(update);
@ -63,6 +66,11 @@ function run_test() {
let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
WindowWatcherFactory);
do_test_finished();
}
function end_test() {
cleanUp();
}

Просмотреть файл

@ -10,8 +10,11 @@
var gCheckFunc;
function run_test() {
dump("Testing: nsIUpdatePrompt notifications should not be seen when there " +
"is already an application update window open\n");
do_test_pending();
do_register_cleanup(end_test);
logTestInfo("testing nsIUpdatePrompt notifications should not be seen when " +
"there is already an application update window open");
removeUpdateDirsAndFiles();
setUpdateChannel();
@ -30,7 +33,7 @@ function run_test() {
standardInit();
dump("showUpdateInstalled should not call openWindow\n");
logTestInfo("testing showUpdateInstalled should not call openWindow");
Services.prefs.setBoolPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI, true);
gCheckFunc = check_showUpdateInstalled;
@ -39,7 +42,7 @@ function run_test() {
// didn't throw and otherwise it would report no tests run.
do_check_true(true);
dump("showUpdateAvailable should not call openWindow\n");
logTestInfo("testing showUpdateAvailable should not call openWindow");
writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false);
let patches = getLocalPatchString(null, null, null, null, null, null,
STATE_FAILED);
@ -60,6 +63,11 @@ function run_test() {
WindowWatcherFactory);
registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"),
WindowMediatorFactory);
do_test_finished();
}
function end_test() {
cleanUp();
}

Просмотреть файл

@ -38,10 +38,13 @@
/* General Complete MAR File Patch Apply Test */
const APPLY_TO_DIR = "applyToDir_0110";
const UPDATES_DIR = "0110_mar";
var gTestFiles = [
{
fileName : "1_exe1.exe",
destinationDir : "mar_test/1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/",
originalContents : null,
compareContents : null,
originalFile : "data/aus-0111_general_ref_image.png",
@ -50,7 +53,7 @@ var gTestFiles = [
comparePerms : 0755
}, {
fileName : "1_1_image1.png",
destinationDir : "mar_test/1/1_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/1_1/",
originalContents : null,
compareContents : null,
originalFile : null,
@ -59,7 +62,7 @@ var gTestFiles = [
comparePerms : 0644
}, {
fileName : "1_1_text1",
destinationDir : "mar_test/1/1_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/1_1/",
originalContents : "ToBeReplacedWithToBeModified\n",
compareContents : "ToBeModified\n",
originalFile : null,
@ -68,7 +71,7 @@ var gTestFiles = [
comparePerms : 0644
}, {
fileName : "1_1_text2",
destinationDir : "mar_test/1/1_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/1_1/",
originalContents : "ToBeReplacedWithToBeDeleted\n",
compareContents : "ToBeDeleted\n",
originalFile : null,
@ -77,7 +80,7 @@ var gTestFiles = [
comparePerms : 0644
}, {
fileName : "2_1_text1",
destinationDir : "mar_test/2/2_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/2/2_1/",
originalContents : "ToBeReplacedWithToBeDeleted\n",
compareContents : "ToBeDeleted\n",
originalFile : null,
@ -86,22 +89,39 @@ var gTestFiles = [
comparePerms : 0644
}];
// All we care about is that the last modified time has changed so that Mac OS
// X Launch Services invalidates its cache so the test allows up to one minute
// difference in the last modified time.
const MAX_TIME_DIFFERENCE = 60000;
function run_test() {
var testFile;
// The directory the updates will be applied to is the current working
// directory and not dist/bin.
var testDir = do_get_file("mar_test", true);
// The mar files were created with all files in a subdirectory named
// mar_test... clear it out of the way if it exists and then create it.
if (IS_ANDROID) {
logTestInfo("this test is not applicable to Android... returning early");
return;
}
do_test_pending();
do_register_cleanup(end_test);
var testDir, testFile;
// The directory the updates will be applied to is the directory name stored
// in the APPLY_TO_DIR constant located in the current working directory and
// not dist/bin.
var applyToDir = do_get_file(APPLY_TO_DIR, true);
// Remove the directory where the update will be applied if it exists.
try {
removeDirRecursive(testDir);
removeDirRecursive(applyToDir);
}
catch (e) {
dump("Unable to remove directory\npath: " + testDir.path +
"\nException: " + e + "\n");
dump("Unable to remove directory\n" +
"path: " + applyToDir.path + "\n" +
"Exception: " + e + "\n");
}
dump("Testing: successful removal of the directory used to apply the mar file\n");
do_check_false(testDir.exists());
logTestInfo("testing successful removal of the directory used to apply the " +
"mar file");
do_check_false(applyToDir.exists());
// Create the files to test the complete mar's ability to replace files.
for (var i = 0; i < gTestFiles.length; i++) {
@ -133,6 +153,15 @@ function run_test() {
}
}
// For Mac OS X set the last modified time for the root directory to a date in
// the past to test that the last modified time is updated on a successful
// update (bug 600098).
if (IS_MACOSX) {
var now = Date.now();
var yesterday = now - (1000 * 60 * 60 * 24);
applyToDir.lastModifiedTime = yesterday;
}
var binDir = getGREDir();
// The updater binary file
@ -151,36 +180,45 @@ function run_test() {
}
// Use a directory outside of dist/bin to lessen the garbage in dist/bin
var updatesDir = do_get_file("0110_mar", true);
var updatesDir = do_get_file(UPDATES_DIR, true);
try {
// Mac OS X intermittently fails when removing the dir where the updater
// binary was launched.
removeDirRecursive(updatesDir);
}
catch (e) {
dump("Unable to remove directory\npath: " + updatesDir.path +
"\nException: " + e + "\n");
dump("Unable to remove directory\n" +
"path: " + updatesDir.path + "\n" +
"Exception: " + e + "\n");
}
var mar = do_get_file("data/aus-0110_general.mar");
mar.copyTo(updatesDir, FILE_UPDATE_ARCHIVE);
// apply the complete mar and check the innards of the files
var exitValue = runUpdate(updatesDir, updater);
dump("Testing: updater binary process exitValue for success when applying " +
"a complete mar\n");
var exitValue = runUpdate(updater, updatesDir, applyToDir);
logTestInfo("testing updater binary process exitValue for success when " +
"applying a complete mar");
do_check_eq(exitValue, 0);
dump("Testing: update.status should be set to STATE_SUCCEEDED\n");
testFile = updatesDir.clone();
testFile.append(FILE_UPDATE_STATUS);
do_check_eq(readFile(testFile).split("\n")[0], STATE_SUCCEEDED);
logTestInfo("testing update.status should be " + STATE_SUCCEEDED);
do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED);
dump("Testing: contents of files added by a complete mar\n");
// For Mac OS X check that the last modified time for a directory has been
// updated after a successful update (bug 600098).
if (IS_MACOSX) {
logTestInfo("testing last modified time on the apply to directory has " +
"changed after a successful update (bug 600098)");
now = Date.now();
var timeDiff = Math.abs(applyToDir.lastModifiedTime - now);
do_check_true(timeDiff < MAX_TIME_DIFFERENCE);
}
logTestInfo("testing contents of files added by a complete mar");
for (i = 0; i < gTestFiles.length; i++) {
f = gTestFiles[i];
testFile = do_get_file(f.destinationDir + f.fileName, true);
dump("Testing: " + testFile.path + "\n");
logTestInfo("testing file: " + testFile.path);
if (f.compareFile || f.compareContents) {
do_check_true(testFile.exists());
@ -188,10 +226,13 @@ function run_test() {
// implementaions of chmod doesn't really set permissions.
if (!IS_WIN && !IS_OS2 && f.comparePerms) {
// Check if the permssions as set in the complete mar file are correct.
if (f.originalPerms)
dump("original permissions: " + f.originalPerms.toString(8) + "\n");
dump("compare permissions : " + f.comparePerms.toString(8) + "\n");
dump("updated permissions : " + testFile.permissions.toString(8) + "\n");
let logPerms = "testing file permissions - ";
if (f.originalPerms) {
logPerms += "original permissions: " + f.originalPerms.toString(8) + ", ";
}
logPerms += "compare permissions : " + f.comparePerms.toString(8) + ", ";
logPerms += "updated permissions : " + testFile.permissions.toString(8);
logTestInfo(logPerms);
do_check_eq(testFile.permissions & 0xfff, f.comparePerms & 0xfff);
}
@ -214,12 +255,37 @@ function run_test() {
}
}
dump("Testing: patch files should not be left behind\n");
logTestInfo("testing patch files should not be left behind");
var entries = updatesDir.QueryInterface(AUS_Ci.nsIFile).directoryEntries;
while (entries.hasMoreElements()) {
var entry = entries.getNext().QueryInterface(AUS_Ci.nsIFile);
do_check_neq(getFileExtension(entry), "patch");
}
do_test_finished();
}
function end_test() {
// Try to remove the updates and the apply to directories.
var applyToDir = do_get_file(APPLY_TO_DIR, true);
try {
removeDirRecursive(applyToDir);
}
catch (e) {
dump("Unable to remove directory\n" +
"path: " + applyToDir.path + "\n" +
"Exception: " + e + "\n");
}
var updatesDir = do_get_file(UPDATES_DIR, true);
try {
removeDirRecursive(updatesDir);
}
catch (e) {
dump("Unable to remove directory\n" +
"path: " + updatesDir.path + "\n" +
"Exception: " + e + "\n");
}
cleanUp();
}

Просмотреть файл

@ -37,11 +37,13 @@
*/
/* General Partial MAR File Patch Apply Test */
const APPLY_TO_DIR = "applyToDir_0111";
const UPDATES_DIR = "0111_mar";
var gTestFiles = [
{
fileName : "1_exe1.exe",
destinationDir : "mar_test/1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/",
originalContents : null,
compareContents : null,
originalFile : "data/aus-0110_general_ref_image.png",
@ -50,7 +52,7 @@ var gTestFiles = [
comparePerms : null
}, {
fileName : "1_1_image1.png",
destinationDir : "mar_test/1/1_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/1_1/",
originalContents : null,
compareContents : null,
originalFile : "data/aus-0110_general_ref_image.png",
@ -59,7 +61,7 @@ var gTestFiles = [
comparePerms : null
}, {
fileName : "1_1_text1",
destinationDir : "mar_test/1/1_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/1_1/",
originalContents : "ToBeModified\n",
compareContents : "Modified\n",
originalFile : null,
@ -68,7 +70,7 @@ var gTestFiles = [
comparePerms : null
}, {
fileName : "1_1_text2",
destinationDir : "mar_test/1/1_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/1_1/",
originalContents : "ToBeDeleted\n",
compareContents : null,
originalFile : null,
@ -77,7 +79,7 @@ var gTestFiles = [
comparePerms : null
}, {
fileName : "1_1_text3",
destinationDir : "mar_test/1/1_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/1_1/",
originalContents : null,
compareContents : "Added\n",
originalFile : null,
@ -86,7 +88,7 @@ var gTestFiles = [
comparePerms : 0644
}, {
fileName : "2_1_text1",
destinationDir : "mar_test/2/2_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/2/2_1/",
originalContents : "ToBeDeleted\n",
compareContents : null,
originalFile : null,
@ -95,7 +97,7 @@ var gTestFiles = [
comparePerms : null
}, {
fileName : "3_1_text1",
destinationDir : "mar_test/3/3_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/3/3_1/",
originalContents : null,
compareContents : "Added\n",
originalFile : null,
@ -104,22 +106,39 @@ var gTestFiles = [
comparePerms : 0644
}];
// All we care about is that the last modified time has changed so that Mac OS
// X Launch Services invalidates its cache so the test allows up to one minute
// difference in the last modified time.
const MAX_TIME_DIFFERENCE = 60000;
function run_test() {
var testFile;
// The directory the updates will be applied to is the current working
// directory and not dist/bin.
var testDir = do_get_file("mar_test", true);
// The mar files were created with all files in a subdirectory named
// mar_test... clear it out of the way if it exists and then create it.
if (IS_ANDROID) {
logTestInfo("this test is not applicable to Android... returning early");
return;
}
do_test_pending();
do_register_cleanup(end_test);
var testDir, testFile;
// The directory the updates will be applied to is the directory name stored
// in the APPLY_TO_DIR constant located in the current working directory and
// not dist/bin.
var applyToDir = do_get_file(APPLY_TO_DIR, true);
// Remove the directory where the update will be applied if it exists.
try {
removeDirRecursive(testDir);
removeDirRecursive(applyToDir);
}
catch (e) {
dump("Unable to remove directory\npath: " + testDir.path +
"\nException: " + e + "\n");
dump("Unable to remove directory\n" +
"path: " + applyToDir.path + "\n" +
"Exception: " + e + "\n");
}
dump("Testing: successful removal of the directory used to apply the mar file\n");
do_check_false(testDir.exists());
logTestInfo("testing successful removal of the directory used to apply the " +
"mar file");
do_check_false(applyToDir.exists());
// Create the files to test the partial mar's ability to modify and delete
// files.
@ -152,6 +171,15 @@ function run_test() {
}
}
// For Mac OS X set the last modified time for the root directory to a date in
// the past to test that the last modified time is updated on a successful
// update (bug 600098).
if (IS_MACOSX) {
var now = Date.now();
var yesterday = now - (1000 * 60 * 60 * 24);
applyToDir.lastModifiedTime = yesterday;
}
var binDir = getGREDir();
// The updater binary file
@ -170,15 +198,16 @@ function run_test() {
}
// Use a directory outside of dist/bin to lessen the garbage in dist/bin
var updatesDir = do_get_file("0111_mar", true);
var updatesDir = do_get_file(UPDATES_DIR, true);
try {
// Mac OS X intermittently fails when removing the dir where the updater
// binary was launched.
removeDirRecursive(updatesDir);
}
catch (e) {
dump("Unable to remove directory\npath: " + updatesDir.path +
"\nException: " + e + "\n");
dump("Unable to remove directory\n" +
"path: " + updatesDir.path + "\n" +
"Exception: " + e + "\n");
}
updatesDir.create(AUS_Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY);
@ -186,22 +215,30 @@ function run_test() {
mar.copyTo(updatesDir, FILE_UPDATE_ARCHIVE);
// apply the partial mar and check the innards of the files
var exitValue = runUpdate(updatesDir, updater);
dump("Testing: updater binary process exitValue for success when applying " +
"a partial mar\n");
var exitValue = runUpdate(updater, updatesDir, applyToDir);
logTestInfo("testing updater binary process exitValue for success when " +
"applying a partial mar");
do_check_eq(exitValue, 0);
dump("Testing: update.status should be set to STATE_SUCCEEDED\n");
testFile = updatesDir.clone();
testFile.append(FILE_UPDATE_STATUS);
do_check_eq(readFile(testFile).split("\n")[0], STATE_SUCCEEDED);
logTestInfo("testing update.status should be " + STATE_SUCCEEDED);
do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED);
dump("Testing: removal of files and contents of added / modified files by " +
"a partial mar including retention of file permissions\n");
// For Mac OS X check that the last modified time for a directory has been
// updated after a successful update (bug 600098).
if (IS_MACOSX) {
logTestInfo("testing last modified time on the apply to directory has " +
"changed after a successful update (bug 600098)");
now = Date.now();
var timeDiff = Math.abs(applyToDir.lastModifiedTime - now);
do_check_true(timeDiff < MAX_TIME_DIFFERENCE);
}
logTestInfo("testing the removal of files and the contents of added / " +
"modified files by a partial mar");
for (i = 0; i < gTestFiles.length; i++) {
f = gTestFiles[i];
testFile = do_get_file(f.destinationDir + f.fileName, true);
dump("Testing: " + testFile.path + "\n");
logTestInfo("testing file: " + testFile.path);
if (f.compareFile || f.compareContents) {
do_check_true(testFile.exists());
@ -209,10 +246,13 @@ function run_test() {
// implementaions of chmod doesn't really set permissions.
if (!IS_WIN && !IS_OS2 && f.comparePerms) {
// Check the original permssions are retained on the file.
if (f.originalPerms)
dump("original permissions: " + f.originalPerms.toString(8) + "\n");
dump("compare permissions : " + f.comparePerms.toString(8) + "\n");
dump("updated permissions : " + testFile.permissions.toString(8) + "\n");
let logPerms = "testing file permissions - ";
if (f.originalPerms) {
logPerms += "original permissions: " + f.originalPerms.toString(8) + ", ";
}
logPerms += "compare permissions : " + f.comparePerms.toString(8) + ", ";
logPerms += "updated permissions : " + testFile.permissions.toString(8);
logTestInfo(logPerms);
do_check_eq(testFile.permissions & 0xfff, f.comparePerms & 0xfff);
}
@ -235,16 +275,41 @@ function run_test() {
}
}
dump("Testing: directory still exists after removal of the last file in " +
"the directory (bug 386760)\n");
do_check_true(do_get_file("mar_test/2/2_1/", true).exists());
logTestInfo("testing directory still exists after removal of the last file " +
"in the directory (bug 386760)");
do_check_true(do_get_file(APPLY_TO_DIR + "/mar_test/2/2_1/", true).exists());
dump("Testing: patch files should not be left behind\n");
logTestInfo("testing patch files should not be left behind");
var entries = updatesDir.QueryInterface(AUS_Ci.nsIFile).directoryEntries;
while (entries.hasMoreElements()) {
var entry = entries.getNext().QueryInterface(AUS_Ci.nsIFile);
do_check_neq(getFileExtension(entry), "patch");
}
do_test_finished();
}
function end_test() {
// Try to remove the updates and the apply to directories.
var applyToDir = do_get_file(APPLY_TO_DIR, true);
try {
removeDirRecursive(applyToDir);
}
catch (e) {
dump("Unable to remove directory\n" +
"path: " + applyToDir.path + "\n" +
"Exception: " + e + "\n");
}
var updatesDir = do_get_file(UPDATES_DIR, true);
try {
removeDirRecursive(updatesDir);
}
catch (e) {
dump("Unable to remove directory\n" +
"path: " + updatesDir.path + "\n" +
"Exception: " + e + "\n");
}
cleanUp();
}

Просмотреть файл

@ -38,10 +38,13 @@
/* General Partial MAR File Patch Apply Failure Test */
const APPLY_TO_DIR = "applyToDir_0112";
const UPDATES_DIR = "0112_mar";
var gTestFiles = [
{
fileName : "1_exe1.exe",
destinationDir : "mar_test/1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/",
originalContents : null,
compareContents : null,
originalFile : "data/aus-0111_general_ref_image.png",
@ -50,7 +53,7 @@ var gTestFiles = [
comparePerms : null
}, {
fileName : "1_1_image1.png",
destinationDir : "mar_test/1/1_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/1_1/",
originalContents : null,
compareContents : null,
originalFile : "data/aus-0110_general_ref_image.png",
@ -59,7 +62,7 @@ var gTestFiles = [
comparePerms : null
}, {
fileName : "1_1_text1",
destinationDir : "mar_test/1/1_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/1_1/",
originalContents : "ShouldNotBeDeleted\n",
compareContents : "ShouldNotBeDeleted\n",
originalFile : null,
@ -68,7 +71,7 @@ var gTestFiles = [
comparePerms : null
}, {
fileName : "1_1_text2",
destinationDir : "mar_test/1/1_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/1/1_1/",
originalContents : "ShouldNotBeDeleted\n",
compareContents : "ShouldNotBeDeleted\n",
originalFile : null,
@ -77,7 +80,7 @@ var gTestFiles = [
comparePerms : null
}, {
fileName : "2_1_text1",
destinationDir : "mar_test/2/2_1/",
destinationDir : APPLY_TO_DIR + "/mar_test/2/2_1/",
originalContents : "ShouldNotBeDeleted\n",
compareContents : "ShouldNotBeDeleted\n",
originalFile : null,
@ -87,21 +90,33 @@ var gTestFiles = [
}];
function run_test() {
var testFile;
// The directory the updates will be applied to is the current working
// directory and not dist/bin.
var testDir = do_get_file("mar_test", true);
// The mar files were created with all files in a subdirectory named
// mar_test... clear it out of the way if it exists and then create it.
if (IS_ANDROID) {
logTestInfo("this test is not applicable to Android... returning early");
return;
}
do_test_pending();
do_register_cleanup(end_test);
var testDir, testFile;
// The directory the updates will be applied to is the directory name stored
// in the APPLY_TO_DIR constant located in the current working directory and
// not dist/bin.
var applyToDir = do_get_file(APPLY_TO_DIR, true);
// Remove the directory where the update will be applied if it exists.
try {
removeDirRecursive(testDir);
removeDirRecursive(applyToDir);
}
catch (e) {
dump("Unable to remove directory\npath: " + testDir.path +
"\nException: " + e + "\n");
dump("Unable to remove directory\n" +
"path: " + applyToDir.path + "\n" +
"Exception: " + e + "\n");
}
dump("Testing: successful removal of the directory used to apply the mar file\n");
do_check_false(testDir.exists());
logTestInfo("testing successful removal of the directory used to apply the " +
"mar file");
do_check_false(applyToDir.exists());
// Create the files to test the partial mar's ability to rollback to the
// original files.
@ -134,6 +149,20 @@ function run_test() {
}
}
// For Mac OS X set the last modified time for a directory to a date in the
// past to test that the last modified time on the directories in not updated
// when an update fails (bug 600098).
if (IS_MACOSX) {
// All we care about is that the last modified time has not changed when an
// update has failed.
var now = Date.now();
var lastModTime = now - (1000 * 60 * 60 * 24);
applyToDir.lastModifiedTime = lastModTime;
// Set lastModTime to the value the OS returns in case it is different than
// the value stored by the OS.
lastModTime = applyToDir.lastModifiedTime;
}
var binDir = getGREDir();
// The updater binary file
@ -152,15 +181,16 @@ function run_test() {
}
// Use a directory outside of dist/bin to lessen the garbage in dist/bin
var updatesDir = do_get_file("0112_mar", true);
var updatesDir = do_get_file(UPDATES_DIR, true);
try {
// Mac OS X intermittently fails when removing the dir where the updater
// binary was launched.
removeDirRecursive(updatesDir);
}
catch (e) {
dump("Unable to remove directory\npath: " + updatesDir.path +
"\nException: " + e + "\n");
dump("Unable to remove directory\n" +
"path: " + updatesDir.path + "\n" +
"Exception: " + e + "\n");
}
updatesDir.create(AUS_Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY);
@ -168,24 +198,30 @@ function run_test() {
mar.copyTo(updatesDir, FILE_UPDATE_ARCHIVE);
// apply the partial mar and check the innards of the files
var exitValue = runUpdate(updatesDir, updater);
dump("Testing: updater binary process exitValue for success when applying " +
"a partial mar\n");
var exitValue = runUpdate(updater, updatesDir, applyToDir);
logTestInfo("testing updater binary process exitValue for success when " +
"applying a partial mar");
do_check_eq(exitValue, 0);
dump("Testing: update.status should be set to STATE_FAILED\n");
testFile = updatesDir.clone();
testFile.append(FILE_UPDATE_STATUS);
logTestInfo("testing update.status should be " + STATE_FAILED);
// The update status format for a failure is failed: # where # is the error
// code for the failure.
do_check_eq(readFile(testFile).split(": ")[0], STATE_FAILED);
do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED);
dump("Testing: files should not be modified or deleted when an update " +
"fails including retention of file permissions\n");
// For Mac OS X check that the last modified time for a directory has not been
// updated after a failed update (bug 600098).
if (IS_MACOSX) {
logTestInfo("testing last modified time on the apply to directory has " +
"not changed after a failed update (bug 600098)");
do_check_eq(applyToDir.lastModifiedTime, lastModTime);
}
logTestInfo("testing files should not be modified or deleted when an " +
"update fails");
for (i = 0; i < gTestFiles.length; i++) {
f = gTestFiles[i];
testFile = do_get_file(f.destinationDir + f.fileName, true);
dump("Testing: " + testFile.path + "\n");
logTestInfo("testing file: " + testFile.path);
if (f.compareFile || f.compareContents) {
do_check_true(testFile.exists());
@ -193,10 +229,13 @@ function run_test() {
// implementaions of chmod doesn't really set permissions.
if (!IS_WIN && !IS_OS2 && f.comparePerms) {
// Check the original permssions are retained on the file.
if (f.originalPerms)
dump("original permissions: " + f.originalPerms.toString(8) + "\n");
dump("compare permissions : " + f.comparePerms.toString(8) + "\n");
dump("updated permissions : " + testFile.permissions.toString(8) + "\n");
let logPerms = "testing file permissions - ";
if (f.originalPerms) {
logPerms += "original permissions: " + f.originalPerms.toString(8) + ", ";
}
logPerms += "compare permissions : " + f.comparePerms.toString(8) + ", ";
logPerms += "updated permissions : " + testFile.permissions.toString(8);
logTestInfo(logPerms);
do_check_eq(testFile.permissions & 0xfff, f.comparePerms & 0xfff);
}
@ -213,12 +252,37 @@ function run_test() {
}
}
dump("Testing: patch files should not be left behind\n");
logTestInfo("testing patch files should not be left behind");
var entries = updatesDir.QueryInterface(AUS_Ci.nsIFile).directoryEntries;
while (entries.hasMoreElements()) {
var entry = entries.getNext().QueryInterface(AUS_Ci.nsIFile);
do_check_neq(getFileExtension(entry), "patch");
}
do_test_finished();
}
function end_test() {
// Try to remove the updates and the apply to directories.
var applyToDir = do_get_file(APPLY_TO_DIR, true);
try {
removeDirRecursive(applyToDir);
}
catch (e) {
dump("Unable to remove directory\n" +
"path: " + applyToDir.path + "\n" +
"Exception: " + e + "\n");
}
var updatesDir = do_get_file(UPDATES_DIR, true);
try {
removeDirRecursive(updatesDir);
}
catch (e) {
dump("Unable to remove directory\n" +
"path: " + updatesDir.path + "\n" +
"Exception: " + e + "\n");
}
cleanUp();
}

Просмотреть файл

@ -0,0 +1,675 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/* Test applying an update by staging an update and launching an application */
// Use a copy of the main application executable for the test to avoid main
// executable in use errors.
const FILE_WIN_TEST_EXE = "updatetest.exe";
// Backup the updater.ini and use a custom one to prevent the updater from
// launching a post update executable.
const FILE_UPDATER_INI_BAK = "updater.ini.bak";
// Number of milliseconds for each do_timeout call.
const CHECK_TIMEOUT_MILLI = 1000;
// Maximum number of milliseconds the process that is launched can run before
// the test will try to kill it.
const APP_TIMER_TIMEOUT = 15000;
let gAppTimer;
let gProcess;
// Environment related globals
let gShouldResetEnv = undefined;
let gAddedEnvXRENoWindowsCrashDialog = false;
let gEnvXPCOMDebugBreak;
let gEnvXPCOMMemLeakLog;
let gEnvDyldLibraryPath;
let gEnvLdLibraryPath;
// A shell script is used to get the OS version due to nsSystemInfo not
// returning the actual OS version. It is possible to get the actual OS version
// using ctypes but it would be more complicated than using a shell script.
XPCOMUtils.defineLazyGetter(this, "gIsLessThanMacOSX_10_6", function test_gMacVer() {
if (!IS_MACOSX) {
return false;
}
let [versionScript, versionFile] = getVersionScriptAndFile();
// Precreate the script with executable permissions
versionScript.create(AUS_Ci.nsILocalFile.NORMAL_FILE_TYPE, PERMS_DIRECTORY);
let scriptContents = "#! /bin/sh\nsw_vers -productVersion >> " + versionFile.path;
writeFile(versionScript, scriptContents);
logTestInfo("created " + versionScript.path + " shell script containing:\n" +
scriptContents);
let versionScriptPath = versionScript.path;
if (/ /.test(versionScriptPath)) {
versionScriptPath = '"' + versionScriptPath + '"';
}
let launchBin = getLaunchBin();
let args = [versionScriptPath];
let process = AUS_Cc["@mozilla.org/process/util;1"].
createInstance(AUS_Ci.nsIProcess);
process.init(launchBin);
process.run(true, args, args.length);
if (process.exitValue != 0) {
do_throw("Version script exited with " + process.exitValue + "... unable " +
"to get Mac OS X version!");
}
let version = readFile(versionFile).split("\n")[0];
logTestInfo("executing on Mac OS X verssion " + version);
return (Services.vc.compare(version, "10.6") < 0)
});
function run_test() {
if (IS_ANDROID) {
logTestInfo("this test is not applicable to Android... returning early");
return;
}
if (IS_WINCE) {
logTestInfo("this test is not applicable to Windows CE... returning early");
return;
}
do_test_pending();
do_register_cleanup(end_test);
removeUpdateDirsAndFiles();
if (!getAppBinPath()) {
do_throw("Main application binary not found... expected: " +
APP_BIN_NAME + APP_BIN_SUFFIX);
return;
}
let channel = Services.prefs.getCharPref(PREF_APP_UPDATE_CHANNEL);
let patches = getLocalPatchString(null, null, null, null, null, "true",
STATE_PENDING);
let updates = getLocalUpdateString(patches, null, null, null, null, null,
null, null, null, null, null, null,
null, "true", channel);
writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true);
// Read the application.ini and use its application version
let processDir = getCurrentProcessDir();
let file = processDir.clone();
file.append("application.ini");
let ini = AUS_Cc["@mozilla.org/xpcom/ini-parser-factory;1"].
getService(AUS_Ci.nsIINIParserFactory).
createINIParser(file);
let version = ini.getString("App", "Version");
writeVersionFile(version);
writeStatusFile(STATE_PENDING);
// This is the directory where the update files will be located
let updateTestDir = getUpdateTestDir();
try {
removeDirRecursive(updateTestDir);
}
catch (e) {
dump("Unable to remove directory\n" +
"path: " + updateTestDir.path + "\n" +
"Exception: " + e + "\n");
}
// Add the directory where the update files will be added and add files that
// will be removed.
if (!updateTestDir.exists()) {
updateTestDir.create(AUS_Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY);
}
logTestInfo("update test directory path: " + updateTestDir.path);
file = updateTestDir.clone();
file.append("UpdateTestRemoveFile");
writeFile(file, "ToBeRemoved");
file = updateTestDir.clone();
file.append("UpdateTestAddFile");
writeFile(file, "ToBeReplaced");
file = updateTestDir.clone();
file.append("removed-files");
writeFile(file, "ToBeReplaced");
let updatesPatchDir = getUpdatesDir();
updatesPatchDir.append("0");
let mar = do_get_file("data/simple.mar");
mar.copyTo(updatesPatchDir, FILE_UPDATE_ARCHIVE);
// Backup the updater.ini
let updaterINI = processDir.clone();
updaterINI.append(FILE_UPDATER_INI);
updaterINI.moveTo(processDir, FILE_UPDATER_INI_BAK);
// Create a new updater.ini to avoid applications that provide a post update
// executable.
updaterINI = processDir.clone();
updaterINI.append(FILE_UPDATER_INI);
writeFile(updaterINI, "[Strings]\n" +
"Title=Update Test\n" +
"Info=XPCShell Application Update Test\n");
let launchBin = getLaunchBin();
let args = getProcessArgs();
let infoArgs = "";
args.forEach(function(aArg) {
infoArgs += " " + aArg;
});
logTestInfo("launching " + launchBin.path + infoArgs);
gProcess = AUS_Cc["@mozilla.org/process/util;1"].
createInstance(AUS_Ci.nsIProcess);
gProcess.init(launchBin);
gAppTimer = AUS_Cc["@mozilla.org/timer;1"].createInstance(AUS_Ci.nsITimer);
gAppTimer.initWithCallback(gTimerCallback, APP_TIMER_TIMEOUT,
AUS_Ci.nsITimer.TYPE_ONE_SHOT);
setEnvironment();
gProcess.runAsync(args, args.length, gProcessObserver);
resetEnvironment();
}
function end_test() {
if (gProcess.isRunning) {
logTestInfo("attempt to kill process");
gProcess.kill();
}
if (gAppTimer) {
logTestInfo("cancelling timer");
gAppTimer.cancel();
gAppTimer = null;
}
resetEnvironment();
let processDir = getCurrentProcessDir();
// Restore the backed up updater.ini
let updaterINI = processDir.clone();
updaterINI.append(FILE_UPDATER_INI_BAK);
updaterINI.moveTo(processDir, FILE_UPDATER_INI);
if (IS_WIN) {
// Remove the copy of the application executable used for the test on
// Windows if it exists.
let appBinCopy = processDir.clone();
appBinCopy.append(FILE_WIN_TEST_EXE);
if (appBinCopy.exists()) {
appBinCopy.remove(false);
}
}
// Remove the files added by the update.
let updateTestDir = getUpdateTestDir();
try {
logTestInfo("removing update test directory " + updateTestDir.path);
removeDirRecursive(updateTestDir);
}
catch (e) {
dump("Unable to remove directory\n" +
"path: " + updateTestDir.path + "\n" +
"Exception: " + e + "\n");
}
// This will delete the app console log file if it exists.
getAppConsoleLogPath();
if (IS_UNIX) {
// This will delete the launch script if it exists.
getLaunchScript();
if (IS_MACOSX) {
// This will delete the version script and version file if they exist.
getVersionScriptAndFile();
}
}
cleanUp();
}
/**
* The observer for the call to nsIProcess:runAsync.
*/
let gProcessObserver = {
observe: function PO_observe(subject, topic, data) {
logTestInfo("topic " + topic + ", process exitValue " + gProcess.exitValue);
if (gAppTimer) {
gAppTimer.cancel();
gAppTimer = null;
}
if (topic != "process-finished" || gProcess.exitValue != 0) {
do_throw("Failed to launch application");
}
do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
},
QueryInterface: XPCOMUtils.generateQI([AUS_Ci.nsIObserver])
};
/**
* The timer callback to kill the process if it takes too long.
*/
let gTimerCallback = {
notify: function TC_notify(aTimer) {
gAppTimer = null;
if (gProcess.isRunning) {
gProcess.kill();
}
do_throw("launch application timer expired");
},
QueryInterface: XPCOMUtils.generateQI([AUS_Ci.nsITimerCallback])
};
/**
* Sets the environment that will be used by the application process when it is
* launched.
*/
function setEnvironment() {
// Prevent setting the environment more than once.
if (gShouldResetEnv !== undefined)
return;
gShouldResetEnv = true;
let env = AUS_Cc["@mozilla.org/process/environment;1"].
getService(AUS_Ci.nsIEnvironment);
if (IS_WIN && !env.exists("XRE_NO_WINDOWS_CRASH_DIALOG")) {
gAddedEnvXRENoWindowsCrashDialog = true;
logTestInfo("setting the XRE_NO_WINDOWS_CRASH_DIALOG environment " +
"variable to 1... previously it didn't exist");
env.set("XRE_NO_WINDOWS_CRASH_DIALOG", "1");
}
if (IS_UNIX) {
let appGreDir = Services.dirsvc.get("GreD", AUS_Ci.nsIFile);
let envGreDir = AUS_Cc["@mozilla.org/file/local;1"].
createInstance(AUS_Ci.nsILocalFile);
let shouldSetEnv = true;
if (IS_MACOSX) {
if (env.exists("DYLD_LIBRARY_PATH")) {
gEnvDyldLibraryPath = env.get("DYLD_LIBRARY_PATH");
envGreDir.initWithPath(gEnvDyldLibraryPath);
if (envGreDir.path == appGreDir.path) {
gEnvDyldLibraryPath = null;
shouldSetEnv = false;
}
}
if (shouldSetEnv) {
logTestInfo("setting DYLD_LIBRARY_PATH environment variable value to " +
appGreDir.path);
env.set("DYLD_LIBRARY_PATH", appGreDir.path);
}
}
else {
if (env.exists("LD_LIBRARY_PATH")) {
gEnvLdLibraryPath = env.get("LD_LIBRARY_PATH");
envGreDir.initWithPath(gEnvLdLibraryPath);
if (envGreDir.path == appGreDir.path) {
gEnvLdLibraryPath = null;
shouldSetEnv = false;
}
}
if (shouldSetEnv) {
logTestInfo("setting LD_LIBRARY_PATH environment variable value to " +
appGreDir.path);
env.set("LD_LIBRARY_PATH", appGreDir.path);
}
}
}
if (env.exists("XPCOM_MEM_LEAK_LOG")) {
gEnvXPCOMMemLeakLog = env.get("XPCOM_MEM_LEAK_LOG");
logTestInfo("removing the XPCOM_MEM_LEAK_LOG environment variable... " +
"previous value " + gEnvXPCOMMemLeakLog);
env.set("XPCOM_MEM_LEAK_LOG", "");
}
if (env.exists("XPCOM_DEBUG_BREAK")) {
gEnvXPCOMDebugBreak = env.get("XPCOM_DEBUG_BREAK");
logTestInfo("setting the XPCOM_DEBUG_BREAK environment variable to " +
"warn... previous value " + gEnvXPCOMDebugBreak);
}
else {
logTestInfo("setting the XPCOM_DEBUG_BREAK environment variable to " +
"warn... previously it didn't exist");
}
env.set("XPCOM_DEBUG_BREAK", "warn");
}
/**
* Sets the environment back to the original values after launching the
* application.
*/
function resetEnvironment() {
// Prevent resetting the environment more than once.
if (gShouldResetEnv !== true)
return;
gShouldResetEnv = false;
let env = AUS_Cc["@mozilla.org/process/environment;1"].
getService(AUS_Ci.nsIEnvironment);
if (gEnvXPCOMMemLeakLog) {
logTestInfo("setting the XPCOM_MEM_LEAK_LOG environment variable back to " +
gEnvXPCOMMemLeakLog);
env.set("XPCOM_MEM_LEAK_LOG", gEnvXPCOMMemLeakLog);
}
if (gEnvXPCOMDebugBreak) {
logTestInfo("setting the XPCOM_DEBUG_BREAK environment variable back to " +
gEnvXPCOMDebugBreak);
env.set("XPCOM_DEBUG_BREAK", gEnvXPCOMDebugBreak);
}
else {
logTestInfo("clearing the XPCOM_DEBUG_BREAK environment variable");
env.set("XPCOM_DEBUG_BREAK", "");
}
if (IS_UNIX) {
if (IS_MACOSX) {
if (gEnvDyldLibraryPath) {
logTestInfo("setting DYLD_LIBRARY_PATH environment variable value " +
"back to " + gEnvDyldLibraryPath);
env.set("DYLD_LIBRARY_PATH", gEnvDyldLibraryPath);
}
else {
logTestInfo("removing DYLD_LIBRARY_PATH environment variable");
env.set("DYLD_LIBRARY_PATH", "");
}
}
else {
if (gEnvLdLibraryPath) {
logTestInfo("setting LD_LIBRARY_PATH environment variable value back " +
"to " + gEnvLdLibraryPath);
env.set("LD_LIBRARY_PATH", gEnvLdLibraryPath);
}
else {
logTestInfo("removing LD_LIBRARY_PATH environment variable");
env.set("LD_LIBRARY_PATH", "");
}
}
}
if (IS_WIN && gAddedEnvXRENoWindowsCrashDialog) {
logTestInfo("removing the XRE_NO_WINDOWS_CRASH_DIALOG environment " +
"variable");
env.set("XRE_NO_WINDOWS_CRASH_DIALOG", "");
}
}
/**
* Checks for the existence of a platform specific application binary that can
* be used for the test and returns its path if it is found.
*
* Note: The application shell scripts for launching the application work on all
* platforms that provide a launch shell script except for Mac OS X 10.5 which
* is why this test uses the binaries to launch the application.
*
* @return path to an application binary that can be used for this test or null
* if an application binary that can be used for this test is not
* found.
*/
function getAppBinPath() {
let processDir = getCurrentProcessDir();
let appBin = processDir.clone();
appBin.append(APP_BIN_NAME + APP_BIN_SUFFIX);
if (appBin.exists()) {
if (IS_WIN) {
let appBinCopy = processDir.clone();
appBinCopy.append(FILE_WIN_TEST_EXE);
if (appBinCopy.exists()) {
appBinCopy.remove(false);
}
appBin.copyTo(processDir, appBinCopy.leafName);
appBin = processDir.clone();
appBin.append(appBinCopy.leafName);
}
let appBinPath = appBin.path;
if (/ /.test(appBinPath)) {
appBinPath = '"' + appBinPath + '"';
}
return appBinPath;
}
return null;
}
/**
* Gets the platform specific binary used to launch the application using
* nsIProcess.
*
* @return nsIFile for the binary to launch using nsIProcess.
*/
function getLaunchBin() {
let launchBin;
if (IS_WIN) {
launchBin = Services.dirsvc.get("WinD", AUS_Ci.nsIFile);
launchBin.append("System32");
launchBin.append("cmd.exe");
}
else {
launchBin = AUS_Cc["@mozilla.org/file/local;1"].
createInstance(AUS_Ci.nsILocalFile);
launchBin.initWithPath("/bin/sh");
}
return launchBin;
}
/**
* Returns the platform specific arguments used by nsIProcess when launching
* the application.
*
* @return an array of arguments to be passed to nsIProcess.
*
* Notes:
* 1. Mozilla universal binaries that contain both i386 and x86_64 on Mac OS X
* 10.5.x must be launched using the i386 architecture.
* 2. A shell is necessary to pipe the application's console output which
* would otherwise pollute the xpcshell log.
*
* Command line arguments used when launching the application:
* -no-remote prevents shell integration from being affected by an existing
* application process.
* -process-updates makes the application exits after being relaunched by the
* updater.
* 1> pipes stdout to a file.
* appConsoleLogPath is the file path to pipe the output from the shell.
* Otherwise the output from the application will end up in the xpchsell log.
* 2>&1 pipes stderr to sdout.
*/
function getProcessArgs() {
let appBinPath = getAppBinPath();
// Pipe the output from the launched application to a file so the output from
// its console isn't present in the xpcshell log.
let appConsoleLogPath = getAppConsoleLogPath();
let args;
if (IS_UNIX) {
let launchScript = getLaunchScript();
// Precreate the script with executable permissions
launchScript.create(AUS_Ci.nsILocalFile.NORMAL_FILE_TYPE, PERMS_DIRECTORY);
let scriptContents = "#! /bin/sh\n";
// On Mac OS X versions prior to 10.6 the i386 acrhitecture must be used.
if (gIsLessThanMacOSX_10_6) {
scriptContents += "arch -arch i386 ";
}
scriptContents += appBinPath + " -no-remote -process-updates 1> " +
appConsoleLogPath + " 2>&1";
writeFile(launchScript, scriptContents);
logTestInfo("created " + launchScript.path + " containing:\n" +
scriptContents);
args = [launchScript.path];
}
else {
args = ["/D", "/Q", "/C", appBinPath, "-no-remote", "-process-updates",
"1>", appConsoleLogPath, "2>&1"];
}
return args;
}
/**
* Gets the directory where the update adds / removes the files contained in the
* update.
*
* @return nsIFile for the directory where the update adds / removes the files
* contained in the update mar.
*/
function getUpdateTestDir() {
let updateTestDir = getCurrentProcessDir();
if (IS_MACOSX) {
updateTestDir = updateTestDir.parent.parent;
}
updateTestDir.append("update_test");
return updateTestDir;
}
/**
* Gets a file path for piping the console output from the application so it
* doesn't appear in the xpcshell log file.
*
* @return path to the file for piping the console output from the application.
*/
function getAppConsoleLogPath() {
let appConsoleLog = do_get_file("/", true);
appConsoleLog.append("app_console_log");
if (appConsoleLog.exists()) {
appConsoleLog.remove(false);
}
let appConsoleLogPath = appConsoleLog.path;
if (/ /.test(appConsoleLogPath)) {
appConsoleLogPath = '"' + appConsoleLogPath + '"';
}
return appConsoleLogPath;
}
/**
* Gets the nsIFile references for the shell script to retrieve the Mac OS X
* version and the nsIFile to pipe the output of the shell script. If either of
* these files exist they will be removed by this function.
*
* @return array containing two nsIFile references. The first array member is
* the nsIFile for the shell script to launch to get the Mac OS X
* version and the second array member is the nsIFile for the piped
* output from the shell script.
*/
function getVersionScriptAndFile() {
let versionScript = do_get_file("/", true);
let versionFile = versionScript.clone();
versionScript.append("get_version.sh");
if (versionScript.exists()) {
versionScript.remove(false);
}
versionFile.append("version.out");
if (versionFile.exists()) {
versionFile.remove(false);
}
return [versionScript, versionFile];
}
/**
* Gets the nsIFile reference for the shell script to launch the application. If
* the file exists it will be removed by this function.
*
* @return the nsIFile for the shell script to launch the application.
*/
function getLaunchScript() {
let launchScript = do_get_file("/", true);
launchScript.append("launch.sh");
if (launchScript.exists()) {
launchScript.remove(false);
}
return launchScript;
}
/**
* Checks if the update has finished and if it has finished performs checks for
* the test.
*/
function checkUpdateFinished() {
// Don't proceed until the update.log has been created.
let log = getUpdatesDir();
log.append("0");
log.append(FILE_UPDATE_LOG);
if (!log.exists()) {
do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
return;
}
// Don't proceed until the update status is no longer pending or applying.
let status = readStatusFile();
if (status == STATE_PENDING || status == STATE_APPLYING) {
do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
return;
}
// Log the contents of the update.log so it is simpler to diagnose a test
// failure. For example, on Windows if the application binary is in use the
// updater will not apply the update.
let contents = readFile(log);
logTestInfo("contents of " + log.path + ":\n" +
contents.replace(/\r\n/g, "\n"));
if (IS_WIN && contents.indexOf("NS_main: file in use") != -1) {
do_throw("the application can't be in use when running this test");
}
do_check_eq(status, STATE_SUCCEEDED);
standardInit();
let update = gUpdateManager.getUpdateAt(0);
do_check_eq(update.state, STATE_SUCCEEDED);
let updateTestDir = getUpdateTestDir();
let file = updateTestDir.clone();
file.append("UpdateTestRemoveFile");
do_check_false(file.exists());
file = updateTestDir.clone();
file.append("UpdateTestAddFile");
do_check_true(file.exists());
do_check_eq(readFileBytes(file), "UpdateTestAddFile\n");
file = updateTestDir.clone();
file.append("removed-files");
do_check_true(file.exists());
do_check_eq(readFileBytes(file), "update_test/UpdateTestRemoveFile\n");
let updatesDir = getUpdatesDir();
let log = updatesDir.clone();
log.append("0");
log.append(FILE_UPDATE_LOG);
logTestInfo("testing " + log.path + " shouldn't exist");
do_check_false(log.exists());
log = updatesDir.clone();
log.append(FILE_LAST_LOG);
logTestInfo("testing " + log.path + " should exist");
do_check_true(log.exists());
log = updatesDir.clone();
log.append(FILE_BACKUP_LOG);
logTestInfo("testing " + log.path + " shouldn't exist");
do_check_false(log.exists());
updatesDir.append("0");
logTestInfo("testing " + updatesDir.path + " should exist");
do_check_true(updatesDir.exists());
do_timeout(CHECK_TIMEOUT_MILLI, do_test_finished);
}

Просмотреть файл

@ -49,9 +49,11 @@ function run_test() {
return;
do_test_pending();
dump("Testing: Bug 497578 - begin download of a complete update after a " +
"failure to apply a partial update with " +
"browser.privatebrowsing.autostart set to true\n");
do_register_cleanup(end_test);
logTestInfo("testing Bug 497578 - begin download of a complete update " +
"after a failure to apply a partial update with " +
"browser.privatebrowsing.autostart set to true");
removeUpdateDirsAndFiles();
setUpdateChannel();
@ -74,7 +76,6 @@ function end_test() {
let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
WindowWatcherFactory);
do_test_finished();
cleanUp();
}
@ -92,8 +93,8 @@ function run_test_pt1() {
standardInit();
dump("Testing: activeUpdate.state should equal STATE_DOWNLOADING prior to " +
"entering private browsing\n");
logTestInfo("testing activeUpdate.state should equal STATE_DOWNLOADING " +
"prior to entering private browsing");
do_check_eq(gUpdateManager.activeUpdate.state, STATE_DOWNLOADING);
let privBrowsing = AUS_Cc[PRIVATEBROWSING_CONTRACT_ID].
@ -101,25 +102,26 @@ function run_test_pt1() {
QueryInterface(AUS_Ci.nsIObserver);
privBrowsing.observe(null, "profile-after-change", "");
dump("Testing: private mode should be entered automatically\n");
logTestInfo("Testing: private mode should be entered automatically");
do_check_true(privBrowsing.privateBrowsingEnabled);
dump("Testing: private browsing is auto-started\n");
logTestInfo("Testing: private browsing is auto-started");
do_check_true(privBrowsing.autoStarted);
// Give private browsing time to reset necko.
do_execute_soon(run_test_pt2);
}
function run_test_pt2() {
dump("Testing: update count should equal 1\n");
logTestInfo("Testing: update count should equal 1");
do_check_eq(gUpdateManager.updateCount, 1);
dump("Testing: activeUpdate should not equal null\n");
logTestInfo("Testing: activeUpdate should not equal null");
do_check_neq(gUpdateManager.activeUpdate, null);
dump("Testing: activeUpdate.state should not equal null\n");
logTestInfo("Testing: activeUpdate.state should not equal null");
do_check_neq(gUpdateManager.activeUpdate.state, null);
dump("Testing: activeUpdate.state should equal STATE_DOWNLOADING\n");
logTestInfo("Testing: activeUpdate.state should equal STATE_DOWNLOADING");
do_check_eq(gUpdateManager.activeUpdate.state, STATE_DOWNLOADING);
end_test();
do_test_finished();
}
// Prevent the attempt to display the Update wizard for the failed update

Просмотреть файл

@ -9,10 +9,12 @@
function run_test() {
do_test_pending();
dump("Testing: Bug 595059 - calling nsIUpdatePrompt::showUpdateError " +
"should call getNewPrompter and alert on the object returned by " +
"getNewPrompter when the update.state = " + STATE_FAILED + " and the " +
"update.errorCode = " + WRITE_ERROR + "\n");
do_register_cleanup(end_test);
logTestInfo("testing Bug 595059 - calling nsIUpdatePrompt::showUpdateError " +
"should call getNewPrompter and alert on the object returned " +
"by getNewPrompter when the update.state = " + STATE_FAILED +
" and the update.errorCode = " + WRITE_ERROR);
removeUpdateDirsAndFiles();
setUpdateChannel();
@ -47,7 +49,6 @@ function end_test() {
let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
WindowWatcherFactory);
do_test_finished();
cleanUp();
}
@ -62,7 +63,7 @@ var WindowWatcher = {
[Services.appinfo.name,
Services.appinfo.name], 2);
do_check_eq(aText, text);
end_test();
do_test_finished();
}
};
},

Просмотреть файл

@ -3279,21 +3279,33 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
}
#if defined(MOZ_UPDATER) && !defined(ANDROID)
// Check for and process any available updates
nsCOMPtr<nsIFile> updRoot;
PRBool persistent;
rv = dirProvider.GetFile(XRE_UPDATE_ROOT_DIR, &persistent,
getter_AddRefs(updRoot));
// XRE_UPDATE_ROOT_DIR may fail. Fallback to appDir if failed
if (NS_FAILED(rv))
updRoot = dirProvider.GetAppDir();
// Check for and process any available updates
nsCOMPtr<nsIFile> updRoot;
PRBool persistent;
rv = dirProvider.GetFile(XRE_UPDATE_ROOT_DIR, &persistent,
getter_AddRefs(updRoot));
// XRE_UPDATE_ROOT_DIR may fail. Fallback to appDir if failed
if (NS_FAILED(rv))
updRoot = dirProvider.GetAppDir();
ProcessUpdates(dirProvider.GetGREDir(),
dirProvider.GetAppDir(),
updRoot,
gRestartArgc,
gRestartArgv,
appData.version);
// Support for processing an update and exiting. The MOZ_PROCESS_UPDATES
// environment variable will be part of the updater's environment and the
// application that is relaunched by the updater. When the application is
// relaunched by the updater it will be removed below and the application
// will exit.
if (CheckArg("process-updates")) {
SaveToEnv("MOZ_PROCESS_UPDATES=1");
}
ProcessUpdates(dirProvider.GetGREDir(),
dirProvider.GetAppDir(),
updRoot,
gRestartArgc,
gRestartArgv,
appData.version);
if (PR_GetEnv("MOZ_PROCESS_UPDATES")) {
PR_SetEnv("MOZ_PROCESS_UPDATES=");
return 0;
}
#endif
nsCOMPtr<nsIProfileLock> profileLock;
@ -3350,32 +3362,32 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
// Also check to see if something has happened to invalidate our
// fastload caches, like an extension upgrade or installation.
// If we see .purgecaches, that means someone did a make.
// Re-register components to catch potential changes.
// We only offer this in debug builds, though.
nsCOMPtr<nsILocalFile> flagFile;
// If we see .purgecaches, that means someone did a make.
// Re-register components to catch potential changes.
// We only offer this in debug builds, though.
nsCOMPtr<nsILocalFile> flagFile;
rv = NS_ERROR_FILE_NOT_FOUND;
nsCOMPtr<nsIFile> fFlagFile;
if (gAppData->directory) {
rv = gAppData->directory->Clone(getter_AddRefs(fFlagFile));
}
flagFile = do_QueryInterface(fFlagFile);
if (flagFile) {
flagFile->AppendNative(FILE_INVALIDATE_CACHES);
}
rv = NS_ERROR_FILE_NOT_FOUND;
nsCOMPtr<nsIFile> fFlagFile;
if (gAppData->directory) {
rv = gAppData->directory->Clone(getter_AddRefs(fFlagFile));
}
flagFile = do_QueryInterface(fFlagFile);
if (flagFile) {
flagFile->AppendNative(FILE_INVALIDATE_CACHES);
}
PRBool cachesOK;
PRBool versionOK = CheckCompatibility(profD, version, osABI,
dirProvider.GetGREDir(),
gAppData->directory, flagFile,
&cachesOK);
if (CheckArg("purgecaches")) {
cachesOK = PR_FALSE;
}
if (PR_GetEnv("MOZ_PURGE_CACHES")) {
cachesOK = PR_FALSE;
}
if (CheckArg("purgecaches")) {
cachesOK = PR_FALSE;
}
if (PR_GetEnv("MOZ_PURGE_CACHES")) {
cachesOK = PR_FALSE;
}
// Every time a profile is loaded by a build with a different version,
// it updates the compatibility.ini file saying what version last wrote