browser/base/content/test/general/browser_overflowScroll.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 var tabstrip = gBrowser.tabContainer.mTabstrip;
     2 var scrollbox = tabstrip._scrollbox;
     3 var originalSmoothScroll = tabstrip.smoothScroll;
     4 var tabs = gBrowser.tabs;
     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];
    17 function test() {
    18   requestLongerTimeout(2);
    19   waitForExplicitFinish();
    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 }
    27 function doTest() {
    28   tabstrip.smoothScroll = false;
    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]);
    36   tabstrip.addEventListener("overflow", runOverflowTests, false);
    37 }
    39 function runOverflowTests(aEvent) {
    40   if (aEvent.detail != 1)
    41     return;
    43   tabstrip.removeEventListener("overflow", runOverflowTests, false);
    45   var upButton = tabstrip._scrollButtonUp;
    46   var downButton = tabstrip._scrollButtonDown;
    47   var element;
    49   gBrowser.selectedTab = firstScrollable();
    50   ok(left(scrollbox) <= left(firstScrollable()), "Selecting the first tab scrolls it into view " +
    51      "(" + left(scrollbox) + " <= " + left(firstScrollable()) + ")");
    53   element = nextRightElement();
    54   EventUtils.synthesizeMouseAtCenter(downButton, {});
    55   isRight(element, "Scrolled one tab to the right with a single click");
    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) + ")");
    61   element = nextLeftElement();
    62   EventUtils.synthesizeMouse(upButton, 1, 1, {});
    63   isLeft(element, "Scrolled one tab to the left with a single click");
    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");
    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 + ")");
    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");
    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");
    86   while (tabs.length > 1)
    87     gBrowser.removeTab(tabs[0]);
    89   tabstrip.smoothScroll = originalSmoothScroll;
    90   finish();
    91 }

mercurial