diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/url/tests/browser_download_after_revoke.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/url/tests/browser_download_after_revoke.js')
-rw-r--r-- | dom/url/tests/browser_download_after_revoke.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/dom/url/tests/browser_download_after_revoke.js b/dom/url/tests/browser_download_after_revoke.js new file mode 100644 index 0000000000..be8ad96e70 --- /dev/null +++ b/dom/url/tests/browser_download_after_revoke.js @@ -0,0 +1,94 @@ +async function test() { + waitForExplicitFinish(); + const target = "http://example.com/browser/dom/url/tests/empty.html"; + info("Loading download page..."); + let tab = BrowserTestUtils.addTab(gBrowser, target); + registerCleanupFunction(function () { + gBrowser.removeTab(tab); + window.restore(); + }); + gBrowser.selectedTab = tab; + BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, target).then( + async () => { + info("Page loaded."); + let allDownloads = await Downloads.getList(Downloads.ALL); + let started = new Promise(resolve => { + if ( + Services.prefs.getBoolPref( + "browser.download.always_ask_before_handling_new_types", + false + ) + ) { + // If the download modal is enabled, wait for it to open and declare the + // download to have begun when we see it. + let listener = { + onOpenWindow(aXULWindow) { + info("Download modal shown..."); + Services.wm.removeListener(listener); + + let domwindow = aXULWindow.docShell.domWindow; + function onModalLoad() { + domwindow.removeEventListener("load", onModalLoad, true); + + is( + domwindow.document.location.href, + "chrome://mozapps/content/downloads/unknownContentType.xhtml", + "Download modal loaded..." + ); + + domwindow.close(); + info("Download modal closed."); + resolve(); + } + + domwindow.addEventListener("load", onModalLoad, true); + }, + onCloseWindow(aXULWindow) {}, + }; + + Services.wm.addListener(listener); + } else { + // With no download modal, the download will begin on its own, so we need + // to wait to be notified by the downloads list when that happens. + let downloadView = { + onDownloadAdded(download) { + ok(true, "Download was started."); + download.cancel(); + allDownloads.removeView(this); + allDownloads.removeFinished(); + resolve(); + }, + }; + allDownloads.addView(downloadView); + } + }); + + let revoked = SpecialPowers.spawn( + tab.linkedBrowser, + [], + () => + new Promise(resolve => { + info("Creating BlobURL..."); + let blob = new content.Blob(["test"], { type: "text/plain" }); + let url = content.URL.createObjectURL(blob); + + let link = content.document.createElement("a"); + link.href = url; + link.download = "example.txt"; + content.document.body.appendChild(link); + info("Clicking HTMLAnchorElement..."); + link.click(); + + content.URL.revokeObjectURL(url); + info("BlobURL revoked."); + resolve(); + }) + ); + + info("Waiting for async activities..."); + await Promise.all([revoked, started]); + ok(true, "Exiting test."); + finish(); + } + ); +} |