| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 template <typename T> | 171 template <typename T> |
| 172 void StoreAndRun(T* result, const base::Closure& closure, const T& result_val) { | 172 void StoreAndRun(T* result, const base::Closure& closure, const T& result_val) { |
| 173 *result = result_val; | 173 *result = result_val; |
| 174 closure.Run(); | 174 closure.Run(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 class MediaRouterMojoImplTest : public MediaRouterMojoTest { | 177 class MediaRouterMojoImplTest : public MediaRouterMojoTest { |
| 178 public: | 178 public: |
| 179 MediaRouterMojoImplTest() {} | 179 MediaRouterMojoImplTest() {} |
| 180 ~MediaRouterMojoImplTest() override {} | 180 ~MediaRouterMojoImplTest() override {} |
| 181 |
| 182 void ExpectResultBucketCount(const std::string& operation, |
| 183 RouteRequestResult::ResultCode result_code, |
| 184 int expected_count) { |
| 185 histogram_tester_.ExpectBucketCount( |
| 186 "MediaRouter.Provider." + operation + ".Result", |
| 187 result_code, |
| 188 expected_count); |
| 189 } |
| 190 |
| 191 private: |
| 192 base::HistogramTester histogram_tester_; |
| 181 }; | 193 }; |
| 182 | 194 |
| 183 // ProcessManager with a mocked method subset, for testing extension suspend | 195 // ProcessManager with a mocked method subset, for testing extension suspend |
| 184 // handling. | 196 // handling. |
| 185 class TestProcessManager : public extensions::ProcessManager { | 197 class TestProcessManager : public extensions::ProcessManager { |
| 186 public: | 198 public: |
| 187 explicit TestProcessManager(content::BrowserContext* context) | 199 explicit TestProcessManager(content::BrowserContext* context) |
| 188 : extensions::ProcessManager( | 200 : extensions::ProcessManager( |
| 189 context, | 201 context, |
| 190 context, | 202 context, |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 mojo::Array<interfaces::MediaRoutePtr> mojo_routes(1); | 380 mojo::Array<interfaces::MediaRoutePtr> mojo_routes(1); |
| 369 mojo_routes[0] = route->Clone(); | 381 mojo_routes[0] = route->Clone(); |
| 370 router()->OnRoutesUpdated(std::move(mojo_routes), mojo::String(), | 382 router()->OnRoutesUpdated(std::move(mojo_routes), mojo::String(), |
| 371 mojo::Array<mojo::String>()); | 383 mojo::Array<mojo::String>()); |
| 372 | 384 |
| 373 // TODO(mfoltz): Where possible, convert other tests to use RunUntilIdle | 385 // TODO(mfoltz): Where possible, convert other tests to use RunUntilIdle |
| 374 // instead of manually calling Run/Quit on the run loop. | 386 // instead of manually calling Run/Quit on the run loop. |
| 375 run_loop.RunUntilIdle(); | 387 run_loop.RunUntilIdle(); |
| 376 | 388 |
| 377 EXPECT_CALL(mock_media_route_provider_, | 389 EXPECT_CALL(mock_media_route_provider_, |
| 378 TerminateRoute(mojo::String(kRouteId))); | 390 TerminateRoute(mojo::String(kRouteId), _)) |
| 391 .WillOnce(Invoke([]( |
| 392 const mojo::String& route_id, |
| 393 const interfaces::MediaRouteProvider::TerminateRouteCallback& cb) { |
| 394 cb.Run(mojo::String(), interfaces::RouteRequestResultCode::OK); |
| 395 })); |
| 396 |
| 379 base::RunLoop run_loop2; | 397 base::RunLoop run_loop2; |
| 380 router()->OnOffTheRecordProfileShutdown(); | 398 router()->OnOffTheRecordProfileShutdown(); |
| 381 run_loop2.RunUntilIdle(); | 399 run_loop2.RunUntilIdle(); |
| 382 } | 400 } |
| 383 | 401 |
| 384 TEST_F(MediaRouterMojoImplTest, JoinRoute) { | 402 TEST_F(MediaRouterMojoImplTest, JoinRoute) { |
| 385 MediaSource media_source(kSource); | 403 MediaSource media_source(kSource); |
| 386 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", | 404 MediaRoute expected_route(kRouteId, media_source, kSinkId, "", false, "", |
| 387 false); | 405 false); |
| 388 | 406 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 base::RunLoop run_loop; | 644 base::RunLoop run_loop; |
| 627 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))) | 645 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))) |
| 628 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 646 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
| 629 router()->DetachRoute(kRouteId); | 647 router()->DetachRoute(kRouteId); |
| 630 run_loop.Run(); | 648 run_loop.Run(); |
| 631 } | 649 } |
| 632 | 650 |
| 633 TEST_F(MediaRouterMojoImplTest, TerminateRoute) { | 651 TEST_F(MediaRouterMojoImplTest, TerminateRoute) { |
| 634 base::RunLoop run_loop; | 652 base::RunLoop run_loop; |
| 635 EXPECT_CALL(mock_media_route_provider_, | 653 EXPECT_CALL(mock_media_route_provider_, |
| 636 TerminateRoute(mojo::String(kRouteId))) | 654 TerminateRoute(mojo::String(kRouteId), _)) |
| 637 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 655 .WillOnce(Invoke([&run_loop]( |
| 656 const mojo::String& route_id, |
| 657 const interfaces::MediaRouteProvider::TerminateRouteCallback& cb) { |
| 658 cb.Run(mojo::String(), interfaces::RouteRequestResultCode::OK); |
| 659 })); |
| 638 router()->TerminateRoute(kRouteId); | 660 router()->TerminateRoute(kRouteId); |
| 639 run_loop.Run(); | 661 run_loop.RunUntilIdle(); |
| 662 ExpectResultBucketCount("TerminateRoute", |
| 663 RouteRequestResult::ResultCode::OK, |
| 664 1); |
| 665 } |
| 666 |
| 667 TEST_F(MediaRouterMojoImplTest, TerminateRouteFails) { |
| 668 base::RunLoop run_loop; |
| 669 EXPECT_CALL(mock_media_route_provider_, |
| 670 TerminateRoute(mojo::String(kRouteId), _)) |
| 671 .WillOnce(Invoke([&run_loop]( |
| 672 const mojo::String& route_id, |
| 673 const interfaces::MediaRouteProvider::TerminateRouteCallback& cb) { |
| 674 cb.Run(mojo::String(), interfaces::RouteRequestResultCode::TIMED_OUT); |
| 675 })); |
| 676 router()->TerminateRoute(kRouteId); |
| 677 run_loop.RunUntilIdle(); |
| 678 ExpectResultBucketCount("TerminateRoute", |
| 679 RouteRequestResult::ResultCode::OK, |
| 680 0); |
| 681 ExpectResultBucketCount("TerminateRoute", |
| 682 RouteRequestResult::ResultCode::TIMED_OUT, |
| 683 1); |
| 640 } | 684 } |
| 641 | 685 |
| 642 TEST_F(MediaRouterMojoImplTest, HandleIssue) { | 686 TEST_F(MediaRouterMojoImplTest, HandleIssue) { |
| 643 MockIssuesObserver issue_observer1(router()); | 687 MockIssuesObserver issue_observer1(router()); |
| 644 MockIssuesObserver issue_observer2(router()); | 688 MockIssuesObserver issue_observer2(router()); |
| 645 issue_observer1.RegisterObserver(); | 689 issue_observer1.RegisterObserver(); |
| 646 issue_observer2.RegisterObserver(); | 690 issue_observer2.RegisterObserver(); |
| 647 | 691 |
| 648 interfaces::IssuePtr mojo_issue1 = CreateMojoIssue("title 1"); | 692 interfaces::IssuePtr mojo_issue1 = CreateMojoIssue("title 1"); |
| 649 const Issue& expected_issue1 = mojo_issue1.To<Issue>(); | 693 const Issue& expected_issue1 = mojo_issue1.To<Issue>(); |
| (...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1558 EXPECT_CALL(mock_media_route_provider_, | 1602 EXPECT_CALL(mock_media_route_provider_, |
| 1559 UpdateMediaSinks(mojo::String(MediaSourceForDesktop().id()))) | 1603 UpdateMediaSinks(mojo::String(MediaSourceForDesktop().id()))) |
| 1560 .WillOnce(InvokeWithoutArgs([&run_loop2]() { | 1604 .WillOnce(InvokeWithoutArgs([&run_loop2]() { |
| 1561 run_loop2.Quit(); | 1605 run_loop2.Quit(); |
| 1562 })); | 1606 })); |
| 1563 | 1607 |
| 1564 run_loop2.Run(); | 1608 run_loop2.Run(); |
| 1565 } | 1609 } |
| 1566 | 1610 |
| 1567 } // namespace media_router | 1611 } // namespace media_router |
| OLD | NEW |