| 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 <iterator> |
| 10 #include <memory> | 11 #include <memory> |
| 11 #include <string> | 12 #include <string> |
| 12 #include <utility> | 13 #include <utility> |
| 13 #include <vector> | 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/location.h" | 16 #include "base/location.h" |
| 16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 18 #include "base/test/test_timeouts.h" | 19 #include "base/test/test_timeouts.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "content/public/browser/navigation_handle.h" | 21 #include "content/public/browser/navigation_handle.h" |
| 21 #include "content/public/browser/presentation_service_delegate.h" | 22 #include "content/public/browser/presentation_service_delegate.h" |
| 22 #include "content/public/common/presentation_constants.h" | 23 #include "content/public/common/presentation_connection_message.h" |
| 23 #include "content/public/common/presentation_session.h" | 24 #include "content/public/common/presentation_session.h" |
| 24 #include "content/test/test_render_frame_host.h" | 25 #include "content/test/test_render_frame_host.h" |
| 25 #include "content/test/test_render_view_host.h" | 26 #include "content/test/test_render_view_host.h" |
| 26 #include "content/test/test_web_contents.h" | 27 #include "content/test/test_web_contents.h" |
| 27 #include "mojo/public/cpp/bindings/interface_ptr.h" | 28 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 29 | 30 |
| 30 using ::testing::_; | 31 using ::testing::_; |
| 32 using ::testing::ByRef; |
| 31 using ::testing::Eq; | 33 using ::testing::Eq; |
| 34 using ::testing::Invoke; |
| 32 using ::testing::InvokeWithoutArgs; | 35 using ::testing::InvokeWithoutArgs; |
| 33 using ::testing::Mock; | 36 using ::testing::Mock; |
| 34 using ::testing::Return; | 37 using ::testing::Return; |
| 35 using ::testing::SaveArg; | 38 using ::testing::SaveArg; |
| 39 using ::testing::WithArgs; |
| 36 | 40 |
| 37 namespace content { | 41 namespace content { |
| 38 | 42 |
| 39 namespace { | 43 namespace { |
| 40 | 44 |
| 41 // Matches Mojo structs. | |
| 42 MATCHER_P(Equals, expected, "") { | |
| 43 return expected.Equals(arg); | |
| 44 } | |
| 45 | |
| 46 // Matches content::PresentationSessionInfo. | 45 // Matches content::PresentationSessionInfo. |
| 47 MATCHER_P(SessionInfoEquals, expected, "") { | 46 MATCHER_P(SessionInfoEquals, expected, "") { |
| 48 return expected.presentation_url == arg.presentation_url && | 47 return expected.presentation_url == arg.presentation_url && |
| 49 expected.presentation_id == arg.presentation_id; | 48 expected.presentation_id == arg.presentation_id; |
| 50 } | 49 } |
| 51 | 50 |
| 52 const char kPresentationId[] = "presentationId"; | 51 const char kPresentationId[] = "presentationId"; |
| 53 const char kPresentationUrl1[] = "http://foo.com/index.html"; | 52 const char kPresentationUrl1[] = "http://foo.com/index.html"; |
| 54 const char kPresentationUrl2[] = "http://example.com/index.html"; | 53 const char kPresentationUrl2[] = "http://example.com/index.html"; |
| 55 const char kPresentationUrl3[] = "http://example.net/index.html"; | 54 const char kPresentationUrl3[] = "http://example.net/index.html"; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 void(int render_process_id, | 108 void(int render_process_id, |
| 110 int render_frame_id, | 109 int render_frame_id, |
| 111 const std::string& presentation_id)); | 110 const std::string& presentation_id)); |
| 112 MOCK_METHOD3(Terminate, | 111 MOCK_METHOD3(Terminate, |
| 113 void(int render_process_id, | 112 void(int render_process_id, |
| 114 int render_frame_id, | 113 int render_frame_id, |
| 115 const std::string& presentation_id)); | 114 const std::string& presentation_id)); |
| 116 MOCK_METHOD4(ListenForConnectionMessages, | 115 MOCK_METHOD4(ListenForConnectionMessages, |
| 117 void(int render_process_id, | 116 void(int render_process_id, |
| 118 int render_frame_id, | 117 int render_frame_id, |
| 119 const content::PresentationSessionInfo& session, | 118 const PresentationSessionInfo& session, |
| 120 const PresentationConnectionMessageCallback& message_cb)); | 119 const PresentationConnectionMessageCallback& message_cb)); |
| 121 MOCK_METHOD5(SendMessageRawPtr, | 120 MOCK_METHOD5(SendMessage, |
| 122 void(int render_process_id, | 121 void(int render_process_id, |
| 123 int render_frame_id, | 122 int render_frame_id, |
| 124 const content::PresentationSessionInfo& session, | 123 const PresentationSessionInfo& session, |
| 125 PresentationConnectionMessage* message_request, | 124 const PresentationConnectionMessage& message_request, |
| 126 const SendMessageCallback& send_message_cb)); | 125 const SendMessageCallback& send_message_cb)); |
| 127 void SendMessage( | 126 MOCK_METHOD4( |
| 128 int render_process_id, | 127 ListenForConnectionStateChange, |
| 129 int render_frame_id, | 128 void(int render_process_id, |
| 130 const content::PresentationSessionInfo& session, | 129 int render_frame_id, |
| 131 std::unique_ptr<PresentationConnectionMessage> message_request, | 130 const PresentationSessionInfo& connection, |
| 132 const SendMessageCallback& send_message_cb) override { | 131 const PresentationConnectionStateChangedCallback& state_changed_cb)); |
| 133 SendMessageRawPtr(render_process_id, render_frame_id, session, | |
| 134 message_request.release(), send_message_cb); | |
| 135 } | |
| 136 MOCK_METHOD4(ListenForConnectionStateChange, | |
| 137 void(int render_process_id, | |
| 138 int render_frame_id, | |
| 139 const content::PresentationSessionInfo& connection, | |
| 140 const content::PresentationConnectionStateChangedCallback& | |
| 141 state_changed_cb)); | |
| 142 | 132 |
| 143 void ConnectToPresentation( | 133 void ConnectToPresentation( |
| 144 int render_process_id, | 134 int render_process_id, |
| 145 int render_frame_id, | 135 int render_frame_id, |
| 146 const content::PresentationSessionInfo& session, | 136 const PresentationSessionInfo& session, |
| 147 PresentationConnectionPtr controller_conn_ptr, | 137 PresentationConnectionPtr controller_conn_ptr, |
| 148 PresentationConnectionRequest receiver_conn_request) override { | 138 PresentationConnectionRequest receiver_conn_request) override { |
| 149 RegisterOffscreenPresentationConnectionRaw( | 139 RegisterOffscreenPresentationConnectionRaw( |
| 150 render_process_id, render_frame_id, session, controller_conn_ptr.get()); | 140 render_process_id, render_frame_id, session, controller_conn_ptr.get()); |
| 151 } | 141 } |
| 152 | 142 |
| 153 MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw, | 143 MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw, |
| 154 void(int render_process_id, | 144 void(int render_process_id, |
| 155 int render_frame_id, | 145 int render_frame_id, |
| 156 const content::PresentationSessionInfo& session, | 146 const PresentationSessionInfo& session, |
| 157 blink::mojom::PresentationConnection* connection)); | 147 blink::mojom::PresentationConnection* connection)); |
| 158 | 148 |
| 159 void set_screen_availability_listening_supported(bool value) { | 149 void set_screen_availability_listening_supported(bool value) { |
| 160 screen_availability_listening_supported_ = value; | 150 screen_availability_listening_supported_ = value; |
| 161 } | 151 } |
| 162 | 152 |
| 163 private: | 153 private: |
| 164 bool screen_availability_listening_supported_ = true; | 154 bool screen_availability_listening_supported_ = true; |
| 165 }; | 155 }; |
| 166 | 156 |
| 167 class MockReceiverPresentationServiceDelegate | 157 class MockReceiverPresentationServiceDelegate |
| 168 : public ReceiverPresentationServiceDelegate { | 158 : public ReceiverPresentationServiceDelegate { |
| 169 public: | 159 public: |
| 170 MOCK_METHOD3(AddObserver, | 160 MOCK_METHOD3(AddObserver, |
| 171 void(int render_process_id, | 161 void(int render_process_id, |
| 172 int render_frame_id, | 162 int render_frame_id, |
| 173 PresentationServiceDelegate::Observer* observer)); | 163 PresentationServiceDelegate::Observer* observer)); |
| 174 MOCK_METHOD2(RemoveObserver, | 164 MOCK_METHOD2(RemoveObserver, |
| 175 void(int render_process_id, int render_frame_id)); | 165 void(int render_process_id, int render_frame_id)); |
| 176 MOCK_METHOD2(Reset, void(int render_process_id, int routing_id)); | 166 MOCK_METHOD2(Reset, void(int render_process_id, int routing_id)); |
| 177 MOCK_METHOD1(RegisterReceiverConnectionAvailableCallback, | 167 MOCK_METHOD1(RegisterReceiverConnectionAvailableCallback, |
| 178 void(const content::ReceiverConnectionAvailableCallback&)); | 168 void(const ReceiverConnectionAvailableCallback&)); |
| 179 }; | 169 }; |
| 180 | 170 |
| 181 class MockPresentationConnection : public blink::mojom::PresentationConnection { | 171 class MockPresentationConnection : public blink::mojom::PresentationConnection { |
| 182 public: | 172 public: |
| 183 void OnMessage(blink::mojom::ConnectionMessagePtr message, | 173 MOCK_METHOD2(OnMessage, |
| 184 const base::Callback<void(bool)>& send_message_cb) override { | 174 void(const PresentationConnectionMessage& message, |
| 185 OnConnectionMessageReceived(*message); | 175 const base::Callback<void(bool)>& send_message_cb)); |
| 186 } | |
| 187 MOCK_METHOD1(OnConnectionMessageReceived, | |
| 188 void(const blink::mojom::ConnectionMessage& message)); | |
| 189 MOCK_METHOD1(DidChangeState, void(PresentationConnectionState state)); | 176 MOCK_METHOD1(DidChangeState, void(PresentationConnectionState state)); |
| 190 }; | 177 }; |
| 191 | 178 |
| 192 class MockPresentationServiceClient | 179 class MockPresentationServiceClient |
| 193 : public blink::mojom::PresentationServiceClient { | 180 : public blink::mojom::PresentationServiceClient { |
| 194 public: | 181 public: |
| 195 MOCK_METHOD2(OnScreenAvailabilityUpdated, | 182 MOCK_METHOD2(OnScreenAvailabilityUpdated, |
| 196 void(const GURL& url, bool available)); | 183 void(const GURL& url, bool available)); |
| 197 MOCK_METHOD2(OnConnectionStateChanged, | 184 MOCK_METHOD2(OnConnectionStateChanged, |
| 198 void(const content::PresentationSessionInfo& connection, | 185 void(const PresentationSessionInfo& connection, |
| 199 PresentationConnectionState new_state)); | 186 PresentationConnectionState new_state)); |
| 200 MOCK_METHOD3(OnConnectionClosed, | 187 MOCK_METHOD3(OnConnectionClosed, |
| 201 void(const content::PresentationSessionInfo& connection, | 188 void(const PresentationSessionInfo& connection, |
| 202 PresentationConnectionCloseReason reason, | 189 PresentationConnectionCloseReason reason, |
| 203 const std::string& message)); | 190 const std::string& message)); |
| 204 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const GURL& url)); | 191 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const GURL& url)); |
| 205 | 192 MOCK_METHOD2( |
| 206 void OnConnectionMessagesReceived( | 193 OnConnectionMessagesReceived, |
| 207 const content::PresentationSessionInfo& session_info, | 194 void(const PresentationSessionInfo& session_info, |
| 208 std::vector<blink::mojom::ConnectionMessagePtr> messages) override { | 195 const std::vector<PresentationConnectionMessage>& messages)); |
| 209 messages_received_ = std::move(messages); | |
| 210 MessagesReceived(); | |
| 211 } | |
| 212 MOCK_METHOD0(MessagesReceived, void()); | |
| 213 | |
| 214 MOCK_METHOD1(OnDefaultSessionStarted, | 196 MOCK_METHOD1(OnDefaultSessionStarted, |
| 215 void(const content::PresentationSessionInfo& session_info)); | 197 void(const PresentationSessionInfo& session_info)); |
| 216 | 198 |
| 217 void OnReceiverConnectionAvailable( | 199 void OnReceiverConnectionAvailable( |
| 218 const content::PresentationSessionInfo& session_info, | 200 const PresentationSessionInfo& session_info, |
| 219 blink::mojom::PresentationConnectionPtr controller_conn_ptr, | 201 blink::mojom::PresentationConnectionPtr controller_conn_ptr, |
| 220 blink::mojom::PresentationConnectionRequest receiver_conn_request) | 202 blink::mojom::PresentationConnectionRequest receiver_conn_request) |
| 221 override { | 203 override { |
| 222 OnReceiverConnectionAvailable(session_info); | 204 OnReceiverConnectionAvailable(session_info); |
| 223 } | 205 } |
| 224 MOCK_METHOD1(OnReceiverConnectionAvailable, | 206 MOCK_METHOD1(OnReceiverConnectionAvailable, |
| 225 void(const content::PresentationSessionInfo& session_info)); | 207 void(const PresentationSessionInfo& session_info)); |
| 226 | |
| 227 std::vector<blink::mojom::ConnectionMessagePtr> messages_received_; | |
| 228 }; | 208 }; |
| 229 | 209 |
| 230 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { | 210 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
| 231 public: | 211 public: |
| 232 PresentationServiceImplTest() | 212 PresentationServiceImplTest() |
| 233 : presentation_url1_(GURL(kPresentationUrl1)), | 213 : presentation_url1_(GURL(kPresentationUrl1)), |
| 234 presentation_url2_(GURL(kPresentationUrl2)), | 214 presentation_url2_(GURL(kPresentationUrl2)), |
| 235 presentation_url3_(GURL(kPresentationUrl3)) {} | 215 presentation_url3_(GURL(kPresentationUrl3)) {} |
| 236 | 216 |
| 237 void SetUp() override { | 217 void SetUp() override { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 261 void TearDown() override { | 241 void TearDown() override { |
| 262 service_ptr_.reset(); | 242 service_ptr_.reset(); |
| 263 if (service_impl_.get()) { | 243 if (service_impl_.get()) { |
| 264 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); | 244 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); |
| 265 service_impl_.reset(); | 245 service_impl_.reset(); |
| 266 } | 246 } |
| 267 RenderViewHostImplTestHarness::TearDown(); | 247 RenderViewHostImplTestHarness::TearDown(); |
| 268 } | 248 } |
| 269 | 249 |
| 270 void Navigate(bool main_frame) { | 250 void Navigate(bool main_frame) { |
| 271 content::RenderFrameHost* rfh = main_rfh(); | 251 RenderFrameHost* rfh = main_rfh(); |
| 272 content::RenderFrameHostTester* rfh_tester = | 252 RenderFrameHostTester* rfh_tester = RenderFrameHostTester::For(rfh); |
| 273 content::RenderFrameHostTester::For(rfh); | |
| 274 if (!main_frame) | 253 if (!main_frame) |
| 275 rfh = rfh_tester->AppendChild("subframe"); | 254 rfh = rfh_tester->AppendChild("subframe"); |
| 276 std::unique_ptr<NavigationHandle> navigation_handle = | 255 std::unique_ptr<NavigationHandle> navigation_handle = |
| 277 NavigationHandle::CreateNavigationHandleForTesting( | 256 NavigationHandle::CreateNavigationHandleForTesting( |
| 278 GURL(), rfh, true); | 257 GURL(), rfh, true); |
| 279 // Destructor calls DidFinishNavigation. | 258 // Destructor calls DidFinishNavigation. |
| 280 } | 259 } |
| 281 | 260 |
| 282 void ListenForScreenAvailabilityAndWait(const GURL& url, | 261 void ListenForScreenAvailabilityAndWait(const GURL& url, |
| 283 bool delegate_success) { | 262 bool delegate_success) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 } | 306 } |
| 328 | 307 |
| 329 void ExpectCleanState() { | 308 void ExpectCleanState() { |
| 330 EXPECT_TRUE(service_impl_->default_presentation_urls_.empty()); | 309 EXPECT_TRUE(service_impl_->default_presentation_urls_.empty()); |
| 331 EXPECT_EQ( | 310 EXPECT_EQ( |
| 332 service_impl_->screen_availability_listeners_.find(presentation_url1_), | 311 service_impl_->screen_availability_listeners_.find(presentation_url1_), |
| 333 service_impl_->screen_availability_listeners_.end()); | 312 service_impl_->screen_availability_listeners_.end()); |
| 334 } | 313 } |
| 335 | 314 |
| 336 void ExpectNewSessionCallbackSuccess( | 315 void ExpectNewSessionCallbackSuccess( |
| 337 const base::Optional<content::PresentationSessionInfo>& info, | 316 const base::Optional<PresentationSessionInfo>& info, |
| 338 const base::Optional<content::PresentationError>& error) { | 317 const base::Optional<PresentationError>& error) { |
| 339 EXPECT_TRUE(info); | 318 EXPECT_TRUE(info); |
| 340 EXPECT_FALSE(error); | 319 EXPECT_FALSE(error); |
| 341 if (!run_loop_quit_closure_.is_null()) | 320 if (!run_loop_quit_closure_.is_null()) |
| 342 run_loop_quit_closure_.Run(); | 321 run_loop_quit_closure_.Run(); |
| 343 } | 322 } |
| 344 | 323 |
| 345 void ExpectNewSessionCallbackError( | 324 void ExpectNewSessionCallbackError( |
| 346 const base::Optional<content::PresentationSessionInfo>& info, | 325 const base::Optional<PresentationSessionInfo>& info, |
| 347 const base::Optional<content::PresentationError>& error) { | 326 const base::Optional<PresentationError>& error) { |
| 348 EXPECT_FALSE(info); | 327 EXPECT_FALSE(info); |
| 349 EXPECT_TRUE(error); | 328 EXPECT_TRUE(error); |
| 350 if (!run_loop_quit_closure_.is_null()) | 329 if (!run_loop_quit_closure_.is_null()) |
| 351 run_loop_quit_closure_.Run(); | 330 run_loop_quit_closure_.Run(); |
| 352 } | 331 } |
| 353 | 332 |
| 354 void ExpectConnectionMessages( | 333 void ExpectConnectionMessages( |
| 355 const std::vector<blink::mojom::ConnectionMessagePtr>& expected_msgs, | 334 const std::vector<PresentationConnectionMessage>& expected_msgs, |
| 356 const std::vector<blink::mojom::ConnectionMessagePtr>& actual_msgs) { | 335 const std::vector<PresentationConnectionMessage>& actual_msgs) { |
| 357 EXPECT_EQ(expected_msgs.size(), actual_msgs.size()); | 336 EXPECT_EQ(expected_msgs.size(), actual_msgs.size()); |
| 358 for (size_t i = 0; i < actual_msgs.size(); ++i) | 337 for (size_t i = 0; i < actual_msgs.size(); ++i) |
| 359 EXPECT_TRUE(expected_msgs[i].Equals(actual_msgs[i])); | 338 EXPECT_EQ(expected_msgs[i], actual_msgs[i]); |
| 360 } | |
| 361 | |
| 362 void RunListenForConnectionMessages(const std::string& text_msg, | |
| 363 const std::vector<uint8_t>& binary_data, | |
| 364 bool pass_ownership) { | |
| 365 std::vector<blink::mojom::ConnectionMessagePtr> expected_msgs(2); | |
| 366 expected_msgs[0] = blink::mojom::ConnectionMessage::New(); | |
| 367 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT; | |
| 368 expected_msgs[0]->message = text_msg; | |
| 369 expected_msgs[1] = blink::mojom::ConnectionMessage::New(); | |
| 370 expected_msgs[1]->type = blink::mojom::PresentationMessageType::BINARY; | |
| 371 expected_msgs[1]->data = binary_data; | |
| 372 | |
| 373 content::PresentationSessionInfo session(presentation_url1_, | |
| 374 kPresentationId); | |
| 375 | |
| 376 PresentationConnectionMessageCallback message_cb; | |
| 377 { | |
| 378 base::RunLoop run_loop; | |
| 379 EXPECT_CALL(mock_delegate_, ListenForConnectionMessages(_, _, _, _)) | |
| 380 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | |
| 381 SaveArg<3>(&message_cb))); | |
| 382 service_ptr_->ListenForConnectionMessages(session); | |
| 383 run_loop.Run(); | |
| 384 } | |
| 385 | |
| 386 std::vector<std::unique_ptr<PresentationConnectionMessage>> messages; | |
| 387 std::unique_ptr<content::PresentationConnectionMessage> message; | |
| 388 message.reset(new content::PresentationConnectionMessage( | |
| 389 PresentationMessageType::TEXT)); | |
| 390 message->message = text_msg; | |
| 391 messages.push_back(std::move(message)); | |
| 392 message.reset(new content::PresentationConnectionMessage( | |
| 393 PresentationMessageType::BINARY)); | |
| 394 message->data.reset(new std::vector<uint8_t>(binary_data)); | |
| 395 messages.push_back(std::move(message)); | |
| 396 | |
| 397 std::vector<blink::mojom::ConnectionMessagePtr> actual_msgs; | |
| 398 { | |
| 399 base::RunLoop run_loop; | |
| 400 EXPECT_CALL(mock_client_, MessagesReceived()) | |
| 401 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | |
| 402 message_cb.Run(std::move(messages), pass_ownership); | |
| 403 run_loop.Run(); | |
| 404 } | |
| 405 ExpectConnectionMessages(expected_msgs, mock_client_.messages_received_); | |
| 406 } | 339 } |
| 407 | 340 |
| 408 MockPresentationServiceDelegate mock_delegate_; | 341 MockPresentationServiceDelegate mock_delegate_; |
| 409 MockReceiverPresentationServiceDelegate mock_receiver_delegate_; | 342 MockReceiverPresentationServiceDelegate mock_receiver_delegate_; |
| 410 | 343 |
| 411 std::unique_ptr<PresentationServiceImpl> service_impl_; | 344 std::unique_ptr<PresentationServiceImpl> service_impl_; |
| 412 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_; | 345 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_; |
| 413 | 346 |
| 414 MockPresentationServiceClient mock_client_; | 347 MockPresentationServiceClient mock_client_; |
| 415 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>> | 348 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>> |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 EXPECT_CALL(mock_delegate_, | 423 EXPECT_CALL(mock_delegate_, |
| 491 SetDefaultPresentationUrls(_, _, presentation_urls_, _)) | 424 SetDefaultPresentationUrls(_, _, presentation_urls_, _)) |
| 492 .Times(1); | 425 .Times(1); |
| 493 | 426 |
| 494 service_impl_->SetDefaultPresentationUrls(presentation_urls_); | 427 service_impl_->SetDefaultPresentationUrls(presentation_urls_); |
| 495 | 428 |
| 496 // Sets different DPUs. | 429 // Sets different DPUs. |
| 497 std::vector<GURL> more_urls = presentation_urls_; | 430 std::vector<GURL> more_urls = presentation_urls_; |
| 498 more_urls.push_back(presentation_url3_); | 431 more_urls.push_back(presentation_url3_); |
| 499 | 432 |
| 500 content::PresentationSessionStartedCallback callback; | 433 PresentationSessionStartedCallback callback; |
| 501 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls(_, _, more_urls, _)) | 434 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls(_, _, more_urls, _)) |
| 502 .WillOnce(SaveArg<3>(&callback)); | 435 .WillOnce(SaveArg<3>(&callback)); |
| 503 service_impl_->SetDefaultPresentationUrls(more_urls); | 436 service_impl_->SetDefaultPresentationUrls(more_urls); |
| 504 | 437 |
| 505 content::PresentationSessionInfo session_info(presentation_url2_, | 438 PresentationSessionInfo session_info(presentation_url2_, kPresentationId); |
| 506 kPresentationId); | |
| 507 | 439 |
| 508 base::RunLoop run_loop; | 440 base::RunLoop run_loop; |
| 509 EXPECT_CALL(mock_client_, | 441 EXPECT_CALL(mock_client_, |
| 510 OnDefaultSessionStarted(SessionInfoEquals(session_info))) | 442 OnDefaultSessionStarted(SessionInfoEquals(session_info))) |
| 511 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 443 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 512 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)); | 444 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)); |
| 513 callback.Run( | 445 callback.Run(PresentationSessionInfo(presentation_url2_, kPresentationId)); |
| 514 content::PresentationSessionInfo(presentation_url2_, kPresentationId)); | |
| 515 run_loop.Run(); | 446 run_loop.Run(); |
| 516 } | 447 } |
| 517 | 448 |
| 518 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { | 449 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { |
| 519 content::PresentationSessionInfo connection(presentation_url1_, | 450 PresentationSessionInfo connection(presentation_url1_, kPresentationId); |
| 520 kPresentationId); | 451 PresentationConnectionStateChangedCallback state_changed_cb; |
| 521 content::PresentationConnectionStateChangedCallback state_changed_cb; | |
| 522 // Trigger state change. It should be propagated back up to |mock_client_|. | 452 // Trigger state change. It should be propagated back up to |mock_client_|. |
| 523 content::PresentationSessionInfo presentation_connection(presentation_url1_, | 453 PresentationSessionInfo presentation_connection(presentation_url1_, |
| 524 kPresentationId); | 454 kPresentationId); |
| 525 | 455 |
| 526 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 456 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 527 .WillOnce(SaveArg<3>(&state_changed_cb)); | 457 .WillOnce(SaveArg<3>(&state_changed_cb)); |
| 528 service_impl_->ListenForConnectionStateChange(connection); | 458 service_impl_->ListenForConnectionStateChange(connection); |
| 529 | 459 |
| 530 { | 460 { |
| 531 base::RunLoop run_loop; | 461 base::RunLoop run_loop; |
| 532 EXPECT_CALL(mock_client_, | 462 EXPECT_CALL( |
| 533 OnConnectionStateChanged( | 463 mock_client_, |
| 534 SessionInfoEquals(presentation_connection), | 464 OnConnectionStateChanged(SessionInfoEquals(presentation_connection), |
| 535 content::PRESENTATION_CONNECTION_STATE_TERMINATED)) | 465 PRESENTATION_CONNECTION_STATE_TERMINATED)) |
| 536 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 466 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 537 state_changed_cb.Run(PresentationConnectionStateChangeInfo( | 467 state_changed_cb.Run(PresentationConnectionStateChangeInfo( |
| 538 PRESENTATION_CONNECTION_STATE_TERMINATED)); | 468 PRESENTATION_CONNECTION_STATE_TERMINATED)); |
| 539 run_loop.Run(); | 469 run_loop.Run(); |
| 540 } | 470 } |
| 541 } | 471 } |
| 542 | 472 |
| 543 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { | 473 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { |
| 544 content::PresentationSessionInfo connection(presentation_url1_, | 474 PresentationSessionInfo connection(presentation_url1_, kPresentationId); |
| 545 kPresentationId); | 475 PresentationConnectionStateChangedCallback state_changed_cb; |
| 546 content::PresentationConnectionStateChangedCallback state_changed_cb; | |
| 547 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 476 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 548 .WillOnce(SaveArg<3>(&state_changed_cb)); | 477 .WillOnce(SaveArg<3>(&state_changed_cb)); |
| 549 service_impl_->ListenForConnectionStateChange(connection); | 478 service_impl_->ListenForConnectionStateChange(connection); |
| 550 | 479 |
| 551 // Trigger connection close. It should be propagated back up to | 480 // Trigger connection close. It should be propagated back up to |
| 552 // |mock_client_|. | 481 // |mock_client_|. |
| 553 content::PresentationSessionInfo presentation_connection(presentation_url1_, | 482 PresentationSessionInfo presentation_connection(presentation_url1_, |
| 554 kPresentationId); | 483 kPresentationId); |
| 555 { | 484 { |
| 556 base::RunLoop run_loop; | 485 base::RunLoop run_loop; |
| 557 PresentationConnectionStateChangeInfo closed_info( | 486 PresentationConnectionStateChangeInfo closed_info( |
| 558 PRESENTATION_CONNECTION_STATE_CLOSED); | 487 PRESENTATION_CONNECTION_STATE_CLOSED); |
| 559 closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; | 488 closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; |
| 560 closed_info.message = "Foo"; | 489 closed_info.message = "Foo"; |
| 561 | 490 |
| 562 EXPECT_CALL(mock_client_, | 491 EXPECT_CALL(mock_client_, |
| 563 OnConnectionClosed( | 492 OnConnectionClosed( |
| 564 SessionInfoEquals(presentation_connection), | 493 SessionInfoEquals(presentation_connection), |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 } | 588 } |
| 660 | 589 |
| 661 TEST_F(PresentationServiceImplTest, Terminate) { | 590 TEST_F(PresentationServiceImplTest, Terminate) { |
| 662 service_ptr_->Terminate(presentation_url1_, kPresentationId); | 591 service_ptr_->Terminate(presentation_url1_, kPresentationId); |
| 663 base::RunLoop run_loop; | 592 base::RunLoop run_loop; |
| 664 EXPECT_CALL(mock_delegate_, Terminate(_, _, Eq(kPresentationId))) | 593 EXPECT_CALL(mock_delegate_, Terminate(_, _, Eq(kPresentationId))) |
| 665 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 594 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 666 run_loop.Run(); | 595 run_loop.Run(); |
| 667 } | 596 } |
| 668 | 597 |
| 669 TEST_F(PresentationServiceImplTest, ListenForConnectionMessagesPassed) { | |
| 670 std::string text_msg("123"); | |
| 671 std::vector<uint8_t> binary_data(3, '\1'); | |
| 672 RunListenForConnectionMessages(text_msg, binary_data, true); | |
| 673 } | |
| 674 | |
| 675 TEST_F(PresentationServiceImplTest, ListenForConnectionMessagesCopied) { | |
| 676 std::string text_msg("123"); | |
| 677 std::vector<uint8_t> binary_data(3, '\1'); | |
| 678 RunListenForConnectionMessages(text_msg, binary_data, false); | |
| 679 } | |
| 680 | |
| 681 TEST_F(PresentationServiceImplTest, ListenForConnectionMessagesWithEmptyMsg) { | |
| 682 std::string text_msg(""); | |
| 683 std::vector<uint8_t> binary_data; | |
| 684 RunListenForConnectionMessages(text_msg, binary_data, false); | |
| 685 } | |
| 686 | |
| 687 TEST_F(PresentationServiceImplTest, SetPresentationConnection) { | 598 TEST_F(PresentationServiceImplTest, SetPresentationConnection) { |
| 688 content::PresentationSessionInfo session(presentation_url1_, kPresentationId); | 599 PresentationSessionInfo session(presentation_url1_, kPresentationId); |
| 689 | 600 |
| 690 blink::mojom::PresentationConnectionPtr connection; | 601 blink::mojom::PresentationConnectionPtr connection; |
| 691 MockPresentationConnection mock_presentation_connection; | 602 MockPresentationConnection mock_presentation_connection; |
| 692 mojo::Binding<blink::mojom::PresentationConnection> connection_binding( | 603 mojo::Binding<blink::mojom::PresentationConnection> connection_binding( |
| 693 &mock_presentation_connection, mojo::MakeRequest(&connection)); | 604 &mock_presentation_connection, mojo::MakeRequest(&connection)); |
| 694 blink::mojom::PresentationConnectionPtr receiver_connection; | 605 blink::mojom::PresentationConnectionPtr receiver_connection; |
| 695 auto request = mojo::MakeRequest(&receiver_connection); | 606 auto request = mojo::MakeRequest(&receiver_connection); |
| 696 | 607 |
| 697 content::PresentationSessionInfo expected(presentation_url1_, | 608 PresentationSessionInfo expected(presentation_url1_, kPresentationId); |
| 698 kPresentationId); | |
| 699 EXPECT_CALL(mock_delegate_, RegisterOffscreenPresentationConnectionRaw( | 609 EXPECT_CALL(mock_delegate_, RegisterOffscreenPresentationConnectionRaw( |
| 700 _, _, SessionInfoEquals(expected), _)); | 610 _, _, SessionInfoEquals(expected), _)); |
| 701 | 611 |
| 702 service_impl_->SetPresentationConnection(session, std::move(connection), | 612 service_impl_->SetPresentationConnection(session, std::move(connection), |
| 703 std::move(request)); | 613 std::move(request)); |
| 704 } | 614 } |
| 705 | 615 |
| 706 TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) { | 616 TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) { |
| 707 MockReceiverPresentationServiceDelegate mock_receiver_delegate; | 617 MockReceiverPresentationServiceDelegate mock_receiver_delegate; |
| 708 | 618 |
| 709 PresentationServiceImpl service_impl(contents()->GetMainFrame(), contents(), | 619 PresentationServiceImpl service_impl(contents()->GetMainFrame(), contents(), |
| 710 nullptr, &mock_receiver_delegate); | 620 nullptr, &mock_receiver_delegate); |
| 711 | 621 |
| 712 ReceiverConnectionAvailableCallback callback; | 622 ReceiverConnectionAvailableCallback callback; |
| 713 EXPECT_CALL(mock_receiver_delegate, | 623 EXPECT_CALL(mock_receiver_delegate, |
| 714 RegisterReceiverConnectionAvailableCallback(_)) | 624 RegisterReceiverConnectionAvailableCallback(_)) |
| 715 .WillOnce(SaveArg<0>(&callback)); | 625 .WillOnce(SaveArg<0>(&callback)); |
| 716 | 626 |
| 717 blink::mojom::PresentationServiceClientPtr client_ptr; | 627 blink::mojom::PresentationServiceClientPtr client_ptr; |
| 718 client_binding_.reset( | 628 client_binding_.reset( |
| 719 new mojo::Binding<blink::mojom::PresentationServiceClient>( | 629 new mojo::Binding<blink::mojom::PresentationServiceClient>( |
| 720 &mock_client_, mojo::MakeRequest(&client_ptr))); | 630 &mock_client_, mojo::MakeRequest(&client_ptr))); |
| 721 service_impl.controller_delegate_ = nullptr; | 631 service_impl.controller_delegate_ = nullptr; |
| 722 service_impl.SetClient(std::move(client_ptr)); | 632 service_impl.SetClient(std::move(client_ptr)); |
| 723 EXPECT_FALSE(callback.is_null()); | 633 EXPECT_FALSE(callback.is_null()); |
| 724 | 634 |
| 725 // NO-OP for ControllerPresentationServiceDelegate API functions | 635 // NO-OP for ControllerPresentationServiceDelegate API functions |
| 726 EXPECT_CALL(mock_delegate_, ListenForConnectionMessages(_, _, _, _)).Times(0); | 636 EXPECT_CALL(mock_delegate_, ListenForConnectionMessages(_, _, _, _)).Times(0); |
| 727 | 637 |
| 728 content::PresentationSessionInfo session(presentation_url1_, kPresentationId); | 638 PresentationSessionInfo session(presentation_url1_, kPresentationId); |
| 729 service_impl.ListenForConnectionMessages(session); | 639 service_impl.ListenForConnectionMessages(session); |
| 730 } | 640 } |
| 731 | 641 |
| 732 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { | 642 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { |
| 733 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _)) | 643 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _)) |
| 734 .Times(1); | 644 .Times(1); |
| 735 service_ptr_->StartSession(presentation_urls_, base::Bind(&DoNothing)); | 645 service_ptr_->StartSession(presentation_urls_, base::Bind(&DoNothing)); |
| 736 | 646 |
| 737 // This request should fail immediately, since there is already a StartSession | 647 // This request should fail immediately, since there is already a StartSession |
| 738 // in progress. | 648 // in progress. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 769 mock_delegate_.set_screen_availability_listening_supported(false); | 679 mock_delegate_.set_screen_availability_listening_supported(false); |
| 770 base::RunLoop run_loop; | 680 base::RunLoop run_loop; |
| 771 EXPECT_CALL(mock_client_, | 681 EXPECT_CALL(mock_client_, |
| 772 OnScreenAvailabilityNotSupported(presentation_url1_)) | 682 OnScreenAvailabilityNotSupported(presentation_url1_)) |
| 773 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 683 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 774 ListenForScreenAvailabilityAndWait(presentation_url1_, false); | 684 ListenForScreenAvailabilityAndWait(presentation_url1_, false); |
| 775 run_loop.Run(); | 685 run_loop.Run(); |
| 776 } | 686 } |
| 777 | 687 |
| 778 } // namespace content | 688 } // namespace content |
| OLD | NEW |