| 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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 base::RunLoop run_loop; | 483 base::RunLoop run_loop; |
| 484 EXPECT_CALL(mock_client_, | 484 EXPECT_CALL(mock_client_, |
| 485 OnDefaultSessionStarted(SessionInfoEquals(ByRef(session_info)))) | 485 OnDefaultSessionStarted(SessionInfoEquals(ByRef(session_info)))) |
| 486 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 486 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 487 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)); | 487 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)); |
| 488 callback.Run( | 488 callback.Run( |
| 489 content::PresentationSessionInfo(presentation_url2_, kPresentationId)); | 489 content::PresentationSessionInfo(presentation_url2_, kPresentationId)); |
| 490 run_loop.Run(); | 490 run_loop.Run(); |
| 491 } | 491 } |
| 492 | 492 |
| 493 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { | 493 TEST_F(PresentationServiceImplTest, |
| 494 ListenForConnectionStateChangeAndChangeState) { |
| 494 content::PresentationSessionInfo connection(presentation_url1_, | 495 content::PresentationSessionInfo connection(presentation_url1_, |
| 495 kPresentationId); | 496 kPresentationId); |
| 496 content::PresentationConnectionStateChangedCallback state_changed_cb; | 497 content::PresentationConnectionStateChangedCallback state_changed_cb; |
| 497 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | |
| 498 .WillOnce(SaveArg<3>(&state_changed_cb)); | |
| 499 service_impl_->ListenForConnectionStateChange(connection); | |
| 500 | |
| 501 // Trigger state change. It should be propagated back up to |mock_client_|. | 498 // Trigger state change. It should be propagated back up to |mock_client_|. |
| 502 blink::mojom::PresentationSessionInfo presentation_connection; | 499 blink::mojom::PresentationSessionInfo presentation_connection; |
| 503 presentation_connection.url = presentation_url1_; | 500 presentation_connection.url = presentation_url1_; |
| 504 presentation_connection.id = kPresentationId; | 501 presentation_connection.id = kPresentationId; |
| 502 |
| 503 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 504 .WillOnce(SaveArg<3>(&state_changed_cb)); |
| 505 EXPECT_CALL(mock_client_, |
| 506 OnConnectionStateChanged( |
| 507 SessionInfoEquals(ByRef(presentation_connection)), |
| 508 blink::mojom::PresentationConnectionState::CONNECTED)); |
| 509 service_impl_->ListenForConnectionStateChangeAndChangeState(connection); |
| 510 |
| 505 { | 511 { |
| 506 base::RunLoop run_loop; | 512 base::RunLoop run_loop; |
| 507 EXPECT_CALL(mock_client_, | 513 EXPECT_CALL(mock_client_, |
| 508 OnConnectionStateChanged( | 514 OnConnectionStateChanged( |
| 509 SessionInfoEquals(ByRef(presentation_connection)), | 515 SessionInfoEquals(ByRef(presentation_connection)), |
| 510 blink::mojom::PresentationConnectionState::TERMINATED)) | 516 blink::mojom::PresentationConnectionState::TERMINATED)) |
| 511 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 517 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 512 state_changed_cb.Run(PresentationConnectionStateChangeInfo( | 518 state_changed_cb.Run(PresentationConnectionStateChangeInfo( |
| 513 PRESENTATION_CONNECTION_STATE_TERMINATED)); | 519 PRESENTATION_CONNECTION_STATE_TERMINATED)); |
| 514 run_loop.Run(); | 520 run_loop.Run(); |
| 515 } | 521 } |
| 516 } | 522 } |
| 517 | 523 |
| 518 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { | 524 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { |
| 519 content::PresentationSessionInfo connection(presentation_url1_, | 525 content::PresentationSessionInfo connection(presentation_url1_, |
| 520 kPresentationId); | 526 kPresentationId); |
| 521 content::PresentationConnectionStateChangedCallback state_changed_cb; | 527 content::PresentationConnectionStateChangedCallback state_changed_cb; |
| 522 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 528 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 523 .WillOnce(SaveArg<3>(&state_changed_cb)); | 529 .WillOnce(SaveArg<3>(&state_changed_cb)); |
| 524 service_impl_->ListenForConnectionStateChange(connection); | 530 service_impl_->ListenForConnectionStateChangeAndChangeState(connection); |
| 525 | 531 |
| 526 // Trigger connection close. It should be propagated back up to | 532 // Trigger connection close. It should be propagated back up to |
| 527 // |mock_client_|. | 533 // |mock_client_|. |
| 528 blink::mojom::PresentationSessionInfo presentation_connection; | 534 blink::mojom::PresentationSessionInfo presentation_connection; |
| 529 presentation_connection.url = presentation_url1_; | 535 presentation_connection.url = presentation_url1_; |
| 530 presentation_connection.id = kPresentationId; | 536 presentation_connection.id = kPresentationId; |
| 531 { | 537 { |
| 532 base::RunLoop run_loop; | 538 base::RunLoop run_loop; |
| 533 PresentationConnectionStateChangeInfo closed_info( | 539 PresentationConnectionStateChangeInfo closed_info( |
| 534 PRESENTATION_CONNECTION_STATE_CLOSED); | 540 PRESENTATION_CONNECTION_STATE_CLOSED); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 mock_delegate_.set_screen_availability_listening_supported(false); | 858 mock_delegate_.set_screen_availability_listening_supported(false); |
| 853 base::RunLoop run_loop; | 859 base::RunLoop run_loop; |
| 854 EXPECT_CALL(mock_client_, | 860 EXPECT_CALL(mock_client_, |
| 855 OnScreenAvailabilityNotSupported(presentation_url1_)) | 861 OnScreenAvailabilityNotSupported(presentation_url1_)) |
| 856 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 862 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 857 ListenForScreenAvailabilityAndWait(presentation_url1_, false); | 863 ListenForScreenAvailabilityAndWait(presentation_url1_, false); |
| 858 run_loop.Run(); | 864 run_loop.Run(); |
| 859 } | 865 } |
| 860 | 866 |
| 861 } // namespace content | 867 } // namespace content |
| OLD | NEW |