| Index: content/browser/presentation/presentation_service_impl_unittest.cc
|
| diff --git a/content/browser/presentation/presentation_service_impl_unittest.cc b/content/browser/presentation/presentation_service_impl_unittest.cc
|
| index 89a6b3c779aa02419bb6b210c2d8f33c1e779ae4..acffb6222d503ad12c020ac0592854a511dff817 100644
|
| --- a/content/browser/presentation/presentation_service_impl_unittest.cc
|
| +++ b/content/browser/presentation/presentation_service_impl_unittest.cc
|
| @@ -7,6 +7,7 @@
|
| #include "base/run_loop.h"
|
| #include "content/browser/presentation/presentation_service_impl.h"
|
| #include "content/public/browser/presentation_service_delegate.h"
|
| +#include "content/public/browser/presentation_session.h"
|
| #include "content/test/test_render_frame_host.h"
|
| #include "content/test/test_render_view_host.h"
|
| #include "content/test/test_web_contents.h"
|
| @@ -18,6 +19,7 @@ using ::testing::Eq;
|
| using ::testing::InvokeWithoutArgs;
|
| using ::testing::Mock;
|
| using ::testing::Return;
|
| +using ::testing::SaveArg;
|
|
|
| namespace content {
|
|
|
| @@ -41,6 +43,27 @@ class MockPresentationServiceDelegate : public PresentationServiceDelegate {
|
| void(
|
| int render_process_id,
|
| int routing_id));
|
| + MOCK_METHOD3(SetDefaultPresentationUrl,
|
| + void(
|
| + int render_process_id,
|
| + int routing_id,
|
| + const std::string& default_presentation_url));
|
| + MOCK_METHOD6(StartSession,
|
| + void(
|
| + int render_process_id,
|
| + int render_frame_id,
|
| + const std::string& presentation_url,
|
| + const std::string& presentation_id,
|
| + const PresentationSessionSuccessCallback& success_cb,
|
| + const PresentationSessionErrorCallback& error_cb));
|
| + MOCK_METHOD6(JoinSession,
|
| + void(
|
| + int render_process_id,
|
| + int render_frame_id,
|
| + const std::string& presentation_url,
|
| + const std::string& presentation_id,
|
| + const PresentationSessionSuccessCallback& success_cb,
|
| + const PresentationSessionErrorCallback& error_cb));
|
| };
|
|
|
| class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
|
| @@ -93,6 +116,10 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
|
| EXPECT_TRUE(it == contexts.end());
|
| }
|
|
|
| + void RunLoopUntilIdle() {
|
| + base::RunLoop().RunUntilIdle();
|
| + }
|
| +
|
| void RunLoopFor(base::TimeDelta duration) {
|
| base::RunLoop run_loop;
|
| base::MessageLoop::current()->PostDelayedTask(
|
| @@ -126,6 +153,31 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
|
| run_loop_quit_closure_.Run();
|
| }
|
|
|
| + void ExpectReset() {
|
| + EXPECT_CALL(mock_delegate_, RemoveAllScreenAvailabilityListeners(_, _))
|
| + .Times(1);
|
| + EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq("")))
|
| + .Times(1);
|
| + }
|
| +
|
| + void ExpectNewSessionMojoCallbackSuccess(
|
| + presentation::PresentationSessionInfoPtr info,
|
| + presentation::PresentationErrorPtr error) {
|
| + EXPECT_FALSE(info.is_null());
|
| + EXPECT_TRUE(error.is_null());
|
| + if (!run_loop_quit_closure_.is_null())
|
| + run_loop_quit_closure_.Run();
|
| + }
|
| +
|
| + void ExpectNewSessionMojoCallbackError(
|
| + presentation::PresentationSessionInfoPtr info,
|
| + presentation::PresentationErrorPtr error) {
|
| + EXPECT_TRUE(info.is_null());
|
| + EXPECT_FALSE(error.is_null());
|
| + if (!run_loop_quit_closure_.is_null())
|
| + run_loop_quit_closure_.Run();
|
| + }
|
| +
|
| MockPresentationServiceDelegate mock_delegate_;
|
| scoped_ptr<PresentationServiceImpl> service_impl_;
|
| mojo::InterfacePtr<presentation::PresentationService> service_ptr_;
|
| @@ -170,7 +222,7 @@ TEST_F(PresentationServiceImplTest, GetScreenAvailability) {
|
| EXPECT_EQ(2, callback_count_);
|
| }
|
|
|
| -TEST_F(PresentationServiceImplTest, RemoveAllListeners) {
|
| +TEST_F(PresentationServiceImplTest, Reset) {
|
| std::string presentation_url("http://fooUrl");
|
| GetScreenAvailabilityAndWait(
|
| presentation_url,
|
| @@ -178,7 +230,8 @@ TEST_F(PresentationServiceImplTest, RemoveAllListeners) {
|
| base::Unretained(this)),
|
| true);
|
|
|
| - service_impl_->RemoveAllListeners();
|
| + ExpectReset();
|
| + service_impl_->Reset();
|
|
|
| ExpectListenerDoesNotExist(presentation_url);
|
|
|
| @@ -193,6 +246,7 @@ TEST_F(PresentationServiceImplTest, DidNavigateThisFrame) {
|
| base::Unretained(this)),
|
| true);
|
|
|
| + ExpectReset();
|
| service_impl_->DidNavigateAnyFrame(
|
| contents()->GetMainFrame(),
|
| content::LoadCommittedDetails(),
|
| @@ -232,6 +286,7 @@ TEST_F(PresentationServiceImplTest, ThisRenderFrameDeleted) {
|
| base::Unretained(this)),
|
| true);
|
|
|
| + ExpectReset();
|
| service_impl_->RenderFrameDeleted(contents()->GetMainFrame());
|
|
|
| ExpectListenerDoesNotExist(presentation_url);
|
| @@ -296,4 +351,136 @@ TEST_F(PresentationServiceImplTest, DelegateFails) {
|
| ExpectListenerDoesNotExist(presentation_url);
|
| }
|
|
|
| +TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrl) {
|
| + std::string url1("http://fooUrl");
|
| + EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url1)))
|
| + .Times(1);
|
| + service_impl_->SetDefaultPresentationUrl(url1);
|
| +
|
| + std::string url2("http://barUrl");
|
| + EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url2)))
|
| + .Times(1);
|
| + service_impl_->SetDefaultPresentationUrl(url2);
|
| +}
|
| +
|
| +TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) {
|
| + std::string url("http://fooUrl");
|
| + EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url)))
|
| + .Times(1);
|
| + service_impl_->SetDefaultPresentationUrl(url);
|
| + EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
|
| +
|
| + // Same URL as before; no-ops.
|
| + service_impl_->SetDefaultPresentationUrl(url);
|
| + EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
|
| +}
|
| +
|
| +TEST_F(PresentationServiceImplTest, ClearDefaultPresentationUrl) {
|
| + std::string url("http://fooUrl");
|
| + EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url)))
|
| + .Times(1);
|
| + service_impl_->SetDefaultPresentationUrl(url);
|
| +
|
| + // Clears the default presentation URL.
|
| + EXPECT_CALL(
|
| + mock_delegate_,
|
| + SetDefaultPresentationUrl(_, _, Eq(std::string())))
|
| + .Times(1);
|
| + service_impl_->SetDefaultPresentationUrl(std::string());
|
| + EXPECT_TRUE(service_impl_->default_presentation_url_.empty());
|
| +}
|
| +
|
| +TEST_F(PresentationServiceImplTest, StartSessionSuccess) {
|
| + std::string presentation_url("http://fooUrl");
|
| + std::string presentation_id("presentationId");
|
| + service_ptr_->StartSession(
|
| + presentation_url,
|
| + presentation_id,
|
| + base::Bind(
|
| + &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess,
|
| + base::Unretained(this)));
|
| + base::Callback<void(const PresentationSessionInfo&)> success_cb;
|
| + EXPECT_CALL(mock_delegate_, StartSession(
|
| + _, _, Eq(presentation_url), Eq(presentation_id), _, _))
|
| + .WillOnce(SaveArg<4>(&success_cb));
|
| + RunLoopUntilIdle();
|
| + success_cb.Run(PresentationSessionInfo(presentation_url, presentation_id));
|
| + SaveQuitClosureAndRunLoop();
|
| +}
|
| +
|
| +TEST_F(PresentationServiceImplTest, StartSessionError) {
|
| + std::string presentation_url("http://fooUrl");
|
| + std::string presentation_id("presentationId");
|
| + service_ptr_->StartSession(
|
| + presentation_url,
|
| + presentation_id,
|
| + base::Bind(
|
| + &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
|
| + base::Unretained(this)));
|
| + base::Callback<void(const PresentationError&)> error_cb;
|
| + EXPECT_CALL(mock_delegate_, StartSession(
|
| + _, _, Eq(presentation_url), Eq(presentation_id), _, _))
|
| + .WillOnce(SaveArg<5>(&error_cb));
|
| + RunLoopUntilIdle();
|
| + error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message"));
|
| + SaveQuitClosureAndRunLoop();
|
| +}
|
| +
|
| +TEST_F(PresentationServiceImplTest, JoinSessionSuccess) {
|
| + std::string presentation_url("http://fooUrl");
|
| + std::string presentation_id("presentationId");
|
| + service_ptr_->JoinSession(
|
| + presentation_url,
|
| + presentation_id,
|
| + base::Bind(
|
| + &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess,
|
| + base::Unretained(this)));
|
| + base::Callback<void(const PresentationSessionInfo&)> success_cb;
|
| + EXPECT_CALL(mock_delegate_, JoinSession(
|
| + _, _, Eq(presentation_url), Eq(presentation_id), _, _))
|
| + .WillOnce(SaveArg<4>(&success_cb));
|
| + RunLoopUntilIdle();
|
| + success_cb.Run(PresentationSessionInfo(presentation_url, presentation_id));
|
| + SaveQuitClosureAndRunLoop();
|
| +}
|
| +
|
| +TEST_F(PresentationServiceImplTest, JoinSessionError) {
|
| + std::string presentation_url("http://fooUrl");
|
| + std::string presentation_id("presentationId");
|
| + service_ptr_->JoinSession(
|
| + presentation_url,
|
| + presentation_id,
|
| + base::Bind(
|
| + &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
|
| + base::Unretained(this)));
|
| + base::Callback<void(const PresentationError&)> error_cb;
|
| + EXPECT_CALL(mock_delegate_, JoinSession(
|
| + _, _, Eq(presentation_url), Eq(presentation_id), _, _))
|
| + .WillOnce(SaveArg<5>(&error_cb));
|
| + RunLoopUntilIdle();
|
| + error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message"));
|
| + SaveQuitClosureAndRunLoop();
|
| +}
|
| +
|
| +TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
|
| + std::string presentation_url("http://fooUrl");
|
| + std::string presentation_id("presentationId");
|
| + service_ptr_->StartSession(
|
| + presentation_url,
|
| + presentation_id,
|
| + base::Bind(
|
| + &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess,
|
| + base::Unretained(this)));
|
| + service_ptr_->StartSession(
|
| + presentation_url,
|
| + presentation_id,
|
| + base::Bind(
|
| + &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess,
|
| + base::Unretained(this)));
|
| + EXPECT_CALL(mock_delegate_, StartSession(
|
| + _, _, Eq(presentation_url), Eq(presentation_id), _, _))
|
| + .Times(1);
|
| + RunLoopUntilIdle();
|
| +}
|
| +
|
| } // namespace content
|
|
|