Bug 965414 - Test downloads in the webapp runtime. r=myk

This commit is contained in:
Marco Castelluccio 2014-04-27 12:22:00 -04:00
parent 2f48cbfb0d
commit 6aee238150
5 changed files with 79 additions and 0 deletions

View File

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

View File

@ -0,0 +1,11 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Download Test App</title>
<meta charset="utf-8">
</head>
<body>
<h1>Download Test App</h1>
<a id="download" href="http://mochi.test:8888//webapprtChrome/webapprt/test/chrome/download.webapp">Download</a>
</body>
</html>

View File

@ -0,0 +1,5 @@
{
"name": "Download Test App",
"description": "an app for testing downloads",
"launch_path": "/webapprtChrome/webapprt/test/chrome/download.html"
}

View File

@ -0,0 +1 @@
Content-Type: application/x-web-app-manifest+json

View File

@ -42,6 +42,9 @@ support-files =
alarm.html
alarm.webapp
alarm.webapp^headers^
download.html
download.webapp
download.webapp^headers^
[browser_sample.js]
@ -57,3 +60,4 @@ support-files =
[browser_window-open.js]
[browser_window-open-blank.js]
[browser_alarm.js]
[browser_download.js]