image/test/mochitest/test_animSVGImage.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.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=610419
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 610419</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=610419">Mozilla Bug 610419</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 610419**/
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
michael@0 38
michael@0 39 function takeReferenceSnapshot() {
michael@0 40 // Take a snapshot of the initial (essentially blank) page
michael@0 41 let blankSnapshot = snapshotWindow(window, false);
michael@0 42
michael@0 43 // Show reference div, & take a snapshot
michael@0 44 let referenceDiv = document.getElementById("referenceDiv");
michael@0 45 referenceDiv.style.display = "block";
michael@0 46 gReferenceSnapshot = snapshotWindow(window, false);
michael@0 47 ok(compareSnapshots(blankSnapshot, gReferenceSnapshot, false)[0],
michael@0 48 "reference snapshot shouldn't match blank page snapshot");
michael@0 49
michael@0 50 // Re-hide reference div, and take another snapshot to be sure it's gone
michael@0 51 referenceDiv.style.display = "none";
michael@0 52 let blankSnapshot2 = snapshotWindow(window, false);
michael@0 53 ok(compareSnapshots(blankSnapshot, blankSnapshot2, true)[0],
michael@0 54 "reference div should disappear when it becomes display:none");
michael@0 55 }
michael@0 56
michael@0 57 function myOnStopFrame() {
michael@0 58 gOnStopFrameCounter++;
michael@0 59 ok(true, "myOnStopFrame called");
michael@0 60 let currentSnapshot = snapshotWindow(window, false);
michael@0 61 if (compareSnapshots(currentSnapshot, gReferenceSnapshot, true)[0]) {
michael@0 62 // SUCCESS!
michael@0 63 ok(true, "Animated image looks correct, " +
michael@0 64 "at call #" + gOnStopFrameCounter + " to onStopFrame");
michael@0 65 cleanUpAndFinish();
michael@0 66 }
michael@0 67 else
michael@0 68 setTimeout(myOnStopFrame, 1);
michael@0 69 }
michael@0 70
michael@0 71 function failTest() {
michael@0 72 ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " +
michael@0 73 "Animated image still doesn't look correct, " +
michael@0 74 "after call #" + gOnStopFrameCounter + " to onStopFrame");
michael@0 75 cleanUpAndFinish();
michael@0 76 }
michael@0 77
michael@0 78 function cleanUpAndFinish() {
michael@0 79 // On the off chance that failTest and myOnStopFrame are triggered
michael@0 80 // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish.
michael@0 81 if (gIsTestFinished) {
michael@0 82 return;
michael@0 83 }
michael@0 84 SimpleTest.finish();
michael@0 85 gIsTestFinished = true;
michael@0 86 }
michael@0 87
michael@0 88 function main() {
michael@0 89 takeReferenceSnapshot();
michael@0 90
michael@0 91 // We want to test the cold loading behavior, so clear cache in case an
michael@0 92 // earlier test got our image in there already.
michael@0 93 clearImageCache();
michael@0 94
michael@0 95 setTimeout(myOnStopFrame, 1);
michael@0 96
michael@0 97 // kick off image-loading! myOnStopFrame handles the rest.
michael@0 98 gImg.setAttribute("src", "lime-anim-100x100.svg");
michael@0 99
michael@0 100 // In case something goes wrong, fail earlier than mochitest timeout,
michael@0 101 // and with more information.
michael@0 102 setTimeout(failTest, FAILURE_TIMEOUT);
michael@0 103 }
michael@0 104
michael@0 105 window.onload = main;
michael@0 106
michael@0 107 </script>
michael@0 108 </pre>
michael@0 109 </body>
michael@0 110 </html>

mercurial