| 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 "base/location.h" | 5 #include "base/location.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 MOCK_METHOD2(Reset, | 76 MOCK_METHOD2(Reset, |
| 77 void( | 77 void( |
| 78 int render_process_id, | 78 int render_process_id, |
| 79 int routing_id)); | 79 int routing_id)); |
| 80 MOCK_METHOD4(SetDefaultPresentationUrl, | 80 MOCK_METHOD4(SetDefaultPresentationUrl, |
| 81 void( | 81 void( |
| 82 int render_process_id, | 82 int render_process_id, |
| 83 int routing_id, | 83 int routing_id, |
| 84 const std::string& default_presentation_url, | 84 const std::string& default_presentation_url, |
| 85 const std::string& default_presentation_id)); | 85 const std::string& default_presentation_id)); |
| 86 MOCK_METHOD6(StartSession, | 86 MOCK_METHOD5(StartSession, |
| 87 void( | 87 void( |
| 88 int render_process_id, | 88 int render_process_id, |
| 89 int render_frame_id, | 89 int render_frame_id, |
| 90 const std::string& presentation_url, | 90 const std::string& presentation_url, |
| 91 const std::string& presentation_id, | |
| 92 const PresentationSessionSuccessCallback& success_cb, | 91 const PresentationSessionSuccessCallback& success_cb, |
| 93 const PresentationSessionErrorCallback& error_cb)); | 92 const PresentationSessionErrorCallback& error_cb)); |
| 94 MOCK_METHOD6(JoinSession, | 93 MOCK_METHOD6(JoinSession, |
| 95 void( | 94 void( |
| 96 int render_process_id, | 95 int render_process_id, |
| 97 int render_frame_id, | 96 int render_frame_id, |
| 98 const std::string& presentation_url, | 97 const std::string& presentation_url, |
| 99 const std::string& presentation_id, | 98 const std::string& presentation_id, |
| 100 const PresentationSessionSuccessCallback& success_cb, | 99 const PresentationSessionSuccessCallback& success_cb, |
| 101 const PresentationSessionErrorCallback& error_cb)); | 100 const PresentationSessionErrorCallback& error_cb)); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 | 455 |
| 457 // Same URL as before; no-ops. | 456 // Same URL as before; no-ops. |
| 458 service_impl_->SetDefaultPresentationURL(kPresentationUrl, dpu_id); | 457 service_impl_->SetDefaultPresentationURL(kPresentationUrl, dpu_id); |
| 459 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); | 458 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
| 460 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_); | 459 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_); |
| 461 } | 460 } |
| 462 | 461 |
| 463 TEST_F(PresentationServiceImplTest, StartSessionSuccess) { | 462 TEST_F(PresentationServiceImplTest, StartSessionSuccess) { |
| 464 service_ptr_->StartSession( | 463 service_ptr_->StartSession( |
| 465 kPresentationUrl, | 464 kPresentationUrl, |
| 466 kPresentationId, | |
| 467 base::Bind( | 465 base::Bind( |
| 468 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess, | 466 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess, |
| 469 base::Unretained(this))); | 467 base::Unretained(this))); |
| 470 base::RunLoop run_loop; | 468 base::RunLoop run_loop; |
| 471 base::Callback<void(const PresentationSessionInfo&)> success_cb; | 469 base::Callback<void(const PresentationSessionInfo&)> success_cb; |
| 472 EXPECT_CALL(mock_delegate_, StartSession( | 470 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(kPresentationUrl), _, _)) |
| 473 _, _, Eq(kPresentationUrl), Eq(kPresentationId), _, _)) | |
| 474 .WillOnce(DoAll( | 471 .WillOnce(DoAll( |
| 475 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 472 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
| 476 SaveArg<4>(&success_cb))); | 473 SaveArg<3>(&success_cb))); |
| 477 run_loop.Run(); | 474 run_loop.Run(); |
| 478 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId)); | 475 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId)); |
| 479 SaveQuitClosureAndRunLoop(); | 476 SaveQuitClosureAndRunLoop(); |
| 480 } | 477 } |
| 481 | 478 |
| 482 TEST_F(PresentationServiceImplTest, StartSessionError) { | 479 TEST_F(PresentationServiceImplTest, StartSessionError) { |
| 483 service_ptr_->StartSession( | 480 service_ptr_->StartSession( |
| 484 kPresentationUrl, | 481 kPresentationUrl, |
| 485 kPresentationId, | |
| 486 base::Bind( | 482 base::Bind( |
| 487 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, | 483 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, |
| 488 base::Unretained(this))); | 484 base::Unretained(this))); |
| 489 base::RunLoop run_loop; | 485 base::RunLoop run_loop; |
| 490 base::Callback<void(const PresentationError&)> error_cb; | 486 base::Callback<void(const PresentationError&)> error_cb; |
| 491 EXPECT_CALL(mock_delegate_, StartSession( | 487 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(kPresentationUrl), _, _)) |
| 492 _, _, Eq(kPresentationUrl), Eq(kPresentationId), _, _)) | |
| 493 .WillOnce(DoAll( | 488 .WillOnce(DoAll( |
| 494 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 489 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
| 495 SaveArg<5>(&error_cb))); | 490 SaveArg<4>(&error_cb))); |
| 496 run_loop.Run(); | 491 run_loop.Run(); |
| 497 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message")); | 492 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message")); |
| 498 SaveQuitClosureAndRunLoop(); | 493 SaveQuitClosureAndRunLoop(); |
| 499 } | 494 } |
| 500 | 495 |
| 501 TEST_F(PresentationServiceImplTest, JoinSessionSuccess) { | 496 TEST_F(PresentationServiceImplTest, JoinSessionSuccess) { |
| 502 service_ptr_->JoinSession( | 497 service_ptr_->JoinSession( |
| 503 kPresentationUrl, | 498 kPresentationUrl, |
| 504 kPresentationId, | 499 kPresentationId, |
| 505 base::Bind( | 500 base::Bind( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 kPresentationUrl, kPresentationId, | 572 kPresentationUrl, kPresentationId, |
| 578 scoped_ptr<std::string>(new std::string(text_msg)))); | 573 scoped_ptr<std::string>(new std::string(text_msg)))); |
| 579 ExpectReset(); | 574 ExpectReset(); |
| 580 service_impl_->Reset(); | 575 service_impl_->Reset(); |
| 581 message_cb.Run(messages.Pass()); | 576 message_cb.Run(messages.Pass()); |
| 582 SaveQuitClosureAndRunLoop(); | 577 SaveQuitClosureAndRunLoop(); |
| 583 } | 578 } |
| 584 | 579 |
| 585 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { | 580 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { |
| 586 std::string presentation_url1("http://fooUrl"); | 581 std::string presentation_url1("http://fooUrl"); |
| 587 std::string presentation_id1("presentationId1"); | |
| 588 std::string presentation_url2("http://barUrl"); | 582 std::string presentation_url2("http://barUrl"); |
| 589 std::string presentation_id2("presentationId2"); | 583 service_ptr_->StartSession(presentation_url1, |
| 590 service_ptr_->StartSession(presentation_url1, presentation_id1, | |
| 591 base::Bind(&DoNothing)); | 584 base::Bind(&DoNothing)); |
| 592 // This request should fail immediately, since there is already a StartSession | 585 // This request should fail immediately, since there is already a StartSession |
| 593 // in progress. | 586 // in progress. |
| 594 service_ptr_->StartSession( | 587 service_ptr_->StartSession( |
| 595 presentation_url2, presentation_id2, | 588 presentation_url2, |
| 596 base::Bind( | 589 base::Bind( |
| 597 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, | 590 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, |
| 598 base::Unretained(this))); | 591 base::Unretained(this))); |
| 599 SaveQuitClosureAndRunLoop(); | 592 SaveQuitClosureAndRunLoop(); |
| 600 } | 593 } |
| 601 | 594 |
| 602 TEST_F(PresentationServiceImplTest, ListenForDefaultSessionStart) { | 595 TEST_F(PresentationServiceImplTest, ListenForDefaultSessionStart) { |
| 603 presentation::PresentationSessionInfo expected_session; | 596 presentation::PresentationSessionInfo expected_session; |
| 604 expected_session.url = kPresentationUrl; | 597 expected_session.url = kPresentationUrl; |
| 605 expected_session.id = kPresentationId; | 598 expected_session.id = kPresentationId; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 service_ptr_->JoinSession( | 828 service_ptr_->JoinSession( |
| 836 base::StringPrintf(presentation_url, i), | 829 base::StringPrintf(presentation_url, i), |
| 837 base::StringPrintf(presentation_id, i), | 830 base::StringPrintf(presentation_id, i), |
| 838 base::Bind( | 831 base::Bind( |
| 839 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, | 832 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, |
| 840 base::Unretained(this))); | 833 base::Unretained(this))); |
| 841 SaveQuitClosureAndRunLoop(); | 834 SaveQuitClosureAndRunLoop(); |
| 842 } | 835 } |
| 843 | 836 |
| 844 } // namespace content | 837 } // namespace content |
| OLD | NEW |