| 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 9374f4a8f8948aee9243b4923e8768f5b850dee9..a2ce915fc5b0c9ff579bd976321a853d85da5bb9 100644
|
| --- a/content/browser/presentation/presentation_service_impl_unittest.cc
|
| +++ b/content/browser/presentation/presentation_service_impl_unittest.cc
|
| @@ -44,12 +44,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";
|
| @@ -60,12 +67,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,21 @@ 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 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 content::PresentationSessionInfo& session,
|
| + blink::mojom::PresentationConnection* connection));
|
| +
|
| void set_screen_availability_listening_supported(bool value) {
|
| screen_availability_listening_supported_ = value;
|
| }
|
| @@ -147,6 +170,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,
|
| + 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 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 +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;
|
| @@ -374,6 +427,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_;
|
| @@ -667,6 +721,57 @@ TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) {
|
| RunListenForSessionMessages(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::GetProxy(&connection));
|
| +
|
| + content::PresentationSessionInfo expected(presentation_url1_,
|
| + kPresentationId);
|
| + EXPECT_CALL(mock_delegate_,
|
| + RegisterOffscreenPresentationConnectionRaw(
|
| + _, _, ContentSessionInfoEquals(ByRef(expected)), _));
|
| +
|
| + service_impl_->SetPresentationConnection(std::move(session),
|
| + std::move(connection));
|
| +}
|
| +
|
| +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::GetProxy(&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_, 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);
|
|
|