| 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" | 5 #include "content/browser/presentation/presentation_service_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 9 #include <string> | 11 #include <string> |
| 10 #include <utility> | 12 #include <utility> |
| 11 #include <vector> | 13 #include <vector> |
| 12 | 14 |
| 13 #include "base/location.h" | 15 #include "base/location.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 17 #include "base/test/test_timeouts.h" | 18 #include "base/test/test_timeouts.h" |
| 18 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| 19 #include "content/public/browser/presentation_service_delegate.h" | 20 #include "content/public/browser/presentation_service_delegate.h" |
| 20 #include "content/public/browser/presentation_session.h" | 21 #include "content/public/browser/presentation_session.h" |
| 21 #include "content/public/common/presentation_constants.h" | 22 #include "content/public/common/presentation_constants.h" |
| 22 #include "content/test/test_render_frame_host.h" | 23 #include "content/test/test_render_frame_host.h" |
| 23 #include "content/test/test_render_view_host.h" | 24 #include "content/test/test_render_view_host.h" |
| 24 #include "content/test/test_web_contents.h" | 25 #include "content/test/test_web_contents.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 const PresentationSessionMessageCallback& message_cb)); | 120 const PresentationSessionMessageCallback& message_cb)); |
| 120 MOCK_METHOD5(SendMessageRawPtr, | 121 MOCK_METHOD5(SendMessageRawPtr, |
| 121 void(int render_process_id, | 122 void(int render_process_id, |
| 122 int render_frame_id, | 123 int render_frame_id, |
| 123 const content::PresentationSessionInfo& session, | 124 const content::PresentationSessionInfo& session, |
| 124 PresentationSessionMessage* message_request, | 125 PresentationSessionMessage* message_request, |
| 125 const SendMessageCallback& send_message_cb)); | 126 const SendMessageCallback& send_message_cb)); |
| 126 void SendMessage(int render_process_id, | 127 void SendMessage(int render_process_id, |
| 127 int render_frame_id, | 128 int render_frame_id, |
| 128 const content::PresentationSessionInfo& session, | 129 const content::PresentationSessionInfo& session, |
| 129 scoped_ptr<PresentationSessionMessage> message_request, | 130 std::unique_ptr<PresentationSessionMessage> message_request, |
| 130 const SendMessageCallback& send_message_cb) override { | 131 const SendMessageCallback& send_message_cb) override { |
| 131 SendMessageRawPtr(render_process_id, render_frame_id, session, | 132 SendMessageRawPtr(render_process_id, render_frame_id, session, |
| 132 message_request.release(), send_message_cb); | 133 message_request.release(), send_message_cb); |
| 133 } | 134 } |
| 134 MOCK_METHOD4(ListenForConnectionStateChange, | 135 MOCK_METHOD4(ListenForConnectionStateChange, |
| 135 void(int render_process_id, | 136 void(int render_process_id, |
| 136 int render_frame_id, | 137 int render_frame_id, |
| 137 const content::PresentationSessionInfo& connection, | 138 const content::PresentationSessionInfo& connection, |
| 138 const content::PresentationConnectionStateChangedCallback& | 139 const content::PresentationConnectionStateChangedCallback& |
| 139 state_changed_cb)); | 140 state_changed_cb)); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 { | 328 { |
| 328 base::RunLoop run_loop; | 329 base::RunLoop run_loop; |
| 329 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _)) | 330 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _)) |
| 330 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 331 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
| 331 SaveArg<3>(&message_cb))); | 332 SaveArg<3>(&message_cb))); |
| 332 service_ptr_->ListenForSessionMessages(session.Clone()); | 333 service_ptr_->ListenForSessionMessages(session.Clone()); |
| 333 run_loop.Run(); | 334 run_loop.Run(); |
| 334 } | 335 } |
| 335 | 336 |
| 336 ScopedVector<PresentationSessionMessage> messages; | 337 ScopedVector<PresentationSessionMessage> messages; |
| 337 scoped_ptr<content::PresentationSessionMessage> message; | 338 std::unique_ptr<content::PresentationSessionMessage> message; |
| 338 message.reset( | 339 message.reset( |
| 339 new content::PresentationSessionMessage(PresentationMessageType::TEXT)); | 340 new content::PresentationSessionMessage(PresentationMessageType::TEXT)); |
| 340 message->message = text_msg; | 341 message->message = text_msg; |
| 341 messages.push_back(std::move(message)); | 342 messages.push_back(std::move(message)); |
| 342 message.reset(new content::PresentationSessionMessage( | 343 message.reset(new content::PresentationSessionMessage( |
| 343 PresentationMessageType::ARRAY_BUFFER)); | 344 PresentationMessageType::ARRAY_BUFFER)); |
| 344 message->data.reset(new std::vector<uint8_t>(binary_data)); | 345 message->data.reset(new std::vector<uint8_t>(binary_data)); |
| 345 messages.push_back(std::move(message)); | 346 messages.push_back(std::move(message)); |
| 346 | 347 |
| 347 std::vector<mojom::SessionMessagePtr> actual_msgs; | 348 std::vector<mojom::SessionMessagePtr> actual_msgs; |
| 348 { | 349 { |
| 349 base::RunLoop run_loop; | 350 base::RunLoop run_loop; |
| 350 EXPECT_CALL(mock_client_, MessagesReceived()) | 351 EXPECT_CALL(mock_client_, MessagesReceived()) |
| 351 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 352 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 352 message_cb.Run(std::move(messages), pass_ownership); | 353 message_cb.Run(std::move(messages), pass_ownership); |
| 353 run_loop.Run(); | 354 run_loop.Run(); |
| 354 } | 355 } |
| 355 ExpectSessionMessages(expected_msgs, mock_client_.messages_received_); | 356 ExpectSessionMessages(expected_msgs, mock_client_.messages_received_); |
| 356 } | 357 } |
| 357 | 358 |
| 358 MockPresentationServiceDelegate mock_delegate_; | 359 MockPresentationServiceDelegate mock_delegate_; |
| 359 | 360 |
| 360 scoped_ptr<PresentationServiceImpl> service_impl_; | 361 std::unique_ptr<PresentationServiceImpl> service_impl_; |
| 361 mojo::InterfacePtr<mojom::PresentationService> service_ptr_; | 362 mojo::InterfacePtr<mojom::PresentationService> service_ptr_; |
| 362 | 363 |
| 363 MockPresentationServiceClient mock_client_; | 364 MockPresentationServiceClient mock_client_; |
| 364 scoped_ptr<mojo::Binding<mojom::PresentationServiceClient>> client_binding_; | 365 std::unique_ptr<mojo::Binding<mojom::PresentationServiceClient>> |
| 366 client_binding_; |
| 365 | 367 |
| 366 base::Closure run_loop_quit_closure_; | 368 base::Closure run_loop_quit_closure_; |
| 367 int default_session_started_count_; | 369 int default_session_started_count_; |
| 368 }; | 370 }; |
| 369 | 371 |
| 370 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { | 372 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { |
| 371 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); | 373 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); |
| 372 | 374 |
| 373 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, true); | 375 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, true); |
| 374 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, false); | 376 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, false); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 | 681 |
| 680 base::RunLoop run_loop; | 682 base::RunLoop run_loop; |
| 681 base::Callback<void(bool)> send_message_cb; | 683 base::Callback<void(bool)> send_message_cb; |
| 682 PresentationSessionMessage* test_message = nullptr; | 684 PresentationSessionMessage* test_message = nullptr; |
| 683 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) | 685 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) |
| 684 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 686 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
| 685 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); | 687 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); |
| 686 run_loop.Run(); | 688 run_loop.Run(); |
| 687 | 689 |
| 688 // Make sure |test_message| gets deleted. | 690 // Make sure |test_message| gets deleted. |
| 689 scoped_ptr<PresentationSessionMessage> scoped_test_message(test_message); | 691 std::unique_ptr<PresentationSessionMessage> scoped_test_message(test_message); |
| 690 EXPECT_TRUE(test_message); | 692 EXPECT_TRUE(test_message); |
| 691 EXPECT_FALSE(test_message->is_binary()); | 693 EXPECT_FALSE(test_message->is_binary()); |
| 692 EXPECT_LE(test_message->message.size(), kMaxPresentationSessionMessageSize); | 694 EXPECT_LE(test_message->message.size(), kMaxPresentationSessionMessageSize); |
| 693 EXPECT_EQ(message, test_message->message); | 695 EXPECT_EQ(message, test_message->message); |
| 694 ASSERT_FALSE(test_message->data); | 696 ASSERT_FALSE(test_message->data); |
| 695 send_message_cb.Run(true); | 697 send_message_cb.Run(true); |
| 696 SaveQuitClosureAndRunLoop(); | 698 SaveQuitClosureAndRunLoop(); |
| 697 } | 699 } |
| 698 | 700 |
| 699 TEST_F(PresentationServiceImplTest, SendArrayBuffer) { | 701 TEST_F(PresentationServiceImplTest, SendArrayBuffer) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 716 | 718 |
| 717 base::RunLoop run_loop; | 719 base::RunLoop run_loop; |
| 718 base::Callback<void(bool)> send_message_cb; | 720 base::Callback<void(bool)> send_message_cb; |
| 719 PresentationSessionMessage* test_message = nullptr; | 721 PresentationSessionMessage* test_message = nullptr; |
| 720 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) | 722 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) |
| 721 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 723 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
| 722 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); | 724 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); |
| 723 run_loop.Run(); | 725 run_loop.Run(); |
| 724 | 726 |
| 725 // Make sure |test_message| gets deleted. | 727 // Make sure |test_message| gets deleted. |
| 726 scoped_ptr<PresentationSessionMessage> scoped_test_message(test_message); | 728 std::unique_ptr<PresentationSessionMessage> scoped_test_message(test_message); |
| 727 EXPECT_TRUE(test_message); | 729 EXPECT_TRUE(test_message); |
| 728 EXPECT_TRUE(test_message->is_binary()); | 730 EXPECT_TRUE(test_message->is_binary()); |
| 729 EXPECT_EQ(PresentationMessageType::ARRAY_BUFFER, test_message->type); | 731 EXPECT_EQ(PresentationMessageType::ARRAY_BUFFER, test_message->type); |
| 730 EXPECT_TRUE(test_message->message.empty()); | 732 EXPECT_TRUE(test_message->message.empty()); |
| 731 ASSERT_TRUE(test_message->data); | 733 ASSERT_TRUE(test_message->data); |
| 732 EXPECT_EQ(data.size(), test_message->data->size()); | 734 EXPECT_EQ(data.size(), test_message->data->size()); |
| 733 EXPECT_LE(test_message->data->size(), kMaxPresentationSessionMessageSize); | 735 EXPECT_LE(test_message->data->size(), kMaxPresentationSessionMessageSize); |
| 734 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer))); | 736 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer))); |
| 735 send_message_cb.Run(true); | 737 send_message_cb.Run(true); |
| 736 SaveQuitClosureAndRunLoop(); | 738 SaveQuitClosureAndRunLoop(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 | 791 |
| 790 base::RunLoop run_loop; | 792 base::RunLoop run_loop; |
| 791 base::Callback<void(bool)> send_message_cb; | 793 base::Callback<void(bool)> send_message_cb; |
| 792 PresentationSessionMessage* test_message = nullptr; | 794 PresentationSessionMessage* test_message = nullptr; |
| 793 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) | 795 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) |
| 794 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 796 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
| 795 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); | 797 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); |
| 796 run_loop.Run(); | 798 run_loop.Run(); |
| 797 | 799 |
| 798 // Make sure |test_message| gets deleted. | 800 // Make sure |test_message| gets deleted. |
| 799 scoped_ptr<PresentationSessionMessage> scoped_test_message(test_message); | 801 std::unique_ptr<PresentationSessionMessage> scoped_test_message(test_message); |
| 800 EXPECT_TRUE(test_message); | 802 EXPECT_TRUE(test_message); |
| 801 EXPECT_TRUE(test_message->is_binary()); | 803 EXPECT_TRUE(test_message->is_binary()); |
| 802 EXPECT_EQ(PresentationMessageType::BLOB, test_message->type); | 804 EXPECT_EQ(PresentationMessageType::BLOB, test_message->type); |
| 803 EXPECT_TRUE(test_message->message.empty()); | 805 EXPECT_TRUE(test_message->message.empty()); |
| 804 ASSERT_TRUE(test_message->data); | 806 ASSERT_TRUE(test_message->data); |
| 805 EXPECT_EQ(data.size(), test_message->data->size()); | 807 EXPECT_EQ(data.size(), test_message->data->size()); |
| 806 EXPECT_LE(test_message->data->size(), kMaxPresentationSessionMessageSize); | 808 EXPECT_LE(test_message->data->size(), kMaxPresentationSessionMessageSize); |
| 807 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer))); | 809 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer))); |
| 808 send_message_cb.Run(true); | 810 send_message_cb.Run(true); |
| 809 SaveQuitClosureAndRunLoop(); | 811 SaveQuitClosureAndRunLoop(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 837 mock_delegate_.set_screen_availability_listening_supported(false); | 839 mock_delegate_.set_screen_availability_listening_supported(false); |
| 838 base::RunLoop run_loop; | 840 base::RunLoop run_loop; |
| 839 EXPECT_CALL(mock_client_, | 841 EXPECT_CALL(mock_client_, |
| 840 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))) | 842 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))) |
| 841 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 843 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 842 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); | 844 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); |
| 843 run_loop.Run(); | 845 run_loop.Run(); |
| 844 } | 846 } |
| 845 | 847 |
| 846 } // namespace content | 848 } // namespace content |
| OLD | NEW |