Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1192)

Unified Diff: content/browser/presentation/presentation_service_impl_unittest.cc

Issue 1073893003: [Presentation API] Implement ondefaultsessionstart in PSImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use RunLoopFor Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 1f7f758405395f55c0f519d7aeba2e52f4302d3e..87c66b364090a273d0731c7031209748b8418a60 100644
--- a/content/browser/presentation/presentation_service_impl_unittest.cc
+++ b/content/browser/presentation/presentation_service_impl_unittest.cc
@@ -23,12 +23,23 @@ using ::testing::SaveArg;
namespace content {
+namespace {
+
+bool ArePresentationSessionsEqual(
+ const presentation::PresentationSessionInfo& expected,
+ const presentation::PresentationSessionInfo& actual) {
+ return expected.url == actual.url && expected.id == actual.id;
+}
+} // namespace
+
class MockPresentationServiceDelegate : public PresentationServiceDelegate {
public:
- MOCK_METHOD1(AddObserver,
- void(PresentationServiceDelegate::Observer* observer));
- MOCK_METHOD1(RemoveObserver,
- void(PresentationServiceDelegate::Observer* observer));
+ MOCK_METHOD3(AddObserver,
+ void(int render_process_id,
+ int render_frame_id,
+ PresentationServiceDelegate::Observer* observer));
+ MOCK_METHOD2(RemoveObserver,
+ void(int render_process_id, int render_frame_id));
MOCK_METHOD3(AddScreenAvailabilityListener,
bool(
int render_process_id,
@@ -69,13 +80,15 @@ class MockPresentationServiceDelegate : public PresentationServiceDelegate {
class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
public:
- PresentationServiceImplTest() : callback_count_(0) {}
+ PresentationServiceImplTest()
+ : callback_count_(0), default_session_started_count_(0) {}
void SetUp() override {
RenderViewHostImplTestHarness::SetUp();
auto request = mojo::GetProxy(&service_ptr_);
- EXPECT_CALL(mock_delegate_, AddObserver(_)).Times(1);
+
+ EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1);
service_impl_.reset(new PresentationServiceImpl(
contents()->GetMainFrame(), contents(), &mock_delegate_));
service_impl_->Bind(request.Pass());
@@ -84,11 +97,9 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
void TearDown() override {
service_ptr_.reset();
if (service_impl_.get()) {
- EXPECT_CALL(mock_delegate_, RemoveObserver(Eq(service_impl_.get())))
- .Times(1);
+ EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1);
service_impl_.reset();
}
-
RenderViewHostImplTestHarness::TearDown();
}
@@ -155,8 +166,7 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
}
void ExpectReset() {
- EXPECT_CALL(mock_delegate_, Reset(_, _))
- .Times(1);
+ EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1);
}
void ExpectCleanState() {
@@ -164,6 +174,7 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
EXPECT_TRUE(service_impl_->default_presentation_url_.empty());
EXPECT_TRUE(service_impl_->default_presentation_id_.empty());
EXPECT_TRUE(service_impl_->queued_start_session_requests_.empty());
+ EXPECT_FALSE(service_impl_->default_session_start_context_.get());
}
void ExpectNewSessionMojoCallbackSuccess(
@@ -184,11 +195,31 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
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();
+ }
+
MockPresentationServiceDelegate mock_delegate_;
scoped_ptr<PresentationServiceImpl> service_impl_;
mojo::InterfacePtr<presentation::PresentationService> service_ptr_;
base::Closure run_loop_quit_closure_;
int callback_count_;
+ int default_session_started_count_;
};
TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) {
@@ -294,7 +325,7 @@ TEST_F(PresentationServiceImplTest, ThisRenderFrameDeleted) {
// Since the frame matched the service, |service_impl_| will be deleted.
PresentationServiceImpl* service = service_impl_.release();
- EXPECT_CALL(mock_delegate_, RemoveObserver(Eq(service))).Times(1);
+ EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1);
service->RenderFrameDeleted(contents()->GetMainFrame());
}
@@ -581,4 +612,59 @@ TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
SaveQuitClosureAndRunLoop();
}
+TEST_F(PresentationServiceImplTest, ListenForDefaultSessionStart) {
+ std::string presentation_url1("http://fooUrl1");
+ std::string presentation_id1("presentationId1");
+ presentation::PresentationSessionInfo expected_session;
+ expected_session.url = presentation_url1;
+ expected_session.id = presentation_id1;
+ service_ptr_->ListenForDefaultSessionStart(
+ base::Bind(&PresentationServiceImplTest::ExpectDefaultSessionStarted,
+ base::Unretained(this),
+ expected_session));
+ RunLoopFor(base::TimeDelta::FromMilliseconds(50));
+ service_impl_->OnDefaultPresentationStarted(
+ content::PresentationSessionInfo(presentation_url1, presentation_id1));
+ 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)));
+ base::RunLoop().RunUntilIdle();
+
+ ExpectReset();
+ service_impl_->Reset();
+ ExpectCleanState();
+ SaveQuitClosureAndRunLoop();
+ EXPECT_EQ(1, default_session_started_count_);
+}
+
} // namespace content
« no previous file with comments | « content/browser/presentation/presentation_service_impl.cc ('k') | content/common/presentation/presentation_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698