Bug 973933 - Fix mochitest chrome updater tests. r=rstrong

This commit is contained in:
Brian R. Bondy 2015-04-06 12:03:18 -04:00
Родитель ab9ccba028
Коммит 0cae4e498f
2 изменённых файлов: 58 добавлений и 0 удалений

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

@ -129,6 +129,7 @@ Cu.import("resource://gre/modules/AddonManager.jsm", this);
Cu.import("resource://gre/modules/Services.jsm", this);
const IS_MACOSX = ("nsILocalFileMac" in Ci);
const IS_WIN = ("@mozilla.org/windows-registry-key;1" in Cc);
// The tests have to use the pageid instead of the pageIndex due to the
// app update wizard's access method being random.
@ -183,6 +184,10 @@ const TEST_ADDONS = [ "appdisabled_1", "appdisabled_2",
const LOG_FUNCTION = info;
const BIN_SUFFIX = (IS_WIN ? ".exe" : "");
const FILE_UPDATER_BIN = "updater" + (IS_MACOSX ? ".app" : BIN_SUFFIX);
const FILE_UPDATER_BIN_BAK = FILE_UPDATER_BIN + ".bak";
var gURLData = URL_HOST + "/" + REL_PATH_DATA + "/";
var gTestTimeout = 240000; // 4 minutes
@ -871,6 +876,26 @@ function verifyTestsRan() {
}
}
/**
* Restore the updater that was backed up. This is called both in setupFiles
* and resetFiles. It is called in setupFiles before the backup is done in
* case the previous test failed. It is called in resetFiles to put things
* back to its original state.
*/
function resetUpdaterBackup() {
let baseAppDir = getAppBaseDir();
let updater = baseAppDir.clone();
let updaterBackup = baseAppDir.clone();
updater.append(FILE_UPDATER_BIN);
updaterBackup.append(FILE_UPDATER_BIN_BAK);
if (updaterBackup.exists()) {
if (updater.exists()) {
updater.remove(true);
}
updaterBackup.moveTo(baseAppDir, FILE_UPDATER_BIN);
}
}
/**
* Creates a backup of files the tests need to modify so they can be restored to
* the original file when the test has finished and then modifies the files.
@ -886,6 +911,31 @@ function setupFiles() {
updateSettingsIni = baseAppDir.clone();
updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI);
writeFile(updateSettingsIni, UPDATE_SETTINGS_CONTENTS);
// Just in case the last test failed, try to reset.
resetUpdaterBackup();
// Move away the real updater
let updater = baseAppDir.clone();
updater.append(FILE_UPDATER_BIN);
updater.moveTo(baseAppDir, FILE_UPDATER_BIN_BAK);
// Move in the test only updater
let testUpdaterDir = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties).
get("CurWorkD", Ci.nsILocalFile);
let relPath = REL_PATH_DATA;
let pathParts = relPath.split("/");
for (let i = 0; i < pathParts.length; ++i) {
testUpdaterDir.append(pathParts[i]);
}
let testUpdater = testUpdaterDir.clone();
testUpdater.append(FILE_UPDATER_BIN);
if (testUpdater.exists()) {
testUpdater.copyToFollowingLinks(baseAppDir, FILE_UPDATER_BIN);
}
}
/**
@ -978,6 +1028,7 @@ function resetFiles() {
", Exception: " + e);
}
}
resetUpdaterBackup();
}
/**

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

@ -6,6 +6,7 @@
# For changes here, also consider ../Makefile.in
XPCSHELLTESTROOT = $(abspath $(DEPTH))/_tests/xpcshell/toolkit/mozapps/update/tests
MOCHITESTROOT = $(abspath $(DEPTH))/_tests/testing/mochitest/chrome/toolkit/mozapps/update/tests
ifndef MOZ_PROFILE_GENERATE
ifdef COMPILE_ENVIRONMENT
@ -34,6 +35,7 @@ endif
libs::
ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
# Copy for xpcshell tests
$(NSINSTALL) -D $(XPCSHELLTESTROOT)/data/updater-xpcshell.app
rsync -a -C --exclude '*.in' $(srcdir)/../macbuild/Contents $(XPCSHELLTESTROOT)/data/updater-xpcshell.app
sed -e 's/%APP_NAME%/$(MOZ_APP_DISPLAYNAME)/' $(srcdir)/../macbuild/Contents/Resources/English.lproj/InfoPlist.strings.in | \
@ -41,10 +43,15 @@ ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
$(NSINSTALL) -D $(XPCSHELLTESTROOT)/data/updater-xpcshell.app/Contents/MacOS/updater-xpcshell
$(NSINSTALL) $(XPCSHELLTESTROOT)/data/updater-xpcshell $(XPCSHELLTESTROOT)/data/updater-xpcshell.app/Contents/MacOS
rm -f $(XPCSHELLTESTROOT)/data/updater-xpcshell
rm -Rf $(XPCSHELLTESTROOT)/data/updater.app
mv $(XPCSHELLTESTROOT)/data/updater-xpcshell.app $(XPCSHELLTESTROOT)/data/updater.app
mv $(XPCSHELLTESTROOT)/data/updater.app/Contents/MacOS/updater-xpcshell $(XPCSHELLTESTROOT)/data/updater.app/Contents/MacOS/updater
# Copy for mochitest chrome tests
rsync -a -C $(XPCSHELLTESTROOT)/data/updater.app $(MOCHITESTROOT)/data/updater.app
else
mv $(XPCSHELLTESTROOT)/data/updater-xpcshell$(BIN_SUFFIX) $(XPCSHELLTESTROOT)/data/updater$(BIN_SUFFIX)
cp $(XPCSHELLTESTROOT)/data/updater$(BIN_SUFFIX) $(MOCHITESTROOT)/data/updater$(BIN_SUFFIX)
endif
CXXFLAGS += $(MOZ_BZ2_CFLAGS)