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

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: Resync with master. 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 // Remove an issue that doesn't exist.
54 manager_.ClearIssue("id");
55
56 // Add initial issue.
57 manager_.AddIssue(issue);
58 EXPECT_EQ(1u, manager_.GetIssueCount());
59
60 // Remove the only issue.
61 manager_.ClearIssue(issue.id());
62 EXPECT_EQ(0u, manager_.GetIssueCount());
63
64 // Remove an issue that doesn't exist.
65 manager_.ClearIssue("id");
66 EXPECT_EQ(0u, manager_.GetIssueCount());
67 }
68
69 TEST_F(IssueManagerUnitTest, ClearAllIssues) {
70 // Add ten issues.
71 for (int i = 0; i < 10; i++) {
72 manager_.AddIssue(CreateTestIssue(kTestRouteId));
73 }
74
75 // Check that the issues were added.
76 EXPECT_EQ(10u, manager_.GetIssueCount());
77
78 // Remove all the issues.
79 manager_.ClearAllIssues();
80 EXPECT_EQ(0u, manager_.GetIssueCount());
81 }
82
83 TEST_F(IssueManagerUnitTest, ClearGlobalIssues) {
84 // Add ten non-global issues.
85 for (int i = 0; i < 10; i++) {
86 manager_.AddIssue(CreateTestIssue(kTestRouteId));
87 }
88
89 // Check that the issues were added.
90 EXPECT_EQ(10u, manager_.GetIssueCount());
91
92 // Add five global issues.
93 for (int i = 0; i < 5; i++) {
94 manager_.AddIssue(CreateTestIssue(""));
95 }
96
97 // Check that the issues were added.
98 EXPECT_EQ(15u, manager_.GetIssueCount());
99
100 // Remove all the global issues.
101 manager_.ClearGlobalIssues();
102 EXPECT_EQ(10u, manager_.GetIssueCount());
103 }
104
105 TEST_F(IssueManagerUnitTest, ClearIssuesWithRouteId) {
106 const std::string route_id_one = "route_id1";
107 const std::string route_id_two = "route_id2";
108
109 // Add ten issues with the same route.
110 for (int i = 0; i < 10; i++) {
111 manager_.AddIssue(CreateTestIssue(route_id_one));
112 }
113
114 // Check that the issues were added.
115 EXPECT_EQ(10u, manager_.GetIssueCount());
116
117 // Add ten issues with a different route.
118 for (int i = 0; i < 10; i++) {
119 manager_.AddIssue(CreateTestIssue(route_id_two));
120 }
121
122 // Check that the issues were added.
123 EXPECT_EQ(20u, manager_.GetIssueCount());
124
125 // Add ten global issues.
126 for (int i = 0; i < 10; i++) {
127 manager_.AddIssue(CreateTestIssue(""));
128 }
129
130 // Check that the issues were added.
131 EXPECT_EQ(30u, manager_.GetIssueCount());
132
133 // Remove all routes with route_id_one.
134 manager_.ClearIssuesWithRouteId(route_id_one);
135 EXPECT_EQ(20u, manager_.GetIssueCount());
136
137 // Remove all routes with route_id_two.
138 manager_.ClearIssuesWithRouteId(route_id_two);
139 EXPECT_EQ(10u, manager_.GetIssueCount());
140 }
141
142 } // namespace
143 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/media/router/issue_manager.cc ('k') | chrome/browser/media/router/issue_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698