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

Side by Side Diff: chrome/browser/media/router/issue_manager_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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "chrome/browser/media/router/issue_manager.h" 9 #include "chrome/browser/media/router/issue_manager.h"
10 #include "chrome/browser/media/router/mock_media_router.h"
11 #include "chrome/browser/media/router/test_helper.h"
10 #include "content/public/test/test_browser_thread_bundle.h" 12 #include "content/public/test/test_browser_thread_bundle.h"
11 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
12 14
15 using testing::_;
16 using testing::SaveArg;
17
13 namespace media_router { 18 namespace media_router {
14 namespace { 19 namespace {
15 20
16 const char kTestRouteId[] = "routeId"; 21 IssueInfo CreateTestIssue(IssueInfo::Severity severity) {
22 IssueInfo issue("title", IssueInfo::Action::DISMISS, severity);
23 issue.message = "message";
24 issue.help_page_id = 12345;
25 return issue;
26 }
17 27
18 Issue CreateTestIssue(const std::string& route_id) { 28 } // namespace
19 return Issue("title", "message", IssueAction(IssueAction::TYPE_DISMISS),
20 std::vector<IssueAction>(), route_id, Issue::WARNING, false,
21 12345);
22 }
23 29
24 class IssueManagerUnitTest : public ::testing::Test { 30 class IssueManagerUnitTest : public ::testing::Test {
25 protected: 31 protected:
26 IssueManagerUnitTest() {} 32 IssueManagerUnitTest() {}
27 ~IssueManagerUnitTest() override {} 33 ~IssueManagerUnitTest() override {}
28 34
29 content::TestBrowserThreadBundle thread_bundle_; 35 content::TestBrowserThreadBundle thread_bundle_;
30 IssueManager manager_; 36 IssueManager manager_;
37 MockMediaRouter router_;
31 38
32 private: 39 private:
33 DISALLOW_COPY_AND_ASSIGN(IssueManagerUnitTest); 40 DISALLOW_COPY_AND_ASSIGN(IssueManagerUnitTest);
34 }; 41 };
35 42
36 TEST_F(IssueManagerUnitTest, InitializeManager) { 43 TEST_F(IssueManagerUnitTest, AddAndClearIssue) {
37 // Before anything is done to the manager, it should hold no issues. 44 IssueInfo issue_info1 = CreateTestIssue(IssueInfo::Severity::WARNING);
38 EXPECT_EQ(0u, manager_.GetIssueCount()); 45
46 // Add initial issue.
47 manager_.AddIssue(issue_info1);
48
49 const Issue* issue1 = nullptr;
50 MockIssuesObserver observer(&router_);
51 EXPECT_CALL(observer, OnIssueUpdated(_)).WillOnce(SaveArg<0>(&issue1));
52 manager_.RegisterObserver(&observer);
53 ASSERT_TRUE(issue1);
54
55 IssueInfo issue_info2 = CreateTestIssue(IssueInfo::Severity::FATAL);
56 EXPECT_TRUE(issue_info2.is_blocking);
57
58 // Blocking issue takes precedence.
59 const Issue* issue2 = nullptr;
60 EXPECT_CALL(observer, OnIssueUpdated(_)).WillOnce(SaveArg<0>(&issue2));
61 manager_.AddIssue(issue_info2);
62 ASSERT_TRUE(issue2);
63
64 // Clear |issue2|. Observer will be notified with |issue1| again as it is now
65 // the top issue.
66 EXPECT_CALL(observer, OnIssueUpdated(issue1));
67 manager_.ClearIssue(issue2->id());
68 issue2 = nullptr;
69
70 // All issues cleared. Observer will be notified with |nullptr| that there are
71 // no more issues.
72 EXPECT_CALL(observer, OnIssueUpdated(nullptr));
73 manager_.ClearIssue(issue1->id());
74 issue1 = nullptr;
75
76 manager_.UnregisterObserver(&observer);
39 } 77 }
40 78
41 TEST_F(IssueManagerUnitTest, AddIssue) {
42 Issue issue = CreateTestIssue(kTestRouteId);
43
44 // Add initial issue.
45 manager_.AddIssue(issue);
46 EXPECT_EQ(1u, manager_.GetIssueCount());
47
48 // Attempt to add the same issue. Duplicates should not be inserted.
49 manager_.AddIssue(issue);
50 EXPECT_EQ(1u, manager_.GetIssueCount());
51 }
52
53 TEST_F(IssueManagerUnitTest, ClearIssue) {
54 Issue issue = CreateTestIssue(kTestRouteId);
55
56 // Remove an issue that doesn't exist.
57 manager_.ClearIssue("id");
58
59 // Add initial issue.
60 manager_.AddIssue(issue);
61 EXPECT_EQ(1u, manager_.GetIssueCount());
62
63 // Remove the only issue.
64 manager_.ClearIssue(issue.id());
65 EXPECT_EQ(0u, manager_.GetIssueCount());
66
67 // Remove an issue that doesn't exist.
68 manager_.ClearIssue("id");
69 EXPECT_EQ(0u, manager_.GetIssueCount());
70 }
71
72 TEST_F(IssueManagerUnitTest, ClearAllIssues) {
73 // Add ten issues.
74 for (int i = 0; i < 10; i++) {
75 manager_.AddIssue(CreateTestIssue(kTestRouteId));
76 }
77
78 // Check that the issues were added.
79 EXPECT_EQ(10u, manager_.GetIssueCount());
80
81 // Remove all the issues.
82 manager_.ClearAllIssues();
83 EXPECT_EQ(0u, manager_.GetIssueCount());
84 }
85
86 TEST_F(IssueManagerUnitTest, ClearGlobalIssues) {
87 // Add ten non-global issues.
88 for (int i = 0; i < 10; i++) {
89 manager_.AddIssue(CreateTestIssue(kTestRouteId));
90 }
91
92 // Check that the issues were added.
93 EXPECT_EQ(10u, manager_.GetIssueCount());
94
95 // Add five global issues.
96 for (int i = 0; i < 5; i++) {
97 manager_.AddIssue(CreateTestIssue(""));
98 }
99
100 // Check that the issues were added.
101 EXPECT_EQ(15u, manager_.GetIssueCount());
102
103 // Remove all the global issues.
104 manager_.ClearGlobalIssues();
105 EXPECT_EQ(10u, manager_.GetIssueCount());
106 }
107
108 TEST_F(IssueManagerUnitTest, ClearIssuesWithRouteId) {
109 const std::string route_id_one = "route_id1";
110 const std::string route_id_two = "route_id2";
111
112 // Add ten issues with the same route.
113 for (int i = 0; i < 10; i++) {
114 manager_.AddIssue(CreateTestIssue(route_id_one));
115 }
116
117 // Check that the issues were added.
118 EXPECT_EQ(10u, manager_.GetIssueCount());
119
120 // Add ten issues with a different route.
121 for (int i = 0; i < 10; i++) {
122 manager_.AddIssue(CreateTestIssue(route_id_two));
123 }
124
125 // Check that the issues were added.
126 EXPECT_EQ(20u, manager_.GetIssueCount());
127
128 // Add ten global issues.
129 for (int i = 0; i < 10; i++) {
130 manager_.AddIssue(CreateTestIssue(""));
131 }
132
133 // Check that the issues were added.
134 EXPECT_EQ(30u, manager_.GetIssueCount());
135
136 // Remove all routes with route_id_one.
137 manager_.ClearIssuesWithRouteId(route_id_one);
138 EXPECT_EQ(20u, manager_.GetIssueCount());
139
140 // Remove all routes with route_id_two.
141 manager_.ClearIssuesWithRouteId(route_id_two);
142 EXPECT_EQ(10u, manager_.GetIssueCount());
143 }
144
145 } // namespace
146 } // namespace media_router 79 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698