Bug 1163832 - Update the reftest harness to wait for APZ repaint flushes before finishing. r=dbaron
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 22 May 2015 06:42:09 -0400
changeset 266235 3373b602df4b48662d0a880eb128ccb501823acd
parent 266234 0867630f82f6887b34da610d40f96e169715e796
child 266236 7c82838a230c23359c0b3484870cca99e262fe74
push id2231
push usermichael.l.comella@gmail.com
push dateFri, 22 May 2015 20:04:59 +0000
reviewersdbaron
bugs1163832
milestone41.0a1
Bug 1163832 - Update the reftest harness to wait for APZ repaint flushes before finishing. r=dbaron
layout/tools/reftest/reftest-content.js
--- a/layout/tools/reftest/reftest-content.js
+++ b/layout/tools/reftest/reftest-content.js
@@ -9,16 +9,17 @@ const CI = Components.interfaces;
 const CR = Components.results;
 const CU = Components.utils;
 
 const XHTML_NS = "http://www.w3.org/1999/xhtml";
 
 const DEBUG_CONTRACTID = "@mozilla.org/xpcom/debug;1";
 const PRINTSETTINGS_CONTRACTID = "@mozilla.org/gfx/printsettings-service;1";
 const ENVIRONMENT_CONTRACTID = "@mozilla.org/process/environment;1";
+const NS_OBSERVER_SERVICE_CONTRACTID = "@mozilla.org/observer-service;1";
 
 // "<!--CLEAR-->"
 const BLANK_URL_FOR_CLEARING = "data:text/html;charset=UTF-8,%3C%21%2D%2DCLEAR%2D%2D%3E";
 
 CU.import("resource://gre/modules/Timer.jsm");
 CU.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
 
 var gBrowserIsRemote;
@@ -358,20 +359,23 @@ function getAssignedLayerMap(contentRoot
 // 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 spell checking is done on all spell-checked elements, we can move to the
 // next state.
 const STATE_WAITING_FOR_SPELL_CHECKS = 2;
+// When any pending compositor-side repaint requests have been flushed, we can
+// move to the next state.
+const STATE_WAITING_FOR_APZ_FLUSH = 3;
 // When all MozAfterPaint events and all explicit paint waits are flushed, we're
 // done and can move to the COMPLETED state.
-const STATE_WAITING_TO_FINISH = 3;
-const STATE_COMPLETED = 4;
+const STATE_WAITING_TO_FINISH = 4;
+const STATE_COMPLETED = 5;
 
 function FlushRendering() {
     var anyPendingPaintsGeneratedInDescendants = false;
 
     function flushWindow(win) {
         var utils = win.QueryInterface(CI.nsIInterfaceRequestor)
                     .getInterface(CI.nsIDOMWindowUtils);
         var afterPaintWasPending = utils.isMozAfterPaintPending;
@@ -527,19 +531,41 @@ function WaitForTestEnd(contentRootEleme
         case STATE_WAITING_FOR_SPELL_CHECKS:
             LogInfo("MakeProgress: STATE_WAITING_FOR_SPELL_CHECKS");
             if (numPendingSpellChecks) {
                 gFailureReason = "timed out waiting for spell checks to end";
                 LogInfo("MakeProgress: waiting for spell checks to end");
                 return;
             }
 
-            state = STATE_WAITING_TO_FINISH;
-            // Try next state
-            MakeProgress();
+            state = STATE_WAITING_FOR_APZ_FLUSH;
+            LogInfo("MakeProgress: STATE_WAITING_FOR_APZ_FLUSH");
+            gFailureReason = "timed out waiting for APZ flush to complete";
+
+            var os = CC[NS_OBSERVER_SERVICE_CONTRACTID].getService(CI.nsIObserverService);
+            var flushWaiter = function(aSubject, aTopic, aData) {
+                if (aTopic) LogInfo("MakeProgress: apz-repaints-flushed fired");
+                os.removeObserver(flushWaiter, "apz-repaints-flushed");
+                state = STATE_WAITING_TO_FINISH;
+                MakeProgress();
+            };
+            os.addObserver(flushWaiter, "apz-repaints-flushed", false);
+
+            if (windowUtils().flushApzRepaints()) {
+                LogInfo("MakeProgress: done requesting APZ flush");
+            } else {
+                LogInfo("MakeProgress: APZ flush not required");
+                flushWaiter(null, null, null);
+            }
+            return;
+
+        case STATE_WAITING_FOR_APZ_FLUSH:
+            LogInfo("MakeProgress: STATE_WAITING_FOR_APZ_FLUSH");
+            // Nothing to do here; once we get the apz-repaints-flushed event
+            // we will go to STATE_WAITING_TO_FINISH
             return;
 
         case STATE_WAITING_TO_FINISH:
             LogInfo("MakeProgress: STATE_WAITING_TO_FINISH");
             if (shouldWaitForExplicitPaintWaiters() || shouldWaitForPendingPaints()) {
                 gFailureReason = "timed out waiting for pending paint count to " +
                     "reach zero (after reftest-wait removed and switch to print mode)";
                 if (shouldWaitForExplicitPaintWaiters()) {