michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: showTabView(onTabViewShown); michael@0: } michael@0: michael@0: function onTabViewShown() { michael@0: let contentWindow = TabView.getContentWindow(); michael@0: let [originalTab] = gBrowser.visibleTabs; michael@0: michael@0: ok(TabView.isVisible(), "Tab View is visible"); michael@0: is(contentWindow.GroupItems.groupItems.length, 1, "There is only one group"); michael@0: let currentActiveGroup = contentWindow.GroupItems.getActiveGroupItem(); michael@0: michael@0: let endGame = function() { michael@0: ok(TabView.isVisible(), "TabView is shown"); michael@0: gBrowser.selectedTab = originalTab; michael@0: michael@0: hideTabView(function () { michael@0: ok(!TabView.isVisible(), "TabView is hidden"); michael@0: finish(); michael@0: }); michael@0: } michael@0: michael@0: // we need to stop the setBounds() css animation or else the test will michael@0: // fail in single-mode because the group is newly created "ontabshown". michael@0: let $container = contentWindow.iQ(currentActiveGroup.container); michael@0: $container.css("transition-property", "none"); michael@0: michael@0: currentActiveGroup.setPosition(40, 40, true); michael@0: currentActiveGroup.arrange({animate: false}); michael@0: michael@0: // move down 20 so we're far enough away from the top. michael@0: checkSnap(currentActiveGroup, 0, 20, contentWindow, function(snapped){ michael@0: is(currentActiveGroup.getBounds().top, 60, "group.top is 60px"); michael@0: ok(!snapped,"Move away from the edge"); michael@0: michael@0: // Just pick it up and drop it. michael@0: checkSnap(currentActiveGroup, 0, 0, contentWindow, function(snapped){ michael@0: is(currentActiveGroup.getBounds().top, 60, "group.top is 60px"); michael@0: ok(!snapped,"Just pick it up and drop it"); michael@0: michael@0: checkSnap(currentActiveGroup, 0, 1, contentWindow, function(snapped){ michael@0: is(currentActiveGroup.getBounds().top, 60, "group.top is 60px"); michael@0: ok(snapped,"Drag one pixel: should snap"); michael@0: michael@0: checkSnap(currentActiveGroup, 0, 5, contentWindow, function(snapped){ michael@0: is(currentActiveGroup.getBounds().top, 65, "group.top is 65px"); michael@0: ok(!snapped,"Moving five pixels: shouldn't snap"); michael@0: endGame(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function simulateDragDrop(item, offsetX, offsetY, contentWindow) { michael@0: let target = item.container; michael@0: michael@0: EventUtils.synthesizeMouse(target, 1, 1, {type: "mousedown"}, contentWindow); michael@0: EventUtils.synthesizeMouse(target, 1 + offsetX, 1 + offsetY, {type: "mousemove"}, contentWindow); michael@0: EventUtils.synthesizeMouse(target, 1, 1, {type: "mouseup"}, contentWindow); michael@0: } michael@0: michael@0: function checkSnap(item, offsetX, offsetY, contentWindow, callback) { michael@0: let firstTop = item.getBounds().top; michael@0: let firstLeft = item.getBounds().left; michael@0: michael@0: simulateDragDrop(item, offsetX, offsetY, contentWindow); michael@0: michael@0: let snapped = false; michael@0: if (item.getBounds().top != firstTop + offsetY) michael@0: snapped = true; michael@0: if (item.getBounds().left != firstLeft + offsetX) michael@0: snapped = true; michael@0: michael@0: callback(snapped); michael@0: }