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

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

Issue 2613153003: [Presentation API] Replaces type converters with typemaps (Closed)
Patch Set: Extend presentation ID max length to 64. 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
« no previous file with comments | « content/renderer/presentation/presentation_dispatcher.cc ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_connection_proxy.h" 10 #include "content/renderer/presentation/presentation_connection_proxy.h"
(...skipping 13 matching lines...) Expand all
24 using blink::WebArrayBuffer; 24 using blink::WebArrayBuffer;
25 using blink::WebPresentationAvailabilityCallbacks; 25 using blink::WebPresentationAvailabilityCallbacks;
26 using blink::WebPresentationAvailabilityObserver; 26 using blink::WebPresentationAvailabilityObserver;
27 using blink::WebPresentationConnectionCallbacks; 27 using blink::WebPresentationConnectionCallbacks;
28 using blink::WebPresentationError; 28 using blink::WebPresentationError;
29 using blink::WebPresentationSessionInfo; 29 using blink::WebPresentationSessionInfo;
30 using blink::WebString; 30 using blink::WebString;
31 using blink::WebURL; 31 using blink::WebURL;
32 using blink::WebVector; 32 using blink::WebVector;
33 using blink::mojom::PresentationConnection; 33 using blink::mojom::PresentationConnection;
34 using blink::mojom::PresentationError;
35 using blink::mojom::PresentationErrorPtr;
36 using blink::mojom::PresentationErrorType;
37 using blink::mojom::PresentationService; 34 using blink::mojom::PresentationService;
38 using blink::mojom::PresentationServiceClientPtr; 35 using blink::mojom::PresentationServiceClientPtr;
39 using blink::mojom::PresentationSessionInfo;
40 using blink::mojom::PresentationSessionInfoPtr;
41 using blink::mojom::ConnectionMessage; 36 using blink::mojom::ConnectionMessage;
42 using blink::mojom::ConnectionMessagePtr; 37 using blink::mojom::ConnectionMessagePtr;
43 38
44 // TODO(crbug.com/576808): Add test cases for the following: 39 // TODO(crbug.com/576808): Add test cases for the following:
45 // - State changes 40 // - State changes
46 // - Messages received 41 // - Messages received
47 // - Discarding queued messages when the frame navigates 42 // - Discarding queued messages when the frame navigates
48 // - Screen availability not supported 43 // - Screen availability not supported
49 // - Default presentation starting 44 // - Default presentation starting
50 45
(...skipping 25 matching lines...) Expand all
76 void(const std::vector<GURL>& presentation_urls, 71 void(const std::vector<GURL>& presentation_urls,
77 const StartSessionCallback& callback)); 72 const StartSessionCallback& callback));
78 MOCK_METHOD3(JoinSession, 73 MOCK_METHOD3(JoinSession,
79 void(const std::vector<GURL>& presentation_urls, 74 void(const std::vector<GURL>& presentation_urls,
80 const base::Optional<std::string>& presentation_id, 75 const base::Optional<std::string>& presentation_id,
81 const JoinSessionCallback& callback)); 76 const JoinSessionCallback& callback));
82 77
83 // *Internal method is to work around lack of support for move-only types in 78 // *Internal method is to work around lack of support for move-only types in
84 // GMock. 79 // GMock.
85 void SendConnectionMessage( 80 void SendConnectionMessage(
86 PresentationSessionInfoPtr session_info, 81 const PresentationSessionInfo& session_info,
87 ConnectionMessagePtr message_request, 82 ConnectionMessagePtr message_request,
88 const SendConnectionMessageCallback& callback) override { 83 const SendConnectionMessageCallback& callback) override {
89 SendConnectionMessageInternal(session_info.get(), message_request.get(), 84 SendConnectionMessageInternal(session_info, message_request.get(),
90 callback); 85 callback);
91 } 86 }
92 MOCK_METHOD3(SendConnectionMessageInternal, 87 MOCK_METHOD3(SendConnectionMessageInternal,
93 void(PresentationSessionInfo* session_info, 88 void(const PresentationSessionInfo& session_info,
94 ConnectionMessage* message_request, 89 ConnectionMessage* message_request,
95 const SendConnectionMessageCallback& callback)); 90 const SendConnectionMessageCallback& callback));
96 91
97 MOCK_METHOD2(CloseConnection, 92 MOCK_METHOD2(CloseConnection,
98 void(const GURL& presentation_url, 93 void(const GURL& presentation_url,
99 const std::string& presentation_id)); 94 const std::string& presentation_id));
100 MOCK_METHOD2(Terminate, 95 MOCK_METHOD2(Terminate,
101 void(const GURL& presentation_url, 96 void(const GURL& presentation_url,
102 const std::string& presentation_id)); 97 const std::string& presentation_id));
103 98
104 // *Internal method is to work around lack of support for move-only types in 99 MOCK_METHOD1(ListenForConnectionMessages,
105 // GMock. 100 void(const PresentationSessionInfo& session_info));
106 void ListenForConnectionMessages(
107 PresentationSessionInfoPtr session_info) override {
108 ListenForConnectionMessagesInternal(session_info.get());
109 }
110 MOCK_METHOD1(ListenForConnectionMessagesInternal,
111 void(PresentationSessionInfo* session_info));
112 101
113 void SetPresentationConnection( 102 void SetPresentationConnection(
114 blink::mojom::PresentationSessionInfoPtr session, 103 const PresentationSessionInfo& session_info,
115 blink::mojom::PresentationConnectionPtr controller_conn_ptr, 104 blink::mojom::PresentationConnectionPtr controller_conn_ptr,
116 blink::mojom::PresentationConnectionRequest receiver_conn_request) 105 blink::mojom::PresentationConnectionRequest receiver_conn_request)
117 override { 106 override {
118 SetPresentationConnection(session.get(), controller_conn_ptr.get()); 107 SetPresentationConnection(session_info, controller_conn_ptr.get());
119 } 108 }
120 MOCK_METHOD2(SetPresentationConnection, 109 MOCK_METHOD2(SetPresentationConnection,
121 void(PresentationSessionInfo* session_info, 110 void(const PresentationSessionInfo& session_info,
122 PresentationConnection* connection)); 111 PresentationConnection* connection));
123 }; 112 };
124 113
125 class MockPresentationAvailabilityCallbacks 114 class MockPresentationAvailabilityCallbacks
126 : public blink::WebCallbacks<bool, const blink::WebPresentationError&> { 115 : public blink::WebCallbacks<bool, const blink::WebPresentationError&> {
127 public: 116 public:
128 MOCK_METHOD1(onSuccess, void(bool value)); 117 MOCK_METHOD1(onSuccess, void(bool value));
129 MOCK_METHOD1(onError, void(const blink::WebPresentationError&)); 118 MOCK_METHOD1(onError, void(const blink::WebPresentationError&));
130 }; 119 };
131 120
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 content::TestBrowserThreadBundle thread_bundle_; 294 content::TestBrowserThreadBundle thread_bundle_;
306 }; 295 };
307 296
308 TEST_F(PresentationDispatcherTest, TestStartSession) { 297 TEST_F(PresentationDispatcherTest, TestStartSession) {
309 base::RunLoop run_loop; 298 base::RunLoop run_loop;
310 299
311 EXPECT_CALL(presentation_service_, StartSession(gurls_, _)) 300 EXPECT_CALL(presentation_service_, StartSession(gurls_, _))
312 .WillOnce(Invoke([this]( 301 .WillOnce(Invoke([this](
313 const std::vector<GURL>& presentation_urls, 302 const std::vector<GURL>& presentation_urls,
314 const PresentationService::StartSessionCallback& callback) { 303 const PresentationService::StartSessionCallback& callback) {
315 PresentationSessionInfoPtr session_info(PresentationSessionInfo::New()); 304 PresentationSessionInfo session_info(gurl1_, presentation_id_.utf8());
316 session_info->url = gurl1_; 305 callback.Run(session_info, base::nullopt);
317 session_info->id = presentation_id_.utf8();
318 callback.Run(std::move(session_info), PresentationErrorPtr());
319 })); 306 }));
320 client()->startSession( 307 client()->startSession(
321 urls_, base::MakeUnique<TestWebPresentationConnectionCallback>( 308 urls_, base::MakeUnique<TestWebPresentationConnectionCallback>(
322 url1_, presentation_id_)); 309 url1_, presentation_id_));
323 run_loop.RunUntilIdle(); 310 run_loop.RunUntilIdle();
324 } 311 }
325 312
326 TEST_F(PresentationDispatcherTest, TestStartSessionError) { 313 TEST_F(PresentationDispatcherTest, TestStartSessionError) {
327 WebString error_message = WebString::fromUTF8("Test error message"); 314 WebString error_message = WebString::fromUTF8("Test error message");
328 base::RunLoop run_loop; 315 base::RunLoop run_loop;
329 316
330 EXPECT_CALL(presentation_service_, StartSession(gurls_, _)) 317 EXPECT_CALL(presentation_service_, StartSession(gurls_, _))
331 .WillOnce(Invoke([&error_message]( 318 .WillOnce(Invoke([&error_message](
332 const std::vector<GURL>& presentation_urls, 319 const std::vector<GURL>& presentation_urls,
333 const PresentationService::StartSessionCallback& callback) { 320 const PresentationService::StartSessionCallback& callback) {
334 PresentationErrorPtr error(PresentationError::New()); 321 callback.Run(
335 error->error_type = PresentationErrorType::NO_AVAILABLE_SCREENS; 322 base::nullopt,
336 error->message = error_message.utf8(); 323 PresentationError(content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS,
337 callback.Run(PresentationSessionInfoPtr(), std::move(error)); 324 error_message.utf8()));
338 })); 325 }));
339 client()->startSession( 326 client()->startSession(
340 urls_, 327 urls_,
341 base::MakeUnique<TestWebPresentationConnectionErrorCallback>( 328 base::MakeUnique<TestWebPresentationConnectionErrorCallback>(
342 WebPresentationError::ErrorTypeNoAvailableScreens, error_message)); 329 WebPresentationError::ErrorTypeNoAvailableScreens, error_message));
343 run_loop.RunUntilIdle(); 330 run_loop.RunUntilIdle();
344 } 331 }
345 332
346 TEST_F(PresentationDispatcherTest, TestJoinSessionError) { 333 TEST_F(PresentationDispatcherTest, TestJoinSessionError) {
347 WebString error_message = WebString::fromUTF8("Test error message"); 334 WebString error_message = WebString::fromUTF8("Test error message");
348 base::RunLoop run_loop; 335 base::RunLoop run_loop;
349 336
350 EXPECT_CALL(presentation_service_, JoinSession(gurls_, _, _)) 337 EXPECT_CALL(presentation_service_, JoinSession(gurls_, _, _))
351 .WillOnce(Invoke([this, &error_message]( 338 .WillOnce(Invoke([this, &error_message](
352 const std::vector<GURL>& presentation_urls, 339 const std::vector<GURL>& presentation_urls,
353 const base::Optional<std::string>& presentation_id, 340 const base::Optional<std::string>& presentation_id,
354 const PresentationService::JoinSessionCallback& callback) { 341 const PresentationService::JoinSessionCallback& callback) {
355 EXPECT_TRUE(presentation_id.has_value()); 342 EXPECT_TRUE(presentation_id.has_value());
356 EXPECT_EQ(presentation_id_.utf8(), presentation_id.value()); 343 EXPECT_EQ(presentation_id_.utf8(), presentation_id.value());
357 PresentationErrorPtr error(PresentationError::New()); 344 callback.Run(
358 error->error_type = PresentationErrorType::NO_AVAILABLE_SCREENS; 345 base::nullopt,
359 error->message = error_message.utf8(); 346 PresentationError(content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS,
360 callback.Run(PresentationSessionInfoPtr(), std::move(error)); 347 error_message.utf8()));
361 })); 348 }));
362 dispatcher_.joinSession( 349 dispatcher_.joinSession(
363 urls_, presentation_id_, 350 urls_, presentation_id_,
364 base::MakeUnique<TestWebPresentationConnectionErrorCallback>( 351 base::MakeUnique<TestWebPresentationConnectionErrorCallback>(
365 WebPresentationError::ErrorTypeNoAvailableScreens, error_message)); 352 WebPresentationError::ErrorTypeNoAvailableScreens, error_message));
366 run_loop.RunUntilIdle(); 353 run_loop.RunUntilIdle();
367 } 354 }
368 355
369 TEST_F(PresentationDispatcherTest, TestJoinSession) { 356 TEST_F(PresentationDispatcherTest, TestJoinSession) {
370 base::RunLoop run_loop; 357 base::RunLoop run_loop;
371 358
372 EXPECT_CALL(presentation_service_, JoinSession(gurls_, _, _)) 359 EXPECT_CALL(presentation_service_, JoinSession(gurls_, _, _))
373 .WillOnce(Invoke([this]( 360 .WillOnce(Invoke([this](
374 const std::vector<GURL>& presentation_urls, 361 const std::vector<GURL>& presentation_urls,
375 const base::Optional<std::string>& presentation_id, 362 const base::Optional<std::string>& presentation_id,
376 const PresentationService::JoinSessionCallback& callback) { 363 const PresentationService::JoinSessionCallback& callback) {
377 EXPECT_TRUE(presentation_id.has_value()); 364 EXPECT_TRUE(presentation_id.has_value());
378 EXPECT_EQ(presentation_id_.utf8(), presentation_id.value()); 365 EXPECT_EQ(presentation_id_.utf8(), presentation_id.value());
379 PresentationSessionInfoPtr session_info(PresentationSessionInfo::New()); 366 callback.Run(PresentationSessionInfo(gurl1_, presentation_id_.utf8()),
380 session_info->url = gurl1_; 367 base::nullopt);
381 session_info->id = presentation_id_.utf8();
382 callback.Run(std::move(session_info), PresentationErrorPtr());
383 })); 368 }));
384 dispatcher_.joinSession( 369 dispatcher_.joinSession(
385 urls_, presentation_id_, 370 urls_, presentation_id_,
386 base::MakeUnique<TestWebPresentationConnectionCallback>( 371 base::MakeUnique<TestWebPresentationConnectionCallback>(
387 url1_, presentation_id_)); 372 url1_, presentation_id_));
388 run_loop.RunUntilIdle(); 373 run_loop.RunUntilIdle();
389 } 374 }
390 375
391 TEST_F(PresentationDispatcherTest, TestSendString) { 376 TEST_F(PresentationDispatcherTest, TestSendString) {
392 WebString message = WebString::fromUTF8("test message"); 377 WebString message = WebString::fromUTF8("test message");
393 base::RunLoop run_loop; 378 base::RunLoop run_loop;
394 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) 379 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _))
395 .WillOnce(Invoke([this, &message]( 380 .WillOnce(Invoke([this, &message](
396 PresentationSessionInfo* session_info, 381 const PresentationSessionInfo& session_info,
397 ConnectionMessage* message_request, 382 ConnectionMessage* message_request,
398 const PresentationService::SendConnectionMessageCallback& callback) { 383 const PresentationService::SendConnectionMessageCallback& callback) {
399 EXPECT_EQ(gurl1_, session_info->url); 384 EXPECT_EQ(gurl1_, session_info.presentation_url);
400 EXPECT_EQ(presentation_id_.utf8(), session_info->id); 385 EXPECT_EQ(presentation_id_.utf8(), session_info.presentation_id);
401 EXPECT_TRUE(message_request->message.has_value()); 386 EXPECT_TRUE(message_request->message.has_value());
402 EXPECT_EQ(message.utf8(), message_request->message.value()); 387 EXPECT_EQ(message.utf8(), message_request->message.value());
403 callback.Run(true); 388 callback.Run(true);
404 })); 389 }));
405 dispatcher_.sendString(url1_, presentation_id_, message, nullptr); 390 dispatcher_.sendString(url1_, presentation_id_, message, nullptr);
406 run_loop.RunUntilIdle(); 391 run_loop.RunUntilIdle();
407 } 392 }
408 393
409 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { 394 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) {
410 base::RunLoop run_loop; 395 base::RunLoop run_loop;
411 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) 396 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _))
412 .WillOnce(Invoke([this]( 397 .WillOnce(Invoke([this](
413 PresentationSessionInfo* session_info, 398 const PresentationSessionInfo& session_info,
414 ConnectionMessage* message_request, 399 ConnectionMessage* message_request,
415 const PresentationService::SendConnectionMessageCallback& callback) { 400 const PresentationService::SendConnectionMessageCallback& callback) {
416 EXPECT_EQ(gurl1_, session_info->url); 401 EXPECT_EQ(gurl1_, session_info.presentation_url);
417 EXPECT_EQ(presentation_id_.utf8(), session_info->id); 402 EXPECT_EQ(presentation_id_.utf8(), session_info.presentation_id);
418 std::vector<uint8_t> data( 403 std::vector<uint8_t> data(
419 array_buffer_data(), 404 array_buffer_data(),
420 array_buffer_data() + array_buffer_.byteLength()); 405 array_buffer_data() + array_buffer_.byteLength());
421 EXPECT_TRUE(message_request->data.has_value()); 406 EXPECT_TRUE(message_request->data.has_value());
422 EXPECT_EQ(data, message_request->data.value()); 407 EXPECT_EQ(data, message_request->data.value());
423 callback.Run(true); 408 callback.Run(true);
424 })); 409 }));
425 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), 410 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(),
426 array_buffer_.byteLength(), nullptr); 411 array_buffer_.byteLength(), nullptr);
427 run_loop.RunUntilIdle(); 412 run_loop.RunUntilIdle();
428 } 413 }
429 414
430 TEST_F(PresentationDispatcherTest, TestSendBlobData) { 415 TEST_F(PresentationDispatcherTest, TestSendBlobData) {
431 base::RunLoop run_loop; 416 base::RunLoop run_loop;
432 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) 417 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _))
433 .WillOnce(Invoke([this]( 418 .WillOnce(Invoke([this](
434 PresentationSessionInfo* session_info, 419 const PresentationSessionInfo& session_info,
435 ConnectionMessage* message_request, 420 ConnectionMessage* message_request,
436 const PresentationService::SendConnectionMessageCallback& callback) { 421 const PresentationService::SendConnectionMessageCallback& callback) {
437 EXPECT_EQ(gurl1_, session_info->url); 422 EXPECT_EQ(gurl1_, session_info.presentation_url);
438 EXPECT_EQ(presentation_id_.utf8(), session_info->id); 423 EXPECT_EQ(presentation_id_.utf8(), session_info.presentation_id);
439 std::vector<uint8_t> data( 424 std::vector<uint8_t> data(
440 array_buffer_data(), 425 array_buffer_data(),
441 array_buffer_data() + array_buffer_.byteLength()); 426 array_buffer_data() + array_buffer_.byteLength());
442 EXPECT_TRUE(message_request->data.has_value()); 427 EXPECT_TRUE(message_request->data.has_value());
443 EXPECT_EQ(data, message_request->data.value()); 428 EXPECT_EQ(data, message_request->data.value());
444 callback.Run(true); 429 callback.Run(true);
445 })); 430 }));
446 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), 431 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(),
447 array_buffer_.byteLength(), nullptr); 432 array_buffer_.byteLength(), nullptr);
448 run_loop.RunUntilIdle(); 433 run_loop.RunUntilIdle();
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 712
728 for (auto* mock_observer : mock_observers_) 713 for (auto* mock_observer : mock_observers_)
729 EXPECT_CALL(*mock_observer, availabilityChanged(false)); 714 EXPECT_CALL(*mock_observer, availabilityChanged(false));
730 715
731 base::RunLoop run_loop_2; 716 base::RunLoop run_loop_2;
732 ChangeURLState(gurl2_, URLState::Unavailable); 717 ChangeURLState(gurl2_, URLState::Unavailable);
733 run_loop_2.RunUntilIdle(); 718 run_loop_2.RunUntilIdle();
734 } 719 }
735 720
736 } // namespace content 721 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/presentation/presentation_dispatcher.cc ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698