summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/events/browser_test_scrolling.js
blob: d9a4a0a73ff48115f0a6a98c44a6ad9c8292fba6 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

addAccessibleTask(
  `
    <div style="height: 100vh" id="one">one</div>
    <div style="height: 100vh" id="two">two</div>
    <div style="height: 100vh; width: 200vw; overflow: auto;" id="three">
      <div style="height: 300%;">three</div>
    </div>`,
  async function(browser, accDoc) {
    let onScrolling = waitForEvents([
      [EVENT_SCROLLING, accDoc],
      [EVENT_SCROLLING_END, accDoc],
    ]);
    await SpecialPowers.spawn(browser, [], () => {
      content.location.hash = "#two";
    });
    let [scrollEvent1, scrollEndEvent1] = await onScrolling;
    scrollEvent1.QueryInterface(nsIAccessibleScrollingEvent);
    ok(
      scrollEvent1.maxScrollY >= scrollEvent1.scrollY,
      "scrollY is within max"
    );
    scrollEndEvent1.QueryInterface(nsIAccessibleScrollingEvent);
    ok(
      scrollEndEvent1.maxScrollY >= scrollEndEvent1.scrollY,
      "scrollY is within max"
    );

    onScrolling = waitForEvents([
      [EVENT_SCROLLING, accDoc],
      [EVENT_SCROLLING_END, accDoc],
    ]);
    await SpecialPowers.spawn(browser, [], () => {
      content.location.hash = "#three";
    });
    let [scrollEvent2, scrollEndEvent2] = await onScrolling;
    scrollEvent2.QueryInterface(nsIAccessibleScrollingEvent);
    ok(
      scrollEvent2.scrollY > scrollEvent1.scrollY,
      `${scrollEvent2.scrollY} > ${scrollEvent1.scrollY}`
    );
    scrollEndEvent2.QueryInterface(nsIAccessibleScrollingEvent);
    ok(
      scrollEndEvent2.maxScrollY >= scrollEndEvent2.scrollY,
      "scrollY is within max"
    );

    onScrolling = waitForEvents([
      [EVENT_SCROLLING, accDoc],
      [EVENT_SCROLLING_END, accDoc],
    ]);
    await SpecialPowers.spawn(browser, [], () => {
      content.scrollTo(10, 0);
    });
    let [scrollEvent3, scrollEndEvent3] = await onScrolling;
    scrollEvent3.QueryInterface(nsIAccessibleScrollingEvent);
    ok(
      scrollEvent3.maxScrollX >= scrollEvent3.scrollX,
      "scrollX is within max"
    );
    scrollEndEvent3.QueryInterface(nsIAccessibleScrollingEvent);
    ok(
      scrollEndEvent3.maxScrollX >= scrollEndEvent3.scrollX,
      "scrollY is within max"
    );
    ok(
      scrollEvent3.scrollX > scrollEvent2.scrollX,
      `${scrollEvent3.scrollX} > ${scrollEvent2.scrollX}`
    );

    // non-doc scrolling
    onScrolling = waitForEvents([
      [EVENT_SCROLLING, "three"],
      [EVENT_SCROLLING_END, "three"],
    ]);
    await SpecialPowers.spawn(browser, [], () => {
      content.document.querySelector("#three").scrollTo(0, 10);
    });
    let [scrollEvent4, scrollEndEvent4] = await onScrolling;
    scrollEvent4.QueryInterface(nsIAccessibleScrollingEvent);
    ok(
      scrollEvent4.maxScrollY >= scrollEvent4.scrollY,
      "scrollY is within max"
    );
    scrollEndEvent4.QueryInterface(nsIAccessibleScrollingEvent);
    ok(
      scrollEndEvent4.maxScrollY >= scrollEndEvent4.scrollY,
      "scrollY is within max"
    );
  }
);