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

Unified Diff: ash/display/display_manager_unittest.cc

Issue 2802403002: Resolve current orientation after applying the previous orientation request. (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ash/display/display_manager_unittest.cc
diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc
index 456625d65aa9b16abd1214dc47e3ff8c222bf6fe..c7d1a90d303d77963eda2d68d36f878375de1fb5 100644
--- a/ash/display/display_manager_unittest.cc
+++ b/ash/display/display_manager_unittest.cc
@@ -21,6 +21,7 @@
#include "ash/strings/grit/ash_strings.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/mirror_window_test_api.h"
+#include "ash/test/screen_orientation_controller_test_api.h"
#include "ash/wm/window_state_aura.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
@@ -2963,6 +2964,30 @@ TEST_F(DisplayManagerTest, GuessDisplayIdFieldsInDisplayLayout) {
namespace {
+class DisplayManagerOrientationTest : public DisplayManagerTest {
+ public:
+ DisplayManagerOrientationTest() {}
+ ~DisplayManagerOrientationTest() override {}
+
+ void SetUp() override {
+ DisplayManagerTest::SetUp();
+ const float kMeanGravity = 9.8066f;
+ portrait_primary->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, kMeanGravity,
+ 0.f, 0.f);
+ portrait_secondary->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN,
+ -kMeanGravity, 0.f, 0.f);
+ }
+
+ protected:
+ scoped_refptr<chromeos::AccelerometerUpdate> portrait_primary =
+ new chromeos::AccelerometerUpdate();
+ scoped_refptr<chromeos::AccelerometerUpdate> portrait_secondary =
+ new chromeos::AccelerometerUpdate();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DisplayManagerOrientationTest);
+};
+
class TestObserver : public ScreenOrientationController::Observer {
public:
TestObserver() {}
@@ -2982,13 +3007,14 @@ class TestObserver : public ScreenOrientationController::Observer {
} // namespace
-TEST_F(DisplayManagerTest, SaveRestoreUserRotationLock) {
+TEST_F(DisplayManagerOrientationTest, SaveRestoreUserRotationLock) {
Shell* shell = Shell::GetInstance();
display::DisplayManager* display_manager = shell->display_manager();
- display::test::DisplayManagerTestApi test_api(display_manager);
- test_api.SetFirstDisplayAsInternalDisplay();
+ display::test::DisplayManagerTestApi(display_manager)
+ .SetFirstDisplayAsInternalDisplay();
ScreenOrientationController* orientation_controller =
shell->screen_orientation_controller();
+ test::ScreenOrientationControllerTestApi test_api(orientation_controller);
TestObserver test_observer;
orientation_controller->AddObserver(&test_observer);
@@ -2998,21 +3024,24 @@ TEST_F(DisplayManagerTest, SaveRestoreUserRotationLock) {
WmWindow* wm_window_a = WmWindow::Get(window_a);
wm_window_a->SetAppType(static_cast<int>(AppType::CHROME_APP));
orientation_controller->LockOrientationForWindow(
- wm_window_a, blink::WebScreenOrientationLockAny);
+ wm_window_a, blink::WebScreenOrientationLockAny,
+ ScreenOrientationController::LockCompletionBehavior::None);
}
aura::Window* window_p = CreateTestWindowInShellWithId(0);
{
WmWindow* wm_window_p = WmWindow::Get(window_p);
wm_window_p->SetAppType(static_cast<int>(AppType::CHROME_APP));
orientation_controller->LockOrientationForWindow(
- wm_window_p, blink::WebScreenOrientationLockPortrait);
+ wm_window_p, blink::WebScreenOrientationLockPortrait,
+ ScreenOrientationController::LockCompletionBehavior::None);
}
aura::Window* window_l = CreateTestWindowInShellWithId(0);
{
WmWindow* wm_window_l = WmWindow::Get(window_l);
wm_window_l->SetAppType(static_cast<int>(AppType::CHROME_APP));
orientation_controller->LockOrientationForWindow(
- wm_window_l, blink::WebScreenOrientationLockLandscape);
+ wm_window_l, blink::WebScreenOrientationLockLandscape,
+ ScreenOrientationController::LockCompletionBehavior::None);
}
DisplayConfigurationController* configuration_controller =
@@ -3035,6 +3064,8 @@ TEST_F(DisplayManagerTest, SaveRestoreUserRotationLock) {
EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation());
EXPECT_FALSE(display_manager->registered_internal_display_rotation_lock());
+ EXPECT_EQ(blink::WebScreenOrientationLockLandscapePrimary,
+ test_api.GetCurrentOrientation());
// Enable lock at 0.
orientation_controller->ToggleUserRotationLock();
@@ -3051,6 +3082,8 @@ TEST_F(DisplayManagerTest, SaveRestoreUserRotationLock) {
EXPECT_EQ(display::Display::ROTATE_0,
display_manager->registered_internal_display_rotation());
EXPECT_EQ(0, test_observer.countAndReset());
+ EXPECT_EQ(blink::WebScreenOrientationLockPortraitPrimary,
+ test_api.GetCurrentOrientation());
// Any will rotate to the locked rotation.
wm::ActivateWindow(window_a);
@@ -3106,7 +3139,7 @@ TEST_F(DisplayManagerTest, SaveRestoreUserRotationLock) {
orientation_controller->RemoveObserver(&test_observer);
}
-TEST_F(DisplayManagerTest, UserRotationLockReverse) {
+TEST_F(DisplayManagerOrientationTest, UserRotationLockReverse) {
Shell* shell = Shell::GetInstance();
display::DisplayManager* display_manager = shell->display_manager();
display::test::DisplayManagerTestApi test_api(display_manager);
@@ -3125,25 +3158,17 @@ TEST_F(DisplayManagerTest, UserRotationLockReverse) {
true);
orientation_controller->LockOrientationForWindow(
- wm_window, blink::WebScreenOrientationLockPortrait);
+ wm_window, blink::WebScreenOrientationLockPortrait,
+ ScreenOrientationController::LockCompletionBehavior::None);
EXPECT_EQ(display::Display::ROTATE_90,
screen->GetPrimaryDisplay().rotation());
- const float kMeanGravity = -9.8066f;
-
- scoped_refptr<chromeos::AccelerometerUpdate> reverse_portrait(
- new chromeos::AccelerometerUpdate());
- reverse_portrait->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, kMeanGravity,
- 0.f, 0.f);
- orientation_controller->OnAccelerometerUpdated(reverse_portrait);
+ orientation_controller->OnAccelerometerUpdated(portrait_secondary);
EXPECT_EQ(display::Display::ROTATE_270,
screen->GetPrimaryDisplay().rotation());
- scoped_refptr<chromeos::AccelerometerUpdate> portrait(
- new chromeos::AccelerometerUpdate());
- portrait->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, -kMeanGravity, 0.f, 0.f);
- orientation_controller->OnAccelerometerUpdated(portrait);
+ orientation_controller->OnAccelerometerUpdated(portrait_primary);
EXPECT_EQ(display::Display::ROTATE_90,
screen->GetPrimaryDisplay().rotation());
@@ -3153,10 +3178,70 @@ TEST_F(DisplayManagerTest, UserRotationLockReverse) {
EXPECT_EQ(display::Display::ROTATE_90,
display_manager->registered_internal_display_rotation());
- orientation_controller->OnAccelerometerUpdated(reverse_portrait);
+ orientation_controller->OnAccelerometerUpdated(portrait_secondary);
EXPECT_EQ(display::Display::ROTATE_90,
screen->GetPrimaryDisplay().rotation());
}
+TEST_F(DisplayManagerOrientationTest, LockToSpecificOrientation) {
+ Shell* shell = Shell::GetInstance();
+ display::DisplayManager* display_manager = shell->display_manager();
+ display::test::DisplayManagerTestApi(display_manager)
+ .SetFirstDisplayAsInternalDisplay();
+ ScreenOrientationController* orientation_controller =
+ shell->screen_orientation_controller();
+ test::ScreenOrientationControllerTestApi test_api(orientation_controller);
+
+ aura::Window* window_a = CreateTestWindowInShellWithId(0);
+ {
+ WmWindow* wm_window_a = WmWindow::Get(window_a);
+ wm_window_a->SetAppType(static_cast<int>(AppType::CHROME_APP));
+ orientation_controller->LockOrientationForWindow(
+ wm_window_a, blink::WebScreenOrientationLockAny,
+ ScreenOrientationController::LockCompletionBehavior::None);
+ }
+ wm::ActivateWindow(window_a);
+ WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
+ true);
+
+ orientation_controller->OnAccelerometerUpdated(portrait_primary);
+
+ EXPECT_EQ(blink::WebScreenOrientationLockPortraitPrimary,
+ test_api.GetCurrentOrientation());
+
+ orientation_controller->OnAccelerometerUpdated(portrait_secondary);
+
+ aura::Window* window_ps = CreateTestWindowInShellWithId(1);
+ {
+ WmWindow* wm_window_ps = WmWindow::Get(window_ps);
+ wm_window_ps->SetAppType(static_cast<int>(AppType::CHROME_APP));
+ orientation_controller->LockOrientationForWindow(
+ wm_window_ps, blink::WebScreenOrientationLockPortrait,
+ ScreenOrientationController::LockCompletionBehavior::DisableSensor);
+ wm::ActivateWindow(window_ps);
+ }
+
+ EXPECT_EQ(blink::WebScreenOrientationLockPortraitSecondary,
+ test_api.GetCurrentOrientation());
+
+ // The orientation should stay portrait secondary.
+ orientation_controller->OnAccelerometerUpdated(portrait_primary);
+ EXPECT_EQ(blink::WebScreenOrientationLockPortraitSecondary,
+ test_api.GetCurrentOrientation());
+
+ wm::ActivateWindow(window_a);
+ orientation_controller->OnAccelerometerUpdated(portrait_primary);
+
+ // Swtching to |window_a| enables rotation.
+ EXPECT_EQ(blink::WebScreenOrientationLockPortraitPrimary,
+ test_api.GetCurrentOrientation());
+
+ // The orientation has alraedy been locked to secondary once, so
+ // it should swtich back to the portrait secondary.
+ wm::ActivateWindow(window_ps);
+ EXPECT_EQ(blink::WebScreenOrientationLockPortraitSecondary,
+ test_api.GetCurrentOrientation());
+}
+
} // namespace ash
« no previous file with comments | « ash/content/screen_orientation_delegate_chromeos.cc ('k') | ash/display/screen_orientation_controller_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698