dom/downloads/tests/test_downloads_bad_file.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.

     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>
    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">
    22 // Testing a simple download, waiting for it to be done.
    24 SimpleTest.waitForExplicitFinish();
    26 var index = -1;
    27 var expected = "_.EVIL.__ _ _ _ _ _ _file.bin";
    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 }
    42 function checkTargetFilename(download) {
    43   ok(download.path.endsWith(expected),
    44      "Download path leaf name '" + download.path +
    45      "' should match '" + expected + "' filename.");
    47   SimpleTest.finish();
    48 }
    50 function downloadChange(evt) {
    51   var download = evt.download;
    53   if (download.state === "succeeded") {
    54     checkTargetFilename(download);
    55   }
    56 }
    58 function downloadStart(evt) {
    59   var download = evt.download;
    60   download.onstatechange = downloadChange;
    61 }
    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   },
    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   },
    81   // Click on the <a download> to start the download.
    82   function() {
    83     document.getElementById("download1").click();
    84   }
    85 ];
    87 next();
    89 </script>
    90 </pre>
    91 </body>
    92 </html>

mercurial