| 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 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 DoInvoke(result.route(), result.presentation_id(), result.error(), | 112 DoInvoke(result.route(), result.presentation_id(), result.error(), |
| 113 result.result_code()); | 113 result.result_code()); |
| 114 } | 114 } |
| 115 MOCK_METHOD4(DoInvoke, | 115 MOCK_METHOD4(DoInvoke, |
| 116 void(const MediaRoute* route, | 116 void(const MediaRoute* route, |
| 117 const std::string& presentation_id, | 117 const std::string& presentation_id, |
| 118 const std::string& error_text, | 118 const std::string& error_text, |
| 119 RouteRequestResult::ResultCode result_code)); | 119 RouteRequestResult::ResultCode result_code)); |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 class SinkResponseCallbackHandler { |
| 123 public: |
| 124 MOCK_METHOD1(Invoke, void(const std::string& sink_id)); |
| 125 }; |
| 126 |
| 122 class SendMessageCallbackHandler { | 127 class SendMessageCallbackHandler { |
| 123 public: | 128 public: |
| 124 MOCK_METHOD1(Invoke, void(bool)); | 129 MOCK_METHOD1(Invoke, void(bool)); |
| 125 }; | 130 }; |
| 126 | 131 |
| 127 class ListenForMessagesCallbackHandler { | 132 class ListenForMessagesCallbackHandler { |
| 128 public: | 133 public: |
| 129 ListenForMessagesCallbackHandler( | 134 ListenForMessagesCallbackHandler( |
| 130 ScopedVector<content::PresentationSessionMessage> expected_messages, | 135 ScopedVector<content::PresentationSessionMessage> expected_messages, |
| 131 bool pass_ownership) | 136 bool pass_ownership) |
| (...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 run_loop.Run(); | 1182 run_loop.Run(); |
| 1178 EXPECT_CALL(mock_event_page_tracker_, IsEventPageSuspended(extension_id())) | 1183 EXPECT_CALL(mock_event_page_tracker_, IsEventPageSuspended(extension_id())) |
| 1179 .Times(1) | 1184 .Times(1) |
| 1180 .WillRepeatedly(Return(false)); | 1185 .WillRepeatedly(Return(false)); |
| 1181 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))); | 1186 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))); |
| 1182 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2))); | 1187 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2))); |
| 1183 ConnectProviderManagerService(); | 1188 ConnectProviderManagerService(); |
| 1184 ProcessEventLoop(); | 1189 ProcessEventLoop(); |
| 1185 } | 1190 } |
| 1186 | 1191 |
| 1192 TEST_F(MediaRouterMojoImplTest, SearchSinksAndCreateRoute) { |
| 1193 std::string search_input("input"); |
| 1194 std::string domain("google.com"); |
| 1195 MediaSource media_source(kSource); |
| 1196 MediaRoute expected_route(kRouteId, media_source, kSinkId2, "", false, "", |
| 1197 false); |
| 1198 auto& media_router_proxy = media_router_proxy_; |
| 1199 |
| 1200 EXPECT_CALL( |
| 1201 mock_media_route_provider_, |
| 1202 SearchSinksAndCreateRoute_(mojo::String(kSinkId), mojo::String(kSource), |
| 1203 _, _, mojo::String(kOrigin), kInvalidTabId, _, |
| 1204 false, _)) |
| 1205 .WillOnce(Invoke([&search_input, &domain, &media_router_proxy]( |
| 1206 const mojo::String& sink_id, const mojo::String& source, |
| 1207 const interfaces::SinkSearchCriteriaPtr& search_criteria, |
| 1208 const mojo::String& presentation_id, const mojo::String& origin, |
| 1209 int32_t tab_id, int64_t timeout_millis, bool off_the_record, |
| 1210 const interfaces::MediaRouteProvider:: |
| 1211 SearchSinksAndCreateRouteCallback& cb) { |
| 1212 interfaces::MediaRoutePtr route = interfaces::MediaRoute::New(); |
| 1213 route->media_source = source; |
| 1214 route->media_sink_id = kSinkId2; |
| 1215 route->media_route_id = kRouteId; |
| 1216 route->description = kDescription; |
| 1217 route->is_local = true; |
| 1218 route->for_display = true; |
| 1219 route->off_the_record = off_the_record; |
| 1220 EXPECT_EQ(search_input, search_criteria->input); |
| 1221 EXPECT_EQ(domain, search_criteria->domain); |
| 1222 media_router_proxy->OnSearchSinkIdReceived(sink_id, kSinkId2); |
| 1223 cb.Run(std::move(route), mojo::String(), |
| 1224 interfaces::RouteRequestResultCode::OK); |
| 1225 })); |
| 1226 |
| 1227 base::RunLoop run_loop; |
| 1228 base::RunLoop run_loop2; |
| 1229 SinkResponseCallbackHandler sink_handler; |
| 1230 EXPECT_CALL(sink_handler, Invoke(kSinkId2)) |
| 1231 .WillOnce(InvokeWithoutArgs([&run_loop] { run_loop.Quit(); })); |
| 1232 RouteResponseCallbackHandler route_handler; |
| 1233 EXPECT_CALL(route_handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), |
| 1234 "", RouteRequestResult::OK)) |
| 1235 .WillOnce(InvokeWithoutArgs([&run_loop2] { run_loop2.Quit(); })); |
| 1236 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 1237 MediaSinkSearchResponseCallback sink_callback = base::Bind( |
| 1238 &SinkResponseCallbackHandler::Invoke, base::Unretained(&sink_handler)); |
| 1239 route_response_callbacks.push_back(base::Bind( |
| 1240 &RouteResponseCallbackHandler::Invoke, base::Unretained(&route_handler))); |
| 1241 router()->SearchSinksAndCreateRoute( |
| 1242 kSinkId, kSource, search_input, domain, GURL(kOrigin), nullptr, |
| 1243 route_response_callbacks, sink_callback, |
| 1244 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 1245 run_loop.Run(); |
| 1246 run_loop2.Run(); |
| 1247 } |
| 1248 |
| 1187 class MediaRouterMojoExtensionTest : public ::testing::Test { | 1249 class MediaRouterMojoExtensionTest : public ::testing::Test { |
| 1188 public: | 1250 public: |
| 1189 MediaRouterMojoExtensionTest() | 1251 MediaRouterMojoExtensionTest() |
| 1190 : process_manager_(nullptr), | 1252 : process_manager_(nullptr), |
| 1191 message_loop_(mojo::common::MessagePumpMojo::Create()) {} | 1253 message_loop_(mojo::common::MessagePumpMojo::Create()) {} |
| 1192 | 1254 |
| 1193 ~MediaRouterMojoExtensionTest() override {} | 1255 ~MediaRouterMojoExtensionTest() override {} |
| 1194 | 1256 |
| 1195 protected: | 1257 protected: |
| 1196 void SetUp() override { | 1258 void SetUp() override { |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1515 BindMediaRouteProvider(); | 1577 BindMediaRouteProvider(); |
| 1516 RegisterMediaRouteProvider(); | 1578 RegisterMediaRouteProvider(); |
| 1517 run_loop4.Run(); | 1579 run_loop4.Run(); |
| 1518 run_loop5.Run(); | 1580 run_loop5.Run(); |
| 1519 // Always a no-op at this point. | 1581 // Always a no-op at this point. |
| 1520 media_router_->OnUserGesture(); | 1582 media_router_->OnUserGesture(); |
| 1521 } | 1583 } |
| 1522 #endif | 1584 #endif |
| 1523 | 1585 |
| 1524 } // namespace media_router | 1586 } // namespace media_router |
| OLD | NEW |