1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/test/test_smilExtDoc.xhtml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<!-- 1.6 +https://bugzilla.mozilla.org/show_bug.cgi?id=628888 1.7 +--> 1.8 +<head> 1.9 + <title>Test for Bug 628888 - Animations in external document sometimes don't run</title> 1.10 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.11 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.12 +</head> 1.13 +<body style="margin:0px"> 1.14 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=628888">Mozilla Bug 628888</a> 1.15 +<p id="display"></p> 1.16 +<div id="content" style="background: red; width: 50px; height: 50px"/> 1.17 + 1.18 +<pre id="test"> 1.19 +<script type="application/javascript"> 1.20 +<![CDATA[ 1.21 + 1.22 +/* Test for Bug 628888 - Animations in external document sometimes don't run 1.23 + * 1.24 + * This bug concerns a condition where an external document is loaded after the 1.25 + * page show event is dispatched, leaving the external document paused. 1.26 + * 1.27 + * To reproduce the bug we attach an external document with animation after the 1.28 + * page show event has fired. 1.29 + * 1.30 + * However, it is difficult to test if the animation is playing or not since we 1.31 + * don't receive events from animations running in an external document. 1.32 + * 1.33 + * Our approach is to simply render the result to a canvas (which requires 1.34 + * elevated privileges and that is why we are using a MochiTest rather 1.35 + * than a reftest) and poll one of the pixels to see if it changes colour. 1.36 + * 1.37 + * This should mean the test succeeds quickly but fails slowly. 1.38 + */ 1.39 + 1.40 +const POLL_INTERVAL = 100; // ms 1.41 +const POLL_TIMEOUT = 10000; // ms 1.42 +var accumulatedWaitTime = 0; 1.43 + 1.44 +function pageShow() 1.45 +{ 1.46 + var content = document.getElementById("content"); 1.47 + content.style.filter = "url(smilExtDoc_helper.svg#filter)"; 1.48 + window.setTimeout(checkResult, 0); 1.49 +} 1.50 + 1.51 +function checkResult() 1.52 +{ 1.53 + var content = document.getElementById("content"); 1.54 + var bbox = content.getBoundingClientRect(); 1.55 + 1.56 + var canvas = SpecialPowers.snapshotRect(window, bbox); 1.57 + var ctx = canvas.getContext("2d"); 1.58 + 1.59 + var imgd = ctx.getImageData(bbox.width/2, bbox.height/2, 1, 1); 1.60 + var isGreen = (imgd.data[0] == 0) && 1.61 + (imgd.data[1] == 255) && 1.62 + (imgd.data[2] == 0); 1.63 + if (isGreen) { 1.64 + ok(true, "Filter is animated as expected"); 1.65 + } else if (accumulatedWaitTime >= POLL_TIMEOUT) { 1.66 + ok(false, "No animation detected after waiting " + POLL_TIMEOUT + "ms"); 1.67 + } else { 1.68 + accumulatedWaitTime += POLL_INTERVAL; 1.69 + window.setTimeout(checkResult, POLL_INTERVAL); 1.70 + return; 1.71 + } 1.72 + // Hide our content since mochitests normally try to be visually "quiet" 1.73 + content.style.display = 'none'; 1.74 + SimpleTest.finish(); 1.75 +} 1.76 +window.addEventListener('pageshow', pageShow, false); 1.77 +SimpleTest.waitForExplicitFinish(); 1.78 +]]> 1.79 +</script> 1.80 +</pre> 1.81 +</body> 1.82 +</html>