Chromium Code Reviews| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 const char kSource[] = "source1"; | 72 const char kSource[] = "source1"; |
| 73 const char kSource2[] = "source2"; | 73 const char kSource2[] = "source2"; |
| 74 const char kRouteId[] = "routeId"; | 74 const char kRouteId[] = "routeId"; |
| 75 const char kRouteId2[] = "routeId2"; | 75 const char kRouteId2[] = "routeId2"; |
| 76 const char kJoinableRouteId[] = "joinableRouteId"; | 76 const char kJoinableRouteId[] = "joinableRouteId"; |
| 77 const char kJoinableRouteId2[] = "joinableRouteId2"; | 77 const char kJoinableRouteId2[] = "joinableRouteId2"; |
| 78 const char kSinkId[] = "sink"; | 78 const char kSinkId[] = "sink"; |
| 79 const char kSinkId2[] = "sink2"; | 79 const char kSinkId2[] = "sink2"; |
| 80 const char kSinkName[] = "sinkName"; | 80 const char kSinkName[] = "sinkName"; |
| 81 const char kPresentationId[] = "presentationId"; | 81 const char kPresentationId[] = "presentationId"; |
| 82 const char kOrigin[] = "http://origin/"; | 82 const url::Origin kOrigin = url::Origin(GURL("http://origin/")); |
|
mark a. foltz
2017/01/20 18:26:40
Move to test ctor
steimel
2017/01/23 19:24:58
Done.
| |
| 83 const int kInvalidTabId = -1; | 83 const int kInvalidTabId = -1; |
| 84 const uint8_t kBinaryMessage[] = {0x01, 0x02, 0x03, 0x04}; | 84 const uint8_t kBinaryMessage[] = {0x01, 0x02, 0x03, 0x04}; |
| 85 const int kTimeoutMillis = 5 * 1000; | 85 const int kTimeoutMillis = 5 * 1000; |
| 86 | 86 |
| 87 IssueInfo CreateIssueInfo(const std::string& title) { | 87 IssueInfo CreateIssueInfo(const std::string& title) { |
| 88 IssueInfo issue_info; | 88 IssueInfo issue_info; |
| 89 issue_info.title = title; | 89 issue_info.title = title; |
| 90 issue_info.message = std::string("msg"); | 90 issue_info.message = std::string("msg"); |
| 91 issue_info.default_action = IssueInfo::Action::DISMISS; | 91 issue_info.default_action = IssueInfo::Action::DISMISS; |
| 92 issue_info.severity = IssueInfo::Severity::WARNING; | 92 issue_info.severity = IssueInfo::Severity::WARNING; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", | 191 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", |
| 192 false); | 192 false); |
| 193 | 193 |
| 194 // Use a lambda function as an invocation target here to work around | 194 // Use a lambda function as an invocation target here to work around |
| 195 // a limitation with GMock::Invoke that prevents it from using move-only types | 195 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 196 // in runnable parameter lists. | 196 // in runnable parameter lists. |
| 197 EXPECT_CALL(mock_media_route_provider_, | 197 EXPECT_CALL(mock_media_route_provider_, |
| 198 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, _, _, _)) | 198 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, _, _, _)) |
| 199 .WillOnce(Invoke( | 199 .WillOnce(Invoke( |
| 200 [](const std::string& source, const std::string& sink, | 200 [](const std::string& source, const std::string& sink, |
| 201 const std::string& presentation_id, const std::string& origin, | 201 const std::string& presentation_id, const url::Origin& origin, |
| 202 int tab_id, base::TimeDelta timeout, bool incognito, | 202 int tab_id, base::TimeDelta timeout, bool incognito, |
| 203 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 203 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 204 cb.Run(CreateMojoRoute(), std::string(), | 204 cb.Run(CreateMojoRoute(), std::string(), |
| 205 mojom::RouteRequestResultCode::OK); | 205 mojom::RouteRequestResultCode::OK); |
| 206 })); | 206 })); |
| 207 | 207 |
| 208 base::RunLoop run_loop; | 208 base::RunLoop run_loop; |
| 209 RouteResponseCallbackHandler handler; | 209 RouteResponseCallbackHandler handler; |
| 210 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 210 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 211 RouteRequestResult::OK)) | 211 RouteRequestResult::OK)) |
| 212 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 212 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 213 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 213 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 214 route_response_callbacks.push_back(base::Bind( | 214 route_response_callbacks.push_back(base::Bind( |
| 215 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 215 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 216 router()->CreateRoute( | 216 router()->CreateRoute( |
| 217 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, | 217 kSource, kSinkId, kOrigin, nullptr, route_response_callbacks, |
| 218 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 218 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 219 run_loop.Run(); | 219 run_loop.Run(); |
| 220 ExpectResultBucketCount("CreateRoute", RouteRequestResult::ResultCode::OK, 1); | 220 ExpectResultBucketCount("CreateRoute", RouteRequestResult::ResultCode::OK, 1); |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST_F(MediaRouterMojoImplTest, CreateIncognitoRoute) { | 223 TEST_F(MediaRouterMojoImplTest, CreateIncognitoRoute) { |
| 224 MediaSource media_source(kSource); | 224 MediaSource media_source(kSource); |
| 225 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", | 225 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", |
| 226 false); | 226 false); |
| 227 expected_route.set_incognito(true); | 227 expected_route.set_incognito(true); |
| 228 | 228 |
| 229 // Use a lambda function as an invocation target here to work around | 229 // Use a lambda function as an invocation target here to work around |
| 230 // a limitation with GMock::Invoke that prevents it from using move-only types | 230 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 231 // in runnable parameter lists. | 231 // in runnable parameter lists. |
| 232 EXPECT_CALL(mock_media_route_provider_, | 232 EXPECT_CALL(mock_media_route_provider_, |
| 233 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, _, _, _)) | 233 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, _, _, _)) |
| 234 .WillOnce(Invoke( | 234 .WillOnce(Invoke( |
| 235 [](const std::string& source, const std::string& sink, | 235 [](const std::string& source, const std::string& sink, |
| 236 const std::string& presentation_id, const std::string& origin, | 236 const std::string& presentation_id, const url::Origin& origin, |
| 237 int tab_id, base::TimeDelta timeout, bool incognito, | 237 int tab_id, base::TimeDelta timeout, bool incognito, |
| 238 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 238 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 239 mojom::MediaRoutePtr route = CreateMojoRoute(); | 239 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 240 route->custom_controller_path = | 240 route->custom_controller_path = |
| 241 std::string("custom/controller/path"); | 241 std::string("custom/controller/path"); |
| 242 route->is_incognito = true; | 242 route->is_incognito = true; |
| 243 cb.Run(std::move(route), std::string(), | 243 cb.Run(std::move(route), std::string(), |
| 244 mojom::RouteRequestResultCode::OK); | 244 mojom::RouteRequestResultCode::OK); |
| 245 })); | 245 })); |
| 246 | 246 |
| 247 base::RunLoop run_loop; | 247 base::RunLoop run_loop; |
| 248 RouteResponseCallbackHandler handler; | 248 RouteResponseCallbackHandler handler; |
| 249 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 249 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 250 RouteRequestResult::OK)) | 250 RouteRequestResult::OK)) |
| 251 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 251 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 252 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 252 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 253 route_response_callbacks.push_back(base::Bind( | 253 route_response_callbacks.push_back(base::Bind( |
| 254 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 254 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 255 router()->CreateRoute( | 255 router()->CreateRoute( |
| 256 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, | 256 kSource, kSinkId, kOrigin, nullptr, route_response_callbacks, |
| 257 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 257 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 258 run_loop.Run(); | 258 run_loop.Run(); |
| 259 ExpectResultBucketCount("CreateRoute", RouteRequestResult::ResultCode::OK, 1); | 259 ExpectResultBucketCount("CreateRoute", RouteRequestResult::ResultCode::OK, 1); |
| 260 } | 260 } |
| 261 | 261 |
| 262 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) { | 262 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) { |
| 263 EXPECT_CALL( | 263 EXPECT_CALL( |
| 264 mock_media_route_provider_, | 264 mock_media_route_provider_, |
| 265 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, | 265 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, |
| 266 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) | 266 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) |
| 267 .WillOnce(Invoke( | 267 .WillOnce(Invoke( |
| 268 [](const std::string& source, const std::string& sink, | 268 [](const std::string& source, const std::string& sink, |
| 269 const std::string& presentation_id, const std::string& origin, | 269 const std::string& presentation_id, const url::Origin& origin, |
| 270 int tab_id, base::TimeDelta timeout, bool incognito, | 270 int tab_id, base::TimeDelta timeout, bool incognito, |
| 271 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 271 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 272 cb.Run(mojom::MediaRoutePtr(), std::string(kError), | 272 cb.Run(mojom::MediaRoutePtr(), std::string(kError), |
| 273 mojom::RouteRequestResultCode::TIMED_OUT); | 273 mojom::RouteRequestResultCode::TIMED_OUT); |
| 274 })); | 274 })); |
| 275 | 275 |
| 276 RouteResponseCallbackHandler handler; | 276 RouteResponseCallbackHandler handler; |
| 277 base::RunLoop run_loop; | 277 base::RunLoop run_loop; |
| 278 EXPECT_CALL(handler, | 278 EXPECT_CALL(handler, |
| 279 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) | 279 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) |
| 280 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 280 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 281 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 281 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 282 route_response_callbacks.push_back(base::Bind( | 282 route_response_callbacks.push_back(base::Bind( |
| 283 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 283 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 284 router()->CreateRoute( | 284 router()->CreateRoute( |
| 285 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, | 285 kSource, kSinkId, kOrigin, nullptr, route_response_callbacks, |
| 286 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 286 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 287 run_loop.Run(); | 287 run_loop.Run(); |
| 288 ExpectResultBucketCount("CreateRoute", | 288 ExpectResultBucketCount("CreateRoute", |
| 289 RouteRequestResult::ResultCode::TIMED_OUT, 1); | 289 RouteRequestResult::ResultCode::TIMED_OUT, 1); |
| 290 } | 290 } |
| 291 | 291 |
| 292 TEST_F(MediaRouterMojoImplTest, CreateRouteIncognitoMismatchFails) { | 292 TEST_F(MediaRouterMojoImplTest, CreateRouteIncognitoMismatchFails) { |
| 293 EXPECT_CALL(mock_media_route_provider_, | 293 EXPECT_CALL( |
| 294 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, | 294 mock_media_route_provider_, |
| 295 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 295 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, |
| 296 true, _)) | 296 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) |
| 297 .WillOnce(Invoke( | 297 .WillOnce(Invoke( |
| 298 [](const std::string& source, const std::string& sink, | 298 [](const std::string& source, const std::string& sink, |
| 299 const std::string& presentation_id, const std::string& origin, | 299 const std::string& presentation_id, const url::Origin& origin, |
| 300 int tab_id, base::TimeDelta timeout, bool incognito, | 300 int tab_id, base::TimeDelta timeout, bool incognito, |
| 301 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 301 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 302 cb.Run(CreateMojoRoute(), std::string(), | 302 cb.Run(CreateMojoRoute(), std::string(), |
| 303 mojom::RouteRequestResultCode::OK); | 303 mojom::RouteRequestResultCode::OK); |
| 304 })); | 304 })); |
| 305 | 305 |
| 306 RouteResponseCallbackHandler handler; | 306 RouteResponseCallbackHandler handler; |
| 307 base::RunLoop run_loop; | 307 base::RunLoop run_loop; |
| 308 std::string error("Mismatch in incognito status: request = 1, response = 0"); | 308 std::string error("Mismatch in incognito status: request = 1, response = 0"); |
| 309 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, | 309 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, |
| 310 RouteRequestResult::INCOGNITO_MISMATCH)) | 310 RouteRequestResult::INCOGNITO_MISMATCH)) |
| 311 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 311 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 312 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 312 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 313 route_response_callbacks.push_back(base::Bind( | 313 route_response_callbacks.push_back(base::Bind( |
| 314 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 314 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 315 router()->CreateRoute( | 315 router()->CreateRoute( |
| 316 kSource, kSinkId, GURL(kOrigin), nullptr, route_response_callbacks, | 316 kSource, kSinkId, kOrigin, nullptr, route_response_callbacks, |
| 317 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 317 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 318 run_loop.Run(); | 318 run_loop.Run(); |
| 319 ExpectResultBucketCount( | 319 ExpectResultBucketCount( |
| 320 "CreateRoute", RouteRequestResult::ResultCode::INCOGNITO_MISMATCH, 1); | 320 "CreateRoute", RouteRequestResult::ResultCode::INCOGNITO_MISMATCH, 1); |
| 321 } | 321 } |
| 322 | 322 |
| 323 TEST_F(MediaRouterMojoImplTest, IncognitoRoutesTerminatedOnProfileShutdown) { | 323 TEST_F(MediaRouterMojoImplTest, IncognitoRoutesTerminatedOnProfileShutdown) { |
| 324 mojom::MediaRoutePtr route = CreateMojoRoute(); | 324 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 325 route->is_incognito = true; | 325 route->is_incognito = true; |
| 326 | 326 |
| 327 EXPECT_CALL(mock_media_route_provider_, | 327 EXPECT_CALL( |
| 328 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, | 328 mock_media_route_provider_, |
| 329 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 329 CreateRoute(kSource, kSinkId, _, kOrigin, kInvalidTabId, |
| 330 true, _)) | 330 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) |
| 331 .WillOnce(Invoke( | 331 .WillOnce(Invoke( |
| 332 [](const std::string& source, const std::string& sink, | 332 [](const std::string& source, const std::string& sink, |
| 333 const std::string& presentation_id, const std::string& origin, | 333 const std::string& presentation_id, const url::Origin& origin, |
| 334 int tab_id, base::TimeDelta timeout, bool incognito, | 334 int tab_id, base::TimeDelta timeout, bool incognito, |
| 335 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 335 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 336 mojom::MediaRoutePtr route = CreateMojoRoute(); | 336 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 337 route->is_incognito = true; | 337 route->is_incognito = true; |
| 338 cb.Run(std::move(route), std::string(), | 338 cb.Run(std::move(route), std::string(), |
| 339 mojom::RouteRequestResultCode::OK); | 339 mojom::RouteRequestResultCode::OK); |
| 340 })); | 340 })); |
| 341 base::RunLoop run_loop; | 341 base::RunLoop run_loop; |
| 342 router()->CreateRoute(kSource, kSinkId, GURL(kOrigin), nullptr, | 342 router()->CreateRoute(kSource, kSinkId, kOrigin, nullptr, |
| 343 std::vector<MediaRouteResponseCallback>(), | 343 std::vector<MediaRouteResponseCallback>(), |
| 344 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 344 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| 345 true); | 345 true); |
| 346 std::vector<mojom::MediaRoutePtr> mojo_routes(1); | 346 std::vector<mojom::MediaRoutePtr> mojo_routes(1); |
| 347 mojo_routes[0] = route->Clone(); | 347 mojo_routes[0] = route->Clone(); |
| 348 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 348 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), |
| 349 std::vector<std::string>()); | 349 std::vector<std::string>()); |
| 350 | 350 |
| 351 // TODO(mfoltz): Where possible, convert other tests to use RunUntilIdle | 351 // TODO(mfoltz): Where possible, convert other tests to use RunUntilIdle |
| 352 // instead of manually calling Run/Quit on the run loop. | 352 // instead of manually calling Run/Quit on the run loop. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 380 | 380 |
| 381 // Use a lambda function as an invocation target here to work around | 381 // Use a lambda function as an invocation target here to work around |
| 382 // a limitation with GMock::Invoke that prevents it from using move-only types | 382 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 383 // in runnable parameter lists. | 383 // in runnable parameter lists. |
| 384 EXPECT_CALL( | 384 EXPECT_CALL( |
| 385 mock_media_route_provider_, | 385 mock_media_route_provider_, |
| 386 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, | 386 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, |
| 387 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) | 387 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) |
| 388 .WillOnce(Invoke([&route]( | 388 .WillOnce(Invoke([&route]( |
| 389 const std::string& source, const std::string& presentation_id, | 389 const std::string& source, const std::string& presentation_id, |
| 390 const std::string& origin, int tab_id, base::TimeDelta timeout, | 390 const url::Origin& origin, int tab_id, base::TimeDelta timeout, |
| 391 bool incognito, | 391 bool incognito, |
| 392 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 392 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 393 cb.Run(std::move(route), std::string(), | 393 cb.Run(std::move(route), std::string(), |
| 394 mojom::RouteRequestResultCode::OK); | 394 mojom::RouteRequestResultCode::OK); |
| 395 })); | 395 })); |
| 396 | 396 |
| 397 RouteResponseCallbackHandler handler; | 397 RouteResponseCallbackHandler handler; |
| 398 base::RunLoop run_loop; | 398 base::RunLoop run_loop; |
| 399 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 399 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 400 RouteRequestResult::OK)) | 400 RouteRequestResult::OK)) |
| 401 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 401 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 402 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 402 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 403 route_response_callbacks.push_back(base::Bind( | 403 route_response_callbacks.push_back(base::Bind( |
| 404 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 404 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 405 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr, | 405 router()->JoinRoute(kSource, kPresentationId, kOrigin, nullptr, |
| 406 route_response_callbacks, | 406 route_response_callbacks, |
| 407 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 407 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 408 run_loop.Run(); | 408 run_loop.Run(); |
| 409 ExpectResultBucketCount("JoinRoute", RouteRequestResult::ResultCode::OK, 1); | 409 ExpectResultBucketCount("JoinRoute", RouteRequestResult::ResultCode::OK, 1); |
| 410 } | 410 } |
| 411 | 411 |
| 412 TEST_F(MediaRouterMojoImplTest, JoinRouteNotFoundFails) { | 412 TEST_F(MediaRouterMojoImplTest, JoinRouteNotFoundFails) { |
| 413 RouteResponseCallbackHandler handler; | 413 RouteResponseCallbackHandler handler; |
| 414 base::RunLoop run_loop; | 414 base::RunLoop run_loop; |
| 415 EXPECT_CALL(handler, DoInvoke(nullptr, "", "Route not found", | 415 EXPECT_CALL(handler, DoInvoke(nullptr, "", "Route not found", |
| 416 RouteRequestResult::ROUTE_NOT_FOUND)) | 416 RouteRequestResult::ROUTE_NOT_FOUND)) |
| 417 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 417 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 418 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 418 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 419 route_response_callbacks.push_back(base::Bind( | 419 route_response_callbacks.push_back(base::Bind( |
| 420 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 420 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 421 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr, | 421 router()->JoinRoute(kSource, kPresentationId, kOrigin, nullptr, |
| 422 route_response_callbacks, | 422 route_response_callbacks, |
| 423 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 423 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 424 run_loop.Run(); | 424 run_loop.Run(); |
| 425 ExpectResultBucketCount("JoinRoute", | 425 ExpectResultBucketCount("JoinRoute", |
| 426 RouteRequestResult::ResultCode::ROUTE_NOT_FOUND, 1); | 426 RouteRequestResult::ResultCode::ROUTE_NOT_FOUND, 1); |
| 427 } | 427 } |
| 428 | 428 |
| 429 TEST_F(MediaRouterMojoImplTest, JoinRouteTimedOutFails) { | 429 TEST_F(MediaRouterMojoImplTest, JoinRouteTimedOutFails) { |
| 430 // Make sure the MR has received an update with the route, so it knows there | 430 // Make sure the MR has received an update with the route, so it knows there |
| 431 // is a route to join. | 431 // is a route to join. |
| 432 std::vector<mojom::MediaRoutePtr> mojo_routes(1); | 432 std::vector<mojom::MediaRoutePtr> mojo_routes(1); |
| 433 mojo_routes[0] = CreateMojoRoute(); | 433 mojo_routes[0] = CreateMojoRoute(); |
| 434 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 434 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), |
| 435 std::vector<std::string>()); | 435 std::vector<std::string>()); |
| 436 EXPECT_TRUE(router()->HasJoinableRoute()); | 436 EXPECT_TRUE(router()->HasJoinableRoute()); |
| 437 | 437 |
| 438 EXPECT_CALL( | 438 EXPECT_CALL( |
| 439 mock_media_route_provider_, | 439 mock_media_route_provider_, |
| 440 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, | 440 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, |
| 441 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) | 441 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) |
| 442 .WillOnce(Invoke( | 442 .WillOnce(Invoke( |
| 443 [](const std::string& source, const std::string& presentation_id, | 443 [](const std::string& source, const std::string& presentation_id, |
| 444 const std::string& origin, int tab_id, base::TimeDelta timeout, | 444 const url::Origin& origin, int tab_id, base::TimeDelta timeout, |
| 445 bool incognito, | 445 bool incognito, |
| 446 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 446 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 447 cb.Run(mojom::MediaRoutePtr(), std::string(kError), | 447 cb.Run(mojom::MediaRoutePtr(), std::string(kError), |
| 448 mojom::RouteRequestResultCode::TIMED_OUT); | 448 mojom::RouteRequestResultCode::TIMED_OUT); |
| 449 })); | 449 })); |
| 450 | 450 |
| 451 RouteResponseCallbackHandler handler; | 451 RouteResponseCallbackHandler handler; |
| 452 base::RunLoop run_loop; | 452 base::RunLoop run_loop; |
| 453 EXPECT_CALL(handler, | 453 EXPECT_CALL(handler, |
| 454 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) | 454 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) |
| 455 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 455 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 456 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 456 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 457 route_response_callbacks.push_back(base::Bind( | 457 route_response_callbacks.push_back(base::Bind( |
| 458 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 458 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 459 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr, | 459 router()->JoinRoute(kSource, kPresentationId, kOrigin, nullptr, |
| 460 route_response_callbacks, | 460 route_response_callbacks, |
| 461 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 461 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 462 run_loop.Run(); | 462 run_loop.Run(); |
| 463 ExpectResultBucketCount("JoinRoute", | 463 ExpectResultBucketCount("JoinRoute", |
| 464 RouteRequestResult::ResultCode::TIMED_OUT, 1); | 464 RouteRequestResult::ResultCode::TIMED_OUT, 1); |
| 465 } | 465 } |
| 466 | 466 |
| 467 TEST_F(MediaRouterMojoImplTest, JoinRouteIncognitoMismatchFails) { | 467 TEST_F(MediaRouterMojoImplTest, JoinRouteIncognitoMismatchFails) { |
| 468 mojom::MediaRoutePtr route = CreateMojoRoute(); | 468 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 469 | 469 |
| 470 // Make sure the MR has received an update with the route, so it knows there | 470 // Make sure the MR has received an update with the route, so it knows there |
| 471 // is a route to join. | 471 // is a route to join. |
| 472 std::vector<mojom::MediaRoutePtr> mojo_routes(1); | 472 std::vector<mojom::MediaRoutePtr> mojo_routes(1); |
| 473 mojo_routes[0] = route->Clone(); | 473 mojo_routes[0] = route->Clone(); |
| 474 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 474 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), |
| 475 std::vector<std::string>()); | 475 std::vector<std::string>()); |
| 476 EXPECT_TRUE(router()->HasJoinableRoute()); | 476 EXPECT_TRUE(router()->HasJoinableRoute()); |
| 477 | 477 |
| 478 // Use a lambda function as an invocation target here to work around | 478 // Use a lambda function as an invocation target here to work around |
| 479 // a limitation with GMock::Invoke that prevents it from using move-only types | 479 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 480 // in runnable parameter lists. | 480 // in runnable parameter lists. |
| 481 EXPECT_CALL( | 481 EXPECT_CALL( |
| 482 mock_media_route_provider_, | 482 mock_media_route_provider_, |
| 483 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, | 483 JoinRoute(kSource, kPresentationId, kOrigin, kInvalidTabId, |
| 484 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) | 484 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) |
| 485 .WillOnce(Invoke([&route]( | 485 .WillOnce(Invoke([&route]( |
| 486 const std::string& source, const std::string& presentation_id, | 486 const std::string& source, const std::string& presentation_id, |
| 487 const std::string& origin, int tab_id, base::TimeDelta timeout, | 487 const url::Origin& origin, int tab_id, base::TimeDelta timeout, |
| 488 bool incognito, | 488 bool incognito, |
| 489 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 489 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 490 cb.Run(std::move(route), std::string(), | 490 cb.Run(std::move(route), std::string(), |
| 491 mojom::RouteRequestResultCode::OK); | 491 mojom::RouteRequestResultCode::OK); |
| 492 })); | 492 })); |
| 493 | 493 |
| 494 RouteResponseCallbackHandler handler; | 494 RouteResponseCallbackHandler handler; |
| 495 base::RunLoop run_loop; | 495 base::RunLoop run_loop; |
| 496 std::string error("Mismatch in incognito status: request = 1, response = 0"); | 496 std::string error("Mismatch in incognito status: request = 1, response = 0"); |
| 497 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, | 497 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, |
| 498 RouteRequestResult::INCOGNITO_MISMATCH)) | 498 RouteRequestResult::INCOGNITO_MISMATCH)) |
| 499 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 499 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 500 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 500 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 501 route_response_callbacks.push_back(base::Bind( | 501 route_response_callbacks.push_back(base::Bind( |
| 502 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 502 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 503 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), nullptr, | 503 router()->JoinRoute(kSource, kPresentationId, kOrigin, nullptr, |
| 504 route_response_callbacks, | 504 route_response_callbacks, |
| 505 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 505 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 506 run_loop.Run(); | 506 run_loop.Run(); |
| 507 ExpectResultBucketCount( | 507 ExpectResultBucketCount( |
| 508 "JoinRoute", RouteRequestResult::ResultCode::INCOGNITO_MISMATCH, 1); | 508 "JoinRoute", RouteRequestResult::ResultCode::INCOGNITO_MISMATCH, 1); |
| 509 } | 509 } |
| 510 | 510 |
| 511 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteId) { | 511 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteId) { |
| 512 MediaSource media_source(kSource); | 512 MediaSource media_source(kSource); |
| 513 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", | 513 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", |
| 514 false); | 514 false); |
| 515 expected_route.set_incognito(false); | 515 expected_route.set_incognito(false); |
| 516 mojom::MediaRoutePtr route = CreateMojoRoute(); | 516 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 517 | 517 |
| 518 // Use a lambda function as an invocation target here to work around | 518 // Use a lambda function as an invocation target here to work around |
| 519 // a limitation with GMock::Invoke that prevents it from using move-only types | 519 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 520 // in runnable parameter lists. | 520 // in runnable parameter lists. |
| 521 EXPECT_CALL( | 521 EXPECT_CALL(mock_media_route_provider_, |
| 522 mock_media_route_provider_, | 522 ConnectRouteByRouteId( |
| 523 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, | 523 kSource, kRouteId, _, kOrigin, kInvalidTabId, |
| 524 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 524 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false, _)) |
| 525 false, _)) | |
| 526 .WillOnce(Invoke([&route]( | 525 .WillOnce(Invoke([&route]( |
| 527 const std::string& source, const std::string& route_id, | 526 const std::string& source, const std::string& route_id, |
| 528 const std::string& presentation_id, const std::string& origin, | 527 const std::string& presentation_id, const url::Origin& origin, |
| 529 int tab_id, base::TimeDelta timeout, bool incognito, | 528 int tab_id, base::TimeDelta timeout, bool incognito, |
| 530 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 529 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 531 cb.Run(std::move(route), std::string(), | 530 cb.Run(std::move(route), std::string(), |
| 532 mojom::RouteRequestResultCode::OK); | 531 mojom::RouteRequestResultCode::OK); |
| 533 })); | 532 })); |
| 534 | 533 |
| 535 RouteResponseCallbackHandler handler; | 534 RouteResponseCallbackHandler handler; |
| 536 base::RunLoop run_loop; | 535 base::RunLoop run_loop; |
| 537 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 536 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 538 RouteRequestResult::OK)) | 537 RouteRequestResult::OK)) |
| 539 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 538 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 540 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 539 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 541 route_response_callbacks.push_back(base::Bind( | 540 route_response_callbacks.push_back(base::Bind( |
| 542 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 541 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 543 router()->ConnectRouteByRouteId( | 542 router()->ConnectRouteByRouteId( |
| 544 kSource, kRouteId, GURL(kOrigin), nullptr, route_response_callbacks, | 543 kSource, kRouteId, kOrigin, nullptr, route_response_callbacks, |
| 545 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 544 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 546 run_loop.Run(); | 545 run_loop.Run(); |
| 547 ExpectResultBucketCount("JoinRoute", RouteRequestResult::ResultCode::OK, 1); | 546 ExpectResultBucketCount("JoinRoute", RouteRequestResult::ResultCode::OK, 1); |
| 548 } | 547 } |
| 549 | 548 |
| 550 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteIdFails) { | 549 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteIdFails) { |
| 551 EXPECT_CALL( | 550 EXPECT_CALL(mock_media_route_provider_, |
| 552 mock_media_route_provider_, | 551 ConnectRouteByRouteId( |
| 553 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, | 552 kSource, kRouteId, _, kOrigin, kInvalidTabId, |
| 554 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 553 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) |
| 555 true, _)) | |
| 556 .WillOnce(Invoke( | 554 .WillOnce(Invoke( |
| 557 [](const std::string& source, const std::string& route_id, | 555 [](const std::string& source, const std::string& route_id, |
| 558 const std::string& presentation_id, const std::string& origin, | 556 const std::string& presentation_id, const url::Origin& origin, |
| 559 int tab_id, base::TimeDelta timeout, bool incognito, | 557 int tab_id, base::TimeDelta timeout, bool incognito, |
| 560 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 558 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 561 cb.Run(mojom::MediaRoutePtr(), std::string(kError), | 559 cb.Run(mojom::MediaRoutePtr(), std::string(kError), |
| 562 mojom::RouteRequestResultCode::TIMED_OUT); | 560 mojom::RouteRequestResultCode::TIMED_OUT); |
| 563 })); | 561 })); |
| 564 | 562 |
| 565 RouteResponseCallbackHandler handler; | 563 RouteResponseCallbackHandler handler; |
| 566 base::RunLoop run_loop; | 564 base::RunLoop run_loop; |
| 567 EXPECT_CALL(handler, | 565 EXPECT_CALL(handler, |
| 568 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) | 566 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) |
| 569 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 567 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 570 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 568 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 571 route_response_callbacks.push_back(base::Bind( | 569 route_response_callbacks.push_back(base::Bind( |
| 572 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 570 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 573 router()->ConnectRouteByRouteId( | 571 router()->ConnectRouteByRouteId( |
| 574 kSource, kRouteId, GURL(kOrigin), nullptr, route_response_callbacks, | 572 kSource, kRouteId, kOrigin, nullptr, route_response_callbacks, |
| 575 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 573 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 576 run_loop.Run(); | 574 run_loop.Run(); |
| 577 ExpectResultBucketCount("JoinRoute", | 575 ExpectResultBucketCount("JoinRoute", |
| 578 RouteRequestResult::ResultCode::TIMED_OUT, 1); | 576 RouteRequestResult::ResultCode::TIMED_OUT, 1); |
| 579 } | 577 } |
| 580 | 578 |
| 581 TEST_F(MediaRouterMojoImplTest, ConnectRouteByIdIncognitoMismatchFails) { | 579 TEST_F(MediaRouterMojoImplTest, ConnectRouteByIdIncognitoMismatchFails) { |
| 582 mojom::MediaRoutePtr route = CreateMojoRoute(); | 580 mojom::MediaRoutePtr route = CreateMojoRoute(); |
| 583 | 581 |
| 584 // Use a lambda function as an invocation target here to work around | 582 // Use a lambda function as an invocation target here to work around |
| 585 // a limitation with GMock::Invoke that prevents it from using move-only types | 583 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 586 // in runnable parameter lists. | 584 // in runnable parameter lists. |
| 587 EXPECT_CALL( | 585 EXPECT_CALL(mock_media_route_provider_, |
| 588 mock_media_route_provider_, | 586 ConnectRouteByRouteId( |
| 589 ConnectRouteByRouteId(kSource, kRouteId, _, kOrigin, kInvalidTabId, | 587 kSource, kRouteId, _, kOrigin, kInvalidTabId, |
| 590 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 588 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) |
| 591 true, _)) | |
| 592 .WillOnce(Invoke([&route]( | 589 .WillOnce(Invoke([&route]( |
| 593 const std::string& source, const std::string& route_id, | 590 const std::string& source, const std::string& route_id, |
| 594 const std::string& presentation_id, const std::string& origin, | 591 const std::string& presentation_id, const url::Origin& origin, |
| 595 int tab_id, base::TimeDelta timeout, bool incognito, | 592 int tab_id, base::TimeDelta timeout, bool incognito, |
| 596 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 593 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 597 cb.Run(std::move(route), std::string(), | 594 cb.Run(std::move(route), std::string(), |
| 598 mojom::RouteRequestResultCode::OK); | 595 mojom::RouteRequestResultCode::OK); |
| 599 })); | 596 })); |
| 600 | 597 |
| 601 RouteResponseCallbackHandler handler; | 598 RouteResponseCallbackHandler handler; |
| 602 base::RunLoop run_loop; | 599 base::RunLoop run_loop; |
| 603 std::string error("Mismatch in incognito status: request = 1, response = 0"); | 600 std::string error("Mismatch in incognito status: request = 1, response = 0"); |
| 604 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, | 601 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, |
| 605 RouteRequestResult::INCOGNITO_MISMATCH)) | 602 RouteRequestResult::INCOGNITO_MISMATCH)) |
| 606 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 603 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 607 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 604 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 608 route_response_callbacks.push_back(base::Bind( | 605 route_response_callbacks.push_back(base::Bind( |
| 609 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 606 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 610 router()->ConnectRouteByRouteId( | 607 router()->ConnectRouteByRouteId( |
| 611 kSource, kRouteId, GURL(kOrigin), nullptr, route_response_callbacks, | 608 kSource, kRouteId, kOrigin, nullptr, route_response_callbacks, |
| 612 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 609 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 613 run_loop.Run(); | 610 run_loop.Run(); |
| 614 ExpectResultBucketCount( | 611 ExpectResultBucketCount( |
| 615 "JoinRoute", RouteRequestResult::ResultCode::INCOGNITO_MISMATCH, 1); | 612 "JoinRoute", RouteRequestResult::ResultCode::INCOGNITO_MISMATCH, 1); |
| 616 } | 613 } |
| 617 | 614 |
| 618 TEST_F(MediaRouterMojoImplTest, DetachRoute) { | 615 TEST_F(MediaRouterMojoImplTest, DetachRoute) { |
| 619 base::RunLoop run_loop; | 616 base::RunLoop run_loop; |
| 620 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId)) | 617 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId)) |
| 621 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 618 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 router()->ClearIssue(issue_from_observer1.id()); | 686 router()->ClearIssue(issue_from_observer1.id()); |
| 690 | 687 |
| 691 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); | 688 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); |
| 692 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); | 689 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); |
| 693 } | 690 } |
| 694 | 691 |
| 695 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) { | 692 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) { |
| 696 router()->OnSinkAvailabilityUpdated( | 693 router()->OnSinkAvailabilityUpdated( |
| 697 mojom::MediaRouter::SinkAvailability::AVAILABLE); | 694 mojom::MediaRouter::SinkAvailability::AVAILABLE); |
| 698 MediaSource media_source(kSource); | 695 MediaSource media_source(kSource); |
| 699 GURL origin("https://google.com"); | |
| 700 | 696 |
| 701 // These should only be called once even if there is more than one observer | 697 // These should only be called once even if there is more than one observer |
| 702 // for a given source. | 698 // for a given source. |
| 703 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource)); | 699 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource)); |
| 704 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource2)); | 700 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource2)); |
| 705 | 701 |
| 706 std::unique_ptr<MockMediaSinksObserver> sinks_observer( | 702 std::unique_ptr<MockMediaSinksObserver> sinks_observer( |
| 707 new MockMediaSinksObserver(router(), media_source, origin)); | 703 new MockMediaSinksObserver(router(), media_source, kOrigin)); |
| 708 EXPECT_TRUE(sinks_observer->Init()); | 704 EXPECT_TRUE(sinks_observer->Init()); |
| 709 std::unique_ptr<MockMediaSinksObserver> extra_sinks_observer( | 705 std::unique_ptr<MockMediaSinksObserver> extra_sinks_observer( |
| 710 new MockMediaSinksObserver(router(), media_source, origin)); | 706 new MockMediaSinksObserver(router(), media_source, kOrigin)); |
| 711 EXPECT_TRUE(extra_sinks_observer->Init()); | 707 EXPECT_TRUE(extra_sinks_observer->Init()); |
| 712 std::unique_ptr<MockMediaSinksObserver> unrelated_sinks_observer( | 708 std::unique_ptr<MockMediaSinksObserver> unrelated_sinks_observer( |
| 713 new MockMediaSinksObserver(router(), MediaSource(kSource2), origin)); | 709 new MockMediaSinksObserver(router(), MediaSource(kSource2), kOrigin)); |
| 714 EXPECT_TRUE(unrelated_sinks_observer->Init()); | 710 EXPECT_TRUE(unrelated_sinks_observer->Init()); |
| 715 ProcessEventLoop(); | 711 ProcessEventLoop(); |
| 716 | 712 |
| 717 std::vector<MediaSink> expected_sinks; | 713 std::vector<MediaSink> expected_sinks; |
| 718 expected_sinks.push_back( | 714 expected_sinks.push_back( |
| 719 MediaSink(kSinkId, kSinkName, MediaSink::IconType::CAST)); | 715 MediaSink(kSinkId, kSinkName, MediaSink::IconType::CAST)); |
| 720 expected_sinks.push_back( | 716 expected_sinks.push_back( |
| 721 MediaSink(kSinkId2, kSinkName, MediaSink::IconType::CAST)); | 717 MediaSink(kSinkId2, kSinkName, MediaSink::IconType::CAST)); |
| 722 | 718 |
| 723 std::vector<mojom::MediaSinkPtr> mojo_sinks(2); | 719 std::vector<mojom::MediaSinkPtr> mojo_sinks(2); |
| 724 mojo_sinks[0] = mojom::MediaSink::New(); | 720 mojo_sinks[0] = mojom::MediaSink::New(); |
| 725 mojo_sinks[0]->sink_id = kSinkId; | 721 mojo_sinks[0]->sink_id = kSinkId; |
| 726 mojo_sinks[0]->name = kSinkName; | 722 mojo_sinks[0]->name = kSinkName; |
| 727 mojo_sinks[0]->icon_type = | 723 mojo_sinks[0]->icon_type = |
| 728 media_router::mojom::MediaSink::IconType::CAST; | 724 media_router::mojom::MediaSink::IconType::CAST; |
| 729 mojo_sinks[1] = mojom::MediaSink::New(); | 725 mojo_sinks[1] = mojom::MediaSink::New(); |
| 730 mojo_sinks[1]->sink_id = kSinkId2; | 726 mojo_sinks[1]->sink_id = kSinkId2; |
| 731 mojo_sinks[1]->name = kSinkName; | 727 mojo_sinks[1]->name = kSinkName; |
| 732 mojo_sinks[1]->icon_type = | 728 mojo_sinks[1]->icon_type = |
| 733 media_router::mojom::MediaSink::IconType::CAST; | 729 media_router::mojom::MediaSink::IconType::CAST; |
| 734 | 730 |
| 735 base::RunLoop run_loop; | 731 base::RunLoop run_loop; |
| 736 EXPECT_CALL(*sinks_observer, OnSinksReceived(SequenceEquals(expected_sinks))); | 732 EXPECT_CALL(*sinks_observer, OnSinksReceived(SequenceEquals(expected_sinks))); |
| 737 EXPECT_CALL(*extra_sinks_observer, | 733 EXPECT_CALL(*extra_sinks_observer, |
| 738 OnSinksReceived(SequenceEquals(expected_sinks))) | 734 OnSinksReceived(SequenceEquals(expected_sinks))) |
| 739 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 735 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 740 media_router_proxy_->OnSinksReceived( | 736 media_router_proxy_->OnSinksReceived(media_source.id(), std::move(mojo_sinks), |
| 741 media_source.id(), std::move(mojo_sinks), | 737 std::vector<url::Origin>(1, kOrigin)); |
| 742 std::vector<std::string>(1, origin.spec())); | |
| 743 run_loop.Run(); | 738 run_loop.Run(); |
| 744 | 739 |
| 745 // Since the MediaRouterMojoImpl has already received results for | 740 // Since the MediaRouterMojoImpl has already received results for |
| 746 // |media_source|, return cached results to observers that are subsequently | 741 // |media_source|, return cached results to observers that are subsequently |
| 747 // registered. | 742 // registered. |
| 748 std::unique_ptr<MockMediaSinksObserver> cached_sinks_observer( | 743 std::unique_ptr<MockMediaSinksObserver> cached_sinks_observer( |
| 749 new MockMediaSinksObserver(router(), media_source, origin)); | 744 new MockMediaSinksObserver(router(), media_source, kOrigin)); |
| 750 EXPECT_CALL(*cached_sinks_observer, | 745 EXPECT_CALL(*cached_sinks_observer, |
| 751 OnSinksReceived(SequenceEquals(expected_sinks))); | 746 OnSinksReceived(SequenceEquals(expected_sinks))); |
| 752 EXPECT_TRUE(cached_sinks_observer->Init()); | 747 EXPECT_TRUE(cached_sinks_observer->Init()); |
| 753 | 748 |
| 754 // Different origin from cached result. Empty list will be returned. | 749 // Different origin from cached result. Empty list will be returned. |
| 755 std::unique_ptr<MockMediaSinksObserver> cached_sinks_observer2( | 750 std::unique_ptr<MockMediaSinksObserver> cached_sinks_observer2( |
| 756 new MockMediaSinksObserver(router(), media_source, | 751 new MockMediaSinksObserver(router(), media_source, |
| 757 GURL("https://youtube.com"))); | 752 url::Origin(GURL("https://youtube.com")))); |
| 758 EXPECT_CALL(*cached_sinks_observer2, OnSinksReceived(IsEmpty())); | 753 EXPECT_CALL(*cached_sinks_observer2, OnSinksReceived(IsEmpty())); |
| 759 EXPECT_TRUE(cached_sinks_observer2->Init()); | 754 EXPECT_TRUE(cached_sinks_observer2->Init()); |
| 760 | 755 |
| 761 base::RunLoop run_loop2; | 756 base::RunLoop run_loop2; |
| 762 EXPECT_CALL(mock_media_route_provider_, StopObservingMediaSinks(kSource)); | 757 EXPECT_CALL(mock_media_route_provider_, StopObservingMediaSinks(kSource)); |
| 763 EXPECT_CALL(mock_media_route_provider_, StopObservingMediaSinks(kSource2)) | 758 EXPECT_CALL(mock_media_route_provider_, StopObservingMediaSinks(kSource2)) |
| 764 .WillOnce(InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); })); | 759 .WillOnce(InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); })); |
| 765 sinks_observer.reset(); | 760 sinks_observer.reset(); |
| 766 extra_sinks_observer.reset(); | 761 extra_sinks_observer.reset(); |
| 767 unrelated_sinks_observer.reset(); | 762 unrelated_sinks_observer.reset(); |
| 768 cached_sinks_observer.reset(); | 763 cached_sinks_observer.reset(); |
| 769 cached_sinks_observer2.reset(); | 764 cached_sinks_observer2.reset(); |
| 770 run_loop2.Run(); | 765 run_loop2.Run(); |
| 771 } | 766 } |
| 772 | 767 |
| 773 TEST_F(MediaRouterMojoImplTest, | 768 TEST_F(MediaRouterMojoImplTest, |
| 774 RegisterMediaSinksObserverWithAvailabilityChange) { | 769 RegisterMediaSinksObserverWithAvailabilityChange) { |
| 775 GURL origin("https://google.com"); | |
| 776 | 770 |
| 777 // When availability is UNAVAILABLE, no calls should be made to MRPM. | 771 // When availability is UNAVAILABLE, no calls should be made to MRPM. |
| 778 router()->OnSinkAvailabilityUpdated( | 772 router()->OnSinkAvailabilityUpdated( |
| 779 mojom::MediaRouter::SinkAvailability::UNAVAILABLE); | 773 mojom::MediaRouter::SinkAvailability::UNAVAILABLE); |
| 780 MediaSource media_source(kSource); | 774 MediaSource media_source(kSource); |
| 781 std::unique_ptr<MockMediaSinksObserver> sinks_observer( | 775 std::unique_ptr<MockMediaSinksObserver> sinks_observer( |
| 782 new MockMediaSinksObserver(router(), media_source, origin)); | 776 new MockMediaSinksObserver(router(), media_source, kOrigin)); |
| 783 EXPECT_CALL(*sinks_observer, OnSinksReceived(IsEmpty())); | 777 EXPECT_CALL(*sinks_observer, OnSinksReceived(IsEmpty())); |
| 784 EXPECT_TRUE(sinks_observer->Init()); | 778 EXPECT_TRUE(sinks_observer->Init()); |
| 785 MediaSource media_source2(kSource2); | 779 MediaSource media_source2(kSource2); |
| 786 std::unique_ptr<MockMediaSinksObserver> sinks_observer2( | 780 std::unique_ptr<MockMediaSinksObserver> sinks_observer2( |
| 787 new MockMediaSinksObserver(router(), media_source2, origin)); | 781 new MockMediaSinksObserver(router(), media_source2, kOrigin)); |
| 788 EXPECT_CALL(*sinks_observer2, OnSinksReceived(IsEmpty())); | 782 EXPECT_CALL(*sinks_observer2, OnSinksReceived(IsEmpty())); |
| 789 EXPECT_TRUE(sinks_observer2->Init()); | 783 EXPECT_TRUE(sinks_observer2->Init()); |
| 790 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource)) | 784 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource)) |
| 791 .Times(0); | 785 .Times(0); |
| 792 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource2)) | 786 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaSinks(kSource2)) |
| 793 .Times(0); | 787 .Times(0); |
| 794 ProcessEventLoop(); | 788 ProcessEventLoop(); |
| 795 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_media_route_provider_)); | 789 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_media_route_provider_)); |
| 796 | 790 |
| 797 // When availability transitions AVAILABLE, existing sink queries should be | 791 // When availability transitions AVAILABLE, existing sink queries should be |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1560 EXPECT_CALL(mock_media_route_provider_, | 1554 EXPECT_CALL(mock_media_route_provider_, |
| 1561 UpdateMediaSinks(MediaSourceForDesktop().id())) | 1555 UpdateMediaSinks(MediaSourceForDesktop().id())) |
| 1562 .WillOnce(InvokeWithoutArgs([&run_loop2]() { | 1556 .WillOnce(InvokeWithoutArgs([&run_loop2]() { |
| 1563 run_loop2.Quit(); | 1557 run_loop2.Quit(); |
| 1564 })); | 1558 })); |
| 1565 | 1559 |
| 1566 run_loop2.Run(); | 1560 run_loop2.Run(); |
| 1567 } | 1561 } |
| 1568 | 1562 |
| 1569 } // namespace media_router | 1563 } // namespace media_router |
| OLD | NEW |