Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / media_router / media_router_ui_unittest.cc
blob44bb9d0e85535d2e06b1831bbacaa3b52fa56df0
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
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "chrome/browser/media/router/media_route.h"
7 #include "chrome/browser/media/router/mock_media_router.h"
8 #include "chrome/browser/ui/webui/media_router/media_router_ui.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 using testing::_;
13 using testing::SaveArg;
15 namespace media_router {
17 class MediaRouterUITest : public ::testing::Test {
18 public:
19 MediaRouterUITest() {}
20 ~MediaRouterUITest() override {}
22 MOCK_METHOD1(OnRoutesUpdated, void(const std::vector<MediaRoute>& routes));
25 TEST_F(MediaRouterUITest, UIMediaRoutesObserverFiltersNonDisplayRoutes) {
26 MockMediaRouter mock_router;
27 EXPECT_CALL(mock_router, RegisterMediaRoutesObserver(_)).Times(1);
28 scoped_ptr<MediaRouterUI::UIMediaRoutesObserver> observer(
29 new MediaRouterUI::UIMediaRoutesObserver(
30 &mock_router, base::Bind(&MediaRouterUITest::OnRoutesUpdated,
31 base::Unretained(this))));
33 MediaRoute display_route_1("routeId1", MediaSource("mediaSource"), "sinkId1",
34 "desc 1", true, "", true);
35 MediaRoute non_display_route_1("routeId2", MediaSource("mediaSource"),
36 "sinkId2", "desc 2", true, "", false);
37 MediaRoute display_route_2("routeId2", MediaSource("mediaSource"), "sinkId2",
38 "desc 2", true, "", true);
39 std::vector<MediaRoute> routes;
40 routes.push_back(display_route_1);
41 routes.push_back(non_display_route_1);
42 routes.push_back(display_route_2);
44 std::vector<MediaRoute> filtered_routes;
45 EXPECT_CALL(*this, OnRoutesUpdated(_)).WillOnce(SaveArg<0>(&filtered_routes));
46 observer->OnRoutesUpdated(routes);
48 ASSERT_EQ(2u, filtered_routes.size());
49 EXPECT_TRUE(display_route_1.Equals(filtered_routes[0]));
50 EXPECT_TRUE(filtered_routes[0].for_display());
51 EXPECT_TRUE(display_route_2.Equals(filtered_routes[1]));
52 EXPECT_TRUE(filtered_routes[1].for_display());
54 EXPECT_CALL(mock_router, UnregisterMediaRoutesObserver(_)).Times(1);
55 observer.reset();
58 } // namespace media_router