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 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 EXPECT_FALSE(service_impl_->send_message_callback_); | 301 EXPECT_FALSE(service_impl_->send_message_callback_); |
302 if (!run_loop_quit_closure_.is_null()) | 302 if (!run_loop_quit_closure_.is_null()) |
303 run_loop_quit_closure_.Run(); | 303 run_loop_quit_closure_.Run(); |
304 } | 304 } |
305 | 305 |
306 void RunListenForSessionMessages(const std::string& text_msg, | 306 void RunListenForSessionMessages(const std::string& text_msg, |
307 const std::vector<uint8_t>& binary_data, | 307 const std::vector<uint8_t>& binary_data, |
308 bool pass_ownership) { | 308 bool pass_ownership) { |
309 mojo::Array<presentation::SessionMessagePtr> expected_msgs(2); | 309 mojo::Array<presentation::SessionMessagePtr> expected_msgs(2); |
310 expected_msgs[0] = presentation::SessionMessage::New(); | 310 expected_msgs[0] = presentation::SessionMessage::New(); |
311 expected_msgs[0]->type = | 311 expected_msgs[0]->type = presentation::PresentationMessageType::TEXT; |
312 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; | |
313 expected_msgs[0]->message = text_msg; | 312 expected_msgs[0]->message = text_msg; |
314 expected_msgs[1] = presentation::SessionMessage::New(); | 313 expected_msgs[1] = presentation::SessionMessage::New(); |
315 expected_msgs[1]->type = presentation::PresentationMessageType:: | 314 expected_msgs[1]->type = |
316 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; | 315 presentation::PresentationMessageType::ARRAY_BUFFER; |
317 expected_msgs[1]->data = mojo::Array<uint8_t>::From(binary_data); | 316 expected_msgs[1]->data = mojo::Array<uint8_t>::From(binary_data); |
318 | 317 |
319 presentation::PresentationSessionInfoPtr session( | 318 presentation::PresentationSessionInfoPtr session( |
320 presentation::PresentationSessionInfo::New()); | 319 presentation::PresentationSessionInfo::New()); |
321 session->url = kPresentationUrl; | 320 session->url = kPresentationUrl; |
322 session->id = kPresentationId; | 321 session->id = kPresentationId; |
323 | 322 |
324 PresentationSessionMessageCallback message_cb; | 323 PresentationSessionMessageCallback message_cb; |
325 { | 324 { |
326 base::RunLoop run_loop; | 325 base::RunLoop run_loop; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 service_impl_->ListenForConnectionStateChange(connection); | 469 service_impl_->ListenForConnectionStateChange(connection); |
471 | 470 |
472 // Trigger state change. It should be propagated back up to |mock_client_|. | 471 // Trigger state change. It should be propagated back up to |mock_client_|. |
473 presentation::PresentationSessionInfo presentation_connection; | 472 presentation::PresentationSessionInfo presentation_connection; |
474 presentation_connection.url = kPresentationUrl; | 473 presentation_connection.url = kPresentationUrl; |
475 presentation_connection.id = kPresentationId; | 474 presentation_connection.id = kPresentationId; |
476 base::RunLoop run_loop; | 475 base::RunLoop run_loop; |
477 EXPECT_CALL(mock_client_, | 476 EXPECT_CALL(mock_client_, |
478 OnConnectionStateChanged( | 477 OnConnectionStateChanged( |
479 Equals(presentation_connection), | 478 Equals(presentation_connection), |
480 presentation::PRESENTATION_CONNECTION_STATE_CLOSED)) | 479 presentation::PresentationConnectionState::CLOSED)) |
481 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 480 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
482 state_changed_cb.Run(content::PRESENTATION_CONNECTION_STATE_CLOSED); | 481 state_changed_cb.Run(PRESENTATION_CONNECTION_STATE_CLOSED); |
483 run_loop.Run(); | 482 run_loop.Run(); |
484 } | 483 } |
485 | 484 |
486 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { | 485 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { |
487 EXPECT_CALL(mock_delegate_, | 486 EXPECT_CALL(mock_delegate_, |
488 SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl), _)) | 487 SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl), _)) |
489 .Times(1); | 488 .Times(1); |
490 service_impl_->SetDefaultPresentationURL(kPresentationUrl); | 489 service_impl_->SetDefaultPresentationURL(kPresentationUrl); |
491 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); | 490 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
492 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_); | 491 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 | 628 |
630 TEST_F(PresentationServiceImplTest, SendStringMessage) { | 629 TEST_F(PresentationServiceImplTest, SendStringMessage) { |
631 std::string message("Test presentation session message"); | 630 std::string message("Test presentation session message"); |
632 | 631 |
633 presentation::PresentationSessionInfoPtr session( | 632 presentation::PresentationSessionInfoPtr session( |
634 presentation::PresentationSessionInfo::New()); | 633 presentation::PresentationSessionInfo::New()); |
635 session->url = kPresentationUrl; | 634 session->url = kPresentationUrl; |
636 session->id = kPresentationId; | 635 session->id = kPresentationId; |
637 presentation::SessionMessagePtr message_request( | 636 presentation::SessionMessagePtr message_request( |
638 presentation::SessionMessage::New()); | 637 presentation::SessionMessage::New()); |
639 message_request->type = presentation::PresentationMessageType:: | 638 message_request->type = presentation::PresentationMessageType::TEXT; |
640 PRESENTATION_MESSAGE_TYPE_TEXT; | |
641 message_request->message = message; | 639 message_request->message = message; |
642 service_ptr_->SendSessionMessage( | 640 service_ptr_->SendSessionMessage( |
643 std::move(session), std::move(message_request), | 641 std::move(session), std::move(message_request), |
644 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, | 642 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, |
645 base::Unretained(this))); | 643 base::Unretained(this))); |
646 | 644 |
647 base::RunLoop run_loop; | 645 base::RunLoop run_loop; |
648 base::Callback<void(bool)> send_message_cb; | 646 base::Callback<void(bool)> send_message_cb; |
649 PresentationSessionMessage* test_message = nullptr; | 647 PresentationSessionMessage* test_message = nullptr; |
650 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) | 648 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) |
(...skipping 17 matching lines...) Expand all Loading... |
668 const uint8_t buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48}; | 666 const uint8_t buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48}; |
669 std::vector<uint8_t> data; | 667 std::vector<uint8_t> data; |
670 data.assign(buffer, buffer + sizeof(buffer)); | 668 data.assign(buffer, buffer + sizeof(buffer)); |
671 | 669 |
672 presentation::PresentationSessionInfoPtr session( | 670 presentation::PresentationSessionInfoPtr session( |
673 presentation::PresentationSessionInfo::New()); | 671 presentation::PresentationSessionInfo::New()); |
674 session->url = kPresentationUrl; | 672 session->url = kPresentationUrl; |
675 session->id = kPresentationId; | 673 session->id = kPresentationId; |
676 presentation::SessionMessagePtr message_request( | 674 presentation::SessionMessagePtr message_request( |
677 presentation::SessionMessage::New()); | 675 presentation::SessionMessage::New()); |
678 message_request->type = presentation::PresentationMessageType:: | 676 message_request->type = presentation::PresentationMessageType::ARRAY_BUFFER; |
679 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; | |
680 message_request->data = mojo::Array<uint8_t>::From(data); | 677 message_request->data = mojo::Array<uint8_t>::From(data); |
681 service_ptr_->SendSessionMessage( | 678 service_ptr_->SendSessionMessage( |
682 std::move(session), std::move(message_request), | 679 std::move(session), std::move(message_request), |
683 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, | 680 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, |
684 base::Unretained(this))); | 681 base::Unretained(this))); |
685 | 682 |
686 base::RunLoop run_loop; | 683 base::RunLoop run_loop; |
687 base::Callback<void(bool)> send_message_cb; | 684 base::Callback<void(bool)> send_message_cb; |
688 PresentationSessionMessage* test_message = nullptr; | 685 PresentationSessionMessage* test_message = nullptr; |
689 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) | 686 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) |
(...skipping 23 matching lines...) Expand all Loading... |
713 memset(buffer, 0, kMaxBufferSizeInBytes+1); | 710 memset(buffer, 0, kMaxBufferSizeInBytes+1); |
714 std::vector<uint8_t> data; | 711 std::vector<uint8_t> data; |
715 data.assign(buffer, buffer + sizeof(buffer)); | 712 data.assign(buffer, buffer + sizeof(buffer)); |
716 | 713 |
717 presentation::PresentationSessionInfoPtr session( | 714 presentation::PresentationSessionInfoPtr session( |
718 presentation::PresentationSessionInfo::New()); | 715 presentation::PresentationSessionInfo::New()); |
719 session->url = kPresentationUrl; | 716 session->url = kPresentationUrl; |
720 session->id = kPresentationId; | 717 session->id = kPresentationId; |
721 presentation::SessionMessagePtr message_request( | 718 presentation::SessionMessagePtr message_request( |
722 presentation::SessionMessage::New()); | 719 presentation::SessionMessage::New()); |
723 message_request->type = presentation::PresentationMessageType:: | 720 message_request->type = presentation::PresentationMessageType::ARRAY_BUFFER; |
724 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; | |
725 message_request->data = mojo::Array<uint8_t>::From(data); | 721 message_request->data = mojo::Array<uint8_t>::From(data); |
726 service_ptr_->SendSessionMessage( | 722 service_ptr_->SendSessionMessage( |
727 std::move(session), std::move(message_request), | 723 std::move(session), std::move(message_request), |
728 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, | 724 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, |
729 base::Unretained(this))); | 725 base::Unretained(this))); |
730 | 726 |
731 base::RunLoop run_loop; | 727 base::RunLoop run_loop; |
732 base::Callback<void(bool)> send_message_cb; | 728 base::Callback<void(bool)> send_message_cb; |
733 PresentationSessionMessage* test_message = nullptr; | 729 PresentationSessionMessage* test_message = nullptr; |
734 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) | 730 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) |
(...skipping 10 matching lines...) Expand all Loading... |
745 const uint8_t buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; | 741 const uint8_t buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; |
746 std::vector<uint8_t> data; | 742 std::vector<uint8_t> data; |
747 data.assign(buffer, buffer + sizeof(buffer)); | 743 data.assign(buffer, buffer + sizeof(buffer)); |
748 | 744 |
749 presentation::PresentationSessionInfoPtr session( | 745 presentation::PresentationSessionInfoPtr session( |
750 presentation::PresentationSessionInfo::New()); | 746 presentation::PresentationSessionInfo::New()); |
751 session->url = kPresentationUrl; | 747 session->url = kPresentationUrl; |
752 session->id = kPresentationId; | 748 session->id = kPresentationId; |
753 presentation::SessionMessagePtr message_request( | 749 presentation::SessionMessagePtr message_request( |
754 presentation::SessionMessage::New()); | 750 presentation::SessionMessage::New()); |
755 message_request->type = | 751 message_request->type = presentation::PresentationMessageType::BLOB; |
756 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_BLOB; | |
757 message_request->data = mojo::Array<uint8_t>::From(data); | 752 message_request->data = mojo::Array<uint8_t>::From(data); |
758 service_ptr_->SendSessionMessage( | 753 service_ptr_->SendSessionMessage( |
759 std::move(session), std::move(message_request), | 754 std::move(session), std::move(message_request), |
760 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, | 755 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, |
761 base::Unretained(this))); | 756 base::Unretained(this))); |
762 | 757 |
763 base::RunLoop run_loop; | 758 base::RunLoop run_loop; |
764 base::Callback<void(bool)> send_message_cb; | 759 base::Callback<void(bool)> send_message_cb; |
765 PresentationSessionMessage* test_message = nullptr; | 760 PresentationSessionMessage* test_message = nullptr; |
766 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) | 761 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 | 803 |
809 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { | 804 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { |
810 mock_delegate_.set_screen_availability_listening_supported(false); | 805 mock_delegate_.set_screen_availability_listening_supported(false); |
811 EXPECT_CALL(mock_client_, | 806 EXPECT_CALL(mock_client_, |
812 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))); | 807 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))); |
813 | 808 |
814 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); | 809 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); |
815 } | 810 } |
816 | 811 |
817 } // namespace content | 812 } // namespace content |
OLD | NEW |