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

Side by Side Diff: chrome/browser/ui/toolbar/media_router_action_unittest.cc

Issue 1268553002: Reflect the current state in Media Router Action icon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes per kmarshall@'s comments. Created 5 years, 4 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/ui/toolbar/media_router_action.h"
6 #include "chrome/browser/ui/webui/media_router/media_router_test.h"
7 #include "chrome/grit/generated_resources.h"
8 #include "content/public/test/test_utils.h"
9 #include "grit/theme_resources.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/image/image_unittest_util.h"
13
14 class MediaRouterActionUnitTest : public MediaRouterTest {
15 public:
16 MediaRouterActionUnitTest()
17 : fake_issue_notification_(media_router::Issue("title notification",
Peter Kasting 2015/08/07 17:49:28 Nit: All lines of args must be aligned (so, probab
apacible 2015/08/10 23:10:32 Done.
18 "message notification",
19 media_router::IssueAction(media_router::IssueAction::TYPE_OK),
20 std::vector<media_router::IssueAction>(),
21 "route_id",
22 media_router::Issue::NOTIFICATION,
23 false, std::string())),
24 fake_issue_warning_(media_router::Issue("title warning",
25 "message warning",
26 media_router::IssueAction(
27 media_router::IssueAction::TYPE_LEARN_MORE),
28 std::vector<media_router::IssueAction>(),
29 "route_id",
30 media_router::Issue::WARNING,
31 false,
32 "www.google.com")),
33 fake_issue_fatal_(media_router::Issue("title fatal",
34 "message fatal",
35 media_router::IssueAction(media_router::IssueAction::TYPE_OK),
36 std::vector<media_router::IssueAction>(),
37 "route_id",
38 media_router::Issue::FATAL,
39 true,
40 std::string())),
41 fake_sink1_("fakeSink1", "Fake Sink 1"),
42 fake_sink2_("fakeSink2", "Fake Sink 2"),
43 fake_source1_("fakeSource1"),
44 fake_source2_("fakeSource2"),
45 fake_route_local_("route1", fake_source1_, fake_sink1_, "desc1",
46 true, "path.html"),
47 fake_route_remote_("route2", fake_source2_, fake_sink2_, "desc2",
48 false, "path.html"),
49 active_icon_(ui::ResourceBundle::GetSharedInstance().
50 GetImageNamed(IDR_MEDIA_ROUTER_ACTIVE_ICON)),
51 error_icon_(ui::ResourceBundle::GetSharedInstance().
52 GetImageNamed(IDR_MEDIA_ROUTER_ERROR_ICON)),
53 idle_icon_(ui::ResourceBundle::GetSharedInstance().
54 GetImageNamed(IDR_MEDIA_ROUTER_IDLE_ICON)),
55 warning_icon_(ui::ResourceBundle::GetSharedInstance().
56 GetImageNamed(IDR_MEDIA_ROUTER_WARNING_ICON)) {
57 }
58
59 ~MediaRouterActionUnitTest() override {}
60
61 // BrowserWithTestWindowTest:
62 void SetUp() override {
63 BrowserWithTestWindowTest::SetUp();
64 action_ = new MediaRouterAction(browser());
65 }
66
67 MediaRouterAction* action() { return action_; }
68 media_router::Issue fake_issue_notification() {
69 return fake_issue_notification_;
70 }
71 media_router::Issue fake_issue_warning() { return fake_issue_warning_; }
72 media_router::Issue fake_issue_fatal() { return fake_issue_fatal_; }
73 media_router::MediaRoute fake_route_local() { return fake_route_local_; }
74 media_router::MediaRoute fake_route_remote() { return fake_route_remote_; }
75 gfx::Image active_icon() { return active_icon_; }
76 gfx::Image error_icon() { return error_icon_; }
77 gfx::Image idle_icon() { return idle_icon_; }
78 gfx::Image warning_icon() { return warning_icon_; }
79
80 private:
81 MediaRouterAction* action_;
82
83 // Fake Issues.
84 media_router::Issue fake_issue_notification_;
85 media_router::Issue fake_issue_warning_;
86 media_router::Issue fake_issue_fatal_;
87
88 // Fake Sinks and Sources, used for the Routes.
89 media_router::MediaSink fake_sink1_;
90 media_router::MediaSink fake_sink2_;
91 media_router::MediaSource fake_source1_;
92 media_router::MediaSource fake_source2_;
93
94 // Fake Routes.
95 media_router::MediaRoute fake_route_local_;
96 media_router::MediaRoute fake_route_remote_;
97
98 // Cached images.
99 gfx::Image active_icon_;
100 gfx::Image error_icon_;
101 gfx::Image idle_icon_;
102 gfx::Image warning_icon_;
103
104 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionUnitTest);
105 };
106
107 // Tests the initial state of MediaRouterAction after construction.
108 TEST_F(MediaRouterActionUnitTest, Initialization) {
109 EXPECT_EQ("media_router_action", action()->GetId());
110 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_TITLE),
111 action()->GetActionName());
112 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(),
113 action()->GetIcon(nullptr, gfx::Size())));
114 }
115
116 // Tests the state of the MediaRouterAction based on updates to issues.
117 TEST_F(MediaRouterActionUnitTest, UpdateIssues) {
118 // Initially, there are no issues.
119 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(),
120 action()->GetIcon(nullptr, gfx::Size())));
121
122 // Don't update |state_| since the issue is only a notification.
Peter Kasting 2015/08/07 17:49:28 All these comments about |state_| are out of date.
apacible 2015/08/10 23:10:33 Done.
123 action()->OnIssueUpdated(new media_router::Issue(fake_issue_notification()));
124 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(),
125 action()->GetIcon(nullptr, gfx::Size())));
126
127 // Update |state_| since the issue is a warning.
128 action()->OnIssueUpdated(new media_router::Issue(fake_issue_warning()));
129 EXPECT_TRUE(gfx::test::IsEqual(warning_icon(),
130 action()->GetIcon(nullptr, gfx::Size())));
131
132 // Update |state_| since the issue is fatal.
133 action()->OnIssueUpdated(new media_router::Issue(fake_issue_fatal()));
134 EXPECT_TRUE(gfx::test::IsEqual(error_icon(),
135 action()->GetIcon(nullptr, gfx::Size())));
136
137 // Clear the issue.
138 action()->OnIssueUpdated(nullptr);
139 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(),
140 action()->GetIcon(nullptr, gfx::Size())));
141 }
142
143 // Tests the state of the MediaRouterAction based on updates to routes.
144 TEST_F(MediaRouterActionUnitTest, UpdateRoutes) {
145 std::vector<media_router::MediaRoute>* routes =
146 new std::vector<media_router::MediaRoute>();
147
148 // Initially, there are no routes.
149 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(),
150 action()->GetIcon(nullptr, gfx::Size())));
151
152 // Update |state_| since there is a local route.
153 routes->push_back(fake_route_local());
154 routes->push_back(fake_route_remote());
155 action()->OnRoutesUpdated(*routes);
156 EXPECT_TRUE(gfx::test::IsEqual(active_icon(),
157 action()->GetIcon(nullptr, gfx::Size())));
158
159 // Update |state_| since there are no more local routes.
160 routes->clear();
161 routes->push_back(fake_route_remote());
162 action()->OnRoutesUpdated(*routes);
163 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(),
164 action()->GetIcon(nullptr, gfx::Size())));
165
166 // |state_| stays the same if there are no local routes or no routes.
167 routes->clear();
168 action()->OnRoutesUpdated(*routes);
169 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(),
170 action()->GetIcon(nullptr, gfx::Size())));
171 }
172
173 // Tests the state of the MediaRouterAction based on updates to both issues
174 // and routes.
175 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) {
176 std::vector<media_router::MediaRoute>* routes =
177 new std::vector<media_router::MediaRoute>();
178
179 // Initially, there are no issues or routes.
180 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(),
181 action()->GetIcon(nullptr, gfx::Size())));
182
183 // There is no change in |state_| since notification issues do not update
184 // the state.
185 action()->OnIssueUpdated(new media_router::Issue(fake_issue_notification()));
186 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(),
187 action()->GetIcon(nullptr, gfx::Size())));
188
189 // Non-local routes also do not have an effect on |state_|.
190 routes->push_back(fake_route_remote());
191 action()->OnRoutesUpdated(*routes);
192 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(),
193 action()->GetIcon(nullptr, gfx::Size())));
194
195 // Update |state_| since there is a local route.
196 routes->clear();
197 routes->push_back(fake_route_local());
198 action()->OnRoutesUpdated(*routes);
199 EXPECT_TRUE(gfx::test::IsEqual(active_icon(),
200 action()->GetIcon(nullptr, gfx::Size())));
201
202 // Update |state_|, with a priority to reflect the warning issue rather than
203 // local route.
204 action()->OnIssueUpdated(new media_router::Issue(fake_issue_warning()));
205 EXPECT_TRUE(gfx::test::IsEqual(warning_icon(),
206 action()->GetIcon(nullptr, gfx::Size())));
207
208 // Swapping the local route for a non-local one makes no difference to the
209 // |state_|.
210 routes->clear();
211 routes->push_back(fake_route_remote());
212 action()->OnRoutesUpdated(*routes);
213 EXPECT_TRUE(gfx::test::IsEqual(warning_icon(),
214 action()->GetIcon(nullptr, gfx::Size())));
215
216 // Update |state_| since the issue has been updated to fatal.
217 action()->OnIssueUpdated(new media_router::Issue(fake_issue_fatal()));
218 EXPECT_TRUE(gfx::test::IsEqual(error_icon(),
219 action()->GetIcon(nullptr, gfx::Size())));
220
221 // Fatal issues still take precedent over local routes.
222 routes->clear();
223 routes->push_back(fake_route_local());
224 action()->OnRoutesUpdated(*routes);
225 EXPECT_TRUE(gfx::test::IsEqual(error_icon(),
226 action()->GetIcon(nullptr, gfx::Size())));
227
228 // When the fatal issue is dismissed, |state_| reflects the existing local
229 // route.
230 action()->OnIssueUpdated(nullptr);
231 EXPECT_TRUE(gfx::test::IsEqual(active_icon(),
232 action()->GetIcon(nullptr, gfx::Size())));
233
234 // Update |state_| when the local route is swapped out for a non-local route.
235 routes->clear();
236 routes->push_back(fake_route_remote());
237 action()->OnRoutesUpdated(*routes);
238 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(),
239 action()->GetIcon(nullptr, gfx::Size())));
240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698