Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 2 | |
michael@0 | 3 | let winObserver = function(win, topic) { |
michael@0 | 4 | if (topic == "domwindowopened") { |
michael@0 | 5 | win.addEventListener("load", function onLoadWindow() { |
michael@0 | 6 | win.removeEventListener("load", onLoadWindow, false); |
michael@0 | 7 | |
michael@0 | 8 | if (win.document.documentURI == |
michael@0 | 9 | "chrome://mozapps/content/downloads/unknownContentType.xul") { |
michael@0 | 10 | ok(true, "Download dialog shown"); |
michael@0 | 11 | |
michael@0 | 12 | setTimeout(() => { |
michael@0 | 13 | let button = win.document.documentElement.getButton("accept"); |
michael@0 | 14 | button.disabled = false; |
michael@0 | 15 | win.document.documentElement.acceptDialog(); |
michael@0 | 16 | }, 0); |
michael@0 | 17 | } |
michael@0 | 18 | }, false); |
michael@0 | 19 | } |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | Services.ww.registerNotification(winObserver); |
michael@0 | 23 | |
michael@0 | 24 | let MockFilePicker = SpecialPowers.MockFilePicker; |
michael@0 | 25 | MockFilePicker.init(window); |
michael@0 | 26 | MockFilePicker.useAnyFile(); |
michael@0 | 27 | MockFilePicker.showCallback = function() { |
michael@0 | 28 | ok(true, "File picker shown"); |
michael@0 | 29 | return MockFilePicker.returnOK; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | let downloadListener = { |
michael@0 | 33 | onDownloadStateChange: function(aState, aDownload) { |
michael@0 | 34 | if (aDownload.state == Services.downloads.DOWNLOAD_FINISHED) { |
michael@0 | 35 | ok(aDownload.targetFile.exists(), "Download completed"); |
michael@0 | 36 | is(aDownload.targetFile.fileSize, 154, "Downloaded file has correct size"); |
michael@0 | 37 | |
michael@0 | 38 | finish(); |
michael@0 | 39 | } |
michael@0 | 40 | }, |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | Services.downloads.addListener(downloadListener); |
michael@0 | 44 | |
michael@0 | 45 | registerCleanupFunction(function() { |
michael@0 | 46 | Services.wm.getMostRecentWindow("Download:Manager").close(); |
michael@0 | 47 | Services.ww.unregisterNotification(winObserver); |
michael@0 | 48 | MockFilePicker.cleanup(); |
michael@0 | 49 | Services.downloads.removeListener(downloadListener); |
michael@0 | 50 | }); |
michael@0 | 51 | |
michael@0 | 52 | function test() { |
michael@0 | 53 | waitForExplicitFinish(); |
michael@0 | 54 | |
michael@0 | 55 | loadWebapp("download.webapp", undefined, function onLoad() { |
michael@0 | 56 | gAppBrowser.contentDocument.getElementById("download").click(); |
michael@0 | 57 | }); |
michael@0 | 58 | } |