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

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

Issue 1648713004: [Media Router] Fix regression with icon not turning blue after casting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 4 years, 10 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 "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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 CreateToolbarModelForProfileWithoutWaitingForReady(profile()); 116 CreateToolbarModelForProfileWithoutWaitingForReady(profile());
117 117
118 // browser() will only be valid once BrowserWithTestWindowTest::SetUp() 118 // browser() will only be valid once BrowserWithTestWindowTest::SetUp()
119 // has run. 119 // has run.
120 browser_action_test_util_.reset( 120 browser_action_test_util_.reset(
121 new BrowserActionTestUtil(browser(), false)); 121 new BrowserActionTestUtil(browser(), false));
122 action_.reset( 122 action_.reset(
123 new TestMediaRouterAction( 123 new TestMediaRouterAction(
124 browser(), 124 browser(),
125 browser_action_test_util_->GetToolbarActionsBar())); 125 browser_action_test_util_->GetToolbarActionsBar()));
126
127 local_display_route_list_.push_back(media_router::MediaRoute(
128 "routeId1", fake_source1_, "sinkId1", "description", true, "", true));
Peter Kasting 2016/01/30 00:52:19 Nit: "" -> std::string()
imcheng 2016/02/01 18:48:07 Done.
129 non_local_display_route_list_.push_back(media_router::MediaRoute(
130 "routeId2", fake_source1_, "sinkId2", "description", false, "", true));
131 non_local_display_route_list_.push_back(media_router::MediaRoute(
132 "routeId3", fake_source2_, "sinkId3", "description", true, "", false));
126 } 133 }
127 134
128 void TearDown() override { 135 void TearDown() override {
129 browser_action_test_util_.reset(); 136 browser_action_test_util_.reset();
130 action_.reset(); 137 action_.reset();
131 MediaRouterTest::TearDown(); 138 MediaRouterTest::TearDown();
132 } 139 }
133 140
134 TestMediaRouterAction* action() { return action_.get(); } 141 TestMediaRouterAction* action() { return action_.get(); }
135 const media_router::Issue* fake_issue_notification() { 142 const media_router::Issue* fake_issue_notification() {
136 return &fake_issue_notification_; 143 return &fake_issue_notification_;
137 } 144 }
138 const media_router::Issue* fake_issue_warning() { 145 const media_router::Issue* fake_issue_warning() {
139 return &fake_issue_warning_; 146 return &fake_issue_warning_;
140 } 147 }
141 const media_router::Issue* fake_issue_fatal() { 148 const media_router::Issue* fake_issue_fatal() {
142 return &fake_issue_fatal_; 149 return &fake_issue_fatal_;
143 } 150 }
144 const gfx::Image active_icon() { return active_icon_; } 151 const gfx::Image active_icon() { return active_icon_; }
145 const gfx::Image error_icon() { return error_icon_; } 152 const gfx::Image error_icon() { return error_icon_; }
146 const gfx::Image idle_icon() { return idle_icon_; } 153 const gfx::Image idle_icon() { return idle_icon_; }
147 const gfx::Image warning_icon() { return warning_icon_; } 154 const gfx::Image warning_icon() { return warning_icon_; }
148 155
156 protected:
157 std::vector<media_router::MediaRoute> local_display_route_list_;
158 std::vector<media_router::MediaRoute> non_local_display_route_list_;
159 std::vector<media_router::MediaRoute::Id> empty_route_id_list_;
Peter Kasting 2016/01/30 00:52:19 Nit: The Google style guide discourages protected
imcheng 2016/02/01 18:48:07 Done.
160
149 private: 161 private:
150 // A BrowserActionTestUtil object constructed with the associated 162 // A BrowserActionTestUtil object constructed with the associated
151 // ToolbarActionsBar. 163 // ToolbarActionsBar.
152 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; 164 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_;
153 165
154 scoped_ptr<TestMediaRouterAction> action_; 166 scoped_ptr<TestMediaRouterAction> action_;
155 167
156 // The associated ToolbarActionsModel (owned by the keyed service setup). 168 // The associated ToolbarActionsModel (owned by the keyed service setup).
157 ToolbarActionsModel* toolbar_model_; 169 ToolbarActionsModel* toolbar_model_;
158 170
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 223 }
212 224
213 // Tests the MediaRouterAction state updates based on whether there are local 225 // Tests the MediaRouterAction state updates based on whether there are local
214 // routes. 226 // routes.
215 TEST_F(MediaRouterActionUnitTest, UpdateRoutes) { 227 TEST_F(MediaRouterActionUnitTest, UpdateRoutes) {
216 // Initially, there are no routes. 228 // Initially, there are no routes.
217 EXPECT_TRUE(gfx::test::AreImagesEqual( 229 EXPECT_TRUE(gfx::test::AreImagesEqual(
218 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 230 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
219 231
220 // Update |current_icon_| since there is a local route. 232 // Update |current_icon_| since there is a local route.
221 action()->OnHasLocalDisplayRouteUpdated(true); 233 action()->OnRoutesUpdated(local_display_route_list_, empty_route_id_list_);
222 EXPECT_TRUE(gfx::test::AreImagesEqual( 234 EXPECT_TRUE(gfx::test::AreImagesEqual(
223 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); 235 active_icon(), action()->GetIcon(nullptr, gfx::Size())));
224 236
225 // Update |current_icon_| since there are no local routes. 237 // Update |current_icon_| since there are no local routes.
226 action()->OnHasLocalDisplayRouteUpdated(false); 238 action()->OnRoutesUpdated(non_local_display_route_list_,
239 empty_route_id_list_);
240 EXPECT_TRUE(gfx::test::AreImagesEqual(
241 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
242
243 action()->OnRoutesUpdated(std::vector<media_router::MediaRoute>(),
244 empty_route_id_list_);
227 EXPECT_TRUE(gfx::test::AreImagesEqual( 245 EXPECT_TRUE(gfx::test::AreImagesEqual(
228 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 246 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
229 } 247 }
230 248
231 // Tests the MediaRouterAction icon based on updates to both issues and routes. 249 // Tests the MediaRouterAction icon based on updates to both issues and routes.
232 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) { 250 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) {
233 // Initially, there are no issues or routes. 251 // Initially, there are no issues or routes.
234 EXPECT_TRUE(gfx::test::AreImagesEqual( 252 EXPECT_TRUE(gfx::test::AreImagesEqual(
235 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 253 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
236 254
237 // There is no change in |current_icon_| since notification issues do not 255 // There is no change in |current_icon_| since notification issues do not
238 // update the state. 256 // update the state.
239 action()->OnIssueUpdated(fake_issue_notification()); 257 action()->OnIssueUpdated(fake_issue_notification());
240 EXPECT_TRUE(gfx::test::AreImagesEqual( 258 EXPECT_TRUE(gfx::test::AreImagesEqual(
241 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 259 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
242 260
243 // Non-local routes also do not have an effect on |current_icon_|. 261 // Non-local routes also do not have an effect on |current_icon_|.
244 action()->OnHasLocalDisplayRouteUpdated(false); 262 action()->OnRoutesUpdated(non_local_display_route_list_,
263 empty_route_id_list_);
245 EXPECT_TRUE(gfx::test::AreImagesEqual( 264 EXPECT_TRUE(gfx::test::AreImagesEqual(
246 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 265 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
247 266
248 // Update |current_icon_| since there is a local route. 267 // Update |current_icon_| since there is a local route.
249 action()->OnHasLocalDisplayRouteUpdated(true); 268 action()->OnRoutesUpdated(local_display_route_list_, empty_route_id_list_);
250 EXPECT_TRUE(gfx::test::AreImagesEqual( 269 EXPECT_TRUE(gfx::test::AreImagesEqual(
251 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); 270 active_icon(), action()->GetIcon(nullptr, gfx::Size())));
252 271
253 // Update |current_icon_|, with a priority to reflect the warning issue 272 // Update |current_icon_|, with a priority to reflect the warning issue
254 // rather than the local route. 273 // rather than the local route.
255 action()->OnIssueUpdated(fake_issue_warning()); 274 action()->OnIssueUpdated(fake_issue_warning());
256 EXPECT_TRUE(gfx::test::AreImagesEqual( 275 EXPECT_TRUE(gfx::test::AreImagesEqual(
257 warning_icon(), action()->GetIcon(nullptr, gfx::Size()))); 276 warning_icon(), action()->GetIcon(nullptr, gfx::Size())));
258 277
259 // Closing a local route makes no difference to |current_icon_|. 278 // Closing a local route makes no difference to |current_icon_|.
260 action()->OnHasLocalDisplayRouteUpdated(false); 279 action()->OnRoutesUpdated(non_local_display_route_list_,
280 empty_route_id_list_);
261 EXPECT_TRUE(gfx::test::AreImagesEqual( 281 EXPECT_TRUE(gfx::test::AreImagesEqual(
262 warning_icon(), action()->GetIcon(nullptr, gfx::Size()))); 282 warning_icon(), action()->GetIcon(nullptr, gfx::Size())));
263 283
264 // Update |current_icon_| since the issue has been updated to fatal. 284 // Update |current_icon_| since the issue has been updated to fatal.
265 action()->OnIssueUpdated(fake_issue_fatal()); 285 action()->OnIssueUpdated(fake_issue_fatal());
266 EXPECT_TRUE(gfx::test::AreImagesEqual( 286 EXPECT_TRUE(gfx::test::AreImagesEqual(
267 error_icon(), action()->GetIcon(nullptr, gfx::Size()))); 287 error_icon(), action()->GetIcon(nullptr, gfx::Size())));
268 288
269 // Fatal issues still take precedent over local routes. 289 // Fatal issues still take precedent over local routes.
270 action()->OnHasLocalDisplayRouteUpdated(true); 290 action()->OnRoutesUpdated(local_display_route_list_, empty_route_id_list_);
271 EXPECT_TRUE(gfx::test::AreImagesEqual( 291 EXPECT_TRUE(gfx::test::AreImagesEqual(
272 error_icon(), action()->GetIcon(nullptr, gfx::Size()))); 292 error_icon(), action()->GetIcon(nullptr, gfx::Size())));
273 293
274 // When the fatal issue is dismissed, |current_icon_| reflects the existing 294 // When the fatal issue is dismissed, |current_icon_| reflects the existing
275 // local route. 295 // local route.
276 action()->OnIssueUpdated(nullptr); 296 action()->OnIssueUpdated(nullptr);
277 EXPECT_TRUE(gfx::test::AreImagesEqual( 297 EXPECT_TRUE(gfx::test::AreImagesEqual(
278 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); 298 active_icon(), action()->GetIcon(nullptr, gfx::Size())));
279 299
280 // Update |current_icon_| when the local route is closed. 300 // Update |current_icon_| when the local route is closed.
281 action()->OnHasLocalDisplayRouteUpdated(false); 301 action()->OnRoutesUpdated(non_local_display_route_list_,
302 empty_route_id_list_);
282 EXPECT_TRUE(gfx::test::AreImagesEqual( 303 EXPECT_TRUE(gfx::test::AreImagesEqual(
283 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 304 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
284 } 305 }
285 306
286 TEST_F(MediaRouterActionUnitTest, IconPressedState) { 307 TEST_F(MediaRouterActionUnitTest, IconPressedState) {
287 // Start with one window with one tab. 308 // Start with one window with one tab.
288 EXPECT_EQ(0, browser()->tab_strip_model()->count()); 309 EXPECT_EQ(0, browser()->tab_strip_model()->count());
289 chrome::NewTab(browser()); 310 chrome::NewTab(browser());
290 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 311 EXPECT_EQ(1, browser()->tab_strip_model()->count());
291 312
(...skipping 23 matching lines...) Expand all
315 336
316 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); 337 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1);
317 dialog_controller_->HideMediaRouterDialog(); 338 dialog_controller_->HideMediaRouterDialog();
318 339
319 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1); 340 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1);
320 dialog_controller_->CreateMediaRouterDialog(); 341 dialog_controller_->CreateMediaRouterDialog();
321 342
322 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); 343 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1);
323 dialog_controller_->HideMediaRouterDialog(); 344 dialog_controller_->HideMediaRouterDialog();
324 } 345 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698