OLD | NEW |
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 const SendMessageCallback& send_message_cb) override { | 132 const SendMessageCallback& send_message_cb) override { |
133 SendMessageRawPtr(render_process_id, render_frame_id, session, | 133 SendMessageRawPtr(render_process_id, render_frame_id, session, |
134 message_request.release(), send_message_cb); | 134 message_request.release(), send_message_cb); |
135 } | 135 } |
136 MOCK_METHOD4(ListenForConnectionStateChange, | 136 MOCK_METHOD4(ListenForConnectionStateChange, |
137 void(int render_process_id, | 137 void(int render_process_id, |
138 int render_frame_id, | 138 int render_frame_id, |
139 const content::PresentationSessionInfo& connection, | 139 const content::PresentationSessionInfo& connection, |
140 const content::PresentationConnectionStateChangedCallback& | 140 const content::PresentationConnectionStateChangedCallback& |
141 state_changed_cb)); | 141 state_changed_cb)); |
| 142 MOCK_METHOD3( |
| 143 GetReceiverConnections, |
| 144 std::vector<content::PresentationSessionInfo>( |
| 145 int render_process_id, |
| 146 int render_frame_id, |
| 147 const content::PresentationSessionStartedCallback& callback)); |
142 | 148 |
143 void set_screen_availability_listening_supported(bool value) { | 149 void set_screen_availability_listening_supported(bool value) { |
144 screen_availability_listening_supported_ = value; | 150 screen_availability_listening_supported_ = value; |
145 } | 151 } |
146 | 152 |
147 private: | 153 private: |
148 bool screen_availability_listening_supported_ = true; | 154 bool screen_availability_listening_supported_ = true; |
149 }; | 155 }; |
150 | 156 |
151 class MockPresentationServiceClient | 157 class MockPresentationServiceClient |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 189 } |
184 MOCK_METHOD0(MessagesReceived, void()); | 190 MOCK_METHOD0(MessagesReceived, void()); |
185 | 191 |
186 void OnDefaultSessionStarted( | 192 void OnDefaultSessionStarted( |
187 blink::mojom::PresentationSessionInfoPtr session_info) override { | 193 blink::mojom::PresentationSessionInfoPtr session_info) override { |
188 OnDefaultSessionStarted(*session_info); | 194 OnDefaultSessionStarted(*session_info); |
189 } | 195 } |
190 MOCK_METHOD1(OnDefaultSessionStarted, | 196 MOCK_METHOD1(OnDefaultSessionStarted, |
191 void(const blink::mojom::PresentationSessionInfo& session_info)); | 197 void(const blink::mojom::PresentationSessionInfo& session_info)); |
192 | 198 |
| 199 void OnReceiverConnectionAvailable( |
| 200 blink::mojom::PresentationSessionInfoPtr connection) { |
| 201 OnReceiverConnectionAvailable(*connection); |
| 202 } |
| 203 MOCK_METHOD1(OnReceiverConnectionAvailable, |
| 204 void(const blink::mojom::PresentationSessionInfo& connection)); |
| 205 |
193 mojo::Array<blink::mojom::SessionMessagePtr> messages_received_; | 206 mojo::Array<blink::mojom::SessionMessagePtr> messages_received_; |
194 }; | 207 }; |
195 | 208 |
196 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { | 209 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
197 public: | 210 public: |
198 PresentationServiceImplTest() {} | 211 PresentationServiceImplTest() {} |
199 | 212 |
200 void SetUp() override { | 213 void SetUp() override { |
201 RenderViewHostImplTestHarness::SetUp(); | 214 RenderViewHostImplTestHarness::SetUp(); |
202 | 215 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 void SaveQuitClosureAndRunLoop() { | 264 void SaveQuitClosureAndRunLoop() { |
252 base::RunLoop run_loop; | 265 base::RunLoop run_loop; |
253 run_loop_quit_closure_ = run_loop.QuitClosure(); | 266 run_loop_quit_closure_ = run_loop.QuitClosure(); |
254 run_loop.Run(); | 267 run_loop.Run(); |
255 run_loop_quit_closure_.Reset(); | 268 run_loop_quit_closure_.Reset(); |
256 } | 269 } |
257 | 270 |
258 void SimulateScreenAvailabilityChangeAndWait( | 271 void SimulateScreenAvailabilityChangeAndWait( |
259 const std::string& url, bool available) { | 272 const std::string& url, bool available) { |
260 auto listener_it = service_impl_->screen_availability_listeners_.find(url); | 273 auto listener_it = service_impl_->screen_availability_listeners_.find(url); |
| 274 ASSERT_TRUE(listener_it != |
| 275 service_impl_->screen_availability_listeners_.end()); |
261 ASSERT_TRUE(listener_it->second); | 276 ASSERT_TRUE(listener_it->second); |
262 | 277 |
263 base::RunLoop run_loop; | 278 base::RunLoop run_loop; |
264 EXPECT_CALL(mock_client_, | 279 EXPECT_CALL(mock_client_, |
265 OnScreenAvailabilityUpdated(mojo::String(url), available)) | 280 OnScreenAvailabilityUpdated(mojo::String(url), available)) |
266 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 281 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
267 listener_it->second->OnScreenAvailabilityChanged(available); | 282 listener_it->second->OnScreenAvailabilityChanged(available); |
268 run_loop.Run(); | 283 run_loop.Run(); |
269 } | 284 } |
270 | 285 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 323 } |
309 } | 324 } |
310 | 325 |
311 void ExpectSendMessageMojoCallback(bool success) { | 326 void ExpectSendMessageMojoCallback(bool success) { |
312 EXPECT_TRUE(success); | 327 EXPECT_TRUE(success); |
313 EXPECT_FALSE(service_impl_->send_message_callback_); | 328 EXPECT_FALSE(service_impl_->send_message_callback_); |
314 if (!run_loop_quit_closure_.is_null()) | 329 if (!run_loop_quit_closure_.is_null()) |
315 run_loop_quit_closure_.Run(); | 330 run_loop_quit_closure_.Run(); |
316 } | 331 } |
317 | 332 |
| 333 void ExpectReceiverConnections( |
| 334 size_t expected_num_connections, |
| 335 mojo::Array<blink::mojom::PresentationSessionInfoPtr> connections) { |
| 336 EXPECT_EQ(expected_num_connections, connections.size()); |
| 337 if (!run_loop_quit_closure_.is_null()) |
| 338 run_loop_quit_closure_.Run(); |
| 339 } |
| 340 |
318 void RunListenForSessionMessages(const std::string& text_msg, | 341 void RunListenForSessionMessages(const std::string& text_msg, |
319 const std::vector<uint8_t>& binary_data, | 342 const std::vector<uint8_t>& binary_data, |
320 bool pass_ownership) { | 343 bool pass_ownership) { |
321 mojo::Array<blink::mojom::SessionMessagePtr> expected_msgs(2); | 344 mojo::Array<blink::mojom::SessionMessagePtr> expected_msgs(2); |
322 expected_msgs[0] = blink::mojom::SessionMessage::New(); | 345 expected_msgs[0] = blink::mojom::SessionMessage::New(); |
323 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT; | 346 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT; |
324 expected_msgs[0]->message = text_msg; | 347 expected_msgs[0]->message = text_msg; |
325 expected_msgs[1] = blink::mojom::SessionMessage::New(); | 348 expected_msgs[1] = blink::mojom::SessionMessage::New(); |
326 expected_msgs[1]->type = | 349 expected_msgs[1]->type = |
327 blink::mojom::PresentationMessageType::ARRAY_BUFFER; | 350 blink::mojom::PresentationMessageType::ARRAY_BUFFER; |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { | 872 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { |
850 mock_delegate_.set_screen_availability_listening_supported(false); | 873 mock_delegate_.set_screen_availability_listening_supported(false); |
851 base::RunLoop run_loop; | 874 base::RunLoop run_loop; |
852 EXPECT_CALL(mock_client_, | 875 EXPECT_CALL(mock_client_, |
853 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))) | 876 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))) |
854 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 877 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
855 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); | 878 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); |
856 run_loop.Run(); | 879 run_loop.Run(); |
857 } | 880 } |
858 | 881 |
| 882 TEST_F(PresentationServiceImplTest, GetReceiverConnections) { |
| 883 std::vector<content::PresentationSessionInfo> connections; |
| 884 content::PresentationSessionInfo connection("", kPresentationId); |
| 885 connections.push_back(connection); |
| 886 EXPECT_CALL(mock_delegate_, GetReceiverConnections(_, _, _)) |
| 887 .WillOnce(Return(connections)); |
| 888 service_ptr_->GetReceiverConnections( |
| 889 base::Bind(&PresentationServiceImplTest::ExpectReceiverConnections, |
| 890 base::Unretained(this), 1)); |
| 891 SaveQuitClosureAndRunLoop(); |
| 892 } |
| 893 |
859 } // namespace content | 894 } // namespace content |
OLD | NEW |