Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc

Issue 10909043: Cancel drag if display configuration changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 15 matching lines...) Expand all
26 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "ui/gfx/screen.h" 29 #include "ui/gfx/screen.h"
30 #include "ui/ui_controls/ui_controls.h" 30 #include "ui/ui_controls/ui_controls.h"
31 #include "ui/views/view.h" 31 #include "ui/views/view.h"
32 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
33 33
34 #if defined(USE_ASH) 34 #if defined(USE_ASH)
35 #include "ash/display/display_controller.h" 35 #include "ash/display/display_controller.h"
36 #include "ash/display/multi_display_manager.h"
36 #include "ash/shell.h" 37 #include "ash/shell.h"
37 #include "ui/aura/test/event_generator.h" 38 #include "ui/aura/test/event_generator.h"
38 #include "ui/aura/root_window.h" 39 #include "ui/aura/root_window.h"
39 #endif 40 #endif
40 41
41 namespace test { 42 namespace test {
42 43
43 namespace { 44 namespace {
44 45
45 const char kTabDragControllerInteractiveUITestUserDataKey[] = 46 const char kTabDragControllerInteractiveUITestUserDataKey[] =
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 // Add another tab. 934 // Add another tab.
934 AddTabAndResetBrowser(browser()); 935 AddTabAndResetBrowser(browser());
935 TabStrip* tab_strip = GetTabStripForBrowser(browser()); 936 TabStrip* tab_strip = GetTabStripForBrowser(browser());
936 937
937 // Create another browser. 938 // Create another browser.
938 Browser* browser2 = CreateBrowser(browser()->profile()); 939 Browser* browser2 = CreateBrowser(browser()->profile());
939 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2); 940 TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
940 ResetIDs(browser2->tab_strip_model(), 100); 941 ResetIDs(browser2->tab_strip_model(), 100);
941 942
942 // Move the second browser to the second display. 943 // Move the second browser to the second display.
943 std::vector<aura::RootWindow*> roots( 944 std::vector<aura::RootWindow*> roots(ash::Shell::GetAllRootWindows());
944 ash::Shell::GetInstance()->display_controller()->GetAllRootWindows());
945 ASSERT_EQ(2u, roots.size()); 945 ASSERT_EQ(2u, roots.size());
946 aura::RootWindow* second_root = roots[1]; 946 aura::RootWindow* second_root = roots[1];
947 gfx::Rect work_area = gfx::Screen::GetDisplayNearestWindow( 947 gfx::Rect work_area = gfx::Screen::GetDisplayNearestWindow(
948 second_root).work_area(); 948 second_root).work_area();
949 browser2->window()->SetBounds(work_area); 949 browser2->window()->SetBounds(work_area);
950 EXPECT_EQ(second_root, 950 EXPECT_EQ(second_root,
951 browser2->window()->GetNativeWindow()->GetRootWindow()); 951 browser2->window()->GetNativeWindow()->GetRootWindow());
952 952
953 // Move to the first tab and drag it enough so that it detaches, but not 953 // Move to the first tab and drag it enough so that it detaches, but not
954 // enough that it attaches to browser2. 954 // enough that it attaches to browser2.
(...skipping 12 matching lines...) Expand all
967 967
968 // Release the mouse, stopping the drag session. 968 // Release the mouse, stopping the drag session.
969 ASSERT_TRUE(ReleaseInput()); 969 ASSERT_TRUE(ReleaseInput());
970 ASSERT_FALSE(tab_strip2->IsDragSessionActive()); 970 ASSERT_FALSE(tab_strip2->IsDragSessionActive());
971 ASSERT_FALSE(tab_strip->IsDragSessionActive()); 971 ASSERT_FALSE(tab_strip->IsDragSessionActive());
972 ASSERT_FALSE(TabDragController::IsActive()); 972 ASSERT_FALSE(TabDragController::IsActive());
973 EXPECT_EQ("0 100", IDString(browser2->tab_strip_model())); 973 EXPECT_EQ("0 100", IDString(browser2->tab_strip_model()));
974 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); 974 EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
975 } 975 }
976 976
977 namespace {
978
979 class DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest
980 : public TabDragControllerTest {
981 public:
982 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest() {}
983
984 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
985 TabDragControllerTest::SetUpCommandLine(command_line);
986 command_line->AppendSwitchASCII("aura-host-window-size",
987 "0+0-250x250,251+0-250x250");
988 }
989
990 bool Press(const gfx::Point& position) {
991 return ui_test_utils::SendMouseMoveSync(position) &&
992 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT,
993 ui_controls::DOWN);
994 }
995
996 bool DragTabAndExecuteTaskWhenDone(const gfx::Point& position,
997 const base::Closure& task) {
998 return ui_controls::SendMouseMoveNotifyWhenDone(
999 position.x(), position.y(), task);
1000 }
1001
1002 void QuitWhenNotDragging() {
1003 test::QuitWhenNotDraggingImpl();
1004 MessageLoop::current()->Run();
1005 }
1006
1007 private:
1008 DISALLOW_COPY_AND_ASSIGN(
1009 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest);
1010 };
1011
1012 // Invoked from the nested message loop.
1013 void CancelDragTabToWindowInSeparateDisplayStep3(
1014 TabStrip* tab_strip) {
1015 ASSERT_FALSE(tab_strip->IsDragSessionActive());
1016 ASSERT_TRUE(TabDragController::IsActive());
1017 ASSERT_EQ(2u, BrowserList::size());
1018
1019 // Switching display mode should cancel the drag operation.
1020 ash::internal::MultiDisplayManager::CycleDisplay();
1021 }
1022
1023 // Invoked from the nested message loop.
1024 void CancelDragTabToWindowInSeparateDisplayStep2(
1025 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest* test,
1026 TabStrip* tab_strip,
1027 aura::RootWindow* current_root,
1028 gfx::Point final_destination) {
1029 ASSERT_FALSE(tab_strip->IsDragSessionActive());
1030 ASSERT_TRUE(TabDragController::IsActive());
1031 ASSERT_EQ(2u, BrowserList::size());
1032
1033 Browser* new_browser = *(++BrowserList::begin());
1034 EXPECT_EQ(current_root,
1035 new_browser->window()->GetNativeWindow()->GetRootWindow());
1036
1037 ASSERT_TRUE(test->DragTabAndExecuteTaskWhenDone(
1038 final_destination,
1039 base::Bind(&CancelDragTabToWindowInSeparateDisplayStep3,
1040 tab_strip)));
1041 }
1042
1043 } // namespace
1044
1045 // Drags from browser to a second display and releases input.
1046 IN_PROC_BROWSER_TEST_F(
1047 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest,
1048 CancelDragTabToWindowIn2ndDisplay) {
1049 // Add another tab.
1050 AddTabAndResetBrowser(browser());
1051 TabStrip* tab_strip = GetTabStripForBrowser(browser());
1052
1053 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
1054
1055 // Move the second browser to the second display.
1056 std::vector<aura::RootWindow*> roots(ash::Shell::GetAllRootWindows());
1057 ASSERT_EQ(2u, roots.size());
1058 gfx::Point final_destination =
1059 gfx::Screen::GetDisplayNearestWindow(roots[1]).work_area().CenterPoint();
1060
1061 // Move to the first tab and drag it enough so that it detaches, but not
1062 // enough to move to another display.
1063 gfx::Point tab_0_dst(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
1064 ASSERT_TRUE(Press(tab_0_dst));
1065 tab_0_dst.Offset(0, GetDetachY(tab_strip));
1066 ASSERT_TRUE(DragTabAndExecuteTaskWhenDone(
1067 tab_0_dst, base::Bind(&CancelDragTabToWindowInSeparateDisplayStep2,
1068 this, tab_strip, roots[0], final_destination)));
1069 QuitWhenNotDragging();
1070
1071 ASSERT_EQ(1u, BrowserList::size());
1072 ASSERT_FALSE(tab_strip->IsDragSessionActive());
1073 ASSERT_FALSE(TabDragController::IsActive());
1074 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
1075
1076 // Release the mouse
1077 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
1078 ui_controls::LEFT, ui_controls::UP));
1079 }
1080
1081 // Drags from browser from a second display to primary and releases input.
1082 IN_PROC_BROWSER_TEST_F(
1083 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest,
1084 CancelDragTabToWindowIn1stDisplay) {
1085 std::vector<aura::RootWindow*> roots(ash::Shell::GetAllRootWindows());
1086 ASSERT_EQ(2u, roots.size());
1087
1088 // Add another tab.
1089 AddTabAndResetBrowser(browser());
1090 TabStrip* tab_strip = GetTabStripForBrowser(browser());
1091
1092 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
1093 EXPECT_EQ(roots[0], browser()->window()->GetNativeWindow()->GetRootWindow());
1094
1095 gfx::Rect work_area =
1096 gfx::Screen::GetDisplayNearestWindow(roots[1]).work_area();
1097 browser()->window()->SetBounds(work_area);
1098 EXPECT_EQ(roots[1], browser()->window()->GetNativeWindow()->GetRootWindow());
1099
1100 // Move the second browser to the display.
1101 gfx::Point final_destination =
1102 gfx::Screen::GetDisplayNearestWindow(roots[0]).work_area().CenterPoint();
1103
1104 // Move to the first tab and drag it enough so that it detaches, but not
1105 // enough to move to another display.
1106 gfx::Point tab_0_dst(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
1107 ASSERT_TRUE(Press(tab_0_dst));
1108 tab_0_dst.Offset(0, GetDetachY(tab_strip));
1109 ASSERT_TRUE(DragTabAndExecuteTaskWhenDone(
1110 tab_0_dst, base::Bind(&CancelDragTabToWindowInSeparateDisplayStep2,
1111 this, tab_strip, roots[1], final_destination)));
1112 QuitWhenNotDragging();
1113
1114 ASSERT_EQ(1u, BrowserList::size());
1115 ASSERT_FALSE(tab_strip->IsDragSessionActive());
1116 ASSERT_FALSE(TabDragController::IsActive());
1117 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
1118
1119 // Release the mouse
1120 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
1121 ui_controls::LEFT, ui_controls::UP));
1122 }
1123
977 #endif 1124 #endif
978 1125
979 #if defined(USE_ASH) 1126 #if defined(USE_ASH)
980 INSTANTIATE_TEST_CASE_P(TabDragging, 1127 INSTANTIATE_TEST_CASE_P(TabDragging,
981 DetachToBrowserInSeparateDisplayTabDragControllerTest, 1128 DetachToBrowserInSeparateDisplayTabDragControllerTest,
982 ::testing::Values("mouse", "touch")); 1129 ::testing::Values("mouse", "touch"));
983 INSTANTIATE_TEST_CASE_P(TabDragging, 1130 INSTANTIATE_TEST_CASE_P(TabDragging,
984 DetachToBrowserTabDragControllerTest, 1131 DetachToBrowserTabDragControllerTest,
985 ::testing::Values("mouse", "touch")); 1132 ::testing::Values("mouse", "touch"));
986 #else 1133 #else
987 INSTANTIATE_TEST_CASE_P(TabDragging, 1134 INSTANTIATE_TEST_CASE_P(TabDragging,
988 DetachToBrowserTabDragControllerTest, 1135 DetachToBrowserTabDragControllerTest,
989 ::testing::Values("mouse")); 1136 ::testing::Values("mouse"));
990 #endif 1137 #endif
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer_unittest.cc ('k') | ui/aura/client/window_move_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698