Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
| 19 #include "base/test/histogram_tester.h" | 19 #include "base/test/histogram_tester.h" |
| 20 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
| 21 #include "chrome/browser/media/router/issue.h" | 21 #include "chrome/browser/media/router/issue.h" |
| 22 #include "chrome/browser/media/router/media_route.h" | 22 #include "chrome/browser/media/router/media_route.h" |
| 23 #include "chrome/browser/media/router/media_source_helper.h" | |
| 23 #include "chrome/browser/media/router/mock_media_router.h" | 24 #include "chrome/browser/media/router/mock_media_router.h" |
| 24 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" | 25 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" |
| 25 #include "chrome/browser/media/router/mojo/media_router_mojo_test.h" | 26 #include "chrome/browser/media/router/mojo/media_router_mojo_test.h" |
| 26 #include "chrome/browser/media/router/mojo/media_router_type_converters.h" | 27 #include "chrome/browser/media/router/mojo/media_router_type_converters.h" |
| 27 #include "chrome/browser/media/router/presentation_session_messages_observer.h" | 28 #include "chrome/browser/media/router/presentation_session_messages_observer.h" |
| 28 #include "chrome/browser/media/router/test_helper.h" | 29 #include "chrome/browser/media/router/test_helper.h" |
| 29 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 30 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 30 #include "chrome/test/base/testing_browser_process.h" | 31 #include "chrome/test/base/testing_browser_process.h" |
| 31 #include "chrome/test/base/testing_profile.h" | 32 #include "chrome/test/base/testing_profile.h" |
| 32 #include "components/version_info/version_info.h" | 33 #include "components/version_info/version_info.h" |
| (...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1465 | 1466 |
| 1466 BindMediaRouteProvider(); | 1467 BindMediaRouteProvider(); |
| 1467 | 1468 |
| 1468 base::RunLoop run_loop; | 1469 base::RunLoop run_loop; |
| 1469 base::RunLoop run_loop2; | 1470 base::RunLoop run_loop2; |
| 1470 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) | 1471 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) |
| 1471 .WillOnce(InvokeWithoutArgs([&run_loop]() { | 1472 .WillOnce(InvokeWithoutArgs([&run_loop]() { |
| 1472 run_loop.Quit(); | 1473 run_loop.Quit(); |
| 1473 })); | 1474 })); |
| 1474 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) | 1475 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1475 .WillOnce(Return(false)); | 1476 .WillOnce(Return(false)).WillOnce(Return(false)); |
| 1477 EXPECT_CALL(mock_media_route_provider_, | |
| 1478 UpdateMediaSinks(mojo::String(MediaSourceForDesktop().id()))) | |
| 1479 .Times(2); | |
| 1476 // EnableMdnsDisocvery() is never called except on Windows. | 1480 // EnableMdnsDisocvery() is never called except on Windows. |
| 1477 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) | 1481 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) |
| 1478 .WillOnce(InvokeWithoutArgs([&run_loop2]() { | 1482 .WillOnce(InvokeWithoutArgs([&run_loop2]() { |
| 1479 run_loop2.Quit(); | 1483 run_loop2.Quit(); |
| 1480 })); | 1484 })); |
| 1481 RegisterMediaRouteProvider(); | 1485 RegisterMediaRouteProvider(); |
| 1482 run_loop.Run(); | 1486 run_loop.Run(); |
| 1483 run_loop2.Run(); | 1487 run_loop2.Run(); |
| 1484 // Always a no-op at this point. | 1488 // Should not call EnableMdnsDiscovery, but will call UpdateMediaSinks |
| 1485 media_router_->OnUserGesture(); | 1489 media_router_->OnUserGesture(); |
|
btolsch
2016/04/16 00:25:55
Add another RunLoop here to send the mojo call thr
amp
2016/04/16 01:35:52
Done.
| |
| 1486 | 1490 |
| 1487 // Reset the extension by "suspending" and notifying MR. | 1491 // Reset the extension by "suspending" and notifying MR. |
| 1488 base::RunLoop run_loop3; | 1492 base::RunLoop run_loop3; |
| 1489 ResetMediaRouteProvider(); | 1493 ResetMediaRouteProvider(); |
| 1490 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) | 1494 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1491 .WillOnce(Return(true)); | 1495 .WillOnce(Return(true)); |
| 1492 EXPECT_CALL(*process_manager_, WakeEventPage(extension_->id(), _)) | 1496 EXPECT_CALL(*process_manager_, WakeEventPage(extension_->id(), _)) |
| 1493 .WillOnce(testing::DoAll( | 1497 .WillOnce(testing::DoAll( |
| 1494 media::RunCallback<1>(true), | 1498 media::RunCallback<1>(true), |
| 1495 InvokeWithoutArgs([&run_loop3]() { run_loop3.Quit(); }), | 1499 InvokeWithoutArgs([&run_loop3]() { run_loop3.Quit(); }), |
| 1496 Return(true))); | 1500 Return(true))); |
| 1497 // Use DetachRoute because it unconditionally calls RunOrDefer(). | 1501 // Use DetachRoute because it unconditionally calls RunOrDefer(). |
| 1498 media_router_->DetachRoute(kRouteId); | 1502 media_router_->DetachRoute(kRouteId); |
| 1499 run_loop3.Run(); | 1503 run_loop3.Run(); |
| 1500 | 1504 |
| 1501 base::RunLoop run_loop4; | 1505 base::RunLoop run_loop4; |
| 1502 base::RunLoop run_loop5; | 1506 base::RunLoop run_loop5; |
| 1503 // RegisterMediaRouteProvider() is called. | 1507 // RegisterMediaRouteProvider() is called. |
| 1504 // The queued DetachRoute(kRouteId) call should be executed. | 1508 // The queued DetachRoute(kRouteId) call should be executed. |
| 1505 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) | 1509 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) |
| 1506 .WillOnce(InvokeWithoutArgs([&run_loop4]() { | 1510 .WillOnce(InvokeWithoutArgs([&run_loop4]() { |
| 1507 run_loop4.Quit(); | 1511 run_loop4.Quit(); |
| 1508 })); | 1512 })); |
| 1509 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) | 1513 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1510 .WillOnce(Return(false)); | 1514 .WillOnce(Return(false)).WillOnce(Return(false)); |
| 1511 // Expected because it was used to wake up the page. | 1515 // Expected because it was used to wake up the page. |
| 1512 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))); | 1516 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))); |
| 1517 EXPECT_CALL(mock_media_route_provider_, | |
| 1518 UpdateMediaSinks(mojo::String(MediaSourceForDesktop().id()))); | |
| 1513 // EnableMdnsDisocvery() is never called except on Windows. | 1519 // EnableMdnsDisocvery() is never called except on Windows. |
| 1514 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) | 1520 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) |
| 1515 .WillOnce(InvokeWithoutArgs([&run_loop5]() { | 1521 .WillOnce(InvokeWithoutArgs([&run_loop5]() { |
| 1516 run_loop5.Quit(); | 1522 run_loop5.Quit(); |
| 1517 })); | 1523 })); |
| 1518 BindMediaRouteProvider(); | 1524 BindMediaRouteProvider(); |
| 1519 RegisterMediaRouteProvider(); | 1525 RegisterMediaRouteProvider(); |
| 1520 run_loop4.Run(); | 1526 run_loop4.Run(); |
| 1521 run_loop5.Run(); | 1527 run_loop5.Run(); |
| 1522 // Always a no-op at this point. | 1528 // Should not call EnableMdnsDiscovery, but will call UpdateMediaSinks |
| 1523 media_router_->OnUserGesture(); | 1529 media_router_->OnUserGesture(); |
|
btolsch
2016/04/16 00:25:55
Add another RunLoop here to send the mojo call thr
amp
2016/04/16 01:35:52
Done.
| |
| 1524 } | 1530 } |
| 1525 #endif | 1531 #endif |
| 1526 | 1532 |
| 1533 TEST_F(MediaRouterMojoExtensionTest, UpdateMediaSinksOnUserGesture) { | |
| 1534 BindMediaRouteProvider(); | |
| 1535 | |
| 1536 base::RunLoop run_loop; | |
| 1537 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) | |
| 1538 .WillOnce(InvokeWithoutArgs([&run_loop]() { | |
| 1539 run_loop.Quit(); | |
| 1540 })); | |
| 1541 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) | |
| 1542 #if defined(OS_WIN) | |
| 1543 // Windows calls once for EnableMdnsDiscovery | |
| 1544 .Times(3) | |
| 1545 #else | |
| 1546 // All others call once for registration, and once for the user gesture. | |
| 1547 .Times(2) | |
| 1548 #endif | |
| 1549 .WillRepeatedly(Return(false)); | |
| 1550 | |
| 1551 | |
| 1552 RegisterMediaRouteProvider(); | |
| 1553 run_loop.Run(); | |
| 1554 | |
| 1555 media_router_->OnUserGesture(); | |
| 1556 | |
| 1557 base::RunLoop run_loop2; | |
| 1558 | |
| 1559 #if defined(OS_WIN) | |
| 1560 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()); | |
| 1561 #endif | |
| 1562 EXPECT_CALL(mock_media_route_provider_, | |
| 1563 UpdateMediaSinks(mojo::String(MediaSourceForDesktop().id()))) | |
| 1564 .WillOnce(InvokeWithoutArgs([&run_loop2]() { | |
| 1565 run_loop2.Quit(); | |
| 1566 })); | |
| 1567 | |
| 1568 run_loop2.Run(); | |
| 1569 } | |
| 1570 | |
| 1527 } // namespace media_router | 1571 } // namespace media_router |
| OLD | NEW |