image/test/mochitest/test_bug490949.html

branch
TOR_BUG_9701
changeset 14
925c144e1f1f
equal deleted inserted replaced
-1:000000000000 0:1a137ba79067
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=490949
5 -->
6 <head>
7 <title>Test for Bug 490949</title>
8 <script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=490949">Mozilla Bug 490949</a>
14 <p id="display"></p>
15 <div id="content" style="display: none">
16 <canvas id="canvas" width="100" height="100"> </canvas>
17 </div>
18 <pre id="test">
19 <script type="application/javascript">
20
21 SimpleTest.waitForExplicitFinish();
22
23 var canvas = document.getElementById('canvas');
24 var first, second, third;
25
26 RemoteCanvas = function() {
27 this.url = "bug490949-iframe.html";
28 };
29
30 RemoteCanvas.CANVAS_WIDTH = 100;
31 RemoteCanvas.CANVAS_HEIGHT = 100;
32
33 RemoteCanvas.prototype.load = function(cb) {
34 this.cb = cb;
35
36 var windowWidth = window.innerWidth - 25;
37 var iframe;
38 iframe = document.createElement("iframe");
39 iframe.id = "test-iframe";
40 iframe.height = "10px";
41 iframe.width = windowWidth + "px";
42 iframe.style.visibility = "hidden";
43 iframe.src = this.url;
44 // Here is where the magic happens... add a listener to the
45 // frame's onload event - it will call handleEvent
46 iframe.addEventListener("load", this, true);
47 //append to the end of the page
48 window.document.body.appendChild(iframe);
49 };
50
51 RemoteCanvas.prototype.reload = function(cb, force) {
52 this.cb = cb;
53 window.frames[0].location.reload(force);
54 }
55
56 RemoteCanvas.prototype.handleEvent = function() {
57 // Look back up the iframe by id
58 var ldrFrame = document.getElementById("test-iframe");
59 // Get a reference to the window object you need for the
60 // SpecialPowers.snapshotRect method
61 var remoteWindow = ldrFrame.contentWindow;
62
63 //Draw canvas
64 canvas.style.width = RemoteCanvas.CANVAS_WIDTH + "px";
65 canvas.style.height = RemoteCanvas.CANVAS_HEIGHT + "px";
66 canvas.width = RemoteCanvas.CANVAS_WIDTH;
67 canvas.height = RemoteCanvas.CANVAS_HEIGHT;
68 var windowWidth = window.innerWidth - 25;
69 var windowHeight = window.innerHeight;
70
71 var rect = { left: 0, top: 0, width: windowWidth, height: windowHeight };
72 var snapshot = SpecialPowers.snapshotRect(remoteWindow, rect, "rgb(0,0,0)");
73
74 var ctx = canvas.getContext("2d");
75 ctx.clearRect(0, 0,
76 RemoteCanvas.CANVAS_WIDTH,
77 RemoteCanvas.CANVAS_HEIGHT);
78 ctx.save();
79 ctx.scale(RemoteCanvas.CANVAS_WIDTH / windowWidth,
80 RemoteCanvas.CANVAS_HEIGHT / windowHeight);
81 ctx.drawImage(snapshot, 0, 0);
82 ctx.restore();
83 this.cb();
84 };
85
86 function checkFirst()
87 {
88 first = canvas.toDataURL();
89 remoteCanvas.reload(checkForceReload, true);
90 }
91
92 function checkForceReload()
93 {
94 second = canvas.toDataURL();
95 ok(first != second, "We got the wrong image.");
96 remoteCanvas.reload(checkLazyReload, false);
97 }
98
99 function checkLazyReload()
100 {
101 third = canvas.toDataURL();
102 ok(second != third, "We got the wrong image.");
103 SimpleTest.finish();
104 }
105
106 var remoteCanvas = new RemoteCanvas();
107 remoteCanvas.load(checkFirst);
108
109 </script>
110 </pre>
111 </body>
112 </html>

mercurial