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 "content/browser/presentation/presentation_service_impl.h" | 5 #include "content/browser/presentation/presentation_service_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/public/browser/presentation_session.h" | 21 #include "content/public/browser/presentation_session.h" |
22 #include "content/public/common/presentation_constants.h" | 22 #include "content/public/common/presentation_constants.h" |
23 #include "content/test/test_render_frame_host.h" | 23 #include "content/test/test_render_frame_host.h" |
24 #include "content/test/test_render_view_host.h" | 24 #include "content/test/test_render_view_host.h" |
25 #include "content/test/test_web_contents.h" | 25 #include "content/test/test_web_contents.h" |
26 #include "mojo/public/cpp/bindings/interface_ptr.h" | 26 #include "mojo/public/cpp/bindings/interface_ptr.h" |
27 #include "mojo/public/cpp/bindings/string.h" | 27 #include "mojo/public/cpp/bindings/string.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
29 | 29 |
30 using ::testing::_; | 30 using ::testing::_; |
| 31 using ::testing::ByRef; |
31 using ::testing::Eq; | 32 using ::testing::Eq; |
32 using ::testing::InvokeWithoutArgs; | 33 using ::testing::InvokeWithoutArgs; |
33 using ::testing::Mock; | 34 using ::testing::Mock; |
34 using ::testing::Return; | 35 using ::testing::Return; |
35 using ::testing::SaveArg; | 36 using ::testing::SaveArg; |
36 | 37 |
37 namespace content { | 38 namespace content { |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
41 // Matches mojo structs. | 42 // Matches mojo structs. |
42 MATCHER_P(Equals, expected, "") { | 43 MATCHER_P(Equals, expected, "") { |
43 return expected.Equals(arg); | 44 return expected.Equals(arg); |
44 } | 45 } |
45 | 46 |
| 47 // Matches std::vector<std::string> to mojo::Array<mojo::String>. |
| 48 MATCHER_P(StringArrayEquals, expected, "") { |
| 49 // Unwrap reference passed by GMock. |
| 50 mojo::Array<mojo::String>& expected_array = expected; |
| 51 if (arg.size() != expected_array.size()) |
| 52 return false; |
| 53 |
| 54 if (expected_array.is_null()) |
| 55 return arg.empty(); |
| 56 |
| 57 for (size_t i = 0; i < expected_array.size(); ++i) { |
| 58 if (arg[i] != expected_array[i]) |
| 59 return false; |
| 60 } |
| 61 |
| 62 return true; |
| 63 } |
| 64 |
46 const char *const kPresentationId = "presentationId"; | 65 const char *const kPresentationId = "presentationId"; |
47 const char *const kPresentationUrl = "http://foo.com/index.html"; | 66 const char* const kPresentationUrl1 = "http://foo.com/index.html"; |
| 67 const char* const kPresentationUrl2 = "http://example.com/index.html"; |
48 | 68 |
49 bool ArePresentationSessionMessagesEqual( | 69 bool ArePresentationSessionMessagesEqual( |
50 const blink::mojom::SessionMessage* expected, | 70 const blink::mojom::SessionMessage* expected, |
51 const blink::mojom::SessionMessage* actual) { | 71 const blink::mojom::SessionMessage* actual) { |
52 return expected->type == actual->type && | 72 return expected->type == actual->type && |
53 expected->message == actual->message && | 73 expected->message == actual->message && |
54 expected->data.Equals(actual->data); | 74 expected->data.Equals(actual->data); |
55 } | 75 } |
56 | 76 |
57 void DoNothing(blink::mojom::PresentationSessionInfoPtr info, | 77 void DoNothing(blink::mojom::PresentationSessionInfoPtr info, |
(...skipping 23 matching lines...) Expand all Loading... |
81 | 101 |
82 MOCK_METHOD3(RemoveScreenAvailabilityListener, | 102 MOCK_METHOD3(RemoveScreenAvailabilityListener, |
83 void( | 103 void( |
84 int render_process_id, | 104 int render_process_id, |
85 int routing_id, | 105 int routing_id, |
86 PresentationScreenAvailabilityListener* listener)); | 106 PresentationScreenAvailabilityListener* listener)); |
87 MOCK_METHOD2(Reset, | 107 MOCK_METHOD2(Reset, |
88 void( | 108 void( |
89 int render_process_id, | 109 int render_process_id, |
90 int routing_id)); | 110 int routing_id)); |
91 MOCK_METHOD4(SetDefaultPresentationUrl, | 111 MOCK_METHOD4(SetDefaultPresentationUrls, |
92 void(int render_process_id, | 112 void(int render_process_id, |
93 int routing_id, | 113 int routing_id, |
94 const std::string& default_presentation_url, | 114 const std::vector<std::string>& default_presentation_urls, |
95 const PresentationSessionStartedCallback& callback)); | 115 const PresentationSessionStartedCallback& callback)); |
96 MOCK_METHOD5(StartSession, | 116 MOCK_METHOD5(StartSession, |
97 void(int render_process_id, | 117 void(int render_process_id, |
98 int render_frame_id, | 118 int render_frame_id, |
99 const std::string& presentation_url, | 119 const std::vector<std::string>& presentation_urls, |
100 const PresentationSessionStartedCallback& success_cb, | 120 const PresentationSessionStartedCallback& success_cb, |
101 const PresentationSessionErrorCallback& error_cb)); | 121 const PresentationSessionErrorCallback& error_cb)); |
102 MOCK_METHOD6(JoinSession, | 122 MOCK_METHOD6(JoinSession, |
103 void(int render_process_id, | 123 void(int render_process_id, |
104 int render_frame_id, | 124 int render_frame_id, |
105 const std::string& presentation_url, | 125 const std::vector<std::string>& presentation_urls, |
106 const std::string& presentation_id, | 126 const std::string& presentation_id, |
107 const PresentationSessionStartedCallback& success_cb, | 127 const PresentationSessionStartedCallback& success_cb, |
108 const PresentationSessionErrorCallback& error_cb)); | 128 const PresentationSessionErrorCallback& error_cb)); |
109 MOCK_METHOD3(CloseConnection, | 129 MOCK_METHOD3(CloseConnection, |
110 void(int render_process_id, | 130 void(int render_process_id, |
111 int render_frame_id, | 131 int render_frame_id, |
112 const std::string& presentation_id)); | 132 const std::string& presentation_id)); |
113 MOCK_METHOD3(Terminate, | 133 MOCK_METHOD3(Terminate, |
114 void(int render_process_id, | 134 void(int render_process_id, |
115 int render_frame_id, | 135 int render_frame_id, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 286 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
267 listener_it->second->OnScreenAvailabilityChanged(available); | 287 listener_it->second->OnScreenAvailabilityChanged(available); |
268 run_loop.Run(); | 288 run_loop.Run(); |
269 } | 289 } |
270 | 290 |
271 void ExpectReset() { | 291 void ExpectReset() { |
272 EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1); | 292 EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1); |
273 } | 293 } |
274 | 294 |
275 void ExpectCleanState() { | 295 void ExpectCleanState() { |
276 EXPECT_TRUE(service_impl_->default_presentation_url_.empty()); | 296 EXPECT_TRUE(service_impl_->default_presentation_urls_.empty()); |
277 EXPECT_EQ( | 297 EXPECT_EQ( |
278 service_impl_->screen_availability_listeners_.find(kPresentationUrl), | 298 service_impl_->screen_availability_listeners_.find(kPresentationUrl1), |
279 service_impl_->screen_availability_listeners_.end()); | 299 service_impl_->screen_availability_listeners_.end()); |
280 EXPECT_FALSE(service_impl_->on_session_messages_callback_.get()); | 300 EXPECT_FALSE(service_impl_->on_session_messages_callback_.get()); |
281 } | 301 } |
282 | 302 |
283 void ExpectNewSessionCallbackSuccess( | 303 void ExpectNewSessionCallbackSuccess( |
284 blink::mojom::PresentationSessionInfoPtr info, | 304 blink::mojom::PresentationSessionInfoPtr info, |
285 blink::mojom::PresentationErrorPtr error) { | 305 blink::mojom::PresentationErrorPtr error) { |
286 EXPECT_FALSE(info.is_null()); | 306 EXPECT_FALSE(info.is_null()); |
287 EXPECT_TRUE(error.is_null()); | 307 EXPECT_TRUE(error.is_null()); |
288 if (!run_loop_quit_closure_.is_null()) | 308 if (!run_loop_quit_closure_.is_null()) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 expected_msgs[0] = blink::mojom::SessionMessage::New(); | 342 expected_msgs[0] = blink::mojom::SessionMessage::New(); |
323 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT; | 343 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT; |
324 expected_msgs[0]->message = text_msg; | 344 expected_msgs[0]->message = text_msg; |
325 expected_msgs[1] = blink::mojom::SessionMessage::New(); | 345 expected_msgs[1] = blink::mojom::SessionMessage::New(); |
326 expected_msgs[1]->type = | 346 expected_msgs[1]->type = |
327 blink::mojom::PresentationMessageType::ARRAY_BUFFER; | 347 blink::mojom::PresentationMessageType::ARRAY_BUFFER; |
328 expected_msgs[1]->data = mojo::Array<uint8_t>::From(binary_data); | 348 expected_msgs[1]->data = mojo::Array<uint8_t>::From(binary_data); |
329 | 349 |
330 blink::mojom::PresentationSessionInfoPtr session( | 350 blink::mojom::PresentationSessionInfoPtr session( |
331 blink::mojom::PresentationSessionInfo::New()); | 351 blink::mojom::PresentationSessionInfo::New()); |
332 session->url = kPresentationUrl; | 352 session->url = kPresentationUrl1; |
333 session->id = kPresentationId; | 353 session->id = kPresentationId; |
334 | 354 |
335 PresentationSessionMessageCallback message_cb; | 355 PresentationSessionMessageCallback message_cb; |
336 { | 356 { |
337 base::RunLoop run_loop; | 357 base::RunLoop run_loop; |
338 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _)) | 358 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _)) |
339 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 359 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
340 SaveArg<3>(&message_cb))); | 360 SaveArg<3>(&message_cb))); |
341 service_ptr_->ListenForSessionMessages(session.Clone()); | 361 service_ptr_->ListenForSessionMessages(session.Clone()); |
342 run_loop.Run(); | 362 run_loop.Run(); |
(...skipping 27 matching lines...) Expand all Loading... |
370 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_; | 390 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_; |
371 | 391 |
372 MockPresentationServiceClient mock_client_; | 392 MockPresentationServiceClient mock_client_; |
373 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>> | 393 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>> |
374 client_binding_; | 394 client_binding_; |
375 | 395 |
376 base::Closure run_loop_quit_closure_; | 396 base::Closure run_loop_quit_closure_; |
377 }; | 397 }; |
378 | 398 |
379 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { | 399 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { |
380 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); | 400 ListenForScreenAvailabilityAndWait(kPresentationUrl1, true); |
381 | 401 |
382 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, true); | 402 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl1, true); |
383 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, false); | 403 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl1, false); |
384 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, true); | 404 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl1, true); |
385 } | 405 } |
386 | 406 |
387 TEST_F(PresentationServiceImplTest, Reset) { | 407 TEST_F(PresentationServiceImplTest, Reset) { |
388 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); | 408 ListenForScreenAvailabilityAndWait(kPresentationUrl1, true); |
389 | 409 |
390 ExpectReset(); | 410 ExpectReset(); |
391 service_impl_->Reset(); | 411 service_impl_->Reset(); |
392 ExpectCleanState(); | 412 ExpectCleanState(); |
393 } | 413 } |
394 | 414 |
395 TEST_F(PresentationServiceImplTest, DidNavigateThisFrame) { | 415 TEST_F(PresentationServiceImplTest, DidNavigateThisFrame) { |
396 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); | 416 ListenForScreenAvailabilityAndWait(kPresentationUrl1, true); |
397 | 417 |
398 ExpectReset(); | 418 ExpectReset(); |
399 service_impl_->DidNavigateAnyFrame( | 419 service_impl_->DidNavigateAnyFrame( |
400 contents()->GetMainFrame(), | 420 contents()->GetMainFrame(), |
401 content::LoadCommittedDetails(), | 421 content::LoadCommittedDetails(), |
402 content::FrameNavigateParams()); | 422 content::FrameNavigateParams()); |
403 ExpectCleanState(); | 423 ExpectCleanState(); |
404 } | 424 } |
405 | 425 |
406 TEST_F(PresentationServiceImplTest, DidNavigateOtherFrame) { | 426 TEST_F(PresentationServiceImplTest, DidNavigateOtherFrame) { |
407 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); | 427 ListenForScreenAvailabilityAndWait(kPresentationUrl1, true); |
408 | 428 |
409 // TODO(imcheng): How to get a different RenderFrameHost? | 429 // TODO(imcheng): How to get a different RenderFrameHost? |
410 service_impl_->DidNavigateAnyFrame( | 430 service_impl_->DidNavigateAnyFrame( |
411 nullptr, | 431 nullptr, |
412 content::LoadCommittedDetails(), | 432 content::LoadCommittedDetails(), |
413 content::FrameNavigateParams()); | 433 content::FrameNavigateParams()); |
414 | 434 |
415 // Availability is reported and callback is invoked since it was not | 435 // Availability is reported and callback is invoked since it was not |
416 // removed. | 436 // removed. |
417 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, true); | 437 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl1, true); |
418 } | 438 } |
419 | 439 |
420 TEST_F(PresentationServiceImplTest, ThisRenderFrameDeleted) { | 440 TEST_F(PresentationServiceImplTest, ThisRenderFrameDeleted) { |
421 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); | 441 ListenForScreenAvailabilityAndWait(kPresentationUrl1, true); |
422 | 442 |
423 ExpectReset(); | 443 ExpectReset(); |
424 | 444 |
425 // Since the frame matched the service, |service_impl_| will be deleted. | 445 // Since the frame matched the service, |service_impl_| will be deleted. |
426 PresentationServiceImpl* service = service_impl_.release(); | 446 PresentationServiceImpl* service = service_impl_.release(); |
427 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); | 447 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); |
428 service->RenderFrameDeleted(contents()->GetMainFrame()); | 448 service->RenderFrameDeleted(contents()->GetMainFrame()); |
429 } | 449 } |
430 | 450 |
431 TEST_F(PresentationServiceImplTest, OtherRenderFrameDeleted) { | 451 TEST_F(PresentationServiceImplTest, OtherRenderFrameDeleted) { |
432 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); | 452 ListenForScreenAvailabilityAndWait(kPresentationUrl1, true); |
433 | 453 |
434 // TODO(imcheng): How to get a different RenderFrameHost? | 454 // TODO(imcheng): How to get a different RenderFrameHost? |
435 service_impl_->RenderFrameDeleted(nullptr); | 455 service_impl_->RenderFrameDeleted(nullptr); |
436 | 456 |
437 // Availability is reported and callback should be invoked since listener | 457 // Availability is reported and callback should be invoked since listener |
438 // has not been deleted. | 458 // has not been deleted. |
439 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, true); | 459 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl1, true); |
440 } | 460 } |
441 | 461 |
442 TEST_F(PresentationServiceImplTest, DelegateFails) { | 462 TEST_F(PresentationServiceImplTest, DelegateFails) { |
443 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); | 463 ListenForScreenAvailabilityAndWait(kPresentationUrl1, false); |
444 ASSERT_EQ( | 464 ASSERT_EQ( |
445 service_impl_->screen_availability_listeners_.find(kPresentationUrl), | 465 service_impl_->screen_availability_listeners_.find(kPresentationUrl1), |
446 service_impl_->screen_availability_listeners_.end()); | 466 service_impl_->screen_availability_listeners_.end()); |
447 } | 467 } |
448 | 468 |
449 TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrl) { | 469 TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrls) { |
450 std::string url1("http://fooUrl"); | 470 mojo::Array<mojo::String> urls(2); |
451 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url1), _)) | 471 urls[0] = kPresentationUrl1; |
| 472 urls[1] = kPresentationUrl2; |
| 473 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls( |
| 474 _, _, StringArrayEquals(ByRef(urls)), _)) |
452 .Times(1); | 475 .Times(1); |
453 service_impl_->SetDefaultPresentationURL(url1); | 476 service_impl_->SetDefaultPresentationUrls(urls.Clone()); |
454 EXPECT_EQ(url1, service_impl_->default_presentation_url_); | |
455 | 477 |
456 std::string url2("http://barUrl"); | 478 std::string url3("http://barUrl"); |
457 // Sets different DPU. | 479 // Sets different DPUs. |
| 480 mojo::Array<mojo::String> more_urls(3); |
| 481 more_urls[0] = kPresentationUrl1; |
| 482 more_urls[1] = kPresentationUrl2; |
| 483 more_urls[2] = url3; |
458 content::PresentationSessionStartedCallback callback; | 484 content::PresentationSessionStartedCallback callback; |
459 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url2), _)) | 485 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls( |
| 486 _, _, StringArrayEquals(ByRef(more_urls)), _)) |
460 .WillOnce(SaveArg<3>(&callback)); | 487 .WillOnce(SaveArg<3>(&callback)); |
461 service_impl_->SetDefaultPresentationURL(url2); | 488 service_impl_->SetDefaultPresentationUrls(more_urls.Clone()); |
462 EXPECT_EQ(url2, service_impl_->default_presentation_url_); | |
463 | 489 |
464 blink::mojom::PresentationSessionInfo session_info; | 490 blink::mojom::PresentationSessionInfo session_info; |
465 session_info.url = url2; | 491 session_info.url = kPresentationUrl2; |
466 session_info.id = kPresentationId; | 492 session_info.id = kPresentationId; |
467 base::RunLoop run_loop; | 493 base::RunLoop run_loop; |
468 EXPECT_CALL(mock_client_, OnDefaultSessionStarted(Equals(session_info))) | 494 EXPECT_CALL(mock_client_, OnDefaultSessionStarted(Equals(session_info))) |
469 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 495 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
470 callback.Run(content::PresentationSessionInfo(url2, kPresentationId)); | 496 callback.Run( |
| 497 content::PresentationSessionInfo(kPresentationUrl2, kPresentationId)); |
471 run_loop.Run(); | 498 run_loop.Run(); |
472 } | 499 } |
473 | 500 |
474 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { | 501 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { |
475 content::PresentationSessionInfo connection(kPresentationUrl, | 502 content::PresentationSessionInfo connection(kPresentationUrl1, |
476 kPresentationId); | 503 kPresentationId); |
477 content::PresentationConnectionStateChangedCallback state_changed_cb; | 504 content::PresentationConnectionStateChangedCallback state_changed_cb; |
478 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 505 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
479 .WillOnce(SaveArg<3>(&state_changed_cb)); | 506 .WillOnce(SaveArg<3>(&state_changed_cb)); |
480 service_impl_->ListenForConnectionStateChange(connection); | 507 service_impl_->ListenForConnectionStateChange(connection); |
481 | 508 |
482 // Trigger state change. It should be propagated back up to |mock_client_|. | 509 // Trigger state change. It should be propagated back up to |mock_client_|. |
483 blink::mojom::PresentationSessionInfo presentation_connection; | 510 blink::mojom::PresentationSessionInfo presentation_connection; |
484 presentation_connection.url = kPresentationUrl; | 511 presentation_connection.url = kPresentationUrl1; |
485 presentation_connection.id = kPresentationId; | 512 presentation_connection.id = kPresentationId; |
486 { | 513 { |
487 base::RunLoop run_loop; | 514 base::RunLoop run_loop; |
488 EXPECT_CALL(mock_client_, | 515 EXPECT_CALL(mock_client_, |
489 OnConnectionStateChanged( | 516 OnConnectionStateChanged( |
490 Equals(presentation_connection), | 517 Equals(presentation_connection), |
491 blink::mojom::PresentationConnectionState::TERMINATED)) | 518 blink::mojom::PresentationConnectionState::TERMINATED)) |
492 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 519 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
493 state_changed_cb.Run(PresentationConnectionStateChangeInfo( | 520 state_changed_cb.Run(PresentationConnectionStateChangeInfo( |
494 PRESENTATION_CONNECTION_STATE_TERMINATED)); | 521 PRESENTATION_CONNECTION_STATE_TERMINATED)); |
495 run_loop.Run(); | 522 run_loop.Run(); |
496 } | 523 } |
497 } | 524 } |
498 | 525 |
499 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { | 526 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { |
500 content::PresentationSessionInfo connection(kPresentationUrl, | 527 content::PresentationSessionInfo connection(kPresentationUrl1, |
501 kPresentationId); | 528 kPresentationId); |
502 content::PresentationConnectionStateChangedCallback state_changed_cb; | 529 content::PresentationConnectionStateChangedCallback state_changed_cb; |
503 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 530 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
504 .WillOnce(SaveArg<3>(&state_changed_cb)); | 531 .WillOnce(SaveArg<3>(&state_changed_cb)); |
505 service_impl_->ListenForConnectionStateChange(connection); | 532 service_impl_->ListenForConnectionStateChange(connection); |
506 | 533 |
507 // Trigger connection close. It should be propagated back up to | 534 // Trigger connection close. It should be propagated back up to |
508 // |mock_client_|. | 535 // |mock_client_|. |
509 blink::mojom::PresentationSessionInfo presentation_connection; | 536 blink::mojom::PresentationSessionInfo presentation_connection; |
510 presentation_connection.url = kPresentationUrl; | 537 presentation_connection.url = kPresentationUrl1; |
511 presentation_connection.id = kPresentationId; | 538 presentation_connection.id = kPresentationId; |
512 { | 539 { |
513 base::RunLoop run_loop; | 540 base::RunLoop run_loop; |
514 PresentationConnectionStateChangeInfo closed_info( | 541 PresentationConnectionStateChangeInfo closed_info( |
515 PRESENTATION_CONNECTION_STATE_CLOSED); | 542 PRESENTATION_CONNECTION_STATE_CLOSED); |
516 closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; | 543 closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; |
517 closed_info.message = "Foo"; | 544 closed_info.message = "Foo"; |
518 | 545 |
519 EXPECT_CALL(mock_client_, | 546 EXPECT_CALL(mock_client_, |
520 OnConnectionClosed( | 547 OnConnectionClosed( |
521 Equals(presentation_connection), | 548 Equals(presentation_connection), |
522 blink::mojom::PresentationConnectionCloseReason::WENT_AWAY, | 549 blink::mojom::PresentationConnectionCloseReason::WENT_AWAY, |
523 mojo::String("Foo"))) | 550 mojo::String("Foo"))) |
524 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 551 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
525 state_changed_cb.Run(closed_info); | 552 state_changed_cb.Run(closed_info); |
526 run_loop.Run(); | 553 run_loop.Run(); |
527 } | 554 } |
528 } | 555 } |
529 | 556 |
530 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { | 557 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrls) { |
531 EXPECT_CALL(mock_delegate_, | 558 mojo::Array<mojo::String> urls(2); |
532 SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl), _)) | 559 urls[0] = kPresentationUrl1; |
| 560 urls[1] = kPresentationUrl2; |
| 561 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls( |
| 562 _, _, StringArrayEquals(ByRef(urls)), _)) |
533 .Times(1); | 563 .Times(1); |
534 service_impl_->SetDefaultPresentationURL(kPresentationUrl); | 564 service_impl_->SetDefaultPresentationUrls(urls.Clone()); |
535 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); | 565 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
536 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_); | |
537 | 566 |
538 // Same URL as before; no-ops. | 567 // Same URLs as before; no-ops. |
539 service_impl_->SetDefaultPresentationURL(kPresentationUrl); | 568 service_impl_->SetDefaultPresentationUrls(urls.Clone()); |
540 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); | 569 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
541 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_); | |
542 } | 570 } |
543 | 571 |
544 TEST_F(PresentationServiceImplTest, StartSessionSuccess) { | 572 TEST_F(PresentationServiceImplTest, StartSessionSuccess) { |
| 573 mojo::Array<mojo::String> urls(2); |
| 574 urls[0] = kPresentationUrl1; |
| 575 urls[1] = kPresentationUrl2; |
545 service_ptr_->StartSession( | 576 service_ptr_->StartSession( |
546 kPresentationUrl, | 577 urls.Clone(), |
547 base::Bind( | 578 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackSuccess, |
548 &PresentationServiceImplTest::ExpectNewSessionCallbackSuccess, | 579 base::Unretained(this))); |
549 base::Unretained(this))); | |
550 base::RunLoop run_loop; | 580 base::RunLoop run_loop; |
551 base::Callback<void(const PresentationSessionInfo&)> success_cb; | 581 base::Callback<void(const PresentationSessionInfo&)> success_cb; |
552 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(kPresentationUrl), _, _)) | 582 EXPECT_CALL(mock_delegate_, |
553 .WillOnce(DoAll( | 583 StartSession(_, _, StringArrayEquals(ByRef(urls)), _, _)) |
554 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 584 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
555 SaveArg<3>(&success_cb))); | 585 SaveArg<3>(&success_cb))); |
556 run_loop.Run(); | 586 run_loop.Run(); |
557 | 587 |
558 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 588 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
559 .Times(1); | 589 .Times(1); |
560 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId)); | 590 success_cb.Run(PresentationSessionInfo(kPresentationUrl1, kPresentationId)); |
561 SaveQuitClosureAndRunLoop(); | 591 SaveQuitClosureAndRunLoop(); |
562 } | 592 } |
563 | 593 |
564 TEST_F(PresentationServiceImplTest, StartSessionError) { | 594 TEST_F(PresentationServiceImplTest, StartSessionError) { |
| 595 mojo::Array<mojo::String> urls(2); |
| 596 urls[0] = kPresentationUrl1; |
| 597 urls[1] = kPresentationUrl2; |
565 service_ptr_->StartSession( | 598 service_ptr_->StartSession( |
566 kPresentationUrl, | 599 urls.Clone(), |
567 base::Bind( | 600 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, |
568 &PresentationServiceImplTest::ExpectNewSessionCallbackError, | 601 base::Unretained(this))); |
569 base::Unretained(this))); | |
570 base::RunLoop run_loop; | 602 base::RunLoop run_loop; |
571 base::Callback<void(const PresentationError&)> error_cb; | 603 base::Callback<void(const PresentationError&)> error_cb; |
572 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(kPresentationUrl), _, _)) | 604 EXPECT_CALL(mock_delegate_, |
573 .WillOnce(DoAll( | 605 StartSession(_, _, StringArrayEquals(ByRef(urls)), _, _)) |
574 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 606 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
575 SaveArg<4>(&error_cb))); | 607 SaveArg<4>(&error_cb))); |
576 run_loop.Run(); | 608 run_loop.Run(); |
577 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message")); | 609 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message")); |
578 SaveQuitClosureAndRunLoop(); | 610 SaveQuitClosureAndRunLoop(); |
579 } | 611 } |
580 | 612 |
581 TEST_F(PresentationServiceImplTest, JoinSessionSuccess) { | 613 TEST_F(PresentationServiceImplTest, JoinSessionSuccess) { |
| 614 mojo::Array<mojo::String> urls(2); |
| 615 urls[0] = kPresentationUrl1; |
| 616 urls[1] = kPresentationUrl2; |
582 service_ptr_->JoinSession( | 617 service_ptr_->JoinSession( |
583 kPresentationUrl, | 618 urls.Clone(), kPresentationId, |
584 kPresentationId, | 619 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackSuccess, |
585 base::Bind( | 620 base::Unretained(this))); |
586 &PresentationServiceImplTest::ExpectNewSessionCallbackSuccess, | |
587 base::Unretained(this))); | |
588 base::RunLoop run_loop; | 621 base::RunLoop run_loop; |
589 base::Callback<void(const PresentationSessionInfo&)> success_cb; | 622 base::Callback<void(const PresentationSessionInfo&)> success_cb; |
590 EXPECT_CALL(mock_delegate_, JoinSession( | 623 EXPECT_CALL(mock_delegate_, JoinSession(_, _, StringArrayEquals(ByRef(urls)), |
591 _, _, Eq(kPresentationUrl), Eq(kPresentationId), _, _)) | 624 kPresentationId, _, _)) |
592 .WillOnce(DoAll( | 625 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
593 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 626 SaveArg<4>(&success_cb))); |
594 SaveArg<4>(&success_cb))); | |
595 run_loop.Run(); | 627 run_loop.Run(); |
596 | 628 |
597 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 629 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
598 .Times(1); | 630 .Times(1); |
599 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId)); | 631 success_cb.Run(PresentationSessionInfo(kPresentationUrl1, kPresentationId)); |
600 SaveQuitClosureAndRunLoop(); | 632 SaveQuitClosureAndRunLoop(); |
601 } | 633 } |
602 | 634 |
603 TEST_F(PresentationServiceImplTest, JoinSessionError) { | 635 TEST_F(PresentationServiceImplTest, JoinSessionError) { |
| 636 mojo::Array<mojo::String> urls(2); |
| 637 urls[0] = kPresentationUrl1; |
| 638 urls[1] = kPresentationUrl2; |
604 service_ptr_->JoinSession( | 639 service_ptr_->JoinSession( |
605 kPresentationUrl, | 640 urls.Clone(), kPresentationId, |
606 kPresentationId, | 641 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, |
607 base::Bind( | 642 base::Unretained(this))); |
608 &PresentationServiceImplTest::ExpectNewSessionCallbackError, | |
609 base::Unretained(this))); | |
610 base::RunLoop run_loop; | 643 base::RunLoop run_loop; |
611 base::Callback<void(const PresentationError&)> error_cb; | 644 base::Callback<void(const PresentationError&)> error_cb; |
612 EXPECT_CALL(mock_delegate_, JoinSession( | 645 EXPECT_CALL(mock_delegate_, JoinSession(_, _, StringArrayEquals(ByRef(urls)), |
613 _, _, Eq(kPresentationUrl), Eq(kPresentationId), _, _)) | 646 kPresentationId, _, _)) |
614 .WillOnce(DoAll( | 647 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
615 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 648 SaveArg<5>(&error_cb))); |
616 SaveArg<5>(&error_cb))); | |
617 run_loop.Run(); | 649 run_loop.Run(); |
618 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message")); | 650 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message")); |
619 SaveQuitClosureAndRunLoop(); | 651 SaveQuitClosureAndRunLoop(); |
620 } | 652 } |
621 | 653 |
622 TEST_F(PresentationServiceImplTest, CloseConnection) { | 654 TEST_F(PresentationServiceImplTest, CloseConnection) { |
623 service_ptr_->CloseConnection(kPresentationUrl, kPresentationId); | 655 service_ptr_->CloseConnection(kPresentationUrl1, kPresentationId); |
624 base::RunLoop run_loop; | 656 base::RunLoop run_loop; |
625 EXPECT_CALL(mock_delegate_, CloseConnection(_, _, Eq(kPresentationId))) | 657 EXPECT_CALL(mock_delegate_, CloseConnection(_, _, Eq(kPresentationId))) |
626 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 658 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
627 run_loop.Run(); | 659 run_loop.Run(); |
628 } | 660 } |
629 | 661 |
630 TEST_F(PresentationServiceImplTest, Terminate) { | 662 TEST_F(PresentationServiceImplTest, Terminate) { |
631 service_ptr_->Terminate(kPresentationUrl, kPresentationId); | 663 service_ptr_->Terminate(kPresentationUrl1, kPresentationId); |
632 base::RunLoop run_loop; | 664 base::RunLoop run_loop; |
633 EXPECT_CALL(mock_delegate_, Terminate(_, _, Eq(kPresentationId))) | 665 EXPECT_CALL(mock_delegate_, Terminate(_, _, Eq(kPresentationId))) |
634 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 666 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
635 run_loop.Run(); | 667 run_loop.Run(); |
636 } | 668 } |
637 | 669 |
638 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesPassed) { | 670 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesPassed) { |
639 std::string text_msg("123"); | 671 std::string text_msg("123"); |
640 std::vector<uint8_t> binary_data(3, '\1'); | 672 std::vector<uint8_t> binary_data(3, '\1'); |
641 RunListenForSessionMessages(text_msg, binary_data, true); | 673 RunListenForSessionMessages(text_msg, binary_data, true); |
642 } | 674 } |
643 | 675 |
644 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesCopied) { | 676 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesCopied) { |
645 std::string text_msg("123"); | 677 std::string text_msg("123"); |
646 std::vector<uint8_t> binary_data(3, '\1'); | 678 std::vector<uint8_t> binary_data(3, '\1'); |
647 RunListenForSessionMessages(text_msg, binary_data, false); | 679 RunListenForSessionMessages(text_msg, binary_data, false); |
648 } | 680 } |
649 | 681 |
650 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) { | 682 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) { |
651 std::string text_msg(""); | 683 std::string text_msg(""); |
652 std::vector<uint8_t> binary_data; | 684 std::vector<uint8_t> binary_data; |
653 RunListenForSessionMessages(text_msg, binary_data, false); | 685 RunListenForSessionMessages(text_msg, binary_data, false); |
654 } | 686 } |
655 | 687 |
656 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { | 688 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { |
| 689 mojo::Array<mojo::String> urls(2); |
657 std::string presentation_url1("http://fooUrl"); | 690 std::string presentation_url1("http://fooUrl"); |
658 std::string presentation_url2("http://barUrl"); | 691 std::string presentation_url2("http://barUrl"); |
659 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(presentation_url1), _, _)) | 692 urls[0] = presentation_url1; |
| 693 urls[1] = presentation_url2; |
| 694 EXPECT_CALL(mock_delegate_, |
| 695 StartSession(_, _, StringArrayEquals(ByRef(urls)), _, _)) |
660 .Times(1); | 696 .Times(1); |
661 service_ptr_->StartSession(presentation_url1, | 697 service_ptr_->StartSession(urls.Clone(), base::Bind(&DoNothing)); |
662 base::Bind(&DoNothing)); | |
663 | 698 |
664 // This request should fail immediately, since there is already a StartSession | 699 // This request should fail immediately, since there is already a StartSession |
665 // in progress. | 700 // in progress. |
666 service_ptr_->StartSession( | 701 service_ptr_->StartSession( |
667 presentation_url2, | 702 urls.Clone(), |
668 base::Bind( | 703 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, |
669 &PresentationServiceImplTest::ExpectNewSessionCallbackError, | 704 base::Unretained(this))); |
670 base::Unretained(this))); | |
671 SaveQuitClosureAndRunLoop(); | 705 SaveQuitClosureAndRunLoop(); |
672 } | 706 } |
673 | 707 |
674 TEST_F(PresentationServiceImplTest, SendStringMessage) { | 708 TEST_F(PresentationServiceImplTest, SendStringMessage) { |
675 std::string message("Test presentation session message"); | 709 std::string message("Test presentation session message"); |
676 | 710 |
677 blink::mojom::PresentationSessionInfoPtr session( | 711 blink::mojom::PresentationSessionInfoPtr session( |
678 blink::mojom::PresentationSessionInfo::New()); | 712 blink::mojom::PresentationSessionInfo::New()); |
679 session->url = kPresentationUrl; | 713 session->url = kPresentationUrl1; |
680 session->id = kPresentationId; | 714 session->id = kPresentationId; |
681 blink::mojom::SessionMessagePtr message_request( | 715 blink::mojom::SessionMessagePtr message_request( |
682 blink::mojom::SessionMessage::New()); | 716 blink::mojom::SessionMessage::New()); |
683 message_request->type = blink::mojom::PresentationMessageType::TEXT; | 717 message_request->type = blink::mojom::PresentationMessageType::TEXT; |
684 message_request->message = message; | 718 message_request->message = message; |
685 service_ptr_->SendSessionMessage( | 719 service_ptr_->SendSessionMessage( |
686 std::move(session), std::move(message_request), | 720 std::move(session), std::move(message_request), |
687 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, | 721 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, |
688 base::Unretained(this))); | 722 base::Unretained(this))); |
689 | 723 |
(...skipping 17 matching lines...) Expand all Loading... |
707 } | 741 } |
708 | 742 |
709 TEST_F(PresentationServiceImplTest, SendArrayBuffer) { | 743 TEST_F(PresentationServiceImplTest, SendArrayBuffer) { |
710 // Test Array buffer data. | 744 // Test Array buffer data. |
711 const uint8_t buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48}; | 745 const uint8_t buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48}; |
712 std::vector<uint8_t> data; | 746 std::vector<uint8_t> data; |
713 data.assign(buffer, buffer + sizeof(buffer)); | 747 data.assign(buffer, buffer + sizeof(buffer)); |
714 | 748 |
715 blink::mojom::PresentationSessionInfoPtr session( | 749 blink::mojom::PresentationSessionInfoPtr session( |
716 blink::mojom::PresentationSessionInfo::New()); | 750 blink::mojom::PresentationSessionInfo::New()); |
717 session->url = kPresentationUrl; | 751 session->url = kPresentationUrl1; |
718 session->id = kPresentationId; | 752 session->id = kPresentationId; |
719 blink::mojom::SessionMessagePtr message_request( | 753 blink::mojom::SessionMessagePtr message_request( |
720 blink::mojom::SessionMessage::New()); | 754 blink::mojom::SessionMessage::New()); |
721 message_request->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER; | 755 message_request->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER; |
722 message_request->data = mojo::Array<uint8_t>::From(data); | 756 message_request->data = mojo::Array<uint8_t>::From(data); |
723 service_ptr_->SendSessionMessage( | 757 service_ptr_->SendSessionMessage( |
724 std::move(session), std::move(message_request), | 758 std::move(session), std::move(message_request), |
725 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, | 759 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, |
726 base::Unretained(this))); | 760 base::Unretained(this))); |
727 | 761 |
(...skipping 23 matching lines...) Expand all Loading... |
751 // Create buffer with size exceeding the limit. | 785 // Create buffer with size exceeding the limit. |
752 // Use same size as in content::kMaxPresentationSessionMessageSize. | 786 // Use same size as in content::kMaxPresentationSessionMessageSize. |
753 const size_t kMaxBufferSizeInBytes = 64 * 1024; // 64 KB. | 787 const size_t kMaxBufferSizeInBytes = 64 * 1024; // 64 KB. |
754 uint8_t buffer[kMaxBufferSizeInBytes + 1]; | 788 uint8_t buffer[kMaxBufferSizeInBytes + 1]; |
755 memset(buffer, 0, kMaxBufferSizeInBytes+1); | 789 memset(buffer, 0, kMaxBufferSizeInBytes+1); |
756 std::vector<uint8_t> data; | 790 std::vector<uint8_t> data; |
757 data.assign(buffer, buffer + sizeof(buffer)); | 791 data.assign(buffer, buffer + sizeof(buffer)); |
758 | 792 |
759 blink::mojom::PresentationSessionInfoPtr session( | 793 blink::mojom::PresentationSessionInfoPtr session( |
760 blink::mojom::PresentationSessionInfo::New()); | 794 blink::mojom::PresentationSessionInfo::New()); |
761 session->url = kPresentationUrl; | 795 session->url = kPresentationUrl1; |
762 session->id = kPresentationId; | 796 session->id = kPresentationId; |
763 blink::mojom::SessionMessagePtr message_request( | 797 blink::mojom::SessionMessagePtr message_request( |
764 blink::mojom::SessionMessage::New()); | 798 blink::mojom::SessionMessage::New()); |
765 message_request->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER; | 799 message_request->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER; |
766 message_request->data = mojo::Array<uint8_t>::From(data); | 800 message_request->data = mojo::Array<uint8_t>::From(data); |
767 service_ptr_->SendSessionMessage( | 801 service_ptr_->SendSessionMessage( |
768 std::move(session), std::move(message_request), | 802 std::move(session), std::move(message_request), |
769 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, | 803 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, |
770 base::Unretained(this))); | 804 base::Unretained(this))); |
771 | 805 |
(...skipping 10 matching lines...) Expand all Loading... |
782 SaveQuitClosureAndRunLoop(); | 816 SaveQuitClosureAndRunLoop(); |
783 } | 817 } |
784 | 818 |
785 TEST_F(PresentationServiceImplTest, SendBlobData) { | 819 TEST_F(PresentationServiceImplTest, SendBlobData) { |
786 const uint8_t buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; | 820 const uint8_t buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; |
787 std::vector<uint8_t> data; | 821 std::vector<uint8_t> data; |
788 data.assign(buffer, buffer + sizeof(buffer)); | 822 data.assign(buffer, buffer + sizeof(buffer)); |
789 | 823 |
790 blink::mojom::PresentationSessionInfoPtr session( | 824 blink::mojom::PresentationSessionInfoPtr session( |
791 blink::mojom::PresentationSessionInfo::New()); | 825 blink::mojom::PresentationSessionInfo::New()); |
792 session->url = kPresentationUrl; | 826 session->url = kPresentationUrl1; |
793 session->id = kPresentationId; | 827 session->id = kPresentationId; |
794 blink::mojom::SessionMessagePtr message_request( | 828 blink::mojom::SessionMessagePtr message_request( |
795 blink::mojom::SessionMessage::New()); | 829 blink::mojom::SessionMessage::New()); |
796 message_request->type = blink::mojom::PresentationMessageType::BLOB; | 830 message_request->type = blink::mojom::PresentationMessageType::BLOB; |
797 message_request->data = mojo::Array<uint8_t>::From(data); | 831 message_request->data = mojo::Array<uint8_t>::From(data); |
798 service_ptr_->SendSessionMessage( | 832 service_ptr_->SendSessionMessage( |
799 std::move(session), std::move(message_request), | 833 std::move(session), std::move(message_request), |
800 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, | 834 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, |
801 base::Unretained(this))); | 835 base::Unretained(this))); |
802 | 836 |
(...skipping 19 matching lines...) Expand all Loading... |
822 SaveQuitClosureAndRunLoop(); | 856 SaveQuitClosureAndRunLoop(); |
823 } | 857 } |
824 | 858 |
825 TEST_F(PresentationServiceImplTest, MaxPendingJoinSessionRequests) { | 859 TEST_F(PresentationServiceImplTest, MaxPendingJoinSessionRequests) { |
826 const char* presentation_url = "http://fooUrl%d"; | 860 const char* presentation_url = "http://fooUrl%d"; |
827 const char* presentation_id = "presentationId%d"; | 861 const char* presentation_id = "presentationId%d"; |
828 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests; | 862 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests; |
829 int i = 0; | 863 int i = 0; |
830 EXPECT_CALL(mock_delegate_, JoinSession(_, _, _, _, _, _)) | 864 EXPECT_CALL(mock_delegate_, JoinSession(_, _, _, _, _, _)) |
831 .Times(num_requests); | 865 .Times(num_requests); |
| 866 mojo::Array<mojo::String> urls(1); |
832 for (; i < num_requests; ++i) { | 867 for (; i < num_requests; ++i) { |
833 service_ptr_->JoinSession( | 868 urls[0] = base::StringPrintf(presentation_url, i); |
834 base::StringPrintf(presentation_url, i), | 869 service_ptr_->JoinSession(urls.Clone(), |
835 base::StringPrintf(presentation_id, i), | 870 base::StringPrintf(presentation_id, i), |
836 base::Bind(&DoNothing)); | 871 base::Bind(&DoNothing)); |
837 } | 872 } |
838 | 873 |
| 874 urls[0] = base::StringPrintf(presentation_url, i); |
839 // Exceeded maximum queue size, should invoke mojo callback with error. | 875 // Exceeded maximum queue size, should invoke mojo callback with error. |
840 service_ptr_->JoinSession( | 876 service_ptr_->JoinSession( |
841 base::StringPrintf(presentation_url, i), | 877 urls.Clone(), base::StringPrintf(presentation_id, i), |
842 base::StringPrintf(presentation_id, i), | 878 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, |
843 base::Bind( | 879 base::Unretained(this))); |
844 &PresentationServiceImplTest::ExpectNewSessionCallbackError, | |
845 base::Unretained(this))); | |
846 SaveQuitClosureAndRunLoop(); | 880 SaveQuitClosureAndRunLoop(); |
847 } | 881 } |
848 | 882 |
849 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { | 883 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { |
850 mock_delegate_.set_screen_availability_listening_supported(false); | 884 mock_delegate_.set_screen_availability_listening_supported(false); |
851 base::RunLoop run_loop; | 885 base::RunLoop run_loop; |
852 EXPECT_CALL(mock_client_, | 886 EXPECT_CALL(mock_client_, |
853 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))) | 887 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl1))) |
854 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 888 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
855 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); | 889 ListenForScreenAvailabilityAndWait(kPresentationUrl1, false); |
856 run_loop.Run(); | 890 run_loop.Run(); |
857 } | 891 } |
858 | 892 |
859 } // namespace content | 893 } // namespace content |
OLD | NEW |