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

Side by Side Diff: chrome/browser/media/router/media_router_base_unittest.cc

Issue 2731043002: [Media Router] Add a presentation id to MediaRoute mapping in the MR (Closed)
Patch Set: resolve code review comments from Derek Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/test/mock_callback.h" 6 #include "base/test/mock_callback.h"
7 #include "chrome/browser/media/router/mock_media_router.h" 7 #include "chrome/browser/media/router/mock_media_router.h"
8 #include "chrome/browser/media/router/test_helper.h" 8 #include "chrome/browser/media/router/test_helper.h"
9 #include "content/public/common/presentation_session.h" 9 #include "content/public/common/presentation_session.h"
10 #include "content/public/test/test_browser_thread_bundle.h" 10 #include "content/public/test/test_browser_thread_bundle.h"
(...skipping 21 matching lines...) Expand all
32 route_id, callback); 32 route_id, callback);
33 } 33 }
34 34
35 void OnIncognitoProfileShutdown() override { 35 void OnIncognitoProfileShutdown() override {
36 MediaRouterBase::OnIncognitoProfileShutdown(); 36 MediaRouterBase::OnIncognitoProfileShutdown();
37 } 37 }
38 38
39 std::vector<MediaRoute> GetCurrentRoutes() const override { 39 std::vector<MediaRoute> GetCurrentRoutes() const override {
40 return MediaRouterBase::GetCurrentRoutes(); 40 return MediaRouterBase::GetCurrentRoutes();
41 } 41 }
42
43 const MediaRoute* GetPresentationRoute(
44 const std::string& presentation_id) const override {
45 return MediaRouterBase::GetPresentationRoute(presentation_id);
46 }
47
48 void SetPresentationId(const MediaRoute::Id& route_id,
49 const std::string& presentation_id) override {
50 MediaRouterBase::SetPresentationId(route_id, presentation_id);
51 }
42 }; 52 };
43 53
44 class MediaRouterBaseTest : public testing::Test { 54 class MediaRouterBaseTest : public testing::Test {
45 public: 55 public:
46 void SetUp() override { 56 void SetUp() override {
47 EXPECT_CALL(router_, RegisterMediaRoutesObserver(_)) 57 EXPECT_CALL(router_, RegisterMediaRoutesObserver(_))
48 .WillOnce(SaveArg<0>(&routes_observer_)); 58 .WillOnce(SaveArg<0>(&routes_observer_));
49 router_.Initialize(); 59 router_.Initialize();
50 } 60 }
51 61
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 std::vector<MediaRoute> current_routes = router_.GetCurrentRoutes(); 139 std::vector<MediaRoute> current_routes = router_.GetCurrentRoutes();
130 ASSERT_EQ(current_routes.size(), 2u); 140 ASSERT_EQ(current_routes.size(), 2u);
131 EXPECT_TRUE(current_routes[0].Equals(route1)); 141 EXPECT_TRUE(current_routes[0].Equals(route1));
132 EXPECT_TRUE(current_routes[1].Equals(route2)); 142 EXPECT_TRUE(current_routes[1].Equals(route2));
133 143
134 routes_observer_->OnRoutesUpdated(std::vector<MediaRoute>(), 144 routes_observer_->OnRoutesUpdated(std::vector<MediaRoute>(),
135 std::vector<MediaRoute::Id>()); 145 std::vector<MediaRoute::Id>());
136 EXPECT_TRUE(router_.GetCurrentRoutes().empty()); 146 EXPECT_TRUE(router_.GetCurrentRoutes().empty());
137 } 147 }
138 148
149 TEST_F(MediaRouterBaseTest, GetPresentationRoute) {
150 MediaSource source1("source_1");
151 MediaSource source2("source_2");
152 MediaRoute route1("route_1", source1, "sink_1", "", false, "", false);
153 MediaRoute route2("route_2", source2, "sink_2", "", true, "", false);
154 std::string presentation_id1("presentation_id1");
155 std::string presentation_id2("presentation_id2");
156 std::string presentation_id3("presentation_id3");
157 route1.set_presentation_id(presentation_id1);
158 route2.set_presentation_id(presentation_id2);
159 std::vector<MediaRoute> routes = {route1, route2};
160 std::vector<MediaRoute::Id> joinable_route_ids = {"route_1"};
161
162 EXPECT_FALSE(router_.GetPresentationRoute(presentation_id1));
163
164 routes_observer_->OnRoutesUpdated(routes, joinable_route_ids);
165 auto* actual_route1 = router_.GetPresentationRoute(presentation_id1);
166 auto* actual_route2 = router_.GetPresentationRoute(presentation_id2);
167
168 EXPECT_TRUE(actual_route1 && actual_route1->Equals(route1));
169 EXPECT_TRUE(actual_route2 && actual_route2->Equals(route2));
170 EXPECT_FALSE(router_.GetPresentationRoute(presentation_id3));
171
172 routes.erase(routes.begin());
173 routes_observer_->OnRoutesUpdated(routes, joinable_route_ids);
174
175 EXPECT_FALSE(router_.GetPresentationRoute(presentation_id1));
176 }
177
178 TEST_F(MediaRouterBaseTest, OnRoutes) {
179 MediaSource source1("source_1");
180 MediaSource source2("source_2");
181 MediaRoute route1("route_1", source1, "sink_1", "", false, "", false);
182 MediaRoute route2("route_2", source2, "sink_2", "", true, "", false);
183 std::string presentation_id1("presentation_id1");
184 std::string presentation_id2("presentation_id2");
185 std::string presentation_id3("presentation_id3");
186 std::vector<MediaRoute> routes = {route1, route2};
187 std::vector<MediaRoute::Id> joinable_route_ids = {"route_1"};
188
189 EXPECT_FALSE(router_.GetPresentationRoute(presentation_id1));
190
191 routes_observer_->OnRoutesUpdated(routes, joinable_route_ids);
192 router_.SetPresentationId(route1.media_route_id(), presentation_id1);
193 router_.SetPresentationId(route2.media_route_id(), presentation_id2);
194 router_.SetPresentationId("route3", presentation_id3);
195
196 auto* actual_route1 = router_.GetPresentationRoute(presentation_id1);
197 auto* actual_route2 = router_.GetPresentationRoute(presentation_id2);
198
199 EXPECT_TRUE(actual_route1 && actual_route1->Equals(route1));
200 EXPECT_TRUE(actual_route2 && actual_route2->Equals(route2));
201 EXPECT_FALSE(router_.GetPresentationRoute(presentation_id3));
202
203 routes.erase(routes.begin());
204 routes_observer_->OnRoutesUpdated(routes, joinable_route_ids);
205
206 EXPECT_FALSE(router_.GetPresentationRoute(presentation_id1));
207 }
208
209 TEST_F(MediaRouterBaseTest, OnRoutesUpdated) {
210 MediaSource source1("source_1");
211 MediaSource source2("source_2");
212 MediaRoute route1("route_1", source1, "sink_1", "", false, "", false);
213 MediaRoute route2("route_2", source2, "sink_2", "", true, "", false);
214 std::string presentation_id1("presentation_id1");
215 std::string presentation_id2("presentation_id2");
216 std::string presentation_id3("presentation_id3");
217 std::string presentation_id4("presentation_id4");
218
219 std::vector<MediaRoute> routes1 = {route1, route2};
220 std::vector<MediaRoute::Id> joinable_route_ids = {"route_1"};
221 routes_observer_->OnRoutesUpdated(routes1, joinable_route_ids);
222 router_.SetPresentationId(route2.media_route_id(), presentation_id2);
223
224 std::vector<MediaRoute> routes2 = {route1, route2};
225 routes_observer_->OnRoutesUpdated(routes2, joinable_route_ids);
226
227 // Preserve old presentation id.
228 auto* actual_route2 = router_.GetPresentationRoute(presentation_id2);
229 EXPECT_TRUE(actual_route2 && actual_route2->Equals(route2));
230
231 // Use new presentation id.
232 route1.set_presentation_id(presentation_id3);
233 route2.set_presentation_id(presentation_id4);
234
235 std::vector<MediaRoute> routes3 = {route1, route2};
236 routes_observer_->OnRoutesUpdated(routes3, joinable_route_ids);
237
238 EXPECT_FALSE(router_.GetPresentationRoute(presentation_id2));
239 auto* actual_route4 = router_.GetPresentationRoute(presentation_id4);
240 EXPECT_TRUE(actual_route4 && actual_route4->Equals(route2));
241 }
242
139 } // namespace media_router 243 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698