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

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

Issue 1259073004: [Presentation API] Change ListenForSessionMessages API to client-style. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update comments Created 5 years, 4 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/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 28 matching lines...) Expand all
39 39
40 bool ArePresentationSessionsEqual( 40 bool ArePresentationSessionsEqual(
41 const presentation::PresentationSessionInfo& expected, 41 const presentation::PresentationSessionInfo& expected,
42 const presentation::PresentationSessionInfo& actual) { 42 const presentation::PresentationSessionInfo& actual) {
43 return expected.url == actual.url && expected.id == actual.id; 43 return expected.url == actual.url && expected.id == actual.id;
44 } 44 }
45 45
46 bool ArePresentationSessionMessagesEqual( 46 bool ArePresentationSessionMessagesEqual(
47 const presentation::SessionMessage* expected, 47 const presentation::SessionMessage* expected,
48 const presentation::SessionMessage* actual) { 48 const presentation::SessionMessage* actual) {
49 return expected->presentation_url == actual->presentation_url && 49 return expected->type == actual->type &&
50 expected->presentation_id == actual->presentation_id &&
51 expected->type == actual->type &&
52 expected->message == actual->message && 50 expected->message == actual->message &&
53 expected->data.Equals(actual->data); 51 expected->data.Equals(actual->data);
54 } 52 }
55 53
56 void DoNothing( 54 void DoNothing(
57 presentation::PresentationSessionInfoPtr info, 55 presentation::PresentationSessionInfoPtr info,
58 presentation::PresentationErrorPtr error) { 56 presentation::PresentationErrorPtr error) {
59 } 57 }
60 58
61 } // namespace 59 } // namespace
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 int render_process_id, 97 int render_process_id,
100 int render_frame_id, 98 int render_frame_id,
101 const std::string& presentation_url, 99 const std::string& presentation_url,
102 const std::string& presentation_id, 100 const std::string& presentation_id,
103 const PresentationSessionSuccessCallback& success_cb, 101 const PresentationSessionSuccessCallback& success_cb,
104 const PresentationSessionErrorCallback& error_cb)); 102 const PresentationSessionErrorCallback& error_cb));
105 MOCK_METHOD3(CloseSession, 103 MOCK_METHOD3(CloseSession,
106 void(int render_process_id, 104 void(int render_process_id,
107 int render_frame_id, 105 int render_frame_id,
108 const std::string& presentation_id)); 106 const std::string& presentation_id));
109 MOCK_METHOD3(ListenForSessionMessages, 107 MOCK_METHOD4(ListenForSessionMessages,
110 void( 108 void(int render_process_id,
111 int render_process_id, 109 int render_frame_id,
112 int render_frame_id, 110 const content::PresentationSessionInfo& session,
113 const PresentationSessionMessageCallback& message_cb)); 111 const PresentationSessionMessageCallback& message_cb));
114 MOCK_METHOD4(SendMessageRawPtr, 112 MOCK_METHOD5(SendMessageRawPtr,
115 void( 113 void(int render_process_id,
116 int render_process_id, 114 int render_frame_id,
117 int render_frame_id, 115 const content::PresentationSessionInfo& session,
118 PresentationSessionMessage* message_request, 116 PresentationSessionMessage* message_request,
119 const SendMessageCallback& send_message_cb)); 117 const SendMessageCallback& send_message_cb));
120 void SendMessage(int render_process_id, 118 void SendMessage(int render_process_id,
121 int render_frame_id, 119 int render_frame_id,
120 const content::PresentationSessionInfo& session,
122 scoped_ptr<PresentationSessionMessage> message_request, 121 scoped_ptr<PresentationSessionMessage> message_request,
123 const SendMessageCallback& send_message_cb) override { 122 const SendMessageCallback& send_message_cb) override {
124 SendMessageRawPtr( 123 SendMessageRawPtr(render_process_id, render_frame_id, session,
125 render_process_id, 124 message_request.release(), send_message_cb);
126 render_frame_id,
127 message_request.release(),
128 send_message_cb);
129 } 125 }
130 MOCK_METHOD3( 126 MOCK_METHOD3(
131 ListenForSessionStateChange, 127 ListenForSessionStateChange,
132 void(int render_process_id, 128 void(int render_process_id,
133 int render_frame_id, 129 int render_frame_id,
134 const content::SessionStateChangedCallback& state_changed_cb)); 130 const content::SessionStateChangedCallback& state_changed_cb));
135 }; 131 };
136 132
137 class MockPresentationServiceClient : 133 class MockPresentationServiceClient :
138 public presentation::PresentationServiceClient { 134 public presentation::PresentationServiceClient {
139 public: 135 public:
140 MOCK_METHOD1(OnScreenAvailabilityUpdated, void(bool available)); 136 MOCK_METHOD1(OnScreenAvailabilityUpdated, void(bool available));
137
141 void OnSessionStateChanged( 138 void OnSessionStateChanged(
142 presentation::PresentationSessionInfoPtr session_info, 139 presentation::PresentationSessionInfoPtr session_info,
143 presentation::PresentationSessionState new_state) override { 140 presentation::PresentationSessionState new_state) override {
144 OnSessionStateChanged(*session_info, new_state); 141 OnSessionStateChanged(*session_info, new_state);
145 } 142 }
146 MOCK_METHOD2(OnSessionStateChanged, 143 MOCK_METHOD2(OnSessionStateChanged,
147 void(const presentation::PresentationSessionInfo& session_info, 144 void(const presentation::PresentationSessionInfo& session_info,
148 presentation::PresentationSessionState new_state)); 145 presentation::PresentationSessionState new_state));
146
149 void OnScreenAvailabilityNotSupported() override { 147 void OnScreenAvailabilityNotSupported() override {
150 NOTIMPLEMENTED(); 148 NOTIMPLEMENTED();
151 } 149 }
150
151 void OnSessionMessagesReceived(
152 presentation::PresentationSessionInfoPtr session_info,
153 mojo::Array<presentation::SessionMessagePtr> messages) override {
154 messages_received_ = messages.Pass();
155 MessagesReceived();
156 }
157 MOCK_METHOD0(MessagesReceived, void());
158
159 mojo::Array<presentation::SessionMessagePtr> messages_received_;
152 }; 160 };
153 161
154 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { 162 class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
155 public: 163 public:
156 PresentationServiceImplTest() : default_session_started_count_(0) {} 164 PresentationServiceImplTest() : default_session_started_count_(0) {}
157 165
158 void SetUp() override { 166 void SetUp() override {
159 RenderViewHostImplTestHarness::SetUp(); 167 RenderViewHostImplTestHarness::SetUp();
160 168
161 auto request = mojo::GetProxy(&service_ptr_); 169 auto request = mojo::GetProxy(&service_ptr_);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 271
264 void ExpectDefaultSessionNull( 272 void ExpectDefaultSessionNull(
265 presentation::PresentationSessionInfoPtr actual_session) { 273 presentation::PresentationSessionInfoPtr actual_session) {
266 EXPECT_TRUE(actual_session.is_null()); 274 EXPECT_TRUE(actual_session.is_null());
267 ++default_session_started_count_; 275 ++default_session_started_count_;
268 if (!run_loop_quit_closure_.is_null()) 276 if (!run_loop_quit_closure_.is_null())
269 run_loop_quit_closure_.Run(); 277 run_loop_quit_closure_.Run();
270 } 278 }
271 279
272 void ExpectSessionMessages( 280 void ExpectSessionMessages(
273 mojo::Array<presentation::SessionMessagePtr> actual_msgs) { 281 const mojo::Array<presentation::SessionMessagePtr>& expected_msgs,
274 EXPECT_TRUE(actual_msgs.size() == expected_msgs_.size()); 282 const mojo::Array<presentation::SessionMessagePtr>& actual_msgs) {
283 EXPECT_EQ(expected_msgs.size(), actual_msgs.size());
275 for (size_t i = 0; i < actual_msgs.size(); ++i) { 284 for (size_t i = 0; i < actual_msgs.size(); ++i) {
276 EXPECT_TRUE(ArePresentationSessionMessagesEqual(expected_msgs_[i].get(), 285 EXPECT_TRUE(ArePresentationSessionMessagesEqual(expected_msgs[i].get(),
277 actual_msgs[i].get())); 286 actual_msgs[i].get()));
278 } 287 }
279 if (!run_loop_quit_closure_.is_null())
280 run_loop_quit_closure_.Run();
281 } 288 }
282 289
283 void ExpectSendMessageMojoCallback(bool success) { 290 void ExpectSendMessageMojoCallback(bool success) {
284 EXPECT_TRUE(success); 291 EXPECT_TRUE(success);
285 EXPECT_FALSE(service_impl_->send_message_callback_); 292 EXPECT_FALSE(service_impl_->send_message_callback_);
286 if (!run_loop_quit_closure_.is_null()) 293 if (!run_loop_quit_closure_.is_null())
287 run_loop_quit_closure_.Run(); 294 run_loop_quit_closure_.Run();
288 } 295 }
289 296
290 void RunListenForSessionMessages(std::string& text_msg, 297 void RunListenForSessionMessages(const std::string& text_msg,
291 std::vector<uint8_t>& binary_data) { 298 const std::vector<uint8_t>& binary_data) {
299 mojo::Array<presentation::SessionMessagePtr> expected_msgs(2);
300 expected_msgs[0] = presentation::SessionMessage::New();
301 expected_msgs[0]->type =
302 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT;
303 expected_msgs[0]->message = text_msg;
304 expected_msgs[1] = presentation::SessionMessage::New();
305 expected_msgs[1]->type = presentation::PresentationMessageType::
306 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER;
307 expected_msgs[1]->data = mojo::Array<uint8_t>::From(binary_data);
292 308
309 presentation::PresentationSessionInfoPtr session(
310 presentation::PresentationSessionInfo::New());
311 session->url = kPresentationUrl;
312 session->id = kPresentationId;
293 313
294 expected_msgs_ = mojo::Array<presentation::SessionMessagePtr>::New(2); 314 PresentationSessionMessageCallback message_cb;
295 expected_msgs_[0] = presentation::SessionMessage::New(); 315 {
296 expected_msgs_[0]->presentation_url = kPresentationUrl; 316 base::RunLoop run_loop;
297 expected_msgs_[0]->presentation_id = kPresentationId; 317 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _))
298 expected_msgs_[0]->type = 318 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
299 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; 319 SaveArg<3>(&message_cb)));
300 expected_msgs_[0]->message = text_msg; 320 service_ptr_->ListenForSessionMessages(session.Clone());
301 expected_msgs_[1] = presentation::SessionMessage::New(); 321 run_loop.Run();
302 expected_msgs_[1]->presentation_url = kPresentationUrl; 322 }
303 expected_msgs_[1]->presentation_id = kPresentationId;
304 expected_msgs_[1]->type = presentation::PresentationMessageType::
305 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER;
306 expected_msgs_[1]->data = mojo::Array<uint8_t>::From(binary_data);
307 323
308 service_ptr_->ListenForSessionMessages( 324 ScopedVector<PresentationSessionMessage> messages;
309 base::Bind(&PresentationServiceImplTest::ExpectSessionMessages, 325 scoped_ptr<content::PresentationSessionMessage> message;
310 base::Unretained(this))); 326 message.reset(
327 new content::PresentationSessionMessage(PresentationMessageType::TEXT));
328 message->message = text_msg;
329 messages.push_back(message.Pass());
330 message.reset(new content::PresentationSessionMessage(
331 PresentationMessageType::ARRAY_BUFFER));
332 message->data.reset(new std::vector<uint8_t>(binary_data));
333 messages.push_back(message.Pass());
311 334
312 base::RunLoop run_loop; 335 std::vector<presentation::SessionMessagePtr> actual_msgs;
313 base::Callback<void(scoped_ptr<ScopedVector<PresentationSessionMessage>>)> 336 {
314 message_cb; 337 base::RunLoop run_loop;
315 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _)) 338 EXPECT_CALL(mock_client_, MessagesReceived())
316 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 339 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
317 SaveArg<2>(&message_cb))); 340 message_cb.Run(messages.Pass());
318 run_loop.Run(); 341 run_loop.Run();
319 342 }
320 scoped_ptr<ScopedVector<PresentationSessionMessage>> messages( 343 ExpectSessionMessages(expected_msgs, mock_client_.messages_received_);
321 new ScopedVector<PresentationSessionMessage>());
322 messages->push_back(
323 content::PresentationSessionMessage::CreateStringMessage(
324 kPresentationUrl, kPresentationId,
325 scoped_ptr<std::string>(new std::string(text_msg))));
326 messages->push_back(
327 content::PresentationSessionMessage::CreateArrayBufferMessage(
328 kPresentationUrl, kPresentationId,
329 scoped_ptr<std::vector<uint8_t>>(
330 new std::vector<uint8_t>(binary_data))));
331 message_cb.Run(messages.Pass());
332 SaveQuitClosureAndRunLoop();
333 } 344 }
334 345
335 MockPresentationServiceDelegate mock_delegate_; 346 MockPresentationServiceDelegate mock_delegate_;
336 347
337 scoped_ptr<PresentationServiceImpl> service_impl_; 348 scoped_ptr<PresentationServiceImpl> service_impl_;
338 mojo::InterfacePtr<presentation::PresentationService> service_ptr_; 349 mojo::InterfacePtr<presentation::PresentationService> service_ptr_;
339 350
340 MockPresentationServiceClient mock_client_; 351 MockPresentationServiceClient mock_client_;
341 scoped_ptr<mojo::Binding<presentation::PresentationServiceClient>> 352 scoped_ptr<mojo::Binding<presentation::PresentationServiceClient>>
342 client_binding_; 353 client_binding_;
343 354
344 base::Closure run_loop_quit_closure_; 355 base::Closure run_loop_quit_closure_;
345 int default_session_started_count_; 356 int default_session_started_count_;
346 mojo::Array<presentation::SessionMessagePtr> expected_msgs_;
347 }; 357 };
348 358
349 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { 359 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) {
350 ListenForScreenAvailabilityAndWait(true); 360 ListenForScreenAvailabilityAndWait(true);
351 361
352 SimulateScreenAvailabilityChangeAndWait(true); 362 SimulateScreenAvailabilityChangeAndWait(true);
353 SimulateScreenAvailabilityChangeAndWait(false); 363 SimulateScreenAvailabilityChangeAndWait(false);
354 SimulateScreenAvailabilityChangeAndWait(true); 364 SimulateScreenAvailabilityChangeAndWait(true);
355 } 365 }
356 366
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 555 }
546 556
547 TEST_F(PresentationServiceImplTest, ListenForSessionMessages) { 557 TEST_F(PresentationServiceImplTest, ListenForSessionMessages) {
548 std::string text_msg("123"); 558 std::string text_msg("123");
549 std::vector<uint8_t> binary_data(3, '\1'); 559 std::vector<uint8_t> binary_data(3, '\1');
550 RunListenForSessionMessages(text_msg, binary_data); 560 RunListenForSessionMessages(text_msg, binary_data);
551 } 561 }
552 562
553 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) { 563 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) {
554 std::string text_msg(""); 564 std::string text_msg("");
555 std::vector<uint8_t> binary_data{}; 565 std::vector<uint8_t> binary_data;
556 RunListenForSessionMessages(text_msg, binary_data); 566 RunListenForSessionMessages(text_msg, binary_data);
557 } 567 }
558 568
559 TEST_F(PresentationServiceImplTest, ReceiveSessionMessagesAfterReset) {
560 std::string text_msg("123");
561 expected_msgs_ = mojo::Array<presentation::SessionMessagePtr>();
562 service_ptr_->ListenForSessionMessages(
563 base::Bind(&PresentationServiceImplTest::ExpectSessionMessages,
564 base::Unretained(this)));
565
566 base::RunLoop run_loop;
567 base::Callback<void(scoped_ptr<ScopedVector<PresentationSessionMessage>>)>
568 message_cb;
569 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _))
570 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
571 SaveArg<2>(&message_cb)));
572 run_loop.Run();
573
574 scoped_ptr<ScopedVector<PresentationSessionMessage>> messages(
575 new ScopedVector<PresentationSessionMessage>());
576 messages->push_back(content::PresentationSessionMessage::CreateStringMessage(
577 kPresentationUrl, kPresentationId,
578 scoped_ptr<std::string>(new std::string(text_msg))));
579 ExpectReset();
580 service_impl_->Reset();
581 message_cb.Run(messages.Pass());
582 SaveQuitClosureAndRunLoop();
583 }
584
585 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { 569 TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
586 std::string presentation_url1("http://fooUrl"); 570 std::string presentation_url1("http://fooUrl");
587 std::string presentation_url2("http://barUrl"); 571 std::string presentation_url2("http://barUrl");
588 service_ptr_->StartSession(presentation_url1, 572 service_ptr_->StartSession(presentation_url1,
589 base::Bind(&DoNothing)); 573 base::Bind(&DoNothing));
590 // This request should fail immediately, since there is already a StartSession 574 // This request should fail immediately, since there is already a StartSession
591 // in progress. 575 // in progress.
592 service_ptr_->StartSession( 576 service_ptr_->StartSession(
593 presentation_url2, 577 presentation_url2,
594 base::Bind( 578 base::Bind(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 ExpectReset(); 630 ExpectReset();
647 service_impl_->Reset(); 631 service_impl_->Reset();
648 ExpectCleanState(); 632 ExpectCleanState();
649 SaveQuitClosureAndRunLoop(); 633 SaveQuitClosureAndRunLoop();
650 EXPECT_EQ(1, default_session_started_count_); 634 EXPECT_EQ(1, default_session_started_count_);
651 } 635 }
652 636
653 TEST_F(PresentationServiceImplTest, SendStringMessage) { 637 TEST_F(PresentationServiceImplTest, SendStringMessage) {
654 std::string message("Test presentation session message"); 638 std::string message("Test presentation session message");
655 639
640 presentation::PresentationSessionInfoPtr session(
641 presentation::PresentationSessionInfo::New());
642 session->url = kPresentationUrl;
643 session->id = kPresentationId;
656 presentation::SessionMessagePtr message_request( 644 presentation::SessionMessagePtr message_request(
657 presentation::SessionMessage::New()); 645 presentation::SessionMessage::New());
658 message_request->presentation_url = kPresentationUrl;
659 message_request->presentation_id = kPresentationId;
660 message_request->type = presentation::PresentationMessageType:: 646 message_request->type = presentation::PresentationMessageType::
661 PRESENTATION_MESSAGE_TYPE_TEXT; 647 PRESENTATION_MESSAGE_TYPE_TEXT;
662 message_request->message = message; 648 message_request->message = message;
663 service_ptr_->SendSessionMessage( 649 service_ptr_->SendSessionMessage(
664 message_request.Pass(), 650 session.Pass(), message_request.Pass(),
665 base::Bind( 651 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback,
666 &PresentationServiceImplTest::ExpectSendMessageMojoCallback, 652 base::Unretained(this)));
667 base::Unretained(this)));
668 653
669 base::RunLoop run_loop; 654 base::RunLoop run_loop;
670 base::Callback<void(bool)> send_message_cb; 655 base::Callback<void(bool)> send_message_cb;
671 PresentationSessionMessage* test_message = nullptr; 656 PresentationSessionMessage* test_message = nullptr;
672 EXPECT_CALL(mock_delegate_, SendMessageRawPtr( 657 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
673 _, _, _, _)) 658 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
674 .WillOnce(DoAll( 659 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
675 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
676 SaveArg<2>(&test_message),
677 SaveArg<3>(&send_message_cb)));
678 run_loop.Run(); 660 run_loop.Run();
679 661
662 // Make sure |test_message| gets deleted.
663 scoped_ptr<PresentationSessionMessage> scoped_test_message(test_message);
680 EXPECT_TRUE(test_message); 664 EXPECT_TRUE(test_message);
681 EXPECT_EQ(kPresentationUrl, test_message->presentation_url);
682 EXPECT_EQ(kPresentationId, test_message->presentation_id);
683 EXPECT_FALSE(test_message->is_binary()); 665 EXPECT_FALSE(test_message->is_binary());
684 EXPECT_TRUE(test_message->message.get()->size() <= 666 EXPECT_LE(test_message->message.size(), kMaxPresentationSessionMessageSize);
685 kMaxPresentationSessionMessageSize); 667 EXPECT_EQ(message, test_message->message);
686 EXPECT_EQ(message, *(test_message->message.get())); 668 ASSERT_FALSE(test_message->data);
687 EXPECT_FALSE(test_message->data);
688 delete test_message;
689 send_message_cb.Run(true); 669 send_message_cb.Run(true);
690 SaveQuitClosureAndRunLoop(); 670 SaveQuitClosureAndRunLoop();
691 } 671 }
692 672
693 TEST_F(PresentationServiceImplTest, SendArrayBuffer) { 673 TEST_F(PresentationServiceImplTest, SendArrayBuffer) {
694 // Test Array buffer data. 674 // Test Array buffer data.
695 const uint8 buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48}; 675 const uint8 buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48};
696 std::vector<uint8> data; 676 std::vector<uint8> data;
697 data.assign(buffer, buffer + sizeof(buffer)); 677 data.assign(buffer, buffer + sizeof(buffer));
698 678
679 presentation::PresentationSessionInfoPtr session(
680 presentation::PresentationSessionInfo::New());
681 session->url = kPresentationUrl;
682 session->id = kPresentationId;
699 presentation::SessionMessagePtr message_request( 683 presentation::SessionMessagePtr message_request(
700 presentation::SessionMessage::New()); 684 presentation::SessionMessage::New());
701 message_request->presentation_url = kPresentationUrl;
702 message_request->presentation_id = kPresentationId;
703 message_request->type = presentation::PresentationMessageType:: 685 message_request->type = presentation::PresentationMessageType::
704 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; 686 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER;
705 message_request->data = mojo::Array<uint8>::From(data); 687 message_request->data = mojo::Array<uint8>::From(data);
706 service_ptr_->SendSessionMessage( 688 service_ptr_->SendSessionMessage(
707 message_request.Pass(), 689 session.Pass(), message_request.Pass(),
708 base::Bind( 690 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback,
709 &PresentationServiceImplTest::ExpectSendMessageMojoCallback, 691 base::Unretained(this)));
710 base::Unretained(this)));
711 692
712 base::RunLoop run_loop; 693 base::RunLoop run_loop;
713 base::Callback<void(bool)> send_message_cb; 694 base::Callback<void(bool)> send_message_cb;
714 PresentationSessionMessage* test_message = nullptr; 695 PresentationSessionMessage* test_message = nullptr;
715 EXPECT_CALL(mock_delegate_, SendMessageRawPtr( 696 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
716 _, _, _, _)) 697 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
717 .WillOnce(DoAll( 698 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
718 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
719 SaveArg<2>(&test_message),
720 SaveArg<3>(&send_message_cb)));
721 run_loop.Run(); 699 run_loop.Run();
722 700
701 // Make sure |test_message| gets deleted.
702 scoped_ptr<PresentationSessionMessage> scoped_test_message(test_message);
723 EXPECT_TRUE(test_message); 703 EXPECT_TRUE(test_message);
724 EXPECT_EQ(kPresentationUrl, test_message->presentation_url);
725 EXPECT_EQ(kPresentationId, test_message->presentation_id);
726 EXPECT_TRUE(test_message->is_binary()); 704 EXPECT_TRUE(test_message->is_binary());
727 EXPECT_EQ(PresentationMessageType::ARRAY_BUFFER, test_message->type); 705 EXPECT_EQ(PresentationMessageType::ARRAY_BUFFER, test_message->type);
728 EXPECT_FALSE(test_message->message); 706 EXPECT_TRUE(test_message->message.empty());
729 EXPECT_EQ(data.size(), test_message->data.get()->size()); 707 ASSERT_TRUE(test_message->data);
730 EXPECT_TRUE(test_message->data.get()->size() <= 708 EXPECT_EQ(data.size(), test_message->data->size());
731 kMaxPresentationSessionMessageSize); 709 EXPECT_LE(test_message->data->size(), kMaxPresentationSessionMessageSize);
732 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data.get())[0], sizeof(buffer))); 710 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer)));
733 delete test_message;
734 send_message_cb.Run(true); 711 send_message_cb.Run(true);
735 SaveQuitClosureAndRunLoop(); 712 SaveQuitClosureAndRunLoop();
736 } 713 }
737 714
738 TEST_F(PresentationServiceImplTest, SendArrayBufferWithExceedingLimit) { 715 TEST_F(PresentationServiceImplTest, SendArrayBufferWithExceedingLimit) {
739 // Create buffer with size exceeding the limit. 716 // Create buffer with size exceeding the limit.
740 // Use same size as in content::kMaxPresentationSessionMessageSize. 717 // Use same size as in content::kMaxPresentationSessionMessageSize.
741 const size_t kMaxBufferSizeInBytes = 64 * 1024; // 64 KB. 718 const size_t kMaxBufferSizeInBytes = 64 * 1024; // 64 KB.
742 uint8 buffer[kMaxBufferSizeInBytes+1]; 719 uint8 buffer[kMaxBufferSizeInBytes+1];
743 memset(buffer, 0, kMaxBufferSizeInBytes+1); 720 memset(buffer, 0, kMaxBufferSizeInBytes+1);
744 std::vector<uint8> data; 721 std::vector<uint8> data;
745 data.assign(buffer, buffer + sizeof(buffer)); 722 data.assign(buffer, buffer + sizeof(buffer));
746 723
724 presentation::PresentationSessionInfoPtr session(
725 presentation::PresentationSessionInfo::New());
726 session->url = kPresentationUrl;
727 session->id = kPresentationId;
747 presentation::SessionMessagePtr message_request( 728 presentation::SessionMessagePtr message_request(
748 presentation::SessionMessage::New()); 729 presentation::SessionMessage::New());
749 message_request->presentation_url = kPresentationUrl;
750 message_request->presentation_id = kPresentationId;
751 message_request->type = presentation::PresentationMessageType:: 730 message_request->type = presentation::PresentationMessageType::
752 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; 731 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER;
753 message_request->data = mojo::Array<uint8>::From(data); 732 message_request->data = mojo::Array<uint8>::From(data);
754 service_ptr_->SendSessionMessage( 733 service_ptr_->SendSessionMessage(
755 message_request.Pass(), 734 session.Pass(), message_request.Pass(),
756 base::Bind( 735 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback,
757 &PresentationServiceImplTest::ExpectSendMessageMojoCallback, 736 base::Unretained(this)));
758 base::Unretained(this)));
759 737
760 base::RunLoop run_loop; 738 base::RunLoop run_loop;
761 base::Callback<void(bool)> send_message_cb; 739 base::Callback<void(bool)> send_message_cb;
762 PresentationSessionMessage* test_message = nullptr; 740 PresentationSessionMessage* test_message = nullptr;
763 EXPECT_CALL(mock_delegate_, SendMessageRawPtr( 741 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
764 _, _, _, _)) 742 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
765 .WillOnce(DoAll( 743 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
766 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
767 SaveArg<2>(&test_message),
768 SaveArg<3>(&send_message_cb)));
769 run_loop.Run(); 744 run_loop.Run();
770 745
771 EXPECT_FALSE(test_message); 746 EXPECT_FALSE(test_message);
772 send_message_cb.Run(true); 747 send_message_cb.Run(true);
773 SaveQuitClosureAndRunLoop(); 748 SaveQuitClosureAndRunLoop();
774 } 749 }
775 750
776 TEST_F(PresentationServiceImplTest, SendBlobData) { 751 TEST_F(PresentationServiceImplTest, SendBlobData) {
777 const uint8 buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; 752 const uint8 buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
778 std::vector<uint8> data; 753 std::vector<uint8> data;
779 data.assign(buffer, buffer + sizeof(buffer)); 754 data.assign(buffer, buffer + sizeof(buffer));
780 755
756 presentation::PresentationSessionInfoPtr session(
757 presentation::PresentationSessionInfo::New());
758 session->url = kPresentationUrl;
759 session->id = kPresentationId;
781 presentation::SessionMessagePtr message_request( 760 presentation::SessionMessagePtr message_request(
782 presentation::SessionMessage::New()); 761 presentation::SessionMessage::New());
783 message_request->presentation_url = kPresentationUrl;
784 message_request->presentation_id = kPresentationId;
785 message_request->type = 762 message_request->type =
786 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_BLOB; 763 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_BLOB;
787 message_request->data = mojo::Array<uint8>::From(data); 764 message_request->data = mojo::Array<uint8>::From(data);
788 service_ptr_->SendSessionMessage( 765 service_ptr_->SendSessionMessage(
789 message_request.Pass(), 766 session.Pass(), message_request.Pass(),
790 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, 767 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback,
791 base::Unretained(this))); 768 base::Unretained(this)));
792 769
793 base::RunLoop run_loop; 770 base::RunLoop run_loop;
794 base::Callback<void(bool)> send_message_cb; 771 base::Callback<void(bool)> send_message_cb;
795 PresentationSessionMessage* test_message = nullptr; 772 PresentationSessionMessage* test_message = nullptr;
796 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _)) 773 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
797 .WillOnce(DoAll( 774 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
798 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 775 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
799 SaveArg<2>(&test_message),
800 SaveArg<3>(&send_message_cb)));
801 run_loop.Run(); 776 run_loop.Run();
802 777
778 // Make sure |test_message| gets deleted.
779 scoped_ptr<PresentationSessionMessage> scoped_test_message(test_message);
803 EXPECT_TRUE(test_message); 780 EXPECT_TRUE(test_message);
804 EXPECT_EQ(kPresentationUrl, test_message->presentation_url);
805 EXPECT_EQ(kPresentationId, test_message->presentation_id);
806 EXPECT_TRUE(test_message->is_binary()); 781 EXPECT_TRUE(test_message->is_binary());
807 EXPECT_EQ(PresentationMessageType::BLOB, test_message->type); 782 EXPECT_EQ(PresentationMessageType::BLOB, test_message->type);
808 EXPECT_FALSE(test_message->message); 783 EXPECT_TRUE(test_message->message.empty());
809 EXPECT_EQ(data.size(), test_message->data.get()->size()); 784 ASSERT_TRUE(test_message->data);
810 EXPECT_TRUE(test_message->data.get()->size() <= 785 EXPECT_EQ(data.size(), test_message->data->size());
811 kMaxPresentationSessionMessageSize); 786 EXPECT_LE(test_message->data->size(), kMaxPresentationSessionMessageSize);
812 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data.get())[0], sizeof(buffer))); 787 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer)));
813 delete test_message;
814 send_message_cb.Run(true); 788 send_message_cb.Run(true);
815 SaveQuitClosureAndRunLoop(); 789 SaveQuitClosureAndRunLoop();
816 } 790 }
817 791
818 TEST_F(PresentationServiceImplTest, MaxPendingJoinSessionRequests) { 792 TEST_F(PresentationServiceImplTest, MaxPendingJoinSessionRequests) {
819 const char* presentation_url = "http://fooUrl%d"; 793 const char* presentation_url = "http://fooUrl%d";
820 const char* presentation_id = "presentationId%d"; 794 const char* presentation_id = "presentationId%d";
821 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests; 795 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests;
822 int i = 0; 796 int i = 0;
823 EXPECT_CALL(mock_delegate_, JoinSession(_, _, _, _, _, _)) 797 EXPECT_CALL(mock_delegate_, JoinSession(_, _, _, _, _, _))
(...skipping 29 matching lines...) Expand all
853 EXPECT_CALL(mock_client_, 827 EXPECT_CALL(mock_client_,
854 OnSessionStateChanged( 828 OnSessionStateChanged(
855 Equals(session_info), 829 Equals(session_info),
856 presentation::PRESENTATION_SESSION_STATE_CONNECTED)); 830 presentation::PRESENTATION_SESSION_STATE_CONNECTED));
857 service_impl_->OnSessionStateChanged( 831 service_impl_->OnSessionStateChanged(
858 content::PresentationSessionInfo(kPresentationUrl, kPresentationId), 832 content::PresentationSessionInfo(kPresentationUrl, kPresentationId),
859 content::PRESENTATION_SESSION_STATE_CONNECTED); 833 content::PRESENTATION_SESSION_STATE_CONNECTED);
860 } 834 }
861 835
862 } // namespace content 836 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/presentation/presentation_service_impl.cc ('k') | content/browser/presentation/presentation_type_converters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698