Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: third_party/WebKit/Source/web/tests/ScreenWakeLockTest.cpp

Issue 2196843003: Blink ServiceRegistry -> InterfaceProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "mojo/public/cpp/bindings/interface_request.h" 10 #include "mojo/public/cpp/bindings/interface_request.h"
11 #include "mojo/public/cpp/bindings/strong_binding.h" 11 #include "mojo/public/cpp/bindings/strong_binding.h"
12 #include "platform/testing/URLTestHelpers.h" 12 #include "platform/testing/URLTestHelpers.h"
13 #include "platform/testing/UnitTestHelpers.h" 13 #include "platform/testing/UnitTestHelpers.h"
14 #include "public/platform/InterfaceProvider.h"
14 #include "public/platform/Platform.h" 15 #include "public/platform/Platform.h"
15 #include "public/platform/ServiceRegistry.h"
16 #include "public/platform/WebPageVisibilityState.h" 16 #include "public/platform/WebPageVisibilityState.h"
17 #include "public/platform/WebURLLoaderMockFactory.h" 17 #include "public/platform/WebURLLoaderMockFactory.h"
18 #include "public/web/WebCache.h" 18 #include "public/web/WebCache.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "web/WebLocalFrameImpl.h" 20 #include "web/WebLocalFrameImpl.h"
21 #include "web/tests/FrameTestHelpers.h" 21 #include "web/tests/FrameTestHelpers.h"
22 22
23 #include <memory> 23 #include <memory>
24 24
25 namespace { 25 namespace {
26 26
27 using blink::ScreenWakeLock; 27 using blink::ScreenWakeLock;
28 using blink::mojom::blink::WakeLockService; 28 using blink::mojom::blink::WakeLockService;
29 using blink::mojom::blink::WakeLockServiceRequest; 29 using blink::mojom::blink::WakeLockServiceRequest;
30 30
31 // This class allows connecting service requests to a MockWakeLockService. 31 // This class allows binding interface requests to a MockWakeLockService.
32 class MockServiceRegistry : public blink::ServiceRegistry { 32 class MockInterfaceProvider : public blink::InterfaceProvider {
33 public: 33 public:
34 MockServiceRegistry() : m_wakeLockStatus(false) {} 34 MockInterfaceProvider() : m_wakeLockStatus(false) {}
35 ~MockServiceRegistry() {} 35 ~MockInterfaceProvider() {}
36 36
37 void connectToRemoteService(const char* name, mojo::ScopedMessagePipeHandle) override; 37 void getInterface(const char* name, mojo::ScopedMessagePipeHandle) override;
38 38
39 bool wakeLockStatus() const { return m_wakeLockStatus; } 39 bool wakeLockStatus() const { return m_wakeLockStatus; }
40 void setWakeLockStatus(bool status) { m_wakeLockStatus = status; } 40 void setWakeLockStatus(bool status) { m_wakeLockStatus = status; }
41 41
42 private: 42 private:
43 // A mock WakeLockService used to intercept calls to the mojo methods. 43 // A mock WakeLockService used to intercept calls to the mojo methods.
44 class MockWakeLockService : public WakeLockService { 44 class MockWakeLockService : public WakeLockService {
45 public: 45 public:
46 MockWakeLockService(MockServiceRegistry* registry, WakeLockServiceReques t request) 46 MockWakeLockService(MockInterfaceProvider* registry, WakeLockServiceRequ est request)
47 : m_binding(this, std::move(request)) 47 : m_binding(this, std::move(request))
48 , m_registry(registry) {} 48 , m_registry(registry) {}
49 ~MockWakeLockService() {} 49 ~MockWakeLockService() {}
50 50
51 private: 51 private:
52 // mojom::WakeLockService 52 // mojom::WakeLockService
53 void RequestWakeLock() override { m_registry->setWakeLockStatus(true); } 53 void RequestWakeLock() override { m_registry->setWakeLockStatus(true); }
54 void CancelWakeLock() override { m_registry->setWakeLockStatus(false); } 54 void CancelWakeLock() override { m_registry->setWakeLockStatus(false); }
55 55
56 mojo::Binding<WakeLockService> m_binding; 56 mojo::Binding<WakeLockService> m_binding;
57 MockServiceRegistry* const m_registry; 57 MockInterfaceProvider* const m_registry;
58 }; 58 };
59 std::unique_ptr<MockWakeLockService> m_mockWakeLockService; 59 std::unique_ptr<MockWakeLockService> m_mockWakeLockService;
60 60
61 bool m_wakeLockStatus; 61 bool m_wakeLockStatus;
62 }; 62 };
63 63
64 void MockServiceRegistry::connectToRemoteService(const char* name, mojo::ScopedM essagePipeHandle handle) 64 void MockInterfaceProvider::getInterface(const char* name, mojo::ScopedMessagePi peHandle handle)
65 { 65 {
66 m_mockWakeLockService.reset( 66 m_mockWakeLockService.reset(
67 new MockWakeLockService(this, mojo::MakeRequest<WakeLockService>(std::mo ve(handle)))); 67 new MockWakeLockService(this, mojo::MakeRequest<WakeLockService>(std::mo ve(handle))));
68 } 68 }
69 69
70 // A TestWebFrameClient to allow overriding the serviceRegistry() with a mock. 70 // A TestWebFrameClient to allow overriding the interfaceProvider() with a mock.
71 class TestWebFrameClient : public blink::FrameTestHelpers::TestWebFrameClient { 71 class TestWebFrameClient : public blink::FrameTestHelpers::TestWebFrameClient {
72 public: 72 public:
73 ~TestWebFrameClient() override = default; 73 ~TestWebFrameClient() override = default;
74 blink::ServiceRegistry* serviceRegistry() override { return &m_serviceRegist ry; } 74 blink::InterfaceProvider* interfaceProvider() override { return &m_interface Provider; }
75 75
76 private: 76 private:
77 MockServiceRegistry m_serviceRegistry; 77 MockInterfaceProvider m_interfaceProvider;
78 }; 78 };
79 79
80 class ScreenWakeLockTest: public testing::Test { 80 class ScreenWakeLockTest: public testing::Test {
81 protected: 81 protected:
82 void SetUp() override 82 void SetUp() override
83 { 83 {
84 m_webViewHelper.initialize(true, &m_testWebFrameClient); 84 m_webViewHelper.initialize(true, &m_testWebFrameClient);
85 blink::URLTestHelpers::registerMockedURLFromBaseURL( 85 blink::URLTestHelpers::registerMockedURLFromBaseURL(
86 blink::WebString::fromUTF8("http://example.com/"), 86 blink::WebString::fromUTF8("http://example.com/"),
87 blink::WebString::fromUTF8("foo.html")); 87 blink::WebString::fromUTF8("foo.html"));
(...skipping 30 matching lines...) Expand all
118 } 118 }
119 119
120 bool screenKeepAwake() 120 bool screenKeepAwake()
121 { 121 {
122 DCHECK(screen()); 122 DCHECK(screen());
123 return ScreenWakeLock::keepAwake(*screen()); 123 return ScreenWakeLock::keepAwake(*screen());
124 } 124 }
125 125
126 bool clientKeepScreenAwake() 126 bool clientKeepScreenAwake()
127 { 127 {
128 return static_cast<MockServiceRegistry*>(m_testWebFrameClient.serviceReg istry())->wakeLockStatus(); 128 return static_cast<MockInterfaceProvider*>(m_testWebFrameClient.interfac eProvider())->wakeLockStatus();
129 } 129 }
130 130
131 void setKeepAwake(bool keepAwake) 131 void setKeepAwake(bool keepAwake)
132 { 132 {
133 DCHECK(screen()); 133 DCHECK(screen());
134 ScreenWakeLock::setKeepAwake(*screen(), keepAwake); 134 ScreenWakeLock::setKeepAwake(*screen(), keepAwake);
135 // Let the notification sink through the mojo pipes. 135 // Let the notification sink through the mojo pipes.
136 blink::testing::runPendingTasks(); 136 blink::testing::runPendingTasks();
137 } 137 }
138 138
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 ASSERT_FALSE(clientKeepScreenAwake()); 217 ASSERT_FALSE(clientKeepScreenAwake());
218 218
219 setKeepAwake(true); 219 setKeepAwake(true);
220 loadFrame(); 220 loadFrame();
221 221
222 EXPECT_FALSE(screenKeepAwake()); 222 EXPECT_FALSE(screenKeepAwake());
223 EXPECT_FALSE(clientKeepScreenAwake()); 223 EXPECT_FALSE(clientKeepScreenAwake());
224 } 224 }
225 225
226 } // namespace 226 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698