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

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: Minor fix to some whitespace 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/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
11 #include "ash/test/display_manager_test_api.h" 11 #include "ash/test/display_manager_test_api.h"
12 #include "ash/test/test_system_tray_delegate.h"
12 #include "ui/aura/test/event_generator.h" 13 #include "ui/aura/test/event_generator.h"
jonross 2014/05/09 14:57:33 unused?
13 #include "ui/events/event_handler.h" 14 #include "ui/events/event_handler.h"
14 #include "ui/gfx/vector3d_f.h" 15 #include "ui/gfx/vector3d_f.h"
16 #include "ui/message_center/message_center.h"
15 17
16 namespace ash { 18 namespace ash {
17 19
18 namespace { 20 namespace {
19 21
20 const float kDegreesToRadians = 3.14159265f / 180.0f; 22 const float kDegreesToRadians = 3.14159265f / 180.0f;
21 23
22 // Filter to count the number of events seen. 24 // Filter to count the number of events seen.
23 class EventCounter : public ui::EventHandler { 25 class EventCounter : public ui::EventHandler {
24 public: 26 public:
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 103
102 bool IsMaximizeModeStarted() const { 104 bool IsMaximizeModeStarted() const {
103 return Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); 105 return Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled();
104 } 106 }
105 107
106 gfx::Display::Rotation GetInternalDisplayRotation() const { 108 gfx::Display::Rotation GetInternalDisplayRotation() const {
107 return Shell::GetInstance()->display_manager()->GetDisplayInfo( 109 return Shell::GetInstance()->display_manager()->GetDisplayInfo(
108 gfx::Display::InternalDisplayId()).rotation(); 110 gfx::Display::InternalDisplayId()).rotation();
109 } 111 }
110 112
113 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) const {
114 Shell::GetInstance()->display_manager()->
115 SetDisplayRotation(gfx::Display::InternalDisplayId(), rotation);
116 }
117
111 private: 118 private:
112 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest); 119 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest);
113 }; 120 };
114 121
115 // Tests that opening the lid beyond 180 will enter touchview, and that it will 122 // Tests that opening the lid beyond 180 will enter touchview, and that it will
116 // exit when the lid comes back from 180. Also tests the thresholds, i.e. it 123 // exit when the lid comes back from 180. Also tests the thresholds, i.e. it
117 // will stick to the current mode. 124 // will stick to the current mode.
118 TEST_F(MaximizeModeControllerTest, EnterExitThresholds) { 125 TEST_F(MaximizeModeControllerTest, EnterExitThresholds) {
119 // For the simple test the base remains steady. 126 // For the simple test the base remains steady.
120 gfx::Vector3dF base(0.0f, 0.0f, 1.0f); 127 gfx::Vector3dF base(0.0f, 0.0f, 1.0f);
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 398
392 maximize_mode_controller()->set_rotation_locked(false); 399 maximize_mode_controller()->set_rotation_locked(false);
393 TriggerAccelerometerUpdate(gravity, gravity); 400 TriggerAccelerometerUpdate(gravity, gravity);
394 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 401 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
395 } 402 }
396 403
397 // Tests that if the display was rotated before entering maximize mode that 404 // Tests that if the display was rotated before entering maximize mode that
398 // rotation becomes locked. 405 // rotation becomes locked.
399 TEST_F(MaximizeModeControllerTest, 406 TEST_F(MaximizeModeControllerTest,
400 RotatedDisplayLocksRotationUponEnteringMaximizeMode) { 407 RotatedDisplayLocksRotationUponEnteringMaximizeMode) {
401 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 408 SetInternalDisplayRotation(gfx::Display::ROTATE_90);
402 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
403 gfx::Display::ROTATE_90);
404 409
405 // Trigger a non-maximize mode accelerometer update. Ensure that the display 410 // Trigger a non-maximize mode accelerometer update. Ensure that the display
406 // does not rotate. 411 // does not rotate.
407 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 412 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
408 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 413 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
409 EXPECT_FALSE(IsMaximizeModeStarted()); 414 EXPECT_FALSE(IsMaximizeModeStarted());
410 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 415 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
411 416
412 // Trigger maximize mode by opening to 270. 417 // Trigger maximize mode by opening to 270.
413 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), 418 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
414 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 419 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
415 ASSERT_TRUE(IsMaximizeModeStarted()); 420 ASSERT_TRUE(IsMaximizeModeStarted());
416 EXPECT_TRUE(maximize_mode_controller()->rotation_locked()); 421 EXPECT_TRUE(maximize_mode_controller()->rotation_locked());
417 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 422 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
418 } 423 }
419 424
425 // Tests that the screen rotation notifications are suppressed when
426 // triggered by the accelerometer.
427 TEST_F(MaximizeModeControllerTest, BlockRotationNotifications) {
428 test::TestSystemTrayDelegate* tray_delegate =
429 static_cast<test::TestSystemTrayDelegate*>(
430 Shell::GetInstance()->system_tray_delegate());
431 tray_delegate->set_should_show_display_notification(true);
432
433 aura::Window* root = Shell::GetPrimaryRootWindow();
jonross 2014/05/09 14:57:33 only used for the event_generator
bruthig 2014/05/14 00:36:16 Done.
434 aura::test::EventGenerator event_generator(root, root);
jonross 2014/05/09 14:57:33 unused?
bruthig 2014/05/14 00:36:16 Done.
435 message_center::MessageCenter* message_center =
436 message_center::MessageCenter::Get();
437
438 // Make sure notifications are still displayed when
439 // adjusting the screen rotation directly when not in maximize mode
440 ASSERT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
441 ASSERT_EQ(0u, message_center->NotificationCount());
442 EXPECT_FALSE(message_center->HasPopupNotifications());
jonross 2014/05/09 14:57:33 nit: use ASSERTs before causing changes, to confir
bruthig 2014/05/14 00:36:16 Done.
443 SetInternalDisplayRotation(gfx::Display::ROTATE_180);
444 ASSERT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
445 ASSERT_EQ(1u, message_center->NotificationCount());
446 EXPECT_TRUE(message_center->HasPopupNotifications());
447
448 // Clear all notifications
449 message_center->RemoveAllNotifications(false);
450 ASSERT_EQ(0u, message_center->NotificationCount());
451 EXPECT_FALSE(message_center->HasPopupNotifications());
452
453 // Trigger maximize mode by opening to 270.
454 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
455 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
456 ASSERT_TRUE(IsMaximizeModeStarted());
457 maximize_mode_controller()->set_rotation_locked(false);
458
459 // Make sure notifications are still displayed when
460 // adjusting the screen rotation directly when in maximize mode
461 ASSERT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
462 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
463 ASSERT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
464 ASSERT_EQ(1u, message_center->NotificationCount());
465 EXPECT_TRUE(message_center->HasPopupNotifications());
466
467 // Clear all notifications
468 message_center->RemoveAllNotifications(false);
469 ASSERT_EQ(0u, message_center->NotificationCount());
470 EXPECT_FALSE(message_center->HasPopupNotifications());
471
472 // Make sure notifications are blocked when adjusting the screen rotation
473 // via the accelerometer while in maximize mode
474 // Rotate the screen 90 degrees
475 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 1.0f, 0.0f),
476 gfx::Vector3dF(0.0f, 1.0f, 0.0f));
477 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
478 EXPECT_EQ(1u, message_center->NotificationCount());
479 EXPECT_FALSE(message_center->HasPopupNotifications());
480 }
481
420 } // namespace ash 482 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698