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

mercurial