1 async function test() {
2 waitForExplicitFinish();
3 const target = "http://example.com/browser/dom/url/tests/empty.html";
4 info("Loading download page...");
5 let tab = BrowserTestUtils.addTab(gBrowser, target);
6 registerCleanupFunction(function () {
7 gBrowser.removeTab(tab);
10 gBrowser.selectedTab = tab;
11 BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, target).then(
14 let allDownloads = await Downloads.getList(Downloads.ALL);
15 let started = new Promise(resolve => {
17 Services.prefs.getBoolPref(
18 "browser.download.always_ask_before_handling_new_types",
22 // If the download modal is enabled, wait for it to open and declare the
23 // download to have begun when we see it.
25 onOpenWindow(aXULWindow) {
26 info("Download modal shown...");
27 Services.wm.removeListener(listener);
29 let domwindow = aXULWindow.docShell.domWindow;
30 function onModalLoad() {
31 domwindow.removeEventListener("load", onModalLoad, true);
34 domwindow.document.location.href,
35 "chrome://mozapps/content/downloads/unknownContentType.xhtml",
36 "Download modal loaded..."
40 info("Download modal closed.");
44 domwindow.addEventListener("load", onModalLoad, true);
49 Services.wm.addListener(listener);
51 // With no download modal, the download will begin on its own, so we need
52 // to wait to be notified by the downloads list when that happens.
54 onDownloadAdded(download) {
55 ok(true, "Download was started.");
57 allDownloads.removeView(this);
58 allDownloads.removeFinished();
62 allDownloads.addView(downloadView);
66 let revoked = SpecialPowers.spawn(
70 new Promise(resolve => {
71 info("Creating BlobURL...");
72 let blob = new content.Blob(["test"], { type: "text/plain" });
73 let url = content.URL.createObjectURL(blob);
75 let link = content.document.createElement("a");
77 link.download = "example.txt";
78 content.document.body.appendChild(link);
79 info("Clicking HTMLAnchorElement...");
82 content.URL.revokeObjectURL(url);
83 info("BlobURL revoked.");
88 info("Waiting for async activities...");
89 await Promise.all([revoked, started]);
90 ok(true, "Exiting test.");