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

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_controller_unittest.cc

Issue 759063002: Move Screen Rotation from MaximizeModeController to ScreenOrientationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor Rotation from MaximizeModeController to ScreenOrientationController Created 6 years 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
OLDNEW
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"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 extern const float kAccelerometerFullyOpenTestData[]; 50 extern const float kAccelerometerFullyOpenTestData[];
51 extern const size_t kAccelerometerFullyOpenTestDataLength; 51 extern const size_t kAccelerometerFullyOpenTestDataLength;
52 52
53 class MaximizeModeControllerTest : public test::AshTestBase { 53 class MaximizeModeControllerTest : public test::AshTestBase {
54 public: 54 public:
55 MaximizeModeControllerTest() {} 55 MaximizeModeControllerTest() {}
56 ~MaximizeModeControllerTest() override {} 56 ~MaximizeModeControllerTest() override {}
57 57
58 void SetUp() override { 58 void SetUp() override {
59 test::AshTestBase::SetUp(); 59 test::AshTestBase::SetUp();
60 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(
61 maximize_mode_controller());
62
63 // Set the first display to be the internal display for the accelerometer 60 // Set the first display to be the internal display for the accelerometer
64 // screen rotation tests. 61 // screen rotation tests.
65 test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()). 62 test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()).
66 SetFirstDisplayAsInternalDisplay(); 63 SetFirstDisplayAsInternalDisplay();
67 } 64 }
68 65
69 void TearDown() override {
70 Shell::GetInstance()->accelerometer_controller()->AddObserver(
71 maximize_mode_controller());
72 test::AshTestBase::TearDown();
73 }
74
75 MaximizeModeController* maximize_mode_controller() { 66 MaximizeModeController* maximize_mode_controller() {
76 return Shell::GetInstance()->maximize_mode_controller(); 67 return Shell::GetInstance()->maximize_mode_controller();
77 } 68 }
78 69
79 void TriggerLidUpdate(const gfx::Vector3dF& lid) { 70 void TriggerLidUpdate(const gfx::Vector3dF& lid) {
80 ui::AccelerometerUpdate update; 71 ui::AccelerometerUpdate update;
81 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(), lid.z()); 72 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(), lid.z());
82 maximize_mode_controller()->OnAccelerometerUpdated(update); 73 maximize_mode_controller()->OnAccelerometerUpdated(update);
83 } 74 }
84 75
85 void TriggerBaseAndLidUpdate(const gfx::Vector3dF& base, 76 void TriggerBaseAndLidUpdate(const gfx::Vector3dF& base,
86 const gfx::Vector3dF& lid) { 77 const gfx::Vector3dF& lid) {
87 ui::AccelerometerUpdate update; 78 ui::AccelerometerUpdate update;
88 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 79 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD,
89 base.x(), base.y(), base.z()); 80 base.x(), base.y(), base.z());
90 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, 81 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN,
91 lid.x(), lid.y(), lid.z()); 82 lid.x(), lid.y(), lid.z());
92 maximize_mode_controller()->OnAccelerometerUpdated(update); 83 maximize_mode_controller()->OnAccelerometerUpdated(update);
93 } 84 }
94 85
86 #if defined(OS_CHROMEOS)
87 void TriggerAccelerometerController(const gfx::Vector3dF& base,
88 const gfx::Vector3dF& lid) {
89 ui::AccelerometerUpdate update;
90 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, base.x(), base.y(),
91 base.z());
92 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(), lid.z());
93 Shell::GetInstance()->accelerometer_controller()->HandleAccelerometerUpdate(
94 update);
95 }
96 #endif
97
95 bool IsMaximizeModeStarted() { 98 bool IsMaximizeModeStarted() {
96 return maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled(); 99 return maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled();
97 } 100 }
98 101
99 gfx::Display::Rotation GetInternalDisplayRotation() const { 102 gfx::Display::Rotation GetInternalDisplayRotation() const {
100 return Shell::GetInstance()->display_manager()->GetDisplayInfo( 103 return Shell::GetInstance()->display_manager()->GetDisplayInfo(
101 gfx::Display::InternalDisplayId()).rotation(); 104 gfx::Display::InternalDisplayId()).rotation();
102 } 105 }
103 106
104 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) const { 107 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) const {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 306 gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
304 EXPECT_TRUE(IsMaximizeModeStarted()); 307 EXPECT_TRUE(IsMaximizeModeStarted());
305 308
306 // Normal 90 degree orientation but near vertical should stay in maximize 309 // Normal 90 degree orientation but near vertical should stay in maximize
307 // mode. 310 // mode.
308 TriggerBaseAndLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, -0.1f), 311 TriggerBaseAndLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, -0.1f),
309 gfx::Vector3dF(kMeanGravity, -0.1f, 0.0f)); 312 gfx::Vector3dF(kMeanGravity, -0.1f, 0.0f));
310 EXPECT_TRUE(IsMaximizeModeStarted()); 313 EXPECT_TRUE(IsMaximizeModeStarted());
311 } 314 }
312 315
313 // Tests that only getting a lid accelerometer update will enter maximize 316 #if defined(OS_CHROMEOS)
314 // mode and rotate the screen.
315 TEST_F(MaximizeModeControllerTest, LidOnlyDisplayRotation) {
316 ASSERT_FALSE(IsMaximizeModeStarted());
317 // Test rotating in all directions.
318 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
319 // The first update should have entered maximize mode.
320 ASSERT_TRUE(IsMaximizeModeStarted());
321 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
322 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
323 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
324 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
325 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
326 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
327 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
328 }
329
330 // Tests that accelerometer readings in each of the screen angles will trigger a
331 // rotation of the internal display.
332 TEST_F(MaximizeModeControllerTest, DisplayRotation) {
333 // Trigger maximize mode by opening to 270.
334 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
335 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
336 ASSERT_TRUE(IsMaximizeModeStarted());
337
338 // Now test rotating in all directions.
339 TriggerBaseAndLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f),
340 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
341 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
342 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f),
343 gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
344 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
345 TriggerBaseAndLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f),
346 gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
347 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
348 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f),
349 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
350 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
351 }
352
353 // Tests that low angles are ignored by the accelerometer (i.e. when the device
354 // is almost laying flat).
355 TEST_F(MaximizeModeControllerTest, RotationIgnoresLowAngles) {
356 // Trigger maximize mode by opening to 270.
357 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
358 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
359 ASSERT_TRUE(IsMaximizeModeStarted());
360
361 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, kMeanGravity),
362 gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity));
363 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
364 TriggerBaseAndLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, kMeanGravity),
365 gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity));
366 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
367 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, -2.0f, kMeanGravity),
368 gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity));
369 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
370 TriggerBaseAndLidUpdate(gfx::Vector3dF(2.0f, 0.0f, kMeanGravity),
371 gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity));
372 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
373 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 2.0f, kMeanGravity),
374 gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity));
375 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
376 }
377
378 // Tests that the display will stick to the current orientation beyond the
379 // halfway point, preventing frequent updates back and forth.
380 TEST_F(MaximizeModeControllerTest, RotationSticky) {
381 // Trigger maximize mode by opening to 270.
382 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
383 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
384 ASSERT_TRUE(IsMaximizeModeStarted());
385
386 gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f);
387 TriggerBaseAndLidUpdate(gravity, gravity);
388 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
389
390 // Turn past half-way point to next direction and rotation should remain
391 // the same.
392 float degrees = 50.0;
393 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
394 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
395 TriggerBaseAndLidUpdate(gravity, gravity);
396 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
397
398 // Turn more and the screen should rotate.
399 degrees = 70.0;
400 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
401 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
402 TriggerBaseAndLidUpdate(gravity, gravity);
403 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
404
405 // Turn back just beyond the half-way point and the new rotation should
406 // still be in effect.
407 degrees = 40.0;
408 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
409 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
410 TriggerBaseAndLidUpdate(gravity, gravity);
411 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
412 }
413 317
414 // Tests that the screen only rotates when maximize mode is engaged, and will 318 // Tests that the screen only rotates when maximize mode is engaged, and will
415 // return to the standard orientation on exiting maximize mode. 319 // return to the standard orientation on exiting maximize mode.
416 TEST_F(MaximizeModeControllerTest, RotationOnlyInMaximizeMode) { 320 TEST_F(MaximizeModeControllerTest, RotationOnlyInMaximizeMode) {
417 // Rotate on side with lid only open 90 degrees. 321 // Rotate on side with lid only open 90 degrees.
418 TriggerBaseAndLidUpdate(gfx::Vector3dF(-9.5f, 0.0f, -3.5f), 322 TriggerAccelerometerController(gfx::Vector3dF(-9.5f, 0.0f, -3.5f),
419 gfx::Vector3dF(-9.5f, -3.5f, 0.0f)); 323 gfx::Vector3dF(-9.5f, -3.5f, 0.0f));
420 ASSERT_FALSE(IsMaximizeModeStarted()); 324 ASSERT_FALSE(IsMaximizeModeStarted());
421 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 325 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
422 326
423 // Open lid, screen should now rotate to match orientation. 327 // Open lid, screen should now rotate to match orientation.
424 TriggerBaseAndLidUpdate(gfx::Vector3dF(-9.5f, 0.0f, 3.5f), 328 TriggerAccelerometerController(gfx::Vector3dF(-9.5f, 0.0f, 3.5f),
425 gfx::Vector3dF(-9.5f, -3.5f, 0.0f)); 329 gfx::Vector3dF(-9.5f, -3.5f, 0.0f));
426 ASSERT_TRUE(IsMaximizeModeStarted()); 330 ASSERT_TRUE(IsMaximizeModeStarted());
427 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 331 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
428 332
429 // Close lid back to 90, screen should rotate back. 333 // Close lid back to 90, screen should rotate back.
430 TriggerBaseAndLidUpdate(gfx::Vector3dF(-9.5f, 0.0f, -3.5f), 334 TriggerAccelerometerController(gfx::Vector3dF(-9.5f, 0.0f, -3.5f),
431 gfx::Vector3dF(-9.5f, -3.5f, 0.0f)); 335 gfx::Vector3dF(-9.5f, -3.5f, 0.0f));
432 ASSERT_FALSE(IsMaximizeModeStarted()); 336 ASSERT_FALSE(IsMaximizeModeStarted());
433 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 337 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
434 } 338 }
435 339 #endif // OS_CHROMEOS
436 340
437 TEST_F(MaximizeModeControllerTest, LaptopTest) { 341 TEST_F(MaximizeModeControllerTest, LaptopTest) {
438 // Feeds in sample accelerometer data and verifies that there are no 342 // Feeds in sample accelerometer data and verifies that there are no
439 // transitions into touchview / maximize mode while shaking the device around 343 // transitions into touchview / maximize mode while shaking the device around
440 // with the hinge at less than 180 degrees. Note the conversion from device 344 // with the hinge at less than 180 degrees. Note the conversion from device
441 // data to accelerometer updates consistent with accelerometer_reader.cc. 345 // data to accelerometer updates consistent with accelerometer_reader.cc.
442 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6); 346 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6);
443 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) { 347 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) {
444 gfx::Vector3dF base(-kAccelerometerLaptopModeTestData[i * 6 + 1], 348 gfx::Vector3dF base(-kAccelerometerLaptopModeTestData[i * 6 + 1],
445 -kAccelerometerLaptopModeTestData[i * 6], 349 -kAccelerometerLaptopModeTestData[i * 6],
(...skipping 30 matching lines...) Expand all
476 kAccelerometerFullyOpenTestData[i * 6 + 3], 380 kAccelerometerFullyOpenTestData[i * 6 + 3],
477 kAccelerometerFullyOpenTestData[i * 6 + 5]); 381 kAccelerometerFullyOpenTestData[i * 6 + 5]);
478 lid.Scale(kMeanGravity); 382 lid.Scale(kMeanGravity);
479 TriggerBaseAndLidUpdate(base, lid); 383 TriggerBaseAndLidUpdate(base, lid);
480 // There are a lot of samples, so ASSERT rather than EXPECT to only generate 384 // There are a lot of samples, so ASSERT rather than EXPECT to only generate
481 // one failure rather than potentially hundreds. 385 // one failure rather than potentially hundreds.
482 ASSERT_TRUE(IsMaximizeModeStarted()); 386 ASSERT_TRUE(IsMaximizeModeStarted());
483 } 387 }
484 } 388 }
485 389
486 // Tests that the display will stick to its current orientation when the
487 // rotation lock has been set.
488 TEST_F(MaximizeModeControllerTest, RotationLockPreventsRotation) {
489 // Trigger maximize mode by opening to 270.
490 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
491 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
492 ASSERT_TRUE(IsMaximizeModeStarted());
493
494 gfx::Vector3dF gravity(-kMeanGravity, 0.0f, 0.0f);
495
496 maximize_mode_controller()->SetRotationLocked(true);
497
498 // Turn past the threshold for rotation.
499 float degrees = 90.0;
500 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
501 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
502 TriggerBaseAndLidUpdate(gravity, gravity);
503 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
504
505 maximize_mode_controller()->SetRotationLocked(false);
506 TriggerBaseAndLidUpdate(gravity, gravity);
507 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
508 }
509
510 // Tests that when MaximizeModeController turns off MaximizeMode that on the
511 // next accelerometer update the rotation lock is cleared.
512 TEST_F(MaximizeModeControllerTest, ExitingMaximizeModeClearRotationLock) {
513 // Trigger maximize mode by opening to 270.
514 OpenLidToAngle(270.0f);
515 ASSERT_TRUE(IsMaximizeModeStarted());
516
517 maximize_mode_controller()->SetRotationLocked(true);
518
519 OpenLidToAngle(90.0f);
520 EXPECT_FALSE(IsMaximizeModeStarted());
521
522 // Send an update that would not relaunch MaximizeMode.
523 OpenLidToAngle(90.0f);
524 EXPECT_FALSE(maximize_mode_controller()->rotation_locked());
525 }
526
527 // The TrayDisplay class that is responsible for adding/updating MessageCenter
528 // notifications is only added to the SystemTray on ChromeOS.
529 #if defined(OS_CHROMEOS) 390 #if defined(OS_CHROMEOS)
530 // Tests that the screen rotation notifications are suppressed when
531 // triggered by the accelerometer.
532 TEST_F(MaximizeModeControllerTest, BlockRotationNotifications) {
533 test::TestSystemTrayDelegate* tray_delegate =
534 static_cast<test::TestSystemTrayDelegate*>(
535 Shell::GetInstance()->system_tray_delegate());
536 tray_delegate->set_should_show_display_notification(true);
537
538 message_center::MessageCenter* message_center =
539 message_center::MessageCenter::Get();
540
541 // Make sure notifications are still displayed when
542 // adjusting the screen rotation directly when not in maximize mode
543 ASSERT_FALSE(IsMaximizeModeStarted());
544 ASSERT_NE(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
545 ASSERT_EQ(0u, message_center->NotificationCount());
546 ASSERT_FALSE(message_center->HasPopupNotifications());
547 SetInternalDisplayRotation(gfx::Display::ROTATE_180);
548 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
549 EXPECT_EQ(1u, message_center->NotificationCount());
550 EXPECT_TRUE(message_center->HasPopupNotifications());
551
552 // Reset the screen rotation.
553 SetInternalDisplayRotation(gfx::Display::ROTATE_0);
554 // Clear all notifications
555 message_center->RemoveAllNotifications(false);
556 // Trigger maximize mode by opening to 270.
557 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
558 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
559 EXPECT_TRUE(IsMaximizeModeStarted());
560 EXPECT_EQ(0u, message_center->NotificationCount());
561 EXPECT_FALSE(message_center->HasPopupNotifications());
562
563 // Make sure notifications are still displayed when
564 // adjusting the screen rotation directly when in maximize mode
565 ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
566 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
567 maximize_mode_controller()->SetRotationLocked(false);
568 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
569 EXPECT_EQ(1u, message_center->NotificationCount());
570 EXPECT_TRUE(message_center->HasPopupNotifications());
571
572 // Clear all notifications
573 message_center->RemoveAllNotifications(false);
574 EXPECT_EQ(0u, message_center->NotificationCount());
575 EXPECT_FALSE(message_center->HasPopupNotifications());
576
577 // Make sure notifications are blocked when adjusting the screen rotation
578 // via the accelerometer while in maximize mode
579 // Rotate the screen 90 degrees
580 ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
581 TriggerBaseAndLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f),
582 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
583 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
584 EXPECT_EQ(0u, message_center->NotificationCount());
585 EXPECT_FALSE(message_center->HasPopupNotifications());
586 }
587 #endif
588
589 // Tests that if a user has set a display rotation that it is restored upon
590 // exiting maximize mode.
591 TEST_F(MaximizeModeControllerTest, ResetUserRotationUponExit) {
592 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
593 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
594 gfx::Display::ROTATE_90);
595
596 // Trigger maximize mode
597 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
598 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
599 ASSERT_TRUE(IsMaximizeModeStarted());
600
601 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f),
602 gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
603 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
604
605 // Exit maximize mode
606 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, -kMeanGravity),
607 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
608 EXPECT_FALSE(IsMaximizeModeStarted());
609 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
610 }
611
612 // Tests that if a user sets a display rotation that accelerometer rotation
613 // becomes locked.
614 TEST_F(MaximizeModeControllerTest,
615 NonAccelerometerRotationChangesLockRotation) {
616 // Trigger maximize mode by opening to 270.
617 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
618 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
619 ASSERT_FALSE(maximize_mode_controller()->rotation_locked());
620 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
621 EXPECT_TRUE(maximize_mode_controller()->rotation_locked());
622 }
623
624 // Tests that if a user changes the display rotation, while rotation is locked,
625 // that the updates are recorded. Upon exiting maximize mode the latest user
626 // rotation should be applied.
627 TEST_F(MaximizeModeControllerTest, UpdateUserRotationWhileRotationLocked) {
628 // Trigger maximize mode by opening to 270.
629 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
630 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
631 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
632 // User sets rotation to the same rotation that the display was at when
633 // maximize mode was activated.
634 SetInternalDisplayRotation(gfx::Display::ROTATE_0);
635 // Exit maximize mode
636 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, -kMeanGravity),
637 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
638 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
639 }
640
641 class MaximizeModeControllerSwitchesTest : public MaximizeModeControllerTest { 391 class MaximizeModeControllerSwitchesTest : public MaximizeModeControllerTest {
642 public: 392 public:
643 MaximizeModeControllerSwitchesTest() {} 393 MaximizeModeControllerSwitchesTest() {}
644 ~MaximizeModeControllerSwitchesTest() override {} 394 ~MaximizeModeControllerSwitchesTest() override {}
645 395
646 void SetUp() override { 396 void SetUp() override {
647 base::CommandLine::ForCurrentProcess()->AppendSwitch( 397 base::CommandLine::ForCurrentProcess()->AppendSwitch(
648 switches::kAshEnableTouchViewTesting); 398 switches::kAshEnableTouchViewTesting);
649 MaximizeModeControllerTest::SetUp(); 399 MaximizeModeControllerTest::SetUp();
650 } 400 }
651 private: 401 private:
652 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerSwitchesTest); 402 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerSwitchesTest);
653 }; 403 };
654 404
655 // Tests that when the command line switch for testing maximize mode is on, that 405 // Tests that when the command line switch for testing maximize mode is on, that
656 // accelerometer updates which would normally cause it to exit do not, and that 406 // accelerometer updates which would normally cause it to exit do not.
657 // screen rotations still occur.
658 TEST_F(MaximizeModeControllerSwitchesTest, IgnoreHingeAngles) { 407 TEST_F(MaximizeModeControllerSwitchesTest, IgnoreHingeAngles) {
659 maximize_mode_controller()->EnableMaximizeModeWindowManager(true); 408 maximize_mode_controller()->EnableMaximizeModeWindowManager(true);
660 409
661 // Would normally trigger an exit from maximize mode. 410 // Would normally trigger an exit from maximize mode.
662 OpenLidToAngle(90.0f); 411 OpenLidToAngle(90.0f);
663 EXPECT_TRUE(IsMaximizeModeStarted()); 412 EXPECT_TRUE(IsMaximizeModeStarted());
664
665 TriggerBaseAndLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f),
666 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
667 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
668 } 413 }
414 #endif // OS_CHROMEOS
669 415
670 } // namespace ash 416 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698