OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ash/magnifier/magnification_controller.h" | 5 #include "ash/magnifier/magnification_controller.h" |
6 | 6 |
7 #include "ash/magnifier/magnifier_constants.h" | 7 #include "ash/magnifier/magnifier_constants.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "ui/aura/client/aura_constants.h" | 11 #include "ui/aura/client/aura_constants.h" |
12 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
13 #include "ui/aura/test/aura_test_utils.h" | 13 #include "ui/aura/test/aura_test_utils.h" |
14 #include "ui/aura/test/event_generator.h" | |
15 #include "ui/aura/window_tree_host.h" | 14 #include "ui/aura/window_tree_host.h" |
| 15 #include "ui/events/test/event_generator.h" |
16 #include "ui/gfx/rect_conversions.h" | 16 #include "ui/gfx/rect_conversions.h" |
17 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
18 | 18 |
19 namespace ash { | 19 namespace ash { |
20 namespace { | 20 namespace { |
21 | 21 |
22 const int kRootHeight = 600; | 22 const int kRootHeight = 600; |
23 const int kRootWidth = 800; | 23 const int kRootWidth = 800; |
24 | 24 |
25 } // namespace | 25 } // namespace |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 EXPECT_EQ("0,300 400x300", GetViewport().ToString()); | 166 EXPECT_EQ("0,300 400x300", GetViewport().ToString()); |
167 | 167 |
168 GetMagnificationController()->MoveWindow(200, 400, false); | 168 GetMagnificationController()->MoveWindow(200, 400, false); |
169 EXPECT_EQ("200,300 400x300", GetViewport().ToString()); | 169 EXPECT_EQ("200,300 400x300", GetViewport().ToString()); |
170 | 170 |
171 GetMagnificationController()->MoveWindow(1000, 1000, false); | 171 GetMagnificationController()->MoveWindow(1000, 1000, false); |
172 EXPECT_EQ("400,300 400x300", GetViewport().ToString()); | 172 EXPECT_EQ("400,300 400x300", GetViewport().ToString()); |
173 } | 173 } |
174 | 174 |
175 TEST_F(MagnificationControllerTest, PointOfInterest) { | 175 TEST_F(MagnificationControllerTest, PointOfInterest) { |
176 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 176 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
177 | 177 |
178 generator.MoveMouseToInHost(gfx::Point(0, 0)); | 178 generator.MoveMouseToInHost(gfx::Point(0, 0)); |
179 EXPECT_EQ("0,0", CurrentPointOfInterest()); | 179 EXPECT_EQ("0,0", CurrentPointOfInterest()); |
180 | 180 |
181 generator.MoveMouseToInHost(gfx::Point(799, 599)); | 181 generator.MoveMouseToInHost(gfx::Point(799, 599)); |
182 EXPECT_EQ("799,599", CurrentPointOfInterest()); | 182 EXPECT_EQ("799,599", CurrentPointOfInterest()); |
183 | 183 |
184 generator.MoveMouseToInHost(gfx::Point(400, 300)); | 184 generator.MoveMouseToInHost(gfx::Point(400, 300)); |
185 EXPECT_EQ("400,300", CurrentPointOfInterest()); | 185 EXPECT_EQ("400,300", CurrentPointOfInterest()); |
186 | 186 |
187 GetMagnificationController()->SetEnabled(true); | 187 GetMagnificationController()->SetEnabled(true); |
188 EXPECT_EQ("400,300", CurrentPointOfInterest()); | 188 EXPECT_EQ("400,300", CurrentPointOfInterest()); |
189 | 189 |
190 generator.MoveMouseToInHost(gfx::Point(500, 400)); | 190 generator.MoveMouseToInHost(gfx::Point(500, 400)); |
191 EXPECT_EQ("450,350", CurrentPointOfInterest()); | 191 EXPECT_EQ("450,350", CurrentPointOfInterest()); |
192 } | 192 } |
193 | 193 |
194 TEST_F(MagnificationControllerTest, PanWindow2xLeftToRight) { | 194 TEST_F(MagnificationControllerTest, PanWindow2xLeftToRight) { |
195 const aura::Env* env = aura::Env::GetInstance(); | 195 const aura::Env* env = aura::Env::GetInstance(); |
196 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 196 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
197 | 197 |
198 generator.MoveMouseToInHost(gfx::Point(0, 0)); | 198 generator.MoveMouseToInHost(gfx::Point(0, 0)); |
199 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); | 199 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
200 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); | 200 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
201 EXPECT_EQ("0,0", env->last_mouse_location().ToString()); | 201 EXPECT_EQ("0,0", env->last_mouse_location().ToString()); |
202 | 202 |
203 // Enables magnifier and confirm the viewport is at center. | 203 // Enables magnifier and confirm the viewport is at center. |
204 GetMagnificationController()->SetEnabled(true); | 204 GetMagnificationController()->SetEnabled(true); |
205 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); | 205 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
206 | 206 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 EXPECT_EQ("780,75", env->last_mouse_location().ToString()); | 290 EXPECT_EQ("780,75", env->last_mouse_location().ToString()); |
291 EXPECT_EQ("400,0 400x300", GetViewport().ToString()); | 291 EXPECT_EQ("400,0 400x300", GetViewport().ToString()); |
292 | 292 |
293 generator.MoveMouseToInHost(gfx::Point(799, 150)); | 293 generator.MoveMouseToInHost(gfx::Point(799, 150)); |
294 EXPECT_EQ("799,75", env->last_mouse_location().ToString()); | 294 EXPECT_EQ("799,75", env->last_mouse_location().ToString()); |
295 EXPECT_EQ("400,0 400x300", GetViewport().ToString()); | 295 EXPECT_EQ("400,0 400x300", GetViewport().ToString()); |
296 } | 296 } |
297 | 297 |
298 TEST_F(MagnificationControllerTest, PanWindow2xRightToLeft) { | 298 TEST_F(MagnificationControllerTest, PanWindow2xRightToLeft) { |
299 const aura::Env* env = aura::Env::GetInstance(); | 299 const aura::Env* env = aura::Env::GetInstance(); |
300 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 300 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
301 | 301 |
302 generator.MoveMouseToInHost(gfx::Point(799, 300)); | 302 generator.MoveMouseToInHost(gfx::Point(799, 300)); |
303 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); | 303 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
304 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); | 304 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
305 EXPECT_EQ("799,300", env->last_mouse_location().ToString()); | 305 EXPECT_EQ("799,300", env->last_mouse_location().ToString()); |
306 | 306 |
307 // Enables magnifier and confirm the viewport is at center. | 307 // Enables magnifier and confirm the viewport is at center. |
308 GetMagnificationController()->SetEnabled(true); | 308 GetMagnificationController()->SetEnabled(true); |
309 | 309 |
310 generator.MoveMouseToInHost(gfx::Point(799, 300)); | 310 generator.MoveMouseToInHost(gfx::Point(799, 300)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 EXPECT_EQ("50,300", env->last_mouse_location().ToString()); | 343 EXPECT_EQ("50,300", env->last_mouse_location().ToString()); |
344 EXPECT_EQ("0,150 400x300", GetViewport().ToString()); | 344 EXPECT_EQ("0,150 400x300", GetViewport().ToString()); |
345 | 345 |
346 generator.MoveMouseToInHost(gfx::Point(0, 300)); | 346 generator.MoveMouseToInHost(gfx::Point(0, 300)); |
347 EXPECT_EQ("0,300", env->last_mouse_location().ToString()); | 347 EXPECT_EQ("0,300", env->last_mouse_location().ToString()); |
348 EXPECT_EQ("0,150 400x300", GetViewport().ToString()); | 348 EXPECT_EQ("0,150 400x300", GetViewport().ToString()); |
349 } | 349 } |
350 | 350 |
351 TEST_F(MagnificationControllerTest, PanWindowToRight) { | 351 TEST_F(MagnificationControllerTest, PanWindowToRight) { |
352 const aura::Env* env = aura::Env::GetInstance(); | 352 const aura::Env* env = aura::Env::GetInstance(); |
353 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 353 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
354 | 354 |
355 generator.MoveMouseToInHost(gfx::Point(400, 300)); | 355 generator.MoveMouseToInHost(gfx::Point(400, 300)); |
356 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); | 356 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
357 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); | 357 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
358 EXPECT_EQ("400,300", env->last_mouse_location().ToString()); | 358 EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
359 | 359 |
360 float scale = 2.f; | 360 float scale = 2.f; |
361 | 361 |
362 // Enables magnifier and confirm the viewport is at center. | 362 // Enables magnifier and confirm the viewport is at center. |
363 GetMagnificationController()->SetEnabled(true); | 363 GetMagnificationController()->SetEnabled(true); |
(...skipping 25 matching lines...) Expand all Loading... |
389 scale *= kMagnificationScaleFactor; | 389 scale *= kMagnificationScaleFactor; |
390 GetMagnificationController()->SetScale(scale, false); | 390 GetMagnificationController()->SetScale(scale, false); |
391 EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); | 391 EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); |
392 generator.MoveMouseToInHost(gfx::Point(799, 300)); | 392 generator.MoveMouseToInHost(gfx::Point(799, 300)); |
393 EXPECT_EQ("649,298", env->last_mouse_location().ToString()); | 393 EXPECT_EQ("649,298", env->last_mouse_location().ToString()); |
394 EXPECT_EQ("704,300", GetHostMouseLocation()); | 394 EXPECT_EQ("704,300", GetHostMouseLocation()); |
395 } | 395 } |
396 | 396 |
397 TEST_F(MagnificationControllerTest, PanWindowToLeft) { | 397 TEST_F(MagnificationControllerTest, PanWindowToLeft) { |
398 const aura::Env* env = aura::Env::GetInstance(); | 398 const aura::Env* env = aura::Env::GetInstance(); |
399 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 399 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
400 | 400 |
401 generator.MoveMouseToInHost(gfx::Point(400, 300)); | 401 generator.MoveMouseToInHost(gfx::Point(400, 300)); |
402 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); | 402 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
403 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); | 403 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
404 EXPECT_EQ("400,300", env->last_mouse_location().ToString()); | 404 EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
405 | 405 |
406 float scale = 2.f; | 406 float scale = 2.f; |
407 | 407 |
408 // Enables magnifier and confirm the viewport is at center. | 408 // Enables magnifier and confirm the viewport is at center. |
409 GetMagnificationController()->SetEnabled(true); | 409 GetMagnificationController()->SetEnabled(true); |
(...skipping 24 matching lines...) Expand all Loading... |
434 | 434 |
435 scale *= kMagnificationScaleFactor; | 435 scale *= kMagnificationScaleFactor; |
436 GetMagnificationController()->SetScale(scale, false); | 436 GetMagnificationController()->SetScale(scale, false); |
437 EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); | 437 EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); |
438 generator.MoveMouseToInHost(gfx::Point(0, 300)); | 438 generator.MoveMouseToInHost(gfx::Point(0, 300)); |
439 EXPECT_EQ("139,298", env->last_mouse_location().ToString()); | 439 EXPECT_EQ("139,298", env->last_mouse_location().ToString()); |
440 EXPECT_EQ("100,300", GetHostMouseLocation()); | 440 EXPECT_EQ("100,300", GetHostMouseLocation()); |
441 } | 441 } |
442 | 442 |
443 } // namespace ash | 443 } // namespace ash |
OLD | NEW |