Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / media / router / issue_manager_unittest.cc
blobe0ad0f049ddc4a1d0cb9fec49bab07862514c7dc
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.
5 #include <string>
6 #include <vector>
8 #include "chrome/browser/media/router/issue_manager.h"
9 #include "testing/gmock/include/gmock/gmock.h"
11 namespace media_router {
12 namespace {
14 const char kTestRouteId[] = "routeId";
16 Issue CreateTestIssue(const std::string& route_id) {
17 return Issue("title", "message", IssueAction(IssueAction::TYPE_DISMISS),
18 std::vector<IssueAction>(), route_id, Issue::WARNING, false,
19 "http://www.example.com/help");
22 class IssueManagerUnitTest : public ::testing::Test {
23 protected:
24 IssueManagerUnitTest() {}
25 ~IssueManagerUnitTest() override {}
27 IssueManager manager_;
29 private:
30 DISALLOW_COPY_AND_ASSIGN(IssueManagerUnitTest);
33 TEST_F(IssueManagerUnitTest, InitializeManager) {
34 // Before anything is done to the manager, it should hold no issues.
35 EXPECT_EQ(0u, manager_.GetIssueCount());
38 TEST_F(IssueManagerUnitTest, AddIssue) {
39 Issue issue = CreateTestIssue(kTestRouteId);
41 // Add initial issue.
42 manager_.AddIssue(issue);
43 EXPECT_EQ(1u, manager_.GetIssueCount());
45 // Attempt to add the same issue. Duplicates should not be inserted.
46 manager_.AddIssue(issue);
47 EXPECT_EQ(1u, manager_.GetIssueCount());
50 TEST_F(IssueManagerUnitTest, ClearIssue) {
51 Issue issue = CreateTestIssue(kTestRouteId);
53 // Remove an issue that doesn't exist.
54 manager_.ClearIssue("id");
56 // Add initial issue.
57 manager_.AddIssue(issue);
58 EXPECT_EQ(1u, manager_.GetIssueCount());
60 // Remove the only issue.
61 manager_.ClearIssue(issue.id());
62 EXPECT_EQ(0u, manager_.GetIssueCount());
64 // Remove an issue that doesn't exist.
65 manager_.ClearIssue("id");
66 EXPECT_EQ(0u, manager_.GetIssueCount());
69 TEST_F(IssueManagerUnitTest, ClearAllIssues) {
70 // Add ten issues.
71 for (int i = 0; i < 10; i++) {
72 manager_.AddIssue(CreateTestIssue(kTestRouteId));
75 // Check that the issues were added.
76 EXPECT_EQ(10u, manager_.GetIssueCount());
78 // Remove all the issues.
79 manager_.ClearAllIssues();
80 EXPECT_EQ(0u, manager_.GetIssueCount());
83 TEST_F(IssueManagerUnitTest, ClearGlobalIssues) {
84 // Add ten non-global issues.
85 for (int i = 0; i < 10; i++) {
86 manager_.AddIssue(CreateTestIssue(kTestRouteId));
89 // Check that the issues were added.
90 EXPECT_EQ(10u, manager_.GetIssueCount());
92 // Add five global issues.
93 for (int i = 0; i < 5; i++) {
94 manager_.AddIssue(CreateTestIssue(""));
97 // Check that the issues were added.
98 EXPECT_EQ(15u, manager_.GetIssueCount());
100 // Remove all the global issues.
101 manager_.ClearGlobalIssues();
102 EXPECT_EQ(10u, manager_.GetIssueCount());
105 TEST_F(IssueManagerUnitTest, ClearIssuesWithRouteId) {
106 const std::string route_id_one = "route_id1";
107 const std::string route_id_two = "route_id2";
109 // Add ten issues with the same route.
110 for (int i = 0; i < 10; i++) {
111 manager_.AddIssue(CreateTestIssue(route_id_one));
114 // Check that the issues were added.
115 EXPECT_EQ(10u, manager_.GetIssueCount());
117 // Add ten issues with a different route.
118 for (int i = 0; i < 10; i++) {
119 manager_.AddIssue(CreateTestIssue(route_id_two));
122 // Check that the issues were added.
123 EXPECT_EQ(20u, manager_.GetIssueCount());
125 // Add ten global issues.
126 for (int i = 0; i < 10; i++) {
127 manager_.AddIssue(CreateTestIssue(""));
130 // Check that the issues were added.
131 EXPECT_EQ(30u, manager_.GetIssueCount());
133 // Remove all routes with route_id_one.
134 manager_.ClearIssuesWithRouteId(route_id_one);
135 EXPECT_EQ(20u, manager_.GetIssueCount());
137 // Remove all routes with route_id_two.
138 manager_.ClearIssuesWithRouteId(route_id_two);
139 EXPECT_EQ(10u, manager_.GetIssueCount());
142 } // namespace
143 } // namespace media_router