Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc

Issue 10824200: Handful of tweaks for tab dragging with touch: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.h" 5 #include "chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/property_bag.h" 10 #include "base/property_bag.h"
11 #include "base/run_loop.h"
11 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h" 14 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents.h" 15 #include "chrome/browser/ui/tab_contents/tab_contents.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/browser/ui/views/frame/browser_view.h" 17 #include "chrome/browser/ui/views/frame/browser_view.h"
17 #include "chrome/browser/ui/views/tabs/tab.h" 18 #include "chrome/browser/ui/views/tabs/tab.h"
18 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h" 19 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h"
19 #include "chrome/browser/ui/views/tabs/tab_strip.h" 20 #include "chrome/browser/ui/views/tabs/tab_strip.h"
20 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
21 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
22 #include "chrome/test/base/in_process_browser_test.h" 23 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chrome/test/base/ui_test_utils.h" 24 #include "chrome/test/base/ui_test_utils.h"
24 #include "content/public/browser/notification_details.h" 25 #include "content/public/browser/notification_details.h"
25 #include "content/public/browser/notification_observer.h" 26 #include "content/public/browser/notification_observer.h"
26 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_source.h" 28 #include "content/public/browser/notification_source.h"
28 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
29 #include "ui/gfx/screen.h" 30 #include "ui/gfx/screen.h"
30 #include "ui/ui_controls/ui_controls.h" 31 #include "ui/ui_controls/ui_controls.h"
31 #include "ui/views/view.h" 32 #include "ui/views/view.h"
32 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
33 34
35 #if defined(USE_ASH)
36 #include "ash/shell.h"
37 #include "ui/aura/test/event_generator.h"
38 #endif
39
34 namespace test { 40 namespace test {
35 41
36 class QuitDraggingObserver : public content::NotificationObserver { 42 class QuitDraggingObserver : public content::NotificationObserver {
37 public: 43 public:
38 QuitDraggingObserver() { 44 QuitDraggingObserver() {
39 registrar_.Add(this, chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE, 45 registrar_.Add(this, chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE,
40 content::NotificationService::AllSources()); 46 content::NotificationService::AllSources());
41 } 47 }
42 48
43 virtual void Observe(int type, 49 virtual void Observe(int type,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 model->GetTabContentsAt(i)->web_contents()->GetPropertyBag()); 93 model->GetTabContentsAt(i)->web_contents()->GetPropertyBag());
88 if (id_value) 94 if (id_value)
89 result += base::IntToString(*id_value); 95 result += base::IntToString(*id_value);
90 else 96 else
91 result += "?"; 97 result += "?";
92 } 98 }
93 return result; 99 return result;
94 } 100 }
95 101
96 // Creates a listener that quits the message loop when no longer dragging. 102 // Creates a listener that quits the message loop when no longer dragging.
97 void QuitWhenNotDragging() { 103 void QuitWhenNotDraggingImpl() {
98 new QuitDraggingObserver(); // QuitDraggingObserver deletes itself. 104 new QuitDraggingObserver(); // QuitDraggingObserver deletes itself.
99 } 105 }
100 106
101 TabStrip* GetTabStripForBrowser(Browser* browser) { 107 TabStrip* GetTabStripForBrowser(Browser* browser) {
102 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 108 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
103 return static_cast<TabStrip*>(browser_view->tabstrip()); 109 return static_cast<TabStrip*>(browser_view->tabstrip());
104 } 110 }
105 111
106 } // namespace test 112 } // namespace test
107 113
108 using test::GetCenterInScreenCoordinates; 114 using test::GetCenterInScreenCoordinates;
109 using test::SetID; 115 using test::SetID;
110 using test::ResetIDs; 116 using test::ResetIDs;
111 using test::IDString; 117 using test::IDString;
112 using test::QuitWhenNotDragging;
113 using test::GetTabStripForBrowser; 118 using test::GetTabStripForBrowser;
114 119
115 TabDragControllerTest::TabDragControllerTest() { 120 TabDragControllerTest::TabDragControllerTest() {
116 } 121 }
117 122
118 TabDragControllerTest::~TabDragControllerTest() { 123 TabDragControllerTest::~TabDragControllerTest() {
119 } 124 }
120 125
121 void TabDragControllerTest::StopAnimating(TabStrip* tab_strip) { 126 void TabDragControllerTest::StopAnimating(TabStrip* tab_strip) {
122 tab_strip->StopAnimating(true); 127 tab_strip->StopAnimating(true);
123 } 128 }
124 129
125 void TabDragControllerTest::AddTabAndResetBrowser(Browser* browser) { 130 void TabDragControllerTest::AddTabAndResetBrowser(Browser* browser) {
126 AddBlankTabAndShow(browser); 131 AddBlankTabAndShow(browser);
127 StopAnimating(GetTabStripForBrowser(browser)); 132 StopAnimating(GetTabStripForBrowser(browser));
128 ResetIDs(browser->tab_strip_model(), 0); 133 ResetIDs(browser->tab_strip_model(), 0);
129 } 134 }
130 135
131 Browser* TabDragControllerTest::CreateAnotherWindowBrowserAndRelayout() { 136 Browser* TabDragControllerTest::CreateAnotherWindowBrowserAndRelayout() {
132 // Add another tab.
133 AddTabAndResetBrowser(browser());
134
135 // Create another browser. 137 // Create another browser.
136 Browser* browser2 = CreateBrowser(browser()->profile()); 138 Browser* browser2 = CreateBrowser(browser()->profile());
137 ResetIDs(browser2->tab_strip_model(), 100); 139 ResetIDs(browser2->tab_strip_model(), 100);
138 140
139 // Resize the two windows so they're right next to each other. 141 // Resize the two windows so they're right next to each other.
140 gfx::Rect work_area = gfx::Screen::GetDisplayNearestWindow( 142 gfx::Rect work_area = gfx::Screen::GetDisplayNearestWindow(
141 browser()->window()->GetNativeWindow()).work_area(); 143 browser()->window()->GetNativeWindow()).work_area();
142 gfx::Size half_size = 144 gfx::Size half_size =
143 gfx::Size(work_area.width() / 3 - 10, work_area.height() / 2 - 10); 145 gfx::Size(work_area.width() / 3 - 10, work_area.height() / 2 - 10);
144 browser()->window()->SetBounds(gfx::Rect(work_area.origin(), half_size)); 146 browser()->window()->SetBounds(gfx::Rect(work_area.origin(), half_size));
145 browser2->window()->SetBounds(gfx::Rect( 147 browser2->window()->SetBounds(gfx::Rect(
146 work_area.x() + half_size.width(), work_area.y(), 148 work_area.x() + half_size.width(), work_area.y(),
147 half_size.width(), half_size.height())); 149 half_size.width(), half_size.height()));
148 return browser2; 150 return browser2;
149 } 151 }
150 152
151 class DetachToBrowserTabDragControllerTest : public TabDragControllerTest { 153 namespace {
154
155 enum InputSource {
156 INPUT_SOURCE_MOUSE = 0,
157 INPUT_SOURCE_TOUCH = 1
158 };
159
160 int GetDetachY(TabStrip* tab_strip) {
161 return std::max(TabDragController::kTouchVerticalDetachMagnetism,
162 TabDragController::kVerticalDetachMagnetism) +
163 tab_strip->height() + 1;
164 }
165
166 } // namespace
167
168 class DetachToBrowserTabDragControllerTest
169 : public TabDragControllerTest,
170 public ::testing::WithParamInterface<const char*> {
152 public: 171 public:
153 DetachToBrowserTabDragControllerTest() {} 172 DetachToBrowserTabDragControllerTest() {}
154 173
155 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 174 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
156 command_line->AppendSwitch(switches::kTabBrowserDragging); 175 command_line->AppendSwitch(switches::kTabBrowserDragging);
157 } 176 }
158 177
178 virtual void SetUpOnMainThread() OVERRIDE {
179 #if defined(USE_ASH)
180 event_generator_.reset(new aura::test::EventGenerator(
181 ash::Shell::GetPrimaryRootWindow()));
182 #endif
183 }
184
185 InputSource input_source() const {
186 return !strcmp(GetParam(), "mouse") ?
187 INPUT_SOURCE_MOUSE : INPUT_SOURCE_TOUCH;
188 }
189
190 // The following methods update one of the mouse or touch input depending upon
191 // the InputSource.
192 bool PressInput(const gfx::Point& location) {
193 if (input_source() == INPUT_SOURCE_MOUSE) {
194 return ui_test_utils::SendMouseMoveSync(location) &&
195 ui_test_utils::SendMouseEventsSync(
196 ui_controls::LEFT, ui_controls::DOWN);
197 }
198 #if defined(USE_ASH)
199 event_generator_->set_current_location(location);
200 event_generator_->PressTouch();
201 #else
202 NOTREACHED();
203 #endif
204 return true;
205 }
206
207 bool DragInputTo(const gfx::Point& location) {
208 if (input_source() == INPUT_SOURCE_MOUSE)
209 return ui_test_utils::SendMouseMoveSync(location);
210 #if defined(USE_ASH)
211 event_generator_->MoveTouch(location);
212 #else
213 NOTREACHED();
214 #endif
215 return true;
216 }
217
218 bool DragInputToAsync(const gfx::Point& location) {
219 if (input_source() == INPUT_SOURCE_MOUSE)
220 return ui_controls::SendMouseMove(location.x(), location.y());
221 #if defined(USE_ASH)
222 event_generator_->MoveTouch(location);
223 #else
224 NOTREACHED();
225 #endif
226 return true;
227 }
228
229 bool DragInputToNotifyWhenDone(int x,
230 int y,
231 const base::Closure& task) {
232 if (input_source() == INPUT_SOURCE_MOUSE)
233 return ui_controls::SendMouseMoveNotifyWhenDone(x, y, task);
234 #if defined(USE_ASH)
235 MessageLoop::current()->PostTask(FROM_HERE, task);
236 event_generator_->MoveTouch(gfx::Point(x, y));
237 #else
238 NOTREACHED();
239 #endif
240 return true;
241 }
242
243 bool ReleaseInput() {
244 if (input_source() == INPUT_SOURCE_MOUSE) {
245 return ui_test_utils::SendMouseEventsSync(
246 ui_controls::LEFT, ui_controls::UP);
247 }
248 #if defined(USE_ASH)
249 event_generator_->ReleaseTouch();
250 #else
251 NOTREACHED();
252 #endif
253 return true;
254 }
255
256 bool ReleaseMouseAsync() {
257 return input_source() == INPUT_SOURCE_MOUSE &&
258 ui_controls::SendMouseEvents(ui_controls::LEFT, ui_controls::UP);
259 }
260
261 void QuitWhenNotDragging() {
262 if (input_source() == INPUT_SOURCE_MOUSE) {
263 // Schedule observer to quit message loop when done dragging. This has to
264 // be async so the message loop can run.
265 test::QuitWhenNotDraggingImpl();
266 MessageLoop::current()->Run();
267 } else {
268 // Touch events are sync, so we know we're not in a drag session. But some
269 // tests rely on the browser fully closing, which is async. So, run all
270 // pending tasks.
271 base::RunLoop run_loop;
272 run_loop.RunUntilIdle();
273 }
274 }
275
159 private: 276 private:
277 #if defined(USE_ASH)
278 scoped_ptr<aura::test::EventGenerator> event_generator_;
279 #endif
280
160 DISALLOW_COPY_AND_ASSIGN(DetachToBrowserTabDragControllerTest); 281 DISALLOW_COPY_AND_ASSIGN(DetachToBrowserTabDragControllerTest);
161 }; 282 };
162 283
163 // Creates a browser with two tabs, drags the second to the first. 284 // Creates a browser with two tabs, drags the second to the first.
164 IN_PROC_BROWSER_TEST_F(DetachToBrowserTabDragControllerTest, DragInSameWindow) { 285 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, DragInSameWindow) {
165 AddTabAndResetBrowser(browser()); 286 AddTabAndResetBrowser(browser());
166 287
167 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 288 TabStrip* tab_strip = GetTabStripForBrowser(browser());
168 TabStripModel* model = browser()->tab_strip_model(); 289 TabStripModel* model = browser()->tab_strip_model();
169 290
170 gfx::Point tab_1_center(GetCenterInScreenCoordinates(tab_strip->tab_at(1))); 291 gfx::Point tab_1_center(GetCenterInScreenCoordinates(tab_strip->tab_at(1)));
171 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_1_center)); 292 ASSERT_TRUE(PressInput(tab_1_center));
172 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
173 ui_controls::LEFT, ui_controls::DOWN));
174 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 293 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
175 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); 294 ASSERT_TRUE(DragInputTo(tab_0_center));
176 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 295 ASSERT_TRUE(ReleaseInput());
177 ui_controls::LEFT, ui_controls::UP));
178 EXPECT_EQ("1 0", IDString(model)); 296 EXPECT_EQ("1 0", IDString(model));
179 EXPECT_FALSE(TabDragController::IsActive()); 297 EXPECT_FALSE(TabDragController::IsActive());
180 EXPECT_FALSE(tab_strip->IsDragSessionActive()); 298 EXPECT_FALSE(tab_strip->IsDragSessionActive());
181 } 299 }
182 300
183 namespace { 301 namespace {
184 302
185 // Invoked from the nested message loop. 303 // Invoked from the nested message loop.
186 void DragToSeparateWindowStep2(TabStrip* not_attached_tab_strip, 304 void DragToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test,
305 TabStrip* not_attached_tab_strip,
187 TabStrip* target_tab_strip) { 306 TabStrip* target_tab_strip) {
188 ASSERT_FALSE(not_attached_tab_strip->IsDragSessionActive()); 307 ASSERT_FALSE(not_attached_tab_strip->IsDragSessionActive());
189 ASSERT_FALSE(target_tab_strip->IsDragSessionActive()); 308 ASSERT_FALSE(target_tab_strip->IsDragSessionActive());
190 ASSERT_TRUE(TabDragController::IsActive()); 309 ASSERT_TRUE(TabDragController::IsActive());
191 310
192 // Drag to target_tab_strip. This should stop the nested loop from dragging 311 // Drag to target_tab_strip. This should stop the nested loop from dragging
193 // the window. 312 // the window.
194 gfx::Point target_point(target_tab_strip->width() -1, 313 gfx::Point target_point(target_tab_strip->width() -1,
195 target_tab_strip->height() / 2); 314 target_tab_strip->height() / 2);
196 views::View::ConvertPointToScreen(target_tab_strip, &target_point); 315 views::View::ConvertPointToScreen(target_tab_strip, &target_point);
197 ASSERT_TRUE(ui_controls::SendMouseMove(target_point.x(), target_point.y())); 316 ASSERT_TRUE(test->DragInputToAsync(target_point));
198 } 317 }
199 318
200 } // namespace 319 } // namespace
201 320
202 // Creates two browsers, drags from first into second. 321 // Creates two browsers, drags from first into second.
203 IN_PROC_BROWSER_TEST_F(DetachToBrowserTabDragControllerTest, 322 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
204 DragToSeparateWindow) { 323 DragToSeparateWindow) {
205 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 324 TabStrip* tab_strip = GetTabStripForBrowser(browser());
206 325
326 // Add another tab to browser().
327 AddTabAndResetBrowser(browser());
328
207 // Create another browser. 329 // Create another browser.
208 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout(); 330 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout();
209 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2); 331 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
210 332
211 // Move to the first tab and drag it enough so that it detaches, but not 333 // Move to the first tab and drag it enough so that it detaches, but not
212 // enough that it attaches to browser2. 334 // enough that it attaches to browser2.
213 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 335 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
214 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); 336 ASSERT_TRUE(PressInput(tab_0_center));
215 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 337 ASSERT_TRUE(DragInputToNotifyWhenDone(
216 ui_controls::LEFT, ui_controls::DOWN)); 338 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
217 ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
218 tab_0_center.x(), tab_0_center.y() + tab_strip->height() + 20,
219 base::Bind(&DragToSeparateWindowStep2, 339 base::Bind(&DragToSeparateWindowStep2,
220 tab_strip, tab_strip2))); 340 this, tab_strip, tab_strip2)));
221 // Schedule observer to quit message loop when done dragging. This has to be
222 // async so the message loop can run.
223 QuitWhenNotDragging(); 341 QuitWhenNotDragging();
224 MessageLoop::current()->Run();
225 342
226 // Should now be attached to tab_strip2. 343 // Should now be attached to tab_strip2.
227 ASSERT_TRUE(tab_strip2->IsDragSessionActive()); 344 ASSERT_TRUE(tab_strip2->IsDragSessionActive());
228 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 345 ASSERT_FALSE(tab_strip->IsDragSessionActive());
229 ASSERT_TRUE(TabDragController::IsActive()); 346 ASSERT_TRUE(TabDragController::IsActive());
230 347
231 // Release the mouse, stopping the drag session. 348 // Release the mouse, stopping the drag session.
232 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 349 ASSERT_TRUE(ReleaseInput());
233 ui_controls::LEFT, ui_controls::UP));
234 ASSERT_FALSE(tab_strip2->IsDragSessionActive()); 350 ASSERT_FALSE(tab_strip2->IsDragSessionActive());
235 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 351 ASSERT_FALSE(tab_strip->IsDragSessionActive());
236 ASSERT_FALSE(TabDragController::IsActive()); 352 ASSERT_FALSE(TabDragController::IsActive());
237 EXPECT_EQ("100 0", IDString(browser2->tab_strip_model())); 353 EXPECT_EQ("100 0", IDString(browser2->tab_strip_model()));
238 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); 354 EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
239 } 355 }
240 356
357 namespace {
358
359 void DetachToOwnWindowStep2(DetachToBrowserTabDragControllerTest* test) {
360 if (test->input_source() == INPUT_SOURCE_TOUCH)
361 ASSERT_TRUE(test->ReleaseInput());
362 }
363
364 } // namespace
365
241 // Drags from browser to separate window and releases mouse. 366 // Drags from browser to separate window and releases mouse.
242 IN_PROC_BROWSER_TEST_F(DetachToBrowserTabDragControllerTest, 367 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
243 DetachToOwnWindow) { 368 DetachToOwnWindow) {
244 // Add another tab. 369 // Add another tab.
245 AddTabAndResetBrowser(browser()); 370 AddTabAndResetBrowser(browser());
246 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 371 TabStrip* tab_strip = GetTabStripForBrowser(browser());
247 372
248 // Move to the first tab and drag it enough so that it detaches. 373 // Move to the first tab and drag it enough so that it detaches.
249 gfx::Point tab_0_center( 374 gfx::Point tab_0_center(
250 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 375 GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
251 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); 376 ASSERT_TRUE(PressInput(tab_0_center));
252 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 377 ASSERT_TRUE(DragInputToNotifyWhenDone(
253 ui_controls::LEFT, ui_controls::DOWN)); 378 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
254 ASSERT_TRUE(ui_controls::SendMouseMove( 379 base::Bind(&DetachToOwnWindowStep2, this)));
255 tab_0_center.x(), tab_0_center.y() + tab_strip->height() + 20)); 380 if (input_source() == INPUT_SOURCE_MOUSE) {
256 ASSERT_TRUE(ui_controls::SendMouseEvents( 381 ASSERT_TRUE(ReleaseMouseAsync());
257 ui_controls::LEFT, ui_controls::UP)); 382 QuitWhenNotDragging();
258 // Schedule observer to quit message loop when done dragging. This has to be 383 }
259 // async so the message loop can run.
260 QuitWhenNotDragging();
261 MessageLoop::current()->Run();
262 384
263 // Should no longer be dragging. 385 // Should no longer be dragging.
264 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 386 ASSERT_FALSE(tab_strip->IsDragSessionActive());
265 ASSERT_FALSE(TabDragController::IsActive()); 387 ASSERT_FALSE(TabDragController::IsActive());
266 388
267 // There should now be another browser. 389 // There should now be another browser.
268 ASSERT_EQ(2u, BrowserList::size()); 390 ASSERT_EQ(2u, BrowserList::size());
269 Browser* new_browser = *(++BrowserList::begin()); 391 Browser* new_browser = *(++BrowserList::begin());
270 ASSERT_TRUE(new_browser->window()->IsActive()); 392 ASSERT_TRUE(new_browser->window()->IsActive());
271 TabStrip* tab_strip2 = GetTabStripForBrowser(new_browser); 393 TabStrip* tab_strip2 = GetTabStripForBrowser(new_browser);
272 ASSERT_FALSE(tab_strip2->IsDragSessionActive()); 394 ASSERT_FALSE(tab_strip2->IsDragSessionActive());
273 395
274 EXPECT_EQ("0", IDString(new_browser->tab_strip_model())); 396 EXPECT_EQ("0", IDString(new_browser->tab_strip_model()));
275 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); 397 EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
276 } 398 }
277 399
278 // Deletes a tab being dragged before the user moved enough to start a drag. 400 // Deletes a tab being dragged before the user moved enough to start a drag.
279 IN_PROC_BROWSER_TEST_F(DetachToBrowserTabDragControllerTest, 401 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
280 DeleteBeforeStartedDragging) { 402 DeleteBeforeStartedDragging) {
281 // Add another tab. 403 // Add another tab.
282 AddTabAndResetBrowser(browser()); 404 AddTabAndResetBrowser(browser());
283 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 405 TabStrip* tab_strip = GetTabStripForBrowser(browser());
284 406
285 // Click on the first tab, but don't move it. 407 // Click on the first tab, but don't move it.
286 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 408 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
287 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); 409 ASSERT_TRUE(PressInput(tab_0_center));
288 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
289 ui_controls::LEFT, ui_controls::DOWN));
290 410
291 // Should be dragging. 411 // Should be dragging.
292 ASSERT_TRUE(tab_strip->IsDragSessionActive()); 412 ASSERT_TRUE(tab_strip->IsDragSessionActive());
293 ASSERT_TRUE(TabDragController::IsActive()); 413 ASSERT_TRUE(TabDragController::IsActive());
294 414
295 // Delete the tab being dragged. 415 // Delete the tab being dragged.
296 delete browser()->tab_strip_model()->GetTabContentsAt(0); 416 delete browser()->tab_strip_model()->GetTabContentsAt(0);
297 417
298 // Should have canceled dragging. 418 // Should have canceled dragging.
299 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 419 ASSERT_FALSE(tab_strip->IsDragSessionActive());
300 ASSERT_FALSE(TabDragController::IsActive()); 420 ASSERT_FALSE(TabDragController::IsActive());
301 421
302 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); 422 EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
303 } 423 }
304 424
305 // Deletes a tab being dragged while still attached. 425 // Deletes a tab being dragged while still attached.
306 IN_PROC_BROWSER_TEST_F(DetachToBrowserTabDragControllerTest, 426 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
307 DeleteTabWhileAttached) { 427 DeleteTabWhileAttached) {
308 // Add another tab. 428 // Add another tab.
309 AddTabAndResetBrowser(browser()); 429 AddTabAndResetBrowser(browser());
310 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 430 TabStrip* tab_strip = GetTabStripForBrowser(browser());
311 431
312 // Click on the first tab and move it enough so that it starts dragging but is 432 // Click on the first tab and move it enough so that it starts dragging but is
313 // still attached. 433 // still attached.
314 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 434 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
315 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); 435 ASSERT_TRUE(PressInput(tab_0_center));
316 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 436 ASSERT_TRUE(DragInputTo(
317 ui_controls::LEFT, ui_controls::DOWN));
318 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
319 gfx::Point(tab_0_center.x() + 20, tab_0_center.y()))); 437 gfx::Point(tab_0_center.x() + 20, tab_0_center.y())));
320 438
321 // Should be dragging. 439 // Should be dragging.
322 ASSERT_TRUE(tab_strip->IsDragSessionActive()); 440 ASSERT_TRUE(tab_strip->IsDragSessionActive());
323 ASSERT_TRUE(TabDragController::IsActive()); 441 ASSERT_TRUE(TabDragController::IsActive());
324 442
325 // Delete the tab being dragged. 443 // Delete the tab being dragged.
326 delete browser()->tab_strip_model()->GetTabContentsAt(0); 444 delete browser()->tab_strip_model()->GetTabContentsAt(0);
327 445
328 // Should have canceled dragging. 446 // Should have canceled dragging.
329 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 447 ASSERT_FALSE(tab_strip->IsDragSessionActive());
330 ASSERT_FALSE(TabDragController::IsActive()); 448 ASSERT_FALSE(TabDragController::IsActive());
331 449
332 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); 450 EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
333 } 451 }
334 452
335 namespace { 453 namespace {
336 454
337 void DeleteWhileDetachedStep2(TabContents* tab) { 455 void DeleteWhileDetachedStep2(TabContents* tab) {
338 delete tab; 456 delete tab;
339 } 457 }
340 458
341 } // namespace 459 } // namespace
342 460
343 // Deletes a tab being dragged after dragging a tab so that a new window is 461 // Deletes a tab being dragged after dragging a tab so that a new window is
344 // created. 462 // created.
345 IN_PROC_BROWSER_TEST_F(DetachToBrowserTabDragControllerTest, 463 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
346 DeleteTabWhileDetached) { 464 DeleteTabWhileDetached) {
347 // Add another tab. 465 // Add another tab.
348 AddTabAndResetBrowser(browser()); 466 AddTabAndResetBrowser(browser());
349 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 467 TabStrip* tab_strip = GetTabStripForBrowser(browser());
350 468
351 // Move to the first tab and drag it enough so that it detaches. 469 // Move to the first tab and drag it enough so that it detaches.
352 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 470 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
353 TabContents* to_delete = 471 TabContents* to_delete =
354 browser()->tab_strip_model()->GetTabContentsAt(0); 472 browser()->tab_strip_model()->GetTabContentsAt(0);
355 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); 473 ASSERT_TRUE(PressInput(tab_0_center));
356 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 474 ASSERT_TRUE(DragInputToNotifyWhenDone(
357 ui_controls::LEFT, ui_controls::DOWN)); 475 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
358 ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
359 tab_0_center.x(), tab_0_center.y() + tab_strip->height() + 20,
360 base::Bind(&DeleteWhileDetachedStep2, to_delete))); 476 base::Bind(&DeleteWhileDetachedStep2, to_delete)));
361 // Schedule observer to quit message loop when done dragging. This has to be
362 // async so the message loop can run.
363 QuitWhenNotDragging(); 477 QuitWhenNotDragging();
364 MessageLoop::current()->Run();
365 478
366 // Should not be dragging. 479 // Should not be dragging.
367 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 480 ASSERT_FALSE(tab_strip->IsDragSessionActive());
368 ASSERT_FALSE(TabDragController::IsActive()); 481 ASSERT_FALSE(TabDragController::IsActive());
369 482
370 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); 483 EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
371 } 484 }
372 485
373 namespace { 486 namespace {
374 487
375 void DeleteSourceDetachedStep2(TabContents* tab) { 488 void DeleteSourceDetachedStep2(TabContents* tab) {
376 // This ends up closing the source window. 489 // This ends up closing the source window.
377 delete tab; 490 delete tab;
378 // Cancel the drag. 491 // Cancel the drag.
379 ui_controls::SendKeyPress(NULL, ui::VKEY_ESCAPE, false, false, false, false); 492 ui_controls::SendKeyPress(NULL, ui::VKEY_ESCAPE, false, false, false, false);
380 } 493 }
381 494
382 } // namespace 495 } // namespace
383 496
384 // Detaches a tab and while detached deletes a tab from the source so that the 497 // Detaches a tab and while detached deletes a tab from the source so that the
385 // source window closes then presses escape to cancel the drag. 498 // source window closes then presses escape to cancel the drag.
386 IN_PROC_BROWSER_TEST_F(DetachToBrowserTabDragControllerTest, 499 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
387 DeleteSourceDetached) { 500 DeleteSourceDetached) {
388 // Add another tab. 501 // Add another tab.
389 AddTabAndResetBrowser(browser()); 502 AddTabAndResetBrowser(browser());
390 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 503 TabStrip* tab_strip = GetTabStripForBrowser(browser());
391 504
392 // Move to the first tab and drag it enough so that it detaches. 505 // Move to the first tab and drag it enough so that it detaches.
393 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 506 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
394 TabContents* to_delete = browser()->tab_strip_model()->GetTabContentsAt(1); 507 TabContents* to_delete = browser()->tab_strip_model()->GetTabContentsAt(1);
395 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); 508 ASSERT_TRUE(PressInput(tab_0_center));
396 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 509 ASSERT_TRUE(DragInputToNotifyWhenDone(
397 ui_controls::LEFT, ui_controls::DOWN)); 510 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
398 ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
399 tab_0_center.x(), tab_0_center.y() + tab_strip->height() + 20,
400 base::Bind(&DeleteSourceDetachedStep2, to_delete))); 511 base::Bind(&DeleteSourceDetachedStep2, to_delete)));
401 // Schedule observer to quit message loop when done dragging. This has to be
402 // async so the message loop can run.
403 QuitWhenNotDragging(); 512 QuitWhenNotDragging();
404 MessageLoop::current()->Run();
405 513
406 // Should not be dragging. 514 // Should not be dragging.
407 ASSERT_EQ(1u, BrowserList::size()); 515 ASSERT_EQ(1u, BrowserList::size());
408 Browser* new_browser = *BrowserList::begin(); 516 Browser* new_browser = *BrowserList::begin();
409 ASSERT_FALSE(GetTabStripForBrowser(new_browser)->IsDragSessionActive()); 517 ASSERT_FALSE(GetTabStripForBrowser(new_browser)->IsDragSessionActive());
410 ASSERT_FALSE(TabDragController::IsActive()); 518 ASSERT_FALSE(TabDragController::IsActive());
411 519
412 EXPECT_EQ("0", IDString(new_browser->tab_strip_model())); 520 EXPECT_EQ("0", IDString(new_browser->tab_strip_model()));
413 } 521 }
414 522
415 namespace { 523 namespace {
416 524
417 void PressEscapeWhileDetachedStep2() { 525 void PressEscapeWhileDetachedStep2() {
418 // Cancel the drag. 526 // Cancel the drag.
419 ui_controls::SendKeyPress(NULL, ui::VKEY_ESCAPE, false, false, false, false); 527 ui_controls::SendKeyPress(NULL, ui::VKEY_ESCAPE, false, false, false, false);
420 } 528 }
421 529
422 } // namespace 530 } // namespace
423 531
424 // This is disabled until NativeViewHost::Detach really detaches. 532 // This is disabled until NativeViewHost::Detach really detaches.
425 // Detaches a tab and while detached presses escape to revert the drag. 533 // Detaches a tab and while detached presses escape to revert the drag.
426 IN_PROC_BROWSER_TEST_F(DetachToBrowserTabDragControllerTest, 534 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
427 DISABLED_PressEscapeWhileDetached) { 535 DISABLED_PressEscapeWhileDetached) {
428 // Add another tab. 536 // Add another tab.
429 AddTabAndResetBrowser(browser()); 537 AddTabAndResetBrowser(browser());
430 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 538 TabStrip* tab_strip = GetTabStripForBrowser(browser());
431 539
432 // Move to the first tab and drag it enough so that it detaches. 540 // Move to the first tab and drag it enough so that it detaches.
433 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 541 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
434 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); 542 ASSERT_TRUE(PressInput(tab_0_center));
435 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 543 ASSERT_TRUE(DragInputToNotifyWhenDone(
436 ui_controls::LEFT, ui_controls::DOWN)); 544 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
437 ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
438 tab_0_center.x(), tab_0_center.y() + tab_strip->height() + 20,
439 base::Bind(&PressEscapeWhileDetachedStep2))); 545 base::Bind(&PressEscapeWhileDetachedStep2)));
440 // Schedule observer to quit message loop when done dragging. This has to be
441 // async so the message loop can run.
442 QuitWhenNotDragging(); 546 QuitWhenNotDragging();
443 MessageLoop::current()->Run();
444 547
445 // Should not be dragging. 548 // Should not be dragging.
446 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 549 ASSERT_FALSE(tab_strip->IsDragSessionActive());
447 ASSERT_FALSE(TabDragController::IsActive()); 550 ASSERT_FALSE(TabDragController::IsActive());
448 551
449 // And there should only be one window. 552 // And there should only be one window.
450 EXPECT_EQ(1u, BrowserList::size()); 553 EXPECT_EQ(1u, BrowserList::size());
451 554
452 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model())); 555 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
453 } 556 }
454 557
455 namespace { 558 namespace {
456 559
457 void DragAllStep2() { 560 void DragAllStep2(DetachToBrowserTabDragControllerTest* test) {
458 // Should only be one window. 561 // Should only be one window.
459 ASSERT_EQ(1u, BrowserList::size()); 562 ASSERT_EQ(1u, BrowserList::size());
460 // Release the mouse. 563 if (test->input_source() == INPUT_SOURCE_TOUCH) {
461 ASSERT_TRUE(ui_controls::SendMouseEvents( 564 ASSERT_TRUE(test->ReleaseInput());
462 ui_controls::LEFT, ui_controls::UP)); 565 } else {
566 ASSERT_TRUE(test->ReleaseMouseAsync());
567 }
463 } 568 }
464 569
465 } // namespace 570 } // namespace
466 571
467 // Selects multiple tabs and starts dragging the window. 572 // Selects multiple tabs and starts dragging the window.
468 IN_PROC_BROWSER_TEST_F(DetachToBrowserTabDragControllerTest, DragAll) { 573 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, DragAll) {
469 // Add another tab. 574 // Add another tab.
470 AddTabAndResetBrowser(browser()); 575 AddTabAndResetBrowser(browser());
471 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 576 TabStrip* tab_strip = GetTabStripForBrowser(browser());
472 browser()->tab_strip_model()->AddTabAtToSelection(0); 577 browser()->tab_strip_model()->AddTabAtToSelection(0);
473 browser()->tab_strip_model()->AddTabAtToSelection(1); 578 browser()->tab_strip_model()->AddTabAtToSelection(1);
474 579
475 // Move to the first tab and drag it enough so that it would normally 580 // Move to the first tab and drag it enough so that it would normally
476 // detach. 581 // detach.
477 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 582 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
478 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); 583 ASSERT_TRUE(PressInput(tab_0_center));
479 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 584 ASSERT_TRUE(DragInputToNotifyWhenDone(
480 ui_controls::LEFT, ui_controls::DOWN)); 585 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
481 ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone( 586 base::Bind(&DragAllStep2, this)));
482 tab_0_center.x(), tab_0_center.y() + tab_strip->height() + 20,
483 base::Bind(&DragAllStep2)));
484 // Schedule observer to quit message loop when done dragging. This has to be
485 // async so the message loop can run.
486 QuitWhenNotDragging(); 587 QuitWhenNotDragging();
487 MessageLoop::current()->Run();
488 588
489 // Should not be dragging. 589 // Should not be dragging.
490 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 590 ASSERT_FALSE(tab_strip->IsDragSessionActive());
491 ASSERT_FALSE(TabDragController::IsActive()); 591 ASSERT_FALSE(TabDragController::IsActive());
492 592
493 // And there should only be one window. 593 // And there should only be one window.
494 EXPECT_EQ(1u, BrowserList::size()); 594 EXPECT_EQ(1u, BrowserList::size());
495 595
496 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model())); 596 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
497 } 597 }
498 598
499 namespace { 599 namespace {
500 600
501 // Invoked from the nested message loop. 601 // Invoked from the nested message loop.
502 void DragAllToSeparateWindowStep2(TabStrip* attached_tab_strip, 602 void DragAllToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test,
603 TabStrip* attached_tab_strip,
503 TabStrip* target_tab_strip) { 604 TabStrip* target_tab_strip) {
504 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive()); 605 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive());
505 ASSERT_FALSE(target_tab_strip->IsDragSessionActive()); 606 ASSERT_FALSE(target_tab_strip->IsDragSessionActive());
506 ASSERT_TRUE(TabDragController::IsActive()); 607 ASSERT_TRUE(TabDragController::IsActive());
507 ASSERT_EQ(2u, BrowserList::size()); 608 ASSERT_EQ(2u, BrowserList::size());
508 609
509 // Drag to target_tab_strip. This should stop the nested loop from dragging 610 // Drag to target_tab_strip. This should stop the nested loop from dragging
510 // the window. 611 // the window.
511 gfx::Point target_point(target_tab_strip->width() - 1, 612 gfx::Point target_point(target_tab_strip->width() - 1,
512 target_tab_strip->height() / 2); 613 target_tab_strip->height() / 2);
513 views::View::ConvertPointToScreen(target_tab_strip, &target_point); 614 views::View::ConvertPointToScreen(target_tab_strip, &target_point);
514 ASSERT_TRUE(ui_controls::SendMouseMove(target_point.x(), target_point.y())); 615 ASSERT_TRUE(test->DragInputToAsync(target_point));
515 } 616 }
516 617
517 } // namespace 618 } // namespace
518 619
519 // Creates two browsers, selects all tabs in first and drags into second. 620 // Creates two browsers, selects all tabs in first and drags into second.
520 IN_PROC_BROWSER_TEST_F(DetachToBrowserTabDragControllerTest, 621 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
521 DragAllToSeparateWindow) { 622 DragAllToSeparateWindow) {
522 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 623 TabStrip* tab_strip = GetTabStripForBrowser(browser());
523 624
625 // Add another tab to browser().
626 AddTabAndResetBrowser(browser());
627
524 // Create another browser. 628 // Create another browser.
525 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout(); 629 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout();
526 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2); 630 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
527 631
528 browser()->tab_strip_model()->AddTabAtToSelection(0); 632 browser()->tab_strip_model()->AddTabAtToSelection(0);
529 browser()->tab_strip_model()->AddTabAtToSelection(1); 633 browser()->tab_strip_model()->AddTabAtToSelection(1);
530 634
531 // Move to the first tab and drag it enough so that it detaches, but not 635 // Move to the first tab and drag it enough so that it detaches, but not
532 // enough that it attaches to browser2. 636 // enough that it attaches to browser2.
533 gfx::Point tab_0_center( 637 gfx::Point tab_0_center(
534 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 638 GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
535 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); 639 ASSERT_TRUE(PressInput(tab_0_center));
536 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 640 ASSERT_TRUE(DragInputToNotifyWhenDone(
537 ui_controls::LEFT, ui_controls::DOWN)); 641 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
538 ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone( 642 base::Bind(&DragAllToSeparateWindowStep2, this, tab_strip, tab_strip2)));
539 tab_0_center.x(), tab_0_center.y() + tab_strip->height() + 20,
540 base::Bind(&DragAllToSeparateWindowStep2, tab_strip, tab_strip2)));
541 // Schedule observer to quit message loop when done dragging. This has to be
542 // async so the message loop can run.
543 QuitWhenNotDragging(); 643 QuitWhenNotDragging();
544 MessageLoop::current()->Run();
545 644
546 // Should now be attached to tab_strip2. 645 // Should now be attached to tab_strip2.
547 ASSERT_TRUE(tab_strip2->IsDragSessionActive()); 646 ASSERT_TRUE(tab_strip2->IsDragSessionActive());
548 ASSERT_TRUE(TabDragController::IsActive()); 647 ASSERT_TRUE(TabDragController::IsActive());
549 ASSERT_EQ(1u, BrowserList::size()); 648 ASSERT_EQ(1u, BrowserList::size());
550 649
551 // Release the mouse, stopping the drag session. 650 // Release the mouse, stopping the drag session.
552 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 651 ASSERT_TRUE(ReleaseInput());
553 ui_controls::LEFT, ui_controls::UP));
554 ASSERT_FALSE(tab_strip2->IsDragSessionActive()); 652 ASSERT_FALSE(tab_strip2->IsDragSessionActive());
555 ASSERT_FALSE(TabDragController::IsActive()); 653 ASSERT_FALSE(TabDragController::IsActive());
556 EXPECT_EQ("100 0 1", IDString(browser2->tab_strip_model())); 654 EXPECT_EQ("100 0 1", IDString(browser2->tab_strip_model()));
557 } 655 }
558 656
559 namespace { 657 namespace {
560 658
561 // Invoked from the nested message loop. 659 // Invoked from the nested message loop.
562 void DragAllToSeparateWindowAndCancelStep2(TabStrip* attached_tab_strip, 660 void DragAllToSeparateWindowAndCancelStep2(
563 TabStrip* target_tab_strip) { 661 DetachToBrowserTabDragControllerTest* test,
662 TabStrip* attached_tab_strip,
663 TabStrip* target_tab_strip) {
564 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive()); 664 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive());
565 ASSERT_FALSE(target_tab_strip->IsDragSessionActive()); 665 ASSERT_FALSE(target_tab_strip->IsDragSessionActive());
566 ASSERT_TRUE(TabDragController::IsActive()); 666 ASSERT_TRUE(TabDragController::IsActive());
567 ASSERT_EQ(2u, BrowserList::size()); 667 ASSERT_EQ(2u, BrowserList::size());
568 668
569 // Drag to target_tab_strip. This should stop the nested loop from dragging 669 // Drag to target_tab_strip. This should stop the nested loop from dragging
570 // the window. 670 // the window.
571 gfx::Point target_point(target_tab_strip->width() - 1, 671 gfx::Point target_point(target_tab_strip->width() - 1,
572 target_tab_strip->height() / 2); 672 target_tab_strip->height() / 2);
573 views::View::ConvertPointToScreen(target_tab_strip, &target_point); 673 views::View::ConvertPointToScreen(target_tab_strip, &target_point);
574 ASSERT_TRUE(ui_controls::SendMouseMove(target_point.x(), target_point.y())); 674 ASSERT_TRUE(test->DragInputToAsync(target_point));
575 } 675 }
576 676
577 } // namespace 677 } // namespace
578 678
579 // Creates two browsers, selects all tabs in first, drags into second, then hits 679 // Creates two browsers, selects all tabs in first, drags into second, then hits
580 // escape. 680 // escape.
581 IN_PROC_BROWSER_TEST_F(DetachToBrowserTabDragControllerTest, 681 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
582 DragAllToSeparateWindowAndCancel) { 682 DragAllToSeparateWindowAndCancel) {
583 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 683 TabStrip* tab_strip = GetTabStripForBrowser(browser());
584 684
685 // Add another tab to browser().
686 AddTabAndResetBrowser(browser());
687
585 // Create another browser. 688 // Create another browser.
586 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout(); 689 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout();
587 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2); 690 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
588 691
589 browser()->tab_strip_model()->AddTabAtToSelection(0); 692 browser()->tab_strip_model()->AddTabAtToSelection(0);
590 browser()->tab_strip_model()->AddTabAtToSelection(1); 693 browser()->tab_strip_model()->AddTabAtToSelection(1);
591 694
592 // Move to the first tab and drag it enough so that it detaches, but not 695 // Move to the first tab and drag it enough so that it detaches, but not
593 // enough that it attaches to browser2. 696 // enough that it attaches to browser2.
594 gfx::Point tab_0_center( 697 gfx::Point tab_0_center(
595 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 698 GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
596 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); 699 ASSERT_TRUE(PressInput(tab_0_center));
597 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 700 ASSERT_TRUE(DragInputToNotifyWhenDone(
598 ui_controls::LEFT, ui_controls::DOWN)); 701 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
599 ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone( 702 base::Bind(&DragAllToSeparateWindowAndCancelStep2, this,
600 tab_0_center.x(), tab_0_center.y() + tab_strip->height() + 20,
601 base::Bind(&DragAllToSeparateWindowAndCancelStep2,
602 tab_strip, tab_strip2))); 703 tab_strip, tab_strip2)));
603 // Schedule observer to quit message loop when done dragging. This has to be
604 // async so the message loop can run.
605 QuitWhenNotDragging(); 704 QuitWhenNotDragging();
606 MessageLoop::current()->Run();
607 705
608 // Should now be attached to tab_strip2. 706 // Should now be attached to tab_strip2.
609 ASSERT_TRUE(tab_strip2->IsDragSessionActive()); 707 ASSERT_TRUE(tab_strip2->IsDragSessionActive());
610 ASSERT_TRUE(TabDragController::IsActive()); 708 ASSERT_TRUE(TabDragController::IsActive());
611 ASSERT_EQ(1u, BrowserList::size()); 709 ASSERT_EQ(1u, BrowserList::size());
612 710
613 // Cancel the drag. 711 // Cancel the drag.
614 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 712 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
615 browser2, ui::VKEY_ESCAPE, false, false, false, false)); 713 browser2, ui::VKEY_ESCAPE, false, false, false, false));
616 714
617 ASSERT_FALSE(tab_strip2->IsDragSessionActive()); 715 ASSERT_FALSE(tab_strip2->IsDragSessionActive());
618 ASSERT_FALSE(TabDragController::IsActive()); 716 ASSERT_FALSE(TabDragController::IsActive());
619 EXPECT_EQ("100 0 1", IDString(browser2->tab_strip_model())); 717 EXPECT_EQ("100 0 1", IDString(browser2->tab_strip_model()));
620 718
621 // browser() will have been destroyed, but browser2 should remain. 719 // browser() will have been destroyed, but browser2 should remain.
622 ASSERT_EQ(1u, BrowserList::size()); 720 ASSERT_EQ(1u, BrowserList::size());
623 } 721 }
624 722
625 // Creates two browsers, drags from first into the second in such a way that 723 // Creates two browsers, drags from first into the second in such a way that
626 // no detaching should happen. 724 // no detaching should happen.
627 IN_PROC_BROWSER_TEST_F(DetachToBrowserTabDragControllerTest, 725 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
628 DragDirectlyToSecondWindow) { 726 DragDirectlyToSecondWindow) {
629 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 727 TabStrip* tab_strip = GetTabStripForBrowser(browser());
630 728
729 // Add another tab to browser().
730 AddTabAndResetBrowser(browser());
731
631 // Create another browser. 732 // Create another browser.
632 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout(); 733 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout();
633 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2); 734 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
634 735
635 // Move to the first tab and drag it enough so that it detaches, but not 736 // Move to the first tab and drag it enough so that it detaches, but not
636 // enough that it attaches to browser2. 737 // enough that it attaches to browser2.
637 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 738 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
638 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); 739 ASSERT_TRUE(PressInput(tab_0_center));
639 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
640 ui_controls::LEFT, ui_controls::DOWN));
641 740
642 gfx::Point b2_location(5, 0); 741 gfx::Point b2_location(5, 0);
643 views::View::ConvertPointToScreen(tab_strip2, &b2_location); 742 views::View::ConvertPointToScreen(tab_strip2, &b2_location);
644 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(b2_location)); 743 ASSERT_TRUE(DragInputTo(b2_location));
645 744
646 // Should now be attached to tab_strip2. 745 // Should now be attached to tab_strip2.
647 ASSERT_TRUE(tab_strip2->IsDragSessionActive()); 746 ASSERT_TRUE(tab_strip2->IsDragSessionActive());
648 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 747 ASSERT_FALSE(tab_strip->IsDragSessionActive());
649 ASSERT_TRUE(TabDragController::IsActive()); 748 ASSERT_TRUE(TabDragController::IsActive());
650 749
651 // Release the mouse, stopping the drag session. 750 // Release the mouse, stopping the drag session.
652 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 751 ASSERT_TRUE(ReleaseInput());
653 ui_controls::LEFT, ui_controls::UP));
654 ASSERT_FALSE(tab_strip2->IsDragSessionActive()); 752 ASSERT_FALSE(tab_strip2->IsDragSessionActive());
655 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 753 ASSERT_FALSE(tab_strip->IsDragSessionActive());
656 ASSERT_FALSE(TabDragController::IsActive()); 754 ASSERT_FALSE(TabDragController::IsActive());
657 EXPECT_EQ("0 100", IDString(browser2->tab_strip_model())); 755 EXPECT_EQ("0 100", IDString(browser2->tab_strip_model()));
658 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); 756 EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
659 } 757 }
758
759 namespace {
760
761 // Invoked from the nested message loop.
762 void DragSingleTabToSeparateWindowStep2(
763 DetachToBrowserTabDragControllerTest* test,
764 TabStrip* attached_tab_strip,
765 TabStrip* target_tab_strip) {
766 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive());
767 ASSERT_FALSE(target_tab_strip->IsDragSessionActive());
768 ASSERT_TRUE(TabDragController::IsActive());
769 ASSERT_EQ(2u, BrowserList::size());
770
771 // Drag to target_tab_strip. This should stop the nested loop from dragging
772 // the window.
773 gfx::Point target_point(target_tab_strip->width() - 1,
774 target_tab_strip->height() / 2);
775 views::View::ConvertPointToScreen(target_tab_strip, &target_point);
776 ASSERT_TRUE(test->DragInputTo(target_point));
777 }
778
779 } // namespace
780
781 // Creates two browsers, the first browser has a single tab and drags into the
782 // second browser.
783 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
784 DragSingleTabToSeparateWindow) {
785 TabStrip* tab_strip = GetTabStripForBrowser(browser());
786
787 ResetIDs(browser()->tab_strip_model(), 0);
788
789 // Create another browser.
790 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout();
791 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
792
793 // Move to the first tab and drag it enough so that it detaches, but not
794 // enough that it attaches to browser2.
795 gfx::Point tab_0_center(
796 GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
797 ASSERT_TRUE(PressInput(tab_0_center));
798 ASSERT_TRUE(DragInputToNotifyWhenDone(
799 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
800 base::Bind(&DragAllToSeparateWindowStep2, this, tab_strip, tab_strip2)));
801 QuitWhenNotDragging();
802
803 // Should now be attached to tab_strip2.
804 ASSERT_TRUE(tab_strip2->IsDragSessionActive());
805 ASSERT_TRUE(TabDragController::IsActive());
806 ASSERT_EQ(1u, BrowserList::size());
807
808 // Release the mouse, stopping the drag session.
809 ASSERT_TRUE(ReleaseInput());
810 ASSERT_FALSE(tab_strip2->IsDragSessionActive());
811 ASSERT_FALSE(TabDragController::IsActive());
812 EXPECT_EQ("100 0", IDString(browser2->tab_strip_model()));
813 }
814
815 #if defined(USE_ASH)
816 INSTANTIATE_TEST_CASE_P(TabDragging,
817 DetachToBrowserTabDragControllerTest,
818 ::testing::Values("mouse", "touch"));
819 #else
820 INSTANTIATE_TEST_CASE_P(TabDragging,
821 DetachToBrowserTabDragControllerTest,
822 ::testing::Values("mouse"));
823 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698