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

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

Issue 2857393005: [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
« no previous file with comments | « chrome/browser/media/router/mojo/media_router_mojo_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 EXPECT_EQ(UINT8_C(2), messages_[4].binary->front()); 1042 EXPECT_EQ(UINT8_C(2), messages_[4].binary->front());
1043 EXPECT_EQ(RouteMessage::BINARY, messages_[5].type); 1043 EXPECT_EQ(RouteMessage::BINARY, messages_[5].type);
1044 ASSERT_TRUE(messages_[5].binary); 1044 ASSERT_TRUE(messages_[5].binary);
1045 ASSERT_EQ(1u, messages_[5].binary->size()); 1045 ASSERT_EQ(1u, messages_[5].binary->size());
1046 EXPECT_EQ(UINT8_C(3), messages_[5].binary->front()); 1046 EXPECT_EQ(UINT8_C(3), messages_[5].binary->front());
1047 } 1047 }
1048 1048
1049 std::vector<RouteMessage> messages_; 1049 std::vector<RouteMessage> messages_;
1050 }; 1050 };
1051 1051
1052 class NullMessageObserver : public RouteMessageObserver {
1053 public:
1054 NullMessageObserver(MediaRouter* router, const MediaRoute::Id& route_id)
1055 : RouteMessageObserver(router, route_id) {}
1056 ~NullMessageObserver() final {}
1057
1058 void OnMessagesReceived(const std::vector<RouteMessage>& messages) final {}
1059 };
1060
1052 } // namespace 1061 } // namespace
1053 1062
1054 TEST_F(MediaRouterMojoImplTest, RouteMessagesSingleObserver) { 1063 TEST_F(MediaRouterMojoImplTest, RouteMessagesSingleObserver) {
1055 std::vector<RouteMessage> incoming_batch1, incoming_batch2, incoming_batch3; 1064 std::vector<RouteMessage> incoming_batch1, incoming_batch2, incoming_batch3;
1056 PopulateRouteMessages(&incoming_batch1, &incoming_batch2, &incoming_batch3); 1065 PopulateRouteMessages(&incoming_batch1, &incoming_batch2, &incoming_batch3);
1057 1066
1058 base::RunLoop run_loop; 1067 base::RunLoop run_loop;
1059 MediaRoute::Id expected_route_id("foo"); 1068 MediaRoute::Id expected_route_id("foo");
1060 EXPECT_CALL(mock_media_route_provider_, 1069 EXPECT_CALL(mock_media_route_provider_,
1061 StartListeningForRouteMessages(Eq(expected_route_id))) 1070 StartListeningForRouteMessages(Eq(expected_route_id)))
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 expected_count); 1306 expected_count);
1298 } 1307 }
1299 1308
1300 void ExpectWakeupBucketCount(MediaRouteProviderWakeup wakeup, 1309 void ExpectWakeupBucketCount(MediaRouteProviderWakeup wakeup,
1301 int expected_count) { 1310 int expected_count) {
1302 histogram_tester_.ExpectBucketCount("MediaRouter.Provider.Wakeup", 1311 histogram_tester_.ExpectBucketCount("MediaRouter.Provider.Wakeup",
1303 static_cast<int>(wakeup), 1312 static_cast<int>(wakeup),
1304 expected_count); 1313 expected_count);
1305 } 1314 }
1306 1315
1316 MediaRouterMojoImpl* router() const { return media_router_.get(); }
1317
1307 content::TestBrowserThreadBundle thread_bundle_; 1318 content::TestBrowserThreadBundle thread_bundle_;
1308 std::unique_ptr<MediaRouterMojoImpl> media_router_; 1319 std::unique_ptr<MediaRouterMojoImpl> media_router_;
1309 RegisterMediaRouteProviderHandler provide_handler_; 1320 RegisterMediaRouteProviderHandler provide_handler_;
1310 TestProcessManager* process_manager_; 1321 TestProcessManager* process_manager_;
1311 testing::StrictMock<MockMediaRouteProvider> mock_media_route_provider_; 1322 testing::StrictMock<MockMediaRouteProvider> mock_media_route_provider_;
1312 mojom::MediaRouterPtr media_router_proxy_; 1323 mojom::MediaRouterPtr media_router_proxy_;
1313 scoped_refptr<extensions::Extension> extension_; 1324 scoped_refptr<extensions::Extension> extension_;
1314 1325
1315 private: 1326 private:
1316 std::unique_ptr<TestingProfile> profile_; 1327 std::unique_ptr<TestingProfile> profile_;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 base::RunLoop run_loop2; 1511 base::RunLoop run_loop2;
1501 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) 1512 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")))
1502 .WillOnce(InvokeWithoutArgs([&run_loop]() { 1513 .WillOnce(InvokeWithoutArgs([&run_loop]() {
1503 run_loop.Quit(); 1514 run_loop.Quit();
1504 })); 1515 }));
1505 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) 1516 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id()))
1506 .WillOnce(Return(false)).WillOnce(Return(false)); 1517 .WillOnce(Return(false)).WillOnce(Return(false));
1507 EXPECT_CALL(mock_media_route_provider_, 1518 EXPECT_CALL(mock_media_route_provider_,
1508 UpdateMediaSinks(MediaSourceForDesktop().id())) 1519 UpdateMediaSinks(MediaSourceForDesktop().id()))
1509 .Times(2); 1520 .Times(2);
1510 // EnableMdnsDisocvery() is never called except on Windows. 1521 // EnableMdnsDiscovery() is never called except on Windows.
1511 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) 1522 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery())
1512 .WillOnce(InvokeWithoutArgs([&run_loop2]() { 1523 .WillOnce(InvokeWithoutArgs([&run_loop2]() {
1513 run_loop2.Quit(); 1524 run_loop2.Quit();
1514 })); 1525 }));
1515 RegisterMediaRouteProvider(); 1526 RegisterMediaRouteProvider();
1516 run_loop.Run(); 1527 run_loop.Run();
1517 run_loop2.Run(); 1528 run_loop2.Run();
1518 // Should not call EnableMdnsDiscovery, but will call UpdateMediaSinks 1529 // Should not call EnableMdnsDiscovery, but will call UpdateMediaSinks
1519 media_router_->OnUserGesture(); 1530 media_router_->OnUserGesture();
1520 base::RunLoop run_loop3; 1531 base::RunLoop run_loop3;
(...skipping 20 matching lines...) Expand all
1541 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) 1552 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")))
1542 .WillOnce(InvokeWithoutArgs([&run_loop5]() { 1553 .WillOnce(InvokeWithoutArgs([&run_loop5]() {
1543 run_loop5.Quit(); 1554 run_loop5.Quit();
1544 })); 1555 }));
1545 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) 1556 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id()))
1546 .WillOnce(Return(false)).WillOnce(Return(false)); 1557 .WillOnce(Return(false)).WillOnce(Return(false));
1547 // Expected because it was used to wake up the page. 1558 // Expected because it was used to wake up the page.
1548 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId)); 1559 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId));
1549 EXPECT_CALL(mock_media_route_provider_, 1560 EXPECT_CALL(mock_media_route_provider_,
1550 UpdateMediaSinks(MediaSourceForDesktop().id())); 1561 UpdateMediaSinks(MediaSourceForDesktop().id()));
1551 // EnableMdnsDisocvery() is never called except on Windows. 1562 // EnableMdnsDiscovery() is never called except on Windows.
1552 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) 1563 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery())
1553 .WillOnce(InvokeWithoutArgs([&run_loop6]() { 1564 .WillOnce(InvokeWithoutArgs([&run_loop6]() {
1554 run_loop6.Quit(); 1565 run_loop6.Quit();
1555 })); 1566 }));
1556 BindMediaRouteProvider(); 1567 BindMediaRouteProvider();
1557 RegisterMediaRouteProvider(); 1568 RegisterMediaRouteProvider();
1558 run_loop5.Run(); 1569 run_loop5.Run();
1559 run_loop6.Run(); 1570 run_loop6.Run();
1560 // Should not call EnableMdnsDiscovery, but will call UpdateMediaSinks 1571 // Should not call EnableMdnsDiscovery, but will call UpdateMediaSinks
1561 media_router_->OnUserGesture(); 1572 media_router_->OnUserGesture();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 #endif 1606 #endif
1596 EXPECT_CALL(mock_media_route_provider_, 1607 EXPECT_CALL(mock_media_route_provider_,
1597 UpdateMediaSinks(MediaSourceForDesktop().id())) 1608 UpdateMediaSinks(MediaSourceForDesktop().id()))
1598 .WillOnce(InvokeWithoutArgs([&run_loop2]() { 1609 .WillOnce(InvokeWithoutArgs([&run_loop2]() {
1599 run_loop2.Quit(); 1610 run_loop2.Quit();
1600 })); 1611 }));
1601 1612
1602 run_loop2.Run(); 1613 run_loop2.Run();
1603 } 1614 }
1604 1615
1616 TEST_F(MediaRouterMojoExtensionTest, SyncStateToMediaRouteProvider) {
1617 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id()))
1618 .WillRepeatedly(Return(false));
1619 MediaSource media_source = MediaSource(kSource);
1620 std::unique_ptr<MockMediaSinksObserver> sinks_observer;
1621 std::unique_ptr<MockMediaRoutesObserver> routes_observer;
1622 std::unique_ptr<NullMessageObserver> messages_observer;
1623
1624 {
1625 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")));
1626 BindMediaRouteProvider();
1627 RegisterMediaRouteProvider();
1628 base::RunLoop().RunUntilIdle();
1629 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&provide_handler_));
1630 }
1631
1632 {
1633 media_router_->OnSinkAvailabilityUpdated(
1634 mojom::MediaRouter::SinkAvailability::PER_SOURCE);
1635 EXPECT_CALL(mock_media_route_provider_,
1636 StartObservingMediaSinks(media_source.id()));
1637 sinks_observer.reset(new MockMediaSinksObserver(
1638 router(), media_source, url::Origin(GURL(kOrigin))));
1639 EXPECT_TRUE(sinks_observer->Init());
1640
1641 EXPECT_CALL(mock_media_route_provider_,
1642 StartObservingMediaRoutes(media_source.id()));
1643 routes_observer.reset(
1644 new MockMediaRoutesObserver(router(), media_source.id()));
1645
1646 EXPECT_CALL(mock_media_route_provider_,
1647 StartListeningForRouteMessages(media_source.id()));
1648 messages_observer.reset(
1649 new NullMessageObserver(router(), media_source.id()));
1650 base::RunLoop().RunUntilIdle();
1651 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_media_route_provider_));
1652 }
1653
1654 {
1655 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")));
1656 EXPECT_CALL(mock_media_route_provider_,
1657 StartObservingMediaSinks(media_source.id()));
1658 EXPECT_CALL(mock_media_route_provider_,
1659 StartObservingMediaRoutes(media_source.id()));
1660 EXPECT_CALL(mock_media_route_provider_,
1661 StartListeningForRouteMessages(media_source.id()));
1662 media_router_->OnConnectionError();
1663 BindMediaRouteProvider();
1664 RegisterMediaRouteProvider();
1665 base::RunLoop().RunUntilIdle();
1666 }
1667 }
1668
1605 } // namespace media_router 1669 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/media/router/mojo/media_router_mojo_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698