| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 using testing::Mock; | 52 using testing::Mock; |
| 53 using testing::Not; | 53 using testing::Not; |
| 54 using testing::Pointee; | 54 using testing::Pointee; |
| 55 using testing::Return; | 55 using testing::Return; |
| 56 using testing::ReturnRef; | 56 using testing::ReturnRef; |
| 57 using testing::SaveArg; | 57 using testing::SaveArg; |
| 58 | 58 |
| 59 namespace media_router { | 59 namespace media_router { |
| 60 | 60 |
| 61 using PresentationConnectionState = | 61 using PresentationConnectionState = |
| 62 interfaces::MediaRouter::PresentationConnectionState; | 62 mojom::MediaRouter::PresentationConnectionState; |
| 63 using PresentationConnectionCloseReason = | 63 using PresentationConnectionCloseReason = |
| 64 interfaces::MediaRouter::PresentationConnectionCloseReason; | 64 mojom::MediaRouter::PresentationConnectionCloseReason; |
| 65 | 65 |
| 66 namespace { | 66 namespace { |
| 67 | 67 |
| 68 const char kDescription[] = "description"; | 68 const char kDescription[] = "description"; |
| 69 const char kError[] = "error"; | 69 const char kError[] = "error"; |
| 70 const char kMessage[] = "message"; | 70 const char kMessage[] = "message"; |
| 71 const char kSource[] = "source1"; | 71 const char kSource[] = "source1"; |
| 72 const char kSource2[] = "source2"; | 72 const char kSource2[] = "source2"; |
| 73 const char kRouteId[] = "routeId"; | 73 const char kRouteId[] = "routeId"; |
| 74 const char kRouteId2[] = "routeId2"; | 74 const char kRouteId2[] = "routeId2"; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 86 bool ArePresentationSessionMessagesEqual( | 86 bool ArePresentationSessionMessagesEqual( |
| 87 const content::PresentationSessionMessage* expected, | 87 const content::PresentationSessionMessage* expected, |
| 88 const content::PresentationSessionMessage* actual) { | 88 const content::PresentationSessionMessage* actual) { |
| 89 if (expected->type != actual->type) | 89 if (expected->type != actual->type) |
| 90 return false; | 90 return false; |
| 91 | 91 |
| 92 return expected->is_binary() ? *expected->data == *actual->data | 92 return expected->is_binary() ? *expected->data == *actual->data |
| 93 : expected->message == actual->message; | 93 : expected->message == actual->message; |
| 94 } | 94 } |
| 95 | 95 |
| 96 interfaces::IssuePtr CreateMojoIssue(const std::string& title) { | 96 mojom::IssuePtr CreateMojoIssue(const std::string& title) { |
| 97 interfaces::IssuePtr mojoIssue = interfaces::Issue::New(); | 97 mojom::IssuePtr mojoIssue = mojom::Issue::New(); |
| 98 mojoIssue->title = title; | 98 mojoIssue->title = title; |
| 99 mojoIssue->message = std::string("msg"); | 99 mojoIssue->message = std::string("msg"); |
| 100 mojoIssue->route_id = std::string(); | 100 mojoIssue->route_id = std::string(); |
| 101 mojoIssue->default_action = interfaces::Issue::ActionType::DISMISS; | 101 mojoIssue->default_action = mojom::Issue::ActionType::DISMISS; |
| 102 mojoIssue->secondary_actions = std::vector<interfaces::Issue::ActionType>(); | 102 mojoIssue->secondary_actions = std::vector<mojom::Issue::ActionType>(); |
| 103 mojoIssue->severity = interfaces::Issue::Severity::WARNING; | 103 mojoIssue->severity = mojom::Issue::Severity::WARNING; |
| 104 mojoIssue->is_blocking = false; | 104 mojoIssue->is_blocking = false; |
| 105 mojoIssue->help_page_id = -1; | 105 mojoIssue->help_page_id = -1; |
| 106 return mojoIssue; | 106 return mojoIssue; |
| 107 } | 107 } |
| 108 | 108 |
| 109 interfaces::MediaRoutePtr CreateMojoRoute() { | 109 mojom::MediaRoutePtr CreateMojoRoute() { |
| 110 interfaces::MediaRoutePtr route = interfaces::MediaRoute::New(); | 110 mojom::MediaRoutePtr route = mojom::MediaRoute::New(); |
| 111 route->media_source = std::string(kSource); | 111 route->media_source = std::string(kSource); |
| 112 route->media_sink_id = kSinkId; | 112 route->media_sink_id = kSinkId; |
| 113 route->media_route_id = kRouteId; | 113 route->media_route_id = kRouteId; |
| 114 route->description = kDescription; | 114 route->description = kDescription; |
| 115 route->is_local = true; | 115 route->is_local = true; |
| 116 route->for_display = true; | 116 route->for_display = true; |
| 117 route->incognito = false; | 117 route->incognito = false; |
| 118 return route; | 118 return route; |
| 119 } | 119 } |
| 120 | 120 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, int64_t timeout_millis, bool incognito, |
| 241 const interfaces::MediaRouteProvider::CreateRouteCallback& cb) { | 241 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 242 cb.Run(CreateMojoRoute(), std::string(), | 242 cb.Run(CreateMojoRoute(), std::string(), |
| 243 interfaces::RouteRequestResultCode::OK); | 243 mojom::RouteRequestResultCode::OK); |
| 244 })); | 244 })); |
| 245 | 245 |
| 246 base::RunLoop run_loop; | 246 base::RunLoop run_loop; |
| 247 RouteResponseCallbackHandler handler; | 247 RouteResponseCallbackHandler handler; |
| 248 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 248 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 249 RouteRequestResult::OK)) | 249 RouteRequestResult::OK)) |
| 250 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 250 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 251 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 251 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 252 route_response_callbacks.push_back(base::Bind( | 252 route_response_callbacks.push_back(base::Bind( |
| 253 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 253 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 265 | 265 |
| 266 // Use a lambda function as an invocation target here to work around | 266 // Use a lambda function as an invocation target here to work around |
| 267 // a limitation with GMock::Invoke that prevents it from using move-only types | 267 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 268 // in runnable parameter lists. | 268 // in runnable parameter lists. |
| 269 EXPECT_CALL(mock_media_route_provider_, | 269 EXPECT_CALL(mock_media_route_provider_, |
| 270 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, _, _, _)) | 270 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, _, _, _)) |
| 271 .WillOnce(Invoke( | 271 .WillOnce(Invoke( |
| 272 [](const std::string& source, const std::string& sink, | 272 [](const std::string& source, const std::string& sink, |
| 273 const std::string& presentation_id, const std::string& origin, | 273 const std::string& presentation_id, const std::string& origin, |
| 274 int tab_id, int64_t timeout_millis, bool incognito, | 274 int tab_id, int64_t timeout_millis, bool incognito, |
| 275 const interfaces::MediaRouteProvider::CreateRouteCallback& cb) { | 275 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 276 interfaces::MediaRoutePtr route = CreateMojoRoute(); | 276 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 277 route->custom_controller_path = | 277 route->custom_controller_path = |
| 278 std::string("custom/controller/path"); | 278 std::string("custom/controller/path"); |
| 279 route->incognito = true; | 279 route->incognito = true; |
| 280 cb.Run(std::move(route), std::string(), | 280 cb.Run(std::move(route), std::string(), |
| 281 interfaces::RouteRequestResultCode::OK); | 281 mojom::RouteRequestResultCode::OK); |
| 282 })); | 282 })); |
| 283 | 283 |
| 284 base::RunLoop run_loop; | 284 base::RunLoop run_loop; |
| 285 RouteResponseCallbackHandler handler; | 285 RouteResponseCallbackHandler handler; |
| 286 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 286 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 287 RouteRequestResult::OK)) | 287 RouteRequestResult::OK)) |
| 288 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 288 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 289 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 289 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 290 route_response_callbacks.push_back(base::Bind( | 290 route_response_callbacks.push_back(base::Bind( |
| 291 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 291 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 292 router()->CreateRoute( | 292 router()->CreateRoute( |
| 293 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, | 293 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, |
| 294 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 294 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 295 run_loop.Run(); | 295 run_loop.Run(); |
| 296 } | 296 } |
| 297 | 297 |
| 298 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) { | 298 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) { |
| 299 EXPECT_CALL( | 299 EXPECT_CALL( |
| 300 mock_media_route_provider_, | 300 mock_media_route_provider_, |
| 301 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, kTimeoutMillis, | 301 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, kTimeoutMillis, |
| 302 _, _)) | 302 _, _)) |
| 303 .WillOnce(Invoke( | 303 .WillOnce(Invoke( |
| 304 [](const std::string& source, const std::string& sink, | 304 [](const std::string& source, const std::string& sink, |
| 305 const std::string& presentation_id, const std::string& origin, | 305 const std::string& presentation_id, const std::string& origin, |
| 306 int tab_id, int64_t timeout_millis, bool incognito, | 306 int tab_id, int64_t timeout_millis, bool incognito, |
| 307 const interfaces::MediaRouteProvider::CreateRouteCallback& cb) { | 307 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 308 cb.Run(interfaces::MediaRoutePtr(), std::string(kError), | 308 cb.Run(mojom::MediaRoutePtr(), std::string(kError), |
| 309 interfaces::RouteRequestResultCode::TIMED_OUT); | 309 mojom::RouteRequestResultCode::TIMED_OUT); |
| 310 })); | 310 })); |
| 311 | 311 |
| 312 RouteResponseCallbackHandler handler; | 312 RouteResponseCallbackHandler handler; |
| 313 base::RunLoop run_loop; | 313 base::RunLoop run_loop; |
| 314 EXPECT_CALL(handler, | 314 EXPECT_CALL(handler, |
| 315 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) | 315 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) |
| 316 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 316 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 317 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 317 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 318 route_response_callbacks.push_back(base::Bind( | 318 route_response_callbacks.push_back(base::Bind( |
| 319 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 319 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 320 router()->CreateRoute( | 320 router()->CreateRoute( |
| 321 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, | 321 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, |
| 322 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 322 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 323 run_loop.Run(); | 323 run_loop.Run(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 TEST_F(MediaRouterMojoImplTest, CreateRouteIncognitoMismatchFails) { | 326 TEST_F(MediaRouterMojoImplTest, CreateRouteIncognitoMismatchFails) { |
| 327 EXPECT_CALL(mock_media_route_provider_, | 327 EXPECT_CALL(mock_media_route_provider_, |
| 328 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, | 328 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, |
| 329 kTimeoutMillis, true, _)) | 329 kTimeoutMillis, true, _)) |
| 330 .WillOnce(Invoke( | 330 .WillOnce(Invoke( |
| 331 [](const std::string& source, const std::string& sink, | 331 [](const std::string& source, const std::string& sink, |
| 332 const std::string& presentation_id, const std::string& origin, | 332 const std::string& presentation_id, const std::string& origin, |
| 333 int tab_id, int64_t timeout_millis, bool incognito, | 333 int tab_id, int64_t timeout_millis, bool incognito, |
| 334 const interfaces::MediaRouteProvider::CreateRouteCallback& cb) { | 334 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 335 cb.Run(CreateMojoRoute(), std::string(), | 335 cb.Run(CreateMojoRoute(), std::string(), |
| 336 interfaces::RouteRequestResultCode::OK); | 336 mojom::RouteRequestResultCode::OK); |
| 337 })); | 337 })); |
| 338 | 338 |
| 339 RouteResponseCallbackHandler handler; | 339 RouteResponseCallbackHandler handler; |
| 340 base::RunLoop run_loop; | 340 base::RunLoop run_loop; |
| 341 std::string error("Mismatch in incognito status: request = 1, response = 0"); | 341 std::string error("Mismatch in incognito status: request = 1, response = 0"); |
| 342 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, | 342 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, |
| 343 RouteRequestResult::INCOGNITO_MISMATCH)) | 343 RouteRequestResult::INCOGNITO_MISMATCH)) |
| 344 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 344 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 345 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 345 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 346 route_response_callbacks.push_back(base::Bind( | 346 route_response_callbacks.push_back(base::Bind( |
| 347 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 347 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 348 router()->CreateRoute( | 348 router()->CreateRoute( |
| 349 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, | 349 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, |
| 350 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 350 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 351 run_loop.Run(); | 351 run_loop.Run(); |
| 352 } | 352 } |
| 353 | 353 |
| 354 TEST_F(MediaRouterMojoImplTest, IncognitoRoutesTerminatedOnProfileShutdown) { | 354 TEST_F(MediaRouterMojoImplTest, IncognitoRoutesTerminatedOnProfileShutdown) { |
| 355 interfaces::MediaRoutePtr route = CreateMojoRoute(); | 355 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 356 route->incognito = true; | 356 route->incognito = true; |
| 357 | 357 |
| 358 EXPECT_CALL(mock_media_route_provider_, | 358 EXPECT_CALL(mock_media_route_provider_, |
| 359 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, | 359 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, |
| 360 kTimeoutMillis, true, _)) | 360 kTimeoutMillis, true, _)) |
| 361 .WillOnce(Invoke( | 361 .WillOnce(Invoke( |
| 362 [](const std::string& source, const std::string& sink, | 362 [](const std::string& source, const std::string& sink, |
| 363 const std::string& presentation_id, const std::string& origin, | 363 const std::string& presentation_id, const std::string& origin, |
| 364 int tab_id, int64_t timeout_millis, bool incognito, | 364 int tab_id, int64_t timeout_millis, bool incognito, |
| 365 const interfaces::MediaRouteProvider::CreateRouteCallback& cb) { | 365 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 366 interfaces::MediaRoutePtr route = CreateMojoRoute(); | 366 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 367 route->incognito = true; | 367 route->incognito = true; |
| 368 cb.Run(std::move(route), std::string(), | 368 cb.Run(std::move(route), std::string(), |
| 369 interfaces::RouteRequestResultCode::OK); | 369 mojom::RouteRequestResultCode::OK); |
| 370 })); | 370 })); |
| 371 base::RunLoop run_loop; | 371 base::RunLoop run_loop; |
| 372 router()->CreateRoute(kSource, kSinkId, GURL(kOrigin), nullptr, | 372 router()->CreateRoute(kSource, kSinkId, GURL(kOrigin), nullptr, |
| 373 std::vector<MediaRouteResponseCallback>(), | 373 std::vector<MediaRouteResponseCallback>(), |
| 374 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 374 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| 375 true); | 375 true); |
| 376 std::vector<interfaces::MediaRoutePtr> mojo_routes(1); | 376 std::vector<mojom::MediaRoutePtr> mojo_routes(1); |
| 377 mojo_routes[0] = route->Clone(); | 377 mojo_routes[0] = route->Clone(); |
| 378 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 378 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), |
| 379 std::vector<std::string>()); | 379 std::vector<std::string>()); |
| 380 | 380 |
| 381 // TODO(mfoltz): Where possible, convert other tests to use RunUntilIdle | 381 // TODO(mfoltz): Where possible, convert other tests to use RunUntilIdle |
| 382 // instead of manually calling Run/Quit on the run loop. | 382 // instead of manually calling Run/Quit on the run loop. |
| 383 run_loop.RunUntilIdle(); | 383 run_loop.RunUntilIdle(); |
| 384 | 384 |
| 385 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) | 385 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) |
| 386 .WillOnce(Invoke([]( | 386 .WillOnce(Invoke([]( |
| 387 const std::string& route_id, | 387 const std::string& route_id, |
| 388 const interfaces::MediaRouteProvider::TerminateRouteCallback& cb) { | 388 const mojom::MediaRouteProvider::TerminateRouteCallback& cb) { |
| 389 cb.Run(base::nullopt, interfaces::RouteRequestResultCode::OK); | 389 cb.Run(base::nullopt, mojom::RouteRequestResultCode::OK); |
| 390 })); | 390 })); |
| 391 | 391 |
| 392 base::RunLoop run_loop2; | 392 base::RunLoop run_loop2; |
| 393 router()->OnIncognitoProfileShutdown(); | 393 router()->OnIncognitoProfileShutdown(); |
| 394 run_loop2.RunUntilIdle(); | 394 run_loop2.RunUntilIdle(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 TEST_F(MediaRouterMojoImplTest, JoinRoute) { | 397 TEST_F(MediaRouterMojoImplTest, JoinRoute) { |
| 398 MediaSource media_source(kSource); | 398 MediaSource media_source(kSource); |
| 399 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", | 399 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", |
| 400 false); | 400 false); |
| 401 | 401 |
| 402 interfaces::MediaRoutePtr route = CreateMojoRoute(); | 402 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 403 // Make sure the MR has received an update with the route, so it knows there | 403 // Make sure the MR has received an update with the route, so it knows there |
| 404 // is a route to join. | 404 // is a route to join. |
| 405 std::vector<interfaces::MediaRoutePtr> mojo_routes(1); | 405 std::vector<mojom::MediaRoutePtr> mojo_routes(1); |
| 406 mojo_routes[0] = route->Clone(); | 406 mojo_routes[0] = route->Clone(); |
| 407 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 407 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), |
| 408 std::vector<std::string>()); | 408 std::vector<std::string>()); |
| 409 EXPECT_TRUE(router()->HasJoinableRoute()); | 409 EXPECT_TRUE(router()->HasJoinableRoute()); |
| 410 | 410 |
| 411 // Use a lambda function as an invocation target here to work around | 411 // Use a lambda function as an invocation target here to work around |
| 412 // a limitation with GMock::Invoke that prevents it from using move-only types | 412 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 413 // in runnable parameter lists. | 413 // in runnable parameter lists. |
| 414 EXPECT_CALL( | 414 EXPECT_CALL( |
| 415 mock_media_route_provider_, | 415 mock_media_route_provider_, |
| 416 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, | 416 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, |
| 417 kTimeoutMillis, _, _)) | 417 kTimeoutMillis, _, _)) |
| 418 .WillOnce(Invoke([&route]( | 418 .WillOnce(Invoke([&route]( |
| 419 const std::string& source, const std::string& presentation_id, | 419 const std::string& source, const std::string& presentation_id, |
| 420 const std::string& origin, int tab_id, int64_t timeout_millis, | 420 const std::string& origin, int tab_id, int64_t timeout_millis, |
| 421 bool incognito, | 421 bool incognito, |
| 422 const interfaces::MediaRouteProvider::JoinRouteCallback& cb) { | 422 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 423 cb.Run(std::move(route), std::string(), | 423 cb.Run(std::move(route), std::string(), |
| 424 interfaces::RouteRequestResultCode::OK); | 424 mojom::RouteRequestResultCode::OK); |
| 425 })); | 425 })); |
| 426 | 426 |
| 427 RouteResponseCallbackHandler handler; | 427 RouteResponseCallbackHandler handler; |
| 428 base::RunLoop run_loop; | 428 base::RunLoop run_loop; |
| 429 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 429 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 430 RouteRequestResult::OK)) | 430 RouteRequestResult::OK)) |
| 431 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 431 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 432 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 432 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 433 route_response_callbacks.push_back(base::Bind( | 433 route_response_callbacks.push_back(base::Bind( |
| 434 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 434 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 449 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 449 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 450 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr, | 450 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr, |
| 451 route_response_callbacks, | 451 route_response_callbacks, |
| 452 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 452 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 453 run_loop.Run(); | 453 run_loop.Run(); |
| 454 } | 454 } |
| 455 | 455 |
| 456 TEST_F(MediaRouterMojoImplTest, JoinRouteTimedOutFails) { | 456 TEST_F(MediaRouterMojoImplTest, JoinRouteTimedOutFails) { |
| 457 // Make sure the MR has received an update with the route, so it knows there | 457 // Make sure the MR has received an update with the route, so it knows there |
| 458 // is a route to join. | 458 // is a route to join. |
| 459 std::vector<interfaces::MediaRoutePtr> mojo_routes(1); | 459 std::vector<mojom::MediaRoutePtr> mojo_routes(1); |
| 460 mojo_routes[0] = CreateMojoRoute(); | 460 mojo_routes[0] = CreateMojoRoute(); |
| 461 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 461 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), |
| 462 std::vector<std::string>()); | 462 std::vector<std::string>()); |
| 463 EXPECT_TRUE(router()->HasJoinableRoute()); | 463 EXPECT_TRUE(router()->HasJoinableRoute()); |
| 464 | 464 |
| 465 EXPECT_CALL( | 465 EXPECT_CALL( |
| 466 mock_media_route_provider_, | 466 mock_media_route_provider_, |
| 467 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, | 467 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, |
| 468 kTimeoutMillis, _, _)) | 468 kTimeoutMillis, _, _)) |
| 469 .WillOnce(Invoke( | 469 .WillOnce(Invoke( |
| 470 [](const std::string& source, const std::string& presentation_id, | 470 [](const std::string& source, const std::string& presentation_id, |
| 471 const std::string& origin, int tab_id, int64_t timeout_millis, | 471 const std::string& origin, int tab_id, int64_t timeout_millis, |
| 472 bool incognito, | 472 bool incognito, |
| 473 const interfaces::MediaRouteProvider::JoinRouteCallback& cb) { | 473 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 474 cb.Run(interfaces::MediaRoutePtr(), std::string(kError), | 474 cb.Run(mojom::MediaRoutePtr(), std::string(kError), |
| 475 interfaces::RouteRequestResultCode::TIMED_OUT); | 475 mojom::RouteRequestResultCode::TIMED_OUT); |
| 476 })); | 476 })); |
| 477 | 477 |
| 478 RouteResponseCallbackHandler handler; | 478 RouteResponseCallbackHandler handler; |
| 479 base::RunLoop run_loop; | 479 base::RunLoop run_loop; |
| 480 EXPECT_CALL(handler, | 480 EXPECT_CALL(handler, |
| 481 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) | 481 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) |
| 482 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 482 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 483 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 483 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 484 route_response_callbacks.push_back(base::Bind( | 484 route_response_callbacks.push_back(base::Bind( |
| 485 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 485 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 486 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr, | 486 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr, |
| 487 route_response_callbacks, | 487 route_response_callbacks, |
| 488 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 488 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 489 run_loop.Run(); | 489 run_loop.Run(); |
| 490 } | 490 } |
| 491 | 491 |
| 492 TEST_F(MediaRouterMojoImplTest, JoinRouteIncognitoMismatchFails) { | 492 TEST_F(MediaRouterMojoImplTest, JoinRouteIncognitoMismatchFails) { |
| 493 interfaces::MediaRoutePtr route = CreateMojoRoute(); | 493 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 494 | 494 |
| 495 // Make sure the MR has received an update with the route, so it knows there | 495 // Make sure the MR has received an update with the route, so it knows there |
| 496 // is a route to join. | 496 // is a route to join. |
| 497 std::vector<interfaces::MediaRoutePtr> mojo_routes(1); | 497 std::vector<mojom::MediaRoutePtr> mojo_routes(1); |
| 498 mojo_routes[0] = route->Clone(); | 498 mojo_routes[0] = route->Clone(); |
| 499 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 499 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), |
| 500 std::vector<std::string>()); | 500 std::vector<std::string>()); |
| 501 EXPECT_TRUE(router()->HasJoinableRoute()); | 501 EXPECT_TRUE(router()->HasJoinableRoute()); |
| 502 | 502 |
| 503 // Use a lambda function as an invocation target here to work around | 503 // Use a lambda function as an invocation target here to work around |
| 504 // a limitation with GMock::Invoke that prevents it from using move-only types | 504 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 505 // in runnable parameter lists. | 505 // in runnable parameter lists. |
| 506 EXPECT_CALL( | 506 EXPECT_CALL( |
| 507 mock_media_route_provider_, | 507 mock_media_route_provider_, |
| 508 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, | 508 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, |
| 509 kTimeoutMillis, true, _)) | 509 kTimeoutMillis, true, _)) |
| 510 .WillOnce(Invoke([&route]( | 510 .WillOnce(Invoke([&route]( |
| 511 const std::string& source, const std::string& presentation_id, | 511 const std::string& source, const std::string& presentation_id, |
| 512 const std::string& origin, int tab_id, int64_t timeout_millis, | 512 const std::string& origin, int tab_id, int64_t timeout_millis, |
| 513 bool incognito, | 513 bool incognito, |
| 514 const interfaces::MediaRouteProvider::JoinRouteCallback& cb) { | 514 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 515 cb.Run(std::move(route), std::string(), | 515 cb.Run(std::move(route), std::string(), |
| 516 interfaces::RouteRequestResultCode::OK); | 516 mojom::RouteRequestResultCode::OK); |
| 517 })); | 517 })); |
| 518 | 518 |
| 519 RouteResponseCallbackHandler handler; | 519 RouteResponseCallbackHandler handler; |
| 520 base::RunLoop run_loop; | 520 base::RunLoop run_loop; |
| 521 std::string error("Mismatch in incognito status: request = 1, response = 0"); | 521 std::string error("Mismatch in incognito status: request = 1, response = 0"); |
| 522 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, | 522 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, |
| 523 RouteRequestResult::INCOGNITO_MISMATCH)) | 523 RouteRequestResult::INCOGNITO_MISMATCH)) |
| 524 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 524 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 525 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 525 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 526 route_response_callbacks.push_back(base::Bind( | 526 route_response_callbacks.push_back(base::Bind( |
| 527 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 527 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 528 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr, | 528 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr, |
| 529 route_response_callbacks, | 529 route_response_callbacks, |
| 530 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 530 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 531 run_loop.Run(); | 531 run_loop.Run(); |
| 532 } | 532 } |
| 533 | 533 |
| 534 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteId) { | 534 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteId) { |
| 535 MediaSource media_source(kSource); | 535 MediaSource media_source(kSource); |
| 536 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", | 536 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", |
| 537 false); | 537 false); |
| 538 expected_route.set_incognito(false); | 538 expected_route.set_incognito(false); |
| 539 interfaces::MediaRoutePtr route = CreateMojoRoute(); | 539 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 540 | 540 |
| 541 // Use a lambda function as an invocation target here to work around | 541 // Use a lambda function as an invocation target here to work around |
| 542 // a limitation with GMock::Invoke that prevents it from using move-only types | 542 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 543 // in runnable parameter lists. | 543 // in runnable parameter lists. |
| 544 EXPECT_CALL( | 544 EXPECT_CALL( |
| 545 mock_media_route_provider_, | 545 mock_media_route_provider_, |
| 546 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, | 546 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, |
| 547 kTimeoutMillis, false, _)) | 547 kTimeoutMillis, false, _)) |
| 548 .WillOnce(Invoke([&route]( | 548 .WillOnce(Invoke([&route]( |
| 549 const std::string& source, const std::string& route_id, | 549 const std::string& source, const std::string& route_id, |
| 550 const std::string& presentation_id, const std::string& origin, | 550 const std::string& presentation_id, const std::string& origin, |
| 551 int tab_id, int64_t timeout_millis, bool incognito, | 551 int tab_id, int64_t timeout_millis, bool incognito, |
| 552 const interfaces::MediaRouteProvider::JoinRouteCallback& cb) { | 552 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 553 cb.Run(std::move(route), std::string(), | 553 cb.Run(std::move(route), std::string(), |
| 554 interfaces::RouteRequestResultCode::OK); | 554 mojom::RouteRequestResultCode::OK); |
| 555 })); | 555 })); |
| 556 | 556 |
| 557 RouteResponseCallbackHandler handler; | 557 RouteResponseCallbackHandler handler; |
| 558 base::RunLoop run_loop; | 558 base::RunLoop run_loop; |
| 559 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 559 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 560 RouteRequestResult::OK)) | 560 RouteRequestResult::OK)) |
| 561 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 561 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 562 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 562 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 563 route_response_callbacks.push_back(base::Bind( | 563 route_response_callbacks.push_back(base::Bind( |
| 564 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 564 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 565 router()->ConnectRouteByRouteId( | 565 router()->ConnectRouteByRouteId( |
| 566 kSource, kRouteId, GURL(kOrigin), nullptr, route_response_callbacks, | 566 kSource, kRouteId, GURL(kOrigin), nullptr, route_response_callbacks, |
| 567 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 567 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 568 run_loop.Run(); | 568 run_loop.Run(); |
| 569 } | 569 } |
| 570 | 570 |
| 571 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteIdFails) { | 571 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteIdFails) { |
| 572 EXPECT_CALL( | 572 EXPECT_CALL( |
| 573 mock_media_route_provider_, | 573 mock_media_route_provider_, |
| 574 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, | 574 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, |
| 575 kTimeoutMillis, true, _)) | 575 kTimeoutMillis, true, _)) |
| 576 .WillOnce(Invoke( | 576 .WillOnce(Invoke( |
| 577 [](const std::string& source, const std::string& route_id, | 577 [](const std::string& source, const std::string& route_id, |
| 578 const std::string& presentation_id, const std::string& origin, | 578 const std::string& presentation_id, const std::string& origin, |
| 579 int tab_id, int64_t timeout_millis, bool incognito, | 579 int tab_id, int64_t timeout_millis, bool incognito, |
| 580 const interfaces::MediaRouteProvider::JoinRouteCallback& cb) { | 580 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 581 cb.Run(interfaces::MediaRoutePtr(), std::string(kError), | 581 cb.Run(mojom::MediaRoutePtr(), std::string(kError), |
| 582 interfaces::RouteRequestResultCode::TIMED_OUT); | 582 mojom::RouteRequestResultCode::TIMED_OUT); |
| 583 })); | 583 })); |
| 584 | 584 |
| 585 RouteResponseCallbackHandler handler; | 585 RouteResponseCallbackHandler handler; |
| 586 base::RunLoop run_loop; | 586 base::RunLoop run_loop; |
| 587 EXPECT_CALL(handler, | 587 EXPECT_CALL(handler, |
| 588 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) | 588 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) |
| 589 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 589 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 590 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 590 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 591 route_response_callbacks.push_back(base::Bind( | 591 route_response_callbacks.push_back(base::Bind( |
| 592 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 592 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 593 router()->ConnectRouteByRouteId( | 593 router()->ConnectRouteByRouteId( |
| 594 kSource, kRouteId, GURL(kOrigin), nullptr, route_response_callbacks, | 594 kSource, kRouteId, GURL(kOrigin), nullptr, route_response_callbacks, |
| 595 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 595 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 596 run_loop.Run(); | 596 run_loop.Run(); |
| 597 } | 597 } |
| 598 | 598 |
| 599 TEST_F(MediaRouterMojoImplTest, ConnectRouteByIdIncognitoMismatchFails) { | 599 TEST_F(MediaRouterMojoImplTest, ConnectRouteByIdIncognitoMismatchFails) { |
| 600 interfaces::MediaRoutePtr route = CreateMojoRoute(); | 600 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 601 | 601 |
| 602 // Use a lambda function as an invocation target here to work around | 602 // Use a lambda function as an invocation target here to work around |
| 603 // a limitation with GMock::Invoke that prevents it from using move-only types | 603 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 604 // in runnable parameter lists. | 604 // in runnable parameter lists. |
| 605 EXPECT_CALL( | 605 EXPECT_CALL( |
| 606 mock_media_route_provider_, | 606 mock_media_route_provider_, |
| 607 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, | 607 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, |
| 608 kTimeoutMillis, true, _)) | 608 kTimeoutMillis, true, _)) |
| 609 .WillOnce(Invoke([&route]( | 609 .WillOnce(Invoke([&route]( |
| 610 const std::string& source, const std::string& route_id, | 610 const std::string& source, const std::string& route_id, |
| 611 const std::string& presentation_id, const std::string& origin, | 611 const std::string& presentation_id, const std::string& origin, |
| 612 int tab_id, int64_t timeout_millis, bool incognito, | 612 int tab_id, int64_t timeout_millis, bool incognito, |
| 613 const interfaces::MediaRouteProvider::JoinRouteCallback& cb) { | 613 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 614 cb.Run(std::move(route), std::string(), | 614 cb.Run(std::move(route), std::string(), |
| 615 interfaces::RouteRequestResultCode::OK); | 615 mojom::RouteRequestResultCode::OK); |
| 616 })); | 616 })); |
| 617 | 617 |
| 618 RouteResponseCallbackHandler handler; | 618 RouteResponseCallbackHandler handler; |
| 619 base::RunLoop run_loop; | 619 base::RunLoop run_loop; |
| 620 std::string error("Mismatch in incognito status: request = 1, response = 0"); | 620 std::string error("Mismatch in incognito status: request = 1, response = 0"); |
| 621 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, | 621 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, |
| 622 RouteRequestResult::INCOGNITO_MISMATCH)) | 622 RouteRequestResult::INCOGNITO_MISMATCH)) |
| 623 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 623 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 624 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 624 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 625 route_response_callbacks.push_back(base::Bind( | 625 route_response_callbacks.push_back(base::Bind( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 636 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 636 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 637 router()->DetachRoute(kRouteId); | 637 router()->DetachRoute(kRouteId); |
| 638 run_loop.Run(); | 638 run_loop.Run(); |
| 639 } | 639 } |
| 640 | 640 |
| 641 TEST_F(MediaRouterMojoImplTest, TerminateRoute) { | 641 TEST_F(MediaRouterMojoImplTest, TerminateRoute) { |
| 642 base::RunLoop run_loop; | 642 base::RunLoop run_loop; |
| 643 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) | 643 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) |
| 644 .WillOnce(Invoke([&run_loop]( | 644 .WillOnce(Invoke([&run_loop]( |
| 645 const std::string& route_id, | 645 const std::string& route_id, |
| 646 const interfaces::MediaRouteProvider::TerminateRouteCallback& cb) { | 646 const mojom::MediaRouteProvider::TerminateRouteCallback& cb) { |
| 647 cb.Run(base::nullopt, interfaces::RouteRequestResultCode::OK); | 647 cb.Run(base::nullopt, mojom::RouteRequestResultCode::OK); |
| 648 })); | 648 })); |
| 649 router()->TerminateRoute(kRouteId); | 649 router()->TerminateRoute(kRouteId); |
| 650 run_loop.RunUntilIdle(); | 650 run_loop.RunUntilIdle(); |
| 651 ExpectResultBucketCount("TerminateRoute", | 651 ExpectResultBucketCount("TerminateRoute", |
| 652 RouteRequestResult::ResultCode::OK, | 652 RouteRequestResult::ResultCode::OK, |
| 653 1); | 653 1); |
| 654 } | 654 } |
| 655 | 655 |
| 656 TEST_F(MediaRouterMojoImplTest, TerminateRouteFails) { | 656 TEST_F(MediaRouterMojoImplTest, TerminateRouteFails) { |
| 657 base::RunLoop run_loop; | 657 base::RunLoop run_loop; |
| 658 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) | 658 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) |
| 659 .WillOnce(Invoke([&run_loop]( | 659 .WillOnce(Invoke([&run_loop]( |
| 660 const mojo::String& route_id, | 660 const mojo::String& route_id, |
| 661 const interfaces::MediaRouteProvider::TerminateRouteCallback& cb) { | 661 const mojom::MediaRouteProvider::TerminateRouteCallback& cb) { |
| 662 cb.Run(std::string("timed out"), | 662 cb.Run(std::string("timed out"), |
| 663 interfaces::RouteRequestResultCode::TIMED_OUT); | 663 mojom::RouteRequestResultCode::TIMED_OUT); |
| 664 })); | 664 })); |
| 665 router()->TerminateRoute(kRouteId); | 665 router()->TerminateRoute(kRouteId); |
| 666 run_loop.RunUntilIdle(); | 666 run_loop.RunUntilIdle(); |
| 667 ExpectResultBucketCount("TerminateRoute", | 667 ExpectResultBucketCount("TerminateRoute", |
| 668 RouteRequestResult::ResultCode::OK, | 668 RouteRequestResult::ResultCode::OK, |
| 669 0); | 669 0); |
| 670 ExpectResultBucketCount("TerminateRoute", | 670 ExpectResultBucketCount("TerminateRoute", |
| 671 RouteRequestResult::ResultCode::TIMED_OUT, | 671 RouteRequestResult::ResultCode::TIMED_OUT, |
| 672 1); | 672 1); |
| 673 } | 673 } |
| 674 | 674 |
| 675 TEST_F(MediaRouterMojoImplTest, HandleIssue) { | 675 TEST_F(MediaRouterMojoImplTest, HandleIssue) { |
| 676 MockIssuesObserver issue_observer1(router()); | 676 MockIssuesObserver issue_observer1(router()); |
| 677 MockIssuesObserver issue_observer2(router()); | 677 MockIssuesObserver issue_observer2(router()); |
| 678 issue_observer1.RegisterObserver(); | 678 issue_observer1.RegisterObserver(); |
| 679 issue_observer2.RegisterObserver(); | 679 issue_observer2.RegisterObserver(); |
| 680 | 680 |
| 681 interfaces::IssuePtr mojo_issue1 = CreateMojoIssue("title 1"); | 681 mojom::IssuePtr mojo_issue1 = CreateMojoIssue("title 1"); |
| 682 const Issue& expected_issue1 = mojo_issue1.To<Issue>(); | 682 const Issue& expected_issue1 = mojo_issue1.To<Issue>(); |
| 683 | 683 |
| 684 const Issue* issue; | 684 const Issue* issue; |
| 685 EXPECT_CALL(issue_observer1, | 685 EXPECT_CALL(issue_observer1, |
| 686 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1)))) | 686 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1)))) |
| 687 .WillOnce(SaveArg<0>(&issue)); | 687 .WillOnce(SaveArg<0>(&issue)); |
| 688 base::RunLoop run_loop; | 688 base::RunLoop run_loop; |
| 689 EXPECT_CALL(issue_observer2, | 689 EXPECT_CALL(issue_observer2, |
| 690 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1)))) | 690 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1)))) |
| 691 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 691 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 692 media_router_proxy_->OnIssue(std::move(mojo_issue1)); | 692 media_router_proxy_->OnIssue(std::move(mojo_issue1)); |
| 693 run_loop.Run(); | 693 run_loop.Run(); |
| 694 | 694 |
| 695 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); | 695 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); |
| 696 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); | 696 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); |
| 697 | 697 |
| 698 EXPECT_CALL(issue_observer1, OnIssueUpdated(nullptr)); | 698 EXPECT_CALL(issue_observer1, OnIssueUpdated(nullptr)); |
| 699 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr)); | 699 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr)); |
| 700 | 700 |
| 701 router()->ClearIssue(issue->id()); | 701 router()->ClearIssue(issue->id()); |
| 702 | 702 |
| 703 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); | 703 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); |
| 704 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); | 704 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); |
| 705 router()->UnregisterIssuesObserver(&issue_observer1); | 705 router()->UnregisterIssuesObserver(&issue_observer1); |
| 706 interfaces::IssuePtr mojo_issue2 = CreateMojoIssue("title 2"); | 706 mojom::IssuePtr mojo_issue2 = CreateMojoIssue("title 2"); |
| 707 const Issue& expected_issue2 = mojo_issue2.To<Issue>(); | 707 const Issue& expected_issue2 = mojo_issue2.To<Issue>(); |
| 708 | 708 |
| 709 EXPECT_CALL(issue_observer2, | 709 EXPECT_CALL(issue_observer2, |
| 710 OnIssueUpdated(Pointee(EqualsIssue(expected_issue2)))); | 710 OnIssueUpdated(Pointee(EqualsIssue(expected_issue2)))); |
| 711 router()->AddIssue(expected_issue2); | 711 router()->AddIssue(expected_issue2); |
| 712 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); | 712 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); |
| 713 | 713 |
| 714 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr)); | 714 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr)); |
| 715 router()->ClearIssue(issue->id()); | 715 router()->ClearIssue(issue->id()); |
| 716 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); | 716 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); |
| 717 | 717 |
| 718 base::RunLoop run_loop2; | 718 base::RunLoop run_loop2; |
| 719 EXPECT_CALL(issue_observer2, | 719 EXPECT_CALL(issue_observer2, |
| 720 OnIssueUpdated(Pointee(EqualsIssue(expected_issue2)))) | 720 OnIssueUpdated(Pointee(EqualsIssue(expected_issue2)))) |
| 721 .WillOnce(InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); })); | 721 .WillOnce(InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); })); |
| 722 media_router_proxy_->OnIssue(std::move(mojo_issue2)); | 722 media_router_proxy_->OnIssue(std::move(mojo_issue2)); |
| 723 run_loop2.Run(); | 723 run_loop2.Run(); |
| 724 | 724 |
| 725 issue_observer1.UnregisterObserver(); | 725 issue_observer1.UnregisterObserver(); |
| 726 issue_observer2.UnregisterObserver(); | 726 issue_observer2.UnregisterObserver(); |
| 727 } | 727 } |
| 728 | 728 |
| 729 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) { | 729 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) { |
| 730 router()->OnSinkAvailabilityUpdated( | 730 router()->OnSinkAvailabilityUpdated( |
| 731 interfaces::MediaRouter::SinkAvailability::AVAILABLE); | 731 mojom::MediaRouter::SinkAvailability::AVAILABLE); |
| 732 MediaSource media_source(kSource); | 732 MediaSource media_source(kSource); |
| 733 GURL origin("https://google.com"); | 733 GURL origin("https://google.com"); |
| 734 | 734 |
| 735 // These should only be called once even if there is more than one observer | 735 // These should only be called once even if there is more than one observer |
| 736 // for a given source. | 736 // for a given source. |
| 737 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource)); | 737 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource)); |
| 738 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource2)); | 738 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource2)); |
| 739 | 739 |
| 740 std::unique_ptr<MockMediaSinksObserver> sinks_observer( | 740 std::unique_ptr<MockMediaSinksObserver> sinks_observer( |
| 741 new MockMediaSinksObserver(router(), media_source, origin)); | 741 new MockMediaSinksObserver(router(), media_source, origin)); |
| 742 EXPECT_TRUE(sinks_observer->Init()); | 742 EXPECT_TRUE(sinks_observer->Init()); |
| 743 std::unique_ptr<MockMediaSinksObserver> extra_sinks_observer( | 743 std::unique_ptr<MockMediaSinksObserver> extra_sinks_observer( |
| 744 new MockMediaSinksObserver(router(), media_source, origin)); | 744 new MockMediaSinksObserver(router(), media_source, origin)); |
| 745 EXPECT_TRUE(extra_sinks_observer->Init()); | 745 EXPECT_TRUE(extra_sinks_observer->Init()); |
| 746 std::unique_ptr<MockMediaSinksObserver> unrelated_sinks_observer( | 746 std::unique_ptr<MockMediaSinksObserver> unrelated_sinks_observer( |
| 747 new MockMediaSinksObserver(router(), MediaSource(kSource2), origin)); | 747 new MockMediaSinksObserver(router(), MediaSource(kSource2), origin)); |
| 748 EXPECT_TRUE(unrelated_sinks_observer->Init()); | 748 EXPECT_TRUE(unrelated_sinks_observer->Init()); |
| 749 ProcessEventLoop(); | 749 ProcessEventLoop(); |
| 750 | 750 |
| 751 std::vector<MediaSink> expected_sinks; | 751 std::vector<MediaSink> expected_sinks; |
| 752 expected_sinks.push_back( | 752 expected_sinks.push_back( |
| 753 MediaSink(kSinkId, kSinkName, MediaSink::IconType::CAST)); | 753 MediaSink(kSinkId, kSinkName, MediaSink::IconType::CAST)); |
| 754 expected_sinks.push_back( | 754 expected_sinks.push_back( |
| 755 MediaSink(kSinkId2, kSinkName, MediaSink::IconType::CAST)); | 755 MediaSink(kSinkId2, kSinkName, MediaSink::IconType::CAST)); |
| 756 | 756 |
| 757 std::vector<interfaces::MediaSinkPtr> mojo_sinks(2); | 757 std::vector<mojom::MediaSinkPtr> mojo_sinks(2); |
| 758 mojo_sinks[0] = interfaces::MediaSink::New(); | 758 mojo_sinks[0] = mojom::MediaSink::New(); |
| 759 mojo_sinks[0]->sink_id = kSinkId; | 759 mojo_sinks[0]->sink_id = kSinkId; |
| 760 mojo_sinks[0]->name = kSinkName; | 760 mojo_sinks[0]->name = kSinkName; |
| 761 mojo_sinks[0]->icon_type = | 761 mojo_sinks[0]->icon_type = |
| 762 media_router::interfaces::MediaSink::IconType::CAST; | 762 media_router::mojom::MediaSink::IconType::CAST; |
| 763 mojo_sinks[1] = interfaces::MediaSink::New(); | 763 mojo_sinks[1] = mojom::MediaSink::New(); |
| 764 mojo_sinks[1]->sink_id = kSinkId2; | 764 mojo_sinks[1]->sink_id = kSinkId2; |
| 765 mojo_sinks[1]->name = kSinkName; | 765 mojo_sinks[1]->name = kSinkName; |
| 766 mojo_sinks[1]->icon_type = | 766 mojo_sinks[1]->icon_type = |
| 767 media_router::interfaces::MediaSink::IconType::CAST; | 767 media_router::mojom::MediaSink::IconType::CAST; |
| 768 | 768 |
| 769 base::RunLoop run_loop; | 769 base::RunLoop run_loop; |
| 770 EXPECT_CALL(*sinks_observer, OnSinksReceived(SequenceEquals(expected_sinks))); | 770 EXPECT_CALL(*sinks_observer, OnSinksReceived(SequenceEquals(expected_sinks))); |
| 771 EXPECT_CALL(*extra_sinks_observer, | 771 EXPECT_CALL(*extra_sinks_observer, |
| 772 OnSinksReceived(SequenceEquals(expected_sinks))) | 772 OnSinksReceived(SequenceEquals(expected_sinks))) |
| 773 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 773 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 774 media_router_proxy_->OnSinksReceived( | 774 media_router_proxy_->OnSinksReceived( |
| 775 media_source.id(), std::move(mojo_sinks), | 775 media_source.id(), std::move(mojo_sinks), |
| 776 std::vector<std::string>(1, origin.spec())); | 776 std::vector<std::string>(1, origin.spec())); |
| 777 run_loop.Run(); | 777 run_loop.Run(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 803 cached_sinks_observer2.reset(); | 803 cached_sinks_observer2.reset(); |
| 804 run_loop2.Run(); | 804 run_loop2.Run(); |
| 805 } | 805 } |
| 806 | 806 |
| 807 TEST_F(MediaRouterMojoImplTest, | 807 TEST_F(MediaRouterMojoImplTest, |
| 808 RegisterMediaSinksObserverWithAvailabilityChange) { | 808 RegisterMediaSinksObserverWithAvailabilityChange) { |
| 809 GURL origin("https://google.com"); | 809 GURL origin("https://google.com"); |
| 810 | 810 |
| 811 // When availability is UNAVAILABLE, no calls should be made to MRPM. | 811 // When availability is UNAVAILABLE, no calls should be made to MRPM. |
| 812 router()->OnSinkAvailabilityUpdated( | 812 router()->OnSinkAvailabilityUpdated( |
| 813 interfaces::MediaRouter::SinkAvailability::UNAVAILABLE); | 813 mojom::MediaRouter::SinkAvailability::UNAVAILABLE); |
| 814 MediaSource media_source(kSource); | 814 MediaSource media_source(kSource); |
| 815 std::unique_ptr<MockMediaSinksObserver> sinks_observer( | 815 std::unique_ptr<MockMediaSinksObserver> sinks_observer( |
| 816 new MockMediaSinksObserver(router(), media_source, origin)); | 816 new MockMediaSinksObserver(router(), media_source, origin)); |
| 817 EXPECT_CALL(*sinks_observer, OnSinksReceived(IsEmpty())); | 817 EXPECT_CALL(*sinks_observer, OnSinksReceived(IsEmpty())); |
| 818 EXPECT_TRUE(sinks_observer->Init()); | 818 EXPECT_TRUE(sinks_observer->Init()); |
| 819 MediaSource media_source2(kSource2); | 819 MediaSource media_source2(kSource2); |
| 820 std::unique_ptr<MockMediaSinksObserver> sinks_observer2( | 820 std::unique_ptr<MockMediaSinksObserver> sinks_observer2( |
| 821 new MockMediaSinksObserver(router(), media_source2, origin)); | 821 new MockMediaSinksObserver(router(), media_source2, origin)); |
| 822 EXPECT_CALL(*sinks_observer2, OnSinksReceived(IsEmpty())); | 822 EXPECT_CALL(*sinks_observer2, OnSinksReceived(IsEmpty())); |
| 823 EXPECT_TRUE(sinks_observer2->Init()); | 823 EXPECT_TRUE(sinks_observer2->Init()); |
| 824 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource)) | 824 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource)) |
| 825 .Times(0); | 825 .Times(0); |
| 826 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource2)) | 826 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource2)) |
| 827 .Times(0); | 827 .Times(0); |
| 828 ProcessEventLoop(); | 828 ProcessEventLoop(); |
| 829 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_media_route_provider_)); | 829 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_media_route_provider_)); |
| 830 | 830 |
| 831 // When availability transitions AVAILABLE, existing sink queries should be | 831 // When availability transitions AVAILABLE, existing sink queries should be |
| 832 // sent to MRPM. | 832 // sent to MRPM. |
| 833 router()->OnSinkAvailabilityUpdated( | 833 router()->OnSinkAvailabilityUpdated( |
| 834 interfaces::MediaRouter::SinkAvailability::AVAILABLE); | 834 mojom::MediaRouter::SinkAvailability::AVAILABLE); |
| 835 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource)) | 835 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource)) |
| 836 .Times(1); | 836 .Times(1); |
| 837 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource2)) | 837 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource2)) |
| 838 .Times(1); | 838 .Times(1); |
| 839 ProcessEventLoop(); | 839 ProcessEventLoop(); |
| 840 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_media_route_provider_)); | 840 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_media_route_provider_)); |
| 841 | 841 |
| 842 // No change in availability status; no calls should be made to MRPM. | 842 // No change in availability status; no calls should be made to MRPM. |
| 843 router()->OnSinkAvailabilityUpdated( | 843 router()->OnSinkAvailabilityUpdated( |
| 844 interfaces::MediaRouter::SinkAvailability::AVAILABLE); | 844 mojom::MediaRouter::SinkAvailability::AVAILABLE); |
| 845 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource)) | 845 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource)) |
| 846 .Times(0); | 846 .Times(0); |
| 847 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource2)) | 847 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource2)) |
| 848 .Times(0); | 848 .Times(0); |
| 849 ProcessEventLoop(); | 849 ProcessEventLoop(); |
| 850 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_media_route_provider_)); | 850 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_media_route_provider_)); |
| 851 | 851 |
| 852 // When availability is UNAVAILABLE, queries are already removed from MRPM. | 852 // When availability is UNAVAILABLE, queries are already removed from MRPM. |
| 853 // Unregistering observer won't result in call to MRPM to remove query. | 853 // Unregistering observer won't result in call to MRPM to remove query. |
| 854 router()->OnSinkAvailabilityUpdated( | 854 router()->OnSinkAvailabilityUpdated( |
| 855 interfaces::MediaRouter::SinkAvailability::UNAVAILABLE); | 855 mojom::MediaRouter::SinkAvailability::UNAVAILABLE); |
| 856 EXPECT_CALL(mock_media_route_provider_, StopObservingMediaSinks(kSource)) | 856 EXPECT_CALL(mock_media_route_provider_, StopObservingMediaSinks(kSource)) |
| 857 .Times(0); | 857 .Times(0); |
| 858 sinks_observer.reset(); | 858 sinks_observer.reset(); |
| 859 ProcessEventLoop(); | 859 ProcessEventLoop(); |
| 860 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_media_route_provider_)); | 860 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_media_route_provider_)); |
| 861 | 861 |
| 862 // When availability is AVAILABLE, call is made to MRPM to remove query when | 862 // When availability is AVAILABLE, call is made to MRPM to remove query when |
| 863 // observer is unregistered. | 863 // observer is unregistered. |
| 864 router()->OnSinkAvailabilityUpdated( | 864 router()->OnSinkAvailabilityUpdated( |
| 865 interfaces::MediaRouter::SinkAvailability::AVAILABLE); | 865 mojom::MediaRouter::SinkAvailability::AVAILABLE); |
| 866 EXPECT_CALL(mock_media_route_provider_, StopObservingMediaSinks(kSource2)); | 866 EXPECT_CALL(mock_media_route_provider_, StopObservingMediaSinks(kSource2)); |
| 867 sinks_observer2.reset(); | 867 sinks_observer2.reset(); |
| 868 ProcessEventLoop(); | 868 ProcessEventLoop(); |
| 869 } | 869 } |
| 870 | 870 |
| 871 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaRoutesObserver) { | 871 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaRoutesObserver) { |
| 872 MockMediaRouter mock_router; | 872 MockMediaRouter mock_router; |
| 873 MediaSource media_source(kSource); | 873 MediaSource media_source(kSource); |
| 874 MediaSource different_media_source(kSource2); | 874 MediaSource different_media_source(kSource2); |
| 875 EXPECT_CALL(mock_media_route_provider_, | 875 EXPECT_CALL(mock_media_route_provider_, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 904 incognito_expected_route.set_incognito(true); | 904 incognito_expected_route.set_incognito(true); |
| 905 expected_routes.push_back(incognito_expected_route); | 905 expected_routes.push_back(incognito_expected_route); |
| 906 std::vector<MediaRoute::Id> expected_joinable_route_ids; | 906 std::vector<MediaRoute::Id> expected_joinable_route_ids; |
| 907 expected_joinable_route_ids.push_back(kJoinableRouteId); | 907 expected_joinable_route_ids.push_back(kJoinableRouteId); |
| 908 expected_joinable_route_ids.push_back(kJoinableRouteId2); | 908 expected_joinable_route_ids.push_back(kJoinableRouteId2); |
| 909 | 909 |
| 910 std::vector<std::string> mojo_joinable_routes(2); | 910 std::vector<std::string> mojo_joinable_routes(2); |
| 911 mojo_joinable_routes[0] = kJoinableRouteId; | 911 mojo_joinable_routes[0] = kJoinableRouteId; |
| 912 mojo_joinable_routes[1] = kJoinableRouteId2; | 912 mojo_joinable_routes[1] = kJoinableRouteId2; |
| 913 | 913 |
| 914 std::vector<interfaces::MediaRoutePtr> mojo_routes(2); | 914 std::vector<mojom::MediaRoutePtr> mojo_routes(2); |
| 915 mojo_routes[0] = CreateMojoRoute(); | 915 mojo_routes[0] = CreateMojoRoute(); |
| 916 mojo_routes[1] = CreateMojoRoute(); | 916 mojo_routes[1] = CreateMojoRoute(); |
| 917 mojo_routes[1]->media_route_id = kRouteId2; | 917 mojo_routes[1]->media_route_id = kRouteId2; |
| 918 mojo_routes[1]->incognito = true; | 918 mojo_routes[1]->incognito = true; |
| 919 | 919 |
| 920 EXPECT_CALL(routes_observer, OnRoutesUpdated(SequenceEquals(expected_routes), | 920 EXPECT_CALL(routes_observer, OnRoutesUpdated(SequenceEquals(expected_routes), |
| 921 expected_joinable_route_ids)); | 921 expected_joinable_route_ids)); |
| 922 EXPECT_CALL(extra_routes_observer, | 922 EXPECT_CALL(extra_routes_observer, |
| 923 OnRoutesUpdated(SequenceEquals(expected_routes), | 923 OnRoutesUpdated(SequenceEquals(expected_routes), |
| 924 expected_joinable_route_ids)); | 924 expected_joinable_route_ids)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 946 mock_media_route_provider_, | 946 mock_media_route_provider_, |
| 947 StopObservingMediaRoutes(different_media_source.id())); | 947 StopObservingMediaRoutes(different_media_source.id())); |
| 948 ProcessEventLoop(); | 948 ProcessEventLoop(); |
| 949 } | 949 } |
| 950 | 950 |
| 951 TEST_F(MediaRouterMojoImplTest, SendRouteMessage) { | 951 TEST_F(MediaRouterMojoImplTest, SendRouteMessage) { |
| 952 EXPECT_CALL( | 952 EXPECT_CALL( |
| 953 mock_media_route_provider_, SendRouteMessage(kRouteId, kMessage, _)) | 953 mock_media_route_provider_, SendRouteMessage(kRouteId, kMessage, _)) |
| 954 .WillOnce(Invoke([]( | 954 .WillOnce(Invoke([]( |
| 955 const MediaRoute::Id& route_id, const std::string& message, | 955 const MediaRoute::Id& route_id, const std::string& message, |
| 956 const interfaces::MediaRouteProvider::SendRouteMessageCallback& cb) { | 956 const mojom::MediaRouteProvider::SendRouteMessageCallback& cb) { |
| 957 cb.Run(true); | 957 cb.Run(true); |
| 958 })); | 958 })); |
| 959 | 959 |
| 960 base::RunLoop run_loop; | 960 base::RunLoop run_loop; |
| 961 SendMessageCallbackHandler handler; | 961 SendMessageCallbackHandler handler; |
| 962 EXPECT_CALL(handler, Invoke(true)) | 962 EXPECT_CALL(handler, Invoke(true)) |
| 963 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 963 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 964 router()->SendRouteMessage(kRouteId, kMessage, | 964 router()->SendRouteMessage(kRouteId, kMessage, |
| 965 base::Bind(&SendMessageCallbackHandler::Invoke, | 965 base::Bind(&SendMessageCallbackHandler::Invoke, |
| 966 base::Unretained(&handler))); | 966 base::Unretained(&handler))); |
| 967 run_loop.Run(); | 967 run_loop.Run(); |
| 968 } | 968 } |
| 969 | 969 |
| 970 TEST_F(MediaRouterMojoImplTest, SendRouteBinaryMessage) { | 970 TEST_F(MediaRouterMojoImplTest, SendRouteBinaryMessage) { |
| 971 std::unique_ptr<std::vector<uint8_t>> expected_binary_data( | 971 std::unique_ptr<std::vector<uint8_t>> expected_binary_data( |
| 972 new std::vector<uint8_t>(kBinaryMessage, | 972 new std::vector<uint8_t>(kBinaryMessage, |
| 973 kBinaryMessage + arraysize(kBinaryMessage))); | 973 kBinaryMessage + arraysize(kBinaryMessage))); |
| 974 | 974 |
| 975 EXPECT_CALL(mock_media_route_provider_, | 975 EXPECT_CALL(mock_media_route_provider_, |
| 976 SendRouteBinaryMessageInternal(kRouteId, _, _)) | 976 SendRouteBinaryMessageInternal(kRouteId, _, _)) |
| 977 .WillOnce(Invoke([]( | 977 .WillOnce(Invoke([]( |
| 978 const MediaRoute::Id& route_id, const std::vector<uint8_t>& data, | 978 const MediaRoute::Id& route_id, const std::vector<uint8_t>& data, |
| 979 const interfaces::MediaRouteProvider::SendRouteMessageCallback& cb) { | 979 const mojom::MediaRouteProvider::SendRouteMessageCallback& cb) { |
| 980 EXPECT_EQ( | 980 EXPECT_EQ( |
| 981 0, memcmp(kBinaryMessage, &(data[0]), arraysize(kBinaryMessage))); | 981 0, memcmp(kBinaryMessage, &(data[0]), arraysize(kBinaryMessage))); |
| 982 cb.Run(true); | 982 cb.Run(true); |
| 983 })); | 983 })); |
| 984 | 984 |
| 985 base::RunLoop run_loop; | 985 base::RunLoop run_loop; |
| 986 SendMessageCallbackHandler handler; | 986 SendMessageCallbackHandler handler; |
| 987 EXPECT_CALL(handler, Invoke(true)) | 987 EXPECT_CALL(handler, Invoke(true)) |
| 988 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 988 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 989 router()->SendRouteBinaryMessage( | 989 router()->SendRouteBinaryMessage( |
| 990 kRouteId, std::move(expected_binary_data), | 990 kRouteId, std::move(expected_binary_data), |
| 991 base::Bind(&SendMessageCallbackHandler::Invoke, | 991 base::Bind(&SendMessageCallbackHandler::Invoke, |
| 992 base::Unretained(&handler))); | 992 base::Unretained(&handler))); |
| 993 run_loop.Run(); | 993 run_loop.Run(); |
| 994 } | 994 } |
| 995 | 995 |
| 996 TEST_F(MediaRouterMojoImplTest, PresentationSessionMessagesSingleObserver) { | 996 TEST_F(MediaRouterMojoImplTest, PresentationSessionMessagesSingleObserver) { |
| 997 std::vector<interfaces::RouteMessagePtr> mojo_messages(2); | 997 std::vector<mojom::RouteMessagePtr> mojo_messages(2); |
| 998 mojo_messages[0] = interfaces::RouteMessage::New(); | 998 mojo_messages[0] = mojom::RouteMessage::New(); |
| 999 mojo_messages[0]->type = interfaces::RouteMessage::Type::TEXT; | 999 mojo_messages[0]->type = mojom::RouteMessage::Type::TEXT; |
| 1000 mojo_messages[0]->message = std::string("text"); | 1000 mojo_messages[0]->message = std::string("text"); |
| 1001 mojo_messages[1] = interfaces::RouteMessage::New(); | 1001 mojo_messages[1] = mojom::RouteMessage::New(); |
| 1002 mojo_messages[1]->type = interfaces::RouteMessage::Type::BINARY; | 1002 mojo_messages[1]->type = mojom::RouteMessage::Type::BINARY; |
| 1003 mojo_messages[1]->data = std::vector<uint8_t>(1, UINT8_C(1)); | 1003 mojo_messages[1]->data = std::vector<uint8_t>(1, UINT8_C(1)); |
| 1004 | 1004 |
| 1005 ScopedVector<content::PresentationSessionMessage> expected_messages; | 1005 ScopedVector<content::PresentationSessionMessage> expected_messages; |
| 1006 std::unique_ptr<content::PresentationSessionMessage> message; | 1006 std::unique_ptr<content::PresentationSessionMessage> message; |
| 1007 message.reset(new content::PresentationSessionMessage( | 1007 message.reset(new content::PresentationSessionMessage( |
| 1008 content::PresentationMessageType::TEXT)); | 1008 content::PresentationMessageType::TEXT)); |
| 1009 message->message = "text"; | 1009 message->message = "text"; |
| 1010 expected_messages.push_back(std::move(message)); | 1010 expected_messages.push_back(std::move(message)); |
| 1011 | 1011 |
| 1012 message.reset(new content::PresentationSessionMessage( | 1012 message.reset(new content::PresentationSessionMessage( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1031 base::Unretained(&handler)), | 1031 base::Unretained(&handler)), |
| 1032 expected_route_id, router())); | 1032 expected_route_id, router())); |
| 1033 run_loop.Run(); | 1033 run_loop.Run(); |
| 1034 | 1034 |
| 1035 EXPECT_CALL(handler, InvokeObserver()); | 1035 EXPECT_CALL(handler, InvokeObserver()); |
| 1036 router()->OnRouteMessagesReceived(expected_route_id, | 1036 router()->OnRouteMessagesReceived(expected_route_id, |
| 1037 std::move(mojo_messages)); | 1037 std::move(mojo_messages)); |
| 1038 } | 1038 } |
| 1039 | 1039 |
| 1040 TEST_F(MediaRouterMojoImplTest, PresentationSessionMessagesMultipleObservers) { | 1040 TEST_F(MediaRouterMojoImplTest, PresentationSessionMessagesMultipleObservers) { |
| 1041 std::vector<interfaces::RouteMessagePtr> mojo_messages(2); | 1041 std::vector<mojom::RouteMessagePtr> mojo_messages(2); |
| 1042 mojo_messages[0] = interfaces::RouteMessage::New(); | 1042 mojo_messages[0] = mojom::RouteMessage::New(); |
| 1043 mojo_messages[0]->type = interfaces::RouteMessage::Type::TEXT; | 1043 mojo_messages[0]->type = mojom::RouteMessage::Type::TEXT; |
| 1044 mojo_messages[0]->message = std::string("text"); | 1044 mojo_messages[0]->message = std::string("text"); |
| 1045 mojo_messages[1] = interfaces::RouteMessage::New(); | 1045 mojo_messages[1] = mojom::RouteMessage::New(); |
| 1046 mojo_messages[1]->type = interfaces::RouteMessage::Type::BINARY; | 1046 mojo_messages[1]->type = mojom::RouteMessage::Type::BINARY; |
| 1047 mojo_messages[1]->data = std::vector<uint8_t>(1, UINT8_C(1)); | 1047 mojo_messages[1]->data = std::vector<uint8_t>(1, UINT8_C(1)); |
| 1048 | 1048 |
| 1049 ScopedVector<content::PresentationSessionMessage> expected_messages; | 1049 ScopedVector<content::PresentationSessionMessage> expected_messages; |
| 1050 std::unique_ptr<content::PresentationSessionMessage> message; | 1050 std::unique_ptr<content::PresentationSessionMessage> message; |
| 1051 message.reset(new content::PresentationSessionMessage( | 1051 message.reset(new content::PresentationSessionMessage( |
| 1052 content::PresentationMessageType::TEXT)); | 1052 content::PresentationMessageType::TEXT)); |
| 1053 message->message = "text"; | 1053 message->message = "text"; |
| 1054 expected_messages.push_back(std::move(message)); | 1054 expected_messages.push_back(std::move(message)); |
| 1055 | 1055 |
| 1056 message.reset(new content::PresentationSessionMessage( | 1056 message.reset(new content::PresentationSessionMessage( |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 | 1174 |
| 1175 TEST_F(MediaRouterMojoImplTest, SearchSinks) { | 1175 TEST_F(MediaRouterMojoImplTest, SearchSinks) { |
| 1176 std::string search_input("input"); | 1176 std::string search_input("input"); |
| 1177 std::string domain("google.com"); | 1177 std::string domain("google.com"); |
| 1178 MediaSource media_source(kSource); | 1178 MediaSource media_source(kSource); |
| 1179 | 1179 |
| 1180 EXPECT_CALL( | 1180 EXPECT_CALL( |
| 1181 mock_media_route_provider_, SearchSinks_(kSinkId, kSource, _, _)) | 1181 mock_media_route_provider_, SearchSinks_(kSinkId, kSource, _, _)) |
| 1182 .WillOnce(Invoke([&search_input, &domain]( | 1182 .WillOnce(Invoke([&search_input, &domain]( |
| 1183 const std::string& sink_id, const std::string& source, | 1183 const std::string& sink_id, const std::string& source, |
| 1184 const interfaces::SinkSearchCriteriaPtr& search_criteria, | 1184 const mojom::SinkSearchCriteriaPtr& search_criteria, |
| 1185 const interfaces::MediaRouteProvider::SearchSinksCallback& cb) { | 1185 const mojom::MediaRouteProvider::SearchSinksCallback& cb) { |
| 1186 EXPECT_EQ(search_input, search_criteria->input); | 1186 EXPECT_EQ(search_input, search_criteria->input); |
| 1187 EXPECT_EQ(domain, search_criteria->domain); | 1187 EXPECT_EQ(domain, search_criteria->domain); |
| 1188 cb.Run(kSinkId2); | 1188 cb.Run(kSinkId2); |
| 1189 })); | 1189 })); |
| 1190 | 1190 |
| 1191 SinkResponseCallbackHandler sink_handler; | 1191 SinkResponseCallbackHandler sink_handler; |
| 1192 EXPECT_CALL(sink_handler, Invoke(kSinkId2)).Times(1); | 1192 EXPECT_CALL(sink_handler, Invoke(kSinkId2)).Times(1); |
| 1193 MediaSinkSearchResponseCallback sink_callback = base::Bind( | 1193 MediaSinkSearchResponseCallback sink_callback = base::Bind( |
| 1194 &SinkResponseCallbackHandler::Invoke, base::Unretained(&sink_handler)); | 1194 &SinkResponseCallbackHandler::Invoke, base::Unretained(&sink_handler)); |
| 1195 | 1195 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 | 1230 |
| 1231 void TearDown() override { | 1231 void TearDown() override { |
| 1232 media_router_.reset(); | 1232 media_router_.reset(); |
| 1233 profile_.reset(); | 1233 profile_.reset(); |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 // Constructs bindings so that |media_router_| delegates calls to | 1236 // Constructs bindings so that |media_router_| delegates calls to |
| 1237 // |mojo_media_router_|, which are then handled by | 1237 // |mojo_media_router_|, which are then handled by |
| 1238 // |mock_media_route_provider_service_|. | 1238 // |mock_media_route_provider_service_|. |
| 1239 void BindMediaRouteProvider() { | 1239 void BindMediaRouteProvider() { |
| 1240 binding_.reset(new mojo::Binding<interfaces::MediaRouteProvider>( | 1240 binding_.reset(new mojo::Binding<mojom::MediaRouteProvider>( |
| 1241 &mock_media_route_provider_, | 1241 &mock_media_route_provider_, |
| 1242 mojo::GetProxy(&media_route_provider_proxy_))); | 1242 mojo::GetProxy(&media_route_provider_proxy_))); |
| 1243 media_router_->BindToMojoRequest(mojo::GetProxy(&media_router_proxy_), | 1243 media_router_->BindToMojoRequest(mojo::GetProxy(&media_router_proxy_), |
| 1244 *extension_); | 1244 *extension_); |
| 1245 } | 1245 } |
| 1246 | 1246 |
| 1247 void ResetMediaRouteProvider() { | 1247 void ResetMediaRouteProvider() { |
| 1248 binding_.reset(); | 1248 binding_.reset(); |
| 1249 media_router_->BindToMojoRequest(mojo::GetProxy(&media_router_proxy_), | 1249 media_router_->BindToMojoRequest(mojo::GetProxy(&media_router_proxy_), |
| 1250 *extension_); | 1250 *extension_); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1278 histogram_tester_.ExpectBucketCount("MediaRouter.Provider.Wakeup", | 1278 histogram_tester_.ExpectBucketCount("MediaRouter.Provider.Wakeup", |
| 1279 static_cast<int>(wakeup), | 1279 static_cast<int>(wakeup), |
| 1280 expected_count); | 1280 expected_count); |
| 1281 } | 1281 } |
| 1282 | 1282 |
| 1283 content::TestBrowserThreadBundle thread_bundle_; | 1283 content::TestBrowserThreadBundle thread_bundle_; |
| 1284 std::unique_ptr<MediaRouterMojoImpl> media_router_; | 1284 std::unique_ptr<MediaRouterMojoImpl> media_router_; |
| 1285 RegisterMediaRouteProviderHandler provide_handler_; | 1285 RegisterMediaRouteProviderHandler provide_handler_; |
| 1286 TestProcessManager* process_manager_; | 1286 TestProcessManager* process_manager_; |
| 1287 testing::StrictMock<MockMediaRouteProvider> mock_media_route_provider_; | 1287 testing::StrictMock<MockMediaRouteProvider> mock_media_route_provider_; |
| 1288 interfaces::MediaRouterPtr media_router_proxy_; | 1288 mojom::MediaRouterPtr media_router_proxy_; |
| 1289 scoped_refptr<extensions::Extension> extension_; | 1289 scoped_refptr<extensions::Extension> extension_; |
| 1290 | 1290 |
| 1291 private: | 1291 private: |
| 1292 std::unique_ptr<TestingProfile> profile_; | 1292 std::unique_ptr<TestingProfile> profile_; |
| 1293 interfaces::MediaRouteProviderPtr media_route_provider_proxy_; | 1293 mojom::MediaRouteProviderPtr media_route_provider_proxy_; |
| 1294 std::unique_ptr<mojo::Binding<interfaces::MediaRouteProvider>> binding_; | 1294 std::unique_ptr<mojo::Binding<mojom::MediaRouteProvider>> binding_; |
| 1295 base::HistogramTester histogram_tester_; | 1295 base::HistogramTester histogram_tester_; |
| 1296 | 1296 |
| 1297 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoExtensionTest); | 1297 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoExtensionTest); |
| 1298 }; | 1298 }; |
| 1299 | 1299 |
| 1300 TEST_F(MediaRouterMojoExtensionTest, DeferredBindingAndSuspension) { | 1300 TEST_F(MediaRouterMojoExtensionTest, DeferredBindingAndSuspension) { |
| 1301 // DetachRoute is called before *any* extension has connected. | 1301 // DetachRoute is called before *any* extension has connected. |
| 1302 // It should be queued. | 1302 // It should be queued. |
| 1303 media_router_->DetachRoute(kRouteId); | 1303 media_router_->DetachRoute(kRouteId); |
| 1304 | 1304 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 EXPECT_CALL(mock_media_route_provider_, | 1572 EXPECT_CALL(mock_media_route_provider_, |
| 1573 UpdateMediaSinks(MediaSourceForDesktop().id())) | 1573 UpdateMediaSinks(MediaSourceForDesktop().id())) |
| 1574 .WillOnce(InvokeWithoutArgs([&run_loop2]() { | 1574 .WillOnce(InvokeWithoutArgs([&run_loop2]() { |
| 1575 run_loop2.Quit(); | 1575 run_loop2.Quit(); |
| 1576 })); | 1576 })); |
| 1577 | 1577 |
| 1578 run_loop2.Run(); | 1578 run_loop2.Run(); |
| 1579 } | 1579 } |
| 1580 | 1580 |
| 1581 } // namespace media_router | 1581 } // namespace media_router |
| OLD | NEW |