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

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 2147923002: [Extensions] Fixed removing from blacklist. (Closed) Base URL: ssh://bitbucket.browser.yandex-team.ru/chromium/src.git@master
Patch Set: Created 4 years, 5 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chrome/browser/extensions/extension_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 3103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3114 base::FilePath path = data_dir().AppendASCII("good.crx"); 3114 base::FilePath path = data_dir().AppendASCII("good.crx");
3115 // HACK: specify WAS_INSTALLED_BY_DEFAULT so that test machinery doesn't 3115 // HACK: specify WAS_INSTALLED_BY_DEFAULT so that test machinery doesn't
3116 // decide to install this silently. Somebody should fix these tests, all 3116 // decide to install this silently. Somebody should fix these tests, all
3117 // 6,000 lines of them. Hah! 3117 // 6,000 lines of them. Hah!
3118 InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT); 3118 InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT);
3119 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 3119 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3120 } 3120 }
3121 #endif // defined(ENABLE_BLACKLIST_TESTS) 3121 #endif // defined(ENABLE_BLACKLIST_TESTS)
3122 3122
3123 #if defined(ENABLE_BLACKLIST_TESTS) 3123 #if defined(ENABLE_BLACKLIST_TESTS)
3124 // Tests that previously blackisted extension will be enabled if it is removed
3125 // from blacklist. Also checks that all blacklisted preferences will be cleaned
Devlin 2016/07/18 16:22:17 nit: from *the* blacklist
3126 // in that case.
3127 TEST_F(ExtensionServiceTest, RemoveExtensionFromBlacklist) {
3128 extensions::TestBlacklist test_blacklist;
3129 // A profile with 3 extensions installed: good0, good1, and good2.
3130 InitializeGoodInstalledExtensionService();
3131 test_blacklist.Attach(service()->blacklist_);
3132 service()->Init();
3133
3134 ASSERT_TRUE(registry()->enabled_extensions().Contains(good0));
3135 extensions::TestExtensionRegistryObserver observer(
3136 extensions::ExtensionRegistry::Get(profile()), good0);
3137
3138 // Add the extension from blacklist.
Devlin 2016/07/18 16:22:17 nit: s/from/to the
3139 test_blacklist.SetBlacklistState(good0, extensions::BLACKLISTED_MALWARE,
3140 true);
3141 observer.WaitForExtensionUnloaded();
3142
3143 // The extension should be disabled, both "blacklist" and "blacklist_state"
3144 // prefs should be set.
3145 const auto prefs = ExtensionPrefs::Get(profile());
3146 EXPECT_FALSE(registry()->enabled_extensions().Contains(good0));
3147 EXPECT_TRUE(prefs->IsExtensionBlacklisted(good0));
3148 EXPECT_EQ(extensions::BLACKLISTED_MALWARE,
3149 prefs->GetExtensionBlacklistState(good0));
3150
3151 // Remove the extension from blacklist.
3152 test_blacklist.SetBlacklistState(good0, extensions::NOT_BLACKLISTED, true);
3153 observer.WaitForExtensionLoaded()->id();
3154
3155 // The extension should be enabled, both "blacklist" and "blacklist_state"
3156 // should be cleaned.
Devlin 2016/07/18 16:22:17 s/cleaned/cleared
3157 EXPECT_TRUE(registry()->enabled_extensions().Contains(good0));
3158 EXPECT_FALSE(prefs->IsExtensionBlacklisted(good0));
3159 EXPECT_EQ(extensions::NOT_BLACKLISTED,
3160 prefs->GetExtensionBlacklistState(good0));
3161 }
3162 #endif // defined(ENABLE_BLACKLIST_TESTS)
3163
3164 #if defined(ENABLE_BLACKLIST_TESTS)
3124 // Unload blacklisted extension on policy change. 3165 // Unload blacklisted extension on policy change.
3125 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) { 3166 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) {
3126 extensions::TestBlacklist test_blacklist; 3167 extensions::TestBlacklist test_blacklist;
3127 3168
3128 // A profile with no extensions installed. 3169 // A profile with no extensions installed.
3129 InitializeEmptyExtensionServiceWithTestingPrefs(); 3170 InitializeEmptyExtensionServiceWithTestingPrefs();
3130 test_blacklist.Attach(service()->blacklist_); 3171 test_blacklist.Attach(service()->blacklist_);
3131 3172
3132 base::FilePath path = data_dir().AppendASCII("good.crx"); 3173 base::FilePath path = data_dir().AppendASCII("good.crx");
3133 3174
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3181 #endif // defined(ENABLE_BLACKLIST_TESTS) 3222 #endif // defined(ENABLE_BLACKLIST_TESTS)
3182 3223
3183 #if defined(ENABLE_BLACKLIST_TESTS) 3224 #if defined(ENABLE_BLACKLIST_TESTS)
3184 // Tests extensions blacklisted in prefs on startup; one still blacklisted by 3225 // Tests extensions blacklisted in prefs on startup; one still blacklisted by
3185 // safe browsing, the other not. The not-blacklisted one should recover. 3226 // safe browsing, the other not. The not-blacklisted one should recover.
3186 TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) { 3227 TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) {
3187 extensions::TestBlacklist test_blacklist; 3228 extensions::TestBlacklist test_blacklist;
3188 3229
3189 InitializeGoodInstalledExtensionService(); 3230 InitializeGoodInstalledExtensionService();
3190 test_blacklist.Attach(service()->blacklist_); 3231 test_blacklist.Attach(service()->blacklist_);
3191 ExtensionPrefs::Get(profile())->SetExtensionBlacklisted(good0, true); 3232 ExtensionPrefs::Get(profile())->SetExtensionBlacklistState(
3192 ExtensionPrefs::Get(profile())->SetExtensionBlacklisted(good1, true); 3233 good0, extensions::BLACKLISTED_MALWARE);
3234 ExtensionPrefs::Get(profile())->SetExtensionBlacklistState(
3235 good1, extensions::BLACKLISTED_MALWARE);
3193 3236
3194 test_blacklist.SetBlacklistState( 3237 test_blacklist.SetBlacklistState(
3195 good1, extensions::BLACKLISTED_MALWARE, false); 3238 good1, extensions::BLACKLISTED_MALWARE, false);
3196 3239
3197 // Extension service hasn't loaded yet, but IsExtensionEnabled reads out of 3240 // Extension service hasn't loaded yet, but IsExtensionEnabled reads out of
3198 // prefs. Ensure it takes into account the blacklist state (crbug.com/373842). 3241 // prefs. Ensure it takes into account the blacklist state (crbug.com/373842).
3199 EXPECT_FALSE(service()->IsExtensionEnabled(good0)); 3242 EXPECT_FALSE(service()->IsExtensionEnabled(good0));
3200 EXPECT_FALSE(service()->IsExtensionEnabled(good1)); 3243 EXPECT_FALSE(service()->IsExtensionEnabled(good1));
3201 EXPECT_TRUE(service()->IsExtensionEnabled(good2)); 3244 EXPECT_TRUE(service()->IsExtensionEnabled(good2));
3202 3245
(...skipping 3633 matching lines...) Expand 10 before | Expand all | Expand 10 after
6836 6879
6837 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 6880 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
6838 content::Source<Profile>(profile()), 6881 content::Source<Profile>(profile()),
6839 content::NotificationService::NoDetails()); 6882 content::NotificationService::NoDetails());
6840 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 6883 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
6841 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 6884 EXPECT_EQ(0u, registry()->enabled_extensions().size());
6842 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 6885 EXPECT_EQ(0u, registry()->disabled_extensions().size());
6843 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 6886 EXPECT_EQ(0u, registry()->terminated_extensions().size());
6844 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 6887 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
6845 } 6888 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698