Bug 1875502 - Pre: Update tests to accomodate async readyUpdate r=nalexander,application-update-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D209116
This commit is contained in:
Robin Steuber
2024-05-15 17:06:13 +00:00
parent e58f96019c
commit bcc4b4f167
19 changed files with 125 additions and 80 deletions

View File

@@ -32,10 +32,10 @@ add_task(async function whats_new_page() {
Ci.nsIUpdateManager
);
await TestUtils.waitForCondition(
() => !um.readyUpdate,
async () => !(await um.getReadyUpdate()),
"Waiting for the ready update to be removed"
);
ok(!um.readyUpdate, "There should not be a ready update");
ok(!(await um.getReadyUpdate()), "There should not be a ready update");
let history;
await TestUtils.waitForCondition(async () => {
history = await um.getHistory();

View File

@@ -33,10 +33,10 @@ add_task(async function nimbus_whats_new_page() {
Ci.nsIUpdateManager
);
await TestUtils.waitForCondition(
() => !um.readyUpdate,
async () => !(await um.getReadyUpdate()),
"Waiting for the ready update to be removed"
);
ok(!um.readyUpdate, "There should not be a ready update");
ok(!(await um.getReadyUpdate()), "There should not be a ready update");
let history;
await TestUtils.waitForCondition(async () => {
history = await um.getHistory();

View File

@@ -228,7 +228,7 @@ async function processUpdateStep(step) {
);
} else {
Assert.ok(
!gUpdateManager.readyUpdate,
!(await gUpdateManager.getReadyUpdate()),
"There should not be a ready update"
);
Assert.ok(

View File

@@ -69,7 +69,7 @@ async function changeAndVerifyUpdateWrites({
`We should ${expectPrompt ? "" : "not "}be prompted`
);
is(
!!gUpdateManager.readyUpdate,
!!(await gUpdateManager.getReadyUpdate()),
expectRemainingUpdate,
`There should ${expectRemainingUpdate ? "" : "not "}be a ready update`
);
@@ -92,7 +92,10 @@ add_task(async function testUpdateAutoPrefUI() {
!gUpdateManager.downloadingUpdate,
"There should not be a downloading update"
);
ok(!gUpdateManager.readyUpdate, "There should not be a ready update");
ok(
!(await gUpdateManager.getReadyUpdate()),
"There should not be a ready update"
);
info("Disable automatic updates and check that works.");
await changeAndVerifyPref(tab, false);
@@ -100,7 +103,10 @@ add_task(async function testUpdateAutoPrefUI() {
!gUpdateManager.downloadingUpdate,
"There should not be a downloading update"
);
ok(!gUpdateManager.readyUpdate, "There should not be a ready update");
ok(
!(await gUpdateManager.getReadyUpdate()),
"There should not be a ready update"
);
let patchProps = { state: STATE_PENDING };
let patches = getLocalPatchString(patchProps);
@@ -109,7 +115,10 @@ add_task(async function testUpdateAutoPrefUI() {
writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true);
writeStatusFile(STATE_PENDING);
reloadUpdateManagerData();
ok(!!gUpdateManager.readyUpdate, "There should be a ready update");
ok(
!!(await gUpdateManager.getReadyUpdate()),
"There should be a ready update"
);
let { prompt } = Services;
registerCleanupFunction(() => {

View File

@@ -22,7 +22,7 @@ add_task(async function doorhanger_bc_downloaded_disableBITS() {
let patch = getPatchOfType(
"partial",
gUpdateManager.readyUpdate
await gUpdateManager.getReadyUpdate()
).QueryInterface(Ci.nsIWritablePropertyBag);
ok(
!patch.getProperty("bitsId"),

View File

@@ -44,9 +44,10 @@ add_task(async function elevation_dialog() {
() => !Services.wm.getMostRecentWindow("Update:Elevation"),
"The Update Elevation dialog should have closed"
);
ok(!!gUpdateManager.readyUpdate, "There should be a ready update");
let readyUpdate = await gUpdateManager.getReadyUpdate();
ok(!!readyUpdate, "There should be a ready update");
is(
gUpdateManager.readyUpdate.state,
readyUpdate.state,
STATE_PENDING_ELEVATE,
"The ready update state should equal " + STATE_PENDING_ELEVATE
);
@@ -64,7 +65,8 @@ add_task(async function elevation_dialog() {
() => !Services.wm.getMostRecentWindow("Update:Elevation"),
"The Update Elevation dialog should have closed"
);
ok(!gUpdateManager.readyUpdate, "There should not be a ready update");
readyUpdate = await gUpdateManager.getReadyUpdate();
ok(!readyUpdate, "There should not be a ready update");
is(
readStatusFile(),
STATE_NONE,
@@ -79,9 +81,10 @@ add_task(async function elevation_dialog() {
() => !Services.wm.getMostRecentWindow("Update:Elevation"),
"The Update Elevation dialog should have closed"
);
ok(!!gUpdateManager.readyUpdate, "There should be a ready update");
readyUpdate = await gUpdateManager.getReadyUpdate();
ok(!!readyUpdate, "There should be a ready update");
is(
gUpdateManager.readyUpdate.state,
readyUpdate.state,
STATE_PENDING_ELEVATE,
"The active update state should equal " + STATE_PENDING_ELEVATE
);

View File

@@ -576,10 +576,9 @@ function runDoorhangerUpdateTest(params, steps) {
);
if (checkActiveUpdate) {
let activeUpdate =
checkActiveUpdate.state == STATE_DOWNLOADING
? gUpdateManager.downloadingUpdate
: gUpdateManager.readyUpdate;
let activeUpdate = await (checkActiveUpdate.state == STATE_DOWNLOADING
? gUpdateManager.downloadingUpdate
: gUpdateManager.getReadyUpdate());
ok(!!activeUpdate, "There should be an active update");
is(
activeUpdate.state,
@@ -591,7 +590,10 @@ function runDoorhangerUpdateTest(params, steps) {
!gUpdateManager.downloadingUpdate,
"There should not be a downloading update"
);
ok(!gUpdateManager.readyUpdate, "There should not be a ready update");
ok(
!(await gUpdateManager.getReadyUpdate()),
"There should not be a ready update"
);
}
let buttonEl = getNotificationButton(window, notificationId, button);
@@ -753,10 +755,9 @@ function runAboutDialogUpdateTest(params, steps) {
);
if (checkActiveUpdate) {
let activeUpdate =
checkActiveUpdate.state == STATE_DOWNLOADING
? gUpdateManager.downloadingUpdate
: gUpdateManager.readyUpdate;
let activeUpdate = await (checkActiveUpdate.state == STATE_DOWNLOADING
? gUpdateManager.downloadingUpdate
: gUpdateManager.getReadyUpdate());
ok(!!activeUpdate, "There should be an active update");
is(
activeUpdate.state,
@@ -768,7 +769,10 @@ function runAboutDialogUpdateTest(params, steps) {
!gUpdateManager.downloadingUpdate,
"There should not be a downloading update"
);
ok(!gUpdateManager.readyUpdate, "There should not be a ready update");
ok(
!(await gUpdateManager.getReadyUpdate()),
"There should not be a ready update"
);
}
// Some tests just want to stop at the downloading state. These won't
@@ -1060,10 +1064,9 @@ function runAboutPrefsUpdateTest(params, steps) {
);
if (checkActiveUpdate) {
let activeUpdate =
checkActiveUpdate.state == STATE_DOWNLOADING
? gUpdateManager.downloadingUpdate
: gUpdateManager.readyUpdate;
let activeUpdate = await (checkActiveUpdate.state == STATE_DOWNLOADING
? gUpdateManager.downloadingUpdate
: gUpdateManager.getReadyUpdate());
ok(!!activeUpdate, "There should be an active update");
is(
activeUpdate.state,
@@ -1075,7 +1078,10 @@ function runAboutPrefsUpdateTest(params, steps) {
!gUpdateManager.downloadingUpdate,
"There should not be a downloading update"
);
ok(!gUpdateManager.readyUpdate, "There should not be a ready update");
ok(
!(await gUpdateManager.getReadyUpdate()),
"There should not be a ready update"
);
}
if (panelId == "downloading") {

View File

@@ -1312,10 +1312,9 @@ async function checkUpdateManager(
aUpdateErrCode,
aUpdateCount
) {
let activeUpdate =
aUpdateStatusState == STATE_DOWNLOADING
? gUpdateManager.downloadingUpdate
: gUpdateManager.readyUpdate;
let activeUpdate = await (aUpdateStatusState == STATE_DOWNLOADING
? gUpdateManager.downloadingUpdate
: gUpdateManager.getReadyUpdate());
Assert.equal(
readStatusState(),
aStatusFileState,
@@ -2286,7 +2285,7 @@ function checkSymlink() {
/**
* Sets the active update and related information for updater tests.
*/
function setupActiveUpdate() {
async function setupActiveUpdate() {
let pendingState = gIsServiceTest ? STATE_PENDING_SVC : STATE_PENDING;
let patchProps = { state: pendingState };
let patches = getLocalPatchString(patchProps);
@@ -2295,7 +2294,10 @@ function setupActiveUpdate() {
writeVersionFile(DEFAULT_UPDATE_VERSION);
writeStatusFile(pendingState);
reloadUpdateManagerData();
Assert.ok(!!gUpdateManager.readyUpdate, "the ready update should be defined");
Assert.ok(
!!(await gUpdateManager.getReadyUpdate()),
"the ready update should be defined"
);
}
/**
@@ -2357,7 +2359,7 @@ async function stageUpdate(
);
Assert.equal(
gUpdateManager.readyUpdate.state,
(await gUpdateManager.getReadyUpdate()).state,
aStateAfterStage,
"the update state" + MSG_SHOULD_EQUAL
);
@@ -3299,7 +3301,7 @@ async function setupUpdaterTest(
});
if (aSetupActiveUpdate) {
setupActiveUpdate();
await setupActiveUpdate();
}
if (aPostUpdateAsync !== null) {

View File

@@ -26,7 +26,10 @@ async function run_test() {
!gUpdateManager.downloadingUpdate,
"there should not be a downloading update"
);
Assert.ok(!gUpdateManager.readyUpdate, "there should not be a ready update");
Assert.ok(
!(await gUpdateManager.getReadyUpdate()),
"there should not be a ready update"
);
const history = await gUpdateManager.getHistory();
Assert.equal(
history.length,

View File

@@ -24,7 +24,10 @@ async function run_test() {
!gUpdateManager.downloadingUpdate,
"there should not be a downloading update"
);
Assert.ok(!gUpdateManager.readyUpdate, "there should not be a ready update");
Assert.ok(
!(await gUpdateManager.getReadyUpdate()),
"there should not be a ready update"
);
const history = await gUpdateManager.getHistory();
Assert.equal(
history.length,

View File

@@ -25,7 +25,10 @@ async function run_test() {
!gUpdateManager.downloadingUpdate,
"there should not be a downloading update"
);
Assert.ok(!gUpdateManager.readyUpdate, "there should not be a ready update");
Assert.ok(
!(await gUpdateManager.getReadyUpdate()),
"there should not be a ready update"
);
const history = await gUpdateManager.getHistory();
Assert.equal(
history.length,

View File

@@ -23,7 +23,10 @@ async function run_test() {
!gUpdateManager.downloadingUpdate,
"there should not be a downloading update"
);
Assert.ok(!gUpdateManager.readyUpdate, "there should not be a ready update");
Assert.ok(
!(await gUpdateManager.getReadyUpdate()),
"there should not be a ready update"
);
const history = await gUpdateManager.getHistory();
Assert.equal(
history.length,

View File

@@ -23,7 +23,10 @@ async function run_test() {
!gUpdateManager.downloadingUpdate,
"there should not be a downloading update"
);
Assert.ok(!gUpdateManager.readyUpdate, "there should not be a ready update");
Assert.ok(
!(await gUpdateManager.getReadyUpdate()),
"there should not be a ready update"
);
const history = await gUpdateManager.getHistory();
Assert.equal(
history.length,

View File

@@ -27,7 +27,10 @@ async function run_test() {
!gUpdateManager.downloadingUpdate,
"there should not be a downloading update"
);
Assert.ok(!gUpdateManager.readyUpdate, "there should not be a ready update");
Assert.ok(
!(await gUpdateManager.getReadyUpdate()),
"there should not be a ready update"
);
const history = await gUpdateManager.getHistory();
Assert.equal(
history.length,

View File

@@ -105,7 +105,10 @@ async function testCleanupSuccessLogsFIFO(
!gUpdateManager.downloadingUpdate,
"there should not be a downloading update"
);
Assert.ok(!gUpdateManager.readyUpdate, "there should not be a ready update");
Assert.ok(
!(await gUpdateManager.getReadyUpdate()),
"there should not be a ready update"
);
const history = await gUpdateManager.getHistory();
Assert.equal(
history.length,

View File

@@ -73,9 +73,9 @@ async function downloadUpdate(appUpdateAuto, onDownloadStartCallback) {
}
let waitToStartPromise = new Promise(resolve => {
let listener = {
onStartRequest: _aRequest => {
onStartRequest: async _aRequest => {
gAUS.removeDownloadListener(listener);
onDownloadStartCallback();
await onDownloadStartCallback();
resolve();
},
onProgress: (_aRequest, _aContext, _aProgress, _aMaxProgress) => {},
@@ -197,11 +197,9 @@ async function multi_update_test(appUpdateAuto) {
prepareToDownloadVersion(FIRST_UPDATE_VERSION);
await downloadUpdate(appUpdateAuto, () => {
Assert.ok(
!gUpdateManager.readyUpdate,
"There should not be a ready update yet"
);
await downloadUpdate(appUpdateAuto, async () => {
const readyUpdate = await gUpdateManager.getReadyUpdate();
Assert.ok(!readyUpdate, "There should not be a ready update yet");
Assert.ok(
!!gUpdateManager.downloadingUpdate,
"First update download should be in downloadingUpdate"
@@ -218,21 +216,19 @@ async function multi_update_test(appUpdateAuto) {
);
});
let readyUpdate = await gUpdateManager.getReadyUpdate();
Assert.ok(
!gUpdateManager.downloadingUpdate,
"First update download should no longer be in downloadingUpdate"
);
Assert.ok(
!!gUpdateManager.readyUpdate,
"First update download should be in readyUpdate"
);
Assert.ok(!!readyUpdate, "First update download should be in readyUpdate");
Assert.equal(
gUpdateManager.readyUpdate.state,
readyUpdate.state,
STATE_PENDING,
"readyUpdate should be pending"
);
Assert.equal(
gUpdateManager.readyUpdate.appVersion,
readyUpdate.appVersion,
FIRST_UPDATE_VERSION,
"readyUpdate version should be match the version of the first update"
);
@@ -242,21 +238,22 @@ async function multi_update_test(appUpdateAuto) {
"Updater state should be pending"
);
let existingUpdate = gUpdateManager.readyUpdate;
let existingUpdate = readyUpdate;
await testUpdateDoesNotDownload();
readyUpdate = await gUpdateManager.getReadyUpdate();
Assert.equal(
gUpdateManager.readyUpdate,
readyUpdate,
existingUpdate,
"readyUpdate should not have changed when no newer update is available"
);
Assert.equal(
gUpdateManager.readyUpdate.state,
readyUpdate.state,
STATE_PENDING,
"readyUpdate should still be pending"
);
Assert.equal(
gUpdateManager.readyUpdate.appVersion,
readyUpdate.appVersion,
FIRST_UPDATE_VERSION,
"readyUpdate version should be match the version of the first update"
);
@@ -271,18 +268,19 @@ async function multi_update_test(appUpdateAuto) {
prepareToDownloadVersion(SECOND_UPDATE_VERSION, true);
await testUpdateDoesNotDownload();
readyUpdate = await gUpdateManager.getReadyUpdate();
Assert.equal(
gUpdateManager.readyUpdate,
readyUpdate,
existingUpdate,
"readyUpdate should not have changed when no newer partial update is available"
);
Assert.equal(
gUpdateManager.readyUpdate.state,
readyUpdate.state,
STATE_PENDING,
"readyUpdate should still be pending"
);
Assert.equal(
gUpdateManager.readyUpdate.appVersion,
readyUpdate.appVersion,
FIRST_UPDATE_VERSION,
"readyUpdate version should be match the version of the first update"
);
@@ -294,7 +292,8 @@ async function multi_update_test(appUpdateAuto) {
prepareToDownloadVersion(SECOND_UPDATE_VERSION);
await downloadUpdate(appUpdateAuto, () => {
await downloadUpdate(appUpdateAuto, async () => {
readyUpdate = await gUpdateManager.getReadyUpdate();
Assert.ok(
!!gUpdateManager.downloadingUpdate,
"Second update download should be in downloadingUpdate"
@@ -305,16 +304,16 @@ async function multi_update_test(appUpdateAuto) {
"downloadingUpdate should be downloading"
);
Assert.ok(
!!gUpdateManager.readyUpdate,
!!readyUpdate,
"First update download should still be in readyUpdate"
);
Assert.equal(
gUpdateManager.readyUpdate.state,
readyUpdate.state,
STATE_PENDING,
"readyUpdate should still be pending"
);
Assert.equal(
gUpdateManager.readyUpdate.appVersion,
readyUpdate.appVersion,
FIRST_UPDATE_VERSION,
"readyUpdate version should be match the version of the first update"
);
@@ -325,21 +324,19 @@ async function multi_update_test(appUpdateAuto) {
);
});
readyUpdate = await gUpdateManager.getReadyUpdate();
Assert.ok(
!gUpdateManager.downloadingUpdate,
"Second update download should no longer be in downloadingUpdate"
);
Assert.ok(
!!gUpdateManager.readyUpdate,
"Second update download should be in readyUpdate"
);
Assert.ok(!!readyUpdate, "Second update download should be in readyUpdate");
Assert.equal(
gUpdateManager.readyUpdate.state,
readyUpdate.state,
STATE_PENDING,
"readyUpdate should be pending"
);
Assert.equal(
gUpdateManager.readyUpdate.appVersion,
readyUpdate.appVersion,
SECOND_UPDATE_VERSION,
"readyUpdate version should be match the version of the second update"
);
@@ -356,7 +353,7 @@ async function multi_update_test(appUpdateAuto) {
// Second parameter forces a complete MAR download.
prepareToDownloadVersion(FIRST_UPDATE_VERSION, true);
await downloadUpdate(appUpdateAuto, () => {
await downloadUpdate(appUpdateAuto, async () => {
Assert.equal(
gUpdateManager.downloadingUpdate.selectedPatch.type,
"complete",
@@ -364,8 +361,9 @@ async function multi_update_test(appUpdateAuto) {
);
});
readyUpdate = await gUpdateManager.getReadyUpdate();
Assert.equal(
gUpdateManager.readyUpdate.selectedPatch.type,
readyUpdate.selectedPatch.type,
"complete",
"First update download should be a complete patch"
);

View File

@@ -50,7 +50,7 @@ add_task(async function onlyDownloadUpdatesThisSession() {
await downloadUpdate();
Assert.ok(
!gUpdateManager.readyUpdate,
!(await gUpdateManager.getReadyUpdate()),
"There should not be a ready update. The update should still be downloading"
);
Assert.ok(

View File

@@ -159,7 +159,10 @@ async function run_test() {
!gUpdateManager.downloadingUpdate,
"there should not be a downloading update"
);
Assert.ok(!gUpdateManager.readyUpdate, "there should not be a ready update");
Assert.ok(
!(await gUpdateManager.getReadyUpdate()),
"there should not be a ready update"
);
const history = await gUpdateManager.getHistory();
Assert.equal(
history.length,

View File

@@ -80,7 +80,10 @@ async function run_test() {
!gUpdateManager.downloadingUpdate,
"there should not be a downloading update"
);
Assert.ok(!gUpdateManager.readyUpdate, "there should not be a ready update");
Assert.ok(
!(await gUpdateManager.getReadyUpdate()),
"there should not be a ready update"
);
const history = await gUpdateManager.getHistory();
Assert.equal(
history.length,