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

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

Issue 795333002: Refactor AccelerometerReader to provide an Observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix athena build 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"
10 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
11 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
12 #include "ash/shell.h" 11 #include "ash/shell.h"
13 #include "ash/system/tray/system_tray_delegate.h" 12 #include "ash/system/tray/system_tray_delegate.h"
14 #include "ash/test/ash_test_base.h" 13 #include "ash/test/ash_test_base.h"
15 #include "ash/test/display_manager_test_api.h" 14 #include "ash/test/display_manager_test_api.h"
16 #include "ash/test/test_system_tray_delegate.h" 15 #include "ash/test/test_system_tray_delegate.h"
17 #include "ash/test/test_volume_control_delegate.h" 16 #include "ash/test/test_volume_control_delegate.h"
18 #include "base/command_line.h" 17 #include "base/command_line.h"
19 #include "base/test/simple_test_tick_clock.h" 18 #include "base/test/simple_test_tick_clock.h"
19 #include "chromeos/accelerometer/accelerometer_reader.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(USE_X11) 26 #if defined(USE_X11)
27 #include "ui/events/test/events_test_utils_x11.h" 27 #include "ui/events/test/events_test_utils_x11.h"
28 #endif 28 #endif
29 29
(...skipping 20 matching lines...) Expand all
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( 60 Shell::GetInstance()->accelerometer_reader()->RemoveObserver(
61 maximize_mode_controller()); 61 maximize_mode_controller());
62 62
63 // Set the first display to be the internal display for the accelerometer 63 // Set the first display to be the internal display for the accelerometer
64 // screen rotation tests. 64 // screen rotation tests.
65 test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()). 65 test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()).
66 SetFirstDisplayAsInternalDisplay(); 66 SetFirstDisplayAsInternalDisplay();
67 } 67 }
68 68
69 void TearDown() override { 69 void TearDown() override {
70 Shell::GetInstance()->accelerometer_controller()->AddObserver( 70 Shell::GetInstance()->accelerometer_reader()->AddObserver(
71 maximize_mode_controller()); 71 maximize_mode_controller());
72 test::AshTestBase::TearDown(); 72 test::AshTestBase::TearDown();
73 } 73 }
74 74
75 MaximizeModeController* maximize_mode_controller() { 75 MaximizeModeController* maximize_mode_controller() {
76 return Shell::GetInstance()->maximize_mode_controller(); 76 return Shell::GetInstance()->maximize_mode_controller();
77 } 77 }
78 78
79 void TriggerLidUpdate(const gfx::Vector3dF& lid) { 79 void TriggerLidUpdate(const gfx::Vector3dF& lid) {
80 ui::AccelerometerUpdate update; 80 ui::AccelerometerUpdate update;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 DCHECK(degrees <= 360.0f); 125 DCHECK(degrees <= 360.0f);
126 126
127 float radians = degrees * kDegreesToRadians; 127 float radians = degrees * kDegreesToRadians;
128 gfx::Vector3dF base_vector(0.0f, -kMeanGravity, 0.0f); 128 gfx::Vector3dF base_vector(0.0f, -kMeanGravity, 0.0f);
129 gfx::Vector3dF lid_vector(0.0f, 129 gfx::Vector3dF lid_vector(0.0f,
130 kMeanGravity * cos(radians), 130 kMeanGravity * cos(radians),
131 kMeanGravity * sin(radians)); 131 kMeanGravity * sin(radians));
132 TriggerBaseAndLidUpdate(base_vector, lid_vector); 132 TriggerBaseAndLidUpdate(base_vector, lid_vector);
133 } 133 }
134 134
135 #if defined(OS_CHROMEOS)
136 void OpenLid() { 135 void OpenLid() {
137 maximize_mode_controller()->LidEventReceived(true /* open */, 136 maximize_mode_controller()->LidEventReceived(true /* open */,
138 maximize_mode_controller()->tick_clock_->NowTicks()); 137 maximize_mode_controller()->tick_clock_->NowTicks());
139 } 138 }
140 139
141 void CloseLid() { 140 void CloseLid() {
142 maximize_mode_controller()->LidEventReceived(false /* open */, 141 maximize_mode_controller()->LidEventReceived(false /* open */,
143 maximize_mode_controller()->tick_clock_->NowTicks()); 142 maximize_mode_controller()->tick_clock_->NowTicks());
144 } 143 }
145 #endif // OS_CHROMEOS
146 144
147 bool WasLidOpenedRecently() { 145 bool WasLidOpenedRecently() {
148 return maximize_mode_controller()->WasLidOpenedRecently(); 146 return maximize_mode_controller()->WasLidOpenedRecently();
149 } 147 }
150 148
151 private: 149 private:
152 base::SimpleTestTickClock* test_tick_clock_; 150 base::SimpleTestTickClock* test_tick_clock_;
153 151
154 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest); 152 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest);
155 }; 153 };
156 154
157 #if defined(OS_CHROMEOS)
158
159 // Verify that closing the lid will exit maximize mode. 155 // Verify that closing the lid will exit maximize mode.
160 TEST_F(MaximizeModeControllerTest, CloseLidWhileInMaximizeMode) { 156 TEST_F(MaximizeModeControllerTest, CloseLidWhileInMaximizeMode) {
161 OpenLidToAngle(315.0f); 157 OpenLidToAngle(315.0f);
162 ASSERT_TRUE(IsMaximizeModeStarted()); 158 ASSERT_TRUE(IsMaximizeModeStarted());
163 159
164 CloseLid(); 160 CloseLid();
165 EXPECT_FALSE(IsMaximizeModeStarted()); 161 EXPECT_FALSE(IsMaximizeModeStarted());
166 } 162 }
167 163
168 // Verify that maximize mode will not be entered when the lid is closed. 164 // Verify that maximize mode will not be entered when the lid is closed.
(...skipping 30 matching lines...) Expand all
199 195
200 // This is a stable reading and should clear the last lid opened time. 196 // This is a stable reading and should clear the last lid opened time.
201 OpenLidToAngle(45.0f); 197 OpenLidToAngle(45.0f);
202 EXPECT_FALSE(IsMaximizeModeStarted()); 198 EXPECT_FALSE(IsMaximizeModeStarted());
203 EXPECT_FALSE(WasLidOpenedRecently()); 199 EXPECT_FALSE(WasLidOpenedRecently());
204 200
205 OpenLidToAngle(355.0f); 201 OpenLidToAngle(355.0f);
206 EXPECT_TRUE(IsMaximizeModeStarted()); 202 EXPECT_TRUE(IsMaximizeModeStarted());
207 } 203 }
208 204
209 #endif // OS_CHROMEOS
210
211 // Verify the WasLidOpenedRecently signal with respect to time. 205 // Verify the WasLidOpenedRecently signal with respect to time.
212 TEST_F(MaximizeModeControllerTest, WasLidOpenedRecentlyOverTime) { 206 TEST_F(MaximizeModeControllerTest, WasLidOpenedRecentlyOverTime) {
213 #if defined(OS_CHROMEOS)
214
215 AttachTickClockForTest(); 207 AttachTickClockForTest();
216 208
217 // No lid open time initially. 209 // No lid open time initially.
218 ASSERT_FALSE(WasLidOpenedRecently()); 210 ASSERT_FALSE(WasLidOpenedRecently());
219 211
220 CloseLid(); 212 CloseLid();
221 EXPECT_FALSE(WasLidOpenedRecently()); 213 EXPECT_FALSE(WasLidOpenedRecently());
222 214
223 OpenLid(); 215 OpenLid();
224 EXPECT_TRUE(WasLidOpenedRecently()); 216 EXPECT_TRUE(WasLidOpenedRecently());
225 217
226 // 1 second after lid open. 218 // 1 second after lid open.
227 AdvanceTickClock(base::TimeDelta::FromSeconds(1)); 219 AdvanceTickClock(base::TimeDelta::FromSeconds(1));
228 EXPECT_TRUE(WasLidOpenedRecently()); 220 EXPECT_TRUE(WasLidOpenedRecently());
229 221
230 // 3 seconds after lid open. 222 // 3 seconds after lid open.
231 AdvanceTickClock(base::TimeDelta::FromSeconds(2)); 223 AdvanceTickClock(base::TimeDelta::FromSeconds(2));
232 EXPECT_FALSE(WasLidOpenedRecently()); 224 EXPECT_FALSE(WasLidOpenedRecently());
233
234 #else
235
236 EXPECT_FALSE(WasLidOpenedRecently());
237
238 #endif // OS_CHROMEOS
239 } 225 }
240 226
241 // Verify the maximize mode enter/exit thresholds for stable angles. 227 // Verify the maximize mode enter/exit thresholds for stable angles.
242 TEST_F(MaximizeModeControllerTest, StableHingeAnglesWithLidOpened) { 228 TEST_F(MaximizeModeControllerTest, StableHingeAnglesWithLidOpened) {
243 ASSERT_FALSE(IsMaximizeModeStarted()); 229 ASSERT_FALSE(IsMaximizeModeStarted());
244 ASSERT_FALSE(WasLidOpenedRecently()); 230 ASSERT_FALSE(WasLidOpenedRecently());
245 231
246 OpenLidToAngle(180.0f); 232 OpenLidToAngle(180.0f);
247 EXPECT_FALSE(IsMaximizeModeStarted()); 233 EXPECT_FALSE(IsMaximizeModeStarted());
248 234
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 OpenLidToAngle(90.0f); 505 OpenLidToAngle(90.0f);
520 EXPECT_FALSE(IsMaximizeModeStarted()); 506 EXPECT_FALSE(IsMaximizeModeStarted());
521 507
522 // Send an update that would not relaunch MaximizeMode. 508 // Send an update that would not relaunch MaximizeMode.
523 OpenLidToAngle(90.0f); 509 OpenLidToAngle(90.0f);
524 EXPECT_FALSE(maximize_mode_controller()->rotation_locked()); 510 EXPECT_FALSE(maximize_mode_controller()->rotation_locked());
525 } 511 }
526 512
527 // The TrayDisplay class that is responsible for adding/updating MessageCenter 513 // The TrayDisplay class that is responsible for adding/updating MessageCenter
528 // notifications is only added to the SystemTray on ChromeOS. 514 // notifications is only added to the SystemTray on ChromeOS.
529 #if defined(OS_CHROMEOS)
530 // Tests that the screen rotation notifications are suppressed when 515 // Tests that the screen rotation notifications are suppressed when
531 // triggered by the accelerometer. 516 // triggered by the accelerometer.
532 TEST_F(MaximizeModeControllerTest, BlockRotationNotifications) { 517 TEST_F(MaximizeModeControllerTest, BlockRotationNotifications) {
533 test::TestSystemTrayDelegate* tray_delegate = 518 test::TestSystemTrayDelegate* tray_delegate =
534 static_cast<test::TestSystemTrayDelegate*>( 519 static_cast<test::TestSystemTrayDelegate*>(
535 Shell::GetInstance()->system_tray_delegate()); 520 Shell::GetInstance()->system_tray_delegate());
536 tray_delegate->set_should_show_display_notification(true); 521 tray_delegate->set_should_show_display_notification(true);
537 522
538 message_center::MessageCenter* message_center = 523 message_center::MessageCenter* message_center =
539 message_center::MessageCenter::Get(); 524 message_center::MessageCenter::Get();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 // Make sure notifications are blocked when adjusting the screen rotation 562 // Make sure notifications are blocked when adjusting the screen rotation
578 // via the accelerometer while in maximize mode 563 // via the accelerometer while in maximize mode
579 // Rotate the screen 90 degrees 564 // Rotate the screen 90 degrees
580 ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 565 ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
581 TriggerBaseAndLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f), 566 TriggerBaseAndLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f),
582 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); 567 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
583 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 568 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
584 EXPECT_EQ(0u, message_center->NotificationCount()); 569 EXPECT_EQ(0u, message_center->NotificationCount());
585 EXPECT_FALSE(message_center->HasPopupNotifications()); 570 EXPECT_FALSE(message_center->HasPopupNotifications());
586 } 571 }
587 #endif
588 572
589 // Tests that if a user has set a display rotation that it is restored upon 573 // Tests that if a user has set a display rotation that it is restored upon
590 // exiting maximize mode. 574 // exiting maximize mode.
591 TEST_F(MaximizeModeControllerTest, ResetUserRotationUponExit) { 575 TEST_F(MaximizeModeControllerTest, ResetUserRotationUponExit) {
592 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 576 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
593 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), 577 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
594 gfx::Display::ROTATE_90); 578 gfx::Display::ROTATE_90);
595 579
596 // Trigger maximize mode 580 // Trigger maximize mode
597 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), 581 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 // Would normally trigger an exit from maximize mode. 645 // Would normally trigger an exit from maximize mode.
662 OpenLidToAngle(90.0f); 646 OpenLidToAngle(90.0f);
663 EXPECT_TRUE(IsMaximizeModeStarted()); 647 EXPECT_TRUE(IsMaximizeModeStarted());
664 648
665 TriggerBaseAndLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f), 649 TriggerBaseAndLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f),
666 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); 650 gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
667 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 651 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
668 } 652 }
669 653
670 } // namespace ash 654 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_controller.cc ('k') | athena/system/orientation_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698