browser/components/tabview/test/browser_tabview_bug580412.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 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 function test() {
     5   waitForExplicitFinish();
     6   showTabView(onTabViewShown);
     7 }
     9 function onTabViewShown() {
    10   let contentWindow = TabView.getContentWindow();
    11   let [originalTab] = gBrowser.visibleTabs;
    13   ok(TabView.isVisible(), "Tab View is visible");
    14   is(contentWindow.GroupItems.groupItems.length, 1, "There is only one group");
    15   let currentActiveGroup = contentWindow.GroupItems.getActiveGroupItem();
    17   let endGame = function() {
    18     ok(TabView.isVisible(), "TabView is shown");
    19     gBrowser.selectedTab = originalTab;
    21     hideTabView(function () {
    22       ok(!TabView.isVisible(), "TabView is hidden");
    23       finish();
    24     });
    25   }
    27   // we need to stop the setBounds() css animation or else the test will
    28   // fail in single-mode because the group is newly created "ontabshown".
    29   let $container = contentWindow.iQ(currentActiveGroup.container);
    30   $container.css("transition-property", "none");
    32   currentActiveGroup.setPosition(40, 40, true);
    33   currentActiveGroup.arrange({animate: false});
    35   // move down 20 so we're far enough away from the top.
    36   checkSnap(currentActiveGroup, 0, 20, contentWindow, function(snapped){
    37     is(currentActiveGroup.getBounds().top, 60, "group.top is 60px");
    38     ok(!snapped,"Move away from the edge");
    40     // Just pick it up and drop it.
    41     checkSnap(currentActiveGroup, 0, 0, contentWindow, function(snapped){
    42       is(currentActiveGroup.getBounds().top, 60, "group.top is 60px");
    43       ok(!snapped,"Just pick it up and drop it");
    45       checkSnap(currentActiveGroup, 0, 1, contentWindow, function(snapped){
    46         is(currentActiveGroup.getBounds().top, 60, "group.top is 60px");
    47         ok(snapped,"Drag one pixel: should snap");
    49         checkSnap(currentActiveGroup, 0, 5, contentWindow, function(snapped){
    50           is(currentActiveGroup.getBounds().top, 65, "group.top is 65px");
    51           ok(!snapped,"Moving five pixels: shouldn't snap");
    52           endGame();
    53         });
    54       });
    55     });
    56   });
    57 }
    59 function simulateDragDrop(item, offsetX, offsetY, contentWindow) {
    60   let target = item.container;
    62   EventUtils.synthesizeMouse(target, 1, 1, {type: "mousedown"}, contentWindow);
    63   EventUtils.synthesizeMouse(target, 1 + offsetX, 1 + offsetY, {type: "mousemove"}, contentWindow);
    64   EventUtils.synthesizeMouse(target, 1, 1, {type: "mouseup"}, contentWindow);
    65 }
    67 function checkSnap(item, offsetX, offsetY, contentWindow, callback) {
    68   let firstTop = item.getBounds().top;
    69   let firstLeft = item.getBounds().left;
    71   simulateDragDrop(item, offsetX, offsetY, contentWindow);
    73   let snapped = false;
    74   if (item.getBounds().top != firstTop + offsetY)
    75     snapped = true;
    76   if (item.getBounds().left != firstLeft + offsetX)
    77     snapped = true;
    79   callback(snapped);
    80 }

mercurial