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 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 #include "ash/wm/window_util.h" | 61 #include "ash/wm/window_util.h" |
| 62 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 62 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
| 63 #include "ui/aura/client/screen_position_client.h" | 63 #include "ui/aura/client/screen_position_client.h" |
| 64 #include "ui/aura/test/event_generator_delegate_aura.h" | 64 #include "ui/aura/test/event_generator_delegate_aura.h" |
| 65 #include "ui/aura/window_event_dispatcher.h" | 65 #include "ui/aura/window_event_dispatcher.h" |
| 66 #include "ui/events/test/event_generator.h" | 66 #include "ui/events/test/event_generator.h" |
| 67 #endif | 67 #endif |
| 68 | 68 |
| 69 using content::WebContents; | 69 using content::WebContents; |
| 70 | 70 |
| 71 void DragAndDrop(const gfx::Point& from, | |
| 72 const gfx::Point& to, | |
| 73 base::TimeDelta delay = base::TimeDelta()) { | |
| 74 #if defined(OS_MACOSX) | |
| 75 ui_test_utils::DragAndDrop(from, to, delay); | |
| 76 #else | |
| 77 ASSERT_TRUE(PressInput(from)); | |
| 78 ASSERT_TRUE(DragInputToNotifyWhenDone(to.x(), to.y())); | |
| 79 base::Bind(&DragAllStep2, this, browser_list))); | |
| 80 QuitWhenNotDragging(); | |
| 81 #endif | |
| 82 } | |
| 83 | |
| 71 namespace test { | 84 namespace test { |
| 72 | 85 |
| 73 namespace { | 86 namespace { |
| 74 | 87 |
| 75 const char kTabDragControllerInteractiveUITestUserDataKey[] = | 88 const char kTabDragControllerInteractiveUITestUserDataKey[] = |
| 76 "TabDragControllerInteractiveUITestUserData"; | 89 "TabDragControllerInteractiveUITestUserData"; |
| 77 | 90 |
| 78 class TabDragControllerInteractiveUITestUserData | 91 class TabDragControllerInteractiveUITestUserData |
| 79 : public base::SupportsUserData::Data { | 92 : public base::SupportsUserData::Data { |
| 80 public: | 93 public: |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 } | 177 } |
| 165 | 178 |
| 166 void TabDragControllerTest::StopAnimating(TabStrip* tab_strip) { | 179 void TabDragControllerTest::StopAnimating(TabStrip* tab_strip) { |
| 167 tab_strip->StopAnimating(true); | 180 tab_strip->StopAnimating(true); |
| 168 } | 181 } |
| 169 | 182 |
| 170 void TabDragControllerTest::AddTabAndResetBrowser(Browser* browser) { | 183 void TabDragControllerTest::AddTabAndResetBrowser(Browser* browser) { |
| 171 AddBlankTabAndShow(browser); | 184 AddBlankTabAndShow(browser); |
| 172 StopAnimating(GetTabStripForBrowser(browser)); | 185 StopAnimating(GetTabStripForBrowser(browser)); |
| 173 ResetIDs(browser->tab_strip_model(), 0); | 186 ResetIDs(browser->tab_strip_model(), 0); |
| 187 | |
| 188 // On Macs if we try to drag on an inactive window it won't work. Two | |
| 189 // solutions are either to activate the window explicitly, or to click on a | |
| 190 // window once before starting dragging. | |
| 191 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser)); | |
| 174 } | 192 } |
| 175 | 193 |
| 176 Browser* TabDragControllerTest::CreateAnotherWindowBrowserAndRelayout() { | 194 Browser* TabDragControllerTest::CreateAnotherWindowBrowserAndRelayout() { |
| 177 // Create another browser. | 195 // Create another browser. |
| 178 Browser* browser2 = CreateBrowser(browser()->profile()); | 196 Browser* browser2 = CreateBrowser(browser()->profile()); |
| 179 ResetIDs(browser2->tab_strip_model(), 100); | 197 ResetIDs(browser2->tab_strip_model(), 100); |
| 180 | 198 |
| 181 // Resize the two windows so they're right next to each other. | 199 // Resize the two windows so they're right next to each other. |
| 182 gfx::Rect work_area = | 200 gfx::Rect work_area = |
| 183 gfx::Screen::GetScreen() | 201 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
| 184 ->GetDisplayNearestWindow(browser()->window()->GetNativeWindow()) | |
| 185 .work_area(); | |
| 186 gfx::Size half_size = | 202 gfx::Size half_size = |
| 187 gfx::Size(work_area.width() / 3 - 10, work_area.height() / 2 - 10); | 203 gfx::Size(work_area.width() / 3 - 10, work_area.height() / 2 - 10); |
| 188 browser()->window()->SetBounds(gfx::Rect(work_area.origin(), half_size)); | 204 browser()->window()->SetBounds(gfx::Rect(work_area.origin(), half_size)); |
| 189 browser2->window()->SetBounds(gfx::Rect( | 205 browser2->window()->SetBounds(gfx::Rect( |
| 190 work_area.x() + half_size.width(), work_area.y(), | 206 work_area.x() + half_size.width(), work_area.y(), |
| 191 half_size.width(), half_size.height())); | 207 half_size.width(), half_size.height())); |
| 192 return browser2; | 208 return browser2; |
| 193 } | 209 } |
| 194 | 210 |
| 195 namespace { | 211 namespace { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 } | 251 } |
| 236 | 252 |
| 237 private: | 253 private: |
| 238 aura::Window* root_window_; | 254 aura::Window* root_window_; |
| 239 | 255 |
| 240 DISALLOW_COPY_AND_ASSIGN(ScreenEventGeneratorDelegate); | 256 DISALLOW_COPY_AND_ASSIGN(ScreenEventGeneratorDelegate); |
| 241 }; | 257 }; |
| 242 | 258 |
| 243 #endif | 259 #endif |
| 244 | 260 |
| 245 #if !defined(OS_CHROMEOS) | 261 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX) |
| 246 | 262 |
| 247 // Following classes verify a crash scenario. Specifically on Windows when focus | 263 // 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 | 264 // 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 | 265 // dragging as it wasn't set up to handle this scenario. These classes |
| 250 // synthesize this scenario. | 266 // synthesize this scenario. |
| 251 | 267 |
| 252 // Allows making ClearNativeFocus() invoke ReleaseCapture(). | 268 // Allows making ClearNativeFocus() invoke ReleaseCapture(). |
| 253 class TestDesktopBrowserFrameAura : public DesktopBrowserFrameAura { | 269 class TestDesktopBrowserFrameAura : public DesktopBrowserFrameAura { |
| 254 public: | 270 public: |
| 255 TestDesktopBrowserFrameAura( | 271 TestDesktopBrowserFrameAura( |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 #define MAYBE_DetachFromFullsizeWindow DISABLED_DetachFromFullsizeWindow | 810 #define MAYBE_DetachFromFullsizeWindow DISABLED_DetachFromFullsizeWindow |
| 795 #else | 811 #else |
| 796 #define MAYBE_DetachFromFullsizeWindow DetachFromFullsizeWindow | 812 #define MAYBE_DetachFromFullsizeWindow DetachFromFullsizeWindow |
| 797 #endif | 813 #endif |
| 798 // Tests that a tab can be dragged from a browser window that is resized to full | 814 // Tests that a tab can be dragged from a browser window that is resized to full |
| 799 // screen. | 815 // screen. |
| 800 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | 816 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, |
| 801 MAYBE_DetachFromFullsizeWindow) { | 817 MAYBE_DetachFromFullsizeWindow) { |
| 802 // Resize the browser window so that it is as big as the work area. | 818 // Resize the browser window so that it is as big as the work area. |
| 803 gfx::Rect work_area = | 819 gfx::Rect work_area = |
| 804 gfx::Screen::GetScreen() | 820 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
|
tapted
2016/03/01 08:11:58
did GetDisplayNearestWindow() not work?
themblsha
2016/03/09 17:40:22
GetDisplayNearestWindow() expects NativeView, but
tapted
2016/03/10 11:51:18
oh weird. There's platform_util::GetViewForWindow
| |
| 805 ->GetDisplayNearestWindow(browser()->window()->GetNativeWindow()) | |
| 806 .work_area(); | |
| 807 browser()->window()->SetBounds(work_area); | 821 browser()->window()->SetBounds(work_area); |
| 808 const gfx::Rect initial_bounds(browser()->window()->GetBounds()); | 822 const gfx::Rect initial_bounds(browser()->window()->GetBounds()); |
| 809 // Add another tab. | 823 // Add another tab. |
| 810 AddTabAndResetBrowser(browser()); | 824 AddTabAndResetBrowser(browser()); |
| 811 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 825 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 812 | 826 |
| 813 // Move to the first tab and drag it enough so that it detaches. | 827 // 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))); | 828 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
| 815 ASSERT_TRUE(PressInput(tab_0_center)); | 829 ASSERT_TRUE(PressInput(tab_0_center)); |
| 816 ASSERT_TRUE(DragInputToNotifyWhenDone( | 830 ASSERT_TRUE(DragInputToNotifyWhenDone( |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1128 // Remaining browser window should not be maximized | 1142 // Remaining browser window should not be maximized |
| 1129 EXPECT_FALSE(browser()->window()->IsMaximized()); | 1143 EXPECT_FALSE(browser()->window()->IsMaximized()); |
| 1130 | 1144 |
| 1131 // The tab strip should no longer have capture because the drag was ended and | 1145 // The tab strip should no longer have capture because the drag was ended and |
| 1132 // mouse/touch was released. | 1146 // mouse/touch was released. |
| 1133 EXPECT_FALSE(tab_strip->GetWidget()->HasCapture()); | 1147 EXPECT_FALSE(tab_strip->GetWidget()->HasCapture()); |
| 1134 } | 1148 } |
| 1135 | 1149 |
| 1136 namespace { | 1150 namespace { |
| 1137 | 1151 |
| 1152 #if !defined(OS_MACOSX) | |
| 1138 void DragAllStep2(DetachToBrowserTabDragControllerTest* test, | 1153 void DragAllStep2(DetachToBrowserTabDragControllerTest* test, |
| 1139 const BrowserList* browser_list) { | 1154 const BrowserList* browser_list) { |
| 1140 // Should only be one window. | 1155 // Should only be one window. |
| 1141 ASSERT_EQ(1u, browser_list->size()); | 1156 ASSERT_EQ(1u, browser_list->size()); |
| 1142 if (test->input_source() == INPUT_SOURCE_TOUCH) { | 1157 if (test->input_source() == INPUT_SOURCE_TOUCH) { |
| 1143 ASSERT_TRUE(test->ReleaseInput()); | 1158 ASSERT_TRUE(test->ReleaseInput()); |
| 1144 } else { | 1159 } else { |
| 1145 ASSERT_TRUE(test->ReleaseMouseAsync()); | 1160 ASSERT_TRUE(test->ReleaseMouseAsync()); |
| 1146 } | 1161 } |
| 1147 } | 1162 } |
| 1163 #endif // !OS_MACOSX | |
| 1148 | 1164 |
| 1149 } // namespace | 1165 } // namespace |
| 1150 | 1166 |
| 1151 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 1167 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 1152 // TODO(sky,sad): Disabled as it fails due to resize locks with a real | 1168 // TODO(sky,sad): Disabled as it fails due to resize locks with a real |
| 1153 // compositor. crbug.com/331924 | 1169 // compositor. crbug.com/331924 |
| 1154 #define MAYBE_DragAll DISABLED_DragAll | 1170 #define MAYBE_DragAll DISABLED_DragAll |
| 1155 #else | 1171 #else |
| 1156 #define MAYBE_DragAll DragAll | 1172 #define MAYBE_DragAll DragAll |
| 1157 #endif | 1173 #endif |
| 1158 // Selects multiple tabs and starts dragging the window. | 1174 // Selects multiple tabs and starts dragging the window. |
| 1159 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, MAYBE_DragAll) { | 1175 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, MAYBE_DragAll) { |
| 1160 // Add another tab. | 1176 // Add another tab. |
| 1161 AddTabAndResetBrowser(browser()); | 1177 AddTabAndResetBrowser(browser()); |
| 1162 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 1178 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 1163 browser()->tab_strip_model()->AddTabAtToSelection(0); | 1179 browser()->tab_strip_model()->AddTabAtToSelection(0); |
| 1164 browser()->tab_strip_model()->AddTabAtToSelection(1); | 1180 browser()->tab_strip_model()->AddTabAtToSelection(1); |
| 1181 const gfx::Rect initial_bounds = browser()->window()->GetBounds(); | |
| 1165 | 1182 |
| 1166 // Move to the first tab and drag it enough so that it would normally | 1183 // Move to the first tab and drag it enough so that it would normally |
| 1167 // detach. | 1184 // detach. |
| 1168 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | 1185 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
| 1169 ASSERT_TRUE(PressInput(tab_0_center)); | 1186 DragAndDrop( |
| 1170 ASSERT_TRUE(DragInputToNotifyWhenDone( | 1187 tab_0_center, |
| 1171 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), | 1188 gfx::Point(tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip))); |
| 1172 base::Bind(&DragAllStep2, this, browser_list))); | |
| 1173 QuitWhenNotDragging(); | |
| 1174 | 1189 |
| 1175 // Should not be dragging. | 1190 // Should not be dragging. |
| 1176 ASSERT_FALSE(tab_strip->IsDragSessionActive()); | 1191 ASSERT_FALSE(tab_strip->IsDragSessionActive()); |
| 1177 ASSERT_FALSE(TabDragController::IsActive()); | 1192 ASSERT_FALSE(TabDragController::IsActive()); |
| 1178 | 1193 |
| 1179 // And there should only be one window. | 1194 // And there should only be one window. |
| 1180 EXPECT_EQ(1u, browser_list->size()); | 1195 EXPECT_EQ(1u, browser_list->size()); |
| 1181 | 1196 |
| 1182 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model())); | 1197 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model())); |
| 1183 | 1198 |
| 1184 EXPECT_FALSE(GetIsDragged(browser())); | 1199 EXPECT_FALSE(GetIsDragged(browser())); |
| 1185 | 1200 |
| 1186 // Remaining browser window should not be maximized | 1201 // Remaining browser window should not be maximized |
| 1187 EXPECT_FALSE(browser()->window()->IsMaximized()); | 1202 EXPECT_FALSE(browser()->window()->IsMaximized()); |
| 1203 | |
| 1204 EXPECT_NE(initial_bounds, browser()->window()->GetBounds()); | |
| 1188 } | 1205 } |
| 1189 | 1206 |
| 1190 namespace { | 1207 namespace { |
| 1191 | 1208 |
| 1192 // Invoked from the nested message loop. | 1209 // Invoked from the nested message loop. |
| 1193 void DragAllToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test, | 1210 void DragAllToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test, |
| 1194 TabStrip* attached_tab_strip, | 1211 TabStrip* attached_tab_strip, |
| 1195 TabStrip* target_tab_strip, | 1212 TabStrip* target_tab_strip, |
| 1196 const BrowserList* browser_list) { | 1213 const BrowserList* browser_list) { |
| 1197 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive()); | 1214 ASSERT_TRUE(attached_tab_strip->IsDragSessionActive()); |
| (...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2350 ::testing::Values("mouse", "touch")); | 2367 ::testing::Values("mouse", "touch")); |
| 2351 INSTANTIATE_TEST_CASE_P(TabDragging, | 2368 INSTANTIATE_TEST_CASE_P(TabDragging, |
| 2352 DifferentDeviceScaleFactorDisplayTabDragControllerTest, | 2369 DifferentDeviceScaleFactorDisplayTabDragControllerTest, |
| 2353 ::testing::Values("mouse")); | 2370 ::testing::Values("mouse")); |
| 2354 INSTANTIATE_TEST_CASE_P(TabDragging, | 2371 INSTANTIATE_TEST_CASE_P(TabDragging, |
| 2355 DetachToBrowserTabDragControllerTest, | 2372 DetachToBrowserTabDragControllerTest, |
| 2356 ::testing::Values("mouse", "touch")); | 2373 ::testing::Values("mouse", "touch")); |
| 2357 INSTANTIATE_TEST_CASE_P(TabDragging, | 2374 INSTANTIATE_TEST_CASE_P(TabDragging, |
| 2358 DetachToBrowserTabDragControllerTestTouch, | 2375 DetachToBrowserTabDragControllerTestTouch, |
| 2359 ::testing::Values("touch")); | 2376 ::testing::Values("touch")); |
| 2360 #elif defined(USE_ASH) | 2377 #elif defined(USE_ASH) |
|
tapted
2016/03/01 08:30:10
oh, and this [not stuff you added :)] actually loo
themblsha
2016/03/09 17:40:22
Added OS_MACOSX block.
| |
| 2361 INSTANTIATE_TEST_CASE_P(TabDragging, | 2378 INSTANTIATE_TEST_CASE_P(TabDragging, |
| 2362 DetachToBrowserTabDragControllerTest, | 2379 DetachToBrowserTabDragControllerTest, |
| 2363 ::testing::Values("mouse")); | 2380 ::testing::Values("mouse")); |
| 2364 #endif | 2381 #endif |
| 2382 INSTANTIATE_TEST_CASE_P(TabDragging, | |
| 2383 DetachToBrowserTabDragControllerTest, | |
| 2384 ::testing::Values("mouse")); | |
| OLD | NEW |