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

Side by Side Diff: ash/display/display_manager_unittest.cc

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