| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "content/browser/screen_orientation/screen_orientation_provider.h" | 5 #include "content/browser/screen_orientation/screen_orientation_provider.h" |
| 6 | 6 |
| 7 #include "base/optional.h" | 7 #include "base/optional.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "content/common/frame_messages.h" | 9 #include "content/common/frame_messages.h" |
| 10 #include "content/public/browser/screen_orientation_delegate.h" | 10 #include "content/public/browser/screen_orientation_delegate.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return fullscreened_contents_ && web_contents == fullscreened_contents_; | 73 return fullscreened_contents_ && web_contents == fullscreened_contents_; |
| 74 } | 74 } |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 WebContents* fullscreened_contents_ = nullptr; | 77 WebContents* fullscreened_contents_ = nullptr; |
| 78 | 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(FakeWebContentsDelegate); | 79 DISALLOW_COPY_AND_ASSIGN(FakeWebContentsDelegate); |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 void LockResultCallback(base::Optional<ScreenOrientationLockResult>* out_result, | 82 void LockResultCallback(base::Optional<ScreenOrientationLockResult>* out_result, |
| 83 ScreenOrientationLockResult result) { | 83 ScreenOrientationLockResult result, |
| 84 blink::WebScreenOrientationLockType lock) { |
| 84 *out_result = result; | 85 *out_result = result; |
| 85 } | 86 } |
| 86 | 87 |
| 87 } // namespace | 88 } // namespace |
| 88 | 89 |
| 89 class ScreenOrientationProviderTest : public RenderViewHostImplTestHarness { | 90 class ScreenOrientationProviderTest : public RenderViewHostImplTestHarness { |
| 90 public: | 91 public: |
| 91 ScreenOrientationProviderTest() = default; | 92 ScreenOrientationProviderTest() = default; |
| 92 | 93 |
| 93 void SetUp() override { | 94 void SetUp() override { |
| 94 content::RenderViewHostImplTestHarness::SetUp(); | 95 content::RenderViewHostImplTestHarness::SetUp(); |
| 95 | 96 |
| 96 contents()->SetDelegate(&wc_delegate_); | 97 contents()->SetDelegate(&wc_delegate_); |
| 97 } | 98 } |
| 98 | 99 |
| 99 // Helpers for testing ScreenOrientationProvider methods. | 100 // Helpers for testing ScreenOrientationProvider methods. |
| 100 void CallLockAndGetResult( | 101 void CallLockAndGetResult( |
| 101 blink::WebScreenOrientationLockType orientation, | 102 blink::WebScreenOrientationLockType orientation, |
| 102 base::Optional<ScreenOrientationLockResult>* out_result) { | 103 base::Optional<ScreenOrientationLockResult>* out_result) { |
| 103 contents()->GetScreenOrientationProviderForTesting()->LockOrientation( | 104 contents()->GetScreenOrientationProvider()->LockOrientation( |
| 104 orientation, base::Bind(&LockResultCallback, out_result)); | 105 orientation, base::Bind(&LockResultCallback, out_result)); |
| 105 | 106 |
| 106 base::RunLoop().RunUntilIdle(); | 107 base::RunLoop().RunUntilIdle(); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void CallUnlock() { | 110 void CallUnlock() { |
| 110 contents()->GetScreenOrientationProviderForTesting()->UnlockOrientation(); | 111 contents()->GetScreenOrientationProvider()->UnlockOrientation(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 private: | 114 private: |
| 114 FakeWebContentsDelegate wc_delegate_; | 115 FakeWebContentsDelegate wc_delegate_; |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 // Lock operation is not available. | 118 // Lock operation is not available. |
| 118 TEST_F(ScreenOrientationProviderTest, DelegateNotAvailableLockOnce) { | 119 TEST_F(ScreenOrientationProviderTest, DelegateNotAvailableLockOnce) { |
| 119 // No ScreenOrientationDelegate. | 120 // No ScreenOrientationDelegate. |
| 120 base::Optional<ScreenOrientationLockResult> result_1; | 121 base::Optional<ScreenOrientationLockResult> result_1; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 contents()->NavigateAndCommit(another_url); | 335 contents()->NavigateAndCommit(another_url); |
| 335 // The pending lock request is cancelled. | 336 // The pending lock request is cancelled. |
| 336 EXPECT_EQ(ScreenOrientationLockResult:: | 337 EXPECT_EQ(ScreenOrientationLockResult:: |
| 337 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED, | 338 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED, |
| 338 result); | 339 result); |
| 339 // Delegate did apply unlock once. | 340 // Delegate did apply unlock once. |
| 340 EXPECT_EQ(1, delegate.unlock_count()); | 341 EXPECT_EQ(1, delegate.unlock_count()); |
| 341 } | 342 } |
| 342 | 343 |
| 343 } // namespace content | 344 } // namespace content |
| OLD | NEW |