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

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: win fix, adjust test screen size 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(DetachToBrowserInSeparateDisplayAndCancelTabDragControlle rTest,
sky 2012/09/10 14:11:37 > 80
oshima 2012/09/10 15:49:11 Done.
1047 CancelDragTabToWindowIn2ndDisplay) {
1048 // Add another tab.
1049 AddTabAndResetBrowser(browser());
1050 TabStrip* tab_strip = GetTabStripForBrowser(browser());
1051
1052 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
1053
1054 // Move the second browser to the second display.
1055 std::vector<aura::RootWindow*> roots(ash::Shell::GetAllRootWindows());
1056 ASSERT_EQ(2u, roots.size());
1057 gfx::Point final_destination =
1058 gfx::Screen::GetDisplayNearestWindow(roots[1]).work_area().CenterPoint();
1059
1060 // Move to the first tab and drag it enough so that it detaches, but not
1061 // enough to move to another display.
1062 gfx::Point tab_0_dst(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
1063 ASSERT_TRUE(Press(tab_0_dst));
1064 tab_0_dst.Offset(0, GetDetachY(tab_strip));
1065 ASSERT_TRUE(DragTabAndExecuteTaskWhenDone(
1066 tab_0_dst, base::Bind(&CancelDragTabToWindowInSeparateDisplayStep2,
1067 this, tab_strip, roots[0], final_destination)));
1068 QuitWhenNotDragging();
1069
1070 ASSERT_EQ(1u, BrowserList::size());
1071 ASSERT_FALSE(tab_strip->IsDragSessionActive());
1072 ASSERT_FALSE(TabDragController::IsActive());
1073 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
1074
1075 // Release the mouse
1076 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
1077 ui_controls::LEFT, ui_controls::UP));
1078 }
1079
1080 // Drags from browser from a second display to primary and releases input.
1081 IN_PROC_BROWSER_TEST_F(
1082 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest,
1083 CancelDragTabToWindowIn1stDisplay) {
1084 std::vector<aura::RootWindow*> roots(ash::Shell::GetAllRootWindows());
1085 ASSERT_EQ(2u, roots.size());
1086
1087 // Add another tab.
1088 AddTabAndResetBrowser(browser());
1089 TabStrip* tab_strip = GetTabStripForBrowser(browser());
1090
1091 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
1092 EXPECT_EQ(roots[0], browser()->window()->GetNativeWindow()->GetRootWindow());
1093
1094 gfx::Rect work_area =
1095 gfx::Screen::GetDisplayNearestWindow(roots[1]).work_area();
1096 browser()->window()->SetBounds(work_area);
1097 EXPECT_EQ(roots[1], browser()->window()->GetNativeWindow()->GetRootWindow());
1098
1099 // Move the second browser to the display.
1100 gfx::Point final_destination =
1101 gfx::Screen::GetDisplayNearestWindow(roots[0]).work_area().CenterPoint();
1102
1103 // Move to the first tab and drag it enough so that it detaches, but not
1104 // enough to move to another display.
1105 gfx::Point tab_0_dst(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
1106 ASSERT_TRUE(Press(tab_0_dst));
1107 tab_0_dst.Offset(0, GetDetachY(tab_strip));
1108 ASSERT_TRUE(DragTabAndExecuteTaskWhenDone(
1109 tab_0_dst, base::Bind(&CancelDragTabToWindowInSeparateDisplayStep2,
1110 this, tab_strip, roots[1], final_destination)));
1111 QuitWhenNotDragging();
1112
1113 ASSERT_EQ(1u, BrowserList::size());
1114 ASSERT_FALSE(tab_strip->IsDragSessionActive());
1115 ASSERT_FALSE(TabDragController::IsActive());
1116 EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
1117
1118 // Release the mouse
1119 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
1120 ui_controls::LEFT, ui_controls::UP));
1121 }
1122
977 #endif 1123 #endif
978 1124
979 #if defined(USE_ASH) 1125 #if defined(USE_ASH)
980 INSTANTIATE_TEST_CASE_P(TabDragging, 1126 INSTANTIATE_TEST_CASE_P(TabDragging,
981 DetachToBrowserInSeparateDisplayTabDragControllerTest, 1127 DetachToBrowserInSeparateDisplayTabDragControllerTest,
982 ::testing::Values("mouse", "touch")); 1128 ::testing::Values("mouse", "touch"));
983 INSTANTIATE_TEST_CASE_P(TabDragging, 1129 INSTANTIATE_TEST_CASE_P(TabDragging,
984 DetachToBrowserTabDragControllerTest, 1130 DetachToBrowserTabDragControllerTest,
985 ::testing::Values("mouse", "touch")); 1131 ::testing::Values("mouse", "touch"));
986 #else 1132 #else
987 INSTANTIATE_TEST_CASE_P(TabDragging, 1133 INSTANTIATE_TEST_CASE_P(TabDragging,
988 DetachToBrowserTabDragControllerTest, 1134 DetachToBrowserTabDragControllerTest,
989 ::testing::Values("mouse")); 1135 ::testing::Values("mouse"));
990 #endif 1136 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698