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

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

Issue 297483007: Revert 270890 "Unload all apps / extensions immediately when del..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/2006/src/
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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_unittest.h" 5 #include "chrome/browser/extensions/extension_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 using extensions::ExtensionCreator; 158 using extensions::ExtensionCreator;
159 using extensions::ExtensionPrefs; 159 using extensions::ExtensionPrefs;
160 using extensions::ExtensionRegistry; 160 using extensions::ExtensionRegistry;
161 using extensions::ExtensionResource; 161 using extensions::ExtensionResource;
162 using extensions::ExtensionSystem; 162 using extensions::ExtensionSystem;
163 using extensions::FakeSafeBrowsingDatabaseManager; 163 using extensions::FakeSafeBrowsingDatabaseManager;
164 using extensions::FeatureSwitch; 164 using extensions::FeatureSwitch;
165 using extensions::Manifest; 165 using extensions::Manifest;
166 using extensions::PermissionSet; 166 using extensions::PermissionSet;
167 using extensions::TestExtensionSystem; 167 using extensions::TestExtensionSystem;
168 using extensions::UnloadedExtensionInfo;
169 using extensions::URLPatternSet; 168 using extensions::URLPatternSet;
170 169
171 namespace keys = extensions::manifest_keys; 170 namespace keys = extensions::manifest_keys;
172 171
173 namespace { 172 namespace {
174 173
175 // Extension ids used during testing. 174 // Extension ids used during testing.
176 const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; 175 const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj";
177 const char good1[] = "hpiknbiabeeppbpihjehijgoemciehgk"; 176 const char good1[] = "hpiknbiabeeppbpihjehijgoemciehgk";
178 const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; 177 const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa";
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 params.profile_path = path; 659 params.profile_path = path;
661 params.pref_file = prefs_filename; 660 params.pref_file = prefs_filename;
662 params.extensions_install_dir = extensions_install_dir; 661 params.extensions_install_dir = extensions_install_dir;
663 return params; 662 return params;
664 } 663 }
665 664
666 class ExtensionServiceTest 665 class ExtensionServiceTest
667 : public ExtensionServiceTestBase, public content::NotificationObserver { 666 : public ExtensionServiceTestBase, public content::NotificationObserver {
668 public: 667 public:
669 ExtensionServiceTest() 668 ExtensionServiceTest()
670 : unloaded_reason_(UnloadedExtensionInfo::REASON_UNDEFINED), 669 : installed_(NULL),
671 installed_(NULL),
672 was_update_(false), 670 was_update_(false),
673 override_external_install_prompt_( 671 override_external_install_prompt_(
674 FeatureSwitch::prompt_for_external_extensions(), 672 FeatureSwitch::prompt_for_external_extensions(), false) {
675 false) {
676 registrar_.Add(this, 673 registrar_.Add(this,
677 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 674 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
678 content::NotificationService::AllSources()); 675 content::NotificationService::AllSources());
679 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 676 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
680 content::NotificationService::AllSources()); 677 content::NotificationService::AllSources());
681 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 678 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
682 content::NotificationService::AllSources()); 679 content::NotificationService::AllSources());
683 } 680 }
684 681
685 virtual void Observe(int type, 682 virtual void Observe(int type,
686 const content::NotificationSource& source, 683 const content::NotificationSource& source,
687 const content::NotificationDetails& details) OVERRIDE { 684 const content::NotificationDetails& details) OVERRIDE {
688 switch (type) { 685 switch (type) {
689 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { 686 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
690 const Extension* extension = 687 const Extension* extension =
691 content::Details<const Extension>(details).ptr(); 688 content::Details<const Extension>(details).ptr();
692 loaded_.push_back(make_scoped_refptr(extension)); 689 loaded_.push_back(make_scoped_refptr(extension));
693 // The tests rely on the errors being in a certain order, which can vary 690 // The tests rely on the errors being in a certain order, which can vary
694 // depending on how filesystem iteration works. 691 // depending on how filesystem iteration works.
695 std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder()); 692 std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder());
696 break; 693 break;
697 } 694 }
698 695
699 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { 696 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
700 UnloadedExtensionInfo* unloaded_info = 697 const Extension* e =
701 content::Details<UnloadedExtensionInfo>(details).ptr(); 698 content::Details<extensions::UnloadedExtensionInfo>(
702 const Extension* e = unloaded_info->extension; 699 details)->extension;
703 unloaded_id_ = e->id(); 700 unloaded_id_ = e->id();
704 unloaded_reason_ = unloaded_info->reason;
705 extensions::ExtensionList::iterator i = 701 extensions::ExtensionList::iterator i =
706 std::find(loaded_.begin(), loaded_.end(), e); 702 std::find(loaded_.begin(), loaded_.end(), e);
707 // TODO(erikkay) fix so this can be an assert. Right now the tests 703 // TODO(erikkay) fix so this can be an assert. Right now the tests
708 // are manually calling clear() on loaded_, so this isn't doable. 704 // are manually calling clear() on loaded_, so this isn't doable.
709 if (i == loaded_.end()) 705 if (i == loaded_.end())
710 return; 706 return;
711 loaded_.erase(i); 707 loaded_.erase(i);
712 break; 708 break;
713 } 709 }
714 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { 710 case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 1243
1248 void InitPluginService() { 1244 void InitPluginService() {
1249 #if defined(ENABLE_PLUGINS) 1245 #if defined(ENABLE_PLUGINS)
1250 PluginService::GetInstance()->Init(); 1246 PluginService::GetInstance()->Init();
1251 #endif 1247 #endif
1252 } 1248 }
1253 1249
1254 protected: 1250 protected:
1255 extensions::ExtensionList loaded_; 1251 extensions::ExtensionList loaded_;
1256 std::string unloaded_id_; 1252 std::string unloaded_id_;
1257 UnloadedExtensionInfo::Reason unloaded_reason_;
1258 const Extension* installed_; 1253 const Extension* installed_;
1259 bool was_update_; 1254 bool was_update_;
1260 std::string old_name_; 1255 std::string old_name_;
1261 FeatureSwitch::ScopedOverride override_external_install_prompt_; 1256 FeatureSwitch::ScopedOverride override_external_install_prompt_;
1262 1257
1263 private: 1258 private:
1264 // Create a CrxInstaller and install the CRX file. 1259 // Create a CrxInstaller and install the CRX file.
1265 // Instead of calling this method yourself, use InstallCRX(), which does extra 1260 // Instead of calling this method yourself, use InstallCRX(), which does extra
1266 // error checking. 1261 // error checking.
1267 void InstallCRXInternal(const base::FilePath& crx_path) { 1262 void InstallCRXInternal(const base::FilePath& crx_path) {
(...skipping 2927 matching lines...) Expand 10 before | Expand all | Expand 10 after
4195 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4190 EXPECT_EQ(1u, registry_->enabled_extensions().size());
4196 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 4191 EXPECT_EQ(0u, registry_->disabled_extensions().size());
4197 } 4192 }
4198 4193
4199 TEST_F(ExtensionServiceTest, UninstallExtension) { 4194 TEST_F(ExtensionServiceTest, UninstallExtension) {
4200 InitializeEmptyExtensionService(); 4195 InitializeEmptyExtensionService();
4201 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4196 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
4202 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4197 EXPECT_EQ(1u, registry_->enabled_extensions().size());
4203 UninstallExtension(good_crx, false); 4198 UninstallExtension(good_crx, false);
4204 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4199 EXPECT_EQ(0u, registry_->enabled_extensions().size());
4205 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_);
4206 } 4200 }
4207 4201
4208 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { 4202 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) {
4209 InitializeEmptyExtensionService(); 4203 InitializeEmptyExtensionService();
4210 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4204 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
4211 TerminateExtension(good_crx); 4205 TerminateExtension(good_crx);
4212 UninstallExtension(good_crx, false); 4206 UninstallExtension(good_crx, false);
4213 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_);
4214 } 4207 }
4215 4208
4216 // Tests the uninstaller helper. 4209 // Tests the uninstaller helper.
4217 TEST_F(ExtensionServiceTest, UninstallExtensionHelper) { 4210 TEST_F(ExtensionServiceTest, UninstallExtensionHelper) {
4218 InitializeEmptyExtensionService(); 4211 InitializeEmptyExtensionService();
4219 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4212 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
4220 UninstallExtension(good_crx, true); 4213 UninstallExtension(good_crx, true);
4221 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_);
4222 } 4214 }
4223 4215
4224 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { 4216 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) {
4225 InitializeEmptyExtensionService(); 4217 InitializeEmptyExtensionService();
4226 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4218 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
4227 TerminateExtension(good_crx); 4219 TerminateExtension(good_crx);
4228 UninstallExtension(good_crx, true); 4220 UninstallExtension(good_crx, true);
4229 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_);
4230 } 4221 }
4231 4222
4232 // An extension disabled because of unsupported requirements should re-enabled 4223 // An extension disabled because of unsupported requirements should re-enabled
4233 // if updated to a version with supported requirements as long as there are no 4224 // if updated to a version with supported requirements as long as there are no
4234 // other disable reasons. 4225 // other disable reasons.
4235 TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) { 4226 TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) {
4236 InitializeEmptyExtensionService(); 4227 InitializeEmptyExtensionService();
4237 BlackListWebGL(); 4228 BlackListWebGL();
4238 4229
4239 base::FilePath path = data_dir_.AppendASCII("requirements"); 4230 base::FilePath path = data_dir_.AppendASCII("requirements");
(...skipping 2715 matching lines...) Expand 10 before | Expand all | Expand 10 after
6955 // ReconcileKnownDisabled(). 6946 // ReconcileKnownDisabled().
6956 service_->EnableExtension(good2); 6947 service_->EnableExtension(good2);
6957 service_->ReconcileKnownDisabled(); 6948 service_->ReconcileKnownDisabled();
6958 expected_extensions.insert(good2); 6949 expected_extensions.insert(good2);
6959 expected_disabled_extensions.erase(good2); 6950 expected_disabled_extensions.erase(good2);
6960 6951
6961 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs()); 6952 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs());
6962 EXPECT_EQ(expected_disabled_extensions, 6953 EXPECT_EQ(expected_disabled_extensions,
6963 registry_->disabled_extensions().GetIDs()); 6954 registry_->disabled_extensions().GetIDs());
6964 } 6955 }
6965
6966 // Tests a profile being destroyed correctly disables extensions.
6967 TEST_F(ExtensionServiceTest, DestroyingProfileClearsExtensions) {
6968 InitializeEmptyExtensionService();
6969
6970 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
6971 EXPECT_NE(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
6972 EXPECT_EQ(1u, registry_->enabled_extensions().size());
6973 EXPECT_EQ(0u, registry_->disabled_extensions().size());
6974 EXPECT_EQ(0u, registry_->terminated_extensions().size());
6975 EXPECT_EQ(0u, registry_->blacklisted_extensions().size());
6976
6977 service_->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
6978 content::Source<Profile>(profile_.get()),
6979 content::NotificationService::NoDetails());
6980 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
6981 EXPECT_EQ(0u, registry_->enabled_extensions().size());
6982 EXPECT_EQ(0u, registry_->disabled_extensions().size());
6983 EXPECT_EQ(0u, registry_->terminated_extensions().size());
6984 EXPECT_EQ(0u, registry_->blacklisted_extensions().size());
6985 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698