summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabs/browser_overflowScroll.js
blob: cae033e3bf6a7a162b6c8a6e643722104f51749d (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
"use strict";

requestLongerTimeout(2);

/**
 * Tests that scrolling the tab strip via the scroll buttons scrolls the right
 * amount in non-smoothscroll mode.
 */
add_task(async function () {
  let arrowScrollbox = gBrowser.tabContainer.arrowScrollbox;
  let scrollbox = arrowScrollbox.scrollbox;

  let rect = ele => ele.getBoundingClientRect();
  let width = ele => rect(ele).width;

  let left = ele => rect(ele).left;
  let right = ele => rect(ele).right;
  let isLeft = (ele, msg) => is(left(ele), left(scrollbox), msg);
  let isRight = (ele, msg) => is(right(ele), right(scrollbox), msg);
  let elementFromPoint = x => arrowScrollbox._elementFromPoint(x);
  let nextLeftElement = () => elementFromPoint(left(scrollbox) - 1);
  let nextRightElement = () => elementFromPoint(right(scrollbox) + 1);
  let firstScrollable = () => gBrowser.tabs[gBrowser._numPinnedTabs];
  let waitForNextFrame = async function () {
    await new Promise(requestAnimationFrame);
    await new Promise(resolve => Services.tm.dispatchToMainThread(resolve));
  };

  await BrowserTestUtils.overflowTabs(registerCleanupFunction, window, {
    overflowAtStart: false,
    overflowTabFactor: 3,
  });

  gBrowser.pinTab(gBrowser.tabs[0]);

  await BrowserTestUtils.waitForCondition(() => {
    return Array.from(gBrowser.tabs).every(tab => tab._fullyOpen);
  });

  ok(
    arrowScrollbox.hasAttribute("overflowing"),
    "Tab strip should be overflowing"
  );

  let upButton = arrowScrollbox._scrollButtonUp;
  let downButton = arrowScrollbox._scrollButtonDown;
  let element;

  gBrowser.selectedTab = firstScrollable();
  await TestUtils.waitForTick();

  Assert.lessOrEqual(
    left(scrollbox),
    left(firstScrollable()),
    "Selecting the first tab scrolls it into view " +
      "(" +
      left(scrollbox) +
      " <= " +
      left(firstScrollable()) +
      ")"
  );

  element = nextRightElement();
  EventUtils.synthesizeMouseAtCenter(downButton, {});
  await waitForNextFrame();
  isRight(element, "Scrolled one tab to the right with a single click");

  gBrowser.selectedTab = gBrowser.tabs[gBrowser.tabs.length - 1];
  await waitForNextFrame();
  Assert.lessOrEqual(
    right(gBrowser.selectedTab),
    right(scrollbox),
    "Selecting the last tab scrolls it into view " +
      "(" +
      right(gBrowser.selectedTab) +
      " <= " +
      right(scrollbox) +
      ")"
  );

  element = nextLeftElement();
  EventUtils.synthesizeMouseAtCenter(upButton, {});
  await waitForNextFrame();
  isLeft(element, "Scrolled one tab to the left with a single click");

  let elementPoint = left(scrollbox) - width(scrollbox);
  element = elementFromPoint(elementPoint);
  element = element.nextElementSibling;

  EventUtils.synthesizeMouseAtCenter(upButton, { clickCount: 2 });
  await waitForNextFrame();
  await BrowserTestUtils.waitForCondition(
    () => !gBrowser.tabContainer.arrowScrollbox._isScrolling
  );
  isLeft(element, "Scrolled one page of tabs with a double click");

  EventUtils.synthesizeMouseAtCenter(upButton, { clickCount: 3 });
  await waitForNextFrame();
  var firstScrollableLeft = left(firstScrollable());
  Assert.lessOrEqual(
    left(scrollbox),
    firstScrollableLeft,
    "Scrolled to the start with a triple click " +
      "(" +
      left(scrollbox) +
      " <= " +
      firstScrollableLeft +
      ")"
  );

  while (gBrowser.tabs.length > 1) {
    BrowserTestUtils.removeTab(gBrowser.tabs[0]);
  }
});