mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 965414 - Test downloads in the webapp runtime. r=myk
This commit is contained in:
parent
2f48cbfb0d
commit
6aee238150
58
webapprt/test/chrome/browser_download.js
Normal file
58
webapprt/test/chrome/browser_download.js
Normal 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();
|
||||
});
|
||||
}
|
11
webapprt/test/chrome/download.html
Normal file
11
webapprt/test/chrome/download.html
Normal 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>
|
5
webapprt/test/chrome/download.webapp
Normal file
5
webapprt/test/chrome/download.webapp
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "Download Test App",
|
||||
"description": "an app for testing downloads",
|
||||
"launch_path": "/webapprtChrome/webapprt/test/chrome/download.html"
|
||||
}
|
1
webapprt/test/chrome/download.webapp^headers^
Normal file
1
webapprt/test/chrome/download.webapp^headers^
Normal file
@ -0,0 +1 @@
|
||||
Content-Type: application/x-web-app-manifest+json
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user