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" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
30 #include "ui/gfx/screen.h" | 30 #include "ui/gfx/screen.h" |
31 #include "ui/ui_controls/ui_controls.h" | 31 #include "ui/ui_controls/ui_controls.h" |
32 #include "ui/views/view.h" | 32 #include "ui/views/view.h" |
33 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
34 | 34 |
35 #if defined(USE_ASH) | 35 #if defined(USE_ASH) |
36 #include "ash/display/display_controller.h" | 36 #include "ash/display/display_controller.h" |
37 #include "ash/display/multi_display_manager.h" | 37 #include "ash/display/multi_display_manager.h" |
38 #include "ash/shell.h" | 38 #include "ash/shell.h" |
39 #include "ash/test/cursor_manager_test_api.h" | |
40 #include "ash/wm/cursor_manager.h" | |
39 #include "ui/aura/test/event_generator.h" | 41 #include "ui/aura/test/event_generator.h" |
40 #include "ui/aura/root_window.h" | 42 #include "ui/aura/root_window.h" |
41 #endif | 43 #endif |
42 | 44 |
43 namespace test { | 45 namespace test { |
44 | 46 |
45 namespace { | 47 namespace { |
46 | 48 |
47 const char kTabDragControllerInteractiveUITestUserDataKey[] = | 49 const char kTabDragControllerInteractiveUITestUserDataKey[] = |
48 "TabDragControllerInteractiveUITestUserData"; | 50 "TabDragControllerInteractiveUITestUserData"; |
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1108 | 1110 |
1109 // Release the mouse, stopping the drag session. | 1111 // Release the mouse, stopping the drag session. |
1110 ASSERT_TRUE(ReleaseInput()); | 1112 ASSERT_TRUE(ReleaseInput()); |
1111 ASSERT_FALSE(tab_strip2->IsDragSessionActive()); | 1113 ASSERT_FALSE(tab_strip2->IsDragSessionActive()); |
1112 ASSERT_FALSE(tab_strip->IsDragSessionActive()); | 1114 ASSERT_FALSE(tab_strip->IsDragSessionActive()); |
1113 ASSERT_FALSE(TabDragController::IsActive()); | 1115 ASSERT_FALSE(TabDragController::IsActive()); |
1114 EXPECT_EQ("0 100", IDString(browser2->tab_strip_model())); | 1116 EXPECT_EQ("0 100", IDString(browser2->tab_strip_model())); |
1115 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); | 1117 EXPECT_EQ("1", IDString(browser()->tab_strip_model())); |
1116 } | 1118 } |
1117 | 1119 |
1120 class DifferentDeviceScaleFactorDisplayTabDragControllerTest | |
1121 : public DetachToBrowserTabDragControllerTest { | |
1122 public: | |
1123 DifferentDeviceScaleFactorDisplayTabDragControllerTest() {} | |
1124 | |
1125 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
1126 DetachToBrowserTabDragControllerTest::SetUpCommandLine(command_line); | |
1127 command_line->AppendSwitchASCII("aura-host-window-size", | |
1128 "400x400,800x800*2"); | |
1129 } | |
1130 | |
1131 float GetCursorDeviceScaleFactor() const { | |
1132 ash::test::CursorManagerTestApi cursor_test_api( | |
1133 ash::Shell::GetInstance()->cursor_manager()); | |
1134 return cursor_test_api.GetDeviceScaleFactor(); | |
1135 } | |
1136 | |
1137 private: | |
1138 DISALLOW_COPY_AND_ASSIGN( | |
1139 DifferentDeviceScaleFactorDisplayTabDragControllerTest); | |
1140 }; | |
1141 | |
1142 namespace { | |
1143 | |
1144 // The points where a tab is dragged in CursorDeviceScaleFactorStep. | |
1145 const struct DragPoint { | |
1146 int x; | |
1147 int y; | |
1148 } kDragPoints[] = { | |
1149 {300, 200}, | |
1150 {399, 200}, | |
1151 {500, 200}, | |
1152 {400, 200}, | |
1153 {300, 200}, | |
1154 }; | |
1155 | |
1156 // The expected device scale factors before the cursor is moved to the | |
1157 // corresponding kDragPoints in CursorDeviceScaleFactorStep. | |
1158 const float kDeviceScaleFactorExpectations[] = { | |
1159 1.0f, | |
1160 1.0f, | |
1161 2.0f, | |
1162 2.0f, | |
1163 1.0f, | |
1164 }; | |
1165 | |
1166 COMPILE_ASSERT( | |
1167 arraysize(kDragPoints) == arraysize(kDeviceScaleFactorExpectations), | |
1168 kDragPoints_and_kDeviceScaleFactorExpectations_must_have_same_size); | |
1169 | |
1170 // Drags tab to |kDragPoints[index]|, then calls the next step function. | |
1171 void CursorDeviceScaleFactorStep( | |
1172 DifferentDeviceScaleFactorDisplayTabDragControllerTest* test, | |
1173 TabStrip* not_attached_tab_strip, | |
1174 size_t index) { | |
1175 ASSERT_FALSE(not_attached_tab_strip->IsDragSessionActive()); | |
1176 ASSERT_TRUE(TabDragController::IsActive()); | |
1177 | |
1178 if (index < arraysize(kDragPoints)) { | |
1179 EXPECT_EQ(kDeviceScaleFactorExpectations[index], | |
1180 test->GetCursorDeviceScaleFactor()); | |
1181 const DragPoint p = kDragPoints[index]; | |
1182 ASSERT_TRUE(test->DragInputToNotifyWhenDone( | |
1183 p.x, p.y, base::Bind(&CursorDeviceScaleFactorStep, | |
1184 test, not_attached_tab_strip, index + 1))); | |
1185 } else { | |
1186 // Finishes a serise of CursorDeviceScaleFactorStep calls and ends drag. | |
1187 EXPECT_EQ(1.0f, test->GetCursorDeviceScaleFactor()); | |
1188 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( | |
1189 ui_controls::LEFT, ui_controls::UP)); | |
1190 } | |
1191 } | |
1192 | |
1193 } // namespace | |
1194 | |
1195 // Verifies cursor's device scale factor is updated when a tab is moved across | |
1196 // displays with different device scale factors (http://crbug.com/154183). | |
1197 IN_PROC_BROWSER_TEST_P(DifferentDeviceScaleFactorDisplayTabDragControllerTest, | |
1198 CursorDeviceScaleFactor) { | |
1199 // Add another tab. | |
1200 AddTabAndResetBrowser(browser()); | |
1201 TabStrip* tab_strip = GetTabStripForBrowser(browser()); | |
1202 | |
1203 // Move the second browser to the second display. | |
1204 std::vector<aura::RootWindow*> roots(ash::Shell::GetAllRootWindows()); | |
1205 ASSERT_EQ(2u, roots.size()); | |
1206 | |
1207 // Move to the first tab and drag it enough so that it detaches, but not | |
1208 // enough that it attaches to browser2. | |
sky
2012/10/18 00:13:37
there is no browser2 here.
mazda
2012/10/18 00:26:16
Fixed the comment. Thanks.
| |
1209 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0))); | |
1210 ASSERT_TRUE(PressInput(tab_0_center)); | |
1211 ASSERT_TRUE(DragInputToNotifyWhenDone( | |
1212 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip), | |
1213 base::Bind(&CursorDeviceScaleFactorStep, | |
1214 this, tab_strip, 0))); | |
1215 QuitWhenNotDragging(); | |
1216 } | |
1217 | |
1118 namespace { | 1218 namespace { |
1119 | 1219 |
1120 class DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest | 1220 class DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest |
1121 : public TabDragControllerTest { | 1221 : public TabDragControllerTest { |
1122 public: | 1222 public: |
1123 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest() {} | 1223 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest() {} |
1124 | 1224 |
1125 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 1225 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
1126 TabDragControllerTest::SetUpCommandLine(command_line); | 1226 TabDragControllerTest::SetUpCommandLine(command_line); |
1127 command_line->AppendSwitchASCII("aura-host-window-size", | 1227 command_line->AppendSwitchASCII("aura-host-window-size", |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1264 ui_controls::LEFT, ui_controls::UP)); | 1364 ui_controls::LEFT, ui_controls::UP)); |
1265 } | 1365 } |
1266 | 1366 |
1267 #endif | 1367 #endif |
1268 | 1368 |
1269 #if defined(USE_ASH) | 1369 #if defined(USE_ASH) |
1270 INSTANTIATE_TEST_CASE_P(TabDragging, | 1370 INSTANTIATE_TEST_CASE_P(TabDragging, |
1271 DetachToBrowserInSeparateDisplayTabDragControllerTest, | 1371 DetachToBrowserInSeparateDisplayTabDragControllerTest, |
1272 ::testing::Values("mouse", "touch")); | 1372 ::testing::Values("mouse", "touch")); |
1273 INSTANTIATE_TEST_CASE_P(TabDragging, | 1373 INSTANTIATE_TEST_CASE_P(TabDragging, |
1374 DifferentDeviceScaleFactorDisplayTabDragControllerTest, | |
1375 ::testing::Values("mouse")); | |
1376 INSTANTIATE_TEST_CASE_P(TabDragging, | |
1274 DetachToBrowserTabDragControllerTest, | 1377 DetachToBrowserTabDragControllerTest, |
1275 ::testing::Values("mouse", "touch")); | 1378 ::testing::Values("mouse", "touch")); |
1276 #else | 1379 #else |
1277 INSTANTIATE_TEST_CASE_P(TabDragging, | 1380 INSTANTIATE_TEST_CASE_P(TabDragging, |
1278 DetachToBrowserTabDragControllerTest, | 1381 DetachToBrowserTabDragControllerTest, |
1279 ::testing::Values("mouse")); | 1382 ::testing::Values("mouse")); |
1280 #endif | 1383 #endif |
OLD | NEW |