widget/tests/test_plugin_scroll_invalidation.html
author Alexander Surkov <surkov.alexander@gmail.com>
Thu, 03 Feb 2011 19:02:26 +0100
branchGECKO20b11_2011020209_RELBRANCH
changeset 61868 7893f45c72c5dd307ed6747c7d351375586bcad9
parent 47757 41143b03b5a141fcd77e4aed43bb7a29af2e9d17
child 74318 1188456710819d4606e74396be333ead9fe63261
permissions -rw-r--r--
Bug 631160 - embedded accessible may expose wrong text, r=davidb, r=marcoz, a=blocking

<!DOCTYPE HTML>
<html>
<head>
  <title>Test for plugin child widgets not being invalidated by scrolling</title>
  <script type="text/javascript" src="/MochiKit/packed.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="initialize()">
<p id="display">
  <iframe id="i" src="plugin_scroll_invalidation.html"
   width="50" height="50" scrolling="no"></iframe>
</p>
<div id="content" style="display: none">

</div>
<pre id="test">
</pre>

<script type="application/javascript">
SimpleTest.waitForExplicitFinish();

var scrolling;
var scrolling_plugins = [];
var paint_waiter;
var last_paint_counts;

function initialize() {
  scrolling = document.getElementById("i").contentWindow;
  scrolling_plugins = scrolling.document.querySelectorAll("embed.scrolling");
  paint_waiter = scrolling.document.getElementById("paint-waiter");

  scrolling.scrollTo(50, 45);

  is(paint_waiter.getPaintCount(), 0, "zero-sized plugin not painted");
  waitForPaint(scrollAround);
}

function scrollAround() {
  var paints = getPaintCounts();

  for (var i = 0; i < paints.length; ++i) {
    isnot(paints[i], 0, "embed " + scrolling_plugins[i].id + " is painted"); 
  }

  last_paint_counts = paints;

  scrolling.scrollBy(-5, 5);
  scrolling.scrollBy(5, 5);
  scrolling.scrollBy(5, -5);
  scrolling.scrollBy(-5, -5);

  scrolling.scrollTo(45, 45);
  scrolling.scrollBy(10, 0);
  scrolling.scrollBy(0, 10);
  scrolling.scrollBy(-10, 0);
  scrolling.scrollBy(0, -10);

  waitForPaint(done);
}

function done() {
  var paints = getPaintCounts();
  for (var i = 0; i < paints.length; ++i) {
    is(paints[i], last_paint_counts[i], "embed " + scrolling_plugins[i].id + " is not painted on scroll");
  }
  SimpleTest.finish();  
}

function waitForPaint(func) {
  paint_waiter.last_paint_count = paint_waiter.getPaintCount();
  paint_waiter.style.left = scrolling.scrollX + "px";
  paint_waiter.style.top = scrolling.scrollY + "px";
  paint_waiter.style.width = "1px";
  paint_waiter.style.height = "1px";
  waitForPaintHelper(func);
}

function waitForPaintHelper(func) {
  if (paint_waiter.getPaintCount() != paint_waiter.last_paint_count) {
    // hide the paint waiter
    paint_waiter.style.width = "0px";
    paint_waiter.style.height = "0px";
    setTimeout(func, 0);
    return;
  }
  setTimeout(function() { waitForPaintHelper(func); }, 100);
}

function getPaintCounts() {
  var result = [];
  for (var i = 0; i < scrolling_plugins.length; ++i) {
    result[i] = scrolling_plugins[i].getPaintCount();
  }
  return result;
}

</script>
</body>
</html>