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

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

Issue 132003: Disable extensions besides externally installed ones and themes. (Closed)
Patch Set: Fix ui test bustage Created 11 years, 6 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/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/json_reader.h" 10 #include "base/json_reader.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 NotificationService::AllSources()); 124 NotificationService::AllSources());
125 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 125 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
126 NotificationService::AllSources()); 126 NotificationService::AllSources());
127 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED, 127 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED,
128 NotificationService::AllSources()); 128 NotificationService::AllSources());
129 registrar_.Add(this, NotificationType::THEME_INSTALLED, 129 registrar_.Add(this, NotificationType::THEME_INSTALLED,
130 NotificationService::AllSources()); 130 NotificationService::AllSources());
131 131
132 profile_.reset(new TestingProfile()); 132 profile_.reset(new TestingProfile());
133 service_ = new ExtensionsService(profile_.get(), &loop_, &loop_); 133 service_ = new ExtensionsService(profile_.get(), &loop_, &loop_);
134 service_->set_extensions_enabled(true); 134 service_->SetExtensionsEnabled(true);
135 service_->set_show_extensions_prompts(false); 135 service_->set_show_extensions_prompts(false);
136 136
137 // When we start up, we want to make sure there is no external provider, 137 // When we start up, we want to make sure there is no external provider,
138 // since the ExtensionService on Windows will use the Registry as a default 138 // since the ExtensionService on Windows will use the Registry as a default
139 // provider and if there is something already registered there then it will 139 // provider and if there is something already registered there then it will
140 // interfere with the tests. Those tests that need an external provider 140 // interfere with the tests. Those tests that need an external provider
141 // will register one specifically. 141 // will register one specifically.
142 service_->ClearProvidersForTesting(); 142 service_->ClearProvidersForTesting();
143 143
144 total_successes_ = 0; 144 total_successes_ = 0;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 case NotificationType::THEME_INSTALLED: 184 case NotificationType::THEME_INSTALLED:
185 installed_ = Details<Extension>(details).ptr(); 185 installed_ = Details<Extension>(details).ptr();
186 break; 186 break;
187 187
188 default: 188 default:
189 DCHECK(false); 189 DCHECK(false);
190 } 190 }
191 } 191 }
192 192
193 void SetExtensionsEnabled(bool enabled) { 193 void SetExtensionsEnabled(bool enabled) {
194 service_->set_extensions_enabled(enabled); 194 service_->SetExtensionsEnabled(enabled);
195 } 195 }
196 196
197 void SetMockExternalProvider(Extension::Location location, 197 void SetMockExternalProvider(Extension::Location location,
198 ExternalExtensionProvider* provider) { 198 ExternalExtensionProvider* provider) {
199 service_->SetProviderForTesting(location, provider); 199 service_->SetProviderForTesting(location, provider);
200 } 200 }
201 201
202 protected: 202 protected:
203 void InstallExtension(const FilePath& path, 203 void InstallExtension(const FilePath& path,
204 bool should_succeed) { 204 bool should_succeed) {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 ValidatePrefKeyCount(pref_count); 491 ValidatePrefKeyCount(pref_count);
492 492
493 // TODO(erikkay): add more tests for many of the failure cases. 493 // TODO(erikkay): add more tests for many of the failure cases.
494 // TODO(erikkay): add tests for upgrade cases. 494 // TODO(erikkay): add tests for upgrade cases.
495 } 495 }
496 496
497 #if defined(OS_WIN) // TODO(port) 497 #if defined(OS_WIN) // TODO(port)
498 // Test Packaging and installing an extension. 498 // Test Packaging and installing an extension.
499 // TODO(rafaelw): add more tests for failure cases. 499 // TODO(rafaelw): add more tests for failure cases.
500 TEST_F(ExtensionsServiceTest, PackExtension) { 500 TEST_F(ExtensionsServiceTest, PackExtension) {
501 SetExtensionsEnabled(true);
502
503 FilePath extensions_path; 501 FilePath extensions_path;
504 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 502 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
505 extensions_path = extensions_path.AppendASCII("extensions"); 503 extensions_path = extensions_path.AppendASCII("extensions");
506 FilePath input_directory = extensions_path.AppendASCII("good") 504 FilePath input_directory = extensions_path.AppendASCII("good")
507 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj").AppendASCII("1.0.0.0"); 505 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj").AppendASCII("1.0.0.0");
508 506
509 FilePath output_directory; 507 FilePath output_directory;
510 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_"), 508 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_"),
511 &output_directory); 509 &output_directory);
512 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); 510 FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
(...skipping 10 matching lines...) Expand all
523 file_util::Delete(privkey_path, false); 521 file_util::Delete(privkey_path, false);
524 } 522 }
525 523
526 // Test Packaging and installing an extension using an openssl generated key. 524 // Test Packaging and installing an extension using an openssl generated key.
527 // The openssl is generated with the following: 525 // The openssl is generated with the following:
528 // > openssl genrsa -out privkey.pem 1024 526 // > openssl genrsa -out privkey.pem 1024
529 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem 527 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem
530 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a 528 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a
531 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. 529 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects.
532 TEST_F(ExtensionsServiceTest, PackExtensionOpenSSLKey) { 530 TEST_F(ExtensionsServiceTest, PackExtensionOpenSSLKey) {
533 SetExtensionsEnabled(true);
534
535 FilePath extensions_path; 531 FilePath extensions_path;
536 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 532 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
537 extensions_path = extensions_path.AppendASCII("extensions"); 533 extensions_path = extensions_path.AppendASCII("extensions");
538 FilePath input_directory = extensions_path.AppendASCII("good") 534 FilePath input_directory = extensions_path.AppendASCII("good")
539 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj").AppendASCII("1.0.0.0"); 535 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj").AppendASCII("1.0.0.0");
540 FilePath privkey_path(extensions_path.AppendASCII( 536 FilePath privkey_path(extensions_path.AppendASCII(
541 "openssl_privkey_asn1.pem")); 537 "openssl_privkey_asn1.pem"));
542 ASSERT_TRUE(file_util::PathExists(privkey_path)); 538 ASSERT_TRUE(file_util::PathExists(privkey_path));
543 539
544 FilePath output_directory; 540 FilePath output_directory;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 EXPECT_EQ(loaded_[1]->location(), Extension::LOAD); 793 EXPECT_EQ(loaded_[1]->location(), Extension::LOAD);
798 794
799 // --load-extension doesn't add entries to prefs 795 // --load-extension doesn't add entries to prefs
800 ValidatePrefKeyCount(0); 796 ValidatePrefKeyCount(0);
801 } 797 }
802 798
803 // Tests the external installation feature 799 // Tests the external installation feature
804 #if defined(OS_WIN) 800 #if defined(OS_WIN)
805 801
806 TEST_F(ExtensionsServiceTest, ExternalInstallRegistry) { 802 TEST_F(ExtensionsServiceTest, ExternalInstallRegistry) {
803 // This should all work, even when normal extension installation is disabled.
804 SetExtensionsEnabled(false);
805
807 // Verify that starting with no providers loads no extensions. 806 // Verify that starting with no providers loads no extensions.
808 service_->Init(); 807 service_->Init();
809 loop_.RunAllPending(); 808 loop_.RunAllPending();
810 ASSERT_EQ(0u, loaded_.size()); 809 ASSERT_EQ(0u, loaded_.size());
811 810
812 // Now add providers. Extension system takes ownership of the objects. 811 // Now add providers. Extension system takes ownership of the objects.
813 MockExtensionProvider* reg_provider = 812 MockExtensionProvider* reg_provider =
814 new MockExtensionProvider(Extension::EXTERNAL_REGISTRY); 813 new MockExtensionProvider(Extension::EXTERNAL_REGISTRY);
815 SetMockExternalProvider(Extension::EXTERNAL_REGISTRY, reg_provider); 814 SetMockExternalProvider(Extension::EXTERNAL_REGISTRY, reg_provider);
816 815
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 1005
1007 ValidatePrefKeyCount(1); 1006 ValidatePrefKeyCount(1);
1008 ValidatePref(good_crx, L"state", Extension::KILLBIT); 1007 ValidatePref(good_crx, L"state", Extension::KILLBIT);
1009 ValidatePref(good_crx, L"location", Extension::EXTERNAL_PREF); 1008 ValidatePref(good_crx, L"location", Extension::EXTERNAL_PREF);
1010 1009
1011 // The extension should also be gone from disk. 1010 // The extension should also be gone from disk.
1012 FilePath extension_path = install_path.DirName(); 1011 FilePath extension_path = install_path.DirName();
1013 extension_path = extension_path.AppendASCII(good_crx); 1012 extension_path = extension_path.AppendASCII(good_crx);
1014 EXPECT_FALSE(file_util::PathExists(extension_path)) << 1013 EXPECT_FALSE(file_util::PathExists(extension_path)) <<
1015 extension_path.ToWStringHack(); 1014 extension_path.ToWStringHack();
1015
1016 // This shouldn't work if extensions are disabled.
1017 SetExtensionsEnabled(false);
1018
1019 pref_provider->UpdateOrAddExtension(good_crx, "1.0", source_path);
1020 service_->CheckForUpdates();
1021 loop_.RunAllPending();
1022
1023 ASSERT_EQ(0u, loaded_.size());
1024 ASSERT_EQ(1u, GetErrors().size());
1016 } 1025 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service.cc ('k') | chrome/browser/renderer_host/browser_render_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698