OLD | NEW |
---|---|
(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", | |
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. | |
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 // Initially, there are no routes. | |
146 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), | |
147 action()->GetIcon(nullptr, gfx::Size()))); | |
148 | |
149 std::vector<media_router::MediaRoute> routes = | |
150 { fake_route_local(), fake_route_remote() }; | |
151 | |
152 // Update |state_| since there is a local route. | |
153 action()->OnRoutesUpdated(routes); | |
154 EXPECT_TRUE(gfx::test::IsEqual(active_icon(), | |
155 action()->GetIcon(nullptr, gfx::Size()))); | |
156 | |
157 // Update |state_| since there are no more local routes. | |
158 routes = { fake_route_remote() }; | |
159 action()->OnRoutesUpdated(routes); | |
160 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), | |
161 action()->GetIcon(nullptr, gfx::Size()))); | |
162 | |
163 // |state_| stays the same if there are no local routes or no routes. | |
164 routes = {}; | |
165 action()->OnRoutesUpdated(routes); | |
166 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), | |
167 action()->GetIcon(nullptr, gfx::Size()))); | |
168 } | |
169 | |
170 // Tests the state of the MediaRouterAction based on updates to both issues | |
171 // and routes. | |
172 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) { | |
173 // Initially, there are no issues or routes. | |
174 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), | |
175 action()->GetIcon(nullptr, gfx::Size()))); | |
176 | |
177 // There is no change in |state_| since notification issues do not update | |
178 // the state. | |
179 action()->OnIssueUpdated(new media_router::Issue(fake_issue_notification())); | |
180 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), | |
181 action()->GetIcon(nullptr, gfx::Size()))); | |
182 | |
183 // Non-local routes also do not have an effect on |state_|. | |
184 std::vector<media_router::MediaRoute> routes = { fake_route_remote() }; | |
185 action()->OnRoutesUpdated(routes); | |
186 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), | |
187 action()->GetIcon(nullptr, gfx::Size()))); | |
188 | |
189 // Update |state_| since there is a local route. | |
190 routes = { fake_route_local() }; | |
191 action()->OnRoutesUpdated(routes); | |
192 EXPECT_TRUE(gfx::test::IsEqual(active_icon(), | |
193 action()->GetIcon(nullptr, gfx::Size()))); | |
194 | |
195 // Update |state_|, with a priority to reflect the warning issue rather than | |
196 // local route. | |
197 action()->OnIssueUpdated(new media_router::Issue(fake_issue_warning())); | |
198 EXPECT_TRUE(gfx::test::IsEqual(warning_icon(), | |
199 action()->GetIcon(nullptr, gfx::Size()))); | |
200 | |
201 // Swapping the local route for a non-local one makes no difference to the | |
202 // |state_|. | |
203 routes = { fake_route_remote() }; | |
204 action()->OnRoutesUpdated(routes); | |
205 EXPECT_TRUE(gfx::test::IsEqual(warning_icon(), | |
206 action()->GetIcon(nullptr, gfx::Size()))); | |
207 | |
208 // Update |state_| since the issue has been updated to fatal. | |
209 action()->OnIssueUpdated(new media_router::Issue(fake_issue_fatal())); | |
210 EXPECT_TRUE(gfx::test::IsEqual(error_icon(), | |
211 action()->GetIcon(nullptr, gfx::Size()))); | |
212 | |
213 // Fatal issues still take precedent over local routes. | |
214 routes = { fake_route_local() }; | |
215 action()->OnRoutesUpdated(routes); | |
216 EXPECT_TRUE(gfx::test::IsEqual(error_icon(), | |
217 action()->GetIcon(nullptr, gfx::Size()))); | |
218 | |
219 // When the fatal issue is dismissed, |state_| reflects the existing local | |
220 // route. | |
221 action()->OnIssueUpdated(nullptr); | |
222 EXPECT_TRUE(gfx::test::IsEqual(active_icon(), | |
223 action()->GetIcon(nullptr, gfx::Size()))); | |
224 | |
225 // Update |state_| when the local route is swapped out for a non-local route. | |
226 routes = { fake_route_remote() }; | |
Kevin M
2015/08/05 20:20:28
This type of assignment isn't allowed :(
see "(Un
apacible
2015/08/05 22:13:52
Updated. Thanks!
| |
227 action()->OnRoutesUpdated(routes); | |
228 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), | |
229 action()->GetIcon(nullptr, gfx::Size()))); | |
230 } | |
OLD | NEW |