| 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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 EXPECT_CALL(mock_client_, | 537 EXPECT_CALL(mock_client_, |
| 538 OnDefaultSessionStarted(SessionInfoEquals(ByRef(session_info)))) | 538 OnDefaultSessionStarted(SessionInfoEquals(ByRef(session_info)))) |
| 539 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 539 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 540 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)); | 540 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)); |
| 541 callback.Run( | 541 callback.Run( |
| 542 content::PresentationSessionInfo(presentation_url2_, kPresentationId)); | 542 content::PresentationSessionInfo(presentation_url2_, kPresentationId)); |
| 543 run_loop.Run(); | 543 run_loop.Run(); |
| 544 } | 544 } |
| 545 | 545 |
| 546 TEST_F(PresentationServiceImplTest, | 546 TEST_F(PresentationServiceImplTest, |
| 547 ListenForConnectionStateChangeAndChangeState) { | 547 ListenForConnectionStateChange) { |
| 548 content::PresentationSessionInfo connection(presentation_url1_, | 548 content::PresentationSessionInfo connection(presentation_url1_, |
| 549 kPresentationId); | 549 kPresentationId); |
| 550 content::PresentationConnectionStateChangedCallback state_changed_cb; | 550 content::PresentationConnectionStateChangedCallback state_changed_cb; |
| 551 // Trigger state change. It should be propagated back up to |mock_client_|. | 551 // Trigger state change. It should be propagated back up to |mock_client_|. |
| 552 blink::mojom::PresentationSessionInfo presentation_connection; | 552 blink::mojom::PresentationSessionInfo presentation_connection; |
| 553 presentation_connection.url = presentation_url1_; | 553 presentation_connection.url = presentation_url1_; |
| 554 presentation_connection.id = kPresentationId; | 554 presentation_connection.id = kPresentationId; |
| 555 | 555 |
| 556 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 556 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 557 .WillOnce(SaveArg<3>(&state_changed_cb)); | 557 .WillOnce(SaveArg<3>(&state_changed_cb)); |
| 558 EXPECT_CALL(mock_client_, | 558 service_impl_->ListenForConnectionStateChange(connection); |
| 559 OnConnectionStateChanged( | |
| 560 SessionInfoEquals(ByRef(presentation_connection)), | |
| 561 blink::mojom::PresentationConnectionState::CONNECTED)); | |
| 562 service_impl_->ListenForConnectionStateChangeAndChangeState(connection); | |
| 563 | 559 |
| 564 { | 560 { |
| 565 base::RunLoop run_loop; | 561 base::RunLoop run_loop; |
| 566 EXPECT_CALL(mock_client_, | 562 EXPECT_CALL(mock_client_, |
| 567 OnConnectionStateChanged( | 563 OnConnectionStateChanged( |
| 568 SessionInfoEquals(ByRef(presentation_connection)), | 564 SessionInfoEquals(ByRef(presentation_connection)), |
| 569 blink::mojom::PresentationConnectionState::TERMINATED)) | 565 blink::mojom::PresentationConnectionState::TERMINATED)) |
| 570 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 566 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 571 state_changed_cb.Run(PresentationConnectionStateChangeInfo( | 567 state_changed_cb.Run(PresentationConnectionStateChangeInfo( |
| 572 PRESENTATION_CONNECTION_STATE_TERMINATED)); | 568 PRESENTATION_CONNECTION_STATE_TERMINATED)); |
| 573 run_loop.Run(); | 569 run_loop.Run(); |
| 574 } | 570 } |
| 575 } | 571 } |
| 576 | 572 |
| 577 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { | 573 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { |
| 578 content::PresentationSessionInfo connection(presentation_url1_, | 574 content::PresentationSessionInfo connection(presentation_url1_, |
| 579 kPresentationId); | 575 kPresentationId); |
| 580 content::PresentationConnectionStateChangedCallback state_changed_cb; | 576 content::PresentationConnectionStateChangedCallback state_changed_cb; |
| 581 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 577 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 582 .WillOnce(SaveArg<3>(&state_changed_cb)); | 578 .WillOnce(SaveArg<3>(&state_changed_cb)); |
| 583 service_impl_->ListenForConnectionStateChangeAndChangeState(connection); | 579 service_impl_->ListenForConnectionStateChange(connection); |
| 584 | 580 |
| 585 // Trigger connection close. It should be propagated back up to | 581 // Trigger connection close. It should be propagated back up to |
| 586 // |mock_client_|. | 582 // |mock_client_|. |
| 587 blink::mojom::PresentationSessionInfo presentation_connection; | 583 blink::mojom::PresentationSessionInfo presentation_connection; |
| 588 presentation_connection.url = presentation_url1_; | 584 presentation_connection.url = presentation_url1_; |
| 589 presentation_connection.id = kPresentationId; | 585 presentation_connection.id = kPresentationId; |
| 590 { | 586 { |
| 591 base::RunLoop run_loop; | 587 base::RunLoop run_loop; |
| 592 PresentationConnectionStateChangeInfo closed_info( | 588 PresentationConnectionStateChangeInfo closed_info( |
| 593 PRESENTATION_CONNECTION_STATE_CLOSED); | 589 PRESENTATION_CONNECTION_STATE_CLOSED); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 mock_delegate_.set_screen_availability_listening_supported(false); | 968 mock_delegate_.set_screen_availability_listening_supported(false); |
| 973 base::RunLoop run_loop; | 969 base::RunLoop run_loop; |
| 974 EXPECT_CALL(mock_client_, | 970 EXPECT_CALL(mock_client_, |
| 975 OnScreenAvailabilityNotSupported(presentation_url1_)) | 971 OnScreenAvailabilityNotSupported(presentation_url1_)) |
| 976 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 972 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 977 ListenForScreenAvailabilityAndWait(presentation_url1_, false); | 973 ListenForScreenAvailabilityAndWait(presentation_url1_, false); |
| 978 run_loop.Run(); | 974 run_loop.Run(); |
| 979 } | 975 } |
| 980 | 976 |
| 981 } // namespace content | 977 } // namespace content |
| OLD | NEW |