Bug 1389492 - Ensure the helper_key_scroll waits for repaints from the main-thread scroll to finish before triggering the async scroll. r?rhunt draft
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 11 Aug 2017 10:37:25 -0400
changeset 644916 3c6a54006d274b3a67f6d5713f7af6bc3db6b312
parent 644320 4e1d0438c31b0e8447cae7d03bf423c2e4b87df4
child 725749 e1dda54e154249d9b7e29b14cca37ac2c7033de7
push id73588
push userkgupta@mozilla.com
push dateFri, 11 Aug 2017 14:40:15 +0000
reviewersrhunt
bugs1389492
milestone57.0a1
Bug 1389492 - Ensure the helper_key_scroll waits for repaints from the main-thread scroll to finish before triggering the async scroll. r?rhunt MozReview-Commit-ID: EsYz5LSc83Q
gfx/layers/apz/test/mochitest/helper_key_scroll.html
--- a/gfx/layers/apz/test/mochitest/helper_key_scroll.html
+++ b/gfx/layers/apz/test/mochitest/helper_key_scroll.html
@@ -38,31 +38,44 @@ https://bugzilla.mozilla.org/show_bug.cg
       window.addEventListener("scroll", waitForScrollBottom);
       window.synthesizeKey("VK_END", {});
     };
 
     function waitForScrollBottom() {
       if (window.scrollY < window.scrollYMax) {
         return;
       }
+      SimpleTest.info("Reached final scroll position of sync VK_END scroll");
       window.removeEventListener("scroll", waitForScrollBottom);
 
-      // Wait for scrolling to finish before dispatching the next key input or
-      // the default action won't occur.
+      // Spin the refresh driver a few times, so that the AsyncScroll instance
+      // that was running the main-thread scroll animation finishes up and
+      // triggers any repaints that it needs to.
+      var utils = SpecialPowers.DOMWindowUtils;
+      for (var i = 0; i < 10; i++) {
+        utils.advanceTimeAndRefresh(50);
+      }
+      utils.restoreNormalRefresh();
+
+      // Wait for the APZ to reach a stable state as well, before dispatching
+      // the next key input or the default action won't occur.
       waitForApzFlushedRepaints(function () {
+        SimpleTest.is(checkHasAsyncKeyScrolled(false), false, "expected no async key scrolling before VK_HOME dispatch");
+
         // This scroll should be asynchronous now that the focus state is up to date.
         window.addEventListener("scroll", waitForScrollTop);
         window.synthesizeKey("VK_HOME", {});
       });
     };
 
     function waitForScrollTop() {
       if (window.scrollY > 0) {
         return;
       }
+      SimpleTest.info("Reached final scroll position of async VK_HOME scroll");
       window.removeEventListener("scroll", waitForScrollTop);
 
       // Wait for APZ to settle and then check that async scrolling happened.
       waitForApzFlushedRepaints(function () {
         SimpleTest.is(checkHasAsyncKeyScrolled(true), true, "expected async key scrolling after test");
         window.opener.finishTest();
       });
     };