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

Side by Side Diff: content/browser/presentation/presentation_service_impl_unittest.cc

Issue 2562603002: Updates SessionMessage to ConnectionMessage. (Closed)
Patch Set: Created 4 years 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 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 325 }
326 326
327 void RunListenForSessionMessages(const std::string& text_msg, 327 void RunListenForSessionMessages(const std::string& text_msg,
328 const std::vector<uint8_t>& binary_data, 328 const std::vector<uint8_t>& binary_data,
329 bool pass_ownership) { 329 bool pass_ownership) {
330 std::vector<blink::mojom::SessionMessagePtr> expected_msgs(2); 330 std::vector<blink::mojom::SessionMessagePtr> expected_msgs(2);
331 expected_msgs[0] = blink::mojom::SessionMessage::New(); 331 expected_msgs[0] = blink::mojom::SessionMessage::New();
332 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT; 332 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT;
333 expected_msgs[0]->message = text_msg; 333 expected_msgs[0]->message = text_msg;
334 expected_msgs[1] = blink::mojom::SessionMessage::New(); 334 expected_msgs[1] = blink::mojom::SessionMessage::New();
335 expected_msgs[1]->type = 335 expected_msgs[1]->type = blink::mojom::PresentationMessageType::BINARY;
336 blink::mojom::PresentationMessageType::ARRAY_BUFFER;
337 expected_msgs[1]->data = binary_data; 336 expected_msgs[1]->data = binary_data;
338 337
339 blink::mojom::PresentationSessionInfoPtr session( 338 blink::mojom::PresentationSessionInfoPtr session(
340 blink::mojom::PresentationSessionInfo::New()); 339 blink::mojom::PresentationSessionInfo::New());
341 session->url = presentation_url1_; 340 session->url = presentation_url1_;
342 session->id = kPresentationId; 341 session->id = kPresentationId;
343 342
344 PresentationSessionMessageCallback message_cb; 343 PresentationSessionMessageCallback message_cb;
345 { 344 {
346 base::RunLoop run_loop; 345 base::RunLoop run_loop;
347 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _)) 346 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _))
348 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 347 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
349 SaveArg<3>(&message_cb))); 348 SaveArg<3>(&message_cb)));
350 service_ptr_->ListenForSessionMessages(std::move(session)); 349 service_ptr_->ListenForSessionMessages(std::move(session));
351 run_loop.Run(); 350 run_loop.Run();
352 } 351 }
353 352
354 ScopedVector<PresentationSessionMessage> messages; 353 ScopedVector<PresentationSessionMessage> messages;
355 std::unique_ptr<content::PresentationSessionMessage> message; 354 std::unique_ptr<content::PresentationSessionMessage> message;
356 message.reset( 355 message.reset(
357 new content::PresentationSessionMessage(PresentationMessageType::TEXT)); 356 new content::PresentationSessionMessage(PresentationMessageType::TEXT));
358 message->message = text_msg; 357 message->message = text_msg;
359 messages.push_back(std::move(message)); 358 messages.push_back(std::move(message));
360 message.reset(new content::PresentationSessionMessage( 359 message.reset(new content::PresentationSessionMessage(
361 PresentationMessageType::ARRAY_BUFFER)); 360 PresentationMessageType::BINARY));
362 message->data.reset(new std::vector<uint8_t>(binary_data)); 361 message->data.reset(new std::vector<uint8_t>(binary_data));
363 messages.push_back(std::move(message)); 362 messages.push_back(std::move(message));
364 363
365 std::vector<blink::mojom::SessionMessagePtr> actual_msgs; 364 std::vector<blink::mojom::SessionMessagePtr> actual_msgs;
366 { 365 {
367 base::RunLoop run_loop; 366 base::RunLoop run_loop;
368 EXPECT_CALL(mock_client_, MessagesReceived()) 367 EXPECT_CALL(mock_client_, MessagesReceived())
369 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 368 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
370 message_cb.Run(std::move(messages), pass_ownership); 369 message_cb.Run(std::move(messages), pass_ownership);
371 run_loop.Run(); 370 run_loop.Run();
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 const uint8_t buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48}; 720 const uint8_t buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48};
722 std::vector<uint8_t> data; 721 std::vector<uint8_t> data;
723 data.assign(buffer, buffer + sizeof(buffer)); 722 data.assign(buffer, buffer + sizeof(buffer));
724 723
725 blink::mojom::PresentationSessionInfoPtr session( 724 blink::mojom::PresentationSessionInfoPtr session(
726 blink::mojom::PresentationSessionInfo::New()); 725 blink::mojom::PresentationSessionInfo::New());
727 session->url = presentation_url1_; 726 session->url = presentation_url1_;
728 session->id = kPresentationId; 727 session->id = kPresentationId;
729 blink::mojom::SessionMessagePtr message_request( 728 blink::mojom::SessionMessagePtr message_request(
730 blink::mojom::SessionMessage::New()); 729 blink::mojom::SessionMessage::New());
731 message_request->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER; 730 message_request->type = blink::mojom::PresentationMessageType::BINARY;
732 message_request->data = data; 731 message_request->data = data;
733 service_ptr_->SendSessionMessage( 732 service_ptr_->SendSessionMessage(
734 std::move(session), std::move(message_request), 733 std::move(session), std::move(message_request),
735 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, 734 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback,
736 base::Unretained(this))); 735 base::Unretained(this)));
737 736
738 base::RunLoop run_loop; 737 base::RunLoop run_loop;
739 base::Callback<void(bool)> send_message_cb; 738 base::Callback<void(bool)> send_message_cb;
740 PresentationSessionMessage* test_message = nullptr; 739 PresentationSessionMessage* test_message = nullptr;
741 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) 740 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
742 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 741 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
743 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); 742 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
744 run_loop.Run(); 743 run_loop.Run();
745 744
746 // Make sure |test_message| gets deleted. 745 // Make sure |test_message| gets deleted.
747 std::unique_ptr<PresentationSessionMessage> scoped_test_message(test_message); 746 std::unique_ptr<PresentationSessionMessage> scoped_test_message(test_message);
748 EXPECT_TRUE(test_message); 747 EXPECT_TRUE(test_message);
749 EXPECT_TRUE(test_message->is_binary()); 748 EXPECT_TRUE(test_message->is_binary());
750 EXPECT_EQ(PresentationMessageType::ARRAY_BUFFER, test_message->type); 749 EXPECT_EQ(PresentationMessageType::BINARY, test_message->type);
751 EXPECT_TRUE(test_message->message.empty()); 750 EXPECT_TRUE(test_message->message.empty());
752 ASSERT_TRUE(test_message->data); 751 ASSERT_TRUE(test_message->data);
753 EXPECT_EQ(data.size(), test_message->data->size()); 752 EXPECT_EQ(data.size(), test_message->data->size());
754 EXPECT_LE(test_message->data->size(), kMaxPresentationSessionMessageSize); 753 EXPECT_LE(test_message->data->size(), kMaxPresentationSessionMessageSize);
755 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer))); 754 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer)));
756 send_message_cb.Run(true); 755 send_message_cb.Run(true);
757 SaveQuitClosureAndRunLoop(); 756 SaveQuitClosureAndRunLoop();
758 } 757 }
759 758
760 TEST_F(PresentationServiceImplTest, SendArrayBufferWithExceedingLimit) { 759 TEST_F(PresentationServiceImplTest, SendArrayBufferWithExceedingLimit) {
761 // Create buffer with size exceeding the limit. 760 // Create buffer with size exceeding the limit.
762 // Use same size as in content::kMaxPresentationSessionMessageSize. 761 // Use same size as in content::kMaxPresentationSessionMessageSize.
763 const size_t kMaxBufferSizeInBytes = 64 * 1024; // 64 KB. 762 const size_t kMaxBufferSizeInBytes = 64 * 1024; // 64 KB.
764 uint8_t buffer[kMaxBufferSizeInBytes + 1]; 763 uint8_t buffer[kMaxBufferSizeInBytes + 1];
765 memset(buffer, 0, kMaxBufferSizeInBytes+1); 764 memset(buffer, 0, kMaxBufferSizeInBytes+1);
766 std::vector<uint8_t> data; 765 std::vector<uint8_t> data;
767 data.assign(buffer, buffer + sizeof(buffer)); 766 data.assign(buffer, buffer + sizeof(buffer));
768 767
769 blink::mojom::PresentationSessionInfoPtr session( 768 blink::mojom::PresentationSessionInfoPtr session(
770 blink::mojom::PresentationSessionInfo::New()); 769 blink::mojom::PresentationSessionInfo::New());
771 session->url = presentation_url1_; 770 session->url = presentation_url1_;
772 session->id = kPresentationId; 771 session->id = kPresentationId;
773 blink::mojom::SessionMessagePtr message_request( 772 blink::mojom::SessionMessagePtr message_request(
774 blink::mojom::SessionMessage::New()); 773 blink::mojom::SessionMessage::New());
775 message_request->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER; 774 message_request->type = blink::mojom::PresentationMessageType::BINARY;
776 message_request->data = data; 775 message_request->data = data;
777 service_ptr_->SendSessionMessage( 776 service_ptr_->SendSessionMessage(
778 std::move(session), std::move(message_request), 777 std::move(session), std::move(message_request),
779 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, 778 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback,
780 base::Unretained(this))); 779 base::Unretained(this)));
781 780
782 base::RunLoop run_loop; 781 base::RunLoop run_loop;
783 base::Callback<void(bool)> send_message_cb; 782 base::Callback<void(bool)> send_message_cb;
784 PresentationSessionMessage* test_message = nullptr; 783 PresentationSessionMessage* test_message = nullptr;
785 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) 784 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
(...skipping 10 matching lines...) Expand all
796 const uint8_t buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; 795 const uint8_t buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
797 std::vector<uint8_t> data; 796 std::vector<uint8_t> data;
798 data.assign(buffer, buffer + sizeof(buffer)); 797 data.assign(buffer, buffer + sizeof(buffer));
799 798
800 blink::mojom::PresentationSessionInfoPtr session( 799 blink::mojom::PresentationSessionInfoPtr session(
801 blink::mojom::PresentationSessionInfo::New()); 800 blink::mojom::PresentationSessionInfo::New());
802 session->url = presentation_url1_; 801 session->url = presentation_url1_;
803 session->id = kPresentationId; 802 session->id = kPresentationId;
804 blink::mojom::SessionMessagePtr message_request( 803 blink::mojom::SessionMessagePtr message_request(
805 blink::mojom::SessionMessage::New()); 804 blink::mojom::SessionMessage::New());
806 message_request->type = blink::mojom::PresentationMessageType::BLOB; 805 message_request->type = blink::mojom::PresentationMessageType::BINARY;
807 message_request->data = data; 806 message_request->data = data;
808 service_ptr_->SendSessionMessage( 807 service_ptr_->SendSessionMessage(
809 std::move(session), std::move(message_request), 808 std::move(session), std::move(message_request),
810 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, 809 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback,
811 base::Unretained(this))); 810 base::Unretained(this)));
812 811
813 base::RunLoop run_loop; 812 base::RunLoop run_loop;
814 base::Callback<void(bool)> send_message_cb; 813 base::Callback<void(bool)> send_message_cb;
815 PresentationSessionMessage* test_message = nullptr; 814 PresentationSessionMessage* test_message = nullptr;
816 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) 815 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
817 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 816 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
818 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); 817 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
819 run_loop.Run(); 818 run_loop.Run();
820 819
821 // Make sure |test_message| gets deleted. 820 // Make sure |test_message| gets deleted.
822 std::unique_ptr<PresentationSessionMessage> scoped_test_message(test_message); 821 std::unique_ptr<PresentationSessionMessage> scoped_test_message(test_message);
823 EXPECT_TRUE(test_message); 822 EXPECT_TRUE(test_message);
824 EXPECT_TRUE(test_message->is_binary()); 823 EXPECT_TRUE(test_message->is_binary());
825 EXPECT_EQ(PresentationMessageType::BLOB, test_message->type); 824 EXPECT_EQ(PresentationMessageType::BINARY, test_message->type);
826 EXPECT_TRUE(test_message->message.empty()); 825 EXPECT_TRUE(test_message->message.empty());
827 ASSERT_TRUE(test_message->data); 826 ASSERT_TRUE(test_message->data);
828 EXPECT_EQ(data.size(), test_message->data->size()); 827 EXPECT_EQ(data.size(), test_message->data->size());
829 EXPECT_LE(test_message->data->size(), kMaxPresentationSessionMessageSize); 828 EXPECT_LE(test_message->data->size(), kMaxPresentationSessionMessageSize);
830 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer))); 829 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer)));
831 send_message_cb.Run(true); 830 send_message_cb.Run(true);
832 SaveQuitClosureAndRunLoop(); 831 SaveQuitClosureAndRunLoop();
833 } 832 }
834 833
835 TEST_F(PresentationServiceImplTest, MaxPendingJoinSessionRequests) { 834 TEST_F(PresentationServiceImplTest, MaxPendingJoinSessionRequests) {
(...skipping 22 matching lines...) Expand all
858 mock_delegate_.set_screen_availability_listening_supported(false); 857 mock_delegate_.set_screen_availability_listening_supported(false);
859 base::RunLoop run_loop; 858 base::RunLoop run_loop;
860 EXPECT_CALL(mock_client_, 859 EXPECT_CALL(mock_client_,
861 OnScreenAvailabilityNotSupported(presentation_url1_)) 860 OnScreenAvailabilityNotSupported(presentation_url1_))
862 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 861 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
863 ListenForScreenAvailabilityAndWait(presentation_url1_, false); 862 ListenForScreenAvailabilityAndWait(presentation_url1_, false);
864 run_loop.Run(); 863 run_loop.Run();
865 } 864 }
866 865
867 } // namespace content 866 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698