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 "chrome/browser/media/router/issue.h"
6 #include "chrome/grit/generated_resources.h"
7 #include "testing/gmock/include/gmock/gmock.h"
8 #include "ui/base/l10n/l10n_util.h"
10 namespace media_router
{
12 // Checks static IssueAction factory method.
13 TEST(IssueUnitTest
, IssueActionConstructor
) {
14 // Pre-defined "Dismiss" issue action.
15 IssueAction
action1(IssueAction::TYPE_DISMISS
);
16 EXPECT_EQ(IssueAction::TYPE_DISMISS
, action1
.type());
18 // Pre-defined "Learn More" issue action.
19 IssueAction
action2(IssueAction::TYPE_LEARN_MORE
);
20 EXPECT_EQ(IssueAction::TYPE_LEARN_MORE
, action2
.type());
23 // Tests custom Issue factory method without any secondary actions.
24 TEST(IssueUnitTest
, CustomIssueConstructionWithNoSecondaryActions
) {
25 std::vector
<IssueAction
> secondary_actions
;
26 std::string title
= "title";
27 std::string message
= "message";
29 Issue
issue1(title
, message
, IssueAction(IssueAction::TYPE_DISMISS
),
30 secondary_actions
, "", Issue::WARNING
, false,
31 "http://www.google.com/");
33 EXPECT_EQ(title
, issue1
.title());
34 EXPECT_EQ(message
, issue1
.message());
35 EXPECT_EQ(IssueAction::TYPE_DISMISS
, issue1
.default_action().type());
36 EXPECT_TRUE(issue1
.secondary_actions().empty());
37 EXPECT_EQ(Issue::WARNING
, issue1
.severity());
38 EXPECT_EQ("", issue1
.route_id());
39 EXPECT_TRUE(issue1
.is_global());
40 EXPECT_FALSE(issue1
.is_blocking());
41 EXPECT_EQ("http://www.google.com/", issue1
.help_url().spec());
43 Issue
issue2(title
, message
, IssueAction(IssueAction::TYPE_DISMISS
),
44 secondary_actions
, "routeid", Issue::FATAL
, true,
45 "http://www.google.com/");
47 EXPECT_EQ(title
, issue2
.title());
48 EXPECT_EQ(message
, issue2
.message());
49 EXPECT_EQ(IssueAction::TYPE_DISMISS
, issue1
.default_action().type());
50 EXPECT_TRUE(issue2
.secondary_actions().empty());
51 EXPECT_EQ(Issue::FATAL
, issue2
.severity());
52 EXPECT_EQ("routeid", issue2
.route_id());
53 EXPECT_FALSE(issue2
.is_global());
54 EXPECT_TRUE(issue2
.is_blocking());
55 EXPECT_EQ("http://www.google.com/", issue1
.help_url().spec());
57 Issue
issue3(title
, "", IssueAction(IssueAction::TYPE_DISMISS
),
58 secondary_actions
, "routeid", Issue::FATAL
, true,
59 "http://www.google.com/");
61 EXPECT_EQ(title
, issue3
.title());
62 EXPECT_EQ("", issue3
.message());
63 EXPECT_EQ(IssueAction::TYPE_DISMISS
, issue1
.default_action().type());
64 EXPECT_TRUE(issue3
.secondary_actions().empty());
65 EXPECT_EQ(Issue::FATAL
, issue3
.severity());
66 EXPECT_EQ("routeid", issue3
.route_id());
67 EXPECT_FALSE(issue3
.is_global());
68 EXPECT_TRUE(issue3
.is_blocking());
69 EXPECT_EQ("http://www.google.com/", issue1
.help_url().spec());
72 // Tests custom Issue factory method with secondary actions.
73 TEST(IssueUnitTest
, CustomIssueConstructionWithSecondaryActions
) {
74 std::vector
<IssueAction
> secondary_actions
;
75 secondary_actions
.push_back(IssueAction(IssueAction::TYPE_DISMISS
));
76 EXPECT_EQ(1u, secondary_actions
.size());
77 std::string title
= "title";
78 std::string message
= "message";
80 Issue
issue1(title
, message
, IssueAction(IssueAction::TYPE_LEARN_MORE
),
81 secondary_actions
, "", Issue::WARNING
, false, "");
83 EXPECT_EQ(title
, issue1
.title());
84 EXPECT_EQ(message
, issue1
.message());
85 EXPECT_EQ(IssueAction::TYPE_LEARN_MORE
, issue1
.default_action().type());
86 EXPECT_FALSE(issue1
.secondary_actions().empty());
87 EXPECT_EQ(1u, issue1
.secondary_actions().size());
88 EXPECT_EQ(Issue::WARNING
, issue1
.severity());
89 EXPECT_EQ("", issue1
.route_id());
90 EXPECT_TRUE(issue1
.is_global());
91 EXPECT_FALSE(issue1
.is_blocking());
93 Issue
issue2(title
, message
, IssueAction(IssueAction::TYPE_LEARN_MORE
),
94 secondary_actions
, "routeid", Issue::FATAL
, true, "");
96 EXPECT_EQ(title
, issue2
.title());
97 EXPECT_EQ(message
, issue2
.message());
98 EXPECT_EQ(IssueAction::TYPE_LEARN_MORE
, issue2
.default_action().type());
99 EXPECT_FALSE(issue2
.secondary_actions().empty());
100 EXPECT_EQ(1u, issue2
.secondary_actions().size());
101 EXPECT_EQ(Issue::FATAL
, issue2
.severity());
102 EXPECT_EQ("routeid", issue2
.route_id());
103 EXPECT_FALSE(issue2
.is_global());
104 EXPECT_TRUE(issue2
.is_blocking());
106 Issue
issue3(title
, "", IssueAction(IssueAction::TYPE_LEARN_MORE
),
107 secondary_actions
, "routeid", Issue::FATAL
, true, "");
109 EXPECT_EQ(title
, issue3
.title());
110 EXPECT_EQ("", issue3
.message());
111 EXPECT_EQ(IssueAction::TYPE_LEARN_MORE
, issue3
.default_action().type());
112 EXPECT_FALSE(issue3
.secondary_actions().empty());
113 EXPECT_EQ(1u, issue3
.secondary_actions().size());
114 EXPECT_EQ(Issue::FATAL
, issue3
.severity());
115 EXPECT_EQ("routeid", issue3
.route_id());
116 EXPECT_FALSE(issue3
.is_global());
117 EXPECT_TRUE(issue3
.is_blocking());
120 // Tests == and != method.
121 TEST(IssueUnitTest
, Equal
) {
122 std::vector
<IssueAction
> secondary_actions
;
123 secondary_actions
.push_back(IssueAction(IssueAction::TYPE_DISMISS
));
125 std::vector
<IssueAction
> secondary_actions2
;
127 std::string title
= "title";
128 std::string message
= "message";
130 Issue
issue1(Issue(title
, message
, IssueAction(IssueAction::TYPE_LEARN_MORE
),
131 secondary_actions
, "", Issue::WARNING
, false, ""));
132 EXPECT_TRUE(issue1
.Equals(issue1
));
134 Issue
issue2(Issue(title
, message
, IssueAction(IssueAction::TYPE_LEARN_MORE
),
135 secondary_actions
, "", Issue::WARNING
, false, ""));
136 EXPECT_FALSE(issue1
.Equals(issue2
));
139 } // namespace media_router