gfx/layers/apz/test/mochitest/helper_hittest_basic.html
author Botond Ballo <botond@mozilla.com>
Wed, 28 Mar 2018 14:22:42 -0400
changeset 773959 ad39696f8573e2e5119720c7495ce1b21cf62f82
parent 755496 0e1283be874466cfa5e154d9b3642ffce716913a
child 802753 3f5b46c9ab23c84e9923500e721739134d10dc0c
permissions -rw-r--r--
Bug 1447131 - Move centerOf() into apz_test_utils.js. r=kats MozReview-Commit-ID: CwO5SnWmhb9

<!DOCTYPE HTML>
<html>
<head>
  <title>Various tests to exercise the APZ hit-testing codepaths</title>
  <script type="application/javascript" src="apz_test_utils.js"></script>
  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
  <meta name="viewport" content="width=device-width"/>
</head>
<body>
 <div id="scroller" style="width: 300px; height: 300px; overflow:scroll; margin-top: 100px; margin-left: 50px">
  <div id="contents" style="width: 500px; height: 500px; background-image: linear-gradient(blue,red)">
   <div id="apzaware" style="position: relative; width: 100px; height: 100px; top: 300px; background-color: red" onwheel="return false;"></div>
  </div>
 </div>
 <div id="make_root_scrollable" style="height: 5000px"></div>
</body>
<script type="application/javascript">

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");

  // 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");

  // 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,
    layerState: LayerState.INACTIVE
  });

  // activate the scrollframe but keep the main-thread scroll position at 0.
  // also apply a async scroll offset in the y-direction such that the
  // scrollframe scrolls to the bottom of its range.
  utils.setDisplayPortForElement(0, 0, 500, 500, scroller, 1);
  yield waitForAllPaints(testDriver);
  var scrollY = scroller.scrollTopMax;
  utils.setAsyncScrollOffset(scroller, 0, scrollY);
  if (config.isWebRender) {
    // Tick the refresh driver once to make sure the compositor has applied the
    // async scroll offset (for APZ hit-testing this doesn't matter, but for
    // 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");

  // 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");

  // 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,
    directions: { vertical: true },
    expectedScrollId: scrollerViewId,
    trackLocation: ScrollbarTrackLocation.START,
    expectThumb: false,
    layerState: LayerState.ACTIVE
  });
  // bottom of scrollbar track (scrollthumb)
  hitTestScrollbar({
    element: scroller,
    directions: { vertical: true },
    expectedScrollId: scrollerViewId,
    trackLocation: ScrollbarTrackLocation.END,
    expectThumb: true,
    layerState: LayerState.ACTIVE
  });
  // left part of scrollbar track (has scrollthumb)
  hitTestScrollbar({
    element: scroller,
    directions: { horizontal: true },
    expectedScrollId: scrollerViewId,
    trackLocation: ScrollbarTrackLocation.START,
    expectThumb: true,
    layerState: LayerState.ACTIVE
  });
  // right part of scrollbar track
  hitTestScrollbar({
    element: scroller,
    directions: { horizontal: true },
    expectedScrollId: scrollerViewId,
    trackLocation: ScrollbarTrackLocation.END,
    expectThumb: false,
    layerState: LayerState.ACTIVE
  });

  subtestDone();
}

waitUntilApzStable().then(runContinuation(test));

</script>
</html>