|
1 var tabstrip = gBrowser.tabContainer.mTabstrip; |
|
2 var scrollbox = tabstrip._scrollbox; |
|
3 var originalSmoothScroll = tabstrip.smoothScroll; |
|
4 var tabs = gBrowser.tabs; |
|
5 |
|
6 function rect(ele) ele.getBoundingClientRect(); |
|
7 function width(ele) rect(ele).width; |
|
8 function left(ele) rect(ele).left; |
|
9 function right(ele) rect(ele).right; |
|
10 function isLeft(ele, msg) is(left(ele) + tabstrip._tabMarginLeft, left(scrollbox), msg); |
|
11 function isRight(ele, msg) is(right(ele) - tabstrip._tabMarginRight, right(scrollbox), msg); |
|
12 function elementFromPoint(x) tabstrip._elementFromPoint(x); |
|
13 function nextLeftElement() elementFromPoint(left(scrollbox) - 1); |
|
14 function nextRightElement() elementFromPoint(right(scrollbox) + 1); |
|
15 function firstScrollable() tabs[gBrowser._numPinnedTabs]; |
|
16 |
|
17 function test() { |
|
18 requestLongerTimeout(2); |
|
19 waitForExplicitFinish(); |
|
20 |
|
21 // If the previous (or more) test finished with cleaning up the tabs, |
|
22 // there may be some pending animations. That can cause a failure of |
|
23 // this tests, so, we should test this in another stack. |
|
24 setTimeout(doTest, 0); |
|
25 } |
|
26 |
|
27 function doTest() { |
|
28 tabstrip.smoothScroll = false; |
|
29 |
|
30 var tabMinWidth = parseInt(getComputedStyle(gBrowser.selectedTab, null).minWidth); |
|
31 var tabCountForOverflow = Math.ceil(width(tabstrip) / tabMinWidth * 3); |
|
32 while (tabs.length < tabCountForOverflow) |
|
33 gBrowser.addTab("about:blank", {skipAnimation: true}); |
|
34 gBrowser.pinTab(tabs[0]); |
|
35 |
|
36 tabstrip.addEventListener("overflow", runOverflowTests, false); |
|
37 } |
|
38 |
|
39 function runOverflowTests(aEvent) { |
|
40 if (aEvent.detail != 1) |
|
41 return; |
|
42 |
|
43 tabstrip.removeEventListener("overflow", runOverflowTests, false); |
|
44 |
|
45 var upButton = tabstrip._scrollButtonUp; |
|
46 var downButton = tabstrip._scrollButtonDown; |
|
47 var element; |
|
48 |
|
49 gBrowser.selectedTab = firstScrollable(); |
|
50 ok(left(scrollbox) <= left(firstScrollable()), "Selecting the first tab scrolls it into view " + |
|
51 "(" + left(scrollbox) + " <= " + left(firstScrollable()) + ")"); |
|
52 |
|
53 element = nextRightElement(); |
|
54 EventUtils.synthesizeMouseAtCenter(downButton, {}); |
|
55 isRight(element, "Scrolled one tab to the right with a single click"); |
|
56 |
|
57 gBrowser.selectedTab = tabs[tabs.length - 1]; |
|
58 ok(right(gBrowser.selectedTab) <= right(scrollbox), "Selecting the last tab scrolls it into view " + |
|
59 "(" + right(gBrowser.selectedTab) + " <= " + right(scrollbox) + ")"); |
|
60 |
|
61 element = nextLeftElement(); |
|
62 EventUtils.synthesizeMouse(upButton, 1, 1, {}); |
|
63 isLeft(element, "Scrolled one tab to the left with a single click"); |
|
64 |
|
65 let elementPoint = left(scrollbox) - width(scrollbox); |
|
66 element = elementFromPoint(elementPoint); |
|
67 if (elementPoint == right(element)) { |
|
68 element = element.nextSibling; |
|
69 } |
|
70 EventUtils.synthesizeMouse(upButton, 1, 1, {clickCount: 2}); |
|
71 isLeft(element, "Scrolled one page of tabs with a double click"); |
|
72 |
|
73 EventUtils.synthesizeMouse(upButton, 1, 1, {clickCount: 3}); |
|
74 var firstScrollableLeft = left(firstScrollable()); |
|
75 ok(left(scrollbox) <= firstScrollableLeft, "Scrolled to the start with a triple click " + |
|
76 "(" + left(scrollbox) + " <= " + firstScrollableLeft + ")"); |
|
77 |
|
78 for (var i = 2; i; i--) |
|
79 EventUtils.synthesizeWheel(scrollbox, 1, 1, { deltaX: -1.0, deltaMode: WheelEvent.DOM_DELTA_LINE }); |
|
80 is(left(firstScrollable()), firstScrollableLeft, "Remained at the start with the mouse wheel"); |
|
81 |
|
82 element = nextRightElement(); |
|
83 EventUtils.synthesizeWheel(scrollbox, 1, 1, { deltaX: 1.0, deltaMode: WheelEvent.DOM_DELTA_LINE}); |
|
84 isRight(element, "Scrolled one tab to the right with the mouse wheel"); |
|
85 |
|
86 while (tabs.length > 1) |
|
87 gBrowser.removeTab(tabs[0]); |
|
88 |
|
89 tabstrip.smoothScroll = originalSmoothScroll; |
|
90 finish(); |
|
91 } |