/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. <!--
  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 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. SimpleTest.waitForExplicitFinish();
  21. var canvas = document.getElementById('canvas');
  22. var first, second, third;
  23. RemoteCanvas = function() {
  24. this.url = "bug490949-iframe.html";
  25. };
  26. RemoteCanvas.CANVAS_WIDTH = 100;
  27. RemoteCanvas.CANVAS_HEIGHT = 100;
  28. RemoteCanvas.prototype.load = function(cb) {
  29. this.cb = cb;
  30. var windowWidth = window.innerWidth - 25;
  31. var iframe;
  32. iframe = document.createElement("iframe");
  33. iframe.id = "test-iframe";
  34. iframe.height = "10px";
  35. iframe.width = windowWidth + "px";
  36. iframe.style.visibility = "hidden";
  37. iframe.src = this.url;
  38. // Here is where the magic happens... add a listener to the
  39. // frame's onload event - it will call handleEvent
  40. iframe.addEventListener("load", this, true);
  41. //append to the end of the page
  42. window.document.body.appendChild(iframe);
  43. };
  44. RemoteCanvas.prototype.reload = function(cb, force) {
  45. this.cb = cb;
  46. window.frames[0].location.reload(force);
  47. }
  48. RemoteCanvas.prototype.handleEvent = function() {
  49. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  50. // Look back up the iframe by id
  51. var ldrFrame = document.getElementById("test-iframe");
  52. // Get a reference to the window object you need for the canvas
  53. // drawWindow method
  54. var remoteWindow = ldrFrame.contentWindow;
  55. //Draw canvas
  56. canvas.style.width = RemoteCanvas.CANVAS_WIDTH + "px";
  57. canvas.style.height = RemoteCanvas.CANVAS_HEIGHT + "px";
  58. canvas.width = RemoteCanvas.CANVAS_WIDTH;
  59. canvas.height = RemoteCanvas.CANVAS_HEIGHT;
  60. var windowWidth = window.innerWidth - 25;
  61. var windowHeight = window.innerHeight;
  62. var ctx = canvas.getContext("2d");
  63. ctx.clearRect(0, 0,
  64. RemoteCanvas.CANVAS_WIDTH,
  65. RemoteCanvas.CANVAS_HEIGHT);
  66. ctx.save();
  67. ctx.scale(RemoteCanvas.CANVAS_WIDTH / windowWidth,
  68. RemoteCanvas.CANVAS_HEIGHT / windowHeight);
  69. ctx.drawWindow(remoteWindow,
  70. 0, 0,
  71. windowWidth, windowHeight,
  72. "rgb(0,0,0)");
  73. ctx.restore();
  74. this.cb();
  75. };
  76. function checkFirst()
  77. {
  78. first = canvas.toDataURL();
  79. remoteCanvas.reload(checkForceReload, true);
  80. }
  81. function checkForceReload()
  82. {
  83. second = canvas.toDataURL();
  84. ok(first != second, "We got the wrong image.");
  85. remoteCanvas.reload(checkLazyReload, false);
  86. }
  87. function checkLazyReload()
  88. {
  89. third = canvas.toDataURL();
  90. ok(second != third, "We got the wrong image.");
  91. SimpleTest.finish();
  92. }
  93. var remoteCanvas = new RemoteCanvas();
  94. remoteCanvas.load(checkFirst);
  95. </script>
  96. </pre>
  97. </body>
  98. </html>