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

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: IssueObserver init behavior and use StructTraits Created 4 years, 2 months 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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 RouteRequestResult::ResultCode::OK, 635 RouteRequestResult::ResultCode::OK,
640 0); 636 0);
641 ExpectResultBucketCount("TerminateRoute", 637 ExpectResultBucketCount("TerminateRoute",
642 RouteRequestResult::ResultCode::TIMED_OUT, 638 RouteRequestResult::ResultCode::TIMED_OUT,
643 1); 639 1);
644 } 640 }
645 641
646 TEST_F(MediaRouterMojoImplTest, HandleIssue) { 642 TEST_F(MediaRouterMojoImplTest, HandleIssue) {
647 MockIssuesObserver issue_observer1(router()); 643 MockIssuesObserver issue_observer1(router());
648 MockIssuesObserver issue_observer2(router()); 644 MockIssuesObserver issue_observer2(router());
649 issue_observer1.RegisterObserver(); 645 issue_observer1.Init();
650 issue_observer2.RegisterObserver(); 646 issue_observer2.Init();
651 647
652 mojom::IssuePtr mojo_issue1 = CreateMojoIssue("title 1"); 648 IssueInfo issue = CreateIssueInfo("title 1");
653 const Issue& expected_issue1 = mojo_issue1.To<Issue>();
654 649
655 const Issue* issue; 650 const Issue* issue_from_observer1;
656 EXPECT_CALL(issue_observer1, 651 const Issue* issue_from_observer2;
657 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1)))) 652 EXPECT_CALL(issue_observer1, OnIssueUpdated(_))
658 .WillOnce(SaveArg<0>(&issue)); 653 .WillOnce(SaveArg<0>(&issue_from_observer1));
mark a. foltz 2016/10/18 21:13:44 Would it be simpler to declare a Matcher for Issue
imcheng 2016/11/18 23:45:13 The pointers should be identical since they are ca
654
659 base::RunLoop run_loop; 655 base::RunLoop run_loop;
660 EXPECT_CALL(issue_observer2, 656 EXPECT_CALL(issue_observer2, OnIssueUpdated(_))
661 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1)))) 657 .WillOnce(DoAll(SaveArg<0>(&issue_from_observer2),
662 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 658 InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })));
mark a. foltz 2016/10/18 21:13:44 Add run_loop.QuitWhenIdle() after Run() and then t
imcheng 2016/11/18 23:45:13 Done.
663 media_router_proxy_->OnIssue(std::move(mojo_issue1)); 659 media_router_proxy_->OnIssue(issue);
664 run_loop.Run(); 660 run_loop.Run();
665 661
662 ASSERT_TRUE(issue_from_observer1);
663 ASSERT_TRUE(issue_from_observer2);
664 ASSERT_EQ(issue_from_observer1, issue_from_observer2);
665 EXPECT_EQ(issue, issue_from_observer1->info());
666
666 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); 667 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1));
667 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); 668 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2));
668 669
669 EXPECT_CALL(issue_observer1, OnIssueUpdated(nullptr)); 670 EXPECT_CALL(issue_observer1, OnIssueUpdated(nullptr));
670 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr)); 671 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr));
671 672
672 router()->ClearIssue(issue->id()); 673 router()->ClearIssue(issue_from_observer1->id());
673 674
674 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); 675 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1));
675 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); 676 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2));
676 router()->UnregisterIssuesObserver(&issue_observer1);
677 mojom::IssuePtr mojo_issue2 = CreateMojoIssue("title 2");
678 const Issue& expected_issue2 = mojo_issue2.To<Issue>();
679
680 EXPECT_CALL(issue_observer2,
681 OnIssueUpdated(Pointee(EqualsIssue(expected_issue2))));
682 router()->AddIssue(expected_issue2);
683 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2));
684
685 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr));
686 router()->ClearIssue(issue->id());
687 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2));
688
689 base::RunLoop run_loop2;
690 EXPECT_CALL(issue_observer2,
691 OnIssueUpdated(Pointee(EqualsIssue(expected_issue2))))
692 .WillOnce(InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); }));
693 media_router_proxy_->OnIssue(std::move(mojo_issue2));
694 run_loop2.Run();
695
696 issue_observer1.UnregisterObserver();
697 issue_observer2.UnregisterObserver();
698 } 677 }
699 678
700 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) { 679 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) {
701 router()->OnSinkAvailabilityUpdated( 680 router()->OnSinkAvailabilityUpdated(
702 mojom::MediaRouter::SinkAvailability::AVAILABLE); 681 mojom::MediaRouter::SinkAvailability::AVAILABLE);
703 MediaSource media_source(kSource); 682 MediaSource media_source(kSource);
704 GURL origin("https://google.com"); 683 GURL origin("https://google.com");
705 684
706 // These should only be called once even if there is more than one observer 685 // These should only be called once even if there is more than one observer
707 // for a given source. 686 // for a given source.
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 EXPECT_CALL(mock_media_route_provider_, 1544 EXPECT_CALL(mock_media_route_provider_,
1566 UpdateMediaSinks(MediaSourceForDesktop().id())) 1545 UpdateMediaSinks(MediaSourceForDesktop().id()))
1567 .WillOnce(InvokeWithoutArgs([&run_loop2]() { 1546 .WillOnce(InvokeWithoutArgs([&run_loop2]() {
1568 run_loop2.Quit(); 1547 run_loop2.Quit();
1569 })); 1548 }));
1570 1549
1571 run_loop2.Run(); 1550 run_loop2.Run();
1572 } 1551 }
1573 1552
1574 } // namespace media_router 1553 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698