1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/test/mochitest/test_bug490949.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=490949 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 490949</title> 1.11 + <script type="application/javascript" src="/MochiKit/MochiKit.js"></script> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=490949">Mozilla Bug 490949</a> 1.17 +<p id="display"></p> 1.18 +<div id="content" style="display: none"> 1.19 +<canvas id="canvas" width="100" height="100"> </canvas> 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script type="application/javascript"> 1.23 + 1.24 +SimpleTest.waitForExplicitFinish(); 1.25 + 1.26 +var canvas = document.getElementById('canvas'); 1.27 +var first, second, third; 1.28 + 1.29 +RemoteCanvas = function() { 1.30 + this.url = "bug490949-iframe.html"; 1.31 +}; 1.32 + 1.33 +RemoteCanvas.CANVAS_WIDTH = 100; 1.34 +RemoteCanvas.CANVAS_HEIGHT = 100; 1.35 + 1.36 +RemoteCanvas.prototype.load = function(cb) { 1.37 + this.cb = cb; 1.38 + 1.39 + var windowWidth = window.innerWidth - 25; 1.40 + var iframe; 1.41 + iframe = document.createElement("iframe"); 1.42 + iframe.id = "test-iframe"; 1.43 + iframe.height = "10px"; 1.44 + iframe.width = windowWidth + "px"; 1.45 + iframe.style.visibility = "hidden"; 1.46 + iframe.src = this.url; 1.47 + // Here is where the magic happens... add a listener to the 1.48 + // frame's onload event - it will call handleEvent 1.49 + iframe.addEventListener("load", this, true); 1.50 + //append to the end of the page 1.51 + window.document.body.appendChild(iframe); 1.52 +}; 1.53 + 1.54 +RemoteCanvas.prototype.reload = function(cb, force) { 1.55 + this.cb = cb; 1.56 + window.frames[0].location.reload(force); 1.57 +} 1.58 + 1.59 +RemoteCanvas.prototype.handleEvent = function() { 1.60 + // Look back up the iframe by id 1.61 + var ldrFrame = document.getElementById("test-iframe"); 1.62 + // Get a reference to the window object you need for the 1.63 + // SpecialPowers.snapshotRect method 1.64 + var remoteWindow = ldrFrame.contentWindow; 1.65 + 1.66 + //Draw canvas 1.67 + canvas.style.width = RemoteCanvas.CANVAS_WIDTH + "px"; 1.68 + canvas.style.height = RemoteCanvas.CANVAS_HEIGHT + "px"; 1.69 + canvas.width = RemoteCanvas.CANVAS_WIDTH; 1.70 + canvas.height = RemoteCanvas.CANVAS_HEIGHT; 1.71 + var windowWidth = window.innerWidth - 25; 1.72 + var windowHeight = window.innerHeight; 1.73 + 1.74 + var rect = { left: 0, top: 0, width: windowWidth, height: windowHeight }; 1.75 + var snapshot = SpecialPowers.snapshotRect(remoteWindow, rect, "rgb(0,0,0)"); 1.76 + 1.77 + var ctx = canvas.getContext("2d"); 1.78 + ctx.clearRect(0, 0, 1.79 + RemoteCanvas.CANVAS_WIDTH, 1.80 + RemoteCanvas.CANVAS_HEIGHT); 1.81 + ctx.save(); 1.82 + ctx.scale(RemoteCanvas.CANVAS_WIDTH / windowWidth, 1.83 + RemoteCanvas.CANVAS_HEIGHT / windowHeight); 1.84 + ctx.drawImage(snapshot, 0, 0); 1.85 + ctx.restore(); 1.86 + this.cb(); 1.87 +}; 1.88 + 1.89 +function checkFirst() 1.90 +{ 1.91 + first = canvas.toDataURL(); 1.92 + remoteCanvas.reload(checkForceReload, true); 1.93 +} 1.94 + 1.95 +function checkForceReload() 1.96 +{ 1.97 + second = canvas.toDataURL(); 1.98 + ok(first != second, "We got the wrong image."); 1.99 + remoteCanvas.reload(checkLazyReload, false); 1.100 +} 1.101 + 1.102 +function checkLazyReload() 1.103 +{ 1.104 + third = canvas.toDataURL(); 1.105 + ok(second != third, "We got the wrong image."); 1.106 + SimpleTest.finish(); 1.107 +} 1.108 + 1.109 +var remoteCanvas = new RemoteCanvas(); 1.110 +remoteCanvas.load(checkFirst); 1.111 + 1.112 +</script> 1.113 +</pre> 1.114 +</body> 1.115 +</html>