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

Side by Side Diff: third_party/WebKit/Source/modules/presentation/PresentationReceiverTest.cpp

Issue 2737413003: [Presentation API] Remove references to presentation sessions. (Closed)
Patch Set: Update PresentationServiceDelegateImpl unittest Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/presentation/PresentationReceiver.h" 5 #include "modules/presentation/PresentationReceiver.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/V8BindingForTesting.h" 10 #include "bindings/core/v8/V8BindingForTesting.h"
(...skipping 16 matching lines...) Expand all
27 MockEventListener() : EventListener(CPPEventListenerType) {} 27 MockEventListener() : EventListener(CPPEventListenerType) {}
28 28
29 bool operator==(const EventListener& other) const final { 29 bool operator==(const EventListener& other) const final {
30 return this == &other; 30 return this == &other;
31 } 31 }
32 32
33 MOCK_METHOD2(handleEvent, void(ExecutionContext* executionContext, Event*)); 33 MOCK_METHOD2(handleEvent, void(ExecutionContext* executionContext, Event*));
34 }; 34 };
35 35
36 class MockWebPresentationClient : public WebPresentationClient { 36 class MockWebPresentationClient : public WebPresentationClient {
37 void startSession( 37 void startPresentation(
38 const WebVector<WebURL>& presentationUrls, 38 const WebVector<WebURL>& presentationUrls,
39 std::unique_ptr<WebPresentationConnectionCallbacks> callbacks) override { 39 std::unique_ptr<WebPresentationConnectionCallbacks> callbacks) override {
40 return startSession_(presentationUrls, callbacks); 40 return startPresentation_(presentationUrls, callbacks);
41 } 41 }
42 void joinSession( 42 void reconnectPresentation(
43 const WebVector<WebURL>& presentationUrls, 43 const WebVector<WebURL>& presentationUrls,
44 const WebString& presentationId, 44 const WebString& presentationId,
45 std::unique_ptr<WebPresentationConnectionCallbacks> callbacks) override { 45 std::unique_ptr<WebPresentationConnectionCallbacks> callbacks) override {
46 return joinSession_(presentationUrls, presentationId, callbacks); 46 return reconnectPresentation_(presentationUrls, presentationId, callbacks);
47 } 47 }
48 48
49 void getAvailability(const WebVector<WebURL>& availabilityURLs, 49 void getAvailability(const WebVector<WebURL>& availabilityURLs,
50 std::unique_ptr<WebPresentationAvailabilityCallbacks> 50 std::unique_ptr<WebPresentationAvailabilityCallbacks>
51 callbacks) override { 51 callbacks) override {
52 return getAvailability_(availabilityURLs, callbacks); 52 return getAvailability_(availabilityURLs, callbacks);
53 } 53 }
54 54
55 public: 55 public:
56 MOCK_METHOD1(setController, void(WebPresentationController*)); 56 MOCK_METHOD1(setController, void(WebPresentationController*));
57 57
58 MOCK_METHOD1(setReceiver, void(WebPresentationReceiver*)); 58 MOCK_METHOD1(setReceiver, void(WebPresentationReceiver*));
59 59
60 MOCK_METHOD2(startSession_, 60 MOCK_METHOD2(startPresentation_,
61 void(const WebVector<WebURL>& presentationUrls, 61 void(const WebVector<WebURL>& presentationUrls,
62 std::unique_ptr<WebPresentationConnectionCallbacks>&)); 62 std::unique_ptr<WebPresentationConnectionCallbacks>&));
63 63
64 MOCK_METHOD3(joinSession_, 64 MOCK_METHOD3(reconnectPresentation_,
65 void(const WebVector<WebURL>& presentationUrls, 65 void(const WebVector<WebURL>& presentationUrls,
66 const WebString& presentationId, 66 const WebString& presentationId,
67 std::unique_ptr<WebPresentationConnectionCallbacks>&)); 67 std::unique_ptr<WebPresentationConnectionCallbacks>&));
68 68
69 MOCK_METHOD4(sendString, 69 MOCK_METHOD4(sendString,
70 void(const WebURL& presentationUrl, 70 void(const WebURL& presentationUrl,
71 const WebString& presentationId, 71 const WebString& presentationId,
72 const WebString& message, 72 const WebString& message,
73 const WebPresentationConnectionProxy* proxy)); 73 const WebPresentationConnectionProxy* proxy));
74 74
75 MOCK_METHOD5(sendArrayBuffer, 75 MOCK_METHOD5(sendArrayBuffer,
76 void(const WebURL& presentationUrl, 76 void(const WebURL& presentationUrl,
77 const WebString& presentationId, 77 const WebString& presentationId,
78 const uint8_t* data, 78 const uint8_t* data,
79 size_t length, 79 size_t length,
80 const WebPresentationConnectionProxy* proxy)); 80 const WebPresentationConnectionProxy* proxy));
81 81
82 MOCK_METHOD5(sendBlobData, 82 MOCK_METHOD5(sendBlobData,
83 void(const WebURL& presentationUrl, 83 void(const WebURL& presentationUrl,
84 const WebString& presentationId, 84 const WebString& presentationId,
85 const uint8_t* data, 85 const uint8_t* data,
86 size_t length, 86 size_t length,
87 const WebPresentationConnectionProxy* proxy)); 87 const WebPresentationConnectionProxy* proxy));
88 88
89 MOCK_METHOD3(closeSession, 89 MOCK_METHOD3(closeConnection,
90 void(const WebURL& presentationUrl, 90 void(const WebURL& presentationUrl,
91 const WebString& presentationId, 91 const WebString& presentationId,
92 const WebPresentationConnectionProxy*)); 92 const WebPresentationConnectionProxy*));
93 93
94 MOCK_METHOD2(terminateConnection, 94 MOCK_METHOD2(terminatePresentation,
95 void(const WebURL& presentationUrl, 95 void(const WebURL& presentationUrl,
96 const WebString& presentationId)); 96 const WebString& presentationId));
97 97
98 MOCK_METHOD2(getAvailability_, 98 MOCK_METHOD2(getAvailability_,
99 void(const WebVector<WebURL>& availabilityUrls, 99 void(const WebVector<WebURL>& availabilityUrls,
100 std::unique_ptr<WebPresentationAvailabilityCallbacks>&)); 100 std::unique_ptr<WebPresentationAvailabilityCallbacks>&));
101 101
102 MOCK_METHOD1(startListening, void(WebPresentationAvailabilityObserver*)); 102 MOCK_METHOD1(startListening, void(WebPresentationAvailabilityObserver*));
103 103
104 MOCK_METHOD1(stopListening, void(WebPresentationAvailabilityObserver*)); 104 MOCK_METHOD1(stopListening, void(WebPresentationAvailabilityObserver*));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 auto receiver = new PresentationReceiver(&scope.frame(), nullptr); 157 auto receiver = new PresentationReceiver(&scope.frame(), nullptr);
158 158
159 auto eventHandler = new StrictMock<MockEventListener>(); 159 auto eventHandler = new StrictMock<MockEventListener>();
160 addConnectionavailableEventListener(eventHandler, receiver); 160 addConnectionavailableEventListener(eventHandler, receiver);
161 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(0); 161 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(0);
162 162
163 receiver->connectionList(scope.getScriptState()); 163 receiver->connectionList(scope.getScriptState());
164 164
165 // Receive first connection. 165 // Receive first connection.
166 receiver->onReceiverConnectionAvailable( 166 receiver->onReceiverConnectionAvailable(
167 WebPresentationSessionInfo(KURL(KURL(), "http://example.com"), "id")); 167 WebPresentationInfo(KURL(KURL(), "http://example.com"), "id"));
168 168
169 verifyConnectionListPropertyState(ScriptPromisePropertyBase::Resolved, 169 verifyConnectionListPropertyState(ScriptPromisePropertyBase::Resolved,
170 receiver); 170 receiver);
171 verifyConnectionListSize(1, receiver); 171 verifyConnectionListSize(1, receiver);
172 } 172 }
173 173
174 TEST_F(PresentationReceiverTest, TwoConnectionsFireOnconnectionavailableEvent) { 174 TEST_F(PresentationReceiverTest, TwoConnectionsFireOnconnectionavailableEvent) {
175 V8TestingScope scope; 175 V8TestingScope scope;
176 auto receiver = new PresentationReceiver(&scope.frame(), nullptr); 176 auto receiver = new PresentationReceiver(&scope.frame(), nullptr);
177 177
178 StrictMock<MockEventListener>* eventHandler = 178 StrictMock<MockEventListener>* eventHandler =
179 new StrictMock<MockEventListener>(); 179 new StrictMock<MockEventListener>();
180 addConnectionavailableEventListener(eventHandler, receiver); 180 addConnectionavailableEventListener(eventHandler, receiver);
181 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(1); 181 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(1);
182 182
183 receiver->connectionList(scope.getScriptState()); 183 receiver->connectionList(scope.getScriptState());
184 184
185 WebPresentationSessionInfo sessionInfo(KURL(KURL(), "http://example.com"), 185 WebPresentationInfo presentationInfo(KURL(KURL(), "http://example.com"),
186 "id"); 186 "id");
187 // Receive first connection. 187 // Receive first connection.
188 receiver->onReceiverConnectionAvailable(sessionInfo); 188 receiver->onReceiverConnectionAvailable(presentationInfo);
189 // Receive second connection. 189 // Receive second connection.
190 receiver->onReceiverConnectionAvailable(sessionInfo); 190 receiver->onReceiverConnectionAvailable(presentationInfo);
191 191
192 verifyConnectionListSize(2, receiver); 192 verifyConnectionListSize(2, receiver);
193 } 193 }
194 194
195 TEST_F(PresentationReceiverTest, TwoConnectionsNoEvent) { 195 TEST_F(PresentationReceiverTest, TwoConnectionsNoEvent) {
196 V8TestingScope scope; 196 V8TestingScope scope;
197 auto receiver = new PresentationReceiver(&scope.frame(), nullptr); 197 auto receiver = new PresentationReceiver(&scope.frame(), nullptr);
198 198
199 StrictMock<MockEventListener>* eventHandler = 199 StrictMock<MockEventListener>* eventHandler =
200 new StrictMock<MockEventListener>(); 200 new StrictMock<MockEventListener>();
201 addConnectionavailableEventListener(eventHandler, receiver); 201 addConnectionavailableEventListener(eventHandler, receiver);
202 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(0); 202 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(0);
203 203
204 WebPresentationSessionInfo sessionInfo(KURL(KURL(), "http://example.com"), 204 WebPresentationInfo presentationInfo(KURL(KURL(), "http://example.com"),
205 "id"); 205 "id");
206 // Receive first connection. 206 // Receive first connection.
207 auto* connection1 = receiver->onReceiverConnectionAvailable(sessionInfo); 207 auto* connection1 = receiver->onReceiverConnectionAvailable(presentationInfo);
208 EXPECT_TRUE(connection1); 208 EXPECT_TRUE(connection1);
209 209
210 // Receive second connection. 210 // Receive second connection.
211 auto* connection2 = receiver->onReceiverConnectionAvailable(sessionInfo); 211 auto* connection2 = receiver->onReceiverConnectionAvailable(presentationInfo);
212 EXPECT_TRUE(connection2); 212 EXPECT_TRUE(connection2);
213 213
214 receiver->connectionList(scope.getScriptState()); 214 receiver->connectionList(scope.getScriptState());
215 verifyConnectionListPropertyState(ScriptPromisePropertyBase::Resolved, 215 verifyConnectionListPropertyState(ScriptPromisePropertyBase::Resolved,
216 receiver); 216 receiver);
217 verifyConnectionListSize(2, receiver); 217 verifyConnectionListSize(2, receiver);
218 } 218 }
219 219
220 TEST_F(PresentationReceiverTest, CreateReceiver) { 220 TEST_F(PresentationReceiverTest, CreateReceiver) {
221 MockWebPresentationClient client; 221 MockWebPresentationClient client;
222 EXPECT_CALL(client, setReceiver(testing::_)); 222 EXPECT_CALL(client, setReceiver(testing::_));
223 223
224 V8TestingScope scope; 224 V8TestingScope scope;
225 new PresentationReceiver(&scope.frame(), &client); 225 new PresentationReceiver(&scope.frame(), &client);
226 } 226 }
227 227
228 } // namespace blink 228 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698