Bug 1516722 - Mochitest. r=kats
authorBotond Ballo <botond@mozilla.com>
Tue, 07 May 2019 03:03:47 +0000
changeset 531646 5e9833abf18153254ee72738e525c22af77435c8
parent 531645 6348ca2145d91a6cd468877ce2940c5a1cb466ce
child 531647 9e64b394951d590347507ced94692d6be8b36d28
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1516722
milestone68.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 1516722 - Mochitest. r=kats Differential Revision: https://phabricator.services.mozilla.com/D29093
gfx/layers/apz/test/mochitest/apz_test_utils.js
gfx/layers/apz/test/mochitest/helper_fixed_pos_displayport.html
gfx/layers/apz/test/mochitest/helper_scroll_into_view_bug1516056.html
--- a/gfx/layers/apz/test/mochitest/apz_test_utils.js
+++ b/gfx/layers/apz/test/mochitest/apz_test_utils.js
@@ -14,16 +14,18 @@
 function convertEntries(entries) {
   var result = {};
   for (var i = 0; i < entries.length; ++i) {
     result[entries[i].key] = entries[i].value;
   }
   return result;
 }
 
+// TODO: Clean up these rect-handling functions so that e.g. a rect returned
+//       by Element.getBoundingClientRect() Just Works with them.
 function parseRect(str) {
   var pieces = str.replace(/[()\s]+/g, "").split(",");
   SimpleTest.is(pieces.length, 4, "expected string of form (x,y,w,h)");
   return { x: parseInt(pieces[0]),
            y: parseInt(pieces[1]),
            w: parseInt(pieces[2]),
            h: parseInt(pieces[3]) };
 }
@@ -34,16 +36,21 @@ function rectContains(haystack, needle) 
   return haystack.x <= needle.x
       && haystack.y <= needle.y
       && (haystack.x + haystack.w) >= (needle.x + needle.w)
       && (haystack.y + haystack.h) >= (needle.y + needle.h);
 }
 function rectToString(rect) {
   return "(" + rect.x + "," + rect.y + "," + rect.w + "," + rect.h + ")";
 }
+function assertRectContainment(haystackRect, haystackDesc, needleRect, needleDesc) {
+  SimpleTest.ok(rectContains(haystackRect, needleRect),
+                haystackDesc + " " + rectToString(haystackRect) + " should contain " +
+                needleDesc + " " + rectToString(needleRect));
+}
 
 function getPropertyAsRect(scrollFrames, scrollId, prop) {
   SimpleTest.ok(scrollId in scrollFrames,
                 "expected scroll frame data for scroll id " + scrollId);
   var scrollFrameData = scrollFrames[scrollId];
   SimpleTest.ok("displayport" in scrollFrameData,
                 "expected a " + prop + " for scroll id " + scrollId);
   var value = scrollFrameData[prop];
--- a/gfx/layers/apz/test/mochitest/helper_fixed_pos_displayport.html
+++ b/gfx/layers/apz/test/mochitest/helper_fixed_pos_displayport.html
@@ -68,19 +68,18 @@
       // relative to the layout viewport (but not relative to the page), since
       // fixed-position elements are attached to the layout viewport.
       // This is accomplished by checking the fixed-pos display port contains
       // the visual viewport rect as expressed relative to the layout viewport.
       let vvRect = { x: vv.offsetLeft,  // offsets relative to layout viewport
                      y: vv.offsetTop,
                      w: vv.width,
                      h: vv.height };
-      ok(rectContains(fixedPosDisplayport, vvRect),
-         "fixed-pos displayport " + rectToString(fixedPosDisplayport) +
-         " should contain visual viewport " + rectToString(vvRect));
+      assertRectContainment(fixedPosDisplayport, "fixed-pos displayport",
+                            vvRect, "visual viewport");
     }
 
     function* test(testDriver) {
       // First, check size and position on page load.
       checkFixedPosDisplayport();
 
       // Scroll the visual viewport within the layout viewport, without
       // scrolling the layout viewport itself, and check the size and
--- a/gfx/layers/apz/test/mochitest/helper_scroll_into_view_bug1516056.html
+++ b/gfx/layers/apz/test/mochitest/helper_scroll_into_view_bug1516056.html
@@ -14,31 +14,54 @@
       margin-right: 50%;
       background: cyan;
     }
   </style>
 </head>
 <body>
   <div id="target"></div>
   <script>
+    let vv = window.visualViewport;
     function getVisualScrollRange() {
       let rootScroller = document.scrollingElement;
-      let vv = window.visualViewport;
       return {
         width: rootScroller.scrollWidth - vv.width,
         height: rootScroller.scrollHeight - vv.height,
       };
     }
+    function getVisualViewportRect() {
+      return {
+        x: vv.pageLeft,
+        y: vv.pageTop,
+        w: vv.width,
+        h: vv.height,
+      };
+    }
     function* test(testDriver) {
       SimpleTest.is(window.scrollMaxX, 0, "page should have a zero horizontal layout scroll range");
       SimpleTest.is(window.scrollMaxY, 0, "page should have a zero vertical layout scroll range");
       let visualScrollRange = getVisualScrollRange();
       SimpleTest.ok(visualScrollRange.width > 0, "page should have a nonzero horizontal visual scroll range");
       SimpleTest.ok(visualScrollRange.height > 0, "page should have a nonzero vertical visual scroll range");
       let target = document.getElementById("target");
+
+      // Scroll target element into view. Wait until any visual scrolling is done before doing checks.
+      vv.addEventListener("scroll", testDriver, { once: true });
       target.scrollIntoView();
+      yield; // wait for visual viewport "scroll" event
+      yield waitForApzFlushedRepaints(testDriver);
+
+      // Test that scrollIntoView() respected the layout scroll range.
       SimpleTest.is(window.scrollX, 0, "page should not layout-scroll with a zero layout scroll range");
       SimpleTest.is(window.scrollY, 0, "page should not layout-scroll with a zero layout scroll range");
+
+      // Test that scrollIntoView() did perform visual scrolling.
+      let vvRect = getVisualViewportRect();
+      let targetBounds = target.getBoundingClientRect();
+      // set property names expected by rectContains()
+      targetBounds.w = targetBounds.width;
+      targetBounds.h = targetBounds.height;
+      assertRectContainment(vvRect, "visual viewport", targetBounds, "target element bounding rect");
     }
     waitUntilApzStable().then(runContinuation(test)).then(subtestDone);
   </script>
 </body>
 </html>