Bug 852850 - Add the ability for the reftest framework to test whether an element is painted in invalidation tests. r=roc
authorMatt Woodrow <mwoodrow@mozilla.com>
Mon, 25 Mar 2013 13:42:27 -0400
changeset 129151 e257b45b714c
parent 129150 312eba5c02d2
child 129152 97b75eac3e0f
push id24559
push userryanvm@gmail.com
push date2013-04-18 14:56 +0000
treeherdermozilla-central@fa5d5fccbc11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs852850
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 852850 - Add the ability for the reftest framework to test whether an element is painted in invalidation tests. r=roc
layout/tools/reftest/README.txt
layout/tools/reftest/reftest-content.js
--- a/layout/tools/reftest/README.txt
+++ b/layout/tools/reftest/README.txt
@@ -437,16 +437,24 @@ make changes that should test invalidati
 document and window so you can set listeners there too. For example,
 
 function doTest() {
   document.body.style.border = "";
   document.documentElement.removeAttribute('class');
 }
 document.addEventListener("MozReftestInvalidate", doTest, false);
 
+Painting Tests
+==============
+
+If an element shouldn't be painted, set the class "reftest-no-paint" on it
+when doing an invalidation test. Causing a repaint in your
+MozReftestInvalidate handler (for example, by changing the body's background
+colour) will accurately test whether the element is painted.
+
 Zoom Tests
 ==========
 
 When the root element of a test has a "reftest-zoom" attribute, that zoom
 factor is applied when rendering the test. The reftest document will be
 800 device pixels wide by 1000 device pixels high. The reftest harness assumes
 that the CSS pixel dimensions are 800/zoom and 1000/zoom. For best results
 therefore, choose zoom factors that do not require rounding when we calculate
--- a/layout/tools/reftest/reftest-content.js
+++ b/layout/tools/reftest/reftest-content.js
@@ -229,16 +229,20 @@ function shouldWaitForPendingPaints() {
 function shouldWaitForReftestWaitRemoval(contentRootElement) {
     // use getAttribute because className works differently in HTML and SVG
     return contentRootElement &&
            contentRootElement.hasAttribute('class') &&
            contentRootElement.getAttribute('class').split(/\s+/)
                              .indexOf("reftest-wait") != -1;
 }
 
+function getNoPaintElements(contentRootElement) {
+  return contentRootElement.getElementsByClassName('reftest-no-paint');
+}
+
 // Initial state. When the document has loaded and all MozAfterPaint events and
 // all explicit paint waits are flushed, we can fire the MozReftestInvalidate
 // event and move to the next state.
 const STATE_WAITING_TO_FIRE_INVALIDATE_EVENT = 0;
 // When reftest-wait has been removed from the root element, we can move to the
 // next state.
 const STATE_WAITING_FOR_REFTEST_WAIT_REMOVAL = 1;
 // When all MozAfterPaint events and all explicit paint waits are flushed, we're
@@ -355,16 +359,20 @@ function WaitForTestEnd(contentRootEleme
                 return;
             }
 
             state = STATE_WAITING_FOR_REFTEST_WAIT_REMOVAL;
             var hasReftestWait = shouldWaitForReftestWaitRemoval(contentRootElement);
             // Notify the test document that now is a good time to test some invalidation
             LogInfo("MakeProgress: dispatching MozReftestInvalidate");
             if (contentRootElement) {
+                var elements = getNoPaintElements(contentRootElement);
+                for (var i = 0; i < elements.length; ++i) {
+                  windowUtils().checkAndClearPaintedState(elements[i]);
+                }
                 var notification = content.document.createEvent("Events");
                 notification.initEvent("MozReftestInvalidate", true, false);
                 contentRootElement.dispatchEvent(notification);
             }
             if (hasReftestWait && !shouldWaitForReftestWaitRemoval(contentRootElement)) {
                 // MozReftestInvalidate handler removed reftest-wait.
                 // We expect something to have been invalidated...
                 FlushRendering();
@@ -403,16 +411,24 @@ function WaitForTestEnd(contentRootEleme
                     LogInfo("MakeProgress: waiting for MozPaintWaitFinished");
                 }
                 if (shouldWaitForPendingPaints()) {
                     gFailureReason += " (waiting for MozAfterPaint)";
                     LogInfo("MakeProgress: waiting for MozAfterPaint");
                 }
                 return;
             }
+            if (contentRootElement) {
+              var elements = getNoPaintElements(contentRootElement);
+              for (var i = 0; i < elements.length; ++i) {
+                  if (windowUtils().checkAndClearPaintedState(elements[i])) {
+                      LogError("REFTEST TEST-UNEXPECTED-FAIL | element marked as reftest-no-paint got repainted!");
+                  }
+              }
+            }
             LogInfo("MakeProgress: Completed");
             state = STATE_COMPLETED;
             gFailureReason = "timed out while taking snapshot (bug in harness?)";
             RemoveListeners();
             CheckForProcessCrashExpectation();
             setTimeout(RecordResult, 0);
             return;
         }