Bug 770001 - Add invalidation test helpers and form control invalidation mochitest. r=roc
☠☠ backed out by 946b285bc14c ☠ ☠
authorMatt Woodrow <mwoodrow@mozilla.com>
Tue, 16 Oct 2012 14:10:45 +1300
changeset 110491 e19d625511a0683ff389dc93a78920c6594a35c0
parent 110490 c67ff8ae77e29628f52bc7e75983160dccf251c7
child 110492 4ea9ef4e135e7cda72202fe216332dd0b4f9469d
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersroc
bugs770001
milestone19.0a1
Bug 770001 - Add invalidation test helpers and form control invalidation mochitest. r=roc
layout/base/tests/Makefile.in
layout/base/tests/chrome/Makefile.in
layout/base/tests/chrome/paint_listener.js
layout/base/tests/chrome/test_bug551434.html
layout/base/tests/invalidation/Makefile.in
layout/base/tests/invalidation/test_form_controls.html
--- a/layout/base/tests/Makefile.in
+++ b/layout/base/tests/Makefile.in
@@ -8,16 +8,17 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= @relativesrcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 PARALLEL_DIRS += \
   chrome \
+  invalidation \
   $(NULL)
 
 TOOL_DIRS := \
   cpp-tests \
   $(NULL)
 
 MOCHITEST_FILES =	\
 		border_radius_hit_testing_iframe.html \
--- a/layout/base/tests/chrome/Makefile.in
+++ b/layout/base/tests/chrome/Makefile.in
@@ -1,17 +1,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DEPTH     = @DEPTH@
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
-relativesrcdir  = layout/base/test/chrome
+relativesrcdir  = layout/base/tests/chrome
 
 include $(DEPTH)/config/autoconf.mk
 
 MOCHITEST_CHROME_FILES = \
 	paint_listener.js \
 	test_bug370436.html \
 	test_bug396367-1.html \
 	test_bug396367-2.html \
--- a/layout/base/tests/chrome/paint_listener.js
+++ b/layout/base/tests/chrome/paint_listener.js
@@ -1,11 +1,14 @@
 var accumulatedRect = null;
 var onpaint = function() {};
 var debug = false;
+var CI = Components.interfaces;
+var utils = window.QueryInterface(CI.nsIInterfaceRequestor)
+            .getInterface(CI.nsIDOMWindowUtils);
 
 function paintListener(event) {
   if (event.target != window)
     return;
   if (debug) {
     dump("got MozAfterPaint: " + event.boundingClientRect.left + "," + event.boundingClientRect.top + "," +
          event.boundingClientRect.right + "," + event.boundingClientRect.bottom + "\n");
   }
@@ -22,19 +25,16 @@ function paintListener(event) {
 }
 window.addEventListener("MozAfterPaint", paintListener, false);
 
 function waitForAllPaintsFlushed(callback, subdoc) {
   document.documentElement.getBoundingClientRect();
   if (subdoc) {
     subdoc.documentElement.getBoundingClientRect();
   }
-  var CI = Components.interfaces;
-  var utils = window.QueryInterface(CI.nsIInterfaceRequestor)
-              .getInterface(CI.nsIDOMWindowUtils);
   if (!utils.isMozAfterPaintPending) {
     if (debug) {
       dump("done...\n");
     }
     var result = accumulatedRect;
     accumulatedRect = null;
     onpaint = function() {};
     if (!result) {
@@ -43,8 +43,41 @@ function waitForAllPaintsFlushed(callbac
     callback(result[0], result[1], result[2], result[3]);
     return;
   }
   if (debug) {
     dump("waiting for paint...\n");
   }
   onpaint = function() { waitForAllPaintsFlushed(callback, subdoc); };
 }
+
+var notPaintedList = new Array();
+var paintedList = new Array();
+
+function ensureNotPainted(element)
+{
+  utils.checkAndClearPaintedState(element);
+  notPaintedList.push(element);
+}
+
+function ensurePainted(element)
+{
+  utils.checkAndClearPaintedState(element);
+  paintedList.push(element);
+}
+
+function checkInvalidation()
+{
+  for (var i = 0; i < notPaintedList.length; i++) {
+    ok(!utils.checkAndClearPaintedState(notPaintedList[i]), "Should not have repainted element!");
+  }
+  notPaintedList = new Array();
+  for (var i = 0; i < paintedList.length; i++) {
+    ok(utils.checkAndClearPaintedState(notPaintedList[i]), "Should have repainted element!");
+  }
+  paintedList = new Array();
+}
+
+function testInvalidation(callback)
+{
+  waitForAllPaintsFlushed(function() { checkInvalidation(); callback(); }); 
+}
+
--- a/layout/base/tests/chrome/test_bug551434.html
+++ b/layout/base/tests/chrome/test_bug551434.html
@@ -10,17 +10,17 @@
 <body>
 </div>
 <pre id="test">
 <input id="i1" onkeydown="gKeyDown1++; $('i2').focus();" onkeypress="gKeyPress1++;" onkeyup="gKeyUp1++;"/>
 <input id="i2" onkeydown="gKeyDown2++;" onkeypress="gKeyPress2++;" onkeyup="gKeyUp2++;"/>
 
 <input id="i3" onkeydown="gKeyDown3++; frames[0].document.getElementById('i4').focus();"
        onkeypress="gKeyPress3++;" onkeyup="gKeyUp3++;"/>
-<iframe id="iframe" src="http://example.org/chrome/layout/base/test/chrome/bug551434_childframe.html"></iframe>
+<iframe id="iframe" src="http://example.org/chrome/layout/base/tests/chrome/bug551434_childframe.html"></iframe>
 
 <script class="testbody" type="text/javascript">
 
 SimpleTest.waitForExplicitFinish();
 
 var gKeyDown1 = 0, gKeyPress1 = 0, gKeyUp1 = 0;
 var gKeyDown2 = 0, gKeyPress2 = 0, gKeyUp2 = 0;
 var gKeyDown3 = 0, gKeyPress3 = 0, gKeyUp3 = 0;
new file mode 100644
--- /dev/null
+++ b/layout/base/tests/invalidation/Makefile.in
@@ -0,0 +1,17 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DEPTH     = @DEPTH@
+topsrcdir = @top_srcdir@
+srcdir    = @srcdir@
+VPATH     = @srcdir@
+relativesrcdir  = layout/base/tests/invalidation
+
+include $(DEPTH)/config/autoconf.mk
+
+MOCHITEST_CHROME_FILES = \
+    test_form_controls.html \
+	$(NULL)
+
+include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/layout/base/tests/invalidation/test_form_controls.html
@@ -0,0 +1,60 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Check if we're over invalidating form controls</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="../chrome/paint_listener.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body onload="waitForAllPaintsFlushed(runTest)">
+<!-- Make sure we can always scroll even on large monitors -->
+<div style="position: absolute; z-index: -100; height: 5000px; width: 1px; background-color: white;"></div>
+
+<div id="test" style="height: 100px; width: 1px; background-color: white;"></div>
+
+<select id="combo"name="product">
+</select>
+<input value="Save Changes" id="button" type="submit">
+<input type="checkbox" id="checkbox"/>
+<select id="listbox" size="7">
+</select>
+<input type="radio" id="radio" value="radio">Radio
+<input type="text" id="text"/>
+<a id="link" href="#">Link</a>
+
+<script type="application/javascript">
+SimpleTest.waitForExplicitFinish();
+
+var NO_REPAINT_ITEMS = ["combo", "button", "checkbox", "listbox", "radio", "text", "link"];
+var SCROLL_TO = 40;
+var SCROLL_INC = 2;
+var posY = 0;
+
+function runTest() {
+  if (window.QueryInterface(CI.nsIInterfaceRequestor).getInterface(CI.nsIDOMWindowUtils).layerManagerType == "Basic") {
+    ok(true, "Skipping test on BasicLayers because it fails due to component alpha flattening.");
+    SimpleTest.finish();
+    return;
+  }
+  // Scroll 
+  posY += SCROLL_INC;
+  if (posY >= SCROLL_TO) {
+    SimpleTest.finish();
+    return;
+  }
+
+  // Add all the items to the no-repaint list unless it's the first few
+  // paints
+  if (posY > (SCROLL_INC * 4)) {
+    for (var i = 0; i < NO_REPAINT_ITEMS.length; i++) {
+      ensureNotPainted(document.getElementById(NO_REPAINT_ITEMS[i]));
+    }
+  }
+
+  window.scrollTo(0, posY);
+  testInvalidation(runTest);
+}
+
+</script>
+</body>
+</html>