| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
| 19 #include "base/test/histogram_tester.h" | 19 #include "base/test/histogram_tester.h" |
| 20 #include "base/test/mock_callback.h" | 20 #include "base/test/mock_callback.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "chrome/browser/media/router/issue.h" | 22 #include "chrome/browser/media/router/issue.h" |
| 23 #include "chrome/browser/media/router/media_route.h" | 23 #include "chrome/browser/media/router/media_route.h" |
| 24 #include "chrome/browser/media/router/media_source_helper.h" | 24 #include "chrome/browser/media/router/media_source_helper.h" |
| 25 #include "chrome/browser/media/router/mock_media_router.h" | 25 #include "chrome/browser/media/router/mock_media_router.h" |
| 26 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" | 26 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" |
| 27 #include "chrome/browser/media/router/mojo/media_router_mojo_test.h" | 27 #include "chrome/browser/media/router/mojo/media_router_mojo_test.h" |
| 28 #include "chrome/browser/media/router/mojo/media_router_type_converters.h" | |
| 29 #include "chrome/browser/media/router/route_message.h" | 28 #include "chrome/browser/media/router/route_message.h" |
| 30 #include "chrome/browser/media/router/route_message_observer.h" | 29 #include "chrome/browser/media/router/route_message_observer.h" |
| 31 #include "chrome/browser/media/router/test_helper.h" | 30 #include "chrome/browser/media/router/test_helper.h" |
| 32 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 31 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 33 #include "chrome/test/base/testing_browser_process.h" | 32 #include "chrome/test/base/testing_browser_process.h" |
| 34 #include "chrome/test/base/testing_profile.h" | 33 #include "chrome/test/base/testing_profile.h" |
| 35 #include "components/version_info/version_info.h" | 34 #include "components/version_info/version_info.h" |
| 36 #include "content/public/test/test_browser_thread_bundle.h" | 35 #include "content/public/test/test_browser_thread_bundle.h" |
| 37 #include "extensions/browser/extension_registry.h" | 36 #include "extensions/browser/extension_registry.h" |
| 38 #include "extensions/browser/process_manager.h" | 37 #include "extensions/browser/process_manager.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 53 using testing::IsEmpty; | 52 using testing::IsEmpty; |
| 54 using testing::Mock; | 53 using testing::Mock; |
| 55 using testing::Not; | 54 using testing::Not; |
| 56 using testing::Pointee; | 55 using testing::Pointee; |
| 57 using testing::Return; | 56 using testing::Return; |
| 58 using testing::ReturnRef; | 57 using testing::ReturnRef; |
| 59 using testing::SaveArg; | 58 using testing::SaveArg; |
| 60 | 59 |
| 61 namespace media_router { | 60 namespace media_router { |
| 62 | 61 |
| 63 using PresentationConnectionState = | |
| 64 mojom::MediaRouter::PresentationConnectionState; | |
| 65 using PresentationConnectionCloseReason = | |
| 66 mojom::MediaRouter::PresentationConnectionCloseReason; | |
| 67 | |
| 68 namespace { | 62 namespace { |
| 69 | 63 |
| 70 const char kDescription[] = "description"; | 64 const char kDescription[] = "description"; |
| 71 const char kError[] = "error"; | 65 const char kError[] = "error"; |
| 72 const char kMessage[] = "message"; | 66 const char kMessage[] = "message"; |
| 73 const char kSource[] = "source1"; | 67 const char kSource[] = "source1"; |
| 74 const char kSource2[] = "source2"; | 68 const char kSource2[] = "source2"; |
| 75 const char kRouteId[] = "routeId"; | 69 const char kRouteId[] = "routeId"; |
| 76 const char kRouteId2[] = "routeId2"; | 70 const char kRouteId2[] = "routeId2"; |
| 77 const char kJoinableRouteId[] = "joinableRouteId"; | 71 const char kJoinableRouteId[] = "joinableRouteId"; |
| 78 const char kJoinableRouteId2[] = "joinableRouteId2"; | 72 const char kJoinableRouteId2[] = "joinableRouteId2"; |
| 79 const char kSinkId[] = "sink"; | 73 const char kSinkId[] = "sink"; |
| 80 const char kSinkId2[] = "sink2"; | 74 const char kSinkId2[] = "sink2"; |
| 81 const char kSinkName[] = "sinkName"; | 75 const char kSinkName[] = "sinkName"; |
| 82 const char kPresentationId[] = "presentationId"; | 76 const char kPresentationId[] = "presentationId"; |
| 83 const char kOrigin[] = "http://origin/"; | 77 const char kOrigin[] = "http://origin/"; |
| 84 const int kInvalidTabId = -1; | 78 const int kInvalidTabId = -1; |
| 85 const uint8_t kBinaryMessage[] = {0x01, 0x02, 0x03, 0x04}; | 79 const uint8_t kBinaryMessage[] = {0x01, 0x02, 0x03, 0x04}; |
| 86 const int kTimeoutMillis = 5 * 1000; | 80 const int kTimeoutMillis = 5 * 1000; |
| 87 | 81 |
| 88 IssueInfo CreateIssueInfo(const std::string& title) { | 82 IssueInfo CreateIssueInfo(const std::string& title) { |
| 89 IssueInfo issue_info; | 83 IssueInfo issue_info; |
| 90 issue_info.title = title; | 84 issue_info.title = title; |
| 91 issue_info.message = std::string("msg"); | 85 issue_info.message = std::string("msg"); |
| 92 issue_info.default_action = IssueInfo::Action::DISMISS; | 86 issue_info.default_action = IssueInfo::Action::DISMISS; |
| 93 issue_info.severity = IssueInfo::Severity::WARNING; | 87 issue_info.severity = IssueInfo::Severity::WARNING; |
| 94 return issue_info; | 88 return issue_info; |
| 95 } | 89 } |
| 96 | 90 |
| 97 mojom::MediaRoutePtr CreateMojoRoute() { | 91 MediaRoute CreateMediaRoute() { |
| 98 mojom::MediaRoutePtr route = mojom::MediaRoute::New(); | 92 return MediaRoute(kRouteId, MediaSource(kSource), kSinkId, kDescription, true, |
| 99 route->media_source = std::string(kSource); | 93 std::string(), true); |
| 100 route->media_sink_id = kSinkId; | |
| 101 route->media_route_id = kRouteId; | |
| 102 route->description = kDescription; | |
| 103 route->is_local = true; | |
| 104 route->for_display = true; | |
| 105 route->is_incognito = false; | |
| 106 return route; | |
| 107 } | 94 } |
| 108 | 95 |
| 109 } // namespace | 96 } // namespace |
| 110 | 97 |
| 111 class RouteResponseCallbackHandler { | 98 class RouteResponseCallbackHandler { |
| 112 public: | 99 public: |
| 113 void Invoke(const RouteRequestResult& result) { | 100 void Invoke(const RouteRequestResult& result) { |
| 114 DoInvoke(result.route(), result.presentation_id(), result.error(), | 101 DoInvoke(result.route(), result.presentation_id(), result.error(), |
| 115 result.result_code()); | 102 result.result_code()); |
| 116 } | 103 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // a limitation with GMock::Invoke that prevents it from using move-only types | 183 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 197 // in runnable parameter lists. | 184 // in runnable parameter lists. |
| 198 EXPECT_CALL(mock_media_route_provider_, | 185 EXPECT_CALL(mock_media_route_provider_, |
| 199 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), | 186 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), |
| 200 kInvalidTabId, _, _, _)) | 187 kInvalidTabId, _, _, _)) |
| 201 .WillOnce(Invoke( | 188 .WillOnce(Invoke( |
| 202 [](const std::string& source, const std::string& sink, | 189 [](const std::string& source, const std::string& sink, |
| 203 const std::string& presentation_id, const url::Origin& origin, | 190 const std::string& presentation_id, const url::Origin& origin, |
| 204 int tab_id, base::TimeDelta timeout, bool incognito, | 191 int tab_id, base::TimeDelta timeout, bool incognito, |
| 205 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 192 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 206 cb.Run(CreateMojoRoute(), std::string(), | 193 cb.Run(CreateMediaRoute(), std::string(), RouteRequestResult::OK); |
| 207 mojom::RouteRequestResultCode::OK); | |
| 208 })); | 194 })); |
| 209 | 195 |
| 210 base::RunLoop run_loop; | 196 base::RunLoop run_loop; |
| 211 RouteResponseCallbackHandler handler; | 197 RouteResponseCallbackHandler handler; |
| 212 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 198 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 213 RouteRequestResult::OK)) | 199 RouteRequestResult::OK)) |
| 214 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 200 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 215 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 201 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 216 route_response_callbacks.push_back(base::Bind( | 202 route_response_callbacks.push_back(base::Bind( |
| 217 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 203 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 218 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, | 204 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, |
| 219 route_response_callbacks, | 205 route_response_callbacks, |
| 220 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 206 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| 221 false); | 207 false); |
| 222 run_loop.Run(); | 208 run_loop.Run(); |
| 223 ExpectResultBucketCount("CreateRoute", RouteRequestResult::ResultCode::OK, 1); | 209 ExpectResultBucketCount("CreateRoute", RouteRequestResult::OK, 1); |
| 224 } | 210 } |
| 225 | 211 |
| 226 TEST_F(MediaRouterMojoImplTest, CreateIncognitoRoute) { | 212 TEST_F(MediaRouterMojoImplTest, CreateIncognitoRoute) { |
| 227 MediaSource media_source(kSource); | 213 MediaSource media_source(kSource); |
| 228 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", | 214 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", |
| 229 false); | 215 false); |
| 230 expected_route.set_incognito(true); | 216 expected_route.set_incognito(true); |
| 231 | 217 |
| 232 // Use a lambda function as an invocation target here to work around | 218 // Use a lambda function as an invocation target here to work around |
| 233 // a limitation with GMock::Invoke that prevents it from using move-only types | 219 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 234 // in runnable parameter lists. | 220 // in runnable parameter lists. |
| 235 EXPECT_CALL(mock_media_route_provider_, | 221 EXPECT_CALL(mock_media_route_provider_, |
| 236 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), | 222 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), |
| 237 kInvalidTabId, _, _, _)) | 223 kInvalidTabId, _, _, _)) |
| 238 .WillOnce(Invoke( | 224 .WillOnce(Invoke([&expected_route]( |
| 239 [](const std::string& source, const std::string& sink, | 225 const std::string& source, const std::string& sink, |
| 240 const std::string& presentation_id, const url::Origin& origin, | 226 const std::string& presentation_id, const url::Origin& origin, |
| 241 int tab_id, base::TimeDelta timeout, bool incognito, | 227 int tab_id, base::TimeDelta timeout, bool incognito, |
| 242 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 228 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 243 mojom::MediaRoutePtr route = CreateMojoRoute(); | 229 cb.Run(expected_route, std::string(), RouteRequestResult::OK); |
| 244 route->custom_controller_path = | 230 })); |
| 245 std::string("custom/controller/path"); | |
| 246 route->is_incognito = true; | |
| 247 cb.Run(std::move(route), std::string(), | |
| 248 mojom::RouteRequestResultCode::OK); | |
| 249 })); | |
| 250 | 231 |
| 251 base::RunLoop run_loop; | 232 base::RunLoop run_loop; |
| 252 RouteResponseCallbackHandler handler; | 233 RouteResponseCallbackHandler handler; |
| 253 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 234 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 254 RouteRequestResult::OK)) | 235 RouteRequestResult::OK)) |
| 255 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 236 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 256 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 237 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 257 route_response_callbacks.push_back(base::Bind( | 238 route_response_callbacks.push_back(base::Bind( |
| 258 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 239 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 259 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, | 240 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, |
| 260 route_response_callbacks, | 241 route_response_callbacks, |
| 261 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 242 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| 262 true); | 243 true); |
| 263 run_loop.Run(); | 244 run_loop.Run(); |
| 264 ExpectResultBucketCount("CreateRoute", RouteRequestResult::ResultCode::OK, 1); | 245 ExpectResultBucketCount("CreateRoute", RouteRequestResult::OK, 1); |
| 265 } | 246 } |
| 266 | 247 |
| 267 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) { | 248 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) { |
| 268 EXPECT_CALL( | 249 EXPECT_CALL( |
| 269 mock_media_route_provider_, | 250 mock_media_route_provider_, |
| 270 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), | 251 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), |
| 271 kInvalidTabId, | 252 kInvalidTabId, |
| 272 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) | 253 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) |
| 273 .WillOnce(Invoke( | 254 .WillOnce(Invoke( |
| 274 [](const std::string& source, const std::string& sink, | 255 [](const std::string& source, const std::string& sink, |
| 275 const std::string& presentation_id, const url::Origin& origin, | 256 const std::string& presentation_id, const url::Origin& origin, |
| 276 int tab_id, base::TimeDelta timeout, bool incognito, | 257 int tab_id, base::TimeDelta timeout, bool incognito, |
| 277 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 258 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 278 cb.Run(mojom::MediaRoutePtr(), std::string(kError), | 259 cb.Run(base::nullopt, std::string(kError), |
| 279 mojom::RouteRequestResultCode::TIMED_OUT); | 260 RouteRequestResult::TIMED_OUT); |
| 280 })); | 261 })); |
| 281 | 262 |
| 282 RouteResponseCallbackHandler handler; | 263 RouteResponseCallbackHandler handler; |
| 283 base::RunLoop run_loop; | 264 base::RunLoop run_loop; |
| 284 EXPECT_CALL(handler, | 265 EXPECT_CALL(handler, |
| 285 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) | 266 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) |
| 286 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 267 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 287 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 268 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 288 route_response_callbacks.push_back(base::Bind( | 269 route_response_callbacks.push_back(base::Bind( |
| 289 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 270 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 290 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, | 271 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, |
| 291 route_response_callbacks, | 272 route_response_callbacks, |
| 292 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 273 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| 293 false); | 274 false); |
| 294 run_loop.Run(); | 275 run_loop.Run(); |
| 295 ExpectResultBucketCount("CreateRoute", | 276 ExpectResultBucketCount("CreateRoute", RouteRequestResult::TIMED_OUT, 1); |
| 296 RouteRequestResult::ResultCode::TIMED_OUT, 1); | |
| 297 } | 277 } |
| 298 | 278 |
| 299 TEST_F(MediaRouterMojoImplTest, CreateRouteIncognitoMismatchFails) { | 279 TEST_F(MediaRouterMojoImplTest, CreateRouteIncognitoMismatchFails) { |
| 300 EXPECT_CALL( | 280 EXPECT_CALL( |
| 301 mock_media_route_provider_, | 281 mock_media_route_provider_, |
| 302 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), | 282 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), |
| 303 kInvalidTabId, | 283 kInvalidTabId, |
| 304 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) | 284 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) |
| 305 .WillOnce(Invoke( | 285 .WillOnce(Invoke( |
| 306 [](const std::string& source, const std::string& sink, | 286 [](const std::string& source, const std::string& sink, |
| 307 const std::string& presentation_id, const url::Origin& origin, | 287 const std::string& presentation_id, const url::Origin& origin, |
| 308 int tab_id, base::TimeDelta timeout, bool incognito, | 288 int tab_id, base::TimeDelta timeout, bool incognito, |
| 309 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 289 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 310 cb.Run(CreateMojoRoute(), std::string(), | 290 cb.Run(CreateMediaRoute(), std::string(), RouteRequestResult::OK); |
| 311 mojom::RouteRequestResultCode::OK); | |
| 312 })); | 291 })); |
| 313 | 292 |
| 314 RouteResponseCallbackHandler handler; | 293 RouteResponseCallbackHandler handler; |
| 315 base::RunLoop run_loop; | 294 base::RunLoop run_loop; |
| 316 std::string error("Mismatch in incognito status: request = 1, response = 0"); | 295 std::string error("Mismatch in incognito status: request = 1, response = 0"); |
| 317 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, | 296 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, |
| 318 RouteRequestResult::INCOGNITO_MISMATCH)) | 297 RouteRequestResult::INCOGNITO_MISMATCH)) |
| 319 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 298 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 320 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 299 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 321 route_response_callbacks.push_back(base::Bind( | 300 route_response_callbacks.push_back(base::Bind( |
| 322 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 301 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 323 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, | 302 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, |
| 324 route_response_callbacks, | 303 route_response_callbacks, |
| 325 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 304 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| 326 true); | 305 true); |
| 327 run_loop.Run(); | 306 run_loop.Run(); |
| 328 ExpectResultBucketCount( | 307 ExpectResultBucketCount("CreateRoute", RouteRequestResult::INCOGNITO_MISMATCH, |
| 329 "CreateRoute", RouteRequestResult::ResultCode::INCOGNITO_MISMATCH, 1); | 308 1); |
| 330 } | 309 } |
| 331 | 310 |
| 332 TEST_F(MediaRouterMojoImplTest, IncognitoRoutesTerminatedOnProfileShutdown) { | 311 TEST_F(MediaRouterMojoImplTest, IncognitoRoutesTerminatedOnProfileShutdown) { |
| 333 mojom::MediaRoutePtr route = CreateMojoRoute(); | 312 MediaRoute route = CreateMediaRoute(); |
| 334 route->is_incognito = true; | 313 route.set_incognito(true); |
| 335 | 314 |
| 336 EXPECT_CALL( | 315 EXPECT_CALL( |
| 337 mock_media_route_provider_, | 316 mock_media_route_provider_, |
| 338 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), | 317 CreateRoute(kSource, kSinkId, _, url::Origin(GURL(kOrigin)), |
| 339 kInvalidTabId, | 318 kInvalidTabId, |
| 340 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) | 319 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) |
| 341 .WillOnce(Invoke( | 320 .WillOnce(Invoke([&route]( |
| 342 [](const std::string& source, const std::string& sink, | 321 const std::string& source, const std::string& sink, |
| 343 const std::string& presentation_id, const url::Origin& origin, | 322 const std::string& presentation_id, const url::Origin& origin, |
| 344 int tab_id, base::TimeDelta timeout, bool incognito, | 323 int tab_id, base::TimeDelta timeout, bool incognito, |
| 345 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { | 324 const mojom::MediaRouteProvider::CreateRouteCallback& cb) { |
| 346 mojom::MediaRoutePtr route = CreateMojoRoute(); | 325 cb.Run(route, std::string(), RouteRequestResult::OK); |
| 347 route->is_incognito = true; | 326 })); |
| 348 cb.Run(std::move(route), std::string(), | |
| 349 mojom::RouteRequestResultCode::OK); | |
| 350 })); | |
| 351 base::RunLoop run_loop; | 327 base::RunLoop run_loop; |
| 352 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, | 328 router()->CreateRoute(kSource, kSinkId, url::Origin(GURL(kOrigin)), nullptr, |
| 353 std::vector<MediaRouteResponseCallback>(), | 329 std::vector<MediaRouteResponseCallback>(), |
| 354 base::TimeDelta::FromMilliseconds(kTimeoutMillis), | 330 base::TimeDelta::FromMilliseconds(kTimeoutMillis), |
| 355 true); | 331 true); |
| 356 std::vector<mojom::MediaRoutePtr> mojo_routes(1); | 332 std::vector<MediaRoute> routes; |
| 357 mojo_routes[0] = route->Clone(); | 333 routes.push_back(route); |
| 358 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 334 router()->OnRoutesUpdated(routes, std::string(), std::vector<std::string>()); |
| 359 std::vector<std::string>()); | |
| 360 | 335 |
| 361 // TODO(mfoltz): Where possible, convert other tests to use RunUntilIdle | 336 // TODO(mfoltz): Where possible, convert other tests to use RunUntilIdle |
| 362 // instead of manually calling Run/Quit on the run loop. | 337 // instead of manually calling Run/Quit on the run loop. |
| 363 run_loop.RunUntilIdle(); | 338 run_loop.RunUntilIdle(); |
| 364 | 339 |
| 365 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) | 340 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) |
| 366 .WillOnce(Invoke([]( | 341 .WillOnce(Invoke( |
| 367 const std::string& route_id, | 342 [](const std::string& route_id, |
| 368 const mojom::MediaRouteProvider::TerminateRouteCallback& cb) { | 343 const mojom::MediaRouteProvider::TerminateRouteCallback& cb) { |
| 369 cb.Run(base::nullopt, mojom::RouteRequestResultCode::OK); | 344 cb.Run(base::nullopt, RouteRequestResult::OK); |
| 370 })); | 345 })); |
| 371 | 346 |
| 372 base::RunLoop run_loop2; | 347 base::RunLoop run_loop2; |
| 373 router()->OnIncognitoProfileShutdown(); | 348 router()->OnIncognitoProfileShutdown(); |
| 374 run_loop2.RunUntilIdle(); | 349 run_loop2.RunUntilIdle(); |
| 375 } | 350 } |
| 376 | 351 |
| 377 TEST_F(MediaRouterMojoImplTest, JoinRoute) { | 352 TEST_F(MediaRouterMojoImplTest, JoinRoute) { |
| 378 MediaSource media_source(kSource); | 353 MediaSource media_source(kSource); |
| 379 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", | 354 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", |
| 380 false); | 355 false); |
| 381 | 356 |
| 382 mojom::MediaRoutePtr route = CreateMojoRoute(); | 357 MediaRoute route = CreateMediaRoute(); |
| 383 // Make sure the MR has received an update with the route, so it knows there | 358 // Make sure the MR has received an update with the route, so it knows there |
| 384 // is a route to join. | 359 // is a route to join. |
| 385 std::vector<mojom::MediaRoutePtr> mojo_routes(1); | 360 std::vector<MediaRoute> routes; |
| 386 mojo_routes[0] = route->Clone(); | 361 routes.push_back(route); |
| 387 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 362 router()->OnRoutesUpdated(routes, std::string(), std::vector<std::string>()); |
| 388 std::vector<std::string>()); | |
| 389 EXPECT_TRUE(router()->HasJoinableRoute()); | 363 EXPECT_TRUE(router()->HasJoinableRoute()); |
| 390 | 364 |
| 391 // Use a lambda function as an invocation target here to work around | 365 // Use a lambda function as an invocation target here to work around |
| 392 // a limitation with GMock::Invoke that prevents it from using move-only types | 366 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 393 // in runnable parameter lists. | 367 // in runnable parameter lists. |
| 394 EXPECT_CALL( | 368 EXPECT_CALL( |
| 395 mock_media_route_provider_, | 369 mock_media_route_provider_, |
| 396 JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), | 370 JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), |
| 397 kInvalidTabId, | 371 kInvalidTabId, |
| 398 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) | 372 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) |
| 399 .WillOnce(Invoke([&route]( | 373 .WillOnce(Invoke([&route]( |
| 400 const std::string& source, const std::string& presentation_id, | 374 const std::string& source, const std::string& presentation_id, |
| 401 const url::Origin& origin, int tab_id, base::TimeDelta timeout, | 375 const url::Origin& origin, int tab_id, base::TimeDelta timeout, |
| 402 bool incognito, | 376 bool incognito, |
| 403 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 377 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 404 cb.Run(std::move(route), std::string(), | 378 cb.Run(route, std::string(), RouteRequestResult::OK); |
| 405 mojom::RouteRequestResultCode::OK); | |
| 406 })); | 379 })); |
| 407 | 380 |
| 408 RouteResponseCallbackHandler handler; | 381 RouteResponseCallbackHandler handler; |
| 409 base::RunLoop run_loop; | 382 base::RunLoop run_loop; |
| 410 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 383 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 411 RouteRequestResult::OK)) | 384 RouteRequestResult::OK)) |
| 412 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 385 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 413 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 386 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 414 route_response_callbacks.push_back(base::Bind( | 387 route_response_callbacks.push_back(base::Bind( |
| 415 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 388 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 416 router()->JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), | 389 router()->JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), |
| 417 nullptr, route_response_callbacks, | 390 nullptr, route_response_callbacks, |
| 418 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 391 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 419 run_loop.Run(); | 392 run_loop.Run(); |
| 420 ExpectResultBucketCount("JoinRoute", RouteRequestResult::ResultCode::OK, 1); | 393 ExpectResultBucketCount("JoinRoute", RouteRequestResult::OK, 1); |
| 421 } | 394 } |
| 422 | 395 |
| 423 TEST_F(MediaRouterMojoImplTest, JoinRouteNotFoundFails) { | 396 TEST_F(MediaRouterMojoImplTest, JoinRouteNotFoundFails) { |
| 424 RouteResponseCallbackHandler handler; | 397 RouteResponseCallbackHandler handler; |
| 425 base::RunLoop run_loop; | 398 base::RunLoop run_loop; |
| 426 EXPECT_CALL(handler, DoInvoke(nullptr, "", "Route not found", | 399 EXPECT_CALL(handler, DoInvoke(nullptr, "", "Route not found", |
| 427 RouteRequestResult::ROUTE_NOT_FOUND)) | 400 RouteRequestResult::ROUTE_NOT_FOUND)) |
| 428 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 401 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 429 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 402 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 430 route_response_callbacks.push_back(base::Bind( | 403 route_response_callbacks.push_back(base::Bind( |
| 431 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 404 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 432 router()->JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), | 405 router()->JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), |
| 433 nullptr, route_response_callbacks, | 406 nullptr, route_response_callbacks, |
| 434 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 407 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 435 run_loop.Run(); | 408 run_loop.Run(); |
| 436 ExpectResultBucketCount("JoinRoute", | 409 ExpectResultBucketCount("JoinRoute", RouteRequestResult::ROUTE_NOT_FOUND, 1); |
| 437 RouteRequestResult::ResultCode::ROUTE_NOT_FOUND, 1); | |
| 438 } | 410 } |
| 439 | 411 |
| 440 TEST_F(MediaRouterMojoImplTest, JoinRouteTimedOutFails) { | 412 TEST_F(MediaRouterMojoImplTest, JoinRouteTimedOutFails) { |
| 441 // Make sure the MR has received an update with the route, so it knows there | 413 // Make sure the MR has received an update with the route, so it knows there |
| 442 // is a route to join. | 414 // is a route to join. |
| 443 std::vector<mojom::MediaRoutePtr> mojo_routes(1); | 415 std::vector<MediaRoute> routes; |
| 444 mojo_routes[0] = CreateMojoRoute(); | 416 routes.push_back(CreateMediaRoute()); |
| 445 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 417 router()->OnRoutesUpdated(routes, std::string(), std::vector<std::string>()); |
| 446 std::vector<std::string>()); | |
| 447 EXPECT_TRUE(router()->HasJoinableRoute()); | 418 EXPECT_TRUE(router()->HasJoinableRoute()); |
| 448 | 419 |
| 449 EXPECT_CALL( | 420 EXPECT_CALL( |
| 450 mock_media_route_provider_, | 421 mock_media_route_provider_, |
| 451 JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), | 422 JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), |
| 452 kInvalidTabId, | 423 kInvalidTabId, |
| 453 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) | 424 base::TimeDelta::FromMilliseconds(kTimeoutMillis), _, _)) |
| 454 .WillOnce(Invoke( | 425 .WillOnce(Invoke( |
| 455 [](const std::string& source, const std::string& presentation_id, | 426 [](const std::string& source, const std::string& presentation_id, |
| 456 const url::Origin& origin, int tab_id, base::TimeDelta timeout, | 427 const url::Origin& origin, int tab_id, base::TimeDelta timeout, |
| 457 bool incognito, | 428 bool incognito, |
| 458 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 429 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 459 cb.Run(mojom::MediaRoutePtr(), std::string(kError), | 430 cb.Run(base::nullopt, std::string(kError), |
| 460 mojom::RouteRequestResultCode::TIMED_OUT); | 431 RouteRequestResult::TIMED_OUT); |
| 461 })); | 432 })); |
| 462 | 433 |
| 463 RouteResponseCallbackHandler handler; | 434 RouteResponseCallbackHandler handler; |
| 464 base::RunLoop run_loop; | 435 base::RunLoop run_loop; |
| 465 EXPECT_CALL(handler, | 436 EXPECT_CALL(handler, |
| 466 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) | 437 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) |
| 467 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 438 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 468 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 439 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 469 route_response_callbacks.push_back(base::Bind( | 440 route_response_callbacks.push_back(base::Bind( |
| 470 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 441 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 471 router()->JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), | 442 router()->JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), |
| 472 nullptr, route_response_callbacks, | 443 nullptr, route_response_callbacks, |
| 473 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 444 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 474 run_loop.Run(); | 445 run_loop.Run(); |
| 475 ExpectResultBucketCount("JoinRoute", | 446 ExpectResultBucketCount("JoinRoute", RouteRequestResult::TIMED_OUT, 1); |
| 476 RouteRequestResult::ResultCode::TIMED_OUT, 1); | |
| 477 } | 447 } |
| 478 | 448 |
| 479 TEST_F(MediaRouterMojoImplTest, JoinRouteIncognitoMismatchFails) { | 449 TEST_F(MediaRouterMojoImplTest, JoinRouteIncognitoMismatchFails) { |
| 480 mojom::MediaRoutePtr route = CreateMojoRoute(); | 450 MediaRoute route = CreateMediaRoute(); |
| 481 | 451 |
| 482 // Make sure the MR has received an update with the route, so it knows there | 452 // Make sure the MR has received an update with the route, so it knows there |
| 483 // is a route to join. | 453 // is a route to join. |
| 484 std::vector<mojom::MediaRoutePtr> mojo_routes(1); | 454 std::vector<MediaRoute> routes; |
| 485 mojo_routes[0] = route->Clone(); | 455 routes.push_back(route); |
| 486 router()->OnRoutesUpdated(std::move(mojo_routes), std::string(), | 456 router()->OnRoutesUpdated(routes, std::string(), std::vector<std::string>()); |
| 487 std::vector<std::string>()); | |
| 488 EXPECT_TRUE(router()->HasJoinableRoute()); | 457 EXPECT_TRUE(router()->HasJoinableRoute()); |
| 489 | 458 |
| 490 // Use a lambda function as an invocation target here to work around | 459 // Use a lambda function as an invocation target here to work around |
| 491 // a limitation with GMock::Invoke that prevents it from using move-only types | 460 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 492 // in runnable parameter lists. | 461 // in runnable parameter lists. |
| 493 EXPECT_CALL( | 462 EXPECT_CALL( |
| 494 mock_media_route_provider_, | 463 mock_media_route_provider_, |
| 495 JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), | 464 JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), |
| 496 kInvalidTabId, | 465 kInvalidTabId, |
| 497 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) | 466 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) |
| 498 .WillOnce(Invoke([&route]( | 467 .WillOnce(Invoke([&route]( |
| 499 const std::string& source, const std::string& presentation_id, | 468 const std::string& source, const std::string& presentation_id, |
| 500 const url::Origin& origin, int tab_id, base::TimeDelta timeout, | 469 const url::Origin& origin, int tab_id, base::TimeDelta timeout, |
| 501 bool incognito, | 470 bool incognito, |
| 502 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 471 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 503 cb.Run(std::move(route), std::string(), | 472 cb.Run(route, std::string(), RouteRequestResult::OK); |
| 504 mojom::RouteRequestResultCode::OK); | |
| 505 })); | 473 })); |
| 506 | 474 |
| 507 RouteResponseCallbackHandler handler; | 475 RouteResponseCallbackHandler handler; |
| 508 base::RunLoop run_loop; | 476 base::RunLoop run_loop; |
| 509 std::string error("Mismatch in incognito status: request = 1, response = 0"); | 477 std::string error("Mismatch in incognito status: request = 1, response = 0"); |
| 510 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, | 478 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, |
| 511 RouteRequestResult::INCOGNITO_MISMATCH)) | 479 RouteRequestResult::INCOGNITO_MISMATCH)) |
| 512 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 480 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 513 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 481 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 514 route_response_callbacks.push_back(base::Bind( | 482 route_response_callbacks.push_back(base::Bind( |
| 515 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 483 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 516 router()->JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), | 484 router()->JoinRoute(kSource, kPresentationId, url::Origin(GURL(kOrigin)), |
| 517 nullptr, route_response_callbacks, | 485 nullptr, route_response_callbacks, |
| 518 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 486 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 519 run_loop.Run(); | 487 run_loop.Run(); |
| 520 ExpectResultBucketCount( | 488 ExpectResultBucketCount("JoinRoute", RouteRequestResult::INCOGNITO_MISMATCH, |
| 521 "JoinRoute", RouteRequestResult::ResultCode::INCOGNITO_MISMATCH, 1); | 489 1); |
| 522 } | 490 } |
| 523 | 491 |
| 524 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteId) { | 492 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteId) { |
| 525 MediaSource media_source(kSource); | 493 MediaSource media_source(kSource); |
| 526 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", | 494 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", |
| 527 false); | 495 false); |
| 528 expected_route.set_incognito(false); | 496 expected_route.set_incognito(false); |
| 529 mojom::MediaRoutePtr route = CreateMojoRoute(); | 497 MediaRoute route = CreateMediaRoute(); |
| 530 | 498 |
| 531 // Use a lambda function as an invocation target here to work around | 499 // Use a lambda function as an invocation target here to work around |
| 532 // a limitation with GMock::Invoke that prevents it from using move-only types | 500 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 533 // in runnable parameter lists. | 501 // in runnable parameter lists. |
| 534 EXPECT_CALL( | 502 EXPECT_CALL( |
| 535 mock_media_route_provider_, | 503 mock_media_route_provider_, |
| 536 ConnectRouteByRouteId( | 504 ConnectRouteByRouteId( |
| 537 kSource, kRouteId, _, url::Origin(GURL(kOrigin)), kInvalidTabId, | 505 kSource, kRouteId, _, url::Origin(GURL(kOrigin)), kInvalidTabId, |
| 538 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false, _)) | 506 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false, _)) |
| 539 .WillOnce(Invoke([&route]( | 507 .WillOnce(Invoke([&route]( |
| 540 const std::string& source, const std::string& route_id, | 508 const std::string& source, const std::string& route_id, |
| 541 const std::string& presentation_id, const url::Origin& origin, | 509 const std::string& presentation_id, const url::Origin& origin, |
| 542 int tab_id, base::TimeDelta timeout, bool incognito, | 510 int tab_id, base::TimeDelta timeout, bool incognito, |
| 543 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 511 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 544 cb.Run(std::move(route), std::string(), | 512 cb.Run(route, std::string(), RouteRequestResult::OK); |
| 545 mojom::RouteRequestResultCode::OK); | |
| 546 })); | 513 })); |
| 547 | 514 |
| 548 RouteResponseCallbackHandler handler; | 515 RouteResponseCallbackHandler handler; |
| 549 base::RunLoop run_loop; | 516 base::RunLoop run_loop; |
| 550 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", | 517 EXPECT_CALL(handler, DoInvoke(Pointee(Equals(expected_route)), Not(""), "", |
| 551 RouteRequestResult::OK)) | 518 RouteRequestResult::OK)) |
| 552 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 519 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 553 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 520 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 554 route_response_callbacks.push_back(base::Bind( | 521 route_response_callbacks.push_back(base::Bind( |
| 555 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 522 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 556 router()->ConnectRouteByRouteId( | 523 router()->ConnectRouteByRouteId( |
| 557 kSource, kRouteId, url::Origin(GURL(kOrigin)), nullptr, | 524 kSource, kRouteId, url::Origin(GURL(kOrigin)), nullptr, |
| 558 route_response_callbacks, | 525 route_response_callbacks, |
| 559 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); | 526 base::TimeDelta::FromMilliseconds(kTimeoutMillis), false); |
| 560 run_loop.Run(); | 527 run_loop.Run(); |
| 561 ExpectResultBucketCount("JoinRoute", RouteRequestResult::ResultCode::OK, 1); | 528 ExpectResultBucketCount("JoinRoute", RouteRequestResult::OK, 1); |
| 562 } | 529 } |
| 563 | 530 |
| 564 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteIdFails) { | 531 TEST_F(MediaRouterMojoImplTest, ConnectRouteByRouteIdFails) { |
| 565 EXPECT_CALL( | 532 EXPECT_CALL( |
| 566 mock_media_route_provider_, | 533 mock_media_route_provider_, |
| 567 ConnectRouteByRouteId( | 534 ConnectRouteByRouteId( |
| 568 kSource, kRouteId, _, url::Origin(GURL(kOrigin)), kInvalidTabId, | 535 kSource, kRouteId, _, url::Origin(GURL(kOrigin)), kInvalidTabId, |
| 569 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) | 536 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) |
| 570 .WillOnce(Invoke( | 537 .WillOnce(Invoke( |
| 571 [](const std::string& source, const std::string& route_id, | 538 [](const std::string& source, const std::string& route_id, |
| 572 const std::string& presentation_id, const url::Origin& origin, | 539 const std::string& presentation_id, const url::Origin& origin, |
| 573 int tab_id, base::TimeDelta timeout, bool incognito, | 540 int tab_id, base::TimeDelta timeout, bool incognito, |
| 574 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 541 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 575 cb.Run(mojom::MediaRoutePtr(), std::string(kError), | 542 cb.Run(base::nullopt, std::string(kError), |
| 576 mojom::RouteRequestResultCode::TIMED_OUT); | 543 RouteRequestResult::TIMED_OUT); |
| 577 })); | 544 })); |
| 578 | 545 |
| 579 RouteResponseCallbackHandler handler; | 546 RouteResponseCallbackHandler handler; |
| 580 base::RunLoop run_loop; | 547 base::RunLoop run_loop; |
| 581 EXPECT_CALL(handler, | 548 EXPECT_CALL(handler, |
| 582 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) | 549 DoInvoke(nullptr, "", kError, RouteRequestResult::TIMED_OUT)) |
| 583 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 550 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 584 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 551 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 585 route_response_callbacks.push_back(base::Bind( | 552 route_response_callbacks.push_back(base::Bind( |
| 586 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 553 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 587 router()->ConnectRouteByRouteId( | 554 router()->ConnectRouteByRouteId( |
| 588 kSource, kRouteId, url::Origin(GURL(kOrigin)), nullptr, | 555 kSource, kRouteId, url::Origin(GURL(kOrigin)), nullptr, |
| 589 route_response_callbacks, | 556 route_response_callbacks, |
| 590 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 557 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 591 run_loop.Run(); | 558 run_loop.Run(); |
| 592 ExpectResultBucketCount("JoinRoute", | 559 ExpectResultBucketCount("JoinRoute", RouteRequestResult::TIMED_OUT, 1); |
| 593 RouteRequestResult::ResultCode::TIMED_OUT, 1); | |
| 594 } | 560 } |
| 595 | 561 |
| 596 TEST_F(MediaRouterMojoImplTest, ConnectRouteByIdIncognitoMismatchFails) { | 562 TEST_F(MediaRouterMojoImplTest, ConnectRouteByIdIncognitoMismatchFails) { |
| 597 mojom::MediaRoutePtr route = CreateMojoRoute(); | 563 MediaRoute route = CreateMediaRoute(); |
| 598 | 564 |
| 599 // Use a lambda function as an invocation target here to work around | 565 // Use a lambda function as an invocation target here to work around |
| 600 // a limitation with GMock::Invoke that prevents it from using move-only types | 566 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 601 // in runnable parameter lists. | 567 // in runnable parameter lists. |
| 602 EXPECT_CALL( | 568 EXPECT_CALL( |
| 603 mock_media_route_provider_, | 569 mock_media_route_provider_, |
| 604 ConnectRouteByRouteId( | 570 ConnectRouteByRouteId( |
| 605 kSource, kRouteId, _, url::Origin(GURL(kOrigin)), kInvalidTabId, | 571 kSource, kRouteId, _, url::Origin(GURL(kOrigin)), kInvalidTabId, |
| 606 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) | 572 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true, _)) |
| 607 .WillOnce(Invoke([&route]( | 573 .WillOnce(Invoke([&route]( |
| 608 const std::string& source, const std::string& route_id, | 574 const std::string& source, const std::string& route_id, |
| 609 const std::string& presentation_id, const url::Origin& origin, | 575 const std::string& presentation_id, const url::Origin& origin, |
| 610 int tab_id, base::TimeDelta timeout, bool incognito, | 576 int tab_id, base::TimeDelta timeout, bool incognito, |
| 611 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { | 577 const mojom::MediaRouteProvider::JoinRouteCallback& cb) { |
| 612 cb.Run(std::move(route), std::string(), | 578 cb.Run(route, std::string(), RouteRequestResult::OK); |
| 613 mojom::RouteRequestResultCode::OK); | |
| 614 })); | 579 })); |
| 615 | 580 |
| 616 RouteResponseCallbackHandler handler; | 581 RouteResponseCallbackHandler handler; |
| 617 base::RunLoop run_loop; | 582 base::RunLoop run_loop; |
| 618 std::string error("Mismatch in incognito status: request = 1, response = 0"); | 583 std::string error("Mismatch in incognito status: request = 1, response = 0"); |
| 619 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, | 584 EXPECT_CALL(handler, DoInvoke(nullptr, "", error, |
| 620 RouteRequestResult::INCOGNITO_MISMATCH)) | 585 RouteRequestResult::INCOGNITO_MISMATCH)) |
| 621 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 586 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 622 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 587 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 623 route_response_callbacks.push_back(base::Bind( | 588 route_response_callbacks.push_back(base::Bind( |
| 624 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); | 589 &RouteResponseCallbackHandler::Invoke, base::Unretained(&handler))); |
| 625 router()->ConnectRouteByRouteId( | 590 router()->ConnectRouteByRouteId( |
| 626 kSource, kRouteId, url::Origin(GURL(kOrigin)), nullptr, | 591 kSource, kRouteId, url::Origin(GURL(kOrigin)), nullptr, |
| 627 route_response_callbacks, | 592 route_response_callbacks, |
| 628 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); | 593 base::TimeDelta::FromMilliseconds(kTimeoutMillis), true); |
| 629 run_loop.Run(); | 594 run_loop.Run(); |
| 630 ExpectResultBucketCount( | 595 ExpectResultBucketCount("JoinRoute", RouteRequestResult::INCOGNITO_MISMATCH, |
| 631 "JoinRoute", RouteRequestResult::ResultCode::INCOGNITO_MISMATCH, 1); | 596 1); |
| 632 } | 597 } |
| 633 | 598 |
| 634 TEST_F(MediaRouterMojoImplTest, DetachRoute) { | 599 TEST_F(MediaRouterMojoImplTest, DetachRoute) { |
| 635 base::RunLoop run_loop; | 600 base::RunLoop run_loop; |
| 636 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId)) | 601 EXPECT_CALL(mock_media_route_provider_, DetachRoute(kRouteId)) |
| 637 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 602 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 638 router()->DetachRoute(kRouteId); | 603 router()->DetachRoute(kRouteId); |
| 639 run_loop.Run(); | 604 run_loop.Run(); |
| 640 } | 605 } |
| 641 | 606 |
| 642 TEST_F(MediaRouterMojoImplTest, TerminateRoute) { | 607 TEST_F(MediaRouterMojoImplTest, TerminateRoute) { |
| 643 base::RunLoop run_loop; | 608 base::RunLoop run_loop; |
| 644 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) | 609 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) |
| 645 .WillOnce(Invoke([]( | 610 .WillOnce(Invoke( |
| 646 const std::string& route_id, | 611 [](const std::string& route_id, |
| 647 const mojom::MediaRouteProvider::TerminateRouteCallback& cb) { | 612 const mojom::MediaRouteProvider::TerminateRouteCallback& cb) { |
| 648 cb.Run(base::nullopt, mojom::RouteRequestResultCode::OK); | 613 cb.Run(base::nullopt, RouteRequestResult::OK); |
| 649 })); | 614 })); |
| 650 router()->TerminateRoute(kRouteId); | 615 router()->TerminateRoute(kRouteId); |
| 651 run_loop.RunUntilIdle(); | 616 run_loop.RunUntilIdle(); |
| 652 ExpectResultBucketCount("TerminateRoute", | 617 ExpectResultBucketCount("TerminateRoute", RouteRequestResult::OK, 1); |
| 653 RouteRequestResult::ResultCode::OK, | |
| 654 1); | |
| 655 } | 618 } |
| 656 | 619 |
| 657 TEST_F(MediaRouterMojoImplTest, TerminateRouteFails) { | 620 TEST_F(MediaRouterMojoImplTest, TerminateRouteFails) { |
| 658 base::RunLoop run_loop; | 621 base::RunLoop run_loop; |
| 659 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) | 622 EXPECT_CALL(mock_media_route_provider_, TerminateRoute(kRouteId, _)) |
| 660 .WillOnce(Invoke([]( | 623 .WillOnce(Invoke( |
| 661 const std::string& route_id, | 624 [](const std::string& route_id, |
| 662 const mojom::MediaRouteProvider::TerminateRouteCallback& cb) { | 625 const mojom::MediaRouteProvider::TerminateRouteCallback& cb) { |
| 663 cb.Run(std::string("timed out"), | 626 cb.Run(std::string("timed out"), RouteRequestResult::TIMED_OUT); |
| 664 mojom::RouteRequestResultCode::TIMED_OUT); | 627 })); |
| 665 })); | |
| 666 router()->TerminateRoute(kRouteId); | 628 router()->TerminateRoute(kRouteId); |
| 667 run_loop.RunUntilIdle(); | 629 run_loop.RunUntilIdle(); |
| 668 ExpectResultBucketCount("TerminateRoute", | 630 ExpectResultBucketCount("TerminateRoute", RouteRequestResult::OK, 0); |
| 669 RouteRequestResult::ResultCode::OK, | 631 ExpectResultBucketCount("TerminateRoute", RouteRequestResult::TIMED_OUT, 1); |
| 670 0); | |
| 671 ExpectResultBucketCount("TerminateRoute", | |
| 672 RouteRequestResult::ResultCode::TIMED_OUT, | |
| 673 1); | |
| 674 } | 632 } |
| 675 | 633 |
| 676 TEST_F(MediaRouterMojoImplTest, HandleIssue) { | 634 TEST_F(MediaRouterMojoImplTest, HandleIssue) { |
| 677 MockIssuesObserver issue_observer1(router()); | 635 MockIssuesObserver issue_observer1(router()); |
| 678 MockIssuesObserver issue_observer2(router()); | 636 MockIssuesObserver issue_observer2(router()); |
| 679 issue_observer1.Init(); | 637 issue_observer1.Init(); |
| 680 issue_observer2.Init(); | 638 issue_observer2.Init(); |
| 681 | 639 |
| 682 IssueInfo issue_info = CreateIssueInfo("title 1"); | 640 IssueInfo issue_info = CreateIssueInfo("title 1"); |
| 683 | 641 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 url::Origin(GURL(kOrigin)))); | 689 url::Origin(GURL(kOrigin)))); |
| 732 EXPECT_TRUE(unrelated_sinks_observer->Init()); | 690 EXPECT_TRUE(unrelated_sinks_observer->Init()); |
| 733 ProcessEventLoop(); | 691 ProcessEventLoop(); |
| 734 | 692 |
| 735 std::vector<MediaSink> expected_sinks; | 693 std::vector<MediaSink> expected_sinks; |
| 736 expected_sinks.push_back( | 694 expected_sinks.push_back( |
| 737 MediaSink(kSinkId, kSinkName, MediaSink::IconType::CAST)); | 695 MediaSink(kSinkId, kSinkName, MediaSink::IconType::CAST)); |
| 738 expected_sinks.push_back( | 696 expected_sinks.push_back( |
| 739 MediaSink(kSinkId2, kSinkName, MediaSink::IconType::CAST)); | 697 MediaSink(kSinkId2, kSinkName, MediaSink::IconType::CAST)); |
| 740 | 698 |
| 741 std::vector<mojom::MediaSinkPtr> mojo_sinks(2); | |
| 742 mojo_sinks[0] = mojom::MediaSink::New(); | |
| 743 mojo_sinks[0]->sink_id = kSinkId; | |
| 744 mojo_sinks[0]->name = kSinkName; | |
| 745 mojo_sinks[0]->icon_type = | |
| 746 media_router::mojom::MediaSink::IconType::CAST; | |
| 747 mojo_sinks[1] = mojom::MediaSink::New(); | |
| 748 mojo_sinks[1]->sink_id = kSinkId2; | |
| 749 mojo_sinks[1]->name = kSinkName; | |
| 750 mojo_sinks[1]->icon_type = | |
| 751 media_router::mojom::MediaSink::IconType::CAST; | |
| 752 | |
| 753 base::RunLoop run_loop; | 699 base::RunLoop run_loop; |
| 754 EXPECT_CALL(*sinks_observer, OnSinksReceived(SequenceEquals(expected_sinks))); | 700 EXPECT_CALL(*sinks_observer, OnSinksReceived(SequenceEquals(expected_sinks))); |
| 755 EXPECT_CALL(*extra_sinks_observer, | 701 EXPECT_CALL(*extra_sinks_observer, |
| 756 OnSinksReceived(SequenceEquals(expected_sinks))) | 702 OnSinksReceived(SequenceEquals(expected_sinks))) |
| 757 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 703 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 758 media_router_proxy_->OnSinksReceived( | 704 media_router_proxy_->OnSinksReceived( |
| 759 media_source.id(), std::move(mojo_sinks), | 705 media_source.id(), expected_sinks, |
| 760 std::vector<url::Origin>(1, url::Origin(GURL(kOrigin)))); | 706 std::vector<url::Origin>(1, url::Origin(GURL(kOrigin)))); |
| 761 run_loop.Run(); | 707 run_loop.Run(); |
| 762 | 708 |
| 763 // Since the MediaRouterMojoImpl has already received results for | 709 // Since the MediaRouterMojoImpl has already received results for |
| 764 // |media_source|, return cached results to observers that are subsequently | 710 // |media_source|, return cached results to observers that are subsequently |
| 765 // registered. | 711 // registered. |
| 766 std::unique_ptr<MockMediaSinksObserver> cached_sinks_observer( | 712 std::unique_ptr<MockMediaSinksObserver> cached_sinks_observer( |
| 767 new MockMediaSinksObserver(router(), media_source, | 713 new MockMediaSinksObserver(router(), media_source, |
| 768 url::Origin(GURL(kOrigin)))); | 714 url::Origin(GURL(kOrigin)))); |
| 769 EXPECT_CALL(*cached_sinks_observer, | 715 EXPECT_CALL(*cached_sinks_observer, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 expected_routes.push_back(MediaRoute(kRouteId, media_source, kSinkId, | 832 expected_routes.push_back(MediaRoute(kRouteId, media_source, kSinkId, |
| 887 kDescription, false, "", false)); | 833 kDescription, false, "", false)); |
| 888 MediaRoute incognito_expected_route(kRouteId2, media_source, kSinkId, | 834 MediaRoute incognito_expected_route(kRouteId2, media_source, kSinkId, |
| 889 kDescription, false, "", false); | 835 kDescription, false, "", false); |
| 890 incognito_expected_route.set_incognito(true); | 836 incognito_expected_route.set_incognito(true); |
| 891 expected_routes.push_back(incognito_expected_route); | 837 expected_routes.push_back(incognito_expected_route); |
| 892 std::vector<MediaRoute::Id> expected_joinable_route_ids; | 838 std::vector<MediaRoute::Id> expected_joinable_route_ids; |
| 893 expected_joinable_route_ids.push_back(kJoinableRouteId); | 839 expected_joinable_route_ids.push_back(kJoinableRouteId); |
| 894 expected_joinable_route_ids.push_back(kJoinableRouteId2); | 840 expected_joinable_route_ids.push_back(kJoinableRouteId2); |
| 895 | 841 |
| 896 std::vector<std::string> mojo_joinable_routes(2); | |
| 897 mojo_joinable_routes[0] = kJoinableRouteId; | |
| 898 mojo_joinable_routes[1] = kJoinableRouteId2; | |
| 899 | |
| 900 std::vector<mojom::MediaRoutePtr> mojo_routes(2); | |
| 901 mojo_routes[0] = CreateMojoRoute(); | |
| 902 mojo_routes[1] = CreateMojoRoute(); | |
| 903 mojo_routes[1]->media_route_id = kRouteId2; | |
| 904 mojo_routes[1]->is_incognito = true; | |
| 905 | |
| 906 EXPECT_CALL(routes_observer, OnRoutesUpdated(SequenceEquals(expected_routes), | 842 EXPECT_CALL(routes_observer, OnRoutesUpdated(SequenceEquals(expected_routes), |
| 907 expected_joinable_route_ids)); | 843 expected_joinable_route_ids)); |
| 908 EXPECT_CALL(extra_routes_observer, | 844 EXPECT_CALL(extra_routes_observer, |
| 909 OnRoutesUpdated(SequenceEquals(expected_routes), | 845 OnRoutesUpdated(SequenceEquals(expected_routes), |
| 910 expected_joinable_route_ids)); | 846 expected_joinable_route_ids)); |
| 911 EXPECT_CALL(different_routes_observer, | 847 EXPECT_CALL(different_routes_observer, |
| 912 OnRoutesUpdated(SequenceEquals(expected_routes), | 848 OnRoutesUpdated(SequenceEquals(expected_routes), |
| 913 expected_joinable_route_ids)) | 849 expected_joinable_route_ids)) |
| 914 .Times(0); | 850 .Times(0); |
| 915 media_router_proxy_->OnRoutesUpdated(std::move(mojo_routes), | 851 media_router_proxy_->OnRoutesUpdated(expected_routes, media_source.id(), |
| 916 media_source.id(), | 852 expected_joinable_route_ids); |
| 917 std::move(mojo_joinable_routes)); | |
| 918 ProcessEventLoop(); | 853 ProcessEventLoop(); |
| 919 | 854 |
| 920 EXPECT_CALL(mock_router, UnregisterMediaRoutesObserver(&routes_observer)); | 855 EXPECT_CALL(mock_router, UnregisterMediaRoutesObserver(&routes_observer)); |
| 921 EXPECT_CALL(mock_router, | 856 EXPECT_CALL(mock_router, |
| 922 UnregisterMediaRoutesObserver(&extra_routes_observer)); | 857 UnregisterMediaRoutesObserver(&extra_routes_observer)); |
| 923 EXPECT_CALL(mock_router, | 858 EXPECT_CALL(mock_router, |
| 924 UnregisterMediaRoutesObserver(&different_routes_observer)); | 859 UnregisterMediaRoutesObserver(&different_routes_observer)); |
| 925 router()->UnregisterMediaRoutesObserver(&routes_observer); | 860 router()->UnregisterMediaRoutesObserver(&routes_observer); |
| 926 router()->UnregisterMediaRoutesObserver(&extra_routes_observer); | 861 router()->UnregisterMediaRoutesObserver(&extra_routes_observer); |
| 927 router()->UnregisterMediaRoutesObserver(&different_routes_observer); | 862 router()->UnregisterMediaRoutesObserver(&different_routes_observer); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 base::RunLoop run_loop; | 1046 base::RunLoop run_loop; |
| 1112 content::PresentationConnectionStateChangeInfo closed_info( | 1047 content::PresentationConnectionStateChangeInfo closed_info( |
| 1113 content::PRESENTATION_CONNECTION_STATE_CLOSED); | 1048 content::PRESENTATION_CONNECTION_STATE_CLOSED); |
| 1114 closed_info.close_reason = | 1049 closed_info.close_reason = |
| 1115 content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; | 1050 content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; |
| 1116 closed_info.message = "Foo"; | 1051 closed_info.message = "Foo"; |
| 1117 | 1052 |
| 1118 EXPECT_CALL(callback, Run(StateChangeInfoEquals(closed_info))) | 1053 EXPECT_CALL(callback, Run(StateChangeInfoEquals(closed_info))) |
| 1119 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 1054 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 1120 media_router_proxy_->OnPresentationConnectionClosed( | 1055 media_router_proxy_->OnPresentationConnectionClosed( |
| 1121 route_id, PresentationConnectionCloseReason::WENT_AWAY, "Foo"); | 1056 route_id, content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY, |
| 1057 "Foo"); |
| 1122 run_loop.Run(); | 1058 run_loop.Run(); |
| 1123 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&callback)); | 1059 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&callback)); |
| 1124 } | 1060 } |
| 1125 | 1061 |
| 1126 content::PresentationConnectionStateChangeInfo terminated_info( | 1062 content::PresentationConnectionStateChangeInfo terminated_info( |
| 1127 content::PRESENTATION_CONNECTION_STATE_TERMINATED); | 1063 content::PRESENTATION_CONNECTION_STATE_TERMINATED); |
| 1128 { | 1064 { |
| 1129 base::RunLoop run_loop; | 1065 base::RunLoop run_loop; |
| 1130 EXPECT_CALL(callback, Run(StateChangeInfoEquals(terminated_info))) | 1066 EXPECT_CALL(callback, Run(StateChangeInfoEquals(terminated_info))) |
| 1131 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 1067 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 1132 media_router_proxy_->OnPresentationConnectionStateChanged( | 1068 media_router_proxy_->OnPresentationConnectionStateChanged( |
| 1133 route_id, PresentationConnectionState::TERMINATED); | 1069 route_id, content::PRESENTATION_CONNECTION_STATE_TERMINATED); |
| 1134 run_loop.Run(); | 1070 run_loop.Run(); |
| 1135 | 1071 |
| 1136 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&callback)); | 1072 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&callback)); |
| 1137 } | 1073 } |
| 1138 } | 1074 } |
| 1139 | 1075 |
| 1140 TEST_F(MediaRouterMojoImplTest, | 1076 TEST_F(MediaRouterMojoImplTest, |
| 1141 PresentationConnectionStateChangedCallbackRemoved) { | 1077 PresentationConnectionStateChangedCallbackRemoved) { |
| 1142 MediaRoute::Id route_id("route-id"); | 1078 MediaRoute::Id route_id("route-id"); |
| 1143 base::MockCallback<content::PresentationConnectionStateChangedCallback> | 1079 base::MockCallback<content::PresentationConnectionStateChangedCallback> |
| 1144 callback; | 1080 callback; |
| 1145 std::unique_ptr<PresentationConnectionStateSubscription> subscription = | 1081 std::unique_ptr<PresentationConnectionStateSubscription> subscription = |
| 1146 router()->AddPresentationConnectionStateChangedCallback(route_id, | 1082 router()->AddPresentationConnectionStateChangedCallback(route_id, |
| 1147 callback.Get()); | 1083 callback.Get()); |
| 1148 | 1084 |
| 1149 // Callback has been removed, so we don't expect it to be called anymore. | 1085 // Callback has been removed, so we don't expect it to be called anymore. |
| 1150 subscription.reset(); | 1086 subscription.reset(); |
| 1151 EXPECT_TRUE(router()->presentation_connection_state_callbacks_.empty()); | 1087 EXPECT_TRUE(router()->presentation_connection_state_callbacks_.empty()); |
| 1152 | 1088 |
| 1153 EXPECT_CALL(callback, Run(_)).Times(0); | 1089 EXPECT_CALL(callback, Run(_)).Times(0); |
| 1154 media_router_proxy_->OnPresentationConnectionStateChanged( | 1090 media_router_proxy_->OnPresentationConnectionStateChanged( |
| 1155 route_id, PresentationConnectionState::TERMINATED); | 1091 route_id, content::PRESENTATION_CONNECTION_STATE_TERMINATED); |
| 1156 ProcessEventLoop(); | 1092 ProcessEventLoop(); |
| 1157 } | 1093 } |
| 1158 | 1094 |
| 1159 TEST_F(MediaRouterMojoImplTest, QueuedWhileAsleep) { | 1095 TEST_F(MediaRouterMojoImplTest, QueuedWhileAsleep) { |
| 1160 base::RunLoop run_loop; | 1096 base::RunLoop run_loop; |
| 1161 EXPECT_CALL(mock_event_page_tracker_, IsEventPageSuspended(extension_id())) | 1097 EXPECT_CALL(mock_event_page_tracker_, IsEventPageSuspended(extension_id())) |
| 1162 .Times(2) | 1098 .Times(2) |
| 1163 .WillRepeatedly(Return(true)); | 1099 .WillRepeatedly(Return(true)); |
| 1164 EXPECT_CALL(mock_event_page_tracker_, WakeEventPage(extension_id(), _)) | 1100 EXPECT_CALL(mock_event_page_tracker_, WakeEventPage(extension_id(), _)) |
| 1165 .Times(2) | 1101 .Times(2) |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1578 EXPECT_CALL(mock_media_route_provider_, | 1514 EXPECT_CALL(mock_media_route_provider_, |
| 1579 UpdateMediaSinks(MediaSourceForDesktop().id())) | 1515 UpdateMediaSinks(MediaSourceForDesktop().id())) |
| 1580 .WillOnce(InvokeWithoutArgs([&run_loop2]() { | 1516 .WillOnce(InvokeWithoutArgs([&run_loop2]() { |
| 1581 run_loop2.Quit(); | 1517 run_loop2.Quit(); |
| 1582 })); | 1518 })); |
| 1583 | 1519 |
| 1584 run_loop2.Run(); | 1520 run_loop2.Run(); |
| 1585 } | 1521 } |
| 1586 | 1522 |
| 1587 } // namespace media_router | 1523 } // namespace media_router |
| OLD | NEW |