dom/downloads/tests/test_downloads_pause_remove.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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&rate=1024" 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 pausing a download and then removing it.
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 var pausing = false;
michael@0 42
michael@0 43 // Catch all error function.
michael@0 44 function error() {
michael@0 45 ok(false, "API failure");
michael@0 46 SimpleTest.finish();
michael@0 47 }
michael@0 48
michael@0 49 function checkDownloadList(downloads) {
michael@0 50 ok(downloads.length == 0, "No downloads left");
michael@0 51 SimpleTest.finish();
michael@0 52 }
michael@0 53
michael@0 54 function checkRemoved(download) {
michael@0 55 ok(download.state == "finalized", "Download removed.");
michael@0 56 navigator.mozDownloadManager.getDownloads()
michael@0 57 .then(checkDownloadList, error);
michael@0 58 }
michael@0 59
michael@0 60 function downloadChange(evt) {
michael@0 61 var download = evt.download;
michael@0 62
michael@0 63 if (download.state == "downloading" && !pausing) {
michael@0 64 pausing = true;
michael@0 65 download.pause();
michael@0 66 } else if (download.state == "stopped") {
michael@0 67 ok(pausing, "Download stopped by pause()");
michael@0 68 navigator.mozDownloadManager.remove(download)
michael@0 69 .then(checkRemoved, error);
michael@0 70 }
michael@0 71 }
michael@0 72
michael@0 73 var steps = [
michael@0 74 // Start by setting the pref to true.
michael@0 75 function() {
michael@0 76 SpecialPowers.pushPrefEnv({
michael@0 77 set: [["dom.mozDownloads.enabled", true]]
michael@0 78 }, next);
michael@0 79 },
michael@0 80
michael@0 81 // Setup permission and clear current list.
michael@0 82 function() {
michael@0 83 SpecialPowers.pushPermissions([
michael@0 84 {type: "downloads", allow: true, context: document}
michael@0 85 ], function() {
michael@0 86 navigator.mozDownloadManager.clearAllDone().then(next, error);
michael@0 87 });
michael@0 88 },
michael@0 89
michael@0 90 function(downloads) {
michael@0 91 ok(downloads.length == 0, "Start with an empty download list.");
michael@0 92 next();
michael@0 93 },
michael@0 94
michael@0 95 // Setup the event listeners.
michael@0 96 function() {
michael@0 97 navigator.mozDownloadManager.ondownloadstart =
michael@0 98 function(evt) {
michael@0 99 ok(true, "Download started");
michael@0 100 evt.download.addEventListener("statechange", downloadChange);
michael@0 101 }
michael@0 102 next();
michael@0 103 },
michael@0 104
michael@0 105 // Click on the <a download> to start the download.
michael@0 106 function() {
michael@0 107 document.getElementById("download1").click();
michael@0 108 }
michael@0 109 ];
michael@0 110
michael@0 111 next();
michael@0 112
michael@0 113 </script>
michael@0 114 </pre>
michael@0 115 </body>
michael@0 116 </html>

mercurial