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

Side by Side Diff: content/browser/presentation/presentation_service_impl_unittest.cc

Issue 2477573002: [Presentation API] (3rd) (1-UA) Split PresentationServiceDelegateImpl(PSDImpl) (Closed)
Patch Set: fix windows compile error Created 3 years, 11 months 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 unified diff | Download patch
OLDNEW
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 9
10 #include <memory> 10 #include <memory>
(...skipping 25 matching lines...) Expand all
36 36
37 namespace content { 37 namespace content {
38 38
39 namespace { 39 namespace {
40 40
41 // Matches Mojo structs. 41 // Matches Mojo structs.
42 MATCHER_P(Equals, expected, "") { 42 MATCHER_P(Equals, expected, "") {
43 return expected.Equals(arg); 43 return expected.Equals(arg);
44 } 44 }
45 45
46 // Matches PresentationSessionInfo passed by reference. 46 // Matches blink::mojom::PresentationSessionInfo passed by reference.
47 MATCHER_P(SessionInfoEquals, expected, "") { 47 MATCHER_P(SessionInfoEquals, expected, "") {
48 blink::mojom::PresentationSessionInfo& expected_value = expected; 48 blink::mojom::PresentationSessionInfo& expected_value = expected;
49 return expected_value.Equals(arg); 49 return expected_value.Equals(arg);
50 } 50 }
51 51
52 // Matches content::PresentationSessionInfo passed by reference.
53 MATCHER_P(ContentSessionInfoEquals, expected, "") {
54 const content::PresentationSessionInfo& expected_value = expected;
55 return expected_value.presentation_url == arg.presentation_url &&
56 expected_value.presentation_id == arg.presentation_id;
57 }
58
52 const char kPresentationId[] = "presentationId"; 59 const char kPresentationId[] = "presentationId";
53 const char kPresentationUrl1[] = "http://foo.com/index.html"; 60 const char kPresentationUrl1[] = "http://foo.com/index.html";
54 const char kPresentationUrl2[] = "http://example.com/index.html"; 61 const char kPresentationUrl2[] = "http://example.com/index.html";
55 const char kPresentationUrl3[] = "http://example.net/index.html"; 62 const char kPresentationUrl3[] = "http://example.net/index.html";
56 63
57 void DoNothing(blink::mojom::PresentationSessionInfoPtr info, 64 void DoNothing(blink::mojom::PresentationSessionInfoPtr info,
58 blink::mojom::PresentationErrorPtr error) {} 65 blink::mojom::PresentationErrorPtr error) {}
59 66
60 } // namespace 67 } // namespace
61 68
62 class MockPresentationServiceDelegate : public PresentationServiceDelegate { 69 class MockPresentationServiceDelegate
70 : public ControllerPresentationServiceDelegate {
63 public: 71 public:
64 MOCK_METHOD3(AddObserver, 72 MOCK_METHOD3(AddObserver,
65 void(int render_process_id, 73 void(int render_process_id,
66 int render_frame_id, 74 int render_frame_id,
67 PresentationServiceDelegate::Observer* observer)); 75 PresentationServiceDelegate::Observer* observer));
68 MOCK_METHOD2(RemoveObserver, 76 MOCK_METHOD2(RemoveObserver,
69 void(int render_process_id, int render_frame_id)); 77 void(int render_process_id, int render_frame_id));
70 78
71 bool AddScreenAvailabilityListener( 79 bool AddScreenAvailabilityListener(
72 int render_process_id, 80 int render_process_id,
73 int routing_id, 81 int routing_id,
74 PresentationScreenAvailabilityListener* listener) override { 82 PresentationScreenAvailabilityListener* listener) override {
75 if (!screen_availability_listening_supported_) 83 if (!screen_availability_listening_supported_)
76 listener->OnScreenAvailabilityNotSupported(); 84 listener->OnScreenAvailabilityNotSupported();
77 85
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 SendMessageRawPtr(render_process_id, render_frame_id, session, 140 SendMessageRawPtr(render_process_id, render_frame_id, session,
133 message_request.release(), send_message_cb); 141 message_request.release(), send_message_cb);
134 } 142 }
135 MOCK_METHOD4(ListenForConnectionStateChange, 143 MOCK_METHOD4(ListenForConnectionStateChange,
136 void(int render_process_id, 144 void(int render_process_id,
137 int render_frame_id, 145 int render_frame_id,
138 const content::PresentationSessionInfo& connection, 146 const content::PresentationSessionInfo& connection,
139 const content::PresentationConnectionStateChangedCallback& 147 const content::PresentationConnectionStateChangedCallback&
140 state_changed_cb)); 148 state_changed_cb));
141 149
150 void ConnectToOffscreenPresentation(
151 int render_process_id,
152 int render_frame_id,
153 const content::PresentationSessionInfo& session,
154 PresentationConnectionPtr controller_conn_ptr,
155 PresentationConnectionRequest receiver_conn_request) override {
156 RegisterOffscreenPresentationConnectionRaw(
157 render_process_id, render_frame_id, session, controller_conn_ptr.get());
158 }
159
160 MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw,
161 void(int render_process_id,
162 int render_frame_id,
163 const content::PresentationSessionInfo& session,
164 blink::mojom::PresentationConnection* connection));
165
142 void set_screen_availability_listening_supported(bool value) { 166 void set_screen_availability_listening_supported(bool value) {
143 screen_availability_listening_supported_ = value; 167 screen_availability_listening_supported_ = value;
144 } 168 }
145 169
146 private: 170 private:
147 bool screen_availability_listening_supported_ = true; 171 bool screen_availability_listening_supported_ = true;
148 }; 172 };
149 173
174 class MockReceiverPresentationServiceDelegate
175 : public ReceiverPresentationServiceDelegate {
176 public:
177 MOCK_METHOD3(AddObserver,
178 void(int render_process_id,
179 int render_frame_id,
180 PresentationServiceDelegate::Observer* observer));
181 MOCK_METHOD2(RemoveObserver,
182 void(int render_process_id, int render_frame_id));
183 MOCK_METHOD2(Reset, void(int render_process_id, int routing_id));
184 MOCK_METHOD1(RegisterReceiverConnectionAvailableCallback,
185 void(const content::ReceiverConnectionAvailableCallback&));
186 };
187
188 class MockPresentationConnection : public blink::mojom::PresentationConnection {
189 public:
190 void OnMessage(blink::mojom::ConnectionMessagePtr message,
191 const base::Callback<void(bool)>& send_message_cb) override {
192 OnConnectionMessageReceived(*message);
193 }
194 MOCK_METHOD1(OnConnectionMessageReceived,
195 void(const blink::mojom::ConnectionMessage& message));
196 MOCK_METHOD1(DidChangeState,
197 void(blink::mojom::PresentationConnectionState state));
198 };
199
150 class MockPresentationServiceClient 200 class MockPresentationServiceClient
151 : public blink::mojom::PresentationServiceClient { 201 : public blink::mojom::PresentationServiceClient {
152 public: 202 public:
153 MOCK_METHOD2(OnScreenAvailabilityUpdated, 203 MOCK_METHOD2(OnScreenAvailabilityUpdated,
154 void(const GURL& url, bool available)); 204 void(const GURL& url, bool available));
155 void OnConnectionStateChanged( 205 void OnConnectionStateChanged(
156 blink::mojom::PresentationSessionInfoPtr connection, 206 blink::mojom::PresentationSessionInfoPtr connection,
157 blink::mojom::PresentationConnectionState new_state) override { 207 blink::mojom::PresentationConnectionState new_state) override {
158 OnConnectionStateChanged(*connection, new_state); 208 OnConnectionStateChanged(*connection, new_state);
159 } 209 }
(...skipping 23 matching lines...) Expand all
183 MOCK_METHOD0(MessagesReceived, void()); 233 MOCK_METHOD0(MessagesReceived, void());
184 234
185 void OnDefaultSessionStarted( 235 void OnDefaultSessionStarted(
186 blink::mojom::PresentationSessionInfoPtr session_info) override { 236 blink::mojom::PresentationSessionInfoPtr session_info) override {
187 OnDefaultSessionStarted(*session_info); 237 OnDefaultSessionStarted(*session_info);
188 } 238 }
189 MOCK_METHOD1(OnDefaultSessionStarted, 239 MOCK_METHOD1(OnDefaultSessionStarted,
190 void(const blink::mojom::PresentationSessionInfo& session_info)); 240 void(const blink::mojom::PresentationSessionInfo& session_info));
191 241
192 void OnReceiverConnectionAvailable( 242 void OnReceiverConnectionAvailable(
193 blink::mojom::PresentationSessionInfoPtr session_info) override { 243 blink::mojom::PresentationSessionInfoPtr session_info,
244 blink::mojom::PresentationConnectionPtr controller_conn_ptr,
245 blink::mojom::PresentationConnectionRequest receiver_conn_request)
246 override {
194 OnReceiverConnectionAvailable(*session_info); 247 OnReceiverConnectionAvailable(*session_info);
195 } 248 }
196 MOCK_METHOD1(OnReceiverConnectionAvailable, 249 MOCK_METHOD1(OnReceiverConnectionAvailable,
197 void(const blink::mojom::PresentationSessionInfo& session_info)); 250 void(const blink::mojom::PresentationSessionInfo& session_info));
198 251
199 std::vector<blink::mojom::ConnectionMessagePtr> messages_received_; 252 std::vector<blink::mojom::ConnectionMessagePtr> messages_received_;
200 }; 253 };
201 254
202 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { 255 class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
203 public: 256 public:
204 PresentationServiceImplTest() 257 PresentationServiceImplTest()
205 : presentation_url1_(GURL(kPresentationUrl1)), 258 : presentation_url1_(GURL(kPresentationUrl1)),
206 presentation_url2_(GURL(kPresentationUrl2)), 259 presentation_url2_(GURL(kPresentationUrl2)),
207 presentation_url3_(GURL(kPresentationUrl3)) {} 260 presentation_url3_(GURL(kPresentationUrl3)) {}
208 261
209 void SetUp() override { 262 void SetUp() override {
210 RenderViewHostImplTestHarness::SetUp(); 263 RenderViewHostImplTestHarness::SetUp();
211 264
212 auto request = mojo::MakeRequest(&service_ptr_); 265 auto request = mojo::MakeRequest(&service_ptr_);
213 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1); 266 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1);
214 TestRenderFrameHost* render_frame_host = contents()->GetMainFrame(); 267 TestRenderFrameHost* render_frame_host = contents()->GetMainFrame();
215 render_frame_host->InitializeRenderFrameIfNeeded(); 268 render_frame_host->InitializeRenderFrameIfNeeded();
216 service_impl_.reset(new PresentationServiceImpl( 269 service_impl_.reset(new PresentationServiceImpl(
217 render_frame_host, contents(), &mock_delegate_)); 270 render_frame_host, contents(), &mock_delegate_, nullptr));
218 service_impl_->Bind(std::move(request)); 271 service_impl_->Bind(std::move(request));
219 272
220 blink::mojom::PresentationServiceClientPtr client_ptr; 273 blink::mojom::PresentationServiceClientPtr client_ptr;
221 client_binding_.reset( 274 client_binding_.reset(
222 new mojo::Binding<blink::mojom::PresentationServiceClient>( 275 new mojo::Binding<blink::mojom::PresentationServiceClient>(
223 &mock_client_, mojo::MakeRequest(&client_ptr))); 276 &mock_client_, mojo::MakeRequest(&client_ptr)));
224 service_impl_->SetClient(std::move(client_ptr)); 277 service_impl_->SetClient(std::move(client_ptr));
225 278
226 presentation_urls_.push_back(presentation_url1_); 279 presentation_urls_.push_back(presentation_url1_);
227 presentation_urls_.push_back(presentation_url2_); 280 presentation_urls_.push_back(presentation_url2_);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 base::RunLoop run_loop; 419 base::RunLoop run_loop;
367 EXPECT_CALL(mock_client_, MessagesReceived()) 420 EXPECT_CALL(mock_client_, MessagesReceived())
368 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 421 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
369 message_cb.Run(std::move(messages), pass_ownership); 422 message_cb.Run(std::move(messages), pass_ownership);
370 run_loop.Run(); 423 run_loop.Run();
371 } 424 }
372 ExpectConnectionMessages(expected_msgs, mock_client_.messages_received_); 425 ExpectConnectionMessages(expected_msgs, mock_client_.messages_received_);
373 } 426 }
374 427
375 MockPresentationServiceDelegate mock_delegate_; 428 MockPresentationServiceDelegate mock_delegate_;
429 MockReceiverPresentationServiceDelegate mock_receiver_delegate_;
376 430
377 std::unique_ptr<PresentationServiceImpl> service_impl_; 431 std::unique_ptr<PresentationServiceImpl> service_impl_;
378 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_; 432 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_;
379 433
380 MockPresentationServiceClient mock_client_; 434 MockPresentationServiceClient mock_client_;
381 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>> 435 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>>
382 client_binding_; 436 client_binding_;
383 437
384 base::Closure run_loop_quit_closure_; 438 base::Closure run_loop_quit_closure_;
385 439
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 std::vector<uint8_t> binary_data(3, '\1'); 713 std::vector<uint8_t> binary_data(3, '\1');
660 RunListenForConnectionMessages(text_msg, binary_data, false); 714 RunListenForConnectionMessages(text_msg, binary_data, false);
661 } 715 }
662 716
663 TEST_F(PresentationServiceImplTest, ListenForConnectionMessagesWithEmptyMsg) { 717 TEST_F(PresentationServiceImplTest, ListenForConnectionMessagesWithEmptyMsg) {
664 std::string text_msg(""); 718 std::string text_msg("");
665 std::vector<uint8_t> binary_data; 719 std::vector<uint8_t> binary_data;
666 RunListenForConnectionMessages(text_msg, binary_data, false); 720 RunListenForConnectionMessages(text_msg, binary_data, false);
667 } 721 }
668 722
723 TEST_F(PresentationServiceImplTest, SetPresentationConnection) {
724 blink::mojom::PresentationSessionInfoPtr session(
725 blink::mojom::PresentationSessionInfo::New());
726 session->url = presentation_url1_;
727 session->id = kPresentationId;
728
729 blink::mojom::PresentationConnectionPtr connection;
730 MockPresentationConnection mock_presentation_connection;
731 mojo::Binding<blink::mojom::PresentationConnection> connection_binding(
732 &mock_presentation_connection, mojo::MakeRequest(&connection));
733 blink::mojom::PresentationConnectionPtr receiver_connection;
734 auto request = mojo::MakeRequest(&receiver_connection);
735
736 content::PresentationSessionInfo expected(presentation_url1_,
737 kPresentationId);
738 EXPECT_CALL(mock_delegate_,
739 RegisterOffscreenPresentationConnectionRaw(
740 _, _, ContentSessionInfoEquals(ByRef(expected)), _));
741
742 service_impl_->SetPresentationConnection(
743 std::move(session), std::move(connection), std::move(request));
744 }
745
746 TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) {
747 MockReceiverPresentationServiceDelegate mock_receiver_delegate;
748
749 PresentationServiceImpl service_impl(contents()->GetMainFrame(), contents(),
750 nullptr, &mock_receiver_delegate);
751
752 ReceiverConnectionAvailableCallback callback;
753 EXPECT_CALL(mock_receiver_delegate,
754 RegisterReceiverConnectionAvailableCallback(_))
755 .WillOnce(SaveArg<0>(&callback));
756
757 blink::mojom::PresentationServiceClientPtr client_ptr;
758 client_binding_.reset(
759 new mojo::Binding<blink::mojom::PresentationServiceClient>(
760 &mock_client_, mojo::MakeRequest(&client_ptr)));
761 service_impl.controller_delegate_ = nullptr;
762 service_impl.SetClient(std::move(client_ptr));
763 EXPECT_FALSE(callback.is_null());
764
765 // NO-OP for ControllerPresentationServiceDelegate API functions
766 EXPECT_CALL(mock_delegate_, ListenForConnectionMessages(_, _, _, _)).Times(0);
767
768 blink::mojom::PresentationSessionInfoPtr session(
769 blink::mojom::PresentationSessionInfo::New());
770 session->url = GURL(kPresentationUrl1);
771 session->id = kPresentationId;
772
773 service_impl.ListenForConnectionMessages(std::move(session));
774 }
775
669 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { 776 TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
670 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _)) 777 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _))
671 .Times(1); 778 .Times(1);
672 service_ptr_->StartSession(presentation_urls_, base::Bind(&DoNothing)); 779 service_ptr_->StartSession(presentation_urls_, base::Bind(&DoNothing));
673 780
674 // This request should fail immediately, since there is already a StartSession 781 // This request should fail immediately, since there is already a StartSession
675 // in progress. 782 // in progress.
676 service_ptr_->StartSession( 783 service_ptr_->StartSession(
677 presentation_urls_, 784 presentation_urls_,
678 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, 785 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 mock_delegate_.set_screen_availability_listening_supported(false); 972 mock_delegate_.set_screen_availability_listening_supported(false);
866 base::RunLoop run_loop; 973 base::RunLoop run_loop;
867 EXPECT_CALL(mock_client_, 974 EXPECT_CALL(mock_client_,
868 OnScreenAvailabilityNotSupported(presentation_url1_)) 975 OnScreenAvailabilityNotSupported(presentation_url1_))
869 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 976 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
870 ListenForScreenAvailabilityAndWait(presentation_url1_, false); 977 ListenForScreenAvailabilityAndWait(presentation_url1_, false);
871 run_loop.Run(); 978 run_loop.Run();
872 } 979 }
873 980
874 } // namespace content 981 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/presentation/presentation_service_impl.cc ('k') | content/public/browser/content_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698