| 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" |
| 6 |
| 7 #include <memory> |
| 5 #include <vector> | 8 #include <vector> |
| 6 | 9 |
| 7 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 8 #include "ash/content/shell_content_state.h" | 11 #include "ash/content/shell_content_state.h" |
| 9 #include "ash/display/display_info.h" | 12 #include "ash/display/display_info.h" |
| 10 #include "ash/display/display_manager.h" | 13 #include "ash/display/display_manager.h" |
| 11 #include "ash/display/screen_orientation_controller_chromeos.h" | |
| 12 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 13 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
| 14 #include "ash/test/ash_test_helper.h" | 16 #include "ash/test/ash_test_helper.h" |
| 15 #include "ash/test/content/test_shell_content_state.h" | 17 #include "ash/test/content/test_shell_content_state.h" |
| 16 #include "ash/test/display_manager_test_api.h" | 18 #include "ash/test/display_manager_test_api.h" |
| 17 #include "ash/test/test_shell_delegate.h" | 19 #include "ash/test/test_shell_delegate.h" |
| 18 #include "ash/test/test_system_tray_delegate.h" | 20 #include "ash/test/test_system_tray_delegate.h" |
| 19 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 21 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 20 #include "base/command_line.h" | 22 #include "base/command_line.h" |
| 21 #include "base/memory/scoped_ptr.h" | |
| 22 #include "chromeos/accelerometer/accelerometer_reader.h" | 23 #include "chromeos/accelerometer/accelerometer_reader.h" |
| 23 #include "chromeos/accelerometer/accelerometer_types.h" | 24 #include "chromeos/accelerometer/accelerometer_types.h" |
| 24 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
| 25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/test/test_browser_context.h" | 27 #include "content/public/test/test_browser_context.h" |
| 27 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" | 28 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" |
| 28 #include "ui/aura/window.h" | 29 #include "ui/aura/window.h" |
| 29 #include "ui/gfx/display.h" | 30 #include "ui/gfx/display.h" |
| 30 #include "ui/message_center/message_center.h" | 31 #include "ui/message_center/message_center.h" |
| 31 #include "ui/views/test/webview_test_helper.h" | 32 #include "ui/views/test/webview_test_helper.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 118 |
| 118 // Creates a secondary content::WebContents, with a separate | 119 // Creates a secondary content::WebContents, with a separate |
| 119 // content::BrowserContext. | 120 // content::BrowserContext. |
| 120 content::WebContents* CreateSecondaryWebContents(); | 121 content::WebContents* CreateSecondaryWebContents(); |
| 121 | 122 |
| 122 // test::AshTestBase: | 123 // test::AshTestBase: |
| 123 void SetUp() override; | 124 void SetUp() override; |
| 124 | 125 |
| 125 private: | 126 private: |
| 126 // Optional content::BrowserContext used for two window tests. | 127 // Optional content::BrowserContext used for two window tests. |
| 127 scoped_ptr<content::BrowserContext> secondary_browser_context_; | 128 std::unique_ptr<content::BrowserContext> secondary_browser_context_; |
| 128 | 129 |
| 129 // Setups underlying content layer so that content::WebContents can be | 130 // Setups underlying content layer so that content::WebContents can be |
| 130 // generated. | 131 // generated. |
| 131 scoped_ptr<views::WebViewTestHelper> webview_test_helper_; | 132 std::unique_ptr<views::WebViewTestHelper> webview_test_helper_; |
| 132 | 133 |
| 133 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationControllerTest); | 134 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationControllerTest); |
| 134 }; | 135 }; |
| 135 | 136 |
| 136 ScreenOrientationControllerTest::ScreenOrientationControllerTest() { | 137 ScreenOrientationControllerTest::ScreenOrientationControllerTest() { |
| 137 webview_test_helper_.reset(new views::WebViewTestHelper()); | 138 webview_test_helper_.reset(new views::WebViewTestHelper()); |
| 138 } | 139 } |
| 139 | 140 |
| 140 ScreenOrientationControllerTest::~ScreenOrientationControllerTest() { | 141 ScreenOrientationControllerTest::~ScreenOrientationControllerTest() { |
| 141 } | 142 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 155 void ScreenOrientationControllerTest::SetUp() { | 156 void ScreenOrientationControllerTest::SetUp() { |
| 156 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 157 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 157 switches::kAshUseFirstDisplayAsInternal); | 158 switches::kAshUseFirstDisplayAsInternal); |
| 158 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 159 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 159 switches::kAshEnableTouchViewTesting); | 160 switches::kAshEnableTouchViewTesting); |
| 160 test::AshTestBase::SetUp(); | 161 test::AshTestBase::SetUp(); |
| 161 } | 162 } |
| 162 | 163 |
| 163 // Tests that a content::WebContents can lock rotation. | 164 // Tests that a content::WebContents can lock rotation. |
| 164 TEST_F(ScreenOrientationControllerTest, LockOrientation) { | 165 TEST_F(ScreenOrientationControllerTest, LockOrientation) { |
| 165 scoped_ptr<content::WebContents> content(CreateWebContents()); | 166 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 166 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 167 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); |
| 167 ASSERT_NE(nullptr, content->GetNativeView()); | 168 ASSERT_NE(nullptr, content->GetNativeView()); |
| 168 ASSERT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 169 ASSERT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 169 ASSERT_FALSE(RotationLocked()); | 170 ASSERT_FALSE(RotationLocked()); |
| 170 | 171 |
| 171 AttachAndActivateWebContents(content.get(), focus_window.get()); | 172 AttachAndActivateWebContents(content.get(), focus_window.get()); |
| 172 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 173 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
| 173 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 174 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 174 EXPECT_TRUE(RotationLocked()); | 175 EXPECT_TRUE(RotationLocked()); |
| 175 } | 176 } |
| 176 | 177 |
| 177 // Tests that a content::WebContents can unlock rotation. | 178 // Tests that a content::WebContents can unlock rotation. |
| 178 TEST_F(ScreenOrientationControllerTest, Unlock) { | 179 TEST_F(ScreenOrientationControllerTest, Unlock) { |
| 179 scoped_ptr<content::WebContents> content(CreateWebContents()); | 180 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 180 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 181 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); |
| 181 ASSERT_NE(nullptr, content->GetNativeView()); | 182 ASSERT_NE(nullptr, content->GetNativeView()); |
| 182 ASSERT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 183 ASSERT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 183 ASSERT_FALSE(RotationLocked()); | 184 ASSERT_FALSE(RotationLocked()); |
| 184 | 185 |
| 185 AttachAndActivateWebContents(content.get(), focus_window.get()); | 186 AttachAndActivateWebContents(content.get(), focus_window.get()); |
| 186 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 187 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
| 187 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 188 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 188 EXPECT_TRUE(RotationLocked()); | 189 EXPECT_TRUE(RotationLocked()); |
| 189 | 190 |
| 190 delegate()->Unlock(content.get()); | 191 delegate()->Unlock(content.get()); |
| 191 EXPECT_FALSE(RotationLocked()); | 192 EXPECT_FALSE(RotationLocked()); |
| 192 } | 193 } |
| 193 | 194 |
| 194 // Tests that a content::WebContents is able to change the orientation of the | 195 // Tests that a content::WebContents is able to change the orientation of the |
| 195 // display after having locked rotation. | 196 // display after having locked rotation. |
| 196 TEST_F(ScreenOrientationControllerTest, OrientationChanges) { | 197 TEST_F(ScreenOrientationControllerTest, OrientationChanges) { |
| 197 scoped_ptr<content::WebContents> content(CreateWebContents()); | 198 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 198 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 199 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); |
| 199 ASSERT_NE(nullptr, content->GetNativeView()); | 200 ASSERT_NE(nullptr, content->GetNativeView()); |
| 200 ASSERT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 201 ASSERT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 201 ASSERT_FALSE(RotationLocked()); | 202 ASSERT_FALSE(RotationLocked()); |
| 202 | 203 |
| 203 AttachAndActivateWebContents(content.get(), focus_window.get()); | 204 AttachAndActivateWebContents(content.get(), focus_window.get()); |
| 204 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); | 205 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); |
| 205 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 206 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 206 EXPECT_TRUE(RotationLocked()); | 207 EXPECT_TRUE(RotationLocked()); |
| 207 | 208 |
| 208 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 209 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
| 209 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 210 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 210 } | 211 } |
| 211 | 212 |
| 212 // Tests that orientation can only be set by the first content::WebContents that | 213 // Tests that orientation can only be set by the first content::WebContents that |
| 213 // has set a rotation lock. | 214 // has set a rotation lock. |
| 214 TEST_F(ScreenOrientationControllerTest, SecondContentCannotChangeOrientation) { | 215 TEST_F(ScreenOrientationControllerTest, SecondContentCannotChangeOrientation) { |
| 215 scoped_ptr<content::WebContents> content1(CreateWebContents()); | 216 std::unique_ptr<content::WebContents> content1(CreateWebContents()); |
| 216 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents()); | 217 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); |
| 217 scoped_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); | 218 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); |
| 218 scoped_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); | 219 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); |
| 219 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); | 220 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); |
| 220 | 221 |
| 221 AttachAndActivateWebContents(content1.get(), focus_window1.get()); | 222 AttachAndActivateWebContents(content1.get(), focus_window1.get()); |
| 222 AttachWebContents(content2.get(), focus_window2.get()); | 223 AttachWebContents(content2.get(), focus_window2.get()); |
| 223 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); | 224 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); |
| 224 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); | 225 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); |
| 225 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 226 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 226 } | 227 } |
| 227 | 228 |
| 228 // Tests that only the content::WebContents that set a rotation lock can perform | 229 // Tests that only the content::WebContents that set a rotation lock can perform |
| 229 // an unlock. | 230 // an unlock. |
| 230 TEST_F(ScreenOrientationControllerTest, SecondContentCannotUnlock) { | 231 TEST_F(ScreenOrientationControllerTest, SecondContentCannotUnlock) { |
| 231 scoped_ptr<content::WebContents> content1(CreateWebContents()); | 232 std::unique_ptr<content::WebContents> content1(CreateWebContents()); |
| 232 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents()); | 233 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); |
| 233 scoped_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); | 234 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); |
| 234 scoped_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); | 235 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); |
| 235 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); | 236 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); |
| 236 | 237 |
| 237 AttachAndActivateWebContents(content1.get(), focus_window1.get()); | 238 AttachAndActivateWebContents(content1.get(), focus_window1.get()); |
| 238 AttachWebContents(content2.get(), focus_window2.get()); | 239 AttachWebContents(content2.get(), focus_window2.get()); |
| 239 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); | 240 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); |
| 240 delegate()->Unlock(content2.get()); | 241 delegate()->Unlock(content2.get()); |
| 241 EXPECT_TRUE(RotationLocked()); | 242 EXPECT_TRUE(RotationLocked()); |
| 242 } | 243 } |
| 243 | 244 |
| 244 // Tests that a rotation lock is applied only while the content::WebContents are | 245 // Tests that a rotation lock is applied only while the content::WebContents are |
| 245 // a part of the active window. | 246 // a part of the active window. |
| 246 TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateLock) { | 247 TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateLock) { |
| 247 scoped_ptr<content::WebContents> content(CreateWebContents()); | 248 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 248 scoped_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); | 249 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); |
| 249 scoped_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); | 250 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); |
| 250 | 251 |
| 251 AttachAndActivateWebContents(content.get(), focus_window1.get()); | 252 AttachAndActivateWebContents(content.get(), focus_window1.get()); |
| 252 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 253 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
| 253 ASSERT_TRUE(RotationLocked()); | 254 ASSERT_TRUE(RotationLocked()); |
| 254 | 255 |
| 255 aura::client::ActivationClient* activation_client = | 256 aura::client::ActivationClient* activation_client = |
| 256 Shell::GetInstance()->activation_client(); | 257 Shell::GetInstance()->activation_client(); |
| 257 activation_client->ActivateWindow(focus_window2.get()); | 258 activation_client->ActivateWindow(focus_window2.get()); |
| 258 EXPECT_FALSE(RotationLocked()); | 259 EXPECT_FALSE(RotationLocked()); |
| 259 | 260 |
| 260 activation_client->ActivateWindow(focus_window1.get()); | 261 activation_client->ActivateWindow(focus_window1.get()); |
| 261 EXPECT_TRUE(RotationLocked()); | 262 EXPECT_TRUE(RotationLocked()); |
| 262 } | 263 } |
| 263 | 264 |
| 264 // Tests that switching between windows with different orientation locks change | 265 // Tests that switching between windows with different orientation locks change |
| 265 // the orientation. | 266 // the orientation. |
| 266 TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) { | 267 TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) { |
| 267 scoped_ptr<content::WebContents> content1(CreateWebContents()); | 268 std::unique_ptr<content::WebContents> content1(CreateWebContents()); |
| 268 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents()); | 269 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); |
| 269 scoped_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); | 270 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); |
| 270 scoped_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); | 271 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); |
| 271 AttachAndActivateWebContents(content1.get(), focus_window1.get()); | 272 AttachAndActivateWebContents(content1.get(), focus_window1.get()); |
| 272 AttachWebContents(content2.get(), focus_window2.get()); | 273 AttachWebContents(content2.get(), focus_window2.get()); |
| 273 | 274 |
| 274 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); | 275 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); |
| 275 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); | 276 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); |
| 276 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 277 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 277 | 278 |
| 278 aura::client::ActivationClient* activation_client = | 279 aura::client::ActivationClient* activation_client = |
| 279 Shell::GetInstance()->activation_client(); | 280 Shell::GetInstance()->activation_client(); |
| 280 activation_client->ActivateWindow(focus_window2.get()); | 281 activation_client->ActivateWindow(focus_window2.get()); |
| 281 EXPECT_TRUE(RotationLocked()); | 282 EXPECT_TRUE(RotationLocked()); |
| 282 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 283 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 283 | 284 |
| 284 activation_client->ActivateWindow(focus_window1.get()); | 285 activation_client->ActivateWindow(focus_window1.get()); |
| 285 EXPECT_TRUE(RotationLocked()); | 286 EXPECT_TRUE(RotationLocked()); |
| 286 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 287 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 287 } | 288 } |
| 288 | 289 |
| 289 // Tests that a rotation lock is removed when the setting window is hidden, and | 290 // Tests that a rotation lock is removed when the setting window is hidden, and |
| 290 // that it is reapplied when the window becomes visible. | 291 // that it is reapplied when the window becomes visible. |
| 291 TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) { | 292 TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) { |
| 292 scoped_ptr<content::WebContents> content(CreateWebContents()); | 293 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 293 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 294 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); |
| 294 AttachAndActivateWebContents(content.get(), focus_window.get()); | 295 AttachAndActivateWebContents(content.get(), focus_window.get()); |
| 295 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 296 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
| 296 EXPECT_TRUE(RotationLocked()); | 297 EXPECT_TRUE(RotationLocked()); |
| 297 | 298 |
| 298 aura::Window* window = content->GetNativeView(); | 299 aura::Window* window = content->GetNativeView(); |
| 299 window->Hide(); | 300 window->Hide(); |
| 300 EXPECT_FALSE(RotationLocked()); | 301 EXPECT_FALSE(RotationLocked()); |
| 301 | 302 |
| 302 window->Show(); | 303 window->Show(); |
| 303 EXPECT_TRUE(RotationLocked()); | 304 EXPECT_TRUE(RotationLocked()); |
| 304 } | 305 } |
| 305 | 306 |
| 306 // Tests that when a window is destroyed that its rotation lock is removed, and | 307 // Tests that when a window is destroyed that its rotation lock is removed, and |
| 307 // window activations no longer change the lock | 308 // window activations no longer change the lock |
| 308 TEST_F(ScreenOrientationControllerTest, WindowDestructionRemovesLock) { | 309 TEST_F(ScreenOrientationControllerTest, WindowDestructionRemovesLock) { |
| 309 scoped_ptr<content::WebContents> content(CreateWebContents()); | 310 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 310 scoped_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); | 311 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); |
| 311 scoped_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); | 312 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); |
| 312 | 313 |
| 313 AttachAndActivateWebContents(content.get(), focus_window1.get()); | 314 AttachAndActivateWebContents(content.get(), focus_window1.get()); |
| 314 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 315 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
| 315 ASSERT_TRUE(RotationLocked()); | 316 ASSERT_TRUE(RotationLocked()); |
| 316 | 317 |
| 317 focus_window1->RemoveChild(content->GetNativeView()); | 318 focus_window1->RemoveChild(content->GetNativeView()); |
| 318 content.reset(); | 319 content.reset(); |
| 319 EXPECT_FALSE(RotationLocked()); | 320 EXPECT_FALSE(RotationLocked()); |
| 320 | 321 |
| 321 aura::client::ActivationClient* activation_client = | 322 aura::client::ActivationClient* activation_client = |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 // User sets rotation to the same rotation that the display was at when | 503 // User sets rotation to the same rotation that the display was at when |
| 503 // maximize mode was activated. | 504 // maximize mode was activated. |
| 504 SetInternalDisplayRotation(gfx::Display::ROTATE_0); | 505 SetInternalDisplayRotation(gfx::Display::ROTATE_0); |
| 505 EnableMaximizeMode(false); | 506 EnableMaximizeMode(false); |
| 506 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 507 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 507 } | 508 } |
| 508 | 509 |
| 509 // Tests that when the orientation lock is set to Landscape, that rotation can | 510 // Tests that when the orientation lock is set to Landscape, that rotation can |
| 510 // be done between the two angles of the orientation. | 511 // be done between the two angles of the orientation. |
| 511 TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { | 512 TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { |
| 512 scoped_ptr<content::WebContents> content(CreateWebContents()); | 513 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 513 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 514 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); |
| 514 EnableMaximizeMode(true); | 515 EnableMaximizeMode(true); |
| 515 | 516 |
| 516 AttachAndActivateWebContents(content.get(), focus_window.get()); | 517 AttachAndActivateWebContents(content.get(), focus_window.get()); |
| 517 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 518 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
| 518 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 519 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 519 EXPECT_TRUE(RotationLocked()); | 520 EXPECT_TRUE(RotationLocked()); |
| 520 | 521 |
| 521 // Inverse of orientation is allowed | 522 // Inverse of orientation is allowed |
| 522 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 523 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
| 523 EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 524 EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
| 524 | 525 |
| 525 // Display rotations between are not allowed | 526 // Display rotations between are not allowed |
| 526 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); | 527 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
| 527 EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 528 EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
| 528 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); | 529 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
| 529 EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 530 EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
| 530 } | 531 } |
| 531 | 532 |
| 532 // Tests that when the orientation lock is set to Portrait, that rotaiton can be | 533 // Tests that when the orientation lock is set to Portrait, that rotaiton can be |
| 533 // done between the two angles of the orientation. | 534 // done between the two angles of the orientation. |
| 534 TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { | 535 TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { |
| 535 scoped_ptr<content::WebContents> content(CreateWebContents()); | 536 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 536 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 537 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); |
| 537 EnableMaximizeMode(true); | 538 EnableMaximizeMode(true); |
| 538 | 539 |
| 539 AttachAndActivateWebContents(content.get(), focus_window.get()); | 540 AttachAndActivateWebContents(content.get(), focus_window.get()); |
| 540 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); | 541 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); |
| 541 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 542 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 542 EXPECT_TRUE(RotationLocked()); | 543 EXPECT_TRUE(RotationLocked()); |
| 543 | 544 |
| 544 // Inverse of orientation is allowed | 545 // Inverse of orientation is allowed |
| 545 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); | 546 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
| 546 EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 547 EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
| 547 | 548 |
| 548 // Display rotations between are not allowed | 549 // Display rotations between are not allowed |
| 549 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 550 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
| 550 EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 551 EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
| 551 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 552 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
| 552 EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 553 EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
| 553 } | 554 } |
| 554 | 555 |
| 555 // Tests that for an orientation lock which does not allow rotation, that the | 556 // Tests that for an orientation lock which does not allow rotation, that the |
| 556 // display rotation remains constant. | 557 // display rotation remains constant. |
| 557 TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { | 558 TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { |
| 558 scoped_ptr<content::WebContents> content(CreateWebContents()); | 559 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 559 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 560 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); |
| 560 EnableMaximizeMode(true); | 561 EnableMaximizeMode(true); |
| 561 | 562 |
| 562 AttachAndActivateWebContents(content.get(), focus_window.get()); | 563 AttachAndActivateWebContents(content.get(), focus_window.get()); |
| 563 delegate()->Lock(content.get(), | 564 delegate()->Lock(content.get(), |
| 564 blink::WebScreenOrientationLockPortraitPrimary); | 565 blink::WebScreenOrientationLockPortraitPrimary); |
| 565 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 566 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 566 EXPECT_TRUE(RotationLocked()); | 567 EXPECT_TRUE(RotationLocked()); |
| 567 | 568 |
| 568 // Rotation does not change. | 569 // Rotation does not change. |
| 569 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); | 570 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
| 570 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 571 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 571 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 572 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
| 572 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 573 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 573 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 574 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
| 574 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 575 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 575 } | 576 } |
| 576 | 577 |
| 577 // Tests that after a content::WebContents has applied an orientation lock which | 578 // Tests that after a content::WebContents has applied an orientation lock which |
| 578 // supports rotation, that a user rotation lock does not allow rotation. | 579 // supports rotation, that a user rotation lock does not allow rotation. |
| 579 TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { | 580 TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { |
| 580 scoped_ptr<content::WebContents> content(CreateWebContents()); | 581 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 581 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); | 582 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); |
| 582 EnableMaximizeMode(true); | 583 EnableMaximizeMode(true); |
| 583 | 584 |
| 584 AttachAndActivateWebContents(content.get(), focus_window.get()); | 585 AttachAndActivateWebContents(content.get(), focus_window.get()); |
| 585 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); | 586 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); |
| 586 delegate()->Unlock(content.get()); | 587 delegate()->Unlock(content.get()); |
| 587 | 588 |
| 588 SetRotationLocked(true); | 589 SetRotationLocked(true); |
| 589 EXPECT_TRUE(RotationLocked()); | 590 EXPECT_TRUE(RotationLocked()); |
| 590 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 591 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 591 | 592 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 .GetActiveRotation()); | 651 .GetActiveRotation()); |
| 651 | 652 |
| 652 Shell::GetInstance()->screen_orientation_controller()->SetDisplayRotation( | 653 Shell::GetInstance()->screen_orientation_controller()->SetDisplayRotation( |
| 653 kNewRotation, gfx::Display::ROTATION_SOURCE_ACTIVE); | 654 kNewRotation, gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 654 | 655 |
| 655 EXPECT_EQ(kNewRotation, display_manager->GetDisplayInfo(kInternalDisplayId) | 656 EXPECT_EQ(kNewRotation, display_manager->GetDisplayInfo(kInternalDisplayId) |
| 656 .GetActiveRotation()); | 657 .GetActiveRotation()); |
| 657 } | 658 } |
| 658 | 659 |
| 659 } // namespace ash | 660 } // namespace ash |
| OLD | NEW |