Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=841579 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 841579</title> |
michael@0 | 8 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script> |
michael@0 | 10 | <script type="application/javascript" src="imgutils.js"></script> |
michael@0 | 11 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
michael@0 | 12 | </head> |
michael@0 | 13 | <body> |
michael@0 | 14 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=841579">Mozilla Bug 841579</a> |
michael@0 | 15 | <p id="display"></p> |
michael@0 | 16 | <div id="content"> |
michael@0 | 17 | </div> |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script type="application/javascript;version=1.8"> |
michael@0 | 20 | /** Test for Bug 841579**/ |
michael@0 | 21 | |
michael@0 | 22 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 23 | |
michael@0 | 24 | const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes) |
michael@0 | 25 | |
michael@0 | 26 | const Cc = Components.classes; |
michael@0 | 27 | const Ci = Components.interfaces; |
michael@0 | 28 | const gContent = document.getElementById("content"); |
michael@0 | 29 | |
michael@0 | 30 | var gImg; |
michael@0 | 31 | var gMyDecoderObserver; |
michael@0 | 32 | var gIsTestFinished = false; |
michael@0 | 33 | var gFiles; |
michael@0 | 34 | var gNotifications = 0; |
michael@0 | 35 | var gLoads = 0; |
michael@0 | 36 | |
michael@0 | 37 | function fileToLoad() { |
michael@0 | 38 | yield "red.png"; |
michael@0 | 39 | yield "invalid.jpg"; |
michael@0 | 40 | yield "lime100x100.svg"; |
michael@0 | 41 | yield "bad.jpg"; |
michael@0 | 42 | yield "rillybad.jpg"; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function onSizeAvailable(aRequest) { |
michael@0 | 46 | ok(true, "AfterLoad.onSizeAvailable called for " + gImg.src); |
michael@0 | 47 | } |
michael@0 | 48 | function onLoadComplete(aRequest) { |
michael@0 | 49 | ok(true, "AfterLoad.onLoadComplete called for " + gImg.src); |
michael@0 | 50 | gLoads++; |
michael@0 | 51 | } |
michael@0 | 52 | function onDecodeComplete(aRequest) { |
michael@0 | 53 | ok(true, "AfterLoad.onDecodeComplete called for " + gImg.src); |
michael@0 | 54 | SimpleTest.executeSoon(function() { |
michael@0 | 55 | try { |
michael@0 | 56 | gContent.removeChild(gImg); |
michael@0 | 57 | } |
michael@0 | 58 | catch (e) {} |
michael@0 | 59 | }); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function failTest() { |
michael@0 | 63 | ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " + |
michael@0 | 64 | "currently displaying " + gImg.src); |
michael@0 | 65 | cleanUpAndFinish(); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | function onNotification() |
michael@0 | 69 | { |
michael@0 | 70 | gNotifications++; |
michael@0 | 71 | try { |
michael@0 | 72 | gImg.src = gFiles.next(); |
michael@0 | 73 | gContent.appendChild(gImg); |
michael@0 | 74 | } catch(e) { |
michael@0 | 75 | cleanUpAndFinish(); |
michael@0 | 76 | } |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function cleanUpAndFinish() { |
michael@0 | 80 | // On the off chance that failTest and myOnStopFrame are triggered |
michael@0 | 81 | // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish. |
michael@0 | 82 | if (gIsTestFinished) { |
michael@0 | 83 | return; |
michael@0 | 84 | } |
michael@0 | 85 | let imgLoadingContent = gImg.QueryInterface(Ci.nsIImageLoadingContent); |
michael@0 | 86 | imgLoadingContent.removeObserver(gMyDecoderObserver); |
michael@0 | 87 | // TODO - this isn't the case until post-bug 716140's refactorings |
michael@0 | 88 | // ok(gNotifications == gLoads, "Should be notified the same number of times as loads"); |
michael@0 | 89 | SimpleTest.finish(); |
michael@0 | 90 | gIsTestFinished = true; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function main() { |
michael@0 | 94 | gFiles = fileToLoad(); |
michael@0 | 95 | gImg = new Image(); |
michael@0 | 96 | gImg.onload = onNotification; |
michael@0 | 97 | gImg.onerror = onNotification; |
michael@0 | 98 | |
michael@0 | 99 | // Create, customize & attach decoder observer |
michael@0 | 100 | observer = new ImageDecoderObserverStub(); |
michael@0 | 101 | observer.sizeAvailable = onSizeAvailable; |
michael@0 | 102 | observer.loadComplete = onLoadComplete; |
michael@0 | 103 | observer.decodeComplete = onDecodeComplete; |
michael@0 | 104 | gMyDecoderObserver = |
michael@0 | 105 | Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools) |
michael@0 | 106 | .createScriptedObserver(observer); |
michael@0 | 107 | let imgLoadingContent = gImg.QueryInterface(Ci.nsIImageLoadingContent); |
michael@0 | 108 | imgLoadingContent.addObserver(gMyDecoderObserver); |
michael@0 | 109 | |
michael@0 | 110 | // We want to test the cold loading behavior, so clear cache in case an |
michael@0 | 111 | // earlier test got our image in there already. |
michael@0 | 112 | clearImageCache(); |
michael@0 | 113 | |
michael@0 | 114 | // kick off image-loading! myOnStopFrame handles the rest. |
michael@0 | 115 | gImg.setAttribute("src", gFiles.next()); |
michael@0 | 116 | |
michael@0 | 117 | // In case something goes wrong, fail earlier than mochitest timeout, |
michael@0 | 118 | // and with more information. |
michael@0 | 119 | setTimeout(failTest, FAILURE_TIMEOUT); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | window.onload = main; |
michael@0 | 123 | |
michael@0 | 124 | </script> |
michael@0 | 125 | </pre> |
michael@0 | 126 | </body> |
michael@0 | 127 | </html> |