Bug 1516722 - Mochitest. r=kats
☠☠ backed out by e8766f96041a ☠ ☠
authorBotond Ballo <botond@mozilla.com>
Mon, 29 Apr 2019 15:45:53 +0000
changeset 530581 8f2db95f0610ed8c51419bb94ed97ab25a2e3c8c
parent 530580 55c8e6f3e522adf4db6a3a6f9cec450ab8ff8926
child 530582 adde7e56d8f62e30b9d7c6d2a6e15c3d1d37e233
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>