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 "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 17 matching lines...) Expand all Loading... | |
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/display/multi_display_manager.h" |
37 #include "ash/shell.h" | 37 #include "ash/shell.h" |
38 #include "ash/test/cursor_manager_test_api.h" | |
39 #include "ash/wm/cursor_manager.h" | |
38 #include "ui/aura/test/event_generator.h" | 40 #include "ui/aura/test/event_generator.h" |
39 #include "ui/aura/root_window.h" | 41 #include "ui/aura/root_window.h" |
40 #endif | 42 #endif |
41 | 43 |
42 namespace test { | 44 namespace test { |
43 | 45 |
44 namespace { | 46 namespace { |
45 | 47 |
46 const char kTabDragControllerInteractiveUITestUserDataKey[] = | 48 const char kTabDragControllerInteractiveUITestUserDataKey[] = |
47 "TabDragControllerInteractiveUITestUserData"; | 49 "TabDragControllerInteractiveUITestUserData"; |
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 | 1028 |
1027 // Release the mouse, stopping the drag session. | 1029 // Release the mouse, stopping the drag session. |
1028 ASSERT_TRUE(ReleaseInput()); | 1030 ASSERT_TRUE(ReleaseInput()); |
1029 ASSERT_FALSE(tab_strip2->IsDragSessionActive()); | 1031 ASSERT_FALSE(tab_strip2->IsDragSessionActive()); |
1030 ASSERT_FALSE(tab_strip->IsDragSessionActive()); | 1032 ASSERT_FALSE(tab_strip->IsDragSessionActive()); |
1031 ASSERT_FALSE(TabDragController::IsActive()); | 1033 ASSERT_FALSE(TabDragController::IsActive()); |
1032 EXPECT_EQ("0 100", IDString(browser2->tab_strip_model())); | 1034 EXPECT_EQ("0 100", IDString(browser2->tab_strip_model())); |
1033 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); | 1035 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); |
1034 } | 1036 } |
1035 | 1037 |
1038 class DifferentDeviceScaleFactorDisplayTabDragControllerTest | |
1039 : public DetachToBrowserTabDragControllerTest { | |
1040 public: | |
1041 DifferentDeviceScaleFactorDisplayTabDragControllerTest() {} | |
1042 | |
1043 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
1044 DetachToBrowserTabDragControllerTest::SetUpCommandLine(command_line); | |
1045 command_line->AppendSwitchASCII("aura-host-window-size", | |
1046 "400x400,800x800*2"); | |
1047 } | |
1048 | |
1049 float GetCursorDeviceScaleFactor() const { | |
1050 ash::test::CursorManagerTestApi cursor_test_api( | |
1051 ash::Shell::GetInstance()->cursor_manager()); | |
1052 return cursor_test_api.GetDeviceScaleFactor(); | |
1053 } | |
1054 | |
1055 private: | |
1056 DISALLOW_COPY_AND_ASSIGN( | |
1057 DifferentDeviceScaleFactorDisplayTabDragControllerTest); | |
1058 }; | |
1059 | |
1060 namespace { | |
1061 | |
1062 // The points where a tab is dragged in CursorDeviceScaleFactorStep. | |
1063 const struct DragPoint { | |
1064 int x; | |
1065 int y; | |
1066 } kDragPoints[] = { | |
1067 {390, 200}, | |
1068 {399, 200}, | |
1069 {410, 200}, | |
1070 {400, 200}, | |
1071 {390, 200}, | |
1072 }; | |
1073 | |
1074 // The expected device scale factors before the cursor is moved to the | |
1075 // corresponding kDragPoints in CursorDeviceScaleFactorStep. | |
1076 const float kDeviceScaleFactorExpectations[] = { | |
1077 1.0f, | |
1078 1.0f, | |
1079 2.0f, | |
1080 2.0f, | |
1081 1.0f, | |
1082 }; | |
oshima
2012/10/05 21:20:59
can you add COMPILE_ASSERT to make sure they have
mazda
2012/10/05 21:34:43
Done.
| |
1083 | |
1084 // Drags tab to |kDragPoints[N]|, then calls the next step function. | |
1085 template <int N> | |
1086 void CursorDeviceScaleFactorStep( | |
1087 DifferentDeviceScaleFactorDisplayTabDragControllerTest* test, | |
1088 TabStrip* not_attached_tab_strip) { | |
1089 ASSERT_FALSE(not_attached_tab_strip->IsDragSessionActive()); | |
1090 ASSERT_TRUE(TabDragController::IsActive()); | |
1091 | |
1092 EXPECT_EQ(kDeviceScaleFactorExpectations[N], | |
1093 test->GetCursorDeviceScaleFactor()); | |
1094 | |
1095 const DragPoint p = kDragPoints[N]; | |
1096 ASSERT_TRUE(test->DragInputToNotifyWhenDone( | |
1097 p.x, p.y, base::Bind(&CursorDeviceScaleFactorStep<N+1>, | |
oshima
2012/10/05 21:20:59
N + 1
mazda
2012/10/05 21:34:43
Done.
| |
1098 test, not_attached_tab_strip))); | |
1099 } | |
1100 | |
1101 // Finishes a serise of CursorDeviceScaleFactorStep<N> calls and ends drag. | |
1102 template <> | |
1103 void CursorDeviceScaleFactorStep<arraysize(kDragPoints)>( | |
1104 DifferentDeviceScaleFactorDisplayTabDragControllerTest* test, | |
1105 TabStrip* not_attached_tab_strip) { | |
1106 ASSERT_FALSE(not_attached_tab_strip->IsDragSessionActive()); | |
1107 ASSERT_TRUE(TabDragController::IsActive()); | |
1108 | |
1109 EXPECT_EQ(1.0f, test->GetCursorDeviceScaleFactor()); | |
1110 | |
1111 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( | |
1112 ui_controls::LEFT, ui_controls::UP)); | |
1113 } | |
1114 | |
1115 } // namespace | |
1116 | |
1117 // Verifies cursor's device scale factor is updated when a tab is moved across | |
1118 // displays with different device scale factors (http://crbug.com/154183). | |
1119 IN_PROC_BROWSER_TEST_P(DifferentDeviceScaleFactorDisplayTabDragControllerTest, | |
1120 CursorDeviceScaleFactor) { | |
1121 // Add another tab. | |
1122 AddTabAndResetBrowser(browser()); | |
1123 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | |
1124 | |
1125 // Move the second browser to the second display. | |
1126 std::vector<aura::RootWindow*> roots(ash::Shell::GetAllRootWindows()); | |
1127 ASSERT_EQ(2u, roots.size()); | |
1128 | |
1129 // Move to the first tab and drag it enough so that it detaches, but not | |
1130 // enough that it attaches to browser2. | |
1131 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | |
1132 ASSERT_TRUE(PressInput(tab_0_center)); | |
1133 ASSERT_TRUE(DragInputToNotifyWhenDone( | |
1134 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), | |
1135 base::Bind(&CursorDeviceScaleFactorStep<0>, | |
1136 this, tab_strip))); | |
1137 QuitWhenNotDragging(); | |
1138 } | |
1139 | |
1036 namespace { | 1140 namespace { |
1037 | 1141 |
1038 class DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest | 1142 class DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest |
1039 : public TabDragControllerTest { | 1143 : public TabDragControllerTest { |
1040 public: | 1144 public: |
1041 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest() {} | 1145 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest() {} |
1042 | 1146 |
1043 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 1147 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
1044 TabDragControllerTest::SetUpCommandLine(command_line); | 1148 TabDragControllerTest::SetUpCommandLine(command_line); |
1045 command_line->AppendSwitchASCII("aura-host-window-size", | 1149 command_line->AppendSwitchASCII("aura-host-window-size", |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1180 ui_controls::LEFT, ui_controls::UP)); | 1284 ui_controls::LEFT, ui_controls::UP)); |
1181 } | 1285 } |
1182 | 1286 |
1183 #endif | 1287 #endif |
1184 | 1288 |
1185 #if defined(USE_ASH) | 1289 #if defined(USE_ASH) |
1186 INSTANTIATE_TEST_CASE_P(TabDragging, | 1290 INSTANTIATE_TEST_CASE_P(TabDragging, |
1187 DetachToBrowserInSeparateDisplayTabDragControllerTest, | 1291 DetachToBrowserInSeparateDisplayTabDragControllerTest, |
1188 ::testing::Values("mouse", "touch")); | 1292 ::testing::Values("mouse", "touch")); |
1189 INSTANTIATE_TEST_CASE_P(TabDragging, | 1293 INSTANTIATE_TEST_CASE_P(TabDragging, |
1294 DifferentDeviceScaleFactorDisplayTabDragControllerTest, | |
1295 ::testing::Values("mouse")); | |
1296 INSTANTIATE_TEST_CASE_P(TabDragging, | |
1190 DetachToBrowserTabDragControllerTest, | 1297 DetachToBrowserTabDragControllerTest, |
1191 ::testing::Values("mouse", "touch")); | 1298 ::testing::Values("mouse", "touch")); |
1192 #else | 1299 #else |
1193 INSTANTIATE_TEST_CASE_P(TabDragging, | 1300 INSTANTIATE_TEST_CASE_P(TabDragging, |
1194 DetachToBrowserTabDragControllerTest, | 1301 DetachToBrowserTabDragControllerTest, |
1195 ::testing::Values("mouse")); | 1302 ::testing::Values("mouse")); |
1196 #endif | 1303 #endif |
OLD | NEW |