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

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

Issue 2174693004: [Presentation API] Add support to content/ for multiple URLs per PresentationRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update service, dispatcher to use Mojo URLs. Created 4 years, 4 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 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 "chrome/browser/media/router/presentation_service_delegate_impl.h" 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h"
6 6
7 #include <vector>
8
9 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
10 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/media/router/media_source.h" 9 #include "chrome/browser/media/router/media_source.h"
12 #include "chrome/browser/media/router/media_source_helper.h" 10 #include "chrome/browser/media/router/media_source_helper.h"
13 #include "chrome/browser/media/router/mock_media_router.h" 11 #include "chrome/browser/media/router/mock_media_router.h"
14 #include "chrome/browser/media/router/mock_screen_availability_listener.h" 12 #include "chrome/browser/media/router/mock_screen_availability_listener.h"
15 #include "chrome/browser/media/router/route_request_result.h" 13 #include "chrome/browser/media/router/route_request_result.h"
16 #include "chrome/browser/media/router/test_helper.h" 14 #include "chrome/browser/media/router/test_helper.h"
17 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 78
81 void RunDefaultPresentationUrlCallbackTest(bool incognito) { 79 void RunDefaultPresentationUrlCallbackTest(bool incognito) {
82 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); 80 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
83 ASSERT_TRUE(main_frame); 81 ASSERT_TRUE(main_frame);
84 int render_process_id = main_frame->GetProcess()->GetID(); 82 int render_process_id = main_frame->GetProcess()->GetID();
85 int routing_id = main_frame->GetRoutingID(); 83 int routing_id = main_frame->GetRoutingID();
86 84
87 auto callback = base::Bind( 85 auto callback = base::Bind(
88 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, 86 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted,
89 base::Unretained(this)); 87 base::Unretained(this));
88 std::vector<std::string> urls(1);
dcheng 2016/08/26 18:13:33 std::vector<std::string> urls = {"http://foo.fakeU
mark a. foltz 2016/08/29 23:54:54 Done.
90 std::string presentation_url1("http://foo.fakeUrl"); 89 std::string presentation_url1("http://foo.fakeUrl");
91 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, 90 urls[0] = presentation_url1;
92 presentation_url1, callback); 91 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id,
92 urls, callback);
93 93
94 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); 94 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest());
95 PresentationRequest request = 95 PresentationRequest request =
96 delegate_impl_->GetDefaultPresentationRequest(); 96 delegate_impl_->GetDefaultPresentationRequest();
97 97
98 // Should not trigger callback since route response is error. 98 // Should not trigger callback since route response is error.
99 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( 99 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError(
100 "Error", RouteRequestResult::UNKNOWN_ERROR); 100 "Error", RouteRequestResult::UNKNOWN_ERROR);
101 delegate_impl_->OnRouteResponse(request, *result); 101 delegate_impl_->OnRouteResponse(request, *result);
102 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); 102 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this));
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 ->NavigateAndCommit(frame_url); 270 ->NavigateAndCommit(frame_url);
271 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); 271 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
272 ASSERT_TRUE(main_frame); 272 ASSERT_TRUE(main_frame);
273 int render_process_id = main_frame->GetProcess()->GetID(); 273 int render_process_id = main_frame->GetProcess()->GetID();
274 int routing_id = main_frame->GetRoutingID(); 274 int routing_id = main_frame->GetRoutingID();
275 275
276 auto callback = base::Bind( 276 auto callback = base::Bind(
277 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, 277 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted,
278 base::Unretained(this)); 278 base::Unretained(this));
279 std::string presentation_url1("http://foo.fakeUrl"); 279 std::string presentation_url1("http://foo.fakeUrl");
280 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, 280 std::vector<std::string> urls(1);
281 presentation_url1, callback); 281 urls[0] = presentation_url1;
282 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id,
283 urls, callback);
282 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); 284 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest());
283 PresentationRequest request1 = 285 PresentationRequest request1 =
284 delegate_impl_->GetDefaultPresentationRequest(); 286 delegate_impl_->GetDefaultPresentationRequest();
285 EXPECT_EQ(presentation_url1, request1.presentation_url()); 287 EXPECT_EQ(presentation_url1, request1.presentation_url());
286 EXPECT_EQ(RenderFrameHostId(render_process_id, routing_id), 288 EXPECT_EQ(RenderFrameHostId(render_process_id, routing_id),
287 request1.render_frame_host_id()); 289 request1.render_frame_host_id());
288 EXPECT_EQ(frame_url, request1.frame_url()); 290 EXPECT_EQ(frame_url, request1.frame_url());
289 291
290 // Set to a new default presentation URL 292 // Set to a new default presentation URL
291 std::string presentation_url2("https://youtube.com"); 293 std::string presentation_url2("https://youtube.com");
292 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, 294 urls[0] = presentation_url2;
293 presentation_url2, callback); 295 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id,
296 urls, callback);
294 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); 297 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest());
295 PresentationRequest request2 = 298 PresentationRequest request2 =
296 delegate_impl_->GetDefaultPresentationRequest(); 299 delegate_impl_->GetDefaultPresentationRequest();
297 EXPECT_EQ(presentation_url2, request2.presentation_url()); 300 EXPECT_EQ(presentation_url2, request2.presentation_url());
298 EXPECT_EQ(RenderFrameHostId(render_process_id, routing_id), 301 EXPECT_EQ(RenderFrameHostId(render_process_id, routing_id),
299 request2.render_frame_host_id()); 302 request2.render_frame_host_id());
300 EXPECT_EQ(frame_url, request2.frame_url()); 303 EXPECT_EQ(frame_url, request2.frame_url());
301 304
302 // Remove default presentation URL. 305 // Remove default presentation URL.
303 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, "", 306 delegate_impl_->SetDefaultPresentationUrls(
304 callback); 307 render_process_id, routing_id, std::vector<std::string>(), callback);
305 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest()); 308 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest());
306 } 309 }
307 310
308 TEST_F(PresentationServiceDelegateImplTest, DefaultPresentationUrlCallback) { 311 TEST_F(PresentationServiceDelegateImplTest, DefaultPresentationUrlCallback) {
309 RunDefaultPresentationUrlCallbackTest(false); 312 RunDefaultPresentationUrlCallbackTest(false);
310 } 313 }
311 314
312 TEST_F(PresentationServiceDelegateImplIncognitoTest, 315 TEST_F(PresentationServiceDelegateImplIncognitoTest,
313 DefaultPresentationUrlCallback) { 316 DefaultPresentationUrlCallback) {
314 RunDefaultPresentationUrlCallbackTest(true); 317 RunDefaultPresentationUrlCallbackTest(true);
(...skipping 14 matching lines...) Expand all
329 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); 332 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
330 ASSERT_TRUE(main_frame); 333 ASSERT_TRUE(main_frame);
331 int render_process_id = main_frame->GetProcess()->GetID(); 334 int render_process_id = main_frame->GetProcess()->GetID();
332 int routing_id = main_frame->GetRoutingID(); 335 int routing_id = main_frame->GetRoutingID();
333 336
334 std::string url1("http://foo.fakeUrl"); 337 std::string url1("http://foo.fakeUrl");
335 PresentationRequest observed_request1( 338 PresentationRequest observed_request1(
336 RenderFrameHostId(render_process_id, routing_id), url1, frame_url); 339 RenderFrameHostId(render_process_id, routing_id), url1, frame_url);
337 EXPECT_CALL(observer, OnDefaultPresentationChanged(Equals(observed_request1))) 340 EXPECT_CALL(observer, OnDefaultPresentationChanged(Equals(observed_request1)))
338 .Times(1); 341 .Times(1);
339 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, url1, 342 std::vector<std::string> urls(1);
340 callback); 343 urls[0] = url1;
344 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id,
345 urls, callback);
341 346
342 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); 347 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest());
343 PresentationRequest request1 = 348 PresentationRequest request1 =
344 delegate_impl_->GetDefaultPresentationRequest(); 349 delegate_impl_->GetDefaultPresentationRequest();
345 EXPECT_TRUE(request1.Equals(observed_request1)); 350 EXPECT_TRUE(request1.Equals(observed_request1));
346 351
347 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); 352 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer));
348 353
349 std::string url2("http://youtube.com"); 354 std::string url2("http://youtube.com");
350 PresentationRequest observed_request2( 355 PresentationRequest observed_request2(
351 RenderFrameHostId(render_process_id, routing_id), url2, frame_url); 356 RenderFrameHostId(render_process_id, routing_id), url2, frame_url);
352 EXPECT_CALL(observer, OnDefaultPresentationChanged(Equals(observed_request2))) 357 EXPECT_CALL(observer, OnDefaultPresentationChanged(Equals(observed_request2)))
353 .Times(1); 358 .Times(1);
354 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, url2, 359 urls[0] = url2;
355 callback); 360 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id,
361 urls, callback);
356 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); 362 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest());
357 PresentationRequest request2 = 363 PresentationRequest request2 =
358 delegate_impl_->GetDefaultPresentationRequest(); 364 delegate_impl_->GetDefaultPresentationRequest();
359 EXPECT_TRUE(request2.Equals(observed_request2)); 365 EXPECT_TRUE(request2.Equals(observed_request2));
360 366
361 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); 367 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer));
362 368
363 // Remove default presentation URL. 369 // Remove default presentation URL.
364 EXPECT_CALL(observer, OnDefaultPresentationRemoved()).Times(1); 370 EXPECT_CALL(observer, OnDefaultPresentationRemoved()).Times(1);
365 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, "", 371 delegate_impl_->SetDefaultPresentationUrls(
366 callback); 372 render_process_id, routing_id, std::vector<std::string>(), callback);
dcheng 2016/08/26 18:13:33 Similarly, you can just put "{}" here instead of w
mark a. foltz 2016/08/29 23:54:54 It doesn't allow you to take a reference to a temp
367 } 373 }
368 374
369 TEST_F(PresentationServiceDelegateImplTest, ListenForConnnectionStateChange) { 375 TEST_F(PresentationServiceDelegateImplTest, ListenForConnnectionStateChange) {
370 GURL frame_url("http://www.google.com"); 376 GURL frame_url("http://www.google.com");
371 content::WebContentsTester::For(GetWebContents()) 377 content::WebContentsTester::For(GetWebContents())
372 ->NavigateAndCommit(frame_url); 378 ->NavigateAndCommit(frame_url);
373 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); 379 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
374 ASSERT_TRUE(main_frame); 380 ASSERT_TRUE(main_frame);
375 int render_process_id = main_frame->GetProcess()->GetID(); 381 int render_process_id = main_frame->GetProcess()->GetID();
376 int routing_id = main_frame->GetRoutingID(); 382 int routing_id = main_frame->GetRoutingID();
377 383
378 // Set up a PresentationConnection so we can listen to it. 384 // Set up a PresentationConnection so we can listen to it.
379 std::vector<MediaRouteResponseCallback> route_response_callbacks; 385 std::vector<MediaRouteResponseCallback> route_response_callbacks;
380 EXPECT_CALL(router_, JoinRoute(_, _, _, _, _, _, false)) 386 EXPECT_CALL(router_, JoinRoute(_, _, _, _, _, _, false))
381 .WillOnce(SaveArg<4>(&route_response_callbacks)); 387 .WillOnce(SaveArg<4>(&route_response_callbacks));
382 388
383 const std::string kPresentationUrl("http://url1.fakeUrl"); 389 const std::string kPresentationUrl("http://url1.fakeUrl");
384 const std::string kPresentationId("pid"); 390 const std::string kPresentationId("pid");
391 std::vector<std::string> urls(1);
392 urls[0] = kPresentationUrl;
385 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; 393 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks;
386 delegate_impl_->JoinSession( 394 delegate_impl_->JoinSession(
387 render_process_id, routing_id, kPresentationUrl, kPresentationId, 395 render_process_id, routing_id, urls, kPresentationId,
388 base::Bind(&MockCreatePresentationConnnectionCallbacks:: 396 base::Bind(&MockCreatePresentationConnnectionCallbacks::
389 OnCreateConnectionSuccess, 397 OnCreateConnectionSuccess,
390 base::Unretained(&mock_create_connection_callbacks)), 398 base::Unretained(&mock_create_connection_callbacks)),
391 base::Bind( 399 base::Bind(
392 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, 400 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError,
393 base::Unretained(&mock_create_connection_callbacks))); 401 base::Unretained(&mock_create_connection_callbacks)));
394 402
395 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_)) 403 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_))
396 .Times(1); 404 .Times(1);
397 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess( 405 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 int render_process_id = main_frame->GetProcess()->GetID(); 471 int render_process_id = main_frame->GetProcess()->GetID();
464 int render_frame_id = main_frame->GetRoutingID(); 472 int render_frame_id = main_frame->GetRoutingID();
465 473
466 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); 474 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false));
467 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); 475 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported());
468 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( 476 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener(
469 render_process_id, render_frame_id, &listener)); 477 render_process_id, render_frame_id, &listener));
470 } 478 }
471 479
472 } // namespace media_router 480 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698