| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 char kOrigin[] = "http://origin/"; |
| 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 mojom::IssuePtr CreateMojoIssue(const std::string& title) { | 87 IssueInfo CreateIssueInfo(const std::string& title) { |
| 88 mojom::IssuePtr mojoIssue = mojom::Issue::New(); | 88 IssueInfo issue_info; |
| 89 mojoIssue->title = title; | 89 issue_info.title = title; |
| 90 mojoIssue->message = std::string("msg"); | 90 issue_info.message = std::string("msg"); |
| 91 mojoIssue->route_id = std::string(); | 91 issue_info.default_action = IssueInfo::Action::DISMISS; |
| 92 mojoIssue->default_action = mojom::Issue::ActionType::DISMISS; | 92 issue_info.severity = IssueInfo::Severity::WARNING; |
| 93 mojoIssue->secondary_actions = std::vector<mojom::Issue::ActionType>(); | 93 return issue_info; |
| 94 mojoIssue->severity = mojom::Issue::Severity::WARNING; | |
| 95 mojoIssue->is_blocking = false; | |
| 96 mojoIssue->help_page_id = -1; | |
| 97 return mojoIssue; | |
| 98 } | 94 } |
| 99 | 95 |
| 100 mojom::MediaRoutePtr CreateMojoRoute() { | 96 mojom::MediaRoutePtr CreateMojoRoute() { |
| 101 mojom::MediaRoutePtr route = mojom::MediaRoute::New(); | 97 mojom::MediaRoutePtr route = mojom::MediaRoute::New(); |
| 102 route->media_source = std::string(kSource); | 98 route->media_source = std::string(kSource); |
| 103 route->media_sink_id = kSinkId; | 99 route->media_sink_id = kSinkId; |
| 104 route->media_route_id = kRouteId; | 100 route->media_route_id = kRouteId; |
| 105 route->description = kDescription; | 101 route->description = kDescription; |
| 106 route->is_local = true; | 102 route->is_local = true; |
| 107 route->for_display = true; | 103 route->for_display = true; |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 RouteRequestResult::ResultCode::OK, | 653 RouteRequestResult::ResultCode::OK, |
| 658 0); | 654 0); |
| 659 ExpectResultBucketCount("TerminateRoute", | 655 ExpectResultBucketCount("TerminateRoute", |
| 660 RouteRequestResult::ResultCode::TIMED_OUT, | 656 RouteRequestResult::ResultCode::TIMED_OUT, |
| 661 1); | 657 1); |
| 662 } | 658 } |
| 663 | 659 |
| 664 TEST_F(MediaRouterMojoImplTest, HandleIssue) { | 660 TEST_F(MediaRouterMojoImplTest, HandleIssue) { |
| 665 MockIssuesObserver issue_observer1(router()); | 661 MockIssuesObserver issue_observer1(router()); |
| 666 MockIssuesObserver issue_observer2(router()); | 662 MockIssuesObserver issue_observer2(router()); |
| 667 issue_observer1.RegisterObserver(); | 663 issue_observer1.Init(); |
| 668 issue_observer2.RegisterObserver(); | 664 issue_observer2.Init(); |
| 669 | 665 |
| 670 mojom::IssuePtr mojo_issue1 = CreateMojoIssue("title 1"); | 666 IssueInfo issue_info = CreateIssueInfo("title 1"); |
| 671 const Issue& expected_issue1 = mojo_issue1.To<Issue>(); | |
| 672 | 667 |
| 673 const Issue* issue; | 668 Issue issue_from_observer1((IssueInfo())); |
| 674 EXPECT_CALL(issue_observer1, | 669 Issue issue_from_observer2((IssueInfo())); |
| 675 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1)))) | 670 EXPECT_CALL(issue_observer1, OnIssue(_)) |
| 676 .WillOnce(SaveArg<0>(&issue)); | 671 .WillOnce(SaveArg<0>(&issue_from_observer1)); |
| 672 EXPECT_CALL(issue_observer2, OnIssue(_)) |
| 673 .WillOnce(SaveArg<0>(&issue_from_observer2)); |
| 674 |
| 677 base::RunLoop run_loop; | 675 base::RunLoop run_loop; |
| 678 EXPECT_CALL(issue_observer2, | 676 media_router_proxy_->OnIssue(issue_info); |
| 679 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1)))) | 677 run_loop.RunUntilIdle(); |
| 680 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 678 |
| 681 media_router_proxy_->OnIssue(std::move(mojo_issue1)); | 679 ASSERT_EQ(issue_from_observer1.id(), issue_from_observer2.id()); |
| 682 run_loop.Run(); | 680 EXPECT_EQ(issue_info, issue_from_observer1.info()); |
| 681 EXPECT_EQ(issue_info, issue_from_observer2.info()); |
| 683 | 682 |
| 684 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); | 683 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); |
| 685 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); | 684 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); |
| 686 | 685 |
| 687 EXPECT_CALL(issue_observer1, OnIssueUpdated(nullptr)); | 686 EXPECT_CALL(issue_observer1, OnIssuesCleared()); |
| 688 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr)); | 687 EXPECT_CALL(issue_observer2, OnIssuesCleared()); |
| 689 | 688 |
| 690 router()->ClearIssue(issue->id()); | 689 router()->ClearIssue(issue_from_observer1.id()); |
| 691 | 690 |
| 692 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); | 691 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); |
| 693 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); | 692 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); |
| 694 router()->UnregisterIssuesObserver(&issue_observer1); | |
| 695 mojom::IssuePtr mojo_issue2 = CreateMojoIssue("title 2"); | |
| 696 const Issue& expected_issue2 = mojo_issue2.To<Issue>(); | |
| 697 | |
| 698 EXPECT_CALL(issue_observer2, | |
| 699 OnIssueUpdated(Pointee(EqualsIssue(expected_issue2)))); | |
| 700 router()->AddIssue(expected_issue2); | |
| 701 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); | |
| 702 | |
| 703 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr)); | |
| 704 router()->ClearIssue(issue->id()); | |
| 705 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); | |
| 706 | |
| 707 base::RunLoop run_loop2; | |
| 708 EXPECT_CALL(issue_observer2, | |
| 709 OnIssueUpdated(Pointee(EqualsIssue(expected_issue2)))) | |
| 710 .WillOnce(InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); })); | |
| 711 media_router_proxy_->OnIssue(std::move(mojo_issue2)); | |
| 712 run_loop2.Run(); | |
| 713 | |
| 714 issue_observer1.UnregisterObserver(); | |
| 715 issue_observer2.UnregisterObserver(); | |
| 716 } | 693 } |
| 717 | 694 |
| 718 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) { | 695 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) { |
| 719 router()->OnSinkAvailabilityUpdated( | 696 router()->OnSinkAvailabilityUpdated( |
| 720 mojom::MediaRouter::SinkAvailability::AVAILABLE); | 697 mojom::MediaRouter::SinkAvailability::AVAILABLE); |
| 721 MediaSource media_source(kSource); | 698 MediaSource media_source(kSource); |
| 722 GURL origin("https://google.com"); | 699 GURL origin("https://google.com"); |
| 723 | 700 |
| 724 // These should only be called once even if there is more than one observer | 701 // These should only be called once even if there is more than one observer |
| 725 // for a given source. | 702 // for a given source. |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 EXPECT_CALL(mock_media_route_provider_, | 1560 EXPECT_CALL(mock_media_route_provider_, |
| 1584 UpdateMediaSinks(MediaSourceForDesktop().id())) | 1561 UpdateMediaSinks(MediaSourceForDesktop().id())) |
| 1585 .WillOnce(InvokeWithoutArgs([&run_loop2]() { | 1562 .WillOnce(InvokeWithoutArgs([&run_loop2]() { |
| 1586 run_loop2.Quit(); | 1563 run_loop2.Quit(); |
| 1587 })); | 1564 })); |
| 1588 | 1565 |
| 1589 run_loop2.Run(); | 1566 run_loop2.Run(); |
| 1590 } | 1567 } |
| 1591 | 1568 |
| 1592 } // namespace media_router | 1569 } // namespace media_router |
| OLD | NEW |