| 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 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(mock_media_route_provider_, |
| 202 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, _, _, _)) | 202 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, _, _, _)) |
| 203 .WillOnce(Invoke( | 203 .WillOnce(Invoke( |
| 204 [](const std::string& source, const std::string& sink, | 204 [](const std::string& source, const std::string& sink, |
| 205 const std::string& presentation_id, const std::string& origin, | 205 const std::string& presentation_id, const std::string& origin, |
| 206 int tab_id, int64_t timeout_millis, bool incognito, | 206 int tab_id, base::TimeDelta timeout, bool incognito, |
| 207 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 207 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 208 cb.Run(CreateMojoRoute(), std::string(), | 208 cb.Run(CreateMojoRoute(), std::string(), |
| 209 mojom::RouteRequestResultCode::OK); | 209 mojom::RouteRequestResultCode::OK); |
| 210 })); | 210 })); |
| 211 | 211 |
| 212 base::RunLoop run_loop; | 212 base::RunLoop run_loop; |
| 213 RouteResponseCallbackHandler handler; | 213 RouteResponseCallbackHandler handler; |
| 214 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 214 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 215 RouteRequestResult::OK)) | 215 RouteRequestResult::OK)) |
| 216 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 216 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 230 expected_route.set_incognito(true); | 230 expected_route.set_incognito(true); |
| 231 | 231 |
| 232 // Use a lambda function as an invocation target here to work around | 232 // Use a lambda function as an invocation target here to work around |
| 233 // a limitation with GMock::Invoke that prevents it from using move-only types | 233 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 234 // in runnable parameter lists. | 234 // in runnable parameter lists. |
| 235 EXPECT_CALL(mock_media_route_provider_, | 235 EXPECT_CALL(mock_media_route_provider_, |
| 236 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, _, _, _)) | 236 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, _, _, _)) |
| 237 .WillOnce(Invoke( | 237 .WillOnce(Invoke( |
| 238 [](const std::string& source, const std::string& sink, | 238 [](const std::string& source, const std::string& sink, |
| 239 const std::string& presentation_id, const std::string& origin, | 239 const std::string& presentation_id, const std::string& origin, |
| 240 int tab_id, int64_t timeout_millis, bool incognito, | 240 int tab_id, base::TimeDelta timeout, bool incognito, |
| 241 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 241 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 242 mojom::MediaRoutePtr route = CreateMojoRoute(); | 242 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 243 route->custom_controller_path = | 243 route->custom_controller_path = |
| 244 std::string("custom/controller/path"); | 244 std::string("custom/controller/path"); |
| 245 route->incognito = true; | 245 route->incognito = true; |
| 246 cb.Run(std::move(route), std::string(), | 246 cb.Run(std::move(route), std::string(), |
| 247 mojom::RouteRequestResultCode::OK); | 247 mojom::RouteRequestResultCode::OK); |
| 248 })); | 248 })); |
| 249 | 249 |
| 250 base::RunLoop run_loop; | 250 base::RunLoop run_loop; |
| 251 RouteResponseCallbackHandler handler; | 251 RouteResponseCallbackHandler handler; |
| 252 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 252 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 253 RouteRequestResult::OK)) | 253 RouteRequestResult::OK)) |
| 254 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 254 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 255 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 255 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 256 route_response_callbacks.push_back(base::Bind( | 256 route_response_callbacks.push_back(base::Bind( |
| 257 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 257 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 258 router()->CreateRoute( | 258 router()->CreateRoute( |
| 259 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, | 259 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, |
| 260 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 260 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 261 run_loop.Run(); | 261 run_loop.Run(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) { | 264 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) { |
| 265 EXPECT_CALL( | 265 EXPECT_CALL( |
| 266 mock_media_route_provider_, | 266 mock_media_route_provider_, |
| 267 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, kTimeoutMillis, | 267 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, |
| 268 _, _)) | 268 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) |
| 269 .WillOnce(Invoke( | 269 .WillOnce(Invoke( |
| 270 [](const std::string& source, const std::string& sink, | 270 [](const std::string& source, const std::string& sink, |
| 271 const std::string& presentation_id, const std::string& origin, | 271 const std::string& presentation_id, const std::string& origin, |
| 272 int tab_id, int64_t timeout_millis, bool incognito, | 272 int tab_id, base::TimeDelta timeout, bool incognito, |
| 273 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 273 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 274 cb.Run(mojom::MediaRoutePtr(), std::string(kError), | 274 cb.Run(mojom::MediaRoutePtr(), std::string(kError), |
| 275 mojom::RouteRequestResultCode::TIMED_OUT); | 275 mojom::RouteRequestResultCode::TIMED_OUT); |
| 276 })); | 276 })); |
| 277 | 277 |
| 278 RouteResponseCallbackHandler handler; | 278 RouteResponseCallbackHandler handler; |
| 279 base::RunLoop run_loop; | 279 base::RunLoop run_loop; |
| 280 EXPECT_CALL(handler, | 280 EXPECT_CALL(handler, |
| 281 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) | 281 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) |
| 282 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 282 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 283 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 283 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 284 route_response_callbacks.push_back(base::Bind( | 284 route_response_callbacks.push_back(base::Bind( |
| 285 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 285 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 286 router()->CreateRoute( | 286 router()->CreateRoute( |
| 287 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, | 287 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, |
| 288 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 288 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 289 run_loop.Run(); | 289 run_loop.Run(); |
| 290 } | 290 } |
| 291 | 291 |
| 292 TEST_F(MediaRouterMojoImplTest, CreateRouteIncognitoMismatchFails) { | 292 TEST_F(MediaRouterMojoImplTest, CreateRouteIncognitoMismatchFails) { |
| 293 EXPECT_CALL(mock_media_route_provider_, | 293 EXPECT_CALL(mock_media_route_provider_, |
| 294 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, | 294 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, |
| 295 kTimeoutMillis, true, _)) | 295 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| 296 true, _)) |
| 296 .WillOnce(Invoke( | 297 .WillOnce(Invoke( |
| 297 [](const std::string& source, const std::string& sink, | 298 [](const std::string& source, const std::string& sink, |
| 298 const std::string& presentation_id, const std::string& origin, | 299 const std::string& presentation_id, const std::string& origin, |
| 299 int tab_id, int64_t timeout_millis, bool incognito, | 300 int tab_id, base::TimeDelta timeout, bool incognito, |
| 300 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 301 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 301 cb.Run(CreateMojoRoute(), std::string(), | 302 cb.Run(CreateMojoRoute(), std::string(), |
| 302 mojom::RouteRequestResultCode::OK); | 303 mojom::RouteRequestResultCode::OK); |
| 303 })); | 304 })); |
| 304 | 305 |
| 305 RouteResponseCallbackHandler handler; | 306 RouteResponseCallbackHandler handler; |
| 306 base::RunLoop run_loop; | 307 base::RunLoop run_loop; |
| 307 std::string error("Mismatch in incognito status: request = 1, response = 0"); | 308 std::string error("Mismatch in incognito status: request = 1, response = 0"); |
| 308 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, | 309 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, |
| 309 RouteRequestResult::INCOGNITO_MISMATCH)) | 310 RouteRequestResult::INCOGNITO_MISMATCH)) |
| 310 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 311 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 311 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 312 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 312 route_response_callbacks.push_back(base::Bind( | 313 route_response_callbacks.push_back(base::Bind( |
| 313 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 314 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 314 router()->CreateRoute( | 315 router()->CreateRoute( |
| 315 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, | 316 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, |
| 316 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 317 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 317 run_loop.Run(); | 318 run_loop.Run(); |
| 318 } | 319 } |
| 319 | 320 |
| 320 TEST_F(MediaRouterMojoImplTest, IncognitoRoutesTerminatedOnProfileShutdown) { | 321 TEST_F(MediaRouterMojoImplTest, IncognitoRoutesTerminatedOnProfileShutdown) { |
| 321 mojom::MediaRoutePtr route = CreateMojoRoute(); | 322 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 322 route->incognito = true; | 323 route->incognito = true; |
| 323 | 324 |
| 324 EXPECT_CALL(mock_media_route_provider_, | 325 EXPECT_CALL(mock_media_route_provider_, |
| 325 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, | 326 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, |
| 326 kTimeoutMillis, true, _)) | 327 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| 328 true, _)) |
| 327 .WillOnce(Invoke( | 329 .WillOnce(Invoke( |
| 328 [](const std::string& source, const std::string& sink, | 330 [](const std::string& source, const std::string& sink, |
| 329 const std::string& presentation_id, const std::string& origin, | 331 const std::string& presentation_id, const std::string& origin, |
| 330 int tab_id, int64_t timeout_millis, bool incognito, | 332 int tab_id, base::TimeDelta timeout, bool incognito, |
| 331 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 333 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 332 mojom::MediaRoutePtr route = CreateMojoRoute(); | 334 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 333 route->incognito = true; | 335 route->incognito = true; |
| 334 cb.Run(std::move(route), std::string(), | 336 cb.Run(std::move(route), std::string(), |
| 335 mojom::RouteRequestResultCode::OK); | 337 mojom::RouteRequestResultCode::OK); |
| 336 })); | 338 })); |
| 337 base::RunLoop run_loop; | 339 base::RunLoop run_loop; |
| 338 router()->CreateRoute(kSource, kSinkId, GURL(kOrigin), nullptr, | 340 router()->CreateRoute(kSource, kSinkId, GURL(kOrigin), nullptr, |
| 339 std::vector<MediaRouteResponseCallback>(), | 341 std::vector<MediaRouteResponseCallback>(), |
| 340 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 342 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 375 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), |
| 374 std::vector<std::string>()); | 376 std::vector<std::string>()); |
| 375 EXPECT_TRUE(router()->HasJoinableRoute()); | 377 EXPECT_TRUE(router()->HasJoinableRoute()); |
| 376 | 378 |
| 377 // Use a lambda function as an invocation target here to work around | 379 // Use a lambda function as an invocation target here to work around |
| 378 // a limitation with GMock::Invoke that prevents it from using move-only types | 380 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 379 // in runnable parameter lists. | 381 // in runnable parameter lists. |
| 380 EXPECT_CALL( | 382 EXPECT_CALL( |
| 381 mock_media_route_provider_, | 383 mock_media_route_provider_, |
| 382 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, | 384 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, |
| 383 kTimeoutMillis, _, _)) | 385 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) |
| 384 .WillOnce(Invoke([&route]( | 386 .WillOnce(Invoke([&route]( |
| 385 const std::string& source, const std::string& presentation_id, | 387 const std::string& source, const std::string& presentation_id, |
| 386 const std::string& origin, int tab_id, int64_t timeout_millis, | 388 const std::string& origin, int tab_id, base::TimeDelta timeout, |
| 387 bool incognito, | 389 bool incognito, |
| 388 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 390 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 389 cb.Run(std::move(route), std::string(), | 391 cb.Run(std::move(route), std::string(), |
| 390 mojom::RouteRequestResultCode::OK); | 392 mojom::RouteRequestResultCode::OK); |
| 391 })); | 393 })); |
| 392 | 394 |
| 393 RouteResponseCallbackHandler handler; | 395 RouteResponseCallbackHandler handler; |
| 394 base::RunLoop run_loop; | 396 base::RunLoop run_loop; |
| 395 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 397 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 396 RouteRequestResult::OK)) | 398 RouteRequestResult::OK)) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 424 // is a route to join. | 426 // is a route to join. |
| 425 std::vector<mojom::MediaRoutePtr> mojo_routes(1); | 427 std::vector<mojom::MediaRoutePtr> mojo_routes(1); |
| 426 mojo_routes[0] = CreateMojoRoute(); | 428 mojo_routes[0] = CreateMojoRoute(); |
| 427 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 429 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), |
| 428 std::vector<std::string>()); | 430 std::vector<std::string>()); |
| 429 EXPECT_TRUE(router()->HasJoinableRoute()); | 431 EXPECT_TRUE(router()->HasJoinableRoute()); |
| 430 | 432 |
| 431 EXPECT_CALL( | 433 EXPECT_CALL( |
| 432 mock_media_route_provider_, | 434 mock_media_route_provider_, |
| 433 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, | 435 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, |
| 434 kTimeoutMillis, _, _)) | 436 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) |
| 435 .WillOnce(Invoke( | 437 .WillOnce(Invoke( |
| 436 [](const std::string& source, const std::string& presentation_id, | 438 [](const std::string& source, const std::string& presentation_id, |
| 437 const std::string& origin, int tab_id, int64_t timeout_millis, | 439 const std::string& origin, int tab_id, base::TimeDelta timeout, |
| 438 bool incognito, | 440 bool incognito, |
| 439 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 441 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 440 cb.Run(mojom::MediaRoutePtr(), std::string(kError), | 442 cb.Run(mojom::MediaRoutePtr(), std::string(kError), |
| 441 mojom::RouteRequestResultCode::TIMED_OUT); | 443 mojom::RouteRequestResultCode::TIMED_OUT); |
| 442 })); | 444 })); |
| 443 | 445 |
| 444 RouteResponseCallbackHandler handler; | 446 RouteResponseCallbackHandler handler; |
| 445 base::RunLoop run_loop; | 447 base::RunLoop run_loop; |
| 446 EXPECT_CALL(handler, | 448 EXPECT_CALL(handler, |
| 447 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) | 449 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 465 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 467 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), |
| 466 std::vector<std::string>()); | 468 std::vector<std::string>()); |
| 467 EXPECT_TRUE(router()->HasJoinableRoute()); | 469 EXPECT_TRUE(router()->HasJoinableRoute()); |
| 468 | 470 |
| 469 // Use a lambda function as an invocation target here to work around | 471 // Use a lambda function as an invocation target here to work around |
| 470 // a limitation with GMock::Invoke that prevents it from using move-only types | 472 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 471 // in runnable parameter lists. | 473 // in runnable parameter lists. |
| 472 EXPECT_CALL( | 474 EXPECT_CALL( |
| 473 mock_media_route_provider_, | 475 mock_media_route_provider_, |
| 474 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, | 476 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, |
| 475 kTimeoutMillis, true, _)) | 477 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) |
| 476 .WillOnce(Invoke([&route]( | 478 .WillOnce(Invoke([&route]( |
| 477 const std::string& source, const std::string& presentation_id, | 479 const std::string& source, const std::string& presentation_id, |
| 478 const std::string& origin, int tab_id, int64_t timeout_millis, | 480 const std::string& origin, int tab_id, base::TimeDelta timeout, |
| 479 bool incognito, | 481 bool incognito, |
| 480 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 482 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 481 cb.Run(std::move(route), std::string(), | 483 cb.Run(std::move(route), std::string(), |
| 482 mojom::RouteRequestResultCode::OK); | 484 mojom::RouteRequestResultCode::OK); |
| 483 })); | 485 })); |
| 484 | 486 |
| 485 RouteResponseCallbackHandler handler; | 487 RouteResponseCallbackHandler handler; |
| 486 base::RunLoop run_loop; | 488 base::RunLoop run_loop; |
| 487 std::string error("Mismatch in incognito status: request = 1, response = 0"); | 489 std::string error("Mismatch in incognito status: request = 1, response = 0"); |
| 488 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, | 490 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 503 false); | 505 false); |
| 504 expected_route.set_incognito(false); | 506 expected_route.set_incognito(false); |
| 505 mojom::MediaRoutePtr route = CreateMojoRoute(); | 507 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 506 | 508 |
| 507 // Use a lambda function as an invocation target here to work around | 509 // Use a lambda function as an invocation target here to work around |
| 508 // a limitation with GMock::Invoke that prevents it from using move-only types | 510 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 509 // in runnable parameter lists. | 511 // in runnable parameter lists. |
| 510 EXPECT_CALL( | 512 EXPECT_CALL( |
| 511 mock_media_route_provider_, | 513 mock_media_route_provider_, |
| 512 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, | 514 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, |
| 513 kTimeoutMillis, false, _)) | 515 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| 516 false, _)) |
| 514 .WillOnce(Invoke([&route]( | 517 .WillOnce(Invoke([&route]( |
| 515 const std::string& source, const std::string& route_id, | 518 const std::string& source, const std::string& route_id, |
| 516 const std::string& presentation_id, const std::string& origin, | 519 const std::string& presentation_id, const std::string& origin, |
| 517 int tab_id, int64_t timeout_millis, bool incognito, | 520 int tab_id, base::TimeDelta timeout, bool incognito, |
| 518 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 521 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 519 cb.Run(std::move(route), std::string(), | 522 cb.Run(std::move(route), std::string(), |
| 520 mojom::RouteRequestResultCode::OK); | 523 mojom::RouteRequestResultCode::OK); |
| 521 })); | 524 })); |
| 522 | 525 |
| 523 RouteResponseCallbackHandler handler; | 526 RouteResponseCallbackHandler handler; |
| 524 base::RunLoop run_loop; | 527 base::RunLoop run_loop; |
| 525 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 528 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 526 RouteRequestResult::OK)) | 529 RouteRequestResult::OK)) |
| 527 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 530 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 528 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 531 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 529 route_response_callbacks.push_back(base::Bind( | 532 route_response_callbacks.push_back(base::Bind( |
| 530 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 533 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 531 router()->ConnectRouteByRouteId( | 534 router()->ConnectRouteByRouteId( |
| 532 kSource, kRouteId, GURL(kOrigin), nullptr, route_response_callbacks, | 535 kSource, kRouteId, GURL(kOrigin), nullptr, route_response_callbacks, |
| 533 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 536 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 534 run_loop.Run(); | 537 run_loop.Run(); |
| 535 } | 538 } |
| 536 | 539 |
| 537 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteIdFails) { | 540 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteIdFails) { |
| 538 EXPECT_CALL( | 541 EXPECT_CALL( |
| 539 mock_media_route_provider_, | 542 mock_media_route_provider_, |
| 540 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, | 543 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, |
| 541 kTimeoutMillis, true, _)) | 544 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| 545 true, _)) |
| 542 .WillOnce(Invoke( | 546 .WillOnce(Invoke( |
| 543 [](const std::string& source, const std::string& route_id, | 547 [](const std::string& source, const std::string& route_id, |
| 544 const std::string& presentation_id, const std::string& origin, | 548 const std::string& presentation_id, const std::string& origin, |
| 545 int tab_id, int64_t timeout_millis, bool incognito, | 549 int tab_id, base::TimeDelta timeout, bool incognito, |
| 546 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 550 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 547 cb.Run(mojom::MediaRoutePtr(), std::string(kError), | 551 cb.Run(mojom::MediaRoutePtr(), std::string(kError), |
| 548 mojom::RouteRequestResultCode::TIMED_OUT); | 552 mojom::RouteRequestResultCode::TIMED_OUT); |
| 549 })); | 553 })); |
| 550 | 554 |
| 551 RouteResponseCallbackHandler handler; | 555 RouteResponseCallbackHandler handler; |
| 552 base::RunLoop run_loop; | 556 base::RunLoop run_loop; |
| 553 EXPECT_CALL(handler, | 557 EXPECT_CALL(handler, |
| 554 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) | 558 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) |
| 555 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 559 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 556 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 560 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 557 route_response_callbacks.push_back(base::Bind( | 561 route_response_callbacks.push_back(base::Bind( |
| 558 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 562 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 559 router()->ConnectRouteByRouteId( | 563 router()->ConnectRouteByRouteId( |
| 560 kSource, kRouteId, GURL(kOrigin), nullptr, route_response_callbacks, | 564 kSource, kRouteId, GURL(kOrigin), nullptr, route_response_callbacks, |
| 561 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 565 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 562 run_loop.Run(); | 566 run_loop.Run(); |
| 563 } | 567 } |
| 564 | 568 |
| 565 TEST_F(MediaRouterMojoImplTest, ConnectRouteByIdIncognitoMismatchFails) { | 569 TEST_F(MediaRouterMojoImplTest, ConnectRouteByIdIncognitoMismatchFails) { |
| 566 mojom::MediaRoutePtr route = CreateMojoRoute(); | 570 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 567 | 571 |
| 568 // Use a lambda function as an invocation target here to work around | 572 // Use a lambda function as an invocation target here to work around |
| 569 // a limitation with GMock::Invoke that prevents it from using move-only types | 573 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 570 // in runnable parameter lists. | 574 // in runnable parameter lists. |
| 571 EXPECT_CALL( | 575 EXPECT_CALL( |
| 572 mock_media_route_provider_, | 576 mock_media_route_provider_, |
| 573 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, | 577 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, |
| 574 kTimeoutMillis, true, _)) | 578 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| 579 true, _)) |
| 575 .WillOnce(Invoke([&route]( | 580 .WillOnce(Invoke([&route]( |
| 576 const std::string& source, const std::string& route_id, | 581 const std::string& source, const std::string& route_id, |
| 577 const std::string& presentation_id, const std::string& origin, | 582 const std::string& presentation_id, const std::string& origin, |
| 578 int tab_id, int64_t timeout_millis, bool incognito, | 583 int tab_id, base::TimeDelta timeout, bool incognito, |
| 579 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 584 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 580 cb.Run(std::move(route), std::string(), | 585 cb.Run(std::move(route), std::string(), |
| 581 mojom::RouteRequestResultCode::OK); | 586 mojom::RouteRequestResultCode::OK); |
| 582 })); | 587 })); |
| 583 | 588 |
| 584 RouteResponseCallbackHandler handler; | 589 RouteResponseCallbackHandler handler; |
| 585 base::RunLoop run_loop; | 590 base::RunLoop run_loop; |
| 586 std::string error("Mismatch in incognito status: request = 1, response = 0"); | 591 std::string error("Mismatch in incognito status: request = 1, response = 0"); |
| 587 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, | 592 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, |
| 588 RouteRequestResult::INCOGNITO_MISMATCH)) | 593 RouteRequestResult::INCOGNITO_MISMATCH)) |
| (...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1560 EXPECT_CALL(mock_media_route_provider_, | 1565 EXPECT_CALL(mock_media_route_provider_, |
| 1561 UpdateMediaSinks(MediaSourceForDesktop().id())) | 1566 UpdateMediaSinks(MediaSourceForDesktop().id())) |
| 1562 .WillOnce(InvokeWithoutArgs([&run_loop2]() { | 1567 .WillOnce(InvokeWithoutArgs([&run_loop2]() { |
| 1563 run_loop2.Quit(); | 1568 run_loop2.Quit(); |
| 1564 })); | 1569 })); |
| 1565 | 1570 |
| 1566 run_loop2.Run(); | 1571 run_loop2.Run(); |
| 1567 } | 1572 } |
| 1568 | 1573 |
| 1569 } // namespace media_router | 1574 } // namespace media_router |
| OLD | NEW |