зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1521664 - Add About Dialog test for the otherInstanceHandlingUpdates panel ID. r=mhowell
This commit is contained in:
Родитель
ffee6dccf3
Коммит
98486c6010
|
@ -1806,6 +1806,15 @@ UpdateService.prototype = {
|
|||
Cc["@mozilla.org/updates/update-checker;1"].
|
||||
createInstance(Ci.nsIUpdateChecker).stopCurrentCheck();
|
||||
break;
|
||||
case "test-close-handle-update-mutex":
|
||||
if (Cu.isInAutomation) {
|
||||
if (AppConstants.platform == "win" && gUpdateMutexHandle) {
|
||||
LOG("UpdateService:observe - closing mutex handle for testing");
|
||||
closeHandle(gUpdateMutexHandle);
|
||||
gUpdateMutexHandle = null;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@ skip-if = os != 'win'
|
|||
reason = test must be able to prevent file deletion.
|
||||
[browser_about_fc_check_malformedXML.js]
|
||||
[browser_about_fc_check_noUpdate.js]
|
||||
[browser_about_fc_check_otherInstance.js]
|
||||
skip-if = os != 'win'
|
||||
reason = Windows only feature.
|
||||
[browser_about_fc_check_unsupported.js]
|
||||
[browser_about_fc_downloadAuto.js]
|
||||
[browser_about_fc_downloadAuto_staging.js]
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Test for About Dialog foreground check for updates
|
||||
// with another application instance handling updates.
|
||||
add_task(async function aboutDialog_foregroundCheck_otherInstance() {
|
||||
setOtherInstanceHandlingUpdates();
|
||||
|
||||
let updateParams = "";
|
||||
await runAboutDialogUpdateTest(updateParams, false, [
|
||||
{
|
||||
panelId: "otherInstanceHandlingUpdates",
|
||||
checkActiveUpdate: null,
|
||||
continueFile: null,
|
||||
},
|
||||
]);
|
||||
});
|
|
@ -103,7 +103,7 @@ async function continueFileHandler(leafName) {
|
|||
* @throws If the function is called on a platform other than Windows.
|
||||
*/
|
||||
function lockWriteTestFile() {
|
||||
if (AppConstants.platform != "win") {
|
||||
if (!IS_WIN) {
|
||||
throw new Error("Windows only test function called");
|
||||
}
|
||||
let file = getUpdatesRootDir();
|
||||
|
@ -125,6 +125,17 @@ function lockWriteTestFile() {
|
|||
});
|
||||
}
|
||||
|
||||
function setOtherInstanceHandlingUpdates() {
|
||||
if (!IS_WIN) {
|
||||
throw new Error("Windows only test function called");
|
||||
}
|
||||
gAUS.observe(null, "test-close-handle-update-mutex", "");
|
||||
let handle = createMutex(getPerInstallationMutexName());
|
||||
registerCleanupFunction(() => {
|
||||
closeHandle(handle);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the update version info for the update url parameters to send to
|
||||
* app_update.sjs.
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "ctypes",
|
||||
"resource://gre/modules/ctypes.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "UpdateUtils",
|
||||
"resource://gre/modules/UpdateUtils.jsm");
|
||||
|
||||
|
@ -644,6 +646,90 @@ function getUpdateConfigFile() {
|
|||
return configFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unique mutex name for the installation.
|
||||
*
|
||||
* @return Global mutex path.
|
||||
* @throws If the function is called on a platform other than Windows.
|
||||
*/
|
||||
function getPerInstallationMutexName() {
|
||||
if (!IS_WIN) {
|
||||
throw new Error("Windows only function called by a different platform!");
|
||||
}
|
||||
|
||||
let hasher = Cc["@mozilla.org/security/hash;1"].
|
||||
createInstance(Ci.nsICryptoHash);
|
||||
hasher.init(hasher.SHA1);
|
||||
|
||||
let exeFile = Services.dirsvc.get(XRE_EXECUTABLE_FILE, Ci.nsIFile);
|
||||
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
|
||||
createInstance(Ci.nsIScriptableUnicodeConverter);
|
||||
converter.charset = "UTF-8";
|
||||
let data = converter.convertToByteArray(exeFile.path.toLowerCase());
|
||||
|
||||
hasher.update(data, data.length);
|
||||
return "Global\\MozillaUpdateMutex-" + hasher.finish(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a Win32 handle.
|
||||
*
|
||||
* @param aHandle
|
||||
* The handle to close.
|
||||
* @throws If the function is called on a platform other than Windows.
|
||||
*/
|
||||
function closeHandle(aHandle) {
|
||||
if (!IS_WIN) {
|
||||
throw new Error("Windows only function called by a different platform!");
|
||||
}
|
||||
|
||||
let lib = ctypes.open("kernel32.dll");
|
||||
let CloseHandle = lib.declare("CloseHandle",
|
||||
ctypes.winapi_abi,
|
||||
ctypes.int32_t, /* success */
|
||||
ctypes.void_t.ptr); /* handle */
|
||||
CloseHandle(aHandle);
|
||||
lib.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a mutex.
|
||||
*
|
||||
* @param aName
|
||||
* The name for the mutex.
|
||||
* @return The Win32 handle to the mutex.
|
||||
* @throws If the function is called on a platform other than Windows.
|
||||
*/
|
||||
function createMutex(aName) {
|
||||
if (!IS_WIN) {
|
||||
throw new Error("Windows only function called by a different platform!");
|
||||
}
|
||||
|
||||
const INITIAL_OWN = 1;
|
||||
const ERROR_ALREADY_EXISTS = 0xB7;
|
||||
let lib = ctypes.open("kernel32.dll");
|
||||
let CreateMutexW = lib.declare("CreateMutexW",
|
||||
ctypes.winapi_abi,
|
||||
ctypes.void_t.ptr, /* return handle */
|
||||
ctypes.void_t.ptr, /* security attributes */
|
||||
ctypes.int32_t, /* initial owner */
|
||||
ctypes.char16_t.ptr); /* name */
|
||||
|
||||
let handle = CreateMutexW(null, INITIAL_OWN, aName);
|
||||
lib.close();
|
||||
let alreadyExists = ctypes.winLastError == ERROR_ALREADY_EXISTS;
|
||||
if (handle && !handle.isNull() && alreadyExists) {
|
||||
closeHandle(handle);
|
||||
handle = null;
|
||||
}
|
||||
|
||||
if (handle && handle.isNull()) {
|
||||
handle = null;
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs TEST-INFO messages.
|
||||
*
|
||||
|
|
|
@ -204,8 +204,6 @@ const DATA_URI_SPEC = Services.io.newFileURI(do_get_file("../data", false)).spec
|
|||
/* import-globals-from ../data/shared.js */
|
||||
Services.scriptloader.loadSubScript(DATA_URI_SPEC + "shared.js", this);
|
||||
|
||||
ChromeUtils.defineModuleGetter(this, "ctypes",
|
||||
"resource://gre/modules/ctypes.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "MockRegistrar",
|
||||
"resource://testing-common/MockRegistrar.jsm");
|
||||
|
||||
|
|
|
@ -52,85 +52,3 @@ function run_test() {
|
|||
|
||||
doTestFinish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines a unique mutex name for the installation.
|
||||
*
|
||||
* @return Global mutex path.
|
||||
*/
|
||||
function getPerInstallationMutexName() {
|
||||
if (!IS_WIN) {
|
||||
do_throw("Windows only function called by a different platform!");
|
||||
}
|
||||
|
||||
let hasher = Cc["@mozilla.org/security/hash;1"].
|
||||
createInstance(Ci.nsICryptoHash);
|
||||
hasher.init(hasher.SHA1);
|
||||
|
||||
let exeFile = Services.dirsvc.get(XRE_EXECUTABLE_FILE, Ci.nsIFile);
|
||||
|
||||
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
|
||||
createInstance(Ci.nsIScriptableUnicodeConverter);
|
||||
converter.charset = "UTF-8";
|
||||
let data = converter.convertToByteArray(exeFile.path.toLowerCase());
|
||||
|
||||
hasher.update(data, data.length);
|
||||
return "Global\\MozillaUpdateMutex-" + hasher.finish(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a Win32 handle.
|
||||
*
|
||||
* @param aHandle
|
||||
* The handle to close.
|
||||
*/
|
||||
function closeHandle(aHandle) {
|
||||
if (!IS_WIN) {
|
||||
do_throw("Windows only function called by a different platform!");
|
||||
}
|
||||
|
||||
let lib = ctypes.open("kernel32.dll");
|
||||
let CloseHandle = lib.declare("CloseHandle",
|
||||
ctypes.winapi_abi,
|
||||
ctypes.int32_t, /* success */
|
||||
ctypes.void_t.ptr); /* handle */
|
||||
CloseHandle(aHandle);
|
||||
lib.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a mutex.
|
||||
*
|
||||
* @param aName
|
||||
* The name for the mutex.
|
||||
* @return The Win32 handle to the mutex.
|
||||
*/
|
||||
function createMutex(aName) {
|
||||
if (!IS_WIN) {
|
||||
do_throw("Windows only function called by a different platform!");
|
||||
}
|
||||
|
||||
const INITIAL_OWN = 1;
|
||||
const ERROR_ALREADY_EXISTS = 0xB7;
|
||||
let lib = ctypes.open("kernel32.dll");
|
||||
let CreateMutexW = lib.declare("CreateMutexW",
|
||||
ctypes.winapi_abi,
|
||||
ctypes.void_t.ptr, /* return handle */
|
||||
ctypes.void_t.ptr, /* security attributes */
|
||||
ctypes.int32_t, /* initial owner */
|
||||
ctypes.char16_t.ptr); /* name */
|
||||
|
||||
let handle = CreateMutexW(null, INITIAL_OWN, aName);
|
||||
lib.close();
|
||||
let alreadyExists = ctypes.winLastError == ERROR_ALREADY_EXISTS;
|
||||
if (handle && !handle.isNull() && alreadyExists) {
|
||||
closeHandle(handle);
|
||||
handle = null;
|
||||
}
|
||||
|
||||
if (handle && handle.isNull()) {
|
||||
handle = null;
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче