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 b85fc8415baa99ee605b5a1ac4413af414eb5c06..3716586eb157f4ca2544b6f50bb014d8a4baa07e 100644 |
--- a/content/browser/presentation/presentation_service_impl_unittest.cc |
+++ b/content/browser/presentation/presentation_service_impl_unittest.cc |
@@ -41,6 +41,12 @@ |
const char *const kPresentationId = "presentationId"; |
const char *const kPresentationUrl = "http://foo.com/index.html"; |
+bool ArePresentationSessionsEqual( |
+ const presentation::PresentationSessionInfo& expected, |
+ const presentation::PresentationSessionInfo& actual) { |
+ return expected.url == actual.url && expected.id == actual.id; |
+} |
+ |
bool ArePresentationSessionMessagesEqual( |
const presentation::SessionMessage* expected, |
const presentation::SessionMessage* actual) { |
@@ -85,24 +91,26 @@ |
void( |
int render_process_id, |
int routing_id)); |
- MOCK_METHOD4(SetDefaultPresentationUrl, |
- void(int render_process_id, |
- int routing_id, |
- const std::string& default_presentation_url, |
- const PresentationSessionStartedCallback& callback)); |
+ MOCK_METHOD3(SetDefaultPresentationUrl, |
+ void( |
+ int render_process_id, |
+ int routing_id, |
+ const std::string& default_presentation_url)); |
MOCK_METHOD5(StartSession, |
- void(int render_process_id, |
- int render_frame_id, |
- const std::string& presentation_url, |
- const PresentationSessionStartedCallback& success_cb, |
- const PresentationSessionErrorCallback& error_cb)); |
+ void( |
+ int render_process_id, |
+ int render_frame_id, |
+ const std::string& presentation_url, |
+ 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 PresentationSessionStartedCallback& success_cb, |
- const PresentationSessionErrorCallback& error_cb)); |
+ 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_METHOD3(CloseSession, |
void(int render_process_id, |
int render_frame_id, |
@@ -164,13 +172,6 @@ |
} |
MOCK_METHOD0(MessagesReceived, void()); |
- void OnDefaultSessionStarted( |
- presentation::PresentationSessionInfoPtr session_info) override { |
- OnDefaultSessionStarted(*session_info); |
- } |
- MOCK_METHOD1(OnDefaultSessionStarted, |
- void(const presentation::PresentationSessionInfo& session_info)); |
- |
mojo::Array<presentation::SessionMessagePtr> messages_received_; |
}; |
@@ -256,6 +257,7 @@ |
EXPECT_EQ( |
service_impl_->screen_availability_listeners_.find(kPresentationUrl), |
service_impl_->screen_availability_listeners_.end()); |
+ EXPECT_FALSE(service_impl_->default_session_start_context_.get()); |
EXPECT_FALSE(service_impl_->on_session_messages_callback_.get()); |
} |
@@ -273,6 +275,25 @@ |
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(); |
+ } |
+ |
+ void ExpectDefaultSessionStarted( |
+ const presentation::PresentationSessionInfo& expected_session, |
+ presentation::PresentationSessionInfoPtr actual_session) { |
+ ASSERT_TRUE(!actual_session.is_null()); |
+ EXPECT_TRUE(ArePresentationSessionsEqual( |
+ expected_session, *actual_session)); |
+ ++default_session_started_count_; |
+ if (!run_loop_quit_closure_.is_null()) |
+ run_loop_quit_closure_.Run(); |
+ } |
+ |
+ void ExpectDefaultSessionNull( |
+ presentation::PresentationSessionInfoPtr actual_session) { |
+ EXPECT_TRUE(actual_session.is_null()); |
+ ++default_session_started_count_; |
if (!run_loop_quit_closure_.is_null()) |
run_loop_quit_closure_.Run(); |
} |
@@ -429,30 +450,24 @@ |
TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrl) { |
std::string url1("http://fooUrl"); |
- EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url1), _)) |
+ EXPECT_CALL(mock_delegate_, |
+ SetDefaultPresentationUrl(_, _, Eq(url1))) |
.Times(1); |
service_impl_->SetDefaultPresentationURL(url1); |
EXPECT_EQ(url1, service_impl_->default_presentation_url_); |
std::string url2("http://barUrl"); |
// Sets different DPU. |
- content::PresentationSessionStartedCallback callback; |
- EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url2), _)) |
- .WillOnce(SaveArg<3>(&callback)); |
+ EXPECT_CALL(mock_delegate_, |
+ SetDefaultPresentationUrl(_, _, Eq(url2))) |
+ .Times(1); |
service_impl_->SetDefaultPresentationURL(url2); |
EXPECT_EQ(url2, service_impl_->default_presentation_url_); |
- |
- presentation::PresentationSessionInfo session_info; |
- session_info.url = url2; |
- session_info.id = kPresentationId; |
- EXPECT_CALL(mock_client_, OnDefaultSessionStarted(Equals(session_info))) |
- .Times(1); |
- callback.Run(content::PresentationSessionInfo(url2, kPresentationId)); |
} |
TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { |
EXPECT_CALL(mock_delegate_, |
- SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl), _)) |
+ SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl))) |
.Times(1); |
service_impl_->SetDefaultPresentationURL(kPresentationUrl); |
EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
@@ -575,6 +590,59 @@ |
&PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, |
base::Unretained(this))); |
SaveQuitClosureAndRunLoop(); |
+} |
+ |
+TEST_F(PresentationServiceImplTest, ListenForDefaultSessionStart) { |
+ presentation::PresentationSessionInfo expected_session; |
+ expected_session.url = kPresentationUrl; |
+ expected_session.id = kPresentationId; |
+ service_ptr_->ListenForDefaultSessionStart( |
+ base::Bind(&PresentationServiceImplTest::ExpectDefaultSessionStarted, |
+ base::Unretained(this), |
+ expected_session)); |
+ RunLoopFor(base::TimeDelta::FromMilliseconds(50)); |
+ service_impl_->OnDefaultPresentationStarted( |
+ content::PresentationSessionInfo(kPresentationUrl, kPresentationId)); |
+ SaveQuitClosureAndRunLoop(); |
+ EXPECT_EQ(1, default_session_started_count_); |
+} |
+ |
+TEST_F(PresentationServiceImplTest, ListenForDefaultSessionStartAfterSet) { |
+ // Note that the callback will only pick up presentation_url2/id2 since |
+ // ListenForDefaultSessionStart wasn't called yet when the DPU was still |
+ // presentation_url1. |
+ std::string presentation_url1("http://fooUrl1"); |
+ std::string presentation_id1("presentationId1"); |
+ std::string presentation_url2("http://fooUrl2"); |
+ std::string presentation_id2("presentationId2"); |
+ service_impl_->OnDefaultPresentationStarted( |
+ content::PresentationSessionInfo(presentation_url1, presentation_id1)); |
+ |
+ presentation::PresentationSessionInfo expected_session; |
+ expected_session.url = presentation_url2; |
+ expected_session.id = presentation_id2; |
+ service_ptr_->ListenForDefaultSessionStart( |
+ base::Bind(&PresentationServiceImplTest::ExpectDefaultSessionStarted, |
+ base::Unretained(this), |
+ expected_session)); |
+ RunLoopFor(base::TimeDelta::FromMilliseconds(50)); |
+ service_impl_->OnDefaultPresentationStarted( |
+ content::PresentationSessionInfo(presentation_url2, presentation_id2)); |
+ SaveQuitClosureAndRunLoop(); |
+ EXPECT_EQ(1, default_session_started_count_); |
+} |
+ |
+TEST_F(PresentationServiceImplTest, DefaultSessionStartReset) { |
+ service_ptr_->ListenForDefaultSessionStart( |
+ base::Bind(&PresentationServiceImplTest::ExpectDefaultSessionNull, |
+ base::Unretained(this))); |
+ RunLoopFor(TestTimeouts::tiny_timeout()); |
+ |
+ ExpectReset(); |
+ service_impl_->Reset(); |
+ ExpectCleanState(); |
+ SaveQuitClosureAndRunLoop(); |
+ EXPECT_EQ(1, default_session_started_count_); |
} |
TEST_F(PresentationServiceImplTest, SendStringMessage) { |