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

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

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