2011-02-27 17:36:36 -08:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
2010-08-09 02:00:33 -07:00
|
|
|
|
2010-08-04 17:12:08 -07:00
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
2011-08-15 07:03:39 -07:00
|
|
|
showTabView(onTabViewShown);
|
2010-08-09 19:31:59 -07:00
|
|
|
}
|
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
function onTabViewShown() {
|
2010-08-09 19:31:59 -07:00
|
|
|
ok(TabView.isVisible(), "Tab View is visible");
|
2010-08-10 11:39:28 -07:00
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
let contentWindow = TabView.getContentWindow();
|
2010-08-19 00:35:55 -07:00
|
|
|
let [originalTab] = gBrowser.visibleTabs;
|
2010-08-04 17:12:08 -07:00
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
let createGroupItem = function (left, top, width, height) {
|
|
|
|
let box = new contentWindow.Rect(left, top, width, height);
|
|
|
|
let groupItem = new contentWindow.GroupItem([], {bounds: box, immediately: true});
|
2010-08-04 17:12:08 -07:00
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
contentWindow.UI.setActive(groupItem);
|
|
|
|
gBrowser.loadOneTab("about:blank", {inBackground: true});
|
2010-08-04 17:12:08 -07:00
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
return groupItem;
|
2011-08-15 10:48:43 -07:00
|
|
|
};
|
2011-08-15 07:03:39 -07:00
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
// create group one and two
|
|
|
|
let groupOne = createGroupItem(20, 20, 300, 300);
|
|
|
|
let groupTwo = createGroupItem(20, 400, 300, 300);
|
|
|
|
|
|
|
|
waitForFocus(function () {
|
|
|
|
addTest(contentWindow, groupOne.id, groupTwo.id, originalTab);
|
|
|
|
});
|
2010-08-04 17:12:08 -07:00
|
|
|
}
|
|
|
|
|
2010-08-19 00:35:55 -07:00
|
|
|
function addTest(contentWindow, groupOneId, groupTwoId, originalTab) {
|
2010-08-09 00:29:42 -07:00
|
|
|
let groupOne = contentWindow.GroupItems.groupItem(groupOneId);
|
|
|
|
let groupTwo = contentWindow.GroupItems.groupItem(groupTwoId);
|
2010-08-04 17:12:08 -07:00
|
|
|
let groupOneTabItemCount = groupOne.getChildren().length;
|
|
|
|
let groupTwoTabItemCount = groupTwo.getChildren().length;
|
2010-09-08 11:52:07 -07:00
|
|
|
is(groupOneTabItemCount, 1, "GroupItem one has one tab");
|
|
|
|
is(groupTwoTabItemCount, 1, "GroupItem two has one tab as well");
|
2010-08-10 11:39:28 -07:00
|
|
|
|
2010-09-08 11:52:07 -07:00
|
|
|
let tabItem = groupOne.getChild(0);
|
|
|
|
ok(tabItem, "The tab item exists");
|
2010-08-10 11:39:28 -07:00
|
|
|
|
2010-08-04 17:12:08 -07:00
|
|
|
// calculate the offsets
|
2010-10-15 01:16:56 -07:00
|
|
|
let groupTwoRectCenter = groupTwo.getBounds().center();
|
|
|
|
let tabItemRectCenter = tabItem.getBounds().center();
|
2010-08-10 11:39:28 -07:00
|
|
|
let offsetX =
|
2010-09-08 11:52:07 -07:00
|
|
|
Math.round(groupTwoRectCenter.x - tabItemRectCenter.x);
|
2010-08-10 11:39:28 -07:00
|
|
|
let offsetY =
|
2010-09-08 11:52:07 -07:00
|
|
|
Math.round(groupTwoRectCenter.y - tabItemRectCenter.y);
|
2010-08-10 11:39:28 -07:00
|
|
|
|
2010-09-08 11:52:07 -07:00
|
|
|
function endGame() {
|
2011-07-14 10:54:25 -07:00
|
|
|
groupTwo.removeSubscriber("childAdded", endGame);
|
2010-08-10 11:39:28 -07:00
|
|
|
|
2010-09-08 11:52:07 -07:00
|
|
|
is(groupOne.getChildren().length, --groupOneTabItemCount,
|
|
|
|
"The number of children in group one is decreased by 1");
|
|
|
|
is(groupTwo.getChildren().length, ++groupTwoTabItemCount,
|
|
|
|
"The number of children in group two is increased by 1");
|
2011-08-15 07:03:39 -07:00
|
|
|
|
|
|
|
closeGroupItem(groupOne, function () {
|
|
|
|
closeGroupItem(groupTwo, function () hideTabView(finish));
|
2010-09-08 11:52:07 -07:00
|
|
|
});
|
|
|
|
}
|
2011-08-15 07:03:39 -07:00
|
|
|
|
2011-07-14 10:54:25 -07:00
|
|
|
groupTwo.addSubscriber("childAdded", endGame);
|
2010-09-08 11:52:07 -07:00
|
|
|
simulateDragDrop(tabItem.container, offsetX, offsetY, contentWindow);
|
2010-08-04 17:12:08 -07:00
|
|
|
}
|
|
|
|
|
2010-10-15 01:16:56 -07:00
|
|
|
function simulateDragDrop(element, offsetX, offsetY, contentWindow) {
|
|
|
|
let rect = element.getBoundingClientRect();
|
|
|
|
let startX = (rect.right - rect.left)/2;
|
|
|
|
let startY = (rect.bottom - rect.top)/2;
|
|
|
|
let incrementX = offsetX / 2;
|
|
|
|
let incrementY = offsetY / 2;
|
2010-08-04 17:12:08 -07:00
|
|
|
|
|
|
|
EventUtils.synthesizeMouse(
|
2010-10-15 01:16:56 -07:00
|
|
|
element, startX, startY, { type: "mousedown" });
|
2010-09-08 11:52:07 -07:00
|
|
|
|
2010-10-15 01:16:56 -07:00
|
|
|
for (let i = 1; i <= 2; i++) {
|
|
|
|
EventUtils.synthesizeMouse(
|
|
|
|
element, (startX + incrementX * i), (startY + incrementY * i),
|
|
|
|
{ type: "mousemove" });
|
|
|
|
}
|
|
|
|
|
|
|
|
EventUtils.synthesizeMouse(
|
|
|
|
element, (startX + incrementX * 2), (startY + incrementY * 2),
|
|
|
|
{ type: "mouseup" });
|
2010-08-04 17:12:08 -07:00
|
|
|
}
|