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

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

Issue 635573005: Cleanup: Better constify some strings in chrome/browser/{chromeos,extensions}. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix cros, really Created 6 years, 2 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) 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 <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location()); 1287 EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location());
1288 1288
1289 int index = expected_num_extensions - 1; 1289 int index = expected_num_extensions - 1;
1290 EXPECT_EQ(std::string(good2), loaded_[index]->id()); 1290 EXPECT_EQ(std::string(good2), loaded_[index]->id());
1291 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); 1291 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name());
1292 EXPECT_EQ(std::string(), loaded_[index]->description()); 1292 EXPECT_EQ(std::string(), loaded_[index]->description());
1293 EXPECT_EQ(0u, 1293 EXPECT_EQ(0u,
1294 extensions::ContentScriptsInfo::GetContentScripts( 1294 extensions::ContentScriptsInfo::GetContentScripts(
1295 loaded_[index].get()).size()); 1295 loaded_[index].get()).size());
1296 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); 1296 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location());
1297 }; 1297 }
1298 1298
1299 // Test loading bad extensions from the profile directory. 1299 // Test loading bad extensions from the profile directory.
1300 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { 1300 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) {
1301 // Initialize the test dir with a bad Preferences/extensions. 1301 // Initialize the test dir with a bad Preferences/extensions.
1302 base::FilePath source_install_dir = 1302 base::FilePath source_install_dir =
1303 data_dir().AppendASCII("bad").AppendASCII("Extensions"); 1303 data_dir().AppendASCII("bad").AppendASCII("Extensions");
1304 base::FilePath pref_path = 1304 base::FilePath pref_path =
1305 source_install_dir.DirName().Append(chrome::kPreferencesFilename); 1305 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
1306 1306
1307 InitializeInstalledExtensionService(pref_path, source_install_dir); 1307 InitializeInstalledExtensionService(pref_path, source_install_dir);
(...skipping 15 matching lines...) Expand all
1323 1323
1324 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[2]), 1324 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[2]),
1325 std::string("Could not load extension from '*'. ") + 1325 std::string("Could not load extension from '*'. ") +
1326 extensions::manifest_errors::kMissingFile)) << 1326 extensions::manifest_errors::kMissingFile)) <<
1327 base::UTF16ToUTF8(GetErrors()[2]); 1327 base::UTF16ToUTF8(GetErrors()[2]);
1328 1328
1329 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[3]), 1329 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[3]),
1330 std::string("Could not load extension from '*'. ") + 1330 std::string("Could not load extension from '*'. ") +
1331 extensions::manifest_errors::kManifestUnreadable)) << 1331 extensions::manifest_errors::kManifestUnreadable)) <<
1332 base::UTF16ToUTF8(GetErrors()[3]); 1332 base::UTF16ToUTF8(GetErrors()[3]);
1333 }; 1333 }
1334 1334
1335 // Test various cases for delayed install because of missing imports. 1335 // Test various cases for delayed install because of missing imports.
1336 TEST_F(ExtensionServiceTest, PendingImports) { 1336 TEST_F(ExtensionServiceTest, PendingImports) {
1337 InitPluginService(); 1337 InitPluginService();
1338 1338
1339 base::FilePath source_install_dir = 1339 base::FilePath source_install_dir =
1340 data_dir().AppendASCII("pending_updates_with_imports").AppendASCII( 1340 data_dir().AppendASCII("pending_updates_with_imports").AppendASCII(
1341 "Extensions"); 1341 "Extensions");
1342 base::FilePath pref_path = 1342 base::FilePath pref_path =
1343 source_install_dir.DirName().Append(chrome::kPreferencesFilename); 1343 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
(...skipping 2682 matching lines...) Expand 10 before | Expand all | Expand 10 after
4026 } 4026 }
4027 4027
4028 // Tests reloading extensions. 4028 // Tests reloading extensions.
4029 TEST_F(ExtensionServiceTest, ReloadExtensions) { 4029 TEST_F(ExtensionServiceTest, ReloadExtensions) {
4030 InitializeEmptyExtensionService(); 4030 InitializeEmptyExtensionService();
4031 4031
4032 // Simple extension that should install without error. 4032 // Simple extension that should install without error.
4033 base::FilePath path = data_dir().AppendASCII("good.crx"); 4033 base::FilePath path = data_dir().AppendASCII("good.crx");
4034 InstallCRX(path, INSTALL_NEW, 4034 InstallCRX(path, INSTALL_NEW,
4035 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); 4035 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT);
4036 const char* extension_id = good_crx; 4036 const char* const extension_id = good_crx;
4037 service()->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); 4037 service()->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION);
4038 4038
4039 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 4039 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4040 EXPECT_EQ(1u, registry()->disabled_extensions().size()); 4040 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4041 4041
4042 service()->ReloadExtensionsForTest(); 4042 service()->ReloadExtensionsForTest();
4043 4043
4044 // The creation flags should not change when reloading the extension. 4044 // The creation flags should not change when reloading the extension.
4045 const Extension* extension = service()->GetExtensionById(good_crx, true); 4045 const Extension* extension = service()->GetExtensionById(good_crx, true);
4046 EXPECT_TRUE(extension->from_webstore()); 4046 EXPECT_TRUE(extension->from_webstore());
(...skipping 19 matching lines...) Expand all
4066 EXPECT_EQ(1u, registry()->enabled_extensions().size()); 4066 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4067 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 4067 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4068 } 4068 }
4069 4069
4070 // Tests reloading an extension. 4070 // Tests reloading an extension.
4071 TEST_F(ExtensionServiceTest, ReloadExtension) { 4071 TEST_F(ExtensionServiceTest, ReloadExtension) {
4072 InitializeEmptyExtensionService(); 4072 InitializeEmptyExtensionService();
4073 InitializeProcessManager(); 4073 InitializeProcessManager();
4074 4074
4075 // Simple extension that should install without error. 4075 // Simple extension that should install without error.
4076 const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj"; 4076 const char extension_id[] = "behllobkkfkfnphdnhnkndlbkcpglgmj";
4077 base::FilePath ext = data_dir() 4077 base::FilePath ext = data_dir()
4078 .AppendASCII("good") 4078 .AppendASCII("good")
4079 .AppendASCII("Extensions") 4079 .AppendASCII("Extensions")
4080 .AppendASCII(extension_id) 4080 .AppendASCII(extension_id)
4081 .AppendASCII("1.0.0.0"); 4081 .AppendASCII("1.0.0.0");
4082 extensions::UnpackedInstaller::Create(service())->Load(ext); 4082 extensions::UnpackedInstaller::Create(service())->Load(ext);
4083 base::RunLoop().RunUntilIdle(); 4083 base::RunLoop().RunUntilIdle();
4084 4084
4085 EXPECT_EQ(1u, registry()->enabled_extensions().size()); 4085 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4086 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 4086 EXPECT_EQ(0u, registry()->disabled_extensions().size());
(...skipping 2158 matching lines...) Expand 10 before | Expand all | Expand 10 after
6245 extension_sync_service()->ProcessSyncChanges(FROM_HERE, change_list); 6245 extension_sync_service()->ProcessSyncChanges(FROM_HERE, change_list);
6246 6246
6247 // Uninstalling the extension without installed_by_custodian should have been 6247 // Uninstalling the extension without installed_by_custodian should have been
6248 // blocked by policy, so it should still be there. 6248 // blocked by policy, so it should still be there.
6249 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_ids[0])); 6249 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_ids[0]));
6250 6250
6251 // But installed_by_custodian should result in bypassing the policy check. 6251 // But installed_by_custodian should result in bypassing the policy check.
6252 EXPECT_FALSE( 6252 EXPECT_FALSE(
6253 registry()->GenerateInstalledExtensionsSet()->Contains(extension_ids[1])); 6253 registry()->GenerateInstalledExtensionsSet()->Contains(extension_ids[1]));
6254 } 6254 }
6255 #endif // defined(ENABLE_MANAGED_USERS) 6255 #endif // defined(ENABLE_MANAGED_USERS)
6256 6256
6257 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { 6257 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) {
6258 InitializeEmptyExtensionService(); 6258 InitializeEmptyExtensionService();
6259 6259
6260 base::FilePath path = data_dir().AppendASCII("good.crx"); 6260 base::FilePath path = data_dir().AppendASCII("good.crx");
6261 InstallCRX(path, INSTALL_NEW); 6261 InstallCRX(path, INSTALL_NEW);
6262 ValidatePrefKeyCount(1u); 6262 ValidatePrefKeyCount(1u);
6263 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 6263 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
6264 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 6264 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
6265 6265
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
7131 7131
7132 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 7132 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
7133 content::Source<Profile>(profile()), 7133 content::Source<Profile>(profile()),
7134 content::NotificationService::NoDetails()); 7134 content::NotificationService::NoDetails());
7135 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 7135 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
7136 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 7136 EXPECT_EQ(0u, registry()->enabled_extensions().size());
7137 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 7137 EXPECT_EQ(0u, registry()->disabled_extensions().size());
7138 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 7138 EXPECT_EQ(0u, registry()->terminated_extensions().size());
7139 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 7139 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
7140 } 7140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698