| OLD | NEW |
| 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 13 matching lines...) Expand all Loading... |
| 24 #include "base/path_service.h" | 24 #include "base/path_service.h" |
| 25 #include "base/stl_util.h" | 25 #include "base/stl_util.h" |
| 26 #include "base/strings/string16.h" | 26 #include "base/strings/string16.h" |
| 27 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
| 28 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
| 29 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| 30 #include "base/version.h" | 30 #include "base/version.h" |
| 31 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
| 32 #include "chrome/browser/chrome_notification_types.h" | 32 #include "chrome/browser/chrome_notification_types.h" |
| 33 #include "chrome/browser/extensions/app_sync_data.h" | 33 #include "chrome/browser/extensions/app_sync_data.h" |
| 34 #include "chrome/browser/extensions/blacklist.h" |
| 34 #include "chrome/browser/extensions/component_loader.h" | 35 #include "chrome/browser/extensions/component_loader.h" |
| 35 #include "chrome/browser/extensions/crx_installer.h" | 36 #include "chrome/browser/extensions/crx_installer.h" |
| 36 #include "chrome/browser/extensions/default_apps.h" | 37 #include "chrome/browser/extensions/default_apps.h" |
| 37 #include "chrome/browser/extensions/extension_creator.h" | 38 #include "chrome/browser/extensions/extension_creator.h" |
| 38 #include "chrome/browser/extensions/extension_error_reporter.h" | 39 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 39 #include "chrome/browser/extensions/extension_error_ui.h" | 40 #include "chrome/browser/extensions/extension_error_ui.h" |
| 40 #include "chrome/browser/extensions/extension_notification_observer.h" | 41 #include "chrome/browser/extensions/extension_notification_observer.h" |
| 41 #include "chrome/browser/extensions/extension_service.h" | 42 #include "chrome/browser/extensions/extension_service.h" |
| 42 #include "chrome/browser/extensions/extension_sorting.h" | 43 #include "chrome/browser/extensions/extension_sorting.h" |
| 43 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 44 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 44 #include "chrome/browser/extensions/extension_sync_data.h" | 45 #include "chrome/browser/extensions/extension_sync_data.h" |
| 45 #include "chrome/browser/extensions/extension_system.h" | 46 #include "chrome/browser/extensions/extension_system.h" |
| 46 #include "chrome/browser/extensions/external_install_ui.h" | 47 #include "chrome/browser/extensions/external_install_ui.h" |
| 47 #include "chrome/browser/extensions/external_policy_loader.h" | 48 #include "chrome/browser/extensions/external_policy_loader.h" |
| 48 #include "chrome/browser/extensions/external_pref_loader.h" | 49 #include "chrome/browser/extensions/external_pref_loader.h" |
| 49 #include "chrome/browser/extensions/external_provider_impl.h" | 50 #include "chrome/browser/extensions/external_provider_impl.h" |
| 50 #include "chrome/browser/extensions/external_provider_interface.h" | 51 #include "chrome/browser/extensions/external_provider_interface.h" |
| 52 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" |
| 51 #include "chrome/browser/extensions/install_observer.h" | 53 #include "chrome/browser/extensions/install_observer.h" |
| 52 #include "chrome/browser/extensions/install_tracker.h" | 54 #include "chrome/browser/extensions/install_tracker.h" |
| 53 #include "chrome/browser/extensions/install_tracker_factory.h" | 55 #include "chrome/browser/extensions/install_tracker_factory.h" |
| 54 #include "chrome/browser/extensions/installed_loader.h" | 56 #include "chrome/browser/extensions/installed_loader.h" |
| 55 #include "chrome/browser/extensions/management_policy.h" | 57 #include "chrome/browser/extensions/management_policy.h" |
| 56 #include "chrome/browser/extensions/pack_extension_job.h" | 58 #include "chrome/browser/extensions/pack_extension_job.h" |
| 57 #include "chrome/browser/extensions/pending_extension_info.h" | 59 #include "chrome/browser/extensions/pending_extension_info.h" |
| 58 #include "chrome/browser/extensions/pending_extension_manager.h" | 60 #include "chrome/browser/extensions/pending_extension_manager.h" |
| 59 #include "chrome/browser/extensions/test_extension_system.h" | 61 #include "chrome/browser/extensions/test_extension_system.h" |
| 60 #include "chrome/browser/extensions/test_management_policy.h" | 62 #include "chrome/browser/extensions/test_management_policy.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 #include "webkit/browser/quota/quota_manager.h" | 119 #include "webkit/browser/quota/quota_manager.h" |
| 118 #include "webkit/common/database/database_identifier.h" | 120 #include "webkit/common/database/database_identifier.h" |
| 119 | 121 |
| 120 #if defined(OS_CHROMEOS) | 122 #if defined(OS_CHROMEOS) |
| 121 #include "chrome/browser/chromeos/extensions/install_limiter.h" | 123 #include "chrome/browser/chromeos/extensions/install_limiter.h" |
| 122 #include "chrome/browser/chromeos/login/user_manager.h" | 124 #include "chrome/browser/chromeos/login/user_manager.h" |
| 123 #include "chrome/browser/chromeos/settings/cros_settings.h" | 125 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 124 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 126 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 125 #endif | 127 #endif |
| 126 | 128 |
| 129 // The blacklist tests rely on safe browsing. |
| 130 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) |
| 131 #define ENABLE_BLACKLIST_TESTS |
| 132 #endif |
| 133 |
| 127 using base::DictionaryValue; | 134 using base::DictionaryValue; |
| 128 using base::ListValue; | 135 using base::ListValue; |
| 129 using base::Value; | 136 using base::Value; |
| 130 using content::BrowserContext; | 137 using content::BrowserContext; |
| 131 using content::BrowserThread; | 138 using content::BrowserThread; |
| 132 using content::DOMStorageContext; | 139 using content::DOMStorageContext; |
| 133 using content::IndexedDBContext; | 140 using content::IndexedDBContext; |
| 134 using content::PluginService; | 141 using content::PluginService; |
| 135 using extensions::APIPermission; | 142 using extensions::APIPermission; |
| 136 using extensions::APIPermissionSet; | 143 using extensions::APIPermissionSet; |
| 144 using extensions::Blacklist; |
| 137 using extensions::CrxInstaller; | 145 using extensions::CrxInstaller; |
| 138 using extensions::Extension; | 146 using extensions::Extension; |
| 139 using extensions::ExtensionCreator; | 147 using extensions::ExtensionCreator; |
| 140 using extensions::ExtensionPrefs; | 148 using extensions::ExtensionPrefs; |
| 141 using extensions::ExtensionResource; | 149 using extensions::ExtensionResource; |
| 142 using extensions::ExtensionSystem; | 150 using extensions::ExtensionSystem; |
| 151 using extensions::FakeSafeBrowsingDatabaseManager; |
| 143 using extensions::FeatureSwitch; | 152 using extensions::FeatureSwitch; |
| 144 using extensions::Manifest; | 153 using extensions::Manifest; |
| 145 using extensions::PermissionSet; | 154 using extensions::PermissionSet; |
| 146 using extensions::TestExtensionSystem; | 155 using extensions::TestExtensionSystem; |
| 147 using extensions::URLPatternSet; | 156 using extensions::URLPatternSet; |
| 148 | 157 |
| 149 namespace keys = extensions::manifest_keys; | 158 namespace keys = extensions::manifest_keys; |
| 150 | 159 |
| 151 namespace { | 160 namespace { |
| 152 | 161 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 base::DeleteFile(extensions_install_dir_, true); | 536 base::DeleteFile(extensions_install_dir_, true); |
| 528 base::CopyDirectory(source_install_dir, extensions_install_dir_, true); | 537 base::CopyDirectory(source_install_dir, extensions_install_dir_, true); |
| 529 | 538 |
| 530 ExtensionServiceInitParams params; | 539 ExtensionServiceInitParams params; |
| 531 params.profile_path = path; | 540 params.profile_path = path; |
| 532 params.pref_file = temp_prefs; | 541 params.pref_file = temp_prefs; |
| 533 params.extensions_install_dir = extensions_install_dir_; | 542 params.extensions_install_dir = extensions_install_dir_; |
| 534 InitializeExtensionService(params); | 543 InitializeExtensionService(params); |
| 535 } | 544 } |
| 536 | 545 |
| 546 void ExtensionServiceTestBase::InitializeGoodInstalledExtensionService() { |
| 547 base::FilePath source_install_dir = data_dir_ |
| 548 .AppendASCII("good") |
| 549 .AppendASCII("Extensions"); |
| 550 base::FilePath pref_path = source_install_dir |
| 551 .DirName() |
| 552 .AppendASCII("Preferences"); |
| 553 InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 554 } |
| 555 |
| 537 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { | 556 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { |
| 538 InitializeExtensionServiceHelper(false, true); | 557 InitializeExtensionServiceHelper(false, true); |
| 539 } | 558 } |
| 540 | 559 |
| 541 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { | 560 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { |
| 542 static_cast<extensions::TestExtensionSystem*>( | 561 static_cast<extensions::TestExtensionSystem*>( |
| 543 ExtensionSystem::Get(profile_.get()))-> | 562 ExtensionSystem::Get(profile_.get()))-> |
| 544 CreateExtensionProcessManager(); | 563 CreateExtensionProcessManager(); |
| 545 } | 564 } |
| 546 | 565 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 } | 669 } |
| 651 | 670 |
| 652 void MockSyncStartFlare(bool* was_called, | 671 void MockSyncStartFlare(bool* was_called, |
| 653 syncer::ModelType* model_type_passed_in, | 672 syncer::ModelType* model_type_passed_in, |
| 654 syncer::ModelType model_type) { | 673 syncer::ModelType model_type) { |
| 655 *was_called = true; | 674 *was_called = true; |
| 656 *model_type_passed_in = model_type; | 675 *model_type_passed_in = model_type; |
| 657 } | 676 } |
| 658 | 677 |
| 659 protected: | 678 protected: |
| 679 // Paths to some of the fake extensions. |
| 680 base::FilePath good0_path() { |
| 681 return data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 682 .AppendASCII(good0).AppendASCII("1.0.0.0"); |
| 683 } |
| 684 |
| 685 base::FilePath good1_path() { |
| 686 return data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 687 .AppendASCII(good1).AppendASCII("2"); |
| 688 } |
| 689 |
| 690 base::FilePath good2_path() { |
| 691 return data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 692 .AppendASCII(good2).AppendASCII("1.0"); |
| 693 } |
| 694 |
| 660 void TestExternalProvider(MockExtensionProvider* provider, | 695 void TestExternalProvider(MockExtensionProvider* provider, |
| 661 Manifest::Location location); | 696 Manifest::Location location); |
| 662 | 697 |
| 663 void PackCRX(const base::FilePath& dir_path, | 698 void PackCRX(const base::FilePath& dir_path, |
| 664 const base::FilePath& pem_path, | 699 const base::FilePath& pem_path, |
| 665 const base::FilePath& crx_path) { | 700 const base::FilePath& crx_path) { |
| 666 // Use the existing pem key, if provided. | 701 // Use the existing pem key, if provided. |
| 667 base::FilePath pem_output_path; | 702 base::FilePath pem_output_path; |
| 668 if (pem_path.value().empty()) { | 703 if (pem_path.value().empty()) { |
| 669 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); | 704 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 base::RunLoop().RunUntilIdle(); | 1024 base::RunLoop().RunUntilIdle(); |
| 990 | 1025 |
| 991 // The directory should be gone. | 1026 // The directory should be gone. |
| 992 EXPECT_FALSE(base::PathExists(extension_path)); | 1027 EXPECT_FALSE(base::PathExists(extension_path)); |
| 993 } | 1028 } |
| 994 | 1029 |
| 995 void ValidatePrefKeyCount(size_t count) { | 1030 void ValidatePrefKeyCount(size_t count) { |
| 996 EXPECT_EQ(count, GetPrefKeyCount()); | 1031 EXPECT_EQ(count, GetPrefKeyCount()); |
| 997 } | 1032 } |
| 998 | 1033 |
| 999 void ValidateBooleanPref(const std::string& extension_id, | 1034 testing::AssertionResult ValidateBooleanPref( |
| 1000 const std::string& pref_path, | 1035 const std::string& extension_id, |
| 1001 bool expected_val) { | 1036 const std::string& pref_path, |
| 1002 std::string msg = " while checking: "; | 1037 bool expected_val) { |
| 1038 std::string msg = "while checking: "; |
| 1003 msg += extension_id; | 1039 msg += extension_id; |
| 1004 msg += " "; | 1040 msg += " "; |
| 1005 msg += pref_path; | 1041 msg += pref_path; |
| 1006 msg += " == "; | 1042 msg += " == "; |
| 1007 msg += expected_val ? "true" : "false"; | 1043 msg += expected_val ? "true" : "false"; |
| 1008 | 1044 |
| 1009 PrefService* prefs = profile_->GetPrefs(); | 1045 PrefService* prefs = profile_->GetPrefs(); |
| 1010 const DictionaryValue* dict = | 1046 const DictionaryValue* dict = |
| 1011 prefs->GetDictionary("extensions.settings"); | 1047 prefs->GetDictionary("extensions.settings"); |
| 1012 ASSERT_TRUE(dict != NULL) << msg; | 1048 if (!dict) { |
| 1049 return testing::AssertionFailure() |
| 1050 << "extension.settings does not exist " << msg; |
| 1051 } |
| 1052 |
| 1013 const DictionaryValue* pref = NULL; | 1053 const DictionaryValue* pref = NULL; |
| 1014 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; | 1054 if (!dict->GetDictionary(extension_id, &pref)) { |
| 1015 EXPECT_TRUE(pref != NULL) << msg; | 1055 return testing::AssertionFailure() |
| 1056 << "extension pref does not exist " << msg; |
| 1057 } |
| 1058 |
| 1016 bool val; | 1059 bool val; |
| 1017 ASSERT_TRUE(pref->GetBoolean(pref_path, &val)) << msg; | 1060 if (!pref->GetBoolean(pref_path, &val)) { |
| 1018 EXPECT_EQ(expected_val, val) << msg; | 1061 return testing::AssertionFailure() |
| 1062 << pref_path << " pref not found " << msg; |
| 1063 } |
| 1064 |
| 1065 return expected_val == val |
| 1066 ? testing::AssertionSuccess() |
| 1067 : testing::AssertionFailure() << "Value is incorrect " << msg; |
| 1019 } | 1068 } |
| 1020 | 1069 |
| 1021 bool IsPrefExist(const std::string& extension_id, | 1070 bool IsPrefExist(const std::string& extension_id, |
| 1022 const std::string& pref_path) { | 1071 const std::string& pref_path) { |
| 1023 const DictionaryValue* dict = | 1072 const DictionaryValue* dict = |
| 1024 profile_->GetPrefs()->GetDictionary("extensions.settings"); | 1073 profile_->GetPrefs()->GetDictionary("extensions.settings"); |
| 1025 if (dict == NULL) return false; | 1074 if (dict == NULL) return false; |
| 1026 const DictionaryValue* pref = NULL; | 1075 const DictionaryValue* pref = NULL; |
| 1027 if (!dict->GetDictionary(extension_id, &pref)) { | 1076 if (!dict->GetDictionary(extension_id, &pref)) { |
| 1028 return false; | 1077 return false; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 ExtensionCreator::ErrorType type) { | 1257 ExtensionCreator::ErrorType type) { |
| 1209 if (type == ExtensionCreator::kCRXExists) | 1258 if (type == ExtensionCreator::kCRXExists) |
| 1210 FAIL() << "Packing should not fail."; | 1259 FAIL() << "Packing should not fail."; |
| 1211 else | 1260 else |
| 1212 FAIL() << "Existing CRX should have been overwritten."; | 1261 FAIL() << "Existing CRX should have been overwritten."; |
| 1213 } | 1262 } |
| 1214 | 1263 |
| 1215 // Test loading good extensions from the profile directory. | 1264 // Test loading good extensions from the profile directory. |
| 1216 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { | 1265 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { |
| 1217 InitPluginService(); | 1266 InitPluginService(); |
| 1218 | 1267 InitializeGoodInstalledExtensionService(); |
| 1219 // Initialize the test dir with a good Preferences/extensions. | |
| 1220 base::FilePath source_install_dir = data_dir_ | |
| 1221 .AppendASCII("good") | |
| 1222 .AppendASCII("Extensions"); | |
| 1223 base::FilePath pref_path = source_install_dir | |
| 1224 .DirName() | |
| 1225 .AppendASCII("Preferences"); | |
| 1226 InitializeInstalledExtensionService(pref_path, source_install_dir); | |
| 1227 | |
| 1228 service_->Init(); | 1268 service_->Init(); |
| 1229 | 1269 |
| 1230 uint32 expected_num_extensions = 3u; | 1270 uint32 expected_num_extensions = 3u; |
| 1231 ASSERT_EQ(expected_num_extensions, loaded_.size()); | 1271 ASSERT_EQ(expected_num_extensions, loaded_.size()); |
| 1232 | 1272 |
| 1233 EXPECT_EQ(std::string(good0), loaded_[0]->id()); | 1273 EXPECT_EQ(std::string(good0), loaded_[0]->id()); |
| 1234 EXPECT_EQ(std::string("My extension 1"), | 1274 EXPECT_EQ(std::string("My extension 1"), |
| 1235 loaded_[0]->name()); | 1275 loaded_[0]->name()); |
| 1236 EXPECT_EQ(std::string("The first extension that I made."), | 1276 EXPECT_EQ(std::string("The first extension that I made."), |
| 1237 loaded_[0]->description()); | 1277 loaded_[0]->description()); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 EXPECT_TRUE(MatchPattern(UTF16ToUTF8(GetErrors()[3]), | 1400 EXPECT_TRUE(MatchPattern(UTF16ToUTF8(GetErrors()[3]), |
| 1361 std::string("Could not load extension from '*'. ") + | 1401 std::string("Could not load extension from '*'. ") + |
| 1362 extensions::manifest_errors::kManifestUnreadable)) << | 1402 extensions::manifest_errors::kManifestUnreadable)) << |
| 1363 UTF16ToUTF8(GetErrors()[3]); | 1403 UTF16ToUTF8(GetErrors()[3]); |
| 1364 }; | 1404 }; |
| 1365 | 1405 |
| 1366 // Test that partially deleted extensions are cleaned up during startup | 1406 // Test that partially deleted extensions are cleaned up during startup |
| 1367 // Test loading bad extensions from the profile directory. | 1407 // Test loading bad extensions from the profile directory. |
| 1368 TEST_F(ExtensionServiceTest, CleanupOnStartup) { | 1408 TEST_F(ExtensionServiceTest, CleanupOnStartup) { |
| 1369 InitPluginService(); | 1409 InitPluginService(); |
| 1370 | 1410 InitializeGoodInstalledExtensionService(); |
| 1371 base::FilePath source_install_dir = data_dir_ | |
| 1372 .AppendASCII("good") | |
| 1373 .AppendASCII("Extensions"); | |
| 1374 base::FilePath pref_path = source_install_dir | |
| 1375 .DirName() | |
| 1376 .AppendASCII("Preferences"); | |
| 1377 | |
| 1378 InitializeInstalledExtensionService(pref_path, source_install_dir); | |
| 1379 | 1411 |
| 1380 // Simulate that one of them got partially deleted by clearing its pref. | 1412 // Simulate that one of them got partially deleted by clearing its pref. |
| 1381 { | 1413 { |
| 1382 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); | 1414 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); |
| 1383 DictionaryValue* dict = update.Get(); | 1415 DictionaryValue* dict = update.Get(); |
| 1384 ASSERT_TRUE(dict != NULL); | 1416 ASSERT_TRUE(dict != NULL); |
| 1385 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); | 1417 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); |
| 1386 } | 1418 } |
| 1387 | 1419 |
| 1388 service_->Init(); | 1420 service_->Init(); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 Extension::FROM_BOOKMARK, | 1727 Extension::FROM_BOOKMARK, |
| 1696 false /* mark_acknowledged */)) { | 1728 false /* mark_acknowledged */)) { |
| 1697 content::WindowedNotificationObserver( | 1729 content::WindowedNotificationObserver( |
| 1698 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 1730 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1699 content::NotificationService::AllSources()).Wait(); | 1731 content::NotificationService::AllSources()).Wait(); |
| 1700 } | 1732 } |
| 1701 | 1733 |
| 1702 const Extension* extension = service_->GetExtensionById(good_crx, false); | 1734 const Extension* extension = service_->GetExtensionById(good_crx, false); |
| 1703 ASSERT_TRUE(extension); | 1735 ASSERT_TRUE(extension); |
| 1704 ASSERT_TRUE(extension->from_bookmark()); | 1736 ASSERT_TRUE(extension->from_bookmark()); |
| 1705 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); | 1737 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
| 1706 | 1738 |
| 1707 // Upgrade to version 2.0, the flag should be preserved. | 1739 // Upgrade to version 2.0, the flag should be preserved. |
| 1708 path = data_dir_.AppendASCII("good2.crx"); | 1740 path = data_dir_.AppendASCII("good2.crx"); |
| 1709 UpdateExtension(good_crx, path, ENABLED); | 1741 UpdateExtension(good_crx, path, ENABLED); |
| 1710 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); | 1742 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
| 1711 extension = service_->GetExtensionById(good_crx, false); | 1743 extension = service_->GetExtensionById(good_crx, false); |
| 1712 ASSERT_TRUE(extension); | 1744 ASSERT_TRUE(extension); |
| 1713 ASSERT_TRUE(extension->from_bookmark()); | 1745 ASSERT_TRUE(extension->from_bookmark()); |
| 1714 } | 1746 } |
| 1715 | 1747 |
| 1716 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED | 1748 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED |
| 1717 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { | 1749 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { |
| 1718 InitializeEmptyExtensionService(); | 1750 InitializeEmptyExtensionService(); |
| 1719 | 1751 |
| 1720 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 1752 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2000 | 2032 |
| 2001 #if !defined(OS_CHROMEOS) | 2033 #if !defined(OS_CHROMEOS) |
| 2002 // Tests that the granted permissions full_access bit gets set correctly when | 2034 // Tests that the granted permissions full_access bit gets set correctly when |
| 2003 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS | 2035 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS |
| 2004 // since they don't support plugins. | 2036 // since they don't support plugins. |
| 2005 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { | 2037 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { |
| 2006 InitPluginService(); | 2038 InitPluginService(); |
| 2007 | 2039 |
| 2008 InitializeEmptyExtensionService(); | 2040 InitializeEmptyExtensionService(); |
| 2009 | 2041 |
| 2010 base::FilePath path = data_dir_ | 2042 ASSERT_TRUE(base::PathExists(good1_path())); |
| 2011 .AppendASCII("good") | 2043 const Extension* extension = PackAndInstallCRX(good1_path(), INSTALL_NEW); |
| 2012 .AppendASCII("Extensions") | |
| 2013 .AppendASCII(good1) | |
| 2014 .AppendASCII("2"); | |
| 2015 | |
| 2016 ASSERT_TRUE(base::PathExists(path)); | |
| 2017 const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW); | |
| 2018 EXPECT_EQ(0u, GetErrors().size()); | 2044 EXPECT_EQ(0u, GetErrors().size()); |
| 2019 EXPECT_EQ(1u, service_->extensions()->size()); | 2045 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2020 ExtensionPrefs* prefs = service_->extension_prefs(); | 2046 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 2021 | 2047 |
| 2022 scoped_refptr<PermissionSet> permissions( | 2048 scoped_refptr<PermissionSet> permissions( |
| 2023 prefs->GetGrantedPermissions(extension->id())); | 2049 prefs->GetGrantedPermissions(extension->id())); |
| 2024 EXPECT_FALSE(permissions->IsEmpty()); | 2050 EXPECT_FALSE(permissions->IsEmpty()); |
| 2025 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); | 2051 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); |
| 2026 EXPECT_FALSE(permissions->apis().empty()); | 2052 EXPECT_FALSE(permissions->apis().empty()); |
| 2027 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); | 2053 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2729 TEST_F(ExtensionServiceTest, FromWebStore) { | 2755 TEST_F(ExtensionServiceTest, FromWebStore) { |
| 2730 InitializeEmptyExtensionService(); | 2756 InitializeEmptyExtensionService(); |
| 2731 | 2757 |
| 2732 // A simple extension that should install without error. | 2758 // A simple extension that should install without error. |
| 2733 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 2759 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2734 // Not from web store. | 2760 // Not from web store. |
| 2735 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 2761 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2736 std::string id = extension->id(); | 2762 std::string id = extension->id(); |
| 2737 | 2763 |
| 2738 ValidatePrefKeyCount(1); | 2764 ValidatePrefKeyCount(1); |
| 2739 ValidateBooleanPref(good_crx, "from_webstore", false); | 2765 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", false)); |
| 2740 ASSERT_FALSE(extension->from_webstore()); | 2766 ASSERT_FALSE(extension->from_webstore()); |
| 2741 | 2767 |
| 2742 // Test install from web store. | 2768 // Test install from web store. |
| 2743 InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store. | 2769 InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store. |
| 2744 | 2770 |
| 2745 ValidatePrefKeyCount(1); | 2771 ValidatePrefKeyCount(1); |
| 2746 ValidateBooleanPref(good_crx, "from_webstore", true); | 2772 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true)); |
| 2747 | 2773 |
| 2748 // Reload so extension gets reinitialized with new value. | 2774 // Reload so extension gets reinitialized with new value. |
| 2749 service_->ReloadExtensions(); | 2775 service_->ReloadExtensions(); |
| 2750 extension = service_->GetExtensionById(id, false); | 2776 extension = service_->GetExtensionById(id, false); |
| 2751 ASSERT_TRUE(extension->from_webstore()); | 2777 ASSERT_TRUE(extension->from_webstore()); |
| 2752 | 2778 |
| 2753 // Upgrade to version 2.0 | 2779 // Upgrade to version 2.0 |
| 2754 path = data_dir_.AppendASCII("good2.crx"); | 2780 path = data_dir_.AppendASCII("good2.crx"); |
| 2755 UpdateExtension(good_crx, path, ENABLED); | 2781 UpdateExtension(good_crx, path, ENABLED); |
| 2756 ValidatePrefKeyCount(1); | 2782 ValidatePrefKeyCount(1); |
| 2757 ValidateBooleanPref(good_crx, "from_webstore", true); | 2783 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true)); |
| 2758 } | 2784 } |
| 2759 | 2785 |
| 2760 // Test upgrading a signed extension. | 2786 // Test upgrading a signed extension. |
| 2761 TEST_F(ExtensionServiceTest, UpgradeSignedGood) { | 2787 TEST_F(ExtensionServiceTest, UpgradeSignedGood) { |
| 2762 InitializeEmptyExtensionService(); | 2788 InitializeEmptyExtensionService(); |
| 2763 | 2789 |
| 2764 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 2790 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2765 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 2791 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2766 std::string id = extension->id(); | 2792 std::string id = extension->id(); |
| 2767 | 2793 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2960 EXPECT_EQ(0u, GetErrors().size()); | 2986 EXPECT_EQ(0u, GetErrors().size()); |
| 2961 ASSERT_EQ(1u, loaded_.size()); | 2987 ASSERT_EQ(1u, loaded_.size()); |
| 2962 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); | 2988 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); |
| 2963 EXPECT_EQ(1u, service_->extensions()->size()); | 2989 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2964 EXPECT_EQ("1.0", loaded_[0]->VersionString()); | 2990 EXPECT_EQ("1.0", loaded_[0]->VersionString()); |
| 2965 } | 2991 } |
| 2966 | 2992 |
| 2967 #if !defined(OS_CHROMEOS) | 2993 #if !defined(OS_CHROMEOS) |
| 2968 // LOAD extensions with plugins require approval. | 2994 // LOAD extensions with plugins require approval. |
| 2969 TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) { | 2995 TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) { |
| 2970 base::FilePath extension_with_plugin_path = data_dir_ | 2996 base::FilePath extension_with_plugin_path = good1_path(); |
| 2971 .AppendASCII("good") | 2997 base::FilePath extension_no_plugin_path = good2_path(); |
| 2972 .AppendASCII("Extensions") | |
| 2973 .AppendASCII(good1) | |
| 2974 .AppendASCII("2"); | |
| 2975 base::FilePath extension_no_plugin_path = data_dir_ | |
| 2976 .AppendASCII("good") | |
| 2977 .AppendASCII("Extensions") | |
| 2978 .AppendASCII(good2) | |
| 2979 .AppendASCII("1.0"); | |
| 2980 | 2998 |
| 2981 InitPluginService(); | 2999 InitPluginService(); |
| 2982 InitializeEmptyExtensionService(); | 3000 InitializeEmptyExtensionService(); |
| 2983 InitializeExtensionProcessManager(); | 3001 InitializeExtensionProcessManager(); |
| 2984 service_->set_show_extensions_prompts(true); | 3002 service_->set_show_extensions_prompts(true); |
| 2985 | 3003 |
| 2986 // Start by canceling any install prompts. | 3004 // Start by canceling any install prompts. |
| 2987 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 3005 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 2988 switches::kAppsGalleryInstallAutoConfirmForTests, | 3006 switches::kAppsGalleryInstallAutoConfirmForTests, |
| 2989 "cancel"); | 3007 "cancel"); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3264 // Use AddExtensionImpl() as AddFrom*() would balk. | 3282 // Use AddExtensionImpl() as AddFrom*() would balk. |
| 3265 service_->pending_extension_manager()->AddExtensionImpl( | 3283 service_->pending_extension_manager()->AddExtensionImpl( |
| 3266 good->id(), extensions::ManifestURL::GetUpdateURL(good), | 3284 good->id(), extensions::ManifestURL::GetUpdateURL(good), |
| 3267 Version(), &IsExtension, kGoodIsFromSync, | 3285 Version(), &IsExtension, kGoodIsFromSync, |
| 3268 kGoodInstallSilently, Manifest::INTERNAL); | 3286 kGoodInstallSilently, Manifest::INTERNAL); |
| 3269 UpdateExtension(good->id(), path, ENABLED); | 3287 UpdateExtension(good->id(), path, ENABLED); |
| 3270 | 3288 |
| 3271 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); | 3289 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
| 3272 } | 3290 } |
| 3273 | 3291 |
| 3274 // Test pref settings for blacklist and unblacklist extensions. | 3292 #if defined(ENABLE_BLACKLIST_TESTS) |
| 3293 // Tests blacklisting then unblacklisting extensions after the service has been |
| 3294 // initialized. |
| 3275 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { | 3295 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { |
| 3276 InitializeEmptyExtensionService(); | 3296 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( |
| 3277 std::vector<std::string> blacklist; | 3297 new FakeSafeBrowsingDatabaseManager(true)); |
| 3278 blacklist.push_back(good0); | 3298 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); |
| 3279 blacklist.push_back("invalid_id"); // an invalid id | |
| 3280 blacklist.push_back(good1); | |
| 3281 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, | |
| 3282 "v1"); | |
| 3283 | 3299 |
| 3284 // Make sure pref is updated | 3300 // A profile with 3 extensions installed: good0, good1, and good2. |
| 3301 InitializeGoodInstalledExtensionService(); |
| 3302 service_->Init(); |
| 3303 |
| 3304 const ExtensionSet* extensions = service_->extensions(); |
| 3305 const ExtensionSet* blacklisted_extensions = |
| 3306 service_->blacklisted_extensions(); |
| 3307 |
| 3308 EXPECT_TRUE( extensions->Contains(good0) && |
| 3309 !blacklisted_extensions->Contains(good0)); |
| 3310 EXPECT_TRUE( extensions->Contains(good1) && |
| 3311 !blacklisted_extensions->Contains(good1)); |
| 3312 EXPECT_TRUE( extensions->Contains(good2) && |
| 3313 !blacklisted_extensions->Contains(good2)); |
| 3314 |
| 3315 EXPECT_FALSE(IsPrefExist(good0, "blacklist")); |
| 3316 EXPECT_FALSE(IsPrefExist(good1, "blacklist")); |
| 3317 EXPECT_FALSE(IsPrefExist(good2, "blacklist")); |
| 3318 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
| 3319 |
| 3320 // Blacklist good0 and good1 (and an invalid extension ID). |
| 3321 blacklist_db->SetUnsafe(good0, good1, "invalid_id").NotifyUpdate(); |
| 3285 base::RunLoop().RunUntilIdle(); | 3322 base::RunLoop().RunUntilIdle(); |
| 3286 | 3323 |
| 3287 // blacklist is set for good0,1,2 | 3324 EXPECT_TRUE(!extensions->Contains(good0) && |
| 3288 ValidateBooleanPref(good0, "blacklist", true); | 3325 blacklisted_extensions->Contains(good0)); |
| 3289 ValidateBooleanPref(good1, "blacklist", true); | 3326 EXPECT_TRUE(!extensions->Contains(good1) && |
| 3290 // invalid_id should not be inserted to pref. | 3327 blacklisted_extensions->Contains(good1)); |
| 3328 EXPECT_TRUE( extensions->Contains(good2) && |
| 3329 !blacklisted_extensions->Contains(good2)); |
| 3330 |
| 3331 EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true)); |
| 3332 EXPECT_TRUE(ValidateBooleanPref(good1, "blacklist", true)); |
| 3333 EXPECT_FALSE(IsPrefExist(good2, "blacklist")); |
| 3291 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); | 3334 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
| 3292 | 3335 |
| 3293 // remove good1, add good2 | 3336 // Un-blacklist good1 and blacklist good2. |
| 3294 blacklist.pop_back(); | 3337 blacklist_db->SetUnsafe(good0, good2, "invalid_id").NotifyUpdate(); |
| 3295 blacklist.push_back(good2); | 3338 base::RunLoop().RunUntilIdle(); |
| 3296 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, | |
| 3297 "v2"); | |
| 3298 | 3339 |
| 3299 // only good0 and good1 should be set | 3340 EXPECT_TRUE(!extensions->Contains(good0) && |
| 3300 ValidateBooleanPref(good0, "blacklist", true); | 3341 blacklisted_extensions->Contains(good0)); |
| 3342 EXPECT_TRUE( extensions->Contains(good1) && |
| 3343 !blacklisted_extensions->Contains(good1)); |
| 3344 EXPECT_TRUE(!extensions->Contains(good2) && |
| 3345 blacklisted_extensions->Contains(good2)); |
| 3346 |
| 3347 EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true)); |
| 3301 EXPECT_FALSE(IsPrefExist(good1, "blacklist")); | 3348 EXPECT_FALSE(IsPrefExist(good1, "blacklist")); |
| 3302 ValidateBooleanPref(good2, "blacklist", true); | 3349 EXPECT_TRUE(ValidateBooleanPref(good2, "blacklist", true)); |
| 3303 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); | 3350 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
| 3304 } | 3351 } |
| 3352 #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3305 | 3353 |
| 3306 // Unload installed extension from blacklist. | 3354 #if defined(ENABLE_BLACKLIST_TESTS) |
| 3307 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtension) { | 3355 // Tests trying to install a blacklisted extension. |
| 3356 TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) { |
| 3357 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( |
| 3358 new FakeSafeBrowsingDatabaseManager(true)); |
| 3359 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); |
| 3360 |
| 3308 InitializeEmptyExtensionService(); | 3361 InitializeEmptyExtensionService(); |
| 3362 service_->Init(); |
| 3309 | 3363 |
| 3310 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3364 // After blacklisting good_crx, we cannot install it. |
| 3311 | 3365 blacklist_db->SetUnsafe(good_crx).NotifyUpdate(); |
| 3312 const Extension* good = InstallCRX(path, INSTALL_NEW); | |
| 3313 EXPECT_EQ(good_crx, good->id()); | |
| 3314 UpdateExtension(good_crx, path, FAILED_SILENTLY); | |
| 3315 | |
| 3316 std::vector<std::string> blacklist; | |
| 3317 blacklist.push_back(good_crx); | |
| 3318 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, | |
| 3319 "v1"); | |
| 3320 | |
| 3321 // Make sure pref is updated | |
| 3322 base::RunLoop().RunUntilIdle(); | 3366 base::RunLoop().RunUntilIdle(); |
| 3323 | 3367 |
| 3324 // Now, the good_crx is blacklisted. | |
| 3325 ValidateBooleanPref(good_crx, "blacklist", true); | |
| 3326 EXPECT_EQ(0u, service_->extensions()->size()); | |
| 3327 | |
| 3328 // Remove good_crx from blacklist | |
| 3329 blacklist.pop_back(); | |
| 3330 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, | |
| 3331 "v2"); | |
| 3332 | |
| 3333 // Make sure pref is updated | |
| 3334 base::RunLoop().RunUntilIdle(); | |
| 3335 // blacklist value should not be set for good_crx | |
| 3336 EXPECT_FALSE(IsPrefExist(good_crx, "blacklist")); | |
| 3337 } | |
| 3338 | |
| 3339 // Unload installed extension from blacklist. | |
| 3340 TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) { | |
| 3341 InitializeEmptyExtensionService(); | |
| 3342 | |
| 3343 // Fake the blacklisting of good_crx by pretending that we get an update | |
| 3344 // which includes it. | |
| 3345 extensions::Blacklist* blacklist = | |
| 3346 ExtensionSystem::Get(profile_.get())->blacklist(); | |
| 3347 blacklist->SetFromUpdater(std::vector<std::string>(1, good_crx), "v1"); | |
| 3348 | |
| 3349 // Now good_crx is blacklisted. | |
| 3350 ValidateBooleanPref(good_crx, "blacklist", true); | |
| 3351 | |
| 3352 // We cannot install good_crx. | |
| 3353 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3368 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 3354 // HACK: specify WAS_INSTALLED_BY_DEFAULT so that test machinery doesn't | 3369 // HACK: specify WAS_INSTALLED_BY_DEFAULT so that test machinery doesn't |
| 3355 // decide to install this silently. Somebody should fix these tests, all | 3370 // decide to install this silently. Somebody should fix these tests, all |
| 3356 // 6,000 lines of them. Hah! | 3371 // 6,000 lines of them. Hah! |
| 3357 InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT); | 3372 InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT); |
| 3358 EXPECT_EQ(0u, service_->extensions()->size()); | 3373 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3359 ValidateBooleanPref(good_crx, "blacklist", true); | |
| 3360 } | 3374 } |
| 3375 #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3361 | 3376 |
| 3377 #if defined(ENABLE_BLACKLIST_TESTS) |
| 3362 // Unload blacklisted extension on policy change. | 3378 // Unload blacklisted extension on policy change. |
| 3363 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) { | 3379 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) { |
| 3380 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( |
| 3381 new FakeSafeBrowsingDatabaseManager(true)); |
| 3382 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); |
| 3383 |
| 3384 // A profile with no extensions installed. |
| 3364 InitializeEmptyExtensionService(); | 3385 InitializeEmptyExtensionService(); |
| 3386 |
| 3365 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3387 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 3366 | 3388 |
| 3367 const Extension* good = InstallCRX(path, INSTALL_NEW); | 3389 const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 3368 EXPECT_EQ(good_crx, good->id()); | 3390 EXPECT_EQ(good_crx, good->id()); |
| 3369 UpdateExtension(good_crx, path, FAILED_SILENTLY); | 3391 UpdateExtension(good_crx, path, FAILED_SILENTLY); |
| 3370 EXPECT_EQ(1u, service_->extensions()->size()); | 3392 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3371 | 3393 |
| 3372 base::ListValue whitelist; | 3394 base::ListValue whitelist; |
| 3373 PrefService* prefs = service_->extension_prefs()->pref_service(); | 3395 PrefService* prefs = service_->extension_prefs()->pref_service(); |
| 3374 whitelist.Append(new base::StringValue(good_crx)); | 3396 whitelist.Append(new base::StringValue(good_crx)); |
| 3375 prefs->Set(prefs::kExtensionInstallAllowList, whitelist); | 3397 prefs->Set(prefs::kExtensionInstallAllowList, whitelist); |
| 3376 | 3398 |
| 3377 std::vector<std::string> blacklist; | 3399 blacklist_db->SetUnsafe(good_crx).NotifyUpdate(); |
| 3378 blacklist.push_back(good_crx); | |
| 3379 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, | |
| 3380 "v1"); | |
| 3381 | |
| 3382 // Make sure pref is updated | |
| 3383 base::RunLoop().RunUntilIdle(); | 3400 base::RunLoop().RunUntilIdle(); |
| 3384 | 3401 |
| 3385 // The good_crx is blacklisted and the whitelist doesn't negate it. | 3402 // The good_crx is blacklisted and the whitelist doesn't negate it. |
| 3386 ValidateBooleanPref(good_crx, "blacklist", true); | 3403 ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true)); |
| 3387 EXPECT_EQ(0u, service_->extensions()->size()); | 3404 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3388 } | 3405 } |
| 3406 #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3389 | 3407 |
| 3390 // Test loading extensions from the profile directory, except | 3408 #if defined(ENABLE_BLACKLIST_TESTS) |
| 3391 // blacklisted ones. | 3409 // Tests that a blacklisted extension is eventually unloaded on startup, if it |
| 3410 // wasn't already. |
| 3392 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { | 3411 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { |
| 3393 // Initialize the test dir with a good Preferences/extensions. | 3412 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( |
| 3394 base::FilePath source_install_dir = data_dir_ | 3413 new FakeSafeBrowsingDatabaseManager(true)); |
| 3395 .AppendASCII("good") | 3414 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); |
| 3396 .AppendASCII("Extensions"); | |
| 3397 base::FilePath pref_path = source_install_dir | |
| 3398 .DirName() | |
| 3399 .AppendASCII("Preferences"); | |
| 3400 InitializeInstalledExtensionService(pref_path, source_install_dir); | |
| 3401 | 3415 |
| 3402 // Blacklist good1. | 3416 // A profile with 3 extensions installed: good0, good1, and good2. |
| 3403 std::vector<std::string> blacklist; | 3417 InitializeGoodInstalledExtensionService(); |
| 3404 blacklist.push_back(good1); | |
| 3405 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, | |
| 3406 "v1"); | |
| 3407 | 3418 |
| 3408 // Make sure pref is updated | 3419 // Blacklist good1 before the service initializes. |
| 3409 base::RunLoop().RunUntilIdle(); | 3420 blacklist_db->SetUnsafe(good1); |
| 3410 | |
| 3411 ValidateBooleanPref(good1, "blacklist", true); | |
| 3412 | 3421 |
| 3413 // Load extensions. | 3422 // Load extensions. |
| 3414 service_->Init(); | 3423 service_->Init(); |
| 3424 ASSERT_EQ(3u, loaded_.size()); // hasn't had time to blacklist yet |
| 3415 | 3425 |
| 3416 std::vector<string16> errors = GetErrors(); | 3426 base::RunLoop().RunUntilIdle(); |
| 3417 for (std::vector<string16>::iterator err = errors.begin(); | 3427 ASSERT_EQ(1u, service_->blacklisted_extensions()->size()); |
| 3418 err != errors.end(); ++err) { | 3428 ASSERT_EQ(2u, service_->extensions()->size()); |
| 3419 LOG(ERROR) << *err; | |
| 3420 } | |
| 3421 ASSERT_EQ(2u, loaded_.size()); | |
| 3422 | 3429 |
| 3423 EXPECT_TRUE(service_->GetInstalledExtension(good1)); | 3430 ASSERT_TRUE(service_->extensions()->Contains(good0)); |
| 3424 int include_mask = ExtensionService::INCLUDE_EVERYTHING & | 3431 ASSERT_TRUE(service_->blacklisted_extensions()->Contains(good1)); |
| 3425 ~ExtensionService::INCLUDE_BLACKLISTED; | 3432 ASSERT_TRUE(service_->extensions()->Contains(good2)); |
| 3426 EXPECT_FALSE(service_->GetExtensionById(good1, include_mask)); | |
| 3427 } | 3433 } |
| 3434 #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3435 |
| 3436 #if defined(ENABLE_BLACKLIST_TESTS) |
| 3437 // Tests extensions blacklisted in prefs on startup; one still blacklisted by |
| 3438 // safe browsing, the other not. The not-blacklisted one should recover. |
| 3439 TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) { |
| 3440 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( |
| 3441 new FakeSafeBrowsingDatabaseManager(true)); |
| 3442 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); |
| 3443 |
| 3444 InitializeGoodInstalledExtensionService(); |
| 3445 service_->extension_prefs()->SetExtensionBlacklisted(good0, true); |
| 3446 service_->extension_prefs()->SetExtensionBlacklisted(good1, true); |
| 3447 |
| 3448 blacklist_db->SetUnsafe(good1); |
| 3449 |
| 3450 service_->Init(); |
| 3451 |
| 3452 ASSERT_EQ(2u, service_->blacklisted_extensions()->size()); |
| 3453 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3454 |
| 3455 ASSERT_TRUE(service_->blacklisted_extensions()->Contains(good0)); |
| 3456 ASSERT_TRUE(service_->blacklisted_extensions()->Contains(good1)); |
| 3457 ASSERT_TRUE(service_->extensions()->Contains(good2)); |
| 3458 |
| 3459 // Give time for the blacklist to update. |
| 3460 base::RunLoop().RunUntilIdle(); |
| 3461 |
| 3462 ASSERT_EQ(1u, service_->blacklisted_extensions()->size()); |
| 3463 ASSERT_EQ(2u, service_->extensions()->size()); |
| 3464 |
| 3465 ASSERT_TRUE(service_->extensions()->Contains(good0)); |
| 3466 ASSERT_TRUE(service_->blacklisted_extensions()->Contains(good1)); |
| 3467 ASSERT_TRUE(service_->extensions()->Contains(good2)); |
| 3468 } |
| 3469 #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3428 | 3470 |
| 3429 // Will not install extension blacklisted by policy. | 3471 // Will not install extension blacklisted by policy. |
| 3430 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { | 3472 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { |
| 3431 InitializeEmptyExtensionService(); | 3473 InitializeEmptyExtensionService(); |
| 3432 | 3474 |
| 3433 // Blacklist everything. | 3475 // Blacklist everything. |
| 3434 { | 3476 { |
| 3435 ListPrefUpdate update(profile_->GetPrefs(), | 3477 ListPrefUpdate update(profile_->GetPrefs(), |
| 3436 prefs::kExtensionInstallDenyList); | 3478 prefs::kExtensionInstallDenyList); |
| 3437 ListValue* blacklist = update.Get(); | 3479 ListValue* blacklist = update.Get(); |
| (...skipping 1677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5115 bool flare_was_called = false; | 5157 bool flare_was_called = false; |
| 5116 syncer::ModelType triggered_type(syncer::UNSPECIFIED); | 5158 syncer::ModelType triggered_type(syncer::UNSPECIFIED); |
| 5117 base::WeakPtrFactory<ExtensionServiceTest> factory(this); | 5159 base::WeakPtrFactory<ExtensionServiceTest> factory(this); |
| 5118 service_->SetSyncStartFlare( | 5160 service_->SetSyncStartFlare( |
| 5119 base::Bind(&ExtensionServiceTest::MockSyncStartFlare, | 5161 base::Bind(&ExtensionServiceTest::MockSyncStartFlare, |
| 5120 factory.GetWeakPtr(), | 5162 factory.GetWeakPtr(), |
| 5121 &flare_was_called, // Safe due to WeakPtrFactory scope. | 5163 &flare_was_called, // Safe due to WeakPtrFactory scope. |
| 5122 &triggered_type)); // Safe due to WeakPtrFactory scope. | 5164 &triggered_type)); // Safe due to WeakPtrFactory scope. |
| 5123 | 5165 |
| 5124 // Install a component extension. | 5166 // Install a component extension. |
| 5125 base::FilePath path = data_dir_ | |
| 5126 .AppendASCII("good") | |
| 5127 .AppendASCII("Extensions") | |
| 5128 .AppendASCII(good0) | |
| 5129 .AppendASCII("1.0.0.0"); | |
| 5130 std::string manifest; | 5167 std::string manifest; |
| 5131 ASSERT_TRUE(base::ReadFileToString( | 5168 ASSERT_TRUE(base::ReadFileToString( |
| 5132 path.Append(extensions::kManifestFilename), &manifest)); | 5169 good0_path().Append(extensions::kManifestFilename), &manifest)); |
| 5133 service_->component_loader()->Add(manifest, path); | 5170 service_->component_loader()->Add(manifest, good0_path()); |
| 5134 ASSERT_FALSE(service_->is_ready()); | 5171 ASSERT_FALSE(service_->is_ready()); |
| 5135 service_->Init(); | 5172 service_->Init(); |
| 5136 ASSERT_TRUE(service_->is_ready()); | 5173 ASSERT_TRUE(service_->is_ready()); |
| 5137 | 5174 |
| 5138 // Extensions added before service is_ready() don't trigger sync startup. | 5175 // Extensions added before service is_ready() don't trigger sync startup. |
| 5139 EXPECT_FALSE(flare_was_called); | 5176 EXPECT_FALSE(flare_was_called); |
| 5140 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); | 5177 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); |
| 5141 } | 5178 } |
| 5142 | 5179 |
| 5143 TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledNormal) { | 5180 TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledNormal) { |
| 5144 // Initialize the test dir with a good Preferences/extensions. | 5181 InitializeGoodInstalledExtensionService(); |
| 5145 base::FilePath source_install_dir = data_dir_ | |
| 5146 .AppendASCII("good") | |
| 5147 .AppendASCII("Extensions"); | |
| 5148 base::FilePath pref_path = source_install_dir | |
| 5149 .DirName() | |
| 5150 .AppendASCII("Preferences"); | |
| 5151 InitializeInstalledExtensionService(pref_path, source_install_dir); | |
| 5152 | 5182 |
| 5153 bool flare_was_called = false; | 5183 bool flare_was_called = false; |
| 5154 syncer::ModelType triggered_type(syncer::UNSPECIFIED); | 5184 syncer::ModelType triggered_type(syncer::UNSPECIFIED); |
| 5155 base::WeakPtrFactory<ExtensionServiceTest> factory(this); | 5185 base::WeakPtrFactory<ExtensionServiceTest> factory(this); |
| 5156 service_->SetSyncStartFlare( | 5186 service_->SetSyncStartFlare( |
| 5157 base::Bind(&ExtensionServiceTest::MockSyncStartFlare, | 5187 base::Bind(&ExtensionServiceTest::MockSyncStartFlare, |
| 5158 factory.GetWeakPtr(), | 5188 factory.GetWeakPtr(), |
| 5159 &flare_was_called, // Safe due to WeakPtrFactory scope. | 5189 &flare_was_called, // Safe due to WeakPtrFactory scope. |
| 5160 &triggered_type)); // Safe due to WeakPtrFactory scope. | 5190 &triggered_type)); // Safe due to WeakPtrFactory scope. |
| 5161 | 5191 |
| (...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6400 EXPECT_TRUE(notifications.CheckNotifications( | 6430 EXPECT_TRUE(notifications.CheckNotifications( |
| 6401 chrome::NOTIFICATION_EXTENSION_INSTALLED)); | 6431 chrome::NOTIFICATION_EXTENSION_INSTALLED)); |
| 6402 | 6432 |
| 6403 EXPECT_TRUE(service_->GetInstalledExtension(id)); | 6433 EXPECT_TRUE(service_->GetInstalledExtension(id)); |
| 6404 EXPECT_FALSE(service_->extensions()->Contains(id)); | 6434 EXPECT_FALSE(service_->extensions()->Contains(id)); |
| 6405 EXPECT_TRUE(service_->blacklisted_extensions()->Contains(id)); | 6435 EXPECT_TRUE(service_->blacklisted_extensions()->Contains(id)); |
| 6406 EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id)); | 6436 EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id)); |
| 6407 EXPECT_TRUE( | 6437 EXPECT_TRUE( |
| 6408 service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id)); | 6438 service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id)); |
| 6409 } | 6439 } |
| OLD | NEW |