From ebe64856b40dc7ec6c08892d71c709bd394b2d41 Mon Sep 17 00:00:00 2001 From: Micah Tigley Date: Tue, 14 Sep 2021 13:50:27 +0000 Subject: [PATCH] Bug 1724319 - Fix remaining failing tests in browser/components/downloads/test/browser. r=mhowell Differential Revision: https://phabricator.services.mozilla.com/D125294 --- .../browser/browser_download_overwrite.js | 89 +++++++++++-------- .../browser/browser_image_mimetype_issues.js | 6 ++ 2 files changed, 60 insertions(+), 35 deletions(-) diff --git a/browser/components/downloads/test/browser/browser_download_overwrite.js b/browser/components/downloads/test/browser/browser_download_overwrite.js index 71eb715315ff..1e79c34cd355 100644 --- a/browser/components/downloads/test/browser/browser_download_overwrite.js +++ b/browser/components/downloads/test/browser/browser_download_overwrite.js @@ -23,7 +23,10 @@ add_task(async function setup() { ok(gTestTargetFile.exists(), "We created a test file."); await SpecialPowers.pushPrefEnv({ - set: [["browser.download.useDownloadDir", false]], + set: [ + ["browser.download.improvements_to_download_panel", true], + ["browser.download.useDownloadDir", false], + ], }); // Set up the file picker. let destDir = gTestTargetFile.parent; @@ -31,6 +34,7 @@ add_task(async function setup() { MockFilePicker.displayDirectory = destDir; MockFilePicker.showCallback = function(fp) { MockFilePicker.setFiles([gTestTargetFile]); + return MockFilePicker.returnOK; }; registerCleanupFunction(function() { MockFilePicker.cleanup(); @@ -57,18 +61,26 @@ add_task(async function test_overwrite_does_not_delete_first() { }); let dialogPromise = BrowserTestUtils.domWindowOpenedAndLoaded(); + // Now try and download a thing to the file: await BrowserTestUtils.withNewTab(TEST_ROOT + "foo.txt", async function() { - let dialog = await dialogPromise; - info("Got dialog."); - let saveEl = dialog.document.getElementById("save"); - dialog.document.getElementById("mode").selectedItem = saveEl; - // Allow accepting the dialog (to avoid the delay helper): - dialog.document - .getElementById("unknownContentType") - .getButton("accept").disabled = false; - // Then accept it: - dialog.document.querySelector("dialog").acceptDialog(); + if ( + !Services.prefs.getBoolPref( + "browser.download.improvements_to_download_panel" + ) + ) { + let dialog = await dialogPromise; + info("Got dialog."); + let saveEl = dialog.document.getElementById("save"); + dialog.document.getElementById("mode").selectedItem = saveEl; + // Allow accepting the dialog (to avoid the delay helper): + dialog.document + .getElementById("unknownContentType") + .getButton("accept").disabled = false; + // Then accept it: + dialog.document.querySelector("dialog").acceptDialog(); + } + ok(await transferCompletePromise, "download should succeed"); ok( gTestTargetFile.exists(), @@ -87,32 +99,39 @@ add_task(async function test_overwrite_does_not_delete_first() { add_task(async function test_overwrite_works() { let dialogPromise = BrowserTestUtils.domWindowOpenedAndLoaded(); let publicDownloads = await Downloads.getList(Downloads.PUBLIC); + // First ensure we catch the download finishing. + let downloadFinishedPromise = new Promise(resolve => { + publicDownloads.addView({ + onDownloadChanged(download) { + info("Download changed!"); + if (download.succeeded || download.error) { + info("Download succeeded or errored"); + publicDownloads.removeView(this); + publicDownloads.removeFinished(); + resolve(download); + } + }, + }); + }); // Now try and download a thing to the file: await BrowserTestUtils.withNewTab(TEST_ROOT + "foo.txt", async function() { - let dialog = await dialogPromise; - info("Got dialog."); - // First ensure we catch the download finishing. - let downloadFinishedPromise = new Promise(resolve => { - publicDownloads.addView({ - onDownloadChanged(download) { - info("Download changed!"); - if (download.succeeded || download.error) { - info("Download succeeded or errored"); - publicDownloads.removeView(this); - publicDownloads.removeFinished(); - resolve(download); - } - }, - }); - }); - let saveEl = dialog.document.getElementById("save"); - dialog.document.getElementById("mode").selectedItem = saveEl; - // Allow accepting the dialog (to avoid the delay helper): - dialog.document - .getElementById("unknownContentType") - .getButton("accept").disabled = false; - // Then accept it: - dialog.document.querySelector("dialog").acceptDialog(); + if ( + !Services.prefs.getBoolPref( + "browser.download.improvements_to_download_panel" + ) + ) { + let dialog = await dialogPromise; + info("Got dialog."); + let saveEl = dialog.document.getElementById("save"); + dialog.document.getElementById("mode").selectedItem = saveEl; + // Allow accepting the dialog (to avoid the delay helper): + dialog.document + .getElementById("unknownContentType") + .getButton("accept").disabled = false; + // Then accept it: + dialog.document.querySelector("dialog").acceptDialog(); + } + info("wait for download to finish"); let download = await downloadFinishedPromise; ok(download.succeeded, "Download should succeed"); diff --git a/browser/components/downloads/test/browser/browser_image_mimetype_issues.js b/browser/components/downloads/test/browser/browser_image_mimetype_issues.js index 096d81120f49..f1fb8ea1aef3 100644 --- a/browser/components/downloads/test/browser/browser_image_mimetype_issues.js +++ b/browser/components/downloads/test/browser/browser_image_mimetype_issues.js @@ -56,6 +56,12 @@ add_task(async function test_save_image_webp_with_jpeg_extension() { * Test with the "save link as" context menu. */ add_task(async function test_save_link_webp_with_jpeg_extension() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["browser.download.improvements_to_download_panel", true], + ["browser.download.useDownloadDir", false], + ], + }); await BrowserTestUtils.withNewTab( `data:text/html,Nice image`, async browser => {