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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 SendMessageRawPtr(render_process_id, render_frame_id, session, | 141 SendMessageRawPtr(render_process_id, render_frame_id, session, |
142 message_request.release(), send_message_cb); | 142 message_request.release(), send_message_cb); |
143 } | 143 } |
144 MOCK_METHOD4(ListenForConnectionStateChange, | 144 MOCK_METHOD4(ListenForConnectionStateChange, |
145 void(int render_process_id, | 145 void(int render_process_id, |
146 int render_frame_id, | 146 int render_frame_id, |
147 const content::PresentationSessionInfo& connection, | 147 const content::PresentationSessionInfo& connection, |
148 const content::PresentationConnectionStateChangedCallback& | 148 const content::PresentationConnectionStateChangedCallback& |
149 state_changed_cb)); | 149 state_changed_cb)); |
150 | 150 |
151 void ConnectToOffscreenPresentation( | 151 void ConnectToPresentation(int render_process_id, |
152 int render_process_id, | 152 int render_frame_id, |
153 int render_frame_id, | 153 const content::PresentationSessionInfo& session, |
154 const content::PresentationSessionInfo& session, | 154 PresentationConnectionPtr connection) override { |
155 PresentationConnectionPtr connection) override { | |
156 RegisterOffscreenPresentationConnectionRaw( | 155 RegisterOffscreenPresentationConnectionRaw( |
157 render_process_id, render_frame_id, session, connection.get()); | 156 render_process_id, render_frame_id, session, connection.get()); |
158 } | 157 } |
159 | 158 |
160 MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw, | 159 MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw, |
161 void(int render_process_id, | 160 void(int render_process_id, |
162 int render_frame_id, | 161 int render_frame_id, |
163 const content::PresentationSessionInfo& session, | 162 const content::PresentationSessionInfo& session, |
164 blink::mojom::PresentationConnection* connection)); | 163 blink::mojom::PresentationConnection* connection)); |
165 | 164 |
(...skipping 22 matching lines...) Expand all Loading... |
188 class MockPresentationConnection : public blink::mojom::PresentationConnection { | 187 class MockPresentationConnection : public blink::mojom::PresentationConnection { |
189 public: | 188 public: |
190 void SetTargetConnection( | 189 void SetTargetConnection( |
191 blink::mojom::PresentationConnectionPtr connection) override { | 190 blink::mojom::PresentationConnectionPtr connection) override { |
192 SetTargetConnection(*connection); | 191 SetTargetConnection(*connection); |
193 } | 192 } |
194 MOCK_METHOD1(SetTargetConnection, | 193 MOCK_METHOD1(SetTargetConnection, |
195 void(blink::mojom::PresentationConnection& connection)); | 194 void(blink::mojom::PresentationConnection& connection)); |
196 | 195 |
197 void OnMessage(blink::mojom::SessionMessagePtr message, | 196 void OnMessage(blink::mojom::SessionMessagePtr message, |
198 const base::Callback<void(bool)>& send_message_cb) override { | 197 const base::Callback<void(bool)>& callback) override { |
199 OnConnectionMessageReceived(*message); | 198 OnConnectionMessageReceived(*message); |
200 } | 199 } |
201 MOCK_METHOD1(OnConnectionMessageReceived, | 200 MOCK_METHOD1(OnConnectionMessageReceived, |
202 void(const blink::mojom::SessionMessage& message)); | 201 void(const blink::mojom::SessionMessage& message)); |
203 MOCK_METHOD1(DidChangeState, | 202 MOCK_METHOD1(DidChangeState, |
204 void(blink::mojom::PresentationConnectionState state)); | 203 void(blink::mojom::PresentationConnectionState state)); |
205 }; | 204 }; |
206 | 205 |
207 class MockPresentationServiceClient | 206 class MockPresentationServiceClient |
208 : public blink::mojom::PresentationServiceClient { | 207 : public blink::mojom::PresentationServiceClient { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 MOCK_METHOD0(MessagesReceived, void()); | 239 MOCK_METHOD0(MessagesReceived, void()); |
241 | 240 |
242 void OnDefaultSessionStarted( | 241 void OnDefaultSessionStarted( |
243 blink::mojom::PresentationSessionInfoPtr session_info) override { | 242 blink::mojom::PresentationSessionInfoPtr session_info) override { |
244 OnDefaultSessionStarted(*session_info); | 243 OnDefaultSessionStarted(*session_info); |
245 } | 244 } |
246 MOCK_METHOD1(OnDefaultSessionStarted, | 245 MOCK_METHOD1(OnDefaultSessionStarted, |
247 void(const blink::mojom::PresentationSessionInfo& session_info)); | 246 void(const blink::mojom::PresentationSessionInfo& session_info)); |
248 | 247 |
249 void OnReceiverConnectionAvailable( | 248 void OnReceiverConnectionAvailable( |
250 blink::mojom::PresentationSessionInfoPtr session_info) override { | 249 blink::mojom::PresentationSessionInfoPtr session_info, |
| 250 blink::mojom::PresentationConnectionPtr connection) override { |
251 OnReceiverConnectionAvailable(*session_info); | 251 OnReceiverConnectionAvailable(*session_info); |
252 } | 252 } |
253 MOCK_METHOD1(OnReceiverConnectionAvailable, | 253 MOCK_METHOD1(OnReceiverConnectionAvailable, |
254 void(const blink::mojom::PresentationSessionInfo& session_info)); | 254 void(const blink::mojom::PresentationSessionInfo& session_info)); |
255 | 255 |
256 std::vector<blink::mojom::SessionMessagePtr> messages_received_; | 256 std::vector<blink::mojom::SessionMessagePtr> messages_received_; |
257 }; | 257 }; |
258 | 258 |
259 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { | 259 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
260 public: | 260 public: |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 base::RunLoop run_loop; | 541 base::RunLoop run_loop; |
542 EXPECT_CALL(mock_client_, | 542 EXPECT_CALL(mock_client_, |
543 OnDefaultSessionStarted(SessionInfoEquals(ByRef(session_info)))) | 543 OnDefaultSessionStarted(SessionInfoEquals(ByRef(session_info)))) |
544 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 544 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
545 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)); | 545 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)); |
546 callback.Run(content::PresentationSessionInfo(presentation_url2_, | 546 callback.Run(content::PresentationSessionInfo(presentation_url2_, |
547 kPresentationId, false)); | 547 kPresentationId, false)); |
548 run_loop.Run(); | 548 run_loop.Run(); |
549 } | 549 } |
550 | 550 |
551 TEST_F(PresentationServiceImplTest, | 551 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { |
552 ListenForConnectionStateChangeAndChangeState) { | |
553 content::PresentationSessionInfo connection(presentation_url1_, | 552 content::PresentationSessionInfo connection(presentation_url1_, |
554 kPresentationId, false); | 553 kPresentationId, false); |
555 content::PresentationConnectionStateChangedCallback state_changed_cb; | 554 content::PresentationConnectionStateChangedCallback state_changed_cb; |
556 // Trigger state change. It should be propagated back up to |mock_client_|. | 555 // Trigger state change. It should be propagated back up to |mock_client_|. |
557 blink::mojom::PresentationSessionInfo presentation_connection; | 556 blink::mojom::PresentationSessionInfo presentation_connection; |
558 presentation_connection.url = presentation_url1_; | 557 presentation_connection.url = presentation_url1_; |
559 presentation_connection.id = kPresentationId; | 558 presentation_connection.id = kPresentationId; |
560 | 559 |
561 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 560 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
562 .WillOnce(SaveArg<3>(&state_changed_cb)); | 561 .WillOnce(SaveArg<3>(&state_changed_cb)); |
563 EXPECT_CALL(mock_client_, | 562 service_impl_->ListenForConnectionStateChange(connection); |
564 OnConnectionStateChanged( | |
565 SessionInfoEquals(ByRef(presentation_connection)), | |
566 blink::mojom::PresentationConnectionState::CONNECTED)); | |
567 service_impl_->ListenForConnectionStateChangeAndChangeState(connection); | |
568 | 563 |
569 { | 564 { |
570 base::RunLoop run_loop; | 565 base::RunLoop run_loop; |
571 EXPECT_CALL(mock_client_, | 566 EXPECT_CALL(mock_client_, |
572 OnConnectionStateChanged( | 567 OnConnectionStateChanged( |
573 SessionInfoEquals(ByRef(presentation_connection)), | 568 SessionInfoEquals(ByRef(presentation_connection)), |
574 blink::mojom::PresentationConnectionState::TERMINATED)) | 569 blink::mojom::PresentationConnectionState::TERMINATED)) |
575 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 570 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
576 state_changed_cb.Run(PresentationConnectionStateChangeInfo( | 571 state_changed_cb.Run(PresentationConnectionStateChangeInfo( |
577 PRESENTATION_CONNECTION_STATE_TERMINATED)); | 572 PRESENTATION_CONNECTION_STATE_TERMINATED)); |
578 run_loop.Run(); | 573 run_loop.Run(); |
579 } | 574 } |
580 } | 575 } |
581 | 576 |
582 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { | 577 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { |
583 content::PresentationSessionInfo connection(presentation_url1_, | 578 content::PresentationSessionInfo connection(presentation_url1_, |
584 kPresentationId, false); | 579 kPresentationId, false); |
585 content::PresentationConnectionStateChangedCallback state_changed_cb; | 580 content::PresentationConnectionStateChangedCallback state_changed_cb; |
586 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 581 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
587 .WillOnce(SaveArg<3>(&state_changed_cb)); | 582 .WillOnce(SaveArg<3>(&state_changed_cb)); |
588 service_impl_->ListenForConnectionStateChangeAndChangeState(connection); | 583 service_impl_->ListenForConnectionStateChange(connection); |
589 | 584 |
590 // Trigger connection close. It should be propagated back up to | 585 // Trigger connection close. It should be propagated back up to |
591 // |mock_client_|. | 586 // |mock_client_|. |
592 blink::mojom::PresentationSessionInfo presentation_connection; | 587 blink::mojom::PresentationSessionInfo presentation_connection; |
593 presentation_connection.url = presentation_url1_; | 588 presentation_connection.url = presentation_url1_; |
594 presentation_connection.id = kPresentationId; | 589 presentation_connection.id = kPresentationId; |
595 { | 590 { |
596 base::RunLoop run_loop; | 591 base::RunLoop run_loop; |
597 PresentationConnectionStateChangeInfo closed_info( | 592 PresentationConnectionStateChangeInfo closed_info( |
598 PRESENTATION_CONNECTION_STATE_CLOSED); | 593 PRESENTATION_CONNECTION_STATE_CLOSED); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 mock_delegate_.set_screen_availability_listening_supported(false); | 964 mock_delegate_.set_screen_availability_listening_supported(false); |
970 base::RunLoop run_loop; | 965 base::RunLoop run_loop; |
971 EXPECT_CALL(mock_client_, | 966 EXPECT_CALL(mock_client_, |
972 OnScreenAvailabilityNotSupported(presentation_url1_)) | 967 OnScreenAvailabilityNotSupported(presentation_url1_)) |
973 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 968 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
974 ListenForScreenAvailabilityAndWait(presentation_url1_, false); | 969 ListenForScreenAvailabilityAndWait(presentation_url1_, false); |
975 run_loop.Run(); | 970 run_loop.Run(); |
976 } | 971 } |
977 | 972 |
978 } // namespace content | 973 } // namespace content |
OLD | NEW |