browser/components/tabview/test/browser_tabview_bug580412.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/tabview/test/browser_tabview_bug580412.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +function test() {
     1.8 +  waitForExplicitFinish();
     1.9 +  showTabView(onTabViewShown);
    1.10 +}
    1.11 +
    1.12 +function onTabViewShown() {
    1.13 +  let contentWindow = TabView.getContentWindow();
    1.14 +  let [originalTab] = gBrowser.visibleTabs;
    1.15 +
    1.16 +  ok(TabView.isVisible(), "Tab View is visible");
    1.17 +  is(contentWindow.GroupItems.groupItems.length, 1, "There is only one group");
    1.18 +  let currentActiveGroup = contentWindow.GroupItems.getActiveGroupItem();
    1.19 +
    1.20 +  let endGame = function() {
    1.21 +    ok(TabView.isVisible(), "TabView is shown");
    1.22 +    gBrowser.selectedTab = originalTab;
    1.23 +
    1.24 +    hideTabView(function () {
    1.25 +      ok(!TabView.isVisible(), "TabView is hidden");
    1.26 +      finish();
    1.27 +    });
    1.28 +  }
    1.29 +
    1.30 +  // we need to stop the setBounds() css animation or else the test will
    1.31 +  // fail in single-mode because the group is newly created "ontabshown".
    1.32 +  let $container = contentWindow.iQ(currentActiveGroup.container);
    1.33 +  $container.css("transition-property", "none");
    1.34 +
    1.35 +  currentActiveGroup.setPosition(40, 40, true);
    1.36 +  currentActiveGroup.arrange({animate: false});
    1.37 +
    1.38 +  // move down 20 so we're far enough away from the top.
    1.39 +  checkSnap(currentActiveGroup, 0, 20, contentWindow, function(snapped){
    1.40 +    is(currentActiveGroup.getBounds().top, 60, "group.top is 60px");
    1.41 +    ok(!snapped,"Move away from the edge");
    1.42 +
    1.43 +    // Just pick it up and drop it.
    1.44 +    checkSnap(currentActiveGroup, 0, 0, contentWindow, function(snapped){
    1.45 +      is(currentActiveGroup.getBounds().top, 60, "group.top is 60px");
    1.46 +      ok(!snapped,"Just pick it up and drop it");
    1.47 +
    1.48 +      checkSnap(currentActiveGroup, 0, 1, contentWindow, function(snapped){
    1.49 +        is(currentActiveGroup.getBounds().top, 60, "group.top is 60px");
    1.50 +        ok(snapped,"Drag one pixel: should snap");
    1.51 +
    1.52 +        checkSnap(currentActiveGroup, 0, 5, contentWindow, function(snapped){
    1.53 +          is(currentActiveGroup.getBounds().top, 65, "group.top is 65px");
    1.54 +          ok(!snapped,"Moving five pixels: shouldn't snap");
    1.55 +          endGame();
    1.56 +        });
    1.57 +      });
    1.58 +    });
    1.59 +  });
    1.60 +}
    1.61 +
    1.62 +function simulateDragDrop(item, offsetX, offsetY, contentWindow) {
    1.63 +  let target = item.container;
    1.64 +
    1.65 +  EventUtils.synthesizeMouse(target, 1, 1, {type: "mousedown"}, contentWindow);
    1.66 +  EventUtils.synthesizeMouse(target, 1 + offsetX, 1 + offsetY, {type: "mousemove"}, contentWindow);
    1.67 +  EventUtils.synthesizeMouse(target, 1, 1, {type: "mouseup"}, contentWindow);
    1.68 +}
    1.69 +
    1.70 +function checkSnap(item, offsetX, offsetY, contentWindow, callback) {
    1.71 +  let firstTop = item.getBounds().top;
    1.72 +  let firstLeft = item.getBounds().left;
    1.73 +
    1.74 +  simulateDragDrop(item, offsetX, offsetY, contentWindow);
    1.75 +
    1.76 +  let snapped = false;
    1.77 +  if (item.getBounds().top != firstTop + offsetY)
    1.78 +    snapped = true;
    1.79 +  if (item.getBounds().left != firstLeft + offsetX)
    1.80 +    snapped = true;
    1.81 +
    1.82 +  callback(snapped);
    1.83 +}

mercurial