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

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

Issue 1383653002: MediaRouterAction: Only observe Media Routes when there is a local route. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add const to function for MediaRouterAndroid. Created 5 years, 2 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/browser_commands.h" 5 #include "chrome/browser/ui/browser_commands.h"
6 #include "chrome/browser/ui/tabs/tab_strip_model.h" 6 #include "chrome/browser/ui/tabs/tab_strip_model.h"
7 #include "chrome/browser/ui/toolbar/media_router_action.h" 7 #include "chrome/browser/ui/toolbar/media_router_action.h"
8 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" 8 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h"
9 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h" 9 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h"
10 #include "chrome/browser/ui/webui/media_router/media_router_test.h" 10 #include "chrome/browser/ui/webui/media_router/media_router_test.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 "title fatal", 89 "title fatal",
90 "message fatal", 90 "message fatal",
91 media_router::IssueAction(media_router::IssueAction::TYPE_DISMISS), 91 media_router::IssueAction(media_router::IssueAction::TYPE_DISMISS),
92 std::vector<media_router::IssueAction>(), 92 std::vector<media_router::IssueAction>(),
93 "route_id", 93 "route_id",
94 media_router::Issue::FATAL, 94 media_router::Issue::FATAL,
95 true, 95 true,
96 std::string())), 96 std::string())),
97 fake_source1_("fakeSource1"), 97 fake_source1_("fakeSource1"),
98 fake_source2_("fakeSource2"), 98 fake_source2_("fakeSource2"),
99 fake_route_local_("route1",
100 fake_source1_,
101 "fakeSink1",
102 "desc1",
103 true,
104 "path.html",
105 false),
106 fake_route_remote_("route2",
107 fake_source2_,
108 "fakeSink2",
109 "desc2",
110 false,
111 "path.html",
112 true),
113 active_icon_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( 99 active_icon_(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
114 IDR_MEDIA_ROUTER_ACTIVE_ICON)), 100 IDR_MEDIA_ROUTER_ACTIVE_ICON)),
115 error_icon_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( 101 error_icon_(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
116 IDR_MEDIA_ROUTER_ERROR_ICON)), 102 IDR_MEDIA_ROUTER_ERROR_ICON)),
117 idle_icon_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( 103 idle_icon_(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
118 IDR_MEDIA_ROUTER_IDLE_ICON)), 104 IDR_MEDIA_ROUTER_IDLE_ICON)),
119 warning_icon_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( 105 warning_icon_(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
120 IDR_MEDIA_ROUTER_WARNING_ICON)) {} 106 IDR_MEDIA_ROUTER_WARNING_ICON)) {}
121 107
122 ~MediaRouterActionUnitTest() override {} 108 ~MediaRouterActionUnitTest() override {}
(...skipping 12 matching lines...) Expand all
135 TestMediaRouterAction* action() { return action_.get(); } 121 TestMediaRouterAction* action() { return action_.get(); }
136 const media_router::Issue* fake_issue_notification() { 122 const media_router::Issue* fake_issue_notification() {
137 return &fake_issue_notification_; 123 return &fake_issue_notification_;
138 } 124 }
139 const media_router::Issue* fake_issue_warning() { 125 const media_router::Issue* fake_issue_warning() {
140 return &fake_issue_warning_; 126 return &fake_issue_warning_;
141 } 127 }
142 const media_router::Issue* fake_issue_fatal() { 128 const media_router::Issue* fake_issue_fatal() {
143 return &fake_issue_fatal_; 129 return &fake_issue_fatal_;
144 } 130 }
145 const media_router::MediaRoute fake_route_local() {
146 return fake_route_local_;
147 }
148 const media_router::MediaRoute fake_route_remote() {
149 return fake_route_remote_;
150 }
151 const gfx::Image active_icon() { return active_icon_; } 131 const gfx::Image active_icon() { return active_icon_; }
152 const gfx::Image error_icon() { return error_icon_; } 132 const gfx::Image error_icon() { return error_icon_; }
153 const gfx::Image idle_icon() { return idle_icon_; } 133 const gfx::Image idle_icon() { return idle_icon_; }
154 const gfx::Image warning_icon() { return warning_icon_; } 134 const gfx::Image warning_icon() { return warning_icon_; }
155 135
156 private: 136 private:
157 scoped_ptr<TestMediaRouterAction> action_; 137 scoped_ptr<TestMediaRouterAction> action_;
158 138
159 // Fake Issues. 139 // Fake Issues.
160 const media_router::Issue fake_issue_notification_; 140 const media_router::Issue fake_issue_notification_;
161 const media_router::Issue fake_issue_warning_; 141 const media_router::Issue fake_issue_warning_;
162 const media_router::Issue fake_issue_fatal_; 142 const media_router::Issue fake_issue_fatal_;
163 143
164 // Fake Sources, used for the Routes. 144 // Fake Sources, used for the Routes.
165 const media_router::MediaSource fake_source1_; 145 const media_router::MediaSource fake_source1_;
166 const media_router::MediaSource fake_source2_; 146 const media_router::MediaSource fake_source2_;
167 147
168 // Fake Routes.
169 const media_router::MediaRoute fake_route_local_;
170 const media_router::MediaRoute fake_route_remote_;
171
172 // Cached images. 148 // Cached images.
173 const gfx::Image active_icon_; 149 const gfx::Image active_icon_;
174 const gfx::Image error_icon_; 150 const gfx::Image error_icon_;
175 const gfx::Image idle_icon_; 151 const gfx::Image idle_icon_;
176 const gfx::Image warning_icon_; 152 const gfx::Image warning_icon_;
177 153
178 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionUnitTest); 154 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionUnitTest);
179 }; 155 };
180 156
181 // Tests the initial state of MediaRouterAction after construction. 157 // Tests the initial state of MediaRouterAction after construction.
(...skipping 25 matching lines...) Expand all
207 action()->OnIssueUpdated(fake_issue_fatal()); 183 action()->OnIssueUpdated(fake_issue_fatal());
208 EXPECT_TRUE(gfx::test::AreImagesEqual( 184 EXPECT_TRUE(gfx::test::AreImagesEqual(
209 error_icon(), action()->GetIcon(nullptr, gfx::Size()))); 185 error_icon(), action()->GetIcon(nullptr, gfx::Size())));
210 186
211 // Clear the issue. 187 // Clear the issue.
212 action()->OnIssueUpdated(nullptr); 188 action()->OnIssueUpdated(nullptr);
213 EXPECT_TRUE(gfx::test::AreImagesEqual(idle_icon(), 189 EXPECT_TRUE(gfx::test::AreImagesEqual(idle_icon(),
214 action()->GetIcon(nullptr, gfx::Size()))); 190 action()->GetIcon(nullptr, gfx::Size())));
215 } 191 }
216 192
217 // Tests the MediaRouterAction state based on updates to routes. 193 // Tests the MediaRouterAction state based on updates on whether there are
194 // local routes.
Peter Kasting 2015/10/02 19:04:01 Nit: Grammar; should this be "state updates based
apacible 2015/10/02 20:45:48 Done.
218 TEST_F(MediaRouterActionUnitTest, UpdateRoutes) { 195 TEST_F(MediaRouterActionUnitTest, UpdateRoutes) {
219 scoped_ptr<std::vector<media_router::MediaRoute>> routes(
220 new std::vector<media_router::MediaRoute>());
221
222 // Initially, there are no routes. 196 // Initially, there are no routes.
223 EXPECT_TRUE(gfx::test::AreImagesEqual( 197 EXPECT_TRUE(gfx::test::AreImagesEqual(
224 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 198 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
225 199
226 // Update |current_icon_| since there is a local route. 200 // Update |current_icon_| since there is a local route.
227 routes->push_back(fake_route_local()); 201 action()->OnHasLocalRouteUpdated(true);
228 routes->push_back(fake_route_remote());
229 action()->OnRoutesUpdated(*routes.get());
230 EXPECT_TRUE(gfx::test::AreImagesEqual( 202 EXPECT_TRUE(gfx::test::AreImagesEqual(
231 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); 203 active_icon(), action()->GetIcon(nullptr, gfx::Size())));
232 204
233 // Update |current_icon_| since there are no more local routes. 205 // Update |current_icon_| since there are no local routes.
234 routes->clear(); 206 action()->OnHasLocalRouteUpdated(false);
235 routes->push_back(fake_route_remote());
236 action()->OnRoutesUpdated(*routes.get());
237 EXPECT_TRUE(gfx::test::AreImagesEqual(
238 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
239
240 // |current_icon_| stays the same if there are no local routes or no routes.
241 routes->clear();
242 action()->OnRoutesUpdated(*routes.get());
243 EXPECT_TRUE(gfx::test::AreImagesEqual( 207 EXPECT_TRUE(gfx::test::AreImagesEqual(
244 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 208 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
245 } 209 }
246 210
247 // Tests the MediaRouterAction icon based on updates to both issues and routes. 211 // Tests the MediaRouterAction icon based on updates to both issues and routes.
248 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) { 212 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) {
249 scoped_ptr<std::vector<media_router::MediaRoute>> routes(
250 new std::vector<media_router::MediaRoute>());
251
252 // Initially, there are no issues or routes. 213 // Initially, there are no issues or routes.
253 EXPECT_TRUE(gfx::test::AreImagesEqual( 214 EXPECT_TRUE(gfx::test::AreImagesEqual(
254 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 215 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
255 216
256 // There is no change in |current_icon_| since notification issues do not 217 // There is no change in |current_icon_| since notification issues do not
257 // update the state. 218 // update the state.
258 action()->OnIssueUpdated(fake_issue_notification()); 219 action()->OnIssueUpdated(fake_issue_notification());
259 EXPECT_TRUE(gfx::test::AreImagesEqual( 220 EXPECT_TRUE(gfx::test::AreImagesEqual(
260 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 221 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
261 222
262 // Non-local routes also do not have an effect on |current_icon_|. 223 // Non-local routes also do not have an effect on |current_icon_|.
263 routes->push_back(fake_route_remote()); 224 action()->OnHasLocalRouteUpdated(false);
264 action()->OnRoutesUpdated(*routes.get());
265 EXPECT_TRUE(gfx::test::AreImagesEqual( 225 EXPECT_TRUE(gfx::test::AreImagesEqual(
266 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 226 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
267 227
268 // Update |current_icon_| since there is a local route. 228 // Update |current_icon_| since there is a local route.
269 routes->clear(); 229 action()->OnHasLocalRouteUpdated(true);
270 routes->push_back(fake_route_local());
271 action()->OnRoutesUpdated(*routes.get());
272 EXPECT_TRUE(gfx::test::AreImagesEqual( 230 EXPECT_TRUE(gfx::test::AreImagesEqual(
273 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); 231 active_icon(), action()->GetIcon(nullptr, gfx::Size())));
274 232
275 // Update |current_icon_|, with a priority to reflect the warning issue 233 // Update |current_icon_|, with a priority to reflect the warning issue
276 // rather than the local route. 234 // rather than the local route.
277 action()->OnIssueUpdated(fake_issue_warning()); 235 action()->OnIssueUpdated(fake_issue_warning());
278 EXPECT_TRUE(gfx::test::AreImagesEqual( 236 EXPECT_TRUE(gfx::test::AreImagesEqual(
279 warning_icon(), action()->GetIcon(nullptr, gfx::Size()))); 237 warning_icon(), action()->GetIcon(nullptr, gfx::Size())));
280 238
281 // Swapping the local route for a non-local one makes no difference to the 239 // Closing a local route makes no difference to |current_icon_|.
282 // |current_icon_|. 240 action()->OnHasLocalRouteUpdated(false);
283 routes->clear();
284 routes->push_back(fake_route_remote());
285 action()->OnRoutesUpdated(*routes.get());
286 EXPECT_TRUE(gfx::test::AreImagesEqual( 241 EXPECT_TRUE(gfx::test::AreImagesEqual(
287 warning_icon(), action()->GetIcon(nullptr, gfx::Size()))); 242 warning_icon(), action()->GetIcon(nullptr, gfx::Size())));
288 243
289 // Update |current_icon_| since the issue has been updated to fatal. 244 // Update |current_icon_| since the issue has been updated to fatal.
290 action()->OnIssueUpdated(fake_issue_fatal()); 245 action()->OnIssueUpdated(fake_issue_fatal());
291 EXPECT_TRUE(gfx::test::AreImagesEqual( 246 EXPECT_TRUE(gfx::test::AreImagesEqual(
292 error_icon(), action()->GetIcon(nullptr, gfx::Size()))); 247 error_icon(), action()->GetIcon(nullptr, gfx::Size())));
293 248
294 // Fatal issues still take precedent over local routes. 249 // Fatal issues still take precedent over local routes.
295 routes->clear(); 250 action()->OnHasLocalRouteUpdated(true);
296 routes->push_back(fake_route_local());
297 action()->OnRoutesUpdated(*routes.get());
298 EXPECT_TRUE(gfx::test::AreImagesEqual( 251 EXPECT_TRUE(gfx::test::AreImagesEqual(
299 error_icon(), action()->GetIcon(nullptr, gfx::Size()))); 252 error_icon(), action()->GetIcon(nullptr, gfx::Size())));
300 253
301 // When the fatal issue is dismissed, |current_icon_| reflects the existing 254 // When the fatal issue is dismissed, |current_icon_| reflects the existing
302 // local route. 255 // local route.
303 action()->OnIssueUpdated(nullptr); 256 action()->OnIssueUpdated(nullptr);
304 EXPECT_TRUE(gfx::test::AreImagesEqual( 257 EXPECT_TRUE(gfx::test::AreImagesEqual(
305 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); 258 active_icon(), action()->GetIcon(nullptr, gfx::Size())));
306 259
307 // Update |current_icon_| when the local route is swapped out for a non-local 260 // Update |current_icon_| when the local route is closed.
308 // route. 261 action()->OnHasLocalRouteUpdated(false);
309 routes->clear();
310 routes->push_back(fake_route_remote());
311 action()->OnRoutesUpdated(*routes.get());
312 EXPECT_TRUE(gfx::test::AreImagesEqual( 262 EXPECT_TRUE(gfx::test::AreImagesEqual(
313 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 263 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
314 } 264 }
315 265
316 TEST_F(MediaRouterActionUnitTest, IconPressedState) { 266 TEST_F(MediaRouterActionUnitTest, IconPressedState) {
317 // Start with one window with one tab. 267 // Start with one window with one tab.
318 EXPECT_EQ(0, browser()->tab_strip_model()->count()); 268 EXPECT_EQ(0, browser()->tab_strip_model()->count());
319 chrome::NewTab(browser()); 269 chrome::NewTab(browser());
320 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 270 EXPECT_EQ(1, browser()->tab_strip_model()->count());
321 271
(...skipping 26 matching lines...) Expand all
348 298
349 EXPECT_CALL(*mock_delegate, OnPopupClosed()).WillOnce(testing::Return()); 299 EXPECT_CALL(*mock_delegate, OnPopupClosed()).WillOnce(testing::Return());
350 dialog_controller_->Reset(); 300 dialog_controller_->Reset();
351 301
352 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).WillOnce(testing::Return()); 302 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).WillOnce(testing::Return());
353 dialog_controller_->CreateMediaRouterDialog(); 303 dialog_controller_->CreateMediaRouterDialog();
354 304
355 EXPECT_CALL(*mock_delegate, OnPopupClosed()).WillOnce(testing::Return()); 305 EXPECT_CALL(*mock_delegate, OnPopupClosed()).WillOnce(testing::Return());
356 dialog_controller_->CloseMediaRouterDialog(); 306 dialog_controller_->CloseMediaRouterDialog();
357 } 307 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698