|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 waitForExplicitFinish(); |
|
6 showTabView(onTabViewShown); |
|
7 } |
|
8 |
|
9 function onTabViewShown() { |
|
10 ok(TabView.isVisible(), "Tab View is visible"); |
|
11 |
|
12 let contentWindow = TabView.getContentWindow(); |
|
13 let [originalTab] = gBrowser.visibleTabs; |
|
14 |
|
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}); |
|
18 |
|
19 contentWindow.UI.setActive(groupItem); |
|
20 gBrowser.loadOneTab("about:blank", {inBackground: true}); |
|
21 |
|
22 return groupItem; |
|
23 }; |
|
24 |
|
25 // create group one and two |
|
26 let groupOne = createGroupItem(20, 20, 300, 300); |
|
27 let groupTwo = createGroupItem(20, 400, 300, 300); |
|
28 |
|
29 waitForFocus(function () { |
|
30 addTest(contentWindow, groupOne.id, groupTwo.id, originalTab); |
|
31 }); |
|
32 } |
|
33 |
|
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"); |
|
41 |
|
42 let tabItem = groupOne.getChild(0); |
|
43 ok(tabItem, "The tab item exists"); |
|
44 |
|
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); |
|
52 |
|
53 function endGame() { |
|
54 groupTwo.removeSubscriber("childAdded", endGame); |
|
55 |
|
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"); |
|
60 |
|
61 closeGroupItem(groupOne, function () { |
|
62 closeGroupItem(groupTwo, function () hideTabView(finish)); |
|
63 }); |
|
64 } |
|
65 |
|
66 groupTwo.addSubscriber("childAdded", endGame); |
|
67 simulateDragDrop(tabItem.container, offsetX, offsetY, contentWindow); |
|
68 } |
|
69 |
|
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; |
|
76 |
|
77 EventUtils.synthesizeMouse( |
|
78 element, startX, startY, { type: "mousedown" }); |
|
79 |
|
80 for (let i = 1; i <= 2; i++) { |
|
81 EventUtils.synthesizeMouse( |
|
82 element, (startX + incrementX * i), (startY + incrementY * i), |
|
83 { type: "mousemove" }); |
|
84 } |
|
85 |
|
86 EventUtils.synthesizeMouse( |
|
87 element, (startX + incrementX * 2), (startY + incrementY * 2), |
|
88 { type: "mouseup" }); |
|
89 } |