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

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

Issue 5730004: Rename ExtensionsService to ExtensionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/extensions_service_unittest.h" 5 #include "chrome/browser/extensions/extension_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/scoped_ptr.h" 16 #include "base/scoped_ptr.h"
17 #include "base/stl_util-inl.h" 17 #include "base/stl_util-inl.h"
18 #include "base/string16.h" 18 #include "base/string16.h"
19 #include "base/string_number_conversions.h" 19 #include "base/string_number_conversions.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/task.h" 21 #include "base/task.h"
22 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
23 #include "base/version.h" 23 #include "base/version.h"
24 #include "chrome/browser/appcache/chrome_appcache_service.h" 24 #include "chrome/browser/appcache/chrome_appcache_service.h"
25 #include "chrome/browser/browser_thread.h" 25 #include "chrome/browser/browser_thread.h"
26 #include "chrome/browser/extensions/crx_installer.h" 26 #include "chrome/browser/extensions/crx_installer.h"
27 #include "chrome/browser/extensions/extension_creator.h" 27 #include "chrome/browser/extensions/extension_creator.h"
28 #include "chrome/browser/extensions/extension_error_reporter.h" 28 #include "chrome/browser/extensions/extension_error_reporter.h"
29 #include "chrome/browser/extensions/extensions_service.h" 29 #include "chrome/browser/extensions/extension_service.h"
30 #include "chrome/browser/extensions/external_extension_provider.h" 30 #include "chrome/browser/extensions/external_extension_provider.h"
31 #include "chrome/browser/extensions/external_pref_extension_provider.h" 31 #include "chrome/browser/extensions/external_pref_extension_provider.h"
32 #include "chrome/browser/extensions/pack_extension_job.cc" 32 #include "chrome/browser/extensions/pack_extension_job.cc"
33 #include "chrome/browser/file_system/browser_file_system_helper.h" 33 #include "chrome/browser/file_system/browser_file_system_helper.h"
34 #include "chrome/browser/in_process_webkit/dom_storage_context.h" 34 #include "chrome/browser/in_process_webkit/dom_storage_context.h"
35 #include "chrome/browser/in_process_webkit/webkit_context.h" 35 #include "chrome/browser/in_process_webkit/webkit_context.h"
36 #include "chrome/browser/prefs/browser_prefs.h" 36 #include "chrome/browser/prefs/browser_prefs.h"
37 #include "chrome/browser/prefs/pref_service_mock_builder.h" 37 #include "chrome/browser/prefs/pref_service_mock_builder.h"
38 #include "chrome/browser/prefs/scoped_pref_update.h" 38 #include "chrome/browser/prefs/scoped_pref_update.h"
39 #include "chrome/common/chrome_paths.h" 39 #include "chrome/common/chrome_paths.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 scoped_ptr<DictionaryValue> prefs_; 291 scoped_ptr<DictionaryValue> prefs_;
292 292
293 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); 293 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
294 }; 294 };
295 295
296 class ExtensionTestingProfile : public TestingProfile { 296 class ExtensionTestingProfile : public TestingProfile {
297 public: 297 public:
298 ExtensionTestingProfile() : service_(NULL) { 298 ExtensionTestingProfile() : service_(NULL) {
299 } 299 }
300 300
301 void set_extensions_service(ExtensionsService* service) { 301 void set_extensions_service(ExtensionService* service) {
302 service_ = service; 302 service_ = service;
303 } 303 }
304 virtual ExtensionsService* GetExtensionsService() { return service_; } 304 virtual ExtensionService* GetExtensionService() { return service_; }
305 305
306 virtual ChromeAppCacheService* GetAppCacheService() { 306 virtual ChromeAppCacheService* GetAppCacheService() {
307 if (!appcache_service_) { 307 if (!appcache_service_) {
308 appcache_service_ = new ChromeAppCacheService; 308 appcache_service_ = new ChromeAppCacheService;
309 BrowserThread::PostTask( 309 BrowserThread::PostTask(
310 BrowserThread::IO, FROM_HERE, 310 BrowserThread::IO, FROM_HERE,
311 NewRunnableMethod(appcache_service_.get(), 311 NewRunnableMethod(appcache_service_.get(),
312 &ChromeAppCacheService::InitializeOnIOThread, 312 &ChromeAppCacheService::InitializeOnIOThread,
313 GetPath(), IsOffTheRecord(), 313 GetPath(), IsOffTheRecord(),
314 make_scoped_refptr(GetHostContentSettingsMap()))); 314 make_scoped_refptr(GetHostContentSettingsMap())));
315 } 315 }
316 return appcache_service_; 316 return appcache_service_;
317 } 317 }
318 318
319 virtual fileapi::SandboxedFileSystemContext* GetFileSystemContext() { 319 virtual fileapi::SandboxedFileSystemContext* GetFileSystemContext() {
320 if (!file_system_context_) 320 if (!file_system_context_)
321 file_system_context_ = CreateFileSystemContext( 321 file_system_context_ = CreateFileSystemContext(
322 GetPath(), IsOffTheRecord()); 322 GetPath(), IsOffTheRecord());
323 return file_system_context_; 323 return file_system_context_;
324 } 324 }
325 325
326 private: 326 private:
327 ExtensionsService* service_; 327 ExtensionService* service_;
328 scoped_refptr<ChromeAppCacheService> appcache_service_; 328 scoped_refptr<ChromeAppCacheService> appcache_service_;
329 scoped_refptr<fileapi::SandboxedFileSystemContext> file_system_context_; 329 scoped_refptr<fileapi::SandboxedFileSystemContext> file_system_context_;
330 }; 330 };
331 331
332 // Our message loop may be used in tests which require it to be an IO loop. 332 // Our message loop may be used in tests which require it to be an IO loop.
333 ExtensionsServiceTestBase::ExtensionsServiceTestBase() 333 ExtensionServiceTestBase::ExtensionServiceTestBase()
334 : total_successes_(0), 334 : total_successes_(0),
335 loop_(MessageLoop::TYPE_IO), 335 loop_(MessageLoop::TYPE_IO),
336 ui_thread_(BrowserThread::UI, &loop_), 336 ui_thread_(BrowserThread::UI, &loop_),
337 db_thread_(BrowserThread::DB, &loop_), 337 db_thread_(BrowserThread::DB, &loop_),
338 webkit_thread_(BrowserThread::WEBKIT, &loop_), 338 webkit_thread_(BrowserThread::WEBKIT, &loop_),
339 file_thread_(BrowserThread::FILE, &loop_), 339 file_thread_(BrowserThread::FILE, &loop_),
340 io_thread_(BrowserThread::IO, &loop_) { 340 io_thread_(BrowserThread::IO, &loop_) {
341 } 341 }
342 342
343 ExtensionsServiceTestBase::~ExtensionsServiceTestBase() { 343 ExtensionServiceTestBase::~ExtensionServiceTestBase() {
344 // Drop our reference to ExtensionsService and TestingProfile, so that they 344 // Drop our reference to ExtensionService and TestingProfile, so that they
345 // can be destroyed while BrowserThreads and MessageLoop are still around 345 // can be destroyed while BrowserThreads and MessageLoop are still around
346 // (they are used in the destruction process). 346 // (they are used in the destruction process).
347 service_ = NULL; 347 service_ = NULL;
348 profile_.reset(NULL); 348 profile_.reset(NULL);
349 MessageLoop::current()->RunAllPending(); 349 MessageLoop::current()->RunAllPending();
350 } 350 }
351 351
352 void ExtensionsServiceTestBase::InitializeExtensionsService( 352 void ExtensionServiceTestBase::InitializeExtensionService(
353 const FilePath& pref_file, const FilePath& extensions_install_dir) { 353 const FilePath& pref_file, const FilePath& extensions_install_dir) {
354 ExtensionTestingProfile* profile = new ExtensionTestingProfile(); 354 ExtensionTestingProfile* profile = new ExtensionTestingProfile();
355 // Create a PrefService that only contains user defined preference values. 355 // Create a PrefService that only contains user defined preference values.
356 PrefService* prefs = 356 PrefService* prefs =
357 PrefServiceMockBuilder().WithUserFilePrefs(pref_file).Create(); 357 PrefServiceMockBuilder().WithUserFilePrefs(pref_file).Create();
358 Profile::RegisterUserPrefs(prefs); 358 Profile::RegisterUserPrefs(prefs);
359 browser::RegisterUserPrefs(prefs); 359 browser::RegisterUserPrefs(prefs);
360 profile->SetPrefService(prefs); 360 profile->SetPrefService(prefs);
361 361
362 profile_.reset(profile); 362 profile_.reset(profile);
363 363
364 service_ = profile->CreateExtensionsService( 364 service_ = profile->CreateExtensionService(
365 CommandLine::ForCurrentProcess(), 365 CommandLine::ForCurrentProcess(),
366 extensions_install_dir); 366 extensions_install_dir);
367 service_->set_extensions_enabled(true); 367 service_->set_extensions_enabled(true);
368 service_->set_show_extensions_prompts(false); 368 service_->set_show_extensions_prompts(false);
369 profile->set_extensions_service(service_.get()); 369 profile->set_extensions_service(service_.get());
370 370
371 // When we start up, we want to make sure there is no external provider, 371 // When we start up, we want to make sure there is no external provider,
372 // since the ExtensionService on Windows will use the Registry as a default 372 // since the ExtensionService on Windows will use the Registry as a default
373 // provider and if there is something already registered there then it will 373 // provider and if there is something already registered there then it will
374 // interfere with the tests. Those tests that need an external provider 374 // interfere with the tests. Those tests that need an external provider
375 // will register one specifically. 375 // will register one specifically.
376 service_->ClearProvidersForTesting(); 376 service_->ClearProvidersForTesting();
377 377
378 total_successes_ = 0; 378 total_successes_ = 0;
379 } 379 }
380 380
381 void ExtensionsServiceTestBase::InitializeInstalledExtensionsService( 381 void ExtensionServiceTestBase::InitializeInstalledExtensionService(
382 const FilePath& prefs_file, const FilePath& source_install_dir) { 382 const FilePath& prefs_file, const FilePath& source_install_dir) {
383 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 383 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
384 FilePath path_ = temp_dir_.path(); 384 FilePath path_ = temp_dir_.path();
385 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 385 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
386 file_util::Delete(path_, true); 386 file_util::Delete(path_, true);
387 file_util::CreateDirectory(path_); 387 file_util::CreateDirectory(path_);
388 FilePath temp_prefs = path_.Append(FILE_PATH_LITERAL("Preferences")); 388 FilePath temp_prefs = path_.Append(FILE_PATH_LITERAL("Preferences"));
389 file_util::CopyFile(prefs_file, temp_prefs); 389 file_util::CopyFile(prefs_file, temp_prefs);
390 390
391 extensions_install_dir_ = path_.Append(FILE_PATH_LITERAL("Extensions")); 391 extensions_install_dir_ = path_.Append(FILE_PATH_LITERAL("Extensions"));
392 file_util::Delete(extensions_install_dir_, true); 392 file_util::Delete(extensions_install_dir_, true);
393 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); 393 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true);
394 394
395 InitializeExtensionsService(temp_prefs, extensions_install_dir_); 395 InitializeExtensionService(temp_prefs, extensions_install_dir_);
396 } 396 }
397 397
398 void ExtensionsServiceTestBase::InitializeEmptyExtensionsService() { 398 void ExtensionServiceTestBase::InitializeEmptyExtensionService() {
399 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 399 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
400 FilePath path_ = temp_dir_.path(); 400 FilePath path_ = temp_dir_.path();
401 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 401 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
402 file_util::Delete(path_, true); 402 file_util::Delete(path_, true);
403 file_util::CreateDirectory(path_); 403 file_util::CreateDirectory(path_);
404 FilePath prefs_filename = path_ 404 FilePath prefs_filename = path_
405 .Append(FILE_PATH_LITERAL("TestPreferences")); 405 .Append(FILE_PATH_LITERAL("TestPreferences"));
406 extensions_install_dir_ = path_.Append(FILE_PATH_LITERAL("Extensions")); 406 extensions_install_dir_ = path_.Append(FILE_PATH_LITERAL("Extensions"));
407 file_util::Delete(extensions_install_dir_, true); 407 file_util::Delete(extensions_install_dir_, true);
408 file_util::CreateDirectory(extensions_install_dir_); 408 file_util::CreateDirectory(extensions_install_dir_);
409 409
410 InitializeExtensionsService(prefs_filename, extensions_install_dir_); 410 InitializeExtensionService(prefs_filename, extensions_install_dir_);
411 } 411 }
412 412
413 // static 413 // static
414 void ExtensionsServiceTestBase::SetUpTestCase() { 414 void ExtensionServiceTestBase::SetUpTestCase() {
415 ExtensionErrorReporter::Init(false); // no noisy errors 415 ExtensionErrorReporter::Init(false); // no noisy errors
416 } 416 }
417 417
418 void ExtensionsServiceTestBase::SetUp() { 418 void ExtensionServiceTestBase::SetUp() {
419 ExtensionErrorReporter::GetInstance()->ClearErrors(); 419 ExtensionErrorReporter::GetInstance()->ClearErrors();
420 } 420 }
421 421
422 class ExtensionsServiceTest 422 class ExtensionServiceTest
423 : public ExtensionsServiceTestBase, public NotificationObserver { 423 : public ExtensionServiceTestBase, public NotificationObserver {
424 public: 424 public:
425 ExtensionsServiceTest() : installed_(NULL) { 425 ExtensionServiceTest() : installed_(NULL) {
426 registrar_.Add(this, NotificationType::EXTENSION_LOADED, 426 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
427 NotificationService::AllSources()); 427 NotificationService::AllSources());
428 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 428 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
429 NotificationService::AllSources()); 429 NotificationService::AllSources());
430 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED, 430 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED,
431 NotificationService::AllSources()); 431 NotificationService::AllSources());
432 registrar_.Add(this, NotificationType::THEME_INSTALLED, 432 registrar_.Add(this, NotificationType::THEME_INSTALLED,
433 NotificationService::AllSources()); 433 NotificationService::AllSources());
434 } 434 }
435 435
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 EXPECT_EQ(expected_private_key_path_.value(), private_key_path.value()); 809 EXPECT_EQ(expected_private_key_path_.value(), private_key_path.value());
810 ASSERT_TRUE(file_util::PathExists(private_key_path)); 810 ASSERT_TRUE(file_util::PathExists(private_key_path));
811 } 811 }
812 812
813 // The tests are designed so that we never expect to see a packing error. 813 // The tests are designed so that we never expect to see a packing error.
814 void PackExtensionTestClient::OnPackFailure(const std::string& error_message) { 814 void PackExtensionTestClient::OnPackFailure(const std::string& error_message) {
815 FAIL() << "Packing should not fail."; 815 FAIL() << "Packing should not fail.";
816 } 816 }
817 817
818 // Test loading good extensions from the profile directory. 818 // Test loading good extensions from the profile directory.
819 TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) { 819 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) {
820 // Initialize the test dir with a good Preferences/extensions. 820 // Initialize the test dir with a good Preferences/extensions.
821 FilePath source_install_dir; 821 FilePath source_install_dir;
822 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); 822 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir));
823 source_install_dir = source_install_dir 823 source_install_dir = source_install_dir
824 .AppendASCII("extensions") 824 .AppendASCII("extensions")
825 .AppendASCII("good") 825 .AppendASCII("good")
826 .AppendASCII("Extensions"); 826 .AppendASCII("Extensions");
827 FilePath pref_path = source_install_dir 827 FilePath pref_path = source_install_dir
828 .DirName() 828 .DirName()
829 .AppendASCII("Preferences"); 829 .AppendASCII("Preferences");
830 InitializeInstalledExtensionsService(pref_path, source_install_dir); 830 InitializeInstalledExtensionService(pref_path, source_install_dir);
831 831
832 service_->Init(); 832 service_->Init();
833 833
834 // On Chrome OS, we disallow extensions with plugins. "good1" has plugins, 834 // On Chrome OS, we disallow extensions with plugins. "good1" has plugins,
835 // so we need to edit it out here. 835 // so we need to edit it out here.
836 uint32 expected_num_extensions = 3u; 836 uint32 expected_num_extensions = 3u;
837 #if defined(OS_CHROMEOS) 837 #if defined(OS_CHROMEOS)
838 --expected_num_extensions; 838 --expected_num_extensions;
839 #endif 839 #endif
840 ASSERT_EQ(expected_num_extensions, loaded_.size()); 840 ASSERT_EQ(expected_num_extensions, loaded_.size());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 913
914 int index = expected_num_extensions - 1; 914 int index = expected_num_extensions - 1;
915 EXPECT_EQ(std::string(good2), loaded_[index]->id()); 915 EXPECT_EQ(std::string(good2), loaded_[index]->id());
916 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); 916 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name());
917 EXPECT_EQ(std::string(""), loaded_[index]->description()); 917 EXPECT_EQ(std::string(""), loaded_[index]->description());
918 EXPECT_EQ(0u, loaded_[index]->content_scripts().size()); 918 EXPECT_EQ(0u, loaded_[index]->content_scripts().size());
919 EXPECT_EQ(Extension::INTERNAL, loaded_[index]->location()); 919 EXPECT_EQ(Extension::INTERNAL, loaded_[index]->location());
920 }; 920 };
921 921
922 // Test loading bad extensions from the profile directory. 922 // Test loading bad extensions from the profile directory.
923 TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectoryFail) { 923 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) {
924 // Initialize the test dir with a bad Preferences/extensions. 924 // Initialize the test dir with a bad Preferences/extensions.
925 FilePath source_install_dir; 925 FilePath source_install_dir;
926 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); 926 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir));
927 source_install_dir = source_install_dir 927 source_install_dir = source_install_dir
928 .AppendASCII("extensions") 928 .AppendASCII("extensions")
929 .AppendASCII("bad") 929 .AppendASCII("bad")
930 .AppendASCII("Extensions"); 930 .AppendASCII("Extensions");
931 FilePath pref_path = source_install_dir 931 FilePath pref_path = source_install_dir
932 .DirName() 932 .DirName()
933 .AppendASCII("Preferences"); 933 .AppendASCII("Preferences");
934 934
935 InitializeInstalledExtensionsService(pref_path, source_install_dir); 935 InitializeInstalledExtensionService(pref_path, source_install_dir);
936 936
937 service_->Init(); 937 service_->Init();
938 loop_.RunAllPending(); 938 loop_.RunAllPending();
939 939
940 ASSERT_EQ(4u, GetErrors().size()); 940 ASSERT_EQ(4u, GetErrors().size());
941 ASSERT_EQ(0u, loaded_.size()); 941 ASSERT_EQ(0u, loaded_.size());
942 942
943 EXPECT_TRUE(MatchPattern(GetErrors()[0], 943 EXPECT_TRUE(MatchPattern(GetErrors()[0],
944 std::string("Could not load extension from '*'. ") + 944 std::string("Could not load extension from '*'. ") +
945 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[0]; 945 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[0];
946 946
947 EXPECT_TRUE(MatchPattern(GetErrors()[1], 947 EXPECT_TRUE(MatchPattern(GetErrors()[1],
948 std::string("Could not load extension from '*'. ") + 948 std::string("Could not load extension from '*'. ") +
949 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[1]; 949 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[1];
950 950
951 EXPECT_TRUE(MatchPattern(GetErrors()[2], 951 EXPECT_TRUE(MatchPattern(GetErrors()[2],
952 std::string("Could not load extension from '*'. ") + 952 std::string("Could not load extension from '*'. ") +
953 extension_manifest_errors::kMissingFile)) << GetErrors()[2]; 953 extension_manifest_errors::kMissingFile)) << GetErrors()[2];
954 954
955 EXPECT_TRUE(MatchPattern(GetErrors()[3], 955 EXPECT_TRUE(MatchPattern(GetErrors()[3],
956 std::string("Could not load extension from '*'. ") + 956 std::string("Could not load extension from '*'. ") +
957 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[3]; 957 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[3];
958 }; 958 };
959 959
960 // Test that partially deleted extensions are cleaned up during startup 960 // Test that partially deleted extensions are cleaned up during startup
961 // Test loading bad extensions from the profile directory. 961 // Test loading bad extensions from the profile directory.
962 TEST_F(ExtensionsServiceTest, CleanupOnStartup) { 962 TEST_F(ExtensionServiceTest, CleanupOnStartup) {
963 FilePath source_install_dir; 963 FilePath source_install_dir;
964 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); 964 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir));
965 source_install_dir = source_install_dir 965 source_install_dir = source_install_dir
966 .AppendASCII("extensions") 966 .AppendASCII("extensions")
967 .AppendASCII("good") 967 .AppendASCII("good")
968 .AppendASCII("Extensions"); 968 .AppendASCII("Extensions");
969 FilePath pref_path = source_install_dir 969 FilePath pref_path = source_install_dir
970 .DirName() 970 .DirName()
971 .AppendASCII("Preferences"); 971 .AppendASCII("Preferences");
972 972
973 InitializeInstalledExtensionsService(pref_path, source_install_dir); 973 InitializeInstalledExtensionService(pref_path, source_install_dir);
974 974
975 // Simulate that one of them got partially deleted by clearing its pref. 975 // Simulate that one of them got partially deleted by clearing its pref.
976 DictionaryValue* dict = 976 DictionaryValue* dict =
977 profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); 977 profile_->GetPrefs()->GetMutableDictionary("extensions.settings");
978 ASSERT_TRUE(dict != NULL); 978 ASSERT_TRUE(dict != NULL);
979 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); 979 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL);
980 980
981 service_->Init(); 981 service_->Init();
982 loop_.RunAllPending(); 982 loop_.RunAllPending();
983 983
984 file_util::FileEnumerator dirs(extensions_install_dir_, false, 984 file_util::FileEnumerator dirs(extensions_install_dir_, false,
985 file_util::FileEnumerator::DIRECTORIES); 985 file_util::FileEnumerator::DIRECTORIES);
986 size_t count = 0; 986 size_t count = 0;
987 while (!dirs.Next().empty()) 987 while (!dirs.Next().empty())
988 count++; 988 count++;
989 989
990 // We should have only gotten two extensions now. 990 // We should have only gotten two extensions now.
991 EXPECT_EQ(2u, count); 991 EXPECT_EQ(2u, count);
992 992
993 // And extension1 dir should now be toast. 993 // And extension1 dir should now be toast.
994 FilePath extension_dir = extensions_install_dir_ 994 FilePath extension_dir = extensions_install_dir_
995 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj"); 995 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj");
996 ASSERT_FALSE(file_util::PathExists(extension_dir)); 996 ASSERT_FALSE(file_util::PathExists(extension_dir));
997 } 997 }
998 998
999 // Test installing extensions. This test tries to install few extensions using 999 // Test installing extensions. This test tries to install few extensions using
1000 // crx files. If you need to change those crx files, feel free to repackage 1000 // crx files. If you need to change those crx files, feel free to repackage
1001 // them, throw away the key used and change the id's above. 1001 // them, throw away the key used and change the id's above.
1002 TEST_F(ExtensionsServiceTest, InstallExtension) { 1002 TEST_F(ExtensionServiceTest, InstallExtension) {
1003 InitializeEmptyExtensionsService(); 1003 InitializeEmptyExtensionService();
1004 1004
1005 FilePath extensions_path; 1005 FilePath extensions_path;
1006 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1006 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1007 extensions_path = extensions_path.AppendASCII("extensions"); 1007 extensions_path = extensions_path.AppendASCII("extensions");
1008 1008
1009 // Extensions not enabled. 1009 // Extensions not enabled.
1010 set_extensions_enabled(false); 1010 set_extensions_enabled(false);
1011 FilePath path = extensions_path.AppendASCII("good.crx"); 1011 FilePath path = extensions_path.AppendASCII("good.crx");
1012 InstallExtension(path, false); 1012 InstallExtension(path, false);
1013 set_extensions_enabled(true); 1013 set_extensions_enabled(true);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 // We did not used to handle this correctly for installation. 1052 // We did not used to handle this correctly for installation.
1053 path = extensions_path.AppendASCII("bad_underscore.crx"); 1053 path = extensions_path.AppendASCII("bad_underscore.crx");
1054 InstallExtension(path, false); 1054 InstallExtension(path, false);
1055 ValidatePrefKeyCount(pref_count); 1055 ValidatePrefKeyCount(pref_count);
1056 1056
1057 // TODO(erikkay): add more tests for many of the failure cases. 1057 // TODO(erikkay): add more tests for many of the failure cases.
1058 // TODO(erikkay): add tests for upgrade cases. 1058 // TODO(erikkay): add tests for upgrade cases.
1059 } 1059 }
1060 1060
1061 // Test the handling of killed extensions. 1061 // Test the handling of killed extensions.
1062 TEST_F(ExtensionsServiceTest, KilledExtensions) { 1062 TEST_F(ExtensionServiceTest, KilledExtensions) {
1063 InitializeEmptyExtensionsService(); 1063 InitializeEmptyExtensionService();
1064 1064
1065 FilePath extensions_path; 1065 FilePath extensions_path;
1066 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1066 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1067 extensions_path = extensions_path.AppendASCII("extensions"); 1067 extensions_path = extensions_path.AppendASCII("extensions");
1068 FilePath path = extensions_path.AppendASCII("good.crx"); 1068 FilePath path = extensions_path.AppendASCII("good.crx");
1069 set_extensions_enabled(true); 1069 set_extensions_enabled(true);
1070 1070
1071 // Install an external extension. 1071 // Install an external extension.
1072 service_->OnExternalExtensionFileFound(good_crx, "1.0.0.0", 1072 service_->OnExternalExtensionFileFound(good_crx, "1.0.0.0",
1073 path, Extension::EXTERNAL_PREF); 1073 path, Extension::EXTERNAL_PREF);
(...skipping 24 matching lines...) Expand all
1098 service_->AddPendingExtensionFromExternalUpdateUrl( 1098 service_->AddPendingExtensionFromExternalUpdateUrl(
1099 good_crx, 1099 good_crx,
1100 GURL("http:://fake.update/url"), 1100 GURL("http:://fake.update/url"),
1101 Extension::EXTERNAL_PREF_DOWNLOAD); 1101 Extension::EXTERNAL_PREF_DOWNLOAD);
1102 const PendingExtensionMap& pending_extensions = 1102 const PendingExtensionMap& pending_extensions =
1103 service_->pending_extensions(); 1103 service_->pending_extensions();
1104 ASSERT_TRUE(pending_extensions.find(good_crx) == pending_extensions.end()); 1104 ASSERT_TRUE(pending_extensions.find(good_crx) == pending_extensions.end());
1105 } 1105 }
1106 1106
1107 // Install a user script (they get converted automatically to an extension) 1107 // Install a user script (they get converted automatically to an extension)
1108 TEST_F(ExtensionsServiceTest, InstallUserScript) { 1108 TEST_F(ExtensionServiceTest, InstallUserScript) {
1109 // The details of script conversion are tested elsewhere, this just tests 1109 // The details of script conversion are tested elsewhere, this just tests
1110 // integration with ExtensionsService. 1110 // integration with ExtensionService.
1111 InitializeEmptyExtensionsService(); 1111 InitializeEmptyExtensionService();
1112 1112
1113 FilePath path; 1113 FilePath path;
1114 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 1114 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
1115 path = path.AppendASCII("extensions") 1115 path = path.AppendASCII("extensions")
1116 .AppendASCII("user_script_basic.user.js"); 1116 .AppendASCII("user_script_basic.user.js");
1117 1117
1118 ASSERT_TRUE(file_util::PathExists(path)); 1118 ASSERT_TRUE(file_util::PathExists(path));
1119 scoped_refptr<CrxInstaller> installer( 1119 scoped_refptr<CrxInstaller> installer(
1120 new CrxInstaller(service_, NULL)); // silent install 1120 new CrxInstaller(service_, NULL)); // silent install
1121 installer->InstallUserScript( 1121 installer->InstallUserScript(
1122 path, 1122 path,
1123 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); 1123 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js"));
1124 1124
1125 loop_.RunAllPending(); 1125 loop_.RunAllPending();
1126 std::vector<std::string> errors = GetErrors(); 1126 std::vector<std::string> errors = GetErrors();
1127 EXPECT_TRUE(installed_) << "Nothing was installed."; 1127 EXPECT_TRUE(installed_) << "Nothing was installed.";
1128 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; 1128 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded.";
1129 EXPECT_EQ(0u, errors.size()) << "There were errors: " 1129 EXPECT_EQ(0u, errors.size()) << "There were errors: "
1130 << JoinString(errors, ','); 1130 << JoinString(errors, ',');
1131 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << 1131 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) <<
1132 path.value(); 1132 path.value();
1133 1133
1134 installed_ = NULL; 1134 installed_ = NULL;
1135 loaded_.clear(); 1135 loaded_.clear();
1136 ExtensionErrorReporter::GetInstance()->ClearErrors(); 1136 ExtensionErrorReporter::GetInstance()->ClearErrors();
1137 } 1137 }
1138 1138
1139 // This tests that the granted permissions preferences are correctly set when 1139 // This tests that the granted permissions preferences are correctly set when
1140 // installing an extension. 1140 // installing an extension.
1141 TEST_F(ExtensionsServiceTest, GrantedPermissions) { 1141 TEST_F(ExtensionServiceTest, GrantedPermissions) {
1142 InitializeEmptyExtensionsService(); 1142 InitializeEmptyExtensionService();
1143 FilePath path; 1143 FilePath path;
1144 FilePath pem_path; 1144 FilePath pem_path;
1145 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 1145 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
1146 path = path.AppendASCII("extensions") 1146 path = path.AppendASCII("extensions")
1147 .AppendASCII("permissions"); 1147 .AppendASCII("permissions");
1148 1148
1149 pem_path = path.AppendASCII("unknown.pem"); 1149 pem_path = path.AppendASCII("unknown.pem");
1150 path = path.AppendASCII("unknown"); 1150 path = path.AppendASCII("unknown");
1151 1151
1152 ASSERT_TRUE(file_util::PathExists(pem_path)); 1152 ASSERT_TRUE(file_util::PathExists(pem_path));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 1190
1191 EXPECT_EQ(expected_api_perms, known_api_perms); 1191 EXPECT_EQ(expected_api_perms, known_api_perms);
1192 EXPECT_FALSE(full_access); 1192 EXPECT_FALSE(full_access);
1193 AssertEqualExtents(&expected_host_perms, &known_host_perms); 1193 AssertEqualExtents(&expected_host_perms, &known_host_perms);
1194 } 1194 }
1195 1195
1196 #if !defined(OS_CHROMEOS) 1196 #if !defined(OS_CHROMEOS)
1197 // Tests that the granted permissions full_access bit gets set correctly when 1197 // Tests that the granted permissions full_access bit gets set correctly when
1198 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS 1198 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS
1199 // since they don't support plugins. 1199 // since they don't support plugins.
1200 TEST_F(ExtensionsServiceTest, GrantedFullAccessPermissions) { 1200 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) {
1201 InitializeEmptyExtensionsService(); 1201 InitializeEmptyExtensionService();
1202 1202
1203 FilePath path; 1203 FilePath path;
1204 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 1204 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
1205 path = path.AppendASCII("extensions") 1205 path = path.AppendASCII("extensions")
1206 .AppendASCII("good") 1206 .AppendASCII("good")
1207 .AppendASCII("Extensions") 1207 .AppendASCII("Extensions")
1208 .AppendASCII(good1) 1208 .AppendASCII(good1)
1209 .AppendASCII("2"); 1209 .AppendASCII("2");
1210 1210
1211 ASSERT_TRUE(file_util::PathExists(path)); 1211 ASSERT_TRUE(file_util::PathExists(path));
(...skipping 14 matching lines...) Expand all
1226 1226
1227 EXPECT_TRUE(full_access); 1227 EXPECT_TRUE(full_access);
1228 EXPECT_TRUE(api_permissions.empty()); 1228 EXPECT_TRUE(api_permissions.empty());
1229 EXPECT_TRUE(host_permissions.is_empty()); 1229 EXPECT_TRUE(host_permissions.is_empty());
1230 } 1230 }
1231 #endif 1231 #endif
1232 1232
1233 // Tests that the extension is disabled when permissions are missing from 1233 // Tests that the extension is disabled when permissions are missing from
1234 // the extension's granted permissions preferences. (This simulates updating 1234 // the extension's granted permissions preferences. (This simulates updating
1235 // the browser to a version which recognizes more permissions). 1235 // the browser to a version which recognizes more permissions).
1236 TEST_F(ExtensionsServiceTest, GrantedAPIAndHostPermissions) { 1236 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
1237 InitializeEmptyExtensionsService(); 1237 InitializeEmptyExtensionService();
1238 1238
1239 FilePath path; 1239 FilePath path;
1240 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 1240 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
1241 path = path.AppendASCII("extensions") 1241 path = path.AppendASCII("extensions")
1242 .AppendASCII("permissions") 1242 .AppendASCII("permissions")
1243 .AppendASCII("unknown"); 1243 .AppendASCII("unknown");
1244 1244
1245 ASSERT_TRUE(file_util::PathExists(path)); 1245 ASSERT_TRUE(file_util::PathExists(path));
1246 1246
1247 PackAndInstallExtension(path, true); 1247 PackAndInstallExtension(path, true);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 &current_full_access, 1356 &current_full_access,
1357 &current_api_permissions, 1357 &current_api_permissions,
1358 &current_host_permissions)); 1358 &current_host_permissions));
1359 1359
1360 ASSERT_FALSE(current_full_access); 1360 ASSERT_FALSE(current_full_access);
1361 ASSERT_EQ(expected_api_permissions, current_api_permissions); 1361 ASSERT_EQ(expected_api_permissions, current_api_permissions);
1362 AssertEqualExtents(&expected_host_permissions, &current_host_permissions); 1362 AssertEqualExtents(&expected_host_permissions, &current_host_permissions);
1363 } 1363 }
1364 1364
1365 // Test Packaging and installing an extension. 1365 // Test Packaging and installing an extension.
1366 TEST_F(ExtensionsServiceTest, PackExtension) { 1366 TEST_F(ExtensionServiceTest, PackExtension) {
1367 InitializeEmptyExtensionsService(); 1367 InitializeEmptyExtensionService();
1368 FilePath extensions_path; 1368 FilePath extensions_path;
1369 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1369 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1370 extensions_path = extensions_path.AppendASCII("extensions"); 1370 extensions_path = extensions_path.AppendASCII("extensions");
1371 FilePath input_directory = extensions_path 1371 FilePath input_directory = extensions_path
1372 .AppendASCII("good") 1372 .AppendASCII("good")
1373 .AppendASCII("Extensions") 1373 .AppendASCII("Extensions")
1374 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 1374 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
1375 .AppendASCII("1.0.0.0"); 1375 .AppendASCII("1.0.0.0");
1376 1376
1377 ScopedTempDir temp_dir; 1377 ScopedTempDir temp_dir;
(...skipping 26 matching lines...) Expand all
1404 std::string invalid_manifest_content = "I am not a manifest."; 1404 std::string invalid_manifest_content = "I am not a manifest.";
1405 ASSERT_TRUE(file_util::WriteFile( 1405 ASSERT_TRUE(file_util::WriteFile(
1406 temp_dir2.path().Append(Extension::kManifestFilename), 1406 temp_dir2.path().Append(Extension::kManifestFilename),
1407 invalid_manifest_content.c_str(), invalid_manifest_content.size())); 1407 invalid_manifest_content.c_str(), invalid_manifest_content.size()));
1408 creator.reset(new ExtensionCreator()); 1408 creator.reset(new ExtensionCreator());
1409 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, 1409 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path,
1410 FilePath())); 1410 FilePath()));
1411 } 1411 }
1412 1412
1413 // Test Packaging and installing an extension whose name contains punctuation. 1413 // Test Packaging and installing an extension whose name contains punctuation.
1414 TEST_F(ExtensionsServiceTest, PackPunctuatedExtension) { 1414 TEST_F(ExtensionServiceTest, PackPunctuatedExtension) {
1415 InitializeEmptyExtensionsService(); 1415 InitializeEmptyExtensionService();
1416 FilePath extensions_path; 1416 FilePath extensions_path;
1417 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1417 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1418 extensions_path = extensions_path.AppendASCII("extensions"); 1418 extensions_path = extensions_path.AppendASCII("extensions");
1419 FilePath input_directory = extensions_path 1419 FilePath input_directory = extensions_path
1420 .AppendASCII("good") 1420 .AppendASCII("good")
1421 .AppendASCII("Extensions") 1421 .AppendASCII("Extensions")
1422 .AppendASCII(good0) 1422 .AppendASCII(good0)
1423 .AppendASCII("1.0.0.0"); 1423 .AppendASCII("1.0.0.0");
1424 1424
1425 ScopedTempDir temp_dir; 1425 ScopedTempDir temp_dir;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 InstallExtension(expected_crx_path, true); 1483 InstallExtension(expected_crx_path, true);
1484 } 1484 }
1485 } 1485 }
1486 1486
1487 // Test Packaging and installing an extension using an openssl generated key. 1487 // Test Packaging and installing an extension using an openssl generated key.
1488 // The openssl is generated with the following: 1488 // The openssl is generated with the following:
1489 // > openssl genrsa -out privkey.pem 1024 1489 // > openssl genrsa -out privkey.pem 1024
1490 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem 1490 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem
1491 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a 1491 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a
1492 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. 1492 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects.
1493 TEST_F(ExtensionsServiceTest, PackExtensionOpenSSLKey) { 1493 TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) {
1494 InitializeEmptyExtensionsService(); 1494 InitializeEmptyExtensionService();
1495 FilePath extensions_path; 1495 FilePath extensions_path;
1496 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1496 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1497 extensions_path = extensions_path.AppendASCII("extensions"); 1497 extensions_path = extensions_path.AppendASCII("extensions");
1498 FilePath input_directory = extensions_path 1498 FilePath input_directory = extensions_path
1499 .AppendASCII("good") 1499 .AppendASCII("good")
1500 .AppendASCII("Extensions") 1500 .AppendASCII("Extensions")
1501 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 1501 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
1502 .AppendASCII("1.0.0.0"); 1502 .AppendASCII("1.0.0.0");
1503 FilePath privkey_path(extensions_path.AppendASCII( 1503 FilePath privkey_path(extensions_path.AppendASCII(
1504 "openssl_privkey_asn1.pem")); 1504 "openssl_privkey_asn1.pem"));
1505 ASSERT_TRUE(file_util::PathExists(privkey_path)); 1505 ASSERT_TRUE(file_util::PathExists(privkey_path));
1506 1506
1507 ScopedTempDir temp_dir; 1507 ScopedTempDir temp_dir;
1508 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1508 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1509 FilePath output_directory = temp_dir.path(); 1509 FilePath output_directory = temp_dir.path();
1510 1510
1511 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); 1511 FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
1512 1512
1513 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); 1513 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
1514 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, 1514 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path,
1515 FilePath())); 1515 FilePath()));
1516 1516
1517 InstallExtension(crx_path, true); 1517 InstallExtension(crx_path, true);
1518 } 1518 }
1519 1519
1520 TEST_F(ExtensionsServiceTest, InstallTheme) { 1520 TEST_F(ExtensionServiceTest, InstallTheme) {
1521 InitializeEmptyExtensionsService(); 1521 InitializeEmptyExtensionService();
1522 FilePath extensions_path; 1522 FilePath extensions_path;
1523 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1523 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1524 extensions_path = extensions_path.AppendASCII("extensions"); 1524 extensions_path = extensions_path.AppendASCII("extensions");
1525 1525
1526 // A theme. 1526 // A theme.
1527 FilePath path = extensions_path.AppendASCII("theme.crx"); 1527 FilePath path = extensions_path.AppendASCII("theme.crx");
1528 InstallExtension(path, true); 1528 InstallExtension(path, true);
1529 int pref_count = 0; 1529 int pref_count = 0;
1530 ValidatePrefKeyCount(++pref_count); 1530 ValidatePrefKeyCount(++pref_count);
1531 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); 1531 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED);
(...skipping 14 matching lines...) Expand all
1546 path = extensions_path.AppendASCII("theme_with_extension.crx"); 1546 path = extensions_path.AppendASCII("theme_with_extension.crx");
1547 InstallExtension(path, false); 1547 InstallExtension(path, false);
1548 ValidatePrefKeyCount(pref_count); 1548 ValidatePrefKeyCount(pref_count);
1549 1549
1550 // A theme with image resources missing (misspelt path). 1550 // A theme with image resources missing (misspelt path).
1551 path = extensions_path.AppendASCII("theme_missing_image.crx"); 1551 path = extensions_path.AppendASCII("theme_missing_image.crx");
1552 InstallExtension(path, false); 1552 InstallExtension(path, false);
1553 ValidatePrefKeyCount(pref_count); 1553 ValidatePrefKeyCount(pref_count);
1554 } 1554 }
1555 1555
1556 TEST_F(ExtensionsServiceTest, LoadLocalizedTheme) { 1556 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) {
1557 // Load. 1557 // Load.
1558 InitializeEmptyExtensionsService(); 1558 InitializeEmptyExtensionService();
1559 FilePath extension_path; 1559 FilePath extension_path;
1560 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extension_path)); 1560 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extension_path));
1561 extension_path = extension_path 1561 extension_path = extension_path
1562 .AppendASCII("extensions") 1562 .AppendASCII("extensions")
1563 .AppendASCII("theme_i18n"); 1563 .AppendASCII("theme_i18n");
1564 1564
1565 service_->LoadExtension(extension_path); 1565 service_->LoadExtension(extension_path);
1566 loop_.RunAllPending(); 1566 loop_.RunAllPending();
1567 EXPECT_EQ(0u, GetErrors().size()); 1567 EXPECT_EQ(0u, GetErrors().size());
1568 ASSERT_EQ(1u, loaded_.size()); 1568 ASSERT_EQ(1u, loaded_.size());
1569 EXPECT_EQ(1u, service_->extensions()->size()); 1569 EXPECT_EQ(1u, service_->extensions()->size());
1570 EXPECT_EQ("name", service_->extensions()->at(0)->name()); 1570 EXPECT_EQ("name", service_->extensions()->at(0)->name());
1571 EXPECT_EQ("description", service_->extensions()->at(0)->description()); 1571 EXPECT_EQ("description", service_->extensions()->at(0)->description());
1572 } 1572 }
1573 1573
1574 TEST_F(ExtensionsServiceTest, InstallLocalizedTheme) { 1574 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) {
1575 InitializeEmptyExtensionsService(); 1575 InitializeEmptyExtensionService();
1576 FilePath theme_path; 1576 FilePath theme_path;
1577 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &theme_path)); 1577 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &theme_path));
1578 theme_path = theme_path 1578 theme_path = theme_path
1579 .AppendASCII("extensions") 1579 .AppendASCII("extensions")
1580 .AppendASCII("theme_i18n"); 1580 .AppendASCII("theme_i18n");
1581 1581
1582 PackAndInstallExtension(theme_path, true); 1582 PackAndInstallExtension(theme_path, true);
1583 1583
1584 EXPECT_EQ(0u, GetErrors().size()); 1584 EXPECT_EQ(0u, GetErrors().size());
1585 EXPECT_EQ(1u, service_->extensions()->size()); 1585 EXPECT_EQ(1u, service_->extensions()->size());
1586 EXPECT_EQ("name", service_->extensions()->at(0)->name()); 1586 EXPECT_EQ("name", service_->extensions()->at(0)->name());
1587 EXPECT_EQ("description", service_->extensions()->at(0)->description()); 1587 EXPECT_EQ("description", service_->extensions()->at(0)->description());
1588 } 1588 }
1589 1589
1590 TEST_F(ExtensionsServiceTest, InstallApps) { 1590 TEST_F(ExtensionServiceTest, InstallApps) {
1591 InitializeEmptyExtensionsService(); 1591 InitializeEmptyExtensionService();
1592 FilePath extensions_path; 1592 FilePath extensions_path;
1593 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1593 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1594 extensions_path = extensions_path.AppendASCII("extensions"); 1594 extensions_path = extensions_path.AppendASCII("extensions");
1595 1595
1596 // An empty app. 1596 // An empty app.
1597 PackAndInstallExtension(extensions_path.AppendASCII("app1"), true); 1597 PackAndInstallExtension(extensions_path.AppendASCII("app1"), true);
1598 int pref_count = 0; 1598 int pref_count = 0;
1599 ValidatePrefKeyCount(++pref_count); 1599 ValidatePrefKeyCount(++pref_count);
1600 ASSERT_EQ(1u, service_->extensions()->size()); 1600 ASSERT_EQ(1u, service_->extensions()->size());
1601 std::string id = service_->extensions()->at(0)->id(); 1601 std::string id = service_->extensions()->at(0)->id();
1602 ValidateIntegerPref(id, "state", Extension::ENABLED); 1602 ValidateIntegerPref(id, "state", Extension::ENABLED);
1603 ValidateIntegerPref(id, "location", Extension::INTERNAL); 1603 ValidateIntegerPref(id, "location", Extension::INTERNAL);
1604 1604
1605 // Another app with non-overlapping extent. Should succeed. 1605 // Another app with non-overlapping extent. Should succeed.
1606 PackAndInstallExtension(extensions_path.AppendASCII("app2"), true); 1606 PackAndInstallExtension(extensions_path.AppendASCII("app2"), true);
1607 ValidatePrefKeyCount(++pref_count); 1607 ValidatePrefKeyCount(++pref_count);
1608 1608
1609 // A third app whose extent overlaps the first. Should fail. 1609 // A third app whose extent overlaps the first. Should fail.
1610 PackAndInstallExtension(extensions_path.AppendASCII("app3"), false); 1610 PackAndInstallExtension(extensions_path.AppendASCII("app3"), false);
1611 ValidatePrefKeyCount(pref_count); 1611 ValidatePrefKeyCount(pref_count);
1612 } 1612 }
1613 1613
1614 TEST_F(ExtensionsServiceTest, InstallAppsWithUnlimtedStorage) { 1614 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) {
1615 InitializeEmptyExtensionsService(); 1615 InitializeEmptyExtensionService();
1616 EXPECT_TRUE(service_->extensions()->empty()); 1616 EXPECT_TRUE(service_->extensions()->empty());
1617 EXPECT_TRUE(service_->unlimited_storage_map_.empty()); 1617 EXPECT_TRUE(service_->unlimited_storage_map_.empty());
1618 1618
1619 FilePath extensions_path; 1619 FilePath extensions_path;
1620 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1620 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1621 extensions_path = extensions_path.AppendASCII("extensions"); 1621 extensions_path = extensions_path.AppendASCII("extensions");
1622 int pref_count = 0; 1622 int pref_count = 0;
1623 ChromeAppCacheService* appcache_service = profile_->GetAppCacheService(); 1623 ChromeAppCacheService* appcache_service = profile_->GetAppCacheService();
1624 1624
1625 // Install app1 with unlimited storage. 1625 // Install app1 with unlimited storage.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 1664
1665 // Uninstall the other, unlimited storage should be revoked. 1665 // Uninstall the other, unlimited storage should be revoked.
1666 service_->UninstallExtension(id2, false); 1666 service_->UninstallExtension(id2, false);
1667 loop_.RunAllPending(); 1667 loop_.RunAllPending();
1668 EXPECT_EQ(0u, service_->extensions()->size()); 1668 EXPECT_EQ(0u, service_->extensions()->size());
1669 EXPECT_EQ(-1L, 1669 EXPECT_EQ(-1L,
1670 appcache_service->storage()->GetOriginQuotaInMemory(origin2)); 1670 appcache_service->storage()->GetOriginQuotaInMemory(origin2));
1671 EXPECT_TRUE(service_->unlimited_storage_map_.empty()); 1671 EXPECT_TRUE(service_->unlimited_storage_map_.empty());
1672 } 1672 }
1673 1673
1674 TEST_F(ExtensionsServiceTest, InstallAppsAndCheckStorageProtection) { 1674 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
1675 InitializeEmptyExtensionsService(); 1675 InitializeEmptyExtensionService();
1676 EXPECT_TRUE(service_->extensions()->empty()); 1676 EXPECT_TRUE(service_->extensions()->empty());
1677 EXPECT_TRUE(service_->protected_storage_map_.empty()); 1677 EXPECT_TRUE(service_->protected_storage_map_.empty());
1678 1678
1679 FilePath extensions_path; 1679 FilePath extensions_path;
1680 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1680 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1681 extensions_path = extensions_path.AppendASCII("extensions"); 1681 extensions_path = extensions_path.AppendASCII("extensions");
1682 int pref_count = 0; 1682 int pref_count = 0;
1683 1683
1684 PackAndInstallExtension(extensions_path.AppendASCII("app1"), true); 1684 PackAndInstallExtension(extensions_path.AppendASCII("app1"), true);
1685 ValidatePrefKeyCount(++pref_count); 1685 ValidatePrefKeyCount(++pref_count);
(...skipping 22 matching lines...) Expand all
1708 EXPECT_FALSE(service_->protected_storage_map_.empty()); 1708 EXPECT_FALSE(service_->protected_storage_map_.empty());
1709 1709
1710 service_->UninstallExtension(id2, false); 1710 service_->UninstallExtension(id2, false);
1711 loop_.RunAllPending(); 1711 loop_.RunAllPending();
1712 1712
1713 EXPECT_TRUE(service_->extensions()->empty()); 1713 EXPECT_TRUE(service_->extensions()->empty());
1714 EXPECT_TRUE(service_->protected_storage_map_.empty()); 1714 EXPECT_TRUE(service_->protected_storage_map_.empty());
1715 } 1715 }
1716 1716
1717 // Test that when an extension version is reinstalled, nothing happens. 1717 // Test that when an extension version is reinstalled, nothing happens.
1718 TEST_F(ExtensionsServiceTest, Reinstall) { 1718 TEST_F(ExtensionServiceTest, Reinstall) {
1719 InitializeEmptyExtensionsService(); 1719 InitializeEmptyExtensionService();
1720 FilePath extensions_path; 1720 FilePath extensions_path;
1721 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1721 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1722 extensions_path = extensions_path.AppendASCII("extensions"); 1722 extensions_path = extensions_path.AppendASCII("extensions");
1723 1723
1724 // A simple extension that should install without error. 1724 // A simple extension that should install without error.
1725 FilePath path = extensions_path.AppendASCII("good.crx"); 1725 FilePath path = extensions_path.AppendASCII("good.crx");
1726 service_->InstallExtension(path); 1726 service_->InstallExtension(path);
1727 loop_.RunAllPending(); 1727 loop_.RunAllPending();
1728 1728
1729 ASSERT_TRUE(installed_); 1729 ASSERT_TRUE(installed_);
(...skipping 13 matching lines...) Expand all
1743 1743
1744 ASSERT_TRUE(installed_); 1744 ASSERT_TRUE(installed_);
1745 ASSERT_EQ(1u, loaded_.size()); 1745 ASSERT_EQ(1u, loaded_.size());
1746 ASSERT_EQ(0u, GetErrors().size()); 1746 ASSERT_EQ(0u, GetErrors().size());
1747 ValidatePrefKeyCount(1); 1747 ValidatePrefKeyCount(1);
1748 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 1748 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
1749 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); 1749 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL);
1750 } 1750 }
1751 1751
1752 // Test upgrading a signed extension. 1752 // Test upgrading a signed extension.
1753 TEST_F(ExtensionsServiceTest, UpgradeSignedGood) { 1753 TEST_F(ExtensionServiceTest, UpgradeSignedGood) {
1754 InitializeEmptyExtensionsService(); 1754 InitializeEmptyExtensionService();
1755 FilePath extensions_path; 1755 FilePath extensions_path;
1756 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1756 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1757 extensions_path = extensions_path.AppendASCII("extensions"); 1757 extensions_path = extensions_path.AppendASCII("extensions");
1758 1758
1759 FilePath path = extensions_path.AppendASCII("good.crx"); 1759 FilePath path = extensions_path.AppendASCII("good.crx");
1760 service_->InstallExtension(path); 1760 service_->InstallExtension(path);
1761 loop_.RunAllPending(); 1761 loop_.RunAllPending();
1762 1762
1763 ASSERT_TRUE(installed_); 1763 ASSERT_TRUE(installed_);
1764 ASSERT_EQ(1u, loaded_.size()); 1764 ASSERT_EQ(1u, loaded_.size());
1765 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 1765 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
1766 ASSERT_EQ(0u, GetErrors().size()); 1766 ASSERT_EQ(0u, GetErrors().size());
1767 1767
1768 // Upgrade to version 2.0 1768 // Upgrade to version 2.0
1769 path = extensions_path.AppendASCII("good2.crx"); 1769 path = extensions_path.AppendASCII("good2.crx");
1770 service_->InstallExtension(path); 1770 service_->InstallExtension(path);
1771 loop_.RunAllPending(); 1771 loop_.RunAllPending();
1772 1772
1773 ASSERT_TRUE(installed_); 1773 ASSERT_TRUE(installed_);
1774 ASSERT_EQ(1u, loaded_.size()); 1774 ASSERT_EQ(1u, loaded_.size());
1775 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 1775 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
1776 ASSERT_EQ(0u, GetErrors().size()); 1776 ASSERT_EQ(0u, GetErrors().size());
1777 } 1777 }
1778 1778
1779 // Test upgrading a signed extension with a bad signature. 1779 // Test upgrading a signed extension with a bad signature.
1780 TEST_F(ExtensionsServiceTest, UpgradeSignedBad) { 1780 TEST_F(ExtensionServiceTest, UpgradeSignedBad) {
1781 InitializeEmptyExtensionsService(); 1781 InitializeEmptyExtensionService();
1782 FilePath extensions_path; 1782 FilePath extensions_path;
1783 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1783 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1784 extensions_path = extensions_path.AppendASCII("extensions"); 1784 extensions_path = extensions_path.AppendASCII("extensions");
1785 1785
1786 FilePath path = extensions_path.AppendASCII("good.crx"); 1786 FilePath path = extensions_path.AppendASCII("good.crx");
1787 service_->InstallExtension(path); 1787 service_->InstallExtension(path);
1788 loop_.RunAllPending(); 1788 loop_.RunAllPending();
1789 1789
1790 ASSERT_TRUE(installed_); 1790 ASSERT_TRUE(installed_);
1791 ASSERT_EQ(1u, loaded_.size()); 1791 ASSERT_EQ(1u, loaded_.size());
1792 ASSERT_EQ(0u, GetErrors().size()); 1792 ASSERT_EQ(0u, GetErrors().size());
1793 installed_ = NULL; 1793 installed_ = NULL;
1794 1794
1795 // Try upgrading with a bad signature. This should fail during the unpack, 1795 // Try upgrading with a bad signature. This should fail during the unpack,
1796 // because the key will not match the signature. 1796 // because the key will not match the signature.
1797 path = extensions_path.AppendASCII("good2_bad_signature.crx"); 1797 path = extensions_path.AppendASCII("good2_bad_signature.crx");
1798 service_->InstallExtension(path); 1798 service_->InstallExtension(path);
1799 loop_.RunAllPending(); 1799 loop_.RunAllPending();
1800 1800
1801 ASSERT_FALSE(installed_); 1801 ASSERT_FALSE(installed_);
1802 ASSERT_EQ(1u, loaded_.size()); 1802 ASSERT_EQ(1u, loaded_.size());
1803 ASSERT_EQ(1u, GetErrors().size()); 1803 ASSERT_EQ(1u, GetErrors().size());
1804 } 1804 }
1805 1805
1806 // Test a normal update via the UpdateExtension API 1806 // Test a normal update via the UpdateExtension API
1807 TEST_F(ExtensionsServiceTest, UpdateExtension) { 1807 TEST_F(ExtensionServiceTest, UpdateExtension) {
1808 InitializeEmptyExtensionsService(); 1808 InitializeEmptyExtensionService();
1809 FilePath extensions_path; 1809 FilePath extensions_path;
1810 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1810 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1811 extensions_path = extensions_path.AppendASCII("extensions"); 1811 extensions_path = extensions_path.AppendASCII("extensions");
1812 1812
1813 FilePath path = extensions_path.AppendASCII("good.crx"); 1813 FilePath path = extensions_path.AppendASCII("good.crx");
1814 1814
1815 InstallExtension(path, true); 1815 InstallExtension(path, true);
1816 const Extension* good = service_->extensions()->at(0); 1816 const Extension* good = service_->extensions()->at(0);
1817 ASSERT_EQ("1.0.0.0", good->VersionString()); 1817 ASSERT_EQ("1.0.0.0", good->VersionString());
1818 ASSERT_EQ(good_crx, good->id()); 1818 ASSERT_EQ(good_crx, good->id());
1819 1819
1820 path = extensions_path.AppendASCII("good2.crx"); 1820 path = extensions_path.AppendASCII("good2.crx");
1821 UpdateExtension(good_crx, path, ENABLED); 1821 UpdateExtension(good_crx, path, ENABLED);
1822 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 1822 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
1823 } 1823 }
1824 1824
1825 // Test updating a not-already-installed extension - this should fail 1825 // Test updating a not-already-installed extension - this should fail
1826 TEST_F(ExtensionsServiceTest, UpdateNotInstalledExtension) { 1826 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) {
1827 InitializeEmptyExtensionsService(); 1827 InitializeEmptyExtensionService();
1828 FilePath extensions_path; 1828 FilePath extensions_path;
1829 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1829 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1830 extensions_path = extensions_path.AppendASCII("extensions"); 1830 extensions_path = extensions_path.AppendASCII("extensions");
1831 1831
1832 FilePath path = extensions_path.AppendASCII("good.crx"); 1832 FilePath path = extensions_path.AppendASCII("good.crx");
1833 UpdateExtension(good_crx, path, UPDATED); 1833 UpdateExtension(good_crx, path, UPDATED);
1834 loop_.RunAllPending(); 1834 loop_.RunAllPending();
1835 1835
1836 ASSERT_EQ(0u, service_->extensions()->size()); 1836 ASSERT_EQ(0u, service_->extensions()->size());
1837 ASSERT_FALSE(installed_); 1837 ASSERT_FALSE(installed_);
1838 ASSERT_EQ(0u, loaded_.size()); 1838 ASSERT_EQ(0u, loaded_.size());
1839 } 1839 }
1840 1840
1841 // Makes sure you can't downgrade an extension via UpdateExtension 1841 // Makes sure you can't downgrade an extension via UpdateExtension
1842 TEST_F(ExtensionsServiceTest, UpdateWillNotDowngrade) { 1842 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) {
1843 InitializeEmptyExtensionsService(); 1843 InitializeEmptyExtensionService();
1844 FilePath extensions_path; 1844 FilePath extensions_path;
1845 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1845 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1846 extensions_path = extensions_path.AppendASCII("extensions"); 1846 extensions_path = extensions_path.AppendASCII("extensions");
1847 1847
1848 FilePath path = extensions_path.AppendASCII("good2.crx"); 1848 FilePath path = extensions_path.AppendASCII("good2.crx");
1849 1849
1850 InstallExtension(path, true); 1850 InstallExtension(path, true);
1851 const Extension* good = service_->extensions()->at(0); 1851 const Extension* good = service_->extensions()->at(0);
1852 ASSERT_EQ("1.0.0.1", good->VersionString()); 1852 ASSERT_EQ("1.0.0.1", good->VersionString());
1853 ASSERT_EQ(good_crx, good->id()); 1853 ASSERT_EQ(good_crx, good->id());
1854 1854
1855 // Change path from good2.crx -> good.crx 1855 // Change path from good2.crx -> good.crx
1856 path = extensions_path.AppendASCII("good.crx"); 1856 path = extensions_path.AppendASCII("good.crx");
1857 UpdateExtension(good_crx, path, FAILED); 1857 UpdateExtension(good_crx, path, FAILED);
1858 ASSERT_EQ("1.0.0.1", service_->extensions()->at(0)->VersionString()); 1858 ASSERT_EQ("1.0.0.1", service_->extensions()->at(0)->VersionString());
1859 } 1859 }
1860 1860
1861 // Make sure calling update with an identical version does nothing 1861 // Make sure calling update with an identical version does nothing
1862 TEST_F(ExtensionsServiceTest, UpdateToSameVersionIsNoop) { 1862 TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) {
1863 InitializeEmptyExtensionsService(); 1863 InitializeEmptyExtensionService();
1864 FilePath extensions_path; 1864 FilePath extensions_path;
1865 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1865 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1866 extensions_path = extensions_path.AppendASCII("extensions"); 1866 extensions_path = extensions_path.AppendASCII("extensions");
1867 1867
1868 FilePath path = extensions_path.AppendASCII("good.crx"); 1868 FilePath path = extensions_path.AppendASCII("good.crx");
1869 1869
1870 InstallExtension(path, true); 1870 InstallExtension(path, true);
1871 const Extension* good = service_->extensions()->at(0); 1871 const Extension* good = service_->extensions()->at(0);
1872 ASSERT_EQ(good_crx, good->id()); 1872 ASSERT_EQ(good_crx, good->id());
1873 UpdateExtension(good_crx, path, FAILED_SILENTLY); 1873 UpdateExtension(good_crx, path, FAILED_SILENTLY);
1874 } 1874 }
1875 1875
1876 // Tests that updating an extension does not clobber old state. 1876 // Tests that updating an extension does not clobber old state.
1877 TEST_F(ExtensionsServiceTest, UpdateExtensionPreservesState) { 1877 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) {
1878 InitializeEmptyExtensionsService(); 1878 InitializeEmptyExtensionService();
1879 FilePath extensions_path; 1879 FilePath extensions_path;
1880 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1880 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1881 extensions_path = extensions_path.AppendASCII("extensions"); 1881 extensions_path = extensions_path.AppendASCII("extensions");
1882 1882
1883 FilePath path = extensions_path.AppendASCII("good.crx"); 1883 FilePath path = extensions_path.AppendASCII("good.crx");
1884 1884
1885 InstallExtension(path, true); 1885 InstallExtension(path, true);
1886 const Extension* good = service_->extensions()->at(0); 1886 const Extension* good = service_->extensions()->at(0);
1887 ASSERT_EQ("1.0.0.0", good->VersionString()); 1887 ASSERT_EQ("1.0.0.0", good->VersionString());
1888 ASSERT_EQ(good_crx, good->id()); 1888 ASSERT_EQ(good_crx, good->id());
1889 1889
1890 // Disable it and allow it to run in incognito. These settings should carry 1890 // Disable it and allow it to run in incognito. These settings should carry
1891 // over to the updated version. 1891 // over to the updated version.
1892 service_->DisableExtension(good->id()); 1892 service_->DisableExtension(good->id());
1893 service_->SetIsIncognitoEnabled(good, true); 1893 service_->SetIsIncognitoEnabled(good, true);
1894 1894
1895 path = extensions_path.AppendASCII("good2.crx"); 1895 path = extensions_path.AppendASCII("good2.crx");
1896 UpdateExtension(good_crx, path, INSTALLED); 1896 UpdateExtension(good_crx, path, INSTALLED);
1897 ASSERT_EQ(1u, service_->disabled_extensions()->size()); 1897 ASSERT_EQ(1u, service_->disabled_extensions()->size());
1898 const Extension* good2 = service_->disabled_extensions()->at(0); 1898 const Extension* good2 = service_->disabled_extensions()->at(0);
1899 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); 1899 ASSERT_EQ("1.0.0.1", good2->version()->GetString());
1900 EXPECT_TRUE(service_->IsIncognitoEnabled(good2)); 1900 EXPECT_TRUE(service_->IsIncognitoEnabled(good2));
1901 } 1901 }
1902 1902
1903 // Tests that updating preserves extension location. 1903 // Tests that updating preserves extension location.
1904 TEST_F(ExtensionsServiceTest, UpdateExtensionPreservesLocation) { 1904 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) {
1905 InitializeEmptyExtensionsService(); 1905 InitializeEmptyExtensionService();
1906 FilePath extensions_path; 1906 FilePath extensions_path;
1907 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1907 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1908 extensions_path = extensions_path.AppendASCII("extensions"); 1908 extensions_path = extensions_path.AppendASCII("extensions");
1909 1909
1910 FilePath path = extensions_path.AppendASCII("good.crx"); 1910 FilePath path = extensions_path.AppendASCII("good.crx");
1911 1911
1912 InstallExtension(path, true); 1912 InstallExtension(path, true);
1913 const Extension* good = service_->extensions()->at(0); 1913 const Extension* good = service_->extensions()->at(0);
1914 1914
1915 ASSERT_EQ("1.0.0.0", good->VersionString()); 1915 ASSERT_EQ("1.0.0.0", good->VersionString());
1916 ASSERT_EQ(good_crx, good->id()); 1916 ASSERT_EQ(good_crx, good->id());
1917 1917
1918 // Simulate non-internal location. 1918 // Simulate non-internal location.
1919 const_cast<Extension*>(good)->location_ = Extension::EXTERNAL_PREF; 1919 const_cast<Extension*>(good)->location_ = Extension::EXTERNAL_PREF;
1920 1920
1921 path = extensions_path.AppendASCII("good2.crx"); 1921 path = extensions_path.AppendASCII("good2.crx");
1922 UpdateExtension(good_crx, path, ENABLED); 1922 UpdateExtension(good_crx, path, ENABLED);
1923 const Extension* good2 = service_->extensions()->at(0); 1923 const Extension* good2 = service_->extensions()->at(0);
1924 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); 1924 ASSERT_EQ("1.0.0.1", good2->version()->GetString());
1925 EXPECT_EQ(good2->location(), Extension::EXTERNAL_PREF); 1925 EXPECT_EQ(good2->location(), Extension::EXTERNAL_PREF);
1926 } 1926 }
1927 1927
1928 // Makes sure that LOAD extension types can downgrade. 1928 // Makes sure that LOAD extension types can downgrade.
1929 TEST_F(ExtensionsServiceTest, LoadExtensionsCanDowngrade) { 1929 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) {
1930 InitializeEmptyExtensionsService(); 1930 InitializeEmptyExtensionService();
1931 1931
1932 ScopedTempDir temp; 1932 ScopedTempDir temp;
1933 ASSERT_TRUE(temp.CreateUniqueTempDir()); 1933 ASSERT_TRUE(temp.CreateUniqueTempDir());
1934 1934
1935 // We'll write the extension manifest dynamically to a temporary path 1935 // We'll write the extension manifest dynamically to a temporary path
1936 // to make it easier to change the version number. 1936 // to make it easier to change the version number.
1937 FilePath extension_path = temp.path(); 1937 FilePath extension_path = temp.path();
1938 FilePath manifest_path = extension_path.Append(Extension::kManifestFilename); 1938 FilePath manifest_path = extension_path.Append(Extension::kManifestFilename);
1939 ASSERT_FALSE(file_util::PathExists(manifest_path)); 1939 ASSERT_FALSE(file_util::PathExists(manifest_path));
1940 1940
(...skipping 23 matching lines...) Expand all
1964 loop_.RunAllPending(); 1964 loop_.RunAllPending();
1965 1965
1966 EXPECT_EQ(0u, GetErrors().size()); 1966 EXPECT_EQ(0u, GetErrors().size());
1967 ASSERT_EQ(1u, loaded_.size()); 1967 ASSERT_EQ(1u, loaded_.size());
1968 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); 1968 EXPECT_EQ(Extension::LOAD, loaded_[0]->location());
1969 EXPECT_EQ(1u, service_->extensions()->size()); 1969 EXPECT_EQ(1u, service_->extensions()->size());
1970 EXPECT_EQ("1.0", loaded_[0]->VersionString()); 1970 EXPECT_EQ("1.0", loaded_[0]->VersionString());
1971 } 1971 }
1972 1972
1973 // Test adding a pending extension. 1973 // Test adding a pending extension.
1974 TEST_F(ExtensionsServiceTest, AddPendingExtension) { 1974 TEST_F(ExtensionServiceTest, AddPendingExtension) {
1975 InitializeEmptyExtensionsService(); 1975 InitializeEmptyExtensionService();
1976 1976
1977 const std::string kFakeId("fake-id"); 1977 const std::string kFakeId("fake-id");
1978 const GURL kFakeUpdateURL("http:://fake.update/url"); 1978 const GURL kFakeUpdateURL("http:://fake.update/url");
1979 const PendingExtensionInfo::ExpectedCrxType kFakeExpectedCrxType = 1979 const PendingExtensionInfo::ExpectedCrxType kFakeExpectedCrxType =
1980 PendingExtensionInfo::EXTENSION; 1980 PendingExtensionInfo::EXTENSION;
1981 const bool kFakeInstallSilently(true); 1981 const bool kFakeInstallSilently(true);
1982 const Extension::State kFakeInitialState(Extension::ENABLED); 1982 const Extension::State kFakeInitialState(Extension::ENABLED);
1983 const bool kFakeInitialIncognitoEnabled(false); 1983 const bool kFakeInitialIncognitoEnabled(false);
1984 1984
1985 service_->AddPendingExtensionFromSync( 1985 service_->AddPendingExtensionFromSync(
(...skipping 14 matching lines...) Expand all
2000 PendingExtensionInfo::THEME; 2000 PendingExtensionInfo::THEME;
2001 const PendingExtensionInfo::ExpectedCrxType kCrxTypeExtension = 2001 const PendingExtensionInfo::ExpectedCrxType kCrxTypeExtension =
2002 PendingExtensionInfo::EXTENSION; 2002 PendingExtensionInfo::EXTENSION;
2003 const bool kGoodIsFromSync = true; 2003 const bool kGoodIsFromSync = true;
2004 const bool kGoodInstallSilently = true; 2004 const bool kGoodInstallSilently = true;
2005 const Extension::State kGoodInitialState = Extension::DISABLED; 2005 const Extension::State kGoodInitialState = Extension::DISABLED;
2006 const bool kGoodInitialIncognitoEnabled = true; 2006 const bool kGoodInitialIncognitoEnabled = true;
2007 } // namespace 2007 } // namespace
2008 2008
2009 // Test updating a pending extension. 2009 // Test updating a pending extension.
2010 TEST_F(ExtensionsServiceTest, UpdatePendingExtension) { 2010 TEST_F(ExtensionServiceTest, UpdatePendingExtension) {
2011 InitializeEmptyExtensionsService(); 2011 InitializeEmptyExtensionService();
2012 service_->AddPendingExtensionFromSync( 2012 service_->AddPendingExtensionFromSync(
2013 kGoodId, GURL(kGoodUpdateURL), kCrxTypeExtension, 2013 kGoodId, GURL(kGoodUpdateURL), kCrxTypeExtension,
2014 kGoodInstallSilently, kGoodInitialState, 2014 kGoodInstallSilently, kGoodInitialState,
2015 kGoodInitialIncognitoEnabled); 2015 kGoodInitialIncognitoEnabled);
2016 EXPECT_TRUE(ContainsKey(service_->pending_extensions(), kGoodId)); 2016 EXPECT_TRUE(ContainsKey(service_->pending_extensions(), kGoodId));
2017 2017
2018 FilePath extensions_path; 2018 FilePath extensions_path;
2019 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2019 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2020 extensions_path = extensions_path.AppendASCII("extensions"); 2020 extensions_path = extensions_path.AppendASCII("extensions");
2021 FilePath path = extensions_path.AppendASCII("good.crx"); 2021 FilePath path = extensions_path.AppendASCII("good.crx");
2022 UpdateExtension(kGoodId, path, INSTALLED); 2022 UpdateExtension(kGoodId, path, INSTALLED);
2023 2023
2024 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), kGoodId)); 2024 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), kGoodId));
2025 2025
2026 const Extension* extension = service_->GetExtensionById(kGoodId, true); 2026 const Extension* extension = service_->GetExtensionById(kGoodId, true);
2027 ASSERT_TRUE(extension); 2027 ASSERT_TRUE(extension);
2028 2028
2029 bool enabled = service_->GetExtensionById(kGoodId, false); 2029 bool enabled = service_->GetExtensionById(kGoodId, false);
2030 EXPECT_EQ(kGoodInitialState == Extension::ENABLED, enabled); 2030 EXPECT_EQ(kGoodInitialState == Extension::ENABLED, enabled);
2031 EXPECT_EQ(kGoodInitialState, 2031 EXPECT_EQ(kGoodInitialState,
2032 service_->extension_prefs()->GetExtensionState(extension->id())); 2032 service_->extension_prefs()->GetExtensionState(extension->id()));
2033 EXPECT_EQ(kGoodInitialIncognitoEnabled, 2033 EXPECT_EQ(kGoodInitialIncognitoEnabled,
2034 service_->IsIncognitoEnabled(extension)); 2034 service_->IsIncognitoEnabled(extension));
2035 } 2035 }
2036 2036
2037 // Test updating a pending theme. 2037 // Test updating a pending theme.
2038 TEST_F(ExtensionsServiceTest, UpdatePendingTheme) { 2038 TEST_F(ExtensionServiceTest, UpdatePendingTheme) {
2039 InitializeEmptyExtensionsService(); 2039 InitializeEmptyExtensionService();
2040 service_->AddPendingExtensionFromSync( 2040 service_->AddPendingExtensionFromSync(
2041 theme_crx, GURL(), PendingExtensionInfo::THEME, 2041 theme_crx, GURL(), PendingExtensionInfo::THEME,
2042 false, Extension::ENABLED, false); 2042 false, Extension::ENABLED, false);
2043 EXPECT_TRUE(ContainsKey(service_->pending_extensions(), theme_crx)); 2043 EXPECT_TRUE(ContainsKey(service_->pending_extensions(), theme_crx));
2044 2044
2045 FilePath extensions_path; 2045 FilePath extensions_path;
2046 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2046 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2047 extensions_path = extensions_path.AppendASCII("extensions"); 2047 extensions_path = extensions_path.AppendASCII("extensions");
2048 FilePath path = extensions_path.AppendASCII("theme.crx"); 2048 FilePath path = extensions_path.AppendASCII("theme.crx");
2049 UpdateExtension(theme_crx, path, ENABLED); 2049 UpdateExtension(theme_crx, path, ENABLED);
2050 2050
2051 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), theme_crx)); 2051 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), theme_crx));
2052 2052
2053 const Extension* extension = service_->GetExtensionById(theme_crx, true); 2053 const Extension* extension = service_->GetExtensionById(theme_crx, true);
2054 ASSERT_TRUE(extension); 2054 ASSERT_TRUE(extension);
2055 2055
2056 EXPECT_EQ(Extension::ENABLED, 2056 EXPECT_EQ(Extension::ENABLED,
2057 service_->extension_prefs()->GetExtensionState(extension->id())); 2057 service_->extension_prefs()->GetExtensionState(extension->id()));
2058 EXPECT_FALSE(service_->IsIncognitoEnabled(extension)); 2058 EXPECT_FALSE(service_->IsIncognitoEnabled(extension));
2059 } 2059 }
2060 2060
2061 // Test updating a pending CRX as if the source is an external extension 2061 // Test updating a pending CRX as if the source is an external extension
2062 // with an update URL. In this case we don't know if the CRX is a theme 2062 // with an update URL. In this case we don't know if the CRX is a theme
2063 // or not. 2063 // or not.
2064 TEST_F(ExtensionsServiceTest, UpdatePendingExternalCrx) { 2064 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrx) {
2065 InitializeEmptyExtensionsService(); 2065 InitializeEmptyExtensionService();
2066 service_->AddPendingExtensionFromExternalUpdateUrl( 2066 service_->AddPendingExtensionFromExternalUpdateUrl(
2067 theme_crx, GURL(), Extension::EXTERNAL_PREF_DOWNLOAD); 2067 theme_crx, GURL(), Extension::EXTERNAL_PREF_DOWNLOAD);
2068 2068
2069 EXPECT_TRUE(ContainsKey(service_->pending_extensions(), theme_crx)); 2069 EXPECT_TRUE(ContainsKey(service_->pending_extensions(), theme_crx));
2070 2070
2071 FilePath extensions_path; 2071 FilePath extensions_path;
2072 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2072 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2073 extensions_path = extensions_path.AppendASCII("extensions"); 2073 extensions_path = extensions_path.AppendASCII("extensions");
2074 FilePath path = extensions_path.AppendASCII("theme.crx"); 2074 FilePath path = extensions_path.AppendASCII("theme.crx");
2075 UpdateExtension(theme_crx, path, ENABLED); 2075 UpdateExtension(theme_crx, path, ENABLED);
2076 2076
2077 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), theme_crx)); 2077 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), theme_crx));
2078 2078
2079 const Extension* extension = service_->GetExtensionById(theme_crx, true); 2079 const Extension* extension = service_->GetExtensionById(theme_crx, true);
2080 ASSERT_TRUE(extension); 2080 ASSERT_TRUE(extension);
2081 2081
2082 EXPECT_EQ(Extension::ENABLED, 2082 EXPECT_EQ(Extension::ENABLED,
2083 service_->extension_prefs()->GetExtensionState(extension->id())); 2083 service_->extension_prefs()->GetExtensionState(extension->id()));
2084 EXPECT_FALSE(service_->IsIncognitoEnabled(extension)); 2084 EXPECT_FALSE(service_->IsIncognitoEnabled(extension));
2085 } 2085 }
2086 2086
2087 // Test updating a pending CRX as if the source is an external extension 2087 // Test updating a pending CRX as if the source is an external extension
2088 // with an update URL. The external update should overwrite a sync update, 2088 // with an update URL. The external update should overwrite a sync update,
2089 // but a sync update should not overwrite a non-sync update. 2089 // but a sync update should not overwrite a non-sync update.
2090 TEST_F(ExtensionsServiceTest, UpdatePendingExternalCrxWinsOverSync) { 2090 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) {
2091 InitializeEmptyExtensionsService(); 2091 InitializeEmptyExtensionService();
2092 2092
2093 // Add a crx to be installed from the update mechanism. 2093 // Add a crx to be installed from the update mechanism.
2094 service_->AddPendingExtensionFromSync( 2094 service_->AddPendingExtensionFromSync(
2095 kGoodId, GURL(kGoodUpdateURL), kCrxTypeExtension, 2095 kGoodId, GURL(kGoodUpdateURL), kCrxTypeExtension,
2096 kGoodInstallSilently, kGoodInitialState, 2096 kGoodInstallSilently, kGoodInitialState,
2097 kGoodInitialIncognitoEnabled); 2097 kGoodInitialIncognitoEnabled);
2098 2098
2099 // Check that there is a pending crx, with is_from_sync set to true. 2099 // Check that there is a pending crx, with is_from_sync set to true.
2100 PendingExtensionMap::const_iterator it; 2100 PendingExtensionMap::const_iterator it;
2101 it = service_->pending_extensions().find(kGoodId); 2101 it = service_->pending_extensions().find(kGoodId);
(...skipping 16 matching lines...) Expand all
2118 kGoodInitialIncognitoEnabled); 2118 kGoodInitialIncognitoEnabled);
2119 2119
2120 // Check that the external, non-sync update was not overridden. 2120 // Check that the external, non-sync update was not overridden.
2121 it = service_->pending_extensions().find(kGoodId); 2121 it = service_->pending_extensions().find(kGoodId);
2122 ASSERT_TRUE(it != service_->pending_extensions().end()); 2122 ASSERT_TRUE(it != service_->pending_extensions().end());
2123 EXPECT_FALSE(it->second.is_from_sync); 2123 EXPECT_FALSE(it->second.is_from_sync);
2124 } 2124 }
2125 2125
2126 // Updating a theme should fail if the updater is explicitly told that 2126 // Updating a theme should fail if the updater is explicitly told that
2127 // the CRX is not a theme. 2127 // the CRX is not a theme.
2128 TEST_F(ExtensionsServiceTest, UpdatePendingCrxThemeMismatch) { 2128 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) {
2129 InitializeEmptyExtensionsService(); 2129 InitializeEmptyExtensionService();
2130 service_->AddPendingExtensionFromSync( 2130 service_->AddPendingExtensionFromSync(
2131 theme_crx, GURL(), 2131 theme_crx, GURL(),
2132 PendingExtensionInfo::EXTENSION, 2132 PendingExtensionInfo::EXTENSION,
2133 true, Extension::ENABLED, false); 2133 true, Extension::ENABLED, false);
2134 2134
2135 EXPECT_TRUE(ContainsKey(service_->pending_extensions(), theme_crx)); 2135 EXPECT_TRUE(ContainsKey(service_->pending_extensions(), theme_crx));
2136 2136
2137 FilePath extensions_path; 2137 FilePath extensions_path;
2138 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2138 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2139 extensions_path = extensions_path.AppendASCII("extensions"); 2139 extensions_path = extensions_path.AppendASCII("extensions");
2140 FilePath path = extensions_path.AppendASCII("theme.crx"); 2140 FilePath path = extensions_path.AppendASCII("theme.crx");
2141 UpdateExtension(theme_crx, path, FAILED_SILENTLY); 2141 UpdateExtension(theme_crx, path, FAILED_SILENTLY);
2142 2142
2143 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), theme_crx)); 2143 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), theme_crx));
2144 2144
2145 const Extension* extension = service_->GetExtensionById(theme_crx, true); 2145 const Extension* extension = service_->GetExtensionById(theme_crx, true);
2146 ASSERT_FALSE(extension); 2146 ASSERT_FALSE(extension);
2147 } 2147 }
2148 2148
2149 // TODO(akalin): Test updating a pending extension non-silently once 2149 // TODO(akalin): Test updating a pending extension non-silently once
2150 // we can mock out ExtensionInstallUI and inject our version into 2150 // we can mock out ExtensionInstallUI and inject our version into
2151 // UpdateExtension(). 2151 // UpdateExtension().
2152 2152
2153 // Test updating a pending extension with wrong is_theme. 2153 // Test updating a pending extension with wrong is_theme.
2154 TEST_F(ExtensionsServiceTest, UpdatePendingExtensionWrongIsTheme) { 2154 TEST_F(ExtensionServiceTest, UpdatePendingExtensionWrongIsTheme) {
2155 InitializeEmptyExtensionsService(); 2155 InitializeEmptyExtensionService();
2156 // Add pending extension with a flipped is_theme. 2156 // Add pending extension with a flipped is_theme.
2157 service_->AddPendingExtensionFromSync( 2157 service_->AddPendingExtensionFromSync(
2158 kGoodId, GURL(kGoodUpdateURL), 2158 kGoodId, GURL(kGoodUpdateURL),
2159 kCrxTypeTheme, kGoodInstallSilently, kGoodInitialState, 2159 kCrxTypeTheme, kGoodInstallSilently, kGoodInitialState,
2160 kGoodInitialIncognitoEnabled); 2160 kGoodInitialIncognitoEnabled);
2161 EXPECT_TRUE(ContainsKey(service_->pending_extensions(), kGoodId)); 2161 EXPECT_TRUE(ContainsKey(service_->pending_extensions(), kGoodId));
2162 2162
2163 FilePath extensions_path; 2163 FilePath extensions_path;
2164 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2164 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2165 extensions_path = extensions_path.AppendASCII("extensions"); 2165 extensions_path = extensions_path.AppendASCII("extensions");
2166 FilePath path = extensions_path.AppendASCII("good.crx"); 2166 FilePath path = extensions_path.AppendASCII("good.crx");
2167 UpdateExtension(kGoodId, path, UPDATED); 2167 UpdateExtension(kGoodId, path, UPDATED);
2168 2168
2169 // TODO(akalin): Figure out how to check that the extensions 2169 // TODO(akalin): Figure out how to check that the extensions
2170 // directory is cleaned up properly in OnExtensionInstalled(). 2170 // directory is cleaned up properly in OnExtensionInstalled().
2171 2171
2172 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), kGoodId)); 2172 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), kGoodId));
2173 } 2173 }
2174 2174
2175 // TODO(akalin): Figure out how to test that installs of pending 2175 // TODO(akalin): Figure out how to test that installs of pending
2176 // unsyncable extensions are blocked. 2176 // unsyncable extensions are blocked.
2177 2177
2178 // Test updating a pending extension for one that is not pending. 2178 // Test updating a pending extension for one that is not pending.
2179 TEST_F(ExtensionsServiceTest, UpdatePendingExtensionNotPending) { 2179 TEST_F(ExtensionServiceTest, UpdatePendingExtensionNotPending) {
2180 InitializeEmptyExtensionsService(); 2180 InitializeEmptyExtensionService();
2181 2181
2182 FilePath extensions_path; 2182 FilePath extensions_path;
2183 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2183 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2184 extensions_path = extensions_path.AppendASCII("extensions"); 2184 extensions_path = extensions_path.AppendASCII("extensions");
2185 FilePath path = extensions_path.AppendASCII("good.crx"); 2185 FilePath path = extensions_path.AppendASCII("good.crx");
2186 UpdateExtension(kGoodId, path, UPDATED); 2186 UpdateExtension(kGoodId, path, UPDATED);
2187 2187
2188 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), kGoodId)); 2188 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), kGoodId));
2189 } 2189 }
2190 2190
2191 // Test updating a pending extension for one that is already 2191 // Test updating a pending extension for one that is already
2192 // installed. 2192 // installed.
2193 TEST_F(ExtensionsServiceTest, UpdatePendingExtensionAlreadyInstalled) { 2193 TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) {
2194 InitializeEmptyExtensionsService(); 2194 InitializeEmptyExtensionService();
2195 2195
2196 FilePath extensions_path; 2196 FilePath extensions_path;
2197 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2197 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2198 extensions_path = extensions_path.AppendASCII("extensions"); 2198 extensions_path = extensions_path.AppendASCII("extensions");
2199 FilePath path = extensions_path.AppendASCII("good.crx"); 2199 FilePath path = extensions_path.AppendASCII("good.crx");
2200 InstallExtension(path, true); 2200 InstallExtension(path, true);
2201 ASSERT_EQ(1u, service_->extensions()->size()); 2201 ASSERT_EQ(1u, service_->extensions()->size());
2202 const Extension* good = service_->extensions()->at(0); 2202 const Extension* good = service_->extensions()->at(0);
2203 2203
2204 EXPECT_FALSE(good->is_theme()); 2204 EXPECT_FALSE(good->is_theme());
2205 2205
2206 // Use AddPendingExtensionInternal() as AddPendingExtension() would 2206 // Use AddPendingExtensionInternal() as AddPendingExtension() would
2207 // balk. 2207 // balk.
2208 service_->AddPendingExtensionInternal( 2208 service_->AddPendingExtensionInternal(
2209 good->id(), good->update_url(), 2209 good->id(), good->update_url(),
2210 PendingExtensionInfo::EXTENSION, 2210 PendingExtensionInfo::EXTENSION,
2211 kGoodIsFromSync, kGoodInstallSilently, kGoodInitialState, 2211 kGoodIsFromSync, kGoodInstallSilently, kGoodInitialState,
2212 kGoodInitialIncognitoEnabled, Extension::INTERNAL); 2212 kGoodInitialIncognitoEnabled, Extension::INTERNAL);
2213 UpdateExtension(good->id(), path, INSTALLED); 2213 UpdateExtension(good->id(), path, INSTALLED);
2214 2214
2215 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), kGoodId)); 2215 EXPECT_FALSE(ContainsKey(service_->pending_extensions(), kGoodId));
2216 } 2216 }
2217 2217
2218 // Test pref settings for blacklist and unblacklist extensions. 2218 // Test pref settings for blacklist and unblacklist extensions.
2219 TEST_F(ExtensionsServiceTest, SetUnsetBlacklistInPrefs) { 2219 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) {
2220 InitializeEmptyExtensionsService(); 2220 InitializeEmptyExtensionService();
2221 std::vector<std::string> blacklist; 2221 std::vector<std::string> blacklist;
2222 blacklist.push_back(good0); 2222 blacklist.push_back(good0);
2223 blacklist.push_back("invalid_id"); // an invalid id 2223 blacklist.push_back("invalid_id"); // an invalid id
2224 blacklist.push_back(good1); 2224 blacklist.push_back(good1);
2225 service_->UpdateExtensionBlacklist(blacklist); 2225 service_->UpdateExtensionBlacklist(blacklist);
2226 // Make sure pref is updated 2226 // Make sure pref is updated
2227 loop_.RunAllPending(); 2227 loop_.RunAllPending();
2228 2228
2229 // blacklist is set for good0,1,2 2229 // blacklist is set for good0,1,2
2230 ValidateBooleanPref(good0, "blacklist", true); 2230 ValidateBooleanPref(good0, "blacklist", true);
2231 ValidateBooleanPref(good1, "blacklist", true); 2231 ValidateBooleanPref(good1, "blacklist", true);
2232 // invalid_id should not be inserted to pref. 2232 // invalid_id should not be inserted to pref.
2233 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); 2233 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist"));
2234 2234
2235 // remove good1, add good2 2235 // remove good1, add good2
2236 blacklist.pop_back(); 2236 blacklist.pop_back();
2237 blacklist.push_back(good2); 2237 blacklist.push_back(good2);
2238 2238
2239 service_->UpdateExtensionBlacklist(blacklist); 2239 service_->UpdateExtensionBlacklist(blacklist);
2240 // only good0 and good1 should be set 2240 // only good0 and good1 should be set
2241 ValidateBooleanPref(good0, "blacklist", true); 2241 ValidateBooleanPref(good0, "blacklist", true);
2242 EXPECT_FALSE(IsPrefExist(good1, "blacklist")); 2242 EXPECT_FALSE(IsPrefExist(good1, "blacklist"));
2243 ValidateBooleanPref(good2, "blacklist", true); 2243 ValidateBooleanPref(good2, "blacklist", true);
2244 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); 2244 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist"));
2245 } 2245 }
2246 2246
2247 // Unload installed extension from blacklist. 2247 // Unload installed extension from blacklist.
2248 TEST_F(ExtensionsServiceTest, UnloadBlacklistedExtension) { 2248 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtension) {
2249 InitializeEmptyExtensionsService(); 2249 InitializeEmptyExtensionService();
2250 FilePath extensions_path; 2250 FilePath extensions_path;
2251 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2251 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2252 extensions_path = extensions_path.AppendASCII("extensions"); 2252 extensions_path = extensions_path.AppendASCII("extensions");
2253 2253
2254 FilePath path = extensions_path.AppendASCII("good.crx"); 2254 FilePath path = extensions_path.AppendASCII("good.crx");
2255 2255
2256 InstallExtension(path, true); 2256 InstallExtension(path, true);
2257 const Extension* good = service_->extensions()->at(0); 2257 const Extension* good = service_->extensions()->at(0);
2258 EXPECT_EQ(good_crx, good->id()); 2258 EXPECT_EQ(good_crx, good->id());
2259 UpdateExtension(good_crx, path, FAILED_SILENTLY); 2259 UpdateExtension(good_crx, path, FAILED_SILENTLY);
(...skipping 11 matching lines...) Expand all
2271 // Remove good_crx from blacklist 2271 // Remove good_crx from blacklist
2272 blacklist.pop_back(); 2272 blacklist.pop_back();
2273 service_->UpdateExtensionBlacklist(blacklist); 2273 service_->UpdateExtensionBlacklist(blacklist);
2274 // Make sure pref is updated 2274 // Make sure pref is updated
2275 loop_.RunAllPending(); 2275 loop_.RunAllPending();
2276 // blacklist value should not be set for good_crx 2276 // blacklist value should not be set for good_crx
2277 EXPECT_FALSE(IsPrefExist(good_crx, "blacklist")); 2277 EXPECT_FALSE(IsPrefExist(good_crx, "blacklist"));
2278 } 2278 }
2279 2279
2280 // Unload installed extension from blacklist. 2280 // Unload installed extension from blacklist.
2281 TEST_F(ExtensionsServiceTest, BlacklistedExtensionWillNotInstall) { 2281 TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) {
2282 InitializeEmptyExtensionsService(); 2282 InitializeEmptyExtensionService();
2283 std::vector<std::string> blacklist; 2283 std::vector<std::string> blacklist;
2284 blacklist.push_back(good_crx); 2284 blacklist.push_back(good_crx);
2285 service_->UpdateExtensionBlacklist(blacklist); 2285 service_->UpdateExtensionBlacklist(blacklist);
2286 // Make sure pref is updated 2286 // Make sure pref is updated
2287 loop_.RunAllPending(); 2287 loop_.RunAllPending();
2288 2288
2289 // Now, the good_crx is blacklisted. 2289 // Now, the good_crx is blacklisted.
2290 ValidateBooleanPref(good_crx, "blacklist", true); 2290 ValidateBooleanPref(good_crx, "blacklist", true);
2291 2291
2292 // We can not install good_crx. 2292 // We can not install good_crx.
2293 FilePath extensions_path; 2293 FilePath extensions_path;
2294 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2294 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2295 extensions_path = extensions_path.AppendASCII("extensions"); 2295 extensions_path = extensions_path.AppendASCII("extensions");
2296 FilePath path = extensions_path.AppendASCII("good.crx"); 2296 FilePath path = extensions_path.AppendASCII("good.crx");
2297 service_->InstallExtension(path); 2297 service_->InstallExtension(path);
2298 loop_.RunAllPending(); 2298 loop_.RunAllPending();
2299 EXPECT_EQ(0u, service_->extensions()->size()); 2299 EXPECT_EQ(0u, service_->extensions()->size());
2300 ValidateBooleanPref(good_crx, "blacklist", true); 2300 ValidateBooleanPref(good_crx, "blacklist", true);
2301 } 2301 }
2302 2302
2303 // Test loading extensions from the profile directory, except 2303 // Test loading extensions from the profile directory, except
2304 // blacklisted ones. 2304 // blacklisted ones.
2305 TEST_F(ExtensionsServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { 2305 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) {
2306 // Initialize the test dir with a good Preferences/extensions. 2306 // Initialize the test dir with a good Preferences/extensions.
2307 FilePath source_install_dir; 2307 FilePath source_install_dir;
2308 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); 2308 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir));
2309 source_install_dir = source_install_dir 2309 source_install_dir = source_install_dir
2310 .AppendASCII("extensions") 2310 .AppendASCII("extensions")
2311 .AppendASCII("good") 2311 .AppendASCII("good")
2312 .AppendASCII("Extensions"); 2312 .AppendASCII("Extensions");
2313 FilePath pref_path = source_install_dir 2313 FilePath pref_path = source_install_dir
2314 .DirName() 2314 .DirName()
2315 .AppendASCII("Preferences"); 2315 .AppendASCII("Preferences");
2316 InitializeInstalledExtensionsService(pref_path, source_install_dir); 2316 InitializeInstalledExtensionService(pref_path, source_install_dir);
2317 2317
2318 // Blacklist good1. 2318 // Blacklist good1.
2319 std::vector<std::string> blacklist; 2319 std::vector<std::string> blacklist;
2320 blacklist.push_back(good1); 2320 blacklist.push_back(good1);
2321 service_->UpdateExtensionBlacklist(blacklist); 2321 service_->UpdateExtensionBlacklist(blacklist);
2322 // Make sure pref is updated 2322 // Make sure pref is updated
2323 loop_.RunAllPending(); 2323 loop_.RunAllPending();
2324 2324
2325 ValidateBooleanPref(good1, "blacklist", true); 2325 ValidateBooleanPref(good1, "blacklist", true);
2326 2326
2327 // Load extensions. 2327 // Load extensions.
2328 service_->Init(); 2328 service_->Init();
2329 loop_.RunAllPending(); 2329 loop_.RunAllPending();
2330 2330
2331 std::vector<std::string> errors = GetErrors(); 2331 std::vector<std::string> errors = GetErrors();
2332 for (std::vector<std::string>::iterator err = errors.begin(); 2332 for (std::vector<std::string>::iterator err = errors.begin();
2333 err != errors.end(); ++err) { 2333 err != errors.end(); ++err) {
2334 LOG(ERROR) << *err; 2334 LOG(ERROR) << *err;
2335 } 2335 }
2336 ASSERT_EQ(2u, loaded_.size()); 2336 ASSERT_EQ(2u, loaded_.size());
2337 2337
2338 EXPECT_NE(std::string(good1), loaded_[0]->id()); 2338 EXPECT_NE(std::string(good1), loaded_[0]->id());
2339 EXPECT_NE(std::string(good1), loaded_[1]->id()); 2339 EXPECT_NE(std::string(good1), loaded_[1]->id());
2340 } 2340 }
2341 2341
2342 #if defined(OS_CHROMEOS) 2342 #if defined(OS_CHROMEOS)
2343 // Test loading extensions from the profile directory, except 2343 // Test loading extensions from the profile directory, except
2344 // ones with a plugin. 2344 // ones with a plugin.
2345 TEST_F(ExtensionsServiceTest, WillNotLoadPluginExtensionsFromDirectory) { 2345 TEST_F(ExtensionServiceTest, WillNotLoadPluginExtensionsFromDirectory) {
2346 // Initialize the test dir with a good Preferences/extensions. 2346 // Initialize the test dir with a good Preferences/extensions.
2347 FilePath source_install_dir; 2347 FilePath source_install_dir;
2348 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); 2348 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir));
2349 source_install_dir = source_install_dir 2349 source_install_dir = source_install_dir
2350 .AppendASCII("extensions") 2350 .AppendASCII("extensions")
2351 .AppendASCII("good") 2351 .AppendASCII("good")
2352 .AppendASCII("Extensions"); 2352 .AppendASCII("Extensions");
2353 FilePath pref_path = source_install_dir 2353 FilePath pref_path = source_install_dir
2354 .DirName() 2354 .DirName()
2355 .AppendASCII("Preferences"); 2355 .AppendASCII("Preferences");
2356 InitializeInstalledExtensionsService(pref_path, source_install_dir); 2356 InitializeInstalledExtensionService(pref_path, source_install_dir);
2357 2357
2358 // good1 contains a plugin. 2358 // good1 contains a plugin.
2359 // Load extensions. 2359 // Load extensions.
2360 service_->Init(); 2360 service_->Init();
2361 loop_.RunAllPending(); 2361 loop_.RunAllPending();
2362 2362
2363 std::vector<std::string> errors = GetErrors(); 2363 std::vector<std::string> errors = GetErrors();
2364 for (std::vector<std::string>::iterator err = errors.begin(); 2364 for (std::vector<std::string>::iterator err = errors.begin();
2365 err != errors.end(); ++err) { 2365 err != errors.end(); ++err) {
2366 LOG(ERROR) << *err; 2366 LOG(ERROR) << *err;
2367 } 2367 }
2368 ASSERT_EQ(2u, loaded_.size()); 2368 ASSERT_EQ(2u, loaded_.size());
2369 2369
2370 EXPECT_NE(std::string(good1), loaded_[0]->id()); 2370 EXPECT_NE(std::string(good1), loaded_[0]->id());
2371 EXPECT_NE(std::string(good1), loaded_[1]->id()); 2371 EXPECT_NE(std::string(good1), loaded_[1]->id());
2372 } 2372 }
2373 #endif 2373 #endif
2374 2374
2375 // Will not install extension blacklisted by policy. 2375 // Will not install extension blacklisted by policy.
2376 TEST_F(ExtensionsServiceTest, BlacklistedByPolicyWillNotInstall) { 2376 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) {
2377 InitializeEmptyExtensionsService(); 2377 InitializeEmptyExtensionService();
2378 2378
2379 ListValue* whitelist = 2379 ListValue* whitelist =
2380 profile_->GetPrefs()->GetMutableList(prefs::kExtensionInstallAllowList); 2380 profile_->GetPrefs()->GetMutableList(prefs::kExtensionInstallAllowList);
2381 ListValue* blacklist = 2381 ListValue* blacklist =
2382 profile_->GetPrefs()->GetMutableList(prefs::kExtensionInstallDenyList); 2382 profile_->GetPrefs()->GetMutableList(prefs::kExtensionInstallDenyList);
2383 ASSERT_TRUE(whitelist != NULL && blacklist != NULL); 2383 ASSERT_TRUE(whitelist != NULL && blacklist != NULL);
2384 2384
2385 // Blacklist everything. 2385 // Blacklist everything.
2386 blacklist->Append(Value::CreateStringValue("*")); 2386 blacklist->Append(Value::CreateStringValue("*"));
2387 2387
2388 // Blacklist prevents us from installing good_crx. 2388 // Blacklist prevents us from installing good_crx.
2389 FilePath extensions_path; 2389 FilePath extensions_path;
2390 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2390 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2391 extensions_path = extensions_path.AppendASCII("extensions"); 2391 extensions_path = extensions_path.AppendASCII("extensions");
2392 FilePath path = extensions_path.AppendASCII("good.crx"); 2392 FilePath path = extensions_path.AppendASCII("good.crx");
2393 service_->InstallExtension(path); 2393 service_->InstallExtension(path);
2394 loop_.RunAllPending(); 2394 loop_.RunAllPending();
2395 EXPECT_EQ(0u, service_->extensions()->size()); 2395 EXPECT_EQ(0u, service_->extensions()->size());
2396 2396
2397 // Now whitelist this particular extension. 2397 // Now whitelist this particular extension.
2398 whitelist->Append(Value::CreateStringValue(good_crx)); 2398 whitelist->Append(Value::CreateStringValue(good_crx));
2399 2399
2400 // Ensure we can now install good_crx. 2400 // Ensure we can now install good_crx.
2401 service_->InstallExtension(path); 2401 service_->InstallExtension(path);
2402 loop_.RunAllPending(); 2402 loop_.RunAllPending();
2403 EXPECT_EQ(1u, service_->extensions()->size()); 2403 EXPECT_EQ(1u, service_->extensions()->size());
2404 } 2404 }
2405 2405
2406 // Extension blacklisted by policy get unloaded after installing. 2406 // Extension blacklisted by policy get unloaded after installing.
2407 TEST_F(ExtensionsServiceTest, BlacklistedByPolicyRemovedIfRunning) { 2407 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) {
2408 InitializeEmptyExtensionsService(); 2408 InitializeEmptyExtensionService();
2409 2409
2410 // Install good_crx. 2410 // Install good_crx.
2411 FilePath extensions_path; 2411 FilePath extensions_path;
2412 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2412 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2413 extensions_path = extensions_path.AppendASCII("extensions"); 2413 extensions_path = extensions_path.AppendASCII("extensions");
2414 FilePath path = extensions_path.AppendASCII("good.crx"); 2414 FilePath path = extensions_path.AppendASCII("good.crx");
2415 service_->InstallExtension(path); 2415 service_->InstallExtension(path);
2416 loop_.RunAllPending(); 2416 loop_.RunAllPending();
2417 EXPECT_EQ(1u, service_->extensions()->size()); 2417 EXPECT_EQ(1u, service_->extensions()->size());
2418 2418
2419 { // Scope for pref update notification. 2419 { // Scope for pref update notification.
2420 PrefService* prefs = profile_->GetPrefs(); 2420 PrefService* prefs = profile_->GetPrefs();
2421 ScopedPrefUpdate pref_update(prefs, prefs::kExtensionInstallDenyList); 2421 ScopedPrefUpdate pref_update(prefs, prefs::kExtensionInstallDenyList);
2422 ListValue* blacklist = 2422 ListValue* blacklist =
2423 prefs->GetMutableList(prefs::kExtensionInstallDenyList); 2423 prefs->GetMutableList(prefs::kExtensionInstallDenyList);
2424 ASSERT_TRUE(blacklist != NULL); 2424 ASSERT_TRUE(blacklist != NULL);
2425 2425
2426 // Blacklist this extension. 2426 // Blacklist this extension.
2427 blacklist->Append(Value::CreateStringValue(good_crx)); 2427 blacklist->Append(Value::CreateStringValue(good_crx));
2428 prefs->ScheduleSavePersistentPrefs(); 2428 prefs->ScheduleSavePersistentPrefs();
2429 } 2429 }
2430 2430
2431 // Extension should not be running now. 2431 // Extension should not be running now.
2432 loop_.RunAllPending(); 2432 loop_.RunAllPending();
2433 EXPECT_EQ(0u, service_->extensions()->size()); 2433 EXPECT_EQ(0u, service_->extensions()->size());
2434 } 2434 }
2435 2435
2436 // Tests disabling extensions 2436 // Tests disabling extensions
2437 TEST_F(ExtensionsServiceTest, DisableExtension) { 2437 TEST_F(ExtensionServiceTest, DisableExtension) {
2438 InitializeEmptyExtensionsService(); 2438 InitializeEmptyExtensionService();
2439 FilePath extensions_path; 2439 FilePath extensions_path;
2440 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2440 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2441 extensions_path = extensions_path.AppendASCII("extensions"); 2441 extensions_path = extensions_path.AppendASCII("extensions");
2442 2442
2443 // A simple extension that should install without error. 2443 // A simple extension that should install without error.
2444 FilePath path = extensions_path.AppendASCII("good.crx"); 2444 FilePath path = extensions_path.AppendASCII("good.crx");
2445 InstallExtension(path, true); 2445 InstallExtension(path, true);
2446 2446
2447 const char* extension_id = good_crx; 2447 const char* extension_id = good_crx;
2448 EXPECT_FALSE(service_->extensions()->empty()); 2448 EXPECT_FALSE(service_->extensions()->empty());
2449 EXPECT_TRUE(service_->GetExtensionById(extension_id, true) != NULL); 2449 EXPECT_TRUE(service_->GetExtensionById(extension_id, true) != NULL);
2450 EXPECT_TRUE(service_->GetExtensionById(extension_id, false) != NULL); 2450 EXPECT_TRUE(service_->GetExtensionById(extension_id, false) != NULL);
2451 EXPECT_TRUE(service_->disabled_extensions()->empty()); 2451 EXPECT_TRUE(service_->disabled_extensions()->empty());
2452 2452
2453 // Disable it. 2453 // Disable it.
2454 service_->DisableExtension(extension_id); 2454 service_->DisableExtension(extension_id);
2455 2455
2456 EXPECT_TRUE(service_->extensions()->empty()); 2456 EXPECT_TRUE(service_->extensions()->empty());
2457 EXPECT_TRUE(service_->GetExtensionById(extension_id, true) != NULL); 2457 EXPECT_TRUE(service_->GetExtensionById(extension_id, true) != NULL);
2458 EXPECT_FALSE(service_->GetExtensionById(extension_id, false) != NULL); 2458 EXPECT_FALSE(service_->GetExtensionById(extension_id, false) != NULL);
2459 EXPECT_FALSE(service_->disabled_extensions()->empty()); 2459 EXPECT_FALSE(service_->disabled_extensions()->empty());
2460 } 2460 }
2461 2461
2462 // Tests disabling all extensions (simulating --disable-extensions flag). 2462 // Tests disabling all extensions (simulating --disable-extensions flag).
2463 TEST_F(ExtensionsServiceTest, DisableAllExtensions) { 2463 TEST_F(ExtensionServiceTest, DisableAllExtensions) {
2464 InitializeEmptyExtensionsService(); 2464 InitializeEmptyExtensionService();
2465 2465
2466 FilePath extensions_path; 2466 FilePath extensions_path;
2467 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2467 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2468 extensions_path = extensions_path.AppendASCII("extensions"); 2468 extensions_path = extensions_path.AppendASCII("extensions");
2469 2469
2470 FilePath path = extensions_path.AppendASCII("good.crx"); 2470 FilePath path = extensions_path.AppendASCII("good.crx");
2471 InstallExtension(path, true); 2471 InstallExtension(path, true);
2472 2472
2473 EXPECT_EQ(1u, service_->extensions()->size()); 2473 EXPECT_EQ(1u, service_->extensions()->size());
2474 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 2474 EXPECT_EQ(0u, service_->disabled_extensions()->size());
(...skipping 16 matching lines...) Expand all
2491 2491
2492 // And then re-enable the extensions. 2492 // And then re-enable the extensions.
2493 service_->set_extensions_enabled(true); 2493 service_->set_extensions_enabled(true);
2494 service_->ReloadExtensions(); 2494 service_->ReloadExtensions();
2495 2495
2496 EXPECT_EQ(1u, service_->extensions()->size()); 2496 EXPECT_EQ(1u, service_->extensions()->size());
2497 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 2497 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2498 } 2498 }
2499 2499
2500 // Tests reloading extensions 2500 // Tests reloading extensions
2501 TEST_F(ExtensionsServiceTest, ReloadExtensions) { 2501 TEST_F(ExtensionServiceTest, ReloadExtensions) {
2502 InitializeEmptyExtensionsService(); 2502 InitializeEmptyExtensionService();
2503 FilePath extensions_path; 2503 FilePath extensions_path;
2504 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2504 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2505 extensions_path = extensions_path.AppendASCII("extensions"); 2505 extensions_path = extensions_path.AppendASCII("extensions");
2506 2506
2507 // Simple extension that should install without error. 2507 // Simple extension that should install without error.
2508 FilePath path = extensions_path.AppendASCII("good.crx"); 2508 FilePath path = extensions_path.AppendASCII("good.crx");
2509 InstallExtension(path, true); 2509 InstallExtension(path, true);
2510 const char* extension_id = good_crx; 2510 const char* extension_id = good_crx;
2511 service_->DisableExtension(extension_id); 2511 service_->DisableExtension(extension_id);
2512 2512
(...skipping 16 matching lines...) Expand all
2529 // UnloadAllExtensions() doesn't send out notifications. 2529 // UnloadAllExtensions() doesn't send out notifications.
2530 loaded_.clear(); 2530 loaded_.clear();
2531 service_->ReloadExtensions(); 2531 service_->ReloadExtensions();
2532 2532
2533 // Extension counts shouldn't change. 2533 // Extension counts shouldn't change.
2534 EXPECT_EQ(1u, service_->extensions()->size()); 2534 EXPECT_EQ(1u, service_->extensions()->size());
2535 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 2535 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2536 } 2536 }
2537 2537
2538 // Tests uninstalling normal extensions 2538 // Tests uninstalling normal extensions
2539 TEST_F(ExtensionsServiceTest, UninstallExtension) { 2539 TEST_F(ExtensionServiceTest, UninstallExtension) {
2540 InitializeEmptyExtensionsService(); 2540 InitializeEmptyExtensionService();
2541 FilePath extensions_path; 2541 FilePath extensions_path;
2542 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2542 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2543 extensions_path = extensions_path.AppendASCII("extensions"); 2543 extensions_path = extensions_path.AppendASCII("extensions");
2544 2544
2545 // A simple extension that should install without error. 2545 // A simple extension that should install without error.
2546 FilePath path = extensions_path.AppendASCII("good.crx"); 2546 FilePath path = extensions_path.AppendASCII("good.crx");
2547 InstallExtension(path, true); 2547 InstallExtension(path, true);
2548 2548
2549 // The directory should be there now. 2549 // The directory should be there now.
2550 const char* extension_id = good_crx; 2550 const char* extension_id = good_crx;
(...skipping 16 matching lines...) Expand all
2567 2567
2568 // The extension should not be in the service anymore. 2568 // The extension should not be in the service anymore.
2569 ASSERT_FALSE(service_->GetExtensionById(extension_id, false)); 2569 ASSERT_FALSE(service_->GetExtensionById(extension_id, false));
2570 loop_.RunAllPending(); 2570 loop_.RunAllPending();
2571 2571
2572 // The directory should be gone. 2572 // The directory should be gone.
2573 EXPECT_FALSE(file_util::PathExists(extension_path)); 2573 EXPECT_FALSE(file_util::PathExists(extension_path));
2574 } 2574 }
2575 2575
2576 // Tests the uninstaller helper. 2576 // Tests the uninstaller helper.
2577 TEST_F(ExtensionsServiceTest, UninstallExtensionHelper) { 2577 TEST_F(ExtensionServiceTest, UninstallExtensionHelper) {
2578 InitializeEmptyExtensionsService(); 2578 InitializeEmptyExtensionService();
2579 FilePath extensions_path; 2579 FilePath extensions_path;
2580 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2580 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2581 extensions_path = extensions_path.AppendASCII("extensions"); 2581 extensions_path = extensions_path.AppendASCII("extensions");
2582 2582
2583 // A simple extension that should install without error. 2583 // A simple extension that should install without error.
2584 FilePath path = extensions_path.AppendASCII("good.crx"); 2584 FilePath path = extensions_path.AppendASCII("good.crx");
2585 InstallExtension(path, true); 2585 InstallExtension(path, true);
2586 2586
2587 // The directory should be there now. 2587 // The directory should be there now.
2588 const char* extension_id = good_crx; 2588 const char* extension_id = good_crx;
2589 FilePath extension_path = extensions_install_dir_.AppendASCII(extension_id); 2589 FilePath extension_path = extensions_install_dir_.AppendASCII(extension_id);
2590 EXPECT_TRUE(file_util::PathExists(extension_path)); 2590 EXPECT_TRUE(file_util::PathExists(extension_path));
2591 2591
2592 bool result = ExtensionsService::UninstallExtensionHelper(service_, 2592 bool result = ExtensionService::UninstallExtensionHelper(service_,
2593 extension_id); 2593 extension_id);
2594 total_successes_ = 0; 2594 total_successes_ = 0;
2595 2595
2596 EXPECT_TRUE(result); 2596 EXPECT_TRUE(result);
2597 2597
2598 // We should get an unload notification. 2598 // We should get an unload notification.
2599 ASSERT_TRUE(unloaded_id_.length()); 2599 ASSERT_TRUE(unloaded_id_.length());
2600 EXPECT_EQ(extension_id, unloaded_id_); 2600 EXPECT_EQ(extension_id, unloaded_id_);
2601 2601
2602 ValidatePrefKeyCount(0); 2602 ValidatePrefKeyCount(0);
2603 2603
2604 // The extension should not be in the service anymore. 2604 // The extension should not be in the service anymore.
2605 ASSERT_FALSE(service_->GetExtensionById(extension_id, false)); 2605 ASSERT_FALSE(service_->GetExtensionById(extension_id, false));
2606 loop_.RunAllPending(); 2606 loop_.RunAllPending();
2607 2607
2608 // The directory should be gone. 2608 // The directory should be gone.
2609 EXPECT_FALSE(file_util::PathExists(extension_path)); 2609 EXPECT_FALSE(file_util::PathExists(extension_path));
2610 2610
2611 // Attempt to uninstall again. This should fail as we just removed the 2611 // Attempt to uninstall again. This should fail as we just removed the
2612 // extension. 2612 // extension.
2613 result = ExtensionsService::UninstallExtensionHelper(service_, extension_id); 2613 result = ExtensionService::UninstallExtensionHelper(service_, extension_id);
2614 EXPECT_FALSE(result); 2614 EXPECT_FALSE(result);
2615 } 2615 }
2616 2616
2617 // Verifies extension state is removed upon uninstall 2617 // Verifies extension state is removed upon uninstall
2618 TEST_F(ExtensionsServiceTest, ClearExtensionData) { 2618 TEST_F(ExtensionServiceTest, ClearExtensionData) {
2619 InitializeEmptyExtensionsService(); 2619 InitializeEmptyExtensionService();
2620 2620
2621 // Load a test extension. 2621 // Load a test extension.
2622 FilePath path; 2622 FilePath path;
2623 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 2623 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
2624 path = path.AppendASCII("extensions"); 2624 path = path.AppendASCII("extensions");
2625 path = path.AppendASCII("good.crx"); 2625 path = path.AppendASCII("good.crx");
2626 InstallExtension(path, true); 2626 InstallExtension(path, true);
2627 const Extension* extension = service_->GetExtensionById(good_crx, false); 2627 const Extension* extension = service_->GetExtensionById(good_crx, false);
2628 ASSERT_TRUE(extension); 2628 ASSERT_TRUE(extension);
2629 GURL ext_url(extension->url()); 2629 GURL ext_url(extension->url());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2685 EXPECT_EQ(0U, origins.size()); 2685 EXPECT_EQ(0U, origins.size());
2686 2686
2687 // Check that the LSO file has been removed. 2687 // Check that the LSO file has been removed.
2688 EXPECT_FALSE(file_util::PathExists(lso_path)); 2688 EXPECT_FALSE(file_util::PathExists(lso_path));
2689 2689
2690 // Check if the indexed db has disappeared too. 2690 // Check if the indexed db has disappeared too.
2691 EXPECT_FALSE(file_util::PathExists(idb_path)); 2691 EXPECT_FALSE(file_util::PathExists(idb_path));
2692 } 2692 }
2693 2693
2694 // Tests loading single extensions (like --load-extension) 2694 // Tests loading single extensions (like --load-extension)
2695 TEST_F(ExtensionsServiceTest, LoadExtension) { 2695 TEST_F(ExtensionServiceTest, LoadExtension) {
2696 InitializeEmptyExtensionsService(); 2696 InitializeEmptyExtensionService();
2697 FilePath extensions_path; 2697 FilePath extensions_path;
2698 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2698 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2699 extensions_path = extensions_path.AppendASCII("extensions"); 2699 extensions_path = extensions_path.AppendASCII("extensions");
2700 2700
2701 FilePath ext1 = extensions_path 2701 FilePath ext1 = extensions_path
2702 .AppendASCII("good") 2702 .AppendASCII("good")
2703 .AppendASCII("Extensions") 2703 .AppendASCII("Extensions")
2704 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 2704 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
2705 .AppendASCII("1.0.0.0"); 2705 .AppendASCII("1.0.0.0");
2706 service_->LoadExtension(ext1); 2706 service_->LoadExtension(ext1);
(...skipping 21 matching lines...) Expand all
2728 EXPECT_FALSE(unloaded_id_.length()); 2728 EXPECT_FALSE(unloaded_id_.length());
2729 service_->UninstallExtension(id, false); 2729 service_->UninstallExtension(id, false);
2730 loop_.RunAllPending(); 2730 loop_.RunAllPending();
2731 EXPECT_EQ(id, unloaded_id_); 2731 EXPECT_EQ(id, unloaded_id_);
2732 ASSERT_EQ(0u, loaded_.size()); 2732 ASSERT_EQ(0u, loaded_.size());
2733 EXPECT_EQ(0u, service_->extensions()->size()); 2733 EXPECT_EQ(0u, service_->extensions()->size());
2734 } 2734 }
2735 2735
2736 // Tests that we generate IDs when they are not specified in the manifest for 2736 // Tests that we generate IDs when they are not specified in the manifest for
2737 // --load-extension. 2737 // --load-extension.
2738 TEST_F(ExtensionsServiceTest, GenerateID) { 2738 TEST_F(ExtensionServiceTest, GenerateID) {
2739 InitializeEmptyExtensionsService(); 2739 InitializeEmptyExtensionService();
2740 2740
2741 FilePath extensions_path; 2741 FilePath extensions_path;
2742 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2742 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2743 extensions_path = extensions_path.AppendASCII("extensions"); 2743 extensions_path = extensions_path.AppendASCII("extensions");
2744 2744
2745 FilePath no_id_ext = extensions_path.AppendASCII("no_id"); 2745 FilePath no_id_ext = extensions_path.AppendASCII("no_id");
2746 service_->LoadExtension(no_id_ext); 2746 service_->LoadExtension(no_id_ext);
2747 loop_.RunAllPending(); 2747 loop_.RunAllPending();
2748 EXPECT_EQ(0u, GetErrors().size()); 2748 EXPECT_EQ(0u, GetErrors().size());
2749 ASSERT_EQ(1u, loaded_.size()); 2749 ASSERT_EQ(1u, loaded_.size());
2750 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); 2750 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id()));
2751 EXPECT_EQ(loaded_[0]->location(), Extension::LOAD); 2751 EXPECT_EQ(loaded_[0]->location(), Extension::LOAD);
2752 2752
2753 ValidatePrefKeyCount(1); 2753 ValidatePrefKeyCount(1);
2754 2754
2755 std::string previous_id = loaded_[0]->id(); 2755 std::string previous_id = loaded_[0]->id();
2756 2756
2757 // If we reload the same path, we should get the same extension ID. 2757 // If we reload the same path, we should get the same extension ID.
2758 service_->LoadExtension(no_id_ext); 2758 service_->LoadExtension(no_id_ext);
2759 loop_.RunAllPending(); 2759 loop_.RunAllPending();
2760 ASSERT_EQ(1u, loaded_.size()); 2760 ASSERT_EQ(1u, loaded_.size());
2761 ASSERT_EQ(previous_id, loaded_[0]->id()); 2761 ASSERT_EQ(previous_id, loaded_[0]->id());
2762 } 2762 }
2763 2763
2764 void ExtensionsServiceTest::TestExternalProvider( 2764 void ExtensionServiceTest::TestExternalProvider(
2765 MockExtensionProvider* provider, Extension::Location location) { 2765 MockExtensionProvider* provider, Extension::Location location) {
2766 // Verify that starting with no providers loads no extensions. 2766 // Verify that starting with no providers loads no extensions.
2767 service_->Init(); 2767 service_->Init();
2768 loop_.RunAllPending(); 2768 loop_.RunAllPending();
2769 ASSERT_EQ(0u, loaded_.size()); 2769 ASSERT_EQ(0u, loaded_.size());
2770 2770
2771 provider->set_visit_count(0); 2771 provider->set_visit_count(0);
2772 2772
2773 // Register a test extension externally using the mock registry provider. 2773 // Register a test extension externally using the mock registry provider.
2774 FilePath source_path; 2774 FilePath source_path;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2884 service_->LoadAllExtensions(); 2884 service_->LoadAllExtensions();
2885 loop_.RunAllPending(); 2885 loop_.RunAllPending();
2886 ASSERT_EQ(0u, loaded_.size()); 2886 ASSERT_EQ(0u, loaded_.size());
2887 ValidatePrefKeyCount(1); 2887 ValidatePrefKeyCount(1);
2888 2888
2889 EXPECT_EQ(5, provider->visit_count()); 2889 EXPECT_EQ(5, provider->visit_count());
2890 } 2890 }
2891 2891
2892 // Tests the external installation feature 2892 // Tests the external installation feature
2893 #if defined(OS_WIN) 2893 #if defined(OS_WIN)
2894 TEST_F(ExtensionsServiceTest, ExternalInstallRegistry) { 2894 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) {
2895 // This should all work, even when normal extension installation is disabled. 2895 // This should all work, even when normal extension installation is disabled.
2896 InitializeEmptyExtensionsService(); 2896 InitializeEmptyExtensionService();
2897 set_extensions_enabled(false); 2897 set_extensions_enabled(false);
2898 2898
2899 // Now add providers. Extension system takes ownership of the objects. 2899 // Now add providers. Extension system takes ownership of the objects.
2900 MockExtensionProvider* reg_provider = 2900 MockExtensionProvider* reg_provider =
2901 new MockExtensionProvider(Extension::EXTERNAL_REGISTRY); 2901 new MockExtensionProvider(Extension::EXTERNAL_REGISTRY);
2902 AddMockExternalProvider(reg_provider); 2902 AddMockExternalProvider(reg_provider);
2903 TestExternalProvider(reg_provider, Extension::EXTERNAL_REGISTRY); 2903 TestExternalProvider(reg_provider, Extension::EXTERNAL_REGISTRY);
2904 } 2904 }
2905 #endif 2905 #endif
2906 2906
2907 TEST_F(ExtensionsServiceTest, ExternalInstallPref) { 2907 TEST_F(ExtensionServiceTest, ExternalInstallPref) {
2908 InitializeEmptyExtensionsService(); 2908 InitializeEmptyExtensionService();
2909 2909
2910 // Now add providers. Extension system takes ownership of the objects. 2910 // Now add providers. Extension system takes ownership of the objects.
2911 MockExtensionProvider* pref_provider = 2911 MockExtensionProvider* pref_provider =
2912 new MockExtensionProvider(Extension::EXTERNAL_PREF); 2912 new MockExtensionProvider(Extension::EXTERNAL_PREF);
2913 2913
2914 AddMockExternalProvider(pref_provider); 2914 AddMockExternalProvider(pref_provider);
2915 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF); 2915 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF);
2916 } 2916 }
2917 2917
2918 TEST_F(ExtensionsServiceTest, ExternalInstallPrefUpdateUrl) { 2918 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) {
2919 // This should all work, even when normal extension installation is disabled. 2919 // This should all work, even when normal extension installation is disabled.
2920 InitializeEmptyExtensionsService(); 2920 InitializeEmptyExtensionService();
2921 set_extensions_enabled(false); 2921 set_extensions_enabled(false);
2922 2922
2923 // TODO(skerner): The mock provider is not a good model of a provider 2923 // TODO(skerner): The mock provider is not a good model of a provider
2924 // that works with update URLs, because it adds file and version info. 2924 // that works with update URLs, because it adds file and version info.
2925 // Extend the mock to work with update URLs. This test checks the 2925 // Extend the mock to work with update URLs. This test checks the
2926 // behavior that is common to all external extension visitors. The 2926 // behavior that is common to all external extension visitors. The
2927 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that 2927 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that
2928 // what the visitor does results in an extension being downloaded and 2928 // what the visitor does results in an extension being downloaded and
2929 // installed. 2929 // installed.
2930 MockExtensionProvider* pref_provider = 2930 MockExtensionProvider* pref_provider =
2931 new MockExtensionProvider(Extension::EXTERNAL_PREF_DOWNLOAD); 2931 new MockExtensionProvider(Extension::EXTERNAL_PREF_DOWNLOAD);
2932 AddMockExternalProvider(pref_provider); 2932 AddMockExternalProvider(pref_provider);
2933 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF_DOWNLOAD); 2933 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF_DOWNLOAD);
2934 } 2934 }
2935 2935
2936 // Tests that external extensions get uninstalled when the external extension 2936 // Tests that external extensions get uninstalled when the external extension
2937 // providers can't account for them. 2937 // providers can't account for them.
2938 TEST_F(ExtensionsServiceTest, ExternalUninstall) { 2938 TEST_F(ExtensionServiceTest, ExternalUninstall) {
2939 // Start the extensions service with one external extension already installed. 2939 // Start the extensions service with one external extension already installed.
2940 FilePath source_install_dir; 2940 FilePath source_install_dir;
2941 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); 2941 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir));
2942 source_install_dir = source_install_dir 2942 source_install_dir = source_install_dir
2943 .AppendASCII("extensions") 2943 .AppendASCII("extensions")
2944 .AppendASCII("good") 2944 .AppendASCII("good")
2945 .AppendASCII("Extensions"); 2945 .AppendASCII("Extensions");
2946 FilePath pref_path = source_install_dir 2946 FilePath pref_path = source_install_dir
2947 .DirName() 2947 .DirName()
2948 .AppendASCII("PreferencesExternal"); 2948 .AppendASCII("PreferencesExternal");
2949 2949
2950 // This initializes the extensions service with no ExternalExtensionProviders. 2950 // This initializes the extensions service with no ExternalExtensionProviders.
2951 InitializeInstalledExtensionsService(pref_path, source_install_dir); 2951 InitializeInstalledExtensionService(pref_path, source_install_dir);
2952 set_extensions_enabled(false); 2952 set_extensions_enabled(false);
2953 2953
2954 service_->Init(); 2954 service_->Init();
2955 loop_.RunAllPending(); 2955 loop_.RunAllPending();
2956 2956
2957 ASSERT_EQ(0u, GetErrors().size()); 2957 ASSERT_EQ(0u, GetErrors().size());
2958 ASSERT_EQ(0u, loaded_.size()); 2958 ASSERT_EQ(0u, loaded_.size());
2959 2959
2960 // Verify that it's not the disabled extensions flag causing it not to load. 2960 // Verify that it's not the disabled extensions flag causing it not to load.
2961 set_extensions_enabled(true); 2961 set_extensions_enabled(true);
2962 service_->ReloadExtensions(); 2962 service_->ReloadExtensions();
2963 loop_.RunAllPending(); 2963 loop_.RunAllPending();
2964 2964
2965 ASSERT_EQ(0u, GetErrors().size()); 2965 ASSERT_EQ(0u, GetErrors().size());
2966 ASSERT_EQ(0u, loaded_.size()); 2966 ASSERT_EQ(0u, loaded_.size());
2967 } 2967 }
2968 2968
2969 TEST_F(ExtensionsServiceTest, ExternalPrefProvider) { 2969 TEST_F(ExtensionServiceTest, ExternalPrefProvider) {
2970 InitializeEmptyExtensionsService(); 2970 InitializeEmptyExtensionService();
2971 std::string json_data = 2971 std::string json_data =
2972 "{" 2972 "{"
2973 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" 2973 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {"
2974 " \"external_crx\": \"RandomExtension.crx\"," 2974 " \"external_crx\": \"RandomExtension.crx\","
2975 " \"external_version\": \"1.0\"" 2975 " \"external_version\": \"1.0\""
2976 " }," 2976 " },"
2977 " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" 2977 " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {"
2978 " \"external_crx\": \"RandomExtension2.crx\"," 2978 " \"external_crx\": \"RandomExtension2.crx\","
2979 " \"external_version\": \"2.0\"" 2979 " \"external_version\": \"2.0\""
2980 " }," 2980 " },"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 " }," 3024 " },"
3025 " \"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\": {" 3025 " \"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\": {"
3026 " \"external_crx\": \"RandomValidExtension.crx\"," 3026 " \"external_crx\": \"RandomValidExtension.crx\","
3027 " \"external_version\": \"1.0\"" 3027 " \"external_version\": \"1.0\""
3028 " }" 3028 " }"
3029 "}"; 3029 "}";
3030 EXPECT_EQ(1, visitor.Visit(json_data)); 3030 EXPECT_EQ(1, visitor.Visit(json_data));
3031 } 3031 }
3032 3032
3033 // Test loading good extensions from the profile directory. 3033 // Test loading good extensions from the profile directory.
3034 TEST_F(ExtensionsServiceTest, LoadAndRelocalizeExtensions) { 3034 TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) {
3035 // Initialize the test dir with a good Preferences/extensions. 3035 // Initialize the test dir with a good Preferences/extensions.
3036 FilePath source_install_dir; 3036 FilePath source_install_dir;
3037 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); 3037 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir));
3038 source_install_dir = source_install_dir 3038 source_install_dir = source_install_dir
3039 .AppendASCII("extensions") 3039 .AppendASCII("extensions")
3040 .AppendASCII("l10n"); 3040 .AppendASCII("l10n");
3041 FilePath pref_path = source_install_dir.AppendASCII("Preferences"); 3041 FilePath pref_path = source_install_dir.AppendASCII("Preferences");
3042 InitializeInstalledExtensionsService(pref_path, source_install_dir); 3042 InitializeInstalledExtensionService(pref_path, source_install_dir);
3043 3043
3044 service_->Init(); 3044 service_->Init();
3045 loop_.RunAllPending(); 3045 loop_.RunAllPending();
3046 3046
3047 ASSERT_EQ(3u, loaded_.size()); 3047 ASSERT_EQ(3u, loaded_.size());
3048 3048
3049 // This was equal to "sr" on load. 3049 // This was equal to "sr" on load.
3050 ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en"); 3050 ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en");
3051 3051
3052 // These are untouched by re-localization. 3052 // These are untouched by re-localization.
(...skipping 29 matching lines...) Expand all
3082 default: 3082 default:
3083 NOTREACHED(); 3083 NOTREACHED();
3084 } 3084 }
3085 } 3085 }
3086 3086
3087 NotificationRegistrar registrar_; 3087 NotificationRegistrar registrar_;
3088 bool ready_; 3088 bool ready_;
3089 }; 3089 };
3090 3090
3091 // Test that we get enabled/disabled correctly for all the pref/command-line 3091 // Test that we get enabled/disabled correctly for all the pref/command-line
3092 // combinations. We don't want to derive from the ExtensionsServiceTest class 3092 // combinations. We don't want to derive from the ExtensionServiceTest class
3093 // for this test, so we use ExtensionsServiceTestSimple. 3093 // for this test, so we use ExtensionServiceTestSimple.
3094 // 3094 //
3095 // Also tests that we always fire EXTENSIONS_READY, no matter whether we are 3095 // Also tests that we always fire EXTENSIONS_READY, no matter whether we are
3096 // enabled or not. 3096 // enabled or not.
3097 TEST(ExtensionsServiceTestSimple, Enabledness) { 3097 TEST(ExtensionServiceTestSimple, Enabledness) {
3098 ExtensionsReadyRecorder recorder; 3098 ExtensionsReadyRecorder recorder;
3099 scoped_ptr<TestingProfile> profile(new TestingProfile()); 3099 scoped_ptr<TestingProfile> profile(new TestingProfile());
3100 MessageLoop loop; 3100 MessageLoop loop;
3101 BrowserThread ui_thread(BrowserThread::UI, &loop); 3101 BrowserThread ui_thread(BrowserThread::UI, &loop);
3102 BrowserThread file_thread(BrowserThread::FILE, &loop); 3102 BrowserThread file_thread(BrowserThread::FILE, &loop);
3103 scoped_ptr<CommandLine> command_line; 3103 scoped_ptr<CommandLine> command_line;
3104 scoped_refptr<ExtensionsService> service; 3104 scoped_refptr<ExtensionService> service;
3105 FilePath install_dir = profile->GetPath() 3105 FilePath install_dir = profile->GetPath()
3106 .AppendASCII(ExtensionsService::kInstallDirectoryName); 3106 .AppendASCII(ExtensionService::kInstallDirectoryName);
3107 3107
3108 // By default, we are enabled. 3108 // By default, we are enabled.
3109 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); 3109 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
3110 service = profile->CreateExtensionsService(command_line.get(), 3110 service = profile->CreateExtensionService(command_line.get(),
3111 install_dir); 3111 install_dir);
3112 EXPECT_TRUE(service->extensions_enabled()); 3112 EXPECT_TRUE(service->extensions_enabled());
3113 service->Init(); 3113 service->Init();
3114 loop.RunAllPending(); 3114 loop.RunAllPending();
3115 EXPECT_TRUE(recorder.ready()); 3115 EXPECT_TRUE(recorder.ready());
3116 3116
3117 // If either the command line or pref is set, we are disabled. 3117 // If either the command line or pref is set, we are disabled.
3118 recorder.set_ready(false); 3118 recorder.set_ready(false);
3119 profile.reset(new TestingProfile()); 3119 profile.reset(new TestingProfile());
3120 command_line->AppendSwitch(switches::kDisableExtensions); 3120 command_line->AppendSwitch(switches::kDisableExtensions);
3121 service = profile->CreateExtensionsService(command_line.get(), 3121 service = profile->CreateExtensionService(command_line.get(),
3122 install_dir); 3122 install_dir);
3123 EXPECT_FALSE(service->extensions_enabled()); 3123 EXPECT_FALSE(service->extensions_enabled());
3124 service->Init(); 3124 service->Init();
3125 loop.RunAllPending(); 3125 loop.RunAllPending();
3126 EXPECT_TRUE(recorder.ready()); 3126 EXPECT_TRUE(recorder.ready());
3127 3127
3128 recorder.set_ready(false); 3128 recorder.set_ready(false);
3129 profile.reset(new TestingProfile()); 3129 profile.reset(new TestingProfile());
3130 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 3130 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
3131 service = profile->CreateExtensionsService(command_line.get(), 3131 service = profile->CreateExtensionService(command_line.get(),
3132 install_dir); 3132 install_dir);
3133 EXPECT_FALSE(service->extensions_enabled()); 3133 EXPECT_FALSE(service->extensions_enabled());
3134 service->Init(); 3134 service->Init();
3135 loop.RunAllPending(); 3135 loop.RunAllPending();
3136 EXPECT_TRUE(recorder.ready()); 3136 EXPECT_TRUE(recorder.ready());
3137 3137
3138 recorder.set_ready(false); 3138 recorder.set_ready(false);
3139 profile.reset(new TestingProfile()); 3139 profile.reset(new TestingProfile());
3140 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 3140 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
3141 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); 3141 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
3142 service = profile->CreateExtensionsService(command_line.get(), 3142 service = profile->CreateExtensionService(command_line.get(),
3143 install_dir); 3143 install_dir);
3144 EXPECT_FALSE(service->extensions_enabled()); 3144 EXPECT_FALSE(service->extensions_enabled());
3145 service->Init(); 3145 service->Init();
3146 loop.RunAllPending(); 3146 loop.RunAllPending();
3147 EXPECT_TRUE(recorder.ready()); 3147 EXPECT_TRUE(recorder.ready());
3148 3148
3149 // Explicitly delete all the resources used in this test. 3149 // Explicitly delete all the resources used in this test.
3150 profile.reset(); 3150 profile.reset();
3151 service = NULL; 3151 service = NULL;
3152 } 3152 }
3153 3153
3154 // Test loading extensions that require limited and unlimited storage quotas. 3154 // Test loading extensions that require limited and unlimited storage quotas.
3155 TEST_F(ExtensionsServiceTest, StorageQuota) { 3155 TEST_F(ExtensionServiceTest, StorageQuota) {
3156 InitializeEmptyExtensionsService(); 3156 InitializeEmptyExtensionService();
3157 3157
3158 FilePath extensions_path; 3158 FilePath extensions_path;
3159 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 3159 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
3160 extensions_path = extensions_path.AppendASCII("extensions") 3160 extensions_path = extensions_path.AppendASCII("extensions")
3161 .AppendASCII("storage_quota"); 3161 .AppendASCII("storage_quota");
3162 3162
3163 FilePath limited_quota_ext = extensions_path.AppendASCII("limited_quota") 3163 FilePath limited_quota_ext = extensions_path.AppendASCII("limited_quota")
3164 .AppendASCII("1.0"); 3164 .AppendASCII("1.0");
3165 3165
3166 // The old permission name for unlimited quota was "unlimited_storage", but 3166 // The old permission name for unlimited quota was "unlimited_storage", but
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3204 1, &database_size, &unlimited_quota); 3204 1, &database_size, &unlimited_quota);
3205 db_tracker->DatabaseClosed(unlimited_quota_identifier, db_name); 3205 db_tracker->DatabaseClosed(unlimited_quota_identifier, db_name);
3206 EXPECT_EQ(kint64max, unlimited_quota); 3206 EXPECT_EQ(kint64max, unlimited_quota);
3207 db_tracker->DatabaseOpened(unlimited_quota_identifier2, db_name, description, 3207 db_tracker->DatabaseOpened(unlimited_quota_identifier2, db_name, description,
3208 1, &database_size, &unlimited_quota); 3208 1, &database_size, &unlimited_quota);
3209 db_tracker->DatabaseClosed(unlimited_quota_identifier2, db_name); 3209 db_tracker->DatabaseClosed(unlimited_quota_identifier2, db_name);
3210 3210
3211 EXPECT_EQ(kint64max, unlimited_quota); 3211 EXPECT_EQ(kint64max, unlimited_quota);
3212 } 3212 }
3213 3213
3214 // Tests ExtensionsService::register_component_extension(). 3214 // Tests ExtensionService::register_component_extension().
3215 TEST_F(ExtensionsServiceTest, ComponentExtensions) { 3215 TEST_F(ExtensionServiceTest, ComponentExtensions) {
3216 InitializeEmptyExtensionsService(); 3216 InitializeEmptyExtensionService();
3217 3217
3218 // Component extensions should work even when extensions are disabled. 3218 // Component extensions should work even when extensions are disabled.
3219 set_extensions_enabled(false); 3219 set_extensions_enabled(false);
3220 3220
3221 FilePath path; 3221 FilePath path;
3222 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 3222 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
3223 path = path.AppendASCII("extensions") 3223 path = path.AppendASCII("extensions")
3224 .AppendASCII("good") 3224 .AppendASCII("good")
3225 .AppendASCII("Extensions") 3225 .AppendASCII("Extensions")
3226 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 3226 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
3227 .AppendASCII("1.0.0.0"); 3227 .AppendASCII("1.0.0.0");
3228 3228
3229 std::string manifest; 3229 std::string manifest;
3230 ASSERT_TRUE(file_util::ReadFileToString( 3230 ASSERT_TRUE(file_util::ReadFileToString(
3231 path.Append(Extension::kManifestFilename), &manifest)); 3231 path.Append(Extension::kManifestFilename), &manifest));
3232 3232
3233 service_->register_component_extension( 3233 service_->register_component_extension(
3234 ExtensionsService::ComponentExtensionInfo(manifest, path)); 3234 ExtensionService::ComponentExtensionInfo(manifest, path));
3235 service_->Init(); 3235 service_->Init();
3236 3236
3237 // Note that we do not pump messages -- the extension should be loaded 3237 // Note that we do not pump messages -- the extension should be loaded
3238 // immediately. 3238 // immediately.
3239 3239
3240 EXPECT_EQ(0u, GetErrors().size()); 3240 EXPECT_EQ(0u, GetErrors().size());
3241 ASSERT_EQ(1u, loaded_.size()); 3241 ASSERT_EQ(1u, loaded_.size());
3242 EXPECT_EQ(Extension::COMPONENT, loaded_[0]->location()); 3242 EXPECT_EQ(Extension::COMPONENT, loaded_[0]->location());
3243 EXPECT_EQ(1u, service_->extensions()->size()); 3243 EXPECT_EQ(1u, service_->extensions()->size());
3244 3244
3245 // Component extensions shouldn't get recourded in the prefs. 3245 // Component extensions shouldn't get recourded in the prefs.
3246 ValidatePrefKeyCount(0); 3246 ValidatePrefKeyCount(0);
3247 3247
3248 // Reload all extensions, and make sure it comes back. 3248 // Reload all extensions, and make sure it comes back.
3249 std::string extension_id = service_->extensions()->at(0)->id(); 3249 std::string extension_id = service_->extensions()->at(0)->id();
3250 loaded_.clear(); 3250 loaded_.clear();
3251 service_->ReloadExtensions(); 3251 service_->ReloadExtensions();
3252 ASSERT_EQ(1u, service_->extensions()->size()); 3252 ASSERT_EQ(1u, service_->extensions()->size());
3253 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); 3253 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id());
3254 } 3254 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.h ('k') | chrome/browser/extensions/extension_sidebar_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698