File: user-scroll-common.js

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (71 lines) | stat: -rw-r--r-- 2,954 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Helper functions for scrollsnapchange-on-user-* tests.

// This performs a touch scroll on |scroller| using the coordinates provided
// in |start_pos| and |end_pos|.
// It is meant for use in scrollsnapchange & scrollsnapchanging tests for triggering snap
// events when touch scrolling from |start_pos| to |end_pos|.
function snap_event_touch_scroll_helper(start_pos, end_pos) {
  return new test_driver.Actions()
    .addPointer("TestPointer", "touch")
    .pointerMove(Math.round(start_pos.x), Math.round(start_pos.y))
    .pointerDown()
    .addTick()
    .pause(200)
    .pointerMove(Math.round(end_pos.x), Math.round(end_pos.y))
    .addTick()
    .pointerUp()
    .send();
}

// This drags the provided |scroller|'s scrollbar  vertically by |drag_amt|.
// Snap event tests should provide a |drag_amt| that would result in a
// the desired snap event being triggered.
const vertical_offset_into_scrollbar = 30;
function snap_event_scrollbar_drag_helper(scroller, scrollbar_width, drag_amt) {
  let x, y, bounds;
  if (scroller == document.scrollingElement) {
    bounds = document.documentElement.getBoundingClientRect();
    x = Math.round(window.innerWidth - scrollbar_width / 2);
  } else {
    bounds = scroller.getBoundingClientRect();
    x = Math.round(bounds.right - Math.round(scrollbar_width / 2));
  }
  y = Math.round(bounds.top + vertical_offset_into_scrollbar);
  return new test_driver.Actions()
    .addPointer('TestPointer', 'mouse')
    .pointerMove(x, y)
    .pointerDown()
    .pointerMove(x, Math.round(y + drag_amt))
    .addTick()
    .pointerUp()
    .send();
}

// This tests that snap event of type |event_type| don't fire for a user (wheel)
// scroll that snaps back to the same element. Snap events tests should provide
// a |delta| small enough that no change in |scroller|'s snap targets occurs at
// the end of the scroll.
async function test_no_snap_event(test, scroller, delta, event_type) {
  const listening_element = scroller == document.scrollingElement
      ? document : scroller;
  checkSnapEventSupport(event_type);
  await waitForScrollReset(test, scroller);
  await waitForCompositorCommit();
  let snap_event_promise = waitForSnapEvent(listening_element, event_type);
  // Set the scroll destination to just a little off (0, 0) top so we snap
  // back to the top box.
  await new test_driver.Actions().scroll(0, 0, delta, delta,
      { origin: scroller }).send();
  let evt = await snap_event_promise;
  assert_equals(evt, null, "no snap event since scroller is back to top");
  assert_equals(scroller.scrollTop, 0, "scroller snaps back to the top");
  assert_equals(scroller.scrollLeft, 0, "scroller snaps back to the left");
}

async function test_no_scrollsnapchange(t, scroller, delta) {
  await test_no_snap_event(t, scroller, delta, "scrollsnapchange");
}

async function test_no_scrollsnapchanging(t, scroller, delta) {
  await test_no_snap_event(t, scroller, delta, "scrollsnapchanging");
}