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

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

Issue 2176613003: [Media Router] Clean up issues related code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove some more EnumTraits calls Created 4 years 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 "base/macros.h" 5 #include "base/macros.h"
6 #include "chrome/browser/extensions/browser_action_test_util.h" 6 #include "chrome/browser/extensions/browser_action_test_util.h"
7 #include "chrome/browser/extensions/extension_action_test_util.h" 7 #include "chrome/browser/extensions/extension_action_test_util.h"
8 #include "chrome/browser/ui/browser_commands.h" 8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/browser/ui/toolbar/media_router_action.h" 10 #include "chrome/browser/ui/toolbar/media_router_action.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 MediaRouterDialogControllerImpl* controller_; 75 MediaRouterDialogControllerImpl* controller_;
76 MediaRouterActionPlatformDelegate* platform_delegate_; 76 MediaRouterActionPlatformDelegate* platform_delegate_;
77 }; 77 };
78 78
79 class MediaRouterActionUnitTest : public MediaRouterWebUITest { 79 class MediaRouterActionUnitTest : public MediaRouterWebUITest {
80 public: 80 public:
81 MediaRouterActionUnitTest() 81 MediaRouterActionUnitTest()
82 : MediaRouterWebUITest(true), 82 : MediaRouterWebUITest(true),
83 toolbar_model_(nullptr), 83 toolbar_model_(nullptr),
84 fake_issue_notification_(media_router::Issue( 84 fake_issue_notification_(media_router::IssueInfo(
85 "title notification", 85 "title notification",
86 "message notification", 86 media_router::IssueInfo::Action::DISMISS,
87 media_router::IssueAction(media_router::IssueAction::TYPE_DISMISS), 87 media_router::IssueInfo::Severity::NOTIFICATION)),
88 std::vector<media_router::IssueAction>(), 88 fake_issue_warning_(media_router::IssueInfo(
89 "route_id", 89 "title warning",
90 media_router::Issue::NOTIFICATION, 90 media_router::IssueInfo::Action::LEARN_MORE,
91 false, 91 media_router::IssueInfo::Severity::WARNING)),
92 -1)), 92 fake_issue_fatal_(
93 fake_issue_warning_( 93 media_router::IssueInfo("title fatal",
94 media_router::Issue("title warning", 94 media_router::IssueInfo::Action::DISMISS,
95 "message warning", 95 media_router::IssueInfo::Severity::FATAL)),
96 media_router::IssueAction(
97 media_router::IssueAction::TYPE_LEARN_MORE),
98 std::vector<media_router::IssueAction>(),
99 "route_id",
100 media_router::Issue::WARNING,
101 false,
102 12345)),
103 fake_issue_fatal_(media_router::Issue(
104 "title fatal",
105 "message fatal",
106 media_router::IssueAction(media_router::IssueAction::TYPE_DISMISS),
107 std::vector<media_router::IssueAction>(),
108 "route_id",
109 media_router::Issue::FATAL,
110 true,
111 -1)),
112 fake_source1_("fakeSource1"), 96 fake_source1_("fakeSource1"),
113 fake_source2_("fakeSource2"), 97 fake_source2_("fakeSource2"),
114 active_icon_(GetIcon(gfx::VectorIconId::MEDIA_ROUTER_ACTIVE)), 98 active_icon_(GetIcon(gfx::VectorIconId::MEDIA_ROUTER_ACTIVE)),
115 error_icon_(GetIcon(gfx::VectorIconId::MEDIA_ROUTER_ERROR)), 99 error_icon_(GetIcon(gfx::VectorIconId::MEDIA_ROUTER_ERROR)),
116 idle_icon_(GetIcon(gfx::VectorIconId::MEDIA_ROUTER_IDLE)), 100 idle_icon_(GetIcon(gfx::VectorIconId::MEDIA_ROUTER_IDLE)),
117 warning_icon_(GetIcon(gfx::VectorIconId::MEDIA_ROUTER_WARNING)) {} 101 warning_icon_(GetIcon(gfx::VectorIconId::MEDIA_ROUTER_WARNING)) {}
118 102
119 ~MediaRouterActionUnitTest() override {} 103 ~MediaRouterActionUnitTest() override {}
120 104
121 // MediaRouterWebUITest: 105 // MediaRouterWebUITest:
(...skipping 28 matching lines...) Expand all
150 browser_action_test_util_.reset(); 134 browser_action_test_util_.reset();
151 MediaRouterWebUITest::TearDown(); 135 MediaRouterWebUITest::TearDown();
152 } 136 }
153 137
154 gfx::Image GetIcon(gfx::VectorIconId icon_id) { 138 gfx::Image GetIcon(gfx::VectorIconId icon_id) {
155 return gfx::Image(gfx::CreateVectorIcon( 139 return gfx::Image(gfx::CreateVectorIcon(
156 icon_id, MediaRouterAction::GetIconColor(icon_id))); 140 icon_id, MediaRouterAction::GetIconColor(icon_id)));
157 } 141 }
158 142
159 TestMediaRouterAction* action() { return action_.get(); } 143 TestMediaRouterAction* action() { return action_.get(); }
160 const media_router::Issue* fake_issue_notification() { 144 const media_router::Issue& fake_issue_notification() {
161 return &fake_issue_notification_; 145 return fake_issue_notification_;
162 } 146 }
163 const media_router::Issue* fake_issue_warning() { 147 const media_router::Issue& fake_issue_warning() {
164 return &fake_issue_warning_; 148 return fake_issue_warning_;
165 } 149 }
166 const media_router::Issue* fake_issue_fatal() { 150 const media_router::Issue& fake_issue_fatal() { return fake_issue_fatal_; }
167 return &fake_issue_fatal_;
168 }
169 const gfx::Image active_icon() { return active_icon_; } 151 const gfx::Image active_icon() { return active_icon_; }
170 const gfx::Image error_icon() { return error_icon_; } 152 const gfx::Image error_icon() { return error_icon_; }
171 const gfx::Image idle_icon() { return idle_icon_; } 153 const gfx::Image idle_icon() { return idle_icon_; }
172 const gfx::Image warning_icon() { return warning_icon_; } 154 const gfx::Image warning_icon() { return warning_icon_; }
173 const std::vector<media_router::MediaRoute>& local_display_route_list() 155 const std::vector<media_router::MediaRoute>& local_display_route_list()
174 const { 156 const {
175 return local_display_route_list_; 157 return local_display_route_list_;
176 } 158 }
177 const std::vector<media_router::MediaRoute>& non_local_display_route_list() 159 const std::vector<media_router::MediaRoute>& non_local_display_route_list()
178 const { 160 const {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 205 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
224 } 206 }
225 207
226 // Tests the MediaRouterAction icon based on updates to issues. 208 // Tests the MediaRouterAction icon based on updates to issues.
227 TEST_F(MediaRouterActionUnitTest, UpdateIssues) { 209 TEST_F(MediaRouterActionUnitTest, UpdateIssues) {
228 // Initially, there are no issues. 210 // Initially, there are no issues.
229 EXPECT_TRUE(gfx::test::AreImagesEqual( 211 EXPECT_TRUE(gfx::test::AreImagesEqual(
230 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 212 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
231 213
232 // Don't update |current_icon_| since the issue is only a notification. 214 // Don't update |current_icon_| since the issue is only a notification.
233 action()->OnIssueUpdated(fake_issue_notification()); 215 action()->OnIssue(fake_issue_notification());
234 EXPECT_TRUE(gfx::test::AreImagesEqual( 216 EXPECT_TRUE(gfx::test::AreImagesEqual(
235 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 217 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
236 218
237 // Update |current_icon_| since the issue is a warning. 219 // Update |current_icon_| since the issue is a warning.
238 action()->OnIssueUpdated(fake_issue_warning()); 220 action()->OnIssue(fake_issue_warning());
239 EXPECT_TRUE(gfx::test::AreImagesEqual( 221 EXPECT_TRUE(gfx::test::AreImagesEqual(
240 warning_icon(), action()->GetIcon(nullptr, gfx::Size()))); 222 warning_icon(), action()->GetIcon(nullptr, gfx::Size())));
241 223
242 // Update |current_icon_| since the issue is fatal. 224 // Update |current_icon_| since the issue is fatal.
243 action()->OnIssueUpdated(fake_issue_fatal()); 225 action()->OnIssue(fake_issue_fatal());
244 EXPECT_TRUE(gfx::test::AreImagesEqual( 226 EXPECT_TRUE(gfx::test::AreImagesEqual(
245 error_icon(), action()->GetIcon(nullptr, gfx::Size()))); 227 error_icon(), action()->GetIcon(nullptr, gfx::Size())));
246 228
247 // Clear the issue. 229 // Clear the issue.
248 action()->OnIssueUpdated(nullptr); 230 action()->OnIssuesCleared();
249 EXPECT_TRUE(gfx::test::AreImagesEqual(idle_icon(), 231 EXPECT_TRUE(gfx::test::AreImagesEqual(idle_icon(),
250 action()->GetIcon(nullptr, gfx::Size()))); 232 action()->GetIcon(nullptr, gfx::Size())));
251 } 233 }
252 234
253 // Tests the MediaRouterAction state updates based on whether there are local 235 // Tests the MediaRouterAction state updates based on whether there are local
254 // routes. 236 // routes.
255 TEST_F(MediaRouterActionUnitTest, UpdateRoutes) { 237 TEST_F(MediaRouterActionUnitTest, UpdateRoutes) {
256 // Initially, there are no routes. 238 // Initially, there are no routes.
257 EXPECT_TRUE(gfx::test::AreImagesEqual( 239 EXPECT_TRUE(gfx::test::AreImagesEqual(
258 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 240 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
(...skipping 16 matching lines...) Expand all
275 } 257 }
276 258
277 // Tests the MediaRouterAction icon based on updates to both issues and routes. 259 // Tests the MediaRouterAction icon based on updates to both issues and routes.
278 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) { 260 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) {
279 // Initially, there are no issues or routes. 261 // Initially, there are no issues or routes.
280 EXPECT_TRUE(gfx::test::AreImagesEqual( 262 EXPECT_TRUE(gfx::test::AreImagesEqual(
281 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 263 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
282 264
283 // There is no change in |current_icon_| since notification issues do not 265 // There is no change in |current_icon_| since notification issues do not
284 // update the state. 266 // update the state.
285 action()->OnIssueUpdated(fake_issue_notification()); 267 action()->OnIssue(fake_issue_notification());
286 EXPECT_TRUE(gfx::test::AreImagesEqual( 268 EXPECT_TRUE(gfx::test::AreImagesEqual(
287 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 269 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
288 270
289 // Non-local routes also do not have an effect on |current_icon_|. 271 // Non-local routes also do not have an effect on |current_icon_|.
290 action()->OnRoutesUpdated(non_local_display_route_list(), 272 action()->OnRoutesUpdated(non_local_display_route_list(),
291 empty_route_id_list()); 273 empty_route_id_list());
292 EXPECT_TRUE(gfx::test::AreImagesEqual( 274 EXPECT_TRUE(gfx::test::AreImagesEqual(
293 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 275 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
294 276
295 // Update |current_icon_| since there is a local route. 277 // Update |current_icon_| since there is a local route.
296 action()->OnRoutesUpdated(local_display_route_list(), empty_route_id_list()); 278 action()->OnRoutesUpdated(local_display_route_list(), empty_route_id_list());
297 EXPECT_TRUE(gfx::test::AreImagesEqual( 279 EXPECT_TRUE(gfx::test::AreImagesEqual(
298 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); 280 active_icon(), action()->GetIcon(nullptr, gfx::Size())));
299 281
300 // Update |current_icon_|, with a priority to reflect the warning issue 282 // Update |current_icon_|, with a priority to reflect the warning issue
301 // rather than the local route. 283 // rather than the local route.
302 action()->OnIssueUpdated(fake_issue_warning()); 284 action()->OnIssue(fake_issue_warning());
303 EXPECT_TRUE(gfx::test::AreImagesEqual( 285 EXPECT_TRUE(gfx::test::AreImagesEqual(
304 warning_icon(), action()->GetIcon(nullptr, gfx::Size()))); 286 warning_icon(), action()->GetIcon(nullptr, gfx::Size())));
305 287
306 // Closing a local route makes no difference to |current_icon_|. 288 // Closing a local route makes no difference to |current_icon_|.
307 action()->OnRoutesUpdated(non_local_display_route_list(), 289 action()->OnRoutesUpdated(non_local_display_route_list(),
308 empty_route_id_list()); 290 empty_route_id_list());
309 EXPECT_TRUE(gfx::test::AreImagesEqual( 291 EXPECT_TRUE(gfx::test::AreImagesEqual(
310 warning_icon(), action()->GetIcon(nullptr, gfx::Size()))); 292 warning_icon(), action()->GetIcon(nullptr, gfx::Size())));
311 293
312 // Update |current_icon_| since the issue has been updated to fatal. 294 // Update |current_icon_| since the issue has been updated to fatal.
313 action()->OnIssueUpdated(fake_issue_fatal()); 295 action()->OnIssue(fake_issue_fatal());
314 EXPECT_TRUE(gfx::test::AreImagesEqual( 296 EXPECT_TRUE(gfx::test::AreImagesEqual(
315 error_icon(), action()->GetIcon(nullptr, gfx::Size()))); 297 error_icon(), action()->GetIcon(nullptr, gfx::Size())));
316 298
317 // Fatal issues still take precedent over local routes. 299 // Fatal issues still take precedent over local routes.
318 action()->OnRoutesUpdated(local_display_route_list(), empty_route_id_list()); 300 action()->OnRoutesUpdated(local_display_route_list(), empty_route_id_list());
319 EXPECT_TRUE(gfx::test::AreImagesEqual( 301 EXPECT_TRUE(gfx::test::AreImagesEqual(
320 error_icon(), action()->GetIcon(nullptr, gfx::Size()))); 302 error_icon(), action()->GetIcon(nullptr, gfx::Size())));
321 303
322 // When the fatal issue is dismissed, |current_icon_| reflects the existing 304 // When the fatal issue is dismissed, |current_icon_| reflects the existing
323 // local route. 305 // local route.
324 action()->OnIssueUpdated(nullptr); 306 action()->OnIssuesCleared();
325 EXPECT_TRUE(gfx::test::AreImagesEqual( 307 EXPECT_TRUE(gfx::test::AreImagesEqual(
326 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); 308 active_icon(), action()->GetIcon(nullptr, gfx::Size())));
327 309
328 // Update |current_icon_| when the local route is closed. 310 // Update |current_icon_| when the local route is closed.
329 action()->OnRoutesUpdated(non_local_display_route_list(), 311 action()->OnRoutesUpdated(non_local_display_route_list(),
330 empty_route_id_list()); 312 empty_route_id_list());
331 EXPECT_TRUE(gfx::test::AreImagesEqual( 313 EXPECT_TRUE(gfx::test::AreImagesEqual(
332 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 314 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
333 } 315 }
334 316
(...skipping 28 matching lines...) Expand all
363 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); 345 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1);
364 action()->ExecuteAction(true); 346 action()->ExecuteAction(true);
365 EXPECT_FALSE(dialog_controller->IsShowingMediaRouterDialog()); 347 EXPECT_FALSE(dialog_controller->IsShowingMediaRouterDialog());
366 348
367 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1); 349 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1);
368 dialog_controller->CreateMediaRouterDialog(); 350 dialog_controller->CreateMediaRouterDialog();
369 351
370 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); 352 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1);
371 dialog_controller->HideMediaRouterDialog(); 353 dialog_controller->HideMediaRouterDialog();
372 } 354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698