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

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

Issue 2710703006: Remove unused PresentationServiceImpl message code (Closed)
Patch Set: Remove unused PresentationDispatcher test code Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 324
325 void ExpectReset() { 325 void ExpectReset() {
326 EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1); 326 EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1);
327 } 327 }
328 328
329 void ExpectCleanState() { 329 void ExpectCleanState() {
330 EXPECT_TRUE(service_impl_->default_presentation_urls_.empty()); 330 EXPECT_TRUE(service_impl_->default_presentation_urls_.empty());
331 EXPECT_EQ( 331 EXPECT_EQ(
332 service_impl_->screen_availability_listeners_.find(presentation_url1_), 332 service_impl_->screen_availability_listeners_.find(presentation_url1_),
333 service_impl_->screen_availability_listeners_.end()); 333 service_impl_->screen_availability_listeners_.end());
334 EXPECT_FALSE(service_impl_->on_connection_messages_callback_.get());
335 } 334 }
336 335
337 void ExpectNewSessionCallbackSuccess( 336 void ExpectNewSessionCallbackSuccess(
338 const base::Optional<content::PresentationSessionInfo>& info, 337 const base::Optional<content::PresentationSessionInfo>& info,
339 const base::Optional<content::PresentationError>& error) { 338 const base::Optional<content::PresentationError>& error) {
340 EXPECT_TRUE(info); 339 EXPECT_TRUE(info);
341 EXPECT_FALSE(error); 340 EXPECT_FALSE(error);
342 if (!run_loop_quit_closure_.is_null()) 341 if (!run_loop_quit_closure_.is_null())
343 run_loop_quit_closure_.Run(); 342 run_loop_quit_closure_.Run();
344 } 343 }
345 344
346 void ExpectNewSessionCallbackError( 345 void ExpectNewSessionCallbackError(
347 const base::Optional<content::PresentationSessionInfo>& info, 346 const base::Optional<content::PresentationSessionInfo>& info,
348 const base::Optional<content::PresentationError>& error) { 347 const base::Optional<content::PresentationError>& error) {
349 EXPECT_FALSE(info); 348 EXPECT_FALSE(info);
350 EXPECT_TRUE(error); 349 EXPECT_TRUE(error);
351 if (!run_loop_quit_closure_.is_null()) 350 if (!run_loop_quit_closure_.is_null())
352 run_loop_quit_closure_.Run(); 351 run_loop_quit_closure_.Run();
353 } 352 }
354 353
355 void ExpectConnectionMessages( 354 void ExpectConnectionMessages(
356 const std::vector<blink::mojom::ConnectionMessagePtr>& expected_msgs, 355 const std::vector<blink::mojom::ConnectionMessagePtr>& expected_msgs,
357 const std::vector<blink::mojom::ConnectionMessagePtr>& actual_msgs) { 356 const std::vector<blink::mojom::ConnectionMessagePtr>& actual_msgs) {
358 EXPECT_EQ(expected_msgs.size(), actual_msgs.size()); 357 EXPECT_EQ(expected_msgs.size(), actual_msgs.size());
359 for (size_t i = 0; i < actual_msgs.size(); ++i) 358 for (size_t i = 0; i < actual_msgs.size(); ++i)
360 EXPECT_TRUE(expected_msgs[i].Equals(actual_msgs[i])); 359 EXPECT_TRUE(expected_msgs[i].Equals(actual_msgs[i]));
361 } 360 }
362 361
363 void ExpectSendConnectionMessageCallback(bool success) {
364 EXPECT_TRUE(success);
365 EXPECT_FALSE(service_impl_->send_message_callback_);
366 if (!run_loop_quit_closure_.is_null())
367 run_loop_quit_closure_.Run();
368 }
369
370 void RunListenForConnectionMessages(const std::string& text_msg, 362 void RunListenForConnectionMessages(const std::string& text_msg,
371 const std::vector<uint8_t>& binary_data, 363 const std::vector<uint8_t>& binary_data,
372 bool pass_ownership) { 364 bool pass_ownership) {
373 std::vector<blink::mojom::ConnectionMessagePtr> expected_msgs(2); 365 std::vector<blink::mojom::ConnectionMessagePtr> expected_msgs(2);
374 expected_msgs[0] = blink::mojom::ConnectionMessage::New(); 366 expected_msgs[0] = blink::mojom::ConnectionMessage::New();
375 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT; 367 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT;
376 expected_msgs[0]->message = text_msg; 368 expected_msgs[0]->message = text_msg;
377 expected_msgs[1] = blink::mojom::ConnectionMessage::New(); 369 expected_msgs[1] = blink::mojom::ConnectionMessage::New();
378 expected_msgs[1]->type = blink::mojom::PresentationMessageType::BINARY; 370 expected_msgs[1]->type = blink::mojom::PresentationMessageType::BINARY;
379 expected_msgs[1]->data = binary_data; 371 expected_msgs[1]->data = binary_data;
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 736
745 // This request should fail immediately, since there is already a StartSession 737 // This request should fail immediately, since there is already a StartSession
746 // in progress. 738 // in progress.
747 service_ptr_->StartSession( 739 service_ptr_->StartSession(
748 presentation_urls_, 740 presentation_urls_,
749 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, 741 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError,
750 base::Unretained(this))); 742 base::Unretained(this)));
751 SaveQuitClosureAndRunLoop(); 743 SaveQuitClosureAndRunLoop();
752 } 744 }
753 745
754 TEST_F(PresentationServiceImplTest, SendStringMessage) {
755 std::string message("Test presentation session message");
756
757 content::PresentationSessionInfo session(presentation_url1_, kPresentationId);
758 blink::mojom::ConnectionMessagePtr message_request(
759 blink::mojom::ConnectionMessage::New());
760 message_request->type = blink::mojom::PresentationMessageType::TEXT;
761 message_request->message = message;
762 service_ptr_->SendConnectionMessage(
763 session, std::move(message_request),
764 base::Bind(
765 &PresentationServiceImplTest::ExpectSendConnectionMessageCallback,
766 base::Unretained(this)));
767
768 base::RunLoop run_loop;
769 base::Callback<void(bool)> send_message_cb;
770 PresentationConnectionMessage* test_message = nullptr;
771 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
772 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
773 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
774 run_loop.Run();
775
776 // Make sure |test_message| gets deleted.
777 std::unique_ptr<PresentationConnectionMessage> scoped_test_message(
778 test_message);
779 EXPECT_TRUE(test_message);
780 EXPECT_FALSE(test_message->is_binary());
781 EXPECT_LE(test_message->message.size(),
782 kMaxPresentationConnectionMessageSize);
783 EXPECT_EQ(message, test_message->message);
784 ASSERT_FALSE(test_message->data);
785 send_message_cb.Run(true);
786 SaveQuitClosureAndRunLoop();
787 }
788
789 TEST_F(PresentationServiceImplTest, SendArrayBuffer) {
790 // Test Array buffer data.
791 const uint8_t buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48};
792 std::vector<uint8_t> data;
793 data.assign(buffer, buffer + sizeof(buffer));
794
795 content::PresentationSessionInfo session(presentation_url1_, kPresentationId);
796 blink::mojom::ConnectionMessagePtr message_request(
797 blink::mojom::ConnectionMessage::New());
798 message_request->type = blink::mojom::PresentationMessageType::BINARY;
799 message_request->data = data;
800 service_ptr_->SendConnectionMessage(
801 session, std::move(message_request),
802 base::Bind(
803 &PresentationServiceImplTest::ExpectSendConnectionMessageCallback,
804 base::Unretained(this)));
805
806 base::RunLoop run_loop;
807 base::Callback<void(bool)> send_message_cb;
808 PresentationConnectionMessage* test_message = nullptr;
809 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
810 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
811 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
812 run_loop.Run();
813
814 // Make sure |test_message| gets deleted.
815 std::unique_ptr<PresentationConnectionMessage> scoped_test_message(
816 test_message);
817 EXPECT_TRUE(test_message);
818 EXPECT_TRUE(test_message->is_binary());
819 EXPECT_EQ(PresentationMessageType::BINARY, test_message->type);
820 EXPECT_TRUE(test_message->message.empty());
821 ASSERT_TRUE(test_message->data);
822 EXPECT_EQ(data.size(), test_message->data->size());
823 EXPECT_LE(test_message->data->size(), kMaxPresentationConnectionMessageSize);
824 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer)));
825 send_message_cb.Run(true);
826 SaveQuitClosureAndRunLoop();
827 }
828
829 TEST_F(PresentationServiceImplTest, SendArrayBufferWithExceedingLimit) {
830 // Create buffer with size exceeding the limit.
831 // Use same size as in content::kMaxPresentationConnectionMessageSize.
832 const size_t kMaxBufferSizeInBytes = 64 * 1024; // 64 KB.
833 uint8_t buffer[kMaxBufferSizeInBytes + 1];
834 memset(buffer, 0, kMaxBufferSizeInBytes+1);
835 std::vector<uint8_t> data;
836 data.assign(buffer, buffer + sizeof(buffer));
837
838 content::PresentationSessionInfo session(presentation_url1_, kPresentationId);
839 blink::mojom::ConnectionMessagePtr message_request(
840 blink::mojom::ConnectionMessage::New());
841 message_request->type = blink::mojom::PresentationMessageType::BINARY;
842 message_request->data = data;
843 service_ptr_->SendConnectionMessage(
844 session, std::move(message_request),
845 base::Bind(
846 &PresentationServiceImplTest::ExpectSendConnectionMessageCallback,
847 base::Unretained(this)));
848
849 base::RunLoop run_loop;
850 base::Callback<void(bool)> send_message_cb;
851 PresentationConnectionMessage* test_message = nullptr;
852 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
853 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
854 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
855 run_loop.Run();
856
857 EXPECT_FALSE(test_message);
858 send_message_cb.Run(true);
859 SaveQuitClosureAndRunLoop();
860 }
861
862 TEST_F(PresentationServiceImplTest, SendBlobData) {
863 const uint8_t buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
864 std::vector<uint8_t> data;
865 data.assign(buffer, buffer + sizeof(buffer));
866
867 content::PresentationSessionInfo session(presentation_url1_, kPresentationId);
868 blink::mojom::ConnectionMessagePtr message_request(
869 blink::mojom::ConnectionMessage::New());
870 message_request->type = blink::mojom::PresentationMessageType::BINARY;
871 message_request->data = data;
872 service_ptr_->SendConnectionMessage(
873 session, std::move(message_request),
874 base::Bind(
875 &PresentationServiceImplTest::ExpectSendConnectionMessageCallback,
876 base::Unretained(this)));
877
878 base::RunLoop run_loop;
879 base::Callback<void(bool)> send_message_cb;
880 PresentationConnectionMessage* test_message = nullptr;
881 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
882 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
883 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
884 run_loop.Run();
885
886 // Make sure |test_message| gets deleted.
887 std::unique_ptr<PresentationConnectionMessage> scoped_test_message(
888 test_message);
889 EXPECT_TRUE(test_message);
890 EXPECT_TRUE(test_message->is_binary());
891 EXPECT_EQ(PresentationMessageType::BINARY, test_message->type);
892 EXPECT_TRUE(test_message->message.empty());
893 ASSERT_TRUE(test_message->data);
894 EXPECT_EQ(data.size(), test_message->data->size());
895 EXPECT_LE(test_message->data->size(), kMaxPresentationConnectionMessageSize);
896 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer)));
897 send_message_cb.Run(true);
898 SaveQuitClosureAndRunLoop();
899 }
900
901 TEST_F(PresentationServiceImplTest, MaxPendingJoinSessionRequests) { 746 TEST_F(PresentationServiceImplTest, MaxPendingJoinSessionRequests) {
902 const char* presentation_url = "http://fooUrl%d"; 747 const char* presentation_url = "http://fooUrl%d";
903 const char* presentation_id = "presentationId%d"; 748 const char* presentation_id = "presentationId%d";
904 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests; 749 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests;
905 int i = 0; 750 int i = 0;
906 EXPECT_CALL(mock_delegate_, JoinSession(_, _, _, _, _, _)) 751 EXPECT_CALL(mock_delegate_, JoinSession(_, _, _, _, _, _))
907 .Times(num_requests); 752 .Times(num_requests);
908 for (; i < num_requests; ++i) { 753 for (; i < num_requests; ++i) {
909 std::vector<GURL> urls = {GURL(base::StringPrintf(presentation_url, i))}; 754 std::vector<GURL> urls = {GURL(base::StringPrintf(presentation_url, i))};
910 service_ptr_->JoinSession(urls, base::StringPrintf(presentation_id, i), 755 service_ptr_->JoinSession(urls, base::StringPrintf(presentation_id, i),
(...skipping 13 matching lines...) Expand all
924 mock_delegate_.set_screen_availability_listening_supported(false); 769 mock_delegate_.set_screen_availability_listening_supported(false);
925 base::RunLoop run_loop; 770 base::RunLoop run_loop;
926 EXPECT_CALL(mock_client_, 771 EXPECT_CALL(mock_client_,
927 OnScreenAvailabilityNotSupported(presentation_url1_)) 772 OnScreenAvailabilityNotSupported(presentation_url1_))
928 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 773 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
929 ListenForScreenAvailabilityAndWait(presentation_url1_, false); 774 ListenForScreenAvailabilityAndWait(presentation_url1_, false);
930 run_loop.Run(); 775 run_loop.Run();
931 } 776 }
932 777
933 } // namespace content 778 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698