Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: chrome/browser/media/router/mojo/media_router_mojo_impl_unittest.cc

Issue 2176613003: [Media Router] Clean up issues related code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 = CreateIssueInfo("title 1");
671 const Issue& expected_issue1 = mojo_issue1.To<Issue>();
672 667
673 const Issue* issue; 668 const Issue* issue_from_observer1;
674 EXPECT_CALL(issue_observer1, 669 const Issue* issue_from_observer2;
675 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1)))) 670 EXPECT_CALL(issue_observer1, OnIssueUpdated(_))
676 .WillOnce(SaveArg<0>(&issue)); 671 .WillOnce(SaveArg<0>(&issue_from_observer1));
672 EXPECT_CALL(issue_observer2, OnIssueUpdated(_))
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);
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_TRUE(issue_from_observer1);
682 run_loop.Run(); 680 ASSERT_TRUE(issue_from_observer2);
681 ASSERT_EQ(issue_from_observer1, issue_from_observer2);
682 EXPECT_EQ(issue, issue_from_observer1->info());
683 683
684 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); 684 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1));
685 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); 685 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2));
686 686
687 EXPECT_CALL(issue_observer1, OnIssueUpdated(nullptr)); 687 EXPECT_CALL(issue_observer1, OnIssueUpdated(nullptr));
688 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr)); 688 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr));
689 689
690 router()->ClearIssue(issue->id()); 690 router()->ClearIssue(issue_from_observer1->id());
691 691
692 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); 692 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1));
693 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); 693 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 } 694 }
717 695
718 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) { 696 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) {
719 router()->OnSinkAvailabilityUpdated( 697 router()->OnSinkAvailabilityUpdated(
720 mojom::MediaRouter::SinkAvailability::AVAILABLE); 698 mojom::MediaRouter::SinkAvailability::AVAILABLE);
721 MediaSource media_source(kSource); 699 MediaSource media_source(kSource);
722 GURL origin("https://google.com"); 700 GURL origin("https://google.com");
723 701
724 // These should only be called once even if there is more than one observer 702 // These should only be called once even if there is more than one observer
725 // for a given source. 703 // for a given source.
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 EXPECT_CALL(mock_media_route_provider_, 1561 EXPECT_CALL(mock_media_route_provider_,
1584 UpdateMediaSinks(MediaSourceForDesktop().id())) 1562 UpdateMediaSinks(MediaSourceForDesktop().id()))
1585 .WillOnce(InvokeWithoutArgs([&run_loop2]() { 1563 .WillOnce(InvokeWithoutArgs([&run_loop2]() {
1586 run_loop2.Quit(); 1564 run_loop2.Quit();
1587 })); 1565 }));
1588 1566
1589 run_loop2.Run(); 1567 run_loop2.Run();
1590 } 1568 }
1591 1569
1592 } // namespace media_router 1570 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698