1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/webapprt/test/chrome/browser_download.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +Cu.import("resource://gre/modules/Services.jsm"); 1.5 + 1.6 +let winObserver = function(win, topic) { 1.7 + if (topic == "domwindowopened") { 1.8 + win.addEventListener("load", function onLoadWindow() { 1.9 + win.removeEventListener("load", onLoadWindow, false); 1.10 + 1.11 + if (win.document.documentURI == 1.12 + "chrome://mozapps/content/downloads/unknownContentType.xul") { 1.13 + ok(true, "Download dialog shown"); 1.14 + 1.15 + setTimeout(() => { 1.16 + let button = win.document.documentElement.getButton("accept"); 1.17 + button.disabled = false; 1.18 + win.document.documentElement.acceptDialog(); 1.19 + }, 0); 1.20 + } 1.21 + }, false); 1.22 + } 1.23 +} 1.24 + 1.25 +Services.ww.registerNotification(winObserver); 1.26 + 1.27 +let MockFilePicker = SpecialPowers.MockFilePicker; 1.28 +MockFilePicker.init(window); 1.29 +MockFilePicker.useAnyFile(); 1.30 +MockFilePicker.showCallback = function() { 1.31 + ok(true, "File picker shown"); 1.32 + return MockFilePicker.returnOK; 1.33 +} 1.34 + 1.35 +let downloadListener = { 1.36 + onDownloadStateChange: function(aState, aDownload) { 1.37 + if (aDownload.state == Services.downloads.DOWNLOAD_FINISHED) { 1.38 + ok(aDownload.targetFile.exists(), "Download completed"); 1.39 + is(aDownload.targetFile.fileSize, 154, "Downloaded file has correct size"); 1.40 + 1.41 + finish(); 1.42 + } 1.43 + }, 1.44 +}; 1.45 + 1.46 +Services.downloads.addListener(downloadListener); 1.47 + 1.48 +registerCleanupFunction(function() { 1.49 + Services.wm.getMostRecentWindow("Download:Manager").close(); 1.50 + Services.ww.unregisterNotification(winObserver); 1.51 + MockFilePicker.cleanup(); 1.52 + Services.downloads.removeListener(downloadListener); 1.53 +}); 1.54 + 1.55 +function test() { 1.56 + waitForExplicitFinish(); 1.57 + 1.58 + loadWebapp("download.webapp", undefined, function onLoad() { 1.59 + gAppBrowser.contentDocument.getElementById("download").click(); 1.60 + }); 1.61 +}