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" |
15 #include "ash/test/test_volume_control_delegate.h" | 16 #include "ash/test/test_volume_control_delegate.h" |
16 #include "ui/aura/test/event_generator.h" | 17 #include "ui/aura/test/event_generator.h" |
17 #include "ui/events/event_handler.h" | 18 #include "ui/events/event_handler.h" |
18 #include "ui/gfx/vector3d_f.h" | 19 #include "ui/gfx/vector3d_f.h" |
| 20 #include "ui/message_center/message_center.h" |
19 | 21 |
20 namespace ash { | 22 namespace ash { |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 const float kDegreesToRadians = 3.14159265f / 180.0f; | 26 const float kDegreesToRadians = 3.14159265f / 180.0f; |
25 | 27 |
26 // Filter to count the number of events seen. | 28 // Filter to count the number of events seen. |
27 class EventCounter : public ui::EventHandler { | 29 class EventCounter : public ui::EventHandler { |
28 public: | 30 public: |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 107 |
106 bool IsMaximizeModeStarted() const { | 108 bool IsMaximizeModeStarted() const { |
107 return Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 109 return Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
108 } | 110 } |
109 | 111 |
110 gfx::Display::Rotation GetInternalDisplayRotation() const { | 112 gfx::Display::Rotation GetInternalDisplayRotation() const { |
111 return Shell::GetInstance()->display_manager()->GetDisplayInfo( | 113 return Shell::GetInstance()->display_manager()->GetDisplayInfo( |
112 gfx::Display::InternalDisplayId()).rotation(); | 114 gfx::Display::InternalDisplayId()).rotation(); |
113 } | 115 } |
114 | 116 |
| 117 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) const { |
| 118 Shell::GetInstance()->display_manager()-> |
| 119 SetDisplayRotation(gfx::Display::InternalDisplayId(), rotation); |
| 120 } |
| 121 |
115 private: | 122 private: |
116 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest); | 123 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest); |
117 }; | 124 }; |
118 | 125 |
119 // Tests that opening the lid beyond 180 will enter touchview, and that it will | 126 // Tests that opening the lid beyond 180 will enter touchview, and that it will |
120 // exit when the lid comes back from 180. Also tests the thresholds, i.e. it | 127 // exit when the lid comes back from 180. Also tests the thresholds, i.e. it |
121 // will stick to the current mode. | 128 // will stick to the current mode. |
122 TEST_F(MaximizeModeControllerTest, EnterExitThresholds) { | 129 TEST_F(MaximizeModeControllerTest, EnterExitThresholds) { |
123 // For the simple test the base remains steady. | 130 // For the simple test the base remains steady. |
124 gfx::Vector3dF base(0.0f, 0.0f, 1.0f); | 131 gfx::Vector3dF base(0.0f, 0.0f, 1.0f); |
(...skipping 20 matching lines...) Expand all Loading... |
145 EXPECT_TRUE(IsMaximizeModeStarted()); | 152 EXPECT_TRUE(IsMaximizeModeStarted()); |
146 | 153 |
147 // Open 90 degrees. | 154 // Open 90 degrees. |
148 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 155 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
149 EXPECT_FALSE(IsMaximizeModeStarted()); | 156 EXPECT_FALSE(IsMaximizeModeStarted()); |
150 } | 157 } |
151 | 158 |
152 // Tests that when the hinge is nearly vertically aligned, the current state | 159 // Tests that when the hinge is nearly vertically aligned, the current state |
153 // persists as the computed angle is highly inaccurate in this orientation. | 160 // persists as the computed angle is highly inaccurate in this orientation. |
154 TEST_F(MaximizeModeControllerTest, HingeAligned) { | 161 TEST_F(MaximizeModeControllerTest, HingeAligned) { |
155 // Laptop in normal orientation lid open 90 degrees. | 162 // Laptop in normal orientation lid open 90 degrees. |
156 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), | 163 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), |
157 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 164 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
158 EXPECT_FALSE(IsMaximizeModeStarted()); | 165 EXPECT_FALSE(IsMaximizeModeStarted()); |
159 | 166 |
160 // Completely vertical. | 167 // Completely vertical. |
161 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f), | 168 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f), |
162 gfx::Vector3dF(0.0f, -1.0f, 0.0f)); | 169 gfx::Vector3dF(0.0f, -1.0f, 0.0f)); |
163 EXPECT_FALSE(IsMaximizeModeStarted()); | 170 EXPECT_FALSE(IsMaximizeModeStarted()); |
164 | 171 |
165 // Close to vertical but with hinge appearing to be open 270 degrees. | 172 // Close to vertical but with hinge appearing to be open 270 degrees. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 // Open up 270 degrees. | 313 // Open up 270 degrees. |
307 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), | 314 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), |
308 gfx::Vector3dF(1.0f, 0.0f, 0.0f)); | 315 gfx::Vector3dF(1.0f, 0.0f, 0.0f)); |
309 ASSERT_TRUE(IsMaximizeModeStarted()); | 316 ASSERT_TRUE(IsMaximizeModeStarted()); |
310 | 317 |
311 event_generator.PressKey(ui::VKEY_ESCAPE, 0); | 318 event_generator.PressKey(ui::VKEY_ESCAPE, 0); |
312 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0); | 319 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0); |
313 EXPECT_EQ(0u, counter.event_count()); | 320 EXPECT_EQ(0u, counter.event_count()); |
314 counter.reset(); | 321 counter.reset(); |
315 | 322 |
316 // Touch should not be blocked. | 323 // Touch should not be blocked. |
317 event_generator.PressTouch(); | 324 event_generator.PressTouch(); |
318 event_generator.ReleaseTouch(); | 325 event_generator.ReleaseTouch(); |
319 EXPECT_GT(counter.event_count(), 0u); | 326 EXPECT_GT(counter.event_count(), 0u); |
320 counter.reset(); | 327 counter.reset(); |
321 | 328 |
322 gfx::Vector3dF base; | 329 gfx::Vector3dF base; |
323 | 330 |
324 // Lid open 90 degrees. | 331 // Lid open 90 degrees. |
325 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), | 332 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), |
326 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 333 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 | 478 |
472 // Open 90 degrees. | 479 // Open 90 degrees. |
473 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 480 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
474 EXPECT_FALSE(IsMaximizeModeStarted()); | 481 EXPECT_FALSE(IsMaximizeModeStarted()); |
475 | 482 |
476 // Send an update that would not relaunch MaximizeMode. 90 degrees. | 483 // Send an update that would not relaunch MaximizeMode. 90 degrees. |
477 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 484 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
478 EXPECT_FALSE(maximize_mode_controller()->rotation_locked()); | 485 EXPECT_FALSE(maximize_mode_controller()->rotation_locked()); |
479 } | 486 } |
480 | 487 |
| 488 // Tests that the screen rotation notifications are suppressed when |
| 489 // triggered by the accelerometer. |
| 490 TEST_F(MaximizeModeControllerTest, BlockRotationNotifications) { |
| 491 test::TestSystemTrayDelegate* tray_delegate = |
| 492 static_cast<test::TestSystemTrayDelegate*>( |
| 493 Shell::GetInstance()->system_tray_delegate()); |
| 494 tray_delegate->set_should_show_display_notification(true); |
| 495 |
| 496 message_center::MessageCenter* message_center = |
| 497 message_center::MessageCenter::Get(); |
| 498 |
| 499 // Make sure notifications are still displayed when |
| 500 // adjusting the screen rotation directly when not in maximize mode |
| 501 ASSERT_FALSE(IsMaximizeModeStarted()); |
| 502 ASSERT_NE(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); |
| 503 ASSERT_EQ(0u, message_center->NotificationCount()); |
| 504 ASSERT_FALSE(message_center->HasPopupNotifications()); |
| 505 SetInternalDisplayRotation(gfx::Display::ROTATE_180); |
| 506 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); |
| 507 EXPECT_EQ(1u, message_center->NotificationCount()); |
| 508 EXPECT_TRUE(message_center->HasPopupNotifications()); |
| 509 |
| 510 // Reset the screen rotation. |
| 511 SetInternalDisplayRotation(gfx::Display::ROTATE_0); |
| 512 // Clear all notifications |
| 513 message_center->RemoveAllNotifications(false); |
| 514 // Trigger maximize mode by opening to 270. |
| 515 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), |
| 516 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
| 517 EXPECT_TRUE(IsMaximizeModeStarted()); |
| 518 EXPECT_EQ(0u, message_center->NotificationCount()); |
| 519 EXPECT_FALSE(message_center->HasPopupNotifications()); |
| 520 |
| 521 // Make sure notifications are still displayed when |
| 522 // adjusting the screen rotation directly when in maximize mode |
| 523 ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); |
| 524 SetInternalDisplayRotation(gfx::Display::ROTATE_270); |
| 525 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); |
| 526 EXPECT_EQ(1u, message_center->NotificationCount()); |
| 527 EXPECT_TRUE(message_center->HasPopupNotifications()); |
| 528 |
| 529 // Clear all notifications |
| 530 message_center->RemoveAllNotifications(false); |
| 531 EXPECT_EQ(0u, message_center->NotificationCount()); |
| 532 EXPECT_FALSE(message_center->HasPopupNotifications()); |
| 533 |
| 534 // Make sure notifications are blocked when adjusting the screen rotation |
| 535 // via the accelerometer while in maximize mode |
| 536 // Rotate the screen 90 degrees |
| 537 ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
| 538 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 1.0f, 0.0f), |
| 539 gfx::Vector3dF(0.0f, 1.0f, 0.0f)); |
| 540 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
| 541 EXPECT_EQ(0u, message_center->NotificationCount()); |
| 542 EXPECT_FALSE(message_center->HasPopupNotifications()); |
| 543 } |
| 544 |
481 } // namespace ash | 545 } // namespace ash |
OLD | NEW |