michael@0: var tabstrip = gBrowser.tabContainer.mTabstrip; michael@0: var scrollbox = tabstrip._scrollbox; michael@0: var originalSmoothScroll = tabstrip.smoothScroll; michael@0: var tabs = gBrowser.tabs; michael@0: michael@0: function rect(ele) ele.getBoundingClientRect(); michael@0: function width(ele) rect(ele).width; michael@0: function left(ele) rect(ele).left; michael@0: function right(ele) rect(ele).right; michael@0: function isLeft(ele, msg) is(left(ele) + tabstrip._tabMarginLeft, left(scrollbox), msg); michael@0: function isRight(ele, msg) is(right(ele) - tabstrip._tabMarginRight, right(scrollbox), msg); michael@0: function elementFromPoint(x) tabstrip._elementFromPoint(x); michael@0: function nextLeftElement() elementFromPoint(left(scrollbox) - 1); michael@0: function nextRightElement() elementFromPoint(right(scrollbox) + 1); michael@0: function firstScrollable() tabs[gBrowser._numPinnedTabs]; michael@0: michael@0: function test() { michael@0: requestLongerTimeout(2); michael@0: waitForExplicitFinish(); michael@0: michael@0: // If the previous (or more) test finished with cleaning up the tabs, michael@0: // there may be some pending animations. That can cause a failure of michael@0: // this tests, so, we should test this in another stack. michael@0: setTimeout(doTest, 0); michael@0: } michael@0: michael@0: function doTest() { michael@0: tabstrip.smoothScroll = false; michael@0: michael@0: var tabMinWidth = parseInt(getComputedStyle(gBrowser.selectedTab, null).minWidth); michael@0: var tabCountForOverflow = Math.ceil(width(tabstrip) / tabMinWidth * 3); michael@0: while (tabs.length < tabCountForOverflow) michael@0: gBrowser.addTab("about:blank", {skipAnimation: true}); michael@0: gBrowser.pinTab(tabs[0]); michael@0: michael@0: tabstrip.addEventListener("overflow", runOverflowTests, false); michael@0: } michael@0: michael@0: function runOverflowTests(aEvent) { michael@0: if (aEvent.detail != 1) michael@0: return; michael@0: michael@0: tabstrip.removeEventListener("overflow", runOverflowTests, false); michael@0: michael@0: var upButton = tabstrip._scrollButtonUp; michael@0: var downButton = tabstrip._scrollButtonDown; michael@0: var element; michael@0: michael@0: gBrowser.selectedTab = firstScrollable(); michael@0: ok(left(scrollbox) <= left(firstScrollable()), "Selecting the first tab scrolls it into view " + michael@0: "(" + left(scrollbox) + " <= " + left(firstScrollable()) + ")"); michael@0: michael@0: element = nextRightElement(); michael@0: EventUtils.synthesizeMouseAtCenter(downButton, {}); michael@0: isRight(element, "Scrolled one tab to the right with a single click"); michael@0: michael@0: gBrowser.selectedTab = tabs[tabs.length - 1]; michael@0: ok(right(gBrowser.selectedTab) <= right(scrollbox), "Selecting the last tab scrolls it into view " + michael@0: "(" + right(gBrowser.selectedTab) + " <= " + right(scrollbox) + ")"); michael@0: michael@0: element = nextLeftElement(); michael@0: EventUtils.synthesizeMouse(upButton, 1, 1, {}); michael@0: isLeft(element, "Scrolled one tab to the left with a single click"); michael@0: michael@0: let elementPoint = left(scrollbox) - width(scrollbox); michael@0: element = elementFromPoint(elementPoint); michael@0: if (elementPoint == right(element)) { michael@0: element = element.nextSibling; michael@0: } michael@0: EventUtils.synthesizeMouse(upButton, 1, 1, {clickCount: 2}); michael@0: isLeft(element, "Scrolled one page of tabs with a double click"); michael@0: michael@0: EventUtils.synthesizeMouse(upButton, 1, 1, {clickCount: 3}); michael@0: var firstScrollableLeft = left(firstScrollable()); michael@0: ok(left(scrollbox) <= firstScrollableLeft, "Scrolled to the start with a triple click " + michael@0: "(" + left(scrollbox) + " <= " + firstScrollableLeft + ")"); michael@0: michael@0: for (var i = 2; i; i--) michael@0: EventUtils.synthesizeWheel(scrollbox, 1, 1, { deltaX: -1.0, deltaMode: WheelEvent.DOM_DELTA_LINE }); michael@0: is(left(firstScrollable()), firstScrollableLeft, "Remained at the start with the mouse wheel"); michael@0: michael@0: element = nextRightElement(); michael@0: EventUtils.synthesizeWheel(scrollbox, 1, 1, { deltaX: 1.0, deltaMode: WheelEvent.DOM_DELTA_LINE}); michael@0: isRight(element, "Scrolled one tab to the right with the mouse wheel"); michael@0: michael@0: while (tabs.length > 1) michael@0: gBrowser.removeTab(tabs[0]); michael@0: michael@0: tabstrip.smoothScroll = originalSmoothScroll; michael@0: finish(); michael@0: }