4 https://bugzilla.mozilla.org/show_bug.cgi?id=938023
7 <title>Test for Bug
938023 Downloads API
</title>
8 <script type=
"text/javascript" src=
"/MochiKit/MochiKit.js"></script>
9 <script type=
"text/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
14 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=938023">Mozilla Bug
938023</a>
16 <div id=
"content" style=
"display: none">
18 <a href=
"serve_file.sjs?contentType=application/octet-stream&size=102400&rate=10240" download=
"test.bin" id=
"download1">Large Download
</a>
20 <script class=
"testbody" type=
"text/javascript;version=1.7">
22 // Testing pausing a download and then resuming it.
24 SimpleTest.waitForExplicitFinish();
30 if (index
>= steps.length) {
31 ok(false,
"Shouldn't get here!");
37 ok(false,
"Caught exception", ex);
44 // Catch all error function.
46 ok(false,
"API failure");
50 function checkDownloadList(downloads) {
51 ok(downloads.length ==
0,
"No downloads left");
55 function checkResumeSucceeded(download) {
56 ok(download.state ==
"succeeded",
"Download resumed successfully.");
57 navigator.mozDownloadManager.clearAllDone()
58 .then(checkDownloadList, error);
61 function downloadChange(evt) {
62 var download = evt.download;
64 if (download.state ==
"downloading" && !pausing) {
67 } else if (download.state ==
"stopped" && !resuming) {
69 ok(pausing,
"Download stopped by pause()");
71 .then(function() { checkResumeSucceeded(download); }, error);
76 // Start by setting the pref to true.
78 SpecialPowers.pushPrefEnv({
79 set: [[
"dom.mozDownloads.enabled", true]]
83 // Setup permission and clear current list.
85 SpecialPowers.pushPermissions([
86 {type:
"downloads", allow: true, context: document}
88 navigator.mozDownloadManager.clearAllDone().then(next, error);
93 ok(downloads.length ==
0,
"Start with an empty download list.");
97 // Setup the event listeners.
99 navigator.mozDownloadManager.ondownloadstart =
101 ok(true,
"Download started");
102 evt.download.addEventListener(
"statechange", downloadChange);
107 // Click on the
<a download
> to start the download.
109 document.getElementById(
"download1").click();