summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/events/scrolling/scrollend-event-for-user-scroll.html
blob: 561c90ca94c6af8c0335a962a16273e44c2d3717 (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="scroll_support.js"></script>
<style>
    #targetDiv {
        width: 200px;
        height: 200px;
        overflow: scroll;
    }

    #innerDiv {
        width: 400px;
        height: 400px;
    }
</style>
</head>
<body style="margin:0" onload=runTest()>
    <div id="targetDiv">
        <div id="innerDiv">
        </div>
    </div>
</body>

<script>
var target_div = document.getElementById('targetDiv');

function runTest() {
  promise_test(async (t) => {
    // Skip the test on a Mac as they do not support touch screens.
    const isMac = navigator.platform.toUpperCase().indexOf('MAC')>=0;
    if (isMac)
      return;

    await resetTargetScrollState(t, target_div);
    await waitForCompositorReady();

    const timeout = 3000; // Because we have two pauses we need longer timeout
    const targetScrollendPromise = createScrollendPromiseForTarget(t, target_div, timeout);
    verifyNoScrollendOnDocument(t);

    let scrollend_count = 0;
    const scrollend_listener = () => {
      scrollend_count += 1;
    };
    target_div.addEventListener("scrollend", scrollend_listener);
    t.add_cleanup(() => {
      target_div.removeEventListener('scrollend', scrollend_listener);
    });

    // Perform a touch drag on target div and wait for target_div to get
    // a scrollend event.
    await new test_driver.Actions()
        .addPointer('TestPointer', 'touch')
        .pointerMove(0, 0, {origin: target_div}) // 0, 0 is center of element.
        .pointerDown()
        .addTick()
        .pointerMove(0, -40, {origin: target_div}) //  Drag up to move down.
        .addTick()
        .pause(200) //  Prevent inertial scroll.
        .pointerMove(0, -60, {origin: target_div})
        .addTick()
        .pause(200) //  Prevent inertial scroll.
        .pointerUp()
        .send();

    await targetScrollendPromise;

    assert_true(target_div.scrollTop > 0);
    await verifyScrollStopped(t, target_div);
    assert_equals(scrollend_count, 1);
  }, 'Tests that the target_div gets scrollend event when touch dragging.');

  promise_test(async (t) => {
    // Skip test on platforms that do not have a visible scrollbar (e.g.
    // overlay scrollbar).
    const scrollbar_width = target_div.offsetWidth - target_div.clientWidth;
    if (scrollbar_width == 0)
      return;

    await resetTargetScrollState(t, target_div);
    await waitForCompositorReady();

    const targetScrollendPromise = createScrollendPromiseForTarget(t, target_div);
    verifyNoScrollendOnDocument(t);

    const bounds = target_div.getBoundingClientRect();
    // Some versions of webdriver have been known to frown at non-int arguments
    // to pointerMove.
    const x = bounds.right - Math.round(scrollbar_width / 2);
    const y = bounds.bottom - 20;
    await new test_driver.Actions()
        .addPointer('TestPointer', 'mouse')
        .pointerMove(x, y, {origin: 'viewport'})
        .pointerDown()
        .addTick()
        .pointerUp()
        .send();

    await targetScrollendPromise;
    assert_true(target_div.scrollTop > 0);
    await verifyScrollStopped(t, target_div);
  }, 'Tests that the target_div gets scrollend event when clicking ' +
     'scrollbar.');

  // Same issue as previous test.
  promise_test(async (t) => {
    // Skip test on platforms that do not have a visible scrollbar (e.g.
    // overlay scrollbar).
    const scrollbar_width = target_div.offsetWidth - target_div.clientWidth;
    if (scrollbar_width == 0)
      return;

    await resetTargetScrollState(t, target_div);
    await waitForCompositorReady();

    const targetScrollendPromise = createScrollendPromiseForTarget(t, target_div, 1000);
    verifyNoScrollendOnDocument(t);

    const bounds = target_div.getBoundingClientRect();
    // Some versions of webdriver have been known to frown at non-int arguments
    // to pointerMove.
    const x = bounds.right - Math.round(scrollbar_width / 2);
    const y = bounds.top + 30;
    const dy = 30;
    await new test_driver.Actions()
        .addPointer('TestPointer', 'mouse')
        .pointerMove(x, y, { origin: 'viewport' })
        .pointerDown()
        .pointerMove(x, y + dy, { origin: 'viewport' })
        .addTick()
        .pointerUp()
        .send();

    await targetScrollendPromise;
    assert_true(target_div.scrollTop > 0);
    await verifyScrollStopped(t, target_div);
  }, 'Tests that the target_div gets scrollend event when dragging the ' +
      'scrollbar thumb.');

  promise_test(async (t) => {
    await resetTargetScrollState(t, target_div);
    await waitForCompositorReady();

    const targetScrollendPromise = createScrollendPromiseForTarget(t, target_div);
    verifyNoScrollendOnDocument(t);

    const x = 0;
    const y = 0;
    const dx = 0;
    const dy = 40;
    const duration_ms = 10;
    await new test_driver.Actions()
        .scroll(x, y, dx, dy, { origin: target_div }, duration_ms)
        .send();

    await targetScrollendPromise;
    assert_true(target_div.scrollTop > 0);
    await verifyScrollStopped(t, target_div);
  }, 'Tests that the target_div gets scrollend event when mouse wheel ' +
     'scrolling.');

  promise_test(async (t) => {
    await resetTargetScrollState(t, target_div);
    await waitForCompositorReady();

    verifyNoScrollendOnDocument(t);
    const targetScrollendPromise = createScrollendPromiseForTarget(t, target_div);

    target_div.focus();
    window.test_driver.send_keys(target_div, '\ue015');

    await targetScrollendPromise;
    assert_true(target_div.scrollTop > 0);
    await verifyScrollStopped(t, target_div);
  }, 'Tests that the target_div gets scrollend event when sending DOWN key ' +
     'to the target.');
}

</script>
</html>