| 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 fbe3bb79509d1e72c75466c80c1345e1d80d6435..e0028b71ae41a94645f6dd5197e8a02d0e39d9db 100644
|
| --- a/content/browser/presentation/presentation_service_impl_unittest.cc
|
| +++ b/content/browser/presentation/presentation_service_impl_unittest.cc
|
| @@ -43,12 +43,19 @@ MATCHER_P(Equals, expected, "") {
|
| return expected.Equals(arg);
|
| }
|
|
|
| -// Matches PresentationSessionInfo passed by reference.
|
| +// Matches blink::mojom::PresentationSessionInfo passed by reference.
|
| MATCHER_P(SessionInfoEquals, expected, "") {
|
| blink::mojom::PresentationSessionInfo& expected_value = expected;
|
| return expected_value.Equals(arg);
|
| }
|
|
|
| +// Matches content::PresentationSessionInfo passed by reference.
|
| +MATCHER_P(ContentSessionInfoEquals, expected, "") {
|
| + const content::PresentationSessionInfo& expected_value = expected;
|
| + return expected_value.presentation_url == arg.presentation_url &&
|
| + expected_value.presentation_id == arg.presentation_id;
|
| +}
|
| +
|
| const char kPresentationId[] = "presentationId";
|
| const char kPresentationUrl1[] = "http://foo.com/index.html";
|
| const char kPresentationUrl2[] = "http://example.com/index.html";
|
| @@ -59,12 +66,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,
|
| + PresentationServiceDelegate::Observer* observer));
|
| MOCK_METHOD2(RemoveObserver,
|
| void(int render_process_id, int render_frame_id));
|
|
|
| @@ -139,6 +147,22 @@ class MockPresentationServiceDelegate : public PresentationServiceDelegate {
|
| const content::PresentationConnectionStateChangedCallback&
|
| state_changed_cb));
|
|
|
| + void ConnectToOffscreenPresentation(
|
| + int render_process_id,
|
| + int render_frame_id,
|
| + const content::PresentationSessionInfo& session,
|
| + PresentationConnectionPtr controller_conn_ptr,
|
| + PresentationConnectionRequest receiver_conn_request) override {
|
| + RegisterOffscreenPresentationConnectionRaw(
|
| + render_process_id, render_frame_id, session, controller_conn_ptr.get());
|
| + }
|
| +
|
| + MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw,
|
| + void(int render_process_id,
|
| + int render_frame_id,
|
| + const content::PresentationSessionInfo& session,
|
| + blink::mojom::PresentationConnection* connection));
|
| +
|
| void set_screen_availability_listening_supported(bool value) {
|
| screen_availability_listening_supported_ = value;
|
| }
|
| @@ -147,6 +171,32 @@ 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,
|
| + PresentationServiceDelegate::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 OnMessage(blink::mojom::ConnectionMessagePtr message,
|
| + const base::Callback<void(bool)>& send_message_cb) override {
|
| + OnConnectionMessageReceived(*message);
|
| + }
|
| + MOCK_METHOD1(OnConnectionMessageReceived,
|
| + void(const blink::mojom::ConnectionMessage& message));
|
| + MOCK_METHOD1(DidChangeState,
|
| + void(blink::mojom::PresentationConnectionState state));
|
| +};
|
| +
|
| class MockPresentationServiceClient
|
| : public blink::mojom::PresentationServiceClient {
|
| public:
|
| @@ -190,7 +240,10 @@ class MockPresentationServiceClient
|
| void(const blink::mojom::PresentationSessionInfo& session_info));
|
|
|
| void OnReceiverConnectionAvailable(
|
| - blink::mojom::PresentationSessionInfoPtr session_info) override {
|
| + blink::mojom::PresentationSessionInfoPtr session_info,
|
| + blink::mojom::PresentationConnectionPtr controller_conn_ptr,
|
| + blink::mojom::PresentationConnectionRequest receiver_conn_request)
|
| + override {
|
| OnReceiverConnectionAvailable(*session_info);
|
| }
|
| MOCK_METHOD1(OnReceiverConnectionAvailable,
|
| @@ -214,7 +267,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;
|
| @@ -373,6 +426,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_;
|
| @@ -666,6 +720,59 @@ TEST_F(PresentationServiceImplTest, ListenForConnectionMessagesWithEmptyMsg) {
|
| RunListenForConnectionMessages(text_msg, binary_data, false);
|
| }
|
|
|
| +TEST_F(PresentationServiceImplTest, SetPresentationConnection) {
|
| + blink::mojom::PresentationSessionInfoPtr session(
|
| + blink::mojom::PresentationSessionInfo::New());
|
| + session->url = presentation_url1_;
|
| + session->id = kPresentationId;
|
| +
|
| + blink::mojom::PresentationConnectionPtr connection;
|
| + MockPresentationConnection mock_presentation_connection;
|
| + mojo::Binding<blink::mojom::PresentationConnection> connection_binding(
|
| + &mock_presentation_connection, mojo::MakeRequest(&connection));
|
| + blink::mojom::PresentationConnectionPtr receiver_connection;
|
| + auto request = mojo::MakeRequest(&receiver_connection);
|
| +
|
| + content::PresentationSessionInfo expected(presentation_url1_,
|
| + kPresentationId);
|
| + EXPECT_CALL(mock_delegate_,
|
| + RegisterOffscreenPresentationConnectionRaw(
|
| + _, _, ContentSessionInfoEquals(ByRef(expected)), _));
|
| +
|
| + service_impl_->SetPresentationConnection(
|
| + std::move(session), std::move(connection), std::move(request));
|
| +}
|
| +
|
| +TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) {
|
| + MockReceiverPresentationServiceDelegate mock_receiver_delegate;
|
| +
|
| + PresentationServiceImpl service_impl(contents()->GetMainFrame(), contents(),
|
| + nullptr, &mock_receiver_delegate);
|
| +
|
| + ReceiverConnectionAvailableCallback callback;
|
| + EXPECT_CALL(mock_receiver_delegate,
|
| + RegisterReceiverConnectionAvailableCallback(_))
|
| + .WillOnce(SaveArg<0>(&callback));
|
| +
|
| + blink::mojom::PresentationServiceClientPtr client_ptr;
|
| + client_binding_.reset(
|
| + new mojo::Binding<blink::mojom::PresentationServiceClient>(
|
| + &mock_client_, mojo::MakeRequest(&client_ptr)));
|
| + service_impl.controller_delegate_ = nullptr;
|
| + service_impl.SetClient(std::move(client_ptr));
|
| + EXPECT_FALSE(callback.is_null());
|
| +
|
| + // NO-OP for ControllerPresentationServiceDelegate API functions
|
| + EXPECT_CALL(mock_delegate_, ListenForConnectionMessages(_, _, _, _)).Times(0);
|
| +
|
| + blink::mojom::PresentationSessionInfoPtr session(
|
| + blink::mojom::PresentationSessionInfo::New());
|
| + session->url = GURL(kPresentationUrl1);
|
| + session->id = kPresentationId;
|
| +
|
| + service_impl.ListenForConnectionMessages(std::move(session));
|
| +}
|
| +
|
| TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
|
| EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _))
|
| .Times(1);
|
|
|