| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/component_migration_helper.h" | 10 #include "chrome/browser/extensions/component_migration_helper.h" |
| 11 #include "chrome/browser/extensions/extension_action_test_util.h" | 11 #include "chrome/browser/extensions/extension_action_test_util.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_service_test_base.h" | 13 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | |
| 16 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 17 #include "components/prefs/pref_registry_simple.h" | 16 #include "components/prefs/pref_registry_simple.h" |
| 18 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
| 19 #include "extensions/common/feature_switch.h" | 18 #include "extensions/common/feature_switch.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 using ::testing::Return; | 22 using ::testing::Return; |
| 24 using ::testing::StrictMock; | 23 using ::testing::StrictMock; |
| 25 | 24 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 41 MockComponentMigrationHelper(Profile* profile, | 40 MockComponentMigrationHelper(Profile* profile, |
| 42 ComponentActionDelegate* delegate) | 41 ComponentActionDelegate* delegate) |
| 43 : ComponentMigrationHelper(profile, delegate) {} | 42 : ComponentMigrationHelper(profile, delegate) {} |
| 44 | 43 |
| 45 ~MockComponentMigrationHelper() override{}; | 44 ~MockComponentMigrationHelper() override{}; |
| 46 | 45 |
| 47 void SetTestComponentActionPref(bool enabled) { | 46 void SetTestComponentActionPref(bool enabled) { |
| 48 SetComponentActionPref(kTestActionId, enabled); | 47 SetComponentActionPref(kTestActionId, enabled); |
| 49 } | 48 } |
| 50 | 49 |
| 51 void SetMediaRouterActionPref(bool enabled) { | |
| 52 SetComponentActionPref( | |
| 53 ComponentToolbarActionsFactory::kMediaRouterActionId, enabled); | |
| 54 } | |
| 55 | |
| 56 void EnableTestFeature() { enabled_actions_.insert(kTestActionId); } | 50 void EnableTestFeature() { enabled_actions_.insert(kTestActionId); } |
| 57 | 51 |
| 58 void DisableTestFeature() { enabled_actions_.erase(kTestActionId); } | 52 void DisableTestFeature() { enabled_actions_.erase(kTestActionId); } |
| 59 }; | 53 }; |
| 60 | 54 |
| 61 } // namespace | 55 } // namespace |
| 62 | 56 |
| 63 class ComponentMigrationHelperTest : public ExtensionServiceTestBase { | 57 class ComponentMigrationHelperTest : public ExtensionServiceTestBase { |
| 64 protected: | 58 protected: |
| 65 ComponentMigrationHelperTest() {} | 59 ComponentMigrationHelperTest() {} |
| (...skipping 28 matching lines...) Expand all Loading... |
| 94 const base::DictionaryValue* migration_pref = | 88 const base::DictionaryValue* migration_pref = |
| 95 profile()->GetPrefs()->GetDictionary( | 89 profile()->GetPrefs()->GetDictionary( |
| 96 ::prefs::kToolbarMigratedComponentActionStatus); | 90 ::prefs::kToolbarMigratedComponentActionStatus); |
| 97 if (!migration_pref->HasKey(kTestActionId)) | 91 if (!migration_pref->HasKey(kTestActionId)) |
| 98 return false; | 92 return false; |
| 99 bool enable_value = false; | 93 bool enable_value = false; |
| 100 CHECK(migration_pref->GetBoolean(kTestActionId, &enable_value)); | 94 CHECK(migration_pref->GetBoolean(kTestActionId, &enable_value)); |
| 101 return enable_value; | 95 return enable_value; |
| 102 } | 96 } |
| 103 | 97 |
| 104 bool IsMediaRouterActionAlwaysShown() { | |
| 105 return profile()->GetPrefs()-> | |
| 106 GetBoolean(prefs::kMediaRouterAlwaysShowActionIcon); | |
| 107 } | |
| 108 | |
| 109 StrictMock<MockComponentActionDelegate> mock_delegate_; | 98 StrictMock<MockComponentActionDelegate> mock_delegate_; |
| 110 std::unique_ptr<StrictMock<MockComponentMigrationHelper>> mock_helper_; | 99 std::unique_ptr<StrictMock<MockComponentMigrationHelper>> mock_helper_; |
| 111 std::unique_ptr<FeatureSwitch::ScopedOverride> extension_action_redesign_; | 100 std::unique_ptr<FeatureSwitch::ScopedOverride> extension_action_redesign_; |
| 112 | 101 |
| 113 // Migrated extensions with browser actions. | 102 // Migrated extensions with browser actions. |
| 114 scoped_refptr<const Extension> migrated_extension_a_; | 103 scoped_refptr<const Extension> migrated_extension_a_; |
| 115 scoped_refptr<const Extension> migrated_extension_b_; | 104 scoped_refptr<const Extension> migrated_extension_b_; |
| 116 // An extension that is not migrated. | 105 // An extension that is not migrated. |
| 117 scoped_refptr<const Extension> unregistered_extension_; | 106 scoped_refptr<const Extension> unregistered_extension_; |
| 118 | 107 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 EXPECT_TRUE(IsTestComponentActionEnabled()); | 202 EXPECT_TRUE(IsTestComponentActionEnabled()); |
| 214 | 203 |
| 215 EXPECT_CALL(mock_delegate_, HasComponentAction(kTestActionId)) | 204 EXPECT_CALL(mock_delegate_, HasComponentAction(kTestActionId)) |
| 216 .WillOnce(Return(true)); | 205 .WillOnce(Return(true)); |
| 217 EXPECT_CALL(mock_delegate_, RemoveComponentAction(kTestActionId)); | 206 EXPECT_CALL(mock_delegate_, RemoveComponentAction(kTestActionId)); |
| 218 | 207 |
| 219 mock_helper_->OnActionRemoved(kTestActionId); | 208 mock_helper_->OnActionRemoved(kTestActionId); |
| 220 EXPECT_FALSE(IsTestComponentActionEnabled()); | 209 EXPECT_FALSE(IsTestComponentActionEnabled()); |
| 221 } | 210 } |
| 222 | 211 |
| 223 TEST_F(ComponentMigrationHelperTest, EnableAndDisableMediaRouterAction) { | |
| 224 mock_helper_->SetMediaRouterActionPref(true); | |
| 225 mock_helper_->Register( | |
| 226 ComponentToolbarActionsFactory::kMediaRouterActionId, | |
| 227 "test_cast_extension"); | |
| 228 EXPECT_FALSE(IsMediaRouterActionAlwaysShown()); | |
| 229 | |
| 230 EXPECT_CALL(mock_delegate_, HasComponentAction( | |
| 231 ComponentToolbarActionsFactory::kMediaRouterActionId)) | |
| 232 .WillOnce(Return(false)); | |
| 233 EXPECT_CALL(mock_delegate_, AddComponentAction( | |
| 234 ComponentToolbarActionsFactory::kMediaRouterActionId)); | |
| 235 | |
| 236 mock_helper_->OnFeatureEnabled( | |
| 237 ComponentToolbarActionsFactory::kMediaRouterActionId); | |
| 238 EXPECT_TRUE(IsMediaRouterActionAlwaysShown()); | |
| 239 | |
| 240 EXPECT_CALL(mock_delegate_, HasComponentAction( | |
| 241 ComponentToolbarActionsFactory::kMediaRouterActionId)) | |
| 242 .WillOnce(Return(true)); | |
| 243 EXPECT_CALL(mock_delegate_, RemoveComponentAction( | |
| 244 ComponentToolbarActionsFactory::kMediaRouterActionId)); | |
| 245 | |
| 246 mock_helper_->OnFeatureDisabled( | |
| 247 ComponentToolbarActionsFactory::kMediaRouterActionId); | |
| 248 EXPECT_FALSE(IsMediaRouterActionAlwaysShown()); | |
| 249 } | |
| 250 | |
| 251 } // namespace extensions | 212 } // namespace extensions |
| OLD | NEW |