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

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() 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 };
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, "")),
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_.reset(new TestMediaRouterAction(browser(), process_manager));
116 }
117
118 protected:
119 scoped_ptr<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_;
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 EXPECT_FALSE(action_->action_observer_);
152 }
153
154 // Tests the state of the MediaRouterAction based on updates to issues.
155 TEST_F(MediaRouterActionUnitTest, UpdateIssues) {
156 // Set the delegate to register the observers.
157 action_->SetDelegate(new TestToolbarActionViewDelegate());
158 MediaRouterActionObserver* action_observer =
159 action_->action_observer_.get();
160 EXPECT_TRUE(action_observer);
161
162 // Initially, there are no issues.
163 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
164
165 // Don't |state_| since the issue is only a notification.
166 action_observer->OnIssueUpdated(&fake_issue_notification_);
167 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
168
169 // Update |state_| since the issue is a warning.
170 action_observer->OnIssueUpdated(&fake_issue_warning_);
171 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_WARNING,
172 action_->state_);
173
174 // Update |state_| since the issue is fatal.
175 action_observer->OnIssueUpdated(&fake_issue_fatal_);
176 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_ERROR,
177 action_->state_);
178
179 // Clear the issue.
180 action_observer->OnIssueUpdated(nullptr);
181 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
182 }
183
184 // Tests the state of the MediaRouterAction based on updates to routes.
185 TEST_F(MediaRouterActionUnitTest, UpdateRoutes) {
186 // Set the delegate to register the observers.
187 action_->SetDelegate(new TestToolbarActionViewDelegate());
188 MediaRouterActionObserver* action_observer =
189 action_->action_observer_.get();
190 EXPECT_TRUE(action_observer);
191
192 // Initially, there are no routes.
193 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
194
195 std::vector<media_router::MediaRoute> routes =
196 { fake_route_local_, fake_route_remote_ };
197
198 // Update |state_| since there is a local route.
199 action_observer->OnRoutesUpdated(routes);
200 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_ACTIVE,
201 action_->state_);
202
203 // Update |state_| since there are no more local routes.
204 routes = { fake_route_remote_ };
205 action_observer->OnRoutesUpdated(routes);
206 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
207
208 // |state_| stays the same if there are no local routes or no routes.
209 routes = {};
210 action_observer->OnRoutesUpdated(routes);
211 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
212 }
213
214 // Tests the state of the MediaRouterAction based on updates to both issues
215 // and routes.
216 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) {
217 // Set the delegate to register the observers.
218 action_->SetDelegate(new TestToolbarActionViewDelegate());
219 MediaRouterActionObserver* action_observer =
220 action_->action_observer_.get();
221 EXPECT_TRUE(action_observer);
222
223 // Initially, there are no issues or routes.
224 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
225
226 // There is no change in |state_| since notification issues do not update
227 // the state.
228 action_observer->OnIssueUpdated(&fake_issue_notification_);
229 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
230
231 // Non-local routes also do not have an effect on |state_|.
232 std::vector<media_router::MediaRoute> routes = { fake_route_remote_ };
233 action_observer->OnRoutesUpdated(routes);
234 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
235
236 // Update |state_| since there is a local route.
237 routes = { fake_route_local_ };
238 action_observer->OnRoutesUpdated(routes);
239 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_ACTIVE,
240 action_->state_);
241
242 // Update |state_|, with a priority to reflect the warning issue rather than
243 // local route.
244 action_observer->OnIssueUpdated(&fake_issue_warning_);
245 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_WARNING,
246 action_->state_);
247
248 // Swapping the local route for a non-local one makes no difference to the
249 // |state_|.
250 routes = { fake_route_remote_ };
251 action_observer->OnRoutesUpdated(routes);
252 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_WARNING,
253 action_->state_);
254
255 // Update |state_| since the issue has been updated to fatal.
256 action_observer->OnIssueUpdated(&fake_issue_fatal_);
257 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_ERROR,
258 action_->state_);
259
260 // Fatal issues still take precedent over local routes.
261 routes = { fake_route_local_ };
262 action_observer->OnRoutesUpdated(routes);
263 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_ERROR,
264 action_->state_);
265
266 // When the fatal issue is dismissed, |state_| reflects the existing local
267 // route.
268 action_observer->OnIssueUpdated(nullptr);
269 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_ACTIVE,
270 action_->state_);
271
272 // Update |state_| when the local route is swapped out for a non-local route.
273 routes = { fake_route_remote_ };
274 action_observer->OnRoutesUpdated(routes);
275 EXPECT_EQ(MediaRouterActionState::MEDIA_ROUTER_ACTION_IDLE, action_->state_);
276 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698