Bug 1465864 - Make hit-testing mochitest failure messages nicer. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 01 Jun 2018 06:58:28 -0400
changeset 421082 46bd77a828860bfb5298c176ef24c0d06a7657c6
parent 421081 7c74241c18ea7be2c5ea758e6dba7a912aee9e9d
child 421083 b9580410937cb100759a59b189f2fa7ef66c6238
push id34088
push userdluca@mozilla.com
push dateMon, 04 Jun 2018 17:56:32 +0000
treeherdermozilla-central@5b15326286d4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1465864
milestone62.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 1465864 - Make hit-testing mochitest failure messages nicer. r=botond Instead of printing out base-10 numbers like "expected 67" this will print out a nicer "expected VISIBLE | DISPATCH_TO_CONTENT | SCROLLBAR" which makes it easier to see which flags are missing from the hit info. MozReview-Commit-ID: gp9ERBIgYj
gfx/layers/apz/test/mochitest/apz_test_utils.js
gfx/layers/apz/test/mochitest/helper_hittest_basic.html
gfx/layers/apz/test/mochitest/helper_hittest_checkerboard.html
--- a/gfx/layers/apz/test/mochitest/apz_test_utils.js
+++ b/gfx/layers/apz/test/mochitest/apz_test_utils.js
@@ -537,16 +537,41 @@ function hitTest(point) {
   dump("Hit-testing point (" + point.x + ", " + point.y + ")\n");
   utils.sendMouseEvent("MozMouseHittest", point.x, point.y, 0, 0, 0, true, 0, 0, true, true);
   var data = utils.getCompositorAPZTestData();
   ok(data.hitResults.length >= 1, "Expected at least one hit result in the APZTestData");
   var result = data.hitResults[data.hitResults.length - 1];
   return { hitInfo: result.hitResult, scrollId: result.scrollId };
 }
 
+// Returns a canonical stringification of the hitInfo bitfield.
+function hitInfoToString(hitInfo) {
+  var strs = [];
+  for (var flag in APZHitResultFlags) {
+    if ((hitInfo & APZHitResultFlags[flag]) != 0) {
+      strs.push(flag);
+    }
+  }
+  if (strs.length == 0) {
+    return "INVISIBLE";
+  }
+  strs.sort(function(a, b) {
+    return APZHitResultFlags[a] - APZHitResultFlags[b];
+  });
+  return strs.join(" | ");
+}
+
+// Takes an object returned by hitTest, along with the expected values, and
+// asserts that they match. Notably, it uses hitInfoToString to provide a
+// more useful message for the case that the hit info doesn't match
+function checkHitResult(hitResult, expectedHitInfo, expectedScrollId, desc) {
+  is(hitInfoToString(hitResult.hitInfo), hitInfoToString(expectedHitInfo), desc + " hit info");
+  is(hitResult.scrollId, expectedScrollId, desc + " scrollid");
+}
+
 // Symbolic constants used by hitTestScrollbar().
 var ScrollbarTrackLocation = {
     START: 1,
     END: 2
 };
 var LayerState = {
     ACTIVE: 1,
     INACTIVE: 2
@@ -618,35 +643,33 @@ function hitTestScrollbar(params) {
   // with zero dimensions.
   if (params.directions.vertical && verticalScrollbarWidth > 0) {
     var verticalScrollbarPoint = {
         x: boundingClientRect.right - (verticalScrollbarWidth / 2),
         y: (params.trackLocation == ScrollbarTrackLocation.START)
              ? (boundingClientRect.y + scrollbarArrowButtonHeight + 5)
              : (boundingClientRect.bottom - horizontalScrollbarHeight - scrollbarArrowButtonHeight - 5)
     };
-    var {hitInfo, scrollId} = hitTest(verticalScrollbarPoint);
-    is(hitInfo, expectedHitInfo | APZHitResultFlags.SCROLLBAR_VERTICAL,
-       scrollframeMsg + " - vertical scrollbar hit info");
-    is(scrollId, params.expectedScrollId,
-       scrollframeMsg + " - vertical scrollbar scrollid");
+    checkHitResult(hitTest(verticalScrollbarPoint),
+                   expectedHitInfo | APZHitResultFlags.SCROLLBAR_VERTICAL,
+                   params.expectedScrollId,
+                   scrollframeMsg + " - vertical scrollbar");
   }
 
   if (params.directions.horizontal && horizontalScrollbarHeight > 0) {
     var horizontalScrollbarPoint = {
         x: (params.trackLocation == ScrollbarTrackLocation.START)
              ? (boundingClientRect.x + scrollbarArrowButtonWidth + 5)
              : (boundingClientRect.right - verticalScrollbarWidth - scrollbarArrowButtonWidth - 5),
         y: boundingClientRect.bottom - (horizontalScrollbarHeight / 2),
     };
-    var {hitInfo, scrollId} = hitTest(horizontalScrollbarPoint);
-    is(hitInfo, expectedHitInfo,
-       scrollframeMsg + " - horizontal scrollbar hit info");
-    is(scrollId, params.expectedScrollId,
-       scrollframeMsg + " - horizontal scrollbar scrollid");
+    checkHitResult(hitTest(horizontalScrollbarPoint),
+                   expectedHitInfo,
+                   params.expectedScrollId,
+                   scrollframeMsg + " - horizontal scrollbar");
   }
 }
 
 var ApzCleanup = {
   _cleanups: [],
 
   register: function(func) {
     if (this._cleanups.length == 0) {
--- a/gfx/layers/apz/test/mochitest/helper_hittest_basic.html
+++ b/gfx/layers/apz/test/mochitest/helper_hittest_basic.html
@@ -19,30 +19,28 @@
 
 function* test(testDriver) {
   var config = getHitTestConfig();
   var utils = config.utils;
 
   var scroller = document.getElementById('scroller');
   var apzaware = document.getElementById('apzaware');
 
-  var {hitInfo, scrollId} = hitTest(centerOf(scroller));
-  is(hitInfo, APZHitResultFlags.VISIBLE | APZHitResultFlags.DISPATCH_TO_CONTENT,
-     "inactive scrollframe hit info");
-  is(scrollId, utils.getViewId(document.scrollingElement),
-     "inactive scrollframe scrollid");
+  checkHitResult(hitTest(centerOf(scroller)),
+                 APZHitResultFlags.VISIBLE | APZHitResultFlags.DISPATCH_TO_CONTENT,
+                 utils.getViewId(document.scrollingElement),
+                 "inactive scrollframe");
 
   // The apz-aware div (which has a non-passive wheel listener) is not visible
   // and so the hit-test should just return the root scrollframe area that's
   // covering it
-  var {hitInfo, scrollId} = hitTest(centerOf(apzaware));
-  is(hitInfo, APZHitResultFlags.VISIBLE,
-     "inactive scrollframe - apzaware block hit info");
-  is(scrollId, utils.getViewId(document.scrollingElement),
-     "inactive scrollframe - apzaware block scrollid");
+  checkHitResult(hitTest(centerOf(apzaware)),
+                 APZHitResultFlags.VISIBLE,
+                 utils.getViewId(document.scrollingElement),
+                 "inactive scrollframe - apzaware block");
 
   // Hit test where the scroll thumbs should be.
   hitTestScrollbar({
     element: scroller,
     directions: { vertical: true, horizontal: true },
     expectedScrollId: utils.getViewId(document.scrollingElement),
     trackLocation: ScrollbarTrackLocation.START,
     expectThumb: true,
@@ -62,30 +60,28 @@ function* test(testDriver) {
     // WebRender hit-testing we need to make sure WR has the latest info).
     utils.advanceTimeAndRefresh(16);
     utils.restoreNormalRefresh();
   }
 
   var scrollerViewId = utils.getViewId(scroller);
 
   // Now we again test the middle of the scrollframe, which is now active
-  var {hitInfo, scrollId} = hitTest(centerOf(scroller));
-  is(hitInfo, APZHitResultFlags.VISIBLE,
-     "active scrollframe hit info");
-  is(scrollId, scrollerViewId,
-     "active scrollframe scrollid");
+  checkHitResult(hitTest(centerOf(scroller)),
+                 APZHitResultFlags.VISIBLE,
+                 scrollerViewId,
+                 "active scrollframe");
 
   // Test the apz-aware block
   var apzawarePosition = centerOf(apzaware); // main thread position
   apzawarePosition.y -= scrollY; // APZ position
-  var {hitInfo, scrollId} = hitTest(apzawarePosition);
-  is(hitInfo, APZHitResultFlags.VISIBLE | APZHitResultFlags.DISPATCH_TO_CONTENT,
-     "active scrollframe - apzaware block hit info");
-  is(scrollId, scrollerViewId,
-     "active scrollframe - apzaware block scrollid");
+  checkHitResult(hitTest(apzawarePosition),
+                 APZHitResultFlags.VISIBLE | APZHitResultFlags.DISPATCH_TO_CONTENT,
+                 scrollerViewId,
+                 "active scrollframe - apzaware block");
 
   // Test the scrollbars. Note that this time the vertical scrollthumb is
   // going to be at the bottom of the track. We'll test both the top and the
   // bottom.
 
   // top of scrollbar track
   hitTestScrollbar({
     element: scroller,
--- a/gfx/layers/apz/test/mochitest/helper_hittest_checkerboard.html
+++ b/gfx/layers/apz/test/mochitest/helper_hittest_checkerboard.html
@@ -39,21 +39,20 @@ function* test(testDriver) {
     utils.restoreNormalRefresh();
   }
 
   var scrollerViewId = utils.getViewId(scroller);
 
   // Hit-test the middle of the scrollframe, which is now inside the
   // checkerboarded region, and check that we hit the scrollframe and
   // not its parent.
-  var {hitInfo, scrollId} = hitTest(centerOf(scroller));
-  is(hitInfo, APZHitResultFlags.VISIBLE,
-     "active scrollframe hit info");
-  is(scrollId, scrollerViewId,
-     "active scrollframe scrollid");
+  checkHitResult(hitTest(centerOf(scroller)),
+                 APZHitResultFlags.VISIBLE,
+                 scrollerViewId,
+                 "active scrollframe");
 
   subtestDone();
 }
 
 waitUntilApzStable().then(runContinuation(test));
 
 </script>
 </html>