Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Unified Diff: content/browser/presentation/presentation_service_impl_unittest.cc

Issue 2477573002: [Presentation API] (3rd) (1-UA) Split PresentationServiceDelegateImpl(PSDImpl) (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 3085b290686db47859f4a41e4c9bbc4d1753193d..a6b73f960c69537af0a20c2f12b9393089217e77 100644
--- a/content/browser/presentation/presentation_service_impl_unittest.cc
+++ b/content/browser/presentation/presentation_service_impl_unittest.cc
@@ -44,12 +44,20 @@ 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, "") {
mark a. foltz 2016/11/15 23:41:47 Nice :)
+ const content::PresentationSessionInfo& expected_value = expected;
+ return expected_value.presentation_url == arg.presentation_url &&
+ expected_value.presentation_id == arg.presentation_id &&
+ expected_value.is_offscreen == arg.is_offscreen;
+}
+
const char kPresentationId[] = "presentationId";
const char kPresentationUrl1[] = "http://foo.com/index.html";
const char kPresentationUrl2[] = "http://example.com/index.html";
@@ -60,12 +68,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 +148,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 +171,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 +268,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 +428,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_;
@@ -669,6 +724,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,
+ false);
+ 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);

Powered by Google App Engine
This is Rietveld 408576698