2010-08-09 02:00:33 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is tabview drag and drop test.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Raymond Lee <raymond@appcoast.com>
|
2010-09-08 11:52:07 -07:00
|
|
|
* Michael Yoshitaka Erlewine <mitcho@mitcho.com>
|
2010-08-09 02:00:33 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2010-08-04 17:12:08 -07:00
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
2010-08-09 19:31:59 -07:00
|
|
|
window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
|
2010-09-07 16:23:29 -07:00
|
|
|
TabView.toggle();
|
2010-08-09 19:31:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function onTabViewWindowLoaded() {
|
|
|
|
window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
|
|
|
|
|
|
|
|
ok(TabView.isVisible(), "Tab View is visible");
|
2010-08-10 11:39:28 -07:00
|
|
|
|
2010-08-04 17:12:08 -07:00
|
|
|
let contentWindow = document.getElementById("tab-view").contentWindow;
|
2010-08-19 00:35:55 -07:00
|
|
|
let [originalTab] = gBrowser.visibleTabs;
|
2010-08-04 17:12:08 -07:00
|
|
|
|
|
|
|
// create group one and two
|
2010-09-08 11:52:07 -07:00
|
|
|
let boxOne = new contentWindow.Rect(20, 20, 300, 300);
|
|
|
|
let groupOne = new contentWindow.GroupItem([], { bounds: boxOne });
|
2010-08-04 17:12:08 -07:00
|
|
|
ok(groupOne.isEmpty(), "This group is empty");
|
|
|
|
|
2010-09-08 11:52:07 -07:00
|
|
|
let boxTwo = new contentWindow.Rect(20, 400, 300, 300);
|
|
|
|
let groupTwo = new contentWindow.GroupItem([], { bounds: boxTwo });
|
2010-08-04 17:12:08 -07:00
|
|
|
|
2010-09-08 11:52:07 -07:00
|
|
|
groupOne.addSubscriber(groupOne, "childAdded", function() {
|
|
|
|
groupOne.removeSubscriber(groupOne, "childAdded");
|
2010-08-19 00:35:55 -07:00
|
|
|
groupTwo.newTab();
|
2010-08-04 17:12:08 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
let count = 0;
|
2010-08-19 00:35:55 -07:00
|
|
|
let onTabViewShown = function() {
|
|
|
|
if (count == 2) {
|
|
|
|
window.removeEventListener("tabviewshown", onTabViewShown, false);
|
|
|
|
addTest(contentWindow, groupOne.id, groupTwo.id, originalTab);
|
|
|
|
}
|
|
|
|
};
|
2010-08-04 17:12:08 -07:00
|
|
|
let onTabViewHidden = function() {
|
|
|
|
TabView.toggle();
|
2010-08-19 00:35:55 -07:00
|
|
|
if (++count == 2)
|
2010-08-04 17:12:08 -07:00
|
|
|
window.removeEventListener("tabviewhidden", onTabViewHidden, false);
|
|
|
|
};
|
2010-08-19 00:35:55 -07:00
|
|
|
window.addEventListener("tabviewshown", onTabViewShown, false);
|
2010-08-04 17:12:08 -07:00
|
|
|
window.addEventListener("tabviewhidden", onTabViewHidden, false);
|
|
|
|
|
|
|
|
// open tab in group
|
2010-08-19 00:35:55 -07:00
|
|
|
groupOne.newTab();
|
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() {
|
|
|
|
groupTwo.removeSubscriber(groupTwo, "childAdded");
|
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");
|
|
|
|
|
|
|
|
let onTabViewHidden = function() {
|
|
|
|
window.removeEventListener("tabviewhidden", onTabViewHidden, false);
|
2010-09-10 07:40:27 -07:00
|
|
|
groupTwo.closeAll();
|
|
|
|
// close undo group
|
|
|
|
let closeButton = groupTwo.$undoContainer.find(".close");
|
|
|
|
EventUtils.sendMouseEvent(
|
|
|
|
{ type: "click" }, closeButton[0], contentWindow);
|
2010-09-08 11:52:07 -07:00
|
|
|
};
|
|
|
|
groupTwo.addSubscriber(groupTwo, "close", function() {
|
|
|
|
groupTwo.removeSubscriber(groupTwo, "close");
|
|
|
|
finish();
|
|
|
|
});
|
|
|
|
window.addEventListener("tabviewhidden", onTabViewHidden, false);
|
|
|
|
gBrowser.selectedTab = originalTab;
|
|
|
|
}
|
|
|
|
groupTwo.addSubscriber(groupTwo, "childAdded", endGame);
|
|
|
|
|
|
|
|
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
|
|
|
}
|