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