tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug490949.html (3169B)


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