browser/components/tabview/test/browser_tabview_bug626791.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:8f8170d77087
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 Cu.import("resource:///modules/CustomizableUI.jsm");
5
6
7 function test() {
8 let cw;
9 let win;
10 let prefix;
11
12 let getToolbar = function () {
13 return win.document.getElementById("TabsToolbar");
14 }
15
16 let assertToolbarButtonExists = function () {
17 isnot(getToolbar().currentSet.indexOf("tabview-button"), -1,
18 prefix + ": panorama button should be in the toolbar");
19 }
20
21 let assertToolbarButtonNotExists = function () {
22 is(getToolbar().currentSet.indexOf("tabview-button"), -1,
23 prefix + ": panorama button should not be in the toolbar");
24 }
25
26 let assertNumberOfTabs = function (num) {
27 is(win.gBrowser.tabs.length, num, prefix + ': there are ' + num + ' tabs');
28 }
29
30 let removeToolbarButton = function () {
31 let toolbar = getToolbar();
32 let currentSet = toolbar.currentSet.split(",");
33 let buttonId = "tabview-button";
34 let pos = currentSet.indexOf(buttonId);
35
36 if (-1 < pos) {
37 CustomizableUI.removeWidgetFromArea("tabview-button");
38 }
39 }
40
41 let testNameGroup = function () {
42 prefix = 'name-group';
43 assertToolbarButtonNotExists();
44 let groupItem = cw.GroupItems.groupItems[0];
45
46 groupItem.setTitle('title');
47 assertToolbarButtonNotExists();
48 groupItem.setTitle('');
49
50 EventUtils.synthesizeMouseAtCenter(groupItem.$titleShield[0], {}, cw);
51 EventUtils.synthesizeKey('t', {}, cw);
52 groupItem.$title[0].blur();
53
54 assertToolbarButtonExists();
55 next();
56 }
57
58 let testDragToCreateGroup = function () {
59 prefix = 'drag-to-create-group';
60 assertToolbarButtonNotExists();
61 let width = cw.innerWidth;
62 let height = cw.innerHeight;
63
64 let body = cw.document.body;
65 EventUtils.synthesizeMouse(body, width - 10, height - 10, {type: 'mousedown'}, cw);
66 EventUtils.synthesizeMouse(body, width - 200, height - 200, {type: 'mousemove'}, cw);
67 EventUtils.synthesizeMouse(body, width - 200, height - 200, {type: 'mouseup'}, cw);
68
69 assertToolbarButtonExists();
70 next();
71 }
72
73 let testCreateOrphan = function (tab) {
74 prefix = 'create-orphan';
75 assertNumberOfTabs(1);
76 assertToolbarButtonNotExists();
77
78 let width = cw.innerWidth;
79 let height = cw.innerHeight;
80
81 let body = cw.document.body;
82 EventUtils.synthesizeMouse(body, width - 10, height - 10, { clickCount: 2 }, cw);
83
84 whenTabViewIsHidden(function () {
85 assertNumberOfTabs(2);
86 assertToolbarButtonExists();
87
88 next();
89 }, win);
90 }
91
92 let testDragToCreateOrphan = function (tab) {
93 if (!tab) {
94 let tab = win.gBrowser.loadOneTab('about:blank', {inBackground: true});
95 afterAllTabsLoaded(function () testDragToCreateOrphan(tab), win);
96 return;
97 }
98
99 prefix = 'drag-to-create-orphan';
100 assertNumberOfTabs(2);
101 assertToolbarButtonNotExists();
102
103 let width = cw.innerWidth;
104 let height = cw.innerHeight;
105
106 let target = tab._tabViewTabItem.container;
107 let rect = target.getBoundingClientRect();
108 EventUtils.synthesizeMouseAtCenter(target, {type: 'mousedown'}, cw);
109 EventUtils.synthesizeMouse(target, rect.width - 10, rect.height - 10, {type: 'mousemove'}, cw);
110 EventUtils.synthesizeMouse(target, width - 300, height - 300, {type: 'mousemove'}, cw);
111 EventUtils.synthesizeMouse(target, width - 200, height - 200, {type: 'mousemove'}, cw);
112 EventUtils.synthesizeMouseAtCenter(target, {type: 'mouseup'}, cw);
113
114 assertToolbarButtonExists();
115 next();
116 }
117
118 let testReAddingAfterRemoval = function () {
119 prefix = 're-adding-after-removal';
120 assertToolbarButtonNotExists();
121
122 win.TabView.firstUseExperienced = true;
123 assertToolbarButtonExists();
124 removeToolbarButton();
125 assertToolbarButtonNotExists();
126
127 win.close();
128
129 newWindowWithTabView(function (newWin) {
130 win = newWin;
131 win.TabView.firstUseExperienced = true;
132 assertToolbarButtonNotExists();
133 next();
134 });
135 }
136
137 let tests = [testNameGroup, testDragToCreateGroup, testCreateOrphan,
138 testDragToCreateOrphan, testReAddingAfterRemoval];
139
140 let next = function () {
141 if (win)
142 win.close();
143
144 let test = tests.shift();
145
146 if (!test) {
147 finish();
148 return;
149 }
150
151 TabView.firstUseExperienced = false;
152
153 let onLoad = function (newWin) {
154 win = newWin;
155 removeToolbarButton();
156 };
157
158 let onShow = function () {
159 cw = win.TabView.getContentWindow();
160
161 let groupItem = cw.GroupItems.groupItems[0];
162 groupItem.setSize(200, 200, true);
163 groupItem.setUserSize();
164
165 SimpleTest.waitForFocus(function () {
166 assertToolbarButtonNotExists();
167 test();
168 }, cw);
169 };
170
171 newWindowWithTabView(onShow, onLoad);
172 }
173
174 waitForExplicitFinish();
175 requestLongerTimeout(2);
176
177 next();
178 }

mercurial