dom/downloads/tests/test_downloads_bad_file.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:8d60c1b1a312
1 <!DOCTYPE html>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=960749
5 -->
6 <head>
7 <title>Test for Bug 960749 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>
13
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=960749">Mozilla Bug 960749</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=1024" download=".&lt;.EVIL.&gt;\ / : * ? &quot; |file.bin" id="download1">Download #1</a>
19 <pre id="test">
20 <script class="testbody" type="text/javascript;version=1.7">
21
22 // Testing a simple download, waiting for it to be done.
23
24 SimpleTest.waitForExplicitFinish();
25
26 var index = -1;
27 var expected = "_.EVIL.__ _ _ _ _ _ _file.bin";
28
29 function next() {
30 index += 1;
31 if (index >= steps.length) {
32 ok(false, "Shouldn't get here!");
33 return;
34 }
35 try {
36 steps[index]();
37 } catch(ex) {
38 ok(false, "Caught exception", ex);
39 }
40 }
41
42 function checkTargetFilename(download) {
43 ok(download.path.endsWith(expected),
44 "Download path leaf name '" + download.path +
45 "' should match '" + expected + "' filename.");
46
47 SimpleTest.finish();
48 }
49
50 function downloadChange(evt) {
51 var download = evt.download;
52
53 if (download.state === "succeeded") {
54 checkTargetFilename(download);
55 }
56 }
57
58 function downloadStart(evt) {
59 var download = evt.download;
60 download.onstatechange = downloadChange;
61 }
62
63 var steps = [
64 // Start by setting the pref to true.
65 function() {
66 SpecialPowers.pushPrefEnv({
67 set: [["dom.mozDownloads.enabled", true]]
68 }, next);
69 },
70
71 // Setup the event listeners.
72 function() {
73 SpecialPowers.pushPermissions([
74 {type: "downloads", allow: true, context: document}
75 ], function() {
76 navigator.mozDownloadManager.ondownloadstart = downloadStart;
77 next();
78 });
79 },
80
81 // Click on the <a download> to start the download.
82 function() {
83 document.getElementById("download1").click();
84 }
85 ];
86
87 next();
88
89 </script>
90 </pre>
91 </body>
92 </html>
93

mercurial