tor-browser

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

test_bug1132427.html (4262B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for scrolling selection into view</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <script src="/tests/SimpleTest/WindowSnapshot.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 
     11 <pre id="test">
     12 <script class="testbody" type="text/javascript">
     13 
     14 // We open a window which contains two copies of the same gif. One at a scaled size, one at the
     15 // natural image size. We rely on the bug only showing up in the scaled image. The gif has three
     16 // frames and a delay of 100ms. The first is all white. The second has a very small update area
     17 // in the upper left, it changes the pixels to slightly off white. The third changes all the
     18 // pixels to blue. When the bug appears we only update the upper left pixels when looping around
     19 // from the last frame to the first frame. We compare a middle pixel of the two images to make
     20 // sure that they are the same at 100ms for a second. If the bug appears then the middle pixel
     21 // on the scaled image will always be blue and so should not match the middle pixel on the
     22 // unscaled image which should be white two thirds of the time. If the timers fire at bad times
     23 // and only fire when both frames are displaying blue we won't be able to detect this bug and the
     24 // test will pass without testing anything important, but that's not a big deal. That should be
     25 // rare enough, and the next time the test is run will should do proper testing.
     26 
     27 SimpleTest.requestFlakyTimeout("Pre-existing timeouts when converting from mochitest-chrome");
     28 SimpleTest.waitForExplicitFinish();
     29 addLoadEvent(openWindow);
     30 
     31 var win = null;
     32 
     33 function openWindow() {
     34  win = window.open("bug1132427.html",
     35                "", "scrollbars=yes,toolbar,menubar,width=600,height=800");
     36  win.focus();
     37 }
     38 
     39 function doTest() {
     40  setTimeout(continueTest, 1000);
     41 }
     42 
     43 function checkPixel(canvas, context, x1, y1, x2, y2) {
     44  var pix = context.getImageData(0, 0, canvas.width, canvas.height).data;
     45  for (var i = 0; i < 4; i++) {
     46    is(pix[4 * (y1 * canvas.width + x1) + i], pix[4 * (y2 * canvas.width + x2) + i], "pixels should match");
     47  }
     48 }
     49 
     50 var iterationsLeft = 10;
     51 
     52 function continueTest() {
     53  // we need to drawWindow the chrome window so we can get a dump of the retained widget layers
     54  // if we have to repaint to fulfill this drawWindow request then it will be impossible to
     55  // observe the bug
     56  // XXX(kmag): This test has not had access to a chrome window since the dawn
     57  // of e10s. I'm not sure how accurate the above comment was even before that
     58  // point, but it certainly is not accurate now.
     59  var topWin = SpecialPowers.wrap(win).top;
     60 
     61  var el = window.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
     62  el.width = topWin.innerWidth;
     63  el.height = topWin.innerHeight;
     64  var ctx = el.getContext("2d");
     65  // pass the correct flags so we don't have to flush the retained layers
     66  SpecialPowers.wrap(ctx).drawWindow(topWin, 0, 0, topWin.innerWidth, topWin.innerHeight, "rgba(0,0,0,0)",
     67    ctx.DRAWWINDOW_USE_WIDGET_LAYERS | ctx.DRAWWINDOW_DRAW_VIEW | ctx.DRAWWINDOW_DRAW_CARET);
     68 
     69  var leftbox = win.document.getElementById("left").getBoundingClientRect();
     70  var rightbox = win.document.getElementById("right").getBoundingClientRect();
     71  // this is actually chrome on left and right, but in practice we have none so it doesn't matter
     72  var chromeleft = win.outerWidth - win.innerWidth;
     73  // this is actually chrome on top and bottom, but bottom chrome is usually small to none and we have
     74  // 100px to spare in hitting the middle of the image elements (they are 200x200)
     75  var chrometop = win.outerHeight - win.innerHeight;
     76 
     77  // compare the middle of the two image elements
     78  checkPixel(el, ctx, chromeleft + leftbox.left + Math.floor(leftbox.width/2), chrometop + leftbox.top + Math.floor(leftbox.height/2),
     79                      chromeleft + rightbox.left + Math.floor(rightbox.width/2), chrometop + rightbox.top + Math.floor(rightbox.height/2));
     80 
     81  iterationsLeft--;
     82  if (iterationsLeft > 0) {
     83    // now test 100ms later, we should have the next frame of the gif then
     84    setTimeout(continueTest, 100);
     85  } else {
     86    win.close();
     87    SimpleTest.finish();
     88  }
     89 }
     90 </script>
     91 </pre>
     92 </body>
     93 
     94 </html>