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 "base/location.h" | 5 #include "base/location.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 SaveArg<2>(&message_cb))); | 298 SaveArg<2>(&message_cb))); |
299 run_loop.Run(); | 299 run_loop.Run(); |
300 | 300 |
301 scoped_ptr<ScopedVector<PresentationSessionMessage>> messages( | 301 scoped_ptr<ScopedVector<PresentationSessionMessage>> messages( |
302 new ScopedVector<PresentationSessionMessage>()); | 302 new ScopedVector<PresentationSessionMessage>()); |
303 messages->push_back( | 303 messages->push_back( |
304 content::PresentationSessionMessage::CreateStringMessage( | 304 content::PresentationSessionMessage::CreateStringMessage( |
305 presentation_url, presentation_id, | 305 presentation_url, presentation_id, |
306 scoped_ptr<std::string>(new std::string(text_msg)))); | 306 scoped_ptr<std::string>(new std::string(text_msg)))); |
307 messages->push_back( | 307 messages->push_back( |
308 content::PresentationSessionMessage::CreateBinaryMessage( | 308 content::PresentationSessionMessage::CreateArrayBufferMessage( |
309 presentation_url, presentation_id, | 309 presentation_url, presentation_id, |
310 scoped_ptr<std::vector<uint8_t>>( | 310 scoped_ptr<std::vector<uint8_t>>( |
311 new std::vector<uint8_t>(binary_data)))); | 311 new std::vector<uint8_t>(binary_data)))); |
312 message_cb.Run(messages.Pass()); | 312 message_cb.Run(messages.Pass()); |
313 SaveQuitClosureAndRunLoop(); | 313 SaveQuitClosureAndRunLoop(); |
314 } | 314 } |
315 | 315 |
316 MockPresentationServiceDelegate mock_delegate_; | 316 MockPresentationServiceDelegate mock_delegate_; |
317 | 317 |
318 scoped_ptr<PresentationServiceImpl> service_impl_; | 318 scoped_ptr<PresentationServiceImpl> service_impl_; |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 .WillOnce(DoAll( | 733 .WillOnce(DoAll( |
734 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 734 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
735 SaveArg<2>(&test_message), | 735 SaveArg<2>(&test_message), |
736 SaveArg<3>(&send_message_cb))); | 736 SaveArg<3>(&send_message_cb))); |
737 run_loop.Run(); | 737 run_loop.Run(); |
738 | 738 |
739 EXPECT_TRUE(test_message); | 739 EXPECT_TRUE(test_message); |
740 EXPECT_EQ(presentation_url, test_message->presentation_url); | 740 EXPECT_EQ(presentation_url, test_message->presentation_url); |
741 EXPECT_EQ(presentation_id, test_message->presentation_id); | 741 EXPECT_EQ(presentation_id, test_message->presentation_id); |
742 EXPECT_TRUE(test_message->is_binary()); | 742 EXPECT_TRUE(test_message->is_binary()); |
| 743 EXPECT_EQ(PresentationMessageType::ARRAY_BUFFER, test_message->type); |
743 EXPECT_FALSE(test_message->message); | 744 EXPECT_FALSE(test_message->message); |
744 EXPECT_EQ(data.size(), test_message->data.get()->size()); | 745 EXPECT_EQ(data.size(), test_message->data.get()->size()); |
745 EXPECT_TRUE(test_message->data.get()->size() <= | 746 EXPECT_TRUE(test_message->data.get()->size() <= |
746 kMaxPresentationSessionMessageSize); | 747 kMaxPresentationSessionMessageSize); |
747 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data.get())[0], sizeof(buffer))); | 748 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data.get())[0], sizeof(buffer))); |
748 delete test_message; | 749 delete test_message; |
749 send_message_cb.Run(); | 750 send_message_cb.Run(); |
750 SaveQuitClosureAndRunLoop(); | 751 SaveQuitClosureAndRunLoop(); |
751 } | 752 } |
752 | 753 |
(...skipping 30 matching lines...) Expand all Loading... |
783 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 784 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
784 SaveArg<2>(&test_message), | 785 SaveArg<2>(&test_message), |
785 SaveArg<3>(&send_message_cb))); | 786 SaveArg<3>(&send_message_cb))); |
786 run_loop.Run(); | 787 run_loop.Run(); |
787 | 788 |
788 EXPECT_FALSE(test_message); | 789 EXPECT_FALSE(test_message); |
789 send_message_cb.Run(); | 790 send_message_cb.Run(); |
790 SaveQuitClosureAndRunLoop(); | 791 SaveQuitClosureAndRunLoop(); |
791 } | 792 } |
792 | 793 |
| 794 TEST_F(PresentationServiceImplTest, SendBlobData) { |
| 795 std::string presentation_url("http://foo.com/index.html"); |
| 796 std::string presentation_id("presentationId"); |
| 797 const uint8 buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; |
| 798 std::vector<uint8> data; |
| 799 data.assign(buffer, buffer + sizeof(buffer)); |
| 800 |
| 801 presentation::SessionMessagePtr message_request( |
| 802 presentation::SessionMessage::New()); |
| 803 message_request->presentation_url = presentation_url; |
| 804 message_request->presentation_id = presentation_id; |
| 805 message_request->type = |
| 806 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_BLOB; |
| 807 message_request->data = mojo::Array<uint8>::From(data); |
| 808 service_ptr_->SendSessionMessage( |
| 809 message_request.Pass(), |
| 810 base::Bind(&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 .WillOnce(DoAll( |
| 818 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
| 819 SaveArg<2>(&test_message), |
| 820 SaveArg<3>(&send_message_cb))); |
| 821 run_loop.Run(); |
| 822 |
| 823 EXPECT_TRUE(test_message); |
| 824 EXPECT_EQ(presentation_url, test_message->presentation_url); |
| 825 EXPECT_EQ(presentation_id, test_message->presentation_id); |
| 826 EXPECT_TRUE(test_message->is_binary()); |
| 827 EXPECT_EQ(PresentationMessageType::BLOB, test_message->type); |
| 828 EXPECT_FALSE(test_message->message); |
| 829 EXPECT_EQ(data.size(), test_message->data.get()->size()); |
| 830 EXPECT_TRUE(test_message->data.get()->size() <= |
| 831 kMaxPresentationSessionMessageSize); |
| 832 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data.get())[0], sizeof(buffer))); |
| 833 delete test_message; |
| 834 send_message_cb.Run(); |
| 835 SaveQuitClosureAndRunLoop(); |
| 836 } |
| 837 |
793 TEST_F(PresentationServiceImplTest, MaxPendingStartSessionRequests) { | 838 TEST_F(PresentationServiceImplTest, MaxPendingStartSessionRequests) { |
794 const char* presentation_url = "http://fooUrl%d"; | 839 const char* presentation_url = "http://fooUrl%d"; |
795 const char* presentation_id = "presentationId%d"; | 840 const char* presentation_id = "presentationId%d"; |
796 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests + 1; | 841 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests + 1; |
797 int i = 0; | 842 int i = 0; |
798 // First request will be processed. The subsequent | 843 // First request will be processed. The subsequent |
799 // |kMaxNumQueuedSessionRequests| requests will be queued. | 844 // |kMaxNumQueuedSessionRequests| requests will be queued. |
800 EXPECT_CALL(mock_delegate_, StartSession(_, _, _, _, _, _)).Times(1); | 845 EXPECT_CALL(mock_delegate_, StartSession(_, _, _, _, _, _)).Times(1); |
801 for (; i < num_requests; ++i) { | 846 for (; i < num_requests; ++i) { |
802 service_ptr_->StartSession( | 847 service_ptr_->StartSession( |
(...skipping 30 matching lines...) Expand all Loading... |
833 service_ptr_->JoinSession( | 878 service_ptr_->JoinSession( |
834 base::StringPrintf(presentation_url, i), | 879 base::StringPrintf(presentation_url, i), |
835 base::StringPrintf(presentation_id, i), | 880 base::StringPrintf(presentation_id, i), |
836 base::Bind( | 881 base::Bind( |
837 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, | 882 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, |
838 base::Unretained(this))); | 883 base::Unretained(this))); |
839 SaveQuitClosureAndRunLoop(); | 884 SaveQuitClosureAndRunLoop(); |
840 } | 885 } |
841 | 886 |
842 } // namespace content | 887 } // namespace content |
OLD | NEW |