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

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

Issue 11033038: Fix the issue of cursor's device scale factor when using monitors with differnt device scale factor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comment and rebase Created 8 years, 2 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
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer_unittest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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
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[N]|, then calls the next step function.
1171 template <int N>
sky 2012/10/17 21:29:42 Ugh. Why do we need the templates here? Can't we j
mazda 2012/10/17 23:44:29 Rewrote it without using template.
1172 void CursorDeviceScaleFactorStep(
1173 DifferentDeviceScaleFactorDisplayTabDragControllerTest* test,
1174 TabStrip* not_attached_tab_strip) {
1175 ASSERT_FALSE(not_attached_tab_strip->IsDragSessionActive());
1176 ASSERT_TRUE(TabDragController::IsActive());
1177
1178 EXPECT_EQ(kDeviceScaleFactorExpectations[N],
1179 test->GetCursorDeviceScaleFactor());
1180
1181 const DragPoint p = kDragPoints[N];
1182 ASSERT_TRUE(test->DragInputToNotifyWhenDone(
1183 p.x, p.y, base::Bind(&CursorDeviceScaleFactorStep<N + 1>,
1184 test, not_attached_tab_strip)));
1185 }
1186
1187 // Finishes a serise of CursorDeviceScaleFactorStep<N> calls and ends drag.
1188 template <>
1189 void CursorDeviceScaleFactorStep<arraysize(kDragPoints)>(
1190 DifferentDeviceScaleFactorDisplayTabDragControllerTest* test,
1191 TabStrip* not_attached_tab_strip) {
1192 ASSERT_FALSE(not_attached_tab_strip->IsDragSessionActive());
1193 ASSERT_TRUE(TabDragController::IsActive());
1194
1195 EXPECT_EQ(1.0f, test->GetCursorDeviceScaleFactor());
1196
1197 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
1198 ui_controls::LEFT, ui_controls::UP));
1199 }
1200
1201 } // namespace
1202
1203 // Verifies cursor's device scale factor is updated when a tab is moved across
1204 // displays with different device scale factors (http://crbug.com/154183).
1205 IN_PROC_BROWSER_TEST_P(DifferentDeviceScaleFactorDisplayTabDragControllerTest,
1206 CursorDeviceScaleFactor) {
1207 // Add another tab.
1208 AddTabAndResetBrowser(browser());
1209 TabStrip* tab_strip = GetTabStripForBrowser(browser());
1210
1211 // Move the second browser to the second display.
1212 std::vector<aura::RootWindow*> roots(ash::Shell::GetAllRootWindows());
1213 ASSERT_EQ(2u, roots.size());
1214
1215 // Move to the first tab and drag it enough so that it detaches, but not
1216 // enough that it attaches to browser2.
1217 gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
1218 ASSERT_TRUE(PressInput(tab_0_center));
1219 ASSERT_TRUE(DragInputToNotifyWhenDone(
1220 tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
1221 base::Bind(&CursorDeviceScaleFactorStep<0>,
1222 this, tab_strip)));
1223 QuitWhenNotDragging();
1224 }
1225
1118 namespace { 1226 namespace {
1119 1227
1120 class DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest 1228 class DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest
1121 : public TabDragControllerTest { 1229 : public TabDragControllerTest {
1122 public: 1230 public:
1123 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest() {} 1231 DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest() {}
1124 1232
1125 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 1233 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
1126 TabDragControllerTest::SetUpCommandLine(command_line); 1234 TabDragControllerTest::SetUpCommandLine(command_line);
1127 command_line->AppendSwitchASCII("aura-host-window-size", 1235 command_line->AppendSwitchASCII("aura-host-window-size",
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 ui_controls::LEFT, ui_controls::UP)); 1372 ui_controls::LEFT, ui_controls::UP));
1265 } 1373 }
1266 1374
1267 #endif 1375 #endif
1268 1376
1269 #if defined(USE_ASH) 1377 #if defined(USE_ASH)
1270 INSTANTIATE_TEST_CASE_P(TabDragging, 1378 INSTANTIATE_TEST_CASE_P(TabDragging,
1271 DetachToBrowserInSeparateDisplayTabDragControllerTest, 1379 DetachToBrowserInSeparateDisplayTabDragControllerTest,
1272 ::testing::Values("mouse", "touch")); 1380 ::testing::Values("mouse", "touch"));
1273 INSTANTIATE_TEST_CASE_P(TabDragging, 1381 INSTANTIATE_TEST_CASE_P(TabDragging,
1382 DifferentDeviceScaleFactorDisplayTabDragControllerTest,
1383 ::testing::Values("mouse"));
1384 INSTANTIATE_TEST_CASE_P(TabDragging,
1274 DetachToBrowserTabDragControllerTest, 1385 DetachToBrowserTabDragControllerTest,
1275 ::testing::Values("mouse", "touch")); 1386 ::testing::Values("mouse", "touch"));
1276 #else 1387 #else
1277 INSTANTIATE_TEST_CASE_P(TabDragging, 1388 INSTANTIATE_TEST_CASE_P(TabDragging,
1278 DetachToBrowserTabDragControllerTest, 1389 DetachToBrowserTabDragControllerTest,
1279 ::testing::Values("mouse")); 1390 ::testing::Values("mouse"));
1280 #endif 1391 #endif
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer_unittest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698