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: ok(TabView.isVisible(), "Tab View is visible"); michael@0: michael@0: let contentWindow = TabView.getContentWindow(); michael@0: let [originalTab] = gBrowser.visibleTabs; michael@0: michael@0: let createGroupItem = function (left, top, width, height) { michael@0: let box = new contentWindow.Rect(left, top, width, height); michael@0: let groupItem = new contentWindow.GroupItem([], {bounds: box, immediately: true}); michael@0: michael@0: contentWindow.UI.setActive(groupItem); michael@0: gBrowser.loadOneTab("about:blank", {inBackground: true}); michael@0: michael@0: return groupItem; michael@0: }; michael@0: michael@0: // create group one and two michael@0: let groupOne = createGroupItem(20, 20, 300, 300); michael@0: let groupTwo = createGroupItem(20, 400, 300, 300); michael@0: michael@0: waitForFocus(function () { michael@0: addTest(contentWindow, groupOne.id, groupTwo.id, originalTab); michael@0: }); michael@0: } michael@0: michael@0: function addTest(contentWindow, groupOneId, groupTwoId, originalTab) { michael@0: let groupOne = contentWindow.GroupItems.groupItem(groupOneId); michael@0: let groupTwo = contentWindow.GroupItems.groupItem(groupTwoId); michael@0: let groupOneTabItemCount = groupOne.getChildren().length; michael@0: let groupTwoTabItemCount = groupTwo.getChildren().length; michael@0: is(groupOneTabItemCount, 1, "GroupItem one has one tab"); michael@0: is(groupTwoTabItemCount, 1, "GroupItem two has one tab as well"); michael@0: michael@0: let tabItem = groupOne.getChild(0); michael@0: ok(tabItem, "The tab item exists"); michael@0: michael@0: // calculate the offsets michael@0: let groupTwoRectCenter = groupTwo.getBounds().center(); michael@0: let tabItemRectCenter = tabItem.getBounds().center(); michael@0: let offsetX = michael@0: Math.round(groupTwoRectCenter.x - tabItemRectCenter.x); michael@0: let offsetY = michael@0: Math.round(groupTwoRectCenter.y - tabItemRectCenter.y); michael@0: michael@0: function endGame() { michael@0: groupTwo.removeSubscriber("childAdded", endGame); michael@0: michael@0: is(groupOne.getChildren().length, --groupOneTabItemCount, michael@0: "The number of children in group one is decreased by 1"); michael@0: is(groupTwo.getChildren().length, ++groupTwoTabItemCount, michael@0: "The number of children in group two is increased by 1"); michael@0: michael@0: closeGroupItem(groupOne, function () { michael@0: closeGroupItem(groupTwo, function () hideTabView(finish)); michael@0: }); michael@0: } michael@0: michael@0: groupTwo.addSubscriber("childAdded", endGame); michael@0: simulateDragDrop(tabItem.container, offsetX, offsetY, contentWindow); michael@0: } michael@0: michael@0: function simulateDragDrop(element, offsetX, offsetY, contentWindow) { michael@0: let rect = element.getBoundingClientRect(); michael@0: let startX = (rect.right - rect.left)/2; michael@0: let startY = (rect.bottom - rect.top)/2; michael@0: let incrementX = offsetX / 2; michael@0: let incrementY = offsetY / 2; michael@0: michael@0: EventUtils.synthesizeMouse( michael@0: element, startX, startY, { type: "mousedown" }); michael@0: michael@0: for (let i = 1; i <= 2; i++) { michael@0: EventUtils.synthesizeMouse( michael@0: element, (startX + incrementX * i), (startY + incrementY * i), michael@0: { type: "mousemove" }); michael@0: } michael@0: michael@0: EventUtils.synthesizeMouse( michael@0: element, (startX + incrementX * 2), (startY + incrementY * 2), michael@0: { type: "mouseup" }); michael@0: }