Bug 1681619 - in browser_extension_correction.js clear finished downloads to avoid intermittents, r=mak

The finished downloads were removed, which meant that the next time the
download code asynchronously refreshed them, they were smaller than the last
time that they checked, which meant we got another `onChange` notification
for the download (which would still be finished / in error state), which
confused the test which expected 1 notification per download.

To avoid this, we clear finished downloads after each iteration inside the
test, instead of at the end.

Differential Revision: https://phabricator.services.mozilla.com/D100149
This commit is contained in:
Gijs Kruitbosch
2020-12-22 11:08:19 +00:00
parent 845b782213
commit 5a3ba53f29

View File

@@ -8,23 +8,18 @@ const TEST_PATH = getRootDirectory(gTestPath).replace(
"https://example.com"
);
let gPathsToRemove = [];
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [["browser.download.useDownloadDir", true]],
});
registerCleanupFunction(async () => {
let publicList = await Downloads.getList(Downloads.PUBLIC);
let downloads = await publicList.getAll();
for (let download of downloads) {
if (download.target.exists) {
try {
info("removing " + download.target.path);
await IOUtils.remove(download.target.path);
} catch (ex) {
/* ignore */
}
}
for (let path of gPathsToRemove) {
// IOUtils.remove ignores non-existing files out of the box.
await IOUtils.remove(path);
}
let publicList = await Downloads.getList(Downloads.PUBLIC);
await publicList.removeFinished();
});
});
@@ -86,7 +81,11 @@ async function checkDownloadWithExtensionState(
expectedName,
`Downloaded file should also match ${expectedName}`
);
await IOUtils.remove(download.target.path);
gPathsToRemove.push(download.target.path);
let pathToRemove = download.target.path;
// Avoid one file interfering with subsequent files.
await publicList.removeFinished();
await IOUtils.remove(pathToRemove);
} else {
// We just cancel out for files that would end up without a path, as we'd
// prompt for a filename.