| 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 "ash/wm/property_util.h" | 7 #include "ash/wm/property_util.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
| 16 #include "chrome/browser/ui/browser_iterator.h" | 16 #include "chrome/browser/ui/browser_iterator.h" |
| 17 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
| 18 #include "chrome/browser/ui/host_desktop.h" | 18 #include "chrome/browser/ui/host_desktop.h" |
| 19 #include "chrome/browser/ui/immersive_fullscreen_configuration.h" | 19 #include "chrome/browser/ui/immersive_fullscreen_configuration.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/browser/ui/views/frame/browser_view.h" | 21 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 22 #include "chrome/browser/ui/views/frame/native_browser_frame_factory.h" |
| 22 #include "chrome/browser/ui/views/tabs/tab.h" | 23 #include "chrome/browser/ui/views/tabs/tab.h" |
| 23 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h" | 24 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h" |
| 24 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 25 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 27 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "chrome/test/base/interactive_test_utils.h" | 28 #include "chrome/test/base/interactive_test_utils.h" |
| 28 #include "chrome/test/base/ui_test_utils.h" | 29 #include "chrome/test/base/ui_test_utils.h" |
| 29 #include "content/public/browser/notification_details.h" | 30 #include "content/public/browser/notification_details.h" |
| 30 #include "content/public/browser/notification_observer.h" | 31 #include "content/public/browser/notification_observer.h" |
| 31 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
| 33 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 34 #include "ui/base/test/ui_controls.h" | 35 #include "ui/base/test/ui_controls.h" |
| 35 #include "ui/gfx/screen.h" | 36 #include "ui/gfx/screen.h" |
| 36 #include "ui/views/view.h" | 37 #include "ui/views/view.h" |
| 37 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
| 38 | 39 |
| 40 #if defined(USE_AURA) && !defined(OS_CHROMEOS) |
| 41 #include "chrome/browser/ui/views/frame/desktop_browser_frame_aura.h" |
| 42 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 43 #endif |
| 44 |
| 39 #if defined(USE_ASH) | 45 #if defined(USE_ASH) |
| 40 #include "ash/display/display_controller.h" | 46 #include "ash/display/display_controller.h" |
| 41 #include "ash/display/display_manager.h" | 47 #include "ash/display/display_manager.h" |
| 42 #include "ash/shell.h" | 48 #include "ash/shell.h" |
| 43 #include "ash/test/cursor_manager_test_api.h" | 49 #include "ash/test/cursor_manager_test_api.h" |
| 44 #include "ash/wm/coordinate_conversion.h" | 50 #include "ash/wm/coordinate_conversion.h" |
| 45 #include "ash/wm/window_util.h" | 51 #include "ash/wm/window_util.h" |
| 46 #include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" | 52 #include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" |
| 47 #include "ui/aura/client/screen_position_client.h" | 53 #include "ui/aura/client/screen_position_client.h" |
| 48 #include "ui/aura/root_window.h" | 54 #include "ui/aura/root_window.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 238 } |
| 233 | 239 |
| 234 private: | 240 private: |
| 235 aura::RootWindow* root_window_; | 241 aura::RootWindow* root_window_; |
| 236 | 242 |
| 237 DISALLOW_COPY_AND_ASSIGN(ScreenEventGeneratorDelegate); | 243 DISALLOW_COPY_AND_ASSIGN(ScreenEventGeneratorDelegate); |
| 238 }; | 244 }; |
| 239 | 245 |
| 240 #endif | 246 #endif |
| 241 | 247 |
| 248 #if defined(USE_AURA) && !defined(OS_CHROMEOS) |
| 249 |
| 250 // Following classes verify a crash scenario. Specifically on Windows when focus |
| 251 // changes it can trigger capture being lost. This was causing a crash in tab |
| 252 // dragging as it wasn't set up to handle this scenario. These classes |
| 253 // synthesize this scenario. |
| 254 |
| 255 // Allows making ClearNativeFocus() invoke ReleaseCapture(). |
| 256 class TestDesktopBrowserFrameAura : public DesktopBrowserFrameAura { |
| 257 public: |
| 258 TestDesktopBrowserFrameAura( |
| 259 BrowserFrame* browser_frame, |
| 260 BrowserView* browser_view) |
| 261 : DesktopBrowserFrameAura(browser_frame, browser_view), |
| 262 release_capture_(false) {} |
| 263 virtual ~TestDesktopBrowserFrameAura() {} |
| 264 |
| 265 void ReleaseCaptureOnNextClear() { |
| 266 release_capture_ = true; |
| 267 } |
| 268 |
| 269 virtual void ClearNativeFocus() OVERRIDE { |
| 270 views::DesktopNativeWidgetAura::ClearNativeFocus(); |
| 271 if (release_capture_) { |
| 272 release_capture_ = false; |
| 273 GetWidget()->ReleaseCapture(); |
| 274 } |
| 275 } |
| 276 |
| 277 private: |
| 278 // If true ReleaseCapture() is invoked in ClearNativeFocus(). |
| 279 bool release_capture_; |
| 280 |
| 281 DISALLOW_COPY_AND_ASSIGN(TestDesktopBrowserFrameAura); |
| 282 }; |
| 283 |
| 284 // Factory for creating a TestDesktopBrowserFrameAura. |
| 285 class TestNativeBrowserFrameFactory : public NativeBrowserFrameFactory { |
| 286 public: |
| 287 TestNativeBrowserFrameFactory() {} |
| 288 virtual ~TestNativeBrowserFrameFactory() {} |
| 289 |
| 290 virtual NativeBrowserFrame* Create( |
| 291 BrowserFrame* browser_frame, |
| 292 BrowserView* browser_view) OVERRIDE { |
| 293 return new TestDesktopBrowserFrameAura(browser_frame, browser_view); |
| 294 } |
| 295 |
| 296 private: |
| 297 DISALLOW_COPY_AND_ASSIGN(TestNativeBrowserFrameFactory); |
| 298 }; |
| 299 |
| 300 class TabDragCaptureLostTest : public TabDragControllerTest { |
| 301 public: |
| 302 TabDragCaptureLostTest() { |
| 303 NativeBrowserFrameFactory::Set(new TestNativeBrowserFrameFactory); |
| 304 } |
| 305 |
| 306 private: |
| 307 DISALLOW_COPY_AND_ASSIGN(TabDragCaptureLostTest); |
| 308 }; |
| 309 |
| 310 // See description above for details. |
| 311 IN_PROC_BROWSER_TEST_F(TabDragCaptureLostTest, ReleaseCaptureOnDrag) { |
| 312 AddTabAndResetBrowser(browser()); |
| 313 |
| 314 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 315 gfx::Point tab_1_center(GetCenterInScreenCoordinates(tab_strip->tab_at(1))); |
| 316 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_1_center) && |
| 317 ui_test_utils::SendMouseEventsSync( |
| 318 ui_controls::LEFT, ui_controls::DOWN)); |
| 319 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
| 320 TestDesktopBrowserFrameAura* frame = |
| 321 static_cast<TestDesktopBrowserFrameAura*>( |
| 322 BrowserView::GetBrowserViewForBrowser(browser())->GetWidget()-> |
| 323 native_widget_private()); |
| 324 // Invoke ReleaseCaptureOnDrag() so that when the drag happens and focus |
| 325 // changes capture is released and the drag cancels. |
| 326 frame->ReleaseCaptureOnNextClear(); |
| 327 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center)); |
| 328 EXPECT_FALSE(tab_strip->IsDragSessionActive()); |
| 329 } |
| 330 |
| 331 #endif |
| 332 |
| 242 class DetachToBrowserTabDragControllerTest | 333 class DetachToBrowserTabDragControllerTest |
| 243 : public TabDragControllerTest, | 334 : public TabDragControllerTest, |
| 244 public ::testing::WithParamInterface<const char*> { | 335 public ::testing::WithParamInterface<const char*> { |
| 245 public: | 336 public: |
| 246 DetachToBrowserTabDragControllerTest() {} | 337 DetachToBrowserTabDragControllerTest() {} |
| 247 | 338 |
| 248 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 339 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 249 command_line->AppendSwitch(switches::kTabBrowserDragging); | 340 command_line->AppendSwitch(switches::kTabBrowserDragging); |
| 250 } | 341 } |
| 251 | 342 |
| (...skipping 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1786 DifferentDeviceScaleFactorDisplayTabDragControllerTest, | 1877 DifferentDeviceScaleFactorDisplayTabDragControllerTest, |
| 1787 ::testing::Values("mouse")); | 1878 ::testing::Values("mouse")); |
| 1788 INSTANTIATE_TEST_CASE_P(TabDragging, | 1879 INSTANTIATE_TEST_CASE_P(TabDragging, |
| 1789 DetachToBrowserTabDragControllerTest, | 1880 DetachToBrowserTabDragControllerTest, |
| 1790 ::testing::Values("mouse", "touch")); | 1881 ::testing::Values("mouse", "touch")); |
| 1791 #else | 1882 #else |
| 1792 INSTANTIATE_TEST_CASE_P(TabDragging, | 1883 INSTANTIATE_TEST_CASE_P(TabDragging, |
| 1793 DetachToBrowserTabDragControllerTest, | 1884 DetachToBrowserTabDragControllerTest, |
| 1794 ::testing::Values("mouse")); | 1885 ::testing::Values("mouse")); |
| 1795 #endif | 1886 #endif |
| OLD | NEW |