b=518506 test no unnecessary invalidation of plugins with gtk2
authorKarl Tomlinson <karlt+@karlt.net>
Mon, 14 Dec 2009 15:32:46 +1300
changeset 35699 f20c4c211ac85da40ed2b1098ea1c5049c9e621e
parent 35698 274480cf21d74e008336532f954e48d3700f3504
child 35700 1f0cfbdf428aa52fdb27dbef9061f2af486c73d1
push id10683
push userktomlinson@mozilla.com
push dateMon, 14 Dec 2009 02:37:51 +0000
treeherdermozilla-central@f20c4c211ac8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs518506
milestone1.9.3a1pre
b=518506 test no unnecessary invalidation of plugins with gtk2
widget/tests/Makefile.in
widget/tests/plugin_scroll_invalidation.html
widget/tests/test_plugin_scroll_invalidation.html
--- a/widget/tests/Makefile.in
+++ b/widget/tests/Makefile.in
@@ -50,48 +50,61 @@ ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 ifdef NS_ENABLE_TSF
 CPP_UNIT_TESTS += TestWinTSF.cpp  \
                   $(NULL)
 endif
 endif
 
 include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =	test_bug343416.xul \
+_TEST_FILES =
+
+_CHROME_FILES =	test_bug343416.xul \
 		test_bug429954.xul \
 		window_bug429954.xul \
 		test_bug444800.xul \
 		test_bug462106.xul \
 		test_bug478536.xul \
 		window_bug478536.xul \
 		test_bug517396.xul \
 		test_keycodes.xul \
 		test_wheeltransaction.xul \
 		window_wheeltransaction.xul \
 		test_imestate.html \
 		test_plugin_scroll_consistency.html \
 		$(NULL)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
-_TEST_FILES += native_menus_window.xul \
+_CHROME_FILES += native_menus_window.xul \
                test_native_menus.xul \
                native_mouse_mac_window.xul \
                test_native_mouse_mac.xul \
                test_bug428405.xul \
                test_bug466599.xul \
                test_bug485118.xul \
                test_bug522217.xul \
                window_bug522217.xul \
                test_platform_colors.xul \
                $(NULL)
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 ifneq ($(OS_ARCH), WINCE)
-_TEST_FILES  += taskbar_previews.xul \
+_CHROME_FILES  += taskbar_previews.xul \
 		window_state_windows.xul \
 		taskbar_progress.xul \
 		$(NULL)
 endif
 endif
 
+ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
+_TEST_FILES += 	plugin_scroll_invalidation.html \
+		test_plugin_scroll_invalidation.html \
+		$(NULL)
+endif
+
+ifdef _TEST_FILES
 libs:: $(_TEST_FILES)
+	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+endif
+
+libs:: $(_CHROME_FILES)
 	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/widget/tests/plugin_scroll_invalidation.html
@@ -0,0 +1,60 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test helper for plugin child widgets not being invalidated by scrolling</title>
+  <style>
+    body {
+      background: -moz-linear-gradient(top, red, black);
+      width: 200px;
+      height: 200px;
+    }
+    embed {
+      position:absolute;
+    }
+    embed#paint-waiter {
+      top: 0px;
+      left: 0px;
+      width: 0px;
+      height: 0px;
+    }
+    embed#e0 {
+      top: 70px;
+      left: 70px;
+      width: 10px;
+      height: 10px;
+    }
+    embed#e1 {
+      top: 60px;
+      left: 60px;
+      width: 10px;
+      height: 20px;
+    }
+    embed#e2 {
+      top: 60px;
+      left: 70px;
+      width: 20px;
+      height: 10px;
+    }
+    embed#e3 {
+      top: 70px;
+      left: 80px;
+      width: 10px;
+      height: 20px;
+    }
+    embed#e4 {
+      top: 80px;
+      left: 60px;
+      width: 20px;
+      height: 10px;
+    }
+  </style>
+</head>
+<body>
+  <embed id="paint-waiter" type="application/x-test" wmode="window">
+  <embed id="e0" type="application/x-test" wmode="window" class="scrolling"/>
+  <embed id="e1" type="application/x-test" wmode="window" class="scrolling"/>
+  <embed id="e2" type="application/x-test" wmode="window" class="scrolling"/>
+  <embed id="e3" type="application/x-test" wmode="window" class="scrolling"/>
+  <embed id="e4" type="application/x-test" wmode="window" class="scrolling"/>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/widget/tests/test_plugin_scroll_invalidation.html
@@ -0,0 +1,121 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for plugin child widgets not being invalidated by scrolling</title>
+  <script type="text/javascript"
+          src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="text/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css"
+          href="chrome://mochikit/content/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 class="testbody" type="application/javascript">
+SimpleTest.waitForExplicitFinish();
+
+var scrolling;
+var scrolling_plugins = [];
+var paint_waiter;
+var last_paint_count;
+
+function initialize() {
+  scrolling = document.getElementById("i").contentWindow;
+  scrolling_plugins = scrolling.document.querySelectorAll("embed.scrolling");
+  paint_waiter = scrolling.document.getElementById("paint-waiter");
+
+  // Plugins are not instantiated until after reflow
+  waitForPlugin(startTest);
+}
+
+function startTest() {
+  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_count = sum(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() {
+  is(sum(getPaintCounts()), last_paint_count, "no paint on scroll");
+  SimpleTest.finish();  
+}
+
+function waitForPlugin(func) {
+  if (paint_waiter.getPaintCount) {
+    func();
+    return;
+  }
+  setTimeout(function() { waitForPlugin(func); }, 0);
+}
+
+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;
+}
+
+function sum(array) {
+  var result = 0;
+  for (var i = 0; i < array.length; ++i) {
+    result += array[i];
+  }
+  return result;
+}
+
+</script>
+</body>
+</html>