mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 14:55:47 +00:00
Bug 572162 - Update root dir migration xpcshell tests. r=rstrong
This commit is contained in:
parent
08dbcd55b0
commit
8921a0379c
@ -6,6 +6,9 @@ const INSTALL_LOCALE = "@AB_CD@";
|
||||
const APP_BIN_NAME = "@MOZ_APP_NAME@";
|
||||
const BIN_SUFFIX = "@BIN_SUFFIX@";
|
||||
|
||||
const APP_INFO_NAME = "XPCShell";
|
||||
const APP_INFO_VENDOR = "Mozilla";
|
||||
|
||||
#ifdef XP_UNIX
|
||||
const APP_BIN_SUFFIX = "-bin";
|
||||
#else
|
||||
@ -367,7 +370,7 @@ function setDefaultPrefs() {
|
||||
* update service stub.
|
||||
*/
|
||||
function standardInit() {
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1.0", "2.0");
|
||||
createAppInfo("xpcshell@tests.mozilla.org", APP_INFO_NAME, "1.0", "2.0");
|
||||
setDefaultPrefs();
|
||||
// Initialize the update service stub component
|
||||
initUpdateServiceStub();
|
||||
@ -1857,7 +1860,7 @@ function createAppInfo(id, name, version, platformVersion) {
|
||||
const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
|
||||
const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");
|
||||
var XULAppInfo = {
|
||||
vendor: "Mozilla",
|
||||
vendor: APP_INFO_VENDOR,
|
||||
name: name,
|
||||
ID: id,
|
||||
version: version,
|
||||
|
@ -0,0 +1,178 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
const TEST_ID = "0300";
|
||||
const PREF_APP_UPDATE_MIGRATE_APP_DIR = "app.update.migrated.updateDir";
|
||||
|
||||
// Maximum number of milliseconds the process that is launched can run before
|
||||
// the test will try to kill it.
|
||||
const APP_TIMER_TIMEOUT = 120000;
|
||||
Components.utils.import("resource://gre/modules/FileUtils.jsm");
|
||||
|
||||
function clearTaskbarIDHash(exePath, appInfoName) {
|
||||
let registry = AUS_Cc["@mozilla.org/windows-registry-key;1"].
|
||||
createInstance(AUS_Ci.nsIWindowsRegKey);
|
||||
try {
|
||||
registry.open(AUS_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
|
||||
"Software\\Mozilla\\" + appInfoName + "\\TaskBarIDs",
|
||||
AUS_Ci.nsIWindowsRegKey.ACCESS_ALL);
|
||||
registry.removeValue(exePath);
|
||||
} catch (ex) {
|
||||
} finally {
|
||||
registry.close();
|
||||
}
|
||||
}
|
||||
|
||||
function setTaskbarIDHash(exePath, hash, appInfoName) {
|
||||
let registry = AUS_Cc["@mozilla.org/windows-registry-key;1"].
|
||||
createInstance(AUS_Ci.nsIWindowsRegKey);
|
||||
try {
|
||||
registry.create(AUS_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
|
||||
"Software\\Mozilla\\" + appInfoName + "\\TaskBarIDs",
|
||||
AUS_Ci.nsIWindowsRegKey.ACCESS_WRITE);
|
||||
registry.writeStringValue(exePath, hash);
|
||||
} catch (ex) {
|
||||
} finally {
|
||||
registry.close();
|
||||
}
|
||||
};
|
||||
|
||||
function getMigrated() {
|
||||
var migrated = 0;
|
||||
try {
|
||||
migrated = Services.prefs.getBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR);
|
||||
} catch (e) {
|
||||
}
|
||||
return migrated;
|
||||
}
|
||||
|
||||
/* General Update Manager Tests */
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
do_register_cleanup(end_test);
|
||||
|
||||
standardInit();
|
||||
|
||||
var appinfo = Components.classes["@mozilla.org/xre/app-info;1"].
|
||||
getService(Components.interfaces.nsIXULAppInfo).
|
||||
QueryInterface(Components.interfaces.nsIXULRuntime);
|
||||
|
||||
// Obtain the old update root leaf
|
||||
var exeFile = FileUtils.getFile("XREExeF", []);
|
||||
var updateLeafName;
|
||||
var programFiles = FileUtils.getFile("ProgF", []);
|
||||
var exeFile = FileUtils.getFile("XREExeF", []);
|
||||
if (exeFile.path.substring(0, programFiles.path.length).toLowerCase() ==
|
||||
programFiles.path.toLowerCase()) {
|
||||
updateLeafName = exeFile.parent.leafName;
|
||||
} else {
|
||||
updateLeafName = appinfo.name;
|
||||
}
|
||||
|
||||
// Obtain the old update root
|
||||
var oldUpdateRoot;
|
||||
if (appinfo.vendor) {
|
||||
oldUpdateRoot = FileUtils.getDir("LocalAppData", [appinfo.vendor,
|
||||
appinfo.name,
|
||||
updateLeafName], false);
|
||||
} else {
|
||||
oldUpdateRoot = FileUtils.getDir("LocalAppData", [appinfo.name,
|
||||
updateLeafName], false);
|
||||
}
|
||||
// Obtain the new update root
|
||||
var newUpdateRoot = FileUtils.getDir("UpdRootD", [], false);
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Setting a taskbar ID without the old update dir existing should set the
|
||||
// pref so a migration isn't retried.
|
||||
|
||||
// Remove the old and new update root directories
|
||||
try {
|
||||
oldUpdateRoot.remove(true);
|
||||
} catch (e) {
|
||||
}
|
||||
try {
|
||||
newUpdateRoot.remove(true);
|
||||
} catch (e) {
|
||||
}
|
||||
Services.prefs.setBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR, false);
|
||||
setTaskbarIDHash(exeFile.parent.path, "AAAAAAAA", appinfo.name);
|
||||
initUpdateServiceStub();
|
||||
do_check_eq(getMigrated(), 1);
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// An application without a taskbar ID should bail early without a pref
|
||||
// being set, so that if a taskbar is set for the application, the migration
|
||||
// will be retried.
|
||||
|
||||
Services.prefs.setBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR, false);
|
||||
clearTaskbarIDHash(exeFile.parent.path, appinfo.name);
|
||||
initUpdateServiceStub();
|
||||
do_check_eq(getMigrated(), 0);
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Migrating files should work
|
||||
|
||||
Services.prefs.setBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR, false);
|
||||
setTaskbarIDHash(exeFile.parent.path, "AAAAAAAA", appinfo.name);
|
||||
var oldUpdateDirs = oldUpdateRoot.clone();
|
||||
oldUpdateDirs.append("updates");
|
||||
oldUpdateDirs.append("0");
|
||||
oldUpdateDirs.create(AUS_Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
||||
|
||||
// Get an array of all of the files we want to migrate.
|
||||
// We do this to create them in the old update directory.
|
||||
var filesToMigrate = [FILE_UPDATES_DB, FILE_UPDATE_ACTIVE,
|
||||
["updates", FILE_LAST_LOG], ["updates", FILE_BACKUP_LOG],
|
||||
["updates", "0", FILE_UPDATE_STATUS]];
|
||||
// Move each of those files to the new directory
|
||||
filesToMigrate.forEach(relPath => {
|
||||
let oldFile = oldUpdateRoot.clone();
|
||||
if (relPath instanceof Array) {
|
||||
relPath.forEach(relPathPart => {
|
||||
oldFile.append(relPathPart);
|
||||
});
|
||||
} else {
|
||||
oldFile.append(relPath);
|
||||
}
|
||||
oldFile.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
|
||||
});
|
||||
// Do the migration
|
||||
initUpdateServiceStub();
|
||||
do_test_finished();
|
||||
return;
|
||||
// Now verify that each of the files exist in the new update directory
|
||||
filesToMigrate.forEach(relPath => {
|
||||
let newFile = newUpdateRoot.clone();
|
||||
let oldFile = oldUpdateRoot.clone();
|
||||
if (relPath instanceof Array) {
|
||||
relPath.forEach(relPathPart => {
|
||||
newFile.append(relPathPart);
|
||||
oldFile.append(relPathPart);
|
||||
});
|
||||
} else {
|
||||
newFile.append(relPath);
|
||||
oldFile.append(relPath);
|
||||
}
|
||||
// The file should be mimgrated, except for FILE_UPDATE_STATUS
|
||||
// which gets consumed by post update after it is migrated..
|
||||
if (newFile.leafName != FILE_UPDATE_STATUS) {
|
||||
do_check_true(newFile.exists());
|
||||
}
|
||||
do_check_false(oldFile.exists());
|
||||
});
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
function end_test() {
|
||||
var appinfo = Components.classes["@mozilla.org/xre/app-info;1"].
|
||||
getService(Components.interfaces.nsIXULAppInfo).
|
||||
QueryInterface(Components.interfaces.nsIXULRuntime);
|
||||
var exeFile = FileUtils.getFile("XREExeF", []);
|
||||
clearTaskbarIDHash(exeFile.parent.path, appinfo.name);
|
||||
cleanUp();
|
||||
}
|
@ -26,3 +26,4 @@
|
||||
[test_0191_rmrfdirFileInUse_xp_win_partial.js]
|
||||
[test_0202_app_launch_apply_update_dirlocked.js]
|
||||
[test_0203_app_launch_apply_update.js]
|
||||
[test_0300_update_root_dir_migration.js]
|
||||
|
Loading…
Reference in New Issue
Block a user