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