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

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

Issue 291233002: Re-landing "Suppressed screen rotation notifications triggeres by the accelerometer." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ifdef'ed BlockRotationNotification test so it only runs on ChromeOS. 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
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 338
332 event_generator.ScrollSequence( 339 event_generator.ScrollSequence(
333 gfx::Point(), base::TimeDelta::FromMilliseconds(5), 0, 100, 5, 2); 340 gfx::Point(), base::TimeDelta::FromMilliseconds(5), 0, 100, 5, 2);
334 EXPECT_EQ(0u, counter.event_count()); 341 EXPECT_EQ(0u, counter.event_count());
335 counter.reset(); 342 counter.reset();
336 343
337 event_generator.MoveMouseWheel(0, 10); 344 event_generator.MoveMouseWheel(0, 10);
338 EXPECT_EQ(0u, counter.event_count()); 345 EXPECT_EQ(0u, counter.event_count());
339 counter.reset(); 346 counter.reset();
340 347
341 // Touch should not be blocked. 348 // Touch should not be blocked.
342 event_generator.PressTouch(); 349 event_generator.PressTouch();
343 event_generator.ReleaseTouch(); 350 event_generator.ReleaseTouch();
344 EXPECT_GT(counter.event_count(), 0u); 351 EXPECT_GT(counter.event_count(), 0u);
345 counter.reset(); 352 counter.reset();
346 353
347 gfx::Vector3dF base; 354 gfx::Vector3dF base;
348 355
349 // Lid open 90 degrees. 356 // Lid open 90 degrees.
350 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 357 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
351 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 358 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 503
497 // Open 90 degrees. 504 // Open 90 degrees.
498 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 505 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
499 EXPECT_FALSE(IsMaximizeModeStarted()); 506 EXPECT_FALSE(IsMaximizeModeStarted());
500 507
501 // Send an update that would not relaunch MaximizeMode. 90 degrees. 508 // Send an update that would not relaunch MaximizeMode. 90 degrees.
502 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 509 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
503 EXPECT_FALSE(maximize_mode_controller()->rotation_locked()); 510 EXPECT_FALSE(maximize_mode_controller()->rotation_locked());
504 } 511 }
505 512
513 // The TrayDisplay class that is responsible for adding/updating MessageCenter
514 // notifications is only added to the SystemTray on ChromeOS.
515 #if defined(OS_CHROMEOS)
516 // Tests that the screen rotation notifications are suppressed when
517 // triggered by the accelerometer.
518 TEST_F(MaximizeModeControllerTest, BlockRotationNotifications) {
519 test::TestSystemTrayDelegate* tray_delegate =
520 static_cast<test::TestSystemTrayDelegate*>(
521 Shell::GetInstance()->system_tray_delegate());
522 tray_delegate->set_should_show_display_notification(true);
523
524 message_center::MessageCenter* message_center =
525 message_center::MessageCenter::Get();
526
527 // Make sure notifications are still displayed when
528 // adjusting the screen rotation directly when not in maximize mode
529 ASSERT_FALSE(IsMaximizeModeStarted());
530 ASSERT_NE(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
531 ASSERT_EQ(0u, message_center->NotificationCount());
532 ASSERT_FALSE(message_center->HasPopupNotifications());
533 SetInternalDisplayRotation(gfx::Display::ROTATE_180);
534 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
535 EXPECT_EQ(1u, message_center->NotificationCount());
536 EXPECT_TRUE(message_center->HasPopupNotifications());
537
538 // Reset the screen rotation.
539 SetInternalDisplayRotation(gfx::Display::ROTATE_0);
540 // Clear all notifications
541 message_center->RemoveAllNotifications(false);
542 // Trigger maximize mode by opening to 270.
543 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
544 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
545 EXPECT_TRUE(IsMaximizeModeStarted());
546 EXPECT_EQ(0u, message_center->NotificationCount());
547 EXPECT_FALSE(message_center->HasPopupNotifications());
548
549 // Make sure notifications are still displayed when
550 // adjusting the screen rotation directly when in maximize mode
551 ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
552 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
553 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
554 EXPECT_EQ(1u, message_center->NotificationCount());
555 EXPECT_TRUE(message_center->HasPopupNotifications());
556
557 // Clear all notifications
558 message_center->RemoveAllNotifications(false);
559 EXPECT_EQ(0u, message_center->NotificationCount());
560 EXPECT_FALSE(message_center->HasPopupNotifications());
561
562 // Make sure notifications are blocked when adjusting the screen rotation
563 // via the accelerometer while in maximize mode
564 // Rotate the screen 90 degrees
565 ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
566 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 1.0f, 0.0f),
567 gfx::Vector3dF(0.0f, 1.0f, 0.0f));
568 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
569 EXPECT_EQ(0u, message_center->NotificationCount());
570 EXPECT_FALSE(message_center->HasPopupNotifications());
571 }
572 #endif
573
506 } // namespace ash 574 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698