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

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

Issue 2332693003: Show media router toolbar icon ephemerally for active local routes and issues (Closed)
Patch Set: Created 4 years, 3 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 <memory>
6 #include <string>
7 #include <vector>
8
9 #include "base/auto_reset.h"
10 #include "base/command_line.h"
5 #include "base/macros.h" 11 #include "base/macros.h"
6 #include "chrome/browser/extensions/browser_action_test_util.h" 12 #include "chrome/browser/extensions/browser_action_test_util.h"
7 #include "chrome/browser/extensions/extension_action_test_util.h" 13 #include "chrome/browser/extensions/extension_action_test_util.h"
8 #include "chrome/browser/ui/browser_commands.h" 14 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
10 #include "chrome/browser/ui/toolbar/media_router_action.h" 17 #include "chrome/browser/ui/toolbar/media_router_action.h"
11 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" 18 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h"
12 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h" 19 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h"
13 #include "chrome/browser/ui/webui/media_router/media_router_test.h" 20 #include "chrome/browser/ui/webui/media_router/media_router_test.h"
14 #include "chrome/grit/generated_resources.h" 21 #include "chrome/grit/generated_resources.h"
15 #include "content/public/browser/site_instance.h" 22 #include "content/public/browser/site_instance.h"
16 #include "content/public/test/test_utils.h" 23 #include "content/public/test/test_utils.h"
17 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
18 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/gfx/color_palette.h" 26 #include "ui/gfx/color_palette.h"
(...skipping 17 matching lines...) Expand all
37 44
38 class TestMediaRouterAction : public MediaRouterAction { 45 class TestMediaRouterAction : public MediaRouterAction {
39 public: 46 public:
40 TestMediaRouterAction(Browser* browser, 47 TestMediaRouterAction(Browser* browser,
41 ToolbarActionsBar* toolbar_actions_bar) 48 ToolbarActionsBar* toolbar_actions_bar)
42 : MediaRouterAction(browser, toolbar_actions_bar), 49 : MediaRouterAction(browser, toolbar_actions_bar),
43 controller_(nullptr), 50 controller_(nullptr),
44 platform_delegate_(nullptr) {} 51 platform_delegate_(nullptr) {}
45 ~TestMediaRouterAction() override {} 52 ~TestMediaRouterAction() override {}
46 53
54 void ActiveTabChanged(content::WebContents* old_contents,
55 content::WebContents* new_contents,
imcheng 2016/09/16 21:47:49 nit: please fix indent
takumif 2016/09/20 14:50:46 Done.
56 int index,
57 int reason) override {
58 // This would be null if |controller_| hasn't been set.
59 if (GetMediaRouterDialogController()) {
60 MediaRouterAction::ActiveTabChanged(
61 old_contents, new_contents, index, reason);
62 }
63 }
64
47 void SetMediaRouterDialogController( 65 void SetMediaRouterDialogController(
48 MediaRouterDialogControllerImpl* controller) { 66 MediaRouterDialogControllerImpl* controller) {
49 DCHECK(controller); 67 DCHECK(controller);
50 controller_ = controller; 68 controller_ = controller;
69 controller_->SetMediaRouterAction(GetWeakPtr());
imcheng 2016/09/16 21:47:49 Is this needed if you don't call SetDelegate a sec
takumif 2016/09/20 14:50:46 No, this is not necessary. Removing.
51 } 70 }
52 71
53 private: 72 private:
54 MediaRouterDialogControllerImpl* GetMediaRouterDialogController() 73 MediaRouterDialogControllerImpl* GetMediaRouterDialogController()
55 override { 74 override {
56 return controller_; 75 return controller_;
57 } 76 }
58 77
59 MediaRouterActionPlatformDelegate* GetPlatformDelegate() override { 78 MediaRouterActionPlatformDelegate* GetPlatformDelegate() override {
60 return platform_delegate_; 79 return platform_delegate_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 warning_icon_( 127 warning_icon_(
109 gfx::CreateVectorIcon(gfx::VectorIconId::MEDIA_ROUTER_WARNING, 128 gfx::CreateVectorIcon(gfx::VectorIconId::MEDIA_ROUTER_WARNING,
110 gfx::kPlaceholderColor)) {} 129 gfx::kPlaceholderColor)) {}
111 130
112 ~MediaRouterActionUnitTest() override {} 131 ~MediaRouterActionUnitTest() override {}
113 132
114 // MediaRouterTest: 133 // MediaRouterTest:
115 void SetUp() override { 134 void SetUp() override {
116 MediaRouterTest::SetUp(); 135 MediaRouterTest::SetUp();
117 toolbar_model_ = extensions::extension_action_test_util:: 136 toolbar_model_ = extensions::extension_action_test_util::
118 CreateToolbarModelForProfileWithoutWaitingForReady(profile()); 137 CreateToolbarModelForProfile(profile());
119 138
120 // browser() will only be valid once BrowserWithTestWindowTest::SetUp() 139 // browser() will only be valid once BrowserWithTestWindowTest::SetUp()
121 // has run. 140 // has run.
122 browser_action_test_util_.reset( 141 browser_action_test_util_.reset(
123 new BrowserActionTestUtil(browser(), false)); 142 new BrowserActionTestUtil(browser(), false));
124 action_.reset( 143 action_.reset(
125 new TestMediaRouterAction( 144 new TestMediaRouterAction(
126 browser(), 145 browser(),
127 browser_action_test_util_->GetToolbarActionsBar())); 146 browser_action_test_util_->GetToolbarActionsBar()));
128 147
148 action()->SetDelegate(new MockToolbarActionViewDelegate());
149
129 local_display_route_list_.push_back( 150 local_display_route_list_.push_back(
130 media_router::MediaRoute("routeId1", fake_source1_, "sinkId1", 151 media_router::MediaRoute("routeId1", fake_source1_, "sinkId1",
131 "description", true, std::string(), true)); 152 "description", true, std::string(), true));
132 non_local_display_route_list_.push_back( 153 non_local_display_route_list_.push_back(
133 media_router::MediaRoute("routeId2", fake_source1_, "sinkId2", 154 media_router::MediaRoute("routeId2", fake_source1_, "sinkId2",
134 "description", false, std::string(), true)); 155 "description", false, std::string(), true));
135 non_local_display_route_list_.push_back( 156 non_local_display_route_list_.push_back(
136 media_router::MediaRoute("routeId3", fake_source2_, "sinkId3", 157 media_router::MediaRoute("routeId3", fake_source2_, "sinkId3",
137 "description", true, std::string(), false)); 158 "description", true, std::string(), false));
138 } 159 }
139 160
140 void TearDown() override { 161 void TearDown() override {
162 action_.reset();
141 browser_action_test_util_.reset(); 163 browser_action_test_util_.reset();
142 action_.reset();
143 MediaRouterTest::TearDown(); 164 MediaRouterTest::TearDown();
144 } 165 }
145 166
146 TestMediaRouterAction* action() { return action_.get(); } 167 TestMediaRouterAction* action() { return action_.get(); }
147 const media_router::Issue* fake_issue_notification() { 168 const media_router::Issue* fake_issue_notification() {
148 return &fake_issue_notification_; 169 return &fake_issue_notification_;
149 } 170 }
150 const media_router::Issue* fake_issue_warning() { 171 const media_router::Issue* fake_issue_warning() {
151 return &fake_issue_warning_; 172 return &fake_issue_warning_;
152 } 173 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); 334 active_icon(), action()->GetIcon(nullptr, gfx::Size())));
314 335
315 // Update |current_icon_| when the local route is closed. 336 // Update |current_icon_| when the local route is closed.
316 action()->OnRoutesUpdated(non_local_display_route_list(), 337 action()->OnRoutesUpdated(non_local_display_route_list(),
317 empty_route_id_list()); 338 empty_route_id_list());
318 EXPECT_TRUE(gfx::test::AreImagesEqual( 339 EXPECT_TRUE(gfx::test::AreImagesEqual(
319 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); 340 idle_icon(), action()->GetIcon(nullptr, gfx::Size())));
320 } 341 }
321 342
322 TEST_F(MediaRouterActionUnitTest, IconPressedState) { 343 TEST_F(MediaRouterActionUnitTest, IconPressedState) {
344 base::AutoReset<bool> disable_animations(
imcheng 2016/09/16 21:47:49 Please add comments on why this is needed?
takumif 2016/09/20 14:50:46 This is no longer necessary. Removed.
345 &ToolbarActionsBar::disable_animations_for_testing_, true);
346
323 // Start with one window with one tab. 347 // Start with one window with one tab.
324 EXPECT_EQ(0, browser()->tab_strip_model()->count()); 348 EXPECT_EQ(0, browser()->tab_strip_model()->count());
325 chrome::NewTab(browser()); 349 chrome::NewTab(browser());
326 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 350 EXPECT_EQ(1, browser()->tab_strip_model()->count());
327 351
328 // Create a reference to initiator contents. 352 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents();
329 WebContents* initiator_ = 353 MediaRouterDialogControllerImpl::CreateForWebContents(initiator);
330 browser()->tab_strip_model()->GetActiveWebContents(); 354 MediaRouterDialogControllerImpl* dialog_controller =
331 355 MediaRouterDialogControllerImpl::FromWebContents(initiator);
332 MediaRouterDialogControllerImpl::CreateForWebContents(initiator_); 356 ASSERT_TRUE(dialog_controller);
333 MediaRouterDialogControllerImpl* dialog_controller_ =
334 MediaRouterDialogControllerImpl::FromWebContents(initiator_);
335 ASSERT_TRUE(dialog_controller_);
336 357
337 // Sets the controller to use for TestMediaRouterAction. 358 // Sets the controller to use for TestMediaRouterAction.
338 action()->SetMediaRouterDialogController(dialog_controller_); 359 action()->SetMediaRouterDialogController(dialog_controller);
339 360
340 // Create a ToolbarActionViewDelegate to use for MediaRouterAction. 361 // Create a ToolbarActionViewDelegate to use for MediaRouterAction.
341 std::unique_ptr<MockToolbarActionViewDelegate> mock_delegate( 362 std::unique_ptr<MockToolbarActionViewDelegate> mock_delegate(
342 new MockToolbarActionViewDelegate()); 363 new MockToolbarActionViewDelegate());
343
344 EXPECT_CALL(*mock_delegate, GetCurrentWebContents()).WillOnce(
345 testing::Return(initiator_));
346 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1);
347 action()->SetDelegate(mock_delegate.get()); 364 action()->SetDelegate(mock_delegate.get());
imcheng 2016/09/16 21:47:49 You changed the test to call SetDelegate() during
takumif 2016/09/20 14:50:46 Removed the first call.
348 365
349 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1);
350 action()->ExecuteAction(true); 366 action()->ExecuteAction(true);
367 EXPECT_TRUE(dialog_controller->IsShowingMediaRouterDialog());
351 368
352 // Pressing the icon while the popup is shown should close the popup 369 // Pressing the icon while the popup is shown should close the popup
353 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1);
354 action()->ExecuteAction(true); 370 action()->ExecuteAction(true);
371 EXPECT_FALSE(dialog_controller->IsShowingMediaRouterDialog());
355 372
356 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1); 373 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1);
357 dialog_controller_->CreateMediaRouterDialog(); 374 dialog_controller->CreateMediaRouterDialog();
358 375
359 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); 376 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1);
360 dialog_controller_->HideMediaRouterDialog(); 377 dialog_controller->HideMediaRouterDialog();
361 } 378 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698