Bug 626245. Part 1: Refactor test_plugin_scroll_invalidation to definitely wait for a paint between each call to waitForPaint. r=matspal
authorRobert O'Callahan <robert@ocallahan.org>
Mon, 08 Oct 2012 17:45:16 +1300
changeset 110318 70c50c331112e6b2f9d03cb933d4d6c2c15b2545
parent 110317 0f0797cdb55a59cadb71837510a53aeae0962a41
child 110319 c4da85db655437a37af15da1d5fa498c40efc27b
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmatspal
bugs626245
milestone19.0a1
Bug 626245. Part 1: Refactor test_plugin_scroll_invalidation to definitely wait for a paint between each call to waitForPaint. r=matspal The current code sets the plugin size to 0,0 and then does some stuff after a setTimeout(0), then sets the size back to 1,1 and expects to be sure to get a new paint event. This is wrong since the timing of plugin geometry changes isn't guaranteed, so we might simply not resize the plugin between setting the size to 0,0 and 1,1.
widget/tests/test_plugin_scroll_invalidation.html
--- a/widget/tests/test_plugin_scroll_invalidation.html
+++ b/widget/tests/test_plugin_scroll_invalidation.html
@@ -27,16 +27,17 @@ 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"); 
@@ -61,34 +62,37 @@ function scrollAround() {
 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();  
 }
 
+// Waits for the paint_waiter plugin to be repainted and then
+// calls 'func' to continue.
 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";
+
+  // Fiddle with the style in a way that should force some repainting
+  paint_waiter.style.width =
+    (paint_waiter.getBoundingClientRect().width + 1) + "px"; 
   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;
+  function waitForPaintHelper() {
+    if (paint_waiter.getPaintCount() != paint_waiter.last_paint_count) {
+      setTimeout(func, 0);
+      return;
+    }
+    setTimeout(waitForPaintHelper, 0);
   }
-  setTimeout(function() { waitForPaintHelper(func); }, 100);
+  waitForPaintHelper();
 }
 
 function getPaintCounts() {
   var result = [];
   for (var i = 0; i < scrolling_plugins.length; ++i) {
     result[i] = scrolling_plugins[i].getPaintCount();
   }
   return result;