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

Side by Side Diff: chrome/browser/media/router/issue_manager_unittest.cc

Issue 1103273013: Upstream the Media Router's Issue class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed feedback, switched manager to std::list, explicitly invalidated top_issue on clear Created 5 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <string>
6 #include <vector>
7
8 #include "chrome/browser/media/router/issue_manager.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10
11 namespace media_router {
12 namespace {
13
14 const char kTestRouteId[] = "routeId";
15
16 Issue CreateTestIssue(const std::string& route_id) {
17 return Issue("title", "message", IssueAction(IssueAction::OK),
18 std::vector<IssueAction>(), route_id, Issue::WARNING, false,
19 "http://www.example.com/help");
20 }
21
22 class IssueManagerUnitTest : public ::testing::Test {
23 protected:
24 IssueManagerUnitTest() {}
25 ~IssueManagerUnitTest() override {}
26
27 IssueManager manager_;
28
29 private:
30 DISALLOW_COPY_AND_ASSIGN(IssueManagerUnitTest);
31 };
32
33 TEST_F(IssueManagerUnitTest, InitializeManager) {
34 // Before anything is done to the manager, it should hold no issues.
35 EXPECT_EQ(0u, manager_.GetIssueCount());
36 }
37
38 TEST_F(IssueManagerUnitTest, AddIssue) {
39 Issue issue = CreateTestIssue(kTestRouteId);
40
41 // Add initial issue.
42 manager_.AddIssue(issue);
43 EXPECT_EQ(1u, manager_.GetIssueCount());
44
45 // Attempt to add the same issue. Duplicates should not be inserted.
46 manager_.AddIssue(issue);
47 EXPECT_EQ(1u, manager_.GetIssueCount());
48 }
49
50 TEST_F(IssueManagerUnitTest, ClearIssue) {
51 Issue issue = CreateTestIssue(kTestRouteId);
52
53 // Add initial issue.
54 manager_.AddIssue(issue);
55 EXPECT_EQ(1u, manager_.GetIssueCount());
56
57 // Remove the only issue.
58 manager_.ClearIssue(issue.id());
59 EXPECT_EQ(0u, manager_.GetIssueCount());
60
61 // Remove an issue that doesn't exist.
62 manager_.ClearIssue("id");
63 EXPECT_EQ(0u, manager_.GetIssueCount());
64 }
65
66 TEST_F(IssueManagerUnitTest, ClearAllIssues) {
67 // Add ten issues.
68 for (int i = 0; i < 10; i++) {
69 manager_.AddIssue(CreateTestIssue(kTestRouteId));
70 }
71
72 // Check that the issues were added.
73 EXPECT_EQ(10u, manager_.GetIssueCount());
74
75 // Remove all the issues.
76 manager_.ClearAllIssues();
77 EXPECT_EQ(0u, manager_.GetIssueCount());
78 }
79
80 TEST_F(IssueManagerUnitTest, ClearGlobalIssues) {
81 // Add ten non-global issues.
82 for (int i = 0; i < 10; i++) {
83 manager_.AddIssue(CreateTestIssue(kTestRouteId));
84 }
85
86 // Check that the issues were added.
87 EXPECT_EQ(10u, manager_.GetIssueCount());
88
89 // Add five global issues.
90 for (int i = 0; i < 5; i++) {
91 manager_.AddIssue(CreateTestIssue(""));
92 }
93
94 // Check that the issues were added.
95 EXPECT_EQ(15u, manager_.GetIssueCount());
96
97 // Remove all the global issues.
98 manager_.ClearGlobalIssues();
99 EXPECT_EQ(10u, manager_.GetIssueCount());
100 }
101
102 TEST_F(IssueManagerUnitTest, ClearIssuesWithRouteId) {
103 const std::string route_id_one = "route_id1";
104 const std::string route_id_two = "route_id2";
105
106 // Add ten issues with the same route.
107 for (int i = 0; i < 10; i++) {
108 manager_.AddIssue(CreateTestIssue(route_id_one));
109 }
110
111 // Check that the issues were added.
112 EXPECT_EQ(10u, manager_.GetIssueCount());
113
114 // Add ten issues with a different route.
115 for (int i = 0; i < 10; i++) {
116 manager_.AddIssue(CreateTestIssue(route_id_two));
117 }
118
119 // Check that the issues were added.
120 EXPECT_EQ(20u, manager_.GetIssueCount());
121
122 // Add ten global issues.
123 for (int i = 0; i < 10; i++) {
124 manager_.AddIssue(CreateTestIssue(""));
125 }
126
127 // Check that the issues were added.
128 EXPECT_EQ(30u, manager_.GetIssueCount());
129
130 // Remove all routes with route_id_one.
131 manager_.ClearIssuesWithRouteId(route_id_one);
132 EXPECT_EQ(20u, manager_.GetIssueCount());
133
134 // Remove all routes with route_id_two.
135 manager_.ClearIssuesWithRouteId(route_id_two);
136 EXPECT_EQ(10u, manager_.GetIssueCount());
137 }
138
139 } // namespace
140 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698