jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Mitsuru Oshima | ddfde355 | 2018-03-22 09:12:13 | [diff] [blame] | 5 | #include "ash/display/screen_orientation_controller.h" |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 6 | |
| 7 | #include <memory> |
bruthig | f57a7bba | 2015-04-24 21:19:31 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
Steven Bennetts | 368a1c8 | 2019-01-11 20:45:22 | [diff] [blame] | 10 | #include "ash/accelerometer/accelerometer_reader.h" |
| 11 | #include "ash/accelerometer/accelerometer_types.h" |
Mitsuru Oshima | ddfde355 | 2018-03-22 09:12:13 | [diff] [blame] | 12 | #include "ash/display/screen_orientation_controller.h" |
James Cook | 346c8c6 | 2017-07-18 19:38:37 | [diff] [blame] | 13 | #include "ash/display/screen_orientation_controller_test_api.h" |
Scott Violet | 1be0306 | 2017-06-26 18:22:17 | [diff] [blame] | 14 | #include "ash/public/cpp/app_types.h" |
Evan Stade | 7d0e823 | 2017-10-04 02:01:36 | [diff] [blame] | 15 | #include "ash/public/cpp/ash_switches.h" |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 16 | #include "ash/shell.h" |
James Cook | a35a1e2 | 2017-04-08 02:33:08 | [diff] [blame] | 17 | #include "ash/system/screen_layout_observer.h" |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 18 | #include "ash/test/ash_test_base.h" |
| 19 | #include "ash/test/ash_test_helper.h" |
James Cook | 346c8c6 | 2017-07-18 19:38:37 | [diff] [blame] | 20 | #include "ash/test_shell_delegate.h" |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 21 | #include "ash/window_factory.h" |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 22 | #include "ash/wm/tablet_mode/tablet_mode_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 23 | #include "ash/wm/window_state.h" |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 24 | #include "base/command_line.h" |
varkha | c8621dd | 2017-05-31 19:09:01 | [diff] [blame] | 25 | #include "ui/aura/client/aura_constants.h" |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 26 | #include "ui/aura/window.h" |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 27 | #include "ui/compositor/layer_type.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 28 | #include "ui/display/display.h" |
rjkroege | 03f3d6b | 2016-09-09 21:27:59 | [diff] [blame] | 29 | #include "ui/display/display_switches.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 30 | #include "ui/display/manager/display_manager.h" |
rjkroege | 259c0188 | 2016-08-30 19:29:50 | [diff] [blame] | 31 | #include "ui/display/manager/managed_display_info.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 32 | #include "ui/display/test/display_manager_test_api.h" |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 33 | #include "ui/message_center/message_center.h" |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 34 | #include "ui/wm/public/activation_client.h" |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 35 | |
| 36 | namespace ash { |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 37 | namespace { |
| 38 | |
| 39 | const float kDegreesToRadians = 3.1415926f / 180.0f; |
jonross | 01d453e | 2015-08-28 15:06:30 | [diff] [blame] | 40 | const float kMeanGravity = -9.8066f; |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 41 | |
rjkroege | 259c0188 | 2016-08-30 19:29:50 | [diff] [blame] | 42 | display::ManagedDisplayInfo CreateDisplayInfo(int64_t id, |
| 43 | const gfx::Rect& bounds) { |
| 44 | display::ManagedDisplayInfo info(id, "dummy", false); |
bruthig | f57a7bba | 2015-04-24 21:19:31 | [diff] [blame] | 45 | info.SetBounds(bounds); |
| 46 | return info; |
| 47 | } |
| 48 | |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 49 | void EnableTabletMode(bool enable) { |
| 50 | Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(enable); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 51 | } |
| 52 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 53 | bool RotationLocked() { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 54 | return Shell::Get()->screen_orientation_controller()->rotation_locked(); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 55 | } |
| 56 | |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 57 | bool UserRotationLocked() { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 58 | return Shell::Get()->screen_orientation_controller()->user_rotation_locked(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 59 | } |
| 60 | |
avi | db567a8a | 2015-12-20 17:07:24 | [diff] [blame] | 61 | void SetDisplayRotationById(int64_t display_id, |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 62 | display::Display::Rotation rotation) { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 63 | Shell::Get()->display_manager()->SetDisplayRotation( |
Miguel Casas | 8f12ad6 | 2018-02-20 15:19:59 | [diff] [blame] | 64 | display_id, rotation, display::Display::RotationSource::USER); |
oshima | 8130b67e | 2015-07-23 16:39:12 | [diff] [blame] | 65 | } |
| 66 | |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 67 | void SetInternalDisplayRotation(display::Display::Rotation rotation) { |
| 68 | SetDisplayRotationById(display::Display::InternalDisplayId(), rotation); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 69 | } |
| 70 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 71 | void TriggerLidUpdate(const gfx::Vector3dF& lid) { |
Steven Bennetts | 368a1c8 | 2019-01-11 20:45:22 | [diff] [blame] | 72 | scoped_refptr<AccelerometerUpdate> update(new AccelerometerUpdate()); |
| 73 | update->Set(ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(), lid.z()); |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 74 | Shell::Get()->screen_orientation_controller()->OnAccelerometerUpdated(update); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 75 | } |
| 76 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 77 | // Shows |child| and adds |child| to |parent|. |
| 78 | void AddWindowAndShow(aura::Window* child, aura::Window* parent) { |
| 79 | child->Show(); |
| 80 | parent->AddChild(child); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 81 | } |
| 82 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 83 | // Adds |child| to |parent| and activates |parent|. |
| 84 | void AddWindowAndActivateParent(aura::Window* child, aura::Window* parent) { |
| 85 | AddWindowAndShow(child, parent); |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 86 | Shell::Get()->activation_client()->ActivateWindow(parent); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 87 | } |
| 88 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 89 | void Lock(aura::Window* window, OrientationLockType orientation_lock) { |
Evan Stade | f553d08 | 2018-10-01 20:02:18 | [diff] [blame] | 90 | Shell::Get()->screen_orientation_controller()->LockOrientationForWindow( |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 91 | window, orientation_lock); |
Evan Stade | f553d08 | 2018-10-01 20:02:18 | [diff] [blame] | 92 | } |
| 93 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 94 | void Unlock(aura::Window* window) { |
Evan Stade | f553d08 | 2018-10-01 20:02:18 | [diff] [blame] | 95 | Shell::Get()->screen_orientation_controller()->UnlockOrientationForWindow( |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 96 | window); |
| 97 | } |
| 98 | |
| 99 | // Creates a window of type WINDOW_TYPE_CONTROL. |
| 100 | std::unique_ptr<aura::Window> CreateControlWindow() { |
| 101 | std::unique_ptr<aura::Window> window = window_factory::NewWindow( |
| 102 | nullptr, aura::client::WindowType::WINDOW_TYPE_CONTROL); |
| 103 | window->Init(ui::LAYER_NOT_DRAWN); |
| 104 | window->set_owned_by_parent(false); |
| 105 | return window; |
Evan Stade | f553d08 | 2018-10-01 20:02:18 | [diff] [blame] | 106 | } |
| 107 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 108 | } // namespace |
| 109 | |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 110 | class ScreenOrientationControllerTest : public AshTestBase { |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 111 | public: |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 112 | ScreenOrientationControllerTest() = default; |
| 113 | ~ScreenOrientationControllerTest() override = default; |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 114 | |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 115 | // AshTestBase: |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 116 | void SetUp() override { |
| 117 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 118 | ::switches::kUseFirstDisplayAsInternal); |
| 119 | AshTestBase::SetUp(); |
| 120 | } |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 121 | |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 122 | protected: |
| 123 | aura::Window* CreateAppWindowInShellWithId(int id) { |
| 124 | aura::Window* window = CreateTestWindowInShellWithId(id); |
varkha | c8621dd | 2017-05-31 19:09:01 | [diff] [blame] | 125 | window->SetProperty(aura::client::kAppType, |
| 126 | static_cast<int>(AppType::CHROME_APP)); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 127 | return window; |
| 128 | } |
| 129 | |
| 130 | void SetSystemRotationLocked(bool rotation_locked) { |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 131 | ScreenOrientationControllerTestApi( |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 132 | Shell::Get()->screen_orientation_controller()) |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 133 | .SetRotationLocked(rotation_locked); |
| 134 | } |
| 135 | |
| 136 | void SetUserRotationLocked(bool rotation_locked) { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 137 | if (Shell::Get()->screen_orientation_controller()->user_rotation_locked() != |
| 138 | rotation_locked) { |
| 139 | Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
Mitsuru Oshima | c6b5111 | 2018-03-19 21:05:29 | [diff] [blame] | 143 | OrientationLockType UserLockedOrientation() const { |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 144 | ScreenOrientationControllerTestApi test_api( |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 145 | Shell::Get()->screen_orientation_controller()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 146 | return test_api.UserLockedOrientation(); |
| 147 | } |
| 148 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 149 | private: |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 150 | DISALLOW_COPY_AND_ASSIGN(ScreenOrientationControllerTest); |
| 151 | }; |
| 152 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 153 | // Tests that a Window can lock rotation. |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 154 | TEST_F(ScreenOrientationControllerTest, LockOrientation) { |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 155 | EnableTabletMode(true); |
| 156 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 157 | std::unique_ptr<aura::Window> child_window = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 158 | std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 159 | ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 160 | ASSERT_FALSE(RotationLocked()); |
| 161 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 162 | AddWindowAndActivateParent(child_window.get(), focus_window.get()); |
| 163 | Lock(child_window.get(), OrientationLockType::kLandscape); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 164 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 165 | EXPECT_TRUE(RotationLocked()); |
| 166 | } |
| 167 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 168 | // Tests that a Window can unlock rotation. |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 169 | TEST_F(ScreenOrientationControllerTest, Unlock) { |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 170 | EnableTabletMode(true); |
| 171 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 172 | std::unique_ptr<aura::Window> child_window = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 173 | std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 174 | ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 175 | ASSERT_FALSE(RotationLocked()); |
| 176 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 177 | AddWindowAndActivateParent(child_window.get(), focus_window.get()); |
| 178 | Lock(child_window.get(), OrientationLockType::kLandscape); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 179 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 180 | EXPECT_TRUE(RotationLocked()); |
| 181 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 182 | Unlock(child_window.get()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 183 | EXPECT_FALSE(RotationLocked()); |
| 184 | } |
| 185 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 186 | // Tests that a Window is able to change the orientation of the display after |
| 187 | // having locked rotation. |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 188 | TEST_F(ScreenOrientationControllerTest, OrientationChanges) { |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 189 | EnableTabletMode(true); |
| 190 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 191 | std::unique_ptr<aura::Window> child_window = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 192 | std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 193 | ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 194 | ASSERT_FALSE(RotationLocked()); |
| 195 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 196 | AddWindowAndActivateParent(child_window.get(), focus_window.get()); |
| 197 | Lock(child_window.get(), OrientationLockType::kPortrait); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 198 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 199 | EXPECT_TRUE(RotationLocked()); |
| 200 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 201 | Lock(child_window.get(), OrientationLockType::kLandscape); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 202 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 203 | } |
| 204 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 205 | // Tests that orientation can only be set by the first Window that has set a |
| 206 | // rotation lock. |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 207 | TEST_F(ScreenOrientationControllerTest, SecondContentCannotChangeOrientation) { |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 208 | EnableTabletMode(true); |
| 209 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 210 | std::unique_ptr<aura::Window> child_window1 = CreateControlWindow(); |
| 211 | std::unique_ptr<aura::Window> child_window2 = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 212 | std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); |
| 213 | std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 214 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 215 | AddWindowAndActivateParent(child_window1.get(), focus_window1.get()); |
| 216 | AddWindowAndShow(child_window2.get(), focus_window2.get()); |
| 217 | Lock(child_window1.get(), OrientationLockType::kLandscape); |
| 218 | Lock(child_window2.get(), OrientationLockType::kPortrait); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 219 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 220 | } |
| 221 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 222 | // Tests that only the Window that set a rotation lock can perform an unlock. |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 223 | TEST_F(ScreenOrientationControllerTest, SecondContentCannotUnlock) { |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 224 | EnableTabletMode(true); |
| 225 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 226 | std::unique_ptr<aura::Window> child_window1 = CreateControlWindow(); |
| 227 | std::unique_ptr<aura::Window> child_window2 = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 228 | std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); |
| 229 | std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 230 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 231 | AddWindowAndActivateParent(child_window1.get(), focus_window1.get()); |
| 232 | AddWindowAndShow(child_window2.get(), focus_window2.get()); |
| 233 | Lock(child_window1.get(), OrientationLockType::kLandscape); |
| 234 | Unlock(child_window2.get()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 235 | EXPECT_TRUE(RotationLocked()); |
| 236 | } |
| 237 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 238 | // Tests that a rotation lock is applied only while the Window are a part of the |
| 239 | // active window. |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 240 | TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateLock) { |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 241 | EnableTabletMode(true); |
| 242 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 243 | std::unique_ptr<aura::Window> child_window = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 244 | std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); |
| 245 | std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 246 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 247 | AddWindowAndActivateParent(child_window.get(), focus_window1.get()); |
| 248 | Lock(child_window.get(), OrientationLockType::kLandscape); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 249 | ASSERT_TRUE(RotationLocked()); |
| 250 | |
Thiago Farina | 3b086a0 | 2017-05-30 22:32:50 | [diff] [blame] | 251 | ::wm::ActivationClient* activation_client = Shell::Get()->activation_client(); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 252 | activation_client->ActivateWindow(focus_window2.get()); |
| 253 | EXPECT_FALSE(RotationLocked()); |
| 254 | |
| 255 | activation_client->ActivateWindow(focus_window1.get()); |
| 256 | EXPECT_TRUE(RotationLocked()); |
| 257 | } |
| 258 | |
| 259 | // Tests that switching between windows with different orientation locks change |
| 260 | // the orientation. |
| 261 | TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) { |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 262 | EnableTabletMode(true); |
| 263 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 264 | std::unique_ptr<aura::Window> child_window1 = CreateControlWindow(); |
| 265 | std::unique_ptr<aura::Window> child_window2 = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 266 | std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); |
| 267 | std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 268 | AddWindowAndActivateParent(child_window1.get(), focus_window1.get()); |
| 269 | AddWindowAndShow(child_window2.get(), focus_window2.get()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 270 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 271 | Lock(child_window1.get(), OrientationLockType::kLandscape); |
| 272 | Lock(child_window2.get(), OrientationLockType::kPortrait); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 273 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 274 | |
Thiago Farina | 3b086a0 | 2017-05-30 22:32:50 | [diff] [blame] | 275 | ::wm::ActivationClient* activation_client = Shell::Get()->activation_client(); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 276 | activation_client->ActivateWindow(focus_window2.get()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 277 | EXPECT_TRUE(RotationLocked()); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 278 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 279 | |
| 280 | activation_client->ActivateWindow(focus_window1.get()); |
| 281 | EXPECT_TRUE(RotationLocked()); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 282 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | // Tests that a rotation lock is removed when the setting window is hidden, and |
| 286 | // that it is reapplied when the window becomes visible. |
| 287 | TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) { |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 288 | EnableTabletMode(true); |
| 289 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 290 | std::unique_ptr<aura::Window> child_window = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 291 | std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 292 | AddWindowAndActivateParent(child_window.get(), focus_window.get()); |
| 293 | Lock(child_window.get(), OrientationLockType::kLandscape); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 294 | EXPECT_TRUE(RotationLocked()); |
| 295 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 296 | child_window->Hide(); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 297 | EXPECT_FALSE(RotationLocked()); |
| 298 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 299 | child_window->Show(); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 300 | EXPECT_TRUE(RotationLocked()); |
| 301 | } |
| 302 | |
| 303 | // Tests that when a window is destroyed that its rotation lock is removed, and |
| 304 | // window activations no longer change the lock |
| 305 | TEST_F(ScreenOrientationControllerTest, WindowDestructionRemovesLock) { |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 306 | EnableTabletMode(true); |
| 307 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 308 | std::unique_ptr<aura::Window> child_window = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 309 | std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); |
| 310 | std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 311 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 312 | AddWindowAndActivateParent(child_window.get(), focus_window1.get()); |
| 313 | Lock(child_window.get(), OrientationLockType::kLandscape); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 314 | ASSERT_TRUE(RotationLocked()); |
| 315 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 316 | focus_window1->RemoveChild(child_window.get()); |
| 317 | child_window.reset(); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 318 | EXPECT_FALSE(RotationLocked()); |
| 319 | |
Thiago Farina | 3b086a0 | 2017-05-30 22:32:50 | [diff] [blame] | 320 | ::wm::ActivationClient* activation_client = Shell::Get()->activation_client(); |
jonross | 31c4a482 | 2015-01-23 15:56:33 | [diff] [blame] | 321 | activation_client->ActivateWindow(focus_window2.get()); |
| 322 | EXPECT_FALSE(RotationLocked()); |
| 323 | |
| 324 | activation_client->ActivateWindow(focus_window1.get()); |
| 325 | EXPECT_FALSE(RotationLocked()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | // Tests that accelerometer readings in each of the screen angles will trigger a |
| 329 | // rotation of the internal display. |
| 330 | TEST_F(ScreenOrientationControllerTest, DisplayRotation) { |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 331 | EnableTabletMode(true); |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 332 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 333 | // Now test rotating in all directions. |
| 334 | TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 335 | EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 336 | TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 337 | EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 338 | TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 339 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 340 | TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 341 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | // Tests that low angles are ignored by the accelerometer (i.e. when the device |
| 345 | // is almost laying flat). |
| 346 | TEST_F(ScreenOrientationControllerTest, RotationIgnoresLowAngles) { |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 347 | EnableTabletMode(true); |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 348 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 349 | TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 350 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 351 | TriggerLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 352 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 353 | TriggerLidUpdate(gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 354 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 355 | TriggerLidUpdate(gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 356 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 357 | TriggerLidUpdate(gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 358 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | // Tests that the display will stick to the current orientation beyond the |
| 362 | // halfway point, preventing frequent updates back and forth. |
| 363 | TEST_F(ScreenOrientationControllerTest, RotationSticky) { |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 364 | EnableTabletMode(true); |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 365 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 366 | gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f); |
| 367 | TriggerLidUpdate(gravity); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 368 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 369 | |
| 370 | // Turn past half-way point to next direction and rotation should remain |
| 371 | // the same. |
| 372 | float degrees = 50.0; |
| 373 | gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); |
| 374 | gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); |
| 375 | TriggerLidUpdate(gravity); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 376 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 377 | |
| 378 | // Turn more and the screen should rotate. |
| 379 | degrees = 70.0; |
| 380 | gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); |
| 381 | gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); |
| 382 | TriggerLidUpdate(gravity); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 383 | EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 384 | |
| 385 | // Turn back just beyond the half-way point and the new rotation should |
| 386 | // still be in effect. |
| 387 | degrees = 40.0; |
| 388 | gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); |
| 389 | gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); |
| 390 | TriggerLidUpdate(gravity); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 391 | EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | // Tests that the display will stick to its current orientation when the |
| 395 | // rotation lock has been set. |
| 396 | TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) { |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 397 | EnableTabletMode(true); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 398 | SetUserRotationLocked(true); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 399 | |
| 400 | // Turn past the threshold for rotation. |
| 401 | float degrees = 90.0; |
| 402 | gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * kMeanGravity, |
| 403 | -cos(degrees * kDegreesToRadians) * kMeanGravity, |
| 404 | 0.0f); |
| 405 | TriggerLidUpdate(gravity); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 406 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 407 | |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 408 | SetUserRotationLocked(false); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 409 | TriggerLidUpdate(gravity); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 410 | EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 411 | } |
| 412 | |
yiyix | a68ade51 | 2016-09-01 17:38:13 | [diff] [blame] | 413 | // The ScreenLayoutObserver class that is responsible for adding/updating |
| 414 | // MessageCenter notifications is only added to the SystemTray on ChromeOS. |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 415 | // Tests that the screen rotation notifications are suppressed when |
| 416 | // triggered by the accelerometer. |
| 417 | TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 418 | EnableTabletMode(true); |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 419 | Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing( |
| 420 | true); |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 421 | display::test::DisplayManagerTestApi(display_manager()) |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 422 | .SetFirstDisplayAsInternalDisplay(); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 423 | |
| 424 | message_center::MessageCenter* message_center = |
| 425 | message_center::MessageCenter::Get(); |
| 426 | |
| 427 | EXPECT_EQ(0u, message_center->NotificationCount()); |
| 428 | EXPECT_FALSE(message_center->HasPopupNotifications()); |
| 429 | |
| 430 | // Make sure notifications are still displayed when |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 431 | // adjusting the screen rotation directly when in tablet mode |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 432 | ASSERT_NE(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
| 433 | SetInternalDisplayRotation(display::Display::ROTATE_270); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 434 | SetSystemRotationLocked(false); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 435 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 436 | EXPECT_EQ(1u, message_center->NotificationCount()); |
| 437 | EXPECT_TRUE(message_center->HasPopupNotifications()); |
| 438 | |
| 439 | // Clear all notifications |
yoshiki | 35c9a3b | 2016-02-25 05:52:13 | [diff] [blame] | 440 | message_center->RemoveAllNotifications( |
| 441 | false /* by_user */, message_center::MessageCenter::RemoveType::ALL); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 442 | EXPECT_EQ(0u, message_center->NotificationCount()); |
| 443 | EXPECT_FALSE(message_center->HasPopupNotifications()); |
| 444 | |
| 445 | // Make sure notifications are blocked when adjusting the screen rotation |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 446 | // via the accelerometer while in tablet mode |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 447 | // Rotate the screen 90 degrees |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 448 | ASSERT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 449 | TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 450 | ASSERT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 451 | EXPECT_EQ(0u, message_center->NotificationCount()); |
| 452 | EXPECT_FALSE(message_center->HasPopupNotifications()); |
| 453 | |
| 454 | // Make sure notifications are still displayed when |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 455 | // adjusting the screen rotation directly when not in tablet mode |
| 456 | EnableTabletMode(false); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 457 | // Reset the screen rotation. |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 458 | SetInternalDisplayRotation(display::Display::ROTATE_0); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 459 | // Clear all notifications |
yoshiki | 35c9a3b | 2016-02-25 05:52:13 | [diff] [blame] | 460 | message_center->RemoveAllNotifications( |
| 461 | false /* by_user */, message_center::MessageCenter::RemoveType::ALL); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 462 | ASSERT_NE(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 463 | ASSERT_EQ(0u, message_center->NotificationCount()); |
| 464 | ASSERT_FALSE(message_center->HasPopupNotifications()); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 465 | SetInternalDisplayRotation(display::Display::ROTATE_180); |
| 466 | EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 467 | EXPECT_EQ(1u, message_center->NotificationCount()); |
| 468 | EXPECT_TRUE(message_center->HasPopupNotifications()); |
| 469 | } |
| 470 | |
| 471 | // Tests that if a user has set a display rotation that it is restored upon |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 472 | // exiting tablet mode. |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 473 | TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) { |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 474 | display::test::DisplayManagerTestApi(display_manager()) |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 475 | .SetFirstDisplayAsInternalDisplay(); |
oshima | 8130b67e | 2015-07-23 16:39:12 | [diff] [blame] | 476 | |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 477 | SetInternalDisplayRotation(display::Display::ROTATE_90); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 478 | EnableTabletMode(true); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 479 | |
| 480 | TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 481 | EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 482 | |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 483 | EnableTabletMode(false); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 484 | EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 485 | } |
| 486 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 487 | // Tests that if a user changes the display rotation, while rotation is locked, |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 488 | // that the updates are recorded. Upon exiting tablet mode the latest user |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 489 | // rotation should be applied. |
| 490 | TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) { |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 491 | EnableTabletMode(true); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 492 | SetInternalDisplayRotation(display::Display::ROTATE_270); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 493 | // User sets rotation to the same rotation that the display was at when |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 494 | // tablet mode was activated. |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 495 | SetInternalDisplayRotation(display::Display::ROTATE_0); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 496 | EnableTabletMode(false); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 497 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 498 | } |
| 499 | |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 500 | // Tests that when the orientation lock is set to Landscape, that rotation can |
| 501 | // be done between the two angles of the orientation. |
| 502 | TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 503 | std::unique_ptr<aura::Window> child_window = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 504 | std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 505 | EnableTabletMode(true); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 506 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 507 | AddWindowAndActivateParent(child_window.get(), focus_window.get()); |
| 508 | Lock(child_window.get(), OrientationLockType::kLandscape); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 509 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 510 | EXPECT_TRUE(RotationLocked()); |
| 511 | |
| 512 | // Inverse of orientation is allowed |
| 513 | TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 514 | EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 515 | |
| 516 | // Display rotations between are not allowed |
| 517 | TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 518 | EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 519 | TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 520 | EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 521 | } |
| 522 | |
Evan Stade | f553d08 | 2018-10-01 20:02:18 | [diff] [blame] | 523 | // Tests that when the orientation lock is set to Portrait, that rotation can be |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 524 | // done between the two angles of the orientation. |
| 525 | TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 526 | std::unique_ptr<aura::Window> child_window = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 527 | std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 528 | EnableTabletMode(true); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 529 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 530 | AddWindowAndActivateParent(child_window.get(), focus_window.get()); |
| 531 | Lock(child_window.get(), OrientationLockType::kPortrait); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 532 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 533 | EXPECT_TRUE(RotationLocked()); |
| 534 | |
| 535 | // Inverse of orientation is allowed |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 536 | TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
| 537 | EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 538 | |
| 539 | // Display rotations between are not allowed |
| 540 | TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 541 | EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 542 | TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 543 | EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | // Tests that for an orientation lock which does not allow rotation, that the |
| 547 | // display rotation remains constant. |
| 548 | TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 549 | std::unique_ptr<aura::Window> child_window = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 550 | std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 551 | EnableTabletMode(true); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 552 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 553 | AddWindowAndActivateParent(child_window.get(), focus_window.get()); |
| 554 | Lock(child_window.get(), OrientationLockType::kPortraitPrimary); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 555 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 556 | EXPECT_TRUE(RotationLocked()); |
| 557 | |
| 558 | // Rotation does not change. |
| 559 | TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 560 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 561 | TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 562 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 563 | TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 564 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 565 | } |
| 566 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 567 | // Tests that after a Window has applied an orientation lock which supports |
| 568 | // rotation, that a user rotation lock does not allow rotation. |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 569 | TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 570 | std::unique_ptr<aura::Window> child_window = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 571 | std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 572 | EnableTabletMode(true); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 573 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 574 | AddWindowAndActivateParent(child_window.get(), focus_window.get()); |
| 575 | Lock(child_window.get(), OrientationLockType::kLandscape); |
| 576 | Unlock(child_window.get()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 577 | |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 578 | SetUserRotationLocked(true); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 579 | EXPECT_TRUE(RotationLocked()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 580 | EXPECT_TRUE(UserRotationLocked()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 581 | |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 582 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 583 | TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 584 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
jonross | 2d2c2fd6 | 2015-02-02 20:58:23 | [diff] [blame] | 585 | } |
| 586 | |
thestig | 259626c | 2015-11-23 20:18:11 | [diff] [blame] | 587 | // Verifies rotating an inactive Display is successful. |
bruthig | f57a7bba | 2015-04-24 21:19:31 | [diff] [blame] | 588 | TEST_F(ScreenOrientationControllerTest, RotateInactiveDisplay) { |
avi | db567a8a | 2015-12-20 17:07:24 | [diff] [blame] | 589 | const int64_t kInternalDisplayId = 9; |
| 590 | const int64_t kExternalDisplayId = 10; |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 591 | const display::Display::Rotation kNewRotation = display::Display::ROTATE_180; |
bruthig | f57a7bba | 2015-04-24 21:19:31 | [diff] [blame] | 592 | |
rjkroege | 259c0188 | 2016-08-30 19:29:50 | [diff] [blame] | 593 | const display::ManagedDisplayInfo internal_display_info = |
bruthig | f57a7bba | 2015-04-24 21:19:31 | [diff] [blame] | 594 | CreateDisplayInfo(kInternalDisplayId, gfx::Rect(0, 0, 500, 500)); |
rjkroege | 259c0188 | 2016-08-30 19:29:50 | [diff] [blame] | 595 | const display::ManagedDisplayInfo external_display_info = |
bruthig | f57a7bba | 2015-04-24 21:19:31 | [diff] [blame] | 596 | CreateDisplayInfo(kExternalDisplayId, gfx::Rect(1, 1, 500, 500)); |
| 597 | |
rjkroege | 259c0188 | 2016-08-30 19:29:50 | [diff] [blame] | 598 | std::vector<display::ManagedDisplayInfo> display_info_list_two_active; |
bruthig | f57a7bba | 2015-04-24 21:19:31 | [diff] [blame] | 599 | display_info_list_two_active.push_back(internal_display_info); |
| 600 | display_info_list_two_active.push_back(external_display_info); |
| 601 | |
rjkroege | 259c0188 | 2016-08-30 19:29:50 | [diff] [blame] | 602 | std::vector<display::ManagedDisplayInfo> display_info_list_one_active; |
bruthig | f57a7bba | 2015-04-24 21:19:31 | [diff] [blame] | 603 | display_info_list_one_active.push_back(external_display_info); |
| 604 | |
rjkroege | 259c0188 | 2016-08-30 19:29:50 | [diff] [blame] | 605 | // The display::ManagedDisplayInfo list with two active displays needs to be |
| 606 | // added first so that the DisplayManager can track the |
| 607 | // |internal_display_info| as inactive instead of non-existent. |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 608 | display_manager()->UpdateDisplaysWith(display_info_list_two_active); |
| 609 | display_manager()->UpdateDisplaysWith(display_info_list_one_active); |
bruthig | f57a7bba | 2015-04-24 21:19:31 | [diff] [blame] | 610 | |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 611 | display::test::ScopedSetInternalDisplayId set_internal(display_manager(), |
| 612 | kInternalDisplayId); |
bruthig | f57a7bba | 2015-04-24 21:19:31 | [diff] [blame] | 613 | |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 614 | ASSERT_NE(kNewRotation, display_manager() |
| 615 | ->GetDisplayInfo(kInternalDisplayId) |
| 616 | .GetActiveRotation()); |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 617 | ScreenOrientationControllerTestApi( |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 618 | Shell::Get()->screen_orientation_controller()) |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 619 | .SetDisplayRotation(kNewRotation, |
Miguel Casas | 8f12ad6 | 2018-02-20 15:19:59 | [diff] [blame] | 620 | display::Display::RotationSource::ACTIVE); |
bruthig | f57a7bba | 2015-04-24 21:19:31 | [diff] [blame] | 621 | |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 622 | EXPECT_EQ(kNewRotation, display_manager() |
| 623 | ->GetDisplayInfo(kInternalDisplayId) |
| 624 | .GetActiveRotation()); |
bruthig | f57a7bba | 2015-04-24 21:19:31 | [diff] [blame] | 625 | } |
| 626 | |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 627 | TEST_F(ScreenOrientationControllerTest, UserRotationLockedOrientation) { |
| 628 | ScreenOrientationController* orientation_controller = |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 629 | Shell::Get()->screen_orientation_controller(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 630 | orientation_controller->ToggleUserRotationLock(); |
| 631 | EXPECT_TRUE(orientation_controller->user_rotation_locked()); |
Mitsuru Oshima | c6b5111 | 2018-03-19 21:05:29 | [diff] [blame] | 632 | EXPECT_EQ(OrientationLockType::kLandscapePrimary, UserLockedOrientation()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 633 | |
| 634 | orientation_controller->ToggleUserRotationLock(); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 635 | SetInternalDisplayRotation(display::Display::ROTATE_270); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 636 | orientation_controller->ToggleUserRotationLock(); |
Mitsuru Oshima | c6b5111 | 2018-03-19 21:05:29 | [diff] [blame] | 637 | EXPECT_EQ(OrientationLockType::kPortraitPrimary, UserLockedOrientation()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 638 | |
| 639 | orientation_controller->ToggleUserRotationLock(); |
| 640 | SetInternalDisplayRotation(display::Display::ROTATE_180); |
| 641 | orientation_controller->ToggleUserRotationLock(); |
Mitsuru Oshima | c6b5111 | 2018-03-19 21:05:29 | [diff] [blame] | 642 | EXPECT_EQ(OrientationLockType::kLandscapeSecondary, UserLockedOrientation()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 643 | |
| 644 | orientation_controller->ToggleUserRotationLock(); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 645 | SetInternalDisplayRotation(display::Display::ROTATE_90); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 646 | orientation_controller->ToggleUserRotationLock(); |
Mitsuru Oshima | c6b5111 | 2018-03-19 21:05:29 | [diff] [blame] | 647 | EXPECT_EQ(OrientationLockType::kPortraitSecondary, UserLockedOrientation()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 648 | orientation_controller->ToggleUserRotationLock(); |
| 649 | |
| 650 | SetInternalDisplayRotation(display::Display::ROTATE_270); |
| 651 | |
| 652 | UpdateDisplay("800x1280"); |
| 653 | orientation_controller->ToggleUserRotationLock(); |
| 654 | EXPECT_TRUE(orientation_controller->user_rotation_locked()); |
Mitsuru Oshima | c6b5111 | 2018-03-19 21:05:29 | [diff] [blame] | 655 | EXPECT_EQ(OrientationLockType::kPortraitPrimary, UserLockedOrientation()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 656 | |
| 657 | orientation_controller->ToggleUserRotationLock(); |
| 658 | SetInternalDisplayRotation(display::Display::ROTATE_90); |
| 659 | orientation_controller->ToggleUserRotationLock(); |
Mitsuru Oshima | c6b5111 | 2018-03-19 21:05:29 | [diff] [blame] | 660 | EXPECT_EQ(OrientationLockType::kLandscapePrimary, UserLockedOrientation()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 661 | |
| 662 | orientation_controller->ToggleUserRotationLock(); |
| 663 | SetInternalDisplayRotation(display::Display::ROTATE_180); |
| 664 | orientation_controller->ToggleUserRotationLock(); |
Mitsuru Oshima | c6b5111 | 2018-03-19 21:05:29 | [diff] [blame] | 665 | EXPECT_EQ(OrientationLockType::kPortraitSecondary, UserLockedOrientation()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 666 | |
| 667 | orientation_controller->ToggleUserRotationLock(); |
| 668 | SetInternalDisplayRotation(display::Display::ROTATE_270); |
| 669 | orientation_controller->ToggleUserRotationLock(); |
Mitsuru Oshima | c6b5111 | 2018-03-19 21:05:29 | [diff] [blame] | 670 | EXPECT_EQ(OrientationLockType::kLandscapeSecondary, UserLockedOrientation()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 671 | orientation_controller->ToggleUserRotationLock(); |
| 672 | } |
| 673 | |
| 674 | TEST_F(ScreenOrientationControllerTest, UserRotationLock) { |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 675 | EnableTabletMode(true); |
| 676 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 677 | std::unique_ptr<aura::Window> child_window1 = CreateControlWindow(); |
| 678 | std::unique_ptr<aura::Window> child_window2 = CreateControlWindow(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 679 | std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); |
| 680 | std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 681 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 682 | AddWindowAndActivateParent(child_window2.get(), focus_window2.get()); |
| 683 | AddWindowAndActivateParent(child_window1.get(), focus_window1.get()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 684 | |
| 685 | ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 686 | ASSERT_FALSE(RotationLocked()); |
| 687 | ASSERT_FALSE(UserRotationLocked()); |
| 688 | |
| 689 | ScreenOrientationController* orientation_controller = |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 690 | Shell::Get()->screen_orientation_controller(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 691 | ASSERT_FALSE(orientation_controller->user_rotation_locked()); |
| 692 | orientation_controller->ToggleUserRotationLock(); |
| 693 | ASSERT_TRUE(orientation_controller->user_rotation_locked()); |
| 694 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 695 | Lock(child_window1.get(), OrientationLockType::kPortrait); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 696 | |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 697 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 698 | |
Thiago Farina | 3b086a0 | 2017-05-30 22:32:50 | [diff] [blame] | 699 | ::wm::ActivationClient* activation_client = Shell::Get()->activation_client(); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 700 | // Activating any will switch to the natural orientation. |
| 701 | activation_client->ActivateWindow(focus_window2.get()); |
| 702 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 703 | |
| 704 | // Activating the portrait window will rotate to the portrait. |
| 705 | activation_client->ActivateWindow(focus_window1.get()); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 706 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 707 | |
| 708 | // User locked to the 90 dig. |
| 709 | orientation_controller->ToggleUserRotationLock(); |
| 710 | orientation_controller->ToggleUserRotationLock(); |
| 711 | |
| 712 | // Switching to Any orientation will stay to the user locked orientation. |
| 713 | activation_client->ActivateWindow(focus_window2.get()); |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 714 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 715 | |
| 716 | // Application forced to be landscape. |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 717 | Lock(child_window2.get(), OrientationLockType::kLandscape); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 718 | EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 719 | |
Scott Violet | 8d5bc4e | 2018-12-18 01:48:01 | [diff] [blame] | 720 | Lock(child_window1.get(), OrientationLockType::kAny); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 721 | activation_client->ActivateWindow(focus_window1.get()); |
| 722 | // Switching back to any will rotate to user rotation. |
Mitsuru Oshima | 162e929b | 2018-01-23 16:56:27 | [diff] [blame] | 723 | EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
oshima | a5176fd7 | 2017-03-24 00:09:05 | [diff] [blame] | 724 | } |
| 725 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 726 | } // namespace ash |