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