OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <math.h> | 5 #include <math.h> |
6 | 6 |
7 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 7 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
8 | 8 |
9 #include "ash/accelerometer/accelerometer_controller.h" | 9 #include "ash/accelerometer/accelerometer_controller.h" |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
11 #include "ash/display/display_manager.h" | 11 #include "ash/display/display_manager.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/system/tray/system_tray_delegate.h" | 13 #include "ash/system/tray/system_tray_delegate.h" |
14 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
15 #include "ash/test/display_manager_test_api.h" | 15 #include "ash/test/display_manager_test_api.h" |
16 #include "ash/test/test_system_tray_delegate.h" | 16 #include "ash/test/test_system_tray_delegate.h" |
17 #include "ash/test/test_volume_control_delegate.h" | 17 #include "ash/test/test_volume_control_delegate.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/test/simple_test_tick_clock.h" | 19 #include "base/test/simple_test_tick_clock.h" |
20 #include "ui/accelerometer/accelerometer_types.h" | 20 #include "ui/accelerometer/accelerometer_types.h" |
21 #include "ui/events/event_handler.h" | 21 #include "ui/events/event_handler.h" |
22 #include "ui/events/test/event_generator.h" | 22 #include "ui/events/test/event_generator.h" |
23 #include "ui/gfx/geometry/vector3d_f.h" | 23 #include "ui/gfx/geometry/vector3d_f.h" |
24 #include "ui/message_center/message_center.h" | 24 #include "ui/message_center/message_center.h" |
25 | 25 |
| 26 #if defined(OS_CHROMEOS) |
| 27 #include "ash/content/display/screen_orientation_delegate_chromeos.h" |
| 28 #endif |
| 29 |
26 #if defined(USE_X11) | 30 #if defined(USE_X11) |
27 #include "ui/events/test/events_test_utils_x11.h" | 31 #include "ui/events/test/events_test_utils_x11.h" |
28 #endif | 32 #endif |
29 | 33 |
30 namespace ash { | 34 namespace ash { |
31 | 35 |
32 namespace { | 36 namespace { |
33 | 37 |
34 const float kDegreesToRadians = 3.1415926f / 180.0f; | 38 const float kDegreesToRadians = 3.1415926f / 180.0f; |
35 const float kMeanGravity = 9.8066f; | 39 const float kMeanGravity = 9.8066f; |
36 | 40 |
| 41 #if defined(OS_CHROMEOS) |
| 42 bool rotation_locked() { |
| 43 return Shell::GetInstance()->screen_orientation_delegate()->rotation_locked(); |
| 44 } |
| 45 |
| 46 void SetRotationLocked(bool rotation_locked) { |
| 47 Shell::GetInstance()->screen_orientation_delegate()->SetRotationLocked( |
| 48 rotation_locked); |
| 49 } |
| 50 #endif // OS_CHROMEOS |
| 51 |
37 } // namespace | 52 } // namespace |
38 | 53 |
39 // Test accelerometer data taken with the lid at less than 180 degrees while | 54 // Test accelerometer data taken with the lid at less than 180 degrees while |
40 // shaking the device around. The data is to be interpreted in groups of 6 where | 55 // shaking the device around. The data is to be interpreted in groups of 6 where |
41 // each 6 values corresponds to the X, Y, and Z readings from the base and lid | 56 // each 6 values corresponds to the X, Y, and Z readings from the base and lid |
42 // accelerometers in this order. | 57 // accelerometers in this order. |
43 extern const float kAccelerometerLaptopModeTestData[]; | 58 extern const float kAccelerometerLaptopModeTestData[]; |
44 extern const size_t kAccelerometerLaptopModeTestDataLength; | 59 extern const size_t kAccelerometerLaptopModeTestDataLength; |
45 | 60 |
46 // Test accelerometer data taken with the lid open 360 degrees while | 61 // Test accelerometer data taken with the lid open 360 degrees while |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 312 gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
298 EXPECT_TRUE(IsMaximizeModeStarted()); | 313 EXPECT_TRUE(IsMaximizeModeStarted()); |
299 | 314 |
300 // Normal 90 degree orientation but near vertical should stay in maximize | 315 // Normal 90 degree orientation but near vertical should stay in maximize |
301 // mode. | 316 // mode. |
302 TriggerAccelerometerUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, -0.1f), | 317 TriggerAccelerometerUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, -0.1f), |
303 gfx::Vector3dF(kMeanGravity, -0.1f, 0.0f)); | 318 gfx::Vector3dF(kMeanGravity, -0.1f, 0.0f)); |
304 EXPECT_TRUE(IsMaximizeModeStarted()); | 319 EXPECT_TRUE(IsMaximizeModeStarted()); |
305 } | 320 } |
306 | 321 |
| 322 #if defined(OS_CHROMEOS) |
307 // Tests that accelerometer readings in each of the screen angles will trigger a | 323 // Tests that accelerometer readings in each of the screen angles will trigger a |
308 // rotation of the internal display. | 324 // rotation of the internal display. |
309 TEST_F(MaximizeModeControllerTest, DisplayRotation) { | 325 TEST_F(MaximizeModeControllerTest, DisplayRotation) { |
310 // Trigger maximize mode by opening to 270. | 326 // Trigger maximize mode by opening to 270. |
311 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), | 327 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), |
312 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 328 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
313 ASSERT_TRUE(IsMaximizeModeStarted()); | 329 ASSERT_TRUE(IsMaximizeModeStarted()); |
314 | 330 |
315 // Now test rotating in all directions. | 331 // Now test rotating in all directions. |
316 TriggerAccelerometerUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f), | 332 TriggerAccelerometerUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f), |
317 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); | 333 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
318 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); | 334 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
319 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f), | 335 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f), |
320 gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 336 gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
321 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); | 337 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); |
322 TriggerAccelerometerUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f), | 338 TriggerAccelerometerUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f), |
323 gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); | 339 gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
324 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); | 340 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); |
325 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f), | 341 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f), |
326 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 342 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
327 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); | 343 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
328 } | 344 } |
| 345 #endif // OS_CHROMEOS |
329 | 346 |
330 // Tests that low angles are ignored by the accelerometer (i.e. when the device | 347 // Tests that low angles are ignored by the accelerometer (i.e. when the device |
331 // is almost laying flat). | 348 // is almost laying flat). |
332 TEST_F(MaximizeModeControllerTest, RotationIgnoresLowAngles) { | 349 TEST_F(MaximizeModeControllerTest, RotationIgnoresLowAngles) { |
333 // Trigger maximize mode by opening to 270. | 350 // Trigger maximize mode by opening to 270. |
334 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), | 351 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), |
335 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 352 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
336 ASSERT_TRUE(IsMaximizeModeStarted()); | 353 ASSERT_TRUE(IsMaximizeModeStarted()); |
337 | 354 |
338 TriggerAccelerometerUpdate( | 355 TriggerAccelerometerUpdate( |
339 gfx::Vector3dF(0.0f, kMeanGravity, kMeanGravity), | 356 gfx::Vector3dF(0.0f, kMeanGravity, kMeanGravity), |
340 gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity)); | 357 gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity)); |
341 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); | 358 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
342 TriggerAccelerometerUpdate(gfx::Vector3dF(-2.0f, 0.0f, kMeanGravity), | 359 TriggerAccelerometerUpdate(gfx::Vector3dF(-2.0f, 0.0f, kMeanGravity), |
343 gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity)); | 360 gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity)); |
344 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); | 361 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
345 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -2.0f, kMeanGravity), | 362 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -2.0f, kMeanGravity), |
346 gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity)); | 363 gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity)); |
347 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); | 364 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
348 TriggerAccelerometerUpdate(gfx::Vector3dF(2.0f, 0.0f, kMeanGravity), | 365 TriggerAccelerometerUpdate(gfx::Vector3dF(2.0f, 0.0f, kMeanGravity), |
349 gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity)); | 366 gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity)); |
350 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); | 367 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
351 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 2.0f, kMeanGravity), | 368 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 2.0f, kMeanGravity), |
352 gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity)); | 369 gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity)); |
353 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); | 370 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
354 } | 371 } |
355 | 372 |
| 373 #if defined(OS_CHROMEOS) |
356 // Tests that the display will stick to the current orientation beyond the | 374 // Tests that the display will stick to the current orientation beyond the |
357 // halfway point, preventing frequent updates back and forth. | 375 // halfway point, preventing frequent updates back and forth. |
358 TEST_F(MaximizeModeControllerTest, RotationSticky) { | 376 TEST_F(MaximizeModeControllerTest, RotationSticky) { |
359 // Trigger maximize mode by opening to 270. | 377 // Trigger maximize mode by opening to 270. |
360 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), | 378 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), |
361 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 379 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
362 ASSERT_TRUE(IsMaximizeModeStarted()); | 380 ASSERT_TRUE(IsMaximizeModeStarted()); |
363 | 381 |
364 gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f); | 382 gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f); |
365 TriggerAccelerometerUpdate(gravity, gravity); | 383 TriggerAccelerometerUpdate(gravity, gravity); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 gfx::Vector3dF(-9.5f, -3.5f, 0.0f)); | 421 gfx::Vector3dF(-9.5f, -3.5f, 0.0f)); |
404 ASSERT_TRUE(IsMaximizeModeStarted()); | 422 ASSERT_TRUE(IsMaximizeModeStarted()); |
405 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); | 423 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
406 | 424 |
407 // Close lid back to 90, screen should rotate back. | 425 // Close lid back to 90, screen should rotate back. |
408 TriggerAccelerometerUpdate(gfx::Vector3dF(-9.5f, 0.0f, -3.5f), | 426 TriggerAccelerometerUpdate(gfx::Vector3dF(-9.5f, 0.0f, -3.5f), |
409 gfx::Vector3dF(-9.5f, -3.5f, 0.0f)); | 427 gfx::Vector3dF(-9.5f, -3.5f, 0.0f)); |
410 ASSERT_FALSE(IsMaximizeModeStarted()); | 428 ASSERT_FALSE(IsMaximizeModeStarted()); |
411 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); | 429 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
412 } | 430 } |
413 | 431 #endif // OS_CHROMEOS |
414 | 432 |
415 TEST_F(MaximizeModeControllerTest, LaptopTest) { | 433 TEST_F(MaximizeModeControllerTest, LaptopTest) { |
416 // Feeds in sample accelerometer data and verifies that there are no | 434 // Feeds in sample accelerometer data and verifies that there are no |
417 // transitions into touchview / maximize mode while shaking the device around | 435 // transitions into touchview / maximize mode while shaking the device around |
418 // with the hinge at less than 180 degrees. Note the conversion from device | 436 // with the hinge at less than 180 degrees. Note the conversion from device |
419 // data to accelerometer updates consistent with accelerometer_reader.cc. | 437 // data to accelerometer updates consistent with accelerometer_reader.cc. |
420 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6); | 438 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6); |
421 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) { | 439 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) { |
422 gfx::Vector3dF base(-kAccelerometerLaptopModeTestData[i * 6 + 1], | 440 gfx::Vector3dF base(-kAccelerometerLaptopModeTestData[i * 6 + 1], |
423 -kAccelerometerLaptopModeTestData[i * 6], | 441 -kAccelerometerLaptopModeTestData[i * 6], |
(...skipping 30 matching lines...) Expand all Loading... |
454 kAccelerometerFullyOpenTestData[i * 6 + 3], | 472 kAccelerometerFullyOpenTestData[i * 6 + 3], |
455 kAccelerometerFullyOpenTestData[i * 6 + 5]); | 473 kAccelerometerFullyOpenTestData[i * 6 + 5]); |
456 lid.Scale(kMeanGravity); | 474 lid.Scale(kMeanGravity); |
457 TriggerAccelerometerUpdate(base, lid); | 475 TriggerAccelerometerUpdate(base, lid); |
458 // There are a lot of samples, so ASSERT rather than EXPECT to only generate | 476 // There are a lot of samples, so ASSERT rather than EXPECT to only generate |
459 // one failure rather than potentially hundreds. | 477 // one failure rather than potentially hundreds. |
460 ASSERT_TRUE(IsMaximizeModeStarted()); | 478 ASSERT_TRUE(IsMaximizeModeStarted()); |
461 } | 479 } |
462 } | 480 } |
463 | 481 |
| 482 #if defined(OS_CHROMEOS) |
464 // Tests that the display will stick to its current orientation when the | 483 // Tests that the display will stick to its current orientation when the |
465 // rotation lock has been set. | 484 // rotation lock has been set. |
466 TEST_F(MaximizeModeControllerTest, RotationLockPreventsRotation) { | 485 TEST_F(MaximizeModeControllerTest, RotationLockPreventsRotation) { |
467 // Trigger maximize mode by opening to 270. | 486 // Trigger maximize mode by opening to 270. |
468 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), | 487 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), |
469 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 488 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
470 ASSERT_TRUE(IsMaximizeModeStarted()); | 489 ASSERT_TRUE(IsMaximizeModeStarted()); |
471 | 490 |
472 gfx::Vector3dF gravity(-kMeanGravity, 0.0f, 0.0f); | 491 gfx::Vector3dF gravity(-kMeanGravity, 0.0f, 0.0f); |
473 | 492 |
474 maximize_mode_controller()->SetRotationLocked(true); | 493 SetRotationLocked(true); |
475 | 494 |
476 // Turn past the threshold for rotation. | 495 // Turn past the threshold for rotation. |
477 float degrees = 90.0; | 496 float degrees = 90.0; |
478 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); | 497 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); |
479 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); | 498 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); |
480 TriggerAccelerometerUpdate(gravity, gravity); | 499 TriggerAccelerometerUpdate(gravity, gravity); |
481 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); | 500 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
482 | 501 |
483 maximize_mode_controller()->SetRotationLocked(false); | 502 SetRotationLocked(false); |
484 TriggerAccelerometerUpdate(gravity, gravity); | 503 TriggerAccelerometerUpdate(gravity, gravity); |
485 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); | 504 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
486 } | 505 } |
487 | 506 |
488 // Tests that when MaximizeModeController turns off MaximizeMode that on the | 507 // Tests that when MaximizeModeController turns off MaximizeMode that on the |
489 // next accelerometer update the rotation lock is cleared. | 508 // next accelerometer update the rotation lock is cleared. |
490 TEST_F(MaximizeModeControllerTest, ExitingMaximizeModeClearRotationLock) { | 509 TEST_F(MaximizeModeControllerTest, ExitingMaximizeModeClearRotationLock) { |
491 // Trigger maximize mode by opening to 270. | 510 // Trigger maximize mode by opening to 270. |
492 OpenLidToAngle(270.0f); | 511 OpenLidToAngle(270.0f); |
493 ASSERT_TRUE(IsMaximizeModeStarted()); | 512 ASSERT_TRUE(IsMaximizeModeStarted()); |
494 | 513 |
495 maximize_mode_controller()->SetRotationLocked(true); | 514 SetRotationLocked(true); |
496 | 515 |
497 OpenLidToAngle(90.0f); | 516 OpenLidToAngle(90.0f); |
498 EXPECT_FALSE(IsMaximizeModeStarted()); | 517 EXPECT_FALSE(IsMaximizeModeStarted()); |
499 | 518 |
500 // Send an update that would not relaunch MaximizeMode. | 519 // Send an update that would not relaunch MaximizeMode. |
501 OpenLidToAngle(90.0f); | 520 OpenLidToAngle(90.0f); |
502 EXPECT_FALSE(maximize_mode_controller()->rotation_locked()); | 521 EXPECT_FALSE(rotation_locked()); |
503 } | 522 } |
504 | 523 |
505 // The TrayDisplay class that is responsible for adding/updating MessageCenter | 524 // The TrayDisplay class that is responsible for adding/updating MessageCenter |
506 // notifications is only added to the SystemTray on ChromeOS. | 525 // notifications is only added to the SystemTray on ChromeOS. |
507 #if defined(OS_CHROMEOS) | |
508 // Tests that the screen rotation notifications are suppressed when | 526 // Tests that the screen rotation notifications are suppressed when |
509 // triggered by the accelerometer. | 527 // triggered by the accelerometer. |
510 TEST_F(MaximizeModeControllerTest, BlockRotationNotifications) { | 528 TEST_F(MaximizeModeControllerTest, BlockRotationNotifications) { |
511 test::TestSystemTrayDelegate* tray_delegate = | 529 test::TestSystemTrayDelegate* tray_delegate = |
512 static_cast<test::TestSystemTrayDelegate*>( | 530 static_cast<test::TestSystemTrayDelegate*>( |
513 Shell::GetInstance()->system_tray_delegate()); | 531 Shell::GetInstance()->system_tray_delegate()); |
514 tray_delegate->set_should_show_display_notification(true); | 532 tray_delegate->set_should_show_display_notification(true); |
515 | 533 |
516 message_center::MessageCenter* message_center = | 534 message_center::MessageCenter* message_center = |
517 message_center::MessageCenter::Get(); | 535 message_center::MessageCenter::Get(); |
(...skipping 17 matching lines...) Expand all Loading... |
535 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), | 553 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), |
536 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 554 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
537 EXPECT_TRUE(IsMaximizeModeStarted()); | 555 EXPECT_TRUE(IsMaximizeModeStarted()); |
538 EXPECT_EQ(0u, message_center->NotificationCount()); | 556 EXPECT_EQ(0u, message_center->NotificationCount()); |
539 EXPECT_FALSE(message_center->HasPopupNotifications()); | 557 EXPECT_FALSE(message_center->HasPopupNotifications()); |
540 | 558 |
541 // Make sure notifications are still displayed when | 559 // Make sure notifications are still displayed when |
542 // adjusting the screen rotation directly when in maximize mode | 560 // adjusting the screen rotation directly when in maximize mode |
543 ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); | 561 ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); |
544 SetInternalDisplayRotation(gfx::Display::ROTATE_270); | 562 SetInternalDisplayRotation(gfx::Display::ROTATE_270); |
545 maximize_mode_controller()->SetRotationLocked(false); | 563 SetRotationLocked(false); |
546 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); | 564 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); |
547 EXPECT_EQ(1u, message_center->NotificationCount()); | 565 EXPECT_EQ(1u, message_center->NotificationCount()); |
548 EXPECT_TRUE(message_center->HasPopupNotifications()); | 566 EXPECT_TRUE(message_center->HasPopupNotifications()); |
549 | 567 |
550 // Clear all notifications | 568 // Clear all notifications |
551 message_center->RemoveAllNotifications(false); | 569 message_center->RemoveAllNotifications(false); |
552 EXPECT_EQ(0u, message_center->NotificationCount()); | 570 EXPECT_EQ(0u, message_center->NotificationCount()); |
553 EXPECT_FALSE(message_center->HasPopupNotifications()); | 571 EXPECT_FALSE(message_center->HasPopupNotifications()); |
554 | 572 |
555 // Make sure notifications are blocked when adjusting the screen rotation | 573 // Make sure notifications are blocked when adjusting the screen rotation |
556 // via the accelerometer while in maximize mode | 574 // via the accelerometer while in maximize mode |
557 // Rotate the screen 90 degrees | 575 // Rotate the screen 90 degrees |
558 ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); | 576 ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
559 TriggerAccelerometerUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f), | 577 TriggerAccelerometerUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f), |
560 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); | 578 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
561 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); | 579 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
562 EXPECT_EQ(0u, message_center->NotificationCount()); | 580 EXPECT_EQ(0u, message_center->NotificationCount()); |
563 EXPECT_FALSE(message_center->HasPopupNotifications()); | 581 EXPECT_FALSE(message_center->HasPopupNotifications()); |
564 } | 582 } |
565 #endif | |
566 | 583 |
567 // Tests that if a user has set a display rotation that it is restored upon | 584 // Tests that if a user has set a display rotation that it is restored upon |
568 // exiting maximize mode. | 585 // exiting maximize mode. |
569 TEST_F(MaximizeModeControllerTest, ResetUserRotationUponExit) { | 586 TEST_F(MaximizeModeControllerTest, ResetUserRotationUponExit) { |
570 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 587 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
571 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 588 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
572 gfx::Display::ROTATE_90); | 589 gfx::Display::ROTATE_90); |
573 | 590 |
574 // Trigger maximize mode | 591 // Trigger maximize mode |
575 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), | 592 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), |
(...skipping 11 matching lines...) Expand all Loading... |
587 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); | 604 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
588 } | 605 } |
589 | 606 |
590 // Tests that if a user sets a display rotation that accelerometer rotation | 607 // Tests that if a user sets a display rotation that accelerometer rotation |
591 // becomes locked. | 608 // becomes locked. |
592 TEST_F(MaximizeModeControllerTest, | 609 TEST_F(MaximizeModeControllerTest, |
593 NonAccelerometerRotationChangesLockRotation) { | 610 NonAccelerometerRotationChangesLockRotation) { |
594 // Trigger maximize mode by opening to 270. | 611 // Trigger maximize mode by opening to 270. |
595 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), | 612 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), |
596 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 613 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
597 ASSERT_FALSE(maximize_mode_controller()->rotation_locked()); | 614 ASSERT_FALSE(rotation_locked()); |
598 SetInternalDisplayRotation(gfx::Display::ROTATE_270); | 615 SetInternalDisplayRotation(gfx::Display::ROTATE_270); |
599 EXPECT_TRUE(maximize_mode_controller()->rotation_locked()); | 616 EXPECT_TRUE(rotation_locked()); |
600 } | 617 } |
| 618 #endif // OS_CHROMEOS |
601 | 619 |
602 // Tests that if a user changes the display rotation, while rotation is locked, | 620 // Tests that if a user changes the display rotation, while rotation is locked, |
603 // that the updates are recorded. Upon exiting maximize mode the latest user | 621 // that the updates are recorded. Upon exiting maximize mode the latest user |
604 // rotation should be applied. | 622 // rotation should be applied. |
605 TEST_F(MaximizeModeControllerTest, UpdateUserRotationWhileRotationLocked) { | 623 TEST_F(MaximizeModeControllerTest, UpdateUserRotationWhileRotationLocked) { |
606 // Trigger maximize mode by opening to 270. | 624 // Trigger maximize mode by opening to 270. |
607 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), | 625 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), |
608 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 626 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
609 SetInternalDisplayRotation(gfx::Display::ROTATE_270); | 627 SetInternalDisplayRotation(gfx::Display::ROTATE_270); |
610 // User sets rotation to the same rotation that the display was at when | 628 // User sets rotation to the same rotation that the display was at when |
611 // maximize mode was activated. | 629 // maximize mode was activated. |
612 SetInternalDisplayRotation(gfx::Display::ROTATE_0); | 630 SetInternalDisplayRotation(gfx::Display::ROTATE_0); |
613 // Exit maximize mode | 631 // Exit maximize mode |
614 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -kMeanGravity), | 632 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -kMeanGravity), |
615 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 633 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
616 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); | 634 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
617 } | 635 } |
618 | 636 |
| 637 #if defined(OS_CHROMEOS) |
619 class MaximizeModeControllerSwitchesTest : public MaximizeModeControllerTest { | 638 class MaximizeModeControllerSwitchesTest : public MaximizeModeControllerTest { |
620 public: | 639 public: |
621 MaximizeModeControllerSwitchesTest() {} | 640 MaximizeModeControllerSwitchesTest() {} |
622 ~MaximizeModeControllerSwitchesTest() override {} | 641 ~MaximizeModeControllerSwitchesTest() override {} |
623 | 642 |
624 void SetUp() override { | 643 void SetUp() override { |
625 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 644 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
626 switches::kAshEnableTouchViewTesting); | 645 switches::kAshEnableTouchViewTesting); |
627 MaximizeModeControllerTest::SetUp(); | 646 MaximizeModeControllerTest::SetUp(); |
628 } | 647 } |
629 private: | 648 private: |
630 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerSwitchesTest); | 649 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerSwitchesTest); |
631 }; | 650 }; |
632 | 651 |
633 // Tests that when the command line switch for testing maximize mode is on, that | 652 // Tests that when the command line switch for testing maximize mode is on, that |
634 // accelerometer updates which would normally cause it to exit do not, and that | 653 // accelerometer updates which would normally cause it to exit do not, and that |
635 // screen rotations still occur. | 654 // screen rotations still occur. |
636 TEST_F(MaximizeModeControllerSwitchesTest, IgnoreHingeAngles) { | 655 TEST_F(MaximizeModeControllerSwitchesTest, IgnoreHingeAngles) { |
637 maximize_mode_controller()->EnableMaximizeModeWindowManager(true); | 656 maximize_mode_controller()->EnableMaximizeModeWindowManager(true); |
638 | 657 |
639 // Would normally trigger an exit from maximize mode. | 658 // Would normally trigger an exit from maximize mode. |
640 OpenLidToAngle(90.0f); | 659 OpenLidToAngle(90.0f); |
641 EXPECT_TRUE(IsMaximizeModeStarted()); | 660 EXPECT_TRUE(IsMaximizeModeStarted()); |
642 | 661 |
643 TriggerAccelerometerUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f), | 662 TriggerAccelerometerUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f), |
644 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); | 663 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
645 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); | 664 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
646 } | 665 } |
| 666 #endif // OS_CHROMEOS |
647 | 667 |
648 } // namespace ash | 668 } // namespace ash |
OLD | NEW |