diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/downloads/tests/test_downloads_pause_remove.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/downloads/tests/test_downloads_pause_remove.html')
-rw-r--r-- | dom/downloads/tests/test_downloads_pause_remove.html | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/dom/downloads/tests/test_downloads_pause_remove.html b/dom/downloads/tests/test_downloads_pause_remove.html new file mode 100644 index 000000000..3b410a667 --- /dev/null +++ b/dom/downloads/tests/test_downloads_pause_remove.html @@ -0,0 +1,117 @@ +<!DOCTYPE html> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=938023 +--> +<head> + <title>Test for Bug 938023 Downloads API</title> + <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <script type="text/javascript" src="clear_all_done_helper.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> + +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=938023">Mozilla Bug 938023</a> +<p id="display"></p> +<div id="content" style="display: none"> +</div> +<a href="serve_file.sjs?contentType=application/octet-stream&size=102400&rate=1024" download="test.bin" id="download1">Large Download</a> +<pre id="test"> +<script class="testbody" type="text/javascript;version=1.7"> + +// Testing pausing a download and then removing it. + +SimpleTest.waitForExplicitFinish(); + +var index = -1; + +function next(args) { + index += 1; + if (index >= steps.length) { + ok(false, "Shouldn't get here!"); + return; + } + try { + steps[index](args); + } catch(ex) { + ok(false, "Caught exception", ex); + } +} + +var pausing = false; + +// Catch all error function. +function error() { + ok(false, "API failure"); + SimpleTest.finish(); +} + +function checkDownloadList(downloads) { + ok(downloads.length == 0, "No downloads left"); + SimpleTest.finish(); +} + +function checkRemoved(download) { + ok(download.state == "finalized", "Download removed."); + navigator.mozDownloadManager.getDownloads() + .then(checkDownloadList, error); +} + +function downloadChange(evt) { + var download = evt.download; + + if (download.state == "downloading" && !pausing) { + pausing = true; + download.pause(); + } else if (download.state == "stopped") { + ok(pausing, "Download stopped by pause()"); + navigator.mozDownloadManager.remove(download) + .then(checkRemoved, error); + } +} + +var steps = [ + // Start by setting the pref to true. + function() { + SpecialPowers.pushPrefEnv({ + set: [["dom.mozDownloads.enabled", true]] + }, next); + }, + + // Setup permission and clear current list. + function() { + SpecialPowers.pushPermissions([ + {type: "downloads", allow: true, context: document} + ], function() { + clearAllDoneHelper(true).then(next, error); + }); + }, + + function(downloads) { + ok(downloads.length == 0, "Start with an empty download list."); + next(); + }, + + // Setup the event listeners. + function() { + navigator.mozDownloadManager.ondownloadstart = + function(evt) { + ok(true, "Download started"); + evt.download.addEventListener("statechange", downloadChange); + } + next(); + }, + + // Click on the <a download> to start the download. + function() { + document.getElementById("download1").click(); + } +]; + +next(); + +</script> +</pre> +</body> +</html> |