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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/display/manager/display_manager.h" 5 #include "ui/display/manager/display_manager.h"
6 6
7 #include "ash/accelerators/accelerator_commands_aura.h" 7 #include "ash/accelerators/accelerator_commands_aura.h"
8 #include "ash/common/ash_switches.h" 8 #include "ash/common/ash_switches.h"
9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
10 #include "ash/common/wm/window_state.h" 10 #include "ash/common/wm/window_state.h"
11 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
12 #include "ash/common/wm_window.h" 12 #include "ash/common/wm_window.h"
13 #include "ash/display/display_configuration_controller.h" 13 #include "ash/display/display_configuration_controller.h"
14 #include "ash/display/display_util.h" 14 #include "ash/display/display_util.h"
15 #include "ash/display/mirror_window_controller.h" 15 #include "ash/display/mirror_window_controller.h"
16 #include "ash/display/screen_orientation_controller_chromeos.h" 16 #include "ash/display/screen_orientation_controller_chromeos.h"
17 #include "ash/display/window_tree_host_manager.h" 17 #include "ash/display/window_tree_host_manager.h"
18 #include "ash/screen_util.h" 18 #include "ash/screen_util.h"
19 #include "ash/shared/app_types.h" 19 #include "ash/shared/app_types.h"
20 #include "ash/shell.h" 20 #include "ash/shell.h"
21 #include "ash/strings/grit/ash_strings.h" 21 #include "ash/strings/grit/ash_strings.h"
22 #include "ash/test/ash_test_base.h" 22 #include "ash/test/ash_test_base.h"
23 #include "ash/test/mirror_window_test_api.h" 23 #include "ash/test/mirror_window_test_api.h"
24 #include "ash/test/screen_orientation_controller_test_api.h"
24 #include "ash/wm/window_state_aura.h" 25 #include "ash/wm/window_state_aura.h"
25 #include "ash/wm/window_util.h" 26 #include "ash/wm/window_util.h"
26 #include "base/command_line.h" 27 #include "base/command_line.h"
27 #include "base/format_macros.h" 28 #include "base/format_macros.h"
28 #include "base/strings/string_number_conversions.h" 29 #include "base/strings/string_number_conversions.h"
29 #include "base/strings/stringprintf.h" 30 #include "base/strings/stringprintf.h"
30 #include "build/build_config.h" 31 #include "build/build_config.h"
31 #include "chromeos/accelerometer/accelerometer_reader.h" 32 #include "chromeos/accelerometer/accelerometer_reader.h"
32 #include "chromeos/accelerometer/accelerometer_types.h" 33 #include "chromeos/accelerometer/accelerometer_types.h"
33 #include "ui/aura/client/aura_constants.h" 34 #include "ui/aura/client/aura_constants.h"
(...skipping 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after
2956 layout_store->RegisterLayoutForDisplayIdList(list, std::move(old_layout)); 2957 layout_store->RegisterLayoutForDisplayIdList(list, std::move(old_layout));
2957 const display::DisplayLayout& stored = 2958 const display::DisplayLayout& stored =
2958 layout_store->GetRegisteredDisplayLayout(list); 2959 layout_store->GetRegisteredDisplayLayout(list);
2959 2960
2960 EXPECT_EQ(id1, stored.placement_list[0].parent_display_id); 2961 EXPECT_EQ(id1, stored.placement_list[0].parent_display_id);
2961 EXPECT_EQ(id2, stored.placement_list[0].display_id); 2962 EXPECT_EQ(id2, stored.placement_list[0].display_id);
2962 } 2963 }
2963 2964
2964 namespace { 2965 namespace {
2965 2966
2967 class DisplayManagerOrientationTest : public DisplayManagerTest {
2968 public:
2969 DisplayManagerOrientationTest() {}
2970 ~DisplayManagerOrientationTest() override {}
2971
2972 void SetUp() override {
2973 DisplayManagerTest::SetUp();
2974 const float kMeanGravity = 9.8066f;
2975 portrait_primary->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, kMeanGravity,
2976 0.f, 0.f);
2977 portrait_secondary->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN,
2978 -kMeanGravity, 0.f, 0.f);
2979 }
2980
2981 protected:
2982 scoped_refptr<chromeos::AccelerometerUpdate> portrait_primary =
2983 new chromeos::AccelerometerUpdate();
2984 scoped_refptr<chromeos::AccelerometerUpdate> portrait_secondary =
2985 new chromeos::AccelerometerUpdate();
2986
2987 private:
2988 DISALLOW_COPY_AND_ASSIGN(DisplayManagerOrientationTest);
2989 };
2990
2966 class TestObserver : public ScreenOrientationController::Observer { 2991 class TestObserver : public ScreenOrientationController::Observer {
2967 public: 2992 public:
2968 TestObserver() {} 2993 TestObserver() {}
2969 ~TestObserver() override{}; 2994 ~TestObserver() override{};
2970 2995
2971 void OnUserRotationLockChanged() override { count_++; } 2996 void OnUserRotationLockChanged() override { count_++; }
2972 2997
2973 int countAndReset() { 2998 int countAndReset() {
2974 int tmp = count_; 2999 int tmp = count_;
2975 count_ = 0; 3000 count_ = 0;
2976 return tmp; 3001 return tmp;
2977 } 3002 }
2978 3003
2979 private: 3004 private:
2980 int count_ = 0; 3005 int count_ = 0;
2981 }; 3006 };
2982 3007
2983 } // namespace 3008 } // namespace
2984 3009
2985 TEST_F(DisplayManagerTest, SaveRestoreUserRotationLock) { 3010 TEST_F(DisplayManagerOrientationTest, SaveRestoreUserRotationLock) {
2986 Shell* shell = Shell::GetInstance(); 3011 Shell* shell = Shell::GetInstance();
2987 display::DisplayManager* display_manager = shell->display_manager(); 3012 display::DisplayManager* display_manager = shell->display_manager();
2988 display::test::DisplayManagerTestApi test_api(display_manager); 3013 display::test::DisplayManagerTestApi(display_manager)
2989 test_api.SetFirstDisplayAsInternalDisplay(); 3014 .SetFirstDisplayAsInternalDisplay();
2990 ScreenOrientationController* orientation_controller = 3015 ScreenOrientationController* orientation_controller =
2991 shell->screen_orientation_controller(); 3016 shell->screen_orientation_controller();
3017 test::ScreenOrientationControllerTestApi test_api(orientation_controller);
2992 TestObserver test_observer; 3018 TestObserver test_observer;
2993 orientation_controller->AddObserver(&test_observer); 3019 orientation_controller->AddObserver(&test_observer);
2994 3020
2995 // Set up windows with portrait,lanscape and any. 3021 // Set up windows with portrait,lanscape and any.
2996 aura::Window* window_a = CreateTestWindowInShellWithId(0); 3022 aura::Window* window_a = CreateTestWindowInShellWithId(0);
2997 { 3023 {
2998 WmWindow* wm_window_a = WmWindow::Get(window_a); 3024 WmWindow* wm_window_a = WmWindow::Get(window_a);
2999 wm_window_a->SetAppType(static_cast<int>(AppType::CHROME_APP)); 3025 wm_window_a->SetAppType(static_cast<int>(AppType::CHROME_APP));
3000 orientation_controller->LockOrientationForWindow( 3026 orientation_controller->LockOrientationForWindow(
3001 wm_window_a, blink::WebScreenOrientationLockAny); 3027 wm_window_a, blink::WebScreenOrientationLockAny,
3028 ScreenOrientationController::LockCompletionBehavior::None);
3002 } 3029 }
3003 aura::Window* window_p = CreateTestWindowInShellWithId(0); 3030 aura::Window* window_p = CreateTestWindowInShellWithId(0);
3004 { 3031 {
3005 WmWindow* wm_window_p = WmWindow::Get(window_p); 3032 WmWindow* wm_window_p = WmWindow::Get(window_p);
3006 wm_window_p->SetAppType(static_cast<int>(AppType::CHROME_APP)); 3033 wm_window_p->SetAppType(static_cast<int>(AppType::CHROME_APP));
3007 orientation_controller->LockOrientationForWindow( 3034 orientation_controller->LockOrientationForWindow(
3008 wm_window_p, blink::WebScreenOrientationLockPortrait); 3035 wm_window_p, blink::WebScreenOrientationLockPortrait,
3036 ScreenOrientationController::LockCompletionBehavior::None);
3009 } 3037 }
3010 aura::Window* window_l = CreateTestWindowInShellWithId(0); 3038 aura::Window* window_l = CreateTestWindowInShellWithId(0);
3011 { 3039 {
3012 WmWindow* wm_window_l = WmWindow::Get(window_l); 3040 WmWindow* wm_window_l = WmWindow::Get(window_l);
3013 wm_window_l->SetAppType(static_cast<int>(AppType::CHROME_APP)); 3041 wm_window_l->SetAppType(static_cast<int>(AppType::CHROME_APP));
3014 orientation_controller->LockOrientationForWindow( 3042 orientation_controller->LockOrientationForWindow(
3015 wm_window_l, blink::WebScreenOrientationLockLandscape); 3043 wm_window_l, blink::WebScreenOrientationLockLandscape,
3044 ScreenOrientationController::LockCompletionBehavior::None);
3016 } 3045 }
3017 3046
3018 DisplayConfigurationController* configuration_controller = 3047 DisplayConfigurationController* configuration_controller =
3019 shell->display_configuration_controller(); 3048 shell->display_configuration_controller();
3020 display::Screen* screen = display::Screen::GetScreen(); 3049 display::Screen* screen = display::Screen::GetScreen();
3021 3050
3022 // Rotate to portrait in clamshell. 3051 // Rotate to portrait in clamshell.
3023 configuration_controller->SetDisplayRotation( 3052 configuration_controller->SetDisplayRotation(
3024 screen->GetPrimaryDisplay().id(), display::Display::ROTATE_90, 3053 screen->GetPrimaryDisplay().id(), display::Display::ROTATE_90,
3025 display::Display::ROTATION_SOURCE_USER); 3054 display::Display::ROTATION_SOURCE_USER);
3026 EXPECT_EQ(display::Display::ROTATE_90, 3055 EXPECT_EQ(display::Display::ROTATE_90,
3027 screen->GetPrimaryDisplay().rotation()); 3056 screen->GetPrimaryDisplay().rotation());
3028 EXPECT_FALSE(display_manager->registered_internal_display_rotation_lock()); 3057 EXPECT_FALSE(display_manager->registered_internal_display_rotation_lock());
3029 3058
3030 EXPECT_EQ(0, test_observer.countAndReset()); 3059 EXPECT_EQ(0, test_observer.countAndReset());
3031 // Just enabling will not save the lock. 3060 // Just enabling will not save the lock.
3032 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( 3061 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
3033 true); 3062 true);
3034 EXPECT_EQ(1, test_observer.countAndReset()); 3063 EXPECT_EQ(1, test_observer.countAndReset());
3035 3064
3036 EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation()); 3065 EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation());
3037 EXPECT_FALSE(display_manager->registered_internal_display_rotation_lock()); 3066 EXPECT_FALSE(display_manager->registered_internal_display_rotation_lock());
3067 EXPECT_EQ(blink::WebScreenOrientationLockLandscapePrimary,
3068 test_api.GetCurrentOrientation());
3038 3069
3039 // Enable lock at 0. 3070 // Enable lock at 0.
3040 orientation_controller->ToggleUserRotationLock(); 3071 orientation_controller->ToggleUserRotationLock();
3041 EXPECT_EQ(1, test_observer.countAndReset()); 3072 EXPECT_EQ(1, test_observer.countAndReset());
3042 3073
3043 EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock()); 3074 EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock());
3044 EXPECT_EQ(display::Display::ROTATE_0, 3075 EXPECT_EQ(display::Display::ROTATE_0,
3045 display_manager->registered_internal_display_rotation()); 3076 display_manager->registered_internal_display_rotation());
3046 3077
3047 // Application can overwwrite the locked orientation. 3078 // Application can overwwrite the locked orientation.
3048 wm::ActivateWindow(window_p); 3079 wm::ActivateWindow(window_p);
3049 EXPECT_EQ(display::Display::ROTATE_90, 3080 EXPECT_EQ(display::Display::ROTATE_90,
3050 screen->GetPrimaryDisplay().rotation()); 3081 screen->GetPrimaryDisplay().rotation());
3051 EXPECT_EQ(display::Display::ROTATE_0, 3082 EXPECT_EQ(display::Display::ROTATE_0,
3052 display_manager->registered_internal_display_rotation()); 3083 display_manager->registered_internal_display_rotation());
3053 EXPECT_EQ(0, test_observer.countAndReset()); 3084 EXPECT_EQ(0, test_observer.countAndReset());
3085 EXPECT_EQ(blink::WebScreenOrientationLockPortraitPrimary,
3086 test_api.GetCurrentOrientation());
3054 3087
3055 // Any will rotate to the locked rotation. 3088 // Any will rotate to the locked rotation.
3056 wm::ActivateWindow(window_a); 3089 wm::ActivateWindow(window_a);
3057 EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation()); 3090 EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation());
3058 EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock()); 3091 EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock());
3059 EXPECT_EQ(display::Display::ROTATE_0, 3092 EXPECT_EQ(display::Display::ROTATE_0,
3060 display_manager->registered_internal_display_rotation()); 3093 display_manager->registered_internal_display_rotation());
3061 EXPECT_EQ(0, test_observer.countAndReset()); 3094 EXPECT_EQ(0, test_observer.countAndReset());
3062 3095
3063 wm::ActivateWindow(window_l); 3096 wm::ActivateWindow(window_l);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3099 display_manager->registered_internal_display_rotation()); 3132 display_manager->registered_internal_display_rotation());
3100 3133
3101 // ANY will rotate to locked ortation. 3134 // ANY will rotate to locked ortation.
3102 wm::ActivateWindow(window_a); 3135 wm::ActivateWindow(window_a);
3103 EXPECT_EQ(display::Display::ROTATE_90, 3136 EXPECT_EQ(display::Display::ROTATE_90,
3104 screen->GetPrimaryDisplay().rotation()); 3137 screen->GetPrimaryDisplay().rotation());
3105 3138
3106 orientation_controller->RemoveObserver(&test_observer); 3139 orientation_controller->RemoveObserver(&test_observer);
3107 } 3140 }
3108 3141
3109 TEST_F(DisplayManagerTest, UserRotationLockReverse) { 3142 TEST_F(DisplayManagerOrientationTest, UserRotationLockReverse) {
3110 Shell* shell = Shell::GetInstance(); 3143 Shell* shell = Shell::GetInstance();
3111 display::DisplayManager* display_manager = shell->display_manager(); 3144 display::DisplayManager* display_manager = shell->display_manager();
3112 display::test::DisplayManagerTestApi test_api(display_manager); 3145 display::test::DisplayManagerTestApi test_api(display_manager);
3113 test_api.SetFirstDisplayAsInternalDisplay(); 3146 test_api.SetFirstDisplayAsInternalDisplay();
3114 ScreenOrientationController* orientation_controller = 3147 ScreenOrientationController* orientation_controller =
3115 shell->screen_orientation_controller(); 3148 shell->screen_orientation_controller();
3116 3149
3117 // Set up windows with portrait,lanscape and any. 3150 // Set up windows with portrait,lanscape and any.
3118 aura::Window* window = CreateTestWindowInShellWithId(0); 3151 aura::Window* window = CreateTestWindowInShellWithId(0);
3119 WmWindow* wm_window = WmWindow::Get(window); 3152 WmWindow* wm_window = WmWindow::Get(window);
3120 wm_window->SetAppType(static_cast<int>(AppType::CHROME_APP)); 3153 wm_window->SetAppType(static_cast<int>(AppType::CHROME_APP));
3121 display::Screen* screen = display::Screen::GetScreen(); 3154 display::Screen* screen = display::Screen::GetScreen();
3122 3155
3123 // Just enabling will not save the lock. 3156 // Just enabling will not save the lock.
3124 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( 3157 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
3125 true); 3158 true);
3126 3159
3127 orientation_controller->LockOrientationForWindow( 3160 orientation_controller->LockOrientationForWindow(
3128 wm_window, blink::WebScreenOrientationLockPortrait); 3161 wm_window, blink::WebScreenOrientationLockPortrait,
3162 ScreenOrientationController::LockCompletionBehavior::None);
3129 EXPECT_EQ(display::Display::ROTATE_90, 3163 EXPECT_EQ(display::Display::ROTATE_90,
3130 screen->GetPrimaryDisplay().rotation()); 3164 screen->GetPrimaryDisplay().rotation());
3131 3165
3132 const float kMeanGravity = -9.8066f; 3166 orientation_controller->OnAccelerometerUpdated(portrait_secondary);
3133
3134 scoped_refptr<chromeos::AccelerometerUpdate> reverse_portrait(
3135 new chromeos::AccelerometerUpdate());
3136 reverse_portrait->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, kMeanGravity,
3137 0.f, 0.f);
3138 orientation_controller->OnAccelerometerUpdated(reverse_portrait);
3139 3167
3140 EXPECT_EQ(display::Display::ROTATE_270, 3168 EXPECT_EQ(display::Display::ROTATE_270,
3141 screen->GetPrimaryDisplay().rotation()); 3169 screen->GetPrimaryDisplay().rotation());
3142 3170
3143 scoped_refptr<chromeos::AccelerometerUpdate> portrait( 3171 orientation_controller->OnAccelerometerUpdated(portrait_primary);
3144 new chromeos::AccelerometerUpdate());
3145 portrait->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, -kMeanGravity, 0.f, 0.f);
3146 orientation_controller->OnAccelerometerUpdated(portrait);
3147 EXPECT_EQ(display::Display::ROTATE_90, 3172 EXPECT_EQ(display::Display::ROTATE_90,
3148 screen->GetPrimaryDisplay().rotation()); 3173 screen->GetPrimaryDisplay().rotation());
3149 3174
3150 // Enable lock at 90. 3175 // Enable lock at 90.
3151 orientation_controller->ToggleUserRotationLock(); 3176 orientation_controller->ToggleUserRotationLock();
3152 EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock()); 3177 EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock());
3153 EXPECT_EQ(display::Display::ROTATE_90, 3178 EXPECT_EQ(display::Display::ROTATE_90,
3154 display_manager->registered_internal_display_rotation()); 3179 display_manager->registered_internal_display_rotation());
3155 3180
3156 orientation_controller->OnAccelerometerUpdated(reverse_portrait); 3181 orientation_controller->OnAccelerometerUpdated(portrait_secondary);
3157 3182
3158 EXPECT_EQ(display::Display::ROTATE_90, 3183 EXPECT_EQ(display::Display::ROTATE_90,
3159 screen->GetPrimaryDisplay().rotation()); 3184 screen->GetPrimaryDisplay().rotation());
3160 } 3185 }
3161 3186
3187 TEST_F(DisplayManagerOrientationTest, LockToSpecificOrientation) {
3188 Shell* shell = Shell::GetInstance();
3189 display::DisplayManager* display_manager = shell->display_manager();
3190 display::test::DisplayManagerTestApi(display_manager)
3191 .SetFirstDisplayAsInternalDisplay();
3192 ScreenOrientationController* orientation_controller =
3193 shell->screen_orientation_controller();
3194 test::ScreenOrientationControllerTestApi test_api(orientation_controller);
3195
3196 aura::Window* window_a = CreateTestWindowInShellWithId(0);
3197 {
3198 WmWindow* wm_window_a = WmWindow::Get(window_a);
3199 wm_window_a->SetAppType(static_cast<int>(AppType::CHROME_APP));
3200 orientation_controller->LockOrientationForWindow(
3201 wm_window_a, blink::WebScreenOrientationLockAny,
3202 ScreenOrientationController::LockCompletionBehavior::None);
3203 }
3204 wm::ActivateWindow(window_a);
3205 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
3206 true);
3207
3208 orientation_controller->OnAccelerometerUpdated(portrait_primary);
3209
3210 EXPECT_EQ(blink::WebScreenOrientationLockPortraitPrimary,
3211 test_api.GetCurrentOrientation());
3212
3213 orientation_controller->OnAccelerometerUpdated(portrait_secondary);
3214
3215 aura::Window* window_ps = CreateTestWindowInShellWithId(1);
3216 {
3217 WmWindow* wm_window_ps = WmWindow::Get(window_ps);
3218 wm_window_ps->SetAppType(static_cast<int>(AppType::CHROME_APP));
3219 orientation_controller->LockOrientationForWindow(
3220 wm_window_ps, blink::WebScreenOrientationLockPortrait,
3221 ScreenOrientationController::LockCompletionBehavior::DisableSensor);
3222 wm::ActivateWindow(window_ps);
3223 }
3224
3225 EXPECT_EQ(blink::WebScreenOrientationLockPortraitSecondary,
3226 test_api.GetCurrentOrientation());
3227
3228 // The orientation should stay portrait secondary.
3229 orientation_controller->OnAccelerometerUpdated(portrait_primary);
3230 EXPECT_EQ(blink::WebScreenOrientationLockPortraitSecondary,
3231 test_api.GetCurrentOrientation());
3232
3233 wm::ActivateWindow(window_a);
3234 orientation_controller->OnAccelerometerUpdated(portrait_primary);
3235
3236 // Swtching to |window_a| enables rotation.
3237 EXPECT_EQ(blink::WebScreenOrientationLockPortraitPrimary,
3238 test_api.GetCurrentOrientation());
3239
3240 // The orientation has alraedy been locked to secondary once, so
3241 // it should swtich back to the portrait secondary.
3242 wm::ActivateWindow(window_ps);
3243 EXPECT_EQ(blink::WebScreenOrientationLockPortraitSecondary,
3244 test_api.GetCurrentOrientation());
3245 }
3246
3162 } // namespace ash 3247 } // namespace ash
OLDNEW
« 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