| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "modules/wake_lock/ScreenWakeLock.h" | 5 #include "modules/wake_lock/ScreenWakeLock.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMImplementation.h" | 7 #include "core/dom/DOMImplementation.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/DocumentInit.h" | 9 #include "core/dom/DocumentInit.h" |
| 10 #include "core/frame/WebLocalFrameBase.h" | 10 #include "core/frame/WebLocalFrameBase.h" |
| 11 #include "mojo/public/cpp/bindings/interface_request.h" | 11 #include "mojo/public/cpp/bindings/interface_request.h" |
| 12 #include "mojo/public/cpp/bindings/strong_binding.h" | 12 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 13 #include "platform/testing/URLTestHelpers.h" | 13 #include "platform/testing/URLTestHelpers.h" |
| 14 #include "platform/testing/UnitTestHelpers.h" | 14 #include "platform/testing/UnitTestHelpers.h" |
| 15 #include "public/platform/InterfaceProvider.h" | 15 #include "public/platform/InterfaceProvider.h" |
| 16 #include "public/platform/Platform.h" | 16 #include "public/platform/Platform.h" |
| 17 #include "public/platform/WebPageVisibilityState.h" | 17 #include "public/platform/WebPageVisibilityState.h" |
| 18 #include "public/platform/WebURLLoaderMockFactory.h" | 18 #include "public/platform/WebURLLoaderMockFactory.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "web/tests/FrameTestHelpers.h" | 20 #include "web/tests/FrameTestHelpers.h" |
| 21 | 21 |
| 22 #include <memory> | 22 #include <memory> |
| 23 | 23 |
| 24 namespace blink { | 24 namespace blink { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 using device::mojom::blink::WakeLockService; | 27 using device::mojom::blink::WakeLock; |
| 28 using device::mojom::blink::WakeLockServiceRequest; | 28 using device::mojom::blink::WakeLockRequest; |
| 29 | 29 |
| 30 // This class allows binding interface requests to a MockWakeLockService. | 30 // This class allows binding interface requests to a MockWakeLock. |
| 31 class MockInterfaceProvider : public InterfaceProvider { | 31 class MockInterfaceProvider : public InterfaceProvider { |
| 32 public: | 32 public: |
| 33 MockInterfaceProvider() : wake_lock_status_(false) {} | 33 MockInterfaceProvider() : wake_lock_status_(false) {} |
| 34 ~MockInterfaceProvider() {} | 34 ~MockInterfaceProvider() {} |
| 35 | 35 |
| 36 void GetInterface(const char* name, mojo::ScopedMessagePipeHandle) override; | 36 void GetInterface(const char* name, mojo::ScopedMessagePipeHandle) override; |
| 37 | 37 |
| 38 bool WakeLockStatus() const { return wake_lock_status_; } | 38 bool WakeLockStatus() const { return wake_lock_status_; } |
| 39 void SetWakeLockStatus(bool status) { wake_lock_status_ = status; } | 39 void SetWakeLockStatus(bool status) { wake_lock_status_ = status; } |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 // A mock WakeLockService used to intercept calls to the mojo methods. | 42 // A mock WakeLock used to intercept calls to the mojo methods. |
| 43 class MockWakeLockService : public WakeLockService { | 43 class MockWakeLock : public WakeLock { |
| 44 public: | 44 public: |
| 45 MockWakeLockService(MockInterfaceProvider* registry, | 45 MockWakeLock(MockInterfaceProvider* registry, WakeLockRequest request) |
| 46 WakeLockServiceRequest request) | |
| 47 : binding_(this, std::move(request)), registry_(registry) {} | 46 : binding_(this, std::move(request)), registry_(registry) {} |
| 48 ~MockWakeLockService() {} | 47 ~MockWakeLock() {} |
| 49 | 48 |
| 50 private: | 49 private: |
| 51 // mojom::WakeLockService | 50 // mojom::WakeLock |
| 52 void RequestWakeLock() override { registry_->SetWakeLockStatus(true); } | 51 void RequestWakeLock() override { registry_->SetWakeLockStatus(true); } |
| 53 void CancelWakeLock() override { registry_->SetWakeLockStatus(false); } | 52 void CancelWakeLock() override { registry_->SetWakeLockStatus(false); } |
| 54 void AddClient( | 53 void AddClient(device::mojom::blink::WakeLockRequest wake_lock) override {} |
| 55 device::mojom::blink::WakeLockServiceRequest wake_lock) override {} | |
| 56 void HasWakeLockForTests(HasWakeLockForTestsCallback callback) override {} | 54 void HasWakeLockForTests(HasWakeLockForTestsCallback callback) override {} |
| 57 | 55 |
| 58 mojo::Binding<WakeLockService> binding_; | 56 mojo::Binding<WakeLock> binding_; |
| 59 MockInterfaceProvider* const registry_; | 57 MockInterfaceProvider* const registry_; |
| 60 }; | 58 }; |
| 61 std::unique_ptr<MockWakeLockService> mock_wake_lock_service_; | 59 std::unique_ptr<MockWakeLock> mock_wake_lock_; |
| 62 | 60 |
| 63 bool wake_lock_status_; | 61 bool wake_lock_status_; |
| 64 }; | 62 }; |
| 65 | 63 |
| 66 void MockInterfaceProvider::GetInterface(const char* name, | 64 void MockInterfaceProvider::GetInterface(const char* name, |
| 67 mojo::ScopedMessagePipeHandle handle) { | 65 mojo::ScopedMessagePipeHandle handle) { |
| 68 mock_wake_lock_service_.reset( | 66 mock_wake_lock_.reset( |
| 69 new MockWakeLockService(this, WakeLockServiceRequest(std::move(handle)))); | 67 new MockWakeLock(this, WakeLockRequest(std::move(handle)))); |
| 70 } | 68 } |
| 71 | 69 |
| 72 // A TestWebFrameClient to allow overriding the interfaceProvider() with a mock. | 70 // A TestWebFrameClient to allow overriding the interfaceProvider() with a mock. |
| 73 class TestWebFrameClient : public FrameTestHelpers::TestWebFrameClient { | 71 class TestWebFrameClient : public FrameTestHelpers::TestWebFrameClient { |
| 74 public: | 72 public: |
| 75 ~TestWebFrameClient() override = default; | 73 ~TestWebFrameClient() override = default; |
| 76 InterfaceProvider* GetInterfaceProvider() override { | 74 InterfaceProvider* GetInterfaceProvider() override { |
| 77 return &interface_provider_; | 75 return &interface_provider_; |
| 78 } | 76 } |
| 79 | 77 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 207 |
| 210 SetKeepAwake(true); | 208 SetKeepAwake(true); |
| 211 LoadFrame(); | 209 LoadFrame(); |
| 212 | 210 |
| 213 EXPECT_FALSE(ScreenKeepAwake()); | 211 EXPECT_FALSE(ScreenKeepAwake()); |
| 214 EXPECT_FALSE(ClientKeepScreenAwake()); | 212 EXPECT_FALSE(ClientKeepScreenAwake()); |
| 215 } | 213 } |
| 216 | 214 |
| 217 } // namespace | 215 } // namespace |
| 218 } // namespace blink | 216 } // namespace blink |
| OLD | NEW |