Sat, 03 Jan 2015 20:18:00 +0100
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=938023 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 938023 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=938023">Mozilla Bug 938023</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=102400&rate=10240" download="test.bin" id="download1">Large Download</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 pausing a download and then resuming it. |
michael@0 | 23 | |
michael@0 | 24 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 25 | |
michael@0 | 26 | var index = -1; |
michael@0 | 27 | |
michael@0 | 28 | function next(args) { |
michael@0 | 29 | index += 1; |
michael@0 | 30 | if (index >= steps.length) { |
michael@0 | 31 | ok(false, "Shouldn't get here!"); |
michael@0 | 32 | return; |
michael@0 | 33 | } |
michael@0 | 34 | try { |
michael@0 | 35 | steps[index](args); |
michael@0 | 36 | } catch(ex) { |
michael@0 | 37 | ok(false, "Caught exception", ex); |
michael@0 | 38 | } |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | var pausing = false; |
michael@0 | 42 | var resuming = false; |
michael@0 | 43 | |
michael@0 | 44 | // Catch all error function. |
michael@0 | 45 | function error() { |
michael@0 | 46 | ok(false, "API failure"); |
michael@0 | 47 | SimpleTest.finish(); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function checkDownloadList(downloads) { |
michael@0 | 51 | ok(downloads.length == 0, "No downloads left"); |
michael@0 | 52 | SimpleTest.finish(); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function checkResumeSucceeded(download) { |
michael@0 | 56 | ok(download.state == "succeeded", "Download resumed successfully."); |
michael@0 | 57 | navigator.mozDownloadManager.clearAllDone() |
michael@0 | 58 | .then(checkDownloadList, error); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function downloadChange(evt) { |
michael@0 | 62 | var download = evt.download; |
michael@0 | 63 | |
michael@0 | 64 | if (download.state == "downloading" && !pausing) { |
michael@0 | 65 | pausing = true; |
michael@0 | 66 | download.pause(); |
michael@0 | 67 | } else if (download.state == "stopped" && !resuming) { |
michael@0 | 68 | resuming = true; |
michael@0 | 69 | ok(pausing, "Download stopped by pause()"); |
michael@0 | 70 | download.resume() |
michael@0 | 71 | .then(function() { checkResumeSucceeded(download); }, error); |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | var steps = [ |
michael@0 | 76 | // Start by setting the pref to true. |
michael@0 | 77 | function() { |
michael@0 | 78 | SpecialPowers.pushPrefEnv({ |
michael@0 | 79 | set: [["dom.mozDownloads.enabled", true]] |
michael@0 | 80 | }, next); |
michael@0 | 81 | }, |
michael@0 | 82 | |
michael@0 | 83 | // Setup permission and clear current list. |
michael@0 | 84 | function() { |
michael@0 | 85 | SpecialPowers.pushPermissions([ |
michael@0 | 86 | {type: "downloads", allow: true, context: document} |
michael@0 | 87 | ], function() { |
michael@0 | 88 | navigator.mozDownloadManager.clearAllDone().then(next, error); |
michael@0 | 89 | }); |
michael@0 | 90 | }, |
michael@0 | 91 | |
michael@0 | 92 | function(downloads) { |
michael@0 | 93 | ok(downloads.length == 0, "Start with an empty download list."); |
michael@0 | 94 | next(); |
michael@0 | 95 | }, |
michael@0 | 96 | |
michael@0 | 97 | // Setup the event listeners. |
michael@0 | 98 | function() { |
michael@0 | 99 | navigator.mozDownloadManager.ondownloadstart = |
michael@0 | 100 | function(evt) { |
michael@0 | 101 | ok(true, "Download started"); |
michael@0 | 102 | evt.download.addEventListener("statechange", downloadChange); |
michael@0 | 103 | } |
michael@0 | 104 | next(); |
michael@0 | 105 | }, |
michael@0 | 106 | |
michael@0 | 107 | // Click on the <a download> to start the download. |
michael@0 | 108 | function() { |
michael@0 | 109 | document.getElementById("download1").click(); |
michael@0 | 110 | } |
michael@0 | 111 | ]; |
michael@0 | 112 | |
michael@0 | 113 | next(); |
michael@0 | 114 | |
michael@0 | 115 | </script> |
michael@0 | 116 | </pre> |
michael@0 | 117 | </body> |
michael@0 | 118 | </html> |