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