1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/downloads/tests/test_downloads_bad_file.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +<!DOCTYPE html> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=960749 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 960749 Downloads API</title> 1.11 + <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 + 1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=960749">Mozilla Bug 960749</a> 1.18 +<p id="display"></p> 1.19 +<div id="content" style="display: none"> 1.20 +</div> 1.21 +<a href="serve_file.sjs?contentType=application/octet-stream&size=1024" download=".<.EVIL.>\ / : * ? " |file.bin" id="download1">Download #1</a> 1.22 +<pre id="test"> 1.23 +<script class="testbody" type="text/javascript;version=1.7"> 1.24 + 1.25 +// Testing a simple download, waiting for it to be done. 1.26 + 1.27 +SimpleTest.waitForExplicitFinish(); 1.28 + 1.29 +var index = -1; 1.30 +var expected = "_.EVIL.__ _ _ _ _ _ _file.bin"; 1.31 + 1.32 +function next() { 1.33 + index += 1; 1.34 + if (index >= steps.length) { 1.35 + ok(false, "Shouldn't get here!"); 1.36 + return; 1.37 + } 1.38 + try { 1.39 + steps[index](); 1.40 + } catch(ex) { 1.41 + ok(false, "Caught exception", ex); 1.42 + } 1.43 +} 1.44 + 1.45 +function checkTargetFilename(download) { 1.46 + ok(download.path.endsWith(expected), 1.47 + "Download path leaf name '" + download.path + 1.48 + "' should match '" + expected + "' filename."); 1.49 + 1.50 + SimpleTest.finish(); 1.51 +} 1.52 + 1.53 +function downloadChange(evt) { 1.54 + var download = evt.download; 1.55 + 1.56 + if (download.state === "succeeded") { 1.57 + checkTargetFilename(download); 1.58 + } 1.59 +} 1.60 + 1.61 +function downloadStart(evt) { 1.62 + var download = evt.download; 1.63 + download.onstatechange = downloadChange; 1.64 +} 1.65 + 1.66 +var steps = [ 1.67 + // Start by setting the pref to true. 1.68 + function() { 1.69 + SpecialPowers.pushPrefEnv({ 1.70 + set: [["dom.mozDownloads.enabled", true]] 1.71 + }, next); 1.72 + }, 1.73 + 1.74 + // Setup the event listeners. 1.75 + function() { 1.76 + SpecialPowers.pushPermissions([ 1.77 + {type: "downloads", allow: true, context: document} 1.78 + ], function() { 1.79 + navigator.mozDownloadManager.ondownloadstart = downloadStart; 1.80 + next(); 1.81 + }); 1.82 + }, 1.83 + 1.84 + // Click on the <a download> to start the download. 1.85 + function() { 1.86 + document.getElementById("download1").click(); 1.87 + } 1.88 +]; 1.89 + 1.90 +next(); 1.91 + 1.92 +</script> 1.93 +</pre> 1.94 +</body> 1.95 +</html> 1.96 +