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

Side by Side Diff: chrome/browser/media/router/mojo/media_router_mojo_impl_unittest.cc

Issue 1911183002: [Media Router] Implement an internal Media Routes observer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 std::vector<MediaRouteResponseCallback> route_response_callbacks; 298 std::vector<MediaRouteResponseCallback> route_response_callbacks;
299 route_response_callbacks.push_back(base::Bind( 299 route_response_callbacks.push_back(base::Bind(
300 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); 300 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
301 router()->CreateRoute( 301 router()->CreateRoute(
302 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, 302 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks,
303 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); 303 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true);
304 run_loop.Run(); 304 run_loop.Run();
305 } 305 }
306 306
307 TEST_F(MediaRouterMojoImplTest, OffTheRecordRoutesTerminatedOnProfileShutdown) { 307 TEST_F(MediaRouterMojoImplTest, OffTheRecordRoutesTerminatedOnProfileShutdown) {
308 interfaces::MediaRoutePtr route = interfaces::MediaRoute::New();
309 route->media_source = kSource;
310 route->media_sink_id = kSinkId;
311 route->media_route_id = kRouteId;
312 route->description = kDescription;
313 route->is_local = true;
314 route->for_display = true;
315 route->off_the_record = true;
316
308 EXPECT_CALL(mock_media_route_provider_, 317 EXPECT_CALL(mock_media_route_provider_,
309 CreateRoute(mojo::String(kSource), mojo::String(kSinkId), _, 318 CreateRoute(mojo::String(kSource), mojo::String(kSinkId), _,
310 mojo::String(kOrigin), kInvalidTabId, kTimeoutMillis, 319 mojo::String(kOrigin), kInvalidTabId, kTimeoutMillis,
311 true, _)) 320 true, _))
312 .WillOnce(Invoke( 321 .WillOnce(Invoke(
313 [](const mojo::String& source, const mojo::String& sink, 322 [](const mojo::String& source, const mojo::String& sink,
314 const mojo::String& presentation_id, const mojo::String& origin, 323 const mojo::String& presentation_id, const mojo::String& origin,
315 int tab_id, int64_t timeout_millis, bool off_the_record, 324 int tab_id, int64_t timeout_millis, bool off_the_record,
316 const interfaces::MediaRouteProvider::CreateRouteCallback& cb) { 325 const interfaces::MediaRouteProvider::CreateRouteCallback& cb) {
317 interfaces::MediaRoutePtr route = interfaces::MediaRoute::New(); 326 interfaces::MediaRoutePtr route = interfaces::MediaRoute::New();
318 route->media_source = kSource; 327 route->media_source = kSource;
319 route->media_sink_id = kSinkId; 328 route->media_sink_id = kSinkId;
320 route->media_route_id = kRouteId; 329 route->media_route_id = kRouteId;
321 route->description = kDescription; 330 route->description = kDescription;
322 route->is_local = true; 331 route->is_local = true;
323 route->for_display = true; 332 route->for_display = true;
324 route->off_the_record = true; 333 route->off_the_record = true;
325 cb.Run(std::move(route), mojo::String(), 334 cb.Run(std::move(route), mojo::String(),
326 interfaces::RouteRequestResultCode::OK); 335 interfaces::RouteRequestResultCode::OK);
327 })); 336 }));
328 base::RunLoop run_loop; 337 base::RunLoop run_loop;
329 router()->CreateRoute(kSource, kSinkId, GURL(kOrigin), nullptr, 338 router()->CreateRoute(kSource, kSinkId, GURL(kOrigin), nullptr,
330 std::vector<MediaRouteResponseCallback>(), 339 std::vector<MediaRouteResponseCallback>(),
331 base::TimeDelta::FromMilliseconds(kTimeoutMillis), 340 base::TimeDelta::FromMilliseconds(kTimeoutMillis),
332 true); 341 true);
342 mojo::Array<interfaces::MediaRoutePtr> mojo_routes(1);
343 mojo_routes[0] = route->Clone();
344 router()->OnRoutesUpdated(std::move(mojo_routes), mojo::String(),
345 mojo::Array<mojo::String>());
333 346
334 // TODO(mfoltz): Where possible, convert other tests to use RunUntilIdle 347 // TODO(mfoltz): Where possible, convert other tests to use RunUntilIdle
335 // instead of manually calling Run/Quit on the run loop. 348 // instead of manually calling Run/Quit on the run loop.
336 run_loop.RunUntilIdle(); 349 run_loop.RunUntilIdle();
337 350
338 EXPECT_CALL(mock_media_route_provider_, 351 EXPECT_CALL(mock_media_route_provider_,
339 TerminateRoute(mojo::String(kRouteId))); 352 TerminateRoute(mojo::String(kRouteId)));
340 base::RunLoop run_loop2; 353 base::RunLoop run_loop2;
341 router()->OnOffTheRecordProfileShutdown(); 354 router()->OnOffTheRecordProfileShutdown();
342 run_loop2.RunUntilIdle(); 355 run_loop2.RunUntilIdle();
343 } 356 }
344 357
345 TEST_F(MediaRouterMojoImplTest, JoinRoute) { 358 TEST_F(MediaRouterMojoImplTest, JoinRoute) {
346 MediaSource media_source(kSource); 359 MediaSource media_source(kSource);
360
347 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", 361 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "",
348 false); 362 false);
349 interfaces::MediaRoutePtr route = interfaces::MediaRoute::New(); 363 interfaces::MediaRoutePtr route = interfaces::MediaRoute::New();
350 route->media_source = kSource; 364 route->media_source = kSource;
351 route->media_sink_id = kSinkId; 365 route->media_sink_id = kSinkId;
352 route->media_route_id = kRouteId; 366 route->media_route_id = kRouteId;
353 route->description = kDescription; 367 route->description = kDescription;
354 route->is_local = true; 368 route->is_local = true;
355 route->for_display = true; 369 route->for_display = true;
356 route->off_the_record = false; 370 route->off_the_record = false;
357 371
372 // Make sure the MR has received an update with the route, so it knows there
373 // is a local route to join.
374 mojo::Array<interfaces::MediaRoutePtr> mojo_routes(1);
375 mojo_routes[0] = route->Clone();
376 router()->OnRoutesUpdated(std::move(mojo_routes), mojo::String(),
377 mojo::Array<mojo::String>());
378
358 // Use a lambda function as an invocation target here to work around 379 // Use a lambda function as an invocation target here to work around
359 // a limitation with GMock::Invoke that prevents it from using move-only types 380 // a limitation with GMock::Invoke that prevents it from using move-only types
360 // in runnable parameter lists. 381 // in runnable parameter lists.
361 EXPECT_CALL( 382 EXPECT_CALL(
362 mock_media_route_provider_, 383 mock_media_route_provider_,
363 JoinRoute(mojo::String(kSource), mojo::String(kPresentationId), 384 JoinRoute(mojo::String(kSource), mojo::String(kPresentationId),
364 mojo::String(kOrigin), kInvalidTabId, kTimeoutMillis, _, _)) 385 mojo::String(kOrigin), kInvalidTabId, kTimeoutMillis, _, _))
365 .WillOnce(Invoke([&route]( 386 .WillOnce(Invoke([&route](
366 const mojo::String& source, const mojo::String& presentation_id, 387 const mojo::String& source, const mojo::String& presentation_id,
367 const mojo::String& origin, int tab_id, int64_t timeout_millis, 388 const mojo::String& origin, int tab_id, int64_t timeout_millis,
(...skipping 10 matching lines...) Expand all
378 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 399 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
379 std::vector<MediaRouteResponseCallback> route_response_callbacks; 400 std::vector<MediaRouteResponseCallback> route_response_callbacks;
380 route_response_callbacks.push_back(base::Bind( 401 route_response_callbacks.push_back(base::Bind(
381 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); 402 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
382 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr, 403 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr,
383 route_response_callbacks, 404 route_response_callbacks,
384 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); 405 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false);
385 run_loop.Run(); 406 run_loop.Run();
386 } 407 }
387 408
388 TEST_F(MediaRouterMojoImplTest, JoinRouteFails) { 409 TEST_F(MediaRouterMojoImplTest, JoinRouteNotFoundFails) {
410 RouteResponseCallbackHandler handler;
411 base::RunLoop run_loop;
412 EXPECT_CALL(handler, DoInvoke(nullptr, "", "Route not found",
413 RouteRequestResult::ROUTE_NOT_FOUND))
414 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
415 std::vector<MediaRouteResponseCallback> route_response_callbacks;
416 route_response_callbacks.push_back(base::Bind(
417 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
418 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr,
419 route_response_callbacks,
420 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false);
421 run_loop.Run();
422 }
423
424 TEST_F(MediaRouterMojoImplTest, JoinRouteTimedOutFails) {
425 interfaces::MediaRoutePtr route = interfaces::MediaRoute::New();
426 route->media_source = kSource;
427 route->media_sink_id = kSinkId;
428 route->media_route_id = kRouteId;
429 route->description = kDescription;
430 route->is_local = true;
431 route->for_display = true;
432 route->off_the_record = false;
433
434 // Make sure the MR has received an update with the route, so it knows there
435 // is a local route to join.
436 mojo::Array<interfaces::MediaRoutePtr> mojo_routes(1);
437 mojo_routes[0] = route->Clone();
438 router()->OnRoutesUpdated(std::move(mojo_routes), mojo::String(),
439 mojo::Array<mojo::String>());
440
389 EXPECT_CALL( 441 EXPECT_CALL(
390 mock_media_route_provider_, 442 mock_media_route_provider_,
391 JoinRoute(mojo::String(kSource), mojo::String(kPresentationId), 443 JoinRoute(mojo::String(kSource), mojo::String(kPresentationId),
392 mojo::String(kOrigin), kInvalidTabId, kTimeoutMillis, _, _)) 444 mojo::String(kOrigin), kInvalidTabId, kTimeoutMillis, _, _))
393 .WillOnce(Invoke( 445 .WillOnce(Invoke(
394 [](const mojo::String& source, const mojo::String& presentation_id, 446 [](const mojo::String& source, const mojo::String& presentation_id,
395 const mojo::String& origin, int tab_id, int64_t timeout_millis, 447 const mojo::String& origin, int tab_id, int64_t timeout_millis,
396 bool off_the_record, 448 bool off_the_record,
397 const interfaces::MediaRouteProvider::JoinRouteCallback& cb) { 449 const interfaces::MediaRouteProvider::JoinRouteCallback& cb) {
398 cb.Run(interfaces::MediaRoutePtr(), mojo::String(kError), 450 cb.Run(interfaces::MediaRoutePtr(), mojo::String(kError),
(...skipping 17 matching lines...) Expand all
416 TEST_F(MediaRouterMojoImplTest, JoinRouteOffTheRecordMismatchFails) { 468 TEST_F(MediaRouterMojoImplTest, JoinRouteOffTheRecordMismatchFails) {
417 interfaces::MediaRoutePtr route = interfaces::MediaRoute::New(); 469 interfaces::MediaRoutePtr route = interfaces::MediaRoute::New();
418 route->media_source = kSource; 470 route->media_source = kSource;
419 route->media_sink_id = kSinkId; 471 route->media_sink_id = kSinkId;
420 route->media_route_id = kRouteId; 472 route->media_route_id = kRouteId;
421 route->description = kDescription; 473 route->description = kDescription;
422 route->is_local = true; 474 route->is_local = true;
423 route->for_display = true; 475 route->for_display = true;
424 route->off_the_record = false; 476 route->off_the_record = false;
425 477
478 // Make sure the MR has received an update with the route, so it knows there
479 // is a local route to join.
480 mojo::Array<interfaces::MediaRoutePtr> mojo_routes(1);
481 mojo_routes[0] = route->Clone();
482 router()->OnRoutesUpdated(std::move(mojo_routes), mojo::String(),
483 mojo::Array<mojo::String>());
484
426 // Use a lambda function as an invocation target here to work around 485 // Use a lambda function as an invocation target here to work around
427 // a limitation with GMock::Invoke that prevents it from using move-only types 486 // a limitation with GMock::Invoke that prevents it from using move-only types
428 // in runnable parameter lists. 487 // in runnable parameter lists.
429 EXPECT_CALL( 488 EXPECT_CALL(
430 mock_media_route_provider_, 489 mock_media_route_provider_,
431 JoinRoute(mojo::String(kSource), mojo::String(kPresentationId), 490 JoinRoute(mojo::String(kSource), mojo::String(kPresentationId),
432 mojo::String(kOrigin), kInvalidTabId, kTimeoutMillis, true, _)) 491 mojo::String(kOrigin), kInvalidTabId, kTimeoutMillis, true, _))
433 .WillOnce(Invoke([&route]( 492 .WillOnce(Invoke([&route](
434 const mojo::String& source, const mojo::String& presentation_id, 493 const mojo::String& source, const mojo::String& presentation_id,
435 const mojo::String& origin, int tab_id, int64_t timeout_millis, 494 const mojo::String& origin, int tab_id, int64_t timeout_millis,
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 .WillRepeatedly(Return(true)); 1232 .WillRepeatedly(Return(true));
1174 EXPECT_CALL(mock_event_page_tracker_, WakeEventPage(extension_id(), _)) 1233 EXPECT_CALL(mock_event_page_tracker_, WakeEventPage(extension_id(), _))
1175 .Times(2) 1234 .Times(2)
1176 .WillOnce(Return(true)) 1235 .WillOnce(Return(true))
1177 .WillOnce(DoAll(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }), 1236 .WillOnce(DoAll(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }),
1178 Return(true))); 1237 Return(true)));
1179 router()->DetachRoute(kRouteId); 1238 router()->DetachRoute(kRouteId);
1180 router()->DetachRoute(kRouteId2); 1239 router()->DetachRoute(kRouteId2);
1181 run_loop.Run(); 1240 run_loop.Run();
1182 EXPECT_CALL(mock_event_page_tracker_, IsEventPageSuspended(extension_id())) 1241 EXPECT_CALL(mock_event_page_tracker_, IsEventPageSuspended(extension_id()))
1183 .Times(1) 1242 .Times(2)
1184 .WillRepeatedly(Return(false)); 1243 .WillRepeatedly(Return(false));
1185 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))); 1244 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId)));
1186 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2))); 1245 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2)));
1187 ConnectProviderManagerService(); 1246 ConnectProviderManagerService();
1188 ProcessEventLoop(); 1247 ProcessEventLoop();
1189 } 1248 }
1190 1249
1191 class MediaRouterMojoExtensionTest : public ::testing::Test { 1250 class MediaRouterMojoExtensionTest : public ::testing::Test {
1192 public: 1251 public:
1193 MediaRouterMojoExtensionTest() 1252 MediaRouterMojoExtensionTest()
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 EXPECT_CALL(mock_media_route_provider_, 1625 EXPECT_CALL(mock_media_route_provider_,
1567 UpdateMediaSinks(mojo::String(MediaSourceForDesktop().id()))) 1626 UpdateMediaSinks(mojo::String(MediaSourceForDesktop().id())))
1568 .WillOnce(InvokeWithoutArgs([&run_loop2]() { 1627 .WillOnce(InvokeWithoutArgs([&run_loop2]() {
1569 run_loop2.Quit(); 1628 run_loop2.Quit();
1570 })); 1629 }));
1571 1630
1572 run_loop2.Run(); 1631 run_loop2.Run();
1573 } 1632 }
1574 1633
1575 } // namespace media_router 1634 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698