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=907503 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 907503</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=907503">Mozilla Bug 907503</a> |
michael@0 | 15 | <p id="display"></p> |
michael@0 | 16 | <div id="content"> |
michael@0 | 17 | <div id="referenceDiv" style="height: 100px; width: 100px; |
michael@0 | 18 | display: none; background: lime"></div> |
michael@0 | 19 | <img> |
michael@0 | 20 | </div> |
michael@0 | 21 | <pre id="test"> |
michael@0 | 22 | <script type="application/javascript;version=1.8"> |
michael@0 | 23 | /** Test for Bug 907503**/ |
michael@0 | 24 | |
michael@0 | 25 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 26 | |
michael@0 | 27 | const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes) |
michael@0 | 28 | |
michael@0 | 29 | const Cc = Components.classes; |
michael@0 | 30 | const Ci = Components.interfaces; |
michael@0 | 31 | const gImg = document.getElementsByTagName("img")[0]; |
michael@0 | 32 | |
michael@0 | 33 | var gMyDecoderObserver; // value will be set in main() |
michael@0 | 34 | var gReferenceSnapshot; // value will be set in takeReferenceSnapshot() |
michael@0 | 35 | var gOnStopFrameCounter = 0; |
michael@0 | 36 | var gIsTestFinished = false; |
michael@0 | 37 | var gTimer = null; |
michael@0 | 38 | |
michael@0 | 39 | |
michael@0 | 40 | function takeReferenceSnapshot() { |
michael@0 | 41 | // Take a snapshot of the initial (essentially blank) page |
michael@0 | 42 | let blankSnapshot = snapshotWindow(window, false); |
michael@0 | 43 | |
michael@0 | 44 | // Show reference div, & take a snapshot |
michael@0 | 45 | let referenceDiv = document.getElementById("referenceDiv"); |
michael@0 | 46 | referenceDiv.style.display = "block"; |
michael@0 | 47 | gReferenceSnapshot = snapshotWindow(window, false); |
michael@0 | 48 | ok(compareSnapshots(blankSnapshot, gReferenceSnapshot, false)[0], |
michael@0 | 49 | "reference snapshot shouldn't match blank page snapshot"); |
michael@0 | 50 | |
michael@0 | 51 | // Re-hide reference div, and take another snapshot to be sure it's gone |
michael@0 | 52 | referenceDiv.style.display = "none"; |
michael@0 | 53 | let blankSnapshot2 = snapshotWindow(window, false); |
michael@0 | 54 | ok(compareSnapshots(blankSnapshot, blankSnapshot2, true)[0], |
michael@0 | 55 | "reference div should disappear when it becomes display:none"); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function myOnStopFrame(aRequest) { |
michael@0 | 59 | gOnStopFrameCounter++; |
michael@0 | 60 | ok(true, "myOnStopFrame called"); |
michael@0 | 61 | let currentSnapshot = snapshotWindow(window, false); |
michael@0 | 62 | if (compareSnapshots(currentSnapshot, gReferenceSnapshot, true)[0]) { |
michael@0 | 63 | // SUCCESS! |
michael@0 | 64 | ok(true, "Animated image looks correct, " + |
michael@0 | 65 | "at call #" + gOnStopFrameCounter + " to onStopFrame"); |
michael@0 | 66 | cleanUpAndFinish(); |
michael@0 | 67 | } |
michael@0 | 68 | if (!gTimer) |
michael@0 | 69 | gTimer = setTimeout(function() { gTimer = null; myOnStopFrame(0, 0); }, 1000); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | function failTest() { |
michael@0 | 73 | ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " + |
michael@0 | 74 | "Animated image still doesn't look correct, " + |
michael@0 | 75 | "after call #" + gOnStopFrameCounter + " to onStopFrame"); |
michael@0 | 76 | cleanUpAndFinish(); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function cleanUpAndFinish() { |
michael@0 | 80 | clearTimeout(gTimer); |
michael@0 | 81 | // On the off chance that failTest and myOnStopFrame are triggered |
michael@0 | 82 | // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish. |
michael@0 | 83 | if (gIsTestFinished) { |
michael@0 | 84 | return; |
michael@0 | 85 | } |
michael@0 | 86 | let imgLoadingContent = gImg.QueryInterface(Ci.nsIImageLoadingContent); |
michael@0 | 87 | imgLoadingContent.removeObserver(gMyDecoderObserver); |
michael@0 | 88 | SimpleTest.finish(); |
michael@0 | 89 | gIsTestFinished = true; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function main() { |
michael@0 | 93 | takeReferenceSnapshot(); |
michael@0 | 94 | |
michael@0 | 95 | // Create, customize & attach decoder observer |
michael@0 | 96 | observer = new ImageDecoderObserverStub(); |
michael@0 | 97 | observer.frameComplete = myOnStopFrame; |
michael@0 | 98 | gMyDecoderObserver = |
michael@0 | 99 | Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools) |
michael@0 | 100 | .createScriptedObserver(observer); |
michael@0 | 101 | let imgLoadingContent = gImg.QueryInterface(Ci.nsIImageLoadingContent); |
michael@0 | 102 | imgLoadingContent.addObserver(gMyDecoderObserver); |
michael@0 | 103 | |
michael@0 | 104 | // We want to test the cold loading behavior, so clear cache in case an |
michael@0 | 105 | // earlier test got our image in there already. |
michael@0 | 106 | clearImageCache(); |
michael@0 | 107 | |
michael@0 | 108 | // kick off image-loading! myOnStopFrame handles the rest. |
michael@0 | 109 | gImg.setAttribute("src", "lime-anim-100x100-2.svg"); |
michael@0 | 110 | |
michael@0 | 111 | // In case something goes wrong, fail earlier than mochitest timeout, |
michael@0 | 112 | // and with more information. |
michael@0 | 113 | setTimeout(failTest, FAILURE_TIMEOUT); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | window.onload = main; |
michael@0 | 117 | |
michael@0 | 118 | </script> |
michael@0 | 119 | </pre> |
michael@0 | 120 | </body> |
michael@0 | 121 | </html> |