1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/file_util.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/view_ids.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/window_proxy.h"
#include "chrome/test/ui/ui_test.h"
#include "gfx/rect.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
#include "views/event.h"
#if defined(OS_CHROMEOS)
// Disabled, see http://crbug.com/40043.
#define MAYBE_Tab2OutOfTabStrip DISABLED_Tab2OutOfTabStrip
#else
#define MAYBE_Tab2OutOfTabStrip Tab2OutOfTabStrip
#endif
#if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
// Disabled on Toolkit views bot. See http://crbug.com/42614
#define MAYBE_Tab1Tab3Escape DISABLED_Tab1Tab3Escape
#else
// Flaky, see http://crbug.com/21092.
#define MAYBE_Tab1Tab3Escape FLAKY_Tab1Tab3Escape
#endif
class TabDraggingTest : public UITest {
protected:
TabDraggingTest() {
show_window_ = true;
}
};
// Automated UI test to open three tabs in a new window, and drag Tab_1 into
// the position of Tab_2.
// Disabled as per http://crbug.com/10941
TEST_F(TabDraggingTest, DISABLED_Tab1Tab2) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
scoped_refptr<WindowProxy> window(browser->GetWindow());
ASSERT_TRUE(window.get());
// Get initial tab count.
int initial_tab_count = 0;
ASSERT_TRUE(browser->GetTabCount(&initial_tab_count));
ASSERT_TRUE(1 == initial_tab_count);
// Get Tab_1 which comes with the browser window.
scoped_refptr<TabProxy> tab1(browser->GetTab(0));
ASSERT_TRUE(tab1.get());
GURL tab1_url;
ASSERT_TRUE(tab1->GetCurrentURL(&tab1_url));
// Add Tab_2.
GURL tab2_url("about:");
ASSERT_TRUE(browser->AppendTab(tab2_url));
scoped_refptr<TabProxy> tab2(browser->GetTab(1));
ASSERT_TRUE(tab2.get());
// Add Tab_3.
GURL tab3_url("about:plugins");
ASSERT_TRUE(browser->AppendTab(tab3_url));
scoped_refptr<TabProxy> tab3(browser->GetTab(2));
ASSERT_TRUE(tab3.get());
// Make sure 3 tabs are open.
ASSERT_TRUE(browser->WaitForTabCountToBecome(initial_tab_count + 2,
10000));
// Get bounds for the tabs.
gfx::Rect bounds1;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_0, &bounds1, false));
EXPECT_LT(0, bounds1.x());
EXPECT_LT(0, bounds1.width());
EXPECT_LT(0, bounds1.height());
gfx::Rect bounds2;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_1, &bounds2, false));
EXPECT_LT(0, bounds2.width());
EXPECT_LT(0, bounds2.height());
EXPECT_LT(bounds1.x(), bounds2.x());
EXPECT_EQ(bounds2.y(), bounds1.y());
gfx::Rect bounds3;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_2, &bounds3, false));
EXPECT_LT(0, bounds3.width());
EXPECT_LT(0, bounds3.height());
EXPECT_LT(bounds2.x(), bounds3.x());
EXPECT_EQ(bounds3.y(), bounds2.y());
// Get url Bar bounds.
gfx::Rect urlbar_bounds;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &urlbar_bounds,
false));
EXPECT_LT(0, urlbar_bounds.x());
EXPECT_LT(0, urlbar_bounds.y());
EXPECT_LT(0, urlbar_bounds.width());
EXPECT_LT(0, urlbar_bounds.height());
/*
TEST: Move Tab_1 to the position of Tab_2
____________ ____________ ____________
/ \ / \ / \
| Tab_1 | Tab_2 | Tab_3 |
---- ---- ---- ---- ---- ---- ---- ---- ----
x---- ---->
____________
/ X \
| Tab_1 |
---- ---- ----
*/
gfx::Point start(bounds1.x() + bounds1.width() / 2,
bounds1.y() + bounds1.height() / 2);
gfx::Point end(start.x() + 2 * bounds1.width() / 3, start.y());
ASSERT_TRUE(browser->SimulateDrag(start, end,
views::Event::EF_LEFT_BUTTON_DOWN,
false));
// Now check for expected results.
tab1 = browser->GetTab(0);
ASSERT_TRUE(tab1.get());
GURL tab1_new_url;
ASSERT_TRUE(tab1->GetCurrentURL(&tab1_new_url));
tab2 = browser->GetTab(1);
ASSERT_TRUE(tab2.get());
GURL tab2_new_url;
ASSERT_TRUE(tab2->GetCurrentURL(&tab2_new_url));
EXPECT_EQ(tab1_url.spec(), tab2_new_url.spec());
EXPECT_EQ(tab2_url.spec(), tab1_new_url.spec());
}
// Drag Tab_1 into the position of Tab_3.
// Disabled as per http://crbug.com/10941
TEST_F(TabDraggingTest, DISABLED_Tab1Tab3) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
scoped_refptr<WindowProxy> window(browser->GetWindow());
ASSERT_TRUE(window.get());
// Get initial tab count.
int initial_tab_count = 0;
ASSERT_TRUE(browser->GetTabCount(&initial_tab_count));
ASSERT_TRUE(1 == initial_tab_count);
// Get Tab_1 which comes with the browser window.
scoped_refptr<TabProxy> tab1(browser->GetTab(0));
ASSERT_TRUE(tab1.get());
GURL tab1_url;
ASSERT_TRUE(tab1->GetCurrentURL(&tab1_url));
// Add Tab_2.
GURL tab2_url("about:");
ASSERT_TRUE(browser->AppendTab(tab2_url));
scoped_refptr<TabProxy> tab2(browser->GetTab(1));
ASSERT_TRUE(tab2.get());
// Add Tab_3.
GURL tab3_url("about:plugins");
ASSERT_TRUE(browser->AppendTab(tab3_url));
scoped_refptr<TabProxy> tab3(browser->GetTab(2));
ASSERT_TRUE(tab3.get());
// Make sure 3 tabs are open.
ASSERT_TRUE(browser->WaitForTabCountToBecome(initial_tab_count + 2,
10000));
// Get bounds for the tabs.
gfx::Rect bounds1;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_0, &bounds1, false));
EXPECT_LT(0, bounds1.x());
EXPECT_LT(0, bounds1.width());
EXPECT_LT(0, bounds1.height());
gfx::Rect bounds2;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_1, &bounds2, false));
EXPECT_LT(0, bounds2.width());
EXPECT_LT(0, bounds2.height());
EXPECT_LT(bounds1.x(), bounds2.x());
EXPECT_EQ(bounds2.y(), bounds1.y());
gfx::Rect bounds3;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_2, &bounds3, false));
EXPECT_LT(0, bounds3.width());
EXPECT_LT(0, bounds3.height());
EXPECT_LT(bounds2.x(), bounds3.x());
EXPECT_EQ(bounds3.y(), bounds2.y());
// Get url Bar bounds.
gfx::Rect urlbar_bounds;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &urlbar_bounds,
false));
EXPECT_LT(0, urlbar_bounds.x());
EXPECT_LT(0, urlbar_bounds.y());
EXPECT_LT(0, urlbar_bounds.width());
EXPECT_LT(0, urlbar_bounds.height());
/*
TEST: Move Tab_1 to the middle position of Tab_3
____________ ____________ ____________
/ \ / \ / \
| Tab_1 | Tab_2 | Tab_3 |
---- ---- ---- ---- ---- ---- ---- ---- ----
x---- ---- ---- ---- ---- ---->
____________
/ X \
| Tab_1 |
---- ---- ----
*/
gfx::Point start(bounds1.x() + bounds1.width() / 2,
bounds1.y() + bounds1.height() / 2);
gfx::Point end(start.x() + bounds1.width() / 2 + bounds2.width() +
bounds3.width() / 2,
start.y());
ASSERT_TRUE(browser->SimulateDrag(start, end,
views::Event::EF_LEFT_BUTTON_DOWN,
false));
// Now check for expected results.
tab1 = browser->GetTab(0);
ASSERT_TRUE(tab1.get());
GURL tab1_new_url;
ASSERT_TRUE(tab1->GetCurrentURL(&tab1_new_url));
tab2 = browser->GetTab(1);
ASSERT_TRUE(tab2.get());
GURL tab2_new_url;
ASSERT_TRUE(tab2->GetCurrentURL(&tab2_new_url));
tab3 = browser->GetTab(2);
ASSERT_TRUE(tab3.get());
GURL tab3_new_url;
ASSERT_TRUE(tab3->GetCurrentURL(&tab3_new_url));
EXPECT_EQ(tab1_new_url.spec(), tab2_url.spec());
EXPECT_EQ(tab2_new_url.spec(), tab3_url.spec());
EXPECT_EQ(tab3_new_url.spec(), tab1_url.spec());
}
// Drag Tab_1 into the position of Tab_3, and press ESCAPE before releasing the
// left mouse button.
TEST_F(TabDraggingTest, MAYBE_Tab1Tab3Escape) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
scoped_refptr<WindowProxy> window(browser->GetWindow());
ASSERT_TRUE(window.get());
// Get initial tab count.
int initial_tab_count = 0;
ASSERT_TRUE(browser->GetTabCount(&initial_tab_count));
ASSERT_TRUE(1 == initial_tab_count);
// Get Tab_1 which comes with the browser window.
scoped_refptr<TabProxy> tab1(browser->GetTab(0));
ASSERT_TRUE(tab1.get());
GURL tab1_url;
ASSERT_TRUE(tab1->GetCurrentURL(&tab1_url));
// Add Tab_2.
GURL tab2_url("about:");
ASSERT_TRUE(browser->AppendTab(tab2_url));
scoped_refptr<TabProxy> tab2(browser->GetTab(1));
ASSERT_TRUE(tab2.get());
// Add Tab_3.
GURL tab3_url("about:plugins");
ASSERT_TRUE(browser->AppendTab(tab3_url));
scoped_refptr<TabProxy> tab3(browser->GetTab(2));
ASSERT_TRUE(tab3.get());
// Make sure 3 tabs are open.
ASSERT_TRUE(browser->WaitForTabCountToBecome(initial_tab_count + 2,
10000));
// Get bounds for the tabs.
gfx::Rect bounds1;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_0, &bounds1, false));
EXPECT_LT(0, bounds1.x());
EXPECT_LT(0, bounds1.width());
EXPECT_LT(0, bounds1.height());
gfx::Rect bounds2;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_1, &bounds2, false));
EXPECT_LT(0, bounds2.width());
EXPECT_LT(0, bounds2.height());
EXPECT_LT(bounds1.x(), bounds2.x());
EXPECT_EQ(bounds2.y(), bounds1.y());
gfx::Rect bounds3;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_2, &bounds3, false));
EXPECT_LT(0, bounds3.width());
EXPECT_LT(0, bounds3.height());
EXPECT_LT(bounds2.x(), bounds3.x());
EXPECT_EQ(bounds3.y(), bounds2.y());
// Get url Bar bounds.
gfx::Rect urlbar_bounds;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &urlbar_bounds,
false));
EXPECT_LT(0, urlbar_bounds.x());
EXPECT_LT(0, urlbar_bounds.y());
EXPECT_LT(0, urlbar_bounds.width());
EXPECT_LT(0, urlbar_bounds.height());
/*
TEST: Move Tab_1 to the middle position of Tab_3
____________ ____________ ____________
/ \ / \ / \
| Tab_1 | Tab_2 | Tab_3 |
---- ---- ---- ---- ---- ---- ---- ---- ----
x---- ---- ---- ---- ---- ----> + ESCAPE
____________
/ X \
| Tab_1 |
---- ---- ----
*/
gfx::Point start(bounds1.x() + bounds1.width() / 2,
bounds1.y() + bounds1.height() / 2);
gfx::Point end(start.x() + bounds1.width() / 2 + bounds2.width() +
bounds3.width() / 2,
start.y());
// Simulate drag with 'true' as the last parameter. This will interrupt
// in-flight with Escape.
ASSERT_TRUE(browser->SimulateDrag(start, end,
views::Event::EF_LEFT_BUTTON_DOWN,
true));
// Now check for expected results.
tab1 = browser->GetTab(0);
ASSERT_TRUE(tab1.get());
GURL tab1_new_url;
ASSERT_TRUE(tab1->GetCurrentURL(&tab1_new_url));
tab2 = browser->GetTab(1);
ASSERT_TRUE(tab2.get());
GURL tab2_new_url;
ASSERT_TRUE(tab2->GetCurrentURL(&tab2_new_url));
tab3 = browser->GetTab(2);
ASSERT_TRUE(tab3.get());
GURL tab3_new_url;
ASSERT_TRUE(tab3->GetCurrentURL(&tab3_new_url));
// The tabs should be in their original positions.
EXPECT_EQ(tab1_new_url.spec(), tab1_url.spec());
EXPECT_EQ(tab2_new_url.spec(), tab2_url.spec());
EXPECT_EQ(tab3_new_url.spec(), tab3_url.spec());
}
// Drag Tab_2 out of the Tab strip. A new window should open with this tab.
TEST_F(TabDraggingTest, MAYBE_Tab2OutOfTabStrip) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
scoped_refptr<WindowProxy> window(browser->GetWindow());
ASSERT_TRUE(window.get());
// Get initial tab count.
int initial_tab_count = 0;
ASSERT_TRUE(browser->GetTabCount(&initial_tab_count));
ASSERT_TRUE(1 == initial_tab_count);
// Get Tab_1 which comes with the browser window.
scoped_refptr<TabProxy> tab1(browser->GetTab(0));
ASSERT_TRUE(tab1.get());
GURL tab1_url;
ASSERT_TRUE(tab1->GetCurrentURL(&tab1_url));
// Add Tab_2.
GURL tab2_url("about:version");
ASSERT_TRUE(browser->AppendTab(tab2_url));
scoped_refptr<TabProxy> tab2(browser->GetTab(1));
ASSERT_TRUE(tab2.get());
// Add Tab_3.
GURL tab3_url("about:plugins");
ASSERT_TRUE(browser->AppendTab(tab3_url));
scoped_refptr<TabProxy> tab3(browser->GetTab(2));
ASSERT_TRUE(tab3.get());
// Make sure 3 tabs are opened.
ASSERT_TRUE(browser->WaitForTabCountToBecome(initial_tab_count + 2,
10000));
// Make sure all the tab URL specs are different.
ASSERT_TRUE(tab1_url != tab2_url);
ASSERT_TRUE(tab1_url != tab3_url);
ASSERT_TRUE(tab2_url != tab3_url);
// Get bounds for the tabs.
gfx::Rect bounds1;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_0, &bounds1, false));
EXPECT_LT(0, bounds1.x());
EXPECT_LT(0, bounds1.width());
EXPECT_LT(0, bounds1.height());
gfx::Rect bounds2;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_1, &bounds2, false));
EXPECT_LT(0, bounds2.width());
EXPECT_LT(0, bounds2.height());
EXPECT_LT(bounds1.x(), bounds2.x());
EXPECT_EQ(bounds2.y(), bounds1.y());
gfx::Rect bounds3;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_2, &bounds3, false));
EXPECT_LT(0, bounds3.width());
EXPECT_LT(0, bounds3.height());
EXPECT_LT(bounds2.x(), bounds3.x());
EXPECT_EQ(bounds3.y(), bounds2.y());
// Get url Bar bounds.
gfx::Rect urlbar_bounds;
ASSERT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &urlbar_bounds,
false));
EXPECT_LT(0, urlbar_bounds.x());
EXPECT_LT(0, urlbar_bounds.y());
EXPECT_LT(0, urlbar_bounds.width());
EXPECT_LT(0, urlbar_bounds.height());
/*
TEST: Move Tab_2 down, out of the tab strip.
This should result in the following:
1- Tab_3 shift left in place of Tab_2 in Window 1
2- Tab_1 to remain in its place
3- Tab_2 openes in a new window
____________ ____________ ____________
/ \ / \ / \
| Tab_1 | Tab_2 | Tab_3 |
---- ---- ---- ---- ---- ---- ---- ---- ----
x
|
| (Drag this below, out of tab strip)
V
____________
/ X \
| Tab_2 | (New Window)
---- ---- ---- ---- ---- ---- ----
*/
gfx::Point start(bounds2.x() + bounds2.width() / 2,
bounds2.y() + bounds2.height() / 2);
gfx::Point end(start.x(),
start.y() + 3 * urlbar_bounds.height());
// Simulate tab drag.
ASSERT_TRUE(browser->SimulateDrag(start, end,
views::Event::EF_LEFT_BUTTON_DOWN,
false));
// Now, first make sure that the old window has only two tabs remaining.
int new_tab_count = 0;
ASSERT_TRUE(browser->GetTabCount(&new_tab_count));
ASSERT_EQ(2, new_tab_count);
// Get the two tabs - they are called Tab_1 and Tab_2 in the old window.
tab1 = browser->GetTab(0);
ASSERT_TRUE(tab1.get());
GURL tab1_new_url;
ASSERT_TRUE(tab1->GetCurrentURL(&tab1_new_url));
tab2 = browser->GetTab(1);
ASSERT_TRUE(tab2.get());
GURL tab2_new_url;
ASSERT_TRUE(tab2->GetCurrentURL(&tab2_new_url));
// Now check for proper shifting of tabs; i.e., Tab_3 in window 1 should
// shift left to the position of Tab_2; Tab_1 should stay where it was.
EXPECT_EQ(tab1_new_url.spec(), tab1_url.spec());
EXPECT_EQ(tab2_new_url.spec(), tab3_url.spec());
// Now check to make sure a new window has opened.
scoped_refptr<BrowserProxy> browser2(automation()->GetBrowserWindow(1));
ASSERT_TRUE(browser2.get());
scoped_refptr<WindowProxy> window2(browser2->GetWindow());
ASSERT_TRUE(window2.get());
// Make sure that the new window has only one tab.
int tab_count_window_2 = 0;
ASSERT_TRUE(browser2->GetTabCount(&tab_count_window_2));
ASSERT_EQ(1, tab_count_window_2);
// Get Tab_1_2 which should be Tab_1 in Window 2.
scoped_refptr<TabProxy> tab1_2(browser2->GetTab(0));
ASSERT_TRUE(tab1_2.get());
GURL tab1_2_url;
ASSERT_TRUE(tab1_2->GetCurrentURL(&tab1_2_url));
// Tab_1_2 of Window 2 should essentially be Tab_2 of Window 1.
EXPECT_EQ(tab1_2_url.spec(), tab2_url.spec());
EXPECT_NE(tab1_2_url.spec(), tab1_url.spec());
EXPECT_NE(tab1_2_url.spec(), tab3_url.spec());
}
|