Chromium Code Reviews| 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 |
| 11 #include "ash/wm/window_state.h" | 11 #include "ash/wm/window_state.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/platform_util.h" | |
| 20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
| 22 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/browser/ui/browser_tabstrip.h" | 24 #include "chrome/browser/ui/browser_tabstrip.h" |
| 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 25 #include "chrome/browser/ui/views/frame/browser_view.h" | 26 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 26 #include "chrome/browser/ui/views/frame/native_browser_frame_factory.h" | 27 #include "chrome/browser/ui/views/frame/native_browser_frame_factory.h" |
| 27 #include "chrome/browser/ui/views/tabs/tab.h" | 28 #include "chrome/browser/ui/views/tabs/tab.h" |
| 28 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h" | 29 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h" |
| 29 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 30 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 } | 165 } |
| 165 | 166 |
| 166 void TabDragControllerTest::StopAnimating(TabStrip* tab_strip) { | 167 void TabDragControllerTest::StopAnimating(TabStrip* tab_strip) { |
| 167 tab_strip->StopAnimating(true); | 168 tab_strip->StopAnimating(true); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void TabDragControllerTest::AddTabAndResetBrowser(Browser* browser) { | 171 void TabDragControllerTest::AddTabAndResetBrowser(Browser* browser) { |
| 171 AddBlankTabAndShow(browser); | 172 AddBlankTabAndShow(browser); |
| 172 StopAnimating(GetTabStripForBrowser(browser)); | 173 StopAnimating(GetTabStripForBrowser(browser)); |
| 173 ResetIDs(browser->tab_strip_model(), 0); | 174 ResetIDs(browser->tab_strip_model(), 0); |
| 175 #if defined(OS_MACOSX) | |
| 176 // Currently MacViews' browser windows are shown in the background anc could | |
| 177 // be obscured by other windows if there are any. This should be fixed in | |
| 178 // order to be consistent with other platforms. | |
| 179 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser)); | |
|
tapted
2016/04/13 08:28:12
Let's move this to TabDragControllerTest::SetUpOnM
themblsha
2016/04/18 09:30:00
Done.
| |
| 180 #endif // OS_MACOSX | |
| 174 } | 181 } |
| 175 | 182 |
| 176 Browser* TabDragControllerTest::CreateAnotherWindowBrowserAndRelayout() { | 183 Browser* TabDragControllerTest::CreateAnotherWindowBrowserAndRelayout() { |
| 177 // Create another browser. | 184 // Create another browser. |
| 178 Browser* browser2 = CreateBrowser(browser()->profile()); | 185 Browser* browser2 = CreateBrowser(browser()->profile()); |
| 179 ResetIDs(browser2->tab_strip_model(), 100); | 186 ResetIDs(browser2->tab_strip_model(), 100); |
| 180 | 187 |
| 181 // Resize the two windows so they're right next to each other. | 188 // Resize the two windows so they're right next to each other. |
| 182 gfx::Rect work_area = | 189 gfx::Rect work_area = |
| 183 gfx::Screen::GetScreen() | 190 gfx::Screen::GetScreen() |
| 184 ->GetDisplayNearestWindow(browser()->window()->GetNativeWindow()) | 191 ->GetDisplayNearestWindow(platform_util::GetViewForWindow( |
| 192 browser()->window()->GetNativeWindow())) | |
| 185 .work_area(); | 193 .work_area(); |
| 186 gfx::Size half_size = | 194 gfx::Size half_size = |
| 187 gfx::Size(work_area.width() / 3 - 10, work_area.height() / 2 - 10); | 195 gfx::Size(work_area.width() / 3 - 10, work_area.height() / 2 - 10); |
| 188 browser()->window()->SetBounds(gfx::Rect(work_area.origin(), half_size)); | 196 browser()->window()->SetBounds(gfx::Rect(work_area.origin(), half_size)); |
| 189 browser2->window()->SetBounds(gfx::Rect( | 197 browser2->window()->SetBounds(gfx::Rect( |
| 190 work_area.x() + half_size.width(), work_area.y(), | 198 work_area.x() + half_size.width(), work_area.y(), |
| 191 half_size.width(), half_size.height())); | 199 half_size.width(), half_size.height())); |
| 192 return browser2; | 200 return browser2; |
| 193 } | 201 } |
| 194 | 202 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 } | 250 } |
| 243 | 251 |
| 244 private: | 252 private: |
| 245 aura::Window* root_window_; | 253 aura::Window* root_window_; |
| 246 | 254 |
| 247 DISALLOW_COPY_AND_ASSIGN(ScreenEventGeneratorDelegate); | 255 DISALLOW_COPY_AND_ASSIGN(ScreenEventGeneratorDelegate); |
| 248 }; | 256 }; |
| 249 | 257 |
| 250 #endif | 258 #endif |
| 251 | 259 |
| 252 #if !defined(OS_CHROMEOS) | 260 #if !defined(OS_CHROMEOS) && defined(USE_AURA) |
| 253 | 261 |
| 254 // Following classes verify a crash scenario. Specifically on Windows when focus | 262 // Following classes verify a crash scenario. Specifically on Windows when focus |
| 255 // changes it can trigger capture being lost. This was causing a crash in tab | 263 // changes it can trigger capture being lost. This was causing a crash in tab |
| 256 // dragging as it wasn't set up to handle this scenario. These classes | 264 // dragging as it wasn't set up to handle this scenario. These classes |
| 257 // synthesize this scenario. | 265 // synthesize this scenario. |
| 258 | 266 |
| 259 // Allows making ClearNativeFocus() invoke ReleaseCapture(). | 267 // Allows making ClearNativeFocus() invoke ReleaseCapture(). |
| 260 class TestDesktopBrowserFrameAura : public DesktopBrowserFrameAura { | 268 class TestDesktopBrowserFrameAura : public DesktopBrowserFrameAura { |
| 261 public: | 269 public: |
| 262 TestDesktopBrowserFrameAura( | 270 TestDesktopBrowserFrameAura( |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 855 #else | 863 #else |
| 856 #define MAYBE_DetachFromFullsizeWindow DetachFromFullsizeWindow | 864 #define MAYBE_DetachFromFullsizeWindow DetachFromFullsizeWindow |
| 857 #endif | 865 #endif |
| 858 // Tests that a tab can be dragged from a browser window that is resized to full | 866 // Tests that a tab can be dragged from a browser window that is resized to full |
| 859 // screen. | 867 // screen. |
| 860 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | 868 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, |
| 861 MAYBE_DetachFromFullsizeWindow) { | 869 MAYBE_DetachFromFullsizeWindow) { |
| 862 // Resize the browser window so that it is as big as the work area. | 870 // Resize the browser window so that it is as big as the work area. |
| 863 gfx::Rect work_area = | 871 gfx::Rect work_area = |
| 864 gfx::Screen::GetScreen() | 872 gfx::Screen::GetScreen() |
| 865 ->GetDisplayNearestWindow(browser()->window()->GetNativeWindow()) | 873 ->GetDisplayNearestWindow(platform_util::GetViewForWindow( |
| 874 browser()->window()->GetNativeWindow())) | |
| 866 .work_area(); | 875 .work_area(); |
| 867 browser()->window()->SetBounds(work_area); | 876 browser()->window()->SetBounds(work_area); |
| 868 const gfx::Rect initial_bounds(browser()->window()->GetBounds()); | 877 const gfx::Rect initial_bounds(browser()->window()->GetBounds()); |
| 869 // Add another tab. | 878 // Add another tab. |
| 870 AddTabAndResetBrowser(browser()); | 879 AddTabAndResetBrowser(browser()); |
| 871 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 880 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 872 | 881 |
| 873 // Move to the first tab and drag it enough so that it detaches. | 882 // Move to the first tab and drag it enough so that it detaches. |
| 874 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | 883 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
| 875 ASSERT_TRUE(PressInput(tab_0_center)); | 884 ASSERT_TRUE(PressInput(tab_0_center)); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 901 | 910 |
| 902 EXPECT_FALSE(GetIsDragged(browser())); | 911 EXPECT_FALSE(GetIsDragged(browser())); |
| 903 EXPECT_FALSE(GetIsDragged(new_browser)); | 912 EXPECT_FALSE(GetIsDragged(new_browser)); |
| 904 // After this both windows should still be manageable. | 913 // After this both windows should still be manageable. |
| 905 EXPECT_TRUE(IsWindowPositionManaged(browser()->window()->GetNativeWindow())); | 914 EXPECT_TRUE(IsWindowPositionManaged(browser()->window()->GetNativeWindow())); |
| 906 EXPECT_TRUE( | 915 EXPECT_TRUE( |
| 907 IsWindowPositionManaged(new_browser->window()->GetNativeWindow())); | 916 IsWindowPositionManaged(new_browser->window()->GetNativeWindow())); |
| 908 | 917 |
| 909 // Only second window should be maximized. | 918 // Only second window should be maximized. |
| 910 EXPECT_FALSE(browser()->window()->IsMaximized()); | 919 EXPECT_FALSE(browser()->window()->IsMaximized()); |
| 911 EXPECT_TRUE(new_browser->window()->IsMaximized()); | 920 EXPECT_TRUE(new_browser->window()->IsMaximized()); |
|
tapted
2016/04/13 08:28:12
this will fail on Mac (likewise a similar check on
themblsha
2016/04/18 09:30:00
Yeah, the two test that fail deal with maximizatio
| |
| 912 | 921 |
| 913 // The tab strip should no longer have capture because the drag was ended and | 922 // The tab strip should no longer have capture because the drag was ended and |
| 914 // mouse/touch was released. | 923 // mouse/touch was released. |
| 915 EXPECT_FALSE(tab_strip->GetWidget()->HasCapture()); | 924 EXPECT_FALSE(tab_strip->GetWidget()->HasCapture()); |
| 916 EXPECT_FALSE(tab_strip2->GetWidget()->HasCapture()); | 925 EXPECT_FALSE(tab_strip2->GetWidget()->HasCapture()); |
| 917 } | 926 } |
| 918 | 927 |
| 919 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 928 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 920 // TODO(sky,sad): Disabled as it fails due to resize locks with a real | 929 // TODO(sky,sad): Disabled as it fails due to resize locks with a real |
| 921 // compositor. crbug.com/331924 | 930 // compositor. crbug.com/331924 |
| 922 #define MAYBE_DetachToOwnWindowFromMaximizedWindow \ | 931 #define MAYBE_DetachToOwnWindowFromMaximizedWindow \ |
| 923 DISABLED_DetachToOwnWindowFromMaximizedWindow | 932 DISABLED_DetachToOwnWindowFromMaximizedWindow |
| 924 #else | 933 #else |
| 925 #define MAYBE_DetachToOwnWindowFromMaximizedWindow \ | 934 #define MAYBE_DetachToOwnWindowFromMaximizedWindow \ |
| 926 DetachToOwnWindowFromMaximizedWindow | 935 DetachToOwnWindowFromMaximizedWindow |
| 927 #endif | 936 #endif |
| 928 // Drags from browser to a separate window and releases mouse. | 937 // Drags from browser to a separate window and releases mouse. |
| 929 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | 938 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, |
| 930 MAYBE_DetachToOwnWindowFromMaximizedWindow) { | 939 MAYBE_DetachToOwnWindowFromMaximizedWindow) { |
| 931 // Maximize the initial browser window. | 940 // Maximize the initial browser window. |
| 932 browser()->window()->Maximize(); | 941 browser()->window()->Maximize(); |
| 933 ASSERT_TRUE(browser()->window()->IsMaximized()); | 942 ASSERT_TRUE(browser()->window()->IsMaximized()); |
|
tapted
2016/04/13 08:28:12
fails - I think here this entire test can be can b
themblsha
2016/04/18 09:30:00
Done.
| |
| 934 | 943 |
| 935 // Add another tab. | 944 // Add another tab. |
| 936 AddTabAndResetBrowser(browser()); | 945 AddTabAndResetBrowser(browser()); |
| 937 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 946 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 938 | 947 |
| 939 // Move to the first tab and drag it enough so that it detaches. | 948 // Move to the first tab and drag it enough so that it detaches. |
| 940 gfx::Point tab_0_center( | 949 gfx::Point tab_0_center( |
| 941 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | 950 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
| 942 ASSERT_TRUE(PressInput(tab_0_center)); | 951 ASSERT_TRUE(PressInput(tab_0_center)); |
| 943 ASSERT_TRUE(DragInputToNotifyWhenDone( | 952 ASSERT_TRUE(DragInputToNotifyWhenDone( |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1215 #else | 1224 #else |
| 1216 #define MAYBE_DragAll DragAll | 1225 #define MAYBE_DragAll DragAll |
| 1217 #endif | 1226 #endif |
| 1218 // Selects multiple tabs and starts dragging the window. | 1227 // Selects multiple tabs and starts dragging the window. |
| 1219 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, MAYBE_DragAll) { | 1228 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, MAYBE_DragAll) { |
| 1220 // Add another tab. | 1229 // Add another tab. |
| 1221 AddTabAndResetBrowser(browser()); | 1230 AddTabAndResetBrowser(browser()); |
| 1222 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 1231 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 1223 browser()->tab_strip_model()->AddTabAtToSelection(0); | 1232 browser()->tab_strip_model()->AddTabAtToSelection(0); |
| 1224 browser()->tab_strip_model()->AddTabAtToSelection(1); | 1233 browser()->tab_strip_model()->AddTabAtToSelection(1); |
| 1234 const gfx::Rect initial_bounds = browser()->window()->GetBounds(); | |
| 1225 | 1235 |
| 1226 // Move to the first tab and drag it enough so that it would normally | 1236 // Move to the first tab and drag it enough so that it would normally |
| 1227 // detach. | 1237 // detach. |
| 1228 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | 1238 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
| 1229 ASSERT_TRUE(PressInput(tab_0_center)); | 1239 ASSERT_TRUE(PressInput(tab_0_center)); |
| 1230 ASSERT_TRUE(DragInputToNotifyWhenDone( | 1240 ASSERT_TRUE(DragInputToNotifyWhenDone( |
| 1231 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), | 1241 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), |
| 1232 base::Bind(&DragAllStep2, this, browser_list))); | 1242 base::Bind(&DragAllStep2, this, browser_list))); |
| 1233 QuitWhenNotDragging(); | 1243 QuitWhenNotDragging(); |
| 1234 | 1244 |
| 1235 // Should not be dragging. | 1245 // Should not be dragging. |
| 1236 ASSERT_FALSE(tab_strip->IsDragSessionActive()); | 1246 ASSERT_FALSE(tab_strip->IsDragSessionActive()); |
| 1237 ASSERT_FALSE(TabDragController::IsActive()); | 1247 ASSERT_FALSE(TabDragController::IsActive()); |
| 1238 | 1248 |
| 1239 // And there should only be one window. | 1249 // And there should only be one window. |
| 1240 EXPECT_EQ(1u, browser_list->size()); | 1250 EXPECT_EQ(1u, browser_list->size()); |
| 1241 | 1251 |
| 1242 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model())); | 1252 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model())); |
| 1243 | 1253 |
| 1244 EXPECT_FALSE(GetIsDragged(browser())); | 1254 EXPECT_FALSE(GetIsDragged(browser())); |
| 1245 | 1255 |
| 1246 // Remaining browser window should not be maximized | 1256 // Remaining browser window should not be maximized |
| 1247 EXPECT_FALSE(browser()->window()->IsMaximized()); | 1257 EXPECT_FALSE(browser()->window()->IsMaximized()); |
| 1258 | |
| 1259 const gfx::Rect final_bounds = browser()->window()->GetBounds(); | |
|
tapted
2016/04/13 08:28:12
Comment ~
// Size unchanged, but it should have m
themblsha
2016/04/18 09:30:01
Done.
| |
| 1260 EXPECT_EQ(initial_bounds.size(), final_bounds.size()); | |
| 1261 EXPECT_EQ(initial_bounds.origin().x(), final_bounds.origin().x()); | |
| 1262 EXPECT_EQ(initial_bounds.origin().y() + GetDetachY(tab_strip), | |
| 1263 final_bounds.origin().y()); | |
| 1248 } | 1264 } |
| 1249 | 1265 |
| 1266 #if defined(OS_MACOSX) | |
| 1267 // Makes sure we can drag the window using WindowServer by dragging on a tab. | |
| 1268 // | |
| 1269 // All other tests move the windows without relying on the WindowServer, because | |
| 1270 // BridgedNativeWidget::RunMoveLoop() immediately offsets the window on first | |
| 1271 // mouse drag. If we generate more mouse move events after that, it's presumed | |
| 1272 // that the WindowServer will move the window. In order for that to work we need | |
| 1273 // to generate global CGEvents instead of app-specific NSEvents, that's what | |
| 1274 // ui_test_utils::DragAndDrop() is for. | |
| 1275 // | |
|
tapted
2016/04/13 08:28:12
Perhaps a note here, since it will be confusing fo
themblsha
2016/04/18 09:30:01
Done.
| |
| 1276 // If the WindowServer fails to move the window, the final window bounds won't | |
| 1277 // match the expected ones. | |
| 1278 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | |
|
tapted
2016/04/13 08:28:12
A comment specific to this test?
E.g.
// Test d
themblsha
2016/04/18 09:30:01
Done.
| |
| 1279 MacDragsWindowUsingCocoaMoveLoop) { | |
| 1280 // Add another tab. | |
| 1281 AddTabAndResetBrowser(browser()); | |
| 1282 | |
| 1283 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | |
| 1284 browser()->tab_strip_model()->AddTabAtToSelection(0); | |
| 1285 browser()->tab_strip_model()->AddTabAtToSelection(1); | |
| 1286 const gfx::Rect initial_bounds = browser()->window()->GetBounds(); | |
| 1287 | |
| 1288 // Move to the first tab and drag it enough so that it would normally | |
| 1289 // detach. | |
| 1290 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | |
| 1291 | |
| 1292 // If we don't make the interactive_ui_tests the active application, we won't | |
| 1293 // be able to monitor NSMouseMoved events and ui_test_utils::DragAndDrop() | |
| 1294 // will deadlock. | |
| 1295 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 1296 | |
| 1297 // We need to move the window using multiple intermediate events in order | |
| 1298 // to verify that CocoaWindowMoveLoop is working correctly. | |
| 1299 const int steps = 10; | |
| 1300 ui_test_utils::DragAndDrop( | |
| 1301 tab_0_center, | |
| 1302 gfx::Point(tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip)), | |
| 1303 steps); | |
| 1304 | |
| 1305 // Should not be dragging. | |
| 1306 EXPECT_FALSE(tab_strip->IsDragSessionActive()); | |
| 1307 EXPECT_FALSE(TabDragController::IsActive()); | |
| 1308 EXPECT_FALSE(GetIsDragged(browser())); | |
| 1309 | |
| 1310 // And there should only be one window. | |
| 1311 EXPECT_EQ(1u, browser_list->size()); | |
| 1312 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model())); | |
| 1313 | |
| 1314 // Remaining browser window should not be maximized | |
| 1315 EXPECT_FALSE(browser()->window()->IsMaximized()); | |
| 1316 | |
| 1317 const gfx::Rect final_bounds = browser()->window()->GetBounds(); | |
| 1318 EXPECT_EQ(initial_bounds.size(), final_bounds.size()); | |
| 1319 EXPECT_EQ(initial_bounds.origin().x(), final_bounds.origin().x()); | |
| 1320 EXPECT_EQ(initial_bounds.origin().y() + GetDetachY(tab_strip), | |
| 1321 final_bounds.origin().y()); | |
| 1322 } | |
| 1323 | |
| 1324 // Tests that when the first mouse event that starts RunMoveLoop does not | |
| 1325 // overlap the Mac menu bar. BridgedNativeWidget::RunMoveLoop() shifts both the | |
| 1326 // mouse position and the expected window frame after detachment. | |
| 1327 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | |
| 1328 MacDetachesWindowOnTopOfMacMenuBar) { | |
| 1329 // Add another tab. | |
| 1330 AddTabAndResetBrowser(browser()); | |
| 1331 | |
| 1332 // Make sure there's enough space to trigger detachment. | |
| 1333 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | |
| 1334 browser()->window()->SetBounds(gfx::Rect(100, 100, 400, 200)); | |
| 1335 DCHECK_GT(browser()->window()->GetBounds().y(), GetDetachY(tab_strip)); | |
| 1336 | |
| 1337 // If we don't make the interactive_ui_tests the active application, we won't | |
| 1338 // be able to monitor NSMouseMoved events and ui_test_utils::DragAndDrop() | |
| 1339 // will deadlock. | |
| 1340 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 1341 | |
| 1342 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | |
| 1343 gfx::Point on_top_of_menu_bar(tab_0_center.x(), 0); | |
| 1344 ui_test_utils::DragAndDrop(tab_0_center, on_top_of_menu_bar); | |
|
tapted
2016/04/13 08:28:12
using a sequence of DragAndDropOperation in place
themblsha
2016/04/18 09:30:01
Added additional check to my code:
EXPECT_GE(wo
tapted
2016/04/20 07:30:22
On one of them :).
If you run two screens side-by
themblsha
2016/04/20 13:38:40
Curiously enough, your test only passes when I hav
| |
| 1345 | |
| 1346 // Should not be dragging. | |
| 1347 EXPECT_FALSE(tab_strip->IsDragSessionActive()); | |
| 1348 EXPECT_FALSE(TabDragController::IsActive()); | |
| 1349 EXPECT_FALSE(GetIsDragged(browser())); | |
| 1350 | |
| 1351 // Second tab should successfully detach. | |
| 1352 EXPECT_EQ(2u, browser_list->size()); | |
| 1353 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); | |
| 1354 } | |
| 1355 | |
| 1356 // Detaches and reattaches second tab. Will fail if detached window is not moved | |
| 1357 // synchronously at the start of BridgedNativeWidget::RunMoveLoop(): the check | |
| 1358 // for expected WindowServerFrame() will fail. | |
| 1359 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | |
| 1360 MacDetachesAndReattachesSecondTab) { | |
| 1361 using namespace ui_test_utils; | |
|
tapted
2016/04/13 08:28:12
nit: using ui_test_utils::DragAndDropOperation, an
themblsha
2016/04/18 09:30:01
Done.
| |
| 1362 | |
| 1363 // Add another tab. | |
| 1364 AddTabAndResetBrowser(browser()); | |
| 1365 | |
| 1366 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | |
| 1367 browser()->window()->SetBounds(gfx::Rect(100, 100, 400, 200)); | |
| 1368 const gfx::Rect initial_bounds = browser()->window()->GetBounds(); | |
| 1369 | |
| 1370 gfx::Point tab_1_center(GetCenterInScreenCoordinates(tab_strip->tab_at(1))); | |
| 1371 gfx::Point tab_1_shake(tab_1_center.x(), | |
| 1372 tab_1_center.y() + GetDetachY(tab_strip) * 2); | |
| 1373 | |
| 1374 // If we don't make the interactive_ui_tests the active application, we won't | |
| 1375 // be able to monitor NSMouseMoved events and ui_test_utils::DragAndDrop() | |
| 1376 // will deadlock. | |
|
tapted
2016/04/13 08:28:12
nit: this comment doesn't need to repeat
themblsha
2016/04/18 09:30:01
Done.
| |
| 1377 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 1378 | |
| 1379 std::list<DragAndDropOperation> operations; | |
| 1380 operations.emplace_back(DragAndDropOperation::Move(tab_1_center)); | |
|
tapted
2016/04/13 08:28:12
The rule at Google is to use push_back unless that
themblsha
2016/04/18 09:30:00
Done. Style Guide is absolute :-)
| |
| 1381 operations.emplace_back(DragAndDropOperation::MouseDown()); | |
| 1382 operations.emplace_back(DragAndDropOperation::Move(tab_1_shake)); | |
| 1383 operations.emplace_back(DragAndDropOperation::Move(tab_1_center)); | |
| 1384 operations.emplace_back(DragAndDropOperation::MouseUp()); | |
| 1385 | |
| 1386 ui_test_utils::DragAndDrop(operations); | |
| 1387 | |
| 1388 // Should not be dragging. | |
| 1389 EXPECT_FALSE(tab_strip->IsDragSessionActive()); | |
| 1390 EXPECT_FALSE(TabDragController::IsActive()); | |
| 1391 EXPECT_FALSE(GetIsDragged(browser())); | |
| 1392 | |
| 1393 // And there should only be one window. | |
| 1394 EXPECT_EQ(1u, browser_list->size()); | |
| 1395 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model())); | |
| 1396 | |
| 1397 // The window should remain in its original place. | |
| 1398 const gfx::Rect final_bounds = browser()->window()->GetBounds(); | |
| 1399 EXPECT_EQ(initial_bounds, final_bounds); | |
| 1400 } | |
| 1401 #endif // OS_MACOSX | |
| 1402 | |
| 1250 namespace { | 1403 namespace { |
| 1251 | 1404 |
| 1252 // Invoked from the nested message loop. | 1405 // Invoked from the nested message loop. |
| 1253 void DragAllToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test, | 1406 void DragAllToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test, |
| 1254 TabStrip* attached_tab_strip, | 1407 TabStrip* attached_tab_strip, |
| 1255 TabStrip* target_tab_strip, | 1408 TabStrip* target_tab_strip, |
| 1256 const BrowserList* browser_list) { | 1409 const BrowserList* browser_list) { |
| 1257 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive()); | 1410 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive()); |
| 1258 ASSERT_FALSE(target_tab_strip->IsDragSessionActive()); | 1411 ASSERT_FALSE(target_tab_strip->IsDragSessionActive()); |
| 1259 ASSERT_TRUE(TabDragController::IsActive()); | 1412 ASSERT_TRUE(TabDragController::IsActive()); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1468 MAYBE_DragSingleTabToSeparateWindow) { | 1621 MAYBE_DragSingleTabToSeparateWindow) { |
| 1469 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 1622 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 1470 | 1623 |
| 1471 ResetIDs(browser()->tab_strip_model(), 0); | 1624 ResetIDs(browser()->tab_strip_model(), 0); |
| 1472 | 1625 |
| 1473 // Create another browser. | 1626 // Create another browser. |
| 1474 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout(); | 1627 Browser* browser2 = CreateAnotherWindowBrowserAndRelayout(); |
| 1475 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2); | 1628 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2); |
| 1476 const gfx::Rect initial_bounds(browser2->window()->GetBounds()); | 1629 const gfx::Rect initial_bounds(browser2->window()->GetBounds()); |
| 1477 | 1630 |
| 1631 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 1632 | |
| 1478 // Move to the first tab and drag it enough so that it detaches, but not | 1633 // Move to the first tab and drag it enough so that it detaches, but not |
| 1479 // enough that it attaches to browser2. | 1634 // enough that it attaches to browser2. |
| 1480 gfx::Point tab_0_center( | 1635 gfx::Point tab_0_center( |
| 1481 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | 1636 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
| 1482 ASSERT_TRUE(PressInput(tab_0_center)); | 1637 ASSERT_TRUE(PressInput(tab_0_center)); |
| 1483 ASSERT_TRUE(DragInputToNotifyWhenDone( | 1638 ASSERT_TRUE(DragInputToNotifyWhenDone( |
| 1484 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), | 1639 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), |
| 1485 base::Bind(&DragAllToSeparateWindowStep2, this, tab_strip, tab_strip2, | 1640 base::Bind(&DragAllToSeparateWindowStep2, this, tab_strip, tab_strip2, |
| 1486 browser_list))); | 1641 browser_list))); |
| 1487 QuitWhenNotDragging(); | 1642 QuitWhenNotDragging(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1514 namespace { | 1669 namespace { |
| 1515 | 1670 |
| 1516 // Invoked from the nested message loop. | 1671 // Invoked from the nested message loop. |
| 1517 void CancelOnNewTabWhenDraggingStep2( | 1672 void CancelOnNewTabWhenDraggingStep2( |
| 1518 DetachToBrowserTabDragControllerTest* test, | 1673 DetachToBrowserTabDragControllerTest* test, |
| 1519 const BrowserList* browser_list) { | 1674 const BrowserList* browser_list) { |
| 1520 ASSERT_TRUE(TabDragController::IsActive()); | 1675 ASSERT_TRUE(TabDragController::IsActive()); |
| 1521 ASSERT_EQ(2u, browser_list->size()); | 1676 ASSERT_EQ(2u, browser_list->size()); |
| 1522 | 1677 |
| 1523 // Add another tab. This should trigger exiting the nested loop. Add at the | 1678 // Add another tab. This should trigger exiting the nested loop. Add at the |
| 1524 // to exercise past crash when model/tabstrip got out of sync (474082). | 1679 // to exercise past crash when model/tabstrip got out of sync (474082). |
|
tapted
2016/04/13 08:28:12
This comment should move as well, since it talks a
themblsha
2016/04/18 09:30:00
Done, thanks!
| |
| 1525 content::WindowedNotificationObserver observer( | |
| 1526 content::NOTIFICATION_LOAD_STOP, | |
| 1527 content::NotificationService::AllSources()); | |
| 1528 chrome::AddTabAt(browser_list->GetLastActive(), GURL(url::kAboutBlankURL), | 1680 chrome::AddTabAt(browser_list->GetLastActive(), GURL(url::kAboutBlankURL), |
| 1529 0, false); | 1681 0, false); |
| 1530 observer.Wait(); | |
| 1531 } | 1682 } |
| 1532 | 1683 |
| 1533 } // namespace | 1684 } // namespace |
| 1534 | 1685 |
| 1535 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 1686 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 1536 // TODO(sky,sad): Disabled as it fails due to resize locks with a real | 1687 // TODO(sky,sad): Disabled as it fails due to resize locks with a real |
| 1537 // compositor. crbug.com/331924 | 1688 // compositor. crbug.com/331924 |
| 1538 #define MAYBE_CancelOnNewTabWhenDragging DISABLED_CancelOnNewTabWhenDragging | 1689 #define MAYBE_CancelOnNewTabWhenDragging DISABLED_CancelOnNewTabWhenDragging |
| 1539 #else | 1690 #else |
| 1540 #define MAYBE_CancelOnNewTabWhenDragging CancelOnNewTabWhenDragging | 1691 #define MAYBE_CancelOnNewTabWhenDragging CancelOnNewTabWhenDragging |
| 1541 #endif | 1692 #endif |
| 1542 // Adds another tab, detaches into separate window, adds another tab and | 1693 // Adds another tab, detaches into separate window, adds another tab and |
| 1543 // verifies the run loop ends. | 1694 // verifies the run loop ends. |
| 1544 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | 1695 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, |
| 1545 MAYBE_CancelOnNewTabWhenDragging) { | 1696 MAYBE_CancelOnNewTabWhenDragging) { |
| 1546 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 1697 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 1547 | 1698 |
| 1548 // Add another tab to browser(). | 1699 // Add another tab to browser(). |
| 1549 AddTabAndResetBrowser(browser()); | 1700 AddTabAndResetBrowser(browser()); |
| 1550 | 1701 |
| 1551 // Move to the first tab and drag it enough so that it detaches. | 1702 // Move to the first tab and drag it enough so that it detaches. |
| 1552 gfx::Point tab_0_center( | 1703 gfx::Point tab_0_center( |
| 1553 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | 1704 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
| 1554 ASSERT_TRUE(PressInput(tab_0_center)); | 1705 ASSERT_TRUE(PressInput(tab_0_center)); |
| 1706 content::WindowedNotificationObserver observer( | |
| 1707 content::NOTIFICATION_LOAD_STOP, | |
| 1708 content::NotificationService::AllSources()); | |
| 1555 ASSERT_TRUE(DragInputToNotifyWhenDone( | 1709 ASSERT_TRUE(DragInputToNotifyWhenDone( |
| 1556 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), | 1710 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), |
| 1557 base::Bind(&CancelOnNewTabWhenDraggingStep2, this, browser_list))); | 1711 base::Bind(&CancelOnNewTabWhenDraggingStep2, this, browser_list))); |
| 1558 QuitWhenNotDragging(); | 1712 observer.Wait(); |
| 1713 | |
| 1714 // On MacViews the Drag ends while waiting for NOTIFICATION_LOAD_STOP. | |
|
tapted
2016/04/13 08:28:12
can you say more about this? (i.e. why it ends ear
themblsha
2016/04/18 09:30:00
Maybe after moving the stuff around it's not Mac-s
| |
| 1715 if (TabDragController::IsActive()) { | |
|
tapted
2016/04/13 08:28:12
nit: no curlies
| |
| 1716 QuitWhenNotDragging(); | |
| 1717 } | |
| 1559 | 1718 |
| 1560 // Should be two windows and not dragging. | 1719 // Should be two windows and not dragging. |
| 1561 ASSERT_FALSE(TabDragController::IsActive()); | 1720 ASSERT_FALSE(TabDragController::IsActive()); |
| 1562 ASSERT_EQ(2u, browser_list->size()); | 1721 ASSERT_EQ(2u, browser_list->size()); |
| 1563 for (auto* browser : *BrowserList::GetInstance()) { | 1722 for (auto* browser : *BrowserList::GetInstance()) { |
| 1564 EXPECT_FALSE(GetIsDragged(browser)); | 1723 EXPECT_FALSE(GetIsDragged(browser)); |
| 1565 // Should not be maximized | 1724 // Should not be maximized |
| 1566 EXPECT_FALSE(browser->window()->IsMaximized()); | 1725 EXPECT_FALSE(browser->window()->IsMaximized()); |
| 1567 } | 1726 } |
| 1568 } | 1727 } |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2134 ui_controls::DOWN); | 2293 ui_controls::DOWN); |
| 2135 } | 2294 } |
| 2136 | 2295 |
| 2137 bool DragTabAndExecuteTaskWhenDone(const gfx::Point& position, | 2296 bool DragTabAndExecuteTaskWhenDone(const gfx::Point& position, |
| 2138 const base::Closure& task) { | 2297 const base::Closure& task) { |
| 2139 return ui_controls::SendMouseMoveNotifyWhenDone( | 2298 return ui_controls::SendMouseMoveNotifyWhenDone( |
| 2140 position.x(), position.y(), task); | 2299 position.x(), position.y(), task); |
| 2141 } | 2300 } |
| 2142 | 2301 |
| 2143 void QuitWhenNotDragging() { | 2302 void QuitWhenNotDragging() { |
| 2303 DCHECK(TabDragController::IsActive()); | |
| 2144 test::QuitWhenNotDraggingImpl(); | 2304 test::QuitWhenNotDraggingImpl(); |
| 2145 base::MessageLoop::current()->Run(); | 2305 base::MessageLoop::current()->Run(); |
| 2146 } | 2306 } |
| 2147 | 2307 |
| 2148 private: | 2308 private: |
| 2149 DISALLOW_COPY_AND_ASSIGN( | 2309 DISALLOW_COPY_AND_ASSIGN( |
| 2150 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest); | 2310 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest); |
| 2151 }; | 2311 }; |
| 2152 | 2312 |
| 2153 // Invoked from the nested message loop. | 2313 // Invoked from the nested message loop. |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2411 DetachToBrowserTabDragControllerTest, | 2571 DetachToBrowserTabDragControllerTest, |
| 2412 ::testing::Values("mouse", "touch")); | 2572 ::testing::Values("mouse", "touch")); |
| 2413 INSTANTIATE_TEST_CASE_P(TabDragging, | 2573 INSTANTIATE_TEST_CASE_P(TabDragging, |
| 2414 DetachToBrowserTabDragControllerTestTouch, | 2574 DetachToBrowserTabDragControllerTestTouch, |
| 2415 ::testing::Values("touch")); | 2575 ::testing::Values("touch")); |
| 2416 #else | 2576 #else |
| 2417 INSTANTIATE_TEST_CASE_P(TabDragging, | 2577 INSTANTIATE_TEST_CASE_P(TabDragging, |
| 2418 DetachToBrowserTabDragControllerTest, | 2578 DetachToBrowserTabDragControllerTest, |
| 2419 ::testing::Values("mouse")); | 2579 ::testing::Values("mouse")); |
| 2420 #endif | 2580 #endif |
| OLD | NEW |