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

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

Issue 289283013: Revert of Unload all apps / extensions when deleting a profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/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 2897 matching lines...) Expand 10 before | Expand all | Expand 10 after
4165 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4160 EXPECT_EQ(1u, registry_->enabled_extensions().size());
4166 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 4161 EXPECT_EQ(0u, registry_->disabled_extensions().size());
4167 } 4162 }
4168 4163
4169 TEST_F(ExtensionServiceTest, UninstallExtension) { 4164 TEST_F(ExtensionServiceTest, UninstallExtension) {
4170 InitializeEmptyExtensionService(); 4165 InitializeEmptyExtensionService();
4171 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4166 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
4172 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4167 EXPECT_EQ(1u, registry_->enabled_extensions().size());
4173 UninstallExtension(good_crx, false); 4168 UninstallExtension(good_crx, false);
4174 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4169 EXPECT_EQ(0u, registry_->enabled_extensions().size());
4175 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_);
4176 } 4170 }
4177 4171
4178 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { 4172 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) {
4179 InitializeEmptyExtensionService(); 4173 InitializeEmptyExtensionService();
4180 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4174 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
4181 TerminateExtension(good_crx); 4175 TerminateExtension(good_crx);
4182 UninstallExtension(good_crx, false); 4176 UninstallExtension(good_crx, false);
4183 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_);
4184 } 4177 }
4185 4178
4186 // Tests the uninstaller helper. 4179 // Tests the uninstaller helper.
4187 TEST_F(ExtensionServiceTest, UninstallExtensionHelper) { 4180 TEST_F(ExtensionServiceTest, UninstallExtensionHelper) {
4188 InitializeEmptyExtensionService(); 4181 InitializeEmptyExtensionService();
4189 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4182 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
4190 UninstallExtension(good_crx, true); 4183 UninstallExtension(good_crx, true);
4191 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_);
4192 } 4184 }
4193 4185
4194 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { 4186 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) {
4195 InitializeEmptyExtensionService(); 4187 InitializeEmptyExtensionService();
4196 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4188 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
4197 TerminateExtension(good_crx); 4189 TerminateExtension(good_crx);
4198 UninstallExtension(good_crx, true); 4190 UninstallExtension(good_crx, true);
4199 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_);
4200 } 4191 }
4201 4192
4202 // An extension disabled because of unsupported requirements should re-enabled 4193 // An extension disabled because of unsupported requirements should re-enabled
4203 // if updated to a version with supported requirements as long as there are no 4194 // if updated to a version with supported requirements as long as there are no
4204 // other disable reasons. 4195 // other disable reasons.
4205 TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) { 4196 TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) {
4206 InitializeEmptyExtensionService(); 4197 InitializeEmptyExtensionService();
4207 BlackListWebGL(); 4198 BlackListWebGL();
4208 4199
4209 base::FilePath path = data_dir_.AppendASCII("requirements"); 4200 base::FilePath path = data_dir_.AppendASCII("requirements");
(...skipping 2709 matching lines...) Expand 10 before | Expand all | Expand 10 after
6919 // ReconcileKnownDisabled(). 6910 // ReconcileKnownDisabled().
6920 service_->EnableExtension(good2); 6911 service_->EnableExtension(good2);
6921 service_->ReconcileKnownDisabled(); 6912 service_->ReconcileKnownDisabled();
6922 expected_extensions.insert(good2); 6913 expected_extensions.insert(good2);
6923 expected_disabled_extensions.erase(good2); 6914 expected_disabled_extensions.erase(good2);
6924 6915
6925 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs()); 6916 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs());
6926 EXPECT_EQ(expected_disabled_extensions, 6917 EXPECT_EQ(expected_disabled_extensions,
6927 registry_->disabled_extensions().GetIDs()); 6918 registry_->disabled_extensions().GetIDs());
6928 } 6919 }
6929
6930 // Tests a profile being destroyed correctly disables extensions.
6931 TEST_F(ExtensionServiceTest, DestroyingProfileClearsExtensions) {
6932 InitializeEmptyExtensionService();
6933
6934 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
6935 EXPECT_NE(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
6936 EXPECT_EQ(1u, registry_->enabled_extensions().size());
6937 EXPECT_EQ(0u, registry_->disabled_extensions().size());
6938 EXPECT_EQ(0u, registry_->terminated_extensions().size());
6939 EXPECT_EQ(0u, registry_->blacklisted_extensions().size());
6940
6941 service_->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
6942 content::Source<Profile>(profile_.get()),
6943 content::NotificationService::NoDetails());
6944 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
6945 EXPECT_EQ(0u, registry_->enabled_extensions().size());
6946 EXPECT_EQ(0u, registry_->disabled_extensions().size());
6947 EXPECT_EQ(0u, registry_->terminated_extensions().size());
6948 EXPECT_EQ(0u, registry_->blacklisted_extensions().size());
6949 }
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