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: michael@0: function moveTabOutOfGroup(aTab, aGroup, aCW, aCallback) { michael@0: let tabPos = aTab.getBounds().center(); michael@0: let groupPos = aGroup.getBounds(); michael@0: let groupPosX = (groupPos.left + groupPos.right) / 2; michael@0: let groupPosY = groupPos.bottom + 200; michael@0: let offsetX = Math.round(groupPosX - tabPos.x); michael@0: let offsetY = Math.round(groupPosY - tabPos.y); michael@0: michael@0: simulateDragDrop(aTab, offsetX, offsetY, aCW); michael@0: } michael@0: michael@0: function moveTabInGroup(aTab, aIndexTo, aGroup, aCW) { michael@0: let tabTo = aGroup.getChild(aIndexTo); michael@0: let tabPos = aTab.getBounds().center(); michael@0: let tabToPos = tabTo.getBounds().center(); michael@0: let offsetX = Math.round(tabToPos.x - tabPos.x); michael@0: let offsetY = Math.round(tabToPos.y - tabPos.y); michael@0: michael@0: simulateDragDrop(aTab, offsetX, offsetY, aCW); michael@0: } michael@0: michael@0: function getTabNumbers(aGroup) { michael@0: return aGroup.getChildren().map(function (child) { michael@0: let url = child.tab.linkedBrowser.currentURI.spec; michael@0: return url.replace("about:blank#", ""); michael@0: }).join(","); michael@0: } michael@0: michael@0: function moveTabs(aGroup, aCW) { michael@0: // Test 1: Move the last tab to the third position. michael@0: let tab = aGroup.getChild(6); michael@0: moveTabInGroup(tab, 2, aGroup, aCW); michael@0: is(getTabNumbers(aGroup), "0,1,6,2,3,4,5", "Validate tab positions in test 1."); michael@0: michael@0: // Test 2: Move the second tab to the end of the list. michael@0: tab = aGroup.getChild(1); michael@0: moveTabInGroup(tab, 6, aGroup, aCW); michael@0: is(getTabNumbers(aGroup), "0,6,2,3,4,5,1", "Validate tab positions in test 2."); michael@0: michael@0: // Test 3: Move the fifth tab outside the group. michael@0: tab = aGroup.getChild(4); michael@0: moveTabOutOfGroup(tab, aGroup, aCW); michael@0: is(getTabNumbers(aGroup), "0,6,2,3,5,1", "Validate tab positions in test 3."); michael@0: is(aCW.GroupItems.groupItems.length, 3, "Validate group count in test 3."); michael@0: michael@0: // This test is disabled because it is fragile -- see bug 797975 michael@0: if (false) { michael@0: // Test 4: Move the fifth tab back into the group, on the second row. michael@0: waitForTransition(tab, function() { michael@0: moveTabInGroup(tab, 4, aGroup, aCW); michael@0: is(getTabNumbers(aGroup), "0,6,2,3,4,5,1", "Validate tab positions in test 4."); michael@0: is(aCW.GroupItems.groupItems.length, 2, "Validate group count in test 4."); michael@0: closeGroupItem(aGroup, function() { hideTabView(finish) }); michael@0: }); michael@0: } else { michael@0: closeGroupItem(aGroup, function() { hideTabView(finish) }); michael@0: } michael@0: } michael@0: michael@0: function createGroup(win) { michael@0: registerCleanupFunction(function() win.close()); michael@0: let cw = win.TabView.getContentWindow(); michael@0: let group = createGroupItemWithTabs(win, 400, 430, 100, [ michael@0: "about:blank#0", "about:blank#1", "about:blank#2", "about:blank#3", michael@0: "about:blank#4", "about:blank#5", "about:blank#6" michael@0: ]); michael@0: let groupSize = group.getChildren().length; michael@0: michael@0: is(cw.GroupItems.groupItems.length, 2, "Validate group count in tab view."); michael@0: ok(!group.shouldStack(groupSize), "Check that group should not stack."); michael@0: is(group._columns, 3, "Check the there should be three columns."); michael@0: michael@0: moveTabs(group, cw); michael@0: } michael@0: michael@0: newWindowWithTabView(createGroup); michael@0: } michael@0: michael@0: function simulateDragDrop(aTab, aOffsetX, aOffsetY, aCW) { michael@0: let target = aTab.container; michael@0: let rect = target.getBoundingClientRect(); michael@0: let startX = (rect.right - rect.left) / 2; michael@0: let startY = (rect.bottom - rect.top) / 2; michael@0: let steps = 2; michael@0: let incrementX = aOffsetX / steps; michael@0: let incrementY = aOffsetY / steps; michael@0: michael@0: EventUtils.synthesizeMouse( michael@0: target, startX, startY, { type: "mousedown" }, aCW); michael@0: for (let i = 1; i <= steps; i++) { michael@0: EventUtils.synthesizeMouse( michael@0: target, incrementX + startX, incrementY + startY, michael@0: { type: "mousemove" }, aCW); michael@0: }; michael@0: EventUtils.synthesizeMouseAtCenter(target, { type: "mouseup" }, aCW); michael@0: } michael@0: michael@0: function waitForTransition(aTab, aCallback) { michael@0: let groupContainer = aTab.parent.container; michael@0: groupContainer.addEventListener("transitionend", function onTransitionEnd(aEvent) { michael@0: if (aEvent.target == groupContainer) { michael@0: groupContainer.removeEventListener("transitionend", onTransitionEnd); michael@0: executeSoon(aCallback); michael@0: } michael@0: }); michael@0: }