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