Bumping manifests a=b2g-bump
[gecko.git] / dom / downloads / tests / test_downloads_pause_resume.html
blob911c6d39f101508b9c5b3fbf04566bbab60fe30b
1 <!DOCTYPE html>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=938023
5 -->
6 <head>
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" />
11 </head>
12 <body>
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=938023">Mozilla Bug 938023</a>
15 <p id="display"></p>
16 <div id="content" style="display: none">
17 </div>
18 <a href="serve_file.sjs?contentType=application/octet-stream&size=102400&rate=10240" download="test.bin" id="download1">Large Download</a>
19 <pre id="test">
20 <script class="testbody" type="text/javascript;version=1.7">
22 // Testing pausing a download and then resuming it.
24 SimpleTest.waitForExplicitFinish();
26 var index = -1;
28 function next(args) {
29 index += 1;
30 if (index >= steps.length) {
31 ok(false, "Shouldn't get here!");
32 return;
34 try {
35 steps[index](args);
36 } catch(ex) {
37 ok(false, "Caught exception", ex);
41 var pausing = false;
42 var resuming = false;
44 // Catch all error function.
45 function error() {
46 ok(false, "API failure");
47 SimpleTest.finish();
50 function checkDownloadList(downloads) {
51 ok(downloads.length == 0, "No downloads left");
52 SimpleTest.finish();
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) {
65 pausing = true;
66 download.pause();
67 } else if (download.state == "stopped" && !resuming) {
68 resuming = true;
69 ok(pausing, "Download stopped by pause()");
70 download.resume()
71 .then(function() { checkResumeSucceeded(download); }, error);
75 var steps = [
76 // Start by setting the pref to true.
77 function() {
78 SpecialPowers.pushPrefEnv({
79 set: [["dom.mozDownloads.enabled", true]]
80 }, next);
83 // Setup permission and clear current list.
84 function() {
85 SpecialPowers.pushPermissions([
86 {type: "downloads", allow: true, context: document}
87 ], function() {
88 navigator.mozDownloadManager.clearAllDone().then(next, error);
89 });
92 function(downloads) {
93 ok(downloads.length == 0, "Start with an empty download list.");
94 next();
97 // Setup the event listeners.
98 function() {
99 navigator.mozDownloadManager.ondownloadstart =
100 function(evt) {
101 ok(true, "Download started");
102 evt.download.addEventListener("statechange", downloadChange);
104 next();
107 // Click on the <a download> to start the download.
108 function() {
109 document.getElementById("download1").click();
113 next();
115 </script>
116 </pre>
117 </body>
118 </html>