PageRenderTime 37ms CodeModel.GetById 14ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/image/test/mochitest/test_bug490949.html

http://github.com/zpao/v8monkey
HTML | 114 lines | 95 code | 16 blank | 3 comment | 0 complexity | 03af2fbedbe8de61300e1a60f364b1a0 MD5 | raw file
  1<!DOCTYPE HTML>
  2<html>
  3<!--
  4https://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 onload="checkFirst()">
 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
 21SimpleTest.waitForExplicitFinish();
 22
 23var canvas = document.getElementById('canvas');
 24var first, second, third;
 25
 26RemoteCanvas = function() {
 27    this.url = "bug490949-iframe.html";
 28};
 29
 30RemoteCanvas.CANVAS_WIDTH = 100;
 31RemoteCanvas.CANVAS_HEIGHT = 100;
 32
 33RemoteCanvas.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
 51RemoteCanvas.prototype.reload = function(cb, force) {
 52    this.cb = cb;
 53    window.frames[0].location.reload(force);
 54}
 55
 56RemoteCanvas.prototype.handleEvent = function() {
 57    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 58
 59    // Look back up the iframe by id
 60    var ldrFrame = document.getElementById("test-iframe");
 61    // Get a reference to the window object you need for the canvas
 62    // drawWindow method
 63    var remoteWindow = ldrFrame.contentWindow;
 64
 65    //Draw canvas
 66    canvas.style.width = RemoteCanvas.CANVAS_WIDTH + "px";
 67    canvas.style.height = RemoteCanvas.CANVAS_HEIGHT + "px";
 68    canvas.width = RemoteCanvas.CANVAS_WIDTH;
 69    canvas.height = RemoteCanvas.CANVAS_HEIGHT;
 70    var windowWidth = window.innerWidth - 25;
 71    var windowHeight = window.innerHeight;
 72
 73    var ctx = canvas.getContext("2d");
 74    ctx.clearRect(0, 0,
 75                  RemoteCanvas.CANVAS_WIDTH,
 76                  RemoteCanvas.CANVAS_HEIGHT);
 77    ctx.save();
 78    ctx.scale(RemoteCanvas.CANVAS_WIDTH / windowWidth,
 79              RemoteCanvas.CANVAS_HEIGHT / windowHeight);
 80    ctx.drawWindow(remoteWindow,
 81                   0, 0,
 82                   windowWidth, windowHeight,
 83                   "rgb(0,0,0)");
 84    ctx.restore();
 85    this.cb();
 86};
 87
 88function checkFirst()
 89{
 90  first = canvas.toDataURL();
 91  remoteCanvas.reload(checkForceReload, true);
 92}
 93
 94function checkForceReload()
 95{
 96  second = canvas.toDataURL();
 97  ok(first != second, "We got the wrong image.");
 98  remoteCanvas.reload(checkLazyReload, false);
 99}
100
101function checkLazyReload()
102{
103  third = canvas.toDataURL();
104  ok(second != third, "We got the wrong image.");
105  SimpleTest.finish();
106}
107
108var remoteCanvas = new RemoteCanvas();
109remoteCanvas.load(checkFirst);
110
111</script>
112</pre>
113</body>
114</html>