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

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 "base/message_loop/message_loop.h"
6 #include "chrome/browser/media/router/media_router_factory.h"
7 #include "chrome/browser/media/router/media_router_mojo_impl.h"
8 #include "chrome/browser/media/router/media_router_type_converters.h"
9 #include "chrome/browser/media/router/media_source_helper.h"
10 #include "chrome/browser/media/router/test_helper.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/toolbar/media_router_action.h"
13 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h"
14 #include "chrome/browser/ui/webui/media_router/media_router_test.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "chrome/test/base/test_browser_window.h"
17 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/test/browser_test_utils.h"
19 #include "content/public/test/test_utils.h"
20 #include "extensions/browser/process_manager.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h"
24
25 class TestMediaRouterAction : public MediaRouterAction {
26 public:
27 TestMediaRouterAction(Browser* browser,
28 extensions::ProcessManager* process_manager)
29 : MediaRouterAction(browser),
30 mock_media_router_(
31 new media_router::MediaRouterMojoImpl(process_manager)) {
32 }
33 ~TestMediaRouterAction() override {};
34
35 // MediaRouterAction:
36 media_router::MediaRouter* GetMediaRouter(Browser* browser) override {
37 return mock_media_router_;
38 }
39
40 private:
41 media_router::MediaRouterMojoImpl* mock_media_router_;
42
43 friend class MediaRouterActionUnitTest;
44 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, Initialization);
45 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, UpdateIssues);
46 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, UpdateRoutes);
47 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, UpdateIssuesAndRoutes);
48 };
Peter Kasting 2015/08/03 21:28:51 Nit: DISALLOW_COPY_AND_ASSIGN for all these classe
apacible 2015/08/05 06:47:55 Done.
49
50 class TestToolbarActionViewDelegate : public ToolbarActionViewDelegate {
51 public:
52 TestToolbarActionViewDelegate() {}
53
54 // ToolbarActionViewDelegate:
55 ToolbarActionViewController* GetPreferredPopupViewController() {
56 return nullptr;
57 }
58 content::WebContents* GetCurrentWebContents() const override {
59 return nullptr;
60 }
61 void UpdateState() override {};
62 bool IsMenuRunning() const override { return false; };
63 void OnPopupShown(bool by_user) override {};
64 void OnPopupClosed() override {};
65
66 protected:
67 ~TestToolbarActionViewDelegate() override {};
68 };
69
70 class MediaRouterActionUnitTest : public MediaRouterTest {
71 public:
72 MediaRouterActionUnitTest()
73 : fake_issue_notification_(media_router::Issue("title notification",
74 "message notification",
75 media_router::IssueAction(media_router::IssueAction::TYPE_OK),
76 std::vector<media_router::IssueAction>(),
77 "route_id",
78 media_router::Issue::NOTIFICATION,
79 false, "")),
Peter Kasting 2015/08/03 21:28:51 Nit: std::string() in place of "" everywhere
apacible 2015/08/05 06:47:55 Done.
80 fake_issue_warning_(media_router::Issue("title warning",
81 "message warning",
82 media_router::IssueAction(
83 media_router::IssueAction::TYPE_LEARN_MORE),
84 std::vector<media_router::IssueAction>(),
85 "route_id",
86 media_router::Issue::WARNING,
87 false,
88 "www.google.com")),
89 fake_issue_fatal_(media_router::Issue("title fatal",
90 "message fatal",
91 media_router::IssueAction(media_router::IssueAction::TYPE_OK),
92 std::vector<media_router::IssueAction>(),
93 "route_id",
94 media_router::Issue::FATAL,
95 true,
96 "")),
97 fake_sink1_("fakeSink1", "Fake Sink 1"),
98 fake_sink2_("fakeSink2", "Fake Sink 2"),
99 fake_source1_("fakeSource1"),
100 fake_source2_("fakeSource2"),
101 fake_route_local_("route1", fake_source1_, fake_sink1_, "desc1",
102 true, "path.html"),
103 fake_route_remote_("route2", fake_source2_, fake_sink2_, "desc2",
104 false, "path.html") {
105 }
106
107 ~MediaRouterActionUnitTest() override {}
108
109 // BrowserWithTestWindowTest:
110 void SetUp() override {
111 BrowserWithTestWindowTest::SetUp();
112
113 extensions::ProcessManager* process_manager =
114 extensions::ProcessManager::Get(profile());
115 action_ = new TestMediaRouterAction(browser(), process_manager);
116 }
117
118 protected:
119 TestMediaRouterAction* action_;
120
121 // Fake Issues.
122 media_router::Issue fake_issue_notification_;
123 media_router::Issue fake_issue_warning_;
124 media_router::Issue fake_issue_fatal_;
125
126 // Fake Sinks.
127 media_router::MediaSink fake_sink1_;
128 media_router::MediaSink fake_sink2_;
129
130 // Fake Sources.
131 media_router::MediaSource fake_source1_;
132 media_router::MediaSource fake_source2_;
133
134 // Fake Routes.
135 media_router::MediaRoute fake_route_local_;
136 media_router::MediaRoute fake_route_remote_;
Peter Kasting 2015/08/03 21:28:51 Nit: Even in test code, we're not supposed to have
apacible 2015/08/05 06:47:55 Thanks for the info! Added helpers for these.
137
138
139 private:
140 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionUnitTest);
141 };
142
143 // Tests the initial state of MediaRouterAction after construction.
144 TEST_F(MediaRouterActionUnitTest, Initialization) {
145 EXPECT_EQ("media_router_action", action_->id_);
146 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_TITLE), action_->name_);
147 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
148 EXPECT_FALSE(action_->issue_);
149 EXPECT_FALSE(action_->has_local_routes_);
150 EXPECT_FALSE(action_->delegate_);
151 }
152
153 // Tests the state of the MediaRouterAction based on updates to issues.
154 TEST_F(MediaRouterActionUnitTest, UpdateIssues) {
155 // Initially, there are no issues.
156 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
157
158 // Don't |state_| since the issue is only a notification.
159 action_->OnIssueUpdated(&fake_issue_notification_);
160 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
161
162 // Update |state_| since the issue is a warning.
163 action_->OnIssueUpdated(&fake_issue_warning_);
164 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_WARNING,
165 action_->state_);
166
167 // Update |state_| since the issue is fatal.
168 action_->OnIssueUpdated(&fake_issue_fatal_);
169 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_ERROR,
170 action_->state_);
171
172 // Clear the issue.
173 action_->OnIssueUpdated(nullptr);
174 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
175 }
176
177 // Tests the state of the MediaRouterAction based on updates to routes.
178 TEST_F(MediaRouterActionUnitTest, UpdateRoutes) {
179 // Initially, there are no routes.
180 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
181
182 std::vector<media_router::MediaRoute> routes =
183 { fake_route_local_, fake_route_remote_ };
184
185 // Update |state_| since there is a local route.
186 action_->OnRoutesUpdated(routes);
187 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_ACTIVE,
188 action_->state_);
189
190 // Update |state_| since there are no more local routes.
191 routes = { fake_route_remote_ };
192 action_->OnRoutesUpdated(routes);
193 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
194
195 // |state_| stays the same if there are no local routes or no routes.
196 routes = {};
197 action_->OnRoutesUpdated(routes);
198 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
199 }
200
201 // Tests the state of the MediaRouterAction based on updates to both issues
202 // and routes.
203 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) {
204 // Initially, there are no issues or routes.
205 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
206
207 // There is no change in |state_| since notification issues do not update
208 // the state.
209 action_->OnIssueUpdated(&fake_issue_notification_);
210 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
211
212 // Non-local routes also do not have an effect on |state_|.
213 std::vector<media_router::MediaRoute> routes = { fake_route_remote_ };
214 action_->OnRoutesUpdated(routes);
215 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
216
217 // Update |state_| since there is a local route.
218 routes = { fake_route_local_ };
219 action_->OnRoutesUpdated(routes);
220 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_ACTIVE,
221 action_->state_);
222
223 // Update |state_|, with a priority to reflect the warning issue rather than
224 // local route.
225 action_->OnIssueUpdated(&fake_issue_warning_);
226 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_WARNING,
227 action_->state_);
228
229 // Swapping the local route for a non-local one makes no difference to the
230 // |state_|.
231 routes = { fake_route_remote_ };
232 action_->OnRoutesUpdated(routes);
233 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_WARNING,
234 action_->state_);
235
236 // Update |state_| since the issue has been updated to fatal.
237 action_->OnIssueUpdated(&fake_issue_fatal_);
238 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_ERROR,
239 action_->state_);
240
241 // Fatal issues still take precedent over local routes.
242 routes = { fake_route_local_ };
243 action_->OnRoutesUpdated(routes);
244 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_ERROR,
245 action_->state_);
246
247 // When the fatal issue is dismissed, |state_| reflects the existing local
248 // route.
249 action_->OnIssueUpdated(nullptr);
250 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_ACTIVE,
251 action_->state_);
252
253 // Update |state_| when the local route is swapped out for a non-local route.
254 routes = { fake_route_remote_ };
255 action_->OnRoutesUpdated(routes);
256 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698