Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" | 11 #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" | 12 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h" |
| 13 #include "chrome/browser/ui/webui/media_router/media_router_web_ui_test.h" | 13 #include "chrome/browser/ui/webui/media_router/media_router_web_ui_test.h" |
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "content/public/browser/site_instance.h" | 15 #include "content/public/browser/site_instance.h" |
| 16 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/gfx/color_palette.h" | 19 #include "ui/gfx/color_palette.h" |
| 20 #include "ui/gfx/image/image_unittest_util.h" | 20 #include "ui/gfx/image/image_unittest_util.h" |
| 21 #include "ui/gfx/paint_vector_icon.h" | 21 #include "ui/gfx/paint_vector_icon.h" |
| 22 | 22 |
| 23 using content::WebContents; | 23 using content::WebContents; |
| 24 using media_router::MediaRouterDialogControllerImpl; | 24 using media_router::MediaRouterDialogControllerImpl; |
| 25 using testing::Return; | |
| 26 | |
| 27 class MockToolbarActionsBar : public ToolbarActionsBar { | |
| 28 public: | |
| 29 MockToolbarActionsBar(ToolbarActionsBarDelegate* delegate, Browser* browser) | |
| 30 : ToolbarActionsBar(delegate, browser, nullptr) {} | |
| 31 ~MockToolbarActionsBar() override {} | |
| 32 | |
| 33 MOCK_METHOD0(UndoPopOut, void()); | |
| 34 MOCK_METHOD0(popped_out_action, ToolbarActionViewController*()); | |
| 35 }; | |
| 25 | 36 |
| 26 class MockToolbarActionViewDelegate : public ToolbarActionViewDelegate { | 37 class MockToolbarActionViewDelegate : public ToolbarActionViewDelegate { |
| 27 public: | 38 public: |
| 28 MockToolbarActionViewDelegate() {} | 39 MockToolbarActionViewDelegate() {} |
| 29 ~MockToolbarActionViewDelegate() {} | 40 ~MockToolbarActionViewDelegate() {} |
| 30 | 41 |
| 31 MOCK_CONST_METHOD0(GetCurrentWebContents, WebContents*()); | 42 MOCK_CONST_METHOD0(GetCurrentWebContents, WebContents*()); |
| 32 MOCK_METHOD0(UpdateState, void()); | 43 MOCK_METHOD0(UpdateState, void()); |
| 33 MOCK_CONST_METHOD0(IsMenuRunning, bool()); | 44 MOCK_CONST_METHOD0(IsMenuRunning, bool()); |
| 34 MOCK_METHOD1(OnPopupShown, void(bool by_user)); | 45 MOCK_METHOD1(OnPopupShown, void(bool by_user)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 void SetUp() override { | 117 void SetUp() override { |
| 107 MediaRouterWebUITest::SetUp(); | 118 MediaRouterWebUITest::SetUp(); |
| 108 toolbar_model_ = | 119 toolbar_model_ = |
| 109 extensions::extension_action_test_util::CreateToolbarModelForProfile( | 120 extensions::extension_action_test_util::CreateToolbarModelForProfile( |
| 110 profile()); | 121 profile()); |
| 111 | 122 |
| 112 // browser() will only be valid once BrowserWithTestWindowTest::SetUp() | 123 // browser() will only be valid once BrowserWithTestWindowTest::SetUp() |
| 113 // has run. | 124 // has run. |
| 114 browser_action_test_util_.reset( | 125 browser_action_test_util_.reset( |
| 115 new BrowserActionTestUtil(browser(), false)); | 126 new BrowserActionTestUtil(browser(), false)); |
| 116 action_.reset( | 127 action_.reset(new TestMediaRouterAction(browser(), GetActionsBar())); |
| 117 new TestMediaRouterAction( | |
| 118 browser(), | |
| 119 browser_action_test_util_->GetToolbarActionsBar())); | |
| 120 | 128 |
| 121 local_display_route_list_.push_back( | 129 local_display_route_list_.push_back( |
| 122 media_router::MediaRoute("routeId1", fake_source1_, "sinkId1", | 130 media_router::MediaRoute("routeId1", fake_source1_, "sinkId1", |
| 123 "description", true, std::string(), true)); | 131 "description", true, std::string(), true)); |
| 124 non_local_display_route_list_.push_back( | 132 non_local_display_route_list_.push_back( |
| 125 media_router::MediaRoute("routeId2", fake_source1_, "sinkId2", | 133 media_router::MediaRoute("routeId2", fake_source1_, "sinkId2", |
| 126 "description", false, std::string(), true)); | 134 "description", false, std::string(), true)); |
| 127 non_local_display_route_list_.push_back( | 135 non_local_display_route_list_.push_back( |
| 128 media_router::MediaRoute("routeId3", fake_source2_, "sinkId3", | 136 media_router::MediaRoute("routeId3", fake_source2_, "sinkId3", |
| 129 "description", true, std::string(), false)); | 137 "description", true, std::string(), false)); |
| 130 } | 138 } |
| 131 | 139 |
| 132 void TearDown() override { | 140 void TearDown() override { |
| 133 action_.reset(); | 141 action_.reset(); |
| 134 browser_action_test_util_.reset(); | 142 browser_action_test_util_.reset(); |
| 135 MediaRouterWebUITest::TearDown(); | 143 MediaRouterWebUITest::TearDown(); |
| 136 } | 144 } |
| 137 | 145 |
| 138 gfx::Image GetIcon(gfx::VectorIconId icon_id) { | 146 gfx::Image GetIcon(gfx::VectorIconId icon_id) { |
| 139 return gfx::Image(gfx::CreateVectorIcon( | 147 return gfx::Image(gfx::CreateVectorIcon( |
| 140 icon_id, MediaRouterAction::GetIconColor(icon_id))); | 148 icon_id, MediaRouterAction::GetIconColor(icon_id))); |
| 141 } | 149 } |
| 142 | 150 |
| 151 ToolbarActionsBar* GetActionsBar() { | |
| 152 return browser_action_test_util_->GetToolbarActionsBar(); | |
| 153 } | |
| 154 | |
| 143 TestMediaRouterAction* action() { return action_.get(); } | 155 TestMediaRouterAction* action() { return action_.get(); } |
| 156 ToolbarActionsModel* toolbar_model() { return toolbar_model_; } | |
| 144 const media_router::Issue& fake_issue_notification() { | 157 const media_router::Issue& fake_issue_notification() { |
| 145 return fake_issue_notification_; | 158 return fake_issue_notification_; |
| 146 } | 159 } |
| 147 const media_router::Issue& fake_issue_warning() { | 160 const media_router::Issue& fake_issue_warning() { |
| 148 return fake_issue_warning_; | 161 return fake_issue_warning_; |
| 149 } | 162 } |
| 150 const media_router::Issue& fake_issue_fatal() { return fake_issue_fatal_; } | 163 const media_router::Issue& fake_issue_fatal() { return fake_issue_fatal_; } |
| 151 const gfx::Image active_icon() { return active_icon_; } | 164 const gfx::Image active_icon() { return active_icon_; } |
| 152 const gfx::Image error_icon() { return error_icon_; } | 165 const gfx::Image error_icon() { return error_icon_; } |
| 153 const gfx::Image idle_icon() { return idle_icon_; } | 166 const gfx::Image idle_icon() { return idle_icon_; } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); | 358 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); |
| 346 action()->ExecuteAction(true); | 359 action()->ExecuteAction(true); |
| 347 EXPECT_FALSE(dialog_controller->IsShowingMediaRouterDialog()); | 360 EXPECT_FALSE(dialog_controller->IsShowingMediaRouterDialog()); |
| 348 | 361 |
| 349 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1); | 362 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1); |
| 350 dialog_controller->CreateMediaRouterDialog(); | 363 dialog_controller->CreateMediaRouterDialog(); |
| 351 | 364 |
| 352 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); | 365 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); |
| 353 dialog_controller->HideMediaRouterDialog(); | 366 dialog_controller->HideMediaRouterDialog(); |
| 354 } | 367 } |
| 368 | |
| 369 TEST_F(MediaRouterActionUnitTest, UndoPopOutOnContextMenuClosed) { | |
| 370 MockToolbarActionsBar mock_actions_bar(GetActionsBar()->delegate_for_test(), | |
| 371 browser()); | |
| 372 TestMediaRouterAction media_router_action(browser(), &mock_actions_bar); | |
| 373 chrome::NewTab(browser()); | |
| 374 MediaRouterDialogControllerImpl* dialog_controller = | |
| 375 MediaRouterDialogControllerImpl::GetOrCreateForWebContents( | |
| 376 browser()->tab_strip_model()->GetActiveWebContents()); | |
| 377 media_router_action.SetMediaRouterDialogController(dialog_controller); | |
| 378 | |
| 379 // If the media router action is popped out when closing its context menu, | |
| 380 // then it should go back into the overflow menu. | |
| 381 EXPECT_CALL(mock_actions_bar, popped_out_action()) | |
|
Devlin
2016/12/15 22:25:26
I'm not a big fan of using mocks like this, becaus
| |
| 382 .WillOnce(Return(&media_router_action)); | |
| 383 EXPECT_CALL(mock_actions_bar, UndoPopOut()).Times(1); | |
| 384 media_router_action.OnContextMenuClosed(); | |
| 385 } | |
| OLD | NEW |