<!DOCTYPE HTML><html><!--https://bugzilla.mozilla.org/show_bug.cgi?id=490949--><head><title>Test for Bug 490949</title><scriptsrc="/tests/SimpleTest/SimpleTest.js"></script><linkrel="stylesheet"type="text/css"href="/tests/SimpleTest/test.css"/></head><body><atarget="_blank"href="https://bugzilla.mozilla.org/show_bug.cgi?id=490949">Mozilla Bug 490949</a><pid="display"></p><divid="content"style="display: none"><canvasid="canvas"width="100"height="100"></canvas></div><preid="test"><scripttype="application/javascript">SimpleTest.waitForExplicitFinish();varcanvas=document.getElementById('canvas');varfirst,second,third;varRemoteCanvas=function(){this.url="bug490949-iframe.html";};RemoteCanvas.CANVAS_WIDTH=100;RemoteCanvas.CANVAS_HEIGHT=100;RemoteCanvas.prototype.load=function(cb){this.cb=cb;varwindowWidth=window.innerWidth-25;variframe;iframe=document.createElement("iframe");iframe.id="test-iframe";iframe.height="10px";iframe.width=windowWidth+"px";iframe.style.visibility="hidden";iframe.src=this.url;// Here is where the magic happens... add a listener to the// frame's onload event - it will call handleEventiframe.addEventListener("load",this,true);// append to the end of the pagewindow.document.body.appendChild(iframe);};RemoteCanvas.prototype.reload=function(cb,force){this.cb=cb;window.frames[0].location.reload(force);}RemoteCanvas.prototype.handleEvent=function(){// Look back up the iframe by idvarldrFrame=document.getElementById("test-iframe");// Get a reference to the window object you need for the// SpecialPowers.snapshotRect methodvarremoteWindow=ldrFrame.contentWindow;// Draw canvascanvas.style.width=RemoteCanvas.CANVAS_WIDTH+"px";canvas.style.height=RemoteCanvas.CANVAS_HEIGHT+"px";canvas.width=RemoteCanvas.CANVAS_WIDTH;canvas.height=RemoteCanvas.CANVAS_HEIGHT;varwindowWidth=window.innerWidth-25;varwindowHeight=window.innerHeight;varrect={left:0,top:0,width:windowWidth,height:windowHeight};varsnapshot=SpecialPowers.snapshotRect(remoteWindow,rect,"rgb(0,0,0)");varctx=canvas.getContext("2d");ctx.clearRect(0,0,RemoteCanvas.CANVAS_WIDTH,RemoteCanvas.CANVAS_HEIGHT);ctx.save();ctx.scale(RemoteCanvas.CANVAS_WIDTH/windowWidth,RemoteCanvas.CANVAS_HEIGHT/windowHeight);ctx.drawImage(snapshot,0,0);ctx.restore();this.cb();};functioncheckFirst(){first=canvas.toDataURL();remoteCanvas.reload(checkForceReload,true);}functioncheckForceReload(){second=canvas.toDataURL();ok(first!=second,"We got the wrong image.");remoteCanvas.reload(checkLazyReload,false);}functioncheckLazyReload(){third=canvas.toDataURL();ok(second!=third,"We got the wrong image.");SimpleTest.finish();}varremoteCanvas=newRemoteCanvas();remoteCanvas.load(checkFirst);</script></pre></body></html>