| 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(); |
| 1490 base::RunLoop run_loop3; |
| 1491 run_loop3.RunUntilIdle(); |
| 1486 | 1492 |
| 1487 // Reset the extension by "suspending" and notifying MR. | 1493 // Reset the extension by "suspending" and notifying MR. |
| 1488 base::RunLoop run_loop3; | 1494 base::RunLoop run_loop4; |
| 1489 ResetMediaRouteProvider(); | 1495 ResetMediaRouteProvider(); |
| 1490 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) | 1496 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1491 .WillOnce(Return(true)); | 1497 .WillOnce(Return(true)); |
| 1492 EXPECT_CALL(*process_manager_, WakeEventPage(extension_->id(), _)) | 1498 EXPECT_CALL(*process_manager_, WakeEventPage(extension_->id(), _)) |
| 1493 .WillOnce(testing::DoAll( | 1499 .WillOnce(testing::DoAll( |
| 1494 media::RunCallback<1>(true), | 1500 media::RunCallback<1>(true), |
| 1495 InvokeWithoutArgs([&run_loop3]() { run_loop3.Quit(); }), | 1501 InvokeWithoutArgs([&run_loop4]() { run_loop4.Quit(); }), |
| 1496 Return(true))); | 1502 Return(true))); |
| 1497 // Use DetachRoute because it unconditionally calls RunOrDefer(). | 1503 // Use DetachRoute because it unconditionally calls RunOrDefer(). |
| 1498 media_router_->DetachRoute(kRouteId); | 1504 media_router_->DetachRoute(kRouteId); |
| 1499 run_loop3.Run(); | 1505 run_loop4.Run(); |
| 1500 | 1506 |
| 1501 base::RunLoop run_loop4; | |
| 1502 base::RunLoop run_loop5; | 1507 base::RunLoop run_loop5; |
| 1508 base::RunLoop run_loop6; |
| 1503 // RegisterMediaRouteProvider() is called. | 1509 // RegisterMediaRouteProvider() is called. |
| 1504 // The queued DetachRoute(kRouteId) call should be executed. | 1510 // The queued DetachRoute(kRouteId) call should be executed. |
| 1505 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) | 1511 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) |
| 1506 .WillOnce(InvokeWithoutArgs([&run_loop4]() { | |
| 1507 run_loop4.Quit(); | |
| 1508 })); | |
| 1509 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) | |
| 1510 .WillOnce(Return(false)); | |
| 1511 // Expected because it was used to wake up the page. | |
| 1512 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))); | |
| 1513 // EnableMdnsDisocvery() is never called except on Windows. | |
| 1514 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) | |
| 1515 .WillOnce(InvokeWithoutArgs([&run_loop5]() { | 1512 .WillOnce(InvokeWithoutArgs([&run_loop5]() { |
| 1516 run_loop5.Quit(); | 1513 run_loop5.Quit(); |
| 1517 })); | 1514 })); |
| 1515 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1516 .WillOnce(Return(false)).WillOnce(Return(false)); |
| 1517 // Expected because it was used to wake up the page. |
| 1518 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))); |
| 1519 EXPECT_CALL(mock_media_route_provider_, |
| 1520 UpdateMediaSinks(mojo::String(MediaSourceForDesktop().id()))); |
| 1521 // EnableMdnsDisocvery() is never called except on Windows. |
| 1522 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) |
| 1523 .WillOnce(InvokeWithoutArgs([&run_loop6]() { |
| 1524 run_loop6.Quit(); |
| 1525 })); |
| 1518 BindMediaRouteProvider(); | 1526 BindMediaRouteProvider(); |
| 1519 RegisterMediaRouteProvider(); | 1527 RegisterMediaRouteProvider(); |
| 1520 run_loop4.Run(); | |
| 1521 run_loop5.Run(); | 1528 run_loop5.Run(); |
| 1522 // Always a no-op at this point. | 1529 run_loop6.Run(); |
| 1530 // Should not call EnableMdnsDiscovery, but will call UpdateMediaSinks |
| 1523 media_router_->OnUserGesture(); | 1531 media_router_->OnUserGesture(); |
| 1532 base::RunLoop run_loop7; |
| 1533 run_loop7.RunUntilIdle(); |
| 1524 } | 1534 } |
| 1525 #endif | 1535 #endif |
| 1526 | 1536 |
| 1537 TEST_F(MediaRouterMojoExtensionTest, UpdateMediaSinksOnUserGesture) { |
| 1538 BindMediaRouteProvider(); |
| 1539 |
| 1540 base::RunLoop run_loop; |
| 1541 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) |
| 1542 .WillOnce(InvokeWithoutArgs([&run_loop]() { |
| 1543 run_loop.Quit(); |
| 1544 })); |
| 1545 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1546 #if defined(OS_WIN) |
| 1547 // Windows calls once for EnableMdnsDiscovery |
| 1548 .Times(3) |
| 1549 #else |
| 1550 // All others call once for registration, and once for the user gesture. |
| 1551 .Times(2) |
| 1552 #endif |
| 1553 .WillRepeatedly(Return(false)); |
| 1554 |
| 1555 |
| 1556 RegisterMediaRouteProvider(); |
| 1557 run_loop.Run(); |
| 1558 |
| 1559 media_router_->OnUserGesture(); |
| 1560 |
| 1561 base::RunLoop run_loop2; |
| 1562 |
| 1563 #if defined(OS_WIN) |
| 1564 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()); |
| 1565 #endif |
| 1566 EXPECT_CALL(mock_media_route_provider_, |
| 1567 UpdateMediaSinks(mojo::String(MediaSourceForDesktop().id()))) |
| 1568 .WillOnce(InvokeWithoutArgs([&run_loop2]() { |
| 1569 run_loop2.Quit(); |
| 1570 })); |
| 1571 |
| 1572 run_loop2.Run(); |
| 1573 } |
| 1574 |
| 1527 } // namespace media_router | 1575 } // namespace media_router |
| OLD | NEW |