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

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

Issue 160311: Pull CrxInstaller out of ExtensionsService. (Closed)
Patch Set: Fix leak of SandboxedExtensionUnpacker Created 11 years, 4 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 virtual void VisitRegisteredExtension( 92 virtual void VisitRegisteredExtension(
93 Visitor* visitor, const std::set<std::string>& ids_to_ignore) const { 93 Visitor* visitor, const std::set<std::string>& ids_to_ignore) const {
94 for (DataMap::const_iterator i = extension_map_.begin(); 94 for (DataMap::const_iterator i = extension_map_.begin();
95 i != extension_map_.end(); ++i) { 95 i != extension_map_.end(); ++i) {
96 if (ids_to_ignore.find(i->first) != ids_to_ignore.end()) 96 if (ids_to_ignore.find(i->first) != ids_to_ignore.end())
97 continue; 97 continue;
98 scoped_ptr<Version> version; 98 scoped_ptr<Version> version;
99 version.reset(Version::GetVersionFromString(i->second.first)); 99 version.reset(Version::GetVersionFromString(i->second.first));
100 100
101 visitor->OnExternalExtensionFound( 101 visitor->OnExternalExtensionFound(
102 i->first, version.get(), i->second.second); 102 i->first, version.get(), i->second.second, location_);
103 } 103 }
104 } 104 }
105 105
106 virtual Version* RegisteredVersion(const std::string& id, 106 virtual Version* RegisteredVersion(const std::string& id,
107 Extension::Location* location) const { 107 Extension::Location* location) const {
108 DataMap::const_iterator it = extension_map_.find(id); 108 DataMap::const_iterator it = extension_map_.find(id);
109 if (it == extension_map_.end()) 109 if (it == extension_map_.end())
110 return NULL; 110 return NULL;
111 111
112 if (location) 112 if (location)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 ids_found_ = 0; 153 ids_found_ = 0;
154 // Ask the provider to look up all extensions (and return the ones 154 // Ask the provider to look up all extensions (and return the ones
155 // found (that are not on the ignore list). 155 // found (that are not on the ignore list).
156 provider_->VisitRegisteredExtension(this, ignore_list); 156 provider_->VisitRegisteredExtension(this, ignore_list);
157 157
158 return ids_found_; 158 return ids_found_;
159 } 159 }
160 160
161 virtual void OnExternalExtensionFound(const std::string& id, 161 virtual void OnExternalExtensionFound(const std::string& id,
162 const Version* version, 162 const Version* version,
163 const FilePath& path) { 163 const FilePath& path,
164 Extension::Location unused) {
164 ++ids_found_; 165 ++ids_found_;
165 DictionaryValue* pref; 166 DictionaryValue* pref;
166 // This tests is to make sure that the provider only notifies us of the 167 // This tests is to make sure that the provider only notifies us of the
167 // values we gave it. So if the id we doesn't exist in our internal 168 // values we gave it. So if the id we doesn't exist in our internal
168 // dictionary then something is wrong. 169 // dictionary then something is wrong.
169 EXPECT_TRUE(prefs_->GetDictionary(ASCIIToWide(id), &pref)) 170 EXPECT_TRUE(prefs_->GetDictionary(ASCIIToWide(id), &pref))
170 << L"Got back ID (" << id.c_str() << ") we weren't expecting"; 171 << L"Got back ID (" << id.c_str() << ") we weren't expecting";
171 172
172 if (pref) { 173 if (pref) {
173 // Ask provider if the extension we got back is registered. 174 // Ask provider if the extension we got back is registered.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 const FilePath& extensions_install_dir) { 211 const FilePath& extensions_install_dir) {
211 prefs_.reset(new PrefService(pref_file, NULL)); 212 prefs_.reset(new PrefService(pref_file, NULL));
212 profile_.reset(new TestingProfile()); 213 profile_.reset(new TestingProfile());
213 service_ = new ExtensionsService(profile_.get(), 214 service_ = new ExtensionsService(profile_.get(),
214 CommandLine::ForCurrentProcess(), 215 CommandLine::ForCurrentProcess(),
215 prefs_.get(), 216 prefs_.get(),
216 extensions_install_dir, 217 extensions_install_dir,
217 &loop_, 218 &loop_,
218 &loop_, 219 &loop_,
219 false); 220 false);
220 service_->SetExtensionsEnabled(true); 221 service_->set_extensions_enabled(true);
221 service_->set_show_extensions_prompts(false); 222 service_->set_show_extensions_prompts(false);
222 223
223 // When we start up, we want to make sure there is no external provider, 224 // When we start up, we want to make sure there is no external provider,
224 // since the ExtensionService on Windows will use the Registry as a default 225 // since the ExtensionService on Windows will use the Registry as a default
225 // provider and if there is something already registered there then it will 226 // provider and if there is something already registered there then it will
226 // interfere with the tests. Those tests that need an external provider 227 // interfere with the tests. Those tests that need an external provider
227 // will register one specifically. 228 // will register one specifically.
228 service_->ClearProvidersForTesting(); 229 service_->ClearProvidersForTesting();
229 230
230 total_successes_ = 0; 231 total_successes_ = 0;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 case NotificationType::EXTENSION_INSTALLED: 302 case NotificationType::EXTENSION_INSTALLED:
302 case NotificationType::THEME_INSTALLED: 303 case NotificationType::THEME_INSTALLED:
303 installed_ = Details<Extension>(details).ptr(); 304 installed_ = Details<Extension>(details).ptr();
304 break; 305 break;
305 306
306 default: 307 default:
307 DCHECK(false); 308 DCHECK(false);
308 } 309 }
309 } 310 }
310 311
311 void SetExtensionsEnabled(bool enabled) { 312 void set_extensions_enabled(bool enabled) {
312 service_->SetExtensionsEnabled(enabled); 313 service_->set_extensions_enabled(enabled);
313 } 314 }
314 315
315 void SetMockExternalProvider(Extension::Location location, 316 void SetMockExternalProvider(Extension::Location location,
316 ExternalExtensionProvider* provider) { 317 ExternalExtensionProvider* provider) {
317 service_->SetProviderForTesting(location, provider); 318 service_->SetProviderForTesting(location, provider);
318 } 319 }
319 320
320 protected: 321 protected:
321 // A class to record whether a ExtensionInstallCallback has fired, and
322 // to remember the args it was called with.
323 class CallbackRecorder {
324 public:
325 CallbackRecorder() : was_called_(false), path_(NULL), extension_(NULL) {}
326
327 void CallbackFunc(const FilePath& path, Extension* extension) {
328 was_called_ = true;
329 path_.reset(new FilePath(path));
330 extension_ = extension;
331 }
332
333 bool was_called() { return was_called_; }
334 const FilePath* path() { return path_.get(); }
335 Extension* extension() { return extension_; }
336
337 private:
338 bool was_called_;
339 scoped_ptr<FilePath> path_;
340 Extension* extension_;
341 };
342
343 void InstallExtension(const FilePath& path, 322 void InstallExtension(const FilePath& path,
344 bool should_succeed) { 323 bool should_succeed) {
345 ASSERT_TRUE(file_util::PathExists(path)); 324 ASSERT_TRUE(file_util::PathExists(path));
346 service_->InstallExtension(path); 325 service_->InstallExtension(path);
347 loop_.RunAllPending(); 326 loop_.RunAllPending();
348 std::vector<std::string> errors = GetErrors(); 327 std::vector<std::string> errors = GetErrors();
349 if (should_succeed) { 328 if (should_succeed) {
350 ++total_successes_; 329 ++total_successes_;
351 330
352 EXPECT_TRUE(installed_) << path.value(); 331 EXPECT_TRUE(installed_) << path.value();
(...skipping 13 matching lines...) Expand all
366 EXPECT_EQ(0u, loaded_.size()) << path.value(); 345 EXPECT_EQ(0u, loaded_.size()) << path.value();
367 EXPECT_EQ(1u, errors.size()) << path.value(); 346 EXPECT_EQ(1u, errors.size()) << path.value();
368 } 347 }
369 348
370 installed_ = NULL; 349 installed_ = NULL;
371 loaded_.clear(); 350 loaded_.clear();
372 ExtensionErrorReporter::GetInstance()->ClearErrors(); 351 ExtensionErrorReporter::GetInstance()->ClearErrors();
373 } 352 }
374 353
375 void UpdateExtension(const std::string& id, const FilePath& path, 354 void UpdateExtension(const std::string& id, const FilePath& path,
376 bool should_succeed, bool use_callback, 355 bool should_succeed, bool expect_report_on_failure) {
377 bool expect_report_on_failure) {
378 ASSERT_TRUE(file_util::PathExists(path)); 356 ASSERT_TRUE(file_util::PathExists(path));
379 357
380 CallbackRecorder callback_recorder; 358 service_->UpdateExtension(id, path);
381 ExtensionInstallCallback* callback = NULL;
382 if (use_callback) {
383 callback = NewCallback(&callback_recorder,
384 &CallbackRecorder::CallbackFunc);
385 }
386
387 service_->UpdateExtension(id, path, false, callback);
388 loop_.RunAllPending(); 359 loop_.RunAllPending();
389 std::vector<std::string> errors = GetErrors(); 360 std::vector<std::string> errors = GetErrors();
390 361
391 if (use_callback) {
392 EXPECT_TRUE(callback_recorder.was_called());
393 EXPECT_TRUE(path == *callback_recorder.path());
394 }
395
396 if (should_succeed) { 362 if (should_succeed) {
397 EXPECT_EQ(0u, errors.size()) << path.value(); 363 EXPECT_EQ(0u, errors.size()) << path.value();
398 EXPECT_EQ(1u, service_->extensions()->size()); 364 EXPECT_EQ(1u, service_->extensions()->size());
399 if (use_callback) {
400 EXPECT_EQ(service_->extensions()->at(0), callback_recorder.extension());
401 }
402 } else { 365 } else {
403 if (expect_report_on_failure) { 366 if (expect_report_on_failure) {
404 EXPECT_EQ(1u, errors.size()) << path.value(); 367 EXPECT_EQ(1u, errors.size()) << path.value();
405 } 368 }
406 if (use_callback) {
407 EXPECT_EQ(NULL, callback_recorder.extension());
408 }
409 } 369 }
370
371 // Update() should delete the temporary input file.
372 EXPECT_FALSE(file_util::PathExists(path));
410 } 373 }
411 374
412 void ValidatePrefKeyCount(size_t count) { 375 void ValidatePrefKeyCount(size_t count) {
413 DictionaryValue* dict = 376 DictionaryValue* dict =
414 prefs_->GetMutableDictionary(L"extensions.settings"); 377 prefs_->GetMutableDictionary(L"extensions.settings");
415 ASSERT_TRUE(dict != NULL); 378 ASSERT_TRUE(dict != NULL);
416 EXPECT_EQ(count, dict->GetSize()); 379 EXPECT_EQ(count, dict->GetSize());
417 } 380 }
418 381
419 void ValidatePref(const std::string& extension_id, 382 void ValidatePref(const std::string& extension_id,
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 // crx files. If you need to change those crx files, feel free to repackage 632 // crx files. If you need to change those crx files, feel free to repackage
670 // them, throw away the key used and change the id's above. 633 // them, throw away the key used and change the id's above.
671 TEST_F(ExtensionsServiceTest, InstallExtension) { 634 TEST_F(ExtensionsServiceTest, InstallExtension) {
672 InitializeEmptyExtensionsService(); 635 InitializeEmptyExtensionsService();
673 636
674 FilePath extensions_path; 637 FilePath extensions_path;
675 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 638 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
676 extensions_path = extensions_path.AppendASCII("extensions"); 639 extensions_path = extensions_path.AppendASCII("extensions");
677 640
678 // Extensions not enabled. 641 // Extensions not enabled.
679 SetExtensionsEnabled(false); 642 set_extensions_enabled(false);
680 FilePath path = extensions_path.AppendASCII("good.crx"); 643 FilePath path = extensions_path.AppendASCII("good.crx");
681 InstallExtension(path, false); 644 InstallExtension(path, false);
682 SetExtensionsEnabled(true); 645 set_extensions_enabled(true);
683 646
684 ValidatePrefKeyCount(0); 647 ValidatePrefKeyCount(0);
685 648
686 // A simple extension that should install without error. 649 // A simple extension that should install without error.
687 path = extensions_path.AppendASCII("good.crx"); 650 path = extensions_path.AppendASCII("good.crx");
688 InstallExtension(path, true); 651 InstallExtension(path, true);
689 // TODO(erikkay): verify the contents of the installed extension. 652 // TODO(erikkay): verify the contents of the installed extension.
690 653
691 int pref_count = 0; 654 int pref_count = 0;
692 ValidatePrefKeyCount(++pref_count); 655 ValidatePrefKeyCount(++pref_count);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 // A theme. 757 // A theme.
795 FilePath path = extensions_path.AppendASCII("theme.crx"); 758 FilePath path = extensions_path.AppendASCII("theme.crx");
796 InstallExtension(path, true); 759 InstallExtension(path, true);
797 int pref_count = 0; 760 int pref_count = 0;
798 ValidatePrefKeyCount(++pref_count); 761 ValidatePrefKeyCount(++pref_count);
799 ValidatePref(theme_crx, L"state", Extension::ENABLED); 762 ValidatePref(theme_crx, L"state", Extension::ENABLED);
800 ValidatePref(theme_crx, L"location", Extension::INTERNAL); 763 ValidatePref(theme_crx, L"location", Extension::INTERNAL);
801 764
802 // A theme when extensions are disabled. Themes can be installed, even when 765 // A theme when extensions are disabled. Themes can be installed, even when
803 // extensions are disabled. 766 // extensions are disabled.
804 SetExtensionsEnabled(false); 767 set_extensions_enabled(false);
805 path = extensions_path.AppendASCII("theme2.crx"); 768 path = extensions_path.AppendASCII("theme2.crx");
806 InstallExtension(path, true); 769 InstallExtension(path, true);
807 ValidatePrefKeyCount(++pref_count); 770 ValidatePrefKeyCount(++pref_count);
808 ValidatePref(theme2_crx, L"state", Extension::ENABLED); 771 ValidatePref(theme2_crx, L"state", Extension::ENABLED);
809 ValidatePref(theme2_crx, L"location", Extension::INTERNAL); 772 ValidatePref(theme2_crx, L"location", Extension::INTERNAL);
810 773
811 // A theme with extension elements. Themes cannot have extension elements so 774 // A theme with extension elements. Themes cannot have extension elements so
812 // this test should fail. 775 // this test should fail.
813 SetExtensionsEnabled(true); 776 set_extensions_enabled(true);
814 path = extensions_path.AppendASCII("theme_with_extension.crx"); 777 path = extensions_path.AppendASCII("theme_with_extension.crx");
815 InstallExtension(path, false); 778 InstallExtension(path, false);
816 ValidatePrefKeyCount(pref_count); 779 ValidatePrefKeyCount(pref_count);
817 780
818 // A theme with image resources missing (misspelt path). 781 // A theme with image resources missing (misspelt path).
819 path = extensions_path.AppendASCII("theme_missing_image.crx"); 782 path = extensions_path.AppendASCII("theme_missing_image.crx");
820 InstallExtension(path, false); 783 InstallExtension(path, false);
821 ValidatePrefKeyCount(pref_count); 784 ValidatePrefKeyCount(pref_count);
822 } 785 }
823 786
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 extensions_path = extensions_path.AppendASCII("extensions"); 881 extensions_path = extensions_path.AppendASCII("extensions");
919 882
920 FilePath path = extensions_path.AppendASCII("good.crx"); 883 FilePath path = extensions_path.AppendASCII("good.crx");
921 884
922 InstallExtension(path, true); 885 InstallExtension(path, true);
923 Extension* good = service_->extensions()->at(0); 886 Extension* good = service_->extensions()->at(0);
924 ASSERT_EQ("1.0.0.0", good->VersionString()); 887 ASSERT_EQ("1.0.0.0", good->VersionString());
925 ASSERT_EQ(good_crx, good->id()); 888 ASSERT_EQ(good_crx, good->id());
926 889
927 path = extensions_path.AppendASCII("good2.crx"); 890 path = extensions_path.AppendASCII("good2.crx");
928 UpdateExtension(good_crx, path, true, true, true); 891 UpdateExtension(good_crx, path, true, true);
929 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 892 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
930 } 893 }
931 894
932 // Test doing an update without passing a completion callback
933 TEST_F(ExtensionsServiceTest, UpdateWithoutCallback) {
934 InitializeEmptyExtensionsService();
935 FilePath extensions_path;
936 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
937 extensions_path = extensions_path.AppendASCII("extensions");
938
939 FilePath path = extensions_path.AppendASCII("good.crx");
940
941 InstallExtension(path, true);
942 Extension* good = service_->extensions()->at(0);
943 ASSERT_EQ("1.0.0.0", good->VersionString());
944 ASSERT_EQ(good_crx, good->id());
945
946 path = extensions_path.AppendASCII("good2.crx");
947 UpdateExtension(good_crx, path, true, false, true);
948 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
949 }
950
951 // Test updating a not-already-installed extension - this should fail 895 // Test updating a not-already-installed extension - this should fail
952 TEST_F(ExtensionsServiceTest, UpdateNotInstalledExtension) { 896 TEST_F(ExtensionsServiceTest, UpdateNotInstalledExtension) {
953 InitializeEmptyExtensionsService(); 897 InitializeEmptyExtensionsService();
954 FilePath extensions_path; 898 FilePath extensions_path;
955 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 899 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
956 extensions_path = extensions_path.AppendASCII("extensions"); 900 extensions_path = extensions_path.AppendASCII("extensions");
957 901
958 FilePath path = extensions_path.AppendASCII("good.crx"); 902 FilePath path = extensions_path.AppendASCII("good.crx");
959 service_->UpdateExtension(good_crx, path, false, NULL); 903 service_->UpdateExtension(good_crx, path);
960 loop_.RunAllPending(); 904 loop_.RunAllPending();
961 905
962 ASSERT_EQ(0u, service_->extensions()->size()); 906 ASSERT_EQ(0u, service_->extensions()->size());
963 ASSERT_FALSE(installed_); 907 ASSERT_FALSE(installed_);
964 ASSERT_EQ(0u, loaded_.size()); 908 ASSERT_EQ(0u, loaded_.size());
965 } 909 }
966 910
967 // Makes sure you can't downgrade an extension via UpdateExtension 911 // Makes sure you can't downgrade an extension via UpdateExtension
968 TEST_F(ExtensionsServiceTest, UpdateWillNotDowngrade) { 912 TEST_F(ExtensionsServiceTest, UpdateWillNotDowngrade) {
969 InitializeEmptyExtensionsService(); 913 InitializeEmptyExtensionsService();
970 FilePath extensions_path; 914 FilePath extensions_path;
971 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 915 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
972 extensions_path = extensions_path.AppendASCII("extensions"); 916 extensions_path = extensions_path.AppendASCII("extensions");
973 917
974 FilePath path = extensions_path.AppendASCII("good2.crx"); 918 FilePath path = extensions_path.AppendASCII("good2.crx");
975 919
976 InstallExtension(path, true); 920 InstallExtension(path, true);
977 Extension* good = service_->extensions()->at(0); 921 Extension* good = service_->extensions()->at(0);
978 ASSERT_EQ("1.0.0.1", good->VersionString()); 922 ASSERT_EQ("1.0.0.1", good->VersionString());
979 ASSERT_EQ(good_crx, good->id()); 923 ASSERT_EQ(good_crx, good->id());
980 924
981 // Change path from good2.crx -> good.crx 925 // Change path from good2.crx -> good.crx
982 path = extensions_path.AppendASCII("good.crx"); 926 path = extensions_path.AppendASCII("good.crx");
983 UpdateExtension(good_crx, path, false, true, true); 927 UpdateExtension(good_crx, path, false, true);
984 ASSERT_EQ("1.0.0.1", service_->extensions()->at(0)->VersionString()); 928 ASSERT_EQ("1.0.0.1", service_->extensions()->at(0)->VersionString());
985 } 929 }
986 930
987 // Make sure calling update with an identical version does nothing 931 // Make sure calling update with an identical version does nothing
988 TEST_F(ExtensionsServiceTest, UpdateToSameVersionIsNoop) { 932 TEST_F(ExtensionsServiceTest, UpdateToSameVersionIsNoop) {
989 InitializeEmptyExtensionsService(); 933 InitializeEmptyExtensionsService();
990 FilePath extensions_path; 934 FilePath extensions_path;
991 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 935 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
992 extensions_path = extensions_path.AppendASCII("extensions"); 936 extensions_path = extensions_path.AppendASCII("extensions");
993 937
994 FilePath path = extensions_path.AppendASCII("good.crx"); 938 FilePath path = extensions_path.AppendASCII("good.crx");
995 939
996 InstallExtension(path, true); 940 InstallExtension(path, true);
997 Extension* good = service_->extensions()->at(0); 941 Extension* good = service_->extensions()->at(0);
998 ASSERT_EQ(good_crx, good->id()); 942 ASSERT_EQ(good_crx, good->id());
999 UpdateExtension(good_crx, path, false, true, false); 943 UpdateExtension(good_crx, path, false, false);
1000 } 944 }
1001 945
1002 // Tests uninstalling normal extensions 946 // Tests uninstalling normal extensions
1003 TEST_F(ExtensionsServiceTest, UninstallExtension) { 947 TEST_F(ExtensionsServiceTest, UninstallExtension) {
1004 InitializeEmptyExtensionsService(); 948 InitializeEmptyExtensionsService();
1005 FilePath extensions_path; 949 FilePath extensions_path;
1006 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 950 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1007 extensions_path = extensions_path.AppendASCII("extensions"); 951 extensions_path = extensions_path.AppendASCII("extensions");
1008 952
1009 // A simple extension that should install without error. 953 // A simple extension that should install without error.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 // --load-extension doesn't add entries to prefs 1072 // --load-extension doesn't add entries to prefs
1129 ValidatePrefKeyCount(0); 1073 ValidatePrefKeyCount(0);
1130 } 1074 }
1131 1075
1132 // Tests the external installation feature 1076 // Tests the external installation feature
1133 #if defined(OS_WIN) 1077 #if defined(OS_WIN)
1134 1078
1135 TEST_F(ExtensionsServiceTest, ExternalInstallRegistry) { 1079 TEST_F(ExtensionsServiceTest, ExternalInstallRegistry) {
1136 // This should all work, even when normal extension installation is disabled. 1080 // This should all work, even when normal extension installation is disabled.
1137 InitializeEmptyExtensionsService(); 1081 InitializeEmptyExtensionsService();
1138 SetExtensionsEnabled(false); 1082 set_extensions_enabled(false);
1139 // Verify that starting with no providers loads no extensions. 1083 // Verify that starting with no providers loads no extensions.
1140 service_->Init(); 1084 service_->Init();
1141 loop_.RunAllPending(); 1085 loop_.RunAllPending();
1142 ASSERT_EQ(0u, loaded_.size()); 1086 ASSERT_EQ(0u, loaded_.size());
1143 1087
1144 // Now add providers. Extension system takes ownership of the objects. 1088 // Now add providers. Extension system takes ownership of the objects.
1145 MockExtensionProvider* reg_provider = 1089 MockExtensionProvider* reg_provider =
1146 new MockExtensionProvider(Extension::EXTERNAL_REGISTRY); 1090 new MockExtensionProvider(Extension::EXTERNAL_REGISTRY);
1147 SetMockExternalProvider(Extension::EXTERNAL_REGISTRY, reg_provider); 1091 SetMockExternalProvider(Extension::EXTERNAL_REGISTRY, reg_provider);
1148 1092
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 service_->LoadAllExtensions(); 1277 service_->LoadAllExtensions();
1334 loop_.RunAllPending(); 1278 loop_.RunAllPending();
1335 ASSERT_EQ(0u, loaded_.size()); 1279 ASSERT_EQ(0u, loaded_.size());
1336 ValidatePrefKeyCount(0); 1280 ValidatePrefKeyCount(0);
1337 1281
1338 // The extension should also be gone from the install directory. 1282 // The extension should also be gone from the install directory.
1339 ASSERT_FALSE(file_util::PathExists(install_path)); 1283 ASSERT_FALSE(file_util::PathExists(install_path));
1340 1284
1341 // It should still work if extensions are disabled (disableness doesn't 1285 // It should still work if extensions are disabled (disableness doesn't
1342 // apply to externally registered extensions). 1286 // apply to externally registered extensions).
1343 SetExtensionsEnabled(false); 1287 set_extensions_enabled(false);
1344 1288
1345 pref_provider->UpdateOrAddExtension(good_crx, "1.0", source_path); 1289 pref_provider->UpdateOrAddExtension(good_crx, "1.0", source_path);
1346 service_->CheckForExternalUpdates(); 1290 service_->CheckForExternalUpdates();
1347 loop_.RunAllPending(); 1291 loop_.RunAllPending();
1348 1292
1349 ASSERT_EQ(1u, loaded_.size()); 1293 ASSERT_EQ(1u, loaded_.size());
1350 ASSERT_EQ(0u, GetErrors().size()); 1294 ASSERT_EQ(0u, GetErrors().size());
1351 } 1295 }
1352 1296
1353 TEST_F(ExtensionsServiceTest, ExternalPrefProvider) { 1297 TEST_F(ExtensionsServiceTest, ExternalPrefProvider) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 1414
1471 recorder.set_ready(false); 1415 recorder.set_ready(false);
1472 command_line.reset(new CommandLine(L"")); 1416 command_line.reset(new CommandLine(L""));
1473 service = new ExtensionsService(&profile, command_line.get(), 1417 service = new ExtensionsService(&profile, command_line.get(),
1474 profile.GetPrefs(), install_dir, &loop, &loop, false); 1418 profile.GetPrefs(), install_dir, &loop, &loop, false);
1475 EXPECT_TRUE(service->extensions_enabled()); 1419 EXPECT_TRUE(service->extensions_enabled());
1476 service->Init(); 1420 service->Init();
1477 loop.RunAllPending(); 1421 loop.RunAllPending();
1478 EXPECT_TRUE(recorder.ready()); 1422 EXPECT_TRUE(recorder.ready());
1479 } 1423 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service.cc ('k') | chrome/browser/extensions/external_extension_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698