browser/components/tabview/test/browser_tabview_bug587503.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:4b6029174181
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 function test() {
5 waitForExplicitFinish();
6
7 function moveTabOutOfGroup(aTab, aGroup, aCW, aCallback) {
8 let tabPos = aTab.getBounds().center();
9 let groupPos = aGroup.getBounds();
10 let groupPosX = (groupPos.left + groupPos.right) / 2;
11 let groupPosY = groupPos.bottom + 200;
12 let offsetX = Math.round(groupPosX - tabPos.x);
13 let offsetY = Math.round(groupPosY - tabPos.y);
14
15 simulateDragDrop(aTab, offsetX, offsetY, aCW);
16 }
17
18 function moveTabInGroup(aTab, aIndexTo, aGroup, aCW) {
19 let tabTo = aGroup.getChild(aIndexTo);
20 let tabPos = aTab.getBounds().center();
21 let tabToPos = tabTo.getBounds().center();
22 let offsetX = Math.round(tabToPos.x - tabPos.x);
23 let offsetY = Math.round(tabToPos.y - tabPos.y);
24
25 simulateDragDrop(aTab, offsetX, offsetY, aCW);
26 }
27
28 function getTabNumbers(aGroup) {
29 return aGroup.getChildren().map(function (child) {
30 let url = child.tab.linkedBrowser.currentURI.spec;
31 return url.replace("about:blank#", "");
32 }).join(",");
33 }
34
35 function moveTabs(aGroup, aCW) {
36 // Test 1: Move the last tab to the third position.
37 let tab = aGroup.getChild(6);
38 moveTabInGroup(tab, 2, aGroup, aCW);
39 is(getTabNumbers(aGroup), "0,1,6,2,3,4,5", "Validate tab positions in test 1.");
40
41 // Test 2: Move the second tab to the end of the list.
42 tab = aGroup.getChild(1);
43 moveTabInGroup(tab, 6, aGroup, aCW);
44 is(getTabNumbers(aGroup), "0,6,2,3,4,5,1", "Validate tab positions in test 2.");
45
46 // Test 3: Move the fifth tab outside the group.
47 tab = aGroup.getChild(4);
48 moveTabOutOfGroup(tab, aGroup, aCW);
49 is(getTabNumbers(aGroup), "0,6,2,3,5,1", "Validate tab positions in test 3.");
50 is(aCW.GroupItems.groupItems.length, 3, "Validate group count in test 3.");
51
52 // This test is disabled because it is fragile -- see bug 797975
53 if (false) {
54 // Test 4: Move the fifth tab back into the group, on the second row.
55 waitForTransition(tab, function() {
56 moveTabInGroup(tab, 4, aGroup, aCW);
57 is(getTabNumbers(aGroup), "0,6,2,3,4,5,1", "Validate tab positions in test 4.");
58 is(aCW.GroupItems.groupItems.length, 2, "Validate group count in test 4.");
59 closeGroupItem(aGroup, function() { hideTabView(finish) });
60 });
61 } else {
62 closeGroupItem(aGroup, function() { hideTabView(finish) });
63 }
64 }
65
66 function createGroup(win) {
67 registerCleanupFunction(function() win.close());
68 let cw = win.TabView.getContentWindow();
69 let group = createGroupItemWithTabs(win, 400, 430, 100, [
70 "about:blank#0", "about:blank#1", "about:blank#2", "about:blank#3",
71 "about:blank#4", "about:blank#5", "about:blank#6"
72 ]);
73 let groupSize = group.getChildren().length;
74
75 is(cw.GroupItems.groupItems.length, 2, "Validate group count in tab view.");
76 ok(!group.shouldStack(groupSize), "Check that group should not stack.");
77 is(group._columns, 3, "Check the there should be three columns.");
78
79 moveTabs(group, cw);
80 }
81
82 newWindowWithTabView(createGroup);
83 }
84
85 function simulateDragDrop(aTab, aOffsetX, aOffsetY, aCW) {
86 let target = aTab.container;
87 let rect = target.getBoundingClientRect();
88 let startX = (rect.right - rect.left) / 2;
89 let startY = (rect.bottom - rect.top) / 2;
90 let steps = 2;
91 let incrementX = aOffsetX / steps;
92 let incrementY = aOffsetY / steps;
93
94 EventUtils.synthesizeMouse(
95 target, startX, startY, { type: "mousedown" }, aCW);
96 for (let i = 1; i <= steps; i++) {
97 EventUtils.synthesizeMouse(
98 target, incrementX + startX, incrementY + startY,
99 { type: "mousemove" }, aCW);
100 };
101 EventUtils.synthesizeMouseAtCenter(target, { type: "mouseup" }, aCW);
102 }
103
104 function waitForTransition(aTab, aCallback) {
105 let groupContainer = aTab.parent.container;
106 groupContainer.addEventListener("transitionend", function onTransitionEnd(aEvent) {
107 if (aEvent.target == groupContainer) {
108 groupContainer.removeEventListener("transitionend", onTransitionEnd);
109 executeSoon(aCallback);
110 }
111 });
112 }

mercurial