diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/mozapps/update/tests/unit_base_updater | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/mozapps/update/tests/unit_base_updater')
44 files changed, 2731 insertions, 0 deletions
diff --git a/toolkit/mozapps/update/tests/unit_base_updater/.eslintrc.js b/toolkit/mozapps/update/tests/unit_base_updater/.eslintrc.js new file mode 100644 index 000000000..d35787cd2 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/.eslintrc.js @@ -0,0 +1,7 @@ +"use strict"; + +module.exports = { + "extends": [ + "../../../../../testing/xpcshell/xpcshell.eslintrc.js" + ] +}; diff --git a/toolkit/mozapps/update/tests/unit_base_updater/head_update.js b/toolkit/mozapps/update/tests/unit_base_updater/head_update.js new file mode 100644 index 000000000..9715c5828 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/head_update.js @@ -0,0 +1,8 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +const IS_SERVICE_TEST = false; + +/* import-globals-from ../data/xpcshellUtilsAUS.js */ +load("../data/xpcshellUtilsAUS.js"); diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgCallbackFileNotInInstallDirFailure.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgCallbackFileNotInInstallDirFailure.js new file mode 100644 index 000000000..f3f767394 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgCallbackFileNotInInstallDirFailure.js @@ -0,0 +1,37 @@ +/* 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/. + */ + +/* Callback file not in install directory or a sub-directory of the install + directory failure */ + +const STATE_AFTER_RUNUPDATE = STATE_FAILED_INVALID_CALLBACK_DIR_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = getTestDirFile(FILE_HELPER_BIN).path; + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, null, path); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgCallbackFilePathTooLongFailure.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgCallbackFilePathTooLongFailure.js new file mode 100644 index 000000000..969f84f9d --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgCallbackFilePathTooLongFailure.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/. + */ + +/* Too long callback file path failure test */ + +const STATE_AFTER_RUNUPDATE = STATE_FAILED_INVALID_CALLBACK_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = "123456789"; + if (IS_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, null, null, path); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTooLongFailure.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTooLongFailure.js new file mode 100644 index 000000000..70e03646a --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTooLongFailure.js @@ -0,0 +1,47 @@ +/* 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 */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_INSTALL_DIR_PATH_ERROR + : STATE_FAILED_INVALID_INSTALL_DIR_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = "123456789"; + if (IS_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); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTraversalFailure.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTraversalFailure.js new file mode 100644 index 000000000..330578de6 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTraversalFailure.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/. + */ + +/* Install directory path traversal failure test */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_INSTALL_DIR_PATH_ERROR + : STATE_FAILED_INVALID_INSTALL_DIR_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = "123456789"; + if (IS_WIN) { + path = "C:\\" + path + "\\..\\" + path; + } else { + path = "/" + path + "/../" + path; + } + + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, path, null, null); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallWorkingDirPathNotSameFailure_win.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallWorkingDirPathNotSameFailure_win.js new file mode 100644 index 000000000..8ddb34af0 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallWorkingDirPathNotSameFailure_win.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/. + */ + +/* Different install and working directories for a regular update failure */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_APPLYTO_DIR_ERROR + : STATE_FAILED_INVALID_APPLYTO_DIR_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = getApplyDirFile("..", false).path; + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, path, null); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgPatchDirPathTraversalFailure.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgPatchDirPathTraversalFailure.js new file mode 100644 index 000000000..c8ae3f0c6 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgPatchDirPathTraversalFailure.js @@ -0,0 +1,43 @@ +/* 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 */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_PENDING_SVC : STATE_PENDING; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = getUpdatesPatchDir(); + if (IS_WIN) { + path = path + "\\..\\"; + } else { + path = path + "/../"; + } + + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, path, null, null, null); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgStageDirNotInInstallDirFailure_win.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgStageDirNotInInstallDirFailure_win.js new file mode 100644 index 000000000..e9b227657 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgStageDirNotInInstallDirFailure_win.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/. + */ + +/* Different install and working directories for a regular update failure */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_APPLYTO_DIR_STAGED_ERROR + : STATE_FAILED_INVALID_APPLYTO_DIR_STAGED_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = getApplyDirFile("..", false).path; + runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true, null, null, path, null); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathLocalUNCFailure_win.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathLocalUNCFailure_win.js new file mode 100644 index 000000000..87bbad4aa --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathLocalUNCFailure_win.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/. + */ + +/* Working directory path local UNC failure test */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_WORKING_DIR_PATH_ERROR + : STATE_FAILED_INVALID_WORKING_DIR_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = "\\\\.\\" + getApplyDirFile(null, false).path; + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, path, null); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathRelativeFailure.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathRelativeFailure.js new file mode 100644 index 000000000..a550909b2 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathRelativeFailure.js @@ -0,0 +1,37 @@ +/* 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 */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_WORKING_DIR_PATH_ERROR + : STATE_FAILED_INVALID_WORKING_DIR_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, "test", null); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyDirLockedStageFailure_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyDirLockedStageFailure_win.js new file mode 100644 index 000000000..b9f793236 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyDirLockedStageFailure_win.js @@ -0,0 +1,41 @@ +/* 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. + */ + +const STATE_AFTER_STAGE = STATE_PENDING; + +function run_test() { + if (!setupTestCommon()) { + return; + } + + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + createUpdateInProgressLockFile(getAppBaseDir()); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + stageUpdate(false); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + removeUpdateInProgressLockFile(getAppBaseDir()); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(PERFORMING_STAGED_UPDATE); + checkUpdateLogContains(ERR_UPDATE_IN_PROGRESS); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateAppBinInUseStageSuccess_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateAppBinInUseStageSuccess_win.js new file mode 100644 index 000000000..a606720b7 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateAppBinInUseStageSuccess_win.js @@ -0,0 +1,83 @@ +/* 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. + */ + +const STATE_AFTER_STAGE = IS_SERVICE_TEST ? STATE_APPLIED_SVC : STATE_APPLIED; + +function run_test() { + if (!setupTestCommon()) { + return; + } + + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setupUpdaterTest(FILE_COMPLETE_MAR, undefined); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateSuccess(getStageDirFile, true, false); + checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true); + lockDirectory(getAppBaseDir().path); + // Switch the application to the staged application that was updated. + runUpdateUsingApp(STATE_SUCCEEDED); +} + +/** + * Called after the call to runUpdateUsingApp finishes. + */ +function runUpdateFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + checkAppBundleModTime(); + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile); + checkUpdateLogContents(LOG_COMPLETE_SUCCESS); + + let updatesDir = getUpdatesPatchDir(); + Assert.ok(updatesDir.exists(), + MSG_SHOULD_EXIST + getMsgPath(updatesDir.path)); + + let log = getUpdateLog(FILE_UPDATE_LOG); + Assert.ok(!log.exists(), + MSG_SHOULD_NOT_EXIST + getMsgPath(log.path)); + + log = getUpdateLog(FILE_LAST_UPDATE_LOG); + Assert.ok(log.exists(), + MSG_SHOULD_EXIST + getMsgPath(log.path)); + + log = getUpdateLog(FILE_BACKUP_UPDATE_LOG); + Assert.ok(log.exists(), + MSG_SHOULD_EXIST + getMsgPath(log.path)); + + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateStageOldVersionFailure.js b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateStageOldVersionFailure.js new file mode 100644 index 000000000..00b38adc7 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateStageOldVersionFailure.js @@ -0,0 +1,88 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +/** + * Test a replace request for a staged update with a version file that specifies + * an older version failure. The same check is used in nsUpdateDriver.cpp for + * all update types which is why there aren't tests for the maintenance service + * as well as for other update types. + */ + +const STATE_AFTER_STAGE = STATE_APPLIED; + +function run_test() { + if (!setupTestCommon()) { + return; + } + + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setupUpdaterTest(FILE_COMPLETE_MAR); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + stageUpdate(false); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateSuccess(getStageDirFile, true); + checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true); + // Change the active update to an older version to simulate installing a new + // version of the application while there is an update that has been staged. + let channel = gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_CHANNEL); + let patches = getLocalPatchString(null, null, null, null, null, "true", + STATE_AFTER_STAGE); + let updates = getLocalUpdateString(patches, null, null, null, "1.0", null, + null, null, null, null, "true", channel); + writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); + // Change the version file to an older version to simulate installing a new + // version of the application while there is an update that has been staged. + writeVersionFile("1.0"); + reloadUpdateManagerData(); + // Try to switch the application to the staged application that was updated. + runUpdateUsingApp(STATE_AFTER_STAGE); +} + +/** + * Called after the call to runUpdateUsingApp finishes. + */ +function runUpdateFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_AFTER_STAGE, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + setTestFilesAndDirsForFailure(); + checkFilesAfterUpdateFailure(getApplyDirFile, IS_MACOSX ? false : true, false); + + let updatesDir = getUpdatesPatchDir(); + Assert.ok(updatesDir.exists(), + MSG_SHOULD_EXIST + getMsgPath(updatesDir.path)); + + let log = getUpdateLog(FILE_UPDATE_LOG); + Assert.ok(!log.exists(), + MSG_SHOULD_NOT_EXIST + getMsgPath(log.path)); + + log = getUpdateLog(FILE_LAST_UPDATE_LOG); + Assert.ok(log.exists(), + MSG_SHOULD_EXIST + getMsgPath(log.path)); + + log = getUpdateLog(FILE_BACKUP_UPDATE_LOG); + Assert.ok(!log.exists(), + MSG_SHOULD_NOT_EXIST + getMsgPath(log.path)); + + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateStageSuccess.js b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateStageSuccess.js new file mode 100644 index 000000000..5b9b08156 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateStageSuccess.js @@ -0,0 +1,82 @@ +/* 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. + */ + +const STATE_AFTER_STAGE = IS_SERVICE_TEST ? STATE_APPLIED_SVC : STATE_APPLIED; + +function run_test() { + if (!setupTestCommon()) { + return; + } + + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setupUpdaterTest(FILE_COMPLETE_MAR, true); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateSuccess(getStageDirFile, true); + checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true); + // Switch the application to the staged application that was updated. + runUpdateUsingApp(STATE_SUCCEEDED); +} + +/** + * Called after the call to runUpdateUsingApp finishes. + */ +function runUpdateFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + checkAppBundleModTime(); + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile, false, true); + checkUpdateLogContents(LOG_REPLACE_SUCCESS, false, true); + + let updatesDir = getUpdatesPatchDir(); + Assert.ok(updatesDir.exists(), + MSG_SHOULD_EXIST + getMsgPath(updatesDir.path)); + + let log = getUpdateLog(FILE_UPDATE_LOG); + Assert.ok(!log.exists(), + MSG_SHOULD_NOT_EXIST + getMsgPath(log.path)); + + log = getUpdateLog(FILE_LAST_UPDATE_LOG); + Assert.ok(log.exists(), + MSG_SHOULD_EXIST + getMsgPath(log.path)); + + log = getUpdateLog(FILE_BACKUP_UPDATE_LOG); + Assert.ok(log.exists(), + MSG_SHOULD_EXIST + getMsgPath(log.path)); + + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateSuccess.js b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateSuccess.js new file mode 100644 index 000000000..e76233fe6 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateSuccess.js @@ -0,0 +1,65 @@ +/* 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. + */ + +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. + setupUpdaterTest(FILE_COMPLETE_MAR, undefined, + getApplyDirFile(null, true).path + "/"); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runUpdateUsingApp(STATE_SUCCEEDED); +} + +/** + * Called after the call to runUpdateUsingApp finishes. + */ +function runUpdateFinished() { + checkAppBundleModTime(); + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateSuccess(getApplyDirFile); + checkUpdateLogContents(LOG_COMPLETE_SUCCESS); + + let updatesDir = getUpdatesPatchDir(); + Assert.ok(updatesDir.exists(), + MSG_SHOULD_EXIST + getMsgPath(updatesDir.path)); + + let log = getUpdateLog(FILE_UPDATE_LOG); + Assert.ok(!log.exists(), + MSG_SHOULD_NOT_EXIST + getMsgPath(log.path)); + + log = getUpdateLog(FILE_LAST_UPDATE_LOG); + Assert.ok(log.exists(), + MSG_SHOULD_EXIST + getMsgPath(log.path)); + + log = getUpdateLog(FILE_BACKUP_UPDATE_LOG); + Assert.ok(!log.exists(), + MSG_SHOULD_NOT_EXIST + getMsgPath(log.path)); + + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseStageFailureComplete_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseStageFailureComplete_win.js new file mode 100644 index 000000000..b1505d58e --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseStageFailureComplete_win.js @@ -0,0 +1,70 @@ +/* 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 */ + +const STATE_AFTER_STAGE = IS_SERVICE_TEST ? STATE_APPLIED_SVC : STATE_APPLIED; +const STATE_AFTER_RUNUPDATE = IS_SERVICE_TEST ? STATE_PENDING_SVC : STATE_PENDING; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperFileInUse(DIR_RESOURCES + gCallbackBinFile, false); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_AFTER_RUNUPDATE, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + setTestFilesAndDirsForFailure(); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(ERR_RENAME_FILE); + checkUpdateLogContains(ERR_MOVE_DESTDIR_7 + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseStageSuccessComplete_unix.js b/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseStageSuccessComplete_unix.js new file mode 100644 index 000000000..a1cc7d043 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseStageSuccessComplete_unix.js @@ -0,0 +1,113 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +/* Application in use complete MAR file staged patch apply success test */ + +const START_STATE = STATE_PENDING; +const STATE_AFTER_STAGE = STATE_APPLIED; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestFiles[gTestFiles.length - 1].originalContents = null; + gTestFiles[gTestFiles.length - 1].compareContents = "FromComplete\n"; + gTestFiles[gTestFiles.length - 1].comparePerms = 0o644; + gTestDirs = gTestDirsCompleteSuccess; + setupUpdaterTest(FILE_COMPLETE_MAR, true); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + setupSymLinks(); + runHelperFileInUse(DIR_RESOURCES + gCallbackBinFile, false); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + checkAppBundleModTime(); + checkSymLinks(); + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile); + checkUpdateLogContents(LOG_REPLACE_SUCCESS, false, true); + checkCallbackLog(); +} + +/** + * Setup symlinks for the test. + */ +function setupSymLinks() { + if (IS_UNIX) { + removeSymlink(); + createSymlink(); + do_register_cleanup(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() { + if (IS_UNIX) { + checkSymlink(); + } +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseSuccessComplete.js b/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseSuccessComplete.js new file mode 100644 index 000000000..93333cade --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseSuccessComplete.js @@ -0,0 +1,62 @@ +/* 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 */ + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperFileInUse(DIR_RESOURCES + gCallbackBinFile, false); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + runUpdate(STATE_SUCCEEDED, false, 0, true); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + checkAppBundleModTime(); + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile); + checkUpdateLogContents(LOG_COMPLETE_SUCCESS); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marCallbackAppStageSuccessComplete_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marCallbackAppStageSuccessComplete_win.js new file mode 100644 index 000000000..79e54c182 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marCallbackAppStageSuccessComplete_win.js @@ -0,0 +1,61 @@ +/* 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 */ + +const STATE_AFTER_STAGE = IS_SERVICE_TEST ? STATE_APPLIED_SVC : STATE_APPLIED; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + gCallbackBinFile = "exe0.exe"; + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile, false, true); + checkUpdateLogContents(LOG_REPLACE_SUCCESS, false, true); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marCallbackAppStageSuccessPartial_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marCallbackAppStageSuccessPartial_win.js new file mode 100644 index 000000000..b1f84715f --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marCallbackAppStageSuccessPartial_win.js @@ -0,0 +1,61 @@ +/* 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 */ + +const STATE_AFTER_STAGE = IS_SERVICE_TEST ? STATE_APPLIED_SVC : STATE_APPLIED; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesPartialSuccess; + gTestDirs = gTestDirsPartialSuccess; + gCallbackBinFile = "exe0.exe"; + setupUpdaterTest(FILE_PARTIAL_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile, false, true); + checkUpdateLogContents(LOG_REPLACE_SUCCESS, false, true); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marCallbackAppSuccessComplete_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marCallbackAppSuccessComplete_win.js new file mode 100644 index 000000000..85e92d290 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marCallbackAppSuccessComplete_win.js @@ -0,0 +1,48 @@ +/* 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 */ + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + gCallbackBinFile = "exe0.exe"; + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runUpdate(STATE_SUCCEEDED, false, 0, true); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile); + checkUpdateLogContents(LOG_COMPLETE_SUCCESS); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marCallbackAppSuccessPartial_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marCallbackAppSuccessPartial_win.js new file mode 100644 index 000000000..1212c9ba2 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marCallbackAppSuccessPartial_win.js @@ -0,0 +1,48 @@ +/* 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 */ + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesPartialSuccess; + gTestDirs = gTestDirsPartialSuccess; + gCallbackBinFile = "exe0.exe"; + setupUpdaterTest(FILE_PARTIAL_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runUpdate(STATE_SUCCEEDED, false, 0, true); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile); + checkUpdateLogContents(LOG_PARTIAL_SUCCESS); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marFailurePartial.js b/toolkit/mozapps/update/tests/unit_base_updater/marFailurePartial.js new file mode 100644 index 000000000..960c96f7b --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marFailurePartial.js @@ -0,0 +1,47 @@ +/* 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 */ + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesPartialSuccess; + gTestFiles[11].originalFile = "partial.png"; + gTestDirs = gTestDirsPartialSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_PARTIAL_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + // 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + checkAppBundleModTime(); + standardInit(); + Assert.equal(readStatusFile(), STATE_NONE, + "the status file failure code" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_FAILED, + "the update state" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).errorCode, LOADSOURCE_ERROR_WRONG_SIZE, + "the update errorCode" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContents(LOG_PARTIAL_FAILURE); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marFileInUseStageFailureComplete_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marFileInUseStageFailureComplete_win.js new file mode 100644 index 000000000..b39595f92 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marFileInUseStageFailureComplete_win.js @@ -0,0 +1,67 @@ +/* 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 */ + +const STATE_AFTER_STAGE = IS_SERVICE_TEST ? STATE_APPLIED_SVC : STATE_APPLIED; +const STATE_AFTER_RUNUPDATE = IS_SERVICE_TEST ? STATE_PENDING_SVC : STATE_PENDING; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperFileInUse(gTestFiles[13].relPathDir + gTestFiles[13].fileName, + false); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + standardInit(); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_AFTER_RUNUPDATE, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + setTestFilesAndDirsForFailure(); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(ERR_RENAME_FILE); + checkUpdateLogContains(ERR_MOVE_DESTDIR_7 + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marFileInUseStageFailurePartial_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marFileInUseStageFailurePartial_win.js new file mode 100644 index 000000000..06d386ad6 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marFileInUseStageFailurePartial_win.js @@ -0,0 +1,67 @@ +/* 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 */ + +const STATE_AFTER_STAGE = IS_SERVICE_TEST ? STATE_APPLIED_SVC : STATE_APPLIED; +const STATE_AFTER_RUNUPDATE = IS_SERVICE_TEST ? STATE_PENDING_SVC : STATE_PENDING; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesPartialSuccess; + gTestDirs = gTestDirsPartialSuccess; + setupUpdaterTest(FILE_PARTIAL_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperFileInUse(gTestFiles[11].relPathDir + gTestFiles[11].fileName, + false); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + standardInit(); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_AFTER_RUNUPDATE, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + setTestFilesAndDirsForFailure(); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(ERR_RENAME_FILE); + checkUpdateLogContains(ERR_MOVE_DESTDIR_7 + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marFileInUseSuccessComplete_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marFileInUseSuccessComplete_win.js new file mode 100644 index 000000000..89a2fff5e --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marFileInUseSuccessComplete_win.js @@ -0,0 +1,63 @@ +/* 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 */ + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperFileInUse(gTestFiles[13].relPathDir + gTestFiles[13].fileName, + false); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + runUpdate(STATE_SUCCEEDED, false, 0, true); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile, false, true); + checkUpdateLogContains(ERR_BACKUP_DISCARD); + checkUpdateLogContains(STATE_SUCCEEDED + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marFileInUseSuccessPartial_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marFileInUseSuccessPartial_win.js new file mode 100644 index 000000000..ea85ddccc --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marFileInUseSuccessPartial_win.js @@ -0,0 +1,63 @@ +/* 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 */ + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesPartialSuccess; + gTestDirs = gTestDirsPartialSuccess; + setupUpdaterTest(FILE_PARTIAL_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperFileInUse(gTestFiles[11].relPathDir + gTestFiles[11].fileName, + false); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + runUpdate(STATE_SUCCEEDED, false, 0, true); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile, false, true); + checkUpdateLogContains(ERR_BACKUP_DISCARD); + checkUpdateLogContains(STATE_SUCCEEDED + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marFileLockedFailureComplete_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marFileLockedFailureComplete_win.js new file mode 100644 index 000000000..c5efaa8c0 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marFileLockedFailureComplete_win.js @@ -0,0 +1,57 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +/* File locked complete MAR file patch apply failure test */ + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperLockFile(gTestFiles[3]); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + runUpdate(STATE_FAILED_WRITE_ERROR, false, 1, true); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + standardInit(); + Assert.equal(readStatusFile(), STATE_PENDING, + "the status file failure code" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_PENDING, + "the update state" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).errorCode, WRITE_ERROR, + "the update errorCode" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(ERR_RENAME_FILE); + checkUpdateLogContains(ERR_BACKUP_CREATE_7); + checkUpdateLogContains(STATE_FAILED_WRITE_ERROR + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marFileLockedFailurePartial_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marFileLockedFailurePartial_win.js new file mode 100644 index 000000000..4fdbadb5b --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marFileLockedFailurePartial_win.js @@ -0,0 +1,56 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +/* File locked partial MAR file patch apply failure test */ + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesPartialSuccess; + gTestDirs = gTestDirsPartialSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_PARTIAL_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperLockFile(gTestFiles[2]); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + runUpdate(STATE_FAILED_READ_ERROR, false, 1, true); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + standardInit(); + Assert.equal(readStatusFile(), STATE_NONE, + "the status file failure code" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_FAILED, + "the update state" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).errorCode, READ_ERROR, + "the update errorCode" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(ERR_UNABLE_OPEN_DEST); + checkUpdateLogContains(STATE_FAILED_READ_ERROR + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marFileLockedStageFailureComplete_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marFileLockedStageFailureComplete_win.js new file mode 100644 index 000000000..4d12f4e42 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marFileLockedStageFailureComplete_win.js @@ -0,0 +1,71 @@ +/* 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 */ + +const STATE_AFTER_STAGE = STATE_PENDING; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperLockFile(gTestFiles[3]); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + standardInit(); + Assert.equal(readStatusFile(), STATE_PENDING, + "the status file failure code" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.updateCount, 2, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_PENDING, + "the update state" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).errorCode, WRITE_ERROR, + "the update errorCode" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(ERR_RENAME_FILE); + checkUpdateLogContains(ERR_BACKUP_CREATE_7); + checkUpdateLogContains(STATE_FAILED_WRITE_ERROR + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marFileLockedStageFailurePartial_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marFileLockedStageFailurePartial_win.js new file mode 100644 index 000000000..5f64df34c --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marFileLockedStageFailurePartial_win.js @@ -0,0 +1,70 @@ +/* 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 */ + +const STATE_AFTER_STAGE = STATE_PENDING; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesPartialSuccess; + gTestDirs = gTestDirsPartialSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_PARTIAL_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperLockFile(gTestFiles[2]); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + standardInit(); + Assert.equal(readStatusFile(), STATE_NONE, + "the status file failure code" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.updateCount, 2, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_FAILED, + "the update state" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).errorCode, READ_ERROR, + "the update errorCode" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(ERR_UNABLE_OPEN_DEST); + checkUpdateLogContains(STATE_FAILED_READ_ERROR + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marRMRFDirFileInUseStageFailureComplete_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marRMRFDirFileInUseStageFailureComplete_win.js new file mode 100644 index 000000000..b83bafccc --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marRMRFDirFileInUseStageFailureComplete_win.js @@ -0,0 +1,72 @@ +/* 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 */ + +const STATE_AFTER_STAGE = IS_SERVICE_TEST ? STATE_APPLIED_SVC : STATE_APPLIED; +const STATE_AFTER_RUNUPDATE = IS_SERVICE_TEST ? STATE_PENDING_SVC : STATE_PENDING; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperFileInUse(gTestDirs[4].relPathDir + gTestDirs[4].subDirs[0] + + gTestDirs[4].subDirFiles[0], true); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_AFTER_RUNUPDATE, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + setTestFilesAndDirsForFailure(); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(ERR_RENAME_FILE); + checkUpdateLogContains(ERR_MOVE_DESTDIR_7 + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marRMRFDirFileInUseStageFailurePartial_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marRMRFDirFileInUseStageFailurePartial_win.js new file mode 100644 index 000000000..39ea485cd --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marRMRFDirFileInUseStageFailurePartial_win.js @@ -0,0 +1,71 @@ +/* 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 */ + +const STATE_AFTER_STAGE = IS_SERVICE_TEST ? STATE_APPLIED_SVC : STATE_APPLIED; +const STATE_AFTER_RUNUPDATE = IS_SERVICE_TEST ? STATE_PENDING_SVC : STATE_PENDING; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesPartialSuccess; + gTestDirs = gTestDirsPartialSuccess; + setupUpdaterTest(FILE_PARTIAL_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperFileInUse(gTestDirs[2].relPathDir + gTestDirs[2].files[0], true); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_AFTER_RUNUPDATE, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + setTestFilesAndDirsForFailure(); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(ERR_RENAME_FILE); + checkUpdateLogContains(ERR_MOVE_DESTDIR_7 + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marRMRFDirFileInUseSuccessComplete_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marRMRFDirFileInUseSuccessComplete_win.js new file mode 100644 index 000000000..a71bb8d49 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marRMRFDirFileInUseSuccessComplete_win.js @@ -0,0 +1,63 @@ +/* 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 */ + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperFileInUse(gTestDirs[4].relPathDir + gTestDirs[4].subDirs[0] + + gTestDirs[4].subDirFiles[0], true); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + runUpdate(STATE_SUCCEEDED, false, 0, true); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile, false, true); + checkUpdateLogContains(ERR_BACKUP_DISCARD); + checkUpdateLogContains(STATE_SUCCEEDED + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marRMRFDirFileInUseSuccessPartial_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marRMRFDirFileInUseSuccessPartial_win.js new file mode 100644 index 000000000..2cbe70ed8 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marRMRFDirFileInUseSuccessPartial_win.js @@ -0,0 +1,62 @@ +/* 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 */ + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesPartialSuccess; + gTestDirs = gTestDirsPartialSuccess; + setupUpdaterTest(FILE_PARTIAL_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runHelperFileInUse(gTestDirs[2].relPathDir + gTestDirs[2].files[0], true); +} + +/** + * Called after the call to waitForHelperSleep finishes. + */ +function waitForHelperSleepFinished() { + runUpdate(STATE_SUCCEEDED, false, 0, true); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + waitForHelperExit(); +} + +/** + * Called after the call to waitForHelperExit finishes. + */ +function waitForHelperExitFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile, false, true); + checkUpdateLogContains(ERR_BACKUP_DISCARD); + checkUpdateLogContains(STATE_SUCCEEDED + "\n" + CALL_QUIT); + checkCallbackLog(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marStageFailurePartial.js b/toolkit/mozapps/update/tests/unit_base_updater/marStageFailurePartial.js new file mode 100644 index 000000000..a9ce23420 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marStageFailurePartial.js @@ -0,0 +1,41 @@ +/* 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 */ + +const STATE_AFTER_STAGE = STATE_FAILED; +gStagingRemovedUpdate = true; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesPartialSuccess; + gTestFiles[11].originalFile = "partial.png"; + gTestDirs = gTestDirsPartialSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_PARTIAL_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).errorCode, LOADSOURCE_ERROR_WRONG_SIZE, + "the update errorCode" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(ERR_LOADSOURCEFILE_FAILED); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marStageSuccessComplete.js b/toolkit/mozapps/update/tests/unit_base_updater/marStageSuccessComplete.js new file mode 100644 index 000000000..f7745f68f --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marStageSuccessComplete.js @@ -0,0 +1,132 @@ +/* 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 */ + +const STATE_AFTER_STAGE = IS_SERVICE_TEST ? STATE_APPLIED_SVC : STATE_APPLIED; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestFiles[gTestFiles.length - 1].originalContents = null; + gTestFiles[gTestFiles.length - 1].compareContents = "FromComplete\n"; + gTestFiles[gTestFiles.length - 1].comparePerms = 0o644; + gTestDirs = gTestDirsCompleteSuccess; + setupDistributionDir(); + setupSymLinks(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + checkAppBundleModTime(); + checkSymLinks(); + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile, false, true); + checkUpdateLogContents(LOG_REPLACE_SUCCESS, false, true); + checkDistributionDir(); + checkCallbackLog(); +} + +/** + * Setup the state of the distribution directory for the test. + */ +function setupDistributionDir() { + if (IS_MACOSX) { + // Create files in the old distribution directory location to verify that + // the directory and its contents are removed when there is a distribution + // directory in the new location. + let testFile = getApplyDirFile(DIR_MACOS + "distribution/testFile", true); + writeFile(testFile, "test\n"); + testFile = getApplyDirFile(DIR_MACOS + "distribution/test1/testFile", true); + writeFile(testFile, "test\n"); + } +} + +/** + * Checks the state of the distribution directory for the test. + */ +function checkDistributionDir() { + if (IS_MACOSX) { + let distributionDir = getApplyDirFile(DIR_MACOS + "distribution", true); + Assert.ok(!distributionDir.exists(), + MSG_SHOULD_NOT_EXIST + getMsgPath(distributionDir.path)); + checkUpdateLogContains(REMOVE_OLD_DIST_DIR); + } +} + +/** + * 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 (IS_UNIX && !IS_MACOSX) { + removeSymlink(); + createSymlink(); + do_register_cleanup(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 (IS_UNIX && !IS_MACOSX) { + checkSymlink(); + } +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marStageSuccessPartial.js b/toolkit/mozapps/update/tests/unit_base_updater/marStageSuccessPartial.js new file mode 100644 index 000000000..ef15326de --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marStageSuccessPartial.js @@ -0,0 +1,112 @@ +/* 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 */ + +const STATE_AFTER_STAGE = IS_SERVICE_TEST ? STATE_APPLIED_SVC : STATE_APPLIED; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesPartialSuccess; + gTestFiles[gTestFiles.length - 2].originalContents = null; + gTestFiles[gTestFiles.length - 2].compareContents = "FromPartial\n"; + gTestFiles[gTestFiles.length - 2].comparePerms = 0o644; + gTestDirs = gTestDirsPartialSuccess; + preventDistributionFiles(); + setupDistributionDir(); + setupUpdaterTest(FILE_PARTIAL_MAR, true); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + stageUpdate(true); +} + +/** + * Called after the call to stageUpdate finishes. + */ +function stageUpdateFinished() { + 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); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + checkAppBundleModTime(); + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile, false, true); + checkUpdateLogContents(LOG_REPLACE_SUCCESS, false, true, true); + checkDistributionDir(); + checkCallbackLog(); +} + +/** + * Setup the state of the distribution directory for the test. + */ +function setupDistributionDir() { + if (IS_MACOSX) { + // Create files in the old distribution directory location to verify that + // the directory and its contents are moved to the new location on update. + let testFile = getApplyDirFile(DIR_MACOS + "distribution/testFile", true); + writeFile(testFile, "test\n"); + testFile = getApplyDirFile(DIR_MACOS + "distribution/test/testFile", true); + writeFile(testFile, "test\n"); + } +} + +/** + * Checks the state of the distribution directory. + */ +function checkDistributionDir() { + let distributionDir = getApplyDirFile(DIR_RESOURCES + "distribution", true); + if (IS_MACOSX) { + Assert.ok(distributionDir.exists(), + MSG_SHOULD_EXIST + getMsgPath(distributionDir.path)); + + let testFile = getApplyDirFile(DIR_RESOURCES + "distribution/testFile", true); + Assert.ok(testFile.exists(), + MSG_SHOULD_EXIST + getMsgPath(testFile.path)); + + testFile = getApplyDirFile(DIR_RESOURCES + "distribution/test/testFile", true); + Assert.ok(testFile.exists(), + MSG_SHOULD_EXIST + getMsgPath(testFile.path)); + + distributionDir = getApplyDirFile(DIR_MACOS + "distribution", true); + Assert.ok(!distributionDir.exists(), + MSG_SHOULD_NOT_EXIST + getMsgPath(distributionDir.path)); + + checkUpdateLogContains(MOVE_OLD_DIST_DIR); + } else { + debugDump("testing that files aren't added with an add-if instruction " + + "when the file's destination directory doesn't exist"); + Assert.ok(!distributionDir.exists(), + MSG_SHOULD_NOT_EXIST + getMsgPath(distributionDir.path)); + } +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marSuccessComplete.js b/toolkit/mozapps/update/tests/unit_base_updater/marSuccessComplete.js new file mode 100644 index 000000000..1008e867f --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marSuccessComplete.js @@ -0,0 +1,96 @@ +/* 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 */ + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + preventDistributionFiles(); + setupDistributionDir(); + setupUpdaterTest(FILE_COMPLETE_MAR, true); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runUpdate(STATE_SUCCEEDED, false, 0, true); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + checkPostUpdateAppLog(); +} + +/** + * Called after the call to checkPostUpdateAppLog finishes. + */ +function checkPostUpdateAppLogFinished() { + checkAppBundleModTime(); + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(true); + checkFilesAfterUpdateSuccess(getApplyDirFile); + checkUpdateLogContents(LOG_COMPLETE_SUCCESS, false, false, true); + checkDistributionDir(); + checkCallbackLog(); +} + +/** + * Setup the state of the distribution directory for the test. + */ +function setupDistributionDir() { + if (IS_MACOSX) { + // Create files in the old distribution directory location to verify that + // the directory and its contents are moved to the new location on update. + let testFile = getApplyDirFile(DIR_MACOS + "distribution/testFile", true); + writeFile(testFile, "test\n"); + testFile = getApplyDirFile(DIR_MACOS + "distribution/test/testFile", true); + writeFile(testFile, "test\n"); + } +} + +/** + * Checks the state of the distribution directory. + */ +function checkDistributionDir() { + let distributionDir = getApplyDirFile(DIR_RESOURCES + "distribution", true); + if (IS_MACOSX) { + Assert.ok(distributionDir.exists(), + MSG_SHOULD_EXIST + getMsgPath(distributionDir.path)); + + let testFile = getApplyDirFile(DIR_RESOURCES + "distribution/testFile", true); + Assert.ok(testFile.exists(), + MSG_SHOULD_EXIST + getMsgPath(testFile.path)); + + testFile = getApplyDirFile(DIR_RESOURCES + "distribution/test/testFile", true); + Assert.ok(testFile.exists(), + MSG_SHOULD_EXIST + getMsgPath(testFile.path)); + + distributionDir = getApplyDirFile(DIR_MACOS + "distribution", true); + Assert.ok(!distributionDir.exists(), + MSG_SHOULD_NOT_EXIST + getMsgPath(distributionDir.path)); + + checkUpdateLogContains(MOVE_OLD_DIST_DIR); + } else { + debugDump("testing that files aren't added with an add-if instruction " + + "when the file's destination directory doesn't exist"); + Assert.ok(!distributionDir.exists(), + MSG_SHOULD_NOT_EXIST + getMsgPath(distributionDir.path)); + } +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marSuccessPartial.js b/toolkit/mozapps/update/tests/unit_base_updater/marSuccessPartial.js new file mode 100644 index 000000000..616390f55 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marSuccessPartial.js @@ -0,0 +1,79 @@ +/* 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 */ + +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; + gTestFiles[gTestFiles.length - 2].originalContents = null; + gTestFiles[gTestFiles.length - 2].compareContents = "FromPartial\n"; + gTestFiles[gTestFiles.length - 2].comparePerms = 0o644; + gTestDirs = gTestDirsPartialSuccess; + setupDistributionDir(); + // The third parameter will test that a relative path that contains a + // directory traversal to the post update binary doesn't execute. + setupUpdaterTest(FILE_PARTIAL_MAR, false, "test/../"); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runUpdate(STATE_SUCCEEDED, false, 0, true); +} + +/** + * Called after the call to runUpdate finishes. + */ +function runUpdateFinished() { + checkAppBundleModTime(); + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, + "the update state" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateSuccess(getApplyDirFile); + checkUpdateLogContents(LOG_PARTIAL_SUCCESS); + checkDistributionDir(); + checkCallbackLog(); +} + +/** + * Setup the state of the distribution directory for the test. + */ +function setupDistributionDir() { + if (IS_MACOSX) { + // Create files in the old distribution directory location to verify that + // the directory and its contents are removed when there is a distribution + // directory in the new location. + let testFile = getApplyDirFile(DIR_MACOS + "distribution/testFile", true); + writeFile(testFile, "test\n"); + testFile = getApplyDirFile(DIR_MACOS + "distribution/test/testFile", true); + writeFile(testFile, "test\n"); + } +} + +/** + * Checks the state of the distribution directory. + */ +function checkDistributionDir() { + if (IS_MACOSX) { + let distributionDir = getApplyDirFile(DIR_MACOS + "distribution", true); + Assert.ok(!distributionDir.exists(), + MSG_SHOULD_NOT_EXIST + getMsgPath(distributionDir.path)); + checkUpdateLogContains(REMOVE_OLD_DIST_DIR); + } +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marVersionDowngrade.js b/toolkit/mozapps/update/tests/unit_base_updater/marVersionDowngrade.js new file mode 100644 index 000000000..86a2eb821 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marVersionDowngrade.js @@ -0,0 +1,51 @@ +/* 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/. + */ + +/* Test version downgrade MAR security check */ + +function run_test() { + if (!MOZ_VERIFY_MAR_SIGNATURE) { + return; + } + + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_OLD_VERSION_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + // 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_VERSION_DOWNGRADE_ERROR, false, (USE_EXECV ? 0 : 1), + false); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_FAILED, + "the update state" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).errorCode, VERSION_DOWNGRADE_ERROR, + "the update errorCode" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(STATE_FAILED_VERSION_DOWNGRADE_ERROR); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marWrongChannel.js b/toolkit/mozapps/update/tests/unit_base_updater/marWrongChannel.js new file mode 100644 index 000000000..6db906fbc --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/marWrongChannel.js @@ -0,0 +1,51 @@ +/* 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/. + */ + +/* Test product/channel MAR security check */ + +function run_test() { + if (!MOZ_VERIFY_MAR_SIGNATURE) { + return; + } + + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_WRONG_CHANNEL_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + // 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_MAR_CHANNEL_MISMATCH_ERROR, false, (USE_EXECV ? 0 : 1), + false); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + Assert.equal(readStatusState(), STATE_NONE, + "the status file state" + MSG_SHOULD_EQUAL); + Assert.ok(!gUpdateManager.activeUpdate, + "the active update should not be defined"); + Assert.equal(gUpdateManager.updateCount, 1, + "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_FAILED, + "the update state" + MSG_SHOULD_EQUAL); + Assert.equal(gUpdateManager.getUpdateAt(0).errorCode, MAR_CHANNEL_MISMATCH_ERROR, + "the update errorCode" + MSG_SHOULD_EQUAL); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + checkUpdateLogContains(STATE_FAILED_MAR_CHANNEL_MISMATCH_ERROR); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/xpcshell.ini b/toolkit/mozapps/update/tests/unit_base_updater/xpcshell.ini new file mode 100644 index 000000000..2b77bee7a --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/xpcshell.ini @@ -0,0 +1,136 @@ +; 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/. + +; Tests that require the updater binary. These tests should never run on Android +; which doesn't use the updater binary as other applications do and are excluded +; from running the tests in the moz.build file. + +[DEFAULT] +tags = appupdate +head = head_update.js +tail = + +[invalidArgCallbackFileNotInInstallDirFailure.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[invalidArgCallbackFilePathTooLongFailure.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[invalidArgInstallDirPathTooLongFailure.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[invalidArgInstallDirPathTraversalFailure.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[invalidArgInstallWorkingDirPathNotSameFailure_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[invalidArgPatchDirPathTraversalFailure.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[invalidArgStageDirNotInInstallDirFailure_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[invalidArgWorkingDirPathLocalUNCFailure_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[invalidArgWorkingDirPathRelativeFailure.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[marSuccessComplete.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[marSuccessPartial.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[marFailurePartial.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[marStageSuccessComplete.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[marStageSuccessPartial.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[marVersionDowngrade.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 and mar signing +[marWrongChannel.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 and mar signing +[marStageFailurePartial.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[marCallbackAppSuccessComplete_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marCallbackAppSuccessPartial_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marCallbackAppStageSuccessComplete_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marCallbackAppStageSuccessPartial_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marAppInUseSuccessComplete.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[marAppInUseStageSuccessComplete_unix.js] +skip-if = os == 'win' +reason = not a Windows test +[marAppInUseStageFailureComplete_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marFileLockedFailureComplete_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marFileLockedFailurePartial_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marFileLockedStageFailureComplete_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marFileLockedStageFailurePartial_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marFileInUseSuccessComplete_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marFileInUseSuccessPartial_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marRMRFDirFileInUseSuccessComplete_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marRMRFDirFileInUseSuccessPartial_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marFileInUseStageFailureComplete_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marFileInUseStageFailurePartial_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marRMRFDirFileInUseStageFailureComplete_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marRMRFDirFileInUseStageFailurePartial_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marAppApplyDirLockedStageFailure_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marAppApplyUpdateAppBinInUseStageSuccess_win.js] +skip-if = os != 'win' || debug && (os_version == '5.1' || os_version == '5.2') +reason = Windows only test and bug 1291985 +[marAppApplyUpdateSuccess.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[marAppApplyUpdateStageSuccess.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 +[marAppApplyUpdateStageOldVersionFailure.js] +skip-if = os == 'win' && debug && (os_version == '5.1' || os_version == '5.2') +reason = bug 1291985 |