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

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

Issue 1140713005: [PresentationAPI] Implements send API for Blob data from WebPresentationClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated unit tests Created 5 years, 7 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
9 #include "content/browser/presentation/presentation_service_impl.h" 9 #include "content/browser/presentation/presentation_service_impl.h"
10 #include "content/public/browser/presentation_service_delegate.h" 10 #include "content/public/browser/presentation_service_delegate.h"
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 scoped_ptr<ScopedVector<PresentationSessionMessage>> messages( 299 scoped_ptr<ScopedVector<PresentationSessionMessage>> messages(
300 new ScopedVector<PresentationSessionMessage>()); 300 new ScopedVector<PresentationSessionMessage>());
301 messages->push_back( 301 messages->push_back(
302 content::PresentationSessionMessage::CreateStringMessage( 302 content::PresentationSessionMessage::CreateStringMessage(
303 presentation_url, presentation_id, 303 presentation_url, presentation_id,
304 scoped_ptr<std::string>(new std::string(text_msg)))); 304 scoped_ptr<std::string>(new std::string(text_msg))));
305 messages->push_back( 305 messages->push_back(
306 content::PresentationSessionMessage::CreateBinaryMessage( 306 content::PresentationSessionMessage::CreateBinaryMessage(
307 presentation_url, presentation_id, 307 presentation_url, presentation_id,
308 scoped_ptr<std::vector<uint8_t>>( 308 scoped_ptr<std::vector<uint8_t>>(
309 new std::vector<uint8_t>(binary_data)))); 309 new std::vector<uint8_t>(binary_data)),
310 PresentationMessageType::ARRAY_BUFFER));
310 message_cb.Run(messages.Pass()); 311 message_cb.Run(messages.Pass());
311 SaveQuitClosureAndRunLoop(); 312 SaveQuitClosureAndRunLoop();
312 } 313 }
313 314
314 MockPresentationServiceDelegate mock_delegate_; 315 MockPresentationServiceDelegate mock_delegate_;
315 316
316 scoped_ptr<PresentationServiceImpl> service_impl_; 317 scoped_ptr<PresentationServiceImpl> service_impl_;
317 mojo::InterfacePtr<presentation::PresentationService> service_ptr_; 318 mojo::InterfacePtr<presentation::PresentationService> service_ptr_;
318 319
319 MockPresentationServiceClient mock_client_; 320 MockPresentationServiceClient mock_client_;
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 .WillOnce(DoAll( 732 .WillOnce(DoAll(
732 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 733 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
733 SaveArg<2>(&test_message), 734 SaveArg<2>(&test_message),
734 SaveArg<3>(&send_message_cb))); 735 SaveArg<3>(&send_message_cb)));
735 run_loop.Run(); 736 run_loop.Run();
736 737
737 EXPECT_TRUE(test_message); 738 EXPECT_TRUE(test_message);
738 EXPECT_EQ(presentation_url, test_message->presentation_url); 739 EXPECT_EQ(presentation_url, test_message->presentation_url);
739 EXPECT_EQ(presentation_id, test_message->presentation_id); 740 EXPECT_EQ(presentation_id, test_message->presentation_id);
740 EXPECT_TRUE(test_message->is_binary()); 741 EXPECT_TRUE(test_message->is_binary());
742 EXPECT_EQ(PresentationMessageType::ARRAY_BUFFER, test_message->type);
741 EXPECT_FALSE(test_message->message); 743 EXPECT_FALSE(test_message->message);
742 EXPECT_EQ(data.size(), test_message->data.get()->size()); 744 EXPECT_EQ(data.size(), test_message->data.get()->size());
743 EXPECT_TRUE(test_message->data.get()->size() <= 745 EXPECT_TRUE(test_message->data.get()->size() <=
744 kMaxPresentationSessionMessageSize); 746 kMaxPresentationSessionMessageSize);
745 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data.get())[0], sizeof(buffer))); 747 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data.get())[0], sizeof(buffer)));
746 delete test_message; 748 delete test_message;
747 send_message_cb.Run(); 749 send_message_cb.Run();
748 SaveQuitClosureAndRunLoop(); 750 SaveQuitClosureAndRunLoop();
749 } 751 }
750 752
(...skipping 30 matching lines...) Expand all
781 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 783 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
782 SaveArg<2>(&test_message), 784 SaveArg<2>(&test_message),
783 SaveArg<3>(&send_message_cb))); 785 SaveArg<3>(&send_message_cb)));
784 run_loop.Run(); 786 run_loop.Run();
785 787
786 EXPECT_FALSE(test_message); 788 EXPECT_FALSE(test_message);
787 send_message_cb.Run(); 789 send_message_cb.Run();
788 SaveQuitClosureAndRunLoop(); 790 SaveQuitClosureAndRunLoop();
789 } 791 }
790 792
793 TEST_F(PresentationServiceImplTest, SendBlobData) {
794 std::string presentation_url("http://foo.com/index.html");
795 std::string presentation_id("presentationId");
796 const uint8 buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
797 std::vector<uint8> data;
798 data.assign(buffer, buffer + sizeof(buffer));
799
800 presentation::SessionMessagePtr message_request(
801 presentation::SessionMessage::New());
802 message_request->presentation_url = presentation_url;
803 message_request->presentation_id = presentation_id;
804 message_request->type = presentation::PresentationMessageType::
805 PRESENTATION_MESSAGE_TYPE_BLOB;
806 message_request->data = mojo::Array<uint8>::From(data);
807 service_ptr_->SendSessionMessage(
808 message_request.Pass(),
809 base::Bind(
810 &PresentationServiceImplTest::ExpectSendMessageMojoCallback,
811 base::Unretained(this)));
812
813 base::RunLoop run_loop;
814 base::Closure send_message_cb;
815 PresentationSessionMessage* test_message = nullptr;
816 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(
817 _, _, _, _))
818 .WillOnce(DoAll(
819 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
820 SaveArg<2>(&test_message),
821 SaveArg<3>(&send_message_cb)));
822 run_loop.Run();
823
824 EXPECT_TRUE(test_message);
825 EXPECT_EQ(presentation_url, test_message->presentation_url);
826 EXPECT_EQ(presentation_id, test_message->presentation_id);
827 EXPECT_TRUE(test_message->is_binary());
828 EXPECT_EQ(PresentationMessageType::BLOB, test_message->type);
829 EXPECT_FALSE(test_message->message);
830 EXPECT_EQ(data.size(), test_message->data.get()->size());
831 EXPECT_TRUE(test_message->data.get()->size() <=
832 kMaxPresentationSessionMessageSize);
833 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data.get())[0], sizeof(buffer)));
834 delete test_message;
835 send_message_cb.Run();
836 SaveQuitClosureAndRunLoop();
mark a. foltz 2015/06/02 23:51:02 Nice test case :)
837 }
838
791 TEST_F(PresentationServiceImplTest, MaxPendingStartSessionRequests) { 839 TEST_F(PresentationServiceImplTest, MaxPendingStartSessionRequests) {
792 const char* presentation_url = "http://fooUrl%d"; 840 const char* presentation_url = "http://fooUrl%d";
793 const char* presentation_id = "presentationId%d"; 841 const char* presentation_id = "presentationId%d";
794 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests + 1; 842 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests + 1;
795 int i = 0; 843 int i = 0;
796 // First request will be processed. The subsequent 844 // First request will be processed. The subsequent
797 // |kMaxNumQueuedSessionRequests| requests will be queued. 845 // |kMaxNumQueuedSessionRequests| requests will be queued.
798 EXPECT_CALL(mock_delegate_, StartSession(_, _, _, _, _, _)).Times(1); 846 EXPECT_CALL(mock_delegate_, StartSession(_, _, _, _, _, _)).Times(1);
799 for (; i < num_requests; ++i) { 847 for (; i < num_requests; ++i) {
800 service_ptr_->StartSession( 848 service_ptr_->StartSession(
(...skipping 30 matching lines...) Expand all
831 service_ptr_->JoinSession( 879 service_ptr_->JoinSession(
832 base::StringPrintf(presentation_url, i), 880 base::StringPrintf(presentation_url, i),
833 base::StringPrintf(presentation_id, i), 881 base::StringPrintf(presentation_id, i),
834 base::Bind( 882 base::Bind(
835 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, 883 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
836 base::Unretained(this))); 884 base::Unretained(this)));
837 SaveQuitClosureAndRunLoop(); 885 SaveQuitClosureAndRunLoop();
838 } 886 }
839 887
840 } // namespace content 888 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698