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

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

Issue 2855473004: [Media Router] Sync state when MR extension is (re)connected to MR. (Closed)
Patch Set: Created 3 years, 7 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 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 EXPECT_EQ(UINT8_C(2), messages_[4].binary->front()); 1056 EXPECT_EQ(UINT8_C(2), messages_[4].binary->front());
1057 EXPECT_EQ(RouteMessage::BINARY, messages_[5].type); 1057 EXPECT_EQ(RouteMessage::BINARY, messages_[5].type);
1058 ASSERT_TRUE(messages_[5].binary); 1058 ASSERT_TRUE(messages_[5].binary);
1059 ASSERT_EQ(1u, messages_[5].binary->size()); 1059 ASSERT_EQ(1u, messages_[5].binary->size());
1060 EXPECT_EQ(UINT8_C(3), messages_[5].binary->front()); 1060 EXPECT_EQ(UINT8_C(3), messages_[5].binary->front());
1061 } 1061 }
1062 1062
1063 std::vector<RouteMessage> messages_; 1063 std::vector<RouteMessage> messages_;
1064 }; 1064 };
1065 1065
1066 class NoopMessageObserver : public RouteMessageObserver {
mark a. foltz 2017/05/03 17:37:08 s/Noop/Fake/ (or maybe s/Noop/Null/) to follow the
imcheng 2017/05/03 18:22:41 Done.
1067 public:
1068 NoopMessageObserver(MediaRouter* router, const MediaRoute::Id& route_id)
1069 : RouteMessageObserver(router, route_id) {}
1070 ~NoopMessageObserver() final {}
1071
1072 void OnMessagesReceived(const std::vector<RouteMessage>& messages) final {}
1073 };
1074
1066 } // namespace 1075 } // namespace
1067 1076
1068 TEST_F(MediaRouterMojoImplTest, RouteMessagesSingleObserver) { 1077 TEST_F(MediaRouterMojoImplTest, RouteMessagesSingleObserver) {
1069 std::vector<RouteMessage> incoming_batch1, incoming_batch2, incoming_batch3; 1078 std::vector<RouteMessage> incoming_batch1, incoming_batch2, incoming_batch3;
1070 PopulateRouteMessages(&incoming_batch1, &incoming_batch2, &incoming_batch3); 1079 PopulateRouteMessages(&incoming_batch1, &incoming_batch2, &incoming_batch3);
1071 1080
1072 base::RunLoop run_loop; 1081 base::RunLoop run_loop;
1073 MediaRoute::Id expected_route_id("foo"); 1082 MediaRoute::Id expected_route_id("foo");
1074 EXPECT_CALL(mock_media_route_provider_, 1083 EXPECT_CALL(mock_media_route_provider_,
1075 StartListeningForRouteMessages(Eq(expected_route_id))) 1084 StartListeningForRouteMessages(Eq(expected_route_id)))
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 expected_count); 1469 expected_count);
1461 } 1470 }
1462 1471
1463 void ExpectWakeupBucketCount(MediaRouteProviderWakeup wakeup, 1472 void ExpectWakeupBucketCount(MediaRouteProviderWakeup wakeup,
1464 int expected_count) { 1473 int expected_count) {
1465 histogram_tester_.ExpectBucketCount("MediaRouter.Provider.Wakeup", 1474 histogram_tester_.ExpectBucketCount("MediaRouter.Provider.Wakeup",
1466 static_cast<int>(wakeup), 1475 static_cast<int>(wakeup),
1467 expected_count); 1476 expected_count);
1468 } 1477 }
1469 1478
1479 MediaRouterMojoImpl* router() const { return media_router_.get(); }
1480
1470 content::TestBrowserThreadBundle thread_bundle_; 1481 content::TestBrowserThreadBundle thread_bundle_;
1471 std::unique_ptr<MediaRouterMojoImpl> media_router_; 1482 std::unique_ptr<MediaRouterMojoImpl> media_router_;
1472 RegisterMediaRouteProviderHandler provide_handler_; 1483 RegisterMediaRouteProviderHandler provide_handler_;
1473 TestProcessManager* process_manager_; 1484 TestProcessManager* process_manager_;
1474 testing::StrictMock<MockMediaRouteProvider> mock_media_route_provider_; 1485 testing::StrictMock<MockMediaRouteProvider> mock_media_route_provider_;
1475 mojom::MediaRouterPtr media_router_proxy_; 1486 mojom::MediaRouterPtr media_router_proxy_;
1476 scoped_refptr<extensions::Extension> extension_; 1487 scoped_refptr<extensions::Extension> extension_;
1477 1488
1478 private: 1489 private:
1479 std::unique_ptr<TestingProfile> profile_; 1490 std::unique_ptr<TestingProfile> profile_;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 base::RunLoop run_loop2; 1674 base::RunLoop run_loop2;
1664 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) 1675 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")))
1665 .WillOnce(InvokeWithoutArgs([&run_loop]() { 1676 .WillOnce(InvokeWithoutArgs([&run_loop]() {
1666 run_loop.Quit(); 1677 run_loop.Quit();
1667 })); 1678 }));
1668 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) 1679 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id()))
1669 .WillOnce(Return(false)).WillOnce(Return(false)); 1680 .WillOnce(Return(false)).WillOnce(Return(false));
1670 EXPECT_CALL(mock_media_route_provider_, 1681 EXPECT_CALL(mock_media_route_provider_,
1671 UpdateMediaSinks(MediaSourceForDesktop().id())) 1682 UpdateMediaSinks(MediaSourceForDesktop().id()))
1672 .Times(2); 1683 .Times(2);
1673 // EnableMdnsDisocvery() is never called except on Windows. 1684 // EnableMdnsDiscovery() is never called except on Windows.
1674 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) 1685 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery())
1675 .WillOnce(InvokeWithoutArgs([&run_loop2]() { 1686 .WillOnce(InvokeWithoutArgs([&run_loop2]() {
1676 run_loop2.Quit(); 1687 run_loop2.Quit();
1677 })); 1688 }));
1678 RegisterMediaRouteProvider(); 1689 RegisterMediaRouteProvider();
1679 run_loop.Run(); 1690 run_loop.Run();
1680 run_loop2.Run(); 1691 run_loop2.Run();
1681 // Should not call EnableMdnsDiscovery, but will call UpdateMediaSinks 1692 // Should not call EnableMdnsDiscovery, but will call UpdateMediaSinks
1682 media_router_->OnUserGesture(); 1693 media_router_->OnUserGesture();
1683 base::RunLoop run_loop3; 1694 base::RunLoop run_loop3;
(...skipping 20 matching lines...) Expand all
1704 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) 1715 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")))
1705 .WillOnce(InvokeWithoutArgs([&run_loop5]() { 1716 .WillOnce(InvokeWithoutArgs([&run_loop5]() {
1706 run_loop5.Quit(); 1717 run_loop5.Quit();
1707 })); 1718 }));
1708 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) 1719 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id()))
1709 .WillOnce(Return(false)).WillOnce(Return(false)); 1720 .WillOnce(Return(false)).WillOnce(Return(false));
1710 // Expected because it was used to wake up the page. 1721 // Expected because it was used to wake up the page.
1711 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId)); 1722 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId));
1712 EXPECT_CALL(mock_media_route_provider_, 1723 EXPECT_CALL(mock_media_route_provider_,
1713 UpdateMediaSinks(MediaSourceForDesktop().id())); 1724 UpdateMediaSinks(MediaSourceForDesktop().id()));
1714 // EnableMdnsDisocvery() is never called except on Windows. 1725 // EnableMdnsDiscovery() is never called except on Windows.
1715 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) 1726 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery())
1716 .WillOnce(InvokeWithoutArgs([&run_loop6]() { 1727 .WillOnce(InvokeWithoutArgs([&run_loop6]() {
1717 run_loop6.Quit(); 1728 run_loop6.Quit();
1718 })); 1729 }));
1719 BindMediaRouteProvider(); 1730 BindMediaRouteProvider();
1720 RegisterMediaRouteProvider(); 1731 RegisterMediaRouteProvider();
1721 run_loop5.Run(); 1732 run_loop5.Run();
1722 run_loop6.Run(); 1733 run_loop6.Run();
1723 // Should not call EnableMdnsDiscovery, but will call UpdateMediaSinks 1734 // Should not call EnableMdnsDiscovery, but will call UpdateMediaSinks
1724 media_router_->OnUserGesture(); 1735 media_router_->OnUserGesture();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1758 #endif 1769 #endif
1759 EXPECT_CALL(mock_media_route_provider_, 1770 EXPECT_CALL(mock_media_route_provider_,
1760 UpdateMediaSinks(MediaSourceForDesktop().id())) 1771 UpdateMediaSinks(MediaSourceForDesktop().id()))
1761 .WillOnce(InvokeWithoutArgs([&run_loop2]() { 1772 .WillOnce(InvokeWithoutArgs([&run_loop2]() {
1762 run_loop2.Quit(); 1773 run_loop2.Quit();
1763 })); 1774 }));
1764 1775
1765 run_loop2.Run(); 1776 run_loop2.Run();
1766 } 1777 }
1767 1778
1779 TEST_F(MediaRouterMojoExtensionTest, SyncStateToMediaRouteProvider) {
1780 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id()))
1781 .WillRepeatedly(Return(false));
1782 MediaSource media_source = MediaSource(kSource);
1783 std::unique_ptr<MockMediaSinksObserver> sinks_observer;
1784 std::unique_ptr<MockMediaRoutesObserver> routes_observer;
1785 std::unique_ptr<NoopMessageObserver> messages_observer;
1786
1787 {
1788 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")));
1789 BindMediaRouteProvider();
1790 RegisterMediaRouteProvider();
1791 base::RunLoop().RunUntilIdle();
1792 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&provide_handler_));
1793 }
1794
1795 {
1796 media_router_->OnSinkAvailabilityUpdated(
1797 mojom::MediaRouter::SinkAvailability::PER_SOURCE);
1798 EXPECT_CALL(mock_media_route_provider_,
1799 StartObservingMediaSinks(media_source.id()));
1800 sinks_observer.reset(new MockMediaSinksObserver(
1801 router(), media_source, url::Origin(GURL(kOrigin))));
1802 EXPECT_TRUE(sinks_observer->Init());
1803
1804 EXPECT_CALL(mock_media_route_provider_,
1805 StartObservingMediaRoutes(media_source.id()));
1806 routes_observer.reset(
1807 new MockMediaRoutesObserver(router(), media_source.id()));
1808
1809 EXPECT_CALL(mock_media_route_provider_,
1810 StartListeningForRouteMessages(media_source.id()));
1811 messages_observer.reset(
1812 new NoopMessageObserver(router(), media_source.id()));
1813 base::RunLoop().RunUntilIdle();
1814 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_media_route_provider_));
1815 }
1816
1817 {
1818 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")));
1819 EXPECT_CALL(mock_media_route_provider_,
1820 StartObservingMediaSinks(media_source.id()));
1821 EXPECT_CALL(mock_media_route_provider_,
1822 StartObservingMediaRoutes(media_source.id()));
1823 EXPECT_CALL(mock_media_route_provider_,
1824 StartListeningForRouteMessages(media_source.id()));
1825 media_router_->OnConnectionError();
1826 BindMediaRouteProvider();
1827 RegisterMediaRouteProvider();
1828 base::RunLoop().RunUntilIdle();
1829 }
1830 }
1831
1768 } // namespace media_router 1832 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698