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

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

Issue 2867713002: Use OnceCallback on Mojo interfaces in //chrome/common/media_router (Closed)
Patch Set: rebase. +#include 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // Creates a media route whose ID is |kRouteId2|. 98 // Creates a media route whose ID is |kRouteId2|.
99 MediaRoute CreateMediaRoute2() { 99 MediaRoute CreateMediaRoute2() {
100 return MediaRoute(kRouteId2, MediaSource(kSource), kSinkId, kDescription, 100 return MediaRoute(kRouteId2, MediaSource(kSource), kSinkId, kDescription,
101 true, std::string(), true); 101 true, std::string(), true);
102 } 102 }
103 103
104 void OnCreateMediaRouteController( 104 void OnCreateMediaRouteController(
105 Unused, 105 Unused,
106 Unused, 106 Unused,
107 Unused, 107 Unused,
108 const mojom::MediaRouteProvider::CreateMediaRouteControllerCallback& cb) { 108 mojom::MediaRouteProvider::CreateMediaRouteControllerCallback& cb) {
109 cb.Run(true); 109 std::move(cb).Run(true);
110 } 110 }
111 111
112 } // namespace 112 } // namespace
113 113
114 class RouteResponseCallbackHandler { 114 class RouteResponseCallbackHandler {
115 public: 115 public:
116 void Invoke(const RouteRequestResult& result) { 116 void Invoke(const RouteRequestResult& result) {
117 DoInvoke(result.route(), result.presentation_id(), result.error(), 117 DoInvoke(result.route(), result.presentation_id(), result.error(),
118 result.result_code()); 118 result.result_code());
119 } 119 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 }; 191 };
192 192
193 TEST_F(MediaRouterMojoImplTest, CreateRoute) { 193 TEST_F(MediaRouterMojoImplTest, CreateRoute) {
194 MediaSource media_source(kSource); 194 MediaSource media_source(kSource);
195 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", 195 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "",
196 false); 196 false);
197 197
198 // Use a lambda function as an invocation target here to work around 198 // Use a lambda function as an invocation target here to work around
199 // a limitation with GMock::Invoke that prevents it from using move-only types 199 // a limitation with GMock::Invoke that prevents it from using move-only types
200 // in runnable parameter lists. 200 // in runnable parameter lists.
201 EXPECT_CALL(mock_media_route_provider_, 201 EXPECT_CALL(
202 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), 202 mock_media_route_provider_,
203 CreateRouteInternal(kSource, kSinkId, _, url::Origin(GURL(kOrigin)),
203 kInvalidTabId, _, _, _)) 204 kInvalidTabId, _, _, _))
204 .WillOnce(Invoke( 205 .WillOnce(Invoke([](const std::string& source, const std::string& sink,
205 [](const std::string& source, const std::string& sink, 206 const std::string& presentation_id,
206 const std::string& presentation_id, const url::Origin& origin, 207 const url::Origin& origin, int tab_id,
207 int tab_id, base::TimeDelta timeout, bool incognito, 208 base::TimeDelta timeout, bool incognito,
208 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { 209 mojom::MediaRouteProvider::CreateRouteCallback& cb) {
209 cb.Run(CreateMediaRoute(), std::string(), RouteRequestResult::OK); 210 std::move(cb).Run(CreateMediaRoute(), std::string(),
210 })); 211 RouteRequestResult::OK);
212 }));
211 213
212 base::RunLoop run_loop; 214 base::RunLoop run_loop;
213 RouteResponseCallbackHandler handler; 215 RouteResponseCallbackHandler handler;
214 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", 216 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "",
215 RouteRequestResult::OK)) 217 RouteRequestResult::OK))
216 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 218 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
217 std::vector<MediaRouteResponseCallback> route_response_callbacks; 219 std::vector<MediaRouteResponseCallback> route_response_callbacks;
218 route_response_callbacks.push_back(base::Bind( 220 route_response_callbacks.push_back(base::Bind(
219 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); 221 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
220 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, 222 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr,
221 route_response_callbacks, 223 route_response_callbacks,
222 base::TimeDelta::FromMilliseconds(kTimeoutMillis), 224 base::TimeDelta::FromMilliseconds(kTimeoutMillis),
223 false); 225 false);
224 run_loop.Run(); 226 run_loop.Run();
225 ExpectResultBucketCount("CreateRoute", RouteRequestResult::OK, 1); 227 ExpectResultBucketCount("CreateRoute", RouteRequestResult::OK, 1);
226 } 228 }
227 229
228 TEST_F(MediaRouterMojoImplTest, CreateIncognitoRoute) { 230 TEST_F(MediaRouterMojoImplTest, CreateIncognitoRoute) {
229 MediaSource media_source(kSource); 231 MediaSource media_source(kSource);
230 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", 232 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "",
231 false); 233 false);
232 expected_route.set_incognito(true); 234 expected_route.set_incognito(true);
233 235
234 // Use a lambda function as an invocation target here to work around 236 // Use a lambda function as an invocation target here to work around
235 // a limitation with GMock::Invoke that prevents it from using move-only types 237 // a limitation with GMock::Invoke that prevents it from using move-only types
236 // in runnable parameter lists. 238 // in runnable parameter lists.
237 EXPECT_CALL(mock_media_route_provider_, 239 EXPECT_CALL(
238 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), 240 mock_media_route_provider_,
241 CreateRouteInternal(kSource, kSinkId, _, url::Origin(GURL(kOrigin)),
239 kInvalidTabId, _, _, _)) 242 kInvalidTabId, _, _, _))
240 .WillOnce(Invoke([&expected_route]( 243 .WillOnce(Invoke([&expected_route](
241 const std::string& source, const std::string& sink, 244 const std::string& source, const std::string& sink,
242 const std::string& presentation_id, const url::Origin& origin, 245 const std::string& presentation_id,
243 int tab_id, base::TimeDelta timeout, bool incognito, 246 const url::Origin& origin, int tab_id,
244 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { 247 base::TimeDelta timeout, bool incognito,
245 cb.Run(expected_route, std::string(), RouteRequestResult::OK); 248 mojom::MediaRouteProvider::CreateRouteCallback& cb) {
249 std::move(cb).Run(expected_route, std::string(),
250 RouteRequestResult::OK);
246 })); 251 }));
247 252
248 base::RunLoop run_loop; 253 base::RunLoop run_loop;
249 RouteResponseCallbackHandler handler; 254 RouteResponseCallbackHandler handler;
250 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", 255 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "",
251 RouteRequestResult::OK)) 256 RouteRequestResult::OK))
252 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 257 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
253 std::vector<MediaRouteResponseCallback> route_response_callbacks; 258 std::vector<MediaRouteResponseCallback> route_response_callbacks;
254 route_response_callbacks.push_back(base::Bind( 259 route_response_callbacks.push_back(base::Bind(
255 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); 260 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
256 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, 261 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr,
257 route_response_callbacks, 262 route_response_callbacks,
258 base::TimeDelta::FromMilliseconds(kTimeoutMillis), 263 base::TimeDelta::FromMilliseconds(kTimeoutMillis),
259 true); 264 true);
260 run_loop.Run(); 265 run_loop.Run();
261 ExpectResultBucketCount("CreateRoute", RouteRequestResult::OK, 1); 266 ExpectResultBucketCount("CreateRoute", RouteRequestResult::OK, 1);
262 } 267 }
263 268
264 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) { 269 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) {
265 EXPECT_CALL( 270 EXPECT_CALL(
266 mock_media_route_provider_, 271 mock_media_route_provider_,
267 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), 272 CreateRouteInternal(
268 kInvalidTabId, 273 kSource, kSinkId, _, url::Origin(GURL(kOrigin)), kInvalidTabId,
269 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) 274 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _))
270 .WillOnce(Invoke( 275 .WillOnce(Invoke([](const std::string& source, const std::string& sink,
271 [](const std::string& source, const std::string& sink, 276 const std::string& presentation_id,
272 const std::string& presentation_id, const url::Origin& origin, 277 const url::Origin& origin, int tab_id,
273 int tab_id, base::TimeDelta timeout, bool incognito, 278 base::TimeDelta timeout, bool incognito,
274 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { 279 mojom::MediaRouteProvider::CreateRouteCallback& cb) {
275 cb.Run(base::nullopt, std::string(kError), 280 std::move(cb).Run(base::nullopt, std::string(kError),
276 RouteRequestResult::TIMED_OUT); 281 RouteRequestResult::TIMED_OUT);
277 })); 282 }));
278 283
279 RouteResponseCallbackHandler handler; 284 RouteResponseCallbackHandler handler;
280 base::RunLoop run_loop; 285 base::RunLoop run_loop;
281 EXPECT_CALL(handler, 286 EXPECT_CALL(handler,
282 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) 287 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT))
283 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 288 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
284 std::vector<MediaRouteResponseCallback> route_response_callbacks; 289 std::vector<MediaRouteResponseCallback> route_response_callbacks;
285 route_response_callbacks.push_back(base::Bind( 290 route_response_callbacks.push_back(base::Bind(
286 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); 291 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
287 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, 292 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr,
288 route_response_callbacks, 293 route_response_callbacks,
289 base::TimeDelta::FromMilliseconds(kTimeoutMillis), 294 base::TimeDelta::FromMilliseconds(kTimeoutMillis),
290 false); 295 false);
291 run_loop.Run(); 296 run_loop.Run();
292 ExpectResultBucketCount("CreateRoute", RouteRequestResult::TIMED_OUT, 1); 297 ExpectResultBucketCount("CreateRoute", RouteRequestResult::TIMED_OUT, 1);
293 } 298 }
294 299
295 TEST_F(MediaRouterMojoImplTest, CreateRouteIncognitoMismatchFails) { 300 TEST_F(MediaRouterMojoImplTest, CreateRouteIncognitoMismatchFails) {
296 EXPECT_CALL( 301 EXPECT_CALL(
297 mock_media_route_provider_, 302 mock_media_route_provider_,
298 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), 303 CreateRouteInternal(
299 kInvalidTabId, 304 kSource, kSinkId, _, url::Origin(GURL(kOrigin)), kInvalidTabId,
300 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) 305 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _))
301 .WillOnce(Invoke( 306 .WillOnce(Invoke([](const std::string& source, const std::string& sink,
302 [](const std::string& source, const std::string& sink, 307 const std::string& presentation_id,
303 const std::string& presentation_id, const url::Origin& origin, 308 const url::Origin& origin, int tab_id,
304 int tab_id, base::TimeDelta timeout, bool incognito, 309 base::TimeDelta timeout, bool incognito,
305 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { 310 mojom::MediaRouteProvider::CreateRouteCallback& cb) {
306 cb.Run(CreateMediaRoute(), std::string(), RouteRequestResult::OK); 311 std::move(cb).Run(CreateMediaRoute(), std::string(),
307 })); 312 RouteRequestResult::OK);
313 }));
308 314
309 RouteResponseCallbackHandler handler; 315 RouteResponseCallbackHandler handler;
310 base::RunLoop run_loop; 316 base::RunLoop run_loop;
311 std::string error("Mismatch in incognito status: request = 1, response = 0"); 317 std::string error("Mismatch in incognito status: request = 1, response = 0");
312 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, 318 EXPECT_CALL(handler, DoInvoke(nullptr, "", error,
313 RouteRequestResult::INCOGNITO_MISMATCH)) 319 RouteRequestResult::INCOGNITO_MISMATCH))
314 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 320 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
315 std::vector<MediaRouteResponseCallback> route_response_callbacks; 321 std::vector<MediaRouteResponseCallback> route_response_callbacks;
316 route_response_callbacks.push_back(base::Bind( 322 route_response_callbacks.push_back(base::Bind(
317 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); 323 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
318 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, 324 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr,
319 route_response_callbacks, 325 route_response_callbacks,
320 base::TimeDelta::FromMilliseconds(kTimeoutMillis), 326 base::TimeDelta::FromMilliseconds(kTimeoutMillis),
321 true); 327 true);
322 run_loop.Run(); 328 run_loop.Run();
323 ExpectResultBucketCount("CreateRoute", RouteRequestResult::INCOGNITO_MISMATCH, 329 ExpectResultBucketCount("CreateRoute", RouteRequestResult::INCOGNITO_MISMATCH,
324 1); 330 1);
325 } 331 }
326 332
327 TEST_F(MediaRouterMojoImplTest, IncognitoRoutesTerminatedOnProfileShutdown) { 333 TEST_F(MediaRouterMojoImplTest, IncognitoRoutesTerminatedOnProfileShutdown) {
328 MediaRoute route = CreateMediaRoute(); 334 MediaRoute route = CreateMediaRoute();
329 route.set_incognito(true); 335 route.set_incognito(true);
330 336
331 EXPECT_CALL( 337 EXPECT_CALL(
332 mock_media_route_provider_, 338 mock_media_route_provider_,
333 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), 339 CreateRouteInternal(
334 kInvalidTabId, 340 kSource, kSinkId, _, url::Origin(GURL(kOrigin)), kInvalidTabId,
335 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) 341 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _))
336 .WillOnce(Invoke([&route]( 342 .WillOnce(
337 const std::string& source, const std::string& sink, 343 Invoke([&route](const std::string& source, const std::string& sink,
338 const std::string& presentation_id, const url::Origin& origin, 344 const std::string& presentation_id,
339 int tab_id, base::TimeDelta timeout, bool incognito, 345 const url::Origin& origin, int tab_id,
340 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { 346 base::TimeDelta timeout, bool incognito,
341 cb.Run(route, std::string(), RouteRequestResult::OK); 347 mojom::MediaRouteProvider::CreateRouteCallback& cb) {
342 })); 348 std::move(cb).Run(route, std::string(), RouteRequestResult::OK);
349 }));
343 base::RunLoop run_loop; 350 base::RunLoop run_loop;
344 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, 351 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr,
345 std::vector<MediaRouteResponseCallback>(), 352 std::vector<MediaRouteResponseCallback>(),
346 base::TimeDelta::FromMilliseconds(kTimeoutMillis), 353 base::TimeDelta::FromMilliseconds(kTimeoutMillis),
347 true); 354 true);
348 std::vector<MediaRoute> routes; 355 std::vector<MediaRoute> routes;
349 routes.push_back(route); 356 routes.push_back(route);
350 router()->OnRoutesUpdated(routes, std::string(), std::vector<std::string>()); 357 router()->OnRoutesUpdated(routes, std::string(), std::vector<std::string>());
351 358
352 // TODO(mfoltz): Where possible, convert other tests to use RunUntilIdle 359 // TODO(mfoltz): Where possible, convert other tests to use RunUntilIdle
353 // instead of manually calling Run/Quit on the run loop. 360 // instead of manually calling Run/Quit on the run loop.
354 run_loop.RunUntilIdle(); 361 run_loop.RunUntilIdle();
355 362
356 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) 363 EXPECT_CALL(mock_media_route_provider_, TerminateRouteInternal(kRouteId, _))
357 .WillOnce(Invoke( 364 .WillOnce(
358 [](const std::string& route_id, 365 Invoke([](const std::string& route_id,
359 const mojom::MediaRouteProvider::TerminateRouteCallback& cb) { 366 mojom::MediaRouteProvider::TerminateRouteCallback& cb) {
360 cb.Run(base::nullopt, RouteRequestResult::OK); 367 std::move(cb).Run(base::nullopt, RouteRequestResult::OK);
361 })); 368 }));
362 369
363 base::RunLoop run_loop2; 370 base::RunLoop run_loop2;
364 router()->OnIncognitoProfileShutdown(); 371 router()->OnIncognitoProfileShutdown();
365 run_loop2.RunUntilIdle(); 372 run_loop2.RunUntilIdle();
366 } 373 }
367 374
368 TEST_F(MediaRouterMojoImplTest, JoinRoute) { 375 TEST_F(MediaRouterMojoImplTest, JoinRoute) {
369 MediaSource media_source(kSource); 376 MediaSource media_source(kSource);
370 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", 377 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "",
371 false); 378 false);
372 379
373 MediaRoute route = CreateMediaRoute(); 380 MediaRoute route = CreateMediaRoute();
374 // Make sure the MR has received an update with the route, so it knows there 381 // Make sure the MR has received an update with the route, so it knows there
375 // is a route to join. 382 // is a route to join.
376 std::vector<MediaRoute> routes; 383 std::vector<MediaRoute> routes;
377 routes.push_back(route); 384 routes.push_back(route);
378 router()->OnRoutesUpdated(routes, std::string(), std::vector<std::string>()); 385 router()->OnRoutesUpdated(routes, std::string(), std::vector<std::string>());
379 EXPECT_TRUE(router()->HasJoinableRoute()); 386 EXPECT_TRUE(router()->HasJoinableRoute());
380 387
381 // Use a lambda function as an invocation target here to work around 388 // Use a lambda function as an invocation target here to work around
382 // a limitation with GMock::Invoke that prevents it from using move-only types 389 // a limitation with GMock::Invoke that prevents it from using move-only types
383 // in runnable parameter lists. 390 // in runnable parameter lists.
384 EXPECT_CALL( 391 EXPECT_CALL(
385 mock_media_route_provider_, 392 mock_media_route_provider_,
386 JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), 393 JoinRouteInternal(
387 kInvalidTabId, 394 kSource, kPresentationId, url::Origin(GURL(kOrigin)), kInvalidTabId,
388 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) 395 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _))
389 .WillOnce(Invoke([&route]( 396 .WillOnce(
390 const std::string& source, const std::string& presentation_id, 397 Invoke([&route](const std::string& source,
391 const url::Origin& origin, int tab_id, base::TimeDelta timeout, 398 const std::string& presentation_id,
392 bool incognito, 399 const url::Origin& origin, int tab_id,
393 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { 400 base::TimeDelta timeout, bool incognito,
394 cb.Run(route, std::string(), RouteRequestResult::OK); 401 mojom::MediaRouteProvider::JoinRouteCallback& cb) {
395 })); 402 std::move(cb).Run(route, std::string(), RouteRequestResult::OK);
403 }));
396 404
397 RouteResponseCallbackHandler handler; 405 RouteResponseCallbackHandler handler;
398 base::RunLoop run_loop; 406 base::RunLoop run_loop;
399 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", 407 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "",
400 RouteRequestResult::OK)) 408 RouteRequestResult::OK))
401 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 409 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
402 std::vector<MediaRouteResponseCallback> route_response_callbacks; 410 std::vector<MediaRouteResponseCallback> route_response_callbacks;
403 route_response_callbacks.push_back(base::Bind( 411 route_response_callbacks.push_back(base::Bind(
404 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); 412 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
405 router()->JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), 413 router()->JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)),
(...skipping 22 matching lines...) Expand all
428 TEST_F(MediaRouterMojoImplTest, JoinRouteTimedOutFails) { 436 TEST_F(MediaRouterMojoImplTest, JoinRouteTimedOutFails) {
429 // Make sure the MR has received an update with the route, so it knows there 437 // Make sure the MR has received an update with the route, so it knows there
430 // is a route to join. 438 // is a route to join.
431 std::vector<MediaRoute> routes; 439 std::vector<MediaRoute> routes;
432 routes.push_back(CreateMediaRoute()); 440 routes.push_back(CreateMediaRoute());
433 router()->OnRoutesUpdated(routes, std::string(), std::vector<std::string>()); 441 router()->OnRoutesUpdated(routes, std::string(), std::vector<std::string>());
434 EXPECT_TRUE(router()->HasJoinableRoute()); 442 EXPECT_TRUE(router()->HasJoinableRoute());
435 443
436 EXPECT_CALL( 444 EXPECT_CALL(
437 mock_media_route_provider_, 445 mock_media_route_provider_,
438 JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), 446 JoinRouteInternal(
439 kInvalidTabId, 447 kSource, kPresentationId, url::Origin(GURL(kOrigin)), kInvalidTabId,
440 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) 448 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _))
441 .WillOnce(Invoke( 449 .WillOnce(Invoke(
442 [](const std::string& source, const std::string& presentation_id, 450 [](const std::string& source, const std::string& presentation_id,
443 const url::Origin& origin, int tab_id, base::TimeDelta timeout, 451 const url::Origin& origin, int tab_id, base::TimeDelta timeout,
444 bool incognito, 452 bool incognito, mojom::MediaRouteProvider::JoinRouteCallback& cb) {
445 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { 453 std::move(cb).Run(base::nullopt, std::string(kError),
446 cb.Run(base::nullopt, std::string(kError), 454 RouteRequestResult::TIMED_OUT);
447 RouteRequestResult::TIMED_OUT);
448 })); 455 }));
449 456
450 RouteResponseCallbackHandler handler; 457 RouteResponseCallbackHandler handler;
451 base::RunLoop run_loop; 458 base::RunLoop run_loop;
452 EXPECT_CALL(handler, 459 EXPECT_CALL(handler,
453 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) 460 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT))
454 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 461 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
455 std::vector<MediaRouteResponseCallback> route_response_callbacks; 462 std::vector<MediaRouteResponseCallback> route_response_callbacks;
456 route_response_callbacks.push_back(base::Bind( 463 route_response_callbacks.push_back(base::Bind(
457 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); 464 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
(...skipping 12 matching lines...) Expand all
470 std::vector<MediaRoute> routes; 477 std::vector<MediaRoute> routes;
471 routes.push_back(route); 478 routes.push_back(route);
472 router()->OnRoutesUpdated(routes, std::string(), std::vector<std::string>()); 479 router()->OnRoutesUpdated(routes, std::string(), std::vector<std::string>());
473 EXPECT_TRUE(router()->HasJoinableRoute()); 480 EXPECT_TRUE(router()->HasJoinableRoute());
474 481
475 // Use a lambda function as an invocation target here to work around 482 // Use a lambda function as an invocation target here to work around
476 // a limitation with GMock::Invoke that prevents it from using move-only types 483 // a limitation with GMock::Invoke that prevents it from using move-only types
477 // in runnable parameter lists. 484 // in runnable parameter lists.
478 EXPECT_CALL( 485 EXPECT_CALL(
479 mock_media_route_provider_, 486 mock_media_route_provider_,
480 JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), 487 JoinRouteInternal(
481 kInvalidTabId, 488 kSource, kPresentationId, url::Origin(GURL(kOrigin)), kInvalidTabId,
482 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) 489 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _))
483 .WillOnce(Invoke([&route]( 490 .WillOnce(
484 const std::string& source, const std::string& presentation_id, 491 Invoke([&route](const std::string& source,
485 const url::Origin& origin, int tab_id, base::TimeDelta timeout, 492 const std::string& presentation_id,
486 bool incognito, 493 const url::Origin& origin, int tab_id,
487 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { 494 base::TimeDelta timeout, bool incognito,
488 cb.Run(route, std::string(), RouteRequestResult::OK); 495 mojom::MediaRouteProvider::JoinRouteCallback& cb) {
489 })); 496 std::move(cb).Run(route, std::string(), RouteRequestResult::OK);
497 }));
490 498
491 RouteResponseCallbackHandler handler; 499 RouteResponseCallbackHandler handler;
492 base::RunLoop run_loop; 500 base::RunLoop run_loop;
493 std::string error("Mismatch in incognito status: request = 1, response = 0"); 501 std::string error("Mismatch in incognito status: request = 1, response = 0");
494 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, 502 EXPECT_CALL(handler, DoInvoke(nullptr, "", error,
495 RouteRequestResult::INCOGNITO_MISMATCH)) 503 RouteRequestResult::INCOGNITO_MISMATCH))
496 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 504 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
497 std::vector<MediaRouteResponseCallback> route_response_callbacks; 505 std::vector<MediaRouteResponseCallback> route_response_callbacks;
498 route_response_callbacks.push_back(base::Bind( 506 route_response_callbacks.push_back(base::Bind(
499 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); 507 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
(...skipping 10 matching lines...) Expand all
510 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", 518 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "",
511 false); 519 false);
512 expected_route.set_incognito(false); 520 expected_route.set_incognito(false);
513 MediaRoute route = CreateMediaRoute(); 521 MediaRoute route = CreateMediaRoute();
514 522
515 // Use a lambda function as an invocation target here to work around 523 // Use a lambda function as an invocation target here to work around
516 // a limitation with GMock::Invoke that prevents it from using move-only types 524 // a limitation with GMock::Invoke that prevents it from using move-only types
517 // in runnable parameter lists. 525 // in runnable parameter lists.
518 EXPECT_CALL( 526 EXPECT_CALL(
519 mock_media_route_provider_, 527 mock_media_route_provider_,
520 ConnectRouteByRouteId( 528 ConnectRouteByRouteIdInternal(
521 kSource, kRouteId, _, url::Origin(GURL(kOrigin)), kInvalidTabId, 529 kSource, kRouteId, _, url::Origin(GURL(kOrigin)), kInvalidTabId,
522 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false, _)) 530 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false, _))
523 .WillOnce(Invoke([&route]( 531 .WillOnce(Invoke(
524 const std::string& source, const std::string& route_id, 532 [&route](const std::string& source, const std::string& route_id,
525 const std::string& presentation_id, const url::Origin& origin, 533 const std::string& presentation_id,
526 int tab_id, base::TimeDelta timeout, bool incognito, 534 const url::Origin& origin, int tab_id,
527 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { 535 base::TimeDelta timeout, bool incognito,
528 cb.Run(route, std::string(), RouteRequestResult::OK); 536 mojom::MediaRouteProvider::JoinRouteCallback& cb) {
529 })); 537 std::move(cb).Run(route, std::string(), RouteRequestResult::OK);
538 }));
530 539
531 RouteResponseCallbackHandler handler; 540 RouteResponseCallbackHandler handler;
532 base::RunLoop run_loop; 541 base::RunLoop run_loop;
533 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", 542 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "",
534 RouteRequestResult::OK)) 543 RouteRequestResult::OK))
535 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 544 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
536 std::vector<MediaRouteResponseCallback> route_response_callbacks; 545 std::vector<MediaRouteResponseCallback> route_response_callbacks;
537 route_response_callbacks.push_back(base::Bind( 546 route_response_callbacks.push_back(base::Bind(
538 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); 547 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
539 router()->ConnectRouteByRouteId( 548 router()->ConnectRouteByRouteId(
540 kSource, kRouteId, url::Origin(GURL(kOrigin)), nullptr, 549 kSource, kRouteId, url::Origin(GURL(kOrigin)), nullptr,
541 route_response_callbacks, 550 route_response_callbacks,
542 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); 551 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false);
543 run_loop.Run(); 552 run_loop.Run();
544 ExpectResultBucketCount("JoinRoute", RouteRequestResult::OK, 1); 553 ExpectResultBucketCount("JoinRoute", RouteRequestResult::OK, 1);
545 } 554 }
546 555
547 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteIdFails) { 556 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteIdFails) {
548 EXPECT_CALL( 557 EXPECT_CALL(
549 mock_media_route_provider_, 558 mock_media_route_provider_,
550 ConnectRouteByRouteId( 559 ConnectRouteByRouteIdInternal(
551 kSource, kRouteId, _, url::Origin(GURL(kOrigin)), kInvalidTabId, 560 kSource, kRouteId, _, url::Origin(GURL(kOrigin)), kInvalidTabId,
552 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) 561 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _))
553 .WillOnce(Invoke( 562 .WillOnce(Invoke(
554 [](const std::string& source, const std::string& route_id, 563 [](const std::string& source, const std::string& route_id,
555 const std::string& presentation_id, const url::Origin& origin, 564 const std::string& presentation_id, const url::Origin& origin,
556 int tab_id, base::TimeDelta timeout, bool incognito, 565 int tab_id, base::TimeDelta timeout, bool incognito,
557 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { 566 mojom::MediaRouteProvider::JoinRouteCallback& cb) {
558 cb.Run(base::nullopt, std::string(kError), 567 std::move(cb).Run(base::nullopt, std::string(kError),
559 RouteRequestResult::TIMED_OUT); 568 RouteRequestResult::TIMED_OUT);
560 })); 569 }));
561 570
562 RouteResponseCallbackHandler handler; 571 RouteResponseCallbackHandler handler;
563 base::RunLoop run_loop; 572 base::RunLoop run_loop;
564 EXPECT_CALL(handler, 573 EXPECT_CALL(handler,
565 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) 574 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT))
566 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 575 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
567 std::vector<MediaRouteResponseCallback> route_response_callbacks; 576 std::vector<MediaRouteResponseCallback> route_response_callbacks;
568 route_response_callbacks.push_back(base::Bind( 577 route_response_callbacks.push_back(base::Bind(
569 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); 578 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
570 router()->ConnectRouteByRouteId( 579 router()->ConnectRouteByRouteId(
571 kSource, kRouteId, url::Origin(GURL(kOrigin)), nullptr, 580 kSource, kRouteId, url::Origin(GURL(kOrigin)), nullptr,
572 route_response_callbacks, 581 route_response_callbacks,
573 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); 582 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true);
574 run_loop.Run(); 583 run_loop.Run();
575 ExpectResultBucketCount("JoinRoute", RouteRequestResult::TIMED_OUT, 1); 584 ExpectResultBucketCount("JoinRoute", RouteRequestResult::TIMED_OUT, 1);
576 } 585 }
577 586
578 TEST_F(MediaRouterMojoImplTest, ConnectRouteByIdIncognitoMismatchFails) { 587 TEST_F(MediaRouterMojoImplTest, ConnectRouteByIdIncognitoMismatchFails) {
579 MediaRoute route = CreateMediaRoute(); 588 MediaRoute route = CreateMediaRoute();
580 589
581 // Use a lambda function as an invocation target here to work around 590 // Use a lambda function as an invocation target here to work around
582 // a limitation with GMock::Invoke that prevents it from using move-only types 591 // a limitation with GMock::Invoke that prevents it from using move-only types
583 // in runnable parameter lists. 592 // in runnable parameter lists.
584 EXPECT_CALL( 593 EXPECT_CALL(
585 mock_media_route_provider_, 594 mock_media_route_provider_,
586 ConnectRouteByRouteId( 595 ConnectRouteByRouteIdInternal(
587 kSource, kRouteId, _, url::Origin(GURL(kOrigin)), kInvalidTabId, 596 kSource, kRouteId, _, url::Origin(GURL(kOrigin)), kInvalidTabId,
588 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) 597 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _))
589 .WillOnce(Invoke([&route]( 598 .WillOnce(Invoke(
590 const std::string& source, const std::string& route_id, 599 [&route](const std::string& source, const std::string& route_id,
591 const std::string& presentation_id, const url::Origin& origin, 600 const std::string& presentation_id,
592 int tab_id, base::TimeDelta timeout, bool incognito, 601 const url::Origin& origin, int tab_id,
593 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { 602 base::TimeDelta timeout, bool incognito,
594 cb.Run(route, std::string(), RouteRequestResult::OK); 603 mojom::MediaRouteProvider::JoinRouteCallback& cb) {
595 })); 604 std::move(cb).Run(route, std::string(), RouteRequestResult::OK);
605 }));
596 606
597 RouteResponseCallbackHandler handler; 607 RouteResponseCallbackHandler handler;
598 base::RunLoop run_loop; 608 base::RunLoop run_loop;
599 std::string error("Mismatch in incognito status: request = 1, response = 0"); 609 std::string error("Mismatch in incognito status: request = 1, response = 0");
600 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, 610 EXPECT_CALL(handler, DoInvoke(nullptr, "", error,
601 RouteRequestResult::INCOGNITO_MISMATCH)) 611 RouteRequestResult::INCOGNITO_MISMATCH))
602 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 612 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
603 std::vector<MediaRouteResponseCallback> route_response_callbacks; 613 std::vector<MediaRouteResponseCallback> route_response_callbacks;
604 route_response_callbacks.push_back(base::Bind( 614 route_response_callbacks.push_back(base::Bind(
605 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); 615 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler)));
606 router()->ConnectRouteByRouteId( 616 router()->ConnectRouteByRouteId(
607 kSource, kRouteId, url::Origin(GURL(kOrigin)), nullptr, 617 kSource, kRouteId, url::Origin(GURL(kOrigin)), nullptr,
608 route_response_callbacks, 618 route_response_callbacks,
609 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); 619 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true);
610 run_loop.Run(); 620 run_loop.Run();
611 ExpectResultBucketCount("JoinRoute", RouteRequestResult::INCOGNITO_MISMATCH, 621 ExpectResultBucketCount("JoinRoute", RouteRequestResult::INCOGNITO_MISMATCH,
612 1); 622 1);
613 } 623 }
614 624
615 TEST_F(MediaRouterMojoImplTest, DetachRoute) { 625 TEST_F(MediaRouterMojoImplTest, DetachRoute) {
616 base::RunLoop run_loop; 626 base::RunLoop run_loop;
617 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId)) 627 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId))
618 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 628 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
619 router()->DetachRoute(kRouteId); 629 router()->DetachRoute(kRouteId);
620 run_loop.Run(); 630 run_loop.Run();
621 } 631 }
622 632
623 TEST_F(MediaRouterMojoImplTest, TerminateRoute) { 633 TEST_F(MediaRouterMojoImplTest, TerminateRoute) {
624 base::RunLoop run_loop; 634 base::RunLoop run_loop;
625 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) 635 EXPECT_CALL(mock_media_route_provider_, TerminateRouteInternal(kRouteId, _))
626 .WillOnce(Invoke( 636 .WillOnce(
627 [](const std::string& route_id, 637 Invoke([](const std::string& route_id,
628 const mojom::MediaRouteProvider::TerminateRouteCallback& cb) { 638 mojom::MediaRouteProvider::TerminateRouteCallback& cb) {
629 cb.Run(base::nullopt, RouteRequestResult::OK); 639 std::move(cb).Run(base::nullopt, RouteRequestResult::OK);
630 })); 640 }));
631 router()->TerminateRoute(kRouteId); 641 router()->TerminateRoute(kRouteId);
632 run_loop.RunUntilIdle(); 642 run_loop.RunUntilIdle();
633 ExpectResultBucketCount("TerminateRoute", RouteRequestResult::OK, 1); 643 ExpectResultBucketCount("TerminateRoute", RouteRequestResult::OK, 1);
634 } 644 }
635 645
636 TEST_F(MediaRouterMojoImplTest, TerminateRouteFails) { 646 TEST_F(MediaRouterMojoImplTest, TerminateRouteFails) {
637 base::RunLoop run_loop; 647 base::RunLoop run_loop;
638 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) 648 EXPECT_CALL(mock_media_route_provider_, TerminateRouteInternal(kRouteId, _))
639 .WillOnce(Invoke( 649 .WillOnce(
640 [](const std::string& route_id, 650 Invoke([](const std::string& route_id,
641 const mojom::MediaRouteProvider::TerminateRouteCallback& cb) { 651 mojom::MediaRouteProvider::TerminateRouteCallback& cb) {
642 cb.Run(std::string("timed out"), RouteRequestResult::TIMED_OUT); 652 std::move(cb).Run(std::string("timed out"),
653 RouteRequestResult::TIMED_OUT);
643 })); 654 }));
644 router()->TerminateRoute(kRouteId); 655 router()->TerminateRoute(kRouteId);
645 run_loop.RunUntilIdle(); 656 run_loop.RunUntilIdle();
646 ExpectResultBucketCount("TerminateRoute", RouteRequestResult::OK, 0); 657 ExpectResultBucketCount("TerminateRoute", RouteRequestResult::OK, 0);
647 ExpectResultBucketCount("TerminateRoute", RouteRequestResult::TIMED_OUT, 1); 658 ExpectResultBucketCount("TerminateRoute", RouteRequestResult::TIMED_OUT, 1);
648 } 659 }
649 660
650 TEST_F(MediaRouterMojoImplTest, HandleIssue) { 661 TEST_F(MediaRouterMojoImplTest, HandleIssue) {
651 MockIssuesObserver issue_observer1(router()); 662 MockIssuesObserver issue_observer1(router());
652 MockIssuesObserver issue_observer2(router()); 663 MockIssuesObserver issue_observer2(router());
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 // Kill the final observer, and expect the provider to be woken-up and called 952 // Kill the final observer, and expect the provider to be woken-up and called
942 // with the "stop observing" notification. 953 // with the "stop observing" notification.
943 EXPECT_CALL(mock_media_route_provider_, 954 EXPECT_CALL(mock_media_route_provider_,
944 StopObservingMediaRoutes(media_source.id())) 955 StopObservingMediaRoutes(media_source.id()))
945 .Times(1); 956 .Times(1);
946 observer3.reset(); 957 observer3.reset();
947 ProcessEventLoop(); 958 ProcessEventLoop();
948 } 959 }
949 960
950 TEST_F(MediaRouterMojoImplTest, SendRouteMessage) { 961 TEST_F(MediaRouterMojoImplTest, SendRouteMessage) {
951 EXPECT_CALL( 962 EXPECT_CALL(mock_media_route_provider_,
952 mock_media_route_provider_, SendRouteMessage(kRouteId, kMessage, _)) 963 SendRouteMessageInternal(kRouteId, kMessage, _))
953 .WillOnce(Invoke([]( 964 .WillOnce(
954 const MediaRoute::Id& route_id, const std::string& message, 965 Invoke([](const MediaRoute::Id& route_id, const std::string& message,
955 const mojom::MediaRouteProvider::SendRouteMessageCallback& cb) { 966 mojom::MediaRouteProvider::SendRouteMessageCallback& cb) {
956 cb.Run(true); 967 std::move(cb).Run(true);
957 })); 968 }));
958 969
959 base::RunLoop run_loop; 970 base::RunLoop run_loop;
960 SendMessageCallbackHandler handler; 971 SendMessageCallbackHandler handler;
961 EXPECT_CALL(handler, Invoke(true)) 972 EXPECT_CALL(handler, Invoke(true))
962 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 973 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
963 router()->SendRouteMessage(kRouteId, kMessage, 974 router()->SendRouteMessage(kRouteId, kMessage,
964 base::Bind(&SendMessageCallbackHandler::Invoke, 975 base::Bind(&SendMessageCallbackHandler::Invoke,
965 base::Unretained(&handler))); 976 base::Unretained(&handler)));
966 run_loop.Run(); 977 run_loop.Run();
967 } 978 }
968 979
969 TEST_F(MediaRouterMojoImplTest, SendRouteBinaryMessage) { 980 TEST_F(MediaRouterMojoImplTest, SendRouteBinaryMessage) {
970 std::unique_ptr<std::vector<uint8_t>> expected_binary_data( 981 std::unique_ptr<std::vector<uint8_t>> expected_binary_data(
971 new std::vector<uint8_t>(kBinaryMessage, 982 new std::vector<uint8_t>(kBinaryMessage,
972 kBinaryMessage + arraysize(kBinaryMessage))); 983 kBinaryMessage + arraysize(kBinaryMessage)));
973 984
974 EXPECT_CALL(mock_media_route_provider_, 985 EXPECT_CALL(mock_media_route_provider_,
975 SendRouteBinaryMessageInternal(kRouteId, _, _)) 986 SendRouteBinaryMessageInternal(kRouteId, _, _))
976 .WillOnce(Invoke([]( 987 .WillOnce(Invoke(
977 const MediaRoute::Id& route_id, const std::vector<uint8_t>& data, 988 [](const MediaRoute::Id& route_id, const std::vector<uint8_t>& data,
978 const mojom::MediaRouteProvider::SendRouteMessageCallback& cb) { 989 mojom::MediaRouteProvider::SendRouteMessageCallback& cb) {
979 EXPECT_EQ( 990 EXPECT_EQ(0, memcmp(kBinaryMessage, &(data[0]),
980 0, memcmp(kBinaryMessage, &(data[0]), arraysize(kBinaryMessage))); 991 arraysize(kBinaryMessage)));
981 cb.Run(true); 992 std::move(cb).Run(true);
982 })); 993 }));
983 994
984 base::RunLoop run_loop; 995 base::RunLoop run_loop;
985 SendMessageCallbackHandler handler; 996 SendMessageCallbackHandler handler;
986 EXPECT_CALL(handler, Invoke(true)) 997 EXPECT_CALL(handler, Invoke(true))
987 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 998 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
988 router()->SendRouteBinaryMessage( 999 router()->SendRouteBinaryMessage(
989 kRouteId, std::move(expected_binary_data), 1000 kRouteId, std::move(expected_binary_data),
990 base::Bind(&SendMessageCallbackHandler::Invoke, 1001 base::Bind(&SendMessageCallbackHandler::Invoke,
991 base::Unretained(&handler))); 1002 base::Unretained(&handler)));
992 run_loop.Run(); 1003 run_loop.Run();
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 std::string search_input("input"); 1215 std::string search_input("input");
1205 std::string domain("google.com"); 1216 std::string domain("google.com");
1206 MediaSource media_source(kSource); 1217 MediaSource media_source(kSource);
1207 1218
1208 EXPECT_CALL(mock_media_route_provider_, 1219 EXPECT_CALL(mock_media_route_provider_,
1209 SearchSinksInternal(kSinkId, kSource, _, _)) 1220 SearchSinksInternal(kSinkId, kSource, _, _))
1210 .WillOnce( 1221 .WillOnce(
1211 Invoke([&search_input, &domain]( 1222 Invoke([&search_input, &domain](
1212 const std::string& sink_id, const std::string& source, 1223 const std::string& sink_id, const std::string& source,
1213 const mojom::SinkSearchCriteriaPtr& search_criteria, 1224 const mojom::SinkSearchCriteriaPtr& search_criteria,
1214 const mojom::MediaRouteProvider::SearchSinksCallback& cb) { 1225 mojom::MediaRouteProvider::SearchSinksCallback& cb) {
1215 EXPECT_EQ(search_input, search_criteria->input); 1226 EXPECT_EQ(search_input, search_criteria->input);
1216 EXPECT_EQ(domain, search_criteria->domain); 1227 EXPECT_EQ(domain, search_criteria->domain);
1217 cb.Run(kSinkId2); 1228 std::move(cb).Run(kSinkId2);
1218 })); 1229 }));
1219 1230
1220 SinkResponseCallbackHandler sink_handler; 1231 SinkResponseCallbackHandler sink_handler;
1221 EXPECT_CALL(sink_handler, Invoke(kSinkId2)).Times(1); 1232 EXPECT_CALL(sink_handler, Invoke(kSinkId2)).Times(1);
1222 MediaSinkSearchResponseCallback sink_callback = base::Bind( 1233 MediaSinkSearchResponseCallback sink_callback = base::Bind(
1223 &SinkResponseCallbackHandler::Invoke, base::Unretained(&sink_handler)); 1234 &SinkResponseCallbackHandler::Invoke, base::Unretained(&sink_handler));
1224 1235
1225 router()->SearchSinks(kSinkId, kSource, search_input, domain, sink_callback); 1236 router()->SearchSinks(kSinkId, kSource, search_input, domain, sink_callback);
1226 1237
1227 base::RunLoop run_loop; 1238 base::RunLoop run_loop;
(...skipping 23 matching lines...) Expand all
1251 MockMediaController media_controller; 1262 MockMediaController media_controller;
1252 mojom::MediaStatusObserverPtr route_controller_as_observer; 1263 mojom::MediaStatusObserverPtr route_controller_as_observer;
1253 MediaStatus media_status; 1264 MediaStatus media_status;
1254 media_status.title = "test title"; 1265 media_status.title = "test title";
1255 1266
1256 router()->OnRoutesUpdated({CreateMediaRoute()}, std::string(), 1267 router()->OnRoutesUpdated({CreateMediaRoute()}, std::string(),
1257 std::vector<std::string>()); 1268 std::vector<std::string>());
1258 1269
1259 EXPECT_CALL(mock_media_route_provider_, 1270 EXPECT_CALL(mock_media_route_provider_,
1260 CreateMediaRouteControllerInternal(kRouteId, _, _, _)) 1271 CreateMediaRouteControllerInternal(kRouteId, _, _, _))
1261 .WillOnce(Invoke([&media_controller, &route_controller_as_observer]( 1272 .WillOnce(Invoke(
1262 const std::string& route_id, 1273 [&media_controller, &route_controller_as_observer](
1263 mojom::MediaControllerRequest& request, 1274 const std::string& route_id,
1264 mojom::MediaStatusObserverPtr& observer, 1275 mojom::MediaControllerRequest& request,
1265 const mojom::MediaRouteProvider:: 1276 mojom::MediaStatusObserverPtr& observer,
1266 CreateMediaRouteControllerCallback& cb) { 1277 mojom::MediaRouteProvider::CreateMediaRouteControllerCallback&
1267 media_controller.Bind(std::move(request)); 1278 cb) {
1268 route_controller_as_observer = std::move(observer); 1279 media_controller.Bind(std::move(request));
1269 cb.Run(true); 1280 route_controller_as_observer = std::move(observer);
1270 })); 1281 std::move(cb).Run(true);
1282 }));
1271 // GetRouteController() should return a MediaRouteController that is connected 1283 // GetRouteController() should return a MediaRouteController that is connected
1272 // to the MediaController provided by the MediaRouteProvider, and will also be 1284 // to the MediaController provided by the MediaRouteProvider, and will also be
1273 // subscribed to MediaStatus updates. 1285 // subscribed to MediaStatus updates.
1274 scoped_refptr<MediaRouteController> route_controller = 1286 scoped_refptr<MediaRouteController> route_controller =
1275 router()->GetRouteController(kRouteId); 1287 router()->GetRouteController(kRouteId);
1276 base::RunLoop().RunUntilIdle(); 1288 base::RunLoop().RunUntilIdle();
1277 1289
1278 // Media commands sent to the MediaRouteController should be forwarded to the 1290 // Media commands sent to the MediaRouteController should be forwarded to the
1279 // MediaController created by the MediaRouteProvider. 1291 // MediaController created by the MediaRouteProvider.
1280 EXPECT_CALL(media_controller, Play()); 1292 EXPECT_CALL(media_controller, Play());
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 } 1388 }
1377 1389
1378 TEST_F(MediaRouterMojoImplTest, FailToCreateRouteController) { 1390 TEST_F(MediaRouterMojoImplTest, FailToCreateRouteController) {
1379 router()->OnRoutesUpdated({CreateMediaRoute()}, std::string(), 1391 router()->OnRoutesUpdated({CreateMediaRoute()}, std::string(),
1380 std::vector<std::string>()); 1392 std::vector<std::string>());
1381 1393
1382 EXPECT_CALL(mock_media_route_provider_, 1394 EXPECT_CALL(mock_media_route_provider_,
1383 CreateMediaRouteControllerInternal(kRouteId, _, _, _)) 1395 CreateMediaRouteControllerInternal(kRouteId, _, _, _))
1384 .WillOnce(Invoke( 1396 .WillOnce(Invoke(
1385 [](Unused, Unused, Unused, 1397 [](Unused, Unused, Unused,
1386 const mojom::MediaRouteProvider:: 1398 mojom::MediaRouteProvider::CreateMediaRouteControllerCallback&
1387 CreateMediaRouteControllerCallback& cb) { cb.Run(false); })); 1399 cb) { std::move(cb).Run(false); }));
1388 MockMediaRouteControllerObserver observer( 1400 MockMediaRouteControllerObserver observer(
1389 router()->GetRouteController(kRouteId)); 1401 router()->GetRouteController(kRouteId));
1390 1402
1391 // When the MediaRouter is notified that the MediaRouteProvider failed to 1403 // When the MediaRouter is notified that the MediaRouteProvider failed to
1392 // create a controller, the browser-side controller should be invalidated. 1404 // create a controller, the browser-side controller should be invalidated.
1393 EXPECT_CALL(observer, OnControllerInvalidated()); 1405 EXPECT_CALL(observer, OnControllerInvalidated());
1394 1406
1395 base::RunLoop().RunUntilIdle(); 1407 base::RunLoop().RunUntilIdle();
1396 } 1408 }
1397 1409
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 EXPECT_CALL(mock_media_route_provider_, 1835 EXPECT_CALL(mock_media_route_provider_,
1824 StartListeningForRouteMessages(media_source.id())); 1836 StartListeningForRouteMessages(media_source.id()));
1825 media_router_->OnConnectionError(); 1837 media_router_->OnConnectionError();
1826 BindMediaRouteProvider(); 1838 BindMediaRouteProvider();
1827 RegisterMediaRouteProvider(); 1839 RegisterMediaRouteProvider();
1828 base::RunLoop().RunUntilIdle(); 1840 base::RunLoop().RunUntilIdle();
1829 } 1841 }
1830 } 1842 }
1831 1843
1832 } // namespace media_router 1844 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698