OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/display/screen_orientation_controller_chromeos.h" | 5 #include "ash/display/screen_orientation_controller_chromeos.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/common/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
11 #include "ash/common/test/test_system_tray_delegate.h" | 11 #include "ash/common/test/test_system_tray_delegate.h" |
12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 13 #include "ash/common/wm/window_state.h" |
13 #include "ash/common/wm_shell.h" | 14 #include "ash/common/wm_shell.h" |
| 15 #include "ash/common/wm_window.h" |
14 #include "ash/content/shell_content_state.h" | 16 #include "ash/content/shell_content_state.h" |
| 17 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 18 #include "ash/shared/app_types.h" |
15 #include "ash/shell.h" | 19 #include "ash/shell.h" |
16 #include "ash/system/chromeos/screen_layout_observer.h" | 20 #include "ash/system/chromeos/screen_layout_observer.h" |
17 #include "ash/test/ash_test_base.h" | 21 #include "ash/test/ash_test_base.h" |
18 #include "ash/test/ash_test_environment_content.h" | 22 #include "ash/test/ash_test_environment_content.h" |
19 #include "ash/test/ash_test_helper.h" | 23 #include "ash/test/ash_test_helper.h" |
20 #include "ash/test/content/test_shell_content_state.h" | 24 #include "ash/test/content/test_shell_content_state.h" |
| 25 #include "ash/test/screen_orientation_controller_test_api.h" |
21 #include "ash/test/test_shell_delegate.h" | 26 #include "ash/test/test_shell_delegate.h" |
22 #include "base/command_line.h" | 27 #include "base/command_line.h" |
23 #include "chromeos/accelerometer/accelerometer_reader.h" | 28 #include "chromeos/accelerometer/accelerometer_reader.h" |
24 #include "chromeos/accelerometer/accelerometer_types.h" | 29 #include "chromeos/accelerometer/accelerometer_types.h" |
25 #include "content/public/browser/browser_context.h" | 30 #include "content/public/browser/browser_context.h" |
26 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
27 #include "content/public/test/test_browser_context.h" | 32 #include "content/public/test/test_browser_context.h" |
28 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" | 33 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" |
29 #include "ui/aura/window.h" | 34 #include "ui/aura/window.h" |
30 #include "ui/display/display.h" | 35 #include "ui/display/display.h" |
(...skipping 25 matching lines...) Expand all Loading... |
56 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 61 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
57 enable); | 62 enable); |
58 } | 63 } |
59 | 64 |
60 bool RotationLocked() { | 65 bool RotationLocked() { |
61 return Shell::GetInstance() | 66 return Shell::GetInstance() |
62 ->screen_orientation_controller() | 67 ->screen_orientation_controller() |
63 ->rotation_locked(); | 68 ->rotation_locked(); |
64 } | 69 } |
65 | 70 |
| 71 bool UserRotationLocked() { |
| 72 return Shell::GetInstance() |
| 73 ->screen_orientation_controller() |
| 74 ->user_rotation_locked(); |
| 75 } |
| 76 |
66 void SetDisplayRotationById(int64_t display_id, | 77 void SetDisplayRotationById(int64_t display_id, |
67 display::Display::Rotation rotation) { | 78 display::Display::Rotation rotation) { |
68 Shell::GetInstance()->display_manager()->SetDisplayRotation( | 79 Shell::GetInstance()->display_manager()->SetDisplayRotation( |
69 display_id, rotation, display::Display::ROTATION_SOURCE_USER); | 80 display_id, rotation, display::Display::ROTATION_SOURCE_USER); |
70 } | 81 } |
71 | 82 |
72 void SetInternalDisplayRotation(display::Display::Rotation rotation) { | 83 void SetInternalDisplayRotation(display::Display::Rotation rotation) { |
73 SetDisplayRotationById(display::Display::InternalDisplayId(), rotation); | 84 SetDisplayRotationById(display::Display::InternalDisplayId(), rotation); |
74 } | 85 } |
75 | 86 |
76 void SetRotationLocked(bool rotation_locked) { | |
77 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( | |
78 rotation_locked); | |
79 } | |
80 | |
81 void TriggerLidUpdate(const gfx::Vector3dF& lid) { | 87 void TriggerLidUpdate(const gfx::Vector3dF& lid) { |
82 scoped_refptr<chromeos::AccelerometerUpdate> update( | 88 scoped_refptr<chromeos::AccelerometerUpdate> update( |
83 new chromeos::AccelerometerUpdate()); | 89 new chromeos::AccelerometerUpdate()); |
84 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(), lid.z()); | 90 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(), lid.z()); |
85 Shell::GetInstance()->screen_orientation_controller()->OnAccelerometerUpdated( | 91 Shell::GetInstance()->screen_orientation_controller()->OnAccelerometerUpdated( |
86 update); | 92 update); |
87 } | 93 } |
88 | 94 |
89 // Attaches the NativeView of |web_contents| to |parent| without changing the | 95 // Attaches the NativeView of |web_contents| to |parent| without changing the |
90 // currently active window. | 96 // currently active window. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // content::BrowserContext and that has an aura::Window. | 128 // content::BrowserContext and that has an aura::Window. |
123 content::WebContents* CreateWebContents(); | 129 content::WebContents* CreateWebContents(); |
124 | 130 |
125 // Creates a secondary content::WebContents, with a separate | 131 // Creates a secondary content::WebContents, with a separate |
126 // content::BrowserContext. | 132 // content::BrowserContext. |
127 content::WebContents* CreateSecondaryWebContents(); | 133 content::WebContents* CreateSecondaryWebContents(); |
128 | 134 |
129 // test::AshTestBase: | 135 // test::AshTestBase: |
130 void SetUp() override; | 136 void SetUp() override; |
131 | 137 |
| 138 protected: |
| 139 aura::Window* CreateAppWindowInShellWithId(int id) { |
| 140 aura::Window* window = CreateTestWindowInShellWithId(id); |
| 141 WmWindow::Get(window)->SetAppType(static_cast<int>(AppType::CHROME_APP)); |
| 142 return window; |
| 143 } |
| 144 |
| 145 void SetSystemRotationLocked(bool rotation_locked) { |
| 146 test::ScreenOrientationControllerTestApi( |
| 147 Shell::GetInstance()->screen_orientation_controller()) |
| 148 .SetRotationLocked(rotation_locked); |
| 149 } |
| 150 |
| 151 void SetUserRotationLocked(bool rotation_locked) { |
| 152 if (Shell::GetInstance() |
| 153 ->screen_orientation_controller() |
| 154 ->user_rotation_locked() != rotation_locked) { |
| 155 Shell::GetInstance() |
| 156 ->screen_orientation_controller() |
| 157 ->ToggleUserRotationLock(); |
| 158 } |
| 159 } |
| 160 |
| 161 blink::WebScreenOrientationLockType UserLockedOrientation() const { |
| 162 test::ScreenOrientationControllerTestApi test_api( |
| 163 Shell::GetInstance()->screen_orientation_controller()); |
| 164 return test_api.UserLockedOrientation(); |
| 165 } |
| 166 |
132 private: | 167 private: |
133 // Optional content::BrowserContext used for two window tests. | 168 // Optional content::BrowserContext used for two window tests. |
134 std::unique_ptr<content::BrowserContext> secondary_browser_context_; | 169 std::unique_ptr<content::BrowserContext> secondary_browser_context_; |
135 | 170 |
136 // Setups underlying content layer so that content::WebContents can be | 171 // Setups underlying content layer so that content::WebContents can be |
137 // generated. | 172 // generated. |
138 std::unique_ptr<views::WebViewTestHelper> webview_test_helper_; | 173 std::unique_ptr<views::WebViewTestHelper> webview_test_helper_; |
139 | 174 |
140 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationControllerTest); | 175 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationControllerTest); |
141 }; | 176 }; |
(...skipping 18 matching lines...) Expand all Loading... |
160 | 195 |
161 void ScreenOrientationControllerTest::SetUp() { | 196 void ScreenOrientationControllerTest::SetUp() { |
162 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 197 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
163 ::switches::kUseFirstDisplayAsInternal); | 198 ::switches::kUseFirstDisplayAsInternal); |
164 test::AshTestBase::SetUp(); | 199 test::AshTestBase::SetUp(); |
165 } | 200 } |
166 | 201 |
167 // Tests that a content::WebContents can lock rotation. | 202 // Tests that a content::WebContents can lock rotation. |
168 TEST_F(ScreenOrientationControllerTest, LockOrientation) { | 203 TEST_F(ScreenOrientationControllerTest, LockOrientation) { |
169 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 204 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
170 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 205 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
171 ASSERT_NE(nullptr, content->GetNativeView()); | 206 ASSERT_NE(nullptr, content->GetNativeView()); |
172 ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 207 ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
173 ASSERT_FALSE(RotationLocked()); | 208 ASSERT_FALSE(RotationLocked()); |
174 | 209 |
175 AttachAndActivateWebContents(content.get(), focus_window.get()); | 210 AttachAndActivateWebContents(content.get(), focus_window.get()); |
176 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 211 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
177 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 212 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
178 EXPECT_TRUE(RotationLocked()); | 213 EXPECT_TRUE(RotationLocked()); |
179 } | 214 } |
180 | 215 |
181 // Tests that a content::WebContents can unlock rotation. | 216 // Tests that a content::WebContents can unlock rotation. |
182 TEST_F(ScreenOrientationControllerTest, Unlock) { | 217 TEST_F(ScreenOrientationControllerTest, Unlock) { |
183 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 218 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
184 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 219 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
185 ASSERT_NE(nullptr, content->GetNativeView()); | 220 ASSERT_NE(nullptr, content->GetNativeView()); |
186 ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 221 ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
187 ASSERT_FALSE(RotationLocked()); | 222 ASSERT_FALSE(RotationLocked()); |
188 | 223 |
189 AttachAndActivateWebContents(content.get(), focus_window.get()); | 224 AttachAndActivateWebContents(content.get(), focus_window.get()); |
190 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 225 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
191 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 226 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
192 EXPECT_TRUE(RotationLocked()); | 227 EXPECT_TRUE(RotationLocked()); |
193 | 228 |
194 delegate()->Unlock(content.get()); | 229 delegate()->Unlock(content.get()); |
195 EXPECT_FALSE(RotationLocked()); | 230 EXPECT_FALSE(RotationLocked()); |
196 } | 231 } |
197 | 232 |
198 // Tests that a content::WebContents is able to change the orientation of the | 233 // Tests that a content::WebContents is able to change the orientation of the |
199 // display after having locked rotation. | 234 // display after having locked rotation. |
200 TEST_F(ScreenOrientationControllerTest, OrientationChanges) { | 235 TEST_F(ScreenOrientationControllerTest, OrientationChanges) { |
201 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 236 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
202 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 237 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
203 ASSERT_NE(nullptr, content->GetNativeView()); | 238 ASSERT_NE(nullptr, content->GetNativeView()); |
204 ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 239 ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
205 ASSERT_FALSE(RotationLocked()); | 240 ASSERT_FALSE(RotationLocked()); |
206 | 241 |
207 AttachAndActivateWebContents(content.get(), focus_window.get()); | 242 AttachAndActivateWebContents(content.get(), focus_window.get()); |
208 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); | 243 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); |
209 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 244 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
210 EXPECT_TRUE(RotationLocked()); | 245 EXPECT_TRUE(RotationLocked()); |
211 | 246 |
212 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 247 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
213 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 248 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
214 } | 249 } |
215 | 250 |
216 // Tests that orientation can only be set by the first content::WebContents that | 251 // Tests that orientation can only be set by the first content::WebContents that |
217 // has set a rotation lock. | 252 // has set a rotation lock. |
218 TEST_F(ScreenOrientationControllerTest, SecondContentCannotChangeOrientation) { | 253 TEST_F(ScreenOrientationControllerTest, SecondContentCannotChangeOrientation) { |
219 std::unique_ptr<content::WebContents> content1(CreateWebContents()); | 254 std::unique_ptr<content::WebContents> content1(CreateWebContents()); |
220 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); | 255 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); |
221 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); | 256 std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); |
222 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); | 257 std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); |
223 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); | 258 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); |
224 | 259 |
225 AttachAndActivateWebContents(content1.get(), focus_window1.get()); | 260 AttachAndActivateWebContents(content1.get(), focus_window1.get()); |
226 AttachWebContents(content2.get(), focus_window2.get()); | 261 AttachWebContents(content2.get(), focus_window2.get()); |
227 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); | 262 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); |
228 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); | 263 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); |
229 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 264 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
230 } | 265 } |
231 | 266 |
232 // Tests that only the content::WebContents that set a rotation lock can perform | 267 // Tests that only the content::WebContents that set a rotation lock can perform |
233 // an unlock. | 268 // an unlock. |
234 TEST_F(ScreenOrientationControllerTest, SecondContentCannotUnlock) { | 269 TEST_F(ScreenOrientationControllerTest, SecondContentCannotUnlock) { |
235 std::unique_ptr<content::WebContents> content1(CreateWebContents()); | 270 std::unique_ptr<content::WebContents> content1(CreateWebContents()); |
236 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); | 271 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); |
237 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); | 272 std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); |
238 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); | 273 std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); |
239 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); | 274 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); |
240 | 275 |
241 AttachAndActivateWebContents(content1.get(), focus_window1.get()); | 276 AttachAndActivateWebContents(content1.get(), focus_window1.get()); |
242 AttachWebContents(content2.get(), focus_window2.get()); | 277 AttachWebContents(content2.get(), focus_window2.get()); |
243 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); | 278 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); |
244 delegate()->Unlock(content2.get()); | 279 delegate()->Unlock(content2.get()); |
245 EXPECT_TRUE(RotationLocked()); | 280 EXPECT_TRUE(RotationLocked()); |
246 } | 281 } |
247 | 282 |
248 // Tests that a rotation lock is applied only while the content::WebContents are | 283 // Tests that a rotation lock is applied only while the content::WebContents are |
249 // a part of the active window. | 284 // a part of the active window. |
250 TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateLock) { | 285 TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateLock) { |
251 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 286 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
252 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); | 287 std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); |
253 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); | 288 std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); |
254 | 289 |
255 AttachAndActivateWebContents(content.get(), focus_window1.get()); | 290 AttachAndActivateWebContents(content.get(), focus_window1.get()); |
256 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 291 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
257 ASSERT_TRUE(RotationLocked()); | 292 ASSERT_TRUE(RotationLocked()); |
258 | 293 |
259 aura::client::ActivationClient* activation_client = | 294 aura::client::ActivationClient* activation_client = |
260 Shell::GetInstance()->activation_client(); | 295 Shell::GetInstance()->activation_client(); |
261 activation_client->ActivateWindow(focus_window2.get()); | 296 activation_client->ActivateWindow(focus_window2.get()); |
262 EXPECT_FALSE(RotationLocked()); | 297 EXPECT_FALSE(RotationLocked()); |
263 | 298 |
264 activation_client->ActivateWindow(focus_window1.get()); | 299 activation_client->ActivateWindow(focus_window1.get()); |
265 EXPECT_TRUE(RotationLocked()); | 300 EXPECT_TRUE(RotationLocked()); |
266 } | 301 } |
267 | 302 |
268 // Tests that switching between windows with different orientation locks change | 303 // Tests that switching between windows with different orientation locks change |
269 // the orientation. | 304 // the orientation. |
270 TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) { | 305 TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) { |
271 std::unique_ptr<content::WebContents> content1(CreateWebContents()); | 306 std::unique_ptr<content::WebContents> content1(CreateWebContents()); |
272 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); | 307 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); |
273 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); | 308 std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); |
274 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); | 309 std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); |
275 AttachAndActivateWebContents(content1.get(), focus_window1.get()); | 310 AttachAndActivateWebContents(content1.get(), focus_window1.get()); |
276 AttachWebContents(content2.get(), focus_window2.get()); | 311 AttachWebContents(content2.get(), focus_window2.get()); |
277 | 312 |
278 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); | 313 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); |
279 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); | 314 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); |
280 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 315 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
281 | 316 |
282 aura::client::ActivationClient* activation_client = | 317 aura::client::ActivationClient* activation_client = |
283 Shell::GetInstance()->activation_client(); | 318 Shell::GetInstance()->activation_client(); |
284 activation_client->ActivateWindow(focus_window2.get()); | 319 activation_client->ActivateWindow(focus_window2.get()); |
285 EXPECT_TRUE(RotationLocked()); | 320 EXPECT_TRUE(RotationLocked()); |
286 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 321 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
287 | 322 |
288 activation_client->ActivateWindow(focus_window1.get()); | 323 activation_client->ActivateWindow(focus_window1.get()); |
289 EXPECT_TRUE(RotationLocked()); | 324 EXPECT_TRUE(RotationLocked()); |
290 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 325 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
291 } | 326 } |
292 | 327 |
293 // Tests that a rotation lock is removed when the setting window is hidden, and | 328 // Tests that a rotation lock is removed when the setting window is hidden, and |
294 // that it is reapplied when the window becomes visible. | 329 // that it is reapplied when the window becomes visible. |
295 TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) { | 330 TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) { |
296 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 331 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
297 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 332 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
298 AttachAndActivateWebContents(content.get(), focus_window.get()); | 333 AttachAndActivateWebContents(content.get(), focus_window.get()); |
299 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 334 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
300 EXPECT_TRUE(RotationLocked()); | 335 EXPECT_TRUE(RotationLocked()); |
301 | 336 |
302 aura::Window* window = content->GetNativeView(); | 337 aura::Window* window = content->GetNativeView(); |
303 window->Hide(); | 338 window->Hide(); |
304 EXPECT_FALSE(RotationLocked()); | 339 EXPECT_FALSE(RotationLocked()); |
305 | 340 |
306 window->Show(); | 341 window->Show(); |
307 EXPECT_TRUE(RotationLocked()); | 342 EXPECT_TRUE(RotationLocked()); |
308 } | 343 } |
309 | 344 |
310 // Tests that when a window is destroyed that its rotation lock is removed, and | 345 // Tests that when a window is destroyed that its rotation lock is removed, and |
311 // window activations no longer change the lock | 346 // window activations no longer change the lock |
312 TEST_F(ScreenOrientationControllerTest, WindowDestructionRemovesLock) { | 347 TEST_F(ScreenOrientationControllerTest, WindowDestructionRemovesLock) { |
313 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 348 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
314 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); | 349 std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); |
315 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); | 350 std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); |
316 | 351 |
317 AttachAndActivateWebContents(content.get(), focus_window1.get()); | 352 AttachAndActivateWebContents(content.get(), focus_window1.get()); |
318 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 353 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
319 ASSERT_TRUE(RotationLocked()); | 354 ASSERT_TRUE(RotationLocked()); |
320 | 355 |
321 focus_window1->RemoveChild(content->GetNativeView()); | 356 focus_window1->RemoveChild(content->GetNativeView()); |
322 content.reset(); | 357 content.reset(); |
323 EXPECT_FALSE(RotationLocked()); | 358 EXPECT_FALSE(RotationLocked()); |
324 | 359 |
325 aura::client::ActivationClient* activation_client = | 360 aura::client::ActivationClient* activation_client = |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); | 426 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); |
392 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); | 427 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); |
393 TriggerLidUpdate(gravity); | 428 TriggerLidUpdate(gravity); |
394 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 429 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
395 } | 430 } |
396 | 431 |
397 // Tests that the display will stick to its current orientation when the | 432 // Tests that the display will stick to its current orientation when the |
398 // rotation lock has been set. | 433 // rotation lock has been set. |
399 TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) { | 434 TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) { |
400 EnableMaximizeMode(true); | 435 EnableMaximizeMode(true); |
401 SetRotationLocked(true); | 436 SetUserRotationLocked(true); |
402 | 437 |
403 // Turn past the threshold for rotation. | 438 // Turn past the threshold for rotation. |
404 float degrees = 90.0; | 439 float degrees = 90.0; |
405 gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * kMeanGravity, | 440 gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * kMeanGravity, |
406 -cos(degrees * kDegreesToRadians) * kMeanGravity, | 441 -cos(degrees * kDegreesToRadians) * kMeanGravity, |
407 0.0f); | 442 0.0f); |
408 TriggerLidUpdate(gravity); | 443 TriggerLidUpdate(gravity); |
409 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 444 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
410 | 445 |
411 SetRotationLocked(false); | 446 SetUserRotationLocked(false); |
412 TriggerLidUpdate(gravity); | 447 TriggerLidUpdate(gravity); |
413 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 448 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
414 } | 449 } |
415 | 450 |
416 // The ScreenLayoutObserver class that is responsible for adding/updating | 451 // The ScreenLayoutObserver class that is responsible for adding/updating |
417 // MessageCenter notifications is only added to the SystemTray on ChromeOS. | 452 // MessageCenter notifications is only added to the SystemTray on ChromeOS. |
418 // Tests that the screen rotation notifications are suppressed when | 453 // Tests that the screen rotation notifications are suppressed when |
419 // triggered by the accelerometer. | 454 // triggered by the accelerometer. |
420 TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { | 455 TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { |
421 EnableMaximizeMode(true); | 456 EnableMaximizeMode(true); |
422 Shell::GetInstance() | 457 Shell::GetInstance() |
423 ->screen_layout_observer() | 458 ->screen_layout_observer() |
424 ->set_show_notifications_for_testing(true); | 459 ->set_show_notifications_for_testing(true); |
425 display::test::DisplayManagerTestApi(display_manager()) | 460 display::test::DisplayManagerTestApi(display_manager()) |
426 .SetFirstDisplayAsInternalDisplay(); | 461 .SetFirstDisplayAsInternalDisplay(); |
427 | 462 |
428 message_center::MessageCenter* message_center = | 463 message_center::MessageCenter* message_center = |
429 message_center::MessageCenter::Get(); | 464 message_center::MessageCenter::Get(); |
430 | 465 |
431 EXPECT_EQ(0u, message_center->NotificationCount()); | 466 EXPECT_EQ(0u, message_center->NotificationCount()); |
432 EXPECT_FALSE(message_center->HasPopupNotifications()); | 467 EXPECT_FALSE(message_center->HasPopupNotifications()); |
433 | 468 |
434 // Make sure notifications are still displayed when | 469 // Make sure notifications are still displayed when |
435 // adjusting the screen rotation directly when in maximize mode | 470 // adjusting the screen rotation directly when in maximize mode |
436 ASSERT_NE(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 471 ASSERT_NE(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
437 SetInternalDisplayRotation(display::Display::ROTATE_270); | 472 SetInternalDisplayRotation(display::Display::ROTATE_270); |
438 SetRotationLocked(false); | 473 SetSystemRotationLocked(false); |
439 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 474 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
440 EXPECT_EQ(1u, message_center->NotificationCount()); | 475 EXPECT_EQ(1u, message_center->NotificationCount()); |
441 EXPECT_TRUE(message_center->HasPopupNotifications()); | 476 EXPECT_TRUE(message_center->HasPopupNotifications()); |
442 | 477 |
443 // Clear all notifications | 478 // Clear all notifications |
444 message_center->RemoveAllNotifications( | 479 message_center->RemoveAllNotifications( |
445 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); | 480 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); |
446 EXPECT_EQ(0u, message_center->NotificationCount()); | 481 EXPECT_EQ(0u, message_center->NotificationCount()); |
447 EXPECT_FALSE(message_center->HasPopupNotifications()); | 482 EXPECT_FALSE(message_center->HasPopupNotifications()); |
448 | 483 |
449 // Make sure notifications are blocked when adjusting the screen rotation | 484 // Make sure notifications are blocked when adjusting the screen rotation |
450 // via the accelerometer while in maximize mode | 485 // via the accelerometer while in maximize mode |
451 // Rotate the screen 90 degrees | 486 // Rotate the screen 90 degrees |
452 ASSERT_NE(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 487 ASSERT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
453 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); | 488 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
454 ASSERT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 489 ASSERT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
455 EXPECT_EQ(0u, message_center->NotificationCount()); | 490 EXPECT_EQ(0u, message_center->NotificationCount()); |
456 EXPECT_FALSE(message_center->HasPopupNotifications()); | 491 EXPECT_FALSE(message_center->HasPopupNotifications()); |
457 | 492 |
458 // Make sure notifications are still displayed when | 493 // Make sure notifications are still displayed when |
459 // adjusting the screen rotation directly when not in maximize mode | 494 // adjusting the screen rotation directly when not in maximize mode |
460 EnableMaximizeMode(false); | 495 EnableMaximizeMode(false); |
461 // Reset the screen rotation. | 496 // Reset the screen rotation. |
462 SetInternalDisplayRotation(display::Display::ROTATE_0); | 497 SetInternalDisplayRotation(display::Display::ROTATE_0); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 // maximize mode was activated. | 543 // maximize mode was activated. |
509 SetInternalDisplayRotation(display::Display::ROTATE_0); | 544 SetInternalDisplayRotation(display::Display::ROTATE_0); |
510 EnableMaximizeMode(false); | 545 EnableMaximizeMode(false); |
511 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 546 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
512 } | 547 } |
513 | 548 |
514 // Tests that when the orientation lock is set to Landscape, that rotation can | 549 // Tests that when the orientation lock is set to Landscape, that rotation can |
515 // be done between the two angles of the orientation. | 550 // be done between the two angles of the orientation. |
516 TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { | 551 TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { |
517 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 552 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
518 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 553 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
519 EnableMaximizeMode(true); | 554 EnableMaximizeMode(true); |
520 | 555 |
521 AttachAndActivateWebContents(content.get(), focus_window.get()); | 556 AttachAndActivateWebContents(content.get(), focus_window.get()); |
522 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 557 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
523 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 558 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
524 EXPECT_TRUE(RotationLocked()); | 559 EXPECT_TRUE(RotationLocked()); |
525 | 560 |
526 // Inverse of orientation is allowed | 561 // Inverse of orientation is allowed |
527 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 562 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
528 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 563 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
529 | 564 |
530 // Display rotations between are not allowed | 565 // Display rotations between are not allowed |
531 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); | 566 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
532 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 567 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
533 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); | 568 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
534 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 569 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
535 } | 570 } |
536 | 571 |
537 // Tests that when the orientation lock is set to Portrait, that rotaiton can be | 572 // Tests that when the orientation lock is set to Portrait, that rotaiton can be |
538 // done between the two angles of the orientation. | 573 // done between the two angles of the orientation. |
539 TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { | 574 TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { |
540 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 575 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
541 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 576 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
542 EnableMaximizeMode(true); | 577 EnableMaximizeMode(true); |
543 | 578 |
544 AttachAndActivateWebContents(content.get(), focus_window.get()); | 579 AttachAndActivateWebContents(content.get(), focus_window.get()); |
545 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); | 580 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); |
546 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 581 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
547 EXPECT_TRUE(RotationLocked()); | 582 EXPECT_TRUE(RotationLocked()); |
548 | 583 |
549 // Inverse of orientation is allowed | 584 // Inverse of orientation is allowed |
550 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); | 585 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
551 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 586 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
552 | 587 |
553 // Display rotations between are not allowed | 588 // Display rotations between are not allowed |
554 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 589 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
555 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 590 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
556 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 591 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
557 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 592 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
558 } | 593 } |
559 | 594 |
560 // Tests that for an orientation lock which does not allow rotation, that the | 595 // Tests that for an orientation lock which does not allow rotation, that the |
561 // display rotation remains constant. | 596 // display rotation remains constant. |
562 TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { | 597 TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { |
563 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 598 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
564 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 599 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
565 EnableMaximizeMode(true); | 600 EnableMaximizeMode(true); |
566 | 601 |
567 AttachAndActivateWebContents(content.get(), focus_window.get()); | 602 AttachAndActivateWebContents(content.get(), focus_window.get()); |
568 delegate()->Lock(content.get(), | 603 delegate()->Lock(content.get(), |
569 blink::WebScreenOrientationLockPortraitPrimary); | 604 blink::WebScreenOrientationLockPortraitPrimary); |
570 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 605 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
571 EXPECT_TRUE(RotationLocked()); | 606 EXPECT_TRUE(RotationLocked()); |
572 | 607 |
573 // Rotation does not change. | 608 // Rotation does not change. |
574 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); | 609 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
575 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 610 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
576 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 611 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
577 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 612 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
578 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 613 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
579 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 614 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
580 } | 615 } |
581 | 616 |
582 // Tests that after a content::WebContents has applied an orientation lock which | 617 // Tests that after a content::WebContents has applied an orientation lock which |
583 // supports rotation, that a user rotation lock does not allow rotation. | 618 // supports rotation, that a user rotation lock does not allow rotation. |
584 TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { | 619 TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { |
585 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 620 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
586 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 621 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
587 EnableMaximizeMode(true); | 622 EnableMaximizeMode(true); |
588 | 623 |
589 AttachAndActivateWebContents(content.get(), focus_window.get()); | 624 AttachAndActivateWebContents(content.get(), focus_window.get()); |
590 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 625 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
591 delegate()->Unlock(content.get()); | 626 delegate()->Unlock(content.get()); |
592 | 627 |
593 SetRotationLocked(true); | 628 SetUserRotationLocked(true); |
594 EXPECT_TRUE(RotationLocked()); | 629 EXPECT_TRUE(RotationLocked()); |
| 630 EXPECT_TRUE(UserRotationLocked()); |
| 631 |
595 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 632 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
596 | |
597 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 633 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
598 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 634 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
599 } | 635 } |
600 | 636 |
601 // Tests that when MaximizeMode is triggered before the internal display is | 637 // Tests that when MaximizeMode is triggered before the internal display is |
602 // ready, that ScreenOrientationController still begins listening to events, | 638 // ready, that ScreenOrientationController still begins listening to events, |
603 // which require an internal display to be acted upon. | 639 // which require an internal display to be acted upon. |
604 TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) { | 640 TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) { |
605 display::test::DisplayManagerTestApi(display_manager()) | 641 display::test::DisplayManagerTestApi(display_manager()) |
606 .SetFirstDisplayAsInternalDisplay(); | 642 .SetFirstDisplayAsInternalDisplay(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 // |internal_display_info| as inactive instead of non-existent. | 684 // |internal_display_info| as inactive instead of non-existent. |
649 display_manager()->UpdateDisplaysWith(display_info_list_two_active); | 685 display_manager()->UpdateDisplaysWith(display_info_list_two_active); |
650 display_manager()->UpdateDisplaysWith(display_info_list_one_active); | 686 display_manager()->UpdateDisplaysWith(display_info_list_one_active); |
651 | 687 |
652 display::test::ScopedSetInternalDisplayId set_internal(display_manager(), | 688 display::test::ScopedSetInternalDisplayId set_internal(display_manager(), |
653 kInternalDisplayId); | 689 kInternalDisplayId); |
654 | 690 |
655 ASSERT_NE(kNewRotation, display_manager() | 691 ASSERT_NE(kNewRotation, display_manager() |
656 ->GetDisplayInfo(kInternalDisplayId) | 692 ->GetDisplayInfo(kInternalDisplayId) |
657 .GetActiveRotation()); | 693 .GetActiveRotation()); |
658 | 694 test::ScreenOrientationControllerTestApi( |
659 Shell::GetInstance()->screen_orientation_controller()->SetDisplayRotation( | 695 Shell::GetInstance()->screen_orientation_controller()) |
660 kNewRotation, display::Display::ROTATION_SOURCE_ACTIVE); | 696 .SetDisplayRotation(kNewRotation, |
| 697 display::Display::ROTATION_SOURCE_ACTIVE); |
661 | 698 |
662 EXPECT_EQ(kNewRotation, display_manager() | 699 EXPECT_EQ(kNewRotation, display_manager() |
663 ->GetDisplayInfo(kInternalDisplayId) | 700 ->GetDisplayInfo(kInternalDisplayId) |
664 .GetActiveRotation()); | 701 .GetActiveRotation()); |
665 } | 702 } |
666 | 703 |
| 704 TEST_F(ScreenOrientationControllerTest, UserRotationLockedOrientation) { |
| 705 ScreenOrientationController* orientation_controller = |
| 706 Shell::GetInstance()->screen_orientation_controller(); |
| 707 orientation_controller->ToggleUserRotationLock(); |
| 708 EXPECT_TRUE(orientation_controller->user_rotation_locked()); |
| 709 EXPECT_EQ(blink::WebScreenOrientationLockLandscapePrimary, |
| 710 UserLockedOrientation()); |
| 711 |
| 712 orientation_controller->ToggleUserRotationLock(); |
| 713 SetInternalDisplayRotation(display::Display::ROTATE_90); |
| 714 orientation_controller->ToggleUserRotationLock(); |
| 715 EXPECT_EQ(blink::WebScreenOrientationLockPortraitPrimary, |
| 716 UserLockedOrientation()); |
| 717 |
| 718 orientation_controller->ToggleUserRotationLock(); |
| 719 SetInternalDisplayRotation(display::Display::ROTATE_180); |
| 720 orientation_controller->ToggleUserRotationLock(); |
| 721 EXPECT_EQ(blink::WebScreenOrientationLockLandscapeSecondary, |
| 722 UserLockedOrientation()); |
| 723 |
| 724 orientation_controller->ToggleUserRotationLock(); |
| 725 SetInternalDisplayRotation(display::Display::ROTATE_270); |
| 726 orientation_controller->ToggleUserRotationLock(); |
| 727 EXPECT_EQ(blink::WebScreenOrientationLockPortraitSecondary, |
| 728 UserLockedOrientation()); |
| 729 orientation_controller->ToggleUserRotationLock(); |
| 730 |
| 731 SetInternalDisplayRotation(display::Display::ROTATE_270); |
| 732 |
| 733 UpdateDisplay("800x1280"); |
| 734 orientation_controller->ToggleUserRotationLock(); |
| 735 EXPECT_TRUE(orientation_controller->user_rotation_locked()); |
| 736 EXPECT_EQ(blink::WebScreenOrientationLockPortraitPrimary, |
| 737 UserLockedOrientation()); |
| 738 |
| 739 orientation_controller->ToggleUserRotationLock(); |
| 740 SetInternalDisplayRotation(display::Display::ROTATE_90); |
| 741 orientation_controller->ToggleUserRotationLock(); |
| 742 EXPECT_EQ(blink::WebScreenOrientationLockLandscapePrimary, |
| 743 UserLockedOrientation()); |
| 744 |
| 745 orientation_controller->ToggleUserRotationLock(); |
| 746 SetInternalDisplayRotation(display::Display::ROTATE_180); |
| 747 orientation_controller->ToggleUserRotationLock(); |
| 748 EXPECT_EQ(blink::WebScreenOrientationLockPortraitSecondary, |
| 749 UserLockedOrientation()); |
| 750 |
| 751 orientation_controller->ToggleUserRotationLock(); |
| 752 SetInternalDisplayRotation(display::Display::ROTATE_270); |
| 753 orientation_controller->ToggleUserRotationLock(); |
| 754 EXPECT_EQ(blink::WebScreenOrientationLockLandscapeSecondary, |
| 755 UserLockedOrientation()); |
| 756 orientation_controller->ToggleUserRotationLock(); |
| 757 } |
| 758 |
| 759 TEST_F(ScreenOrientationControllerTest, UserRotationLock) { |
| 760 std::unique_ptr<content::WebContents> content1(CreateWebContents()); |
| 761 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); |
| 762 std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); |
| 763 std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); |
| 764 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); |
| 765 |
| 766 AttachAndActivateWebContents(content2.get(), focus_window2.get()); |
| 767 AttachAndActivateWebContents(content1.get(), focus_window1.get()); |
| 768 |
| 769 ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 770 ASSERT_FALSE(RotationLocked()); |
| 771 ASSERT_FALSE(UserRotationLocked()); |
| 772 |
| 773 ScreenOrientationController* orientation_controller = |
| 774 Shell::GetInstance()->screen_orientation_controller(); |
| 775 ASSERT_FALSE(orientation_controller->user_rotation_locked()); |
| 776 orientation_controller->ToggleUserRotationLock(); |
| 777 ASSERT_TRUE(orientation_controller->user_rotation_locked()); |
| 778 |
| 779 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockPortrait); |
| 780 |
| 781 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 782 |
| 783 aura::client::ActivationClient* activation_client = |
| 784 Shell::GetInstance()->activation_client(); |
| 785 // Activating any will switch to the natural orientation. |
| 786 activation_client->ActivateWindow(focus_window2.get()); |
| 787 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 788 |
| 789 // Activating the portrait window will rotate to the portrait. |
| 790 activation_client->ActivateWindow(focus_window1.get()); |
| 791 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 792 |
| 793 // User locked to the 90 dig. |
| 794 orientation_controller->ToggleUserRotationLock(); |
| 795 orientation_controller->ToggleUserRotationLock(); |
| 796 |
| 797 // Switching to Any orientation will stay to the user locked orientation. |
| 798 activation_client->ActivateWindow(focus_window2.get()); |
| 799 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 800 |
| 801 // Application forced to be landscape. |
| 802 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockLandscape); |
| 803 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 804 |
| 805 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockAny); |
| 806 activation_client->ActivateWindow(focus_window1.get()); |
| 807 // Switching back to any will rotate to user rotation. |
| 808 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 809 } |
| 810 |
667 } // namespace ash | 811 } // namespace ash |
OLD | NEW |