| 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> |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 bool(const std::string& extension_id, | 180 bool(const std::string& extension_id, |
| 181 const base::Callback<void(bool)>& callback)); | 181 const base::Callback<void(bool)>& callback)); |
| 182 | 182 |
| 183 private: | 183 private: |
| 184 DISALLOW_COPY_AND_ASSIGN(TestProcessManager); | 184 DISALLOW_COPY_AND_ASSIGN(TestProcessManager); |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 // Mockable class for awaiting RegisterMediaRouteProvider callbacks. | 187 // Mockable class for awaiting RegisterMediaRouteProvider callbacks. |
| 188 class RegisterMediaRouteProviderHandler { | 188 class RegisterMediaRouteProviderHandler { |
| 189 public: | 189 public: |
| 190 MOCK_METHOD1(Invoke, void(const std::string& instance_id)); | 190 MOCK_METHOD2(Invoke, |
| 191 void(const std::string& instance_id, |
| 192 bool enable_browser_side_discovery)); |
| 191 }; | 193 }; |
| 192 | 194 |
| 193 TEST_F(MediaRouterMojoImplTest, CreateRoute) { | 195 TEST_F(MediaRouterMojoImplTest, CreateRoute) { |
| 194 MediaSource media_source(kSource); | 196 MediaSource media_source(kSource); |
| 195 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", | 197 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", |
| 196 false); | 198 false); |
| 197 | 199 |
| 198 // Use a lambda function as an invocation target here to work around | 200 // Use a lambda function as an invocation target here to work around |
| 199 // a limitation with GMock::Invoke that prevents it from using move-only types | 201 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 200 // in runnable parameter lists. | 202 // in runnable parameter lists. |
| (...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1404 | 1406 |
| 1405 profile_.reset(new TestingProfile); | 1407 profile_.reset(new TestingProfile); |
| 1406 // Set up a mock ProcessManager instance. | 1408 // Set up a mock ProcessManager instance. |
| 1407 extensions::ProcessManagerFactory::GetInstance()->SetTestingFactory( | 1409 extensions::ProcessManagerFactory::GetInstance()->SetTestingFactory( |
| 1408 profile_.get(), &TestProcessManager::Create); | 1410 profile_.get(), &TestProcessManager::Create); |
| 1409 process_manager_ = static_cast<TestProcessManager*>( | 1411 process_manager_ = static_cast<TestProcessManager*>( |
| 1410 extensions::ProcessManager::Get(profile_.get())); | 1412 extensions::ProcessManager::Get(profile_.get())); |
| 1411 DCHECK(process_manager_); | 1413 DCHECK(process_manager_); |
| 1412 | 1414 |
| 1413 // Create MR and its proxy, so that it can be accessed through Mojo. | 1415 // Create MR and its proxy, so that it can be accessed through Mojo. |
| 1414 media_router_.reset(new MediaRouterMojoImpl(process_manager_)); | 1416 media_router_.reset( |
| 1417 new MediaRouterMojoImpl(process_manager_, profile_.get())); |
| 1415 ProcessEventLoop(); | 1418 ProcessEventLoop(); |
| 1416 } | 1419 } |
| 1417 | 1420 |
| 1418 void TearDown() override { | 1421 void TearDown() override { |
| 1419 media_router_.reset(); | 1422 media_router_.reset(); |
| 1420 profile_.reset(); | 1423 profile_.reset(); |
| 1421 } | 1424 } |
| 1422 | 1425 |
| 1423 // Constructs bindings so that |media_router_| delegates calls to | 1426 // Constructs bindings so that |media_router_| delegates calls to |
| 1424 // |mojo_media_router_|, which are then handled by | 1427 // |mojo_media_router_|, which are then handled by |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1489 // It should be queued. | 1492 // It should be queued. |
| 1490 media_router_->DetachRoute(kRouteId); | 1493 media_router_->DetachRoute(kRouteId); |
| 1491 | 1494 |
| 1492 BindMediaRouteProvider(); | 1495 BindMediaRouteProvider(); |
| 1493 | 1496 |
| 1494 base::RunLoop run_loop, run_loop2; | 1497 base::RunLoop run_loop, run_loop2; |
| 1495 // |mojo_media_router| signals its readiness to the MR by registering | 1498 // |mojo_media_router| signals its readiness to the MR by registering |
| 1496 // itself via RegisterMediaRouteProvider(). | 1499 // itself via RegisterMediaRouteProvider(). |
| 1497 // Now that the |media_router| and |mojo_media_router| are fully initialized, | 1500 // Now that the |media_router| and |mojo_media_router| are fully initialized, |
| 1498 // the queued DetachRoute() call should be executed. | 1501 // the queued DetachRoute() call should be executed. |
| 1499 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) | 1502 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""), false)) |
| 1500 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 1503 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 1501 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) | 1504 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1502 .WillOnce(Return(false)); | 1505 .WillOnce(Return(false)); |
| 1503 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) | 1506 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) |
| 1504 .Times(AtMost(1)); | 1507 .Times(AtMost(1)); |
| 1505 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId)) | 1508 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId)) |
| 1506 .WillOnce(InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); })); | 1509 .WillOnce(InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); })); |
| 1507 RegisterMediaRouteProvider(); | 1510 RegisterMediaRouteProvider(); |
| 1508 run_loop.Run(); | 1511 run_loop.Run(); |
| 1509 run_loop2.Run(); | 1512 run_loop2.Run(); |
| 1510 | 1513 |
| 1511 base::RunLoop run_loop3; | 1514 base::RunLoop run_loop3; |
| 1512 // Extension is suspended and re-awoken. | 1515 // Extension is suspended and re-awoken. |
| 1513 ResetMediaRouteProvider(); | 1516 ResetMediaRouteProvider(); |
| 1514 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) | 1517 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1515 .WillOnce(Return(true)); | 1518 .WillOnce(Return(true)); |
| 1516 EXPECT_CALL(*process_manager_, WakeEventPage(extension_->id(), _)) | 1519 EXPECT_CALL(*process_manager_, WakeEventPage(extension_->id(), _)) |
| 1517 .WillOnce(testing::DoAll( | 1520 .WillOnce(testing::DoAll( |
| 1518 media::RunCallback<1>(true), | 1521 media::RunCallback<1>(true), |
| 1519 InvokeWithoutArgs([&run_loop3]() { run_loop3.Quit(); }), | 1522 InvokeWithoutArgs([&run_loop3]() { run_loop3.Quit(); }), |
| 1520 Return(true))); | 1523 Return(true))); |
| 1521 media_router_->DetachRoute(kRouteId2); | 1524 media_router_->DetachRoute(kRouteId2); |
| 1522 run_loop3.Run(); | 1525 run_loop3.Run(); |
| 1523 | 1526 |
| 1524 base::RunLoop run_loop4, run_loop5; | 1527 base::RunLoop run_loop4, run_loop5; |
| 1525 // RegisterMediaRouteProvider() is called. | 1528 // RegisterMediaRouteProvider() is called. |
| 1526 // The queued DetachRoute(kRouteId2) call should be executed. | 1529 // The queued DetachRoute(kRouteId2) call should be executed. |
| 1527 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) | 1530 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""), false)) |
| 1528 .WillOnce(InvokeWithoutArgs([&run_loop4]() { run_loop4.Quit(); })); | 1531 .WillOnce(InvokeWithoutArgs([&run_loop4]() { run_loop4.Quit(); })); |
| 1529 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) | 1532 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1530 .WillOnce(Return(false)); | 1533 .WillOnce(Return(false)); |
| 1531 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) | 1534 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) |
| 1532 .Times(AtMost(1)); | 1535 .Times(AtMost(1)); |
| 1533 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId2)) | 1536 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId2)) |
| 1534 .WillOnce(InvokeWithoutArgs([&run_loop5]() { run_loop5.Quit(); })); | 1537 .WillOnce(InvokeWithoutArgs([&run_loop5]() { run_loop5.Quit(); })); |
| 1535 BindMediaRouteProvider(); | 1538 BindMediaRouteProvider(); |
| 1536 RegisterMediaRouteProvider(); | 1539 RegisterMediaRouteProvider(); |
| 1537 run_loop4.Run(); | 1540 run_loop4.Run(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1627 media_router_->DetachRoute(kRouteId2); | 1630 media_router_->DetachRoute(kRouteId2); |
| 1628 | 1631 |
| 1629 // The request queue size should not exceed |kMaxPendingRequests|. | 1632 // The request queue size should not exceed |kMaxPendingRequests|. |
| 1630 EXPECT_EQ(kMaxPendingRequests, media_router_->pending_requests_.size()); | 1633 EXPECT_EQ(kMaxPendingRequests, media_router_->pending_requests_.size()); |
| 1631 | 1634 |
| 1632 base::RunLoop run_loop, run_loop2; | 1635 base::RunLoop run_loop, run_loop2; |
| 1633 size_t count = 0; | 1636 size_t count = 0; |
| 1634 // The oldest request should have been dropped, so we don't expect to see | 1637 // The oldest request should have been dropped, so we don't expect to see |
| 1635 // DetachRoute(kRouteId) here. | 1638 // DetachRoute(kRouteId) here. |
| 1636 BindMediaRouteProvider(); | 1639 BindMediaRouteProvider(); |
| 1637 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) | 1640 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""), false)) |
| 1638 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 1641 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 1639 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())); | 1642 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())); |
| 1640 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) | 1643 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) |
| 1641 .Times(AtMost(1)); | 1644 .Times(AtMost(1)); |
| 1642 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId2)) | 1645 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId2)) |
| 1643 .Times(kMaxPendingRequests) | 1646 .Times(kMaxPendingRequests) |
| 1644 .WillRepeatedly(InvokeWithoutArgs([&run_loop2, &count]() { | 1647 .WillRepeatedly(InvokeWithoutArgs([&run_loop2, &count]() { |
| 1645 if (++count == MediaRouterMojoImpl::kMaxPendingRequests) | 1648 if (++count == MediaRouterMojoImpl::kMaxPendingRequests) |
| 1646 run_loop2.Quit(); | 1649 run_loop2.Quit(); |
| 1647 })); | 1650 })); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1724 media_router_->OnUserGesture(); | 1727 media_router_->OnUserGesture(); |
| 1725 base::RunLoop run_loop7; | 1728 base::RunLoop run_loop7; |
| 1726 run_loop7.RunUntilIdle(); | 1729 run_loop7.RunUntilIdle(); |
| 1727 } | 1730 } |
| 1728 #endif | 1731 #endif |
| 1729 | 1732 |
| 1730 TEST_F(MediaRouterMojoExtensionTest, UpdateMediaSinksOnUserGesture) { | 1733 TEST_F(MediaRouterMojoExtensionTest, UpdateMediaSinksOnUserGesture) { |
| 1731 BindMediaRouteProvider(); | 1734 BindMediaRouteProvider(); |
| 1732 | 1735 |
| 1733 base::RunLoop run_loop; | 1736 base::RunLoop run_loop; |
| 1734 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) | 1737 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""), false)) |
| 1735 .WillOnce(InvokeWithoutArgs([&run_loop]() { | 1738 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 1736 run_loop.Quit(); | |
| 1737 })); | |
| 1738 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) | 1739 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1739 #if defined(OS_WIN) | 1740 #if defined(OS_WIN) |
| 1740 // Windows calls once for EnableMdnsDiscovery | 1741 // Windows calls once for EnableMdnsDiscovery |
| 1741 .Times(3) | 1742 .Times(3) |
| 1742 #else | 1743 #else |
| 1743 // All others call once for registration, and once for the user gesture. | 1744 // All others call once for registration, and once for the user gesture. |
| 1744 .Times(2) | 1745 .Times(2) |
| 1745 #endif | 1746 #endif |
| 1746 .WillRepeatedly(Return(false)); | 1747 .WillRepeatedly(Return(false)); |
| 1747 | 1748 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1759 EXPECT_CALL(mock_media_route_provider_, | 1760 EXPECT_CALL(mock_media_route_provider_, |
| 1760 UpdateMediaSinks(MediaSourceForDesktop().id())) | 1761 UpdateMediaSinks(MediaSourceForDesktop().id())) |
| 1761 .WillOnce(InvokeWithoutArgs([&run_loop2]() { | 1762 .WillOnce(InvokeWithoutArgs([&run_loop2]() { |
| 1762 run_loop2.Quit(); | 1763 run_loop2.Quit(); |
| 1763 })); | 1764 })); |
| 1764 | 1765 |
| 1765 run_loop2.Run(); | 1766 run_loop2.Run(); |
| 1766 } | 1767 } |
| 1767 | 1768 |
| 1768 } // namespace media_router | 1769 } // namespace media_router |
| OLD | NEW |