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 "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/callback_helpers.h" | |
| 13 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 14 #include "base/location.h" | 16 #include "base/location.h" |
| 15 #include "base/macros.h" | 17 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 17 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 19 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 22 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 } | 791 } |
| 790 #else | 792 #else |
| 791 bool IsWindowPositionManaged(gfx::NativeWindow window) { | 793 bool IsWindowPositionManaged(gfx::NativeWindow window) { |
| 792 return true; | 794 return true; |
| 793 } | 795 } |
| 794 bool HasUserChangedWindowPositionOrSize(gfx::NativeWindow window) { | 796 bool HasUserChangedWindowPositionOrSize(gfx::NativeWindow window) { |
| 795 return false; | 797 return false; |
| 796 } | 798 } |
| 797 #endif | 799 #endif |
| 798 | 800 |
| 801 // Encapsulates waiting for the browser window to become maximized. This is | |
| 802 // needed for example on Chrome desktop linux, where window maximization is done | |
| 803 // asynchronously as an event received from a different process. | |
| 804 class MaximizedBrowserWindowWaiter { | |
| 805 public: | |
| 806 explicit MaximizedBrowserWindowWaiter(BrowserWindow* window) | |
| 807 : window_(window) {} | |
| 808 ~MaximizedBrowserWindowWaiter() = default; | |
| 809 | |
| 810 // Blocks until the browser window becomes maximized. | |
| 811 void Wait() { | |
| 812 if (CheckMaximized()) | |
| 813 return; | |
| 814 | |
| 815 base::RunLoop run_loop; | |
| 816 quit_ = run_loop.QuitClosure(); | |
| 817 run_loop.Run(); | |
| 818 } | |
| 819 | |
| 820 private: | |
| 821 bool CheckMaximized() { | |
| 822 if (!window_->IsMaximized()) { | |
| 823 base::MessageLoop::current()->task_runner()->PostTask( | |
|
sky
2016/11/28 21:31:50
It's generally preferable to install a listener th
afakhry
2016/11/28 22:54:25
Yes, that's the first thing I tried. I wasn't howe
| |
| 824 FROM_HERE, base::Bind( | |
| 825 base::IgnoreResult(&MaximizedBrowserWindowWaiter::CheckMaximized), | |
| 826 base::Unretained(this))); | |
| 827 return false; | |
| 828 } | |
| 829 | |
| 830 // Quit the run_loop to end the wait. | |
| 831 if (!quit_.is_null()) | |
| 832 base::ResetAndReturn(&quit_).Run(); | |
| 833 return true; | |
| 834 } | |
| 835 | |
| 836 // The browser window observed by this waiter. | |
| 837 BrowserWindow* window_; | |
| 838 | |
| 839 // The waiter's RunLoop quit closure. | |
| 840 base::Closure quit_; | |
| 841 | |
| 842 DISALLOW_COPY_AND_ASSIGN(MaximizedBrowserWindowWaiter); | |
| 843 }; | |
| 844 | |
| 799 } // namespace | 845 } // namespace |
| 800 | 846 |
| 801 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | |
| 802 // TODO(sky,sad): Disabled as it fails due to resize locks with a real | |
| 803 // compositor. crbug.com/331924 | |
| 804 #define MAYBE_DetachToOwnWindow DISABLED_DetachToOwnWindow | |
| 805 #else | |
| 806 #define MAYBE_DetachToOwnWindow DetachToOwnWindow | |
| 807 #endif | |
| 808 // Drags from browser to separate window and releases mouse. | 847 // Drags from browser to separate window and releases mouse. |
| 809 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | 848 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, |
| 810 MAYBE_DetachToOwnWindow) { | 849 DetachToOwnWindow) { |
| 811 const gfx::Rect initial_bounds(browser()->window()->GetBounds()); | 850 const gfx::Rect initial_bounds(browser()->window()->GetBounds()); |
| 812 // Add another tab. | 851 // Add another tab. |
| 813 AddTabAndResetBrowser(browser()); | 852 AddTabAndResetBrowser(browser()); |
| 814 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 853 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 815 | 854 |
| 816 // Move to the first tab and drag it enough so that it detaches. | 855 // Move to the first tab and drag it enough so that it detaches. |
| 817 gfx::Point tab_0_center( | 856 gfx::Point tab_0_center( |
| 818 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | 857 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
| 819 ASSERT_TRUE(PressInput(tab_0_center)); | 858 ASSERT_TRUE(PressInput(tab_0_center)); |
| 820 ASSERT_TRUE(DragInputToNotifyWhenDone( | 859 ASSERT_TRUE(DragInputToNotifyWhenDone( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 853 // Both windows should not be maximized | 892 // Both windows should not be maximized |
| 854 EXPECT_FALSE(browser()->window()->IsMaximized()); | 893 EXPECT_FALSE(browser()->window()->IsMaximized()); |
| 855 EXPECT_FALSE(new_browser->window()->IsMaximized()); | 894 EXPECT_FALSE(new_browser->window()->IsMaximized()); |
| 856 | 895 |
| 857 // The tab strip should no longer have capture because the drag was ended and | 896 // The tab strip should no longer have capture because the drag was ended and |
| 858 // mouse/touch was released. | 897 // mouse/touch was released. |
| 859 EXPECT_FALSE(tab_strip->GetWidget()->HasCapture()); | 898 EXPECT_FALSE(tab_strip->GetWidget()->HasCapture()); |
| 860 EXPECT_FALSE(tab_strip2->GetWidget()->HasCapture()); | 899 EXPECT_FALSE(tab_strip2->GetWidget()->HasCapture()); |
| 861 } | 900 } |
| 862 | 901 |
| 863 #if defined(OS_CHROMEOS) || defined(OS_LINUX) || defined(OS_MACOSX) | 902 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 864 // TODO(sky,sad): Disabled as it fails due to resize locks with a real | 903 // TODO(afakhry,varkha): Disabled on Linux as it fails on the bot because |
| 865 // compositor. crbug.com/331924 | 904 // setting the window bounds to the work area bounds in |
| 905 // DesktopWindowTreeHostX11::SetBounds() always insets it by one pixel in both | |
| 906 // width and height. This results in considering the source browser window not | |
| 907 // being full size, and the test is not as expected. | |
| 908 // crbug.com/626761, crbug.com/331924. | |
| 866 // TODO(tapted,mblsha): Disabled as the Mac IsMaximized() behavior is not | 909 // TODO(tapted,mblsha): Disabled as the Mac IsMaximized() behavior is not |
| 867 // consistent with other platforms. crbug.com/603562 | 910 // consistent with other platforms. crbug.com/603562 |
| 868 #define MAYBE_DetachFromFullsizeWindow DISABLED_DetachFromFullsizeWindow | 911 #define MAYBE_DetachFromFullsizeWindow DISABLED_DetachFromFullsizeWindow |
| 869 #else | 912 #else |
| 870 #define MAYBE_DetachFromFullsizeWindow DetachFromFullsizeWindow | 913 #define MAYBE_DetachFromFullsizeWindow DetachFromFullsizeWindow |
| 871 #endif | 914 #endif |
| 872 // Tests that a tab can be dragged from a browser window that is resized to full | 915 // Tests that a tab can be dragged from a browser window that is resized to full |
| 873 // screen. | 916 // screen. |
| 874 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | 917 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, |
| 875 MAYBE_DetachFromFullsizeWindow) { | 918 MAYBE_DetachFromFullsizeWindow) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 916 | 959 |
| 917 EXPECT_FALSE(GetIsDragged(browser())); | 960 EXPECT_FALSE(GetIsDragged(browser())); |
| 918 EXPECT_FALSE(GetIsDragged(new_browser)); | 961 EXPECT_FALSE(GetIsDragged(new_browser)); |
| 919 // After this both windows should still be manageable. | 962 // After this both windows should still be manageable. |
| 920 EXPECT_TRUE(IsWindowPositionManaged(browser()->window()->GetNativeWindow())); | 963 EXPECT_TRUE(IsWindowPositionManaged(browser()->window()->GetNativeWindow())); |
| 921 EXPECT_TRUE( | 964 EXPECT_TRUE( |
| 922 IsWindowPositionManaged(new_browser->window()->GetNativeWindow())); | 965 IsWindowPositionManaged(new_browser->window()->GetNativeWindow())); |
| 923 | 966 |
| 924 // Only second window should be maximized. | 967 // Only second window should be maximized. |
| 925 EXPECT_FALSE(browser()->window()->IsMaximized()); | 968 EXPECT_FALSE(browser()->window()->IsMaximized()); |
| 969 MaximizedBrowserWindowWaiter(new_browser->window()).Wait(); | |
| 926 EXPECT_TRUE(new_browser->window()->IsMaximized()); | 970 EXPECT_TRUE(new_browser->window()->IsMaximized()); |
| 927 | 971 |
| 928 // The tab strip should no longer have capture because the drag was ended and | 972 // The tab strip should no longer have capture because the drag was ended and |
| 929 // mouse/touch was released. | 973 // mouse/touch was released. |
| 930 EXPECT_FALSE(tab_strip->GetWidget()->HasCapture()); | 974 EXPECT_FALSE(tab_strip->GetWidget()->HasCapture()); |
| 931 EXPECT_FALSE(tab_strip2->GetWidget()->HasCapture()); | 975 EXPECT_FALSE(tab_strip2->GetWidget()->HasCapture()); |
| 932 } | 976 } |
| 933 | 977 |
| 934 #if defined(OS_CHROMEOS) || defined(OS_LINUX) || defined(OS_MACOSX) | 978 #if defined(OS_MACOSX) |
| 935 // TODO(sky,sad): Disabled as it fails due to resize locks with a real | |
| 936 // compositor. crbug.com/331924 | |
| 937 // TODO(tapted,mblsha): Disabled as the Mac IsMaximized() behavior is not | 979 // TODO(tapted,mblsha): Disabled as the Mac IsMaximized() behavior is not |
| 938 // consistent with other platforms. crbug.com/603562 | 980 // consistent with other platforms. crbug.com/603562 |
| 939 #define MAYBE_DetachToOwnWindowFromMaximizedWindow \ | 981 #define MAYBE_DetachToOwnWindowFromMaximizedWindow \ |
| 940 DISABLED_DetachToOwnWindowFromMaximizedWindow | 982 DISABLED_DetachToOwnWindowFromMaximizedWindow |
| 941 #else | 983 #else |
| 942 #define MAYBE_DetachToOwnWindowFromMaximizedWindow \ | 984 #define MAYBE_DetachToOwnWindowFromMaximizedWindow \ |
| 943 DetachToOwnWindowFromMaximizedWindow | 985 DetachToOwnWindowFromMaximizedWindow |
| 944 #endif | 986 #endif |
| 945 // Drags from browser to a separate window and releases mouse. | 987 // Drags from browser to a separate window and releases mouse. |
| 946 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | 988 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, |
| 947 MAYBE_DetachToOwnWindowFromMaximizedWindow) { | 989 MAYBE_DetachToOwnWindowFromMaximizedWindow) { |
| 948 // Maximize the initial browser window. | 990 // Maximize the initial browser window. |
| 949 browser()->window()->Maximize(); | 991 browser()->window()->Maximize(); |
| 992 MaximizedBrowserWindowWaiter(browser()->window()).Wait(); | |
| 950 ASSERT_TRUE(browser()->window()->IsMaximized()); | 993 ASSERT_TRUE(browser()->window()->IsMaximized()); |
| 951 | 994 |
| 952 // Add another tab. | 995 // Add another tab. |
| 953 AddTabAndResetBrowser(browser()); | 996 AddTabAndResetBrowser(browser()); |
| 954 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 997 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 955 | 998 |
| 956 // Move to the first tab and drag it enough so that it detaches. | 999 // Move to the first tab and drag it enough so that it detaches. |
| 957 gfx::Point tab_0_center( | 1000 gfx::Point tab_0_center( |
| 958 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | 1001 GetCenterInScreenCoordinates(tab_strip->tab_at(0))); |
| 959 ASSERT_TRUE(PressInput(tab_0_center)); | 1002 ASSERT_TRUE(PressInput(tab_0_center)); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 983 EXPECT_TRUE(browser()->window()->IsMaximized()); | 1026 EXPECT_TRUE(browser()->window()->IsMaximized()); |
| 984 | 1027 |
| 985 EXPECT_FALSE(GetIsDragged(browser())); | 1028 EXPECT_FALSE(GetIsDragged(browser())); |
| 986 EXPECT_FALSE(GetIsDragged(new_browser)); | 1029 EXPECT_FALSE(GetIsDragged(new_browser)); |
| 987 // After this both windows should still be manageable. | 1030 // After this both windows should still be manageable. |
| 988 EXPECT_TRUE(IsWindowPositionManaged(browser()->window()->GetNativeWindow())); | 1031 EXPECT_TRUE(IsWindowPositionManaged(browser()->window()->GetNativeWindow())); |
| 989 EXPECT_TRUE(IsWindowPositionManaged( | 1032 EXPECT_TRUE(IsWindowPositionManaged( |
| 990 new_browser->window()->GetNativeWindow())); | 1033 new_browser->window()->GetNativeWindow())); |
| 991 | 1034 |
| 992 // The new window should be maximized. | 1035 // The new window should be maximized. |
| 1036 MaximizedBrowserWindowWaiter(new_browser->window()).Wait(); | |
| 993 EXPECT_TRUE(new_browser->window()->IsMaximized()); | 1037 EXPECT_TRUE(new_browser->window()->IsMaximized()); |
| 994 } | 1038 } |
| 995 | 1039 |
| 996 // Deletes a tab being dragged before the user moved enough to start a drag. | 1040 // Deletes a tab being dragged before the user moved enough to start a drag. |
| 997 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | 1041 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, |
| 998 DeleteBeforeStartedDragging) { | 1042 DeleteBeforeStartedDragging) { |
| 999 // Add another tab. | 1043 // Add another tab. |
| 1000 AddTabAndResetBrowser(browser()); | 1044 AddTabAndResetBrowser(browser()); |
| 1001 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 1045 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 1002 | 1046 |
| (...skipping 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2422 base::Bind(&DetachToDockedWindowNextStep, | 2466 base::Bind(&DetachToDockedWindowNextStep, |
| 2423 test, | 2467 test, |
| 2424 gfx::Point(target_point.x(), 1 + target_point.y()), | 2468 gfx::Point(target_point.x(), 1 + target_point.y()), |
| 2425 iteration - 1))); | 2469 iteration - 1))); |
| 2426 } | 2470 } |
| 2427 | 2471 |
| 2428 } // namespace | 2472 } // namespace |
| 2429 | 2473 |
| 2430 // Drags from browser to separate window, docks that window and releases mouse. | 2474 // Drags from browser to separate window, docks that window and releases mouse. |
| 2431 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, | 2475 IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, |
| 2432 DISABLED_DetachToDockedWindowFromMaximizedWindow) { | 2476 DetachToDockedWindowFromMaximizedWindow) { |
| 2433 // Maximize the initial browser window. | 2477 // Maximize the initial browser window. |
| 2434 browser()->window()->Maximize(); | 2478 browser()->window()->Maximize(); |
| 2435 ASSERT_TRUE(browser()->window()->IsMaximized()); | 2479 ASSERT_TRUE(browser()->window()->IsMaximized()); |
| 2436 | 2480 |
| 2437 // Add another tab. | 2481 // Add another tab. |
| 2438 AddTabAndResetBrowser(browser()); | 2482 AddTabAndResetBrowser(browser()); |
| 2439 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | 2483 TabStrip* tab_strip = GetTabStripForBrowser(browser()); |
| 2440 | 2484 |
| 2441 // Move to the first tab and drag it enough so that it detaches. | 2485 // Move to the first tab and drag it enough so that it detaches. |
| 2442 gfx::Point tab_0_center( | 2486 gfx::Point tab_0_center( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2499 DetachToBrowserTabDragControllerTest, | 2543 DetachToBrowserTabDragControllerTest, |
| 2500 ::testing::Values("mouse", "touch")); | 2544 ::testing::Values("mouse", "touch")); |
| 2501 INSTANTIATE_TEST_CASE_P(TabDragging, | 2545 INSTANTIATE_TEST_CASE_P(TabDragging, |
| 2502 DetachToBrowserTabDragControllerTestTouch, | 2546 DetachToBrowserTabDragControllerTestTouch, |
| 2503 ::testing::Values("touch")); | 2547 ::testing::Values("touch")); |
| 2504 #else | 2548 #else |
| 2505 INSTANTIATE_TEST_CASE_P(TabDragging, | 2549 INSTANTIATE_TEST_CASE_P(TabDragging, |
| 2506 DetachToBrowserTabDragControllerTest, | 2550 DetachToBrowserTabDragControllerTest, |
| 2507 ::testing::Values("mouse")); | 2551 ::testing::Values("mouse")); |
| 2508 #endif | 2552 #endif |
| OLD | NEW |