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