Index: chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc |
diff --git a/chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc b/chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc |
index c3099aa275a5fa1437808d4b883315795b15b95e..7a1e1c99be60f5f59aca76a1fd6f4e33984a5617 100644 |
--- a/chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc |
+++ b/chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc |
@@ -59,6 +59,13 @@ class PresentationServiceDelegateImplTest |
MOCK_METHOD1(OnDefaultPresentationStarted, |
void(const content::PresentationSessionInfo& session_info)); |
+ MOCK_METHOD1(OnCreateConnectionSuccess, |
+ void(const content::PresentationSessionInfo& connection)); |
+ MOCK_METHOD1(OnCreateConnectionError, |
+ void(const content::PresentationError& error)); |
+ MOCK_METHOD2(OnPresentationConnectionStateChanged, |
+ void(const content::PresentationSessionInfo& connection, |
+ content::PresentationConnectionState state)); |
PresentationServiceDelegateImpl* delegate_impl_; |
MockMediaRouter router_; |
@@ -125,7 +132,7 @@ TEST_F(PresentationServiceDelegateImplTest, AddSameListenerTwice) { |
} |
// TODO(imcheng): Add a test to set default presentation URL in a different |
-// RenderFrameHost and verify that it works. |
+// RenderFrameHost and verify that it is ignored. |
TEST_F(PresentationServiceDelegateImplTest, SetDefaultPresentationUrl) { |
EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest()); |
@@ -258,6 +265,60 @@ TEST_F(PresentationServiceDelegateImplTest, |
callback); |
} |
+TEST_F(PresentationServiceDelegateImplTest, ListenForConnnectionStateChange) { |
+ GURL frame_url("http://www.google.com"); |
+ content::WebContentsTester::For(web_contents())->NavigateAndCommit(frame_url); |
+ content::RenderFrameHost* main_frame = web_contents()->GetMainFrame(); |
+ ASSERT_TRUE(main_frame); |
+ int render_process_id = main_frame->GetProcess()->GetID(); |
+ int routing_id = main_frame->GetRoutingID(); |
+ |
+ // Set up a PresentationConnection so we can listen to it. |
+ std::vector<MediaRouteResponseCallback> callbacks; |
+ EXPECT_CALL(router_, JoinRoute(_, _, _, _, _)) |
+ .WillOnce(SaveArg<4>(&callbacks)); |
+ |
+ const std::string kPresentationUrl("http://url1.fakeUrl"); |
+ const std::string kPresentationId("pid"); |
+ delegate_impl_->JoinSession( |
+ render_process_id, routing_id, kPresentationUrl, kPresentationId, |
+ base::Bind( |
+ &PresentationServiceDelegateImplTest::OnCreateConnectionSuccess, |
+ base::Unretained(this)), |
mark a. foltz
2015/11/12 04:19:38
It's a little weird to bind callbacks to the test
imcheng
2015/11/16 23:52:01
Done. I refactored the mock object into test_helpe
|
+ base::Bind(&PresentationServiceDelegateImplTest::OnCreateConnectionError, |
+ base::Unretained(this))); |
+ |
+ EXPECT_CALL(*this, OnCreateConnectionSuccess(_)).Times(1); |
+ MediaRoute route("routeId", MediaSourceForPresentationUrl(kPresentationUrl), |
+ "mediaSinkId", "description", true, "", true); |
+ for (const auto& callback : callbacks) |
+ callback.Run(&route, kPresentationId, ""); |
+ |
+ content::PresentationSessionInfo connection(kPresentationUrl, |
+ kPresentationId); |
+ PresentationConnectionStateObserver* state_observer = nullptr; |
+ EXPECT_CALL(router_, RegisterPresentationConnectionStateObserver(_)) |
+ .WillOnce(SaveArg<0>(&state_observer)); |
+ delegate_impl_->ListenForConnectionStateChange( |
+ render_process_id, routing_id, connection, |
+ base::Bind(&PresentationServiceDelegateImplTest:: |
+ OnPresentationConnectionStateChanged, |
+ base::Unretained(this))); |
+ ASSERT_TRUE(state_observer); |
+ EXPECT_EQ(route.media_route_id(), state_observer->route_id()); |
+ |
+ EXPECT_CALL(*this, OnPresentationConnectionStateChanged( |
+ _, content::PRESENTATION_CONNECTION_STATE_CLOSED)) |
+ .Times(1); |
+ state_observer->OnStateChanged(content::PRESENTATION_CONNECTION_STATE_CLOSED); |
+ |
+ EXPECT_CALL(*this, OnPresentationConnectionStateChanged( |
+ _, content::PRESENTATION_CONNECTION_STATE_TERMINATED)) |
mark a. foltz
2015/11/12 04:19:38
Strictly speaking, CLOSED is a terminal state for
imcheng
2015/11/16 23:52:01
Ack. That part has been moved to media_router_mojo
|
+ .Times(1); |
+ state_observer->OnStateChanged( |
+ content::PRESENTATION_CONNECTION_STATE_TERMINATED); |
+} |
+ |
TEST_F(PresentationServiceDelegateImplTest, Reset) { |
ON_CALL(router_, RegisterMediaSinksObserver(_)).WillByDefault(Return(true)); |