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 "content/browser/presentation/presentation_service_impl.h" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 #include <stdint.h> | 8 #include <stdint.h> |
7 | |
8 #include <string> | 9 #include <string> |
| 10 #include <utility> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/location.h" | 13 #include "base/location.h" |
12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
13 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
14 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
15 #include "base/test/test_timeouts.h" | 17 #include "base/test/test_timeouts.h" |
16 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
17 #include "content/browser/presentation/presentation_service_impl.h" | |
18 #include "content/public/browser/presentation_service_delegate.h" | 19 #include "content/public/browser/presentation_service_delegate.h" |
19 #include "content/public/browser/presentation_session.h" | 20 #include "content/public/browser/presentation_session.h" |
20 #include "content/public/common/presentation_constants.h" | 21 #include "content/public/common/presentation_constants.h" |
21 #include "content/test/test_render_frame_host.h" | 22 #include "content/test/test_render_frame_host.h" |
22 #include "content/test/test_render_view_host.h" | 23 #include "content/test/test_render_view_host.h" |
23 #include "content/test/test_web_contents.h" | 24 #include "content/test/test_web_contents.h" |
24 #include "mojo/public/cpp/bindings/interface_ptr.h" | 25 #include "mojo/public/cpp/bindings/interface_ptr.h" |
25 #include "mojo/public/cpp/bindings/string.h" | 26 #include "mojo/public/cpp/bindings/string.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
27 | 28 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 161 } |
161 MOCK_METHOD2(OnConnectionStateChanged, | 162 MOCK_METHOD2(OnConnectionStateChanged, |
162 void(const presentation::PresentationSessionInfo& connection, | 163 void(const presentation::PresentationSessionInfo& connection, |
163 presentation::PresentationConnectionState new_state)); | 164 presentation::PresentationConnectionState new_state)); |
164 | 165 |
165 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const mojo::String& url)); | 166 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const mojo::String& url)); |
166 | 167 |
167 void OnSessionMessagesReceived( | 168 void OnSessionMessagesReceived( |
168 presentation::PresentationSessionInfoPtr session_info, | 169 presentation::PresentationSessionInfoPtr session_info, |
169 mojo::Array<presentation::SessionMessagePtr> messages) override { | 170 mojo::Array<presentation::SessionMessagePtr> messages) override { |
170 messages_received_ = messages.Pass(); | 171 messages_received_ = std::move(messages); |
171 MessagesReceived(); | 172 MessagesReceived(); |
172 } | 173 } |
173 MOCK_METHOD0(MessagesReceived, void()); | 174 MOCK_METHOD0(MessagesReceived, void()); |
174 | 175 |
175 void OnDefaultSessionStarted( | 176 void OnDefaultSessionStarted( |
176 presentation::PresentationSessionInfoPtr session_info) override { | 177 presentation::PresentationSessionInfoPtr session_info) override { |
177 OnDefaultSessionStarted(*session_info); | 178 OnDefaultSessionStarted(*session_info); |
178 } | 179 } |
179 MOCK_METHOD1(OnDefaultSessionStarted, | 180 MOCK_METHOD1(OnDefaultSessionStarted, |
180 void(const presentation::PresentationSessionInfo& session_info)); | 181 void(const presentation::PresentationSessionInfo& session_info)); |
181 | 182 |
182 mojo::Array<presentation::SessionMessagePtr> messages_received_; | 183 mojo::Array<presentation::SessionMessagePtr> messages_received_; |
183 }; | 184 }; |
184 | 185 |
185 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { | 186 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
186 public: | 187 public: |
187 PresentationServiceImplTest() : default_session_started_count_(0) {} | 188 PresentationServiceImplTest() : default_session_started_count_(0) {} |
188 | 189 |
189 void SetUp() override { | 190 void SetUp() override { |
190 RenderViewHostImplTestHarness::SetUp(); | 191 RenderViewHostImplTestHarness::SetUp(); |
191 | 192 |
192 auto request = mojo::GetProxy(&service_ptr_); | 193 auto request = mojo::GetProxy(&service_ptr_); |
193 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1); | 194 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1); |
194 service_impl_.reset(new PresentationServiceImpl( | 195 service_impl_.reset(new PresentationServiceImpl( |
195 contents()->GetMainFrame(), contents(), &mock_delegate_)); | 196 contents()->GetMainFrame(), contents(), &mock_delegate_)); |
196 service_impl_->Bind(request.Pass()); | 197 service_impl_->Bind(std::move(request)); |
197 | 198 |
198 presentation::PresentationServiceClientPtr client_ptr; | 199 presentation::PresentationServiceClientPtr client_ptr; |
199 client_binding_.reset( | 200 client_binding_.reset( |
200 new mojo::Binding<presentation::PresentationServiceClient>( | 201 new mojo::Binding<presentation::PresentationServiceClient>( |
201 &mock_client_, mojo::GetProxy(&client_ptr))); | 202 &mock_client_, mojo::GetProxy(&client_ptr))); |
202 service_impl_->SetClient(client_ptr.Pass()); | 203 service_impl_->SetClient(std::move(client_ptr)); |
203 } | 204 } |
204 | 205 |
205 void TearDown() override { | 206 void TearDown() override { |
206 service_ptr_.reset(); | 207 service_ptr_.reset(); |
207 if (service_impl_.get()) { | 208 if (service_impl_.get()) { |
208 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); | 209 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); |
209 service_impl_.reset(); | 210 service_impl_.reset(); |
210 } | 211 } |
211 RenderViewHostImplTestHarness::TearDown(); | 212 RenderViewHostImplTestHarness::TearDown(); |
212 } | 213 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 SaveArg<3>(&message_cb))); | 329 SaveArg<3>(&message_cb))); |
329 service_ptr_->ListenForSessionMessages(session.Clone()); | 330 service_ptr_->ListenForSessionMessages(session.Clone()); |
330 run_loop.Run(); | 331 run_loop.Run(); |
331 } | 332 } |
332 | 333 |
333 ScopedVector<PresentationSessionMessage> messages; | 334 ScopedVector<PresentationSessionMessage> messages; |
334 scoped_ptr<content::PresentationSessionMessage> message; | 335 scoped_ptr<content::PresentationSessionMessage> message; |
335 message.reset( | 336 message.reset( |
336 new content::PresentationSessionMessage(PresentationMessageType::TEXT)); | 337 new content::PresentationSessionMessage(PresentationMessageType::TEXT)); |
337 message->message = text_msg; | 338 message->message = text_msg; |
338 messages.push_back(message.Pass()); | 339 messages.push_back(std::move(message)); |
339 message.reset(new content::PresentationSessionMessage( | 340 message.reset(new content::PresentationSessionMessage( |
340 PresentationMessageType::ARRAY_BUFFER)); | 341 PresentationMessageType::ARRAY_BUFFER)); |
341 message->data.reset(new std::vector<uint8_t>(binary_data)); | 342 message->data.reset(new std::vector<uint8_t>(binary_data)); |
342 messages.push_back(message.Pass()); | 343 messages.push_back(std::move(message)); |
343 | 344 |
344 std::vector<presentation::SessionMessagePtr> actual_msgs; | 345 std::vector<presentation::SessionMessagePtr> actual_msgs; |
345 { | 346 { |
346 base::RunLoop run_loop; | 347 base::RunLoop run_loop; |
347 EXPECT_CALL(mock_client_, MessagesReceived()) | 348 EXPECT_CALL(mock_client_, MessagesReceived()) |
348 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 349 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
349 message_cb.Run(messages.Pass(), pass_ownership); | 350 message_cb.Run(std::move(messages), pass_ownership); |
350 run_loop.Run(); | 351 run_loop.Run(); |
351 } | 352 } |
352 ExpectSessionMessages(expected_msgs, mock_client_.messages_received_); | 353 ExpectSessionMessages(expected_msgs, mock_client_.messages_received_); |
353 } | 354 } |
354 | 355 |
355 MockPresentationServiceDelegate mock_delegate_; | 356 MockPresentationServiceDelegate mock_delegate_; |
356 | 357 |
357 scoped_ptr<PresentationServiceImpl> service_impl_; | 358 scoped_ptr<PresentationServiceImpl> service_impl_; |
358 mojo::InterfacePtr<presentation::PresentationService> service_ptr_; | 359 mojo::InterfacePtr<presentation::PresentationService> service_ptr_; |
359 | 360 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 presentation::PresentationSessionInfoPtr session( | 633 presentation::PresentationSessionInfoPtr session( |
633 presentation::PresentationSessionInfo::New()); | 634 presentation::PresentationSessionInfo::New()); |
634 session->url = kPresentationUrl; | 635 session->url = kPresentationUrl; |
635 session->id = kPresentationId; | 636 session->id = kPresentationId; |
636 presentation::SessionMessagePtr message_request( | 637 presentation::SessionMessagePtr message_request( |
637 presentation::SessionMessage::New()); | 638 presentation::SessionMessage::New()); |
638 message_request->type = presentation::PresentationMessageType:: | 639 message_request->type = presentation::PresentationMessageType:: |
639 PRESENTATION_MESSAGE_TYPE_TEXT; | 640 PRESENTATION_MESSAGE_TYPE_TEXT; |
640 message_request->message = message; | 641 message_request->message = message; |
641 service_ptr_->SendSessionMessage( | 642 service_ptr_->SendSessionMessage( |
642 session.Pass(), message_request.Pass(), | 643 std::move(session), std::move(message_request), |
643 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, | 644 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, |
644 base::Unretained(this))); | 645 base::Unretained(this))); |
645 | 646 |
646 base::RunLoop run_loop; | 647 base::RunLoop run_loop; |
647 base::Callback<void(bool)> send_message_cb; | 648 base::Callback<void(bool)> send_message_cb; |
648 PresentationSessionMessage* test_message = nullptr; | 649 PresentationSessionMessage* test_message = nullptr; |
649 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) | 650 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) |
650 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 651 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
651 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); | 652 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); |
652 run_loop.Run(); | 653 run_loop.Run(); |
(...skipping 18 matching lines...) Expand all Loading... |
671 presentation::PresentationSessionInfoPtr session( | 672 presentation::PresentationSessionInfoPtr session( |
672 presentation::PresentationSessionInfo::New()); | 673 presentation::PresentationSessionInfo::New()); |
673 session->url = kPresentationUrl; | 674 session->url = kPresentationUrl; |
674 session->id = kPresentationId; | 675 session->id = kPresentationId; |
675 presentation::SessionMessagePtr message_request( | 676 presentation::SessionMessagePtr message_request( |
676 presentation::SessionMessage::New()); | 677 presentation::SessionMessage::New()); |
677 message_request->type = presentation::PresentationMessageType:: | 678 message_request->type = presentation::PresentationMessageType:: |
678 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; | 679 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; |
679 message_request->data = mojo::Array<uint8_t>::From(data); | 680 message_request->data = mojo::Array<uint8_t>::From(data); |
680 service_ptr_->SendSessionMessage( | 681 service_ptr_->SendSessionMessage( |
681 session.Pass(), message_request.Pass(), | 682 std::move(session), std::move(message_request), |
682 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, | 683 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, |
683 base::Unretained(this))); | 684 base::Unretained(this))); |
684 | 685 |
685 base::RunLoop run_loop; | 686 base::RunLoop run_loop; |
686 base::Callback<void(bool)> send_message_cb; | 687 base::Callback<void(bool)> send_message_cb; |
687 PresentationSessionMessage* test_message = nullptr; | 688 PresentationSessionMessage* test_message = nullptr; |
688 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) | 689 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) |
689 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 690 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
690 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); | 691 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); |
691 run_loop.Run(); | 692 run_loop.Run(); |
(...skipping 24 matching lines...) Expand all Loading... |
716 presentation::PresentationSessionInfoPtr session( | 717 presentation::PresentationSessionInfoPtr session( |
717 presentation::PresentationSessionInfo::New()); | 718 presentation::PresentationSessionInfo::New()); |
718 session->url = kPresentationUrl; | 719 session->url = kPresentationUrl; |
719 session->id = kPresentationId; | 720 session->id = kPresentationId; |
720 presentation::SessionMessagePtr message_request( | 721 presentation::SessionMessagePtr message_request( |
721 presentation::SessionMessage::New()); | 722 presentation::SessionMessage::New()); |
722 message_request->type = presentation::PresentationMessageType:: | 723 message_request->type = presentation::PresentationMessageType:: |
723 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; | 724 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; |
724 message_request->data = mojo::Array<uint8_t>::From(data); | 725 message_request->data = mojo::Array<uint8_t>::From(data); |
725 service_ptr_->SendSessionMessage( | 726 service_ptr_->SendSessionMessage( |
726 session.Pass(), message_request.Pass(), | 727 std::move(session), std::move(message_request), |
727 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, | 728 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, |
728 base::Unretained(this))); | 729 base::Unretained(this))); |
729 | 730 |
730 base::RunLoop run_loop; | 731 base::RunLoop run_loop; |
731 base::Callback<void(bool)> send_message_cb; | 732 base::Callback<void(bool)> send_message_cb; |
732 PresentationSessionMessage* test_message = nullptr; | 733 PresentationSessionMessage* test_message = nullptr; |
733 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) | 734 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) |
734 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 735 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
735 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); | 736 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); |
736 run_loop.Run(); | 737 run_loop.Run(); |
(...skipping 11 matching lines...) Expand all Loading... |
748 presentation::PresentationSessionInfoPtr session( | 749 presentation::PresentationSessionInfoPtr session( |
749 presentation::PresentationSessionInfo::New()); | 750 presentation::PresentationSessionInfo::New()); |
750 session->url = kPresentationUrl; | 751 session->url = kPresentationUrl; |
751 session->id = kPresentationId; | 752 session->id = kPresentationId; |
752 presentation::SessionMessagePtr message_request( | 753 presentation::SessionMessagePtr message_request( |
753 presentation::SessionMessage::New()); | 754 presentation::SessionMessage::New()); |
754 message_request->type = | 755 message_request->type = |
755 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_BLOB; | 756 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_BLOB; |
756 message_request->data = mojo::Array<uint8_t>::From(data); | 757 message_request->data = mojo::Array<uint8_t>::From(data); |
757 service_ptr_->SendSessionMessage( | 758 service_ptr_->SendSessionMessage( |
758 session.Pass(), message_request.Pass(), | 759 std::move(session), std::move(message_request), |
759 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, | 760 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, |
760 base::Unretained(this))); | 761 base::Unretained(this))); |
761 | 762 |
762 base::RunLoop run_loop; | 763 base::RunLoop run_loop; |
763 base::Callback<void(bool)> send_message_cb; | 764 base::Callback<void(bool)> send_message_cb; |
764 PresentationSessionMessage* test_message = nullptr; | 765 PresentationSessionMessage* test_message = nullptr; |
765 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) | 766 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) |
766 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 767 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
767 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); | 768 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); |
768 run_loop.Run(); | 769 run_loop.Run(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 | 808 |
808 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { | 809 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { |
809 mock_delegate_.set_screen_availability_listening_supported(false); | 810 mock_delegate_.set_screen_availability_listening_supported(false); |
810 EXPECT_CALL(mock_client_, | 811 EXPECT_CALL(mock_client_, |
811 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))); | 812 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))); |
812 | 813 |
813 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); | 814 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); |
814 } | 815 } |
815 | 816 |
816 } // namespace content | 817 } // namespace content |
OLD | NEW |