| 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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 478 |
| 479 blink::mojom::PresentationSessionInfo session_info; | 479 blink::mojom::PresentationSessionInfo session_info; |
| 480 session_info.url = presentation_url2_; | 480 session_info.url = presentation_url2_; |
| 481 session_info.id = kPresentationId; | 481 session_info.id = kPresentationId; |
| 482 | 482 |
| 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(content::PresentationSessionInfo(presentation_url2_, |
| 489 content::PresentationSessionInfo(presentation_url2_, kPresentationId)); | 489 kPresentationId, false)); |
| 490 run_loop.Run(); | 490 run_loop.Run(); |
| 491 } | 491 } |
| 492 | 492 |
| 493 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { | 493 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { |
| 494 content::PresentationSessionInfo connection(presentation_url1_, | 494 content::PresentationSessionInfo connection(presentation_url1_, |
| 495 kPresentationId); | 495 kPresentationId, false); |
| 496 content::PresentationConnectionStateChangedCallback state_changed_cb; | 496 content::PresentationConnectionStateChangedCallback state_changed_cb; |
| 497 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 497 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 498 .WillOnce(SaveArg<3>(&state_changed_cb)); | 498 .WillOnce(SaveArg<3>(&state_changed_cb)); |
| 499 service_impl_->ListenForConnectionStateChange(connection); | 499 service_impl_->ListenForConnectionStateChange(connection); |
| 500 | 500 |
| 501 // Trigger state change. It should be propagated back up to |mock_client_|. | 501 // Trigger state change. It should be propagated back up to |mock_client_|. |
| 502 blink::mojom::PresentationSessionInfo presentation_connection; | 502 blink::mojom::PresentationSessionInfo presentation_connection; |
| 503 presentation_connection.url = presentation_url1_; | 503 presentation_connection.url = presentation_url1_; |
| 504 presentation_connection.id = kPresentationId; | 504 presentation_connection.id = kPresentationId; |
| 505 { | 505 { |
| 506 base::RunLoop run_loop; | 506 base::RunLoop run_loop; |
| 507 EXPECT_CALL(mock_client_, | 507 EXPECT_CALL(mock_client_, |
| 508 OnConnectionStateChanged( | 508 OnConnectionStateChanged( |
| 509 SessionInfoEquals(ByRef(presentation_connection)), | 509 SessionInfoEquals(ByRef(presentation_connection)), |
| 510 blink::mojom::PresentationConnectionState::TERMINATED)) | 510 blink::mojom::PresentationConnectionState::TERMINATED)) |
| 511 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 511 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 512 state_changed_cb.Run(PresentationConnectionStateChangeInfo( | 512 state_changed_cb.Run(PresentationConnectionStateChangeInfo( |
| 513 PRESENTATION_CONNECTION_STATE_TERMINATED)); | 513 PRESENTATION_CONNECTION_STATE_TERMINATED)); |
| 514 run_loop.Run(); | 514 run_loop.Run(); |
| 515 } | 515 } |
| 516 } | 516 } |
| 517 | 517 |
| 518 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { | 518 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { |
| 519 content::PresentationSessionInfo connection(presentation_url1_, | 519 content::PresentationSessionInfo connection(presentation_url1_, |
| 520 kPresentationId); | 520 kPresentationId, false); |
| 521 content::PresentationConnectionStateChangedCallback state_changed_cb; | 521 content::PresentationConnectionStateChangedCallback state_changed_cb; |
| 522 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 522 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 523 .WillOnce(SaveArg<3>(&state_changed_cb)); | 523 .WillOnce(SaveArg<3>(&state_changed_cb)); |
| 524 service_impl_->ListenForConnectionStateChange(connection); | 524 service_impl_->ListenForConnectionStateChange(connection); |
| 525 | 525 |
| 526 // Trigger connection close. It should be propagated back up to | 526 // Trigger connection close. It should be propagated back up to |
| 527 // |mock_client_|. | 527 // |mock_client_|. |
| 528 blink::mojom::PresentationSessionInfo presentation_connection; | 528 blink::mojom::PresentationSessionInfo presentation_connection; |
| 529 presentation_connection.url = presentation_url1_; | 529 presentation_connection.url = presentation_url1_; |
| 530 presentation_connection.id = kPresentationId; | 530 presentation_connection.id = kPresentationId; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 base::Unretained(this))); | 565 base::Unretained(this))); |
| 566 base::RunLoop run_loop; | 566 base::RunLoop run_loop; |
| 567 base::Callback<void(const PresentationSessionInfo&)> success_cb; | 567 base::Callback<void(const PresentationSessionInfo&)> success_cb; |
| 568 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _)) | 568 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _)) |
| 569 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 569 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
| 570 SaveArg<3>(&success_cb))); | 570 SaveArg<3>(&success_cb))); |
| 571 run_loop.Run(); | 571 run_loop.Run(); |
| 572 | 572 |
| 573 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 573 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 574 .Times(1); | 574 .Times(1); |
| 575 success_cb.Run(PresentationSessionInfo(presentation_url1_, kPresentationId)); | 575 success_cb.Run( |
| 576 PresentationSessionInfo(presentation_url1_, kPresentationId, false)); |
| 576 SaveQuitClosureAndRunLoop(); | 577 SaveQuitClosureAndRunLoop(); |
| 577 } | 578 } |
| 578 | 579 |
| 579 TEST_F(PresentationServiceImplTest, StartSessionError) { | 580 TEST_F(PresentationServiceImplTest, StartSessionError) { |
| 580 service_ptr_->StartSession( | 581 service_ptr_->StartSession( |
| 581 presentation_urls_, | 582 presentation_urls_, |
| 582 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, | 583 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, |
| 583 base::Unretained(this))); | 584 base::Unretained(this))); |
| 584 base::RunLoop run_loop; | 585 base::RunLoop run_loop; |
| 585 base::Callback<void(const PresentationError&)> error_cb; | 586 base::Callback<void(const PresentationError&)> error_cb; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 599 base::RunLoop run_loop; | 600 base::RunLoop run_loop; |
| 600 base::Callback<void(const PresentationSessionInfo&)> success_cb; | 601 base::Callback<void(const PresentationSessionInfo&)> success_cb; |
| 601 EXPECT_CALL(mock_delegate_, | 602 EXPECT_CALL(mock_delegate_, |
| 602 JoinSession(_, _, presentation_urls_, kPresentationId, _, _)) | 603 JoinSession(_, _, presentation_urls_, kPresentationId, _, _)) |
| 603 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 604 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
| 604 SaveArg<4>(&success_cb))); | 605 SaveArg<4>(&success_cb))); |
| 605 run_loop.Run(); | 606 run_loop.Run(); |
| 606 | 607 |
| 607 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) | 608 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 608 .Times(1); | 609 .Times(1); |
| 609 success_cb.Run(PresentationSessionInfo(presentation_url1_, kPresentationId)); | 610 success_cb.Run( |
| 611 PresentationSessionInfo(presentation_url1_, kPresentationId, false)); |
| 610 SaveQuitClosureAndRunLoop(); | 612 SaveQuitClosureAndRunLoop(); |
| 611 } | 613 } |
| 612 | 614 |
| 613 TEST_F(PresentationServiceImplTest, JoinSessionError) { | 615 TEST_F(PresentationServiceImplTest, JoinSessionError) { |
| 614 service_ptr_->JoinSession( | 616 service_ptr_->JoinSession( |
| 615 presentation_urls_, base::Optional<std::string>(kPresentationId), | 617 presentation_urls_, base::Optional<std::string>(kPresentationId), |
| 616 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, | 618 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, |
| 617 base::Unretained(this))); | 619 base::Unretained(this))); |
| 618 base::RunLoop run_loop; | 620 base::RunLoop run_loop; |
| 619 base::Callback<void(const PresentationError&)> error_cb; | 621 base::Callback<void(const PresentationError&)> error_cb; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 mock_delegate_.set_screen_availability_listening_supported(false); | 854 mock_delegate_.set_screen_availability_listening_supported(false); |
| 853 base::RunLoop run_loop; | 855 base::RunLoop run_loop; |
| 854 EXPECT_CALL(mock_client_, | 856 EXPECT_CALL(mock_client_, |
| 855 OnScreenAvailabilityNotSupported(presentation_url1_)) | 857 OnScreenAvailabilityNotSupported(presentation_url1_)) |
| 856 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 858 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 857 ListenForScreenAvailabilityAndWait(presentation_url1_, false); | 859 ListenForScreenAvailabilityAndWait(presentation_url1_, false); |
| 858 run_loop.Run(); | 860 run_loop.Run(); |
| 859 } | 861 } |
| 860 | 862 |
| 861 } // namespace content | 863 } // namespace content |
| OLD | NEW |