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

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: review fixes and cl format. Created 5 years, 6 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 SaveArg<2>(&message_cb))); 296 SaveArg<2>(&message_cb)));
297 run_loop.Run(); 297 run_loop.Run();
298 298
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::CreateArrayBufferMessage(
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 message_cb.Run(messages.Pass()); 310 message_cb.Run(messages.Pass());
311 SaveQuitClosureAndRunLoop(); 311 SaveQuitClosureAndRunLoop();
312 } 312 }
313 313
314 MockPresentationServiceDelegate mock_delegate_; 314 MockPresentationServiceDelegate mock_delegate_;
315 315
316 scoped_ptr<PresentationServiceImpl> service_impl_; 316 scoped_ptr<PresentationServiceImpl> service_impl_;
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 .WillOnce(DoAll( 731 .WillOnce(DoAll(
732 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 732 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
733 SaveArg<2>(&test_message), 733 SaveArg<2>(&test_message),
734 SaveArg<3>(&send_message_cb))); 734 SaveArg<3>(&send_message_cb)));
735 run_loop.Run(); 735 run_loop.Run();
736 736
737 EXPECT_TRUE(test_message); 737 EXPECT_TRUE(test_message);
738 EXPECT_EQ(presentation_url, test_message->presentation_url); 738 EXPECT_EQ(presentation_url, test_message->presentation_url);
739 EXPECT_EQ(presentation_id, test_message->presentation_id); 739 EXPECT_EQ(presentation_id, test_message->presentation_id);
740 EXPECT_TRUE(test_message->is_binary()); 740 EXPECT_TRUE(test_message->is_binary());
741 EXPECT_EQ(PresentationMessageType::ARRAY_BUFFER, test_message->type);
741 EXPECT_FALSE(test_message->message); 742 EXPECT_FALSE(test_message->message);
742 EXPECT_EQ(data.size(), test_message->data.get()->size()); 743 EXPECT_EQ(data.size(), test_message->data.get()->size());
743 EXPECT_TRUE(test_message->data.get()->size() <= 744 EXPECT_TRUE(test_message->data.get()->size() <=
744 kMaxPresentationSessionMessageSize); 745 kMaxPresentationSessionMessageSize);
745 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data.get())[0], sizeof(buffer))); 746 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data.get())[0], sizeof(buffer)));
746 delete test_message; 747 delete test_message;
747 send_message_cb.Run(); 748 send_message_cb.Run();
748 SaveQuitClosureAndRunLoop(); 749 SaveQuitClosureAndRunLoop();
749 } 750 }
750 751
(...skipping 30 matching lines...) Expand all
781 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 782 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
782 SaveArg<2>(&test_message), 783 SaveArg<2>(&test_message),
783 SaveArg<3>(&send_message_cb))); 784 SaveArg<3>(&send_message_cb)));
784 run_loop.Run(); 785 run_loop.Run();
785 786
786 EXPECT_FALSE(test_message); 787 EXPECT_FALSE(test_message);
787 send_message_cb.Run(); 788 send_message_cb.Run();
788 SaveQuitClosureAndRunLoop(); 789 SaveQuitClosureAndRunLoop();
789 } 790 }
790 791
792 TEST_F(PresentationServiceImplTest, SendBlobData) {
793 std::string presentation_url("http://foo.com/index.html");
794 std::string presentation_id("presentationId");
795 const uint8 buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
796 std::vector<uint8> data;
797 data.assign(buffer, buffer + sizeof(buffer));
798
799 presentation::SessionMessagePtr message_request(
800 presentation::SessionMessage::New());
801 message_request->presentation_url = presentation_url;
802 message_request->presentation_id = presentation_id;
803 message_request->type =
804 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_BLOB;
805 message_request->data = mojo::Array<uint8>::From(data);
806 service_ptr_->SendSessionMessage(
807 message_request.Pass(),
808 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback,
809 base::Unretained(this)));
810
811 base::RunLoop run_loop;
812 base::Closure send_message_cb;
813 PresentationSessionMessage* test_message = nullptr;
814 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _))
815 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
mark a. foltz 2015/06/05 22:40:56 I preferred the previous formatting that kept the
USE s.singapati at gmail.com 2015/06/08 13:04:19 Done.
816 SaveArg<2>(&test_message), SaveArg<3>(&send_message_cb)));
817 run_loop.Run();
818
819 EXPECT_TRUE(test_message);
820 EXPECT_EQ(presentation_url, test_message->presentation_url);
821 EXPECT_EQ(presentation_id, test_message->presentation_id);
822 EXPECT_TRUE(test_message->is_binary());
823 EXPECT_EQ(PresentationMessageType::BLOB, test_message->type);
824 EXPECT_FALSE(test_message->message);
825 EXPECT_EQ(data.size(), test_message->data.get()->size());
826 EXPECT_TRUE(test_message->data.get()->size() <=
827 kMaxPresentationSessionMessageSize);
828 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data.get())[0], sizeof(buffer)));
829 delete test_message;
830 send_message_cb.Run();
831 SaveQuitClosureAndRunLoop();
832 }
833
791 TEST_F(PresentationServiceImplTest, MaxPendingStartSessionRequests) { 834 TEST_F(PresentationServiceImplTest, MaxPendingStartSessionRequests) {
792 const char* presentation_url = "http://fooUrl%d"; 835 const char* presentation_url = "http://fooUrl%d";
793 const char* presentation_id = "presentationId%d"; 836 const char* presentation_id = "presentationId%d";
794 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests + 1; 837 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests + 1;
795 int i = 0; 838 int i = 0;
796 // First request will be processed. The subsequent 839 // First request will be processed. The subsequent
797 // |kMaxNumQueuedSessionRequests| requests will be queued. 840 // |kMaxNumQueuedSessionRequests| requests will be queued.
798 EXPECT_CALL(mock_delegate_, StartSession(_, _, _, _, _, _)).Times(1); 841 EXPECT_CALL(mock_delegate_, StartSession(_, _, _, _, _, _)).Times(1);
799 for (; i < num_requests; ++i) { 842 for (; i < num_requests; ++i) {
800 service_ptr_->StartSession( 843 service_ptr_->StartSession(
(...skipping 30 matching lines...) Expand all
831 service_ptr_->JoinSession( 874 service_ptr_->JoinSession(
832 base::StringPrintf(presentation_url, i), 875 base::StringPrintf(presentation_url, i),
833 base::StringPrintf(presentation_id, i), 876 base::StringPrintf(presentation_id, i),
834 base::Bind( 877 base::Bind(
835 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, 878 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
836 base::Unretained(this))); 879 base::Unretained(this)));
837 SaveQuitClosureAndRunLoop(); 880 SaveQuitClosureAndRunLoop();
838 } 881 }
839 882
840 } // namespace content 883 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698