summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/update/tests/unit_service_updater
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/mozapps/update/tests/unit_service_updater')
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/bootstrapSvc.js23
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/checkUpdaterSigSvc.js53
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/fallbackOnSvcFailure.js38
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/head_update.js7
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTooLongFailureSvc.js53
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTraversalFailureSvc.js50
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallWorkingDirPathNotSameFailureSvc_win.js45
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/invalidArgPatchDirPathSuffixFailureSvc.js27
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/invalidArgPatchDirPathTraversalFailureSvc.js32
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/invalidArgStageDirNotInInstallDirFailureSvc_win.js45
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathLocalUNCFailureSvc_win.js45
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathRelativeFailureSvc.js44
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marAppApplyDirLockedStageFailureSvc_win.js29
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateAppBinInUseStageSuccessSvc_win.js50
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateStageSuccessSvc.js49
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateSuccessSvc.js47
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marAppInUseBackgroundTaskFailureSvc_win.js51
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marAppInUseStageFailureCompleteSvc_win.js37
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marAppInUseSuccessCompleteSvc.js26
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppStageSuccessCompleteSvc_win.js30
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppStageSuccessPartialSvc_win.js30
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppSuccessCompleteSvc_win.js24
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppSuccessPartialSvc_win.js24
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marFailurePartialSvc.js39
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marFileInUseStageFailureCompleteSvc_win.js40
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marFileInUseStageFailurePartialSvc_win.js40
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marFileInUseSuccessCompleteSvc_win.js29
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marFileInUseSuccessPartialSvc_win.js29
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marFileLockedFailureCompleteSvc_win.js27
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marFileLockedFailurePartialSvc_win.js26
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marFileLockedStageFailureCompleteSvc_win.js34
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marFileLockedStageFailurePartialSvc_win.js33
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseStageFailureCompleteSvc_win.js43
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseStageFailurePartialSvc_win.js41
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseSuccessCompleteSvc_win.js31
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseSuccessPartialSvc_win.js29
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marStageFailurePartialSvc.js31
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marStageSuccessCompleteSvc.js71
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marStageSuccessPartialSvc.js35
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marSuccessCompleteSvc.js26
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/marSuccessPartialSvc.js29
-rw-r--r--toolkit/mozapps/update/tests/unit_service_updater/xpcshell.toml134
42 files changed, 1626 insertions, 0 deletions
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/bootstrapSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/bootstrapSvc.js
new file mode 100644
index 0000000000..57eb630248
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/bootstrapSvc.js
@@ -0,0 +1,23 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* Bootstrap the tests using the service by installing our own version of the service */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ // We don't actually care if the MAR has any data, we only care about the
+ // application return code and update.status result.
+ gTestFiles = gTestFilesCommon;
+ gTestDirs = [];
+ await setupUpdaterTest(FILE_COMPLETE_MAR, null);
+ runUpdate(STATE_SUCCEEDED, false, 0, true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile, false, false);
+
+ // We need to check the service log even though this is a bootstrap
+ // because the app bin could be in use by this test by the time the next
+ // test runs.
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/checkUpdaterSigSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/checkUpdaterSigSvc.js
new file mode 100644
index 0000000000..d6e1753f35
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/checkUpdaterSigSvc.js
@@ -0,0 +1,53 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/**
+ * We skip authenticode cert checks from the service udpates
+ * so that we can use updater-xpcshell with the wrong certs for testing.
+ * This tests that code path. */
+
+function run_test() {
+ if (!IS_AUTHENTICODE_CHECK_ENABLED) {
+ return;
+ }
+
+ let binDir = getGREBinDir();
+ let maintenanceServiceBin = binDir.clone();
+ maintenanceServiceBin.append(FILE_MAINTENANCE_SERVICE_BIN);
+
+ let updaterBin = binDir.clone();
+ updaterBin.append(FILE_UPDATER_BIN);
+
+ debugDump(
+ "Launching maintenance service bin: " +
+ maintenanceServiceBin.path +
+ " to check updater: " +
+ updaterBin.path +
+ " signature."
+ );
+
+ // Bypass the manifest and run as invoker
+ Services.env.set("__COMPAT_LAYER", "RunAsInvoker");
+
+ let dummyInstallPath = "---";
+ let maintenanceServiceBinArgs = [
+ "check-cert",
+ dummyInstallPath,
+ updaterBin.path,
+ ];
+ let maintenanceServiceBinProcess = Cc[
+ "@mozilla.org/process/util;1"
+ ].createInstance(Ci.nsIProcess);
+ maintenanceServiceBinProcess.init(maintenanceServiceBin);
+ maintenanceServiceBinProcess.run(
+ true,
+ maintenanceServiceBinArgs,
+ maintenanceServiceBinArgs.length
+ );
+ Assert.equal(
+ maintenanceServiceBinProcess.exitValue,
+ 0,
+ "the maintenance service exit value should be 0"
+ );
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/fallbackOnSvcFailure.js b/toolkit/mozapps/update/tests/unit_service_updater/fallbackOnSvcFailure.js
new file mode 100644
index 0000000000..d09ea7b448
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/fallbackOnSvcFailure.js
@@ -0,0 +1,38 @@
+/* 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/.
+ */
+
+/**
+ * If updating with the maintenance service fails in a way specific to the
+ * maintenance service, we should fall back to not using the maintenance
+ * service, which should succeed. This test ensures that that happens as
+ * expected.
+ */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ // This variable forces the service to fail by having the updater pass it the
+ // wrong number of arguments. Then we can verify that the fallback happens
+ // properly.
+ gEnvForceServiceFallback = true;
+
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ preventDistributionFiles();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, true);
+ // It's very important that we pass in true for aCheckSvcLog (4th param),
+ // because otherwise we may not have used the service at all, so we wouldn't
+ // really check that we fell back (to not using the service) properly.
+ runUpdate(STATE_SUCCEEDED, false, 0, true);
+ await checkPostUpdateAppLog();
+ checkAppBundleModTime();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/head_update.js b/toolkit/mozapps/update/tests/unit_service_updater/head_update.js
new file mode 100644
index 0000000000..8d30c09e4f
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/head_update.js
@@ -0,0 +1,7 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* import-globals-from ../data/xpcshellUtilsAUS.js */
+load("xpcshellUtilsAUS.js");
+gIsServiceTest = true;
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTooLongFailureSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTooLongFailureSvc.js
new file mode 100644
index 0000000000..c2746e2bd1
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTooLongFailureSvc.js
@@ -0,0 +1,53 @@
+/* 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/.
+ */
+
+/* Too long install directory path failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_FAILED_SERVICE_INVALID_INSTALL_DIR_PATH_ERROR
+ : STATE_FAILED_INVALID_INSTALL_DIR_PATH_ERROR;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ let path = "123456789";
+ if (AppConstants.platform == "win") {
+ path = "\\" + path;
+ path = path.repeat(30); // 300 characters
+ path = "C:" + path;
+ } else {
+ path = "/" + path;
+ path = path.repeat(1000); // 10000 characters
+ }
+ runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, path, null, null);
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ await waitForUpdateXMLFiles();
+ if (gIsServiceTest) {
+ // The invalid argument service tests launch the maintenance service
+ // directly so the unelevated updater doesn't handle the invalid argument.
+ // By doing this it is possible to test that the maintenance service
+ // properly handles the invalid argument but since the updater isn't used to
+ // launch the maintenance service the update.status file isn't copied from
+ // the secure log directory to the patch directory and the update manager
+ // won't read the failure from the update.status file.
+ checkUpdateManager(STATE_NONE, false, STATE_PENDING_SVC, 0, 1);
+ } else {
+ checkUpdateManager(
+ STATE_NONE,
+ false,
+ STATE_FAILED,
+ INVALID_INSTALL_DIR_PATH_ERROR,
+ 1
+ );
+ }
+
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTraversalFailureSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTraversalFailureSvc.js
new file mode 100644
index 0000000000..b611fac972
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTraversalFailureSvc.js
@@ -0,0 +1,50 @@
+/* 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/.
+ */
+
+/* Install directory path traversal failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_FAILED_SERVICE_INVALID_INSTALL_DIR_PATH_ERROR
+ : STATE_FAILED_INVALID_INSTALL_DIR_PATH_ERROR;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ let path = "123456789";
+ if (AppConstants.platform == "win") {
+ path = "C:\\" + path + "\\..\\" + path;
+ } else {
+ path = "/" + path + "/../" + path;
+ }
+ runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, path, null, null);
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ await waitForUpdateXMLFiles();
+ if (gIsServiceTest) {
+ // The invalid argument service tests launch the maintenance service
+ // directly so the unelevated updater doesn't handle the invalid argument.
+ // By doing this it is possible to test that the maintenance service
+ // properly handles the invalid argument but since the updater isn't used to
+ // launch the maintenance service the update.status file isn't copied from
+ // the secure log directory to the patch directory and the update manager
+ // won't read the failure from the update.status file.
+ checkUpdateManager(STATE_NONE, false, STATE_PENDING_SVC, 0, 1);
+ } else {
+ checkUpdateManager(
+ STATE_NONE,
+ false,
+ STATE_FAILED,
+ INVALID_INSTALL_DIR_PATH_ERROR,
+ 1
+ );
+ }
+
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallWorkingDirPathNotSameFailureSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallWorkingDirPathNotSameFailureSvc_win.js
new file mode 100644
index 0000000000..0506d100fd
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallWorkingDirPathNotSameFailureSvc_win.js
@@ -0,0 +1,45 @@
+/* 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/.
+ */
+
+/* Different install and working directories for a regular update failure */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_FAILED_SERVICE_INVALID_APPLYTO_DIR_ERROR
+ : STATE_FAILED_INVALID_APPLYTO_DIR_ERROR;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ let path = getApplyDirFile("..", false).path;
+ runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, path, null);
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ await waitForUpdateXMLFiles();
+ if (gIsServiceTest) {
+ // The invalid argument service tests launch the maintenance service
+ // directly so the unelevated updater doesn't handle the invalid argument.
+ // By doing this it is possible to test that the maintenance service
+ // properly handles the invalid argument but since the updater isn't used to
+ // launch the maintenance service the update.status file isn't copied from
+ // the secure log directory to the patch directory and the update manager
+ // won't read the failure from the update.status file.
+ checkUpdateManager(STATE_NONE, false, STATE_PENDING_SVC, 0, 1);
+ } else {
+ checkUpdateManager(
+ STATE_NONE,
+ false,
+ STATE_FAILED,
+ INVALID_APPLYTO_DIR_ERROR,
+ 1
+ );
+ }
+
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgPatchDirPathSuffixFailureSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgPatchDirPathSuffixFailureSvc.js
new file mode 100644
index 0000000000..3eb792ecb4
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgPatchDirPathSuffixFailureSvc.js
@@ -0,0 +1,27 @@
+/* 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/.
+ */
+
+/* Patch directory path must end with \updates\0 failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_PENDING_SVC
+ : STATE_PENDING;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ let path = getUpdateDirFile(DIR_PATCH).parent.path;
+ runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, path, null, null, null);
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_AFTER_RUNUPDATE, 0, 1);
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgPatchDirPathTraversalFailureSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgPatchDirPathTraversalFailureSvc.js
new file mode 100644
index 0000000000..cf053e3ff5
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgPatchDirPathTraversalFailureSvc.js
@@ -0,0 +1,32 @@
+/* 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/.
+ */
+
+/* Patch directory path traversal failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_PENDING_SVC
+ : STATE_PENDING;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ let path = getUpdateDirFile(DIR_PATCH);
+ if (AppConstants.platform == "win") {
+ path = path + "\\..\\";
+ } else {
+ path = path + "/../";
+ }
+ runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, path, null, null, null);
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_AFTER_RUNUPDATE, 0, 1);
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgStageDirNotInInstallDirFailureSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgStageDirNotInInstallDirFailureSvc_win.js
new file mode 100644
index 0000000000..4624179bfd
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgStageDirNotInInstallDirFailureSvc_win.js
@@ -0,0 +1,45 @@
+/* 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/.
+ */
+
+/* Different install and working directories for a regular update failure */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_FAILED_SERVICE_INVALID_APPLYTO_DIR_STAGED_ERROR
+ : STATE_FAILED_INVALID_APPLYTO_DIR_STAGED_ERROR;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ let path = getApplyDirFile("..", false).path;
+ runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true, null, null, path, null);
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ await waitForUpdateXMLFiles();
+ if (gIsServiceTest) {
+ // The invalid argument service tests launch the maintenance service
+ // directly so the unelevated updater doesn't handle the invalid argument.
+ // By doing this it is possible to test that the maintenance service
+ // properly handles the invalid argument but since the updater isn't used to
+ // launch the maintenance service the update.status file isn't copied from
+ // the secure log directory to the patch directory and the update manager
+ // won't read the failure from the update.status file.
+ checkUpdateManager(STATE_NONE, false, STATE_PENDING_SVC, 0, 1);
+ } else {
+ checkUpdateManager(
+ STATE_NONE,
+ false,
+ STATE_FAILED,
+ INVALID_APPLYTO_DIR_STAGED_ERROR,
+ 1
+ );
+ }
+
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathLocalUNCFailureSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathLocalUNCFailureSvc_win.js
new file mode 100644
index 0000000000..7c0af26e37
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathLocalUNCFailureSvc_win.js
@@ -0,0 +1,45 @@
+/* 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/.
+ */
+
+/* Working directory path local UNC failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_FAILED_SERVICE_INVALID_WORKING_DIR_PATH_ERROR
+ : STATE_FAILED_INVALID_WORKING_DIR_PATH_ERROR;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ let path = "\\\\.\\" + getApplyDirFile(null, false).path;
+ runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, path, null);
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ await waitForUpdateXMLFiles();
+ if (gIsServiceTest) {
+ // The invalid argument service tests launch the maintenance service
+ // directly so the unelevated updater doesn't handle the invalid argument.
+ // By doing this it is possible to test that the maintenance service
+ // properly handles the invalid argument but since the updater isn't used to
+ // launch the maintenance service the update.status file isn't copied from
+ // the secure log directory to the patch directory and the update manager
+ // won't read the failure from the update.status file.
+ checkUpdateManager(STATE_NONE, false, STATE_PENDING_SVC, 0, 1);
+ } else {
+ checkUpdateManager(
+ STATE_NONE,
+ false,
+ STATE_FAILED,
+ INVALID_WORKING_DIR_PATH_ERROR,
+ 1
+ );
+ }
+
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathRelativeFailureSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathRelativeFailureSvc.js
new file mode 100644
index 0000000000..cfbd9eaec9
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathRelativeFailureSvc.js
@@ -0,0 +1,44 @@
+/* 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/.
+ */
+
+/* Relative working directory path failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_FAILED_SERVICE_INVALID_WORKING_DIR_PATH_ERROR
+ : STATE_FAILED_INVALID_WORKING_DIR_PATH_ERROR;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, "test", null);
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ await waitForUpdateXMLFiles();
+ if (gIsServiceTest) {
+ // The invalid argument service tests launch the maintenance service
+ // directly so the unelevated updater doesn't handle the invalid argument.
+ // By doing this it is possible to test that the maintenance service
+ // properly handles the invalid argument but since the updater isn't used to
+ // launch the maintenance service the update.status file isn't copied from
+ // the secure log directory to the patch directory and the update manager
+ // won't read the failure from the update.status file.
+ checkUpdateManager(STATE_NONE, false, STATE_PENDING_SVC, 0, 1);
+ } else {
+ checkUpdateManager(
+ STATE_NONE,
+ false,
+ STATE_FAILED,
+ INVALID_WORKING_DIR_PATH_ERROR,
+ 1
+ );
+ }
+
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyDirLockedStageFailureSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyDirLockedStageFailureSvc_win.js
new file mode 100644
index 0000000000..9280a0736e
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyDirLockedStageFailureSvc_win.js
@@ -0,0 +1,29 @@
+/* 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 to
+ * apply it.
+ */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = STATE_PENDING_SVC;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setTestFilesAndDirsForFailure();
+ createUpdateInProgressLockFile(getGREBinDir());
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await stageUpdate(STATE_AFTER_STAGE, false);
+ removeUpdateInProgressLockFile(getGREBinDir());
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContains(PERFORMING_STAGED_UPDATE);
+ checkUpdateLogContains(ERR_UPDATE_IN_PROGRESS);
+ await waitForUpdateXMLFiles(true, false);
+ checkUpdateManager(STATE_AFTER_STAGE, true, STATE_AFTER_STAGE, 0, 0);
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateAppBinInUseStageSuccessSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateAppBinInUseStageSuccessSvc_win.js
new file mode 100644
index 0000000000..319aee8e34
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateAppBinInUseStageSuccessSvc_win.js
@@ -0,0 +1,50 @@
+/* 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 to
+ * apply it.
+ */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = gIsServiceTest ? STATE_APPLIED_SVC : STATE_APPLIED;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getStageDirFile, true, false);
+ checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
+ lockDirectory(getGREBinDir().path);
+ // Switch the application to the staged application that was updated.
+ await runUpdateUsingApp(STATE_SUCCEEDED);
+ await checkPostUpdateAppLog();
+ checkAppBundleModTime();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile);
+ checkUpdateLogContents(LOG_COMPLETE_SUCCESS);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+
+ let updatesDir = getUpdateDirFile(DIR_PATCH);
+ Assert.ok(
+ updatesDir.exists(),
+ MSG_SHOULD_EXIST + getMsgPath(updatesDir.path)
+ );
+
+ let log = getUpdateDirFile(FILE_UPDATE_LOG);
+ Assert.ok(!log.exists(), MSG_SHOULD_NOT_EXIST + getMsgPath(log.path));
+
+ log = getUpdateDirFile(FILE_LAST_UPDATE_LOG);
+ Assert.ok(log.exists(), MSG_SHOULD_EXIST + getMsgPath(log.path));
+
+ log = getUpdateDirFile(FILE_BACKUP_UPDATE_LOG);
+ Assert.ok(log.exists(), MSG_SHOULD_EXIST + getMsgPath(log.path));
+
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateStageSuccessSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateStageSuccessSvc.js
new file mode 100644
index 0000000000..34b47866b1
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateStageSuccessSvc.js
@@ -0,0 +1,49 @@
+/* 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 to
+ * apply it.
+ */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = gIsServiceTest ? STATE_APPLIED_SVC : STATE_APPLIED;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ await setupUpdaterTest(FILE_COMPLETE_MAR, true);
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getStageDirFile, true);
+ checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
+ // Switch the application to the staged application that was updated.
+ await runUpdateUsingApp(STATE_SUCCEEDED);
+ await checkPostUpdateAppLog();
+ checkAppBundleModTime();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile, false, true);
+ checkUpdateLogContents(LOG_REPLACE_SUCCESS, false, true);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+
+ let updatesDir = getUpdateDirFile(DIR_PATCH);
+ Assert.ok(
+ updatesDir.exists(),
+ MSG_SHOULD_EXIST + getMsgPath(updatesDir.path)
+ );
+
+ let log = getUpdateDirFile(FILE_UPDATE_LOG);
+ Assert.ok(!log.exists(), MSG_SHOULD_NOT_EXIST + getMsgPath(log.path));
+
+ log = getUpdateDirFile(FILE_LAST_UPDATE_LOG);
+ Assert.ok(log.exists(), MSG_SHOULD_EXIST + getMsgPath(log.path));
+
+ log = getUpdateDirFile(FILE_BACKUP_UPDATE_LOG);
+ Assert.ok(log.exists(), MSG_SHOULD_EXIST + getMsgPath(log.path));
+
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateSuccessSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateSuccessSvc.js
new file mode 100644
index 0000000000..980b0cb89a
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateSuccessSvc.js
@@ -0,0 +1,47 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/**
+ * Test applying an update by launching an application to apply it.
+ */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ // The third parameter will test that a full path to the post update binary
+ // doesn't execute.
+ await setupUpdaterTest(
+ FILE_COMPLETE_MAR,
+ undefined,
+ getApplyDirFile(null, true).path + "/"
+ );
+ await runUpdateUsingApp(STATE_SUCCEEDED);
+ checkAppBundleModTime();
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getApplyDirFile);
+ checkUpdateLogContents(LOG_COMPLETE_SUCCESS);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+
+ let updatesDir = getUpdateDirFile(DIR_PATCH);
+ Assert.ok(
+ updatesDir.exists(),
+ MSG_SHOULD_EXIST + getMsgPath(updatesDir.path)
+ );
+
+ let log = getUpdateDirFile(FILE_UPDATE_LOG);
+ Assert.ok(!log.exists(), MSG_SHOULD_NOT_EXIST + getMsgPath(log.path));
+
+ log = getUpdateDirFile(FILE_LAST_UPDATE_LOG);
+ Assert.ok(log.exists(), MSG_SHOULD_EXIST + getMsgPath(log.path));
+
+ log = getUpdateDirFile(FILE_BACKUP_UPDATE_LOG);
+ Assert.ok(!log.exists(), MSG_SHOULD_NOT_EXIST + getMsgPath(log.path));
+
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseBackgroundTaskFailureSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseBackgroundTaskFailureSvc_win.js
new file mode 100644
index 0000000000..bcb24bee94
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseBackgroundTaskFailureSvc_win.js
@@ -0,0 +1,51 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* Fail to apply a complete MAR when the application is in use and the callback is a background task. */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setTestFilesAndDirsForFailure();
+
+ // Add a dummy --backgroundtask arg; this will have no effect on the
+ // callback (TestAUSHelper) but will cause the updater to detect
+ // that this is a background task.
+ gCallbackArgs = gCallbackArgs.concat(["--backgroundtask", "not_found"]);
+
+ // Run the update with the helper file in use, expecting failure.
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await runHelperFileInUse(DIR_RESOURCES + gCallbackBinFile, false);
+ runUpdate(
+ STATE_FAILED_WRITE_ERROR_BACKGROUND_TASK_SHARING_VIOLATION,
+ false, // aSwitchApp
+ 1, // aExpectedExitValue
+ true // aCheckSvcLog
+ );
+ await waitForHelperExit();
+
+ standardInit();
+
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContains(ERR_BGTASK_EXCLUSIVE);
+
+ // Check that the update was reset to "pending".
+ await waitForUpdateXMLFiles(
+ true, // aActiveUpdateExists
+ false // aUpdatesExists
+ );
+ checkUpdateManager(
+ STATE_PENDING, // aStatusFileState
+ true, // aHasActiveUpdate
+ STATE_PENDING, // aUpdateStatusState
+ WRITE_ERROR_BACKGROUND_TASK_SHARING_VIOLATION,
+ 0 // aUpdateCount
+ );
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseStageFailureCompleteSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseStageFailureCompleteSvc_win.js
new file mode 100644
index 0000000000..502561ed1e
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseStageFailureCompleteSvc_win.js
@@ -0,0 +1,37 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* Application in use complete MAR file staged patch apply failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = gIsServiceTest ? STATE_APPLIED_SVC : STATE_APPLIED;
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_PENDING_SVC
+ : STATE_PENDING;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await runHelperFileInUse(DIR_RESOURCES + gCallbackBinFile, false);
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getStageDirFile, true);
+ checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
+ // Switch the application to the staged application that was updated.
+ runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
+ await waitForHelperExit();
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ setTestFilesAndDirsForFailure();
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContains(ERR_RENAME_FILE);
+ checkUpdateLogContains(
+ ERR_MOVE_DESTDIR_7 + "\n" + STATE_FAILED_WRITE_ERROR + "\n" + CALL_QUIT
+ );
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_AFTER_RUNUPDATE, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseSuccessCompleteSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseSuccessCompleteSvc.js
new file mode 100644
index 0000000000..e08777d042
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseSuccessCompleteSvc.js
@@ -0,0 +1,26 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* Application in use complete MAR file patch apply success test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await runHelperFileInUse(DIR_RESOURCES + gCallbackBinFile, false);
+ runUpdate(STATE_SUCCEEDED, false, 0, true);
+ await waitForHelperExit();
+ await checkPostUpdateAppLog();
+ checkAppBundleModTime();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile);
+ checkUpdateLogContents(LOG_COMPLETE_SUCCESS);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppStageSuccessCompleteSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppStageSuccessCompleteSvc_win.js
new file mode 100644
index 0000000000..2f8155c790
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppStageSuccessCompleteSvc_win.js
@@ -0,0 +1,30 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* Replace app binary complete MAR file staged patch apply success test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = gIsServiceTest ? STATE_APPLIED_SVC : STATE_APPLIED;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ gCallbackBinFile = "exe0.exe";
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getStageDirFile, true);
+ checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
+ // Switch the application to the staged application that was updated.
+ runUpdate(STATE_SUCCEEDED, true, 0, true);
+ await checkPostUpdateAppLog();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile, false, true);
+ checkUpdateLogContents(LOG_REPLACE_SUCCESS, false, true);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppStageSuccessPartialSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppStageSuccessPartialSvc_win.js
new file mode 100644
index 0000000000..04c72896b4
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppStageSuccessPartialSvc_win.js
@@ -0,0 +1,30 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* Patch app binary partial MAR file staged patch apply success test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = gIsServiceTest ? STATE_APPLIED_SVC : STATE_APPLIED;
+ gTestFiles = gTestFilesPartialSuccess;
+ gTestDirs = gTestDirsPartialSuccess;
+ gCallbackBinFile = "exe0.exe";
+ await setupUpdaterTest(FILE_PARTIAL_MAR, false);
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getStageDirFile, true);
+ checkUpdateLogContents(LOG_PARTIAL_SUCCESS, true);
+ // Switch the application to the staged application that was updated.
+ runUpdate(STATE_SUCCEEDED, true, 0, true);
+ await checkPostUpdateAppLog();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile, false, true);
+ checkUpdateLogContents(LOG_REPLACE_SUCCESS, false, true);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppSuccessCompleteSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppSuccessCompleteSvc_win.js
new file mode 100644
index 0000000000..fa13f07f46
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppSuccessCompleteSvc_win.js
@@ -0,0 +1,24 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* Replace app binary complete MAR file patch apply success test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ gCallbackBinFile = "exe0.exe";
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ runUpdate(STATE_SUCCEEDED, false, 0, true);
+ await checkPostUpdateAppLog();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile);
+ checkUpdateLogContents(LOG_COMPLETE_SUCCESS);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppSuccessPartialSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppSuccessPartialSvc_win.js
new file mode 100644
index 0000000000..e74509c06e
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marCallbackAppSuccessPartialSvc_win.js
@@ -0,0 +1,24 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* Patch app binary partial MAR file patch apply success test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesPartialSuccess;
+ gTestDirs = gTestDirsPartialSuccess;
+ gCallbackBinFile = "exe0.exe";
+ await setupUpdaterTest(FILE_PARTIAL_MAR, false);
+ runUpdate(STATE_SUCCEEDED, false, 0, true);
+ await checkPostUpdateAppLog();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile);
+ checkUpdateLogContents(LOG_PARTIAL_SUCCESS);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marFailurePartialSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/marFailurePartialSvc.js
new file mode 100644
index 0000000000..de8db067bc
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marFailurePartialSvc.js
@@ -0,0 +1,39 @@
+/* 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/.
+ */
+
+/* General Partial MAR File Patch Apply Failure Test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesPartialSuccess;
+ gTestFiles[11].originalFile = "partial.png";
+ gTestDirs = gTestDirsPartialSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_PARTIAL_MAR, false);
+ // If execv is used the updater process will turn into the callback process
+ // and the updater's return code will be that of the callback process.
+ runUpdate(
+ STATE_FAILED_LOADSOURCE_ERROR_WRONG_SIZE,
+ false,
+ USE_EXECV ? 0 : 1,
+ true
+ );
+ checkAppBundleModTime();
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContents(LOG_PARTIAL_FAILURE);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(
+ STATE_NONE,
+ false,
+ STATE_FAILED,
+ LOADSOURCE_ERROR_WRONG_SIZE,
+ 1
+ );
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marFileInUseStageFailureCompleteSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marFileInUseStageFailureCompleteSvc_win.js
new file mode 100644
index 0000000000..b93b023934
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marFileInUseStageFailureCompleteSvc_win.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* File in use complete MAR file staged patch apply failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = gIsServiceTest ? STATE_APPLIED_SVC : STATE_APPLIED;
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_PENDING_SVC
+ : STATE_PENDING;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await runHelperFileInUse(
+ gTestFiles[13].relPathDir + gTestFiles[13].fileName,
+ false
+ );
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getStageDirFile, true);
+ checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
+ // Switch the application to the staged application that was updated.
+ runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
+ await waitForHelperExit();
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ setTestFilesAndDirsForFailure();
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContains(ERR_RENAME_FILE);
+ checkUpdateLogContains(
+ ERR_MOVE_DESTDIR_7 + "\n" + STATE_FAILED_WRITE_ERROR + "\n" + CALL_QUIT
+ );
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_AFTER_RUNUPDATE, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marFileInUseStageFailurePartialSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marFileInUseStageFailurePartialSvc_win.js
new file mode 100644
index 0000000000..b41da12396
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marFileInUseStageFailurePartialSvc_win.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* File in use partial MAR file staged patch apply failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = gIsServiceTest ? STATE_APPLIED_SVC : STATE_APPLIED;
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_PENDING_SVC
+ : STATE_PENDING;
+ gTestFiles = gTestFilesPartialSuccess;
+ gTestDirs = gTestDirsPartialSuccess;
+ await setupUpdaterTest(FILE_PARTIAL_MAR, false);
+ await runHelperFileInUse(
+ gTestFiles[11].relPathDir + gTestFiles[11].fileName,
+ false
+ );
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getStageDirFile, true);
+ checkUpdateLogContents(LOG_PARTIAL_SUCCESS, true);
+ // Switch the application to the staged application that was updated.
+ runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
+ await waitForHelperExit();
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ setTestFilesAndDirsForFailure();
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContains(ERR_RENAME_FILE);
+ checkUpdateLogContains(
+ ERR_MOVE_DESTDIR_7 + "\n" + STATE_FAILED_WRITE_ERROR + "\n" + CALL_QUIT
+ );
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_AFTER_RUNUPDATE, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marFileInUseSuccessCompleteSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marFileInUseSuccessCompleteSvc_win.js
new file mode 100644
index 0000000000..4b946ac3e4
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marFileInUseSuccessCompleteSvc_win.js
@@ -0,0 +1,29 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* File in use complete MAR file patch apply success test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await runHelperFileInUse(
+ gTestFiles[13].relPathDir + gTestFiles[13].fileName,
+ false
+ );
+ runUpdate(STATE_SUCCEEDED, false, 0, true);
+ await waitForHelperExit();
+ await checkPostUpdateAppLog();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile, false, true);
+ checkUpdateLogContains(ERR_BACKUP_DISCARD);
+ checkUpdateLogContains(STATE_SUCCEEDED + "\n" + CALL_QUIT);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marFileInUseSuccessPartialSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marFileInUseSuccessPartialSvc_win.js
new file mode 100644
index 0000000000..15c3a1121a
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marFileInUseSuccessPartialSvc_win.js
@@ -0,0 +1,29 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* File in use partial MAR file patch apply success test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesPartialSuccess;
+ gTestDirs = gTestDirsPartialSuccess;
+ await setupUpdaterTest(FILE_PARTIAL_MAR, false);
+ await runHelperFileInUse(
+ gTestFiles[11].relPathDir + gTestFiles[11].fileName,
+ false
+ );
+ runUpdate(STATE_SUCCEEDED, false, 0, true);
+ await waitForHelperExit();
+ await checkPostUpdateAppLog();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile, false, true);
+ checkUpdateLogContains(ERR_BACKUP_DISCARD);
+ checkUpdateLogContains(STATE_SUCCEEDED + "\n" + CALL_QUIT);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marFileLockedFailureCompleteSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marFileLockedFailureCompleteSvc_win.js
new file mode 100644
index 0000000000..698ccb7fe5
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marFileLockedFailureCompleteSvc_win.js
@@ -0,0 +1,27 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* File locked complete MAR file patch apply failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await runHelperLockFile(gTestFiles[3]);
+ runUpdate(STATE_FAILED_WRITE_ERROR, false, 1, true);
+ await waitForHelperExit();
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContains(ERR_RENAME_FILE);
+ checkUpdateLogContains(ERR_BACKUP_CREATE_7);
+ checkUpdateLogContains(STATE_FAILED_WRITE_ERROR + "\n" + CALL_QUIT);
+ await waitForUpdateXMLFiles(true, false);
+ checkUpdateManager(STATE_PENDING, true, STATE_PENDING, WRITE_ERROR, 0);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marFileLockedFailurePartialSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marFileLockedFailurePartialSvc_win.js
new file mode 100644
index 0000000000..c8c019ec5c
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marFileLockedFailurePartialSvc_win.js
@@ -0,0 +1,26 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* File locked partial MAR file patch apply failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesPartialSuccess;
+ gTestDirs = gTestDirsPartialSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_PARTIAL_MAR, false);
+ await runHelperLockFile(gTestFiles[2]);
+ runUpdate(STATE_FAILED_READ_ERROR, false, 1, true);
+ await waitForHelperExit();
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContains(ERR_UNABLE_OPEN_DEST);
+ checkUpdateLogContains(STATE_FAILED_READ_ERROR + "\n" + CALL_QUIT);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_FAILED, READ_ERROR, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marFileLockedStageFailureCompleteSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marFileLockedStageFailureCompleteSvc_win.js
new file mode 100644
index 0000000000..7b582dbd45
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marFileLockedStageFailureCompleteSvc_win.js
@@ -0,0 +1,34 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* File locked complete MAR file staged patch apply failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = STATE_PENDING;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await runHelperLockFile(gTestFiles[3]);
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ // Files aren't checked after staging since this test locks a file which
+ // prevents reading the file.
+ checkUpdateLogContains(ERR_ENSURE_COPY);
+ // Switch the application to the staged application that was updated.
+ runUpdate(STATE_FAILED_WRITE_ERROR, false, 1, false);
+ await waitForHelperExit();
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContains(ERR_RENAME_FILE);
+ checkUpdateLogContains(ERR_BACKUP_CREATE_7);
+ checkUpdateLogContains(STATE_FAILED_WRITE_ERROR + "\n" + CALL_QUIT);
+ await waitForUpdateXMLFiles(true, false);
+ checkUpdateManager(STATE_PENDING, true, STATE_PENDING, WRITE_ERROR, 0);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marFileLockedStageFailurePartialSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marFileLockedStageFailurePartialSvc_win.js
new file mode 100644
index 0000000000..bf3abd8c37
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marFileLockedStageFailurePartialSvc_win.js
@@ -0,0 +1,33 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* File locked partial MAR file staged patch apply failure test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = STATE_PENDING;
+ gTestFiles = gTestFilesPartialSuccess;
+ gTestDirs = gTestDirsPartialSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_PARTIAL_MAR, false);
+ await runHelperLockFile(gTestFiles[2]);
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ // Files aren't checked after staging since this test locks a file which
+ // prevents reading the file.
+ checkUpdateLogContains(ERR_ENSURE_COPY);
+ // Switch the application to the staged application that was updated.
+ runUpdate(STATE_FAILED_READ_ERROR, false, 1, false);
+ await waitForHelperExit();
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContains(ERR_UNABLE_OPEN_DEST);
+ checkUpdateLogContains(STATE_FAILED_READ_ERROR + "\n" + CALL_QUIT);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_FAILED, READ_ERROR, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseStageFailureCompleteSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseStageFailureCompleteSvc_win.js
new file mode 100644
index 0000000000..31c5b8bd7a
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseStageFailureCompleteSvc_win.js
@@ -0,0 +1,43 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* File in use inside removed dir complete MAR file staged patch apply failure
+ test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = gIsServiceTest ? STATE_APPLIED_SVC : STATE_APPLIED;
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_PENDING_SVC
+ : STATE_PENDING;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await runHelperFileInUse(
+ gTestDirs[4].relPathDir +
+ gTestDirs[4].subDirs[0] +
+ gTestDirs[4].subDirFiles[0],
+ true
+ );
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getStageDirFile, true);
+ checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
+ // Switch the application to the staged application that was updated.
+ runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
+ await waitForHelperExit();
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ setTestFilesAndDirsForFailure();
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContains(ERR_RENAME_FILE);
+ checkUpdateLogContains(
+ ERR_MOVE_DESTDIR_7 + "\n" + STATE_FAILED_WRITE_ERROR + "\n" + CALL_QUIT
+ );
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_AFTER_RUNUPDATE, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseStageFailurePartialSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseStageFailurePartialSvc_win.js
new file mode 100644
index 0000000000..b57f8c81b7
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseStageFailurePartialSvc_win.js
@@ -0,0 +1,41 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* File in use inside removed dir partial MAR file staged patch apply failure
+ test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = gIsServiceTest ? STATE_APPLIED_SVC : STATE_APPLIED;
+ const STATE_AFTER_RUNUPDATE = gIsServiceTest
+ ? STATE_PENDING_SVC
+ : STATE_PENDING;
+ gTestFiles = gTestFilesPartialSuccess;
+ gTestDirs = gTestDirsPartialSuccess;
+ await setupUpdaterTest(FILE_PARTIAL_MAR, false);
+ await runHelperFileInUse(
+ gTestDirs[2].relPathDir + gTestDirs[2].files[0],
+ true
+ );
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getStageDirFile, true);
+ checkUpdateLogContents(LOG_PARTIAL_SUCCESS, true);
+ // Switch the application to the staged application that was updated.
+ runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
+ await waitForHelperExit();
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ setTestFilesAndDirsForFailure();
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContains(ERR_RENAME_FILE);
+ checkUpdateLogContains(
+ ERR_MOVE_DESTDIR_7 + "\n" + STATE_FAILED_WRITE_ERROR + "\n" + CALL_QUIT
+ );
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_AFTER_RUNUPDATE, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseSuccessCompleteSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseSuccessCompleteSvc_win.js
new file mode 100644
index 0000000000..0683df0d8d
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseSuccessCompleteSvc_win.js
@@ -0,0 +1,31 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* File in use inside removed dir complete MAR file patch apply success test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await runHelperFileInUse(
+ gTestDirs[4].relPathDir +
+ gTestDirs[4].subDirs[0] +
+ gTestDirs[4].subDirFiles[0],
+ true
+ );
+ runUpdate(STATE_SUCCEEDED, false, 0, true);
+ await waitForHelperExit();
+ await checkPostUpdateAppLog();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile, false, true);
+ checkUpdateLogContains(ERR_BACKUP_DISCARD);
+ checkUpdateLogContains(STATE_SUCCEEDED + "\n" + CALL_QUIT);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseSuccessPartialSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseSuccessPartialSvc_win.js
new file mode 100644
index 0000000000..d4da3a5f37
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marRMRFDirFileInUseSuccessPartialSvc_win.js
@@ -0,0 +1,29 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* File in use inside removed dir partial MAR file patch apply success test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesPartialSuccess;
+ gTestDirs = gTestDirsPartialSuccess;
+ await setupUpdaterTest(FILE_PARTIAL_MAR, false);
+ await runHelperFileInUse(
+ gTestDirs[2].relPathDir + gTestDirs[2].files[0],
+ true
+ );
+ runUpdate(STATE_SUCCEEDED, false, 0, true);
+ await waitForHelperExit();
+ await checkPostUpdateAppLog();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile, false, true);
+ checkUpdateLogContains(ERR_BACKUP_DISCARD);
+ checkUpdateLogContains(STATE_SUCCEEDED + "\n" + CALL_QUIT);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marStageFailurePartialSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/marStageFailurePartialSvc.js
new file mode 100644
index 0000000000..a1a0de0fe4
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marStageFailurePartialSvc.js
@@ -0,0 +1,31 @@
+/* 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/.
+ */
+
+/* General Partial MAR File Staged Patch Apply Failure Test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = STATE_FAILED;
+ gTestFiles = gTestFilesPartialSuccess;
+ gTestFiles[11].originalFile = "partial.png";
+ gTestDirs = gTestDirsPartialSuccess;
+ setTestFilesAndDirsForFailure();
+ await setupUpdaterTest(FILE_PARTIAL_MAR, false);
+ await stageUpdate(STATE_AFTER_STAGE, true, true);
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateFailure(getApplyDirFile);
+ checkUpdateLogContains(ERR_LOADSOURCEFILE_FAILED);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(
+ STATE_NONE,
+ false,
+ STATE_FAILED,
+ LOADSOURCE_ERROR_WRONG_SIZE,
+ 1
+ );
+ waitForFilesInUse();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marStageSuccessCompleteSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/marStageSuccessCompleteSvc.js
new file mode 100644
index 0000000000..943a45ba95
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marStageSuccessCompleteSvc.js
@@ -0,0 +1,71 @@
+/* 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/.
+ */
+
+/* General Complete MAR File Staged Patch Apply Test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = gIsServiceTest ? STATE_APPLIED_SVC : STATE_APPLIED;
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestFiles[gTestFiles.length - 1].originalContents = null;
+ gTestFiles[gTestFiles.length - 1].compareContents = "FromComplete\n";
+ gTestFiles[gTestFiles.length - 1].comparePerms = 0o644;
+ gTestDirs = gTestDirsCompleteSuccess;
+ setupSymLinks();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, false);
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getStageDirFile, true);
+ checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
+ // Switch the application to the staged application that was updated.
+ runUpdate(STATE_SUCCEEDED, true, 0, true);
+ await checkPostUpdateAppLog();
+ checkAppBundleModTime();
+ checkSymLinks();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile, false, true);
+ checkUpdateLogContents(LOG_REPLACE_SUCCESS, false, true);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
+
+/**
+ * Setup symlinks for the test.
+ */
+function setupSymLinks() {
+ // Don't test symlinks on Mac OS X in this test since it tends to timeout.
+ // It is tested on Mac OS X in marAppInUseStageSuccessComplete_unix.js
+ if (AppConstants.platform == "linux") {
+ removeSymlink();
+ createSymlink();
+ registerCleanupFunction(removeSymlink);
+ gTestFiles.splice(gTestFiles.length - 3, 0, {
+ description: "Readable symlink",
+ fileName: "link",
+ relPathDir: DIR_RESOURCES,
+ originalContents: "test",
+ compareContents: "test",
+ originalFile: null,
+ compareFile: null,
+ originalPerms: 0o666,
+ comparePerms: 0o666,
+ });
+ }
+}
+
+/**
+ * Checks the state of the symlinks for the test.
+ */
+function checkSymLinks() {
+ // Don't test symlinks on Mac OS X in this test since it tends to timeout.
+ // It is tested on Mac OS X in marAppInUseStageSuccessComplete_unix.js
+ if (AppConstants.platform == "linux") {
+ checkSymlink();
+ }
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marStageSuccessPartialSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/marStageSuccessPartialSvc.js
new file mode 100644
index 0000000000..dd5c240919
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marStageSuccessPartialSvc.js
@@ -0,0 +1,35 @@
+/* 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/.
+ */
+
+/* General Partial MAR File Staged Patch Apply Test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ const STATE_AFTER_STAGE = gIsServiceTest ? STATE_APPLIED_SVC : STATE_APPLIED;
+ gTestFiles = gTestFilesPartialSuccess;
+ gTestFiles[gTestFiles.length - 1].originalContents = null;
+ gTestFiles[gTestFiles.length - 1].compareContents = "FromPartial\n";
+ gTestFiles[gTestFiles.length - 1].comparePerms = 0o644;
+ gTestDirs = gTestDirsPartialSuccess;
+ preventDistributionFiles();
+ await setupUpdaterTest(FILE_PARTIAL_MAR, true);
+ await stageUpdate(STATE_AFTER_STAGE, true);
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getStageDirFile, true);
+ checkUpdateLogContents(LOG_PARTIAL_SUCCESS, true, false, true);
+ // Switch the application to the staged application that was updated.
+ runUpdate(STATE_SUCCEEDED, true, 0, true);
+ await checkPostUpdateAppLog();
+ checkAppBundleModTime();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile, false, true);
+ checkUpdateLogContents(LOG_REPLACE_SUCCESS, false, true, true);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marSuccessCompleteSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/marSuccessCompleteSvc.js
new file mode 100644
index 0000000000..2dd1e54f90
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marSuccessCompleteSvc.js
@@ -0,0 +1,26 @@
+/* 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/.
+ */
+
+/* General Complete MAR File Patch Apply Test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesCompleteSuccess;
+ gTestDirs = gTestDirsCompleteSuccess;
+ preventDistributionFiles();
+ await setupUpdaterTest(FILE_COMPLETE_MAR, true);
+ runUpdate(STATE_SUCCEEDED, false, 0, true);
+ await checkPostUpdateAppLog();
+ checkAppBundleModTime();
+ standardInit();
+ checkPostUpdateRunningFile(true);
+ checkFilesAfterUpdateSuccess(getApplyDirFile);
+ checkUpdateLogContents(LOG_COMPLETE_SUCCESS, false, false, true);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marSuccessPartialSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/marSuccessPartialSvc.js
new file mode 100644
index 0000000000..8e8e9d094a
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/marSuccessPartialSvc.js
@@ -0,0 +1,29 @@
+/* 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/.
+ */
+
+/* General Partial MAR File Patch Apply Test */
+
+async function run_test() {
+ if (!setupTestCommon()) {
+ return;
+ }
+ gTestFiles = gTestFilesPartialSuccess;
+ gTestFiles[gTestFiles.length - 1].originalContents = null;
+ gTestFiles[gTestFiles.length - 1].compareContents = "FromPartial\n";
+ gTestFiles[gTestFiles.length - 1].comparePerms = 0o644;
+ gTestDirs = gTestDirsPartialSuccess;
+ // The third parameter will test that a relative path that contains a
+ // directory traversal to the post update binary doesn't execute.
+ await setupUpdaterTest(FILE_PARTIAL_MAR, false, "test/../");
+ runUpdate(STATE_SUCCEEDED, false, 0, true);
+ checkAppBundleModTime();
+ standardInit();
+ checkPostUpdateRunningFile(false);
+ checkFilesAfterUpdateSuccess(getApplyDirFile);
+ checkUpdateLogContents(LOG_PARTIAL_SUCCESS);
+ await waitForUpdateXMLFiles();
+ checkUpdateManager(STATE_NONE, false, STATE_SUCCEEDED, 0, 1);
+ checkCallbackLog();
+}
diff --git a/toolkit/mozapps/update/tests/unit_service_updater/xpcshell.toml b/toolkit/mozapps/update/tests/unit_service_updater/xpcshell.toml
new file mode 100644
index 0000000000..d10ae8ec3b
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_service_updater/xpcshell.toml
@@ -0,0 +1,134 @@
+[DEFAULT]
+skip-if = [
+ "os == 'win' && verify",
+ "os == 'win' && ccov", # 1532801
+ "os == 'win' && asan", # updater binary must be signed for these tests, but it isn't in this build config
+ "os == 'win' && msix", # Updates are disabled for MSIX builds
+]
+tags = "appupdate"
+head = "head_update.js"
+support-files = [
+ "../data/shared.js",
+ "../data/sharedUpdateXML.js",
+ "../data/xpcshellUtilsAUS.js",
+]
+
+["bootstrapSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["checkUpdaterSigSvc.js"]
+
+["fallbackOnSvcFailure.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["invalidArgInstallDirPathTooLongFailureSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["invalidArgInstallDirPathTraversalFailureSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["invalidArgInstallWorkingDirPathNotSameFailureSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["invalidArgPatchDirPathSuffixFailureSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["invalidArgPatchDirPathTraversalFailureSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["invalidArgStageDirNotInInstallDirFailureSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["invalidArgWorkingDirPathLocalUNCFailureSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["invalidArgWorkingDirPathRelativeFailureSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marAppApplyDirLockedStageFailureSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marAppApplyUpdateAppBinInUseStageSuccessSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+skip-if = ["ccov && os == 'win'"] #Bug 1651090
+
+["marAppApplyUpdateStageSuccessSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marAppApplyUpdateSuccessSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marAppInUseBackgroundTaskFailureSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marAppInUseStageFailureCompleteSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marAppInUseSuccessCompleteSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marCallbackAppStageSuccessCompleteSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marCallbackAppStageSuccessPartialSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marCallbackAppSuccessCompleteSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marCallbackAppSuccessPartialSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marFailurePartialSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marFileInUseStageFailureCompleteSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marFileInUseStageFailurePartialSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marFileInUseSuccessCompleteSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marFileInUseSuccessPartialSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marFileLockedFailureCompleteSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marFileLockedFailurePartialSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marFileLockedStageFailureCompleteSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marFileLockedStageFailurePartialSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marRMRFDirFileInUseStageFailureCompleteSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marRMRFDirFileInUseStageFailurePartialSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marRMRFDirFileInUseSuccessCompleteSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marRMRFDirFileInUseSuccessPartialSvc_win.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marStageFailurePartialSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marStageSuccessCompleteSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marStageSuccessPartialSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marSuccessCompleteSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."
+
+["marSuccessPartialSvc.js"]
+run-sequentially = "Uses the Mozilla Maintenance Service."