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

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

Issue 267743010: Suppressed screen rotation notifications triggeres by the accelerometer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed maximize_mode_controller to use it's own SetDisplayRotation method. Created 6 years, 7 months 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 "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
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
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
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
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_NE(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
502 ASSERT_EQ(0u, message_center->NotificationCount());
503 ASSERT_FALSE(message_center->HasPopupNotifications());
504 SetInternalDisplayRotation(gfx::Display::ROTATE_180);
505 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
506 EXPECT_EQ(1u, message_center->NotificationCount());
507 EXPECT_TRUE(message_center->HasPopupNotifications());
508
509 // Clear all notifications
510 message_center->RemoveAllNotifications(false);
511 // Trigger maximize mode by opening to 270.
512 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
513 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
514 maximize_mode_controller()->set_rotation_locked(false);
jonross 2014/05/14 01:00:39 Is this being triggered to require disabling?
flackr 2014/05/14 01:48:33 A SetInternalDisplayRotation(ROTATE_0...) would pr
bruthig 2014/05/14 18:48:49 Done.
515 EXPECT_TRUE(IsMaximizeModeStarted());
516 EXPECT_EQ(1u, message_center->NotificationCount());
517 EXPECT_FALSE(message_center->HasPopupNotifications());
518
519 // Make sure notifications are still displayed when
520 // adjusting the screen rotation directly when in maximize mode
521 ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
522 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
523 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
524 EXPECT_EQ(1u, message_center->NotificationCount());
525 EXPECT_TRUE(message_center->HasPopupNotifications());
526
527 // Clear all notifications
528 message_center->RemoveAllNotifications(false);
529 EXPECT_EQ(0u, message_center->NotificationCount());
530 EXPECT_FALSE(message_center->HasPopupNotifications());
531
532 // Make sure notifications are blocked when adjusting the screen rotation
533 // via the accelerometer while in maximize mode
534 // Rotate the screen 90 degrees
535 ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
536 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 1.0f, 0.0f),
537 gfx::Vector3dF(0.0f, 1.0f, 0.0f));
538 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
539 EXPECT_EQ(1u, message_center->NotificationCount());
540 EXPECT_FALSE(message_center->HasPopupNotifications());
541 }
542
481 } // namespace ash 543 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698