OLD | NEW |
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 ResetIDs(browser->tab_strip_model(), 0); | 173 ResetIDs(browser->tab_strip_model(), 0); |
174 } | 174 } |
175 | 175 |
176 Browser* TabDragControllerTest::CreateAnotherWindowBrowserAndRelayout() { | 176 Browser* TabDragControllerTest::CreateAnotherWindowBrowserAndRelayout() { |
177 // Create another browser. | 177 // Create another browser. |
178 Browser* browser2 = CreateBrowser(browser()->profile()); | 178 Browser* browser2 = CreateBrowser(browser()->profile()); |
179 ResetIDs(browser2->tab_strip_model(), 100); | 179 ResetIDs(browser2->tab_strip_model(), 100); |
180 | 180 |
181 // Resize the two windows so they're right next to each other. | 181 // Resize the two windows so they're right next to each other. |
182 gfx::Rect work_area = | 182 gfx::Rect work_area = |
183 gfx::Screen::GetScreen() | 183 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
184 ->GetDisplayNearestWindow(browser()->window()->GetNativeWindow()) | |
185 .work_area(); | |
186 gfx::Size half_size = | 184 gfx::Size half_size = |
187 gfx::Size(work_area.width() / 3 - 10, work_area.height() / 2 - 10); | 185 gfx::Size(work_area.width() / 3 - 10, work_area.height() / 2 - 10); |
188 browser()->window()->SetBounds(gfx::Rect(work_area.origin(), half_size)); | 186 browser()->window()->SetBounds(gfx::Rect(work_area.origin(), half_size)); |
189 browser2->window()->SetBounds(gfx::Rect( | 187 browser2->window()->SetBounds(gfx::Rect( |
190 work_area.x() + half_size.width(), work_area.y(), | 188 work_area.x() + half_size.width(), work_area.y(), |
191 half_size.width(), half_size.height())); | 189 half_size.width(), half_size.height())); |
192 return browser2; | 190 return browser2; |
193 } | 191 } |
194 | 192 |
195 namespace { | 193 namespace { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 233 } |
236 | 234 |
237 private: | 235 private: |
238 aura::Window* root_window_; | 236 aura::Window* root_window_; |
239 | 237 |
240 DISALLOW_COPY_AND_ASSIGN(ScreenEventGeneratorDelegate); | 238 DISALLOW_COPY_AND_ASSIGN(ScreenEventGeneratorDelegate); |
241 }; | 239 }; |
242 | 240 |
243 #endif | 241 #endif |
244 | 242 |
245 #if !defined(OS_CHROMEOS) | 243 #if !defined(OS_CHROMEOS) && defined(USE_AURA) |
246 | 244 |
247 // Following classes verify a crash scenario. Specifically on Windows when focus | 245 // 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 | 246 // 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 | 247 // dragging as it wasn't set up to handle this scenario. These classes |
250 // synthesize this scenario. | 248 // synthesize this scenario. |
251 | 249 |
252 // Allows making ClearNativeFocus() invoke ReleaseCapture(). | 250 // Allows making ClearNativeFocus() invoke ReleaseCapture(). |
253 class TestDesktopBrowserFrameAura : public DesktopBrowserFrameAura { | 251 class TestDesktopBrowserFrameAura : public DesktopBrowserFrameAura { |
254 public: | 252 public: |
255 TestDesktopBrowserFrameAura( | 253 TestDesktopBrowserFrameAura( |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 #define MAYBE_DetachFromFullsizeWindow DISABLED_DetachFromFullsizeWindow | 792 #define MAYBE_DetachFromFullsizeWindow DISABLED_DetachFromFullsizeWindow |
795 #else | 793 #else |
796 #define MAYBE_DetachFromFullsizeWindow DetachFromFullsizeWindow | 794 #define MAYBE_DetachFromFullsizeWindow DetachFromFullsizeWindow |
797 #endif | 795 #endif |
798 // Tests that a tab can be dragged from a browser window that is resized to full | 796 // Tests that a tab can be dragged from a browser window that is resized to full |
799 // screen. | 797 // screen. |
800 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | 798 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, |
801 MAYBE_DetachFromFullsizeWindow) { | 799 MAYBE_DetachFromFullsizeWindow) { |
802 // Resize the browser window so that it is as big as the work area. | 800 // Resize the browser window so that it is as big as the work area. |
803 gfx::Rect work_area = | 801 gfx::Rect work_area = |
804 gfx::Screen::GetScreen() | 802 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
805 ->GetDisplayNearestWindow(browser()->window()->GetNativeWindow()) | |
806 .work_area(); | |
807 browser()->window()->SetBounds(work_area); | 803 browser()->window()->SetBounds(work_area); |
808 const gfx::Rect initial_bounds(browser()->window()->GetBounds()); | 804 const gfx::Rect initial_bounds(browser()->window()->GetBounds()); |
809 // Add another tab. | 805 // Add another tab. |
810 AddTabAndResetBrowser(browser()); | 806 AddTabAndResetBrowser(browser()); |
811 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 807 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
812 | 808 |
813 // Move to the first tab and drag it enough so that it detaches. | 809 // 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))); | 810 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
815 ASSERT_TRUE(PressInput(tab_0_center)); | 811 ASSERT_TRUE(PressInput(tab_0_center)); |
816 ASSERT_TRUE(DragInputToNotifyWhenDone( | 812 ASSERT_TRUE(DragInputToNotifyWhenDone( |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 #else | 1151 #else |
1156 #define MAYBE_DragAll DragAll | 1152 #define MAYBE_DragAll DragAll |
1157 #endif | 1153 #endif |
1158 // Selects multiple tabs and starts dragging the window. | 1154 // Selects multiple tabs and starts dragging the window. |
1159 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, MAYBE_DragAll) { | 1155 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, MAYBE_DragAll) { |
1160 // Add another tab. | 1156 // Add another tab. |
1161 AddTabAndResetBrowser(browser()); | 1157 AddTabAndResetBrowser(browser()); |
1162 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 1158 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
1163 browser()->tab_strip_model()->AddTabAtToSelection(0); | 1159 browser()->tab_strip_model()->AddTabAtToSelection(0); |
1164 browser()->tab_strip_model()->AddTabAtToSelection(1); | 1160 browser()->tab_strip_model()->AddTabAtToSelection(1); |
| 1161 const gfx::Rect initial_bounds = browser()->window()->GetBounds(); |
1165 | 1162 |
1166 // Move to the first tab and drag it enough so that it would normally | 1163 // Move to the first tab and drag it enough so that it would normally |
1167 // detach. | 1164 // detach. |
1168 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | 1165 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
1169 ASSERT_TRUE(PressInput(tab_0_center)); | 1166 ASSERT_TRUE(PressInput(tab_0_center)); |
1170 ASSERT_TRUE(DragInputToNotifyWhenDone( | 1167 ASSERT_TRUE(DragInputToNotifyWhenDone( |
1171 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), | 1168 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), |
1172 base::Bind(&DragAllStep2, this, browser_list))); | 1169 base::Bind(&DragAllStep2, this, browser_list))); |
1173 QuitWhenNotDragging(); | 1170 QuitWhenNotDragging(); |
1174 | 1171 |
1175 // Should not be dragging. | 1172 // Should not be dragging. |
1176 ASSERT_FALSE(tab_strip->IsDragSessionActive()); | 1173 ASSERT_FALSE(tab_strip->IsDragSessionActive()); |
1177 ASSERT_FALSE(TabDragController::IsActive()); | 1174 ASSERT_FALSE(TabDragController::IsActive()); |
1178 | 1175 |
1179 // And there should only be one window. | 1176 // And there should only be one window. |
1180 EXPECT_EQ(1u, browser_list->size()); | 1177 EXPECT_EQ(1u, browser_list->size()); |
1181 | 1178 |
1182 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model())); | 1179 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model())); |
1183 | 1180 |
1184 EXPECT_FALSE(GetIsDragged(browser())); | 1181 EXPECT_FALSE(GetIsDragged(browser())); |
1185 | 1182 |
1186 // Remaining browser window should not be maximized | 1183 // Remaining browser window should not be maximized |
1187 EXPECT_FALSE(browser()->window()->IsMaximized()); | 1184 EXPECT_FALSE(browser()->window()->IsMaximized()); |
| 1185 |
| 1186 const gfx::Rect final_bounds = browser()->window()->GetBounds(); |
| 1187 EXPECT_EQ(initial_bounds.size(), final_bounds.size()); |
| 1188 EXPECT_EQ(initial_bounds.origin().x(), final_bounds.origin().x()); |
| 1189 EXPECT_EQ(initial_bounds.origin().y() + GetDetachY(tab_strip), |
| 1190 final_bounds.origin().y()); |
1188 } | 1191 } |
1189 | 1192 |
| 1193 #if defined(OS_MACOSX) |
| 1194 // Makes sure we can drag the window using WindowServer by dragging on a tab. |
| 1195 // |
| 1196 // All other tests move the windows without relying on the WindowServer, because |
| 1197 // BridgedNativeWidget::RunMoveLoop() immediately offsets the window on first |
| 1198 // mouse drag. If we generate more mouse move events after that, it's presumed |
| 1199 // that the WindowServer will move the window. In order for that to work we need |
| 1200 // to generate global CGEvents instead of app-specific NSEvents, that's what |
| 1201 // ui_test_utils::DragAndDrop() is for. |
| 1202 // |
| 1203 // If the WindowServer fails to move the window, the final window bounds won't |
| 1204 // match the expected ones. |
| 1205 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, |
| 1206 DragsWindowUsingCocoaMoveLoop) { |
| 1207 // Add another tab. |
| 1208 AddTabAndResetBrowser(browser()); |
| 1209 |
| 1210 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 1211 browser()->tab_strip_model()->AddTabAtToSelection(0); |
| 1212 browser()->tab_strip_model()->AddTabAtToSelection(1); |
| 1213 const gfx::Rect initial_bounds = browser()->window()->GetBounds(); |
| 1214 |
| 1215 // Move to the first tab and drag it enough so that it would normally |
| 1216 // detach. |
| 1217 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
| 1218 |
| 1219 // If we don't make the interactive_ui_tests the active application, we won't |
| 1220 // be able to monitor NSMouseMoved events and ui_test_utils::DragAndDrop() |
| 1221 // will deadlock. |
| 1222 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 1223 |
| 1224 // We need to move the window using multiple intermediate events in order |
| 1225 // to verify that CocoaWindowMoveLoop is working correctly. |
| 1226 const int steps = 10; |
| 1227 ui_test_utils::DragAndDrop( |
| 1228 tab_0_center, |
| 1229 gfx::Point(tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip)), |
| 1230 steps); |
| 1231 |
| 1232 // Should not be dragging. |
| 1233 EXPECT_FALSE(tab_strip->IsDragSessionActive()); |
| 1234 EXPECT_FALSE(TabDragController::IsActive()); |
| 1235 |
| 1236 // And there should only be one window. |
| 1237 EXPECT_EQ(1u, browser_list->size()); |
| 1238 |
| 1239 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model())); |
| 1240 |
| 1241 EXPECT_FALSE(GetIsDragged(browser())); |
| 1242 |
| 1243 // Remaining browser window should not be maximized |
| 1244 EXPECT_FALSE(browser()->window()->IsMaximized()); |
| 1245 |
| 1246 const gfx::Rect final_bounds = browser()->window()->GetBounds(); |
| 1247 EXPECT_EQ(initial_bounds.size(), final_bounds.size()); |
| 1248 EXPECT_EQ(initial_bounds.origin().x(), final_bounds.origin().x()); |
| 1249 EXPECT_EQ(initial_bounds.origin().y() + GetDetachY(tab_strip), |
| 1250 final_bounds.origin().y()); |
| 1251 } |
| 1252 #endif // OS_MACOSX |
| 1253 |
1190 namespace { | 1254 namespace { |
1191 | 1255 |
1192 // Invoked from the nested message loop. | 1256 // Invoked from the nested message loop. |
1193 void DragAllToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test, | 1257 void DragAllToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test, |
1194 TabStrip* attached_tab_strip, | 1258 TabStrip* attached_tab_strip, |
1195 TabStrip* target_tab_strip, | 1259 TabStrip* target_tab_strip, |
1196 const BrowserList* browser_list) { | 1260 const BrowserList* browser_list) { |
1197 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive()); | 1261 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive()); |
1198 ASSERT_FALSE(target_tab_strip->IsDragSessionActive()); | 1262 ASSERT_FALSE(target_tab_strip->IsDragSessionActive()); |
1199 ASSERT_TRUE(TabDragController::IsActive()); | 1263 ASSERT_TRUE(TabDragController::IsActive()); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 MAYBE_DragSingleTabToSeparateWindow) { | 1472 MAYBE_DragSingleTabToSeparateWindow) { |
1409 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 1473 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
1410 | 1474 |
1411 ResetIDs(browser()->tab_strip_model(), 0); | 1475 ResetIDs(browser()->tab_strip_model(), 0); |
1412 | 1476 |
1413 // Create another browser. | 1477 // Create another browser. |
1414 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout(); | 1478 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout(); |
1415 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2); | 1479 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2); |
1416 const gfx::Rect initial_bounds(browser2->window()->GetBounds()); | 1480 const gfx::Rect initial_bounds(browser2->window()->GetBounds()); |
1417 | 1481 |
| 1482 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 1483 |
1418 // Move to the first tab and drag it enough so that it detaches, but not | 1484 // Move to the first tab and drag it enough so that it detaches, but not |
1419 // enough that it attaches to browser2. | 1485 // enough that it attaches to browser2. |
1420 gfx::Point tab_0_center( | 1486 gfx::Point tab_0_center( |
1421 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | 1487 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
1422 ASSERT_TRUE(PressInput(tab_0_center)); | 1488 ASSERT_TRUE(PressInput(tab_0_center)); |
1423 ASSERT_TRUE(DragInputToNotifyWhenDone( | 1489 ASSERT_TRUE(DragInputToNotifyWhenDone( |
1424 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), | 1490 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), |
1425 base::Bind(&DragAllToSeparateWindowStep2, this, tab_strip, tab_strip2, | 1491 base::Bind(&DragAllToSeparateWindowStep2, this, tab_strip, tab_strip2, |
1426 browser_list))); | 1492 browser_list))); |
1427 QuitWhenNotDragging(); | 1493 QuitWhenNotDragging(); |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2351 DetachToBrowserTabDragControllerTest, | 2417 DetachToBrowserTabDragControllerTest, |
2352 ::testing::Values("mouse", "touch")); | 2418 ::testing::Values("mouse", "touch")); |
2353 INSTANTIATE_TEST_CASE_P(TabDragging, | 2419 INSTANTIATE_TEST_CASE_P(TabDragging, |
2354 DetachToBrowserTabDragControllerTestTouch, | 2420 DetachToBrowserTabDragControllerTestTouch, |
2355 ::testing::Values("touch")); | 2421 ::testing::Values("touch")); |
2356 #else | 2422 #else |
2357 INSTANTIATE_TEST_CASE_P(TabDragging, | 2423 INSTANTIATE_TEST_CASE_P(TabDragging, |
2358 DetachToBrowserTabDragControllerTest, | 2424 DetachToBrowserTabDragControllerTest, |
2359 ::testing::Values("mouse")); | 2425 ::testing::Values("mouse")); |
2360 #endif | 2426 #endif |
OLD | NEW |