Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 function test() {
5 waitForExplicitFinish();
6 showTabView(onTabViewShown);
7 }
9 function onTabViewShown() {
10 ok(TabView.isVisible(), "Tab View is visible");
12 let contentWindow = TabView.getContentWindow();
13 let [originalTab] = gBrowser.visibleTabs;
15 let createGroupItem = function (left, top, width, height) {
16 let box = new contentWindow.Rect(left, top, width, height);
17 let groupItem = new contentWindow.GroupItem([], {bounds: box, immediately: true});
19 contentWindow.UI.setActive(groupItem);
20 gBrowser.loadOneTab("about:blank", {inBackground: true});
22 return groupItem;
23 };
25 // create group one and two
26 let groupOne = createGroupItem(20, 20, 300, 300);
27 let groupTwo = createGroupItem(20, 400, 300, 300);
29 waitForFocus(function () {
30 addTest(contentWindow, groupOne.id, groupTwo.id, originalTab);
31 });
32 }
34 function addTest(contentWindow, groupOneId, groupTwoId, originalTab) {
35 let groupOne = contentWindow.GroupItems.groupItem(groupOneId);
36 let groupTwo = contentWindow.GroupItems.groupItem(groupTwoId);
37 let groupOneTabItemCount = groupOne.getChildren().length;
38 let groupTwoTabItemCount = groupTwo.getChildren().length;
39 is(groupOneTabItemCount, 1, "GroupItem one has one tab");
40 is(groupTwoTabItemCount, 1, "GroupItem two has one tab as well");
42 let tabItem = groupOne.getChild(0);
43 ok(tabItem, "The tab item exists");
45 // calculate the offsets
46 let groupTwoRectCenter = groupTwo.getBounds().center();
47 let tabItemRectCenter = tabItem.getBounds().center();
48 let offsetX =
49 Math.round(groupTwoRectCenter.x - tabItemRectCenter.x);
50 let offsetY =
51 Math.round(groupTwoRectCenter.y - tabItemRectCenter.y);
53 function endGame() {
54 groupTwo.removeSubscriber("childAdded", endGame);
56 is(groupOne.getChildren().length, --groupOneTabItemCount,
57 "The number of children in group one is decreased by 1");
58 is(groupTwo.getChildren().length, ++groupTwoTabItemCount,
59 "The number of children in group two is increased by 1");
61 closeGroupItem(groupOne, function () {
62 closeGroupItem(groupTwo, function () hideTabView(finish));
63 });
64 }
66 groupTwo.addSubscriber("childAdded", endGame);
67 simulateDragDrop(tabItem.container, offsetX, offsetY, contentWindow);
68 }
70 function simulateDragDrop(element, offsetX, offsetY, contentWindow) {
71 let rect = element.getBoundingClientRect();
72 let startX = (rect.right - rect.left)/2;
73 let startY = (rect.bottom - rect.top)/2;
74 let incrementX = offsetX / 2;
75 let incrementY = offsetY / 2;
77 EventUtils.synthesizeMouse(
78 element, startX, startY, { type: "mousedown" });
80 for (let i = 1; i <= 2; i++) {
81 EventUtils.synthesizeMouse(
82 element, (startX + incrementX * i), (startY + incrementY * i),
83 { type: "mousemove" });
84 }
86 EventUtils.synthesizeMouse(
87 element, (startX + incrementX * 2), (startY + incrementY * 2),
88 { type: "mouseup" });
89 }