dom/downloads/tests/test_downloads_large.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE html>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=938023
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 938023 Downloads API</title>
michael@0 8 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 11 </head>
michael@0 12 <body>
michael@0 13
michael@0 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=938023">Mozilla Bug 938023</a>
michael@0 15 <p id="display"></p>
michael@0 16 <div id="content" style="display: none">
michael@0 17 </div>
michael@0 18 <a href="serve_file.sjs?contentType=application/octet-stream&size=102400" download="test.bin" id="download1">Large Download</a>
michael@0 19 <pre id="test">
michael@0 20 <script class="testbody" type="text/javascript;version=1.7">
michael@0 21
michael@0 22 // Testing downloading a file, then checking getDownloads() and clearAllDone().
michael@0 23
michael@0 24 SimpleTest.waitForExplicitFinish();
michael@0 25
michael@0 26 var index = -1;
michael@0 27
michael@0 28 function next(args) {
michael@0 29 index += 1;
michael@0 30 if (index >= steps.length) {
michael@0 31 ok(false, "Shouldn't get here!");
michael@0 32 return;
michael@0 33 }
michael@0 34 try {
michael@0 35 steps[index](args);
michael@0 36 } catch(ex) {
michael@0 37 ok(false, "Caught exception", ex);
michael@0 38 }
michael@0 39 }
michael@0 40
michael@0 41 // Catch all error function.
michael@0 42 function error() {
michael@0 43 ok(false, "API failure");
michael@0 44 SimpleTest.finish();
michael@0 45 }
michael@0 46
michael@0 47 function getDownloads(downloads) {
michael@0 48 ok(downloads.length == 1, "One downloads after getDownloads");
michael@0 49 navigator.mozDownloadManager.clearAllDone().then(clearAllDone, error);
michael@0 50 }
michael@0 51
michael@0 52 function clearAllDone(downloads) {
michael@0 53 ok(downloads.length == 0, "No downloads after clearAllDone");
michael@0 54 SimpleTest.finish();
michael@0 55 }
michael@0 56
michael@0 57 function downloadChange(evt) {
michael@0 58 var download = evt.download;
michael@0 59
michael@0 60 if (download.state == "succeeded") {
michael@0 61 ok(download.totalBytes == 102400, "Download size is 100k bytes.");
michael@0 62 navigator.mozDownloadManager.getDownloads().then(getDownloads, error);
michael@0 63 }
michael@0 64 }
michael@0 65
michael@0 66 var steps = [
michael@0 67 // Start by setting the pref to true.
michael@0 68 function() {
michael@0 69 SpecialPowers.pushPrefEnv({
michael@0 70 set: [["dom.mozDownloads.enabled", true]]
michael@0 71 }, next);
michael@0 72 },
michael@0 73
michael@0 74 // Setup permission and clear current list.
michael@0 75 function() {
michael@0 76 SpecialPowers.pushPermissions([
michael@0 77 {type: "downloads", allow: true, context: document}
michael@0 78 ], function() {
michael@0 79 navigator.mozDownloadManager.clearAllDone().then(next, error);
michael@0 80 });
michael@0 81 },
michael@0 82
michael@0 83 function(downloads) {
michael@0 84 ok(downloads.length == 0, "Start with an empty download list.");
michael@0 85 next();
michael@0 86 },
michael@0 87
michael@0 88 // Setup the event listeners.
michael@0 89 function() {
michael@0 90 navigator.mozDownloadManager.ondownloadstart =
michael@0 91 function(evt) {
michael@0 92 ok(true, "Download started");
michael@0 93 evt.download.addEventListener("statechange", downloadChange);
michael@0 94 }
michael@0 95 next();
michael@0 96 },
michael@0 97
michael@0 98 // Click on the <a download> to start the download.
michael@0 99 function() {
michael@0 100 document.getElementById("download1").click();
michael@0 101 }
michael@0 102 ];
michael@0 103
michael@0 104 next();
michael@0 105
michael@0 106 </script>
michael@0 107 </pre>
michael@0 108 </body>
michael@0 109 </html>

mercurial