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

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

Issue 8417012: Refactor loading out of ExtensionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: finally Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/json/json_reader.h" 15 #include "base/json/json_reader.h"
16 #include "base/json/json_value_serializer.h" 16 #include "base/json/json_value_serializer.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/message_loop.h" 18 #include "base/message_loop.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/scoped_temp_dir.h" 20 #include "base/scoped_temp_dir.h"
21 #include "base/stl_util.h" 21 #include "base/stl_util.h"
22 #include "base/string16.h" 22 #include "base/string16.h"
23 #include "base/string_number_conversions.h" 23 #include "base/string_number_conversions.h"
24 #include "base/string_util.h" 24 #include "base/string_util.h"
25 #include "base/utf_string_conversions.h" 25 #include "base/utf_string_conversions.h"
26 #include "base/version.h" 26 #include "base/version.h"
27 #include "chrome/browser/browser_process.h" 27 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/extensions/crx_installer.h" 28 #include "chrome/browser/extensions/crx_installer.h"
29 #include "chrome/browser/extensions/component_loader.h"
29 #include "chrome/browser/extensions/extension_creator.h" 30 #include "chrome/browser/extensions/extension_creator.h"
30 #include "chrome/browser/extensions/extension_error_reporter.h" 31 #include "chrome/browser/extensions/extension_error_reporter.h"
31 #include "chrome/browser/extensions/extension_service.h" 32 #include "chrome/browser/extensions/extension_service.h"
32 #include "chrome/browser/extensions/extension_special_storage_policy.h" 33 #include "chrome/browser/extensions/extension_special_storage_policy.h"
33 #include "chrome/browser/extensions/extension_sync_data.h" 34 #include "chrome/browser/extensions/extension_sync_data.h"
34 #include "chrome/browser/extensions/extension_updater.h" 35 #include "chrome/browser/extensions/extension_updater.h"
35 #include "chrome/browser/extensions/external_extension_provider_impl.h" 36 #include "chrome/browser/extensions/external_extension_provider_impl.h"
36 #include "chrome/browser/extensions/external_extension_provider_interface.h" 37 #include "chrome/browser/extensions/external_extension_provider_interface.h"
37 #include "chrome/browser/extensions/external_pref_extension_loader.h" 38 #include "chrome/browser/extensions/external_pref_extension_loader.h"
39 #include "chrome/browser/extensions/installed_loader.h"
38 #include "chrome/browser/extensions/pack_extension_job.cc" 40 #include "chrome/browser/extensions/pack_extension_job.cc"
39 #include "chrome/browser/extensions/pending_extension_info.h" 41 #include "chrome/browser/extensions/pending_extension_info.h"
40 #include "chrome/browser/extensions/pending_extension_manager.h" 42 #include "chrome/browser/extensions/pending_extension_manager.h"
43 #include "chrome/browser/extensions/unpacked_installer.h"
41 #include "chrome/browser/prefs/browser_prefs.h" 44 #include "chrome/browser/prefs/browser_prefs.h"
42 #include "chrome/browser/prefs/pref_service_mock_builder.h" 45 #include "chrome/browser/prefs/pref_service_mock_builder.h"
43 #include "chrome/browser/prefs/scoped_user_pref_update.h" 46 #include "chrome/browser/prefs/scoped_user_pref_update.h"
44 #include "chrome/browser/sync/protocol/app_specifics.pb.h" 47 #include "chrome/browser/sync/protocol/app_specifics.pb.h"
45 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" 48 #include "chrome/browser/sync/protocol/extension_specifics.pb.h"
46 #include "chrome/common/chrome_notification_types.h" 49 #include "chrome/common/chrome_notification_types.h"
47 #include "chrome/common/chrome_paths.h" 50 #include "chrome/common/chrome_paths.h"
48 #include "chrome/common/chrome_switches.h" 51 #include "chrome/common/chrome_switches.h"
49 #include "chrome/common/extensions/extension.h" 52 #include "chrome/common/extensions/extension.h"
50 #include "chrome/common/extensions/extension_constants.h" 53 #include "chrome/common/extensions/extension_constants.h"
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 // to happen, use loop_.RunAllPending();. Most tests will not use this 584 // to happen, use loop_.RunAllPending();. Most tests will not use this
582 // method directly. Instead, use InstallCrx(), which waits for 585 // method directly. Instead, use InstallCrx(), which waits for
583 // the crx to be installed and does extra error checking. 586 // the crx to be installed and does extra error checking.
584 void StartCrxInstall(const FilePath& crx_path) { 587 void StartCrxInstall(const FilePath& crx_path) {
585 StartCrxInstall(crx_path, false); 588 StartCrxInstall(crx_path, false);
586 } 589 }
587 590
588 void StartCrxInstall(const FilePath& crx_path, bool from_webstore) { 591 void StartCrxInstall(const FilePath& crx_path, bool from_webstore) {
589 ASSERT_TRUE(file_util::PathExists(crx_path)) 592 ASSERT_TRUE(file_util::PathExists(crx_path))
590 << "Path does not exist: "<< crx_path.value().c_str(); 593 << "Path does not exist: "<< crx_path.value().c_str();
591 scoped_refptr<CrxInstaller> installer( 594 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
592 service_->MakeCrxInstaller(NULL));
593 installer->set_allow_silent_install(true); 595 installer->set_allow_silent_install(true);
594 installer->set_is_gallery_install(from_webstore); 596 installer->set_is_gallery_install(from_webstore);
595 installer->InstallCrx(crx_path); 597 installer->InstallCrx(crx_path);
596 } 598 }
597 599
598 void InstallCrx(const FilePath& path, 600 void InstallCrx(const FilePath& path,
599 bool should_succeed) { 601 bool should_succeed) {
600 StartCrxInstall(path); 602 StartCrxInstall(path);
601 WaitForCrxInstall(path, should_succeed); 603 WaitForCrxInstall(path, should_succeed);
602 } 604 }
603 605
604 void InstallCrxWithLocation(const FilePath& crx_path, 606 void InstallCrxWithLocation(const FilePath& crx_path,
605 Extension::Location install_location, 607 Extension::Location install_location,
606 bool should_succeed) { 608 bool should_succeed) {
607 ASSERT_TRUE(file_util::PathExists(crx_path)) 609 ASSERT_TRUE(file_util::PathExists(crx_path))
608 << "Path does not exist: "<< crx_path.value().c_str(); 610 << "Path does not exist: "<< crx_path.value().c_str();
609 // no client (silent install) 611 // no client (silent install)
610 scoped_refptr<CrxInstaller> installer(service_->MakeCrxInstaller(NULL)); 612 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
611 613
612 installer->set_install_source(install_location); 614 installer->set_install_source(install_location);
613 installer->InstallCrx(crx_path); 615 installer->InstallCrx(crx_path);
614 616
615 WaitForCrxInstall(crx_path, should_succeed); 617 WaitForCrxInstall(crx_path, should_succeed);
616 } 618 }
617 619
618 // Wait for a CrxInstaller to finish. Used by InstallCrx. 620 // Wait for a CrxInstaller to finish. Used by InstallCrx.
619 void WaitForCrxInstall(const FilePath& path, 621 void WaitForCrxInstall(const FilePath& path,
620 bool should_succeed) { 622 bool should_succeed) {
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 // Install a user script (they get converted automatically to an extension) 1367 // Install a user script (they get converted automatically to an extension)
1366 TEST_F(ExtensionServiceTest, InstallUserScript) { 1368 TEST_F(ExtensionServiceTest, InstallUserScript) {
1367 // The details of script conversion are tested elsewhere, this just tests 1369 // The details of script conversion are tested elsewhere, this just tests
1368 // integration with ExtensionService. 1370 // integration with ExtensionService.
1369 InitializeEmptyExtensionService(); 1371 InitializeEmptyExtensionService();
1370 1372
1371 FilePath path = data_dir_ 1373 FilePath path = data_dir_
1372 .AppendASCII("user_script_basic.user.js"); 1374 .AppendASCII("user_script_basic.user.js");
1373 1375
1374 ASSERT_TRUE(file_util::PathExists(path)); 1376 ASSERT_TRUE(file_util::PathExists(path));
1375 scoped_refptr<CrxInstaller> installer( 1377 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
1376 service_->MakeCrxInstaller(NULL));
1377 installer->set_allow_silent_install(true); 1378 installer->set_allow_silent_install(true);
1378 installer->InstallUserScript( 1379 installer->InstallUserScript(
1379 path, 1380 path,
1380 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); 1381 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js"));
1381 1382
1382 loop_.RunAllPending(); 1383 loop_.RunAllPending();
1383 std::vector<std::string> errors = GetErrors(); 1384 std::vector<std::string> errors = GetErrors();
1384 EXPECT_TRUE(installed_) << "Nothing was installed."; 1385 EXPECT_TRUE(installed_) << "Nothing was installed.";
1385 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; 1386 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded.";
1386 EXPECT_EQ(0u, errors.size()) << "There were errors: " 1387 EXPECT_EQ(0u, errors.size()) << "There were errors: "
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 InstallCrx(path, false); 1755 InstallCrx(path, false);
1755 ValidatePrefKeyCount(pref_count); 1756 ValidatePrefKeyCount(pref_count);
1756 } 1757 }
1757 1758
1758 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { 1759 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) {
1759 // Load. 1760 // Load.
1760 InitializeEmptyExtensionService(); 1761 InitializeEmptyExtensionService();
1761 FilePath extension_path = data_dir_ 1762 FilePath extension_path = data_dir_
1762 .AppendASCII("theme_i18n"); 1763 .AppendASCII("theme_i18n");
1763 1764
1764 service_->LoadExtension(extension_path); 1765 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
1765 loop_.RunAllPending(); 1766 loop_.RunAllPending();
1766 EXPECT_EQ(0u, GetErrors().size()); 1767 EXPECT_EQ(0u, GetErrors().size());
1767 ASSERT_EQ(1u, loaded_.size()); 1768 ASSERT_EQ(1u, loaded_.size());
1768 EXPECT_EQ(1u, service_->extensions()->size()); 1769 EXPECT_EQ(1u, service_->extensions()->size());
1769 EXPECT_EQ("name", service_->extensions()->at(0)->name()); 1770 EXPECT_EQ("name", service_->extensions()->at(0)->name());
1770 EXPECT_EQ("description", service_->extensions()->at(0)->description()); 1771 EXPECT_EQ("description", service_->extensions()->at(0)->description());
1771 } 1772 }
1772 1773
1773 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { 1774 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) {
1774 InitializeEmptyExtensionService(); 1775 InitializeEmptyExtensionService();
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
2170 ASSERT_FALSE(file_util::PathExists(manifest_path)); 2171 ASSERT_FALSE(file_util::PathExists(manifest_path));
2171 2172
2172 // Start with version 2.0. 2173 // Start with version 2.0.
2173 DictionaryValue manifest; 2174 DictionaryValue manifest;
2174 manifest.SetString("version", "2.0"); 2175 manifest.SetString("version", "2.0");
2175 manifest.SetString("name", "LOAD Downgrade Test"); 2176 manifest.SetString("name", "LOAD Downgrade Test");
2176 2177
2177 JSONFileValueSerializer serializer(manifest_path); 2178 JSONFileValueSerializer serializer(manifest_path);
2178 ASSERT_TRUE(serializer.Serialize(manifest)); 2179 ASSERT_TRUE(serializer.Serialize(manifest));
2179 2180
2180 service_->LoadExtension(extension_path); 2181 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2181 loop_.RunAllPending(); 2182 loop_.RunAllPending();
2182 2183
2183 EXPECT_EQ(0u, GetErrors().size()); 2184 EXPECT_EQ(0u, GetErrors().size());
2184 ASSERT_EQ(1u, loaded_.size()); 2185 ASSERT_EQ(1u, loaded_.size());
2185 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); 2186 EXPECT_EQ(Extension::LOAD, loaded_[0]->location());
2186 EXPECT_EQ(1u, service_->extensions()->size()); 2187 EXPECT_EQ(1u, service_->extensions()->size());
2187 EXPECT_EQ("2.0", loaded_[0]->VersionString()); 2188 EXPECT_EQ("2.0", loaded_[0]->VersionString());
2188 2189
2189 // Now set the version number to 1.0, reload the extensions and verify that 2190 // Now set the version number to 1.0, reload the extensions and verify that
2190 // the downgrade was accepted. 2191 // the downgrade was accepted.
2191 manifest.SetString("version", "1.0"); 2192 manifest.SetString("version", "1.0");
2192 ASSERT_TRUE(serializer.Serialize(manifest)); 2193 ASSERT_TRUE(serializer.Serialize(manifest));
2193 2194
2194 service_->LoadExtension(extension_path); 2195 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2195 loop_.RunAllPending(); 2196 loop_.RunAllPending();
2196 2197
2197 EXPECT_EQ(0u, GetErrors().size()); 2198 EXPECT_EQ(0u, GetErrors().size());
2198 ASSERT_EQ(1u, loaded_.size()); 2199 ASSERT_EQ(1u, loaded_.size());
2199 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); 2200 EXPECT_EQ(Extension::LOAD, loaded_[0]->location());
2200 EXPECT_EQ(1u, service_->extensions()->size()); 2201 EXPECT_EQ(1u, service_->extensions()->size());
2201 EXPECT_EQ("1.0", loaded_[0]->VersionString()); 2202 EXPECT_EQ("1.0", loaded_[0]->VersionString());
2202 } 2203 }
2203 2204
2204 namespace { 2205 namespace {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
2613 2614
2614 // Install a component extension. 2615 // Install a component extension.
2615 FilePath path = data_dir_ 2616 FilePath path = data_dir_
2616 .AppendASCII("good") 2617 .AppendASCII("good")
2617 .AppendASCII("Extensions") 2618 .AppendASCII("Extensions")
2618 .AppendASCII(good0) 2619 .AppendASCII(good0)
2619 .AppendASCII("1.0.0.0"); 2620 .AppendASCII("1.0.0.0");
2620 std::string manifest; 2621 std::string manifest;
2621 ASSERT_TRUE(file_util::ReadFileToString( 2622 ASSERT_TRUE(file_util::ReadFileToString(
2622 path.Append(Extension::kManifestFilename), &manifest)); 2623 path.Append(Extension::kManifestFilename), &manifest));
2623 service_->register_component_extension( 2624 service_->component_loader()->Add(manifest, path);
2624 ExtensionService::ComponentExtensionInfo(manifest, path));
2625 service_->Init(); 2625 service_->Init();
2626 2626
2627 // Extension should be installed despite blacklist. 2627 // Extension should be installed despite blacklist.
2628 ASSERT_EQ(1u, service_->extensions()->size()); 2628 ASSERT_EQ(1u, service_->extensions()->size());
2629 EXPECT_EQ(good0, service_->extensions()->at(0)->id()); 2629 EXPECT_EQ(good0, service_->extensions()->at(0)->id());
2630 2630
2631 // Poke external providers and make sure the extension is still present. 2631 // Poke external providers and make sure the extension is still present.
2632 service_->CheckForExternalUpdates(); 2632 service_->CheckForExternalUpdates();
2633 ASSERT_EQ(1u, service_->extensions()->size()); 2633 ASSERT_EQ(1u, service_->extensions()->size());
2634 EXPECT_EQ(good0, service_->extensions()->at(0)->id()); 2634 EXPECT_EQ(good0, service_->extensions()->at(0)->id());
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
3065 3065
3066 // Tests loading single extensions (like --load-extension) 3066 // Tests loading single extensions (like --load-extension)
3067 TEST_F(ExtensionServiceTest, LoadExtension) { 3067 TEST_F(ExtensionServiceTest, LoadExtension) {
3068 InitializeEmptyExtensionService(); 3068 InitializeEmptyExtensionService();
3069 3069
3070 FilePath ext1 = data_dir_ 3070 FilePath ext1 = data_dir_
3071 .AppendASCII("good") 3071 .AppendASCII("good")
3072 .AppendASCII("Extensions") 3072 .AppendASCII("Extensions")
3073 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 3073 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
3074 .AppendASCII("1.0.0.0"); 3074 .AppendASCII("1.0.0.0");
3075 service_->LoadExtension(ext1); 3075 extensions::UnpackedInstaller::Create(service_)->Load(ext1);
3076 loop_.RunAllPending(); 3076 loop_.RunAllPending();
3077 EXPECT_EQ(0u, GetErrors().size()); 3077 EXPECT_EQ(0u, GetErrors().size());
3078 ASSERT_EQ(1u, loaded_.size()); 3078 ASSERT_EQ(1u, loaded_.size());
3079 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); 3079 EXPECT_EQ(Extension::LOAD, loaded_[0]->location());
3080 EXPECT_EQ(1u, service_->extensions()->size()); 3080 EXPECT_EQ(1u, service_->extensions()->size());
3081 3081
3082 ValidatePrefKeyCount(1); 3082 ValidatePrefKeyCount(1);
3083 3083
3084 FilePath no_manifest = data_dir_ 3084 FilePath no_manifest = data_dir_
3085 .AppendASCII("bad") 3085 .AppendASCII("bad")
3086 // .AppendASCII("Extensions") 3086 // .AppendASCII("Extensions")
3087 .AppendASCII("cccccccccccccccccccccccccccccccc") 3087 .AppendASCII("cccccccccccccccccccccccccccccccc")
3088 .AppendASCII("1"); 3088 .AppendASCII("1");
3089 service_->LoadExtension(no_manifest); 3089 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest);
3090 loop_.RunAllPending(); 3090 loop_.RunAllPending();
3091 EXPECT_EQ(1u, GetErrors().size()); 3091 EXPECT_EQ(1u, GetErrors().size());
3092 ASSERT_EQ(1u, loaded_.size()); 3092 ASSERT_EQ(1u, loaded_.size());
3093 EXPECT_EQ(1u, service_->extensions()->size()); 3093 EXPECT_EQ(1u, service_->extensions()->size());
3094 3094
3095 // Test uninstall. 3095 // Test uninstall.
3096 std::string id = loaded_[0]->id(); 3096 std::string id = loaded_[0]->id();
3097 EXPECT_FALSE(unloaded_id_.length()); 3097 EXPECT_FALSE(unloaded_id_.length());
3098 service_->UninstallExtension(id, false, NULL); 3098 service_->UninstallExtension(id, false, NULL);
3099 loop_.RunAllPending(); 3099 loop_.RunAllPending();
3100 EXPECT_EQ(id, unloaded_id_); 3100 EXPECT_EQ(id, unloaded_id_);
3101 ASSERT_EQ(0u, loaded_.size()); 3101 ASSERT_EQ(0u, loaded_.size());
3102 EXPECT_EQ(0u, service_->extensions()->size()); 3102 EXPECT_EQ(0u, service_->extensions()->size());
3103 } 3103 }
3104 3104
3105 // Tests that we generate IDs when they are not specified in the manifest for 3105 // Tests that we generate IDs when they are not specified in the manifest for
3106 // --load-extension. 3106 // --load-extension.
3107 TEST_F(ExtensionServiceTest, GenerateID) { 3107 TEST_F(ExtensionServiceTest, GenerateID) {
3108 InitializeEmptyExtensionService(); 3108 InitializeEmptyExtensionService();
3109 3109
3110 3110
3111 FilePath no_id_ext = data_dir_.AppendASCII("no_id"); 3111 FilePath no_id_ext = data_dir_.AppendASCII("no_id");
3112 service_->LoadExtension(no_id_ext); 3112 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext);
3113 loop_.RunAllPending(); 3113 loop_.RunAllPending();
3114 EXPECT_EQ(0u, GetErrors().size()); 3114 EXPECT_EQ(0u, GetErrors().size());
3115 ASSERT_EQ(1u, loaded_.size()); 3115 ASSERT_EQ(1u, loaded_.size());
3116 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); 3116 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id()));
3117 EXPECT_EQ(loaded_[0]->location(), Extension::LOAD); 3117 EXPECT_EQ(loaded_[0]->location(), Extension::LOAD);
3118 3118
3119 ValidatePrefKeyCount(1); 3119 ValidatePrefKeyCount(1);
3120 3120
3121 std::string previous_id = loaded_[0]->id(); 3121 std::string previous_id = loaded_[0]->id();
3122 3122
3123 // If we reload the same path, we should get the same extension ID. 3123 // If we reload the same path, we should get the same extension ID.
3124 service_->LoadExtension(no_id_ext); 3124 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext);
3125 loop_.RunAllPending(); 3125 loop_.RunAllPending();
3126 ASSERT_EQ(1u, loaded_.size()); 3126 ASSERT_EQ(1u, loaded_.size());
3127 ASSERT_EQ(previous_id, loaded_[0]->id()); 3127 ASSERT_EQ(previous_id, loaded_[0]->id());
3128 } 3128 }
3129 3129
3130 void ExtensionServiceTest::TestExternalProvider( 3130 void ExtensionServiceTest::TestExternalProvider(
3131 MockExtensionProvider* provider, Extension::Location location) { 3131 MockExtensionProvider* provider, Extension::Location location) {
3132 // Verify that starting with no providers loads no extensions. 3132 // Verify that starting with no providers loads no extensions.
3133 service_->Init(); 3133 service_->Init();
3134 loop_.RunAllPending(); 3134 loop_.RunAllPending();
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
3243 loaded_.clear(); 3243 loaded_.clear();
3244 service_->UninstallExtension(id, false, NULL); 3244 service_->UninstallExtension(id, false, NULL);
3245 loop_.RunAllPending(); 3245 loop_.RunAllPending();
3246 ASSERT_EQ(0u, loaded_.size()); 3246 ASSERT_EQ(0u, loaded_.size());
3247 3247
3248 // Then remove the extension from the extension provider. 3248 // Then remove the extension from the extension provider.
3249 provider->RemoveExtension(good_crx); 3249 provider->RemoveExtension(good_crx);
3250 3250
3251 // Should still be at 0. 3251 // Should still be at 0.
3252 loaded_.clear(); 3252 loaded_.clear();
3253 service_->LoadAllExtensions(); 3253 extensions::InstalledLoader(service_).LoadAllExtensions();
3254 loop_.RunAllPending(); 3254 loop_.RunAllPending();
3255 ASSERT_EQ(0u, loaded_.size()); 3255 ASSERT_EQ(0u, loaded_.size());
3256 ValidatePrefKeyCount(1); 3256 ValidatePrefKeyCount(1);
3257 3257
3258 EXPECT_EQ(5, provider->visit_count()); 3258 EXPECT_EQ(5, provider->visit_count());
3259 } else { 3259 } else {
3260 EXPECT_EQ(2, provider->visit_count()); 3260 EXPECT_EQ(2, provider->visit_count());
3261 } 3261 }
3262 } 3262 }
3263 3263
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
3694 .AppendASCII("1.0"); 3694 .AppendASCII("1.0");
3695 3695
3696 // The old permission name for unlimited quota was "unlimited_storage", but 3696 // The old permission name for unlimited quota was "unlimited_storage", but
3697 // we changed it to "unlimitedStorage". This tests both versions. 3697 // we changed it to "unlimitedStorage". This tests both versions.
3698 FilePath unlimited_quota_ext = 3698 FilePath unlimited_quota_ext =
3699 extensions_path.AppendASCII("unlimited_quota") 3699 extensions_path.AppendASCII("unlimited_quota")
3700 .AppendASCII("1.0"); 3700 .AppendASCII("1.0");
3701 FilePath unlimited_quota_ext2 = 3701 FilePath unlimited_quota_ext2 =
3702 extensions_path.AppendASCII("unlimited_quota") 3702 extensions_path.AppendASCII("unlimited_quota")
3703 .AppendASCII("2.0"); 3703 .AppendASCII("2.0");
3704 service_->LoadExtension(limited_quota_ext); 3704 extensions::UnpackedInstaller::Create(service_)->Load(limited_quota_ext);
3705 service_->LoadExtension(unlimited_quota_ext); 3705 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext);
3706 service_->LoadExtension(unlimited_quota_ext2); 3706 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext2);
3707 loop_.RunAllPending(); 3707 loop_.RunAllPending();
3708 3708
3709 ASSERT_EQ(3u, loaded_.size()); 3709 ASSERT_EQ(3u, loaded_.size());
3710 EXPECT_TRUE(profile_.get()); 3710 EXPECT_TRUE(profile_.get());
3711 EXPECT_FALSE(profile_->IsOffTheRecord()); 3711 EXPECT_FALSE(profile_->IsOffTheRecord());
3712 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 3712 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
3713 loaded_[0]->url())); 3713 loaded_[0]->url()));
3714 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 3714 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
3715 loaded_[1]->url())); 3715 loaded_[1]->url()));
3716 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 3716 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
3717 loaded_[2]->url())); 3717 loaded_[2]->url()));
3718 } 3718 }
3719 3719
3720 // Tests ExtensionService::register_component_extension(). 3720 // Tests ComponentLoader::Add().
3721 TEST_F(ExtensionServiceTest, ComponentExtensions) { 3721 TEST_F(ExtensionServiceTest, ComponentExtensions) {
3722 InitializeEmptyExtensionService(); 3722 InitializeEmptyExtensionService();
3723 3723
3724 // Component extensions should work even when extensions are disabled. 3724 // Component extensions should work even when extensions are disabled.
3725 set_extensions_enabled(false); 3725 set_extensions_enabled(false);
3726 3726
3727 FilePath path = data_dir_ 3727 FilePath path = data_dir_
3728 .AppendASCII("good") 3728 .AppendASCII("good")
3729 .AppendASCII("Extensions") 3729 .AppendASCII("Extensions")
3730 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 3730 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
3731 .AppendASCII("1.0.0.0"); 3731 .AppendASCII("1.0.0.0");
3732 3732
3733 std::string manifest; 3733 std::string manifest;
3734 ASSERT_TRUE(file_util::ReadFileToString( 3734 ASSERT_TRUE(file_util::ReadFileToString(
3735 path.Append(Extension::kManifestFilename), &manifest)); 3735 path.Append(Extension::kManifestFilename), &manifest));
3736 3736
3737 service_->register_component_extension( 3737 service_->component_loader()->Add(manifest, path);
3738 ExtensionService::ComponentExtensionInfo(manifest, path));
3739 service_->Init(); 3738 service_->Init();
3740 3739
3741 // Note that we do not pump messages -- the extension should be loaded 3740 // Note that we do not pump messages -- the extension should be loaded
3742 // immediately. 3741 // immediately.
3743 3742
3744 EXPECT_EQ(0u, GetErrors().size()); 3743 EXPECT_EQ(0u, GetErrors().size());
3745 ASSERT_EQ(1u, loaded_.size()); 3744 ASSERT_EQ(1u, loaded_.size());
3746 EXPECT_EQ(Extension::COMPONENT, loaded_[0]->location()); 3745 EXPECT_EQ(Extension::COMPONENT, loaded_[0]->location());
3747 EXPECT_EQ(1u, service_->extensions()->size()); 3746 EXPECT_EQ(1u, service_->extensions()->size());
3748 3747
3749 // Component extensions shouldn't get recourded in the prefs. 3748 // Component extensions shouldn't get recorded in the prefs.
3750 ValidatePrefKeyCount(0); 3749 ValidatePrefKeyCount(0);
3751 3750
3752 // Reload all extensions, and make sure it comes back. 3751 // Reload all extensions, and make sure it comes back.
3753 std::string extension_id = service_->extensions()->at(0)->id(); 3752 std::string extension_id = service_->extensions()->at(0)->id();
3754 loaded_.clear(); 3753 loaded_.clear();
3755 service_->ReloadExtensions(); 3754 service_->ReloadExtensions();
3756 ASSERT_EQ(1u, service_->extensions()->size()); 3755 ASSERT_EQ(1u, service_->extensions()->size());
3757 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); 3756 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id());
3758 } 3757 }
3759 3758
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
4320 ASSERT_FALSE(AddPendingSyncInstall()); 4319 ASSERT_FALSE(AddPendingSyncInstall());
4321 4320
4322 // Wait for the external source to install. 4321 // Wait for the external source to install.
4323 WaitForCrxInstall(crx_path_, true); 4322 WaitForCrxInstall(crx_path_, true);
4324 ASSERT_TRUE(IsCrxInstalled()); 4323 ASSERT_TRUE(IsCrxInstalled());
4325 4324
4326 // Now that the extension is installed, sync request should fail 4325 // Now that the extension is installed, sync request should fail
4327 // because the extension is already installed. 4326 // because the extension is already installed.
4328 ASSERT_FALSE(AddPendingSyncInstall()); 4327 ASSERT_FALSE(AddPendingSyncInstall());
4329 } 4328 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/extension_updater_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698