Chromium Code Reviews| Index: content/browser/presentation/presentation_service_impl_unittest.cc |
| diff --git a/content/browser/presentation/presentation_service_impl_unittest.cc b/content/browser/presentation/presentation_service_impl_unittest.cc |
| index 73f3dde1d00b56c60105fe3cf9dfe1c974423aad..aa3ae2dc74e2f8dd0e011e277448f2cfc62f2acc 100644 |
| --- a/content/browser/presentation/presentation_service_impl_unittest.cc |
| +++ b/content/browser/presentation/presentation_service_impl_unittest.cc |
| @@ -60,12 +60,13 @@ void DoNothing(blink::mojom::PresentationSessionInfoPtr info, |
| } // namespace |
| -class MockPresentationServiceDelegate : public PresentationServiceDelegate { |
| +class MockPresentationServiceDelegate |
| + : public ControllerPresentationServiceDelegate { |
| public: |
| MOCK_METHOD3(AddObserver, |
| - void(int render_process_id, |
| - int render_frame_id, |
| - PresentationServiceDelegate::Observer* observer)); |
| + void(int render_process_id, |
| + int render_frame_id, |
| + PresentationServiceDelegateBase::Observer* observer)); |
| MOCK_METHOD2(RemoveObserver, |
| void(int render_process_id, int render_frame_id)); |
| @@ -139,6 +140,21 @@ class MockPresentationServiceDelegate : public PresentationServiceDelegate { |
| const content::PresentationConnectionStateChangedCallback& |
| state_changed_cb)); |
| + void ConnectToOffscreenPresentation( |
| + int render_process_id, |
| + int render_frame_id, |
| + const PresentationSessionInfo& session, |
| + PresentationConnectionPtr connection) override { |
| + RegisterOffscreenPresentationConnectionRaw( |
| + render_process_id, render_frame_id, session, connection.get()); |
| + } |
| + |
| + MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw, |
| + void(int render_process_id, |
| + int render_frame_id, |
| + const PresentationSessionInfo& session, |
| + blink::mojom::PresentationConnection* connection)); |
| + |
| void set_screen_availability_listening_supported(bool value) { |
| screen_availability_listening_supported_ = value; |
| } |
| @@ -147,6 +163,36 @@ class MockPresentationServiceDelegate : public PresentationServiceDelegate { |
| bool screen_availability_listening_supported_ = true; |
| }; |
| +class MockReceiverPresentationServiceDelegate |
| + : public ReceiverPresentationServiceDelegate { |
| + public: |
| + MOCK_METHOD3(AddObserver, |
| + void(int render_process_id, |
| + int render_frame_id, |
| + PresentationServiceDelegateBase::Observer* observer)); |
| + MOCK_METHOD2(RemoveObserver, |
| + void(int render_process_id, int render_frame_id)); |
| + MOCK_METHOD2(Reset, void(int render_process_id, int routing_id)); |
| + MOCK_METHOD1(RegisterReceiverConnectionAvailableCallback, |
| + void(const content::ReceiverConnectionAvailableCallback&)); |
| +}; |
| + |
| +class MockPresentationConnection : public blink::mojom::PresentationConnection { |
| + public: |
| + void SetTargetConnection( |
| + blink::mojom::PresentationConnectionPtr connection) override { |
| + SetTargetConnection(*connection); |
| + } |
| + MOCK_METHOD1(SetTargetConnection, |
| + void(blink::mojom::PresentationConnection& connection)); |
| + |
| + void OnMessage(blink::mojom::SessionMessagePtr message) override { |
| + OnConnectionMessageReceived(*message); |
| + } |
| + MOCK_METHOD1(OnConnectionMessageReceived, |
| + void(const blink::mojom::SessionMessage& message)); |
| +}; |
| + |
| class MockPresentationServiceClient |
| : public blink::mojom::PresentationServiceClient { |
| public: |
| @@ -214,7 +260,7 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
| TestRenderFrameHost* render_frame_host = contents()->GetMainFrame(); |
| render_frame_host->InitializeRenderFrameIfNeeded(); |
| service_impl_.reset(new PresentationServiceImpl( |
| - render_frame_host, contents(), &mock_delegate_)); |
| + render_frame_host, contents(), &mock_delegate_, nullptr)); |
| service_impl_->Bind(std::move(request)); |
| blink::mojom::PresentationServiceClientPtr client_ptr; |
| @@ -374,6 +420,7 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
| } |
| MockPresentationServiceDelegate mock_delegate_; |
| + MockReceiverPresentationServiceDelegate mock_receiver_delegate_; |
| std::unique_ptr<PresentationServiceImpl> service_impl_; |
| mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_; |
| @@ -661,6 +708,56 @@ TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) { |
| RunListenForSessionMessages(text_msg, binary_data, false); |
| } |
| +TEST_F(PresentationServiceImplTest, SetPresentationConnection) { |
| + blink::mojom::PresentationSessionInfoPtr session( |
| + blink::mojom::PresentationSessionInfo::New()); |
| + session->url = GURL(kPresentationUrl1); |
| + session->id = kPresentationId; |
| + |
| + blink::mojom::PresentationConnectionPtr connection; |
| + |
| + MockPresentationConnection mock_presentation_connection; |
| + mojo::Binding<blink::mojom::PresentationConnection> binding( |
| + &mock_presentation_connection, mojo::GetProxy(&connection)); |
| + |
| + EXPECT_CALL(mock_delegate_, |
| + RegisterOffscreenPresentationConnectionRaw(_, _, _, _)) |
|
mark a. foltz
2016/11/08 23:40:52
Can you verify the contents of |session| here?
zhaobin
2016/11/10 04:14:00
Done.
|
| + .Times(1); |
| + |
| + service_impl_->SetPresentationConnection(std::move(session), |
| + std::move(connection)); |
| +} |
| + |
| +TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) { |
| + MockReceiverPresentationServiceDelegate mock_receiver_delegate; |
| + |
| + PresentationServiceImpl service_impl(contents()->GetMainFrame(), contents(), |
| + &mock_delegate_, |
|
mark a. foltz
2016/11/08 23:40:52
Should the controller delegate be nullptr here?
zhaobin
2016/11/10 04:14:00
Done.
|
| + &mock_receiver_delegate); |
| + |
| + EXPECT_CALL(mock_receiver_delegate, |
| + RegisterReceiverConnectionAvailableCallback(_)); |
|
mark a. foltz
2016/11/08 23:40:52
Nit: verify that the callback registered is not nu
zhaobin
2016/11/10 04:14:00
Done.
|
| + |
| + blink::mojom::PresentationServiceClientPtr client_ptr; |
| + client_binding_.reset( |
| + new mojo::Binding<blink::mojom::PresentationServiceClient>( |
| + &mock_client_, mojo::GetProxy(&client_ptr))); |
| + // If receiver_delegate_ != nullptr, set controller_delegate = nullptr in |
| + // CreateMojoService(). |
| + service_impl.controller_delegate_ = nullptr; |
| + service_impl.SetClient(std::move(client_ptr)); |
| + |
| + // NO-OP for ControllerPresentationServiceDelegate API functions |
| + EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _)).Times(0); |
| + |
| + blink::mojom::PresentationSessionInfoPtr session( |
| + blink::mojom::PresentationSessionInfo::New()); |
| + session->url = GURL(kPresentationUrl1); |
| + session->id = kPresentationId; |
| + |
| + service_impl.ListenForSessionMessages(std::move(session)); |
| +} |
| + |
| TEST_F(PresentationServiceImplTest, StartSessionInProgress) { |
| EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _)) |
| .Times(1); |