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

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: 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 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 ConnectToOffscreenPresentation(
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(RegisterReceiverConnectionAvailableCallback,
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 OnMessage(blink::mojom::SessionMessagePtr message) override {
190 OnConnectionMessageReceived(*message);
191 }
192 MOCK_METHOD1(OnConnectionMessageReceived,
193 void(const blink::mojom::SessionMessage& message));
194 };
195
150 class MockPresentationServiceClient 196 class MockPresentationServiceClient
151 : public blink::mojom::PresentationServiceClient { 197 : public blink::mojom::PresentationServiceClient {
152 public: 198 public:
153 MOCK_METHOD2(OnScreenAvailabilityUpdated, 199 MOCK_METHOD2(OnScreenAvailabilityUpdated,
154 void(const GURL& url, bool available)); 200 void(const GURL& url, bool available));
155 void OnConnectionStateChanged( 201 void OnConnectionStateChanged(
156 blink::mojom::PresentationSessionInfoPtr connection, 202 blink::mojom::PresentationSessionInfoPtr connection,
157 blink::mojom::PresentationConnectionState new_state) override { 203 blink::mojom::PresentationConnectionState new_state) override {
158 OnConnectionStateChanged(*connection, new_state); 204 OnConnectionStateChanged(*connection, new_state);
159 } 205 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 presentation_url3_(GURL(kPresentationUrl3)) {} 253 presentation_url3_(GURL(kPresentationUrl3)) {}
208 254
209 void SetUp() override { 255 void SetUp() override {
210 RenderViewHostImplTestHarness::SetUp(); 256 RenderViewHostImplTestHarness::SetUp();
211 257
212 auto request = mojo::GetProxy(&service_ptr_); 258 auto request = mojo::GetProxy(&service_ptr_);
213 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1); 259 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1);
214 TestRenderFrameHost* render_frame_host = contents()->GetMainFrame(); 260 TestRenderFrameHost* render_frame_host = contents()->GetMainFrame();
215 render_frame_host->InitializeRenderFrameIfNeeded(); 261 render_frame_host->InitializeRenderFrameIfNeeded();
216 service_impl_.reset(new PresentationServiceImpl( 262 service_impl_.reset(new PresentationServiceImpl(
217 render_frame_host, contents(), &mock_delegate_)); 263 render_frame_host, contents(), &mock_delegate_, nullptr));
218 service_impl_->Bind(std::move(request)); 264 service_impl_->Bind(std::move(request));
219 265
220 blink::mojom::PresentationServiceClientPtr client_ptr; 266 blink::mojom::PresentationServiceClientPtr client_ptr;
221 client_binding_.reset( 267 client_binding_.reset(
222 new mojo::Binding<blink::mojom::PresentationServiceClient>( 268 new mojo::Binding<blink::mojom::PresentationServiceClient>(
223 &mock_client_, mojo::GetProxy(&client_ptr))); 269 &mock_client_, mojo::GetProxy(&client_ptr)));
224 service_impl_->SetClient(std::move(client_ptr)); 270 service_impl_->SetClient(std::move(client_ptr));
225 271
226 presentation_urls_.push_back(presentation_url1_); 272 presentation_urls_.push_back(presentation_url1_);
227 presentation_urls_.push_back(presentation_url2_); 273 presentation_urls_.push_back(presentation_url2_);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 base::RunLoop run_loop; 413 base::RunLoop run_loop;
368 EXPECT_CALL(mock_client_, MessagesReceived()) 414 EXPECT_CALL(mock_client_, MessagesReceived())
369 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 415 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
370 message_cb.Run(std::move(messages), pass_ownership); 416 message_cb.Run(std::move(messages), pass_ownership);
371 run_loop.Run(); 417 run_loop.Run();
372 } 418 }
373 ExpectSessionMessages(expected_msgs, mock_client_.messages_received_); 419 ExpectSessionMessages(expected_msgs, mock_client_.messages_received_);
374 } 420 }
375 421
376 MockPresentationServiceDelegate mock_delegate_; 422 MockPresentationServiceDelegate mock_delegate_;
423 MockReceiverPresentationServiceDelegate mock_receiver_delegate_;
377 424
378 std::unique_ptr<PresentationServiceImpl> service_impl_; 425 std::unique_ptr<PresentationServiceImpl> service_impl_;
379 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_; 426 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_;
380 427
381 MockPresentationServiceClient mock_client_; 428 MockPresentationServiceClient mock_client_;
382 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>> 429 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>>
383 client_binding_; 430 client_binding_;
384 431
385 base::Closure run_loop_quit_closure_; 432 base::Closure run_loop_quit_closure_;
386 433
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 std::vector<uint8_t> binary_data(3, '\1'); 701 std::vector<uint8_t> binary_data(3, '\1');
655 RunListenForSessionMessages(text_msg, binary_data, false); 702 RunListenForSessionMessages(text_msg, binary_data, false);
656 } 703 }
657 704
658 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) { 705 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) {
659 std::string text_msg(""); 706 std::string text_msg("");
660 std::vector<uint8_t> binary_data; 707 std::vector<uint8_t> binary_data;
661 RunListenForSessionMessages(text_msg, binary_data, false); 708 RunListenForSessionMessages(text_msg, binary_data, false);
662 } 709 }
663 710
711 TEST_F(PresentationServiceImplTest, SetPresentationConnection) {
712 blink::mojom::PresentationSessionInfoPtr session(
713 blink::mojom::PresentationSessionInfo::New());
714 session->url = GURL(kPresentationUrl1);
715 session->id = kPresentationId;
716
717 blink::mojom::PresentationConnectionPtr connection;
718
719 MockPresentationConnection mock_presentation_connection;
720 mojo::Binding<blink::mojom::PresentationConnection> binding(
721 &mock_presentation_connection, mojo::GetProxy(&connection));
722
723 EXPECT_CALL(mock_delegate_,
724 RegisterOffscreenPresentationConnectionRaw(_, _, _, _))
mark a. foltz 2016/11/08 23:40:52 Can you verify the contents of |session| here?
zhaobin 2016/11/10 04:14:00 Done.
725 .Times(1);
726
727 service_impl_->SetPresentationConnection(std::move(session),
728 std::move(connection));
729 }
730
731 TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) {
732 MockReceiverPresentationServiceDelegate mock_receiver_delegate;
733
734 PresentationServiceImpl service_impl(contents()->GetMainFrame(), contents(),
735 &mock_delegate_,
mark a. foltz 2016/11/08 23:40:52 Should the controller delegate be nullptr here?
zhaobin 2016/11/10 04:14:00 Done.
736 &mock_receiver_delegate);
737
738 EXPECT_CALL(mock_receiver_delegate,
739 RegisterReceiverConnectionAvailableCallback(_));
mark a. foltz 2016/11/08 23:40:52 Nit: verify that the callback registered is not nu
zhaobin 2016/11/10 04:14:00 Done.
740
741 blink::mojom::PresentationServiceClientPtr client_ptr;
742 client_binding_.reset(
743 new mojo::Binding<blink::mojom::PresentationServiceClient>(
744 &mock_client_, mojo::GetProxy(&client_ptr)));
745 // If receiver_delegate_ != nullptr, set controller_delegate = nullptr in
746 // CreateMojoService().
747 service_impl.controller_delegate_ = nullptr;
748 service_impl.SetClient(std::move(client_ptr));
749
750 // NO-OP for ControllerPresentationServiceDelegate API functions
751 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _)).Times(0);
752
753 blink::mojom::PresentationSessionInfoPtr session(
754 blink::mojom::PresentationSessionInfo::New());
755 session->url = GURL(kPresentationUrl1);
756 session->id = kPresentationId;
757
758 service_impl.ListenForSessionMessages(std::move(session));
759 }
760
664 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { 761 TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
665 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _)) 762 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _))
666 .Times(1); 763 .Times(1);
667 service_ptr_->StartSession(presentation_urls_, base::Bind(&DoNothing)); 764 service_ptr_->StartSession(presentation_urls_, base::Bind(&DoNothing));
668 765
669 // This request should fail immediately, since there is already a StartSession 766 // This request should fail immediately, since there is already a StartSession
670 // in progress. 767 // in progress.
671 service_ptr_->StartSession( 768 service_ptr_->StartSession(
672 presentation_urls_, 769 presentation_urls_,
673 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, 770 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); 949 mock_delegate_.set_screen_availability_listening_supported(false);
853 base::RunLoop run_loop; 950 base::RunLoop run_loop;
854 EXPECT_CALL(mock_client_, 951 EXPECT_CALL(mock_client_,
855 OnScreenAvailabilityNotSupported(presentation_url1_)) 952 OnScreenAvailabilityNotSupported(presentation_url1_))
856 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 953 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
857 ListenForScreenAvailabilityAndWait(presentation_url1_, false); 954 ListenForScreenAvailabilityAndWait(presentation_url1_, false);
858 run_loop.Run(); 955 run_loop.Run();
859 } 956 }
860 957
861 } // namespace content 958 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698