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

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

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile gdi. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_service_unittest.h" 5 #include "chrome/browser/extensions/extension_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/at_exit.h" 11 #include "base/at_exit.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/files/file_enumerator.h" 16 #include "base/files/file_enumerator.h"
17 #include "base/files/scoped_temp_dir.h" 17 #include "base/files/scoped_temp_dir.h"
18 #include "base/json/json_file_value_serializer.h" 18 #include "base/json/json_file_value_serializer.h"
19 #include "base/json/json_reader.h" 19 #include "base/json/json_reader.h"
20 #include "base/json/json_string_value_serializer.h" 20 #include "base/json/json_string_value_serializer.h"
21 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
22 #include "base/memory/weak_ptr.h" 22 #include "base/memory/weak_ptr.h"
23 #include "base/message_loop/message_loop.h" 23 #include "base/message_loop/message_loop.h"
24 #include "base/path_service.h" 24 #include "base/path_service.h"
25 #include "base/run_loop.h"
25 #include "base/stl_util.h" 26 #include "base/stl_util.h"
26 #include "base/strings/string16.h" 27 #include "base/strings/string16.h"
27 #include "base/strings/string_number_conversions.h" 28 #include "base/strings/string_number_conversions.h"
28 #include "base/strings/string_util.h" 29 #include "base/strings/string_util.h"
29 #include "base/strings/utf_string_conversions.h" 30 #include "base/strings/utf_string_conversions.h"
30 #include "base/version.h" 31 #include "base/version.h"
31 #include "chrome/browser/browser_process.h" 32 #include "chrome/browser/browser_process.h"
32 #include "chrome/browser/chrome_notification_types.h" 33 #include "chrome/browser/chrome_notification_types.h"
33 #include "chrome/browser/extensions/app_sync_data.h" 34 #include "chrome/browser/extensions/app_sync_data.h"
34 #include "chrome/browser/extensions/component_loader.h" 35 #include "chrome/browser/extensions/component_loader.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #include "chrome/common/extensions/extension_manifest_constants.h" 76 #include "chrome/common/extensions/extension_manifest_constants.h"
76 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 77 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
77 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" 78 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
78 #include "chrome/common/extensions/manifest_url_handler.h" 79 #include "chrome/common/extensions/manifest_url_handler.h"
79 #include "chrome/common/extensions/permissions/permission_set.h" 80 #include "chrome/common/extensions/permissions/permission_set.h"
80 #include "chrome/common/extensions/value_builder.h" 81 #include "chrome/common/extensions/value_builder.h"
81 #include "chrome/common/pref_names.h" 82 #include "chrome/common/pref_names.h"
82 #include "chrome/common/url_constants.h" 83 #include "chrome/common/url_constants.h"
83 #include "chrome/test/base/testing_profile.h" 84 #include "chrome/test/base/testing_profile.h"
84 #include "components/user_prefs/pref_registry_syncable.h" 85 #include "components/user_prefs/pref_registry_syncable.h"
86 #include "content/public/browser/cookie_store_map.h"
85 #include "content/public/browser/dom_storage_context.h" 87 #include "content/public/browser/dom_storage_context.h"
86 #include "content/public/browser/gpu_data_manager.h" 88 #include "content/public/browser/gpu_data_manager.h"
87 #include "content/public/browser/indexed_db_context.h" 89 #include "content/public/browser/indexed_db_context.h"
88 #include "content/public/browser/notification_registrar.h" 90 #include "content/public/browser/notification_registrar.h"
89 #include "content/public/browser/notification_service.h" 91 #include "content/public/browser/notification_service.h"
90 #include "content/public/browser/plugin_service.h" 92 #include "content/public/browser/plugin_service.h"
91 #include "content/public/browser/render_process_host.h" 93 #include "content/public/browser/render_process_host.h"
92 #include "content/public/browser/storage_partition.h" 94 #include "content/public/browser/storage_partition.h"
93 #include "content/public/common/content_constants.h" 95 #include "content/public/common/content_constants.h"
94 #include "content/public/test/test_browser_thread.h"
95 #include "content/public/test/test_utils.h" 96 #include "content/public/test/test_utils.h"
96 #include "extensions/common/constants.h" 97 #include "extensions/common/constants.h"
97 #include "extensions/common/extension_resource.h" 98 #include "extensions/common/extension_resource.h"
98 #include "extensions/common/url_pattern.h" 99 #include "extensions/common/url_pattern.h"
99 #include "gpu/config/gpu_info.h" 100 #include "gpu/config/gpu_info.h"
100 #include "grit/browser_resources.h" 101 #include "grit/browser_resources.h"
101 #include "net/cookies/canonical_cookie.h" 102 #include "net/cookies/canonical_cookie.h"
102 #include "net/cookies/cookie_monster.h" 103 #include "net/cookies/cookie_monster.h"
103 #include "net/cookies/cookie_options.h" 104 #include "net/cookies/cookie_options.h"
104 #include "net/url_request/url_request_context.h" 105 #include "net/url_request/url_request_context.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); 434 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
434 }; 435 };
435 436
436 ExtensionServiceTestBase::ExtensionServiceInitParams:: 437 ExtensionServiceTestBase::ExtensionServiceInitParams::
437 ExtensionServiceInitParams() 438 ExtensionServiceInitParams()
438 : autoupdate_enabled(false), is_first_run(true) { 439 : autoupdate_enabled(false), is_first_run(true) {
439 } 440 }
440 441
441 // Our message loop may be used in tests which require it to be an IO loop. 442 // Our message loop may be used in tests which require it to be an IO loop.
442 ExtensionServiceTestBase::ExtensionServiceTestBase() 443 ExtensionServiceTestBase::ExtensionServiceTestBase()
443 : loop_(base::MessageLoop::TYPE_IO), 444 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
444 service_(NULL), 445 service_(NULL),
445 management_policy_(NULL), 446 management_policy_(NULL),
446 expected_extensions_count_(0), 447 expected_extensions_count_(0) {
447 ui_thread_(BrowserThread::UI, &loop_),
448 db_thread_(BrowserThread::DB, &loop_),
449 file_thread_(BrowserThread::FILE, &loop_),
450 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_),
451 io_thread_(BrowserThread::IO, &loop_) {
452 base::FilePath test_data_dir; 448 base::FilePath test_data_dir;
453 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { 449 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
454 ADD_FAILURE(); 450 ADD_FAILURE();
455 return; 451 return;
456 } 452 }
457 data_dir_ = test_data_dir.AppendASCII("extensions"); 453 data_dir_ = test_data_dir.AppendASCII("extensions");
458 } 454 }
459 455
460 ExtensionServiceTestBase::~ExtensionServiceTestBase() { 456 ExtensionServiceTestBase::~ExtensionServiceTestBase() {
461 // Drop our reference to ExtensionService and TestingProfile, so that they 457 // Drop our reference to ExtensionService and TestingProfile, so that they
462 // can be destroyed while BrowserThreads and MessageLoop are still around 458 // can be destroyed while BrowserThreads and MessageLoop are still around
463 // (they are used in the destruction process). 459 // (they are used in the destruction process).
464 service_ = NULL; 460 service_ = NULL;
465 base::MessageLoop::current()->RunUntilIdle(); 461 base::MessageLoop::current()->RunUntilIdle();
466 profile_.reset(NULL); 462 profile_.reset(NULL);
467 base::MessageLoop::current()->RunUntilIdle(); 463 base::MessageLoop::current()->RunUntilIdle();
468 } 464 }
469 465
470 void ExtensionServiceTestBase::InitializeExtensionService( 466 void ExtensionServiceTestBase::InitializeExtensionService(
471 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) { 467 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) {
472 TestingProfile::Builder profile_builder; 468 TestingProfile::Builder profile_builder;
473 // Create a PrefService that only contains user defined preference values. 469 // Create a PrefService that only contains user defined preference values.
474 PrefServiceMockBuilder builder; 470 PrefServiceMockBuilder builder;
475 // If pref_file is empty, TestingProfile automatically creates 471 // If pref_file is empty, TestingProfile automatically creates
476 // TestingPrefServiceSyncable instance. 472 // TestingPrefServiceSyncable instance.
477 if (!params.pref_file.empty()) { 473 if (!params.pref_file.empty()) {
478 builder.WithUserFilePrefs(params.pref_file, 474 builder.WithUserFilePrefs(
479 loop_.message_loop_proxy().get()); 475 params.pref_file,
476 base::MessageLoop::current()->message_loop_proxy().get());
480 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( 477 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
481 new user_prefs::PrefRegistrySyncable); 478 new user_prefs::PrefRegistrySyncable);
482 scoped_ptr<PrefServiceSyncable> prefs( 479 scoped_ptr<PrefServiceSyncable> prefs(
483 builder.CreateSyncable(registry.get())); 480 builder.CreateSyncable(registry.get()));
484 chrome::RegisterUserProfilePrefs(registry.get()); 481 chrome::RegisterUserProfilePrefs(registry.get());
485 profile_builder.SetPrefService(prefs.Pass()); 482 profile_builder.SetPrefService(prefs.Pass());
486 } 483 }
487 profile_builder.SetPath(params.profile_path); 484 profile_builder.SetPath(params.profile_path);
488 profile_ = profile_builder.Build(); 485 profile_ = profile_builder.Build();
489 486
490 TestExtensionSystem* system = static_cast<TestExtensionSystem*>( 487 TestExtensionSystem* system = static_cast<TestExtensionSystem*>(
491 ExtensionSystem::Get(profile_.get())); 488 ExtensionSystem::Get(profile_.get()));
492 if (!params.is_first_run) { 489 if (!params.is_first_run) {
493 ExtensionPrefs* prefs = system->CreateExtensionPrefs( 490 ExtensionPrefs* prefs = system->CreateExtensionPrefs(
494 CommandLine::ForCurrentProcess(), 491 CommandLine::ForCurrentProcess(),
495 params.extensions_install_dir); 492 params.extensions_install_dir);
496 prefs->SetAlertSystemFirstRun(); 493 prefs->SetAlertSystemFirstRun();
497 } 494 }
498 495
499 service_ = system->CreateExtensionService( 496 service_ = system->CreateExtensionService(
500 CommandLine::ForCurrentProcess(), 497 CommandLine::ForCurrentProcess(),
501 params.extensions_install_dir, 498 params.extensions_install_dir,
502 params.autoupdate_enabled); 499 params.autoupdate_enabled);
503 service_->SetFileTaskRunnerForTesting(loop_.message_loop_proxy().get()); 500 service_->SetFileTaskRunnerForTesting(
501 base::MessageLoop::current()->message_loop_proxy().get());
504 service_->set_extensions_enabled(true); 502 service_->set_extensions_enabled(true);
505 service_->set_show_extensions_prompts(false); 503 service_->set_show_extensions_prompts(false);
506 service_->set_install_updates_when_idle_for_test(false); 504 service_->set_install_updates_when_idle_for_test(false);
507 505
508 management_policy_ = 506 management_policy_ =
509 ExtensionSystem::Get(profile_.get())->management_policy(); 507 ExtensionSystem::Get(profile_.get())->management_policy();
510 508
511 // When we start up, we want to make sure there is no external provider, 509 // When we start up, we want to make sure there is no external provider,
512 // since the ExtensionService on Windows will use the Registry as a default 510 // since the ExtensionService on Windows will use the Registry as a default
513 // provider and if there is something already registered there then it will 511 // provider and if there is something already registered there then it will
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 ASSERT_TRUE(creator->Run(dir_path, 685 ASSERT_TRUE(creator->Run(dir_path,
688 crx_path, 686 crx_path,
689 pem_path, 687 pem_path,
690 pem_output_path, 688 pem_output_path,
691 ExtensionCreator::kOverwriteCRX)); 689 ExtensionCreator::kOverwriteCRX));
692 690
693 ASSERT_TRUE(base::PathExists(crx_path)); 691 ASSERT_TRUE(base::PathExists(crx_path));
694 } 692 }
695 693
696 // Create a CrxInstaller and start installation. To allow the install 694 // Create a CrxInstaller and start installation. To allow the install
697 // to happen, use loop_.RunUntilIdle();. Most tests will not use this 695 // to happen, use base::RunLoop().RunUntilIdle();. Most tests will not use
698 // method directly. Instead, use InstallCrx(), which waits for 696 // this method directly. Instead, use InstallCrx(), which waits for
699 // the crx to be installed and does extra error checking. 697 // the crx to be installed and does extra error checking.
700 void StartCRXInstall(const base::FilePath& crx_path) { 698 void StartCRXInstall(const base::FilePath& crx_path) {
701 StartCRXInstall(crx_path, Extension::NO_FLAGS); 699 StartCRXInstall(crx_path, Extension::NO_FLAGS);
702 } 700 }
703 701
704 void StartCRXInstall(const base::FilePath& crx_path, int creation_flags) { 702 void StartCRXInstall(const base::FilePath& crx_path, int creation_flags) {
705 ASSERT_TRUE(base::PathExists(crx_path)) 703 ASSERT_TRUE(base::PathExists(crx_path))
706 << "Path does not exist: "<< crx_path.value().c_str(); 704 << "Path does not exist: "<< crx_path.value().c_str();
707 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); 705 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
708 installer->set_creation_flags(creation_flags); 706 installer->set_creation_flags(creation_flags);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 service_->disabled_extensions()->size(); 904 service_->disabled_extensions()->size();
907 905
908 extensions::CrxInstaller* installer = NULL; 906 extensions::CrxInstaller* installer = NULL;
909 service_->UpdateExtension(id, path, GURL(), &installer); 907 service_->UpdateExtension(id, path, GURL(), &installer);
910 908
911 if (installer) { 909 if (installer) {
912 content::WindowedNotificationObserver( 910 content::WindowedNotificationObserver(
913 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 911 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
914 content::Source<extensions::CrxInstaller>(installer)).Wait(); 912 content::Source<extensions::CrxInstaller>(installer)).Wait();
915 } else { 913 } else {
916 loop_.RunUntilIdle(); 914 base::RunLoop().RunUntilIdle();
917 } 915 }
918 916
919 std::vector<string16> errors = GetErrors(); 917 std::vector<string16> errors = GetErrors();
920 int error_count = errors.size(); 918 int error_count = errors.size();
921 int enabled_extension_count = 919 int enabled_extension_count =
922 service_->extensions()->size(); 920 service_->extensions()->size();
923 int installed_extension_count = 921 int installed_extension_count =
924 enabled_extension_count + service_->disabled_extensions()->size(); 922 enabled_extension_count + service_->disabled_extensions()->size();
925 923
926 int expected_error_count = (expected_state == FAILED) ? 1 : 0; 924 int expected_error_count = (expected_state == FAILED) ? 1 : 0;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 size_t new_pref_key_count = GetPrefKeyCount(); 987 size_t new_pref_key_count = GetPrefKeyCount();
990 if (new_pref_key_count == pref_key_count) { 988 if (new_pref_key_count == pref_key_count) {
991 ValidateIntegerPref(id, "location", 989 ValidateIntegerPref(id, "location",
992 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 990 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
993 } else { 991 } else {
994 EXPECT_EQ(new_pref_key_count, pref_key_count - 1); 992 EXPECT_EQ(new_pref_key_count, pref_key_count - 1);
995 } 993 }
996 994
997 // The extension should not be in the service anymore. 995 // The extension should not be in the service anymore.
998 EXPECT_FALSE(service_->GetInstalledExtension(id)); 996 EXPECT_FALSE(service_->GetInstalledExtension(id));
999 loop_.RunUntilIdle(); 997 base::RunLoop().RunUntilIdle();
1000 998
1001 // The directory should be gone. 999 // The directory should be gone.
1002 EXPECT_FALSE(base::PathExists(extension_path)); 1000 EXPECT_FALSE(base::PathExists(extension_path));
1003 } 1001 }
1004 1002
1005 void ValidatePrefKeyCount(size_t count) { 1003 void ValidatePrefKeyCount(size_t count) {
1006 EXPECT_EQ(count, GetPrefKeyCount()); 1004 EXPECT_EQ(count, GetPrefKeyCount());
1007 } 1005 }
1008 1006
1009 void ValidateBooleanPref(const std::string& extension_id, 1007 void ValidateBooleanPref(const std::string& extension_id,
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 ASSERT_TRUE(dict != NULL); 1392 ASSERT_TRUE(dict != NULL);
1395 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); 1393 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL);
1396 } 1394 }
1397 1395
1398 service_->Init(); 1396 service_->Init();
1399 // A delayed task to call GarbageCollectExtensions is posted by 1397 // A delayed task to call GarbageCollectExtensions is posted by
1400 // ExtensionService::Init. As the test won't wait for the delayed task to 1398 // ExtensionService::Init. As the test won't wait for the delayed task to
1401 // be called, call it manually instead. 1399 // be called, call it manually instead.
1402 service_->GarbageCollectExtensions(); 1400 service_->GarbageCollectExtensions();
1403 // Wait for GarbageCollectExtensions task to complete. 1401 // Wait for GarbageCollectExtensions task to complete.
1404 loop_.RunUntilIdle(); 1402 base::RunLoop().RunUntilIdle();
1405 1403
1406 base::FileEnumerator dirs(extensions_install_dir_, false, 1404 base::FileEnumerator dirs(extensions_install_dir_, false,
1407 base::FileEnumerator::DIRECTORIES); 1405 base::FileEnumerator::DIRECTORIES);
1408 size_t count = 0; 1406 size_t count = 0;
1409 while (!dirs.Next().empty()) 1407 while (!dirs.Next().empty())
1410 count++; 1408 count++;
1411 1409
1412 // We should have only gotten two extensions now. 1410 // We should have only gotten two extensions now.
1413 EXPECT_EQ(2u, count); 1411 EXPECT_EQ(2u, count);
1414 1412
(...skipping 17 matching lines...) Expand all
1432 1430
1433 InitializeInstalledExtensionService(pref_path, source_install_dir); 1431 InitializeInstalledExtensionService(pref_path, source_install_dir);
1434 1432
1435 // This is the directory that is going to be deleted, so make sure it actually 1433 // This is the directory that is going to be deleted, so make sure it actually
1436 // is there before the garbage collection. 1434 // is there before the garbage collection.
1437 ASSERT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1435 ASSERT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
1438 "hpiknbiabeeppbpihjehijgoemciehgk/3"))); 1436 "hpiknbiabeeppbpihjehijgoemciehgk/3")));
1439 1437
1440 service_->GarbageCollectExtensions(); 1438 service_->GarbageCollectExtensions();
1441 // Wait for GarbageCollectExtensions task to complete. 1439 // Wait for GarbageCollectExtensions task to complete.
1442 loop_.RunUntilIdle(); 1440 base::RunLoop().RunUntilIdle();
1443 1441
1444 // Verify that the pending update for the first extension didn't get 1442 // Verify that the pending update for the first extension didn't get
1445 // deleted. 1443 // deleted.
1446 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1444 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
1447 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); 1445 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0")));
1448 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1446 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
1449 "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0"))); 1447 "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0")));
1450 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1448 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
1451 "hpiknbiabeeppbpihjehijgoemciehgk/2"))); 1449 "hpiknbiabeeppbpihjehijgoemciehgk/2")));
1452 EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII( 1450 EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII(
(...skipping 17 matching lines...) Expand all
1470 // is there before the garbage collection. 1468 // is there before the garbage collection.
1471 ASSERT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1469 ASSERT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
1472 "hpiknbiabeeppbpihjehijgoemciehgk/3"))); 1470 "hpiknbiabeeppbpihjehijgoemciehgk/3")));
1473 1471
1474 service_->Init(); 1472 service_->Init();
1475 // A delayed task to call GarbageCollectExtensions is posted by 1473 // A delayed task to call GarbageCollectExtensions is posted by
1476 // ExtensionService::Init. As the test won't wait for the delayed task to 1474 // ExtensionService::Init. As the test won't wait for the delayed task to
1477 // be called, call it manually instead. 1475 // be called, call it manually instead.
1478 service_->GarbageCollectExtensions(); 1476 service_->GarbageCollectExtensions();
1479 // Wait for GarbageCollectExtensions task to complete. 1477 // Wait for GarbageCollectExtensions task to complete.
1480 loop_.RunUntilIdle(); 1478 base::RunLoop().RunUntilIdle();
1481 1479
1482 // Verify that the pending update for the first extension got installed. 1480 // Verify that the pending update for the first extension got installed.
1483 EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII( 1481 EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII(
1484 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); 1482 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0")));
1485 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1483 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
1486 "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0"))); 1484 "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0")));
1487 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1485 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
1488 "hpiknbiabeeppbpihjehijgoemciehgk/2"))); 1486 "hpiknbiabeeppbpihjehijgoemciehgk/2")));
1489 EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII( 1487 EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII(
1490 "hpiknbiabeeppbpihjehijgoemciehgk/3"))); 1488 "hpiknbiabeeppbpihjehijgoemciehgk/3")));
(...skipping 15 matching lines...) Expand all
1506 .DirName() 1504 .DirName()
1507 .AppendASCII("Preferences"); 1505 .AppendASCII("Preferences");
1508 1506
1509 InitializeInstalledExtensionService(pref_path, source_install_dir); 1507 InitializeInstalledExtensionService(pref_path, source_install_dir);
1510 1508
1511 // Verify there are no pending extensions initially. 1509 // Verify there are no pending extensions initially.
1512 EXPECT_FALSE(service_->pending_extension_manager()->HasPendingExtensions()); 1510 EXPECT_FALSE(service_->pending_extension_manager()->HasPendingExtensions());
1513 1511
1514 service_->Init(); 1512 service_->Init();
1515 // Wait for GarbageCollectExtensions task to complete. 1513 // Wait for GarbageCollectExtensions task to complete.
1516 loop_.RunUntilIdle(); 1514 base::RunLoop().RunUntilIdle();
1517 1515
1518 // These extensions are used by the extensions we test below, they must be 1516 // These extensions are used by the extensions we test below, they must be
1519 // installed. 1517 // installed.
1520 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1518 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
1521 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); 1519 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0")));
1522 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1520 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
1523 "hpiknbiabeeppbpihjehijgoemciehgk/2"))); 1521 "hpiknbiabeeppbpihjehijgoemciehgk/2")));
1524 1522
1525 // Each of these extensions should have been rejected because of dependencies 1523 // Each of these extensions should have been rejected because of dependencies
1526 // that cannot be satisfied. 1524 // that cannot be satisfied.
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 1744
1747 // Uninstall it and check that its killbit gets set. 1745 // Uninstall it and check that its killbit gets set.
1748 UninstallExtension(good_crx, false); 1746 UninstallExtension(good_crx, false);
1749 ValidateIntegerPref(good_crx, "location", 1747 ValidateIntegerPref(good_crx, "location",
1750 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1748 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1751 1749
1752 // Try to re-install it externally. This should fail because of the killbit. 1750 // Try to re-install it externally. This should fail because of the killbit.
1753 service_->OnExternalExtensionFileFound(good_crx, &version, 1751 service_->OnExternalExtensionFileFound(good_crx, &version,
1754 path, Manifest::EXTERNAL_PREF, 1752 path, Manifest::EXTERNAL_PREF,
1755 Extension::NO_FLAGS, false); 1753 Extension::NO_FLAGS, false);
1756 loop_.RunUntilIdle(); 1754 base::RunLoop().RunUntilIdle();
1757 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); 1755 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false));
1758 ValidateIntegerPref(good_crx, "location", 1756 ValidateIntegerPref(good_crx, "location",
1759 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1757 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1760 1758
1761 version = Version("1.0.0.1"); 1759 version = Version("1.0.0.1");
1762 // Repeat the same thing with a newer version of the extension. 1760 // Repeat the same thing with a newer version of the extension.
1763 path = data_dir_.AppendASCII("good2.crx"); 1761 path = data_dir_.AppendASCII("good2.crx");
1764 service_->OnExternalExtensionFileFound(good_crx, &version, 1762 service_->OnExternalExtensionFileFound(good_crx, &version,
1765 path, Manifest::EXTERNAL_PREF, 1763 path, Manifest::EXTERNAL_PREF,
1766 Extension::NO_FLAGS, false); 1764 Extension::NO_FLAGS, false);
1767 loop_.RunUntilIdle(); 1765 base::RunLoop().RunUntilIdle();
1768 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); 1766 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false));
1769 ValidateIntegerPref(good_crx, "location", 1767 ValidateIntegerPref(good_crx, "location",
1770 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1768 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1771 1769
1772 // Try adding the same extension from an external update URL. 1770 // Try adding the same extension from an external update URL.
1773 ASSERT_FALSE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( 1771 ASSERT_FALSE(service_->pending_extension_manager()->AddFromExternalUpdateUrl(
1774 good_crx, 1772 good_crx,
1775 GURL("http:://fake.update/url"), 1773 GURL("http:://fake.update/url"),
1776 Manifest::EXTERNAL_PREF_DOWNLOAD)); 1774 Manifest::EXTERNAL_PREF_DOWNLOAD));
1777 1775
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 base::FilePath path = data_dir_ 1878 base::FilePath path = data_dir_
1881 .AppendASCII("user_script_basic.user.js"); 1879 .AppendASCII("user_script_basic.user.js");
1882 1880
1883 ASSERT_TRUE(base::PathExists(path)); 1881 ASSERT_TRUE(base::PathExists(path));
1884 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); 1882 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
1885 installer->set_allow_silent_install(true); 1883 installer->set_allow_silent_install(true);
1886 installer->InstallUserScript( 1884 installer->InstallUserScript(
1887 path, 1885 path,
1888 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); 1886 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js"));
1889 1887
1890 loop_.RunUntilIdle(); 1888 base::RunLoop().RunUntilIdle();
1891 std::vector<string16> errors = GetErrors(); 1889 std::vector<string16> errors = GetErrors();
1892 EXPECT_TRUE(installed_) << "Nothing was installed."; 1890 EXPECT_TRUE(installed_) << "Nothing was installed.";
1893 EXPECT_FALSE(was_update_) << path.value(); 1891 EXPECT_FALSE(was_update_) << path.value();
1894 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; 1892 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded.";
1895 EXPECT_EQ(0u, errors.size()) << "There were errors: " 1893 EXPECT_EQ(0u, errors.size()) << "There were errors: "
1896 << JoinString(errors, ','); 1894 << JoinString(errors, ',');
1897 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << 1895 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) <<
1898 path.value(); 1896 path.value();
1899 1897
1900 installed_ = NULL; 1898 installed_ = NULL;
1901 was_update_ = false; 1899 was_update_ = false;
1902 loaded_.clear(); 1900 loaded_.clear();
1903 ExtensionErrorReporter::GetInstance()->ClearErrors(); 1901 ExtensionErrorReporter::GetInstance()->ClearErrors();
1904 } 1902 }
1905 1903
1906 // Extensions don't install during shutdown. 1904 // Extensions don't install during shutdown.
1907 TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) { 1905 TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) {
1908 InitializeEmptyExtensionService(); 1906 InitializeEmptyExtensionService();
1909 1907
1910 // Simulate shutdown. 1908 // Simulate shutdown.
1911 service_->set_browser_terminating_for_test(true); 1909 service_->set_browser_terminating_for_test(true);
1912 1910
1913 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1911 base::FilePath path = data_dir_.AppendASCII("good.crx");
1914 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); 1912 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
1915 installer->set_allow_silent_install(true); 1913 installer->set_allow_silent_install(true);
1916 installer->InstallCrx(path); 1914 installer->InstallCrx(path);
1917 loop_.RunUntilIdle(); 1915 base::RunLoop().RunUntilIdle();
1918 1916
1919 EXPECT_FALSE(installed_) << "Extension installed during shutdown."; 1917 EXPECT_FALSE(installed_) << "Extension installed during shutdown.";
1920 ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown."; 1918 ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown.";
1921 } 1919 }
1922 1920
1923 // This tests that the granted permissions preferences are correctly set when 1921 // This tests that the granted permissions preferences are correctly set when
1924 // installing an extension. 1922 // installing an extension.
1925 TEST_F(ExtensionServiceTest, GrantedPermissions) { 1923 TEST_F(ExtensionServiceTest, GrantedPermissions) {
1926 InitializeEmptyExtensionService(); 1924 InitializeEmptyExtensionService();
1927 base::FilePath path = data_dir_ 1925 base::FilePath path = data_dir_
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
2400 2398
2401 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { 2399 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) {
2402 // Load. 2400 // Load.
2403 InitializeEmptyExtensionService(); 2401 InitializeEmptyExtensionService();
2404 service_->Init(); 2402 service_->Init();
2405 2403
2406 base::FilePath extension_path = data_dir_ 2404 base::FilePath extension_path = data_dir_
2407 .AppendASCII("theme_i18n"); 2405 .AppendASCII("theme_i18n");
2408 2406
2409 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2407 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2410 loop_.RunUntilIdle(); 2408 base::RunLoop().RunUntilIdle();
2411 EXPECT_EQ(0u, GetErrors().size()); 2409 EXPECT_EQ(0u, GetErrors().size());
2412 ASSERT_EQ(1u, loaded_.size()); 2410 ASSERT_EQ(1u, loaded_.size());
2413 EXPECT_EQ(1u, service_->extensions()->size()); 2411 EXPECT_EQ(1u, service_->extensions()->size());
2414 const Extension* theme = service_->extensions()->begin()->get(); 2412 const Extension* theme = service_->extensions()->begin()->get();
2415 EXPECT_EQ("name", theme->name()); 2413 EXPECT_EQ("name", theme->name());
2416 EXPECT_EQ("description", theme->description()); 2414 EXPECT_EQ("description", theme->description());
2417 2415
2418 // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a 2416 // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a
2419 // temporary directory, but it automatically installs to the extension's 2417 // temporary directory, but it automatically installs to the extension's
2420 // directory, and we don't want to copy the whole extension for a unittest. 2418 // directory, and we don't want to copy the whole extension for a unittest.
(...skipping 21 matching lines...) Expand all
2442 AppendASCII("unpacked"). 2440 AppendASCII("unpacked").
2443 AppendASCII("manifest_with_key.json"); 2441 AppendASCII("manifest_with_key.json");
2444 2442
2445 ASSERT_TRUE(base::PathExists(manifest_no_key)); 2443 ASSERT_TRUE(base::PathExists(manifest_no_key));
2446 ASSERT_TRUE(base::PathExists(manifest_with_key)); 2444 ASSERT_TRUE(base::PathExists(manifest_with_key));
2447 2445
2448 // Load the unpacked extension with no key. 2446 // Load the unpacked extension with no key.
2449 base::CopyFile(manifest_no_key, manifest_path); 2447 base::CopyFile(manifest_no_key, manifest_path);
2450 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2448 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2451 2449
2452 loop_.RunUntilIdle(); 2450 base::RunLoop().RunUntilIdle();
2453 EXPECT_EQ(0u, GetErrors().size()); 2451 EXPECT_EQ(0u, GetErrors().size());
2454 ASSERT_EQ(1u, loaded_.size()); 2452 ASSERT_EQ(1u, loaded_.size());
2455 EXPECT_EQ(1u, service_->extensions()->size()); 2453 EXPECT_EQ(1u, service_->extensions()->size());
2456 2454
2457 // Add the key to the manifest. 2455 // Add the key to the manifest.
2458 base::CopyFile(manifest_with_key, manifest_path); 2456 base::CopyFile(manifest_with_key, manifest_path);
2459 loaded_.clear(); 2457 loaded_.clear();
2460 2458
2461 // Reload the extensions. 2459 // Reload the extensions.
2462 service_->ReloadExtensions(); 2460 service_->ReloadExtensions();
(...skipping 23 matching lines...) Expand all
2486 base::FilePath extension_path = temp.path(); 2484 base::FilePath extension_path = temp.path();
2487 base::FilePath manifest = extension_path.Append( 2485 base::FilePath manifest = extension_path.Append(
2488 extensions::kManifestFilename); 2486 extensions::kManifestFilename);
2489 base::FilePath icon_symlink = extension_path.AppendASCII("icon.png"); 2487 base::FilePath icon_symlink = extension_path.AppendASCII("icon.png");
2490 base::CopyFile(source_manifest, manifest); 2488 base::CopyFile(source_manifest, manifest);
2491 file_util::CreateSymbolicLink(source_icon, icon_symlink); 2489 file_util::CreateSymbolicLink(source_icon, icon_symlink);
2492 2490
2493 // Load extension. 2491 // Load extension.
2494 InitializeEmptyExtensionService(); 2492 InitializeEmptyExtensionService();
2495 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2493 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2496 loop_.RunUntilIdle(); 2494 base::RunLoop().RunUntilIdle();
2497 2495
2498 EXPECT_TRUE(GetErrors().empty()); 2496 EXPECT_TRUE(GetErrors().empty());
2499 ASSERT_EQ(1u, loaded_.size()); 2497 ASSERT_EQ(1u, loaded_.size());
2500 EXPECT_EQ(1u, service_->extensions()->size()); 2498 EXPECT_EQ(1u, service_->extensions()->size());
2501 } 2499 }
2502 #endif 2500 #endif
2503 2501
2504 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { 2502 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) {
2505 InitializeEmptyExtensionService(); 2503 InitializeEmptyExtensionService();
2506 service_->Init(); 2504 service_->Init();
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
2831 service_->GetExtensionById(good_crx, false)-> 2829 service_->GetExtensionById(good_crx, false)->
2832 version()->GetString()); 2830 version()->GetString());
2833 } 2831 }
2834 2832
2835 // Test updating a not-already-installed extension - this should fail 2833 // Test updating a not-already-installed extension - this should fail
2836 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) { 2834 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) {
2837 InitializeEmptyExtensionService(); 2835 InitializeEmptyExtensionService();
2838 2836
2839 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2837 base::FilePath path = data_dir_.AppendASCII("good.crx");
2840 UpdateExtension(good_crx, path, UPDATED); 2838 UpdateExtension(good_crx, path, UPDATED);
2841 loop_.RunUntilIdle(); 2839 base::RunLoop().RunUntilIdle();
2842 2840
2843 ASSERT_EQ(0u, service_->extensions()->size()); 2841 ASSERT_EQ(0u, service_->extensions()->size());
2844 ASSERT_FALSE(installed_); 2842 ASSERT_FALSE(installed_);
2845 ASSERT_EQ(0u, loaded_.size()); 2843 ASSERT_EQ(0u, loaded_.size());
2846 } 2844 }
2847 2845
2848 // Makes sure you can't downgrade an extension via UpdateExtension 2846 // Makes sure you can't downgrade an extension via UpdateExtension
2849 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { 2847 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) {
2850 InitializeEmptyExtensionService(); 2848 InitializeEmptyExtensionService();
2851 2849
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2936 // Start with version 2.0. 2934 // Start with version 2.0.
2937 DictionaryValue manifest; 2935 DictionaryValue manifest;
2938 manifest.SetString("version", "2.0"); 2936 manifest.SetString("version", "2.0");
2939 manifest.SetString("name", "LOAD Downgrade Test"); 2937 manifest.SetString("name", "LOAD Downgrade Test");
2940 manifest.SetInteger("manifest_version", 2); 2938 manifest.SetInteger("manifest_version", 2);
2941 2939
2942 JSONFileValueSerializer serializer(manifest_path); 2940 JSONFileValueSerializer serializer(manifest_path);
2943 ASSERT_TRUE(serializer.Serialize(manifest)); 2941 ASSERT_TRUE(serializer.Serialize(manifest));
2944 2942
2945 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2943 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2946 loop_.RunUntilIdle(); 2944 base::RunLoop().RunUntilIdle();
2947 2945
2948 EXPECT_EQ(0u, GetErrors().size()); 2946 EXPECT_EQ(0u, GetErrors().size());
2949 ASSERT_EQ(1u, loaded_.size()); 2947 ASSERT_EQ(1u, loaded_.size());
2950 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); 2948 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
2951 EXPECT_EQ(1u, service_->extensions()->size()); 2949 EXPECT_EQ(1u, service_->extensions()->size());
2952 EXPECT_EQ("2.0", loaded_[0]->VersionString()); 2950 EXPECT_EQ("2.0", loaded_[0]->VersionString());
2953 2951
2954 // Now set the version number to 1.0, reload the extensions and verify that 2952 // Now set the version number to 1.0, reload the extensions and verify that
2955 // the downgrade was accepted. 2953 // the downgrade was accepted.
2956 manifest.SetString("version", "1.0"); 2954 manifest.SetString("version", "1.0");
2957 ASSERT_TRUE(serializer.Serialize(manifest)); 2955 ASSERT_TRUE(serializer.Serialize(manifest));
2958 2956
2959 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2957 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2960 loop_.RunUntilIdle(); 2958 base::RunLoop().RunUntilIdle();
2961 2959
2962 EXPECT_EQ(0u, GetErrors().size()); 2960 EXPECT_EQ(0u, GetErrors().size());
2963 ASSERT_EQ(1u, loaded_.size()); 2961 ASSERT_EQ(1u, loaded_.size());
2964 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); 2962 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
2965 EXPECT_EQ(1u, service_->extensions()->size()); 2963 EXPECT_EQ(1u, service_->extensions()->size());
2966 EXPECT_EQ("1.0", loaded_[0]->VersionString()); 2964 EXPECT_EQ("1.0", loaded_[0]->VersionString());
2967 } 2965 }
2968 2966
2969 #if !defined(OS_CHROMEOS) 2967 #if !defined(OS_CHROMEOS)
2970 // LOAD extensions with plugins require approval. 2968 // LOAD extensions with plugins require approval.
(...skipping 15 matching lines...) Expand all
2986 service_->set_show_extensions_prompts(true); 2984 service_->set_show_extensions_prompts(true);
2987 2985
2988 // Start by canceling any install prompts. 2986 // Start by canceling any install prompts.
2989 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2987 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2990 switches::kAppsGalleryInstallAutoConfirmForTests, 2988 switches::kAppsGalleryInstallAutoConfirmForTests,
2991 "cancel"); 2989 "cancel");
2992 2990
2993 // The extension that has a plugin should not install. 2991 // The extension that has a plugin should not install.
2994 extensions::UnpackedInstaller::Create(service_)->Load( 2992 extensions::UnpackedInstaller::Create(service_)->Load(
2995 extension_with_plugin_path); 2993 extension_with_plugin_path);
2996 loop_.RunUntilIdle(); 2994 base::RunLoop().RunUntilIdle();
2997 EXPECT_EQ(0u, GetErrors().size()); 2995 EXPECT_EQ(0u, GetErrors().size());
2998 EXPECT_EQ(0u, loaded_.size()); 2996 EXPECT_EQ(0u, loaded_.size());
2999 EXPECT_EQ(0u, service_->extensions()->size()); 2997 EXPECT_EQ(0u, service_->extensions()->size());
3000 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 2998 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3001 2999
3002 // But the extension with no plugin should since there's no prompt. 3000 // But the extension with no plugin should since there's no prompt.
3003 ExtensionErrorReporter::GetInstance()->ClearErrors(); 3001 ExtensionErrorReporter::GetInstance()->ClearErrors();
3004 extensions::UnpackedInstaller::Create(service_)->Load( 3002 extensions::UnpackedInstaller::Create(service_)->Load(
3005 extension_no_plugin_path); 3003 extension_no_plugin_path);
3006 loop_.RunUntilIdle(); 3004 base::RunLoop().RunUntilIdle();
3007 EXPECT_EQ(0u, GetErrors().size()); 3005 EXPECT_EQ(0u, GetErrors().size());
3008 EXPECT_EQ(1u, loaded_.size()); 3006 EXPECT_EQ(1u, loaded_.size());
3009 EXPECT_EQ(1u, service_->extensions()->size()); 3007 EXPECT_EQ(1u, service_->extensions()->size());
3010 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 3008 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3011 EXPECT_TRUE(service_->extensions()->Contains(good2)); 3009 EXPECT_TRUE(service_->extensions()->Contains(good2));
3012 3010
3013 // The plugin extension should install if we accept the dialog. 3011 // The plugin extension should install if we accept the dialog.
3014 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 3012 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
3015 switches::kAppsGalleryInstallAutoConfirmForTests, 3013 switches::kAppsGalleryInstallAutoConfirmForTests,
3016 "accept"); 3014 "accept");
3017 3015
3018 ExtensionErrorReporter::GetInstance()->ClearErrors(); 3016 ExtensionErrorReporter::GetInstance()->ClearErrors();
3019 extensions::UnpackedInstaller::Create(service_)->Load( 3017 extensions::UnpackedInstaller::Create(service_)->Load(
3020 extension_with_plugin_path); 3018 extension_with_plugin_path);
3021 loop_.RunUntilIdle(); 3019 base::RunLoop().RunUntilIdle();
3022 EXPECT_EQ(0u, GetErrors().size()); 3020 EXPECT_EQ(0u, GetErrors().size());
3023 EXPECT_EQ(2u, loaded_.size()); 3021 EXPECT_EQ(2u, loaded_.size());
3024 EXPECT_EQ(2u, service_->extensions()->size()); 3022 EXPECT_EQ(2u, service_->extensions()->size());
3025 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 3023 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3026 EXPECT_TRUE(service_->extensions()->Contains(good1)); 3024 EXPECT_TRUE(service_->extensions()->Contains(good1));
3027 EXPECT_TRUE(service_->extensions()->Contains(good2)); 3025 EXPECT_TRUE(service_->extensions()->Contains(good2));
3028 3026
3029 // Make sure the granted permissions have been setup. 3027 // Make sure the granted permissions have been setup.
3030 scoped_refptr<PermissionSet> permissions( 3028 scoped_refptr<PermissionSet> permissions(
3031 service_->extension_prefs()->GetGrantedPermissions(good1)); 3029 service_->extension_prefs()->GetGrantedPermissions(good1));
3032 EXPECT_FALSE(permissions->IsEmpty()); 3030 EXPECT_FALSE(permissions->IsEmpty());
3033 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); 3031 EXPECT_TRUE(permissions->HasEffectiveFullAccess());
3034 EXPECT_FALSE(permissions->apis().empty()); 3032 EXPECT_FALSE(permissions->apis().empty());
3035 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); 3033 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin));
3036 3034
3037 // We should be able to reload the extension without getting another prompt. 3035 // We should be able to reload the extension without getting another prompt.
3038 loaded_.clear(); 3036 loaded_.clear();
3039 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 3037 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
3040 switches::kAppsGalleryInstallAutoConfirmForTests, 3038 switches::kAppsGalleryInstallAutoConfirmForTests,
3041 "cancel"); 3039 "cancel");
3042 3040
3043 service_->ReloadExtension(good1); 3041 service_->ReloadExtension(good1);
3044 loop_.RunUntilIdle(); 3042 base::RunLoop().RunUntilIdle();
3045 EXPECT_EQ(1u, loaded_.size()); 3043 EXPECT_EQ(1u, loaded_.size());
3046 EXPECT_EQ(2u, service_->extensions()->size()); 3044 EXPECT_EQ(2u, service_->extensions()->size());
3047 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 3045 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3048 } 3046 }
3049 #endif 3047 #endif
3050 3048
3051 namespace { 3049 namespace {
3052 3050
3053 bool IsExtension(const Extension* extension) { 3051 bool IsExtension(const Extension* extension) {
3054 return extension->GetType() == Manifest::TYPE_EXTENSION; 3052 return extension->GetType() == Manifest::TYPE_EXTENSION;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
3277 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { 3275 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) {
3278 InitializeEmptyExtensionService(); 3276 InitializeEmptyExtensionService();
3279 std::vector<std::string> blacklist; 3277 std::vector<std::string> blacklist;
3280 blacklist.push_back(good0); 3278 blacklist.push_back(good0);
3281 blacklist.push_back("invalid_id"); // an invalid id 3279 blacklist.push_back("invalid_id"); // an invalid id
3282 blacklist.push_back(good1); 3280 blacklist.push_back(good1);
3283 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, 3281 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist,
3284 "v1"); 3282 "v1");
3285 3283
3286 // Make sure pref is updated 3284 // Make sure pref is updated
3287 loop_.RunUntilIdle(); 3285 base::RunLoop().RunUntilIdle();
3288 3286
3289 // blacklist is set for good0,1,2 3287 // blacklist is set for good0,1,2
3290 ValidateBooleanPref(good0, "blacklist", true); 3288 ValidateBooleanPref(good0, "blacklist", true);
3291 ValidateBooleanPref(good1, "blacklist", true); 3289 ValidateBooleanPref(good1, "blacklist", true);
3292 // invalid_id should not be inserted to pref. 3290 // invalid_id should not be inserted to pref.
3293 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); 3291 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist"));
3294 3292
3295 // remove good1, add good2 3293 // remove good1, add good2
3296 blacklist.pop_back(); 3294 blacklist.pop_back();
3297 blacklist.push_back(good2); 3295 blacklist.push_back(good2);
(...skipping 16 matching lines...) Expand all
3314 const Extension* good = InstallCRX(path, INSTALL_NEW); 3312 const Extension* good = InstallCRX(path, INSTALL_NEW);
3315 EXPECT_EQ(good_crx, good->id()); 3313 EXPECT_EQ(good_crx, good->id());
3316 UpdateExtension(good_crx, path, FAILED_SILENTLY); 3314 UpdateExtension(good_crx, path, FAILED_SILENTLY);
3317 3315
3318 std::vector<std::string> blacklist; 3316 std::vector<std::string> blacklist;
3319 blacklist.push_back(good_crx); 3317 blacklist.push_back(good_crx);
3320 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, 3318 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist,
3321 "v1"); 3319 "v1");
3322 3320
3323 // Make sure pref is updated 3321 // Make sure pref is updated
3324 loop_.RunUntilIdle(); 3322 base::RunLoop().RunUntilIdle();
3325 3323
3326 // Now, the good_crx is blacklisted. 3324 // Now, the good_crx is blacklisted.
3327 ValidateBooleanPref(good_crx, "blacklist", true); 3325 ValidateBooleanPref(good_crx, "blacklist", true);
3328 EXPECT_EQ(0u, service_->extensions()->size()); 3326 EXPECT_EQ(0u, service_->extensions()->size());
3329 3327
3330 // Remove good_crx from blacklist 3328 // Remove good_crx from blacklist
3331 blacklist.pop_back(); 3329 blacklist.pop_back();
3332 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, 3330 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist,
3333 "v2"); 3331 "v2");
3334 3332
3335 // Make sure pref is updated 3333 // Make sure pref is updated
3336 loop_.RunUntilIdle(); 3334 base::RunLoop().RunUntilIdle();
3337 // blacklist value should not be set for good_crx 3335 // blacklist value should not be set for good_crx
3338 EXPECT_FALSE(IsPrefExist(good_crx, "blacklist")); 3336 EXPECT_FALSE(IsPrefExist(good_crx, "blacklist"));
3339 } 3337 }
3340 3338
3341 // Unload installed extension from blacklist. 3339 // Unload installed extension from blacklist.
3342 TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) { 3340 TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) {
3343 InitializeEmptyExtensionService(); 3341 InitializeEmptyExtensionService();
3344 3342
3345 // Fake the blacklisting of good_crx by pretending that we get an update 3343 // Fake the blacklisting of good_crx by pretending that we get an update
3346 // which includes it. 3344 // which includes it.
(...skipping 28 matching lines...) Expand all
3375 PrefService* prefs = service_->extension_prefs()->pref_service(); 3373 PrefService* prefs = service_->extension_prefs()->pref_service();
3376 whitelist.Append(base::Value::CreateStringValue(good_crx)); 3374 whitelist.Append(base::Value::CreateStringValue(good_crx));
3377 prefs->Set(prefs::kExtensionInstallAllowList, whitelist); 3375 prefs->Set(prefs::kExtensionInstallAllowList, whitelist);
3378 3376
3379 std::vector<std::string> blacklist; 3377 std::vector<std::string> blacklist;
3380 blacklist.push_back(good_crx); 3378 blacklist.push_back(good_crx);
3381 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, 3379 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist,
3382 "v1"); 3380 "v1");
3383 3381
3384 // Make sure pref is updated 3382 // Make sure pref is updated
3385 loop_.RunUntilIdle(); 3383 base::RunLoop().RunUntilIdle();
3386 3384
3387 // The good_crx is blacklisted and the whitelist doesn't negate it. 3385 // The good_crx is blacklisted and the whitelist doesn't negate it.
3388 ValidateBooleanPref(good_crx, "blacklist", true); 3386 ValidateBooleanPref(good_crx, "blacklist", true);
3389 EXPECT_EQ(0u, service_->extensions()->size()); 3387 EXPECT_EQ(0u, service_->extensions()->size());
3390 } 3388 }
3391 3389
3392 // Test loading extensions from the profile directory, except 3390 // Test loading extensions from the profile directory, except
3393 // blacklisted ones. 3391 // blacklisted ones.
3394 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { 3392 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) {
3395 // Initialize the test dir with a good Preferences/extensions. 3393 // Initialize the test dir with a good Preferences/extensions.
3396 base::FilePath source_install_dir = data_dir_ 3394 base::FilePath source_install_dir = data_dir_
3397 .AppendASCII("good") 3395 .AppendASCII("good")
3398 .AppendASCII("Extensions"); 3396 .AppendASCII("Extensions");
3399 base::FilePath pref_path = source_install_dir 3397 base::FilePath pref_path = source_install_dir
3400 .DirName() 3398 .DirName()
3401 .AppendASCII("Preferences"); 3399 .AppendASCII("Preferences");
3402 InitializeInstalledExtensionService(pref_path, source_install_dir); 3400 InitializeInstalledExtensionService(pref_path, source_install_dir);
3403 3401
3404 // Blacklist good1. 3402 // Blacklist good1.
3405 std::vector<std::string> blacklist; 3403 std::vector<std::string> blacklist;
3406 blacklist.push_back(good1); 3404 blacklist.push_back(good1);
3407 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, 3405 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist,
3408 "v1"); 3406 "v1");
3409 3407
3410 // Make sure pref is updated 3408 // Make sure pref is updated
3411 loop_.RunUntilIdle(); 3409 base::RunLoop().RunUntilIdle();
3412 3410
3413 ValidateBooleanPref(good1, "blacklist", true); 3411 ValidateBooleanPref(good1, "blacklist", true);
3414 3412
3415 // Load extensions. 3413 // Load extensions.
3416 service_->Init(); 3414 service_->Init();
3417 3415
3418 std::vector<string16> errors = GetErrors(); 3416 std::vector<string16> errors = GetErrors();
3419 for (std::vector<string16>::iterator err = errors.begin(); 3417 for (std::vector<string16>::iterator err = errors.begin();
3420 err != errors.end(); ++err) { 3418 err != errors.end(); ++err) {
3421 LOG(ERROR) << *err; 3419 LOG(ERROR) << *err;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3471 PrefService* prefs = profile_->GetPrefs(); 3469 PrefService* prefs = profile_->GetPrefs();
3472 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList); 3470 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList);
3473 ListValue* blacklist = update.Get(); 3471 ListValue* blacklist = update.Get();
3474 ASSERT_TRUE(blacklist != NULL); 3472 ASSERT_TRUE(blacklist != NULL);
3475 3473
3476 // Blacklist this extension. 3474 // Blacklist this extension.
3477 blacklist->Append(Value::CreateStringValue(good_crx)); 3475 blacklist->Append(Value::CreateStringValue(good_crx));
3478 } 3476 }
3479 3477
3480 // Extension should not be running now. 3478 // Extension should not be running now.
3481 loop_.RunUntilIdle(); 3479 base::RunLoop().RunUntilIdle();
3482 EXPECT_EQ(0u, service_->extensions()->size()); 3480 EXPECT_EQ(0u, service_->extensions()->size());
3483 } 3481 }
3484 3482
3485 // Tests that component extensions are not blacklisted by policy. 3483 // Tests that component extensions are not blacklisted by policy.
3486 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { 3484 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) {
3487 InitializeEmptyExtensionService(); 3485 InitializeEmptyExtensionService();
3488 3486
3489 // Blacklist everything. 3487 // Blacklist everything.
3490 { 3488 {
3491 ListPrefUpdate update(profile_->GetPrefs(), 3489 ListPrefUpdate update(profile_->GetPrefs(),
(...skipping 23 matching lines...) Expand all
3515 ASSERT_EQ(1u, service_->extensions()->size()); 3513 ASSERT_EQ(1u, service_->extensions()->size());
3516 EXPECT_TRUE(service_->GetExtensionById(good0, false)); 3514 EXPECT_TRUE(service_->GetExtensionById(good0, false));
3517 3515
3518 // Extension should not be uninstalled on blacklist changes. 3516 // Extension should not be uninstalled on blacklist changes.
3519 { 3517 {
3520 ListPrefUpdate update(profile_->GetPrefs(), 3518 ListPrefUpdate update(profile_->GetPrefs(),
3521 prefs::kExtensionInstallDenyList); 3519 prefs::kExtensionInstallDenyList);
3522 ListValue* blacklist = update.Get(); 3520 ListValue* blacklist = update.Get();
3523 blacklist->Append(Value::CreateStringValue(good0)); 3521 blacklist->Append(Value::CreateStringValue(good0));
3524 } 3522 }
3525 loop_.RunUntilIdle(); 3523 base::RunLoop().RunUntilIdle();
3526 ASSERT_EQ(1u, service_->extensions()->size()); 3524 ASSERT_EQ(1u, service_->extensions()->size());
3527 EXPECT_TRUE(service_->GetExtensionById(good0, false)); 3525 EXPECT_TRUE(service_->GetExtensionById(good0, false));
3528 } 3526 }
3529 3527
3530 // Tests that policy-installed extensions are not blacklisted by policy. 3528 // Tests that policy-installed extensions are not blacklisted by policy.
3531 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { 3529 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) {
3532 InitializeEmptyExtensionService(); 3530 InitializeEmptyExtensionService();
3533 3531
3534 { 3532 {
3535 // Blacklist everything. 3533 // Blacklist everything.
(...skipping 28 matching lines...) Expand all
3564 ASSERT_EQ(1u, service_->extensions()->size()); 3562 ASSERT_EQ(1u, service_->extensions()->size());
3565 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3563 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3566 3564
3567 // Blacklist update should not uninstall the extension. 3565 // Blacklist update should not uninstall the extension.
3568 { 3566 {
3569 ListPrefUpdate update(profile_->GetPrefs(), 3567 ListPrefUpdate update(profile_->GetPrefs(),
3570 prefs::kExtensionInstallDenyList); 3568 prefs::kExtensionInstallDenyList);
3571 ListValue* blacklist = update.Get(); 3569 ListValue* blacklist = update.Get();
3572 blacklist->Append(Value::CreateStringValue(good0)); 3570 blacklist->Append(Value::CreateStringValue(good0));
3573 } 3571 }
3574 loop_.RunUntilIdle(); 3572 base::RunLoop().RunUntilIdle();
3575 ASSERT_EQ(1u, service_->extensions()->size()); 3573 ASSERT_EQ(1u, service_->extensions()->size());
3576 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3574 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3577 } 3575 }
3578 3576
3579 // Tests that extensions cannot be installed if the policy provider prohibits 3577 // Tests that extensions cannot be installed if the policy provider prohibits
3580 // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). 3578 // it. This functionality is implemented in CrxInstaller::ConfirmInstall().
3581 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) { 3579 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) {
3582 InitializeEmptyExtensionService(); 3580 InitializeEmptyExtensionService();
3583 3581
3584 management_policy_->UnregisterAllProviders(); 3582 management_policy_->UnregisterAllProviders();
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
3907 InitializeExtensionProcessManager(); 3905 InitializeExtensionProcessManager();
3908 3906
3909 // Simple extension that should install without error. 3907 // Simple extension that should install without error.
3910 const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj"; 3908 const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj";
3911 base::FilePath ext = data_dir_ 3909 base::FilePath ext = data_dir_
3912 .AppendASCII("good") 3910 .AppendASCII("good")
3913 .AppendASCII("Extensions") 3911 .AppendASCII("Extensions")
3914 .AppendASCII(extension_id) 3912 .AppendASCII(extension_id)
3915 .AppendASCII("1.0.0.0"); 3913 .AppendASCII("1.0.0.0");
3916 extensions::UnpackedInstaller::Create(service_)->Load(ext); 3914 extensions::UnpackedInstaller::Create(service_)->Load(ext);
3917 loop_.RunUntilIdle(); 3915 base::RunLoop().RunUntilIdle();
3918 3916
3919 EXPECT_EQ(1u, service_->extensions()->size()); 3917 EXPECT_EQ(1u, service_->extensions()->size());
3920 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 3918 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3921 3919
3922 service_->ReloadExtension(extension_id); 3920 service_->ReloadExtension(extension_id);
3923 3921
3924 // Extension should be disabled now, waiting to be reloaded. 3922 // Extension should be disabled now, waiting to be reloaded.
3925 EXPECT_EQ(0u, service_->extensions()->size()); 3923 EXPECT_EQ(0u, service_->extensions()->size());
3926 EXPECT_EQ(1u, service_->disabled_extensions()->size()); 3924 EXPECT_EQ(1u, service_->disabled_extensions()->size());
3927 EXPECT_EQ(Extension::DISABLE_RELOAD, 3925 EXPECT_EQ(Extension::DISABLE_RELOAD,
3928 service_->extension_prefs()->GetDisableReasons(extension_id)); 3926 service_->extension_prefs()->GetDisableReasons(extension_id));
3929 3927
3930 // Reloading again should not crash. 3928 // Reloading again should not crash.
3931 service_->ReloadExtension(extension_id); 3929 service_->ReloadExtension(extension_id);
3932 3930
3933 // Finish reloading 3931 // Finish reloading
3934 loop_.RunUntilIdle(); 3932 base::RunLoop().RunUntilIdle();
3935 3933
3936 // Extension should be enabled again. 3934 // Extension should be enabled again.
3937 EXPECT_EQ(1u, service_->extensions()->size()); 3935 EXPECT_EQ(1u, service_->extensions()->size());
3938 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 3936 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3939 } 3937 }
3940 3938
3941 TEST_F(ExtensionServiceTest, UninstallExtension) { 3939 TEST_F(ExtensionServiceTest, UninstallExtension) {
3942 InitializeEmptyExtensionService(); 3940 InitializeEmptyExtensionService();
3943 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3941 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
3944 EXPECT_EQ(1u, service_->extensions()->size()); 3942 EXPECT_EQ(1u, service_->extensions()->size());
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
4062 4060
4063 // Unpacked extensions are not allowed to be installed if they have unsupported 4061 // Unpacked extensions are not allowed to be installed if they have unsupported
4064 // requirements. 4062 // requirements.
4065 TEST_F(ExtensionServiceTest, UnpackedRequirements) { 4063 TEST_F(ExtensionServiceTest, UnpackedRequirements) {
4066 InitializeEmptyExtensionService(); 4064 InitializeEmptyExtensionService();
4067 BlackListWebGL(); 4065 BlackListWebGL();
4068 4066
4069 base::FilePath path = data_dir_.AppendASCII("requirements") 4067 base::FilePath path = data_dir_.AppendASCII("requirements")
4070 .AppendASCII("v2_bad_requirements"); 4068 .AppendASCII("v2_bad_requirements");
4071 extensions::UnpackedInstaller::Create(service_)->Load(path); 4069 extensions::UnpackedInstaller::Create(service_)->Load(path);
4072 loop_.RunUntilIdle(); 4070 base::RunLoop().RunUntilIdle();
4073 EXPECT_EQ(1u, GetErrors().size()); 4071 EXPECT_EQ(1u, GetErrors().size());
4074 EXPECT_EQ(0u, service_->extensions()->size()); 4072 EXPECT_EQ(0u, service_->extensions()->size());
4075 } 4073 }
4076 4074
4077 class ExtensionCookieCallback { 4075 class ExtensionCookieCallback {
4078 public: 4076 public:
4079 ExtensionCookieCallback() 4077 ExtensionCookieCallback()
4080 : result_(false), 4078 : result_(false),
4081 weak_factory_(base::MessageLoop::current()) {} 4079 weak_factory_(base::MessageLoop::current()) {}
4082 4080
(...skipping 20 matching lines...) Expand all
4103 4101
4104 // Load a test extension. 4102 // Load a test extension.
4105 base::FilePath path = data_dir_; 4103 base::FilePath path = data_dir_;
4106 path = path.AppendASCII("good.crx"); 4104 path = path.AppendASCII("good.crx");
4107 const Extension* extension = InstallCRX(path, INSTALL_NEW); 4105 const Extension* extension = InstallCRX(path, INSTALL_NEW);
4108 ASSERT_TRUE(extension); 4106 ASSERT_TRUE(extension);
4109 GURL ext_url(extension->url()); 4107 GURL ext_url(extension->url());
4110 std::string origin_id = webkit_database::GetIdentifierFromOrigin(ext_url); 4108 std::string origin_id = webkit_database::GetIdentifierFromOrigin(ext_url);
4111 4109
4112 // Set a cookie for the extension. 4110 // Set a cookie for the extension.
4113 net::CookieMonster* cookie_monster = 4111 net::CookieStore* cookie_store =
4114 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> 4112 BrowserContext::GetDefaultStoragePartition(profile_.get())->
4115 cookie_store()->GetCookieMonster(); 4113 GetCookieStoreMap().GetForScheme(ext_url.scheme());
4114 ASSERT_TRUE(cookie_store);
4115 net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster();
4116 ASSERT_TRUE(cookie_monster); 4116 ASSERT_TRUE(cookie_monster);
4117 net::CookieOptions options; 4117 net::CookieOptions options;
4118 cookie_monster->SetCookieWithOptionsAsync( 4118 cookie_monster->SetCookieWithOptionsAsync(
4119 ext_url, "dummy=value", options, 4119 ext_url, "dummy=value", options,
4120 base::Bind(&ExtensionCookieCallback::SetCookieCallback, 4120 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
4121 base::Unretained(&callback))); 4121 base::Unretained(&callback)));
4122 loop_.RunUntilIdle(); 4122 base::RunLoop().RunUntilIdle();
4123 EXPECT_TRUE(callback.result_); 4123 EXPECT_TRUE(callback.result_);
4124 4124
4125 cookie_monster->GetAllCookiesForURLAsync( 4125 cookie_monster->GetAllCookiesForURLAsync(
4126 ext_url, 4126 ext_url,
4127 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4127 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4128 base::Unretained(&callback))); 4128 base::Unretained(&callback)));
4129 loop_.RunUntilIdle(); 4129 base::RunLoop().RunUntilIdle();
4130 EXPECT_EQ(1U, callback.list_.size()); 4130 EXPECT_EQ(1U, callback.list_.size());
4131 4131
4132 // Open a database. 4132 // Open a database.
4133 webkit_database::DatabaseTracker* db_tracker = 4133 webkit_database::DatabaseTracker* db_tracker =
4134 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 4134 BrowserContext::GetDefaultStoragePartition(profile_.get())->
4135 GetDatabaseTracker(); 4135 GetDatabaseTracker();
4136 string16 db_name = UTF8ToUTF16("db"); 4136 string16 db_name = UTF8ToUTF16("db");
4137 string16 description = UTF8ToUTF16("db_description"); 4137 string16 description = UTF8ToUTF16("db_description");
4138 int64 size; 4138 int64 size;
4139 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); 4139 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size);
(...skipping 20 matching lines...) Expand all
4160 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 4160 BrowserContext::GetDefaultStoragePartition(profile_.get())->
4161 GetIndexedDBContext(); 4161 GetIndexedDBContext();
4162 idb_context->SetTaskRunnerForTesting( 4162 idb_context->SetTaskRunnerForTesting(
4163 base::MessageLoop::current()->message_loop_proxy().get()); 4163 base::MessageLoop::current()->message_loop_proxy().get());
4164 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); 4164 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id);
4165 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); 4165 EXPECT_TRUE(file_util::CreateDirectory(idb_path));
4166 EXPECT_TRUE(base::DirectoryExists(idb_path)); 4166 EXPECT_TRUE(base::DirectoryExists(idb_path));
4167 4167
4168 // Uninstall the extension. 4168 // Uninstall the extension.
4169 service_->UninstallExtension(good_crx, false, NULL); 4169 service_->UninstallExtension(good_crx, false, NULL);
4170 loop_.RunUntilIdle(); 4170 base::RunLoop().RunUntilIdle();
4171 4171
4172 // Check that the cookie is gone. 4172 // Check that the cookie is gone.
4173 cookie_monster->GetAllCookiesForURLAsync( 4173 cookie_monster->GetAllCookiesForURLAsync(
4174 ext_url, 4174 ext_url,
4175 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4175 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4176 base::Unretained(&callback))); 4176 base::Unretained(&callback)));
4177 loop_.RunUntilIdle(); 4177 base::RunLoop().RunUntilIdle();
4178 EXPECT_EQ(0U, callback.list_.size()); 4178 EXPECT_EQ(0U, callback.list_.size());
4179 4179
4180 // The database should have vanished as well. 4180 // The database should have vanished as well.
4181 origins.clear(); 4181 origins.clear();
4182 db_tracker->GetAllOriginsInfo(&origins); 4182 db_tracker->GetAllOriginsInfo(&origins);
4183 EXPECT_EQ(0U, origins.size()); 4183 EXPECT_EQ(0U, origins.size());
4184 4184
4185 // Check that the LSO file has been removed. 4185 // Check that the LSO file has been removed.
4186 EXPECT_FALSE(base::PathExists(lso_file_path)); 4186 EXPECT_FALSE(base::PathExists(lso_file_path));
4187 4187
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4219 APIPermission::kUnlimitedStorage)); 4219 APIPermission::kUnlimitedStorage));
4220 EXPECT_TRUE(extension->web_extent().MatchesURL( 4220 EXPECT_TRUE(extension->web_extent().MatchesURL(
4221 extensions::AppLaunchInfo::GetFullLaunchURL(extension))); 4221 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
4222 const GURL origin2( 4222 const GURL origin2(
4223 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 4223 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
4224 EXPECT_EQ(origin1, origin2); 4224 EXPECT_EQ(origin1, origin2);
4225 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 4225 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
4226 IsStorageUnlimited(origin2)); 4226 IsStorageUnlimited(origin2));
4227 4227
4228 // Set a cookie for the extension. 4228 // Set a cookie for the extension.
4229 content::StoragePartition* partition =
4230 content::BrowserContext::GetDefaultStoragePartition(profile_.get());
4229 net::CookieMonster* cookie_monster = 4231 net::CookieMonster* cookie_monster =
4230 profile_->GetRequestContext()->GetURLRequestContext()-> 4232 partition->GetCookieStoreMap().GetForScheme(origin1.scheme())->
4231 cookie_store()->GetCookieMonster(); 4233 GetCookieMonster();
4232 ASSERT_TRUE(cookie_monster); 4234 ASSERT_TRUE(cookie_monster);
4233 net::CookieOptions options; 4235 net::CookieOptions options;
4234 cookie_monster->SetCookieWithOptionsAsync( 4236 cookie_monster->SetCookieWithOptionsAsync(
4235 origin1, "dummy=value", options, 4237 origin1, "dummy=value", options,
4236 base::Bind(&ExtensionCookieCallback::SetCookieCallback, 4238 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
4237 base::Unretained(&callback))); 4239 base::Unretained(&callback)));
4238 loop_.RunUntilIdle(); 4240 base::RunLoop().RunUntilIdle();
4239 EXPECT_TRUE(callback.result_); 4241 EXPECT_TRUE(callback.result_);
4240 4242
4241 cookie_monster->GetAllCookiesForURLAsync( 4243 cookie_monster->GetAllCookiesForURLAsync(
4242 origin1, 4244 origin1,
4243 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4245 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4244 base::Unretained(&callback))); 4246 base::Unretained(&callback)));
4245 loop_.RunUntilIdle(); 4247 base::RunLoop().RunUntilIdle();
4246 EXPECT_EQ(1U, callback.list_.size()); 4248 EXPECT_EQ(1U, callback.list_.size());
4247 4249
4248 // Open a database. 4250 // Open a database.
4249 webkit_database::DatabaseTracker* db_tracker = 4251 webkit_database::DatabaseTracker* db_tracker =
4250 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 4252 BrowserContext::GetDefaultStoragePartition(profile_.get())->
4251 GetDatabaseTracker(); 4253 GetDatabaseTracker();
4252 string16 db_name = UTF8ToUTF16("db"); 4254 string16 db_name = UTF8ToUTF16("db");
4253 string16 description = UTF8ToUTF16("db_description"); 4255 string16 description = UTF8ToUTF16("db_description");
4254 int64 size; 4256 int64 size;
4255 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); 4257 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size);
(...skipping 30 matching lines...) Expand all
4286 UninstallExtension(id1, false); 4288 UninstallExtension(id1, false);
4287 EXPECT_EQ(1u, service_->extensions()->size()); 4289 EXPECT_EQ(1u, service_->extensions()->size());
4288 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 4290 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
4289 IsStorageUnlimited(origin1)); 4291 IsStorageUnlimited(origin1));
4290 4292
4291 // Check that the cookie is still there. 4293 // Check that the cookie is still there.
4292 cookie_monster->GetAllCookiesForURLAsync( 4294 cookie_monster->GetAllCookiesForURLAsync(
4293 origin1, 4295 origin1,
4294 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4296 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4295 base::Unretained(&callback))); 4297 base::Unretained(&callback)));
4296 loop_.RunUntilIdle(); 4298 base::RunLoop().RunUntilIdle();
4297 EXPECT_EQ(1U, callback.list_.size()); 4299 EXPECT_EQ(1U, callback.list_.size());
4298 4300
4299 // Now uninstall the other. Storage should be cleared for the apps. 4301 // Now uninstall the other. Storage should be cleared for the apps.
4300 UninstallExtension(id2, false); 4302 UninstallExtension(id2, false);
4301 EXPECT_EQ(0u, service_->extensions()->size()); 4303 EXPECT_EQ(0u, service_->extensions()->size());
4302 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 4304 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
4303 IsStorageUnlimited(origin1)); 4305 IsStorageUnlimited(origin1));
4304 4306
4305 // Check that the cookie is gone. 4307 // Check that the cookie is gone.
4306 cookie_monster->GetAllCookiesForURLAsync( 4308 cookie_monster->GetAllCookiesForURLAsync(
4307 origin1, 4309 origin1,
4308 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4310 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4309 base::Unretained(&callback))); 4311 base::Unretained(&callback)));
4310 loop_.RunUntilIdle(); 4312 base::RunLoop().RunUntilIdle();
4311 EXPECT_EQ(0U, callback.list_.size()); 4313 EXPECT_EQ(0U, callback.list_.size());
4312 4314
4313 // The database should have vanished as well. 4315 // The database should have vanished as well.
4314 origins.clear(); 4316 origins.clear();
4315 db_tracker->GetAllOriginsInfo(&origins); 4317 db_tracker->GetAllOriginsInfo(&origins);
4316 EXPECT_EQ(0U, origins.size()); 4318 EXPECT_EQ(0U, origins.size());
4317 4319
4318 // Check that the LSO file has been removed. 4320 // Check that the LSO file has been removed.
4319 EXPECT_FALSE(base::PathExists(lso_file_path)); 4321 EXPECT_FALSE(base::PathExists(lso_file_path));
4320 4322
4321 // Check if the indexed db has disappeared too. 4323 // Check if the indexed db has disappeared too.
4322 EXPECT_FALSE(base::DirectoryExists(idb_path)); 4324 EXPECT_FALSE(base::DirectoryExists(idb_path));
4323 } 4325 }
4324 4326
4325 // Tests loading single extensions (like --load-extension) 4327 // Tests loading single extensions (like --load-extension)
4326 // Flaky crashes. http://crbug.com/231806 4328 // Flaky crashes. http://crbug.com/231806
4327 TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) { 4329 TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) {
4328 InitializeEmptyExtensionService(); 4330 InitializeEmptyExtensionService();
4329 4331
4330 base::FilePath ext1 = data_dir_ 4332 base::FilePath ext1 = data_dir_
4331 .AppendASCII("good") 4333 .AppendASCII("good")
4332 .AppendASCII("Extensions") 4334 .AppendASCII("Extensions")
4333 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 4335 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
4334 .AppendASCII("1.0.0.0"); 4336 .AppendASCII("1.0.0.0");
4335 extensions::UnpackedInstaller::Create(service_)->Load(ext1); 4337 extensions::UnpackedInstaller::Create(service_)->Load(ext1);
4336 loop_.RunUntilIdle(); 4338 base::RunLoop().RunUntilIdle();
4337 EXPECT_EQ(0u, GetErrors().size()); 4339 EXPECT_EQ(0u, GetErrors().size());
4338 ASSERT_EQ(1u, loaded_.size()); 4340 ASSERT_EQ(1u, loaded_.size());
4339 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); 4341 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
4340 EXPECT_EQ(1u, service_->extensions()->size()); 4342 EXPECT_EQ(1u, service_->extensions()->size());
4341 4343
4342 ValidatePrefKeyCount(1); 4344 ValidatePrefKeyCount(1);
4343 4345
4344 base::FilePath no_manifest = data_dir_ 4346 base::FilePath no_manifest = data_dir_
4345 .AppendASCII("bad") 4347 .AppendASCII("bad")
4346 // .AppendASCII("Extensions") 4348 // .AppendASCII("Extensions")
4347 .AppendASCII("cccccccccccccccccccccccccccccccc") 4349 .AppendASCII("cccccccccccccccccccccccccccccccc")
4348 .AppendASCII("1"); 4350 .AppendASCII("1");
4349 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest); 4351 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest);
4350 loop_.RunUntilIdle(); 4352 base::RunLoop().RunUntilIdle();
4351 EXPECT_EQ(1u, GetErrors().size()); 4353 EXPECT_EQ(1u, GetErrors().size());
4352 ASSERT_EQ(1u, loaded_.size()); 4354 ASSERT_EQ(1u, loaded_.size());
4353 EXPECT_EQ(1u, service_->extensions()->size()); 4355 EXPECT_EQ(1u, service_->extensions()->size());
4354 4356
4355 // Test uninstall. 4357 // Test uninstall.
4356 std::string id = loaded_[0]->id(); 4358 std::string id = loaded_[0]->id();
4357 EXPECT_FALSE(unloaded_id_.length()); 4359 EXPECT_FALSE(unloaded_id_.length());
4358 service_->UninstallExtension(id, false, NULL); 4360 service_->UninstallExtension(id, false, NULL);
4359 loop_.RunUntilIdle(); 4361 base::RunLoop().RunUntilIdle();
4360 EXPECT_EQ(id, unloaded_id_); 4362 EXPECT_EQ(id, unloaded_id_);
4361 ASSERT_EQ(0u, loaded_.size()); 4363 ASSERT_EQ(0u, loaded_.size());
4362 EXPECT_EQ(0u, service_->extensions()->size()); 4364 EXPECT_EQ(0u, service_->extensions()->size());
4363 } 4365 }
4364 4366
4365 // Tests that we generate IDs when they are not specified in the manifest for 4367 // Tests that we generate IDs when they are not specified in the manifest for
4366 // --load-extension. 4368 // --load-extension.
4367 TEST_F(ExtensionServiceTest, GenerateID) { 4369 TEST_F(ExtensionServiceTest, GenerateID) {
4368 InitializeEmptyExtensionService(); 4370 InitializeEmptyExtensionService();
4369 4371
4370 base::FilePath no_id_ext = data_dir_.AppendASCII("no_id"); 4372 base::FilePath no_id_ext = data_dir_.AppendASCII("no_id");
4371 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); 4373 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext);
4372 loop_.RunUntilIdle(); 4374 base::RunLoop().RunUntilIdle();
4373 EXPECT_EQ(0u, GetErrors().size()); 4375 EXPECT_EQ(0u, GetErrors().size());
4374 ASSERT_EQ(1u, loaded_.size()); 4376 ASSERT_EQ(1u, loaded_.size());
4375 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); 4377 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id()));
4376 EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED); 4378 EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED);
4377 4379
4378 ValidatePrefKeyCount(1); 4380 ValidatePrefKeyCount(1);
4379 4381
4380 std::string previous_id = loaded_[0]->id(); 4382 std::string previous_id = loaded_[0]->id();
4381 4383
4382 // If we reload the same path, we should get the same extension ID. 4384 // If we reload the same path, we should get the same extension ID.
4383 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); 4385 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext);
4384 loop_.RunUntilIdle(); 4386 base::RunLoop().RunUntilIdle();
4385 ASSERT_EQ(1u, loaded_.size()); 4387 ASSERT_EQ(1u, loaded_.size());
4386 ASSERT_EQ(previous_id, loaded_[0]->id()); 4388 ASSERT_EQ(previous_id, loaded_[0]->id());
4387 } 4389 }
4388 4390
4389 void ExtensionServiceTest::TestExternalProvider( 4391 void ExtensionServiceTest::TestExternalProvider(
4390 MockExtensionProvider* provider, Manifest::Location location) { 4392 MockExtensionProvider* provider, Manifest::Location location) {
4391 // Verify that starting with no providers loads no extensions. 4393 // Verify that starting with no providers loads no extensions.
4392 service_->Init(); 4394 service_->Init();
4393 ASSERT_EQ(0u, loaded_.size()); 4395 ASSERT_EQ(0u, loaded_.size());
4394 4396
(...skipping 17 matching lines...) Expand all
4412 ASSERT_EQ(location, loaded_[0]->location()); 4414 ASSERT_EQ(location, loaded_[0]->location());
4413 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4415 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4414 ValidatePrefKeyCount(1); 4416 ValidatePrefKeyCount(1);
4415 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4417 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4416 ValidateIntegerPref(good_crx, "location", location); 4418 ValidateIntegerPref(good_crx, "location", location);
4417 4419
4418 // Reload extensions without changing anything. The extension should be 4420 // Reload extensions without changing anything. The extension should be
4419 // loaded again. 4421 // loaded again.
4420 loaded_.clear(); 4422 loaded_.clear();
4421 service_->ReloadExtensions(); 4423 service_->ReloadExtensions();
4422 loop_.RunUntilIdle(); 4424 base::RunLoop().RunUntilIdle();
4423 ASSERT_EQ(0u, GetErrors().size()); 4425 ASSERT_EQ(0u, GetErrors().size());
4424 ASSERT_EQ(1u, loaded_.size()); 4426 ASSERT_EQ(1u, loaded_.size());
4425 ValidatePrefKeyCount(1); 4427 ValidatePrefKeyCount(1);
4426 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4428 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4427 ValidateIntegerPref(good_crx, "location", location); 4429 ValidateIntegerPref(good_crx, "location", location);
4428 4430
4429 // Now update the extension with a new version. We should get upgraded. 4431 // Now update the extension with a new version. We should get upgraded.
4430 source_path = source_path.DirName().AppendASCII("good2.crx"); 4432 source_path = source_path.DirName().AppendASCII("good2.crx");
4431 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4433 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4432 4434
4433 loaded_.clear(); 4435 loaded_.clear();
4434 service_->CheckForExternalUpdates(); 4436 service_->CheckForExternalUpdates();
4435 content::WindowedNotificationObserver( 4437 content::WindowedNotificationObserver(
4436 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4438 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4437 content::NotificationService::AllSources()).Wait(); 4439 content::NotificationService::AllSources()).Wait();
4438 ASSERT_EQ(0u, GetErrors().size()); 4440 ASSERT_EQ(0u, GetErrors().size());
4439 ASSERT_EQ(1u, loaded_.size()); 4441 ASSERT_EQ(1u, loaded_.size());
4440 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 4442 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
4441 ValidatePrefKeyCount(1); 4443 ValidatePrefKeyCount(1);
4442 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4444 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4443 ValidateIntegerPref(good_crx, "location", location); 4445 ValidateIntegerPref(good_crx, "location", location);
4444 4446
4445 // Uninstall the extension and reload. Nothing should happen because the 4447 // Uninstall the extension and reload. Nothing should happen because the
4446 // preference should prevent us from reinstalling. 4448 // preference should prevent us from reinstalling.
4447 std::string id = loaded_[0]->id(); 4449 std::string id = loaded_[0]->id();
4448 bool no_uninstall = 4450 bool no_uninstall =
4449 management_policy_->MustRemainEnabled(loaded_[0].get(), NULL); 4451 management_policy_->MustRemainEnabled(loaded_[0].get(), NULL);
4450 service_->UninstallExtension(id, false, NULL); 4452 service_->UninstallExtension(id, false, NULL);
4451 loop_.RunUntilIdle(); 4453 base::RunLoop().RunUntilIdle();
4452 4454
4453 base::FilePath install_path = extensions_install_dir_.AppendASCII(id); 4455 base::FilePath install_path = extensions_install_dir_.AppendASCII(id);
4454 if (no_uninstall) { 4456 if (no_uninstall) {
4455 // Policy controlled extensions should not have been touched by uninstall. 4457 // Policy controlled extensions should not have been touched by uninstall.
4456 ASSERT_TRUE(base::PathExists(install_path)); 4458 ASSERT_TRUE(base::PathExists(install_path));
4457 } else { 4459 } else {
4458 // The extension should also be gone from the install directory. 4460 // The extension should also be gone from the install directory.
4459 ASSERT_FALSE(base::PathExists(install_path)); 4461 ASSERT_FALSE(base::PathExists(install_path));
4460 loaded_.clear(); 4462 loaded_.clear();
4461 service_->CheckForExternalUpdates(); 4463 service_->CheckForExternalUpdates();
4462 loop_.RunUntilIdle(); 4464 base::RunLoop().RunUntilIdle();
4463 ASSERT_EQ(0u, loaded_.size()); 4465 ASSERT_EQ(0u, loaded_.size());
4464 ValidatePrefKeyCount(1); 4466 ValidatePrefKeyCount(1);
4465 ValidateIntegerPref(good_crx, "state", 4467 ValidateIntegerPref(good_crx, "state",
4466 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 4468 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
4467 ValidateIntegerPref(good_crx, "location", location); 4469 ValidateIntegerPref(good_crx, "location", location);
4468 4470
4469 // Now clear the preference and reinstall. 4471 // Now clear the preference and reinstall.
4470 SetPrefInteg(good_crx, "state", Extension::ENABLED); 4472 SetPrefInteg(good_crx, "state", Extension::ENABLED);
4471 4473
4472 loaded_.clear(); 4474 loaded_.clear();
4473 service_->CheckForExternalUpdates(); 4475 service_->CheckForExternalUpdates();
4474 content::WindowedNotificationObserver( 4476 content::WindowedNotificationObserver(
4475 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4477 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4476 content::NotificationService::AllSources()).Wait(); 4478 content::NotificationService::AllSources()).Wait();
4477 ASSERT_EQ(1u, loaded_.size()); 4479 ASSERT_EQ(1u, loaded_.size());
4478 } 4480 }
4479 ValidatePrefKeyCount(1); 4481 ValidatePrefKeyCount(1);
4480 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4482 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4481 ValidateIntegerPref(good_crx, "location", location); 4483 ValidateIntegerPref(good_crx, "location", location);
4482 4484
4483 if (management_policy_->MustRemainEnabled(loaded_[0].get(), NULL)) { 4485 if (management_policy_->MustRemainEnabled(loaded_[0].get(), NULL)) {
4484 EXPECT_EQ(2, provider->visit_count()); 4486 EXPECT_EQ(2, provider->visit_count());
4485 } else { 4487 } else {
4486 // Now test an externally triggered uninstall (deleting the registry key or 4488 // Now test an externally triggered uninstall (deleting the registry key or
4487 // the pref entry). 4489 // the pref entry).
4488 provider->RemoveExtension(good_crx); 4490 provider->RemoveExtension(good_crx);
4489 4491
4490 loaded_.clear(); 4492 loaded_.clear();
4491 service_->OnExternalProviderReady(provider); 4493 service_->OnExternalProviderReady(provider);
4492 loop_.RunUntilIdle(); 4494 base::RunLoop().RunUntilIdle();
4493 ASSERT_EQ(0u, loaded_.size()); 4495 ASSERT_EQ(0u, loaded_.size());
4494 ValidatePrefKeyCount(0); 4496 ValidatePrefKeyCount(0);
4495 4497
4496 // The extension should also be gone from the install directory. 4498 // The extension should also be gone from the install directory.
4497 ASSERT_FALSE(base::PathExists(install_path)); 4499 ASSERT_FALSE(base::PathExists(install_path));
4498 4500
4499 // Now test the case where user uninstalls and then the extension is removed 4501 // Now test the case where user uninstalls and then the extension is removed
4500 // from the external provider. 4502 // from the external provider.
4501 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4503 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4502 service_->CheckForExternalUpdates(); 4504 service_->CheckForExternalUpdates();
4503 content::WindowedNotificationObserver( 4505 content::WindowedNotificationObserver(
4504 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4506 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4505 content::NotificationService::AllSources()).Wait(); 4507 content::NotificationService::AllSources()).Wait();
4506 4508
4507 ASSERT_EQ(1u, loaded_.size()); 4509 ASSERT_EQ(1u, loaded_.size());
4508 ASSERT_EQ(0u, GetErrors().size()); 4510 ASSERT_EQ(0u, GetErrors().size());
4509 4511
4510 // User uninstalls. 4512 // User uninstalls.
4511 loaded_.clear(); 4513 loaded_.clear();
4512 service_->UninstallExtension(id, false, NULL); 4514 service_->UninstallExtension(id, false, NULL);
4513 loop_.RunUntilIdle(); 4515 base::RunLoop().RunUntilIdle();
4514 ASSERT_EQ(0u, loaded_.size()); 4516 ASSERT_EQ(0u, loaded_.size());
4515 4517
4516 // Then remove the extension from the extension provider. 4518 // Then remove the extension from the extension provider.
4517 provider->RemoveExtension(good_crx); 4519 provider->RemoveExtension(good_crx);
4518 4520
4519 // Should still be at 0. 4521 // Should still be at 0.
4520 loaded_.clear(); 4522 loaded_.clear();
4521 extensions::InstalledLoader(service_).LoadAllExtensions(); 4523 extensions::InstalledLoader(service_).LoadAllExtensions();
4522 loop_.RunUntilIdle(); 4524 base::RunLoop().RunUntilIdle();
4523 ASSERT_EQ(0u, loaded_.size()); 4525 ASSERT_EQ(0u, loaded_.size());
4524 ValidatePrefKeyCount(1); 4526 ValidatePrefKeyCount(1);
4525 4527
4526 EXPECT_EQ(5, provider->visit_count()); 4528 EXPECT_EQ(5, provider->visit_count());
4527 } 4529 }
4528 } 4530 }
4529 4531
4530 // Tests the external installation feature 4532 // Tests the external installation feature
4531 #if defined(OS_WIN) 4533 #if defined(OS_WIN)
4532 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { 4534 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
4607 set_extensions_enabled(false); 4609 set_extensions_enabled(false);
4608 4610
4609 service_->Init(); 4611 service_->Init();
4610 4612
4611 ASSERT_EQ(0u, GetErrors().size()); 4613 ASSERT_EQ(0u, GetErrors().size());
4612 ASSERT_EQ(0u, loaded_.size()); 4614 ASSERT_EQ(0u, loaded_.size());
4613 4615
4614 // Verify that it's not the disabled extensions flag causing it not to load. 4616 // Verify that it's not the disabled extensions flag causing it not to load.
4615 set_extensions_enabled(true); 4617 set_extensions_enabled(true);
4616 service_->ReloadExtensions(); 4618 service_->ReloadExtensions();
4617 loop_.RunUntilIdle(); 4619 base::RunLoop().RunUntilIdle();
4618 4620
4619 ASSERT_EQ(0u, GetErrors().size()); 4621 ASSERT_EQ(0u, GetErrors().size());
4620 ASSERT_EQ(0u, loaded_.size()); 4622 ASSERT_EQ(0u, loaded_.size());
4621 } 4623 }
4622 4624
4623 // Test that running multiple update checks simultaneously does not 4625 // Test that running multiple update checks simultaneously does not
4624 // keep the update from succeeding. 4626 // keep the update from succeeding.
4625 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { 4627 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) {
4626 InitializeEmptyExtensionService(); 4628 InitializeEmptyExtensionService();
4627 4629
4628 MockExtensionProvider* provider = 4630 MockExtensionProvider* provider =
4629 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 4631 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
4630 AddMockExternalProvider(provider); 4632 AddMockExternalProvider(provider);
4631 4633
4632 // Verify that starting with no providers loads no extensions. 4634 // Verify that starting with no providers loads no extensions.
4633 service_->Init(); 4635 service_->Init();
4634 ASSERT_EQ(0u, loaded_.size()); 4636 ASSERT_EQ(0u, loaded_.size());
4635 4637
4636 // Start two checks for updates. 4638 // Start two checks for updates.
4637 provider->set_visit_count(0); 4639 provider->set_visit_count(0);
4638 service_->CheckForExternalUpdates(); 4640 service_->CheckForExternalUpdates();
4639 service_->CheckForExternalUpdates(); 4641 service_->CheckForExternalUpdates();
4640 loop_.RunUntilIdle(); 4642 base::RunLoop().RunUntilIdle();
4641 4643
4642 // Two calls should cause two checks for external extensions. 4644 // Two calls should cause two checks for external extensions.
4643 EXPECT_EQ(2, provider->visit_count()); 4645 EXPECT_EQ(2, provider->visit_count());
4644 EXPECT_EQ(0u, GetErrors().size()); 4646 EXPECT_EQ(0u, GetErrors().size());
4645 EXPECT_EQ(0u, loaded_.size()); 4647 EXPECT_EQ(0u, loaded_.size());
4646 4648
4647 // Register a test extension externally using the mock registry provider. 4649 // Register a test extension externally using the mock registry provider.
4648 base::FilePath source_path = data_dir_.AppendASCII("good.crx"); 4650 base::FilePath source_path = data_dir_.AppendASCII("good.crx");
4649 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4651 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4650 4652
(...skipping 11 matching lines...) Expand all
4662 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); 4664 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location());
4663 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4665 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4664 ValidatePrefKeyCount(1); 4666 ValidatePrefKeyCount(1);
4665 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4667 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4666 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF); 4668 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF);
4667 4669
4668 provider->RemoveExtension(good_crx); 4670 provider->RemoveExtension(good_crx);
4669 provider->set_visit_count(0); 4671 provider->set_visit_count(0);
4670 service_->CheckForExternalUpdates(); 4672 service_->CheckForExternalUpdates();
4671 service_->CheckForExternalUpdates(); 4673 service_->CheckForExternalUpdates();
4672 loop_.RunUntilIdle(); 4674 base::RunLoop().RunUntilIdle();
4673 4675
4674 // Two calls should cause two checks for external extensions. 4676 // Two calls should cause two checks for external extensions.
4675 // Because the external source no longer includes good_crx, 4677 // Because the external source no longer includes good_crx,
4676 // good_crx will be uninstalled. So, expect that no extensions 4678 // good_crx will be uninstalled. So, expect that no extensions
4677 // are loaded. 4679 // are loaded.
4678 EXPECT_EQ(2, provider->visit_count()); 4680 EXPECT_EQ(2, provider->visit_count());
4679 EXPECT_EQ(0u, GetErrors().size()); 4681 EXPECT_EQ(0u, GetErrors().size());
4680 EXPECT_EQ(0u, loaded_.size()); 4682 EXPECT_EQ(0u, loaded_.size());
4681 } 4683 }
4682 4684
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
4934 TEST(ExtensionServiceTestSimple, Enabledness) { 4936 TEST(ExtensionServiceTestSimple, Enabledness) {
4935 // Make sure the PluginService singleton is destroyed at the end of the test. 4937 // Make sure the PluginService singleton is destroyed at the end of the test.
4936 base::ShadowingAtExitManager at_exit_manager; 4938 base::ShadowingAtExitManager at_exit_manager;
4937 #if defined(ENABLE_PLUGINS) 4939 #if defined(ENABLE_PLUGINS)
4938 content::PluginService::GetInstance()->Init(); 4940 content::PluginService::GetInstance()->Init();
4939 content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting(); 4941 content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting();
4940 #endif 4942 #endif
4941 4943
4942 ExtensionErrorReporter::Init(false); // no noisy errors 4944 ExtensionErrorReporter::Init(false); // no noisy errors
4943 ExtensionsReadyRecorder recorder; 4945 ExtensionsReadyRecorder recorder;
4946 content::TestBrowserThreadBundle thread_bundle;
4944 scoped_ptr<TestingProfile> profile(new TestingProfile()); 4947 scoped_ptr<TestingProfile> profile(new TestingProfile());
4945 base::MessageLoop loop;
4946 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop);
4947 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop);
4948 #if defined OS_CHROMEOS 4948 #if defined OS_CHROMEOS
4949 chromeos::ScopedTestDeviceSettingsService device_settings_service; 4949 chromeos::ScopedTestDeviceSettingsService device_settings_service;
4950 chromeos::ScopedTestCrosSettings cros_settings; 4950 chromeos::ScopedTestCrosSettings cros_settings;
4951 scoped_ptr<chromeos::ScopedTestUserManager> user_manager( 4951 scoped_ptr<chromeos::ScopedTestUserManager> user_manager(
4952 new chromeos::ScopedTestUserManager); 4952 new chromeos::ScopedTestUserManager);
4953 #endif 4953 #endif
4954 scoped_ptr<CommandLine> command_line; 4954 scoped_ptr<CommandLine> command_line;
4955 base::FilePath install_dir = profile->GetPath() 4955 base::FilePath install_dir = profile->GetPath()
4956 .AppendASCII(extensions::kInstallDirectoryName); 4956 .AppendASCII(extensions::kInstallDirectoryName);
4957 4957
4958 // By default, we are enabled. 4958 // By default, we are enabled.
4959 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); 4959 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
4960 ExtensionService* service = static_cast<extensions::TestExtensionSystem*>( 4960 ExtensionService* service = static_cast<extensions::TestExtensionSystem*>(
4961 ExtensionSystem::Get(profile.get()))-> 4961 ExtensionSystem::Get(profile.get()))->
4962 CreateExtensionService( 4962 CreateExtensionService(
4963 command_line.get(), 4963 command_line.get(),
4964 install_dir, 4964 install_dir,
4965 false); 4965 false);
4966 EXPECT_TRUE(service->extensions_enabled()); 4966 EXPECT_TRUE(service->extensions_enabled());
4967 service->Init(); 4967 service->Init();
4968 loop.RunUntilIdle(); 4968 base::RunLoop().RunUntilIdle();
4969 EXPECT_TRUE(recorder.ready()); 4969 EXPECT_TRUE(recorder.ready());
4970 #if defined OS_CHROMEOS 4970 #if defined OS_CHROMEOS
4971 user_manager.reset(); 4971 user_manager.reset();
4972 #endif 4972 #endif
4973 4973
4974 // If either the command line or pref is set, we are disabled. 4974 // If either the command line or pref is set, we are disabled.
4975 recorder.set_ready(false); 4975 recorder.set_ready(false);
4976 profile.reset(new TestingProfile()); 4976 profile.reset(new TestingProfile());
4977 command_line->AppendSwitch(switches::kDisableExtensions); 4977 command_line->AppendSwitch(switches::kDisableExtensions);
4978 service = static_cast<extensions::TestExtensionSystem*>( 4978 service = static_cast<extensions::TestExtensionSystem*>(
4979 ExtensionSystem::Get(profile.get()))-> 4979 ExtensionSystem::Get(profile.get()))->
4980 CreateExtensionService( 4980 CreateExtensionService(
4981 command_line.get(), 4981 command_line.get(),
4982 install_dir, 4982 install_dir,
4983 false); 4983 false);
4984 EXPECT_FALSE(service->extensions_enabled()); 4984 EXPECT_FALSE(service->extensions_enabled());
4985 service->Init(); 4985 service->Init();
4986 loop.RunUntilIdle(); 4986 base::RunLoop().RunUntilIdle();
4987 EXPECT_TRUE(recorder.ready()); 4987 EXPECT_TRUE(recorder.ready());
4988 4988
4989 recorder.set_ready(false); 4989 recorder.set_ready(false);
4990 profile.reset(new TestingProfile()); 4990 profile.reset(new TestingProfile());
4991 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 4991 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
4992 service = static_cast<extensions::TestExtensionSystem*>( 4992 service = static_cast<extensions::TestExtensionSystem*>(
4993 ExtensionSystem::Get(profile.get()))-> 4993 ExtensionSystem::Get(profile.get()))->
4994 CreateExtensionService( 4994 CreateExtensionService(
4995 command_line.get(), 4995 command_line.get(),
4996 install_dir, 4996 install_dir,
4997 false); 4997 false);
4998 EXPECT_FALSE(service->extensions_enabled()); 4998 EXPECT_FALSE(service->extensions_enabled());
4999 service->Init(); 4999 service->Init();
5000 loop.RunUntilIdle(); 5000 base::RunLoop().RunUntilIdle();
5001 EXPECT_TRUE(recorder.ready()); 5001 EXPECT_TRUE(recorder.ready());
5002 5002
5003 recorder.set_ready(false); 5003 recorder.set_ready(false);
5004 profile.reset(new TestingProfile()); 5004 profile.reset(new TestingProfile());
5005 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 5005 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
5006 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); 5006 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
5007 service = static_cast<extensions::TestExtensionSystem*>( 5007 service = static_cast<extensions::TestExtensionSystem*>(
5008 ExtensionSystem::Get(profile.get()))-> 5008 ExtensionSystem::Get(profile.get()))->
5009 CreateExtensionService( 5009 CreateExtensionService(
5010 command_line.get(), 5010 command_line.get(),
5011 install_dir, 5011 install_dir,
5012 false); 5012 false);
5013 EXPECT_FALSE(service->extensions_enabled()); 5013 EXPECT_FALSE(service->extensions_enabled());
5014 service->Init(); 5014 service->Init();
5015 loop.RunUntilIdle(); 5015 base::RunLoop().RunUntilIdle();
5016 EXPECT_TRUE(recorder.ready()); 5016 EXPECT_TRUE(recorder.ready());
5017 5017
5018 // Explicitly delete all the resources used in this test. 5018 // Explicitly delete all the resources used in this test.
5019 profile.reset(); 5019 profile.reset();
5020 service = NULL; 5020 service = NULL;
5021 // Execute any pending deletion tasks. 5021 // Execute any pending deletion tasks.
5022 loop.RunUntilIdle(); 5022 base::RunLoop().RunUntilIdle();
5023 } 5023 }
5024 5024
5025 // Test loading extensions that require limited and unlimited storage quotas. 5025 // Test loading extensions that require limited and unlimited storage quotas.
5026 TEST_F(ExtensionServiceTest, StorageQuota) { 5026 TEST_F(ExtensionServiceTest, StorageQuota) {
5027 InitializeEmptyExtensionService(); 5027 InitializeEmptyExtensionService();
5028 5028
5029 base::FilePath extensions_path = data_dir_ 5029 base::FilePath extensions_path = data_dir_
5030 .AppendASCII("storage_quota"); 5030 .AppendASCII("storage_quota");
5031 5031
5032 base::FilePath limited_quota_ext = 5032 base::FilePath limited_quota_ext =
5033 extensions_path.AppendASCII("limited_quota") 5033 extensions_path.AppendASCII("limited_quota")
5034 .AppendASCII("1.0"); 5034 .AppendASCII("1.0");
5035 5035
5036 // The old permission name for unlimited quota was "unlimited_storage", but 5036 // The old permission name for unlimited quota was "unlimited_storage", but
5037 // we changed it to "unlimitedStorage". This tests both versions. 5037 // we changed it to "unlimitedStorage". This tests both versions.
5038 base::FilePath unlimited_quota_ext = 5038 base::FilePath unlimited_quota_ext =
5039 extensions_path.AppendASCII("unlimited_quota") 5039 extensions_path.AppendASCII("unlimited_quota")
5040 .AppendASCII("1.0"); 5040 .AppendASCII("1.0");
5041 base::FilePath unlimited_quota_ext2 = 5041 base::FilePath unlimited_quota_ext2 =
5042 extensions_path.AppendASCII("unlimited_quota") 5042 extensions_path.AppendASCII("unlimited_quota")
5043 .AppendASCII("2.0"); 5043 .AppendASCII("2.0");
5044 extensions::UnpackedInstaller::Create(service_)->Load(limited_quota_ext); 5044 extensions::UnpackedInstaller::Create(service_)->Load(limited_quota_ext);
5045 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext); 5045 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext);
5046 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext2); 5046 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext2);
5047 loop_.RunUntilIdle(); 5047 base::RunLoop().RunUntilIdle();
5048 5048
5049 ASSERT_EQ(3u, loaded_.size()); 5049 ASSERT_EQ(3u, loaded_.size());
5050 EXPECT_TRUE(profile_.get()); 5050 EXPECT_TRUE(profile_.get());
5051 EXPECT_FALSE(profile_->IsOffTheRecord()); 5051 EXPECT_FALSE(profile_->IsOffTheRecord());
5052 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 5052 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
5053 loaded_[0]->url())); 5053 loaded_[0]->url()));
5054 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 5054 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
5055 loaded_[1]->url())); 5055 loaded_[1]->url()));
5056 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 5056 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
5057 loaded_[2]->url())); 5057 loaded_[2]->url()));
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
6203 // needs to know about. 6203 // needs to know about.
6204 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6204 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
6205 6205
6206 // This is a normal extension, installed normally. 6206 // This is a normal extension, installed normally.
6207 // This should NOT trigger an alert. 6207 // This should NOT trigger an alert.
6208 set_extensions_enabled(true); 6208 set_extensions_enabled(true);
6209 base::FilePath path = data_dir_.AppendASCII("good.crx"); 6209 base::FilePath path = data_dir_.AppendASCII("good.crx");
6210 InstallCRX(path, INSTALL_NEW); 6210 InstallCRX(path, INSTALL_NEW);
6211 6211
6212 service_->CheckForExternalUpdates(); 6212 service_->CheckForExternalUpdates();
6213 loop_.RunUntilIdle(); 6213 base::RunLoop().RunUntilIdle();
6214 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6214 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
6215 6215
6216 // A hosted app, installed externally. 6216 // A hosted app, installed externally.
6217 // This should NOT trigger an alert. 6217 // This should NOT trigger an alert.
6218 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 6218 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
6219 data_dir_.AppendASCII("hosted_app.crx")); 6219 data_dir_.AppendASCII("hosted_app.crx"));
6220 6220
6221 service_->CheckForExternalUpdates(); 6221 service_->CheckForExternalUpdates();
6222 content::WindowedNotificationObserver( 6222 content::WindowedNotificationObserver(
6223 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6223 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
6378 content::NotificationService::AllSources(), id_set); 6378 content::NotificationService::AllSources(), id_set);
6379 6379
6380 // Installation should be allowed but the extension should never have been 6380 // Installation should be allowed but the extension should never have been
6381 // loaded and it should be blacklisted in prefs. 6381 // loaded and it should be blacklisted in prefs.
6382 service_->OnExtensionInstalled( 6382 service_->OnExtensionInstalled(
6383 extension.get(), 6383 extension.get(),
6384 syncer::StringOrdinal(), 6384 syncer::StringOrdinal(),
6385 false /* has requirement errors */, 6385 false /* has requirement errors */,
6386 extensions::Blacklist::BLACKLISTED, 6386 extensions::Blacklist::BLACKLISTED,
6387 false /* wait for idle */); 6387 false /* wait for idle */);
6388 loop_.RunUntilIdle(); 6388 base::RunLoop().RunUntilIdle();
6389 6389
6390 // Extension was installed but not loaded. 6390 // Extension was installed but not loaded.
6391 EXPECT_TRUE(notifications.CheckNotifications( 6391 EXPECT_TRUE(notifications.CheckNotifications(
6392 chrome::NOTIFICATION_EXTENSION_INSTALLED)); 6392 chrome::NOTIFICATION_EXTENSION_INSTALLED));
6393 6393
6394 EXPECT_TRUE(service_->GetInstalledExtension(id)); 6394 EXPECT_TRUE(service_->GetInstalledExtension(id));
6395 EXPECT_FALSE(service_->extensions()->Contains(id)); 6395 EXPECT_FALSE(service_->extensions()->Contains(id));
6396 EXPECT_TRUE(service_->blacklisted_extensions()->Contains(id)); 6396 EXPECT_TRUE(service_->blacklisted_extensions()->Contains(id));
6397 EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id)); 6397 EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id));
6398 EXPECT_TRUE( 6398 EXPECT_TRUE(
6399 service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id)); 6399 service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id));
6400 } 6400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698