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

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

Issue 16295003: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
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 "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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 451
452 void ExtensionServiceTestBase::InitializeExtensionService( 452 void ExtensionServiceTestBase::InitializeExtensionService(
453 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) { 453 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) {
454 TestingProfile::Builder profile_builder; 454 TestingProfile::Builder profile_builder;
455 // Create a PrefService that only contains user defined preference values. 455 // Create a PrefService that only contains user defined preference values.
456 PrefServiceMockBuilder builder; 456 PrefServiceMockBuilder builder;
457 builder.WithUserFilePrefs( 457 builder.WithUserFilePrefs(
458 params.pref_file, loop_.message_loop_proxy()); 458 params.pref_file, loop_.message_loop_proxy());
459 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( 459 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
460 new user_prefs::PrefRegistrySyncable); 460 new user_prefs::PrefRegistrySyncable);
461 scoped_ptr<PrefServiceSyncable> prefs(builder.CreateSyncable(registry)); 461 scoped_ptr<PrefServiceSyncable> prefs(builder.CreateSyncable(registry.get()));
462 chrome::RegisterUserPrefs(registry); 462 chrome::RegisterUserPrefs(registry.get());
463 profile_builder.SetPrefService(prefs.Pass()); 463 profile_builder.SetPrefService(prefs.Pass());
464 profile_builder.SetPath(params.profile_path); 464 profile_builder.SetPath(params.profile_path);
465 profile_ = profile_builder.Build(); 465 profile_ = profile_builder.Build();
466 466
467 TestExtensionSystem* system = static_cast<TestExtensionSystem*>( 467 TestExtensionSystem* system = static_cast<TestExtensionSystem*>(
468 ExtensionSystem::Get(profile_.get())); 468 ExtensionSystem::Get(profile_.get()));
469 if (!params.is_first_run) { 469 if (!params.is_first_run) {
470 ExtensionPrefs* prefs = system->CreateExtensionPrefs( 470 ExtensionPrefs* prefs = system->CreateExtensionPrefs(
471 CommandLine::ForCurrentProcess(), 471 CommandLine::ForCurrentProcess(),
472 params.extensions_install_dir); 472 params.extensions_install_dir);
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 if (install_state == INSTALL_UPDATED && !expected_old_name.empty()) 796 if (install_state == INSTALL_UPDATED && !expected_old_name.empty())
797 EXPECT_EQ(expected_old_name, old_name_); 797 EXPECT_EQ(expected_old_name, old_name_);
798 EXPECT_EQ(0u, errors.size()) << path.value(); 798 EXPECT_EQ(0u, errors.size()) << path.value();
799 799
800 if (install_state == INSTALL_WITHOUT_LOAD) { 800 if (install_state == INSTALL_WITHOUT_LOAD) {
801 EXPECT_EQ(0u, loaded_.size()) << path.value(); 801 EXPECT_EQ(0u, loaded_.size()) << path.value();
802 } else { 802 } else {
803 EXPECT_EQ(1u, loaded_.size()) << path.value(); 803 EXPECT_EQ(1u, loaded_.size()) << path.value();
804 EXPECT_EQ(expected_extensions_count_, service_->extensions()->size()) << 804 EXPECT_EQ(expected_extensions_count_, service_->extensions()->size()) <<
805 path.value(); 805 path.value();
806 extension = loaded_[0]; 806 extension = loaded_[0].get();
807 EXPECT_TRUE(service_->GetExtensionById(extension->id(), false)) << 807 EXPECT_TRUE(service_->GetExtensionById(extension->id(), false))
808 path.value(); 808 << path.value();
809 } 809 }
810 810
811 for (std::vector<string16>::iterator err = errors.begin(); 811 for (std::vector<string16>::iterator err = errors.begin();
812 err != errors.end(); ++err) { 812 err != errors.end(); ++err) {
813 LOG(ERROR) << *err; 813 LOG(ERROR) << *err;
814 } 814 }
815 } else { 815 } else {
816 EXPECT_FALSE(installed_) << path.value(); 816 EXPECT_FALSE(installed_) << path.value();
817 EXPECT_EQ(0u, loaded_.size()) << path.value(); 817 EXPECT_EQ(0u, loaded_.size()) << path.value();
818 EXPECT_EQ(1u, errors.size()) << path.value(); 818 EXPECT_EQ(1u, errors.size()) << path.value();
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 ValidateIntegerPref(good0, "location", Manifest::INTERNAL); 1208 ValidateIntegerPref(good0, "location", Manifest::INTERNAL);
1209 ValidateIntegerPref(good1, "state", Extension::ENABLED); 1209 ValidateIntegerPref(good1, "state", Extension::ENABLED);
1210 ValidateIntegerPref(good1, "location", Manifest::INTERNAL); 1210 ValidateIntegerPref(good1, "location", Manifest::INTERNAL);
1211 ValidateIntegerPref(good2, "state", Extension::ENABLED); 1211 ValidateIntegerPref(good2, "state", Extension::ENABLED);
1212 ValidateIntegerPref(good2, "location", Manifest::INTERNAL); 1212 ValidateIntegerPref(good2, "location", Manifest::INTERNAL);
1213 1213
1214 URLPatternSet expected_patterns; 1214 URLPatternSet expected_patterns;
1215 AddPattern(&expected_patterns, "file:///*"); 1215 AddPattern(&expected_patterns, "file:///*");
1216 AddPattern(&expected_patterns, "http://*.google.com/*"); 1216 AddPattern(&expected_patterns, "http://*.google.com/*");
1217 AddPattern(&expected_patterns, "https://*.google.com/*"); 1217 AddPattern(&expected_patterns, "https://*.google.com/*");
1218 const Extension* extension = loaded_[0]; 1218 const Extension* extension = loaded_[0].get();
1219 const extensions::UserScriptList& scripts = 1219 const extensions::UserScriptList& scripts =
1220 extensions::ContentScriptsInfo::GetContentScripts(extension); 1220 extensions::ContentScriptsInfo::GetContentScripts(extension);
1221 ASSERT_EQ(2u, scripts.size()); 1221 ASSERT_EQ(2u, scripts.size());
1222 EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); 1222 EXPECT_EQ(expected_patterns, scripts[0].url_patterns());
1223 EXPECT_EQ(2u, scripts[0].js_scripts().size()); 1223 EXPECT_EQ(2u, scripts[0].js_scripts().size());
1224 ExtensionResource resource00(extension->id(), 1224 ExtensionResource resource00(extension->id(),
1225 scripts[0].js_scripts()[0].extension_root(), 1225 scripts[0].js_scripts()[0].extension_root(),
1226 scripts[0].js_scripts()[0].relative_path()); 1226 scripts[0].js_scripts()[0].relative_path());
1227 base::FilePath expected_path = 1227 base::FilePath expected_path =
1228 base::MakeAbsoluteFilePath(extension->path().AppendASCII("script1.js")); 1228 base::MakeAbsoluteFilePath(extension->path().AppendASCII("script1.js"));
(...skipping 19 matching lines...) Expand all
1248 expected_patterns.ClearPatterns(); 1248 expected_patterns.ClearPatterns();
1249 AddPattern(&expected_patterns, "http://*.google.com/*"); 1249 AddPattern(&expected_patterns, "http://*.google.com/*");
1250 AddPattern(&expected_patterns, "https://*.google.com/*"); 1250 AddPattern(&expected_patterns, "https://*.google.com/*");
1251 EXPECT_EQ(expected_patterns, 1251 EXPECT_EQ(expected_patterns,
1252 extension->GetActivePermissions()->explicit_hosts()); 1252 extension->GetActivePermissions()->explicit_hosts());
1253 1253
1254 EXPECT_EQ(std::string(good1), loaded_[1]->id()); 1254 EXPECT_EQ(std::string(good1), loaded_[1]->id());
1255 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); 1255 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name());
1256 EXPECT_EQ(std::string(), loaded_[1]->description()); 1256 EXPECT_EQ(std::string(), loaded_[1]->description());
1257 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), 1257 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"),
1258 extensions::BackgroundInfo::GetBackgroundURL(loaded_[1])); 1258 extensions::BackgroundInfo::GetBackgroundURL(loaded_[1].get()));
1259 EXPECT_EQ( 1259 EXPECT_EQ(0u,
1260 0u, extensions::ContentScriptsInfo::GetContentScripts(loaded_[1]).size()); 1260 extensions::ContentScriptsInfo::GetContentScripts(loaded_[1].get())
1261 .size());
1261 1262
1262 // We don't parse the plugins section on Chrome OS. 1263 // We don't parse the plugins section on Chrome OS.
1263 #if defined(OS_CHROMEOS) 1264 #if defined(OS_CHROMEOS)
1264 EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(loaded_[1])); 1265 EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(loaded_[1]));
1265 #else 1266 #else
1266 ASSERT_TRUE(extensions::PluginInfo::HasPlugins(loaded_[1])); 1267 ASSERT_TRUE(extensions::PluginInfo::HasPlugins(loaded_[1].get()));
1267 const std::vector<extensions::PluginInfo>* plugins = 1268 const std::vector<extensions::PluginInfo>* plugins =
1268 extensions::PluginInfo::GetPlugins(loaded_[1]); 1269 extensions::PluginInfo::GetPlugins(loaded_[1].get());
1269 ASSERT_TRUE(plugins); 1270 ASSERT_TRUE(plugins);
1270 ASSERT_EQ(2u, plugins->size()); 1271 ASSERT_EQ(2u, plugins->size());
1271 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), 1272 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(),
1272 plugins->at(0).path.value()); 1273 plugins->at(0).path.value());
1273 EXPECT_TRUE(plugins->at(0).is_public); 1274 EXPECT_TRUE(plugins->at(0).is_public);
1274 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), 1275 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(),
1275 plugins->at(1).path.value()); 1276 plugins->at(1).path.value());
1276 EXPECT_FALSE(plugins->at(1).is_public); 1277 EXPECT_FALSE(plugins->at(1).is_public);
1277 #endif 1278 #endif
1278 1279
1279 EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location()); 1280 EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location());
1280 1281
1281 int index = expected_num_extensions - 1; 1282 int index = expected_num_extensions - 1;
1282 EXPECT_EQ(std::string(good2), loaded_[index]->id()); 1283 EXPECT_EQ(std::string(good2), loaded_[index]->id());
1283 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); 1284 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name());
1284 EXPECT_EQ(std::string(), loaded_[index]->description()); 1285 EXPECT_EQ(std::string(), loaded_[index]->description());
1285 EXPECT_EQ( 1286 EXPECT_EQ(0u,
1286 0u, 1287 extensions::ContentScriptsInfo::GetContentScripts(
1287 extensions::ContentScriptsInfo::GetContentScripts(loaded_[index]).size()); 1288 loaded_[index].get()).size());
1288 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); 1289 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location());
1289 }; 1290 };
1290 1291
1291 // Test loading bad extensions from the profile directory. 1292 // Test loading bad extensions from the profile directory.
1292 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { 1293 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) {
1293 // Initialize the test dir with a bad Preferences/extensions. 1294 // Initialize the test dir with a bad Preferences/extensions.
1294 base::FilePath source_install_dir = data_dir_ 1295 base::FilePath source_install_dir = data_dir_
1295 .AppendASCII("bad") 1296 .AppendASCII("bad")
1296 .AppendASCII("Extensions"); 1297 .AppendASCII("Extensions");
1297 base::FilePath pref_path = source_install_dir 1298 base::FilePath pref_path = source_install_dir
(...skipping 2902 matching lines...) Expand 10 before | Expand all | Expand 10 after
4200 ASSERT_EQ(0u, GetErrors().size()); 4201 ASSERT_EQ(0u, GetErrors().size());
4201 ASSERT_EQ(1u, loaded_.size()); 4202 ASSERT_EQ(1u, loaded_.size());
4202 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 4203 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
4203 ValidatePrefKeyCount(1); 4204 ValidatePrefKeyCount(1);
4204 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4205 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4205 ValidateIntegerPref(good_crx, "location", location); 4206 ValidateIntegerPref(good_crx, "location", location);
4206 4207
4207 // Uninstall the extension and reload. Nothing should happen because the 4208 // Uninstall the extension and reload. Nothing should happen because the
4208 // preference should prevent us from reinstalling. 4209 // preference should prevent us from reinstalling.
4209 std::string id = loaded_[0]->id(); 4210 std::string id = loaded_[0]->id();
4210 bool no_uninstall = management_policy_->MustRemainEnabled(loaded_[0], NULL); 4211 bool no_uninstall =
4212 management_policy_->MustRemainEnabled(loaded_[0].get(), NULL);
4211 service_->UninstallExtension(id, false, NULL); 4213 service_->UninstallExtension(id, false, NULL);
4212 loop_.RunUntilIdle(); 4214 loop_.RunUntilIdle();
4213 4215
4214 base::FilePath install_path = extensions_install_dir_.AppendASCII(id); 4216 base::FilePath install_path = extensions_install_dir_.AppendASCII(id);
4215 if (no_uninstall) { 4217 if (no_uninstall) {
4216 // Policy controlled extensions should not have been touched by uninstall. 4218 // Policy controlled extensions should not have been touched by uninstall.
4217 ASSERT_TRUE(file_util::PathExists(install_path)); 4219 ASSERT_TRUE(file_util::PathExists(install_path));
4218 } else { 4220 } else {
4219 // The extension should also be gone from the install directory. 4221 // The extension should also be gone from the install directory.
4220 ASSERT_FALSE(file_util::PathExists(install_path)); 4222 ASSERT_FALSE(file_util::PathExists(install_path));
(...skipping 11 matching lines...) Expand all
4232 4234
4233 loaded_.clear(); 4235 loaded_.clear();
4234 service_->CheckForExternalUpdates(); 4236 service_->CheckForExternalUpdates();
4235 loop_.RunUntilIdle(); 4237 loop_.RunUntilIdle();
4236 ASSERT_EQ(1u, loaded_.size()); 4238 ASSERT_EQ(1u, loaded_.size());
4237 } 4239 }
4238 ValidatePrefKeyCount(1); 4240 ValidatePrefKeyCount(1);
4239 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4241 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4240 ValidateIntegerPref(good_crx, "location", location); 4242 ValidateIntegerPref(good_crx, "location", location);
4241 4243
4242 if (management_policy_->MustRemainEnabled(loaded_[0], NULL)) { 4244 if (management_policy_->MustRemainEnabled(loaded_[0].get(), NULL)) {
4243 EXPECT_EQ(2, provider->visit_count()); 4245 EXPECT_EQ(2, provider->visit_count());
4244 } else { 4246 } else {
4245 // Now test an externally triggered uninstall (deleting the registry key or 4247 // Now test an externally triggered uninstall (deleting the registry key or
4246 // the pref entry). 4248 // the pref entry).
4247 provider->RemoveExtension(good_crx); 4249 provider->RemoveExtension(good_crx);
4248 4250
4249 loaded_.clear(); 4251 loaded_.clear();
4250 service_->OnExternalProviderReady(provider); 4252 service_->OnExternalProviderReady(provider);
4251 loop_.RunUntilIdle(); 4253 loop_.RunUntilIdle();
4252 ASSERT_EQ(0u, loaded_.size()); 4254 ASSERT_EQ(0u, loaded_.size());
(...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after
6010 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6012 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
6011 AddMockExternalProvider(provider); 6013 AddMockExternalProvider(provider);
6012 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6014 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
6013 6015
6014 service_->CheckForExternalUpdates(); 6016 service_->CheckForExternalUpdates();
6015 loop_.RunUntilIdle(); 6017 loop_.RunUntilIdle();
6016 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6018 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
6017 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); 6019 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_));
6018 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); 6020 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore));
6019 } 6021 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/extension_sorting_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698