| 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 "ash/wm/maximize_mode/maximize_mode_controller.h" | 5 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 6 | 6 |
| 7 #include "ash/accelerometer/accelerometer_controller.h" | 7 #include "ash/accelerometer/accelerometer_controller.h" |
| 8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/display_manager_test_api.h" | 12 #include "ash/test/display_manager_test_api.h" |
| 13 #include "ash/test/test_lock_state_controller_delegate.h" | 13 #include "ash/test/test_lock_state_controller_delegate.h" |
| 14 #include "ash/test/test_screenshot_delegate.h" | 14 #include "ash/test/test_screenshot_delegate.h" |
| 15 #include "ash/test/test_system_tray_delegate.h" | |
| 16 #include "ash/test/test_volume_control_delegate.h" | 15 #include "ash/test/test_volume_control_delegate.h" |
| 17 #include "ui/aura/test/event_generator.h" | 16 #include "ui/aura/test/event_generator.h" |
| 18 #include "ui/events/event_handler.h" | 17 #include "ui/events/event_handler.h" |
| 19 #include "ui/gfx/vector3d_f.h" | 18 #include "ui/gfx/vector3d_f.h" |
| 20 #include "ui/message_center/message_center.h" | |
| 21 | 19 |
| 22 namespace ash { | 20 namespace ash { |
| 23 | 21 |
| 24 namespace { | 22 namespace { |
| 25 | 23 |
| 26 const float kDegreesToRadians = 3.14159265f / 180.0f; | 24 const float kDegreesToRadians = 3.14159265f / 180.0f; |
| 27 | 25 |
| 28 // Filter to count the number of events seen. | 26 // Filter to count the number of events seen. |
| 29 class EventCounter : public ui::EventHandler { | 27 class EventCounter : public ui::EventHandler { |
| 30 public: | 28 public: |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 105 |
| 108 bool IsMaximizeModeStarted() const { | 106 bool IsMaximizeModeStarted() const { |
| 109 return Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 107 return Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
| 110 } | 108 } |
| 111 | 109 |
| 112 gfx::Display::Rotation GetInternalDisplayRotation() const { | 110 gfx::Display::Rotation GetInternalDisplayRotation() const { |
| 113 return Shell::GetInstance()->display_manager()->GetDisplayInfo( | 111 return Shell::GetInstance()->display_manager()->GetDisplayInfo( |
| 114 gfx::Display::InternalDisplayId()).rotation(); | 112 gfx::Display::InternalDisplayId()).rotation(); |
| 115 } | 113 } |
| 116 | 114 |
| 117 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) const { | |
| 118 Shell::GetInstance()->display_manager()-> | |
| 119 SetDisplayRotation(gfx::Display::InternalDisplayId(), rotation); | |
| 120 } | |
| 121 | |
| 122 private: | 115 private: |
| 123 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest); | 116 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest); |
| 124 }; | 117 }; |
| 125 | 118 |
| 126 // Tests that opening the lid beyond 180 will enter touchview, and that it will | 119 // Tests that opening the lid beyond 180 will enter touchview, and that it will |
| 127 // exit when the lid comes back from 180. Also tests the thresholds, i.e. it | 120 // exit when the lid comes back from 180. Also tests the thresholds, i.e. it |
| 128 // will stick to the current mode. | 121 // will stick to the current mode. |
| 129 TEST_F(MaximizeModeControllerTest, EnterExitThresholds) { | 122 TEST_F(MaximizeModeControllerTest, EnterExitThresholds) { |
| 130 // For the simple test the base remains steady. | 123 // For the simple test the base remains steady. |
| 131 gfx::Vector3dF base(0.0f, 0.0f, 1.0f); | 124 gfx::Vector3dF base(0.0f, 0.0f, 1.0f); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 152 EXPECT_TRUE(IsMaximizeModeStarted()); | 145 EXPECT_TRUE(IsMaximizeModeStarted()); |
| 153 | 146 |
| 154 // Open 90 degrees. | 147 // Open 90 degrees. |
| 155 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 148 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
| 156 EXPECT_FALSE(IsMaximizeModeStarted()); | 149 EXPECT_FALSE(IsMaximizeModeStarted()); |
| 157 } | 150 } |
| 158 | 151 |
| 159 // Tests that when the hinge is nearly vertically aligned, the current state | 152 // Tests that when the hinge is nearly vertically aligned, the current state |
| 160 // persists as the computed angle is highly inaccurate in this orientation. | 153 // persists as the computed angle is highly inaccurate in this orientation. |
| 161 TEST_F(MaximizeModeControllerTest, HingeAligned) { | 154 TEST_F(MaximizeModeControllerTest, HingeAligned) { |
| 162 // Laptop in normal orientation lid open 90 degrees. | 155 // Laptop in normal orientation lid open 90 degrees. |
| 163 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), | 156 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), |
| 164 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 157 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
| 165 EXPECT_FALSE(IsMaximizeModeStarted()); | 158 EXPECT_FALSE(IsMaximizeModeStarted()); |
| 166 | 159 |
| 167 // Completely vertical. | 160 // Completely vertical. |
| 168 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f), | 161 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f), |
| 169 gfx::Vector3dF(0.0f, -1.0f, 0.0f)); | 162 gfx::Vector3dF(0.0f, -1.0f, 0.0f)); |
| 170 EXPECT_FALSE(IsMaximizeModeStarted()); | 163 EXPECT_FALSE(IsMaximizeModeStarted()); |
| 171 | 164 |
| 172 // Close to vertical but with hinge appearing to be open 270 degrees. | 165 // Close to vertical but with hinge appearing to be open 270 degrees. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 331 |
| 339 event_generator.ScrollSequence( | 332 event_generator.ScrollSequence( |
| 340 gfx::Point(), base::TimeDelta::FromMilliseconds(5), 0, 100, 5, 2); | 333 gfx::Point(), base::TimeDelta::FromMilliseconds(5), 0, 100, 5, 2); |
| 341 EXPECT_EQ(0u, counter.event_count()); | 334 EXPECT_EQ(0u, counter.event_count()); |
| 342 counter.reset(); | 335 counter.reset(); |
| 343 | 336 |
| 344 event_generator.MoveMouseWheel(0, 10); | 337 event_generator.MoveMouseWheel(0, 10); |
| 345 EXPECT_EQ(0u, counter.event_count()); | 338 EXPECT_EQ(0u, counter.event_count()); |
| 346 counter.reset(); | 339 counter.reset(); |
| 347 | 340 |
| 348 // Touch should not be blocked. | 341 // Touch should not be blocked. |
| 349 event_generator.PressTouch(); | 342 event_generator.PressTouch(); |
| 350 event_generator.ReleaseTouch(); | 343 event_generator.ReleaseTouch(); |
| 351 EXPECT_GT(counter.event_count(), 0u); | 344 EXPECT_GT(counter.event_count(), 0u); |
| 352 counter.reset(); | 345 counter.reset(); |
| 353 | 346 |
| 354 gfx::Vector3dF base; | 347 gfx::Vector3dF base; |
| 355 | 348 |
| 356 // Lid open 90 degrees. | 349 // Lid open 90 degrees. |
| 357 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), | 350 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), |
| 358 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 351 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 496 |
| 504 // Open 90 degrees. | 497 // Open 90 degrees. |
| 505 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 498 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
| 506 EXPECT_FALSE(IsMaximizeModeStarted()); | 499 EXPECT_FALSE(IsMaximizeModeStarted()); |
| 507 | 500 |
| 508 // Send an update that would not relaunch MaximizeMode. 90 degrees. | 501 // Send an update that would not relaunch MaximizeMode. 90 degrees. |
| 509 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 502 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
| 510 EXPECT_FALSE(maximize_mode_controller()->rotation_locked()); | 503 EXPECT_FALSE(maximize_mode_controller()->rotation_locked()); |
| 511 } | 504 } |
| 512 | 505 |
| 513 // Tests that the screen rotation notifications are suppressed when | |
| 514 // triggered by the accelerometer. | |
| 515 TEST_F(MaximizeModeControllerTest, BlockRotationNotifications) { | |
| 516 test::TestSystemTrayDelegate* tray_delegate = | |
| 517 static_cast<test::TestSystemTrayDelegate*>( | |
| 518 Shell::GetInstance()->system_tray_delegate()); | |
| 519 tray_delegate->set_should_show_display_notification(true); | |
| 520 | |
| 521 message_center::MessageCenter* message_center = | |
| 522 message_center::MessageCenter::Get(); | |
| 523 | |
| 524 // Make sure notifications are still displayed when | |
| 525 // adjusting the screen rotation directly when not in maximize mode | |
| 526 ASSERT_FALSE(IsMaximizeModeStarted()); | |
| 527 ASSERT_NE(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); | |
| 528 ASSERT_EQ(0u, message_center->NotificationCount()); | |
| 529 ASSERT_FALSE(message_center->HasPopupNotifications()); | |
| 530 SetInternalDisplayRotation(gfx::Display::ROTATE_180); | |
| 531 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); | |
| 532 EXPECT_EQ(1u, message_center->NotificationCount()); | |
| 533 EXPECT_TRUE(message_center->HasPopupNotifications()); | |
| 534 | |
| 535 // Reset the screen rotation. | |
| 536 SetInternalDisplayRotation(gfx::Display::ROTATE_0); | |
| 537 // Clear all notifications | |
| 538 message_center->RemoveAllNotifications(false); | |
| 539 // Trigger maximize mode by opening to 270. | |
| 540 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), | |
| 541 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | |
| 542 EXPECT_TRUE(IsMaximizeModeStarted()); | |
| 543 EXPECT_EQ(0u, message_center->NotificationCount()); | |
| 544 EXPECT_FALSE(message_center->HasPopupNotifications()); | |
| 545 | |
| 546 // Make sure notifications are still displayed when | |
| 547 // adjusting the screen rotation directly when in maximize mode | |
| 548 ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); | |
| 549 SetInternalDisplayRotation(gfx::Display::ROTATE_270); | |
| 550 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); | |
| 551 EXPECT_EQ(1u, message_center->NotificationCount()); | |
| 552 EXPECT_TRUE(message_center->HasPopupNotifications()); | |
| 553 | |
| 554 // Clear all notifications | |
| 555 message_center->RemoveAllNotifications(false); | |
| 556 EXPECT_EQ(0u, message_center->NotificationCount()); | |
| 557 EXPECT_FALSE(message_center->HasPopupNotifications()); | |
| 558 | |
| 559 // Make sure notifications are blocked when adjusting the screen rotation | |
| 560 // via the accelerometer while in maximize mode | |
| 561 // Rotate the screen 90 degrees | |
| 562 ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); | |
| 563 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 1.0f, 0.0f), | |
| 564 gfx::Vector3dF(0.0f, 1.0f, 0.0f)); | |
| 565 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); | |
| 566 EXPECT_EQ(0u, message_center->NotificationCount()); | |
| 567 EXPECT_FALSE(message_center->HasPopupNotifications()); | |
| 568 } | |
| 569 | |
| 570 } // namespace ash | 506 } // namespace ash |
| OLD | NEW |