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

Side by Side Diff: chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc

Issue 1430413003: [Media Router] Connection state change listening redesign part 2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/media/router/media_source.h" 8 #include "chrome/browser/media/router/media_source.h"
9 #include "chrome/browser/media/router/media_source_helper.h" 9 #include "chrome/browser/media/router/media_source_helper.h"
10 #include "chrome/browser/media/router/mock_media_router.h" 10 #include "chrome/browser/media/router/mock_media_router.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 ChromeRenderViewHostTestHarness::SetUp(); 52 ChromeRenderViewHostTestHarness::SetUp();
53 content::WebContents* wc = web_contents(); 53 content::WebContents* wc = web_contents();
54 ASSERT_TRUE(wc); 54 ASSERT_TRUE(wc);
55 PresentationServiceDelegateImpl::CreateForWebContents(wc); 55 PresentationServiceDelegateImpl::CreateForWebContents(wc);
56 delegate_impl_ = PresentationServiceDelegateImpl::FromWebContents(wc); 56 delegate_impl_ = PresentationServiceDelegateImpl::FromWebContents(wc);
57 delegate_impl_->SetMediaRouterForTest(&router_); 57 delegate_impl_->SetMediaRouterForTest(&router_);
58 } 58 }
59 59
60 MOCK_METHOD1(OnDefaultPresentationStarted, 60 MOCK_METHOD1(OnDefaultPresentationStarted,
61 void(const content::PresentationSessionInfo& session_info)); 61 void(const content::PresentationSessionInfo& session_info));
62 MOCK_METHOD1(OnCreateConnectionSuccess,
63 void(const content::PresentationSessionInfo& connection));
64 MOCK_METHOD1(OnCreateConnectionError,
65 void(const content::PresentationError& error));
66 MOCK_METHOD2(OnPresentationConnectionStateChanged,
67 void(const content::PresentationSessionInfo& connection,
68 content::PresentationConnectionState state));
62 69
63 PresentationServiceDelegateImpl* delegate_impl_; 70 PresentationServiceDelegateImpl* delegate_impl_;
64 MockMediaRouter router_; 71 MockMediaRouter router_;
65 }; 72 };
66 73
67 TEST_F(PresentationServiceDelegateImplTest, AddScreenAvailabilityListener) { 74 TEST_F(PresentationServiceDelegateImplTest, AddScreenAvailabilityListener) {
68 ON_CALL(router_, RegisterMediaSinksObserver(_)).WillByDefault(Return(true)); 75 ON_CALL(router_, RegisterMediaSinksObserver(_)).WillByDefault(Return(true));
69 76
70 std::string presentation_url1("http://url1.fakeUrl"); 77 std::string presentation_url1("http://url1.fakeUrl");
71 std::string presentation_url2("http://url2.fakeUrl"); 78 std::string presentation_url2("http://url2.fakeUrl");
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 render_process_id, render_frame_id, source1.id())); 125 render_process_id, render_frame_id, source1.id()));
119 126
120 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(1); 127 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(1);
121 delegate_impl_->RemoveScreenAvailabilityListener(render_process_id, 128 delegate_impl_->RemoveScreenAvailabilityListener(render_process_id,
122 render_frame_id, &listener1); 129 render_frame_id, &listener1);
123 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( 130 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest(
124 render_process_id, render_frame_id, source1.id())); 131 render_process_id, render_frame_id, source1.id()));
125 } 132 }
126 133
127 // TODO(imcheng): Add a test to set default presentation URL in a different 134 // TODO(imcheng): Add a test to set default presentation URL in a different
128 // RenderFrameHost and verify that it works. 135 // RenderFrameHost and verify that it is ignored.
129 TEST_F(PresentationServiceDelegateImplTest, SetDefaultPresentationUrl) { 136 TEST_F(PresentationServiceDelegateImplTest, SetDefaultPresentationUrl) {
130 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest()); 137 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest());
131 138
132 GURL frame_url("http://www.google.com"); 139 GURL frame_url("http://www.google.com");
133 content::WebContentsTester::For(web_contents())->NavigateAndCommit(frame_url); 140 content::WebContentsTester::For(web_contents())->NavigateAndCommit(frame_url);
134 content::RenderFrameHost* main_frame = web_contents()->GetMainFrame(); 141 content::RenderFrameHost* main_frame = web_contents()->GetMainFrame();
135 ASSERT_TRUE(main_frame); 142 ASSERT_TRUE(main_frame);
136 int render_process_id = main_frame->GetProcess()->GetID(); 143 int render_process_id = main_frame->GetProcess()->GetID();
137 int routing_id = main_frame->GetRoutingID(); 144 int routing_id = main_frame->GetRoutingID();
138 145
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 EXPECT_TRUE(request2.Equals(observed_request2)); 258 EXPECT_TRUE(request2.Equals(observed_request2));
252 259
253 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); 260 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer));
254 261
255 // Remove default presentation URL. 262 // Remove default presentation URL.
256 EXPECT_CALL(observer, OnDefaultPresentationRemoved()).Times(1); 263 EXPECT_CALL(observer, OnDefaultPresentationRemoved()).Times(1);
257 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, "", 264 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, "",
258 callback); 265 callback);
259 } 266 }
260 267
268 TEST_F(PresentationServiceDelegateImplTest, ListenForConnnectionStateChange) {
269 GURL frame_url("http://www.google.com");
270 content::WebContentsTester::For(web_contents())->NavigateAndCommit(frame_url);
271 content::RenderFrameHost* main_frame = web_contents()->GetMainFrame();
272 ASSERT_TRUE(main_frame);
273 int render_process_id = main_frame->GetProcess()->GetID();
274 int routing_id = main_frame->GetRoutingID();
275
276 // Set up a PresentationConnection so we can listen to it.
277 std::vector<MediaRouteResponseCallback> callbacks;
278 EXPECT_CALL(router_, JoinRoute(_, _, _, _, _))
279 .WillOnce(SaveArg<4>(&callbacks));
280
281 const std::string kPresentationUrl("http://url1.fakeUrl");
282 const std::string kPresentationId("pid");
283 delegate_impl_->JoinSession(
284 render_process_id, routing_id, kPresentationUrl, kPresentationId,
285 base::Bind(
286 &PresentationServiceDelegateImplTest::OnCreateConnectionSuccess,
287 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
288 base::Bind(&PresentationServiceDelegateImplTest::OnCreateConnectionError,
289 base::Unretained(this)));
290
291 EXPECT_CALL(*this, OnCreateConnectionSuccess(_)).Times(1);
292 MediaRoute route("routeId", MediaSourceForPresentationUrl(kPresentationUrl),
293 "mediaSinkId", "description", true, "", true);
294 for (const auto& callback : callbacks)
295 callback.Run(&route, kPresentationId, "");
296
297 content::PresentationSessionInfo connection(kPresentationUrl,
298 kPresentationId);
299 PresentationConnectionStateObserver* state_observer = nullptr;
300 EXPECT_CALL(router_, RegisterPresentationConnectionStateObserver(_))
301 .WillOnce(SaveArg<0>(&state_observer));
302 delegate_impl_->ListenForConnectionStateChange(
303 render_process_id, routing_id, connection,
304 base::Bind(&PresentationServiceDelegateImplTest::
305 OnPresentationConnectionStateChanged,
306 base::Unretained(this)));
307 ASSERT_TRUE(state_observer);
308 EXPECT_EQ(route.media_route_id(), state_observer->route_id());
309
310 EXPECT_CALL(*this, OnPresentationConnectionStateChanged(
311 _, content::PRESENTATION_CONNECTION_STATE_CLOSED))
312 .Times(1);
313 state_observer->OnStateChanged(content::PRESENTATION_CONNECTION_STATE_CLOSED);
314
315 EXPECT_CALL(*this, OnPresentationConnectionStateChanged(
316 _, 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
317 .Times(1);
318 state_observer->OnStateChanged(
319 content::PRESENTATION_CONNECTION_STATE_TERMINATED);
320 }
321
261 TEST_F(PresentationServiceDelegateImplTest, Reset) { 322 TEST_F(PresentationServiceDelegateImplTest, Reset) {
262 ON_CALL(router_, RegisterMediaSinksObserver(_)).WillByDefault(Return(true)); 323 ON_CALL(router_, RegisterMediaSinksObserver(_)).WillByDefault(Return(true));
263 324
264 std::string presentation_url1("http://url1.fakeUrl"); 325 std::string presentation_url1("http://url1.fakeUrl");
265 MediaSource source = MediaSourceForPresentationUrl(presentation_url1); 326 MediaSource source = MediaSourceForPresentationUrl(presentation_url1);
266 MockScreenAvailabilityListener listener1(presentation_url1); 327 MockScreenAvailabilityListener listener1(presentation_url1);
267 int render_process_id = 1; 328 int render_process_id = 1;
268 int render_frame_id = 0; 329 int render_frame_id = 0;
269 330
270 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( 331 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 MockScreenAvailabilityListener listener(presentation_url); 363 MockScreenAvailabilityListener listener(presentation_url);
303 const int render_process_id = 10; 364 const int render_process_id = 10;
304 const int render_frame_id = 1; 365 const int render_frame_id = 1;
305 366
306 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).Times(1); 367 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).Times(1);
307 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( 368 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener(
308 render_process_id, render_frame_id, &listener)); 369 render_process_id, render_frame_id, &listener));
309 } 370 }
310 371
311 } // namespace media_router 372 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698