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

Side by Side Diff: content/renderer/presentation/presentation_dispatcher_unittest.cc

Issue 2613153003: [Presentation API] Replaces type converters with typemaps (Closed)
Patch Set: Add more OWNERS foo Created 3 years, 10 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 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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "content/public/test/test_browser_thread_bundle.h" 9 #include "content/public/test/test_browser_thread_bundle.h"
10 #include "content/renderer/presentation/presentation_dispatcher.h" 10 #include "content/renderer/presentation/presentation_dispatcher.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h" 12 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h"
13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" 13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h"
14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nSessionInfo.h" 14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nSessionInfo.h"
15 #include "third_party/WebKit/public/web/WebArrayBuffer.h" 15 #include "third_party/WebKit/public/web/WebArrayBuffer.h"
16 16
17 using ::testing::_; 17 using ::testing::_;
18 using ::testing::Invoke; 18 using ::testing::Invoke;
19 using blink::WebArrayBuffer; 19 using blink::WebArrayBuffer;
20 using blink::WebPresentationAvailabilityCallbacks; 20 using blink::WebPresentationAvailabilityCallbacks;
21 using blink::WebPresentationAvailabilityObserver; 21 using blink::WebPresentationAvailabilityObserver;
22 using blink::WebPresentationConnectionCallback; 22 using blink::WebPresentationConnectionCallback;
23 using blink::WebPresentationError; 23 using blink::WebPresentationError;
24 using blink::WebPresentationSessionInfo; 24 using blink::WebPresentationSessionInfo;
25 using blink::WebString; 25 using blink::WebString;
26 using blink::WebURL; 26 using blink::WebURL;
27 using blink::WebVector; 27 using blink::WebVector;
28 using blink::mojom::PresentationConnection; 28 using blink::mojom::PresentationConnection;
29 using blink::mojom::PresentationError;
30 using blink::mojom::PresentationErrorPtr;
31 using blink::mojom::PresentationErrorType;
32 using blink::mojom::PresentationService; 29 using blink::mojom::PresentationService;
33 using blink::mojom::PresentationServiceClientPtr; 30 using blink::mojom::PresentationServiceClientPtr;
34 using blink::mojom::PresentationSessionInfo;
35 using blink::mojom::PresentationSessionInfoPtr;
36 using blink::mojom::ConnectionMessage; 31 using blink::mojom::ConnectionMessage;
37 using blink::mojom::ConnectionMessagePtr; 32 using blink::mojom::ConnectionMessagePtr;
38 33
39 // TODO(crbug.com/576808): Add test cases for the following: 34 // TODO(crbug.com/576808): Add test cases for the following:
40 // - State changes 35 // - State changes
41 // - Messages received 36 // - Messages received
42 // - Discarding queued messages when the frame navigates 37 // - Discarding queued messages when the frame navigates
43 // - Screen availability not supported 38 // - Screen availability not supported
44 // - Default presentation starting 39 // - Default presentation starting
45 40
(...skipping 24 matching lines...) Expand all
70 void(const std::vector<GURL>& presentation_urls, 65 void(const std::vector<GURL>& presentation_urls,
71 const StartSessionCallback& callback)); 66 const StartSessionCallback& callback));
72 MOCK_METHOD3(JoinSession, 67 MOCK_METHOD3(JoinSession,
73 void(const std::vector<GURL>& presentation_urls, 68 void(const std::vector<GURL>& presentation_urls,
74 const base::Optional<std::string>& presentation_id, 69 const base::Optional<std::string>& presentation_id,
75 const JoinSessionCallback& callback)); 70 const JoinSessionCallback& callback));
76 71
77 // *Internal method is to work around lack of support for move-only types in 72 // *Internal method is to work around lack of support for move-only types in
78 // GMock. 73 // GMock.
79 void SendConnectionMessage( 74 void SendConnectionMessage(
80 PresentationSessionInfoPtr session_info, 75 const PresentationSessionInfo& session_info,
81 ConnectionMessagePtr message_request, 76 ConnectionMessagePtr message_request,
82 const SendConnectionMessageCallback& callback) override { 77 const SendConnectionMessageCallback& callback) override {
83 SendConnectionMessageInternal(session_info.get(), message_request.get(), 78 SendConnectionMessageInternal(session_info, message_request.get(),
84 callback); 79 callback);
85 } 80 }
86 MOCK_METHOD3(SendConnectionMessageInternal, 81 MOCK_METHOD3(SendConnectionMessageInternal,
87 void(PresentationSessionInfo* session_info, 82 void(const PresentationSessionInfo& session_info,
88 ConnectionMessage* message_request, 83 ConnectionMessage* message_request,
89 const SendConnectionMessageCallback& callback)); 84 const SendConnectionMessageCallback& callback));
90 85
91 MOCK_METHOD2(CloseConnection, 86 MOCK_METHOD2(CloseConnection,
92 void(const GURL& presentation_url, 87 void(const GURL& presentation_url,
93 const std::string& presentation_id)); 88 const std::string& presentation_id));
94 MOCK_METHOD2(Terminate, 89 MOCK_METHOD2(Terminate,
95 void(const GURL& presentation_url, 90 void(const GURL& presentation_url,
96 const std::string& presentation_id)); 91 const std::string& presentation_id));
97 92
98 // *Internal method is to work around lack of support for move-only types in 93 MOCK_METHOD1(ListenForConnectionMessages,
99 // GMock. 94 void(const PresentationSessionInfo& session_info));
100 void ListenForConnectionMessages(
101 PresentationSessionInfoPtr session_info) override {
102 ListenForConnectionMessagesInternal(session_info.get());
103 }
104 MOCK_METHOD1(ListenForConnectionMessagesInternal,
105 void(PresentationSessionInfo* session_info));
106 95
107 void SetPresentationConnection( 96 void SetPresentationConnection(
108 blink::mojom::PresentationSessionInfoPtr session, 97 const PresentationSessionInfo& session_info,
109 blink::mojom::PresentationConnectionPtr controller_conn_ptr, 98 blink::mojom::PresentationConnectionPtr controller_conn_ptr,
110 blink::mojom::PresentationConnectionRequest receiver_conn_request) 99 blink::mojom::PresentationConnectionRequest receiver_conn_request)
111 override { 100 override {
112 SetPresentationConnection(session.get(), controller_conn_ptr.get()); 101 SetPresentationConnection(session_info, controller_conn_ptr.get());
113 } 102 }
114 MOCK_METHOD2(SetPresentationConnection, 103 MOCK_METHOD2(SetPresentationConnection,
115 void(PresentationSessionInfo* session_info, 104 void(const PresentationSessionInfo& session_info,
116 PresentationConnection* connection)); 105 PresentationConnection* connection));
117 }; 106 };
118 107
119 class TestWebPresentationConnectionCallback 108 class TestWebPresentationConnectionCallback
120 : public WebPresentationConnectionCallback { 109 : public WebPresentationConnectionCallback {
121 public: 110 public:
122 TestWebPresentationConnectionCallback(WebURL url, WebString id) 111 TestWebPresentationConnectionCallback(WebURL url, WebString id)
123 : url_(url), id_(id), callback_called_(false) {} 112 : url_(url), id_(id), callback_called_(false) {}
124 ~TestWebPresentationConnectionCallback() override { 113 ~TestWebPresentationConnectionCallback() override {
125 EXPECT_TRUE(callback_called_); 114 EXPECT_TRUE(callback_called_);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 content::TestBrowserThreadBundle thread_bundle_; 211 content::TestBrowserThreadBundle thread_bundle_;
223 }; 212 };
224 213
225 TEST_F(PresentationDispatcherTest, TestStartSession) { 214 TEST_F(PresentationDispatcherTest, TestStartSession) {
226 base::RunLoop run_loop; 215 base::RunLoop run_loop;
227 216
228 EXPECT_CALL(presentation_service_, StartSession(gurls_, _)) 217 EXPECT_CALL(presentation_service_, StartSession(gurls_, _))
229 .WillOnce(Invoke([this]( 218 .WillOnce(Invoke([this](
230 const std::vector<GURL>& presentation_urls, 219 const std::vector<GURL>& presentation_urls,
231 const PresentationService::StartSessionCallback& callback) { 220 const PresentationService::StartSessionCallback& callback) {
232 PresentationSessionInfoPtr session_info(PresentationSessionInfo::New()); 221 PresentationSessionInfo session_info(gurl1_, presentation_id_.utf8());
233 session_info->url = gurl1_; 222 callback.Run(session_info, base::nullopt);
234 session_info->id = presentation_id_.utf8();
235 callback.Run(std::move(session_info), PresentationErrorPtr());
236 })); 223 }));
237 dispatcher_.startSession( 224 dispatcher_.startSession(
238 urls_, base::MakeUnique<TestWebPresentationConnectionCallback>( 225 urls_, base::MakeUnique<TestWebPresentationConnectionCallback>(
239 url1_, presentation_id_)); 226 url1_, presentation_id_));
240 run_loop.RunUntilIdle(); 227 run_loop.RunUntilIdle();
241 } 228 }
242 229
243 TEST_F(PresentationDispatcherTest, TestStartSessionError) { 230 TEST_F(PresentationDispatcherTest, TestStartSessionError) {
244 WebString error_message = WebString::fromUTF8("Test error message"); 231 WebString error_message = WebString::fromUTF8("Test error message");
245 base::RunLoop run_loop; 232 base::RunLoop run_loop;
246 233
247 EXPECT_CALL(presentation_service_, StartSession(gurls_, _)) 234 EXPECT_CALL(presentation_service_, StartSession(gurls_, _))
248 .WillOnce(Invoke([this, &error_message]( 235 .WillOnce(Invoke([this, &error_message](
249 const std::vector<GURL>& presentation_urls, 236 const std::vector<GURL>& presentation_urls,
250 const PresentationService::StartSessionCallback& callback) { 237 const PresentationService::StartSessionCallback& callback) {
251 PresentationErrorPtr error(PresentationError::New()); 238 PresentationError error(PRESENTATION_ERROR_NO_AVAILABLE_SCREENS,
252 error->error_type = PresentationErrorType::NO_AVAILABLE_SCREENS; 239 error_message.utf8());
253 error->message = error_message.utf8(); 240 callback.Run(base::nullopt, error);
254 callback.Run(PresentationSessionInfoPtr(), std::move(error));
255 })); 241 }));
256 dispatcher_.startSession( 242 dispatcher_.startSession(
257 urls_, 243 urls_,
258 base::MakeUnique<TestWebPresentationConnectionErrorCallback>( 244 base::MakeUnique<TestWebPresentationConnectionErrorCallback>(
259 WebPresentationError::ErrorTypeNoAvailableScreens, error_message)); 245 WebPresentationError::ErrorTypeNoAvailableScreens, error_message));
260 run_loop.RunUntilIdle(); 246 run_loop.RunUntilIdle();
261 } 247 }
262 248
263 TEST_F(PresentationDispatcherTest, TestJoinSessionError) { 249 TEST_F(PresentationDispatcherTest, TestJoinSessionError) {
264 WebString error_message = WebString::fromUTF8("Test error message"); 250 WebString error_message = WebString::fromUTF8("Test error message");
265 base::RunLoop run_loop; 251 base::RunLoop run_loop;
266 252
267 EXPECT_CALL(presentation_service_, JoinSession(gurls_, _, _)) 253 EXPECT_CALL(presentation_service_, JoinSession(gurls_, _, _))
268 .WillOnce(Invoke([this, &error_message]( 254 .WillOnce(Invoke([this, &error_message](
269 const std::vector<GURL>& presentation_urls, 255 const std::vector<GURL>& presentation_urls,
270 const base::Optional<std::string>& presentation_id, 256 const base::Optional<std::string>& presentation_id,
271 const PresentationService::JoinSessionCallback& callback) { 257 const PresentationService::JoinSessionCallback& callback) {
272 EXPECT_TRUE(presentation_id.has_value()); 258 EXPECT_TRUE(presentation_id.has_value());
273 EXPECT_EQ(presentation_id_.utf8(), presentation_id.value()); 259 EXPECT_EQ(presentation_id_.utf8(), presentation_id.value());
274 PresentationErrorPtr error(PresentationError::New()); 260 PresentationError error(PRESENTATION_ERROR_NO_AVAILABLE_SCREENS,
275 error->error_type = PresentationErrorType::NO_AVAILABLE_SCREENS; 261 error_message.utf8());
276 error->message = error_message.utf8(); 262 callback.Run(base::nullopt, error);
277 callback.Run(PresentationSessionInfoPtr(), std::move(error));
278 })); 263 }));
279 dispatcher_.joinSession( 264 dispatcher_.joinSession(
280 urls_, presentation_id_, 265 urls_, presentation_id_,
281 base::MakeUnique<TestWebPresentationConnectionErrorCallback>( 266 base::MakeUnique<TestWebPresentationConnectionErrorCallback>(
282 WebPresentationError::ErrorTypeNoAvailableScreens, error_message)); 267 WebPresentationError::ErrorTypeNoAvailableScreens, error_message));
283 run_loop.RunUntilIdle(); 268 run_loop.RunUntilIdle();
284 } 269 }
285 270
286 TEST_F(PresentationDispatcherTest, TestJoinSession) { 271 TEST_F(PresentationDispatcherTest, TestJoinSession) {
287 base::RunLoop run_loop; 272 base::RunLoop run_loop;
288 273
289 EXPECT_CALL(presentation_service_, JoinSession(gurls_, _, _)) 274 EXPECT_CALL(presentation_service_, JoinSession(gurls_, _, _))
290 .WillOnce(Invoke([this]( 275 .WillOnce(Invoke([this](
291 const std::vector<GURL>& presentation_urls, 276 const std::vector<GURL>& presentation_urls,
292 const base::Optional<std::string>& presentation_id, 277 const base::Optional<std::string>& presentation_id,
293 const PresentationService::JoinSessionCallback& callback) { 278 const PresentationService::JoinSessionCallback& callback) {
294 EXPECT_TRUE(presentation_id.has_value()); 279 EXPECT_TRUE(presentation_id.has_value());
295 EXPECT_EQ(presentation_id_.utf8(), presentation_id.value()); 280 EXPECT_EQ(presentation_id_.utf8(), presentation_id.value());
296 PresentationSessionInfoPtr session_info(PresentationSessionInfo::New()); 281 PresentationSessionInfo session_info(gurl1_, presentation_id_.utf8());
297 session_info->url = gurl1_; 282 callback.Run(session_info, base::nullopt);
298 session_info->id = presentation_id_.utf8();
299 callback.Run(std::move(session_info), PresentationErrorPtr());
300 })); 283 }));
301 dispatcher_.joinSession( 284 dispatcher_.joinSession(
302 urls_, presentation_id_, 285 urls_, presentation_id_,
303 base::MakeUnique<TestWebPresentationConnectionCallback>( 286 base::MakeUnique<TestWebPresentationConnectionCallback>(
304 url1_, presentation_id_)); 287 url1_, presentation_id_));
305 run_loop.RunUntilIdle(); 288 run_loop.RunUntilIdle();
306 } 289 }
307 290
308 TEST_F(PresentationDispatcherTest, TestSendString) { 291 TEST_F(PresentationDispatcherTest, TestSendString) {
309 WebString message = WebString::fromUTF8("test message"); 292 WebString message = WebString::fromUTF8("test message");
310 base::RunLoop run_loop; 293 base::RunLoop run_loop;
311 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) 294 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _))
312 .WillOnce(Invoke([this, &message]( 295 .WillOnce(Invoke([this, &message](
313 PresentationSessionInfo* session_info, 296 const PresentationSessionInfo& session_info,
314 ConnectionMessage* message_request, 297 ConnectionMessage* message_request,
315 const PresentationService::SendConnectionMessageCallback& callback) { 298 const PresentationService::SendConnectionMessageCallback& callback) {
316 EXPECT_EQ(gurl1_, session_info->url); 299 EXPECT_EQ(gurl1_, session_info.presentation_url);
317 EXPECT_EQ(presentation_id_.utf8(), session_info->id); 300 EXPECT_EQ(presentation_id_.utf8(), session_info.presentation_id);
318 EXPECT_TRUE(message_request->message.has_value()); 301 EXPECT_TRUE(message_request->message.has_value());
319 EXPECT_EQ(message.utf8(), message_request->message.value()); 302 EXPECT_EQ(message.utf8(), message_request->message.value());
320 callback.Run(true); 303 callback.Run(true);
321 })); 304 }));
322 dispatcher_.sendString(url1_, presentation_id_, message); 305 dispatcher_.sendString(url1_, presentation_id_, message);
323 run_loop.RunUntilIdle(); 306 run_loop.RunUntilIdle();
324 } 307 }
325 308
326 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { 309 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) {
327 base::RunLoop run_loop; 310 base::RunLoop run_loop;
328 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) 311 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _))
329 .WillOnce(Invoke([this]( 312 .WillOnce(Invoke([this](
330 PresentationSessionInfo* session_info, 313 const PresentationSessionInfo& session_info,
331 ConnectionMessage* message_request, 314 ConnectionMessage* message_request,
332 const PresentationService::SendConnectionMessageCallback& callback) { 315 const PresentationService::SendConnectionMessageCallback& callback) {
333 EXPECT_EQ(gurl1_, session_info->url); 316 EXPECT_EQ(gurl1_, session_info.presentation_url);
334 EXPECT_EQ(presentation_id_.utf8(), session_info->id); 317 EXPECT_EQ(presentation_id_.utf8(), session_info.presentation_id);
335 std::vector<uint8_t> data( 318 std::vector<uint8_t> data(
336 array_buffer_data(), 319 array_buffer_data(),
337 array_buffer_data() + array_buffer_.byteLength()); 320 array_buffer_data() + array_buffer_.byteLength());
338 EXPECT_TRUE(message_request->data.has_value()); 321 EXPECT_TRUE(message_request->data.has_value());
339 EXPECT_EQ(data, message_request->data.value()); 322 EXPECT_EQ(data, message_request->data.value());
340 callback.Run(true); 323 callback.Run(true);
341 })); 324 }));
342 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), 325 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(),
343 array_buffer_.byteLength()); 326 array_buffer_.byteLength());
344 run_loop.RunUntilIdle(); 327 run_loop.RunUntilIdle();
345 } 328 }
346 329
347 TEST_F(PresentationDispatcherTest, TestSendBlobData) { 330 TEST_F(PresentationDispatcherTest, TestSendBlobData) {
348 base::RunLoop run_loop; 331 base::RunLoop run_loop;
349 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) 332 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _))
350 .WillOnce(Invoke([this]( 333 .WillOnce(Invoke([this](
351 PresentationSessionInfo* session_info, 334 const PresentationSessionInfo& session_info,
352 ConnectionMessage* message_request, 335 ConnectionMessage* message_request,
353 const PresentationService::SendConnectionMessageCallback& callback) { 336 const PresentationService::SendConnectionMessageCallback& callback) {
354 EXPECT_EQ(gurl1_, session_info->url); 337 EXPECT_EQ(gurl1_, session_info.presentation_url);
355 EXPECT_EQ(presentation_id_.utf8(), session_info->id); 338 EXPECT_EQ(presentation_id_.utf8(), session_info.presentation_id);
356 std::vector<uint8_t> data( 339 std::vector<uint8_t> data(
357 array_buffer_data(), 340 array_buffer_data(),
358 array_buffer_data() + array_buffer_.byteLength()); 341 array_buffer_data() + array_buffer_.byteLength());
359 EXPECT_TRUE(message_request->data.has_value()); 342 EXPECT_TRUE(message_request->data.has_value());
360 EXPECT_EQ(data, message_request->data.value()); 343 EXPECT_EQ(data, message_request->data.value());
361 callback.Run(true); 344 callback.Run(true);
362 })); 345 }));
363 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), 346 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(),
364 array_buffer_.byteLength()); 347 array_buffer_.byteLength());
365 run_loop.RunUntilIdle(); 348 run_loop.RunUntilIdle();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 395 }
413 396
414 TEST_F(PresentationDispatcherTest, TestSetDefaultPresentationUrls) { 397 TEST_F(PresentationDispatcherTest, TestSetDefaultPresentationUrls) {
415 base::RunLoop run_loop; 398 base::RunLoop run_loop;
416 EXPECT_CALL(presentation_service_, SetDefaultPresentationUrls(gurls_)); 399 EXPECT_CALL(presentation_service_, SetDefaultPresentationUrls(gurls_));
417 dispatcher_.setDefaultPresentationUrls(urls_); 400 dispatcher_.setDefaultPresentationUrls(urls_);
418 run_loop.RunUntilIdle(); 401 run_loop.RunUntilIdle();
419 } 402 }
420 403
421 } // namespace content 404 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698