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

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

Issue 2379703002: [Presentation API] (alternative) 1-UA: send message between controller and receiver page (Closed)
Patch Set: rebase with master and resolve merge conflicts Created 4 years, 2 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 const char kPresentationId[] = "presentationId"; 53 const char kPresentationId[] = "presentationId";
54 const char kPresentationUrl1[] = "http://foo.com/index.html"; 54 const char kPresentationUrl1[] = "http://foo.com/index.html";
55 const char kPresentationUrl2[] = "http://example.com/index.html"; 55 const char kPresentationUrl2[] = "http://example.com/index.html";
56 const char kPresentationUrl3[] = "http://example.net/index.html"; 56 const char kPresentationUrl3[] = "http://example.net/index.html";
57 57
58 void DoNothing(blink::mojom::PresentationSessionInfoPtr info, 58 void DoNothing(blink::mojom::PresentationSessionInfoPtr info,
59 blink::mojom::PresentationErrorPtr error) {} 59 blink::mojom::PresentationErrorPtr error) {}
60 60
61 } // namespace 61 } // namespace
62 62
63 class MockPresentationServiceDelegate : public PresentationServiceDelegate { 63 class MockPresentationServiceDelegate
64 : public ControllerPresentationServiceDelegate {
64 public: 65 public:
65 MOCK_METHOD3(AddObserver, 66 MOCK_METHOD3(AddObserver,
66 void(int render_process_id, 67 void(int render_process_id,
67 int render_frame_id, 68 int render_frame_id,
68 PresentationServiceDelegate::Observer* observer)); 69 PresentationServiceDelegateBase::Observer* observer));
69 MOCK_METHOD2(RemoveObserver, 70 MOCK_METHOD2(RemoveObserver,
70 void(int render_process_id, int render_frame_id)); 71 void(int render_process_id, int render_frame_id));
71 72
72 bool AddScreenAvailabilityListener( 73 bool AddScreenAvailabilityListener(
73 int render_process_id, 74 int render_process_id,
74 int routing_id, 75 int routing_id,
75 PresentationScreenAvailabilityListener* listener) override { 76 PresentationScreenAvailabilityListener* listener) override {
76 if (!screen_availability_listening_supported_) 77 if (!screen_availability_listening_supported_)
77 listener->OnScreenAvailabilityNotSupported(); 78 listener->OnScreenAvailabilityNotSupported();
78 79
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 SendMessageRawPtr(render_process_id, render_frame_id, session, 133 SendMessageRawPtr(render_process_id, render_frame_id, session,
133 message_request.release(), send_message_cb); 134 message_request.release(), send_message_cb);
134 } 135 }
135 MOCK_METHOD4(ListenForConnectionStateChange, 136 MOCK_METHOD4(ListenForConnectionStateChange,
136 void(int render_process_id, 137 void(int render_process_id,
137 int render_frame_id, 138 int render_frame_id,
138 const content::PresentationSessionInfo& connection, 139 const content::PresentationSessionInfo& connection,
139 const content::PresentationConnectionStateChangedCallback& 140 const content::PresentationConnectionStateChangedCallback&
140 state_changed_cb)); 141 state_changed_cb));
141 142
143 void RegisterOffscreenPresentationConnection(
144 int render_process_id,
145 int render_frame_id,
146 const PresentationSessionInfo& session,
147 PresentationConnectionPtr connection) override {
148 RegisterOffscreenPresentationConnectionRaw(
149 render_process_id, render_frame_id, session, connection.get());
150 }
151
152 MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw,
153 void(int render_process_id,
154 int render_frame_id,
155 const PresentationSessionInfo& session,
156 blink::mojom::PresentationConnection* connection));
157
142 void set_screen_availability_listening_supported(bool value) { 158 void set_screen_availability_listening_supported(bool value) {
143 screen_availability_listening_supported_ = value; 159 screen_availability_listening_supported_ = value;
144 } 160 }
145 161
146 private: 162 private:
147 bool screen_availability_listening_supported_ = true; 163 bool screen_availability_listening_supported_ = true;
148 }; 164 };
149 165
166 class MockReceiverPresentationServiceDelegate
167 : public ReceiverPresentationServiceDelegate {
168 public:
169 MOCK_METHOD3(AddObserver,
170 void(int render_process_id,
171 int render_frame_id,
172 PresentationServiceDelegateBase::Observer* observer));
173 MOCK_METHOD2(RemoveObserver,
174 void(int render_process_id, int render_frame_id));
175 MOCK_METHOD2(Reset, void(int render_process_id, int routing_id));
176 MOCK_METHOD1(RegisterReceiverAvailableCallback,
177 void(const content::ReceiverConnectionAvailableCallback&));
178 };
179
180 class MockPresentationConnection : public blink::mojom::PresentationConnection {
181 public:
182 void SetTargetConnection(
183 blink::mojom::PresentationConnectionPtr connection) override {
184 SetTargetConnection(*connection);
185 }
186 MOCK_METHOD1(SetTargetConnection,
187 void(blink::mojom::PresentationConnection& connection));
188
189 void OnConnectionMessageReceived(
190 blink::mojom::SessionMessagePtr message) override {
191 OnConnectionMessageReceived(*message);
192 }
193 MOCK_METHOD1(OnConnectionMessageReceived,
194 void(const blink::mojom::SessionMessage& message));
195 };
196
150 class MockPresentationServiceClient 197 class MockPresentationServiceClient
151 : public blink::mojom::PresentationServiceClient { 198 : public blink::mojom::PresentationServiceClient {
152 public: 199 public:
153 MOCK_METHOD2(OnScreenAvailabilityUpdated, 200 MOCK_METHOD2(OnScreenAvailabilityUpdated,
154 void(const GURL& url, bool available)); 201 void(const GURL& url, bool available));
155 void OnConnectionStateChanged( 202 void OnConnectionStateChanged(
156 blink::mojom::PresentationSessionInfoPtr connection, 203 blink::mojom::PresentationSessionInfoPtr connection,
157 blink::mojom::PresentationConnectionState new_state) override { 204 blink::mojom::PresentationConnectionState new_state) override {
158 OnConnectionStateChanged(*connection, new_state); 205 OnConnectionStateChanged(*connection, new_state);
159 } 206 }
(...skipping 23 matching lines...) Expand all
183 MOCK_METHOD0(MessagesReceived, void()); 230 MOCK_METHOD0(MessagesReceived, void());
184 231
185 void OnDefaultSessionStarted( 232 void OnDefaultSessionStarted(
186 blink::mojom::PresentationSessionInfoPtr session_info) override { 233 blink::mojom::PresentationSessionInfoPtr session_info) override {
187 OnDefaultSessionStarted(*session_info); 234 OnDefaultSessionStarted(*session_info);
188 } 235 }
189 MOCK_METHOD1(OnDefaultSessionStarted, 236 MOCK_METHOD1(OnDefaultSessionStarted,
190 void(const blink::mojom::PresentationSessionInfo& session_info)); 237 void(const blink::mojom::PresentationSessionInfo& session_info));
191 238
192 void OnReceiverConnectionAvailable( 239 void OnReceiverConnectionAvailable(
193 blink::mojom::PresentationSessionInfoPtr session_info) override { 240 blink::mojom::PresentationSessionInfoPtr session_info,
241 blink::mojom::PresentationConnectionPtr connection) override {
194 OnReceiverConnectionAvailable(*session_info); 242 OnReceiverConnectionAvailable(*session_info);
195 } 243 }
196 MOCK_METHOD1(OnReceiverConnectionAvailable, 244 MOCK_METHOD1(OnReceiverConnectionAvailable,
197 void(const blink::mojom::PresentationSessionInfo& session_info)); 245 void(const blink::mojom::PresentationSessionInfo& session_info));
198 246
199 std::vector<blink::mojom::SessionMessagePtr> messages_received_; 247 std::vector<blink::mojom::SessionMessagePtr> messages_received_;
200 }; 248 };
201 249
202 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { 250 class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
203 public: 251 public:
204 PresentationServiceImplTest() 252 PresentationServiceImplTest()
205 : presentation_url1_(GURL(kPresentationUrl1)), 253 : presentation_url1_(GURL(kPresentationUrl1)),
206 presentation_url2_(GURL(kPresentationUrl2)), 254 presentation_url2_(GURL(kPresentationUrl2)),
207 presentation_url3_(GURL(kPresentationUrl3)) {} 255 presentation_url3_(GURL(kPresentationUrl3)) {}
208 256
209 void SetUp() override { 257 void SetUp() override {
210 RenderViewHostImplTestHarness::SetUp(); 258 RenderViewHostImplTestHarness::SetUp();
211 259
212 auto request = mojo::GetProxy(&service_ptr_); 260 auto request = mojo::GetProxy(&service_ptr_);
213 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1); 261 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1);
214 TestRenderFrameHost* render_frame_host = contents()->GetMainFrame(); 262 TestRenderFrameHost* render_frame_host = contents()->GetMainFrame();
215 render_frame_host->InitializeRenderFrameIfNeeded(); 263 render_frame_host->InitializeRenderFrameIfNeeded();
216 service_impl_.reset(new PresentationServiceImpl( 264 service_impl_.reset(new PresentationServiceImpl(
217 render_frame_host, contents(), &mock_delegate_)); 265 render_frame_host, contents(), &mock_delegate_, nullptr));
218 service_impl_->Bind(std::move(request)); 266 service_impl_->Bind(std::move(request));
219 267
220 blink::mojom::PresentationServiceClientPtr client_ptr; 268 blink::mojom::PresentationServiceClientPtr client_ptr;
221 client_binding_.reset( 269 client_binding_.reset(
222 new mojo::Binding<blink::mojom::PresentationServiceClient>( 270 new mojo::Binding<blink::mojom::PresentationServiceClient>(
223 &mock_client_, mojo::GetProxy(&client_ptr))); 271 &mock_client_, mojo::GetProxy(&client_ptr)));
224 service_impl_->SetClient(std::move(client_ptr)); 272 service_impl_->SetClient(std::move(client_ptr));
225 273
226 presentation_urls_.push_back(presentation_url1_); 274 presentation_urls_.push_back(presentation_url1_);
227 presentation_urls_.push_back(presentation_url2_); 275 presentation_urls_.push_back(presentation_url2_);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 base::RunLoop run_loop; 415 base::RunLoop run_loop;
368 EXPECT_CALL(mock_client_, MessagesReceived()) 416 EXPECT_CALL(mock_client_, MessagesReceived())
369 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 417 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
370 message_cb.Run(std::move(messages), pass_ownership); 418 message_cb.Run(std::move(messages), pass_ownership);
371 run_loop.Run(); 419 run_loop.Run();
372 } 420 }
373 ExpectSessionMessages(expected_msgs, mock_client_.messages_received_); 421 ExpectSessionMessages(expected_msgs, mock_client_.messages_received_);
374 } 422 }
375 423
376 MockPresentationServiceDelegate mock_delegate_; 424 MockPresentationServiceDelegate mock_delegate_;
425 MockReceiverPresentationServiceDelegate mock_receiver_delegate_;
377 426
378 std::unique_ptr<PresentationServiceImpl> service_impl_; 427 std::unique_ptr<PresentationServiceImpl> service_impl_;
379 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_; 428 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_;
380 429
381 MockPresentationServiceClient mock_client_; 430 MockPresentationServiceClient mock_client_;
382 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>> 431 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>>
383 client_binding_; 432 client_binding_;
384 433
385 base::Closure run_loop_quit_closure_; 434 base::Closure run_loop_quit_closure_;
386 435
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 std::vector<uint8_t> binary_data(3, '\1'); 703 std::vector<uint8_t> binary_data(3, '\1');
655 RunListenForSessionMessages(text_msg, binary_data, false); 704 RunListenForSessionMessages(text_msg, binary_data, false);
656 } 705 }
657 706
658 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) { 707 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) {
659 std::string text_msg(""); 708 std::string text_msg("");
660 std::vector<uint8_t> binary_data; 709 std::vector<uint8_t> binary_data;
661 RunListenForSessionMessages(text_msg, binary_data, false); 710 RunListenForSessionMessages(text_msg, binary_data, false);
662 } 711 }
663 712
713 TEST_F(PresentationServiceImplTest, SetPresentationConnection) {
714 blink::mojom::PresentationSessionInfoPtr session(
715 blink::mojom::PresentationSessionInfo::New());
716 session->url = GURL(kPresentationUrl1);
717 session->id = kPresentationId;
718
719 blink::mojom::PresentationConnectionPtr connection;
720
721 MockPresentationConnection mock_presentation_connection;
722 mojo::Binding<blink::mojom::PresentationConnection> binding(
723 &mock_presentation_connection, mojo::GetProxy(&connection));
724
725 EXPECT_CALL(mock_delegate_,
726 RegisterOffscreenPresentationConnectionRaw(_, _, _, _))
727 .Times(1);
728
729 service_impl_->SetPresentationConnection(std::move(session),
730 std::move(connection));
731 }
732
733 TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) {
734 MockReceiverPresentationServiceDelegate mock_receiver_delegate;
735
736 PresentationServiceImpl service_impl(contents()->GetMainFrame(), contents(),
737 &mock_delegate_,
738 &mock_receiver_delegate);
739
740 EXPECT_CALL(mock_receiver_delegate, RegisterReceiverAvailableCallback(_));
741
742 blink::mojom::PresentationServiceClientPtr client_ptr;
743 client_binding_.reset(
744 new mojo::Binding<blink::mojom::PresentationServiceClient>(
745 &mock_client_, mojo::GetProxy(&client_ptr)));
746 service_impl.SetClient(std::move(client_ptr));
747
748 // NO-OP for ControllerPresentationServiceDelegate API functions
749 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _)).Times(0);
750
751 blink::mojom::PresentationSessionInfoPtr session(
752 blink::mojom::PresentationSessionInfo::New());
753 session->url = GURL(kPresentationUrl1);
754 session->id = kPresentationId;
755
756 service_impl.ListenForSessionMessages(std::move(session));
757 }
758
664 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { 759 TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
665 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _)) 760 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _))
666 .Times(1); 761 .Times(1);
667 service_ptr_->StartSession(presentation_urls_, base::Bind(&DoNothing)); 762 service_ptr_->StartSession(presentation_urls_, base::Bind(&DoNothing));
668 763
669 // This request should fail immediately, since there is already a StartSession 764 // This request should fail immediately, since there is already a StartSession
670 // in progress. 765 // in progress.
671 service_ptr_->StartSession( 766 service_ptr_->StartSession(
672 presentation_urls_, 767 presentation_urls_,
673 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, 768 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 mock_delegate_.set_screen_availability_listening_supported(false); 947 mock_delegate_.set_screen_availability_listening_supported(false);
853 base::RunLoop run_loop; 948 base::RunLoop run_loop;
854 EXPECT_CALL(mock_client_, 949 EXPECT_CALL(mock_client_,
855 OnScreenAvailabilityNotSupported(presentation_url1_)) 950 OnScreenAvailabilityNotSupported(presentation_url1_))
856 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 951 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
857 ListenForScreenAvailabilityAndWait(presentation_url1_, false); 952 ListenForScreenAvailabilityAndWait(presentation_url1_, false);
858 run_loop.Run(); 953 run_loop.Run();
859 } 954 }
860 955
861 } // namespace content 956 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698