| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 |
| 5 #include "base/macros.h" | 7 #include "base/macros.h" |
| 6 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 7 #include "chrome/browser/extensions/browser_action_test_util.h" | 9 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 10 #include "chrome/browser/extensions/extension_action_test_util.h" |
| 8 #include "chrome/browser/signin/fake_signin_manager_builder.h" | 11 #include "chrome/browser/signin/fake_signin_manager_builder.h" |
| 9 #include "chrome/browser/signin/signin_manager_factory.h" | 12 #include "chrome/browser/signin/signin_manager_factory.h" |
| 13 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 10 #include "chrome/browser/ui/toolbar/media_router_action.h" | 14 #include "chrome/browser/ui/toolbar/media_router_action.h" |
| 11 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h" | 15 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h" |
| 12 #include "chrome/test/base/browser_with_test_window_test.h" | 16 #include "chrome/test/base/browser_with_test_window_test.h" |
| 13 | 17 |
| 14 class MediaRouterContextualMenuUnitTest : public BrowserWithTestWindowTest { | 18 class MediaRouterContextualMenuUnitTest : public BrowserWithTestWindowTest { |
| 15 public: | 19 public: |
| 16 MediaRouterContextualMenuUnitTest() {} | 20 MediaRouterContextualMenuUnitTest() {} |
| 17 ~MediaRouterContextualMenuUnitTest() override {} | 21 ~MediaRouterContextualMenuUnitTest() override {} |
| 18 | 22 |
| 19 void SetUp() override { | 23 void SetUp() override { |
| 20 BrowserWithTestWindowTest::SetUp(); | 24 BrowserWithTestWindowTest::SetUp(); |
| 25 |
| 26 toolbar_actions_model_ = |
| 27 extensions::extension_action_test_util::CreateToolbarModelForProfile( |
| 28 profile()); |
| 29 |
| 21 signin_manager_ = | 30 signin_manager_ = |
| 22 SigninManagerFactory::GetInstance()->GetForProfile(profile()); | 31 SigninManagerFactory::GetInstance()->GetForProfile(profile()); |
| 23 browser_action_test_util_.reset( | 32 browser_action_test_util_.reset( |
| 24 new BrowserActionTestUtil(browser(), false)); | 33 new BrowserActionTestUtil(browser(), false)); |
| 25 action_.reset(new MediaRouterAction(browser(), | 34 action_.reset(new MediaRouterAction(browser(), |
| 26 browser_action_test_util_->GetToolbarActionsBar())); | 35 browser_action_test_util_->GetToolbarActionsBar())); |
| 27 model_ = static_cast<ui::SimpleMenuModel*>(action_->GetContextMenu()); | 36 model_ = static_cast<ui::SimpleMenuModel*>(action_->GetContextMenu()); |
| 28 } | 37 } |
| 29 | 38 |
| 30 void TearDown() override { | 39 void TearDown() override { |
| 31 action_.reset(); | 40 action_.reset(); |
| 32 browser_action_test_util_.reset(); | 41 browser_action_test_util_.reset(); |
| 33 BrowserWithTestWindowTest::TearDown(); | 42 BrowserWithTestWindowTest::TearDown(); |
| 34 } | 43 } |
| 35 | 44 |
| 36 SigninManagerBase* signin_manager() { return signin_manager_; } | 45 SigninManagerBase* signin_manager() { return signin_manager_; } |
| 37 ui::SimpleMenuModel* model() { return model_; } | 46 ui::SimpleMenuModel* model() { return model_; } |
| 47 ToolbarActionsModel* toolbar_actions_model() { |
| 48 return toolbar_actions_model_; |
| 49 } |
| 38 | 50 |
| 39 private: | 51 private: |
| 40 std::unique_ptr<BrowserActionTestUtil> browser_action_test_util_; | 52 std::unique_ptr<BrowserActionTestUtil> browser_action_test_util_; |
| 41 std::unique_ptr<MediaRouterAction> action_; | 53 std::unique_ptr<MediaRouterAction> action_; |
| 42 SigninManagerBase* signin_manager_; | 54 SigninManagerBase* signin_manager_; |
| 43 ui::SimpleMenuModel* model_; | 55 ui::SimpleMenuModel* model_; |
| 56 ToolbarActionsModel* toolbar_actions_model_; |
| 44 | 57 |
| 45 DISALLOW_COPY_AND_ASSIGN(MediaRouterContextualMenuUnitTest); | 58 DISALLOW_COPY_AND_ASSIGN(MediaRouterContextualMenuUnitTest); |
| 46 }; | 59 }; |
| 47 | 60 |
| 48 // Tests the basic state of the contextual menu. | 61 // Tests the basic state of the contextual menu. |
| 49 TEST_F(MediaRouterContextualMenuUnitTest, Basic) { | 62 TEST_F(MediaRouterContextualMenuUnitTest, Basic) { |
| 50 int expected_number_items = 7; | 63 int expected_number_items = 7; |
| 51 | 64 |
| 52 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | 65 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 53 // On all platforms except Linux, there's an additional menu item to access | 66 // On all platforms except Linux, there's an additional menu item to access |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 121 |
| 109 menu.ExecuteCommand(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE, 0); | 122 menu.ExecuteCommand(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE, 0); |
| 110 EXPECT_TRUE(menu.IsCommandIdChecked( | 123 EXPECT_TRUE(menu.IsCommandIdChecked( |
| 111 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); | 124 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); |
| 112 | 125 |
| 113 menu.ExecuteCommand(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE, 0); | 126 menu.ExecuteCommand(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE, 0); |
| 114 EXPECT_FALSE(menu.IsCommandIdChecked( | 127 EXPECT_FALSE(menu.IsCommandIdChecked( |
| 115 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); | 128 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); |
| 116 } | 129 } |
| 117 #endif // GOOGLE_CHROME_BUILD | 130 #endif // GOOGLE_CHROME_BUILD |
| 131 |
| 132 TEST_F(MediaRouterContextualMenuUnitTest, ToggleAlwaysShowIconItem) { |
| 133 MediaRouterContextualMenu menu(browser()); |
| 134 extensions::ComponentMigrationHelper* const component_migration_helper = |
| 135 toolbar_actions_model()->component_migration_helper(); |
| 136 |
| 137 // Whether the option is checked should reflect the pref. |
| 138 component_migration_helper->SetComponentActionPref( |
| 139 ComponentToolbarActionsFactory::kMediaRouterActionId, true); |
| 140 EXPECT_TRUE( |
| 141 menu.IsCommandIdChecked(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION)); |
| 142 |
| 143 component_migration_helper->SetComponentActionPref( |
| 144 ComponentToolbarActionsFactory::kMediaRouterActionId, false); |
| 145 EXPECT_FALSE( |
| 146 menu.IsCommandIdChecked(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION)); |
| 147 |
| 148 // Executing the option should toggle the pref. |
| 149 menu.ExecuteCommand(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION, 0); |
| 150 EXPECT_TRUE(component_migration_helper->GetComponentActionPref( |
| 151 ComponentToolbarActionsFactory::kMediaRouterActionId)); |
| 152 |
| 153 menu.ExecuteCommand(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION, 0); |
| 154 EXPECT_FALSE(component_migration_helper->GetComponentActionPref( |
| 155 ComponentToolbarActionsFactory::kMediaRouterActionId)); |
| 156 } |
| OLD | NEW |