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

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

Powered by Google App Engine
This is Rietveld 408576698