michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: let winObserver = function(win, topic) { michael@0: if (topic == "domwindowopened") { michael@0: win.addEventListener("load", function onLoadWindow() { michael@0: win.removeEventListener("load", onLoadWindow, false); michael@0: michael@0: if (win.document.documentURI == michael@0: "chrome://mozapps/content/downloads/unknownContentType.xul") { michael@0: ok(true, "Download dialog shown"); michael@0: michael@0: setTimeout(() => { michael@0: let button = win.document.documentElement.getButton("accept"); michael@0: button.disabled = false; michael@0: win.document.documentElement.acceptDialog(); michael@0: }, 0); michael@0: } michael@0: }, false); michael@0: } michael@0: } michael@0: michael@0: Services.ww.registerNotification(winObserver); michael@0: michael@0: let MockFilePicker = SpecialPowers.MockFilePicker; michael@0: MockFilePicker.init(window); michael@0: MockFilePicker.useAnyFile(); michael@0: MockFilePicker.showCallback = function() { michael@0: ok(true, "File picker shown"); michael@0: return MockFilePicker.returnOK; michael@0: } michael@0: michael@0: let downloadListener = { michael@0: onDownloadStateChange: function(aState, aDownload) { michael@0: if (aDownload.state == Services.downloads.DOWNLOAD_FINISHED) { michael@0: ok(aDownload.targetFile.exists(), "Download completed"); michael@0: is(aDownload.targetFile.fileSize, 154, "Downloaded file has correct size"); michael@0: michael@0: finish(); michael@0: } michael@0: }, michael@0: }; michael@0: michael@0: Services.downloads.addListener(downloadListener); michael@0: michael@0: registerCleanupFunction(function() { michael@0: Services.wm.getMostRecentWindow("Download:Manager").close(); michael@0: Services.ww.unregisterNotification(winObserver); michael@0: MockFilePicker.cleanup(); michael@0: Services.downloads.removeListener(downloadListener); michael@0: }); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: loadWebapp("download.webapp", undefined, function onLoad() { michael@0: gAppBrowser.contentDocument.getElementById("download").click(); michael@0: }); michael@0: }