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

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

Issue 1747803003: MacViews: Implement Tab Dragging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Extract DragsWindowUsingCocoaMoveLoop test, cleanup code. Created 4 years, 9 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 165
166 void TabDragControllerTest::StopAnimating(TabStrip* tab_strip) { 166 void TabDragControllerTest::StopAnimating(TabStrip* tab_strip) {
167 tab_strip->StopAnimating(true); 167 tab_strip->StopAnimating(true);
168 } 168 }
169 169
170 void TabDragControllerTest::AddTabAndResetBrowser(Browser* browser) { 170 void TabDragControllerTest::AddTabAndResetBrowser(Browser* browser) {
171 AddBlankTabAndShow(browser); 171 AddBlankTabAndShow(browser);
172 StopAnimating(GetTabStripForBrowser(browser)); 172 StopAnimating(GetTabStripForBrowser(browser));
173 ResetIDs(browser->tab_strip_model(), 0); 173 ResetIDs(browser->tab_strip_model(), 0);
174
175 // On Macs if we try to drag on an inactive window it won't work. Two
tapted 2016/03/10 11:51:19 Hm - this should work. Or at least, it works with
themblsha 2016/03/10 17:18:58 Did some tests a couple more times: in order for d
tapted 2016/03/11 09:38:28 Yeah I think acceptsFirstMouse returning YES is go
176 // solutions are either to activate the window explicitly, or to click on a
177 // window once before starting dragging.
178 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser));
174 } 179 }
175 180
176 Browser* TabDragControllerTest::CreateAnotherWindowBrowserAndRelayout() { 181 Browser* TabDragControllerTest::CreateAnotherWindowBrowserAndRelayout() {
177 // Create another browser. 182 // Create another browser.
178 Browser* browser2 = CreateBrowser(browser()->profile()); 183 Browser* browser2 = CreateBrowser(browser()->profile());
179 ResetIDs(browser2->tab_strip_model(), 100); 184 ResetIDs(browser2->tab_strip_model(), 100);
180 185
181 // Resize the two windows so they're right next to each other. 186 // Resize the two windows so they're right next to each other.
182 gfx::Rect work_area = 187 gfx::Rect work_area =
183 gfx::Screen::GetScreen() 188 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area();
184 ->GetDisplayNearestWindow(browser()->window()->GetNativeWindow())
185 .work_area();
186 gfx::Size half_size = 189 gfx::Size half_size =
187 gfx::Size(work_area.width() / 3 - 10, work_area.height() / 2 - 10); 190 gfx::Size(work_area.width() / 3 - 10, work_area.height() / 2 - 10);
188 browser()->window()->SetBounds(gfx::Rect(work_area.origin(), half_size)); 191 browser()->window()->SetBounds(gfx::Rect(work_area.origin(), half_size));
189 browser2->window()->SetBounds(gfx::Rect( 192 browser2->window()->SetBounds(gfx::Rect(
190 work_area.x() + half_size.width(), work_area.y(), 193 work_area.x() + half_size.width(), work_area.y(),
191 half_size.width(), half_size.height())); 194 half_size.width(), half_size.height()));
192 return browser2; 195 return browser2;
193 } 196 }
194 197
195 namespace { 198 namespace {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 238 }
236 239
237 private: 240 private:
238 aura::Window* root_window_; 241 aura::Window* root_window_;
239 242
240 DISALLOW_COPY_AND_ASSIGN(ScreenEventGeneratorDelegate); 243 DISALLOW_COPY_AND_ASSIGN(ScreenEventGeneratorDelegate);
241 }; 244 };
242 245
243 #endif 246 #endif
244 247
245 #if !defined(OS_CHROMEOS) 248 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
tapted 2016/03/10 11:51:19 I'd go with && defined(USE_AURA) instead - since t
themblsha 2016/03/10 17:18:58 Done.
246 249
247 // Following classes verify a crash scenario. Specifically on Windows when focus 250 // Following classes verify a crash scenario. Specifically on Windows when focus
248 // changes it can trigger capture being lost. This was causing a crash in tab 251 // changes it can trigger capture being lost. This was causing a crash in tab
249 // dragging as it wasn't set up to handle this scenario. These classes 252 // dragging as it wasn't set up to handle this scenario. These classes
250 // synthesize this scenario. 253 // synthesize this scenario.
251 254
252 // Allows making ClearNativeFocus() invoke ReleaseCapture(). 255 // Allows making ClearNativeFocus() invoke ReleaseCapture().
253 class TestDesktopBrowserFrameAura : public DesktopBrowserFrameAura { 256 class TestDesktopBrowserFrameAura : public DesktopBrowserFrameAura {
254 public: 257 public:
255 TestDesktopBrowserFrameAura( 258 TestDesktopBrowserFrameAura(
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 #define MAYBE_DetachFromFullsizeWindow DISABLED_DetachFromFullsizeWindow 797 #define MAYBE_DetachFromFullsizeWindow DISABLED_DetachFromFullsizeWindow
795 #else 798 #else
796 #define MAYBE_DetachFromFullsizeWindow DetachFromFullsizeWindow 799 #define MAYBE_DetachFromFullsizeWindow DetachFromFullsizeWindow
797 #endif 800 #endif
798 // Tests that a tab can be dragged from a browser window that is resized to full 801 // Tests that a tab can be dragged from a browser window that is resized to full
799 // screen. 802 // screen.
800 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, 803 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
801 MAYBE_DetachFromFullsizeWindow) { 804 MAYBE_DetachFromFullsizeWindow) {
802 // Resize the browser window so that it is as big as the work area. 805 // Resize the browser window so that it is as big as the work area.
803 gfx::Rect work_area = 806 gfx::Rect work_area =
804 gfx::Screen::GetScreen() 807 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area();
805 ->GetDisplayNearestWindow(browser()->window()->GetNativeWindow())
806 .work_area();
807 browser()->window()->SetBounds(work_area); 808 browser()->window()->SetBounds(work_area);
808 const gfx::Rect initial_bounds(browser()->window()->GetBounds()); 809 const gfx::Rect initial_bounds(browser()->window()->GetBounds());
809 // Add another tab. 810 // Add another tab.
810 AddTabAndResetBrowser(browser()); 811 AddTabAndResetBrowser(browser());
811 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 812 TabStrip* tab_strip = GetTabStripForBrowser(browser());
812 813
813 // Move to the first tab and drag it enough so that it detaches. 814 // Move to the first tab and drag it enough so that it detaches.
814 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 815 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
815 ASSERT_TRUE(PressInput(tab_0_center)); 816 ASSERT_TRUE(PressInput(tab_0_center));
816 ASSERT_TRUE(DragInputToNotifyWhenDone( 817 ASSERT_TRUE(DragInputToNotifyWhenDone(
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 #else 1156 #else
1156 #define MAYBE_DragAll DragAll 1157 #define MAYBE_DragAll DragAll
1157 #endif 1158 #endif
1158 // Selects multiple tabs and starts dragging the window. 1159 // Selects multiple tabs and starts dragging the window.
1159 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, MAYBE_DragAll) { 1160 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, MAYBE_DragAll) {
1160 // Add another tab. 1161 // Add another tab.
1161 AddTabAndResetBrowser(browser()); 1162 AddTabAndResetBrowser(browser());
1162 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 1163 TabStrip* tab_strip = GetTabStripForBrowser(browser());
1163 browser()->tab_strip_model()->AddTabAtToSelection(0); 1164 browser()->tab_strip_model()->AddTabAtToSelection(0);
1164 browser()->tab_strip_model()->AddTabAtToSelection(1); 1165 browser()->tab_strip_model()->AddTabAtToSelection(1);
1166 const gfx::Rect initial_bounds = browser()->window()->GetBounds();
1165 1167
1166 // Move to the first tab and drag it enough so that it would normally 1168 // Move to the first tab and drag it enough so that it would normally
1167 // detach. 1169 // detach.
1168 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 1170 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
1169 ASSERT_TRUE(PressInput(tab_0_center)); 1171 ASSERT_TRUE(PressInput(tab_0_center));
1170 ASSERT_TRUE(DragInputToNotifyWhenDone( 1172 ASSERT_TRUE(DragInputToNotifyWhenDone(
1171 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), 1173 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
1172 base::Bind(&DragAllStep2, this, browser_list))); 1174 base::Bind(&DragAllStep2, this, browser_list)));
1173 QuitWhenNotDragging(); 1175 QuitWhenNotDragging();
1174 1176
1175 // Should not be dragging. 1177 // Should not be dragging.
1176 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 1178 ASSERT_FALSE(tab_strip->IsDragSessionActive());
1177 ASSERT_FALSE(TabDragController::IsActive()); 1179 ASSERT_FALSE(TabDragController::IsActive());
1178 1180
1179 // And there should only be one window. 1181 // And there should only be one window.
1180 EXPECT_EQ(1u, browser_list->size()); 1182 EXPECT_EQ(1u, browser_list->size());
1181 1183
1182 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model())); 1184 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
1183 1185
1184 EXPECT_FALSE(GetIsDragged(browser())); 1186 EXPECT_FALSE(GetIsDragged(browser()));
1185 1187
1186 // Remaining browser window should not be maximized 1188 // Remaining browser window should not be maximized
1187 EXPECT_FALSE(browser()->window()->IsMaximized()); 1189 EXPECT_FALSE(browser()->window()->IsMaximized());
1190
1191 const gfx::Rect final_bounds = browser()->window()->GetBounds();
1192 EXPECT_EQ(initial_bounds.size(), final_bounds.size());
1193 EXPECT_EQ(initial_bounds.origin().x(), final_bounds.origin().x());
1194 EXPECT_EQ(initial_bounds.origin().y() + GetDetachY(tab_strip),
1195 final_bounds.origin().y());
1188 } 1196 }
1189 1197
1198 #if defined(OS_MACOSX)
1199 // Makes sure we can drag the window using WindowServer by dragging on a tab
tapted 2016/03/10 11:51:19 nit: full-stop on the end. Also say why this is on
themblsha 2016/03/10 17:18:58 Done.
1200 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
1201 DragsWindowUsingCocoaMoveLoop) {
1202 // Add another tab.
1203 AddTabAndResetBrowser(browser());
1204 TabStrip* tab_strip = GetTabStripForBrowser(browser());
1205 browser()->tab_strip_model()->AddTabAtToSelection(0);
1206 browser()->tab_strip_model()->AddTabAtToSelection(1);
1207 const gfx::Rect initial_bounds = browser()->window()->GetBounds();
1208
1209 // Move to the first tab and drag it enough so that it would normally
1210 // detach.
1211 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
1212 const unsigned int steps = 10; // use anything greater than 1 to verify that
tapted 2016/03/10 11:51:19 we tend not to use `unsigned` on Chrome if int wor
themblsha 2016/03/10 17:18:58 Done.
1213 // CocoaWindowMoveLoop is working correctly
tapted 2016/03/10 11:51:18 nit: Comment above the declaration. Also sentence-
themblsha 2016/03/10 17:18:58 Done.
1214 ui_test_utils::DragAndDrop(
1215 tab_0_center,
1216 gfx::Point(tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip)),
1217 base::TimeDelta(), steps);
1218
1219 // Should not be dragging.
1220 ASSERT_FALSE(tab_strip->IsDragSessionActive());
tapted 2016/03/10 11:51:19 nit: typically we just use EXPECT_ unless things r
themblsha 2016/03/10 17:18:58 Done. But I used the DragAll test as a base, and i
1221 ASSERT_FALSE(TabDragController::IsActive());
1222
1223 // And there should only be one window.
1224 EXPECT_EQ(1u, browser_list->size());
1225
1226 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
1227
1228 EXPECT_FALSE(GetIsDragged(browser()));
1229
1230 // Remaining browser window should not be maximized
1231 EXPECT_FALSE(browser()->window()->IsMaximized());
1232
1233 const gfx::Rect final_bounds = browser()->window()->GetBounds();
1234 EXPECT_EQ(initial_bounds.size(), final_bounds.size());
1235 EXPECT_EQ(initial_bounds.origin().x(), final_bounds.origin().x());
1236 EXPECT_EQ(initial_bounds.origin().y() + GetDetachY(tab_strip),
1237 final_bounds.origin().y());
1238 }
1239 #endif // OS_MACOSX
1240
1190 namespace { 1241 namespace {
1191 1242
1192 // Invoked from the nested message loop. 1243 // Invoked from the nested message loop.
1193 void DragAllToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test, 1244 void DragAllToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test,
1194 TabStrip* attached_tab_strip, 1245 TabStrip* attached_tab_strip,
1195 TabStrip* target_tab_strip, 1246 TabStrip* target_tab_strip,
1196 const BrowserList* browser_list) { 1247 const BrowserList* browser_list) {
1197 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive()); 1248 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive());
1198 ASSERT_FALSE(target_tab_strip->IsDragSessionActive()); 1249 ASSERT_FALSE(target_tab_strip->IsDragSessionActive());
1199 ASSERT_TRUE(TabDragController::IsActive()); 1250 ASSERT_TRUE(TabDragController::IsActive());
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 MAYBE_DragSingleTabToSeparateWindow) { 1459 MAYBE_DragSingleTabToSeparateWindow) {
1409 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 1460 TabStrip* tab_strip = GetTabStripForBrowser(browser());
1410 1461
1411 ResetIDs(browser()->tab_strip_model(), 0); 1462 ResetIDs(browser()->tab_strip_model(), 0);
1412 1463
1413 // Create another browser. 1464 // Create another browser.
1414 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout(); 1465 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout();
1415 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2); 1466 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
1416 const gfx::Rect initial_bounds(browser2->window()->GetBounds()); 1467 const gfx::Rect initial_bounds(browser2->window()->GetBounds());
1417 1468
1469 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
1470
1418 // Move to the first tab and drag it enough so that it detaches, but not 1471 // Move to the first tab and drag it enough so that it detaches, but not
1419 // enough that it attaches to browser2. 1472 // enough that it attaches to browser2.
1420 gfx::Point tab_0_center( 1473 gfx::Point tab_0_center(
1421 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); 1474 GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
1422 ASSERT_TRUE(PressInput(tab_0_center)); 1475 ASSERT_TRUE(PressInput(tab_0_center));
1423 ASSERT_TRUE(DragInputToNotifyWhenDone( 1476 ASSERT_TRUE(DragInputToNotifyWhenDone(
1424 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), 1477 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
1425 base::Bind(&DragAllToSeparateWindowStep2, this, tab_strip, tab_strip2, 1478 base::Bind(&DragAllToSeparateWindowStep2, this, tab_strip, tab_strip2,
1426 browser_list))); 1479 browser_list)));
1427 QuitWhenNotDragging(); 1480 QuitWhenNotDragging();
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
2350 INSTANTIATE_TEST_CASE_P(TabDragging, 2403 INSTANTIATE_TEST_CASE_P(TabDragging,
2351 DetachToBrowserTabDragControllerTest, 2404 DetachToBrowserTabDragControllerTest,
2352 ::testing::Values("mouse", "touch")); 2405 ::testing::Values("mouse", "touch"));
2353 INSTANTIATE_TEST_CASE_P(TabDragging, 2406 INSTANTIATE_TEST_CASE_P(TabDragging,
2354 DetachToBrowserTabDragControllerTestTouch, 2407 DetachToBrowserTabDragControllerTestTouch,
2355 ::testing::Values("touch")); 2408 ::testing::Values("touch"));
2356 #else 2409 #else
2357 INSTANTIATE_TEST_CASE_P(TabDragging, 2410 INSTANTIATE_TEST_CASE_P(TabDragging,
2358 DetachToBrowserTabDragControllerTest, 2411 DetachToBrowserTabDragControllerTest,
2359 ::testing::Values("mouse")); 2412 ::testing::Values("mouse"));
2413 #elif defined(OS_MACOSX)
tapted 2016/03/10 11:51:19 this shouldn't be needed any more -- we can just u
themblsha 2016/03/10 17:18:58 Whoops, clang indeed complains about that, but at
2414 INSTANTIATE_TEST_CASE_P(TabDragging,
2415 DetachToBrowserTabDragControllerTest,
2416 ::testing::Values("mouse"));
2360 #endif 2417 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698