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 <iterator> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/test/test_timeouts.h" | 19 #include "base/test/test_timeouts.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
21 #include "content/public/browser/navigation_handle.h" | 21 #include "content/public/browser/navigation_handle.h" |
22 #include "content/public/browser/presentation_service_delegate.h" | 22 #include "content/public/browser/presentation_service_delegate.h" |
23 #include "content/public/common/presentation_connection_message.h" | 23 #include "content/public/common/presentation_connection_message.h" |
24 #include "content/public/common/presentation_session.h" | 24 #include "content/public/common/presentation_info.h" |
25 #include "content/test/test_render_frame_host.h" | 25 #include "content/test/test_render_frame_host.h" |
26 #include "content/test/test_render_view_host.h" | 26 #include "content/test/test_render_view_host.h" |
27 #include "content/test/test_web_contents.h" | 27 #include "content/test/test_web_contents.h" |
28 #include "mojo/public/cpp/bindings/interface_ptr.h" | 28 #include "mojo/public/cpp/bindings/interface_ptr.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
30 | 30 |
31 using ::testing::_; | 31 using ::testing::_; |
32 using ::testing::ByRef; | 32 using ::testing::ByRef; |
33 using ::testing::Eq; | 33 using ::testing::Eq; |
34 using ::testing::Invoke; | 34 using ::testing::Invoke; |
35 using ::testing::InvokeWithoutArgs; | 35 using ::testing::InvokeWithoutArgs; |
36 using ::testing::Mock; | 36 using ::testing::Mock; |
37 using ::testing::Return; | 37 using ::testing::Return; |
38 using ::testing::SaveArg; | 38 using ::testing::SaveArg; |
39 using ::testing::WithArgs; | 39 using ::testing::WithArgs; |
40 | 40 |
41 namespace content { | 41 namespace content { |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 // Matches content::PresentationSessionInfo. | 45 // Matches content::PresentationInfo. |
46 MATCHER_P(SessionInfoEquals, expected, "") { | 46 MATCHER_P(InfoEquals, expected, "") { |
47 return expected.presentation_url == arg.presentation_url && | 47 return expected.presentation_url == arg.presentation_url && |
48 expected.presentation_id == arg.presentation_id; | 48 expected.presentation_id == arg.presentation_id; |
49 } | 49 } |
50 | 50 |
51 const char kPresentationId[] = "presentationId"; | 51 const char kPresentationId[] = "presentationId"; |
52 const char kPresentationUrl1[] = "http://foo.com/index.html"; | 52 const char kPresentationUrl1[] = "http://foo.com/index.html"; |
53 const char kPresentationUrl2[] = "http://example.com/index.html"; | 53 const char kPresentationUrl2[] = "http://example.com/index.html"; |
54 const char kPresentationUrl3[] = "http://example.net/index.html"; | 54 const char kPresentationUrl3[] = "http://example.net/index.html"; |
55 | 55 |
56 void DoNothing(const base::Optional<content::PresentationSessionInfo>& info, | 56 void DoNothing(const base::Optional<content::PresentationInfo>& info, |
57 const base::Optional<content::PresentationError>& error) {} | 57 const base::Optional<content::PresentationError>& error) {} |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 class MockPresentationServiceDelegate | 61 class MockPresentationServiceDelegate |
62 : public ControllerPresentationServiceDelegate { | 62 : public ControllerPresentationServiceDelegate { |
63 public: | 63 public: |
64 MOCK_METHOD3(AddObserver, | 64 MOCK_METHOD3(AddObserver, |
65 void(int render_process_id, | 65 void(int render_process_id, |
66 int render_frame_id, | 66 int render_frame_id, |
(...skipping 16 matching lines...) Expand all Loading... |
83 void(int render_process_id, | 83 void(int render_process_id, |
84 int routing_id, | 84 int routing_id, |
85 PresentationScreenAvailabilityListener* listener)); | 85 PresentationScreenAvailabilityListener* listener)); |
86 MOCK_METHOD2(Reset, | 86 MOCK_METHOD2(Reset, |
87 void(int render_process_id, | 87 void(int render_process_id, |
88 int routing_id)); | 88 int routing_id)); |
89 MOCK_METHOD4(SetDefaultPresentationUrls, | 89 MOCK_METHOD4(SetDefaultPresentationUrls, |
90 void(int render_process_id, | 90 void(int render_process_id, |
91 int routing_id, | 91 int routing_id, |
92 const std::vector<GURL>& default_presentation_urls, | 92 const std::vector<GURL>& default_presentation_urls, |
93 const PresentationSessionStartedCallback& callback)); | 93 const PresentationConnectionCallback& callback)); |
94 MOCK_METHOD5(StartSession, | 94 MOCK_METHOD5(StartPresentation, |
95 void(int render_process_id, | 95 void(int render_process_id, |
96 int render_frame_id, | 96 int render_frame_id, |
97 const std::vector<GURL>& presentation_urls, | 97 const std::vector<GURL>& presentation_urls, |
98 const PresentationSessionStartedCallback& success_cb, | 98 const PresentationConnectionCallback& success_cb, |
99 const PresentationSessionErrorCallback& error_cb)); | 99 const PresentationConnectionErrorCallback& error_cb)); |
100 MOCK_METHOD6(JoinSession, | 100 MOCK_METHOD6(ReconnectPresentation, |
101 void(int render_process_id, | 101 void(int render_process_id, |
102 int render_frame_id, | 102 int render_frame_id, |
103 const std::vector<GURL>& presentation_urls, | 103 const std::vector<GURL>& presentation_urls, |
104 const std::string& presentation_id, | 104 const std::string& presentation_id, |
105 const PresentationSessionStartedCallback& success_cb, | 105 const PresentationConnectionCallback& success_cb, |
106 const PresentationSessionErrorCallback& error_cb)); | 106 const PresentationConnectionErrorCallback& error_cb)); |
107 MOCK_METHOD3(CloseConnection, | 107 MOCK_METHOD3(CloseConnection, |
108 void(int render_process_id, | 108 void(int render_process_id, |
109 int render_frame_id, | 109 int render_frame_id, |
110 const std::string& presentation_id)); | 110 const std::string& presentation_id)); |
111 MOCK_METHOD3(Terminate, | 111 MOCK_METHOD3(Terminate, |
112 void(int render_process_id, | 112 void(int render_process_id, |
113 int render_frame_id, | 113 int render_frame_id, |
114 const std::string& presentation_id)); | 114 const std::string& presentation_id)); |
115 MOCK_METHOD4(ListenForConnectionMessages, | 115 MOCK_METHOD4(ListenForConnectionMessages, |
116 void(int render_process_id, | 116 void(int render_process_id, |
117 int render_frame_id, | 117 int render_frame_id, |
118 const PresentationSessionInfo& session, | 118 const PresentationInfo& presentation_info, |
119 const PresentationConnectionMessageCallback& message_cb)); | 119 const PresentationConnectionMessageCallback& message_cb)); |
120 // PresentationConnectionMessage is move-only. | 120 // PresentationConnectionMessage is move-only. |
121 void SendMessage(int render_process_id, | 121 void SendMessage(int render_process_id, |
122 int render_frame_id, | 122 int render_frame_id, |
123 const PresentationSessionInfo& session, | 123 const PresentationInfo& presentation_info, |
124 PresentationConnectionMessage message, | 124 PresentationConnectionMessage message, |
125 const SendMessageCallback& send_message_cb) { | 125 const SendMessageCallback& send_message_cb) { |
126 SendMessageInternal(render_process_id, render_frame_id, session, message, | 126 SendMessageInternal(render_process_id, render_frame_id, presentation_info, |
127 send_message_cb); | 127 message, send_message_cb); |
128 } | 128 } |
129 MOCK_METHOD5(SendMessageInternal, | 129 MOCK_METHOD5(SendMessageInternal, |
130 void(int render_process_id, | 130 void(int render_process_id, |
131 int render_frame_id, | 131 int render_frame_id, |
132 const PresentationSessionInfo& session, | 132 const PresentationInfo& presentation_info, |
133 const PresentationConnectionMessage& message, | 133 const PresentationConnectionMessage& message, |
134 const SendMessageCallback& send_message_cb)); | 134 const SendMessageCallback& send_message_cb)); |
135 MOCK_METHOD4( | 135 MOCK_METHOD4( |
136 ListenForConnectionStateChange, | 136 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 PresentationSessionInfo& connection, | 139 const PresentationInfo& connection, |
140 const PresentationConnectionStateChangedCallback& state_changed_cb)); | 140 const PresentationConnectionStateChangedCallback& state_changed_cb)); |
141 | 141 |
142 void ConnectToPresentation( | 142 void ConnectToPresentation( |
143 int render_process_id, | 143 int render_process_id, |
144 int render_frame_id, | 144 int render_frame_id, |
145 const PresentationSessionInfo& session, | 145 const PresentationInfo& presentation_info, |
146 PresentationConnectionPtr controller_conn_ptr, | 146 PresentationConnectionPtr controller_conn_ptr, |
147 PresentationConnectionRequest receiver_conn_request) override { | 147 PresentationConnectionRequest receiver_conn_request) override { |
148 RegisterOffscreenPresentationConnectionRaw( | 148 RegisterOffscreenPresentationConnectionRaw( |
149 render_process_id, render_frame_id, session, controller_conn_ptr.get()); | 149 render_process_id, render_frame_id, presentation_info, |
| 150 controller_conn_ptr.get()); |
150 } | 151 } |
151 | 152 |
152 MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw, | 153 MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw, |
153 void(int render_process_id, | 154 void(int render_process_id, |
154 int render_frame_id, | 155 int render_frame_id, |
155 const PresentationSessionInfo& session, | 156 const PresentationInfo& presentation_info, |
156 blink::mojom::PresentationConnection* connection)); | 157 blink::mojom::PresentationConnection* connection)); |
157 | 158 |
158 void set_screen_availability_listening_supported(bool value) { | 159 void set_screen_availability_listening_supported(bool value) { |
159 screen_availability_listening_supported_ = value; | 160 screen_availability_listening_supported_ = value; |
160 } | 161 } |
161 | 162 |
162 private: | 163 private: |
163 bool screen_availability_listening_supported_ = true; | 164 bool screen_availability_listening_supported_ = true; |
164 }; | 165 }; |
165 | 166 |
(...skipping 24 matching lines...) Expand all Loading... |
190 MOCK_METHOD1(DidChangeState, void(PresentationConnectionState state)); | 191 MOCK_METHOD1(DidChangeState, void(PresentationConnectionState state)); |
191 MOCK_METHOD0(OnClose, void()); | 192 MOCK_METHOD0(OnClose, void()); |
192 }; | 193 }; |
193 | 194 |
194 class MockPresentationServiceClient | 195 class MockPresentationServiceClient |
195 : public blink::mojom::PresentationServiceClient { | 196 : public blink::mojom::PresentationServiceClient { |
196 public: | 197 public: |
197 MOCK_METHOD2(OnScreenAvailabilityUpdated, | 198 MOCK_METHOD2(OnScreenAvailabilityUpdated, |
198 void(const GURL& url, bool available)); | 199 void(const GURL& url, bool available)); |
199 MOCK_METHOD2(OnConnectionStateChanged, | 200 MOCK_METHOD2(OnConnectionStateChanged, |
200 void(const PresentationSessionInfo& connection, | 201 void(const PresentationInfo& connection, |
201 PresentationConnectionState new_state)); | 202 PresentationConnectionState new_state)); |
202 MOCK_METHOD3(OnConnectionClosed, | 203 MOCK_METHOD3(OnConnectionClosed, |
203 void(const PresentationSessionInfo& connection, | 204 void(const PresentationInfo& connection, |
204 PresentationConnectionCloseReason reason, | 205 PresentationConnectionCloseReason reason, |
205 const std::string& message)); | 206 const std::string& message)); |
206 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const GURL& url)); | 207 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const GURL& url)); |
207 // PresentationConnectionMessage is move-only. | 208 // PresentationConnectionMessage is move-only. |
208 void OnConnectionMessagesReceived( | 209 void OnConnectionMessagesReceived( |
209 const PresentationSessionInfo& session_info, | 210 const PresentationInfo& presentation_info, |
210 std::vector<PresentationConnectionMessage> messages) { | 211 std::vector<PresentationConnectionMessage> messages) { |
211 OnConnectionMessagesReceivedInternal(session_info, messages); | 212 OnConnectionMessagesReceivedInternal(presentation_info, messages); |
212 } | 213 } |
213 MOCK_METHOD2( | 214 MOCK_METHOD2( |
214 OnConnectionMessagesReceivedInternal, | 215 OnConnectionMessagesReceivedInternal, |
215 void(const PresentationSessionInfo& session_info, | 216 void(const PresentationInfo& presentation_info, |
216 const std::vector<PresentationConnectionMessage>& messages)); | 217 const std::vector<PresentationConnectionMessage>& messages)); |
217 MOCK_METHOD1(OnDefaultSessionStarted, | 218 MOCK_METHOD1(OnDefaultPresentationStarted, |
218 void(const PresentationSessionInfo& session_info)); | 219 void(const PresentationInfo& presentation_info)); |
219 | 220 |
220 void OnReceiverConnectionAvailable( | 221 void OnReceiverConnectionAvailable( |
221 const PresentationSessionInfo& session_info, | 222 const PresentationInfo& presentation_info, |
222 blink::mojom::PresentationConnectionPtr controller_conn_ptr, | 223 blink::mojom::PresentationConnectionPtr controller_conn_ptr, |
223 blink::mojom::PresentationConnectionRequest receiver_conn_request) | 224 blink::mojom::PresentationConnectionRequest receiver_conn_request) |
224 override { | 225 override { |
225 OnReceiverConnectionAvailable(session_info); | 226 OnReceiverConnectionAvailable(presentation_info); |
226 } | 227 } |
227 MOCK_METHOD1(OnReceiverConnectionAvailable, | 228 MOCK_METHOD1(OnReceiverConnectionAvailable, |
228 void(const PresentationSessionInfo& session_info)); | 229 void(const PresentationInfo& presentation_info)); |
229 }; | 230 }; |
230 | 231 |
231 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { | 232 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
232 public: | 233 public: |
233 PresentationServiceImplTest() | 234 PresentationServiceImplTest() |
234 : presentation_url1_(GURL(kPresentationUrl1)), | 235 : presentation_url1_(GURL(kPresentationUrl1)), |
235 presentation_url2_(GURL(kPresentationUrl2)), | 236 presentation_url2_(GURL(kPresentationUrl2)), |
236 presentation_url3_(GURL(kPresentationUrl3)) {} | 237 presentation_url3_(GURL(kPresentationUrl3)) {} |
237 | 238 |
238 void SetUp() override { | 239 void SetUp() override { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1); | 327 EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1); |
327 } | 328 } |
328 | 329 |
329 void ExpectCleanState() { | 330 void ExpectCleanState() { |
330 EXPECT_TRUE(service_impl_->default_presentation_urls_.empty()); | 331 EXPECT_TRUE(service_impl_->default_presentation_urls_.empty()); |
331 EXPECT_EQ( | 332 EXPECT_EQ( |
332 service_impl_->screen_availability_listeners_.find(presentation_url1_), | 333 service_impl_->screen_availability_listeners_.find(presentation_url1_), |
333 service_impl_->screen_availability_listeners_.end()); | 334 service_impl_->screen_availability_listeners_.end()); |
334 } | 335 } |
335 | 336 |
336 void ExpectNewSessionCallbackSuccess( | 337 void ExpectNewPresentationCallbackSuccess( |
337 const base::Optional<PresentationSessionInfo>& info, | 338 const base::Optional<PresentationInfo>& info, |
338 const base::Optional<PresentationError>& error) { | 339 const base::Optional<PresentationError>& error) { |
339 EXPECT_TRUE(info); | 340 EXPECT_TRUE(info); |
340 EXPECT_FALSE(error); | 341 EXPECT_FALSE(error); |
341 if (!run_loop_quit_closure_.is_null()) | 342 if (!run_loop_quit_closure_.is_null()) |
342 run_loop_quit_closure_.Run(); | 343 run_loop_quit_closure_.Run(); |
343 } | 344 } |
344 | 345 |
345 void ExpectNewSessionCallbackError( | 346 void ExpectNewPresentationCallbackError( |
346 const base::Optional<PresentationSessionInfo>& info, | 347 const base::Optional<PresentationInfo>& info, |
347 const base::Optional<PresentationError>& error) { | 348 const base::Optional<PresentationError>& error) { |
348 EXPECT_FALSE(info); | 349 EXPECT_FALSE(info); |
349 EXPECT_TRUE(error); | 350 EXPECT_TRUE(error); |
350 if (!run_loop_quit_closure_.is_null()) | 351 if (!run_loop_quit_closure_.is_null()) |
351 run_loop_quit_closure_.Run(); | 352 run_loop_quit_closure_.Run(); |
352 } | 353 } |
353 | 354 |
354 void ExpectConnectionMessages( | 355 void ExpectConnectionMessages( |
355 const std::vector<PresentationConnectionMessage>& expected_msgs, | 356 const std::vector<PresentationConnectionMessage>& expected_msgs, |
356 const std::vector<PresentationConnectionMessage>& actual_msgs) { | 357 const std::vector<PresentationConnectionMessage>& actual_msgs) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 EXPECT_CALL(mock_delegate_, | 445 EXPECT_CALL(mock_delegate_, |
445 SetDefaultPresentationUrls(_, _, presentation_urls_, _)) | 446 SetDefaultPresentationUrls(_, _, presentation_urls_, _)) |
446 .Times(1); | 447 .Times(1); |
447 | 448 |
448 service_impl_->SetDefaultPresentationUrls(presentation_urls_); | 449 service_impl_->SetDefaultPresentationUrls(presentation_urls_); |
449 | 450 |
450 // Sets different DPUs. | 451 // Sets different DPUs. |
451 std::vector<GURL> more_urls = presentation_urls_; | 452 std::vector<GURL> more_urls = presentation_urls_; |
452 more_urls.push_back(presentation_url3_); | 453 more_urls.push_back(presentation_url3_); |
453 | 454 |
454 PresentationSessionStartedCallback callback; | 455 PresentationConnectionCallback callback; |
455 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls(_, _, more_urls, _)) | 456 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls(_, _, more_urls, _)) |
456 .WillOnce(SaveArg<3>(&callback)); | 457 .WillOnce(SaveArg<3>(&callback)); |
457 service_impl_->SetDefaultPresentationUrls(more_urls); | 458 service_impl_->SetDefaultPresentationUrls(more_urls); |
458 | 459 |
459 PresentationSessionInfo session_info(presentation_url2_, kPresentationId); | 460 PresentationInfo presentation_info(presentation_url2_, kPresentationId); |
460 | 461 |
461 base::RunLoop run_loop; | 462 base::RunLoop run_loop; |
462 EXPECT_CALL(mock_client_, | 463 EXPECT_CALL(mock_client_, |
463 OnDefaultSessionStarted(SessionInfoEquals(session_info))) | 464 OnDefaultPresentationStarted(InfoEquals(presentation_info))) |
464 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 465 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
465 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)); | 466 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)); |
466 callback.Run(PresentationSessionInfo(presentation_url2_, kPresentationId)); | 467 callback.Run(PresentationInfo(presentation_url2_, kPresentationId)); |
467 run_loop.Run(); | 468 run_loop.Run(); |
468 } | 469 } |
469 | 470 |
470 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { | 471 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { |
471 PresentationSessionInfo connection(presentation_url1_, kPresentationId); | 472 PresentationInfo connection(presentation_url1_, kPresentationId); |
472 PresentationConnectionStateChangedCallback state_changed_cb; | 473 PresentationConnectionStateChangedCallback state_changed_cb; |
473 // Trigger state change. It should be propagated back up to |mock_client_|. | 474 // Trigger state change. It should be propagated back up to |mock_client_|. |
474 PresentationSessionInfo presentation_connection(presentation_url1_, | 475 PresentationInfo presentation_connection(presentation_url1_, kPresentationId); |
475 kPresentationId); | |
476 | 476 |
477 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 477 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
478 .WillOnce(SaveArg<3>(&state_changed_cb)); | 478 .WillOnce(SaveArg<3>(&state_changed_cb)); |
479 service_impl_->ListenForConnectionStateChange(connection); | 479 service_impl_->ListenForConnectionStateChange(connection); |
480 | 480 |
481 { | 481 { |
482 base::RunLoop run_loop; | 482 base::RunLoop run_loop; |
483 EXPECT_CALL(mock_client_, OnConnectionStateChanged( | 483 EXPECT_CALL(mock_client_, OnConnectionStateChanged( |
484 SessionInfoEquals(presentation_connection), | 484 InfoEquals(presentation_connection), |
485 PRESENTATION_CONNECTION_STATE_TERMINATED)) | 485 PRESENTATION_CONNECTION_STATE_TERMINATED)) |
486 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 486 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
487 state_changed_cb.Run(PresentationConnectionStateChangeInfo( | 487 state_changed_cb.Run(PresentationConnectionStateChangeInfo( |
488 PRESENTATION_CONNECTION_STATE_TERMINATED)); | 488 PRESENTATION_CONNECTION_STATE_TERMINATED)); |
489 run_loop.Run(); | 489 run_loop.Run(); |
490 } | 490 } |
491 } | 491 } |
492 | 492 |
493 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { | 493 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { |
494 PresentationSessionInfo connection(presentation_url1_, kPresentationId); | 494 PresentationInfo connection(presentation_url1_, kPresentationId); |
495 PresentationConnectionStateChangedCallback state_changed_cb; | 495 PresentationConnectionStateChangedCallback state_changed_cb; |
496 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 496 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
497 .WillOnce(SaveArg<3>(&state_changed_cb)); | 497 .WillOnce(SaveArg<3>(&state_changed_cb)); |
498 service_impl_->ListenForConnectionStateChange(connection); | 498 service_impl_->ListenForConnectionStateChange(connection); |
499 | 499 |
500 // Trigger connection close. It should be propagated back up to | 500 // Trigger connection close. It should be propagated back up to |
501 // |mock_client_|. | 501 // |mock_client_|. |
502 PresentationSessionInfo presentation_connection(presentation_url1_, | 502 PresentationInfo presentation_connection(presentation_url1_, kPresentationId); |
503 kPresentationId); | |
504 { | 503 { |
505 base::RunLoop run_loop; | 504 base::RunLoop run_loop; |
506 PresentationConnectionStateChangeInfo closed_info( | 505 PresentationConnectionStateChangeInfo closed_info( |
507 PRESENTATION_CONNECTION_STATE_CLOSED); | 506 PRESENTATION_CONNECTION_STATE_CLOSED); |
508 closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; | 507 closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; |
509 closed_info.message = "Foo"; | 508 closed_info.message = "Foo"; |
510 | 509 |
511 EXPECT_CALL(mock_client_, | 510 EXPECT_CALL(mock_client_, |
512 OnConnectionClosed( | 511 OnConnectionClosed( |
513 SessionInfoEquals(presentation_connection), | 512 InfoEquals(presentation_connection), |
514 PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY, "Foo")) | 513 PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY, "Foo")) |
515 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 514 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
516 state_changed_cb.Run(closed_info); | 515 state_changed_cb.Run(closed_info); |
517 run_loop.Run(); | 516 run_loop.Run(); |
518 } | 517 } |
519 } | 518 } |
520 | 519 |
521 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrls) { | 520 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrls) { |
522 EXPECT_CALL(mock_delegate_, | 521 EXPECT_CALL(mock_delegate_, |
523 SetDefaultPresentationUrls(_, _, presentation_urls_, _)) | 522 SetDefaultPresentationUrls(_, _, presentation_urls_, _)) |
524 .Times(1); | 523 .Times(1); |
525 service_impl_->SetDefaultPresentationUrls(presentation_urls_); | 524 service_impl_->SetDefaultPresentationUrls(presentation_urls_); |
526 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); | 525 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
527 | 526 |
528 // Same URLs as before; no-ops. | 527 // Same URLs as before; no-ops. |
529 service_impl_->SetDefaultPresentationUrls(presentation_urls_); | 528 service_impl_->SetDefaultPresentationUrls(presentation_urls_); |
530 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); | 529 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
531 } | 530 } |
532 | 531 |
533 TEST_F(PresentationServiceImplTest, StartSessionSuccess) { | 532 TEST_F(PresentationServiceImplTest, StartPresentationSuccess) { |
534 service_ptr_->StartSession( | 533 service_ptr_->StartPresentation( |
535 presentation_urls_, | 534 presentation_urls_, |
536 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackSuccess, | 535 base::Bind( |
537 base::Unretained(this))); | 536 &PresentationServiceImplTest::ExpectNewPresentationCallbackSuccess, |
| 537 base::Unretained(this))); |
538 base::RunLoop run_loop; | 538 base::RunLoop run_loop; |
539 base::Callback<void(const PresentationSessionInfo&)> success_cb; | 539 base::Callback<void(const PresentationInfo&)> success_cb; |
540 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _)) | 540 EXPECT_CALL(mock_delegate_, StartPresentation(_, _, presentation_urls_, _, _)) |
541 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 541 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
542 SaveArg<3>(&success_cb))); | 542 SaveArg<3>(&success_cb))); |
543 run_loop.Run(); | 543 run_loop.Run(); |
544 | 544 |
545 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 545 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
546 .Times(1); | 546 .Times(1); |
547 success_cb.Run(PresentationSessionInfo(presentation_url1_, kPresentationId)); | 547 success_cb.Run(PresentationInfo(presentation_url1_, kPresentationId)); |
548 SaveQuitClosureAndRunLoop(); | 548 SaveQuitClosureAndRunLoop(); |
549 } | 549 } |
550 | 550 |
551 TEST_F(PresentationServiceImplTest, StartSessionError) { | 551 TEST_F(PresentationServiceImplTest, StartPresentationError) { |
552 service_ptr_->StartSession( | 552 service_ptr_->StartPresentation( |
553 presentation_urls_, | 553 presentation_urls_, |
554 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, | 554 base::Bind( |
555 base::Unretained(this))); | 555 &PresentationServiceImplTest::ExpectNewPresentationCallbackError, |
| 556 base::Unretained(this))); |
556 base::RunLoop run_loop; | 557 base::RunLoop run_loop; |
557 base::Callback<void(const PresentationError&)> error_cb; | 558 base::Callback<void(const PresentationError&)> error_cb; |
558 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _)) | 559 EXPECT_CALL(mock_delegate_, StartPresentation(_, _, presentation_urls_, _, _)) |
559 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 560 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
560 SaveArg<4>(&error_cb))); | 561 SaveArg<4>(&error_cb))); |
561 run_loop.Run(); | 562 run_loop.Run(); |
562 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message")); | 563 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message")); |
563 SaveQuitClosureAndRunLoop(); | 564 SaveQuitClosureAndRunLoop(); |
564 } | 565 } |
565 | 566 |
566 TEST_F(PresentationServiceImplTest, JoinSessionSuccess) { | 567 TEST_F(PresentationServiceImplTest, ReconnectPresentationSuccess) { |
567 service_ptr_->JoinSession( | 568 service_ptr_->ReconnectPresentation( |
568 presentation_urls_, base::Optional<std::string>(kPresentationId), | 569 presentation_urls_, base::Optional<std::string>(kPresentationId), |
569 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackSuccess, | 570 base::Bind( |
570 base::Unretained(this))); | 571 &PresentationServiceImplTest::ExpectNewPresentationCallbackSuccess, |
| 572 base::Unretained(this))); |
571 base::RunLoop run_loop; | 573 base::RunLoop run_loop; |
572 base::Callback<void(const PresentationSessionInfo&)> success_cb; | 574 base::Callback<void(const PresentationInfo&)> success_cb; |
573 EXPECT_CALL(mock_delegate_, | 575 EXPECT_CALL(mock_delegate_, ReconnectPresentation(_, _, presentation_urls_, |
574 JoinSession(_, _, presentation_urls_, kPresentationId, _, _)) | 576 kPresentationId, _, _)) |
575 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 577 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
576 SaveArg<4>(&success_cb))); | 578 SaveArg<4>(&success_cb))); |
577 run_loop.Run(); | 579 run_loop.Run(); |
578 | 580 |
579 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 581 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
580 .Times(1); | 582 .Times(1); |
581 success_cb.Run(PresentationSessionInfo(presentation_url1_, kPresentationId)); | 583 success_cb.Run(PresentationInfo(presentation_url1_, kPresentationId)); |
582 SaveQuitClosureAndRunLoop(); | 584 SaveQuitClosureAndRunLoop(); |
583 } | 585 } |
584 | 586 |
585 TEST_F(PresentationServiceImplTest, JoinSessionError) { | 587 TEST_F(PresentationServiceImplTest, ReconnectPresentationError) { |
586 service_ptr_->JoinSession( | 588 service_ptr_->ReconnectPresentation( |
587 presentation_urls_, base::Optional<std::string>(kPresentationId), | 589 presentation_urls_, base::Optional<std::string>(kPresentationId), |
588 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, | 590 base::Bind( |
589 base::Unretained(this))); | 591 &PresentationServiceImplTest::ExpectNewPresentationCallbackError, |
| 592 base::Unretained(this))); |
590 base::RunLoop run_loop; | 593 base::RunLoop run_loop; |
591 base::Callback<void(const PresentationError&)> error_cb; | 594 base::Callback<void(const PresentationError&)> error_cb; |
592 EXPECT_CALL(mock_delegate_, | 595 EXPECT_CALL(mock_delegate_, ReconnectPresentation(_, _, presentation_urls_, |
593 JoinSession(_, _, presentation_urls_, kPresentationId, _, _)) | 596 kPresentationId, _, _)) |
594 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 597 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
595 SaveArg<5>(&error_cb))); | 598 SaveArg<5>(&error_cb))); |
596 run_loop.Run(); | 599 run_loop.Run(); |
597 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message")); | 600 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message")); |
598 SaveQuitClosureAndRunLoop(); | 601 SaveQuitClosureAndRunLoop(); |
599 } | 602 } |
600 | 603 |
601 TEST_F(PresentationServiceImplTest, CloseConnection) { | 604 TEST_F(PresentationServiceImplTest, CloseConnection) { |
602 service_ptr_->CloseConnection(presentation_url1_, kPresentationId); | 605 service_ptr_->CloseConnection(presentation_url1_, kPresentationId); |
603 | 606 |
604 base::RunLoop run_loop; | 607 base::RunLoop run_loop; |
605 EXPECT_CALL(mock_delegate_, CloseConnection(_, _, Eq(kPresentationId))) | 608 EXPECT_CALL(mock_delegate_, CloseConnection(_, _, Eq(kPresentationId))) |
606 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 609 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
607 run_loop.Run(); | 610 run_loop.Run(); |
608 } | 611 } |
609 | 612 |
610 TEST_F(PresentationServiceImplTest, Terminate) { | 613 TEST_F(PresentationServiceImplTest, Terminate) { |
611 service_ptr_->Terminate(presentation_url1_, kPresentationId); | 614 service_ptr_->Terminate(presentation_url1_, kPresentationId); |
612 base::RunLoop run_loop; | 615 base::RunLoop run_loop; |
613 EXPECT_CALL(mock_delegate_, Terminate(_, _, Eq(kPresentationId))) | 616 EXPECT_CALL(mock_delegate_, Terminate(_, _, Eq(kPresentationId))) |
614 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 617 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
615 run_loop.Run(); | 618 run_loop.Run(); |
616 } | 619 } |
617 | 620 |
618 TEST_F(PresentationServiceImplTest, SetPresentationConnection) { | 621 TEST_F(PresentationServiceImplTest, SetPresentationConnection) { |
619 PresentationSessionInfo session(presentation_url1_, kPresentationId); | 622 PresentationInfo presentation_info(presentation_url1_, kPresentationId); |
620 | 623 |
621 blink::mojom::PresentationConnectionPtr connection; | 624 blink::mojom::PresentationConnectionPtr connection; |
622 MockPresentationConnection mock_presentation_connection; | 625 MockPresentationConnection mock_presentation_connection; |
623 mojo::Binding<blink::mojom::PresentationConnection> connection_binding( | 626 mojo::Binding<blink::mojom::PresentationConnection> connection_binding( |
624 &mock_presentation_connection, mojo::MakeRequest(&connection)); | 627 &mock_presentation_connection, mojo::MakeRequest(&connection)); |
625 blink::mojom::PresentationConnectionPtr receiver_connection; | 628 blink::mojom::PresentationConnectionPtr receiver_connection; |
626 auto request = mojo::MakeRequest(&receiver_connection); | 629 auto request = mojo::MakeRequest(&receiver_connection); |
627 | 630 |
628 PresentationSessionInfo expected(presentation_url1_, kPresentationId); | 631 PresentationInfo expected(presentation_url1_, kPresentationId); |
629 EXPECT_CALL(mock_delegate_, RegisterOffscreenPresentationConnectionRaw( | 632 EXPECT_CALL(mock_delegate_, RegisterOffscreenPresentationConnectionRaw( |
630 _, _, SessionInfoEquals(expected), _)); | 633 _, _, InfoEquals(expected), _)); |
631 | 634 |
632 service_impl_->SetPresentationConnection(session, std::move(connection), | 635 service_impl_->SetPresentationConnection( |
633 std::move(request)); | 636 presentation_info, std::move(connection), std::move(request)); |
634 } | 637 } |
635 | 638 |
636 TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) { | 639 TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) { |
637 MockReceiverPresentationServiceDelegate mock_receiver_delegate; | 640 MockReceiverPresentationServiceDelegate mock_receiver_delegate; |
638 | 641 |
639 PresentationServiceImpl service_impl(contents()->GetMainFrame(), contents(), | 642 PresentationServiceImpl service_impl(contents()->GetMainFrame(), contents(), |
640 nullptr, &mock_receiver_delegate); | 643 nullptr, &mock_receiver_delegate); |
641 | 644 |
642 ReceiverConnectionAvailableCallback callback; | 645 ReceiverConnectionAvailableCallback callback; |
643 EXPECT_CALL(mock_receiver_delegate, | 646 EXPECT_CALL(mock_receiver_delegate, |
644 RegisterReceiverConnectionAvailableCallback(_)) | 647 RegisterReceiverConnectionAvailableCallback(_)) |
645 .WillOnce(SaveArg<0>(&callback)); | 648 .WillOnce(SaveArg<0>(&callback)); |
646 | 649 |
647 blink::mojom::PresentationServiceClientPtr client_ptr; | 650 blink::mojom::PresentationServiceClientPtr client_ptr; |
648 client_binding_.reset( | 651 client_binding_.reset( |
649 new mojo::Binding<blink::mojom::PresentationServiceClient>( | 652 new mojo::Binding<blink::mojom::PresentationServiceClient>( |
650 &mock_client_, mojo::MakeRequest(&client_ptr))); | 653 &mock_client_, mojo::MakeRequest(&client_ptr))); |
651 service_impl.controller_delegate_ = nullptr; | 654 service_impl.controller_delegate_ = nullptr; |
652 service_impl.SetClient(std::move(client_ptr)); | 655 service_impl.SetClient(std::move(client_ptr)); |
653 EXPECT_FALSE(callback.is_null()); | 656 EXPECT_FALSE(callback.is_null()); |
654 | 657 |
655 // NO-OP for ControllerPresentationServiceDelegate API functions | 658 // NO-OP for ControllerPresentationServiceDelegate API functions |
656 EXPECT_CALL(mock_delegate_, ListenForConnectionMessages(_, _, _, _)).Times(0); | 659 EXPECT_CALL(mock_delegate_, ListenForConnectionMessages(_, _, _, _)).Times(0); |
657 | 660 |
658 PresentationSessionInfo session(presentation_url1_, kPresentationId); | 661 PresentationInfo presentation_info(presentation_url1_, kPresentationId); |
659 service_impl.ListenForConnectionMessages(session); | 662 service_impl.ListenForConnectionMessages(presentation_info); |
660 } | 663 } |
661 | 664 |
662 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { | 665 TEST_F(PresentationServiceImplTest, StartPresentationInProgress) { |
663 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _)) | 666 EXPECT_CALL(mock_delegate_, StartPresentation(_, _, presentation_urls_, _, _)) |
664 .Times(1); | 667 .Times(1); |
665 service_ptr_->StartSession(presentation_urls_, base::Bind(&DoNothing)); | 668 service_ptr_->StartPresentation(presentation_urls_, base::Bind(&DoNothing)); |
666 | 669 |
667 // This request should fail immediately, since there is already a StartSession | 670 // This request should fail immediately, since there is already a |
668 // in progress. | 671 // StartPresentation in progress. |
669 service_ptr_->StartSession( | 672 service_ptr_->StartPresentation( |
670 presentation_urls_, | 673 presentation_urls_, |
671 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, | 674 base::Bind( |
672 base::Unretained(this))); | 675 &PresentationServiceImplTest::ExpectNewPresentationCallbackError, |
| 676 base::Unretained(this))); |
673 SaveQuitClosureAndRunLoop(); | 677 SaveQuitClosureAndRunLoop(); |
674 } | 678 } |
675 | 679 |
676 TEST_F(PresentationServiceImplTest, MaxPendingJoinSessionRequests) { | 680 TEST_F(PresentationServiceImplTest, MaxPendingReconnectPresentationRequests) { |
677 const char* presentation_url = "http://fooUrl%d"; | 681 const char* presentation_url = "http://fooUrl%d"; |
678 const char* presentation_id = "presentationId%d"; | 682 const char* presentation_id = "presentationId%d"; |
679 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests; | 683 int num_requests = PresentationServiceImpl::kMaxQueuedRequests; |
680 int i = 0; | 684 int i = 0; |
681 EXPECT_CALL(mock_delegate_, JoinSession(_, _, _, _, _, _)) | 685 EXPECT_CALL(mock_delegate_, ReconnectPresentation(_, _, _, _, _, _)) |
682 .Times(num_requests); | 686 .Times(num_requests); |
683 for (; i < num_requests; ++i) { | 687 for (; i < num_requests; ++i) { |
684 std::vector<GURL> urls = {GURL(base::StringPrintf(presentation_url, i))}; | 688 std::vector<GURL> urls = {GURL(base::StringPrintf(presentation_url, i))}; |
685 service_ptr_->JoinSession(urls, base::StringPrintf(presentation_id, i), | 689 service_ptr_->ReconnectPresentation( |
686 base::Bind(&DoNothing)); | 690 urls, base::StringPrintf(presentation_id, i), base::Bind(&DoNothing)); |
687 } | 691 } |
688 | 692 |
689 std::vector<GURL> urls = {GURL(base::StringPrintf(presentation_url, i))}; | 693 std::vector<GURL> urls = {GURL(base::StringPrintf(presentation_url, i))}; |
690 // Exceeded maximum queue size, should invoke mojo callback with error. | 694 // Exceeded maximum queue size, should invoke mojo callback with error. |
691 service_ptr_->JoinSession( | 695 service_ptr_->ReconnectPresentation( |
692 urls, base::StringPrintf(presentation_id, i), | 696 urls, base::StringPrintf(presentation_id, i), |
693 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, | 697 base::Bind( |
694 base::Unretained(this))); | 698 &PresentationServiceImplTest::ExpectNewPresentationCallbackError, |
| 699 base::Unretained(this))); |
695 SaveQuitClosureAndRunLoop(); | 700 SaveQuitClosureAndRunLoop(); |
696 } | 701 } |
697 | 702 |
698 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { | 703 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { |
699 mock_delegate_.set_screen_availability_listening_supported(false); | 704 mock_delegate_.set_screen_availability_listening_supported(false); |
700 base::RunLoop run_loop; | 705 base::RunLoop run_loop; |
701 EXPECT_CALL(mock_client_, | 706 EXPECT_CALL(mock_client_, |
702 OnScreenAvailabilityNotSupported(presentation_url1_)) | 707 OnScreenAvailabilityNotSupported(presentation_url1_)) |
703 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 708 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
704 ListenForScreenAvailabilityAndWait(presentation_url1_, false); | 709 ListenForScreenAvailabilityAndWait(presentation_url1_, false); |
705 run_loop.Run(); | 710 run_loop.Run(); |
706 } | 711 } |
707 | 712 |
708 } // namespace content | 713 } // namespace content |
OLD | NEW |