chromium/third_party/blink/web_tests/fast/scroll-behavior/middleclick-autoscroll-use-count.html

<!DOCTYPE HTML>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src='../../resources/gesture-util.js'></script>
<style>

  ::-webkit-scrollbar {
    display: none;
  }
  body {
    margin: 0px;
    height: 1000px;
    width: 1000px;
  }
  #scrollable {
    background-color: #FF7F7F;
    height: 600px;
    width: 600px;
    overflow: scroll;
  }
  #content {
    height: 900px;
    width: 900px;
  }

</style>

<div id="scrollable">
	<div id="content"></div>
</div>

<script>
// from enum WebFeature in web_feature.mojom-shared.h
const MIDDLE_CLICK_AUTOSCROLL = 1551;
const SCROLL_BY_TOUCH_COUNTER = 1847;
const SCROLL_BY_WHEEL_COUNTER = 1848;

var scrollable = document.getElementById('scrollable');
var rect = scrollable.getBoundingClientRect();
var start_x = (rect.left + rect.right) / 2;
var start_y = (rect.top + rect.bottom) / 2;

async function middleClickAutoscroll() {
  const middle_button = 1;
  await waitForCompositorCommit();
  await mouseMoveTo(start_x, start_y);
  await mouseClickOn(start_x, start_y, middle_button);
  await mouseMoveTo(start_x, start_y + 100);
  await waitFor(() => {
    return scrollable.scrollTop > 0;
  });
  await waitFor(() => {
    return internals.isUseCounted(document, MIDDLE_CLICK_AUTOSCROLL);
  }, "Didn't record middle click autoscroll");
  await mouseClickOn(start_x, start_y + 100, middle_button);
}

async function wheelScrollDown() {
  const precise_deltas = false;
  await waitForCompositorCommit();
  var previous_scroll_offset = scrollable.scrollTop;

  await smoothScroll(50, start_x, start_y,
      GestureSourceType.MOUSE_INPUT,'down', SPEED_INSTANT, precise_deltas);
  await waitFor(() => {
    return scrollable.scrollTop - previous_scroll_offset > 0;
  }, "Didn't scroll by wheel");
  await waitForCompositorCommit();
}

promise_test(async () => {
  // Autoscroll and check that middle click autoscroll use is counted.
  await middleClickAutoscroll();

  // Scroll by wheel and wait for wheel scrolling use count to increase.
  await wheelScrollDown();
  await waitFor(() => {
    return internals.isUseCounted(document, SCROLL_BY_WHEEL_COUNTER);
  }, "Didn't record wheel use count");

  // Now check that autoscrolling has not increased the touch scrolling use
  // count. We do this checking after wheel count increment to make sure that
  // we have waited long enough before verifying that the touch scrolling use
  // count is not incremented due to autoscrolling.
  assert_false(internals.isUseCounted(document, SCROLL_BY_TOUCH_COUNTER))
}, "Autoscrolling should not update touch scrolling usecounter.");

</script>