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

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

Issue 318863008: Move ExtensionServiceTestBase into it's own header/cc file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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"
6
7 #include <algorithm> 5 #include <algorithm>
8 #include <set> 6 #include <set>
9 #include <vector> 7 #include <vector>
10 8
11 #include "base/at_exit.h" 9 #include "base/at_exit.h"
12 #include "base/basictypes.h" 10 #include "base/basictypes.h"
13 #include "base/bind.h" 11 #include "base/bind.h"
14 #include "base/command_line.h" 12 #include "base/command_line.h"
15 #include "base/file_util.h" 13 #include "base/file_util.h"
16 #include "base/files/file_enumerator.h" 14 #include "base/files/file_enumerator.h"
17 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
18 #include "base/json/json_file_value_serializer.h" 16 #include "base/json/json_file_value_serializer.h"
19 #include "base/json/json_reader.h" 17 #include "base/json/json_reader.h"
20 #include "base/json/json_string_value_serializer.h" 18 #include "base/json/json_string_value_serializer.h"
21 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
22 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
23 #include "base/message_loop/message_loop.h" 21 #include "base/message_loop/message_loop.h"
24 #include "base/path_service.h"
25 #include "base/prefs/scoped_user_pref_update.h" 22 #include "base/prefs/scoped_user_pref_update.h"
26 #include "base/stl_util.h" 23 #include "base/stl_util.h"
27 #include "base/strings/string16.h" 24 #include "base/strings/string16.h"
28 #include "base/strings/string_number_conversions.h" 25 #include "base/strings/string_number_conversions.h"
29 #include "base/strings/string_util.h" 26 #include "base/strings/string_util.h"
30 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
31 #include "base/version.h" 28 #include "base/version.h"
32 #include "chrome/browser/browser_process.h" 29 #include "chrome/browser/browser_process.h"
33 #include "chrome/browser/chrome_notification_types.h" 30 #include "chrome/browser/chrome_notification_types.h"
34 #include "chrome/browser/extensions/app_sync_data.h" 31 #include "chrome/browser/extensions/app_sync_data.h"
35 #include "chrome/browser/extensions/blacklist.h" 32 #include "chrome/browser/extensions/blacklist.h"
36 #include "chrome/browser/extensions/chrome_app_sorting.h" 33 #include "chrome/browser/extensions/chrome_app_sorting.h"
37 #include "chrome/browser/extensions/component_loader.h" 34 #include "chrome/browser/extensions/component_loader.h"
38 #include "chrome/browser/extensions/crx_installer.h" 35 #include "chrome/browser/extensions/crx_installer.h"
39 #include "chrome/browser/extensions/default_apps.h" 36 #include "chrome/browser/extensions/default_apps.h"
40 #include "chrome/browser/extensions/extension_creator.h" 37 #include "chrome/browser/extensions/extension_creator.h"
41 #include "chrome/browser/extensions/extension_error_reporter.h" 38 #include "chrome/browser/extensions/extension_error_reporter.h"
42 #include "chrome/browser/extensions/extension_error_ui.h" 39 #include "chrome/browser/extensions/extension_error_ui.h"
43 #include "chrome/browser/extensions/extension_garbage_collector_factory.h"
44 #include "chrome/browser/extensions/extension_notification_observer.h" 40 #include "chrome/browser/extensions/extension_notification_observer.h"
45 #include "chrome/browser/extensions/extension_service.h" 41 #include "chrome/browser/extensions/extension_service.h"
42 #include "chrome/browser/extensions/extension_service_test_base.h"
46 #include "chrome/browser/extensions/extension_special_storage_policy.h" 43 #include "chrome/browser/extensions/extension_special_storage_policy.h"
47 #include "chrome/browser/extensions/extension_sync_data.h" 44 #include "chrome/browser/extensions/extension_sync_data.h"
48 #include "chrome/browser/extensions/extension_sync_service.h" 45 #include "chrome/browser/extensions/extension_sync_service.h"
49 #include "chrome/browser/extensions/extension_util.h" 46 #include "chrome/browser/extensions/extension_util.h"
50 #include "chrome/browser/extensions/external_install_ui.h" 47 #include "chrome/browser/extensions/external_install_ui.h"
51 #include "chrome/browser/extensions/external_policy_loader.h" 48 #include "chrome/browser/extensions/external_policy_loader.h"
52 #include "chrome/browser/extensions/external_pref_loader.h" 49 #include "chrome/browser/extensions/external_pref_loader.h"
53 #include "chrome/browser/extensions/external_provider_impl.h" 50 #include "chrome/browser/extensions/external_provider_impl.h"
54 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" 51 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h"
55 #include "chrome/browser/extensions/install_observer.h" 52 #include "chrome/browser/extensions/install_observer.h"
56 #include "chrome/browser/extensions/install_tracker.h" 53 #include "chrome/browser/extensions/install_tracker.h"
57 #include "chrome/browser/extensions/install_tracker_factory.h" 54 #include "chrome/browser/extensions/install_tracker_factory.h"
58 #include "chrome/browser/extensions/installed_loader.h" 55 #include "chrome/browser/extensions/installed_loader.h"
59 #include "chrome/browser/extensions/pack_extension_job.h" 56 #include "chrome/browser/extensions/pack_extension_job.h"
60 #include "chrome/browser/extensions/pending_extension_info.h" 57 #include "chrome/browser/extensions/pending_extension_info.h"
61 #include "chrome/browser/extensions/pending_extension_manager.h" 58 #include "chrome/browser/extensions/pending_extension_manager.h"
62 #include "chrome/browser/extensions/test_blacklist.h" 59 #include "chrome/browser/extensions/test_blacklist.h"
63 #include "chrome/browser/extensions/test_extension_system.h" 60 #include "chrome/browser/extensions/test_extension_system.h"
64 #include "chrome/browser/extensions/unpacked_installer.h" 61 #include "chrome/browser/extensions/unpacked_installer.h"
65 #include "chrome/browser/extensions/updater/extension_updater.h" 62 #include "chrome/browser/extensions/updater/extension_updater.h"
66 #include "chrome/browser/prefs/browser_prefs.h"
67 #include "chrome/browser/prefs/pref_service_mock_factory.h"
68 #include "chrome/browser/prefs/pref_service_syncable.h" 63 #include "chrome/browser/prefs/pref_service_syncable.h"
69 #include "chrome/browser/sync/profile_sync_service.h" 64 #include "chrome/browser/sync/profile_sync_service.h"
70 #include "chrome/browser/sync/profile_sync_service_factory.h" 65 #include "chrome/browser/sync/profile_sync_service_factory.h"
71 #include "chrome/common/chrome_constants.h" 66 #include "chrome/common/chrome_constants.h"
72 #include "chrome/common/chrome_paths.h"
73 #include "chrome/common/chrome_switches.h" 67 #include "chrome/common/chrome_switches.h"
74 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 68 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
75 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 69 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
76 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" 70 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
77 #include "chrome/common/extensions/manifest_url_handler.h" 71 #include "chrome/common/extensions/manifest_url_handler.h"
78 #include "chrome/common/pref_names.h" 72 #include "chrome/common/pref_names.h"
79 #include "chrome/common/url_constants.h" 73 #include "chrome/common/url_constants.h"
80 #include "chrome/test/base/scoped_browser_locale.h" 74 #include "chrome/test/base/scoped_browser_locale.h"
81 #include "chrome/test/base/testing_profile.h" 75 #include "chrome/test/base/testing_profile.h"
82 #include "components/pref_registry/pref_registry_syncable.h" 76 #include "components/pref_registry/pref_registry_syncable.h"
(...skipping 11 matching lines...) Expand all
94 #include "extensions/browser/extension_system.h" 88 #include "extensions/browser/extension_system.h"
95 #include "extensions/browser/external_provider_interface.h" 89 #include "extensions/browser/external_provider_interface.h"
96 #include "extensions/browser/management_policy.h" 90 #include "extensions/browser/management_policy.h"
97 #include "extensions/browser/pref_names.h" 91 #include "extensions/browser/pref_names.h"
98 #include "extensions/browser/test_management_policy.h" 92 #include "extensions/browser/test_management_policy.h"
99 #include "extensions/common/constants.h" 93 #include "extensions/common/constants.h"
100 #include "extensions/common/extension.h" 94 #include "extensions/common/extension.h"
101 #include "extensions/common/extension_builder.h" 95 #include "extensions/common/extension_builder.h"
102 #include "extensions/common/extension_l10n_util.h" 96 #include "extensions/common/extension_l10n_util.h"
103 #include "extensions/common/extension_resource.h" 97 #include "extensions/common/extension_resource.h"
98 #include "extensions/common/feature_switch.h"
104 #include "extensions/common/manifest_constants.h" 99 #include "extensions/common/manifest_constants.h"
105 #include "extensions/common/manifest_handlers/background_info.h" 100 #include "extensions/common/manifest_handlers/background_info.h"
106 #include "extensions/common/permissions/permission_set.h" 101 #include "extensions/common/permissions/permission_set.h"
107 #include "extensions/common/permissions/permissions_data.h" 102 #include "extensions/common/permissions/permissions_data.h"
108 #include "extensions/common/switches.h" 103 #include "extensions/common/switches.h"
109 #include "extensions/common/url_pattern.h" 104 #include "extensions/common/url_pattern.h"
110 #include "extensions/common/value_builder.h" 105 #include "extensions/common/value_builder.h"
111 #include "gpu/config/gpu_info.h" 106 #include "gpu/config/gpu_info.h"
112 #include "grit/browser_resources.h" 107 #include "grit/browser_resources.h"
113 #include "net/cookies/canonical_cookie.h" 108 #include "net/cookies/canonical_cookie.h"
(...skipping 11 matching lines...) Expand all
125 #include "sync/protocol/extension_specifics.pb.h" 120 #include "sync/protocol/extension_specifics.pb.h"
126 #include "sync/protocol/sync.pb.h" 121 #include "sync/protocol/sync.pb.h"
127 #include "testing/gtest/include/gtest/gtest.h" 122 #include "testing/gtest/include/gtest/gtest.h"
128 #include "testing/platform_test.h" 123 #include "testing/platform_test.h"
129 #include "url/gurl.h" 124 #include "url/gurl.h"
130 #include "webkit/browser/database/database_tracker.h" 125 #include "webkit/browser/database/database_tracker.h"
131 #include "webkit/browser/quota/quota_manager.h" 126 #include "webkit/browser/quota/quota_manager.h"
132 #include "webkit/common/database/database_identifier.h" 127 #include "webkit/common/database/database_identifier.h"
133 128
134 #if defined(OS_CHROMEOS) 129 #if defined(OS_CHROMEOS)
135 #include "chrome/browser/chromeos/extensions/install_limiter.h"
136 #include "chrome/browser/chromeos/login/users/user_manager.h" 130 #include "chrome/browser/chromeos/login/users/user_manager.h"
137 #include "chrome/browser/chromeos/settings/cros_settings.h" 131 #include "chrome/browser/chromeos/settings/cros_settings.h"
138 #include "chrome/browser/chromeos/settings/device_settings_service.h" 132 #include "chrome/browser/chromeos/settings/device_settings_service.h"
139 #endif 133 #endif
140 134
141 // The blacklist tests rely on safe browsing. 135 // The blacklist tests rely on safe browsing.
142 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) 136 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
143 #define ENABLE_BLACKLIST_TESTS 137 #define ENABLE_BLACKLIST_TESTS
144 #endif 138 #endif
145 139
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 int ids_found_; 451 int ids_found_;
458 base::FilePath fake_base_path_; 452 base::FilePath fake_base_path_;
459 int expected_creation_flags_; 453 int expected_creation_flags_;
460 scoped_ptr<extensions::ExternalProviderImpl> provider_; 454 scoped_ptr<extensions::ExternalProviderImpl> provider_;
461 scoped_ptr<base::DictionaryValue> prefs_; 455 scoped_ptr<base::DictionaryValue> prefs_;
462 scoped_ptr<TestingProfile> profile_; 456 scoped_ptr<TestingProfile> profile_;
463 457
464 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); 458 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
465 }; 459 };
466 460
467 ExtensionServiceTestBase::ExtensionServiceInitParams:: 461 class ExtensionServiceTest : public extensions::ExtensionServiceTestBase,
468 ExtensionServiceInitParams() 462 public content::NotificationObserver {
469 : autoupdate_enabled(false), is_first_run(true), profile_is_managed(false) {
470 }
471
472 // Our message loop may be used in tests which require it to be an IO loop.
473 ExtensionServiceTestBase::ExtensionServiceTestBase()
474 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
475 service_(NULL),
476 management_policy_(NULL),
477 expected_extensions_count_(0),
478 registry_(NULL) {
479 base::FilePath test_data_dir;
480 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
481 ADD_FAILURE();
482 return;
483 }
484 data_dir_ = test_data_dir.AppendASCII("extensions");
485 }
486
487 ExtensionServiceTestBase::~ExtensionServiceTestBase() {
488 service_ = NULL;
489 }
490
491 void ExtensionServiceTestBase::InitializeExtensionService(
492 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) {
493 profile_ = CreateTestingProfile(params);
494 service_ = InitializeExtensionServiceForProfile(params, profile_.get());
495 management_policy_ =
496 ExtensionSystem::Get(profile_.get())->management_policy();
497 extensions_install_dir_ = params.extensions_install_dir;
498 expected_extensions_count_ = 0;
499 registry_ = extensions::ExtensionRegistry::Get(profile_.get());
500 extensions::ExtensionGarbageCollectorFactory::GetInstance()
501 ->SetTestingFactoryAndUse(
502 profile_.get(),
503 &extensions::ExtensionGarbageCollectorFactory::BuildInstanceFor);
504 }
505
506 // static
507 scoped_ptr<TestingProfile> ExtensionServiceTestBase::CreateTestingProfile(
508 const ExtensionServiceInitParams& params) {
509 TestingProfile::Builder profile_builder;
510 // Create a PrefService that only contains user defined preference values.
511 PrefServiceMockFactory factory;
512 // If pref_file is empty, TestingProfile automatically creates
513 // TestingPrefServiceSyncable instance.
514 if (!params.pref_file.empty()) {
515 factory.SetUserPrefsFile(params.pref_file,
516 base::MessageLoopProxy::current().get());
517 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
518 new user_prefs::PrefRegistrySyncable);
519 scoped_ptr<PrefServiceSyncable> prefs(
520 factory.CreateSyncable(registry.get()));
521 chrome::RegisterUserProfilePrefs(registry.get());
522 profile_builder.SetPrefService(prefs.Pass());
523 }
524
525 if (params.profile_is_managed)
526 profile_builder.SetManagedUserId("asdf");
527
528 profile_builder.SetPath(params.profile_path);
529 return profile_builder.Build();
530 }
531
532 // static
533 ExtensionService*
534 ExtensionServiceTestBase::InitializeExtensionServiceForProfile(
535 const ExtensionServiceInitParams& params,
536 Profile* profile) {
537 TestExtensionSystem* system = static_cast<TestExtensionSystem*>(
538 ExtensionSystem::Get(profile));
539 if (!params.is_first_run) {
540 ExtensionPrefs* prefs = system->CreateExtensionPrefs(
541 CommandLine::ForCurrentProcess(),
542 params.extensions_install_dir);
543 prefs->SetAlertSystemFirstRun();
544 }
545
546 ExtensionService* service = system->CreateExtensionService(
547 CommandLine::ForCurrentProcess(),
548 params.extensions_install_dir,
549 params.autoupdate_enabled);
550
551 service->SetFileTaskRunnerForTesting(
552 base::MessageLoopProxy::current().get());
553 service->set_extensions_enabled(true);
554 service->set_show_extensions_prompts(false);
555 service->set_install_updates_when_idle_for_test(false);
556
557 // When we start up, we want to make sure there is no external provider,
558 // since the ExtensionService on Windows will use the Registry as a default
559 // provider and if there is something already registered there then it will
560 // interfere with the tests. Those tests that need an external provider
561 // will register one specifically.
562 service->ClearProvidersForTesting();
563
564 #if defined(OS_CHROMEOS)
565 extensions::InstallLimiter::Get(profile)->DisableForTest();
566 #endif
567 return service;
568 }
569
570 void ExtensionServiceTestBase::InitializeInstalledExtensionService(
571 const base::FilePath& prefs_file,
572 const base::FilePath& source_install_dir) {
573 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
574 base::FilePath path = temp_dir_.path();
575 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
576 EXPECT_TRUE(base::DeleteFile(path, true));
577 base::File::Error error = base::File::FILE_OK;
578 EXPECT_TRUE(base::CreateDirectoryAndGetError(path, &error)) << error;
579 base::FilePath temp_prefs = path.Append(chrome::kPreferencesFilename);
580 EXPECT_TRUE(base::CopyFile(prefs_file, temp_prefs));
581
582 base::FilePath extensions_install_dir =
583 path.Append(FILE_PATH_LITERAL("Extensions"));
584 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true));
585 EXPECT_TRUE(
586 base::CopyDirectory(source_install_dir, extensions_install_dir, true));
587
588 ExtensionServiceInitParams params;
589 params.profile_path = path;
590 params.pref_file = temp_prefs;
591 params.extensions_install_dir = extensions_install_dir;
592 InitializeExtensionService(params);
593 }
594
595 void ExtensionServiceTestBase::InitializeGoodInstalledExtensionService() {
596 base::FilePath source_install_dir = data_dir_
597 .AppendASCII("good")
598 .AppendASCII("Extensions");
599 base::FilePath pref_path =
600 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
601 InitializeInstalledExtensionService(pref_path, source_install_dir);
602 }
603
604 void ExtensionServiceTestBase::InitializeEmptyExtensionService() {
605 InitializeExtensionService(CreateDefaultInitParams());
606 }
607
608 void ExtensionServiceTestBase::InitializeProcessManager() {
609 static_cast<extensions::TestExtensionSystem*>(
610 ExtensionSystem::Get(profile_.get()))->
611 CreateProcessManager();
612 }
613
614 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() {
615 ExtensionServiceInitParams params = CreateDefaultInitParams();
616 params.autoupdate_enabled = true;
617 InitializeExtensionService(params);
618 service_->updater()->Start();
619 }
620
621 void ExtensionServiceTestBase::InitializeExtensionSyncService() {
622 extension_sync_service_.reset(new ExtensionSyncService(
623 profile_.get(), ExtensionPrefs::Get(profile_.get()), service_));
624 }
625
626 // static
627 void ExtensionServiceTestBase::SetUpTestCase() {
628 ExtensionErrorReporter::Init(false); // no noisy errors
629 }
630
631 void ExtensionServiceTestBase::SetUp() {
632 ExtensionErrorReporter::GetInstance()->ClearErrors();
633 }
634
635 void ExtensionServiceTestBase::TearDown() {
636 }
637
638 ExtensionServiceTestBase::ExtensionServiceInitParams
639 ExtensionServiceTestBase::CreateDefaultInitParams() {
640 return CreateDefaultInitParamsInTempDir(&temp_dir_);
641 }
642
643 // static
644 ExtensionServiceTestBase::ExtensionServiceInitParams
645 ExtensionServiceTestBase::CreateDefaultInitParamsInTempDir(
646 base::ScopedTempDir* temp_dir) {
647 ExtensionServiceInitParams params;
648 EXPECT_TRUE(temp_dir->CreateUniqueTempDir());
649 base::FilePath path = temp_dir->path();
650 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
651 EXPECT_TRUE(base::DeleteFile(path, true));
652 base::File::Error error = base::File::FILE_OK;
653 EXPECT_TRUE(base::CreateDirectoryAndGetError(path, &error)) << error;
654 base::FilePath prefs_filename =
655 path.Append(FILE_PATH_LITERAL("TestPreferences"));
656 base::FilePath extensions_install_dir =
657 path.Append(FILE_PATH_LITERAL("Extensions"));
658 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true));
659 EXPECT_TRUE(base::CreateDirectoryAndGetError(extensions_install_dir,
660 &error)) << error;
661
662 params.profile_path = path;
663 params.pref_file = prefs_filename;
664 params.extensions_install_dir = extensions_install_dir;
665 return params;
666 }
667
668 class ExtensionServiceTest
669 : public ExtensionServiceTestBase, public content::NotificationObserver {
670 public: 463 public:
671 ExtensionServiceTest() 464 ExtensionServiceTest()
672 : unloaded_reason_(UnloadedExtensionInfo::REASON_UNDEFINED), 465 : unloaded_reason_(UnloadedExtensionInfo::REASON_UNDEFINED),
673 installed_(NULL), 466 installed_(NULL),
674 was_update_(false), 467 was_update_(false),
675 override_external_install_prompt_( 468 override_external_install_prompt_(
676 FeatureSwitch::prompt_for_external_extensions(), 469 FeatureSwitch::prompt_for_external_extensions(),
677 false) { 470 false),
471 expected_extensions_count_(0) {
678 registrar_.Add(this, 472 registrar_.Add(this,
679 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 473 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
680 content::NotificationService::AllSources()); 474 content::NotificationService::AllSources());
681 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 475 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
682 content::NotificationService::AllSources()); 476 content::NotificationService::AllSources());
683 registrar_.Add(this, 477 registrar_.Add(this,
684 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, 478 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED,
685 content::NotificationService::AllSources()); 479 content::NotificationService::AllSources());
686 } 480 }
687 481
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 break; 518 break;
725 } 519 }
726 520
727 default: 521 default:
728 DCHECK(false); 522 DCHECK(false);
729 } 523 }
730 } 524 }
731 525
732 void AddMockExternalProvider( 526 void AddMockExternalProvider(
733 extensions::ExternalProviderInterface* provider) { 527 extensions::ExternalProviderInterface* provider) {
734 service_->AddProviderForTesting(provider); 528 service()->AddProviderForTesting(provider);
735 } 529 }
736 530
737 void MockSyncStartFlare(bool* was_called, 531 void MockSyncStartFlare(bool* was_called,
738 syncer::ModelType* model_type_passed_in, 532 syncer::ModelType* model_type_passed_in,
739 syncer::ModelType model_type) { 533 syncer::ModelType model_type) {
740 *was_called = true; 534 *was_called = true;
741 *model_type_passed_in = model_type; 535 *model_type_passed_in = model_type;
742 } 536 }
743 537
744 protected: 538 protected:
745 // Paths to some of the fake extensions. 539 // Paths to some of the fake extensions.
746 base::FilePath good0_path() { 540 base::FilePath good0_path() {
747 return data_dir_.AppendASCII("good").AppendASCII("Extensions") 541 return data_dir()
748 .AppendASCII(good0).AppendASCII("1.0.0.0"); 542 .AppendASCII("good")
543 .AppendASCII("Extensions")
544 .AppendASCII(good0)
545 .AppendASCII("1.0.0.0");
749 } 546 }
750 547
751 base::FilePath good1_path() { 548 base::FilePath good1_path() {
752 return data_dir_.AppendASCII("good").AppendASCII("Extensions") 549 return data_dir()
753 .AppendASCII(good1).AppendASCII("2"); 550 .AppendASCII("good")
551 .AppendASCII("Extensions")
552 .AppendASCII(good1)
553 .AppendASCII("2");
754 } 554 }
755 555
756 base::FilePath good2_path() { 556 base::FilePath good2_path() {
757 return data_dir_.AppendASCII("good").AppendASCII("Extensions") 557 return data_dir()
758 .AppendASCII(good2).AppendASCII("1.0"); 558 .AppendASCII("good")
559 .AppendASCII("Extensions")
560 .AppendASCII(good2)
561 .AppendASCII("1.0");
759 } 562 }
760 563
761 void TestExternalProvider(MockExtensionProvider* provider, 564 void TestExternalProvider(MockExtensionProvider* provider,
762 Manifest::Location location); 565 Manifest::Location location);
763 566
764 void PackCRX(const base::FilePath& dir_path, 567 void PackCRX(const base::FilePath& dir_path,
765 const base::FilePath& pem_path, 568 const base::FilePath& pem_path,
766 const base::FilePath& crx_path) { 569 const base::FilePath& crx_path) {
767 // Use the existing pem key, if provided. 570 // Use the existing pem key, if provided.
768 base::FilePath pem_output_path; 571 base::FilePath pem_output_path;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 InstallCRXInternal(path, Extension::FROM_WEBSTORE); 653 InstallCRXInternal(path, Extension::FROM_WEBSTORE);
851 return VerifyCrxInstall(path, install_state); 654 return VerifyCrxInstall(path, install_state);
852 } 655 }
853 656
854 const Extension* InstallCRXWithLocation(const base::FilePath& crx_path, 657 const Extension* InstallCRXWithLocation(const base::FilePath& crx_path,
855 Manifest::Location install_location, 658 Manifest::Location install_location,
856 InstallState install_state) { 659 InstallState install_state) {
857 EXPECT_TRUE(base::PathExists(crx_path)) 660 EXPECT_TRUE(base::PathExists(crx_path))
858 << "Path does not exist: "<< crx_path.value().c_str(); 661 << "Path does not exist: "<< crx_path.value().c_str();
859 // no client (silent install) 662 // no client (silent install)
860 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service_)); 663 scoped_refptr<CrxInstaller> installer(
664 CrxInstaller::CreateSilent(service()));
861 installer->set_install_source(install_location); 665 installer->set_install_source(install_location);
862 666
863 content::WindowedNotificationObserver observer( 667 content::WindowedNotificationObserver observer(
864 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 668 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
865 content::NotificationService::AllSources()); 669 content::NotificationService::AllSources());
866 installer->InstallCrx(crx_path); 670 installer->InstallCrx(crx_path);
867 observer.Wait(); 671 observer.Wait();
868 672
869 return VerifyCrxInstall(crx_path, install_state); 673 return VerifyCrxInstall(crx_path, install_state);
870 } 674 }
(...skipping 27 matching lines...) Expand all
898 << path.value(); 702 << path.value();
899 // If INSTALL_UPDATED, old_name_ should match the given string. 703 // If INSTALL_UPDATED, old_name_ should match the given string.
900 if (install_state == INSTALL_UPDATED && !expected_old_name.empty()) 704 if (install_state == INSTALL_UPDATED && !expected_old_name.empty())
901 EXPECT_EQ(expected_old_name, old_name_); 705 EXPECT_EQ(expected_old_name, old_name_);
902 EXPECT_EQ(0u, errors.size()) << path.value(); 706 EXPECT_EQ(0u, errors.size()) << path.value();
903 707
904 if (install_state == INSTALL_WITHOUT_LOAD) { 708 if (install_state == INSTALL_WITHOUT_LOAD) {
905 EXPECT_EQ(0u, loaded_.size()) << path.value(); 709 EXPECT_EQ(0u, loaded_.size()) << path.value();
906 } else { 710 } else {
907 EXPECT_EQ(1u, loaded_.size()) << path.value(); 711 EXPECT_EQ(1u, loaded_.size()) << path.value();
908 size_t actual_extension_count = registry_->enabled_extensions().size() + 712 size_t actual_extension_count =
909 registry_->disabled_extensions().size(); 713 registry()->enabled_extensions().size() +
714 registry()->disabled_extensions().size();
910 EXPECT_EQ(expected_extensions_count_, actual_extension_count) << 715 EXPECT_EQ(expected_extensions_count_, actual_extension_count) <<
911 path.value(); 716 path.value();
912 extension = loaded_[0].get(); 717 extension = loaded_[0].get();
913 EXPECT_TRUE(service_->GetExtensionById(extension->id(), false)) 718 EXPECT_TRUE(service()->GetExtensionById(extension->id(), false))
914 << path.value(); 719 << path.value();
915 } 720 }
916 721
917 for (std::vector<base::string16>::iterator err = errors.begin(); 722 for (std::vector<base::string16>::iterator err = errors.begin();
918 err != errors.end(); ++err) { 723 err != errors.end(); ++err) {
919 LOG(ERROR) << *err; 724 LOG(ERROR) << *err;
920 } 725 }
921 } else { 726 } else {
922 EXPECT_FALSE(installed_) << path.value(); 727 EXPECT_FALSE(installed_) << path.value();
923 EXPECT_EQ(0u, loaded_.size()) << path.value(); 728 EXPECT_EQ(0u, loaded_.size()) << path.value();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 *installer; 772 *installer;
968 } 773 }
969 774
970 void UpdateExtension(const std::string& id, 775 void UpdateExtension(const std::string& id,
971 const base::FilePath& in_path, 776 const base::FilePath& in_path,
972 UpdateState expected_state) { 777 UpdateState expected_state) {
973 ASSERT_TRUE(base::PathExists(in_path)); 778 ASSERT_TRUE(base::PathExists(in_path));
974 779
975 // We need to copy this to a temporary location because Update() will delete 780 // We need to copy this to a temporary location because Update() will delete
976 // it. 781 // it.
977 base::FilePath path = temp_dir_.path(); 782 base::FilePath path = temp_dir().path();
978 path = path.Append(in_path.BaseName()); 783 path = path.Append(in_path.BaseName());
979 ASSERT_TRUE(base::CopyFile(in_path, path)); 784 ASSERT_TRUE(base::CopyFile(in_path, path));
980 785
981 int previous_enabled_extension_count = 786 int previous_enabled_extension_count =
982 registry_->enabled_extensions().size(); 787 registry()->enabled_extensions().size();
983 int previous_installed_extension_count = 788 int previous_installed_extension_count =
984 previous_enabled_extension_count + 789 previous_enabled_extension_count +
985 registry_->disabled_extensions().size(); 790 registry()->disabled_extensions().size();
986 791
987 extensions::CrxInstaller* installer = NULL; 792 extensions::CrxInstaller* installer = NULL;
988 content::WindowedNotificationObserver observer( 793 content::WindowedNotificationObserver observer(
989 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 794 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
990 base::Bind(&IsCrxInstallerDone, &installer)); 795 base::Bind(&IsCrxInstallerDone, &installer));
991 service_->UpdateExtension(id, path, true, &installer); 796 service()->UpdateExtension(id, path, true, &installer);
992 797
993 if (installer) 798 if (installer)
994 observer.Wait(); 799 observer.Wait();
995 else 800 else
996 base::RunLoop().RunUntilIdle(); 801 base::RunLoop().RunUntilIdle();
997 802
998 std::vector<base::string16> errors = GetErrors(); 803 std::vector<base::string16> errors = GetErrors();
999 int error_count = errors.size(); 804 int error_count = errors.size();
1000 int enabled_extension_count = registry_->enabled_extensions().size(); 805 int enabled_extension_count = registry()->enabled_extensions().size();
1001 int installed_extension_count = 806 int installed_extension_count =
1002 enabled_extension_count + registry_->disabled_extensions().size(); 807 enabled_extension_count + registry()->disabled_extensions().size();
1003 808
1004 int expected_error_count = (expected_state == FAILED) ? 1 : 0; 809 int expected_error_count = (expected_state == FAILED) ? 1 : 0;
1005 EXPECT_EQ(expected_error_count, error_count) << path.value(); 810 EXPECT_EQ(expected_error_count, error_count) << path.value();
1006 811
1007 if (expected_state <= FAILED) { 812 if (expected_state <= FAILED) {
1008 EXPECT_EQ(previous_enabled_extension_count, 813 EXPECT_EQ(previous_enabled_extension_count,
1009 enabled_extension_count); 814 enabled_extension_count);
1010 EXPECT_EQ(previous_installed_extension_count, 815 EXPECT_EQ(previous_installed_extension_count,
1011 installed_extension_count); 816 installed_extension_count);
1012 } else { 817 } else {
1013 int expected_installed_extension_count = 818 int expected_installed_extension_count =
1014 (expected_state >= INSTALLED) ? 1 : 0; 819 (expected_state >= INSTALLED) ? 1 : 0;
1015 int expected_enabled_extension_count = 820 int expected_enabled_extension_count =
1016 (expected_state >= ENABLED) ? 1 : 0; 821 (expected_state >= ENABLED) ? 1 : 0;
1017 EXPECT_EQ(expected_installed_extension_count, 822 EXPECT_EQ(expected_installed_extension_count,
1018 installed_extension_count); 823 installed_extension_count);
1019 EXPECT_EQ(expected_enabled_extension_count, 824 EXPECT_EQ(expected_enabled_extension_count,
1020 enabled_extension_count); 825 enabled_extension_count);
1021 } 826 }
1022 827
1023 // Update() should the temporary input file. 828 // Update() should the temporary input file.
1024 EXPECT_FALSE(base::PathExists(path)); 829 EXPECT_FALSE(base::PathExists(path));
1025 } 830 }
1026 831
1027 void TerminateExtension(const std::string& id) { 832 void TerminateExtension(const std::string& id) {
1028 const Extension* extension = service_->GetInstalledExtension(id); 833 const Extension* extension = service()->GetInstalledExtension(id);
1029 if (!extension) { 834 if (!extension) {
1030 ADD_FAILURE(); 835 ADD_FAILURE();
1031 return; 836 return;
1032 } 837 }
1033 service_->TrackTerminatedExtensionForTest(extension); 838 service()->TrackTerminatedExtensionForTest(extension);
1034 } 839 }
1035 840
1036 size_t GetPrefKeyCount() { 841 size_t GetPrefKeyCount() {
1037 const base::DictionaryValue* dict = 842 const base::DictionaryValue* dict =
1038 profile_->GetPrefs()->GetDictionary("extensions.settings"); 843 profile()->GetPrefs()->GetDictionary("extensions.settings");
1039 if (!dict) { 844 if (!dict) {
1040 ADD_FAILURE(); 845 ADD_FAILURE();
1041 return 0; 846 return 0;
1042 } 847 }
1043 return dict->size(); 848 return dict->size();
1044 } 849 }
1045 850
1046 void UninstallExtension(const std::string& id, bool use_helper) { 851 void UninstallExtension(const std::string& id, bool use_helper) {
1047 // Verify that the extension is installed. 852 // Verify that the extension is installed.
1048 base::FilePath extension_path = extensions_install_dir_.AppendASCII(id); 853 base::FilePath extension_path = extensions_install_dir().AppendASCII(id);
1049 EXPECT_TRUE(base::PathExists(extension_path)); 854 EXPECT_TRUE(base::PathExists(extension_path));
1050 size_t pref_key_count = GetPrefKeyCount(); 855 size_t pref_key_count = GetPrefKeyCount();
1051 EXPECT_GT(pref_key_count, 0u); 856 EXPECT_GT(pref_key_count, 0u);
1052 ValidateIntegerPref(id, "state", Extension::ENABLED); 857 ValidateIntegerPref(id, "state", Extension::ENABLED);
1053 858
1054 // Uninstall it. 859 // Uninstall it.
1055 if (use_helper) { 860 if (use_helper) {
1056 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(service_, id)); 861 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(service(), id));
1057 } else { 862 } else {
1058 EXPECT_TRUE(service_->UninstallExtension(id, false, NULL)); 863 EXPECT_TRUE(service()->UninstallExtension(id, false, NULL));
1059 } 864 }
1060 --expected_extensions_count_; 865 --expected_extensions_count_;
1061 866
1062 // We should get an unload notification. 867 // We should get an unload notification.
1063 EXPECT_FALSE(unloaded_id_.empty()); 868 EXPECT_FALSE(unloaded_id_.empty());
1064 EXPECT_EQ(id, unloaded_id_); 869 EXPECT_EQ(id, unloaded_id_);
1065 870
1066 // Verify uninstalled state. 871 // Verify uninstalled state.
1067 size_t new_pref_key_count = GetPrefKeyCount(); 872 size_t new_pref_key_count = GetPrefKeyCount();
1068 if (new_pref_key_count == pref_key_count) { 873 if (new_pref_key_count == pref_key_count) {
1069 ValidateIntegerPref(id, "location", 874 ValidateIntegerPref(id, "location",
1070 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 875 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1071 } else { 876 } else {
1072 EXPECT_EQ(new_pref_key_count, pref_key_count - 1); 877 EXPECT_EQ(new_pref_key_count, pref_key_count - 1);
1073 } 878 }
1074 879
1075 // The extension should not be in the service anymore. 880 // The extension should not be in the service anymore.
1076 EXPECT_FALSE(service_->GetInstalledExtension(id)); 881 EXPECT_FALSE(service()->GetInstalledExtension(id));
1077 base::RunLoop().RunUntilIdle(); 882 base::RunLoop().RunUntilIdle();
1078 883
1079 // The directory should be gone. 884 // The directory should be gone.
1080 EXPECT_FALSE(base::PathExists(extension_path)); 885 EXPECT_FALSE(base::PathExists(extension_path));
1081 } 886 }
1082 887
1083 void ValidatePrefKeyCount(size_t count) { 888 void ValidatePrefKeyCount(size_t count) {
1084 EXPECT_EQ(count, GetPrefKeyCount()); 889 EXPECT_EQ(count, GetPrefKeyCount());
1085 } 890 }
1086 891
1087 testing::AssertionResult ValidateBooleanPref( 892 testing::AssertionResult ValidateBooleanPref(
1088 const std::string& extension_id, 893 const std::string& extension_id,
1089 const std::string& pref_path, 894 const std::string& pref_path,
1090 bool expected_val) { 895 bool expected_val) {
1091 std::string msg = "while checking: "; 896 std::string msg = "while checking: ";
1092 msg += extension_id; 897 msg += extension_id;
1093 msg += " "; 898 msg += " ";
1094 msg += pref_path; 899 msg += pref_path;
1095 msg += " == "; 900 msg += " == ";
1096 msg += expected_val ? "true" : "false"; 901 msg += expected_val ? "true" : "false";
1097 902
1098 PrefService* prefs = profile_->GetPrefs(); 903 PrefService* prefs = profile()->GetPrefs();
1099 const base::DictionaryValue* dict = 904 const base::DictionaryValue* dict =
1100 prefs->GetDictionary("extensions.settings"); 905 prefs->GetDictionary("extensions.settings");
1101 if (!dict) { 906 if (!dict) {
1102 return testing::AssertionFailure() 907 return testing::AssertionFailure()
1103 << "extension.settings does not exist " << msg; 908 << "extension.settings does not exist " << msg;
1104 } 909 }
1105 910
1106 const base::DictionaryValue* pref = NULL; 911 const base::DictionaryValue* pref = NULL;
1107 if (!dict->GetDictionary(extension_id, &pref)) { 912 if (!dict->GetDictionary(extension_id, &pref)) {
1108 return testing::AssertionFailure() 913 return testing::AssertionFailure()
1109 << "extension pref does not exist " << msg; 914 << "extension pref does not exist " << msg;
1110 } 915 }
1111 916
1112 bool val; 917 bool val;
1113 if (!pref->GetBoolean(pref_path, &val)) { 918 if (!pref->GetBoolean(pref_path, &val)) {
1114 return testing::AssertionFailure() 919 return testing::AssertionFailure()
1115 << pref_path << " pref not found " << msg; 920 << pref_path << " pref not found " << msg;
1116 } 921 }
1117 922
1118 return expected_val == val 923 return expected_val == val
1119 ? testing::AssertionSuccess() 924 ? testing::AssertionSuccess()
1120 : testing::AssertionFailure() << "base::Value is incorrect " << msg; 925 : testing::AssertionFailure() << "base::Value is incorrect " << msg;
1121 } 926 }
1122 927
1123 bool IsPrefExist(const std::string& extension_id, 928 bool IsPrefExist(const std::string& extension_id,
1124 const std::string& pref_path) { 929 const std::string& pref_path) {
1125 const base::DictionaryValue* dict = 930 const base::DictionaryValue* dict =
1126 profile_->GetPrefs()->GetDictionary("extensions.settings"); 931 profile()->GetPrefs()->GetDictionary("extensions.settings");
1127 if (dict == NULL) return false; 932 if (dict == NULL) return false;
1128 const base::DictionaryValue* pref = NULL; 933 const base::DictionaryValue* pref = NULL;
1129 if (!dict->GetDictionary(extension_id, &pref)) { 934 if (!dict->GetDictionary(extension_id, &pref)) {
1130 return false; 935 return false;
1131 } 936 }
1132 if (pref == NULL) { 937 if (pref == NULL) {
1133 return false; 938 return false;
1134 } 939 }
1135 bool val; 940 bool val;
1136 if (!pref->GetBoolean(pref_path, &val)) { 941 if (!pref->GetBoolean(pref_path, &val)) {
1137 return false; 942 return false;
1138 } 943 }
1139 return true; 944 return true;
1140 } 945 }
1141 946
1142 void ValidateIntegerPref(const std::string& extension_id, 947 void ValidateIntegerPref(const std::string& extension_id,
1143 const std::string& pref_path, 948 const std::string& pref_path,
1144 int expected_val) { 949 int expected_val) {
1145 std::string msg = " while checking: "; 950 std::string msg = " while checking: ";
1146 msg += extension_id; 951 msg += extension_id;
1147 msg += " "; 952 msg += " ";
1148 msg += pref_path; 953 msg += pref_path;
1149 msg += " == "; 954 msg += " == ";
1150 msg += base::IntToString(expected_val); 955 msg += base::IntToString(expected_val);
1151 956
1152 PrefService* prefs = profile_->GetPrefs(); 957 PrefService* prefs = profile()->GetPrefs();
1153 const base::DictionaryValue* dict = 958 const base::DictionaryValue* dict =
1154 prefs->GetDictionary("extensions.settings"); 959 prefs->GetDictionary("extensions.settings");
1155 ASSERT_TRUE(dict != NULL) << msg; 960 ASSERT_TRUE(dict != NULL) << msg;
1156 const base::DictionaryValue* pref = NULL; 961 const base::DictionaryValue* pref = NULL;
1157 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; 962 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
1158 EXPECT_TRUE(pref != NULL) << msg; 963 EXPECT_TRUE(pref != NULL) << msg;
1159 int val; 964 int val;
1160 ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg; 965 ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg;
1161 EXPECT_EQ(expected_val, val) << msg; 966 EXPECT_EQ(expected_val, val) << msg;
1162 } 967 }
1163 968
1164 void ValidateStringPref(const std::string& extension_id, 969 void ValidateStringPref(const std::string& extension_id,
1165 const std::string& pref_path, 970 const std::string& pref_path,
1166 const std::string& expected_val) { 971 const std::string& expected_val) {
1167 std::string msg = " while checking: "; 972 std::string msg = " while checking: ";
1168 msg += extension_id; 973 msg += extension_id;
1169 msg += ".manifest."; 974 msg += ".manifest.";
1170 msg += pref_path; 975 msg += pref_path;
1171 msg += " == "; 976 msg += " == ";
1172 msg += expected_val; 977 msg += expected_val;
1173 978
1174 const base::DictionaryValue* dict = 979 const base::DictionaryValue* dict =
1175 profile_->GetPrefs()->GetDictionary("extensions.settings"); 980 profile()->GetPrefs()->GetDictionary("extensions.settings");
1176 ASSERT_TRUE(dict != NULL) << msg; 981 ASSERT_TRUE(dict != NULL) << msg;
1177 const base::DictionaryValue* pref = NULL; 982 const base::DictionaryValue* pref = NULL;
1178 std::string manifest_path = extension_id + ".manifest"; 983 std::string manifest_path = extension_id + ".manifest";
1179 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; 984 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg;
1180 EXPECT_TRUE(pref != NULL) << msg; 985 EXPECT_TRUE(pref != NULL) << msg;
1181 std::string val; 986 std::string val;
1182 ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; 987 ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg;
1183 EXPECT_EQ(expected_val, val) << msg; 988 EXPECT_EQ(expected_val, val) << msg;
1184 } 989 }
1185 990
1186 void SetPref(const std::string& extension_id, 991 void SetPref(const std::string& extension_id,
1187 const std::string& pref_path, 992 const std::string& pref_path,
1188 base::Value* value, 993 base::Value* value,
1189 const std::string& msg) { 994 const std::string& msg) {
1190 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); 995 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings");
1191 base::DictionaryValue* dict = update.Get(); 996 base::DictionaryValue* dict = update.Get();
1192 ASSERT_TRUE(dict != NULL) << msg; 997 ASSERT_TRUE(dict != NULL) << msg;
1193 base::DictionaryValue* pref = NULL; 998 base::DictionaryValue* pref = NULL;
1194 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; 999 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
1195 EXPECT_TRUE(pref != NULL) << msg; 1000 EXPECT_TRUE(pref != NULL) << msg;
1196 pref->Set(pref_path, value); 1001 pref->Set(pref_path, value);
1197 } 1002 }
1198 1003
1199 void SetPrefInteg(const std::string& extension_id, 1004 void SetPrefInteg(const std::string& extension_id,
1200 const std::string& pref_path, 1005 const std::string& pref_path,
(...skipping 17 matching lines...) Expand all
1218 msg += (value ? "true" : "false"); 1023 msg += (value ? "true" : "false");
1219 1024
1220 SetPref(extension_id, pref_path, new base::FundamentalValue(value), msg); 1025 SetPref(extension_id, pref_path, new base::FundamentalValue(value), msg);
1221 } 1026 }
1222 1027
1223 void ClearPref(const std::string& extension_id, 1028 void ClearPref(const std::string& extension_id,
1224 const std::string& pref_path) { 1029 const std::string& pref_path) {
1225 std::string msg = " while clearing: "; 1030 std::string msg = " while clearing: ";
1226 msg += extension_id + " " + pref_path; 1031 msg += extension_id + " " + pref_path;
1227 1032
1228 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); 1033 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings");
1229 base::DictionaryValue* dict = update.Get(); 1034 base::DictionaryValue* dict = update.Get();
1230 ASSERT_TRUE(dict != NULL) << msg; 1035 ASSERT_TRUE(dict != NULL) << msg;
1231 base::DictionaryValue* pref = NULL; 1036 base::DictionaryValue* pref = NULL;
1232 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; 1037 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
1233 EXPECT_TRUE(pref != NULL) << msg; 1038 EXPECT_TRUE(pref != NULL) << msg;
1234 pref->Remove(pref_path, NULL); 1039 pref->Remove(pref_path, NULL);
1235 } 1040 }
1236 1041
1237 void SetPrefStringSet(const std::string& extension_id, 1042 void SetPrefStringSet(const std::string& extension_id,
1238 const std::string& pref_path, 1043 const std::string& pref_path,
1239 const std::set<std::string>& value) { 1044 const std::set<std::string>& value) {
1240 std::string msg = " while setting: "; 1045 std::string msg = " while setting: ";
1241 msg += extension_id + " " + pref_path; 1046 msg += extension_id + " " + pref_path;
1242 1047
1243 base::ListValue* list_value = new base::ListValue(); 1048 base::ListValue* list_value = new base::ListValue();
1244 for (std::set<std::string>::const_iterator iter = value.begin(); 1049 for (std::set<std::string>::const_iterator iter = value.begin();
1245 iter != value.end(); ++iter) 1050 iter != value.end(); ++iter)
1246 list_value->Append(new base::StringValue(*iter)); 1051 list_value->Append(new base::StringValue(*iter));
1247 1052
1248 SetPref(extension_id, pref_path, list_value, msg); 1053 SetPref(extension_id, pref_path, list_value, msg);
1249 } 1054 }
1250 1055
1251 void InitPluginService() { 1056 void InitPluginService() {
1252 #if defined(ENABLE_PLUGINS) 1057 #if defined(ENABLE_PLUGINS)
1253 PluginService::GetInstance()->Init(); 1058 PluginService::GetInstance()->Init();
1254 #endif 1059 #endif
1255 } 1060 }
1256 1061
1062 void InitializeExtensionSyncService() {
1063 extension_sync_service_.reset(new ExtensionSyncService(
1064 profile(), ExtensionPrefs::Get(browser_context()), service()));
1065 }
1066
1067 extensions::ManagementPolicy* GetManagementPolicy() {
1068 return ExtensionSystem::Get(browser_context())->management_policy();
1069 }
1070
1071 ExtensionSyncService* extension_sync_service() {
1072 return extension_sync_service_.get();
1073 }
1074
1257 protected: 1075 protected:
1076 scoped_ptr<ExtensionSyncService> extension_sync_service_;
1258 extensions::ExtensionList loaded_; 1077 extensions::ExtensionList loaded_;
1259 std::string unloaded_id_; 1078 std::string unloaded_id_;
1260 UnloadedExtensionInfo::Reason unloaded_reason_; 1079 UnloadedExtensionInfo::Reason unloaded_reason_;
1261 const Extension* installed_; 1080 const Extension* installed_;
1262 bool was_update_; 1081 bool was_update_;
1263 std::string old_name_; 1082 std::string old_name_;
1264 FeatureSwitch::ScopedOverride override_external_install_prompt_; 1083 FeatureSwitch::ScopedOverride override_external_install_prompt_;
1265 1084
1266 private: 1085 private:
1267 // Create a CrxInstaller and install the CRX file. 1086 // Create a CrxInstaller and install the CRX file.
1268 // Instead of calling this method yourself, use InstallCRX(), which does extra 1087 // Instead of calling this method yourself, use InstallCRX(), which does extra
1269 // error checking. 1088 // error checking.
1270 void InstallCRXInternal(const base::FilePath& crx_path) { 1089 void InstallCRXInternal(const base::FilePath& crx_path) {
1271 InstallCRXInternal(crx_path, Extension::NO_FLAGS); 1090 InstallCRXInternal(crx_path, Extension::NO_FLAGS);
1272 } 1091 }
1273 1092
1274 void InstallCRXInternal(const base::FilePath& crx_path, int creation_flags) { 1093 void InstallCRXInternal(const base::FilePath& crx_path, int creation_flags) {
1275 ASSERT_TRUE(base::PathExists(crx_path)) 1094 ASSERT_TRUE(base::PathExists(crx_path))
1276 << "Path does not exist: "<< crx_path.value().c_str(); 1095 << "Path does not exist: "<< crx_path.value().c_str();
1277 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service_)); 1096 scoped_refptr<CrxInstaller> installer(
1097 CrxInstaller::CreateSilent(service()));
1278 installer->set_creation_flags(creation_flags); 1098 installer->set_creation_flags(creation_flags);
1279 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT)) 1099 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT))
1280 installer->set_allow_silent_install(true); 1100 installer->set_allow_silent_install(true);
1281 1101
1282 content::WindowedNotificationObserver observer( 1102 content::WindowedNotificationObserver observer(
1283 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1103 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1284 content::Source<extensions::CrxInstaller>(installer)); 1104 content::Source<extensions::CrxInstaller>(installer));
1285 1105
1286 installer->InstallCrx(crx_path); 1106 installer->InstallCrx(crx_path);
1287 1107
1288 observer.Wait(); 1108 observer.Wait();
1289 } 1109 }
1290 1110
1111 size_t expected_extensions_count_;
Devlin 2014/06/10 21:46:06 STOP! Every change past this line is the result o
1291 content::NotificationRegistrar registrar_; 1112 content::NotificationRegistrar registrar_;
1292 }; 1113 };
1293 1114
1294 // Receives notifications from a PackExtensionJob, indicating either that 1115 // Receives notifications from a PackExtensionJob, indicating either that
1295 // packing succeeded or that there was some error. 1116 // packing succeeded or that there was some error.
1296 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { 1117 class PackExtensionTestClient : public extensions::PackExtensionJob::Client {
1297 public: 1118 public:
1298 PackExtensionTestClient(const base::FilePath& expected_crx_path, 1119 PackExtensionTestClient(const base::FilePath& expected_crx_path,
1299 const base::FilePath& expected_private_key_path); 1120 const base::FilePath& expected_private_key_path);
1300 virtual void OnPackSuccess(const base::FilePath& crx_path, 1121 virtual void OnPackSuccess(const base::FilePath& crx_path,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 if (type == ExtensionCreator::kCRXExists) 1157 if (type == ExtensionCreator::kCRXExists)
1337 FAIL() << "Packing should not fail."; 1158 FAIL() << "Packing should not fail.";
1338 else 1159 else
1339 FAIL() << "Existing CRX should have been overwritten."; 1160 FAIL() << "Existing CRX should have been overwritten.";
1340 } 1161 }
1341 1162
1342 // Test loading good extensions from the profile directory. 1163 // Test loading good extensions from the profile directory.
1343 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { 1164 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) {
1344 InitPluginService(); 1165 InitPluginService();
1345 InitializeGoodInstalledExtensionService(); 1166 InitializeGoodInstalledExtensionService();
1346 service_->Init(); 1167 service()->Init();
1347 1168
1348 uint32 expected_num_extensions = 3u; 1169 uint32 expected_num_extensions = 3u;
1349 ASSERT_EQ(expected_num_extensions, loaded_.size()); 1170 ASSERT_EQ(expected_num_extensions, loaded_.size());
1350 1171
1351 EXPECT_EQ(std::string(good0), loaded_[0]->id()); 1172 EXPECT_EQ(std::string(good0), loaded_[0]->id());
1352 EXPECT_EQ(std::string("My extension 1"), 1173 EXPECT_EQ(std::string("My extension 1"),
1353 loaded_[0]->name()); 1174 loaded_[0]->name());
1354 EXPECT_EQ(std::string("The first extension that I made."), 1175 EXPECT_EQ(std::string("The first extension that I made."),
1355 loaded_[0]->description()); 1176 loaded_[0]->description());
1356 EXPECT_EQ(Manifest::INTERNAL, loaded_[0]->location()); 1177 EXPECT_EQ(Manifest::INTERNAL, loaded_[0]->location());
1357 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)); 1178 EXPECT_TRUE(service()->GetExtensionById(loaded_[0]->id(), false));
1358 EXPECT_EQ(expected_num_extensions, registry_->enabled_extensions().size()); 1179 EXPECT_EQ(expected_num_extensions, registry()->enabled_extensions().size());
1359 1180
1360 ValidatePrefKeyCount(3); 1181 ValidatePrefKeyCount(3);
1361 ValidateIntegerPref(good0, "state", Extension::ENABLED); 1182 ValidateIntegerPref(good0, "state", Extension::ENABLED);
1362 ValidateIntegerPref(good0, "location", Manifest::INTERNAL); 1183 ValidateIntegerPref(good0, "location", Manifest::INTERNAL);
1363 ValidateIntegerPref(good1, "state", Extension::ENABLED); 1184 ValidateIntegerPref(good1, "state", Extension::ENABLED);
1364 ValidateIntegerPref(good1, "location", Manifest::INTERNAL); 1185 ValidateIntegerPref(good1, "location", Manifest::INTERNAL);
1365 ValidateIntegerPref(good2, "state", Extension::ENABLED); 1186 ValidateIntegerPref(good2, "state", Extension::ENABLED);
1366 ValidateIntegerPref(good2, "location", Manifest::INTERNAL); 1187 ValidateIntegerPref(good2, "location", Manifest::INTERNAL);
1367 1188
1368 URLPatternSet expected_patterns; 1189 URLPatternSet expected_patterns;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 EXPECT_EQ(std::string(), loaded_[index]->description()); 1261 EXPECT_EQ(std::string(), loaded_[index]->description());
1441 EXPECT_EQ(0u, 1262 EXPECT_EQ(0u,
1442 extensions::ContentScriptsInfo::GetContentScripts( 1263 extensions::ContentScriptsInfo::GetContentScripts(
1443 loaded_[index].get()).size()); 1264 loaded_[index].get()).size());
1444 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); 1265 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location());
1445 }; 1266 };
1446 1267
1447 // Test loading bad extensions from the profile directory. 1268 // Test loading bad extensions from the profile directory.
1448 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { 1269 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) {
1449 // Initialize the test dir with a bad Preferences/extensions. 1270 // Initialize the test dir with a bad Preferences/extensions.
1450 base::FilePath source_install_dir = data_dir_ 1271 base::FilePath source_install_dir =
1451 .AppendASCII("bad") 1272 data_dir().AppendASCII("bad").AppendASCII("Extensions");
1452 .AppendASCII("Extensions");
1453 base::FilePath pref_path = 1273 base::FilePath pref_path =
1454 source_install_dir.DirName().Append(chrome::kPreferencesFilename); 1274 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
1455 1275
1456 InitializeInstalledExtensionService(pref_path, source_install_dir); 1276 InitializeInstalledExtensionService(pref_path, source_install_dir);
1457 1277
1458 service_->Init(); 1278 service()->Init();
1459 1279
1460 ASSERT_EQ(4u, GetErrors().size()); 1280 ASSERT_EQ(4u, GetErrors().size());
1461 ASSERT_EQ(0u, loaded_.size()); 1281 ASSERT_EQ(0u, loaded_.size());
1462 1282
1463 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[0]), 1283 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[0]),
1464 std::string("Could not load extension from '*'. ") + 1284 std::string("Could not load extension from '*'. ") +
1465 extensions::manifest_errors::kManifestUnreadable)) << 1285 extensions::manifest_errors::kManifestUnreadable)) <<
1466 base::UTF16ToUTF8(GetErrors()[0]); 1286 base::UTF16ToUTF8(GetErrors()[0]);
1467 1287
1468 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[1]), 1288 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[1]),
1469 std::string("Could not load extension from '*'. ") + 1289 std::string("Could not load extension from '*'. ") +
1470 extensions::manifest_errors::kManifestUnreadable)) << 1290 extensions::manifest_errors::kManifestUnreadable)) <<
1471 base::UTF16ToUTF8(GetErrors()[1]); 1291 base::UTF16ToUTF8(GetErrors()[1]);
1472 1292
1473 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[2]), 1293 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[2]),
1474 std::string("Could not load extension from '*'. ") + 1294 std::string("Could not load extension from '*'. ") +
1475 extensions::manifest_errors::kMissingFile)) << 1295 extensions::manifest_errors::kMissingFile)) <<
1476 base::UTF16ToUTF8(GetErrors()[2]); 1296 base::UTF16ToUTF8(GetErrors()[2]);
1477 1297
1478 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[3]), 1298 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[3]),
1479 std::string("Could not load extension from '*'. ") + 1299 std::string("Could not load extension from '*'. ") +
1480 extensions::manifest_errors::kManifestUnreadable)) << 1300 extensions::manifest_errors::kManifestUnreadable)) <<
1481 base::UTF16ToUTF8(GetErrors()[3]); 1301 base::UTF16ToUTF8(GetErrors()[3]);
1482 }; 1302 };
1483 1303
1484 // Test various cases for delayed install because of missing imports. 1304 // Test various cases for delayed install because of missing imports.
1485 TEST_F(ExtensionServiceTest, PendingImports) { 1305 TEST_F(ExtensionServiceTest, PendingImports) {
1486 InitPluginService(); 1306 InitPluginService();
1487 1307
1488 base::FilePath source_install_dir = data_dir_ 1308 base::FilePath source_install_dir =
1489 .AppendASCII("pending_updates_with_imports") 1309 data_dir().AppendASCII("pending_updates_with_imports").AppendASCII(
1490 .AppendASCII("Extensions"); 1310 "Extensions");
1491 base::FilePath pref_path = 1311 base::FilePath pref_path =
1492 source_install_dir.DirName().Append(chrome::kPreferencesFilename); 1312 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
1493 1313
1494 InitializeInstalledExtensionService(pref_path, source_install_dir); 1314 InitializeInstalledExtensionService(pref_path, source_install_dir);
1495 1315
1496 // Verify there are no pending extensions initially. 1316 // Verify there are no pending extensions initially.
1497 EXPECT_FALSE(service_->pending_extension_manager()->HasPendingExtensions()); 1317 EXPECT_FALSE(service()->pending_extension_manager()->HasPendingExtensions());
1498 1318
1499 service_->Init(); 1319 service()->Init();
1500 // Wait for GarbageCollectExtensions task to complete. 1320 // Wait for GarbageCollectExtensions task to complete.
1501 base::RunLoop().RunUntilIdle(); 1321 base::RunLoop().RunUntilIdle();
1502 1322
1503 // These extensions are used by the extensions we test below, they must be 1323 // These extensions are used by the extensions we test below, they must be
1504 // installed. 1324 // installed.
1505 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1325 EXPECT_TRUE(base::PathExists(extensions_install_dir().AppendASCII(
1506 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); 1326 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0")));
1507 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1327 EXPECT_TRUE(base::PathExists(extensions_install_dir().AppendASCII(
1508 "hpiknbiabeeppbpihjehijgoemciehgk/2"))); 1328 "hpiknbiabeeppbpihjehijgoemciehgk/2")));
1509 1329
1510 // Each of these extensions should have been rejected because of dependencies 1330 // Each of these extensions should have been rejected because of dependencies
1511 // that cannot be satisfied. 1331 // that cannot be satisfied.
1512 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 1332 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
1513 EXPECT_FALSE( 1333 EXPECT_FALSE(
1514 prefs->GetDelayedInstallInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); 1334 prefs->GetDelayedInstallInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
1515 EXPECT_FALSE( 1335 EXPECT_FALSE(
1516 prefs->GetInstalledExtensionInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); 1336 prefs->GetInstalledExtensionInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
1517 EXPECT_FALSE( 1337 EXPECT_FALSE(
1518 prefs->GetDelayedInstallInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); 1338 prefs->GetDelayedInstallInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"));
1519 EXPECT_FALSE( 1339 EXPECT_FALSE(
1520 prefs->GetInstalledExtensionInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); 1340 prefs->GetInstalledExtensionInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"));
1521 EXPECT_FALSE( 1341 EXPECT_FALSE(
1522 prefs->GetDelayedInstallInfo("cccccccccccccccccccccccccccccccc")); 1342 prefs->GetDelayedInstallInfo("cccccccccccccccccccccccccccccccc"));
1523 EXPECT_FALSE( 1343 EXPECT_FALSE(
1524 prefs->GetInstalledExtensionInfo("cccccccccccccccccccccccccccccccc")); 1344 prefs->GetInstalledExtensionInfo("cccccccccccccccccccccccccccccccc"));
1525 1345
1526 // Make sure the import started for the extension with a dependency. 1346 // Make sure the import started for the extension with a dependency.
1527 EXPECT_TRUE( 1347 EXPECT_TRUE(
1528 prefs->GetDelayedInstallInfo("behllobkkfkfnphdnhnkndlbkcpglgmj")); 1348 prefs->GetDelayedInstallInfo("behllobkkfkfnphdnhnkndlbkcpglgmj"));
1529 EXPECT_EQ(ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, 1349 EXPECT_EQ(ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
1530 prefs->GetDelayedInstallReason("behllobkkfkfnphdnhnkndlbkcpglgmj")); 1350 prefs->GetDelayedInstallReason("behllobkkfkfnphdnhnkndlbkcpglgmj"));
1531 1351
1532 EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII( 1352 EXPECT_FALSE(base::PathExists(extensions_install_dir().AppendASCII(
1533 "behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0"))); 1353 "behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0")));
1534 1354
1535 EXPECT_TRUE(service_->pending_extension_manager()->HasPendingExtensions()); 1355 EXPECT_TRUE(service()->pending_extension_manager()->HasPendingExtensions());
1536 std::string pending_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); 1356 std::string pending_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
1537 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(pending_id)); 1357 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(pending_id));
1538 // Remove it because we are not testing the pending extension manager's 1358 // Remove it because we are not testing the pending extension manager's
1539 // ability to download and install extensions. 1359 // ability to download and install extensions.
1540 EXPECT_TRUE(service_->pending_extension_manager()->Remove(pending_id)); 1360 EXPECT_TRUE(service()->pending_extension_manager()->Remove(pending_id));
1541 } 1361 }
1542 1362
1543 // Test installing extensions. This test tries to install few extensions using 1363 // Test installing extensions. This test tries to install few extensions using
1544 // crx files. If you need to change those crx files, feel free to repackage 1364 // crx files. If you need to change those crx files, feel free to repackage
1545 // them, throw away the key used and change the id's above. 1365 // them, throw away the key used and change the id's above.
1546 TEST_F(ExtensionServiceTest, InstallExtension) { 1366 TEST_F(ExtensionServiceTest, InstallExtension) {
1547 InitializeEmptyExtensionService(); 1367 InitializeEmptyExtensionService();
1548 1368
1549 // Extensions not enabled. 1369 // Extensions not enabled.
1550 set_extensions_enabled(false); 1370 service()->set_extensions_enabled(false);
1551 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1371 base::FilePath path = data_dir().AppendASCII("good.crx");
1552 InstallCRX(path, INSTALL_FAILED); 1372 InstallCRX(path, INSTALL_FAILED);
1553 set_extensions_enabled(true); 1373 service()->set_extensions_enabled(true);
1554 1374
1555 ValidatePrefKeyCount(0); 1375 ValidatePrefKeyCount(0);
1556 1376
1557 // A simple extension that should install without error. 1377 // A simple extension that should install without error.
1558 path = data_dir_.AppendASCII("good.crx"); 1378 path = data_dir().AppendASCII("good.crx");
1559 InstallCRX(path, INSTALL_NEW); 1379 InstallCRX(path, INSTALL_NEW);
1560 // TODO(erikkay): verify the contents of the installed extension. 1380 // TODO(erikkay): verify the contents of the installed extension.
1561 1381
1562 int pref_count = 0; 1382 int pref_count = 0;
1563 ValidatePrefKeyCount(++pref_count); 1383 ValidatePrefKeyCount(++pref_count);
1564 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 1384 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
1565 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 1385 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
1566 1386
1567 // An extension with page actions. 1387 // An extension with page actions.
1568 path = data_dir_.AppendASCII("page_action.crx"); 1388 path = data_dir().AppendASCII("page_action.crx");
1569 InstallCRX(path, INSTALL_NEW); 1389 InstallCRX(path, INSTALL_NEW);
1570 ValidatePrefKeyCount(++pref_count); 1390 ValidatePrefKeyCount(++pref_count);
1571 ValidateIntegerPref(page_action, "state", Extension::ENABLED); 1391 ValidateIntegerPref(page_action, "state", Extension::ENABLED);
1572 ValidateIntegerPref(page_action, "location", Manifest::INTERNAL); 1392 ValidateIntegerPref(page_action, "location", Manifest::INTERNAL);
1573 1393
1574 // Bad signature. 1394 // Bad signature.
1575 path = data_dir_.AppendASCII("bad_signature.crx"); 1395 path = data_dir().AppendASCII("bad_signature.crx");
1576 InstallCRX(path, INSTALL_FAILED); 1396 InstallCRX(path, INSTALL_FAILED);
1577 ValidatePrefKeyCount(pref_count); 1397 ValidatePrefKeyCount(pref_count);
1578 1398
1579 // 0-length extension file. 1399 // 0-length extension file.
1580 path = data_dir_.AppendASCII("not_an_extension.crx"); 1400 path = data_dir().AppendASCII("not_an_extension.crx");
1581 InstallCRX(path, INSTALL_FAILED); 1401 InstallCRX(path, INSTALL_FAILED);
1582 ValidatePrefKeyCount(pref_count); 1402 ValidatePrefKeyCount(pref_count);
1583 1403
1584 // Bad magic number. 1404 // Bad magic number.
1585 path = data_dir_.AppendASCII("bad_magic.crx"); 1405 path = data_dir().AppendASCII("bad_magic.crx");
1586 InstallCRX(path, INSTALL_FAILED); 1406 InstallCRX(path, INSTALL_FAILED);
1587 ValidatePrefKeyCount(pref_count); 1407 ValidatePrefKeyCount(pref_count);
1588 1408
1589 // Packed extensions may have folders or files that have underscores. 1409 // Packed extensions may have folders or files that have underscores.
1590 // This will only cause a warning, rather than a fatal error. 1410 // This will only cause a warning, rather than a fatal error.
1591 path = data_dir_.AppendASCII("bad_underscore.crx"); 1411 path = data_dir().AppendASCII("bad_underscore.crx");
1592 InstallCRX(path, INSTALL_NEW); 1412 InstallCRX(path, INSTALL_NEW);
1593 ValidatePrefKeyCount(++pref_count); 1413 ValidatePrefKeyCount(++pref_count);
1594 1414
1595 // A test for an extension with a 2048-bit public key. 1415 // A test for an extension with a 2048-bit public key.
1596 path = data_dir_.AppendASCII("good2048.crx"); 1416 path = data_dir().AppendASCII("good2048.crx");
1597 InstallCRX(path, INSTALL_NEW); 1417 InstallCRX(path, INSTALL_NEW);
1598 ValidatePrefKeyCount(++pref_count); 1418 ValidatePrefKeyCount(++pref_count);
1599 ValidateIntegerPref(good2048, "state", Extension::ENABLED); 1419 ValidateIntegerPref(good2048, "state", Extension::ENABLED);
1600 ValidateIntegerPref(good2048, "location", Manifest::INTERNAL); 1420 ValidateIntegerPref(good2048, "location", Manifest::INTERNAL);
1601 1421
1602 // TODO(erikkay): add more tests for many of the failure cases. 1422 // TODO(erikkay): add more tests for many of the failure cases.
1603 // TODO(erikkay): add tests for upgrade cases. 1423 // TODO(erikkay): add tests for upgrade cases.
1604 } 1424 }
1605 1425
1606 struct MockInstallObserver : public extensions::InstallObserver { 1426 struct MockInstallObserver : public extensions::InstallObserver {
(...skipping 14 matching lines...) Expand all
1621 std::string last_extension_installed; 1441 std::string last_extension_installed;
1622 std::string last_extension_uninstalled; 1442 std::string last_extension_uninstalled;
1623 }; 1443 };
1624 1444
1625 // Test that correct notifications are sent to InstallTracker observers on 1445 // Test that correct notifications are sent to InstallTracker observers on
1626 // extension install and uninstall. 1446 // extension install and uninstall.
1627 TEST_F(ExtensionServiceTest, InstallObserverNotified) { 1447 TEST_F(ExtensionServiceTest, InstallObserverNotified) {
1628 InitializeEmptyExtensionService(); 1448 InitializeEmptyExtensionService();
1629 1449
1630 extensions::InstallTracker* tracker( 1450 extensions::InstallTracker* tracker(
1631 extensions::InstallTrackerFactory::GetForProfile(profile_.get())); 1451 extensions::InstallTrackerFactory::GetForProfile(profile()));
1632 MockInstallObserver observer; 1452 MockInstallObserver observer;
1633 tracker->AddObserver(&observer); 1453 tracker->AddObserver(&observer);
1634 1454
1635 // A simple extension that should install without error. 1455 // A simple extension that should install without error.
1636 ASSERT_TRUE(observer.last_extension_installed.empty()); 1456 ASSERT_TRUE(observer.last_extension_installed.empty());
1637 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1457 base::FilePath path = data_dir().AppendASCII("good.crx");
1638 InstallCRX(path, INSTALL_NEW); 1458 InstallCRX(path, INSTALL_NEW);
1639 ASSERT_EQ(good_crx, observer.last_extension_installed); 1459 ASSERT_EQ(good_crx, observer.last_extension_installed);
1640 1460
1641 // Uninstall the extension. 1461 // Uninstall the extension.
1642 ASSERT_TRUE(observer.last_extension_uninstalled.empty()); 1462 ASSERT_TRUE(observer.last_extension_uninstalled.empty());
1643 UninstallExtension(good_crx, false); 1463 UninstallExtension(good_crx, false);
1644 ASSERT_EQ(good_crx, observer.last_extension_uninstalled); 1464 ASSERT_EQ(good_crx, observer.last_extension_uninstalled);
1645 1465
1646 tracker->RemoveObserver(&observer); 1466 tracker->RemoveObserver(&observer);
1647 } 1467 }
1648 1468
1649 // Tests that flags passed to OnExternalExtensionFileFound() make it to the 1469 // Tests that flags passed to OnExternalExtensionFileFound() make it to the
1650 // extension object. 1470 // extension object.
1651 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { 1471 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) {
1652 const char kPrefFromBookmark[] = "from_bookmark"; 1472 const char kPrefFromBookmark[] = "from_bookmark";
1653 1473
1654 InitializeEmptyExtensionService(); 1474 InitializeEmptyExtensionService();
1655 1475
1656 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1476 base::FilePath path = data_dir().AppendASCII("good.crx");
1657 set_extensions_enabled(true); 1477 service()->set_extensions_enabled(true);
1658 1478
1659 // Register and install an external extension. 1479 // Register and install an external extension.
1660 Version version("1.0.0.0"); 1480 Version version("1.0.0.0");
1661 content::WindowedNotificationObserver observer( 1481 content::WindowedNotificationObserver observer(
1662 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1482 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1663 content::NotificationService::AllSources()); 1483 content::NotificationService::AllSources());
1664 if (service_->OnExternalExtensionFileFound( 1484 if (service()->OnExternalExtensionFileFound(good_crx,
1665 good_crx, 1485 &version,
1666 &version, 1486 path,
1667 path, 1487 Manifest::EXTERNAL_PREF,
1668 Manifest::EXTERNAL_PREF, 1488 Extension::FROM_BOOKMARK,
1669 Extension::FROM_BOOKMARK, 1489 false /* mark_acknowledged */)) {
1670 false /* mark_acknowledged */)) {
1671 observer.Wait(); 1490 observer.Wait();
1672 } 1491 }
1673 1492
1674 const Extension* extension = service_->GetExtensionById(good_crx, false); 1493 const Extension* extension = service()->GetExtensionById(good_crx, false);
1675 ASSERT_TRUE(extension); 1494 ASSERT_TRUE(extension);
1676 ASSERT_TRUE(extension->from_bookmark()); 1495 ASSERT_TRUE(extension->from_bookmark());
1677 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); 1496 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true));
1678 1497
1679 // Upgrade to version 2.0, the flag should be preserved. 1498 // Upgrade to version 2.0, the flag should be preserved.
1680 path = data_dir_.AppendASCII("good2.crx"); 1499 path = data_dir().AppendASCII("good2.crx");
1681 UpdateExtension(good_crx, path, ENABLED); 1500 UpdateExtension(good_crx, path, ENABLED);
1682 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); 1501 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true));
1683 extension = service_->GetExtensionById(good_crx, false); 1502 extension = service()->GetExtensionById(good_crx, false);
1684 ASSERT_TRUE(extension); 1503 ASSERT_TRUE(extension);
1685 ASSERT_TRUE(extension->from_bookmark()); 1504 ASSERT_TRUE(extension->from_bookmark());
1686 } 1505 }
1687 1506
1688 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED 1507 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED
1689 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { 1508 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) {
1690 InitializeEmptyExtensionService(); 1509 InitializeEmptyExtensionService();
1691 1510
1692 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1511 base::FilePath path = data_dir().AppendASCII("good.crx");
1693 set_extensions_enabled(true); 1512 service()->set_extensions_enabled(true);
1694 1513
1695 // Install an external extension. 1514 // Install an external extension.
1696 Version version("1.0.0.0"); 1515 Version version("1.0.0.0");
1697 content::WindowedNotificationObserver observer( 1516 content::WindowedNotificationObserver observer(
1698 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1517 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1699 content::NotificationService::AllSources()); 1518 content::NotificationService::AllSources());
1700 if (service_->OnExternalExtensionFileFound(good_crx, &version, 1519 if (service()->OnExternalExtensionFileFound(good_crx,
1701 path, Manifest::EXTERNAL_PREF, 1520 &version,
1702 Extension::NO_FLAGS, false)) { 1521 path,
1522 Manifest::EXTERNAL_PREF,
1523 Extension::NO_FLAGS,
1524 false)) {
1703 observer.Wait(); 1525 observer.Wait();
1704 } 1526 }
1705 1527
1706 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); 1528 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1707 1529
1708 // Uninstall it and check that its killbit gets set. 1530 // Uninstall it and check that its killbit gets set.
1709 UninstallExtension(good_crx, false); 1531 UninstallExtension(good_crx, false);
1710 ValidateIntegerPref(good_crx, "location", 1532 ValidateIntegerPref(good_crx, "location",
1711 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1533 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1712 1534
1713 // Try to re-install it externally. This should fail because of the killbit. 1535 // Try to re-install it externally. This should fail because of the killbit.
1714 service_->OnExternalExtensionFileFound(good_crx, &version, 1536 service()->OnExternalExtensionFileFound(good_crx,
1715 path, Manifest::EXTERNAL_PREF, 1537 &version,
1716 Extension::NO_FLAGS, false); 1538 path,
1539 Manifest::EXTERNAL_PREF,
1540 Extension::NO_FLAGS,
1541 false);
1717 base::RunLoop().RunUntilIdle(); 1542 base::RunLoop().RunUntilIdle();
1718 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); 1543 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false));
1719 ValidateIntegerPref(good_crx, "location", 1544 ValidateIntegerPref(good_crx, "location",
1720 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1545 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1721 1546
1722 version = Version("1.0.0.1"); 1547 version = Version("1.0.0.1");
1723 // Repeat the same thing with a newer version of the extension. 1548 // Repeat the same thing with a newer version of the extension.
1724 path = data_dir_.AppendASCII("good2.crx"); 1549 path = data_dir().AppendASCII("good2.crx");
1725 service_->OnExternalExtensionFileFound(good_crx, &version, 1550 service()->OnExternalExtensionFileFound(good_crx,
1726 path, Manifest::EXTERNAL_PREF, 1551 &version,
1727 Extension::NO_FLAGS, false); 1552 path,
1553 Manifest::EXTERNAL_PREF,
1554 Extension::NO_FLAGS,
1555 false);
1728 base::RunLoop().RunUntilIdle(); 1556 base::RunLoop().RunUntilIdle();
1729 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); 1557 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false));
1730 ValidateIntegerPref(good_crx, "location", 1558 ValidateIntegerPref(good_crx, "location",
1731 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1559 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1732 1560
1733 // Try adding the same extension from an external update URL. 1561 // Try adding the same extension from an external update URL.
1734 ASSERT_FALSE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( 1562 ASSERT_FALSE(service()->pending_extension_manager()->AddFromExternalUpdateUrl(
1735 good_crx, 1563 good_crx,
1736 std::string(), 1564 std::string(),
1737 GURL("http:://fake.update/url"), 1565 GURL("http:://fake.update/url"),
1738 Manifest::EXTERNAL_PREF_DOWNLOAD, 1566 Manifest::EXTERNAL_PREF_DOWNLOAD,
1739 Extension::NO_FLAGS, 1567 Extension::NO_FLAGS,
1740 false)); 1568 false));
1741 1569
1742 ASSERT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); 1570 ASSERT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx));
1743 } 1571 }
1744 1572
1745 // Test that uninstalling an external extension does not crash when 1573 // Test that uninstalling an external extension does not crash when
1746 // the extension could not be loaded. 1574 // the extension could not be loaded.
1747 // This extension shown in preferences file requires an experimental permission. 1575 // This extension shown in preferences file requires an experimental permission.
1748 // It could not be loaded without such permission. 1576 // It could not be loaded without such permission.
1749 TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) { 1577 TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) {
1750 base::FilePath source_install_dir = data_dir_ 1578 base::FilePath source_install_dir =
1751 .AppendASCII("good") 1579 data_dir().AppendASCII("good").AppendASCII("Extensions");
1752 .AppendASCII("Extensions");
1753 // The preference contains an external extension 1580 // The preference contains an external extension
1754 // that requires 'experimental' permission. 1581 // that requires 'experimental' permission.
1755 base::FilePath pref_path = source_install_dir 1582 base::FilePath pref_path = source_install_dir
1756 .DirName() 1583 .DirName()
1757 .AppendASCII("PreferencesExperimental"); 1584 .AppendASCII("PreferencesExperimental");
1758 1585
1759 // Aforementioned extension will not be loaded if 1586 // Aforementioned extension will not be loaded if
1760 // there is no '--enable-experimental-extension-apis' command line flag. 1587 // there is no '--enable-experimental-extension-apis' command line flag.
1761 InitializeInstalledExtensionService(pref_path, source_install_dir); 1588 InitializeInstalledExtensionService(pref_path, source_install_dir);
1762 1589
1763 service_->Init(); 1590 service()->Init();
1764 1591
1765 // Check and try to uninstall it. 1592 // Check and try to uninstall it.
1766 // If we don't check whether the extension is loaded before we uninstall it 1593 // If we don't check whether the extension is loaded before we uninstall it
1767 // in CheckExternalUninstall, a crash will happen here because we will get or 1594 // in CheckExternalUninstall, a crash will happen here because we will get or
1768 // dereference a NULL pointer (extension) inside UninstallExtension. 1595 // dereference a NULL pointer (extension) inside UninstallExtension.
1769 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); 1596 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY);
1770 service_->OnExternalProviderReady(&provider); 1597 service()->OnExternalProviderReady(&provider);
1771 } 1598 }
1772 1599
1773 // Test that external extensions with incorrect IDs are not installed. 1600 // Test that external extensions with incorrect IDs are not installed.
1774 TEST_F(ExtensionServiceTest, FailOnWrongId) { 1601 TEST_F(ExtensionServiceTest, FailOnWrongId) {
1775 InitializeEmptyExtensionService(); 1602 InitializeEmptyExtensionService();
1776 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1603 base::FilePath path = data_dir().AppendASCII("good.crx");
1777 set_extensions_enabled(true); 1604 service()->set_extensions_enabled(true);
1778 1605
1779 Version version("1.0.0.0"); 1606 Version version("1.0.0.0");
1780 1607
1781 const std::string wrong_id = all_zero; 1608 const std::string wrong_id = all_zero;
1782 const std::string correct_id = good_crx; 1609 const std::string correct_id = good_crx;
1783 ASSERT_NE(correct_id, wrong_id); 1610 ASSERT_NE(correct_id, wrong_id);
1784 1611
1785 // Install an external extension with an ID from the external 1612 // Install an external extension with an ID from the external
1786 // source that is not equal to the ID in the extension manifest. 1613 // source that is not equal to the ID in the extension manifest.
1787 content::WindowedNotificationObserver observer( 1614 content::WindowedNotificationObserver observer(
1788 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1615 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1789 content::NotificationService::AllSources()); 1616 content::NotificationService::AllSources());
1790 service_->OnExternalExtensionFileFound( 1617 service()->OnExternalExtensionFileFound(wrong_id,
1791 wrong_id, &version, path, Manifest::EXTERNAL_PREF, 1618 &version,
1792 Extension::NO_FLAGS, false); 1619 path,
1620 Manifest::EXTERNAL_PREF,
1621 Extension::NO_FLAGS,
1622 false);
1793 1623
1794 observer.Wait(); 1624 observer.Wait();
1795 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); 1625 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
1796 1626
1797 // Try again with the right ID. Expect success. 1627 // Try again with the right ID. Expect success.
1798 content::WindowedNotificationObserver observer2( 1628 content::WindowedNotificationObserver observer2(
1799 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1629 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1800 content::NotificationService::AllSources()); 1630 content::NotificationService::AllSources());
1801 if (service_->OnExternalExtensionFileFound( 1631 if (service()->OnExternalExtensionFileFound(correct_id,
1802 correct_id, &version, path, Manifest::EXTERNAL_PREF, 1632 &version,
1803 Extension::NO_FLAGS, false)) { 1633 path,
1634 Manifest::EXTERNAL_PREF,
1635 Extension::NO_FLAGS,
1636 false)) {
1804 observer2.Wait(); 1637 observer2.Wait();
1805 } 1638 }
1806 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); 1639 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1807 } 1640 }
1808 1641
1809 // Test that external extensions with incorrect versions are not installed. 1642 // Test that external extensions with incorrect versions are not installed.
1810 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { 1643 TEST_F(ExtensionServiceTest, FailOnWrongVersion) {
1811 InitializeEmptyExtensionService(); 1644 InitializeEmptyExtensionService();
1812 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1645 base::FilePath path = data_dir().AppendASCII("good.crx");
1813 set_extensions_enabled(true); 1646 service()->set_extensions_enabled(true);
1814 1647
1815 // Install an external extension with a version from the external 1648 // Install an external extension with a version from the external
1816 // source that is not equal to the version in the extension manifest. 1649 // source that is not equal to the version in the extension manifest.
1817 Version wrong_version("1.2.3.4"); 1650 Version wrong_version("1.2.3.4");
1818 content::WindowedNotificationObserver observer( 1651 content::WindowedNotificationObserver observer(
1819 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1652 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1820 content::NotificationService::AllSources()); 1653 content::NotificationService::AllSources());
1821 service_->OnExternalExtensionFileFound( 1654 service()->OnExternalExtensionFileFound(good_crx,
1822 good_crx, &wrong_version, path, Manifest::EXTERNAL_PREF, 1655 &wrong_version,
1823 Extension::NO_FLAGS, false); 1656 path,
1657 Manifest::EXTERNAL_PREF,
1658 Extension::NO_FLAGS,
1659 false);
1824 1660
1825 observer.Wait(); 1661 observer.Wait();
1826 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); 1662 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
1827 1663
1828 // Try again with the right version. Expect success. 1664 // Try again with the right version. Expect success.
1829 service_->pending_extension_manager()->Remove(good_crx); 1665 service()->pending_extension_manager()->Remove(good_crx);
1830 Version correct_version("1.0.0.0"); 1666 Version correct_version("1.0.0.0");
1831 content::WindowedNotificationObserver observer2( 1667 content::WindowedNotificationObserver observer2(
1832 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1668 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1833 content::NotificationService::AllSources()); 1669 content::NotificationService::AllSources());
1834 if (service_->OnExternalExtensionFileFound( 1670 if (service()->OnExternalExtensionFileFound(good_crx,
1835 good_crx, &correct_version, path, Manifest::EXTERNAL_PREF, 1671 &correct_version,
1836 Extension::NO_FLAGS, false)) { 1672 path,
1673 Manifest::EXTERNAL_PREF,
1674 Extension::NO_FLAGS,
1675 false)) {
1837 observer2.Wait(); 1676 observer2.Wait();
1838 } 1677 }
1839 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); 1678 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1840 } 1679 }
1841 1680
1842 // Install a user script (they get converted automatically to an extension) 1681 // Install a user script (they get converted automatically to an extension)
1843 TEST_F(ExtensionServiceTest, InstallUserScript) { 1682 TEST_F(ExtensionServiceTest, InstallUserScript) {
1844 // The details of script conversion are tested elsewhere, this just tests 1683 // The details of script conversion are tested elsewhere, this just tests
1845 // integration with ExtensionService. 1684 // integration with ExtensionService.
1846 InitializeEmptyExtensionService(); 1685 InitializeEmptyExtensionService();
1847 1686
1848 base::FilePath path = data_dir_ 1687 base::FilePath path = data_dir().AppendASCII("user_script_basic.user.js");
1849 .AppendASCII("user_script_basic.user.js");
1850 1688
1851 ASSERT_TRUE(base::PathExists(path)); 1689 ASSERT_TRUE(base::PathExists(path));
1852 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service_)); 1690 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service()));
1853 installer->set_allow_silent_install(true); 1691 installer->set_allow_silent_install(true);
1854 installer->InstallUserScript( 1692 installer->InstallUserScript(
1855 path, 1693 path,
1856 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); 1694 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js"));
1857 1695
1858 base::RunLoop().RunUntilIdle(); 1696 base::RunLoop().RunUntilIdle();
1859 std::vector<base::string16> errors = GetErrors(); 1697 std::vector<base::string16> errors = GetErrors();
1860 EXPECT_TRUE(installed_) << "Nothing was installed."; 1698 EXPECT_TRUE(installed_) << "Nothing was installed.";
1861 EXPECT_FALSE(was_update_) << path.value(); 1699 EXPECT_FALSE(was_update_) << path.value();
1862 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; 1700 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded.";
1863 EXPECT_EQ(0u, errors.size()) << "There were errors: " 1701 EXPECT_EQ(0u, errors.size()) << "There were errors: "
1864 << JoinString(errors, ','); 1702 << JoinString(errors, ',');
1865 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << 1703 EXPECT_TRUE(service()->GetExtensionById(loaded_[0]->id(), false))
1866 path.value(); 1704 << path.value();
1867 1705
1868 installed_ = NULL; 1706 installed_ = NULL;
1869 was_update_ = false; 1707 was_update_ = false;
1870 loaded_.clear(); 1708 loaded_.clear();
1871 ExtensionErrorReporter::GetInstance()->ClearErrors(); 1709 ExtensionErrorReporter::GetInstance()->ClearErrors();
1872 } 1710 }
1873 1711
1874 // Extensions don't install during shutdown. 1712 // Extensions don't install during shutdown.
1875 TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) { 1713 TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) {
1876 InitializeEmptyExtensionService(); 1714 InitializeEmptyExtensionService();
1877 1715
1878 // Simulate shutdown. 1716 // Simulate shutdown.
1879 service_->set_browser_terminating_for_test(true); 1717 service()->set_browser_terminating_for_test(true);
1880 1718
1881 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1719 base::FilePath path = data_dir().AppendASCII("good.crx");
1882 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service_)); 1720 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service()));
1883 installer->set_allow_silent_install(true); 1721 installer->set_allow_silent_install(true);
1884 installer->InstallCrx(path); 1722 installer->InstallCrx(path);
1885 base::RunLoop().RunUntilIdle(); 1723 base::RunLoop().RunUntilIdle();
1886 1724
1887 EXPECT_FALSE(installed_) << "Extension installed during shutdown."; 1725 EXPECT_FALSE(installed_) << "Extension installed during shutdown.";
1888 ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown."; 1726 ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown.";
1889 } 1727 }
1890 1728
1891 // This tests that the granted permissions preferences are correctly set when 1729 // This tests that the granted permissions preferences are correctly set when
1892 // installing an extension. 1730 // installing an extension.
1893 TEST_F(ExtensionServiceTest, GrantedPermissions) { 1731 TEST_F(ExtensionServiceTest, GrantedPermissions) {
1894 InitializeEmptyExtensionService(); 1732 InitializeEmptyExtensionService();
1895 base::FilePath path = data_dir_ 1733 base::FilePath path = data_dir().AppendASCII("permissions");
1896 .AppendASCII("permissions");
1897 1734
1898 base::FilePath pem_path = path.AppendASCII("unknown.pem"); 1735 base::FilePath pem_path = path.AppendASCII("unknown.pem");
1899 path = path.AppendASCII("unknown"); 1736 path = path.AppendASCII("unknown");
1900 1737
1901 ASSERT_TRUE(base::PathExists(pem_path)); 1738 ASSERT_TRUE(base::PathExists(pem_path));
1902 ASSERT_TRUE(base::PathExists(path)); 1739 ASSERT_TRUE(base::PathExists(path));
1903 1740
1904 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 1741 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
1905 1742
1906 APIPermissionSet expected_api_perms; 1743 APIPermissionSet expected_api_perms;
1907 URLPatternSet expected_host_perms; 1744 URLPatternSet expected_host_perms;
1908 1745
1909 // Make sure there aren't any granted permissions before the 1746 // Make sure there aren't any granted permissions before the
1910 // extension is installed. 1747 // extension is installed.
1911 scoped_refptr<PermissionSet> known_perms( 1748 scoped_refptr<PermissionSet> known_perms(
1912 prefs->GetGrantedPermissions(permissions_crx)); 1749 prefs->GetGrantedPermissions(permissions_crx));
1913 EXPECT_FALSE(known_perms.get()); 1750 EXPECT_FALSE(known_perms.get());
1914 1751
1915 const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); 1752 const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW);
1916 1753
1917 EXPECT_EQ(0u, GetErrors().size()); 1754 EXPECT_EQ(0u, GetErrors().size());
1918 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 1755 ASSERT_EQ(1u, registry()->enabled_extensions().size());
1919 EXPECT_EQ(permissions_crx, extension->id()); 1756 EXPECT_EQ(permissions_crx, extension->id());
1920 1757
1921 // Verify that the valid API permissions have been recognized. 1758 // Verify that the valid API permissions have been recognized.
1922 expected_api_perms.insert(APIPermission::kTab); 1759 expected_api_perms.insert(APIPermission::kTab);
1923 1760
1924 AddPattern(&expected_host_perms, "http://*.google.com/*"); 1761 AddPattern(&expected_host_perms, "http://*.google.com/*");
1925 AddPattern(&expected_host_perms, "https://*.google.com/*"); 1762 AddPattern(&expected_host_perms, "https://*.google.com/*");
1926 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); 1763 AddPattern(&expected_host_perms, "http://*.google.com.hk/*");
1927 AddPattern(&expected_host_perms, "http://www.example.com/*"); 1764 AddPattern(&expected_host_perms, "http://www.example.com/*");
1928 1765
1929 known_perms = prefs->GetGrantedPermissions(extension->id()); 1766 known_perms = prefs->GetGrantedPermissions(extension->id());
1930 EXPECT_TRUE(known_perms.get()); 1767 EXPECT_TRUE(known_perms.get());
1931 EXPECT_FALSE(known_perms->IsEmpty()); 1768 EXPECT_FALSE(known_perms->IsEmpty());
1932 EXPECT_EQ(expected_api_perms, known_perms->apis()); 1769 EXPECT_EQ(expected_api_perms, known_perms->apis());
1933 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); 1770 EXPECT_FALSE(known_perms->HasEffectiveFullAccess());
1934 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); 1771 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts());
1935 } 1772 }
1936 1773
1937 1774
1938 #if !defined(OS_CHROMEOS) 1775 #if !defined(OS_CHROMEOS)
1939 // This tests that the granted permissions preferences are correctly set for 1776 // This tests that the granted permissions preferences are correctly set for
1940 // default apps. 1777 // default apps.
1941 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { 1778 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) {
1942 InitializeEmptyExtensionService(); 1779 InitializeEmptyExtensionService();
1943 base::FilePath path = data_dir_ 1780 base::FilePath path = data_dir().AppendASCII("permissions");
1944 .AppendASCII("permissions");
1945 1781
1946 base::FilePath pem_path = path.AppendASCII("unknown.pem"); 1782 base::FilePath pem_path = path.AppendASCII("unknown.pem");
1947 path = path.AppendASCII("unknown"); 1783 path = path.AppendASCII("unknown");
1948 1784
1949 ASSERT_TRUE(base::PathExists(pem_path)); 1785 ASSERT_TRUE(base::PathExists(pem_path));
1950 ASSERT_TRUE(base::PathExists(path)); 1786 ASSERT_TRUE(base::PathExists(path));
1951 1787
1952 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 1788 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
1953 1789
1954 APIPermissionSet expected_api_perms; 1790 APIPermissionSet expected_api_perms;
1955 URLPatternSet expected_host_perms; 1791 URLPatternSet expected_host_perms;
1956 1792
1957 // Make sure there aren't any granted permissions before the 1793 // Make sure there aren't any granted permissions before the
1958 // extension is installed. 1794 // extension is installed.
1959 scoped_refptr<PermissionSet> known_perms( 1795 scoped_refptr<PermissionSet> known_perms(
1960 prefs->GetGrantedPermissions(permissions_crx)); 1796 prefs->GetGrantedPermissions(permissions_crx));
1961 EXPECT_FALSE(known_perms.get()); 1797 EXPECT_FALSE(known_perms.get());
1962 1798
1963 const Extension* extension = PackAndInstallCRX( 1799 const Extension* extension = PackAndInstallCRX(
1964 path, pem_path, INSTALL_NEW, Extension::WAS_INSTALLED_BY_DEFAULT); 1800 path, pem_path, INSTALL_NEW, Extension::WAS_INSTALLED_BY_DEFAULT);
1965 1801
1966 EXPECT_EQ(0u, GetErrors().size()); 1802 EXPECT_EQ(0u, GetErrors().size());
1967 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 1803 ASSERT_EQ(1u, registry()->enabled_extensions().size());
1968 EXPECT_EQ(permissions_crx, extension->id()); 1804 EXPECT_EQ(permissions_crx, extension->id());
1969 1805
1970 // Verify that the valid API permissions have been recognized. 1806 // Verify that the valid API permissions have been recognized.
1971 expected_api_perms.insert(APIPermission::kTab); 1807 expected_api_perms.insert(APIPermission::kTab);
1972 1808
1973 known_perms = prefs->GetGrantedPermissions(extension->id()); 1809 known_perms = prefs->GetGrantedPermissions(extension->id());
1974 EXPECT_TRUE(known_perms.get()); 1810 EXPECT_TRUE(known_perms.get());
1975 EXPECT_FALSE(known_perms->IsEmpty()); 1811 EXPECT_FALSE(known_perms->IsEmpty());
1976 EXPECT_EQ(expected_api_perms, known_perms->apis()); 1812 EXPECT_EQ(expected_api_perms, known_perms->apis());
1977 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); 1813 EXPECT_FALSE(known_perms->HasEffectiveFullAccess());
1978 } 1814 }
1979 #endif 1815 #endif
1980 1816
1981 #if !defined(OS_POSIX) || defined(OS_MACOSX) 1817 #if !defined(OS_POSIX) || defined(OS_MACOSX)
1982 // Tests that the granted permissions full_access bit gets set correctly when 1818 // Tests that the granted permissions full_access bit gets set correctly when
1983 // an extension contains an NPAPI plugin. 1819 // an extension contains an NPAPI plugin.
1984 // Only run this on platforms that support NPAPI plugins. 1820 // Only run this on platforms that support NPAPI plugins.
1985 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { 1821 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) {
1986 InitPluginService(); 1822 InitPluginService();
1987 1823
1988 InitializeEmptyExtensionService(); 1824 InitializeEmptyExtensionService();
1989 1825
1990 ASSERT_TRUE(base::PathExists(good1_path())); 1826 ASSERT_TRUE(base::PathExists(good1_path()));
1991 const Extension* extension = PackAndInstallCRX(good1_path(), INSTALL_NEW); 1827 const Extension* extension = PackAndInstallCRX(good1_path(), INSTALL_NEW);
1992 EXPECT_EQ(0u, GetErrors().size()); 1828 EXPECT_EQ(0u, GetErrors().size());
1993 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 1829 EXPECT_EQ(1u, registry()->enabled_extensions().size());
1994 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 1830 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
1995 1831
1996 scoped_refptr<PermissionSet> permissions( 1832 scoped_refptr<PermissionSet> permissions(
1997 prefs->GetGrantedPermissions(extension->id())); 1833 prefs->GetGrantedPermissions(extension->id()));
1998 EXPECT_FALSE(permissions->IsEmpty()); 1834 EXPECT_FALSE(permissions->IsEmpty());
1999 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); 1835 EXPECT_TRUE(permissions->HasEffectiveFullAccess());
2000 EXPECT_FALSE(permissions->apis().empty()); 1836 EXPECT_FALSE(permissions->apis().empty());
2001 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); 1837 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin));
2002 1838
2003 // Full access implies full host access too... 1839 // Full access implies full host access too...
2004 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); 1840 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts());
2005 } 1841 }
2006 #endif 1842 #endif
2007 1843
2008 // Tests that the extension is disabled when permissions are missing from 1844 // Tests that the extension is disabled when permissions are missing from
2009 // the extension's granted permissions preferences. (This simulates updating 1845 // the extension's granted permissions preferences. (This simulates updating
2010 // the browser to a version which recognizes more permissions). 1846 // the browser to a version which recognizes more permissions).
2011 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { 1847 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
2012 InitializeEmptyExtensionService(); 1848 InitializeEmptyExtensionService();
2013 1849
2014 base::FilePath path = data_dir_ 1850 base::FilePath path =
2015 .AppendASCII("permissions") 1851 data_dir().AppendASCII("permissions").AppendASCII("unknown");
2016 .AppendASCII("unknown");
2017 1852
2018 ASSERT_TRUE(base::PathExists(path)); 1853 ASSERT_TRUE(base::PathExists(path));
2019 1854
2020 const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW); 1855 const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW);
2021 1856
2022 EXPECT_EQ(0u, GetErrors().size()); 1857 EXPECT_EQ(0u, GetErrors().size());
2023 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 1858 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2024 std::string extension_id = extension->id(); 1859 std::string extension_id = extension->id();
2025 1860
2026 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 1861 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
2027 1862
2028 APIPermissionSet expected_api_permissions; 1863 APIPermissionSet expected_api_permissions;
2029 URLPatternSet expected_host_permissions; 1864 URLPatternSet expected_host_permissions;
2030 1865
2031 expected_api_permissions.insert(APIPermission::kTab); 1866 expected_api_permissions.insert(APIPermission::kTab);
2032 AddPattern(&expected_host_permissions, "http://*.google.com/*"); 1867 AddPattern(&expected_host_permissions, "http://*.google.com/*");
2033 AddPattern(&expected_host_permissions, "https://*.google.com/*"); 1868 AddPattern(&expected_host_permissions, "https://*.google.com/*");
2034 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); 1869 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*");
2035 AddPattern(&expected_host_permissions, "http://www.example.com/*"); 1870 AddPattern(&expected_host_permissions, "http://www.example.com/*");
2036 1871
2037 std::set<std::string> host_permissions; 1872 std::set<std::string> host_permissions;
2038 1873
2039 // Test that the extension is disabled when an API permission is missing from 1874 // Test that the extension is disabled when an API permission is missing from
2040 // the extension's granted api permissions preference. (This simulates 1875 // the extension's granted api permissions preference. (This simulates
2041 // updating the browser to a version which recognizes a new API permission). 1876 // updating the browser to a version which recognizes a new API permission).
2042 SetPref(extension_id, "granted_permissions.api", 1877 SetPref(extension_id, "granted_permissions.api",
2043 new base::ListValue(), "granted_permissions.api"); 1878 new base::ListValue(), "granted_permissions.api");
2044 service_->ReloadExtensionsForTest(); 1879 service()->ReloadExtensionsForTest();
2045 1880
2046 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 1881 EXPECT_EQ(1u, registry()->disabled_extensions().size());
2047 extension = registry_->disabled_extensions().begin()->get(); 1882 extension = registry()->disabled_extensions().begin()->get();
2048 1883
2049 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); 1884 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id));
2050 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); 1885 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id));
2051 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); 1886 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
2052 1887
2053 // Now grant and re-enable the extension, making sure the prefs are updated. 1888 // Now grant and re-enable the extension, making sure the prefs are updated.
2054 service_->GrantPermissionsAndEnableExtension(extension); 1889 service()->GrantPermissionsAndEnableExtension(extension);
2055 1890
2056 ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id)); 1891 ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id));
2057 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); 1892 ASSERT_TRUE(service()->IsExtensionEnabled(extension_id));
2058 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); 1893 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
2059 1894
2060 scoped_refptr<PermissionSet> current_perms( 1895 scoped_refptr<PermissionSet> current_perms(
2061 prefs->GetGrantedPermissions(extension_id)); 1896 prefs->GetGrantedPermissions(extension_id));
2062 ASSERT_TRUE(current_perms.get()); 1897 ASSERT_TRUE(current_perms.get());
2063 ASSERT_FALSE(current_perms->IsEmpty()); 1898 ASSERT_FALSE(current_perms->IsEmpty());
2064 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); 1899 ASSERT_FALSE(current_perms->HasEffectiveFullAccess());
2065 ASSERT_EQ(expected_api_permissions, current_perms->apis()); 1900 ASSERT_EQ(expected_api_permissions, current_perms->apis());
2066 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); 1901 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts());
2067 1902
2068 // Tests that the extension is disabled when a host permission is missing from 1903 // Tests that the extension is disabled when a host permission is missing from
2069 // the extension's granted host permissions preference. (This simulates 1904 // the extension's granted host permissions preference. (This simulates
2070 // updating the browser to a version which recognizes additional host 1905 // updating the browser to a version which recognizes additional host
2071 // permissions). 1906 // permissions).
2072 host_permissions.clear(); 1907 host_permissions.clear();
2073 current_perms = NULL; 1908 current_perms = NULL;
2074 1909
2075 host_permissions.insert("http://*.google.com/*"); 1910 host_permissions.insert("http://*.google.com/*");
2076 host_permissions.insert("https://*.google.com/*"); 1911 host_permissions.insert("https://*.google.com/*");
2077 host_permissions.insert("http://*.google.com.hk/*"); 1912 host_permissions.insert("http://*.google.com.hk/*");
2078 1913
2079 base::ListValue* api_permissions = new base::ListValue(); 1914 base::ListValue* api_permissions = new base::ListValue();
2080 api_permissions->Append( 1915 api_permissions->Append(
2081 new base::StringValue("tabs")); 1916 new base::StringValue("tabs"));
2082 SetPref(extension_id, "granted_permissions.api", 1917 SetPref(extension_id, "granted_permissions.api",
2083 api_permissions, "granted_permissions.api"); 1918 api_permissions, "granted_permissions.api");
2084 SetPrefStringSet( 1919 SetPrefStringSet(
2085 extension_id, "granted_permissions.scriptable_host", host_permissions); 1920 extension_id, "granted_permissions.scriptable_host", host_permissions);
2086 1921
2087 service_->ReloadExtensionsForTest(); 1922 service()->ReloadExtensionsForTest();
2088 1923
2089 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 1924 EXPECT_EQ(1u, registry()->disabled_extensions().size());
2090 extension = registry_->disabled_extensions().begin()->get(); 1925 extension = registry()->disabled_extensions().begin()->get();
2091 1926
2092 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); 1927 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id));
2093 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); 1928 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id));
2094 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); 1929 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
2095 1930
2096 // Now grant and re-enable the extension, making sure the prefs are updated. 1931 // Now grant and re-enable the extension, making sure the prefs are updated.
2097 service_->GrantPermissionsAndEnableExtension(extension); 1932 service()->GrantPermissionsAndEnableExtension(extension);
2098 1933
2099 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); 1934 ASSERT_TRUE(service()->IsExtensionEnabled(extension_id));
2100 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); 1935 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
2101 1936
2102 current_perms = prefs->GetGrantedPermissions(extension_id); 1937 current_perms = prefs->GetGrantedPermissions(extension_id);
2103 ASSERT_TRUE(current_perms.get()); 1938 ASSERT_TRUE(current_perms.get());
2104 ASSERT_FALSE(current_perms->IsEmpty()); 1939 ASSERT_FALSE(current_perms->IsEmpty());
2105 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); 1940 ASSERT_FALSE(current_perms->HasEffectiveFullAccess());
2106 ASSERT_EQ(expected_api_permissions, current_perms->apis()); 1941 ASSERT_EQ(expected_api_permissions, current_perms->apis());
2107 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); 1942 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts());
2108 } 1943 }
2109 1944
2110 // Test Packaging and installing an extension. 1945 // Test Packaging and installing an extension.
2111 TEST_F(ExtensionServiceTest, PackExtension) { 1946 TEST_F(ExtensionServiceTest, PackExtension) {
2112 InitializeEmptyExtensionService(); 1947 InitializeEmptyExtensionService();
2113 base::FilePath input_directory = data_dir_ 1948 base::FilePath input_directory =
2114 .AppendASCII("good") 1949 data_dir()
2115 .AppendASCII("Extensions") 1950 .AppendASCII("good")
2116 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 1951 .AppendASCII("Extensions")
2117 .AppendASCII("1.0.0.0"); 1952 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
1953 .AppendASCII("1.0.0.0");
2118 1954
2119 base::ScopedTempDir temp_dir; 1955 base::ScopedTempDir temp_dir;
2120 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1956 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
2121 base::FilePath output_directory = temp_dir.path(); 1957 base::FilePath output_directory = temp_dir.path();
2122 1958
2123 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); 1959 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
2124 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); 1960 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem"));
2125 1961
2126 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); 1962 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
2127 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), 1963 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2165 std::string invalid_manifest_content = "I am not a manifest."; 2001 std::string invalid_manifest_content = "I am not a manifest.";
2166 ASSERT_TRUE(base::WriteFile( 2002 ASSERT_TRUE(base::WriteFile(
2167 temp_dir2.path().Append(extensions::kManifestFilename), 2003 temp_dir2.path().Append(extensions::kManifestFilename),
2168 invalid_manifest_content.c_str(), invalid_manifest_content.size())); 2004 invalid_manifest_content.c_str(), invalid_manifest_content.size()));
2169 creator.reset(new ExtensionCreator()); 2005 creator.reset(new ExtensionCreator());
2170 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, 2006 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path,
2171 base::FilePath(), ExtensionCreator::kOverwriteCRX)); 2007 base::FilePath(), ExtensionCreator::kOverwriteCRX));
2172 2008
2173 // Try packing with a private key that is a valid key, but invalid for the 2009 // Try packing with a private key that is a valid key, but invalid for the
2174 // extension. 2010 // extension.
2175 base::FilePath bad_private_key_dir = data_dir_.AppendASCII("bad_private_key"); 2011 base::FilePath bad_private_key_dir =
2012 data_dir().AppendASCII("bad_private_key");
2176 crx_path = output_directory.AppendASCII("bad_private_key.crx"); 2013 crx_path = output_directory.AppendASCII("bad_private_key.crx");
2177 privkey_path = data_dir_.AppendASCII("bad_private_key.pem"); 2014 privkey_path = data_dir().AppendASCII("bad_private_key.pem");
2178 ASSERT_FALSE(creator->Run(bad_private_key_dir, crx_path, base::FilePath(), 2015 ASSERT_FALSE(creator->Run(bad_private_key_dir, crx_path, base::FilePath(),
2179 privkey_path, ExtensionCreator::kOverwriteCRX)); 2016 privkey_path, ExtensionCreator::kOverwriteCRX));
2180 } 2017 }
2181 2018
2182 // Test Packaging and installing an extension whose name contains punctuation. 2019 // Test Packaging and installing an extension whose name contains punctuation.
2183 TEST_F(ExtensionServiceTest, PackPunctuatedExtension) { 2020 TEST_F(ExtensionServiceTest, PackPunctuatedExtension) {
2184 InitializeEmptyExtensionService(); 2021 InitializeEmptyExtensionService();
2185 base::FilePath input_directory = data_dir_ 2022 base::FilePath input_directory = data_dir()
2186 .AppendASCII("good") 2023 .AppendASCII("good")
2187 .AppendASCII("Extensions") 2024 .AppendASCII("Extensions")
2188 .AppendASCII(good0) 2025 .AppendASCII(good0)
2189 .AppendASCII("1.0.0.0"); 2026 .AppendASCII("1.0.0.0");
2190 2027
2191 base::ScopedTempDir temp_dir; 2028 base::ScopedTempDir temp_dir;
2192 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 2029 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
2193 2030
2194 // Extension names containing punctuation, and the expected names for the 2031 // Extension names containing punctuation, and the expected names for the
2195 // packed extensions. 2032 // packed extensions.
2196 const base::FilePath punctuated_names[] = { 2033 const base::FilePath punctuated_names[] = {
2197 base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods")), 2034 base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods")),
2198 base::FilePath(FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod")), 2035 base::FilePath(FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod")),
2199 base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname/")). 2036 base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname/")).
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 InstallCRX(expected_crx_path, INSTALL_NEW); 2082 InstallCRX(expected_crx_path, INSTALL_NEW);
2246 } 2083 }
2247 } 2084 }
2248 2085
2249 TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) { 2086 TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) {
2250 InitializeEmptyExtensionService(); 2087 InitializeEmptyExtensionService();
2251 2088
2252 base::ScopedTempDir extension_temp_dir; 2089 base::ScopedTempDir extension_temp_dir;
2253 ASSERT_TRUE(extension_temp_dir.CreateUniqueTempDir()); 2090 ASSERT_TRUE(extension_temp_dir.CreateUniqueTempDir());
2254 base::FilePath input_directory = extension_temp_dir.path().AppendASCII("ext"); 2091 base::FilePath input_directory = extension_temp_dir.path().AppendASCII("ext");
2255 ASSERT_TRUE(base::CopyDirectory( 2092 ASSERT_TRUE(
2256 data_dir_ 2093 base::CopyDirectory(data_dir()
2257 .AppendASCII("good") 2094 .AppendASCII("good")
2258 .AppendASCII("Extensions") 2095 .AppendASCII("Extensions")
2259 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 2096 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
2260 .AppendASCII("1.0.0.0"), 2097 .AppendASCII("1.0.0.0"),
2261 input_directory, 2098 input_directory,
2262 /*recursive=*/true)); 2099 /*recursive=*/true));
2263 2100
2264 base::ScopedTempDir output_temp_dir; 2101 base::ScopedTempDir output_temp_dir;
2265 ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir()); 2102 ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir());
2266 base::FilePath output_directory = output_temp_dir.path(); 2103 base::FilePath output_directory = output_temp_dir.path();
2267 2104
2268 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); 2105 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
2269 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); 2106 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem"));
2270 2107
2271 // Pack the extension once to get a private key. 2108 // Pack the extension once to get a private key.
2272 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); 2109 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
(...skipping 17 matching lines...) Expand all
2290 } 2127 }
2291 2128
2292 // Test Packaging and installing an extension using an openssl generated key. 2129 // Test Packaging and installing an extension using an openssl generated key.
2293 // The openssl is generated with the following: 2130 // The openssl is generated with the following:
2294 // > openssl genrsa -out privkey.pem 1024 2131 // > openssl genrsa -out privkey.pem 1024
2295 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem 2132 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem
2296 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a 2133 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a
2297 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. 2134 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects.
2298 TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) { 2135 TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) {
2299 InitializeEmptyExtensionService(); 2136 InitializeEmptyExtensionService();
2300 base::FilePath input_directory = data_dir_ 2137 base::FilePath input_directory =
2301 .AppendASCII("good") 2138 data_dir()
2302 .AppendASCII("Extensions") 2139 .AppendASCII("good")
2303 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 2140 .AppendASCII("Extensions")
2304 .AppendASCII("1.0.0.0"); 2141 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
2305 base::FilePath privkey_path(data_dir_.AppendASCII( 2142 .AppendASCII("1.0.0.0");
2306 "openssl_privkey_asn1.pem")); 2143 base::FilePath privkey_path(
2144 data_dir().AppendASCII("openssl_privkey_asn1.pem"));
2307 ASSERT_TRUE(base::PathExists(privkey_path)); 2145 ASSERT_TRUE(base::PathExists(privkey_path));
2308 2146
2309 base::ScopedTempDir temp_dir; 2147 base::ScopedTempDir temp_dir;
2310 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 2148 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
2311 base::FilePath output_directory = temp_dir.path(); 2149 base::FilePath output_directory = temp_dir.path();
2312 2150
2313 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); 2151 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
2314 2152
2315 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); 2153 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
2316 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, 2154 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path,
2317 base::FilePath(), ExtensionCreator::kOverwriteCRX)); 2155 base::FilePath(), ExtensionCreator::kOverwriteCRX));
2318 2156
2319 InstallCRX(crx_path, INSTALL_NEW); 2157 InstallCRX(crx_path, INSTALL_NEW);
2320 } 2158 }
2321 2159
2322 #if defined(THREAD_SANITIZER) 2160 #if defined(THREAD_SANITIZER)
2323 // Flaky under Tsan. http://crbug.com/377702 2161 // Flaky under Tsan. http://crbug.com/377702
2324 #define MAYBE_InstallTheme DISABLED_InstallTheme 2162 #define MAYBE_InstallTheme DISABLED_InstallTheme
2325 #else 2163 #else
2326 #define MAYBE_InstallTheme InstallTheme 2164 #define MAYBE_InstallTheme InstallTheme
2327 #endif 2165 #endif
2328 2166
2329 TEST_F(ExtensionServiceTest, MAYBE_InstallTheme) { 2167 TEST_F(ExtensionServiceTest, MAYBE_InstallTheme) {
2330 InitializeEmptyExtensionService(); 2168 InitializeEmptyExtensionService();
2331 service_->Init(); 2169 service()->Init();
2332 2170
2333 // A theme. 2171 // A theme.
2334 base::FilePath path = data_dir_.AppendASCII("theme.crx"); 2172 base::FilePath path = data_dir().AppendASCII("theme.crx");
2335 InstallCRX(path, INSTALL_NEW); 2173 InstallCRX(path, INSTALL_NEW);
2336 int pref_count = 0; 2174 int pref_count = 0;
2337 ValidatePrefKeyCount(++pref_count); 2175 ValidatePrefKeyCount(++pref_count);
2338 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); 2176 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED);
2339 ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL); 2177 ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL);
2340 2178
2341 // A theme when extensions are disabled. Themes can be installed, even when 2179 // A theme when extensions are disabled. Themes can be installed, even when
2342 // extensions are disabled. 2180 // extensions are disabled.
2343 set_extensions_enabled(false); 2181 service()->set_extensions_enabled(false);
2344 path = data_dir_.AppendASCII("theme2.crx"); 2182 path = data_dir().AppendASCII("theme2.crx");
2345 InstallCRX(path, INSTALL_NEW); 2183 InstallCRX(path, INSTALL_NEW);
2346 ValidatePrefKeyCount(++pref_count); 2184 ValidatePrefKeyCount(++pref_count);
2347 ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED); 2185 ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED);
2348 ValidateIntegerPref(theme2_crx, "location", Manifest::INTERNAL); 2186 ValidateIntegerPref(theme2_crx, "location", Manifest::INTERNAL);
2349 2187
2350 // A theme with extension elements. Themes cannot have extension elements, 2188 // A theme with extension elements. Themes cannot have extension elements,
2351 // so any such elements (like content scripts) should be ignored. 2189 // so any such elements (like content scripts) should be ignored.
2352 set_extensions_enabled(true); 2190 service()->set_extensions_enabled(true);
2353 { 2191 {
2354 path = data_dir_.AppendASCII("theme_with_extension.crx"); 2192 path = data_dir().AppendASCII("theme_with_extension.crx");
2355 const Extension* extension = InstallCRX(path, INSTALL_NEW); 2193 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2356 ValidatePrefKeyCount(++pref_count); 2194 ValidatePrefKeyCount(++pref_count);
2357 ASSERT_TRUE(extension); 2195 ASSERT_TRUE(extension);
2358 EXPECT_TRUE(extension->is_theme()); 2196 EXPECT_TRUE(extension->is_theme());
2359 EXPECT_EQ( 2197 EXPECT_EQ(
2360 0u, 2198 0u,
2361 extensions::ContentScriptsInfo::GetContentScripts(extension).size()); 2199 extensions::ContentScriptsInfo::GetContentScripts(extension).size());
2362 } 2200 }
2363 2201
2364 // A theme with image resources missing (misspelt path). 2202 // A theme with image resources missing (misspelt path).
2365 path = data_dir_.AppendASCII("theme_missing_image.crx"); 2203 path = data_dir().AppendASCII("theme_missing_image.crx");
2366 InstallCRX(path, INSTALL_FAILED); 2204 InstallCRX(path, INSTALL_FAILED);
2367 ValidatePrefKeyCount(pref_count); 2205 ValidatePrefKeyCount(pref_count);
2368 } 2206 }
2369 2207
2370 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { 2208 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) {
2371 // Load. 2209 // Load.
2372 InitializeEmptyExtensionService(); 2210 InitializeEmptyExtensionService();
2373 service_->Init(); 2211 service()->Init();
2374 2212
2375 base::FilePath extension_path = data_dir_ 2213 base::FilePath extension_path = data_dir().AppendASCII("theme_i18n");
2376 .AppendASCII("theme_i18n");
2377 2214
2378 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2215 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
2379 base::RunLoop().RunUntilIdle(); 2216 base::RunLoop().RunUntilIdle();
2380 EXPECT_EQ(0u, GetErrors().size()); 2217 EXPECT_EQ(0u, GetErrors().size());
2381 ASSERT_EQ(1u, loaded_.size()); 2218 ASSERT_EQ(1u, loaded_.size());
2382 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2219 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2383 const Extension* theme = registry_->enabled_extensions().begin()->get(); 2220 const Extension* theme = registry()->enabled_extensions().begin()->get();
2384 EXPECT_EQ("name", theme->name()); 2221 EXPECT_EQ("name", theme->name());
2385 EXPECT_EQ("description", theme->description()); 2222 EXPECT_EQ("description", theme->description());
2386 2223
2387 // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a 2224 // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a
2388 // temporary directory, but it automatically installs to the extension's 2225 // temporary directory, but it automatically installs to the extension's
2389 // directory, and we don't want to copy the whole extension for a unittest. 2226 // directory, and we don't want to copy the whole extension for a unittest.
2390 base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename); 2227 base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename);
2391 ASSERT_TRUE(base::PathExists(theme_file)); 2228 ASSERT_TRUE(base::PathExists(theme_file));
2392 ASSERT_TRUE(base::DeleteFile(theme_file, false)); // Not recursive. 2229 ASSERT_TRUE(base::DeleteFile(theme_file, false)); // Not recursive.
2393 } 2230 }
2394 2231
2395 // Tests that we can change the ID of an unpacked extension by adding a key 2232 // Tests that we can change the ID of an unpacked extension by adding a key
2396 // to its manifest. 2233 // to its manifest.
2397 TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) { 2234 TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) {
2398 InitializeEmptyExtensionService(); 2235 InitializeEmptyExtensionService();
2399 2236
2400 base::ScopedTempDir temp; 2237 base::ScopedTempDir temp;
2401 ASSERT_TRUE(temp.CreateUniqueTempDir()); 2238 ASSERT_TRUE(temp.CreateUniqueTempDir());
2402 2239
2403 base::FilePath extension_path = temp.path(); 2240 base::FilePath extension_path = temp.path();
2404 base::FilePath manifest_path = 2241 base::FilePath manifest_path =
2405 extension_path.Append(extensions::kManifestFilename); 2242 extension_path.Append(extensions::kManifestFilename);
2406 base::FilePath manifest_no_key = data_dir_. 2243 base::FilePath manifest_no_key =
2407 AppendASCII("unpacked"). 2244 data_dir().AppendASCII("unpacked").AppendASCII("manifest_no_key.json");
2408 AppendASCII("manifest_no_key.json");
2409 2245
2410 base::FilePath manifest_with_key = data_dir_. 2246 base::FilePath manifest_with_key =
2411 AppendASCII("unpacked"). 2247 data_dir().AppendASCII("unpacked").AppendASCII("manifest_with_key.json");
2412 AppendASCII("manifest_with_key.json");
2413 2248
2414 ASSERT_TRUE(base::PathExists(manifest_no_key)); 2249 ASSERT_TRUE(base::PathExists(manifest_no_key));
2415 ASSERT_TRUE(base::PathExists(manifest_with_key)); 2250 ASSERT_TRUE(base::PathExists(manifest_with_key));
2416 2251
2417 // Load the unpacked extension with no key. 2252 // Load the unpacked extension with no key.
2418 base::CopyFile(manifest_no_key, manifest_path); 2253 base::CopyFile(manifest_no_key, manifest_path);
2419 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2254 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
2420 2255
2421 base::RunLoop().RunUntilIdle(); 2256 base::RunLoop().RunUntilIdle();
2422 EXPECT_EQ(0u, GetErrors().size()); 2257 EXPECT_EQ(0u, GetErrors().size());
2423 ASSERT_EQ(1u, loaded_.size()); 2258 ASSERT_EQ(1u, loaded_.size());
2424 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2259 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2425 2260
2426 // Add the key to the manifest. 2261 // Add the key to the manifest.
2427 base::CopyFile(manifest_with_key, manifest_path); 2262 base::CopyFile(manifest_with_key, manifest_path);
2428 loaded_.clear(); 2263 loaded_.clear();
2429 2264
2430 // Reload the extensions. 2265 // Reload the extensions.
2431 service_->ReloadExtensionsForTest(); 2266 service()->ReloadExtensionsForTest();
2432 const Extension* extension = service_->GetExtensionById(unpacked, false); 2267 const Extension* extension = service()->GetExtensionById(unpacked, false);
2433 EXPECT_EQ(unpacked, extension->id()); 2268 EXPECT_EQ(unpacked, extension->id());
2434 ASSERT_EQ(1u, loaded_.size()); 2269 ASSERT_EQ(1u, loaded_.size());
2435 2270
2436 // TODO(jstritar): Right now this just makes sure we don't crash and burn, but 2271 // TODO(jstritar): Right now this just makes sure we don't crash and burn, but
2437 // we should also test that preferences are preserved. 2272 // we should also test that preferences are preserved.
2438 } 2273 }
2439 2274
2440 #if defined(OS_POSIX) 2275 #if defined(OS_POSIX)
2441 TEST_F(ExtensionServiceTest, UnpackedExtensionMayContainSymlinkedFiles) { 2276 TEST_F(ExtensionServiceTest, UnpackedExtensionMayContainSymlinkedFiles) {
2442 base::FilePath source_data_dir = data_dir_. 2277 base::FilePath source_data_dir =
2443 AppendASCII("unpacked"). 2278 data_dir().AppendASCII("unpacked").AppendASCII("symlinks_allowed");
2444 AppendASCII("symlinks_allowed");
2445 2279
2446 // Paths to test data files. 2280 // Paths to test data files.
2447 base::FilePath source_manifest = source_data_dir.AppendASCII("manifest.json"); 2281 base::FilePath source_manifest = source_data_dir.AppendASCII("manifest.json");
2448 ASSERT_TRUE(base::PathExists(source_manifest)); 2282 ASSERT_TRUE(base::PathExists(source_manifest));
2449 base::FilePath source_icon = source_data_dir.AppendASCII("icon.png"); 2283 base::FilePath source_icon = source_data_dir.AppendASCII("icon.png");
2450 ASSERT_TRUE(base::PathExists(source_icon)); 2284 ASSERT_TRUE(base::PathExists(source_icon));
2451 2285
2452 // Set up the temporary extension directory. 2286 // Set up the temporary extension directory.
2453 base::ScopedTempDir temp; 2287 base::ScopedTempDir temp;
2454 ASSERT_TRUE(temp.CreateUniqueTempDir()); 2288 ASSERT_TRUE(temp.CreateUniqueTempDir());
2455 base::FilePath extension_path = temp.path(); 2289 base::FilePath extension_path = temp.path();
2456 base::FilePath manifest = extension_path.Append( 2290 base::FilePath manifest = extension_path.Append(
2457 extensions::kManifestFilename); 2291 extensions::kManifestFilename);
2458 base::FilePath icon_symlink = extension_path.AppendASCII("icon.png"); 2292 base::FilePath icon_symlink = extension_path.AppendASCII("icon.png");
2459 base::CopyFile(source_manifest, manifest); 2293 base::CopyFile(source_manifest, manifest);
2460 base::CreateSymbolicLink(source_icon, icon_symlink); 2294 base::CreateSymbolicLink(source_icon, icon_symlink);
2461 2295
2462 // Load extension. 2296 // Load extension.
2463 InitializeEmptyExtensionService(); 2297 InitializeEmptyExtensionService();
2464 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2298 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
2465 base::RunLoop().RunUntilIdle(); 2299 base::RunLoop().RunUntilIdle();
2466 2300
2467 EXPECT_TRUE(GetErrors().empty()); 2301 EXPECT_TRUE(GetErrors().empty());
2468 ASSERT_EQ(1u, loaded_.size()); 2302 ASSERT_EQ(1u, loaded_.size());
2469 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2303 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2470 } 2304 }
2471 #endif 2305 #endif
2472 2306
2473 TEST_F(ExtensionServiceTest, UnpackedExtensionMayNotHaveUnderscore) { 2307 TEST_F(ExtensionServiceTest, UnpackedExtensionMayNotHaveUnderscore) {
2474 InitializeEmptyExtensionService(); 2308 InitializeEmptyExtensionService();
2475 base::FilePath extension_path = data_dir_ 2309 base::FilePath extension_path = data_dir().AppendASCII("underscore_name");
2476 .AppendASCII("underscore_name"); 2310 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
2477 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2478 base::RunLoop().RunUntilIdle(); 2311 base::RunLoop().RunUntilIdle();
2479 EXPECT_EQ(1u, GetErrors().size()); 2312 EXPECT_EQ(1u, GetErrors().size());
2480 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 2313 EXPECT_EQ(0u, registry()->enabled_extensions().size());
2481 } 2314 }
2482 2315
2483 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { 2316 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) {
2484 InitializeEmptyExtensionService(); 2317 InitializeEmptyExtensionService();
2485 service_->Init(); 2318 service()->Init();
2486 2319
2487 base::FilePath theme_path = data_dir_ 2320 base::FilePath theme_path = data_dir().AppendASCII("theme_i18n");
2488 .AppendASCII("theme_i18n");
2489 2321
2490 const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW); 2322 const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW);
2491 2323
2492 EXPECT_EQ(0u, GetErrors().size()); 2324 EXPECT_EQ(0u, GetErrors().size());
2493 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2325 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2494 EXPECT_EQ("name", theme->name()); 2326 EXPECT_EQ("name", theme->name());
2495 EXPECT_EQ("description", theme->description()); 2327 EXPECT_EQ("description", theme->description());
2496 } 2328 }
2497 2329
2498 TEST_F(ExtensionServiceTest, InstallApps) { 2330 TEST_F(ExtensionServiceTest, InstallApps) {
2499 InitializeEmptyExtensionService(); 2331 InitializeEmptyExtensionService();
2500 2332
2501 // An empty app. 2333 // An empty app.
2502 const Extension* app = PackAndInstallCRX(data_dir_.AppendASCII("app1"), 2334 const Extension* app =
2503 INSTALL_NEW); 2335 PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
2504 int pref_count = 0; 2336 int pref_count = 0;
2505 ValidatePrefKeyCount(++pref_count); 2337 ValidatePrefKeyCount(++pref_count);
2506 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 2338 ASSERT_EQ(1u, registry()->enabled_extensions().size());
2507 ValidateIntegerPref(app->id(), "state", Extension::ENABLED); 2339 ValidateIntegerPref(app->id(), "state", Extension::ENABLED);
2508 ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL); 2340 ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL);
2509 2341
2510 // Another app with non-overlapping extent. Should succeed. 2342 // Another app with non-overlapping extent. Should succeed.
2511 PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 2343 PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
2512 ValidatePrefKeyCount(++pref_count); 2344 ValidatePrefKeyCount(++pref_count);
2513 2345
2514 // A third app whose extent overlaps the first. Should fail. 2346 // A third app whose extent overlaps the first. Should fail.
2515 PackAndInstallCRX(data_dir_.AppendASCII("app3"), INSTALL_FAILED); 2347 PackAndInstallCRX(data_dir().AppendASCII("app3"), INSTALL_FAILED);
2516 ValidatePrefKeyCount(pref_count); 2348 ValidatePrefKeyCount(pref_count);
2517 } 2349 }
2518 2350
2519 // Tests that file access is OFF by default. 2351 // Tests that file access is OFF by default.
2520 TEST_F(ExtensionServiceTest, DefaultFileAccess) { 2352 TEST_F(ExtensionServiceTest, DefaultFileAccess) {
2521 InitializeEmptyExtensionService(); 2353 InitializeEmptyExtensionService();
2522 const Extension* extension = 2354 const Extension* extension = PackAndInstallCRX(
2523 PackAndInstallCRX(data_dir_ 2355 data_dir().AppendASCII("permissions").AppendASCII("files"), INSTALL_NEW);
2524 .AppendASCII("permissions")
2525 .AppendASCII("files"),
2526 INSTALL_NEW);
2527 EXPECT_EQ(0u, GetErrors().size()); 2356 EXPECT_EQ(0u, GetErrors().size());
2528 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2357 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2529 EXPECT_FALSE( 2358 EXPECT_FALSE(
2530 ExtensionPrefs::Get(profile_.get())->AllowFileAccess(extension->id())); 2359 ExtensionPrefs::Get(profile())->AllowFileAccess(extension->id()));
2531 } 2360 }
2532 2361
2533 TEST_F(ExtensionServiceTest, UpdateApps) { 2362 TEST_F(ExtensionServiceTest, UpdateApps) {
2534 InitializeEmptyExtensionService(); 2363 InitializeEmptyExtensionService();
2535 base::FilePath extensions_path = data_dir_.AppendASCII("app_update"); 2364 base::FilePath extensions_path = data_dir().AppendASCII("app_update");
2536 2365
2537 // First install v1 of a hosted app. 2366 // First install v1 of a hosted app.
2538 const Extension* extension = 2367 const Extension* extension =
2539 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); 2368 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW);
2540 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 2369 ASSERT_EQ(1u, registry()->enabled_extensions().size());
2541 std::string id = extension->id(); 2370 std::string id = extension->id();
2542 ASSERT_EQ(std::string("1"), extension->version()->GetString()); 2371 ASSERT_EQ(std::string("1"), extension->version()->GetString());
2543 2372
2544 // Now try updating to v2. 2373 // Now try updating to v2.
2545 UpdateExtension(id, 2374 UpdateExtension(id,
2546 extensions_path.AppendASCII("v2.crx"), 2375 extensions_path.AppendASCII("v2.crx"),
2547 ENABLED); 2376 ENABLED);
2548 ASSERT_EQ(std::string("2"), 2377 ASSERT_EQ(std::string("2"),
2549 service_->GetExtensionById(id, false)->version()->GetString()); 2378 service()->GetExtensionById(id, false)->version()->GetString());
2550 } 2379 }
2551 2380
2552 // Verifies that the NTP page and launch ordinals are kept when updating apps. 2381 // Verifies that the NTP page and launch ordinals are kept when updating apps.
2553 TEST_F(ExtensionServiceTest, UpdateAppsRetainOrdinals) { 2382 TEST_F(ExtensionServiceTest, UpdateAppsRetainOrdinals) {
2554 InitializeEmptyExtensionService(); 2383 InitializeEmptyExtensionService();
2555 AppSorting* sorting = ExtensionPrefs::Get(profile_.get())->app_sorting(); 2384 AppSorting* sorting = ExtensionPrefs::Get(profile())->app_sorting();
2556 base::FilePath extensions_path = data_dir_.AppendASCII("app_update"); 2385 base::FilePath extensions_path = data_dir().AppendASCII("app_update");
2557 2386
2558 // First install v1 of a hosted app. 2387 // First install v1 of a hosted app.
2559 const Extension* extension = 2388 const Extension* extension =
2560 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); 2389 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW);
2561 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 2390 ASSERT_EQ(1u, registry()->enabled_extensions().size());
2562 std::string id = extension->id(); 2391 std::string id = extension->id();
2563 ASSERT_EQ(std::string("1"), extension->version()->GetString()); 2392 ASSERT_EQ(std::string("1"), extension->version()->GetString());
2564 2393
2565 // Modify the ordinals so we can distinguish them from the defaults. 2394 // Modify the ordinals so we can distinguish them from the defaults.
2566 syncer::StringOrdinal new_page_ordinal = 2395 syncer::StringOrdinal new_page_ordinal =
2567 sorting->GetPageOrdinal(id).CreateAfter(); 2396 sorting->GetPageOrdinal(id).CreateAfter();
2568 syncer::StringOrdinal new_launch_ordinal = 2397 syncer::StringOrdinal new_launch_ordinal =
2569 sorting->GetAppLaunchOrdinal(id).CreateBefore(); 2398 sorting->GetAppLaunchOrdinal(id).CreateBefore();
2570 2399
2571 sorting->SetPageOrdinal(id, new_page_ordinal); 2400 sorting->SetPageOrdinal(id, new_page_ordinal);
2572 sorting->SetAppLaunchOrdinal(id, new_launch_ordinal); 2401 sorting->SetAppLaunchOrdinal(id, new_launch_ordinal);
2573 2402
2574 // Now try updating to v2. 2403 // Now try updating to v2.
2575 UpdateExtension(id, extensions_path.AppendASCII("v2.crx"), ENABLED); 2404 UpdateExtension(id, extensions_path.AppendASCII("v2.crx"), ENABLED);
2576 ASSERT_EQ(std::string("2"), 2405 ASSERT_EQ(std::string("2"),
2577 service_->GetExtensionById(id, false)->version()->GetString()); 2406 service()->GetExtensionById(id, false)->version()->GetString());
2578 2407
2579 // Verify that the ordinals match. 2408 // Verify that the ordinals match.
2580 ASSERT_TRUE(new_page_ordinal.Equals(sorting->GetPageOrdinal(id))); 2409 ASSERT_TRUE(new_page_ordinal.Equals(sorting->GetPageOrdinal(id)));
2581 ASSERT_TRUE(new_launch_ordinal.Equals(sorting->GetAppLaunchOrdinal(id))); 2410 ASSERT_TRUE(new_launch_ordinal.Equals(sorting->GetAppLaunchOrdinal(id)));
2582 } 2411 }
2583 2412
2584 // Ensures that the CWS has properly initialized ordinals. 2413 // Ensures that the CWS has properly initialized ordinals.
2585 TEST_F(ExtensionServiceTest, EnsureCWSOrdinalsInitialized) { 2414 TEST_F(ExtensionServiceTest, EnsureCWSOrdinalsInitialized) {
2586 InitializeEmptyExtensionService(); 2415 InitializeEmptyExtensionService();
2587 service_->component_loader()->Add( 2416 service()->component_loader()->Add(
2588 IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store"))); 2417 IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store")));
2589 service_->Init(); 2418 service()->Init();
2590 2419
2591 AppSorting* sorting = ExtensionPrefs::Get(profile_.get())->app_sorting(); 2420 AppSorting* sorting = ExtensionPrefs::Get(profile())->app_sorting();
2592 EXPECT_TRUE( 2421 EXPECT_TRUE(
2593 sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid()); 2422 sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid());
2594 EXPECT_TRUE( 2423 EXPECT_TRUE(
2595 sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid()); 2424 sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid());
2596 } 2425 }
2597 2426
2598 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { 2427 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
2599 InitializeEmptyExtensionService(); 2428 InitializeEmptyExtensionService();
2600 EXPECT_TRUE(registry_->enabled_extensions().is_empty()); 2429 EXPECT_TRUE(registry()->enabled_extensions().is_empty());
2601 2430
2602 int pref_count = 0; 2431 int pref_count = 0;
2603 2432
2604 // Install app1 with unlimited storage. 2433 // Install app1 with unlimited storage.
2605 const Extension* extension = 2434 const Extension* extension =
2606 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 2435 PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
2607 ValidatePrefKeyCount(++pref_count); 2436 ValidatePrefKeyCount(++pref_count);
2608 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 2437 ASSERT_EQ(1u, registry()->enabled_extensions().size());
2609 const std::string id1 = extension->id(); 2438 const std::string id1 = extension->id();
2610 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( 2439 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
2611 APIPermission::kUnlimitedStorage)); 2440 APIPermission::kUnlimitedStorage));
2612 EXPECT_TRUE(extension->web_extent().MatchesURL( 2441 EXPECT_TRUE(extension->web_extent().MatchesURL(
2613 extensions::AppLaunchInfo::GetFullLaunchURL(extension))); 2442 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
2614 const GURL origin1( 2443 const GURL origin1(
2615 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 2444 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2616 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2445 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
2617 IsStorageUnlimited(origin1)); 2446 origin1));
2618 2447
2619 // Install app2 from the same origin with unlimited storage. 2448 // Install app2 from the same origin with unlimited storage.
2620 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 2449 extension = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
2621 ValidatePrefKeyCount(++pref_count); 2450 ValidatePrefKeyCount(++pref_count);
2622 ASSERT_EQ(2u, registry_->enabled_extensions().size()); 2451 ASSERT_EQ(2u, registry()->enabled_extensions().size());
2623 const std::string id2 = extension->id(); 2452 const std::string id2 = extension->id();
2624 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( 2453 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
2625 APIPermission::kUnlimitedStorage)); 2454 APIPermission::kUnlimitedStorage));
2626 EXPECT_TRUE(extension->web_extent().MatchesURL( 2455 EXPECT_TRUE(extension->web_extent().MatchesURL(
2627 extensions::AppLaunchInfo::GetFullLaunchURL(extension))); 2456 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
2628 const GURL origin2( 2457 const GURL origin2(
2629 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 2458 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2630 EXPECT_EQ(origin1, origin2); 2459 EXPECT_EQ(origin1, origin2);
2631 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2460 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
2632 IsStorageUnlimited(origin2)); 2461 origin2));
2633 2462
2634 // Uninstall one of them, unlimited storage should still be granted 2463 // Uninstall one of them, unlimited storage should still be granted
2635 // to the origin. 2464 // to the origin.
2636 UninstallExtension(id1, false); 2465 UninstallExtension(id1, false);
2637 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2466 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2638 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2467 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
2639 IsStorageUnlimited(origin1)); 2468 origin1));
2640 2469
2641 // Uninstall the other, unlimited storage should be revoked. 2470 // Uninstall the other, unlimited storage should be revoked.
2642 UninstallExtension(id2, false); 2471 UninstallExtension(id2, false);
2643 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 2472 EXPECT_EQ(0u, registry()->enabled_extensions().size());
2644 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 2473 EXPECT_FALSE(
2645 IsStorageUnlimited(origin2)); 2474 profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
2475 origin2));
2646 } 2476 }
2647 2477
2648 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { 2478 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
2649 InitializeEmptyExtensionService(); 2479 InitializeEmptyExtensionService();
2650 EXPECT_TRUE(registry_->enabled_extensions().is_empty()); 2480 EXPECT_TRUE(registry()->enabled_extensions().is_empty());
2651 2481
2652 int pref_count = 0; 2482 int pref_count = 0;
2653 2483
2654 const Extension* extension = 2484 const Extension* extension =
2655 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 2485 PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
2656 ValidatePrefKeyCount(++pref_count); 2486 ValidatePrefKeyCount(++pref_count);
2657 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 2487 ASSERT_EQ(1u, registry()->enabled_extensions().size());
2658 EXPECT_TRUE(extension->is_app()); 2488 EXPECT_TRUE(extension->is_app());
2659 const std::string id1 = extension->id(); 2489 const std::string id1 = extension->id();
2660 const GURL origin1( 2490 const GURL origin1(
2661 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 2491 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2662 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2492 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected(
2663 IsStorageProtected(origin1)); 2493 origin1));
2664 2494
2665 // App 4 has a different origin (maps.google.com). 2495 // App 4 has a different origin (maps.google.com).
2666 extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); 2496 extension = PackAndInstallCRX(data_dir().AppendASCII("app4"), INSTALL_NEW);
2667 ValidatePrefKeyCount(++pref_count); 2497 ValidatePrefKeyCount(++pref_count);
2668 ASSERT_EQ(2u, registry_->enabled_extensions().size()); 2498 ASSERT_EQ(2u, registry()->enabled_extensions().size());
2669 const std::string id2 = extension->id(); 2499 const std::string id2 = extension->id();
2670 const GURL origin2( 2500 const GURL origin2(
2671 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 2501 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2672 ASSERT_NE(origin1, origin2); 2502 ASSERT_NE(origin1, origin2);
2673 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2503 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected(
2674 IsStorageProtected(origin2)); 2504 origin2));
2675 2505
2676 UninstallExtension(id1, false); 2506 UninstallExtension(id1, false);
2677 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2507 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2678 2508
2679 UninstallExtension(id2, false); 2509 UninstallExtension(id2, false);
2680 2510
2681 EXPECT_TRUE(registry_->enabled_extensions().is_empty()); 2511 EXPECT_TRUE(registry()->enabled_extensions().is_empty());
2682 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 2512 EXPECT_FALSE(
2683 IsStorageProtected(origin1)); 2513 profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected(
2684 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 2514 origin1));
2685 IsStorageProtected(origin2)); 2515 EXPECT_FALSE(
2516 profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected(
2517 origin2));
2686 } 2518 }
2687 2519
2688 // Test that when an extension version is reinstalled, nothing happens. 2520 // Test that when an extension version is reinstalled, nothing happens.
2689 TEST_F(ExtensionServiceTest, Reinstall) { 2521 TEST_F(ExtensionServiceTest, Reinstall) {
2690 InitializeEmptyExtensionService(); 2522 InitializeEmptyExtensionService();
2691 2523
2692 // A simple extension that should install without error. 2524 // A simple extension that should install without error.
2693 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2525 base::FilePath path = data_dir().AppendASCII("good.crx");
2694 InstallCRX(path, INSTALL_NEW); 2526 InstallCRX(path, INSTALL_NEW);
2695 2527
2696 ValidatePrefKeyCount(1); 2528 ValidatePrefKeyCount(1);
2697 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 2529 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
2698 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 2530 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
2699 2531
2700 // Reinstall the same version, it should overwrite the previous one. 2532 // Reinstall the same version, it should overwrite the previous one.
2701 InstallCRX(path, INSTALL_UPDATED); 2533 InstallCRX(path, INSTALL_UPDATED);
2702 2534
2703 ValidatePrefKeyCount(1); 2535 ValidatePrefKeyCount(1);
2704 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 2536 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
2705 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 2537 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
2706 } 2538 }
2707 2539
2708 // Test that we can determine if extensions came from the 2540 // Test that we can determine if extensions came from the
2709 // Chrome web store. 2541 // Chrome web store.
2710 TEST_F(ExtensionServiceTest, FromWebStore) { 2542 TEST_F(ExtensionServiceTest, FromWebStore) {
2711 InitializeEmptyExtensionService(); 2543 InitializeEmptyExtensionService();
2712 2544
2713 // A simple extension that should install without error. 2545 // A simple extension that should install without error.
2714 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2546 base::FilePath path = data_dir().AppendASCII("good.crx");
2715 // Not from web store. 2547 // Not from web store.
2716 const Extension* extension = InstallCRX(path, INSTALL_NEW); 2548 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2717 std::string id = extension->id(); 2549 std::string id = extension->id();
2718 2550
2719 ValidatePrefKeyCount(1); 2551 ValidatePrefKeyCount(1);
2720 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", false)); 2552 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", false));
2721 ASSERT_FALSE(extension->from_webstore()); 2553 ASSERT_FALSE(extension->from_webstore());
2722 2554
2723 // Test install from web store. 2555 // Test install from web store.
2724 InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store. 2556 InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store.
2725 2557
2726 ValidatePrefKeyCount(1); 2558 ValidatePrefKeyCount(1);
2727 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true)); 2559 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true));
2728 2560
2729 // Reload so extension gets reinitialized with new value. 2561 // Reload so extension gets reinitialized with new value.
2730 service_->ReloadExtensionsForTest(); 2562 service()->ReloadExtensionsForTest();
2731 extension = service_->GetExtensionById(id, false); 2563 extension = service()->GetExtensionById(id, false);
2732 ASSERT_TRUE(extension->from_webstore()); 2564 ASSERT_TRUE(extension->from_webstore());
2733 2565
2734 // Upgrade to version 2.0 2566 // Upgrade to version 2.0
2735 path = data_dir_.AppendASCII("good2.crx"); 2567 path = data_dir().AppendASCII("good2.crx");
2736 UpdateExtension(good_crx, path, ENABLED); 2568 UpdateExtension(good_crx, path, ENABLED);
2737 ValidatePrefKeyCount(1); 2569 ValidatePrefKeyCount(1);
2738 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true)); 2570 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true));
2739 } 2571 }
2740 2572
2741 // Test upgrading a signed extension. 2573 // Test upgrading a signed extension.
2742 TEST_F(ExtensionServiceTest, UpgradeSignedGood) { 2574 TEST_F(ExtensionServiceTest, UpgradeSignedGood) {
2743 InitializeEmptyExtensionService(); 2575 InitializeEmptyExtensionService();
2744 2576
2745 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2577 base::FilePath path = data_dir().AppendASCII("good.crx");
2746 const Extension* extension = InstallCRX(path, INSTALL_NEW); 2578 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2747 std::string id = extension->id(); 2579 std::string id = extension->id();
2748 2580
2749 ASSERT_EQ("1.0.0.0", extension->version()->GetString()); 2581 ASSERT_EQ("1.0.0.0", extension->version()->GetString());
2750 ASSERT_EQ(0u, GetErrors().size()); 2582 ASSERT_EQ(0u, GetErrors().size());
2751 2583
2752 // Upgrade to version 1.0.0.1. 2584 // Upgrade to version 1.0.0.1.
2753 // Also test that the extension's old and new title are correctly retrieved. 2585 // Also test that the extension's old and new title are correctly retrieved.
2754 path = data_dir_.AppendASCII("good2.crx"); 2586 path = data_dir().AppendASCII("good2.crx");
2755 InstallCRX(path, INSTALL_UPDATED, Extension::NO_FLAGS, "My extension 1"); 2587 InstallCRX(path, INSTALL_UPDATED, Extension::NO_FLAGS, "My extension 1");
2756 extension = service_->GetExtensionById(id, false); 2588 extension = service()->GetExtensionById(id, false);
2757 2589
2758 ASSERT_EQ("1.0.0.1", extension->version()->GetString()); 2590 ASSERT_EQ("1.0.0.1", extension->version()->GetString());
2759 ASSERT_EQ("My updated extension 1", extension->name()); 2591 ASSERT_EQ("My updated extension 1", extension->name());
2760 ASSERT_EQ(0u, GetErrors().size()); 2592 ASSERT_EQ(0u, GetErrors().size());
2761 } 2593 }
2762 2594
2763 // Test upgrading a signed extension with a bad signature. 2595 // Test upgrading a signed extension with a bad signature.
2764 TEST_F(ExtensionServiceTest, UpgradeSignedBad) { 2596 TEST_F(ExtensionServiceTest, UpgradeSignedBad) {
2765 InitializeEmptyExtensionService(); 2597 InitializeEmptyExtensionService();
2766 2598
2767 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2599 base::FilePath path = data_dir().AppendASCII("good.crx");
2768 InstallCRX(path, INSTALL_NEW); 2600 InstallCRX(path, INSTALL_NEW);
2769 2601
2770 // Try upgrading with a bad signature. This should fail during the unpack, 2602 // Try upgrading with a bad signature. This should fail during the unpack,
2771 // because the key will not match the signature. 2603 // because the key will not match the signature.
2772 path = data_dir_.AppendASCII("bad_signature.crx"); 2604 path = data_dir().AppendASCII("bad_signature.crx");
2773 InstallCRX(path, INSTALL_FAILED); 2605 InstallCRX(path, INSTALL_FAILED);
2774 } 2606 }
2775 2607
2776 // Test a normal update via the UpdateExtension API 2608 // Test a normal update via the UpdateExtension API
2777 TEST_F(ExtensionServiceTest, UpdateExtension) { 2609 TEST_F(ExtensionServiceTest, UpdateExtension) {
2778 InitializeEmptyExtensionService(); 2610 InitializeEmptyExtensionService();
2779 2611
2780 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2612 base::FilePath path = data_dir().AppendASCII("good.crx");
2781 2613
2782 const Extension* good = InstallCRX(path, INSTALL_NEW); 2614 const Extension* good = InstallCRX(path, INSTALL_NEW);
2783 ASSERT_EQ("1.0.0.0", good->VersionString()); 2615 ASSERT_EQ("1.0.0.0", good->VersionString());
2784 ASSERT_EQ(good_crx, good->id()); 2616 ASSERT_EQ(good_crx, good->id());
2785 2617
2786 path = data_dir_.AppendASCII("good2.crx"); 2618 path = data_dir().AppendASCII("good2.crx");
2787 UpdateExtension(good_crx, path, ENABLED); 2619 UpdateExtension(good_crx, path, ENABLED);
2788 ASSERT_EQ("1.0.0.1", 2620 ASSERT_EQ(
2789 service_->GetExtensionById(good_crx, false)-> 2621 "1.0.0.1",
2790 version()->GetString()); 2622 service()->GetExtensionById(good_crx, false)->version()->GetString());
2791 } 2623 }
2792 2624
2793 // Extensions should not be updated during browser shutdown. 2625 // Extensions should not be updated during browser shutdown.
2794 TEST_F(ExtensionServiceTest, UpdateExtensionDuringShutdown) { 2626 TEST_F(ExtensionServiceTest, UpdateExtensionDuringShutdown) {
2795 InitializeEmptyExtensionService(); 2627 InitializeEmptyExtensionService();
2796 2628
2797 // Install an extension. 2629 // Install an extension.
2798 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2630 base::FilePath path = data_dir().AppendASCII("good.crx");
2799 const Extension* good = InstallCRX(path, INSTALL_NEW); 2631 const Extension* good = InstallCRX(path, INSTALL_NEW);
2800 ASSERT_EQ(good_crx, good->id()); 2632 ASSERT_EQ(good_crx, good->id());
2801 2633
2802 // Simulate shutdown. 2634 // Simulate shutdown.
2803 service_->set_browser_terminating_for_test(true); 2635 service()->set_browser_terminating_for_test(true);
2804 2636
2805 // Update should fail and extension should not be updated. 2637 // Update should fail and extension should not be updated.
2806 path = data_dir_.AppendASCII("good2.crx"); 2638 path = data_dir().AppendASCII("good2.crx");
2807 bool updated = service_->UpdateExtension(good_crx, path, true, NULL); 2639 bool updated = service()->UpdateExtension(good_crx, path, true, NULL);
2808 ASSERT_FALSE(updated); 2640 ASSERT_FALSE(updated);
2809 ASSERT_EQ("1.0.0.0", 2641 ASSERT_EQ(
2810 service_->GetExtensionById(good_crx, false)-> 2642 "1.0.0.0",
2811 version()->GetString()); 2643 service()->GetExtensionById(good_crx, false)->version()->GetString());
2812 } 2644 }
2813 2645
2814 // Test updating a not-already-installed extension - this should fail 2646 // Test updating a not-already-installed extension - this should fail
2815 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) { 2647 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) {
2816 InitializeEmptyExtensionService(); 2648 InitializeEmptyExtensionService();
2817 2649
2818 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2650 base::FilePath path = data_dir().AppendASCII("good.crx");
2819 UpdateExtension(good_crx, path, UPDATED); 2651 UpdateExtension(good_crx, path, UPDATED);
2820 base::RunLoop().RunUntilIdle(); 2652 base::RunLoop().RunUntilIdle();
2821 2653
2822 ASSERT_EQ(0u, registry_->enabled_extensions().size()); 2654 ASSERT_EQ(0u, registry()->enabled_extensions().size());
2823 ASSERT_FALSE(installed_); 2655 ASSERT_FALSE(installed_);
2824 ASSERT_EQ(0u, loaded_.size()); 2656 ASSERT_EQ(0u, loaded_.size());
2825 } 2657 }
2826 2658
2827 // Makes sure you can't downgrade an extension via UpdateExtension 2659 // Makes sure you can't downgrade an extension via UpdateExtension
2828 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { 2660 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) {
2829 InitializeEmptyExtensionService(); 2661 InitializeEmptyExtensionService();
2830 2662
2831 base::FilePath path = data_dir_.AppendASCII("good2.crx"); 2663 base::FilePath path = data_dir().AppendASCII("good2.crx");
2832 2664
2833 const Extension* good = InstallCRX(path, INSTALL_NEW); 2665 const Extension* good = InstallCRX(path, INSTALL_NEW);
2834 ASSERT_EQ("1.0.0.1", good->VersionString()); 2666 ASSERT_EQ("1.0.0.1", good->VersionString());
2835 ASSERT_EQ(good_crx, good->id()); 2667 ASSERT_EQ(good_crx, good->id());
2836 2668
2837 // Change path from good2.crx -> good.crx 2669 // Change path from good2.crx -> good.crx
2838 path = data_dir_.AppendASCII("good.crx"); 2670 path = data_dir().AppendASCII("good.crx");
2839 UpdateExtension(good_crx, path, FAILED); 2671 UpdateExtension(good_crx, path, FAILED);
2840 ASSERT_EQ("1.0.0.1", 2672 ASSERT_EQ(
2841 service_->GetExtensionById(good_crx, false)-> 2673 "1.0.0.1",
2842 version()->GetString()); 2674 service()->GetExtensionById(good_crx, false)->version()->GetString());
2843 } 2675 }
2844 2676
2845 // Make sure calling update with an identical version does nothing 2677 // Make sure calling update with an identical version does nothing
2846 TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) { 2678 TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) {
2847 InitializeEmptyExtensionService(); 2679 InitializeEmptyExtensionService();
2848 2680
2849 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2681 base::FilePath path = data_dir().AppendASCII("good.crx");
2850 2682
2851 const Extension* good = InstallCRX(path, INSTALL_NEW); 2683 const Extension* good = InstallCRX(path, INSTALL_NEW);
2852 ASSERT_EQ(good_crx, good->id()); 2684 ASSERT_EQ(good_crx, good->id());
2853 UpdateExtension(good_crx, path, FAILED_SILENTLY); 2685 UpdateExtension(good_crx, path, FAILED_SILENTLY);
2854 } 2686 }
2855 2687
2856 // Tests that updating an extension does not clobber old state. 2688 // Tests that updating an extension does not clobber old state.
2857 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) { 2689 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) {
2858 InitializeEmptyExtensionService(); 2690 InitializeEmptyExtensionService();
2859 2691
2860 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2692 base::FilePath path = data_dir().AppendASCII("good.crx");
2861 2693
2862 const Extension* good = InstallCRX(path, INSTALL_NEW); 2694 const Extension* good = InstallCRX(path, INSTALL_NEW);
2863 ASSERT_EQ("1.0.0.0", good->VersionString()); 2695 ASSERT_EQ("1.0.0.0", good->VersionString());
2864 ASSERT_EQ(good_crx, good->id()); 2696 ASSERT_EQ(good_crx, good->id());
2865 2697
2866 // Disable it and allow it to run in incognito. These settings should carry 2698 // Disable it and allow it to run in incognito. These settings should carry
2867 // over to the updated version. 2699 // over to the updated version.
2868 service_->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION); 2700 service()->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION);
2869 extensions::util::SetIsIncognitoEnabled(good->id(), profile_.get(), true); 2701 extensions::util::SetIsIncognitoEnabled(good->id(), profile(), true);
2870 ExtensionPrefs::Get(profile_.get()) 2702 ExtensionPrefs::Get(profile())
2871 ->SetDidExtensionEscalatePermissions(good, true); 2703 ->SetDidExtensionEscalatePermissions(good, true);
2872 2704
2873 path = data_dir_.AppendASCII("good2.crx"); 2705 path = data_dir().AppendASCII("good2.crx");
2874 UpdateExtension(good_crx, path, INSTALLED); 2706 UpdateExtension(good_crx, path, INSTALLED);
2875 ASSERT_EQ(1u, registry_->disabled_extensions().size()); 2707 ASSERT_EQ(1u, registry()->disabled_extensions().size());
2876 const Extension* good2 = service_->GetExtensionById(good_crx, true); 2708 const Extension* good2 = service()->GetExtensionById(good_crx, true);
2877 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); 2709 ASSERT_EQ("1.0.0.1", good2->version()->GetString());
2878 EXPECT_TRUE(extensions::util::IsIncognitoEnabled( 2710 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good2->id(), profile()));
2879 good2->id(), profile_.get())); 2711 EXPECT_TRUE(ExtensionPrefs::Get(profile())
2880 EXPECT_TRUE(ExtensionPrefs::Get(profile_.get())
2881 ->DidExtensionEscalatePermissions(good2->id())); 2712 ->DidExtensionEscalatePermissions(good2->id()));
2882 } 2713 }
2883 2714
2884 // Tests that updating preserves extension location. 2715 // Tests that updating preserves extension location.
2885 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { 2716 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) {
2886 InitializeEmptyExtensionService(); 2717 InitializeEmptyExtensionService();
2887 2718
2888 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2719 base::FilePath path = data_dir().AppendASCII("good.crx");
2889 2720
2890 const Extension* good = 2721 const Extension* good =
2891 InstallCRXWithLocation(path, Manifest::EXTERNAL_PREF, INSTALL_NEW); 2722 InstallCRXWithLocation(path, Manifest::EXTERNAL_PREF, INSTALL_NEW);
2892 2723
2893 ASSERT_EQ("1.0.0.0", good->VersionString()); 2724 ASSERT_EQ("1.0.0.0", good->VersionString());
2894 ASSERT_EQ(good_crx, good->id()); 2725 ASSERT_EQ(good_crx, good->id());
2895 2726
2896 path = data_dir_.AppendASCII("good2.crx"); 2727 path = data_dir().AppendASCII("good2.crx");
2897 UpdateExtension(good_crx, path, ENABLED); 2728 UpdateExtension(good_crx, path, ENABLED);
2898 const Extension* good2 = service_->GetExtensionById(good_crx, false); 2729 const Extension* good2 = service()->GetExtensionById(good_crx, false);
2899 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); 2730 ASSERT_EQ("1.0.0.1", good2->version()->GetString());
2900 EXPECT_EQ(good2->location(), Manifest::EXTERNAL_PREF); 2731 EXPECT_EQ(good2->location(), Manifest::EXTERNAL_PREF);
2901 } 2732 }
2902 2733
2903 // Makes sure that LOAD extension types can downgrade. 2734 // Makes sure that LOAD extension types can downgrade.
2904 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { 2735 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) {
2905 InitializeEmptyExtensionService(); 2736 InitializeEmptyExtensionService();
2906 2737
2907 base::ScopedTempDir temp; 2738 base::ScopedTempDir temp;
2908 ASSERT_TRUE(temp.CreateUniqueTempDir()); 2739 ASSERT_TRUE(temp.CreateUniqueTempDir());
2909 2740
2910 // We'll write the extension manifest dynamically to a temporary path 2741 // We'll write the extension manifest dynamically to a temporary path
2911 // to make it easier to change the version number. 2742 // to make it easier to change the version number.
2912 base::FilePath extension_path = temp.path(); 2743 base::FilePath extension_path = temp.path();
2913 base::FilePath manifest_path = 2744 base::FilePath manifest_path =
2914 extension_path.Append(extensions::kManifestFilename); 2745 extension_path.Append(extensions::kManifestFilename);
2915 ASSERT_FALSE(base::PathExists(manifest_path)); 2746 ASSERT_FALSE(base::PathExists(manifest_path));
2916 2747
2917 // Start with version 2.0. 2748 // Start with version 2.0.
2918 base::DictionaryValue manifest; 2749 base::DictionaryValue manifest;
2919 manifest.SetString("version", "2.0"); 2750 manifest.SetString("version", "2.0");
2920 manifest.SetString("name", "LOAD Downgrade Test"); 2751 manifest.SetString("name", "LOAD Downgrade Test");
2921 manifest.SetInteger("manifest_version", 2); 2752 manifest.SetInteger("manifest_version", 2);
2922 2753
2923 JSONFileValueSerializer serializer(manifest_path); 2754 JSONFileValueSerializer serializer(manifest_path);
2924 ASSERT_TRUE(serializer.Serialize(manifest)); 2755 ASSERT_TRUE(serializer.Serialize(manifest));
2925 2756
2926 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2757 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
2927 base::RunLoop().RunUntilIdle(); 2758 base::RunLoop().RunUntilIdle();
2928 2759
2929 EXPECT_EQ(0u, GetErrors().size()); 2760 EXPECT_EQ(0u, GetErrors().size());
2930 ASSERT_EQ(1u, loaded_.size()); 2761 ASSERT_EQ(1u, loaded_.size());
2931 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); 2762 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
2932 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2763 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2933 EXPECT_EQ("2.0", loaded_[0]->VersionString()); 2764 EXPECT_EQ("2.0", loaded_[0]->VersionString());
2934 2765
2935 // Now set the version number to 1.0, reload the extensions and verify that 2766 // Now set the version number to 1.0, reload the extensions and verify that
2936 // the downgrade was accepted. 2767 // the downgrade was accepted.
2937 manifest.SetString("version", "1.0"); 2768 manifest.SetString("version", "1.0");
2938 ASSERT_TRUE(serializer.Serialize(manifest)); 2769 ASSERT_TRUE(serializer.Serialize(manifest));
2939 2770
2940 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2771 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
2941 base::RunLoop().RunUntilIdle(); 2772 base::RunLoop().RunUntilIdle();
2942 2773
2943 EXPECT_EQ(0u, GetErrors().size()); 2774 EXPECT_EQ(0u, GetErrors().size());
2944 ASSERT_EQ(1u, loaded_.size()); 2775 ASSERT_EQ(1u, loaded_.size());
2945 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); 2776 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
2946 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2777 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2947 EXPECT_EQ("1.0", loaded_[0]->VersionString()); 2778 EXPECT_EQ("1.0", loaded_[0]->VersionString());
2948 } 2779 }
2949 2780
2950 #if !defined(OS_POSIX) || defined(OS_MACOSX) 2781 #if !defined(OS_POSIX) || defined(OS_MACOSX)
2951 // LOAD extensions with plugins require approval. 2782 // LOAD extensions with plugins require approval.
2952 // Only run this on platforms that support NPAPI plugins. 2783 // Only run this on platforms that support NPAPI plugins.
2953 TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) { 2784 TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) {
2954 base::FilePath extension_with_plugin_path = good1_path(); 2785 base::FilePath extension_with_plugin_path = good1_path();
2955 base::FilePath extension_no_plugin_path = good2_path(); 2786 base::FilePath extension_no_plugin_path = good2_path();
2956 2787
2957 InitPluginService(); 2788 InitPluginService();
2958 InitializeEmptyExtensionService(); 2789 InitializeEmptyExtensionService();
2959 InitializeProcessManager(); 2790 InitializeProcessManager();
2960 service_->set_show_extensions_prompts(true); 2791 service()->set_show_extensions_prompts(true);
2961 2792
2962 // Start by canceling any install prompts. 2793 // Start by canceling any install prompts.
2963 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2794 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2964 switches::kAppsGalleryInstallAutoConfirmForTests, 2795 switches::kAppsGalleryInstallAutoConfirmForTests,
2965 "cancel"); 2796 "cancel");
2966 2797
2967 // The extension that has a plugin should not install. 2798 // The extension that has a plugin should not install.
2968 extensions::UnpackedInstaller::Create(service_)->Load( 2799 extensions::UnpackedInstaller::Create(service())
2969 extension_with_plugin_path); 2800 ->Load(extension_with_plugin_path);
2970 base::RunLoop().RunUntilIdle(); 2801 base::RunLoop().RunUntilIdle();
2971 EXPECT_EQ(0u, GetErrors().size()); 2802 EXPECT_EQ(0u, GetErrors().size());
2972 EXPECT_EQ(0u, loaded_.size()); 2803 EXPECT_EQ(0u, loaded_.size());
2973 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 2804 EXPECT_EQ(0u, registry()->enabled_extensions().size());
2974 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 2805 EXPECT_EQ(0u, registry()->disabled_extensions().size());
2975 2806
2976 // But the extension with no plugin should since there's no prompt. 2807 // But the extension with no plugin should since there's no prompt.
2977 ExtensionErrorReporter::GetInstance()->ClearErrors(); 2808 ExtensionErrorReporter::GetInstance()->ClearErrors();
2978 extensions::UnpackedInstaller::Create(service_)->Load( 2809 extensions::UnpackedInstaller::Create(service())
2979 extension_no_plugin_path); 2810 ->Load(extension_no_plugin_path);
2980 base::RunLoop().RunUntilIdle(); 2811 base::RunLoop().RunUntilIdle();
2981 EXPECT_EQ(0u, GetErrors().size()); 2812 EXPECT_EQ(0u, GetErrors().size());
2982 EXPECT_EQ(1u, loaded_.size()); 2813 EXPECT_EQ(1u, loaded_.size());
2983 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2814 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2984 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 2815 EXPECT_EQ(0u, registry()->disabled_extensions().size());
2985 EXPECT_TRUE(registry_->enabled_extensions().Contains(good2)); 2816 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
2986 2817
2987 // The plugin extension should install if we accept the dialog. 2818 // The plugin extension should install if we accept the dialog.
2988 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2819 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2989 switches::kAppsGalleryInstallAutoConfirmForTests, 2820 switches::kAppsGalleryInstallAutoConfirmForTests,
2990 "accept"); 2821 "accept");
2991 2822
2992 ExtensionErrorReporter::GetInstance()->ClearErrors(); 2823 ExtensionErrorReporter::GetInstance()->ClearErrors();
2993 extensions::UnpackedInstaller::Create(service_)->Load( 2824 extensions::UnpackedInstaller::Create(service())
2994 extension_with_plugin_path); 2825 ->Load(extension_with_plugin_path);
2995 base::RunLoop().RunUntilIdle(); 2826 base::RunLoop().RunUntilIdle();
2996 EXPECT_EQ(0u, GetErrors().size()); 2827 EXPECT_EQ(0u, GetErrors().size());
2997 EXPECT_EQ(2u, loaded_.size()); 2828 EXPECT_EQ(2u, loaded_.size());
2998 EXPECT_EQ(2u, registry_->enabled_extensions().size()); 2829 EXPECT_EQ(2u, registry()->enabled_extensions().size());
2999 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 2830 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3000 EXPECT_TRUE(registry_->enabled_extensions().Contains(good1)); 2831 EXPECT_TRUE(registry()->enabled_extensions().Contains(good1));
3001 EXPECT_TRUE(registry_->enabled_extensions().Contains(good2)); 2832 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
3002 2833
3003 // Make sure the granted permissions have been setup. 2834 // Make sure the granted permissions have been setup.
3004 scoped_refptr<PermissionSet> permissions( 2835 scoped_refptr<PermissionSet> permissions(
3005 ExtensionPrefs::Get(profile_.get())->GetGrantedPermissions(good1)); 2836 ExtensionPrefs::Get(profile())->GetGrantedPermissions(good1));
3006 EXPECT_FALSE(permissions->IsEmpty()); 2837 EXPECT_FALSE(permissions->IsEmpty());
3007 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); 2838 EXPECT_TRUE(permissions->HasEffectiveFullAccess());
3008 EXPECT_FALSE(permissions->apis().empty()); 2839 EXPECT_FALSE(permissions->apis().empty());
3009 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); 2840 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin));
3010 2841
3011 // We should be able to reload the extension without getting another prompt. 2842 // We should be able to reload the extension without getting another prompt.
3012 loaded_.clear(); 2843 loaded_.clear();
3013 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2844 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
3014 switches::kAppsGalleryInstallAutoConfirmForTests, 2845 switches::kAppsGalleryInstallAutoConfirmForTests,
3015 "cancel"); 2846 "cancel");
3016 2847
3017 service_->ReloadExtension(good1); 2848 service()->ReloadExtension(good1);
3018 base::RunLoop().RunUntilIdle(); 2849 base::RunLoop().RunUntilIdle();
3019 EXPECT_EQ(1u, loaded_.size()); 2850 EXPECT_EQ(1u, loaded_.size());
3020 EXPECT_EQ(2u, registry_->enabled_extensions().size()); 2851 EXPECT_EQ(2u, registry()->enabled_extensions().size());
3021 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 2852 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3022 } 2853 }
3023 #endif // !defined(OS_POSIX) || defined(OS_MACOSX) 2854 #endif // !defined(OS_POSIX) || defined(OS_MACOSX)
3024 2855
3025 namespace { 2856 namespace {
3026 2857
3027 bool IsExtension(const Extension* extension) { 2858 bool IsExtension(const Extension* extension) {
3028 return extension->GetType() == Manifest::TYPE_EXTENSION; 2859 return extension->GetType() == Manifest::TYPE_EXTENSION;
3029 } 2860 }
3030 2861
3031 #if defined(ENABLE_BLACKLIST_TESTS) 2862 #if defined(ENABLE_BLACKLIST_TESTS)
(...skipping 14 matching lines...) Expand all
3046 // Test adding a pending extension. 2877 // Test adding a pending extension.
3047 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { 2878 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) {
3048 InitializeEmptyExtensionService(); 2879 InitializeEmptyExtensionService();
3049 2880
3050 const std::string kFakeId(all_zero); 2881 const std::string kFakeId(all_zero);
3051 const GURL kFakeUpdateURL("http:://fake.update/url"); 2882 const GURL kFakeUpdateURL("http:://fake.update/url");
3052 const bool kFakeInstallSilently(true); 2883 const bool kFakeInstallSilently(true);
3053 const bool kFakeRemoteInstall(false); 2884 const bool kFakeRemoteInstall(false);
3054 2885
3055 EXPECT_TRUE( 2886 EXPECT_TRUE(
3056 service_->pending_extension_manager()->AddFromSync(kFakeId, 2887 service()->pending_extension_manager()->AddFromSync(kFakeId,
3057 kFakeUpdateURL, 2888 kFakeUpdateURL,
3058 &IsExtension, 2889 &IsExtension,
3059 kFakeInstallSilently, 2890 kFakeInstallSilently,
3060 kFakeRemoteInstall)); 2891 kFakeRemoteInstall));
3061 2892
3062 const extensions::PendingExtensionInfo* pending_extension_info; 2893 const extensions::PendingExtensionInfo* pending_extension_info;
3063 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> 2894 ASSERT_TRUE((pending_extension_info =
3064 GetById(kFakeId))); 2895 service()->pending_extension_manager()->GetById(kFakeId)));
3065 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); 2896 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url());
3066 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); 2897 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_);
3067 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently()); 2898 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently());
3068 // Use 2899 // Use
3069 // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()) 2900 // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install())
3070 // instead of 2901 // instead of
3071 // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install()) 2902 // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install())
3072 // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is 2903 // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is
3073 // turned into an error with -Werror=conversion-null: 2904 // turned into an error with -Werror=conversion-null:
3074 // converting 'false' to pointer type for argument 1 of 2905 // converting 'false' to pointer type for argument 1 of
3075 // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' 2906 // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)'
3076 // https://code.google.com/p/googletest/issues/detail?id=458 2907 // https://code.google.com/p/googletest/issues/detail?id=458
3077 EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()); 2908 EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install());
3078 } 2909 }
3079 2910
3080 namespace { 2911 namespace {
3081 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 2912 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
3082 const char kGoodUpdateURL[] = "http://good.update/url"; 2913 const char kGoodUpdateURL[] = "http://good.update/url";
3083 const bool kGoodIsFromSync = true; 2914 const bool kGoodIsFromSync = true;
3084 const bool kGoodInstallSilently = true; 2915 const bool kGoodInstallSilently = true;
3085 const bool kGoodRemoteInstall = false; 2916 const bool kGoodRemoteInstall = false;
3086 } // namespace 2917 } // namespace
3087 2918
3088 // Test updating a pending extension. 2919 // Test updating a pending extension.
3089 TEST_F(ExtensionServiceTest, UpdatePendingExtension) { 2920 TEST_F(ExtensionServiceTest, UpdatePendingExtension) {
3090 InitializeEmptyExtensionService(); 2921 InitializeEmptyExtensionService();
3091 EXPECT_TRUE( 2922 EXPECT_TRUE(
3092 service_->pending_extension_manager()->AddFromSync(kGoodId, 2923 service()->pending_extension_manager()->AddFromSync(kGoodId,
3093 GURL(kGoodUpdateURL), 2924 GURL(kGoodUpdateURL),
3094 &IsExtension, 2925 &IsExtension,
3095 kGoodInstallSilently, 2926 kGoodInstallSilently,
3096 kGoodRemoteInstall)); 2927 kGoodRemoteInstall));
3097 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(kGoodId)); 2928 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3098 2929
3099 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2930 base::FilePath path = data_dir().AppendASCII("good.crx");
3100 UpdateExtension(kGoodId, path, ENABLED); 2931 UpdateExtension(kGoodId, path, ENABLED);
3101 2932
3102 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); 2933 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3103 2934
3104 const Extension* extension = service_->GetExtensionById(kGoodId, true); 2935 const Extension* extension = service()->GetExtensionById(kGoodId, true);
3105 ASSERT_TRUE(extension); 2936 ASSERT_TRUE(extension);
3106 } 2937 }
3107 2938
3108 namespace { 2939 namespace {
3109 2940
3110 bool IsTheme(const Extension* extension) { 2941 bool IsTheme(const Extension* extension) {
3111 return extension->is_theme(); 2942 return extension->is_theme();
3112 } 2943 }
3113 2944
3114 } // namespace 2945 } // namespace
3115 2946
3116 // Test updating a pending theme. 2947 // Test updating a pending theme.
3117 // Disabled due to ASAN failure. http://crbug.com/108320 2948 // Disabled due to ASAN failure. http://crbug.com/108320
3118 TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) { 2949 TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) {
3119 InitializeEmptyExtensionService(); 2950 InitializeEmptyExtensionService();
3120 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( 2951 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync(
3121 theme_crx, GURL(), &IsTheme, false, false)); 2952 theme_crx, GURL(), &IsTheme, false, false));
3122 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 2953 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3123 2954
3124 base::FilePath path = data_dir_.AppendASCII("theme.crx"); 2955 base::FilePath path = data_dir().AppendASCII("theme.crx");
3125 UpdateExtension(theme_crx, path, ENABLED); 2956 UpdateExtension(theme_crx, path, ENABLED);
3126 2957
3127 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 2958 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3128 2959
3129 const Extension* extension = service_->GetExtensionById(theme_crx, true); 2960 const Extension* extension = service()->GetExtensionById(theme_crx, true);
3130 ASSERT_TRUE(extension); 2961 ASSERT_TRUE(extension);
3131 2962
3132 EXPECT_FALSE(ExtensionPrefs::Get(profile_.get()) 2963 EXPECT_FALSE(
3133 ->IsExtensionDisabled(extension->id())); 2964 ExtensionPrefs::Get(profile())->IsExtensionDisabled(extension->id()));
3134 EXPECT_TRUE(service_->IsExtensionEnabled(theme_crx)); 2965 EXPECT_TRUE(service()->IsExtensionEnabled(theme_crx));
3135 } 2966 }
3136 2967
3137 #if defined(OS_CHROMEOS) 2968 #if defined(OS_CHROMEOS)
3138 // Always fails on ChromeOS: http://crbug.com/79737 2969 // Always fails on ChromeOS: http://crbug.com/79737
3139 #define MAYBE_UpdatePendingExternalCrx DISABLED_UpdatePendingExternalCrx 2970 #define MAYBE_UpdatePendingExternalCrx DISABLED_UpdatePendingExternalCrx
3140 #else 2971 #else
3141 #define MAYBE_UpdatePendingExternalCrx UpdatePendingExternalCrx 2972 #define MAYBE_UpdatePendingExternalCrx UpdatePendingExternalCrx
3142 #endif 2973 #endif
3143 // Test updating a pending CRX as if the source is an external extension 2974 // Test updating a pending CRX as if the source is an external extension
3144 // with an update URL. In this case we don't know if the CRX is a theme 2975 // with an update URL. In this case we don't know if the CRX is a theme
3145 // or not. 2976 // or not.
3146 TEST_F(ExtensionServiceTest, MAYBE_UpdatePendingExternalCrx) { 2977 TEST_F(ExtensionServiceTest, MAYBE_UpdatePendingExternalCrx) {
3147 InitializeEmptyExtensionService(); 2978 InitializeEmptyExtensionService();
3148 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( 2979 EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl(
3149 theme_crx, 2980 theme_crx,
3150 std::string(), 2981 std::string(),
3151 GURL(), 2982 GURL(),
3152 Manifest::EXTERNAL_PREF_DOWNLOAD, 2983 Manifest::EXTERNAL_PREF_DOWNLOAD,
3153 Extension::NO_FLAGS, 2984 Extension::NO_FLAGS,
3154 false)); 2985 false));
3155 2986
3156 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 2987 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3157 2988
3158 base::FilePath path = data_dir_.AppendASCII("theme.crx"); 2989 base::FilePath path = data_dir().AppendASCII("theme.crx");
3159 UpdateExtension(theme_crx, path, ENABLED); 2990 UpdateExtension(theme_crx, path, ENABLED);
3160 2991
3161 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 2992 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3162 2993
3163 const Extension* extension = service_->GetExtensionById(theme_crx, true); 2994 const Extension* extension = service()->GetExtensionById(theme_crx, true);
3164 ASSERT_TRUE(extension); 2995 ASSERT_TRUE(extension);
3165 2996
3166 EXPECT_FALSE(ExtensionPrefs::Get(profile_.get()) 2997 EXPECT_FALSE(
3167 ->IsExtensionDisabled(extension->id())); 2998 ExtensionPrefs::Get(profile())->IsExtensionDisabled(extension->id()));
3168 EXPECT_TRUE(service_->IsExtensionEnabled(extension->id())); 2999 EXPECT_TRUE(service()->IsExtensionEnabled(extension->id()));
3169 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(extension->id(), 3000 EXPECT_FALSE(
3170 profile_.get())); 3001 extensions::util::IsIncognitoEnabled(extension->id(), profile()));
3171 } 3002 }
3172 3003
3173 // Test updating a pending CRX as if the source is an external extension 3004 // Test updating a pending CRX as if the source is an external extension
3174 // with an update URL. The external update should overwrite a sync update, 3005 // with an update URL. The external update should overwrite a sync update,
3175 // but a sync update should not overwrite a non-sync update. 3006 // but a sync update should not overwrite a non-sync update.
3176 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { 3007 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) {
3177 InitializeEmptyExtensionService(); 3008 InitializeEmptyExtensionService();
3178 3009
3179 // Add a crx to be installed from the update mechanism. 3010 // Add a crx to be installed from the update mechanism.
3180 EXPECT_TRUE( 3011 EXPECT_TRUE(
3181 service_->pending_extension_manager()->AddFromSync(kGoodId, 3012 service()->pending_extension_manager()->AddFromSync(kGoodId,
3182 GURL(kGoodUpdateURL), 3013 GURL(kGoodUpdateURL),
3183 &IsExtension, 3014 &IsExtension,
3184 kGoodInstallSilently, 3015 kGoodInstallSilently,
3185 kGoodRemoteInstall)); 3016 kGoodRemoteInstall));
3186 3017
3187 // Check that there is a pending crx, with is_from_sync set to true. 3018 // Check that there is a pending crx, with is_from_sync set to true.
3188 const extensions::PendingExtensionInfo* pending_extension_info; 3019 const extensions::PendingExtensionInfo* pending_extension_info;
3189 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> 3020 ASSERT_TRUE((pending_extension_info =
3190 GetById(kGoodId))); 3021 service()->pending_extension_manager()->GetById(kGoodId)));
3191 EXPECT_TRUE(pending_extension_info->is_from_sync()); 3022 EXPECT_TRUE(pending_extension_info->is_from_sync());
3192 3023
3193 // Add a crx to be updated, with the same ID, from a non-sync source. 3024 // Add a crx to be updated, with the same ID, from a non-sync source.
3194 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( 3025 EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl(
3195 kGoodId, 3026 kGoodId,
3196 std::string(), 3027 std::string(),
3197 GURL(kGoodUpdateURL), 3028 GURL(kGoodUpdateURL),
3198 Manifest::EXTERNAL_PREF_DOWNLOAD, 3029 Manifest::EXTERNAL_PREF_DOWNLOAD,
3199 Extension::NO_FLAGS, 3030 Extension::NO_FLAGS,
3200 false)); 3031 false));
3201 3032
3202 // Check that there is a pending crx, with is_from_sync set to false. 3033 // Check that there is a pending crx, with is_from_sync set to false.
3203 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> 3034 ASSERT_TRUE((pending_extension_info =
3204 GetById(kGoodId))); 3035 service()->pending_extension_manager()->GetById(kGoodId)));
3205 EXPECT_FALSE(pending_extension_info->is_from_sync()); 3036 EXPECT_FALSE(pending_extension_info->is_from_sync());
3206 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, 3037 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD,
3207 pending_extension_info->install_source()); 3038 pending_extension_info->install_source());
3208 3039
3209 // Add a crx to be installed from the update mechanism. 3040 // Add a crx to be installed from the update mechanism.
3210 EXPECT_FALSE( 3041 EXPECT_FALSE(
3211 service_->pending_extension_manager()->AddFromSync(kGoodId, 3042 service()->pending_extension_manager()->AddFromSync(kGoodId,
3212 GURL(kGoodUpdateURL), 3043 GURL(kGoodUpdateURL),
3213 &IsExtension, 3044 &IsExtension,
3214 kGoodInstallSilently, 3045 kGoodInstallSilently,
3215 kGoodRemoteInstall)); 3046 kGoodRemoteInstall));
3216 3047
3217 // Check that the external, non-sync update was not overridden. 3048 // Check that the external, non-sync update was not overridden.
3218 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> 3049 ASSERT_TRUE((pending_extension_info =
3219 GetById(kGoodId))); 3050 service()->pending_extension_manager()->GetById(kGoodId)));
3220 EXPECT_FALSE(pending_extension_info->is_from_sync()); 3051 EXPECT_FALSE(pending_extension_info->is_from_sync());
3221 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, 3052 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD,
3222 pending_extension_info->install_source()); 3053 pending_extension_info->install_source());
3223 } 3054 }
3224 3055
3225 // Updating a theme should fail if the updater is explicitly told that 3056 // Updating a theme should fail if the updater is explicitly told that
3226 // the CRX is not a theme. 3057 // the CRX is not a theme.
3227 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { 3058 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) {
3228 InitializeEmptyExtensionService(); 3059 InitializeEmptyExtensionService();
3229 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( 3060 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync(
3230 theme_crx, GURL(), &IsExtension, true, false)); 3061 theme_crx, GURL(), &IsExtension, true, false));
3231 3062
3232 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 3063 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3233 3064
3234 base::FilePath path = data_dir_.AppendASCII("theme.crx"); 3065 base::FilePath path = data_dir().AppendASCII("theme.crx");
3235 UpdateExtension(theme_crx, path, FAILED_SILENTLY); 3066 UpdateExtension(theme_crx, path, FAILED_SILENTLY);
3236 3067
3237 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 3068 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3238 3069
3239 const Extension* extension = service_->GetExtensionById(theme_crx, true); 3070 const Extension* extension = service()->GetExtensionById(theme_crx, true);
3240 ASSERT_FALSE(extension); 3071 ASSERT_FALSE(extension);
3241 } 3072 }
3242 3073
3243 // TODO(akalin): Test updating a pending extension non-silently once 3074 // TODO(akalin): Test updating a pending extension non-silently once
3244 // we can mock out ExtensionInstallUI and inject our version into 3075 // we can mock out ExtensionInstallUI and inject our version into
3245 // UpdateExtension(). 3076 // UpdateExtension().
3246 3077
3247 // Test updating a pending extension which fails the should-install test. 3078 // Test updating a pending extension which fails the should-install test.
3248 TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) { 3079 TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) {
3249 InitializeEmptyExtensionService(); 3080 InitializeEmptyExtensionService();
3250 // Add pending extension with a flipped is_theme. 3081 // Add pending extension with a flipped is_theme.
3251 EXPECT_TRUE( 3082 EXPECT_TRUE(
3252 service_->pending_extension_manager()->AddFromSync(kGoodId, 3083 service()->pending_extension_manager()->AddFromSync(kGoodId,
3253 GURL(kGoodUpdateURL), 3084 GURL(kGoodUpdateURL),
3254 &IsTheme, 3085 &IsTheme,
3255 kGoodInstallSilently, 3086 kGoodInstallSilently,
3256 kGoodRemoteInstall)); 3087 kGoodRemoteInstall));
3257 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(kGoodId)); 3088 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3258 3089
3259 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3090 base::FilePath path = data_dir().AppendASCII("good.crx");
3260 UpdateExtension(kGoodId, path, UPDATED); 3091 UpdateExtension(kGoodId, path, UPDATED);
3261 3092
3262 // TODO(akalin): Figure out how to check that the extensions 3093 // TODO(akalin): Figure out how to check that the extensions
3263 // directory is cleaned up properly in OnExtensionInstalled(). 3094 // directory is cleaned up properly in OnExtensionInstalled().
3264 3095
3265 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); 3096 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3266 } 3097 }
3267 3098
3268 // TODO(akalin): Figure out how to test that installs of pending 3099 // TODO(akalin): Figure out how to test that installs of pending
3269 // unsyncable extensions are blocked. 3100 // unsyncable extensions are blocked.
3270 3101
3271 // Test updating a pending extension for one that is not pending. 3102 // Test updating a pending extension for one that is not pending.
3272 TEST_F(ExtensionServiceTest, UpdatePendingExtensionNotPending) { 3103 TEST_F(ExtensionServiceTest, UpdatePendingExtensionNotPending) {
3273 InitializeEmptyExtensionService(); 3104 InitializeEmptyExtensionService();
3274 3105
3275 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3106 base::FilePath path = data_dir().AppendASCII("good.crx");
3276 UpdateExtension(kGoodId, path, UPDATED); 3107 UpdateExtension(kGoodId, path, UPDATED);
3277 3108
3278 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); 3109 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3279 } 3110 }
3280 3111
3281 // Test updating a pending extension for one that is already 3112 // Test updating a pending extension for one that is already
3282 // installed. 3113 // installed.
3283 TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) { 3114 TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) {
3284 InitializeEmptyExtensionService(); 3115 InitializeEmptyExtensionService();
3285 3116
3286 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3117 base::FilePath path = data_dir().AppendASCII("good.crx");
3287 const Extension* good = InstallCRX(path, INSTALL_NEW); 3118 const Extension* good = InstallCRX(path, INSTALL_NEW);
3288 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3119 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3289 3120
3290 EXPECT_FALSE(good->is_theme()); 3121 EXPECT_FALSE(good->is_theme());
3291 3122
3292 // Use AddExtensionImpl() as AddFrom*() would balk. 3123 // Use AddExtensionImpl() as AddFrom*() would balk.
3293 service_->pending_extension_manager()->AddExtensionImpl( 3124 service()->pending_extension_manager()->AddExtensionImpl(
3294 good->id(), 3125 good->id(),
3295 std::string(), 3126 std::string(),
3296 extensions::ManifestURL::GetUpdateURL(good), 3127 extensions::ManifestURL::GetUpdateURL(good),
3297 Version(), 3128 Version(),
3298 &IsExtension, 3129 &IsExtension,
3299 kGoodIsFromSync, 3130 kGoodIsFromSync,
3300 kGoodInstallSilently, 3131 kGoodInstallSilently,
3301 Manifest::INTERNAL, 3132 Manifest::INTERNAL,
3302 Extension::NO_FLAGS, 3133 Extension::NO_FLAGS,
3303 false, 3134 false,
3304 kGoodRemoteInstall); 3135 kGoodRemoteInstall);
3305 UpdateExtension(good->id(), path, ENABLED); 3136 UpdateExtension(good->id(), path, ENABLED);
3306 3137
3307 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); 3138 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3308 } 3139 }
3309 3140
3310 #if defined(ENABLE_BLACKLIST_TESTS) 3141 #if defined(ENABLE_BLACKLIST_TESTS)
3311 // Tests blacklisting then unblacklisting extensions after the service has been 3142 // Tests blacklisting then unblacklisting extensions after the service has been
3312 // initialized. 3143 // initialized.
3313 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { 3144 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) {
3314 extensions::TestBlacklist test_blacklist; 3145 extensions::TestBlacklist test_blacklist;
3315 // A profile with 3 extensions installed: good0, good1, and good2. 3146 // A profile with 3 extensions installed: good0, good1, and good2.
3316 InitializeGoodInstalledExtensionService(); 3147 InitializeGoodInstalledExtensionService();
3317 test_blacklist.Attach(service_->blacklist_); 3148 test_blacklist.Attach(service()->blacklist_);
3318 service_->Init(); 3149 service()->Init();
3319 3150
3320 const extensions::ExtensionSet& enabled_extensions = 3151 const extensions::ExtensionSet& enabled_extensions =
3321 registry_->enabled_extensions(); 3152 registry()->enabled_extensions();
3322 const extensions::ExtensionSet& blacklisted_extensions = 3153 const extensions::ExtensionSet& blacklisted_extensions =
3323 registry_->blacklisted_extensions(); 3154 registry()->blacklisted_extensions();
3324 3155
3325 EXPECT_TRUE(enabled_extensions.Contains(good0) && 3156 EXPECT_TRUE(enabled_extensions.Contains(good0) &&
3326 !blacklisted_extensions.Contains(good0)); 3157 !blacklisted_extensions.Contains(good0));
3327 EXPECT_TRUE(enabled_extensions.Contains(good1) && 3158 EXPECT_TRUE(enabled_extensions.Contains(good1) &&
3328 !blacklisted_extensions.Contains(good1)); 3159 !blacklisted_extensions.Contains(good1));
3329 EXPECT_TRUE(enabled_extensions.Contains(good2) && 3160 EXPECT_TRUE(enabled_extensions.Contains(good2) &&
3330 !blacklisted_extensions.Contains(good2)); 3161 !blacklisted_extensions.Contains(good2));
3331 3162
3332 EXPECT_FALSE(IsPrefExist(good0, "blacklist")); 3163 EXPECT_FALSE(IsPrefExist(good0, "blacklist"));
3333 EXPECT_FALSE(IsPrefExist(good1, "blacklist")); 3164 EXPECT_FALSE(IsPrefExist(good1, "blacklist"));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3380 #endif // defined(ENABLE_BLACKLIST_TESTS) 3211 #endif // defined(ENABLE_BLACKLIST_TESTS)
3381 3212
3382 #if defined(ENABLE_BLACKLIST_TESTS) 3213 #if defined(ENABLE_BLACKLIST_TESTS)
3383 // Tests trying to install a blacklisted extension. 3214 // Tests trying to install a blacklisted extension.
3384 TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) { 3215 TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) {
3385 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( 3216 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db(
3386 new FakeSafeBrowsingDatabaseManager(true)); 3217 new FakeSafeBrowsingDatabaseManager(true));
3387 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); 3218 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db);
3388 3219
3389 InitializeEmptyExtensionService(); 3220 InitializeEmptyExtensionService();
3390 service_->Init(); 3221 service()->Init();
3391 3222
3392 // After blacklisting good_crx, we cannot install it. 3223 // After blacklisting good_crx, we cannot install it.
3393 blacklist_db->SetUnsafe(good_crx).NotifyUpdate(); 3224 blacklist_db->SetUnsafe(good_crx).NotifyUpdate();
3394 base::RunLoop().RunUntilIdle(); 3225 base::RunLoop().RunUntilIdle();
3395 3226
3396 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3227 base::FilePath path = data_dir().AppendASCII("good.crx");
3397 // HACK: specify WAS_INSTALLED_BY_DEFAULT so that test machinery doesn't 3228 // HACK: specify WAS_INSTALLED_BY_DEFAULT so that test machinery doesn't
3398 // decide to install this silently. Somebody should fix these tests, all 3229 // decide to install this silently. Somebody should fix these tests, all
3399 // 6,000 lines of them. Hah! 3230 // 6,000 lines of them. Hah!
3400 InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT); 3231 InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT);
3401 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3232 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3402 } 3233 }
3403 #endif // defined(ENABLE_BLACKLIST_TESTS) 3234 #endif // defined(ENABLE_BLACKLIST_TESTS)
3404 3235
3405 #if defined(ENABLE_BLACKLIST_TESTS) 3236 #if defined(ENABLE_BLACKLIST_TESTS)
3406 // Unload blacklisted extension on policy change. 3237 // Unload blacklisted extension on policy change.
3407 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) { 3238 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) {
3408 extensions::TestBlacklist test_blacklist; 3239 extensions::TestBlacklist test_blacklist;
3409 3240
3410 // A profile with no extensions installed. 3241 // A profile with no extensions installed.
3411 InitializeEmptyExtensionService(); 3242 InitializeEmptyExtensionService();
3412 test_blacklist.Attach(service_->blacklist_); 3243 test_blacklist.Attach(service()->blacklist_);
3413 3244
3414 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3245 base::FilePath path = data_dir().AppendASCII("good.crx");
3415 3246
3416 const Extension* good = InstallCRX(path, INSTALL_NEW); 3247 const Extension* good = InstallCRX(path, INSTALL_NEW);
3417 EXPECT_EQ(good_crx, good->id()); 3248 EXPECT_EQ(good_crx, good->id());
3418 UpdateExtension(good_crx, path, FAILED_SILENTLY); 3249 UpdateExtension(good_crx, path, FAILED_SILENTLY);
3419 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3250 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3420 3251
3421 base::ListValue whitelist; 3252 base::ListValue whitelist;
3422 PrefService* prefs = ExtensionPrefs::Get(profile_.get())->pref_service(); 3253 PrefService* prefs = ExtensionPrefs::Get(profile())->pref_service();
3423 whitelist.Append(new base::StringValue(good_crx)); 3254 whitelist.Append(new base::StringValue(good_crx));
3424 prefs->Set(extensions::pref_names::kInstallAllowList, whitelist); 3255 prefs->Set(extensions::pref_names::kInstallAllowList, whitelist);
3425 3256
3426 test_blacklist.SetBlacklistState( 3257 test_blacklist.SetBlacklistState(
3427 good_crx, extensions::BLACKLISTED_MALWARE, true); 3258 good_crx, extensions::BLACKLISTED_MALWARE, true);
3428 base::RunLoop().RunUntilIdle(); 3259 base::RunLoop().RunUntilIdle();
3429 3260
3430 // The good_crx is blacklisted and the whitelist doesn't negate it. 3261 // The good_crx is blacklisted and the whitelist doesn't negate it.
3431 ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true)); 3262 ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true));
3432 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3263 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3433 } 3264 }
3434 #endif // defined(ENABLE_BLACKLIST_TESTS) 3265 #endif // defined(ENABLE_BLACKLIST_TESTS)
3435 3266
3436 #if defined(ENABLE_BLACKLIST_TESTS) 3267 #if defined(ENABLE_BLACKLIST_TESTS)
3437 // Tests that a blacklisted extension is eventually unloaded on startup, if it 3268 // Tests that a blacklisted extension is eventually unloaded on startup, if it
3438 // wasn't already. 3269 // wasn't already.
3439 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { 3270 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) {
3440 extensions::TestBlacklist test_blacklist; 3271 extensions::TestBlacklist test_blacklist;
3441 3272
3442 // A profile with 3 extensions installed: good0, good1, and good2. 3273 // A profile with 3 extensions installed: good0, good1, and good2.
3443 InitializeGoodInstalledExtensionService(); 3274 InitializeGoodInstalledExtensionService();
3444 test_blacklist.Attach(service_->blacklist_); 3275 test_blacklist.Attach(service()->blacklist_);
3445 3276
3446 // Blacklist good1 before the service initializes. 3277 // Blacklist good1 before the service initializes.
3447 test_blacklist.SetBlacklistState( 3278 test_blacklist.SetBlacklistState(
3448 good1, extensions::BLACKLISTED_MALWARE, false); 3279 good1, extensions::BLACKLISTED_MALWARE, false);
3449 3280
3450 // Load extensions. 3281 // Load extensions.
3451 service_->Init(); 3282 service()->Init();
3452 ASSERT_EQ(3u, loaded_.size()); // hasn't had time to blacklist yet 3283 ASSERT_EQ(3u, loaded_.size()); // hasn't had time to blacklist yet
3453 3284
3454 base::RunLoop().RunUntilIdle(); 3285 base::RunLoop().RunUntilIdle();
3455 3286
3456 ASSERT_EQ(1u, registry_->blacklisted_extensions().size()); 3287 ASSERT_EQ(1u, registry()->blacklisted_extensions().size());
3457 ASSERT_EQ(2u, registry_->enabled_extensions().size()); 3288 ASSERT_EQ(2u, registry()->enabled_extensions().size());
3458 3289
3459 ASSERT_TRUE(registry_->enabled_extensions().Contains(good0)); 3290 ASSERT_TRUE(registry()->enabled_extensions().Contains(good0));
3460 ASSERT_TRUE(registry_->blacklisted_extensions().Contains(good1)); 3291 ASSERT_TRUE(registry()->blacklisted_extensions().Contains(good1));
3461 ASSERT_TRUE(registry_->enabled_extensions().Contains(good2)); 3292 ASSERT_TRUE(registry()->enabled_extensions().Contains(good2));
3462 } 3293 }
3463 #endif // defined(ENABLE_BLACKLIST_TESTS) 3294 #endif // defined(ENABLE_BLACKLIST_TESTS)
3464 3295
3465 #if defined(ENABLE_BLACKLIST_TESTS) 3296 #if defined(ENABLE_BLACKLIST_TESTS)
3466 // Tests extensions blacklisted in prefs on startup; one still blacklisted by 3297 // Tests extensions blacklisted in prefs on startup; one still blacklisted by
3467 // safe browsing, the other not. The not-blacklisted one should recover. 3298 // safe browsing, the other not. The not-blacklisted one should recover.
3468 TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) { 3299 TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) {
3469 extensions::TestBlacklist test_blacklist; 3300 extensions::TestBlacklist test_blacklist;
3470 3301
3471 InitializeGoodInstalledExtensionService(); 3302 InitializeGoodInstalledExtensionService();
3472 test_blacklist.Attach(service_->blacklist_); 3303 test_blacklist.Attach(service()->blacklist_);
3473 ExtensionPrefs::Get(profile_.get())->SetExtensionBlacklisted(good0, true); 3304 ExtensionPrefs::Get(profile())->SetExtensionBlacklisted(good0, true);
3474 ExtensionPrefs::Get(profile_.get())->SetExtensionBlacklisted(good1, true); 3305 ExtensionPrefs::Get(profile())->SetExtensionBlacklisted(good1, true);
3475 3306
3476 test_blacklist.SetBlacklistState( 3307 test_blacklist.SetBlacklistState(
3477 good1, extensions::BLACKLISTED_MALWARE, false); 3308 good1, extensions::BLACKLISTED_MALWARE, false);
3478 3309
3479 // Extension service hasn't loaded yet, but IsExtensionEnabled reads out of 3310 // Extension service hasn't loaded yet, but IsExtensionEnabled reads out of
3480 // prefs. Ensure it takes into account the blacklist state (crbug.com/373842). 3311 // prefs. Ensure it takes into account the blacklist state (crbug.com/373842).
3481 EXPECT_FALSE(service_->IsExtensionEnabled(good0)); 3312 EXPECT_FALSE(service()->IsExtensionEnabled(good0));
3482 EXPECT_FALSE(service_->IsExtensionEnabled(good1)); 3313 EXPECT_FALSE(service()->IsExtensionEnabled(good1));
3483 EXPECT_TRUE(service_->IsExtensionEnabled(good2)); 3314 EXPECT_TRUE(service()->IsExtensionEnabled(good2));
3484 3315
3485 service_->Init(); 3316 service()->Init();
3486 3317
3487 EXPECT_EQ(2u, registry_->blacklisted_extensions().size()); 3318 EXPECT_EQ(2u, registry()->blacklisted_extensions().size());
3488 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3319 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3489 3320
3490 EXPECT_TRUE(registry_->blacklisted_extensions().Contains(good0)); 3321 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good0));
3491 EXPECT_TRUE(registry_->blacklisted_extensions().Contains(good1)); 3322 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good1));
3492 EXPECT_TRUE(registry_->enabled_extensions().Contains(good2)); 3323 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
3493 3324
3494 // Give time for the blacklist to update. 3325 // Give time for the blacklist to update.
3495 base::RunLoop().RunUntilIdle(); 3326 base::RunLoop().RunUntilIdle();
3496 3327
3497 EXPECT_EQ(1u, registry_->blacklisted_extensions().size()); 3328 EXPECT_EQ(1u, registry()->blacklisted_extensions().size());
3498 EXPECT_EQ(2u, registry_->enabled_extensions().size()); 3329 EXPECT_EQ(2u, registry()->enabled_extensions().size());
3499 3330
3500 EXPECT_TRUE(registry_->enabled_extensions().Contains(good0)); 3331 EXPECT_TRUE(registry()->enabled_extensions().Contains(good0));
3501 EXPECT_TRUE(registry_->blacklisted_extensions().Contains(good1)); 3332 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good1));
3502 EXPECT_TRUE(registry_->enabled_extensions().Contains(good2)); 3333 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
3503 } 3334 }
3504 #endif // defined(ENABLE_BLACKLIST_TESTS) 3335 #endif // defined(ENABLE_BLACKLIST_TESTS)
3505 3336
3506 #if defined(ENABLE_BLACKLIST_TESTS) 3337 #if defined(ENABLE_BLACKLIST_TESTS)
3507 // Extension is added to blacklist with BLACKLISTED_POTENTIALLY_UNWANTED state 3338 // Extension is added to blacklist with BLACKLISTED_POTENTIALLY_UNWANTED state
3508 // after it is installed. It is then successfully re-enabled by the user. 3339 // after it is installed. It is then successfully re-enabled by the user.
3509 TEST_F(ExtensionServiceTest, GreylistedExtensionDisabled) { 3340 TEST_F(ExtensionServiceTest, GreylistedExtensionDisabled) {
3510 extensions::TestBlacklist test_blacklist; 3341 extensions::TestBlacklist test_blacklist;
3511 // A profile with 3 extensions installed: good0, good1, and good2. 3342 // A profile with 3 extensions installed: good0, good1, and good2.
3512 InitializeGoodInstalledExtensionService(); 3343 InitializeGoodInstalledExtensionService();
3513 test_blacklist.Attach(service_->blacklist_); 3344 test_blacklist.Attach(service()->blacklist_);
3514 service_->Init(); 3345 service()->Init();
3515 3346
3516 const extensions::ExtensionSet& enabled_extensions = 3347 const extensions::ExtensionSet& enabled_extensions =
3517 registry_->enabled_extensions(); 3348 registry()->enabled_extensions();
3518 const extensions::ExtensionSet& disabled_extensions = 3349 const extensions::ExtensionSet& disabled_extensions =
3519 registry_->disabled_extensions(); 3350 registry()->disabled_extensions();
3520 3351
3521 EXPECT_TRUE(enabled_extensions.Contains(good0)); 3352 EXPECT_TRUE(enabled_extensions.Contains(good0));
3522 EXPECT_TRUE(enabled_extensions.Contains(good1)); 3353 EXPECT_TRUE(enabled_extensions.Contains(good1));
3523 EXPECT_TRUE(enabled_extensions.Contains(good2)); 3354 EXPECT_TRUE(enabled_extensions.Contains(good2));
3524 3355
3525 // Blacklist good0 and good1 (and an invalid extension ID). 3356 // Blacklist good0 and good1 (and an invalid extension ID).
3526 test_blacklist.SetBlacklistState( 3357 test_blacklist.SetBlacklistState(
3527 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); 3358 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true);
3528 test_blacklist.SetBlacklistState( 3359 test_blacklist.SetBlacklistState(
3529 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); 3360 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true);
3530 test_blacklist.SetBlacklistState( 3361 test_blacklist.SetBlacklistState(
3531 "invalid_id", extensions::BLACKLISTED_MALWARE, true); 3362 "invalid_id", extensions::BLACKLISTED_MALWARE, true);
3532 base::RunLoop().RunUntilIdle(); 3363 base::RunLoop().RunUntilIdle();
3533 3364
3534 EXPECT_FALSE(enabled_extensions.Contains(good0)); 3365 EXPECT_FALSE(enabled_extensions.Contains(good0));
3535 EXPECT_TRUE(disabled_extensions.Contains(good0)); 3366 EXPECT_TRUE(disabled_extensions.Contains(good0));
3536 EXPECT_FALSE(enabled_extensions.Contains(good1)); 3367 EXPECT_FALSE(enabled_extensions.Contains(good1));
3537 EXPECT_TRUE(disabled_extensions.Contains(good1)); 3368 EXPECT_TRUE(disabled_extensions.Contains(good1));
3538 EXPECT_TRUE(enabled_extensions.Contains(good2)); 3369 EXPECT_TRUE(enabled_extensions.Contains(good2));
3539 EXPECT_FALSE(disabled_extensions.Contains(good2)); 3370 EXPECT_FALSE(disabled_extensions.Contains(good2));
3540 3371
3541 ValidateIntegerPref( 3372 ValidateIntegerPref(
3542 good0, "blacklist_state", extensions::BLACKLISTED_CWS_POLICY_VIOLATION); 3373 good0, "blacklist_state", extensions::BLACKLISTED_CWS_POLICY_VIOLATION);
3543 ValidateIntegerPref( 3374 ValidateIntegerPref(
3544 good1, "blacklist_state", extensions::BLACKLISTED_POTENTIALLY_UNWANTED); 3375 good1, "blacklist_state", extensions::BLACKLISTED_POTENTIALLY_UNWANTED);
3545 3376
3546 // Now user enables good0. 3377 // Now user enables good0.
3547 service_->EnableExtension(good0); 3378 service()->EnableExtension(good0);
3548 3379
3549 EXPECT_TRUE(enabled_extensions.Contains(good0)); 3380 EXPECT_TRUE(enabled_extensions.Contains(good0));
3550 EXPECT_FALSE(disabled_extensions.Contains(good0)); 3381 EXPECT_FALSE(disabled_extensions.Contains(good0));
3551 EXPECT_FALSE(enabled_extensions.Contains(good1)); 3382 EXPECT_FALSE(enabled_extensions.Contains(good1));
3552 EXPECT_TRUE(disabled_extensions.Contains(good1)); 3383 EXPECT_TRUE(disabled_extensions.Contains(good1));
3553 3384
3554 // Remove extensions from blacklist. 3385 // Remove extensions from blacklist.
3555 test_blacklist.SetBlacklistState( 3386 test_blacklist.SetBlacklistState(
3556 good0, extensions::NOT_BLACKLISTED, true); 3387 good0, extensions::NOT_BLACKLISTED, true);
3557 test_blacklist.SetBlacklistState( 3388 test_blacklist.SetBlacklistState(
(...skipping 10 matching lines...) Expand all
3568 } 3399 }
3569 #endif // defined(ENABLE_BLACKLIST_TESTS) 3400 #endif // defined(ENABLE_BLACKLIST_TESTS)
3570 3401
3571 #if defined(ENABLE_BLACKLIST_TESTS) 3402 #if defined(ENABLE_BLACKLIST_TESTS)
3572 // When extension is removed from greylist, do not re-enable it if it is 3403 // When extension is removed from greylist, do not re-enable it if it is
3573 // disabled by user. 3404 // disabled by user.
3574 TEST_F(ExtensionServiceTest, GreylistDontEnableManuallyDisabled) { 3405 TEST_F(ExtensionServiceTest, GreylistDontEnableManuallyDisabled) {
3575 extensions::TestBlacklist test_blacklist; 3406 extensions::TestBlacklist test_blacklist;
3576 // A profile with 3 extensions installed: good0, good1, and good2. 3407 // A profile with 3 extensions installed: good0, good1, and good2.
3577 InitializeGoodInstalledExtensionService(); 3408 InitializeGoodInstalledExtensionService();
3578 test_blacklist.Attach(service_->blacklist_); 3409 test_blacklist.Attach(service()->blacklist_);
3579 service_->Init(); 3410 service()->Init();
3580 3411
3581 const extensions::ExtensionSet& enabled_extensions = 3412 const extensions::ExtensionSet& enabled_extensions =
3582 registry_->enabled_extensions(); 3413 registry()->enabled_extensions();
3583 const extensions::ExtensionSet& disabled_extensions = 3414 const extensions::ExtensionSet& disabled_extensions =
3584 registry_->disabled_extensions(); 3415 registry()->disabled_extensions();
3585 3416
3586 // Manually disable. 3417 // Manually disable.
3587 service_->DisableExtension(good0, extensions::Extension::DISABLE_USER_ACTION); 3418 service()->DisableExtension(good0,
3419 extensions::Extension::DISABLE_USER_ACTION);
3588 3420
3589 test_blacklist.SetBlacklistState( 3421 test_blacklist.SetBlacklistState(
3590 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); 3422 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true);
3591 test_blacklist.SetBlacklistState( 3423 test_blacklist.SetBlacklistState(
3592 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); 3424 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true);
3593 test_blacklist.SetBlacklistState( 3425 test_blacklist.SetBlacklistState(
3594 good2, extensions::BLACKLISTED_SECURITY_VULNERABILITY, true); 3426 good2, extensions::BLACKLISTED_SECURITY_VULNERABILITY, true);
3595 base::RunLoop().RunUntilIdle(); 3427 base::RunLoop().RunUntilIdle();
3596 3428
3597 // All extensions disabled. 3429 // All extensions disabled.
3598 EXPECT_FALSE(enabled_extensions.Contains(good0)); 3430 EXPECT_FALSE(enabled_extensions.Contains(good0));
3599 EXPECT_TRUE(disabled_extensions.Contains(good0)); 3431 EXPECT_TRUE(disabled_extensions.Contains(good0));
3600 EXPECT_FALSE(enabled_extensions.Contains(good1)); 3432 EXPECT_FALSE(enabled_extensions.Contains(good1));
3601 EXPECT_TRUE(disabled_extensions.Contains(good1)); 3433 EXPECT_TRUE(disabled_extensions.Contains(good1));
3602 EXPECT_FALSE(enabled_extensions.Contains(good2)); 3434 EXPECT_FALSE(enabled_extensions.Contains(good2));
3603 EXPECT_TRUE(disabled_extensions.Contains(good2)); 3435 EXPECT_TRUE(disabled_extensions.Contains(good2));
3604 3436
3605 // Greylisted extension can be enabled. 3437 // Greylisted extension can be enabled.
3606 service_->EnableExtension(good1); 3438 service()->EnableExtension(good1);
3607 EXPECT_TRUE(enabled_extensions.Contains(good1)); 3439 EXPECT_TRUE(enabled_extensions.Contains(good1));
3608 EXPECT_FALSE(disabled_extensions.Contains(good1)); 3440 EXPECT_FALSE(disabled_extensions.Contains(good1));
3609 3441
3610 // good1 is now manually disabled. 3442 // good1 is now manually disabled.
3611 service_->DisableExtension(good1, extensions::Extension::DISABLE_USER_ACTION); 3443 service()->DisableExtension(good1,
3444 extensions::Extension::DISABLE_USER_ACTION);
3612 EXPECT_FALSE(enabled_extensions.Contains(good1)); 3445 EXPECT_FALSE(enabled_extensions.Contains(good1));
3613 EXPECT_TRUE(disabled_extensions.Contains(good1)); 3446 EXPECT_TRUE(disabled_extensions.Contains(good1));
3614 3447
3615 // Remove extensions from blacklist. 3448 // Remove extensions from blacklist.
3616 test_blacklist.SetBlacklistState( 3449 test_blacklist.SetBlacklistState(
3617 good0, extensions::NOT_BLACKLISTED, true); 3450 good0, extensions::NOT_BLACKLISTED, true);
3618 test_blacklist.SetBlacklistState( 3451 test_blacklist.SetBlacklistState(
3619 good1, extensions::NOT_BLACKLISTED, true); 3452 good1, extensions::NOT_BLACKLISTED, true);
3620 test_blacklist.SetBlacklistState( 3453 test_blacklist.SetBlacklistState(
3621 good2, extensions::NOT_BLACKLISTED, true); 3454 good2, extensions::NOT_BLACKLISTED, true);
3622 base::RunLoop().RunUntilIdle(); 3455 base::RunLoop().RunUntilIdle();
3623 3456
3624 // good0 and good1 remain disabled. 3457 // good0 and good1 remain disabled.
3625 EXPECT_FALSE(enabled_extensions.Contains(good0)); 3458 EXPECT_FALSE(enabled_extensions.Contains(good0));
3626 EXPECT_TRUE(disabled_extensions.Contains(good0)); 3459 EXPECT_TRUE(disabled_extensions.Contains(good0));
3627 EXPECT_FALSE(enabled_extensions.Contains(good1)); 3460 EXPECT_FALSE(enabled_extensions.Contains(good1));
3628 EXPECT_TRUE(disabled_extensions.Contains(good1)); 3461 EXPECT_TRUE(disabled_extensions.Contains(good1));
3629 EXPECT_TRUE(enabled_extensions.Contains(good2)); 3462 EXPECT_TRUE(enabled_extensions.Contains(good2));
3630 EXPECT_FALSE(disabled_extensions.Contains(good2)); 3463 EXPECT_FALSE(disabled_extensions.Contains(good2));
3631 } 3464 }
3632 #endif // defined(ENABLE_BLACKLIST_TESTS) 3465 #endif // defined(ENABLE_BLACKLIST_TESTS)
3633 3466
3634 #if defined(ENABLE_BLACKLIST_TESTS) 3467 #if defined(ENABLE_BLACKLIST_TESTS)
3635 // Blacklisted extension with unknown state are not enabled/disabled. 3468 // Blacklisted extension with unknown state are not enabled/disabled.
3636 TEST_F(ExtensionServiceTest, GreylistUnknownDontChange) { 3469 TEST_F(ExtensionServiceTest, GreylistUnknownDontChange) {
3637 extensions::TestBlacklist test_blacklist; 3470 extensions::TestBlacklist test_blacklist;
3638 // A profile with 3 extensions installed: good0, good1, and good2. 3471 // A profile with 3 extensions installed: good0, good1, and good2.
3639 InitializeGoodInstalledExtensionService(); 3472 InitializeGoodInstalledExtensionService();
3640 test_blacklist.Attach(service_->blacklist_); 3473 test_blacklist.Attach(service()->blacklist_);
3641 service_->Init(); 3474 service()->Init();
3642 3475
3643 const extensions::ExtensionSet& enabled_extensions = 3476 const extensions::ExtensionSet& enabled_extensions =
3644 registry_->enabled_extensions(); 3477 registry()->enabled_extensions();
3645 const extensions::ExtensionSet& disabled_extensions = 3478 const extensions::ExtensionSet& disabled_extensions =
3646 registry_->disabled_extensions(); 3479 registry()->disabled_extensions();
3647 3480
3648 test_blacklist.SetBlacklistState( 3481 test_blacklist.SetBlacklistState(
3649 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); 3482 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true);
3650 test_blacklist.SetBlacklistState( 3483 test_blacklist.SetBlacklistState(
3651 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); 3484 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true);
3652 base::RunLoop().RunUntilIdle(); 3485 base::RunLoop().RunUntilIdle();
3653 3486
3654 EXPECT_FALSE(enabled_extensions.Contains(good0)); 3487 EXPECT_FALSE(enabled_extensions.Contains(good0));
3655 EXPECT_TRUE(disabled_extensions.Contains(good0)); 3488 EXPECT_TRUE(disabled_extensions.Contains(good0));
3656 EXPECT_FALSE(enabled_extensions.Contains(good1)); 3489 EXPECT_FALSE(enabled_extensions.Contains(good1));
(...skipping 17 matching lines...) Expand all
3674 EXPECT_TRUE(enabled_extensions.Contains(good2)); 3507 EXPECT_TRUE(enabled_extensions.Contains(good2));
3675 EXPECT_FALSE(disabled_extensions.Contains(good2)); 3508 EXPECT_FALSE(disabled_extensions.Contains(good2));
3676 } 3509 }
3677 3510
3678 // Tests that blacklisted extensions cannot be reloaded, both those loaded 3511 // Tests that blacklisted extensions cannot be reloaded, both those loaded
3679 // before and after extension service startup. 3512 // before and after extension service startup.
3680 TEST_F(ExtensionServiceTest, ReloadBlacklistedExtension) { 3513 TEST_F(ExtensionServiceTest, ReloadBlacklistedExtension) {
3681 extensions::TestBlacklist test_blacklist; 3514 extensions::TestBlacklist test_blacklist;
3682 3515
3683 InitializeGoodInstalledExtensionService(); 3516 InitializeGoodInstalledExtensionService();
3684 test_blacklist.Attach(service_->blacklist_); 3517 test_blacklist.Attach(service()->blacklist_);
3685 3518
3686 test_blacklist.SetBlacklistState( 3519 test_blacklist.SetBlacklistState(
3687 good1, extensions::BLACKLISTED_MALWARE, false); 3520 good1, extensions::BLACKLISTED_MALWARE, false);
3688 service_->Init(); 3521 service()->Init();
3689 test_blacklist.SetBlacklistState( 3522 test_blacklist.SetBlacklistState(
3690 good2, extensions::BLACKLISTED_MALWARE, false); 3523 good2, extensions::BLACKLISTED_MALWARE, false);
3691 base::RunLoop().RunUntilIdle(); 3524 base::RunLoop().RunUntilIdle();
3692 3525
3693 EXPECT_EQ(StringSet(good0), registry_->enabled_extensions().GetIDs()); 3526 EXPECT_EQ(StringSet(good0), registry()->enabled_extensions().GetIDs());
3694 EXPECT_EQ(StringSet(good1, good2), 3527 EXPECT_EQ(StringSet(good1, good2),
3695 registry_->blacklisted_extensions().GetIDs()); 3528 registry()->blacklisted_extensions().GetIDs());
3696 3529
3697 service_->ReloadExtension(good1); 3530 service()->ReloadExtension(good1);
3698 service_->ReloadExtension(good2); 3531 service()->ReloadExtension(good2);
3699 base::RunLoop().RunUntilIdle(); 3532 base::RunLoop().RunUntilIdle();
3700 3533
3701 EXPECT_EQ(StringSet(good0), registry_->enabled_extensions().GetIDs()); 3534 EXPECT_EQ(StringSet(good0), registry()->enabled_extensions().GetIDs());
3702 EXPECT_EQ(StringSet(good1, good2), 3535 EXPECT_EQ(StringSet(good1, good2),
3703 registry_->blacklisted_extensions().GetIDs()); 3536 registry()->blacklisted_extensions().GetIDs());
3704 } 3537 }
3705 3538
3706 #endif // defined(ENABLE_BLACKLIST_TESTS) 3539 #endif // defined(ENABLE_BLACKLIST_TESTS)
3707 3540
3708 // Will not install extension blacklisted by policy. 3541 // Will not install extension blacklisted by policy.
3709 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { 3542 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) {
3710 InitializeEmptyExtensionService(); 3543 InitializeEmptyExtensionService();
3711 3544
3712 // Blacklist everything. 3545 // Blacklist everything.
3713 { 3546 {
3714 ListPrefUpdate update(profile_->GetPrefs(), 3547 ListPrefUpdate update(profile()->GetPrefs(),
3715 extensions::pref_names::kInstallDenyList); 3548 extensions::pref_names::kInstallDenyList);
3716 base::ListValue* blacklist = update.Get(); 3549 base::ListValue* blacklist = update.Get();
3717 blacklist->Append(new base::StringValue("*")); 3550 blacklist->Append(new base::StringValue("*"));
3718 } 3551 }
3719 3552
3720 // Blacklist prevents us from installing good_crx. 3553 // Blacklist prevents us from installing good_crx.
3721 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3554 base::FilePath path = data_dir().AppendASCII("good.crx");
3722 InstallCRX(path, INSTALL_FAILED); 3555 InstallCRX(path, INSTALL_FAILED);
3723 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3556 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3724 3557
3725 // Now whitelist this particular extension. 3558 // Now whitelist this particular extension.
3726 { 3559 {
3727 ListPrefUpdate update(profile_->GetPrefs(), 3560 ListPrefUpdate update(profile()->GetPrefs(),
3728 extensions::pref_names::kInstallAllowList); 3561 extensions::pref_names::kInstallAllowList);
3729 base::ListValue* whitelist = update.Get(); 3562 base::ListValue* whitelist = update.Get();
3730 whitelist->Append(new base::StringValue(good_crx)); 3563 whitelist->Append(new base::StringValue(good_crx));
3731 } 3564 }
3732 3565
3733 // Ensure we can now install good_crx. 3566 // Ensure we can now install good_crx.
3734 InstallCRX(path, INSTALL_NEW); 3567 InstallCRX(path, INSTALL_NEW);
3735 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3568 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3736 } 3569 }
3737 3570
3738 // Extension blacklisted by policy get unloaded after installing. 3571 // Extension blacklisted by policy get unloaded after installing.
3739 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { 3572 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) {
3740 InitializeEmptyExtensionService(); 3573 InitializeEmptyExtensionService();
3741 3574
3742 // Install good_crx. 3575 // Install good_crx.
3743 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3576 base::FilePath path = data_dir().AppendASCII("good.crx");
3744 InstallCRX(path, INSTALL_NEW); 3577 InstallCRX(path, INSTALL_NEW);
3745 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3578 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3746 3579
3747 { // Scope for pref update notification. 3580 { // Scope for pref update notification.
3748 PrefService* prefs = profile_->GetPrefs(); 3581 PrefService* prefs = profile()->GetPrefs();
3749 ListPrefUpdate update(prefs, extensions::pref_names::kInstallDenyList); 3582 ListPrefUpdate update(prefs, extensions::pref_names::kInstallDenyList);
3750 base::ListValue* blacklist = update.Get(); 3583 base::ListValue* blacklist = update.Get();
3751 ASSERT_TRUE(blacklist != NULL); 3584 ASSERT_TRUE(blacklist != NULL);
3752 3585
3753 // Blacklist this extension. 3586 // Blacklist this extension.
3754 blacklist->Append(new base::StringValue(good_crx)); 3587 blacklist->Append(new base::StringValue(good_crx));
3755 } 3588 }
3756 3589
3757 // Extension should not be running now. 3590 // Extension should not be running now.
3758 base::RunLoop().RunUntilIdle(); 3591 base::RunLoop().RunUntilIdle();
3759 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3592 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3760 } 3593 }
3761 3594
3762 // Tests that component extensions are not blacklisted by policy. 3595 // Tests that component extensions are not blacklisted by policy.
3763 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { 3596 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) {
3764 InitializeEmptyExtensionService(); 3597 InitializeEmptyExtensionService();
3765 3598
3766 // Blacklist everything. 3599 // Blacklist everything.
3767 { 3600 {
3768 ListPrefUpdate update(profile_->GetPrefs(), 3601 ListPrefUpdate update(profile()->GetPrefs(),
3769 extensions::pref_names::kInstallDenyList); 3602 extensions::pref_names::kInstallDenyList);
3770 base::ListValue* blacklist = update.Get(); 3603 base::ListValue* blacklist = update.Get();
3771 blacklist->Append(new base::StringValue("*")); 3604 blacklist->Append(new base::StringValue("*"));
3772 } 3605 }
3773 3606
3774 // Install a component extension. 3607 // Install a component extension.
3775 base::FilePath path = data_dir_ 3608 base::FilePath path = data_dir()
3776 .AppendASCII("good") 3609 .AppendASCII("good")
3777 .AppendASCII("Extensions") 3610 .AppendASCII("Extensions")
3778 .AppendASCII(good0) 3611 .AppendASCII(good0)
3779 .AppendASCII("1.0.0.0"); 3612 .AppendASCII("1.0.0.0");
3780 std::string manifest; 3613 std::string manifest;
3781 ASSERT_TRUE(base::ReadFileToString( 3614 ASSERT_TRUE(base::ReadFileToString(
3782 path.Append(extensions::kManifestFilename), &manifest)); 3615 path.Append(extensions::kManifestFilename), &manifest));
3783 service_->component_loader()->Add(manifest, path); 3616 service()->component_loader()->Add(manifest, path);
3784 service_->Init(); 3617 service()->Init();
3785 3618
3786 // Extension should be installed despite blacklist. 3619 // Extension should be installed despite blacklist.
3787 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3620 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3788 EXPECT_TRUE(service_->GetExtensionById(good0, false)); 3621 EXPECT_TRUE(service()->GetExtensionById(good0, false));
3789 3622
3790 // Poke external providers and make sure the extension is still present. 3623 // Poke external providers and make sure the extension is still present.
3791 service_->CheckForExternalUpdates(); 3624 service()->CheckForExternalUpdates();
3792 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3625 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3793 EXPECT_TRUE(service_->GetExtensionById(good0, false)); 3626 EXPECT_TRUE(service()->GetExtensionById(good0, false));
3794 3627
3795 // Extension should not be uninstalled on blacklist changes. 3628 // Extension should not be uninstalled on blacklist changes.
3796 { 3629 {
3797 ListPrefUpdate update(profile_->GetPrefs(), 3630 ListPrefUpdate update(profile()->GetPrefs(),
3798 extensions::pref_names::kInstallDenyList); 3631 extensions::pref_names::kInstallDenyList);
3799 base::ListValue* blacklist = update.Get(); 3632 base::ListValue* blacklist = update.Get();
3800 blacklist->Append(new base::StringValue(good0)); 3633 blacklist->Append(new base::StringValue(good0));
3801 } 3634 }
3802 base::RunLoop().RunUntilIdle(); 3635 base::RunLoop().RunUntilIdle();
3803 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3636 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3804 EXPECT_TRUE(service_->GetExtensionById(good0, false)); 3637 EXPECT_TRUE(service()->GetExtensionById(good0, false));
3805 } 3638 }
3806 3639
3807 // Tests that policy-installed extensions are not blacklisted by policy. 3640 // Tests that policy-installed extensions are not blacklisted by policy.
3808 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { 3641 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) {
3809 InitializeEmptyExtensionService(); 3642 InitializeEmptyExtensionService();
3810 3643
3811 { 3644 {
3812 // Blacklist everything. 3645 // Blacklist everything.
3813 ListPrefUpdate blacklist_update( 3646 ListPrefUpdate blacklist_update(profile()->GetPrefs(),
3814 profile_->GetPrefs(), extensions::pref_names::kInstallDenyList); 3647 extensions::pref_names::kInstallDenyList);
3815 base::ListValue* blacklist = blacklist_update.Get(); 3648 base::ListValue* blacklist = blacklist_update.Get();
3816 blacklist->AppendString("*"); 3649 blacklist->AppendString("*");
3817 3650
3818 // Mark good.crx for force-installation. 3651 // Mark good.crx for force-installation.
3819 DictionaryPrefUpdate forcelist_update( 3652 DictionaryPrefUpdate forcelist_update(
3820 profile_->GetPrefs(), 3653 profile()->GetPrefs(), extensions::pref_names::kInstallForceList);
3821 extensions::pref_names::kInstallForceList);
3822 extensions::ExternalPolicyLoader::AddExtension( 3654 extensions::ExternalPolicyLoader::AddExtension(
3823 forcelist_update.Get(), good_crx, "http://example.com/update_url"); 3655 forcelist_update.Get(), good_crx, "http://example.com/update_url");
3824 } 3656 }
3825 3657
3826 // Have policy force-install an extension. 3658 // Have policy force-install an extension.
3827 MockExtensionProvider* provider = 3659 MockExtensionProvider* provider =
3828 new MockExtensionProvider(service_, 3660 new MockExtensionProvider(service(), Manifest::EXTERNAL_POLICY_DOWNLOAD);
3829 Manifest::EXTERNAL_POLICY_DOWNLOAD);
3830 AddMockExternalProvider(provider); 3661 AddMockExternalProvider(provider);
3831 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 3662 provider->UpdateOrAddExtension(
3832 data_dir_.AppendASCII("good.crx")); 3663 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx"));
3833 3664
3834 // Reloading extensions should find our externally registered extension 3665 // Reloading extensions should find our externally registered extension
3835 // and install it. 3666 // and install it.
3836 content::WindowedNotificationObserver observer( 3667 content::WindowedNotificationObserver observer(
3837 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 3668 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
3838 content::NotificationService::AllSources()); 3669 content::NotificationService::AllSources());
3839 service_->CheckForExternalUpdates(); 3670 service()->CheckForExternalUpdates();
3840 observer.Wait(); 3671 observer.Wait();
3841 3672
3842 // Extension should be installed despite blacklist. 3673 // Extension should be installed despite blacklist.
3843 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3674 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3844 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3675 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3845 3676
3846 // Blacklist update should not uninstall the extension. 3677 // Blacklist update should not uninstall the extension.
3847 { 3678 {
3848 ListPrefUpdate update(profile_->GetPrefs(), 3679 ListPrefUpdate update(profile()->GetPrefs(),
3849 extensions::pref_names::kInstallDenyList); 3680 extensions::pref_names::kInstallDenyList);
3850 base::ListValue* blacklist = update.Get(); 3681 base::ListValue* blacklist = update.Get();
3851 blacklist->Append(new base::StringValue(good0)); 3682 blacklist->Append(new base::StringValue(good0));
3852 } 3683 }
3853 base::RunLoop().RunUntilIdle(); 3684 base::RunLoop().RunUntilIdle();
3854 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3685 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3855 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3686 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3856 } 3687 }
3857 3688
3858 // Tests that extensions cannot be installed if the policy provider prohibits 3689 // Tests that extensions cannot be installed if the policy provider prohibits
3859 // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). 3690 // it. This functionality is implemented in CrxInstaller::ConfirmInstall().
3860 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) { 3691 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) {
3861 InitializeEmptyExtensionService(); 3692 InitializeEmptyExtensionService();
3862 3693
3863 management_policy_->UnregisterAllProviders(); 3694 GetManagementPolicy()->UnregisterAllProviders();
3864 extensions::TestManagementPolicyProvider provider_( 3695 extensions::TestManagementPolicyProvider provider_(
3865 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); 3696 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
3866 management_policy_->RegisterProvider(&provider_); 3697 GetManagementPolicy()->RegisterProvider(&provider_);
3867 3698
3868 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_FAILED); 3699 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_FAILED);
3869 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3700 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3870 } 3701 }
3871 3702
3872 // Tests that extensions cannot be loaded from prefs if the policy provider 3703 // Tests that extensions cannot be loaded from prefs if the policy provider
3873 // prohibits it. This functionality is implemented in InstalledLoader::Load(). 3704 // prohibits it. This functionality is implemented in InstalledLoader::Load().
3874 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) { 3705 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) {
3875 InitializeEmptyExtensionService(); 3706 InitializeEmptyExtensionService();
3876 3707
3877 // Create a fake extension to be loaded as though it were read from prefs. 3708 // Create a fake extension to be loaded as though it were read from prefs.
3878 base::FilePath path = data_dir_.AppendASCII("management") 3709 base::FilePath path =
3879 .AppendASCII("simple_extension"); 3710 data_dir().AppendASCII("management").AppendASCII("simple_extension");
3880 base::DictionaryValue manifest; 3711 base::DictionaryValue manifest;
3881 manifest.SetString(keys::kName, "simple_extension"); 3712 manifest.SetString(keys::kName, "simple_extension");
3882 manifest.SetString(keys::kVersion, "1"); 3713 manifest.SetString(keys::kVersion, "1");
3883 // UNPACKED is for extensions loaded from a directory. We use it here, even 3714 // UNPACKED is for extensions loaded from a directory. We use it here, even
3884 // though we're testing loading from prefs, so that we don't need to provide 3715 // though we're testing loading from prefs, so that we don't need to provide
3885 // an extension key. 3716 // an extension key.
3886 extensions::ExtensionInfo extension_info( 3717 extensions::ExtensionInfo extension_info(
3887 &manifest, std::string(), path, Manifest::UNPACKED); 3718 &manifest, std::string(), path, Manifest::UNPACKED);
3888 3719
3889 // Ensure we can load it with no management policy in place. 3720 // Ensure we can load it with no management policy in place.
3890 management_policy_->UnregisterAllProviders(); 3721 GetManagementPolicy()->UnregisterAllProviders();
3891 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3722 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3892 extensions::InstalledLoader(service_).Load(extension_info, false); 3723 extensions::InstalledLoader(service()).Load(extension_info, false);
3893 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3724 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3894 3725
3895 const Extension* extension = (registry_->enabled_extensions().begin())->get(); 3726 const Extension* extension =
3896 EXPECT_TRUE(service_->UninstallExtension(extension->id(), false, NULL)); 3727 (registry()->enabled_extensions().begin())->get();
3897 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3728 EXPECT_TRUE(service()->UninstallExtension(extension->id(), false, NULL));
3729 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3898 3730
3899 // Ensure we cannot load it if management policy prohibits installation. 3731 // Ensure we cannot load it if management policy prohibits installation.
3900 extensions::TestManagementPolicyProvider provider_( 3732 extensions::TestManagementPolicyProvider provider_(
3901 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); 3733 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
3902 management_policy_->RegisterProvider(&provider_); 3734 GetManagementPolicy()->RegisterProvider(&provider_);
3903 3735
3904 extensions::InstalledLoader(service_).Load(extension_info, false); 3736 extensions::InstalledLoader(service()).Load(extension_info, false);
3905 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3737 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3906 } 3738 }
3907 3739
3908 // Tests disabling an extension when prohibited by the ManagementPolicy. 3740 // Tests disabling an extension when prohibited by the ManagementPolicy.
3909 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) { 3741 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) {
3910 InitializeEmptyExtensionService(); 3742 InitializeEmptyExtensionService();
3911 3743
3912 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3744 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3913 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3745 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3914 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3746 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3915 3747
3916 management_policy_->UnregisterAllProviders(); 3748 GetManagementPolicy()->UnregisterAllProviders();
3917 extensions::TestManagementPolicyProvider provider( 3749 extensions::TestManagementPolicyProvider provider(
3918 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); 3750 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
3919 management_policy_->RegisterProvider(&provider); 3751 GetManagementPolicy()->RegisterProvider(&provider);
3920 3752
3921 // Attempt to disable it. 3753 // Attempt to disable it.
3922 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); 3754 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
3923 3755
3924 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3756 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3925 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3757 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3926 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3758 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3927 } 3759 }
3928 3760
3929 // Tests uninstalling an extension when prohibited by the ManagementPolicy. 3761 // Tests uninstalling an extension when prohibited by the ManagementPolicy.
3930 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) { 3762 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) {
3931 InitializeEmptyExtensionService(); 3763 InitializeEmptyExtensionService();
3932 3764
3933 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3765 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3934 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3766 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3935 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3767 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3936 3768
3937 management_policy_->UnregisterAllProviders(); 3769 GetManagementPolicy()->UnregisterAllProviders();
3938 extensions::TestManagementPolicyProvider provider( 3770 extensions::TestManagementPolicyProvider provider(
3939 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); 3771 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
3940 management_policy_->RegisterProvider(&provider); 3772 GetManagementPolicy()->RegisterProvider(&provider);
3941 3773
3942 // Attempt to uninstall it. 3774 // Attempt to uninstall it.
3943 EXPECT_FALSE(service_->UninstallExtension(good_crx, false, NULL)); 3775 EXPECT_FALSE(service()->UninstallExtension(good_crx, false, NULL));
3944 3776
3945 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3777 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3946 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3778 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3947 } 3779 }
3948 3780
3949 // Tests that previously installed extensions that are now prohibited from 3781 // Tests that previously installed extensions that are now prohibited from
3950 // being installed are removed. 3782 // being installed are removed.
3951 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { 3783 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) {
3952 InitializeEmptyExtensionService(); 3784 InitializeEmptyExtensionService();
3953 3785
3954 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3786 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3955 InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW); 3787 InstallCRX(data_dir().AppendASCII("page_action.crx"), INSTALL_NEW);
3956 EXPECT_EQ(2u, registry_->enabled_extensions().size()); 3788 EXPECT_EQ(2u, registry()->enabled_extensions().size());
3957 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3789 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3958 3790
3959 management_policy_->UnregisterAllProviders(); 3791 GetManagementPolicy()->UnregisterAllProviders();
3960 extensions::TestManagementPolicyProvider provider( 3792 extensions::TestManagementPolicyProvider provider(
3961 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); 3793 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
3962 management_policy_->RegisterProvider(&provider); 3794 GetManagementPolicy()->RegisterProvider(&provider);
3963 3795
3964 // Run the policy check. 3796 // Run the policy check.
3965 service_->CheckManagementPolicy(); 3797 service()->CheckManagementPolicy();
3966 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3798 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3967 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3799 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3968 } 3800 }
3969 3801
3970 // Tests that previously disabled extensions that are now required to be 3802 // Tests that previously disabled extensions that are now required to be
3971 // enabled are re-enabled on reinstall. 3803 // enabled are re-enabled on reinstall.
3972 TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) { 3804 TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) {
3973 InitializeEmptyExtensionService(); 3805 InitializeEmptyExtensionService();
3974 3806
3975 // Install, then disable, an extension. 3807 // Install, then disable, an extension.
3976 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3808 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3977 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3809 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3978 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); 3810 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
3979 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 3811 EXPECT_EQ(1u, registry()->disabled_extensions().size());
3980 3812
3981 // Register an ExtensionMnagementPolicy that requires the extension to remain 3813 // Register an ExtensionMnagementPolicy that requires the extension to remain
3982 // enabled. 3814 // enabled.
3983 management_policy_->UnregisterAllProviders(); 3815 GetManagementPolicy()->UnregisterAllProviders();
3984 extensions::TestManagementPolicyProvider provider( 3816 extensions::TestManagementPolicyProvider provider(
3985 extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED); 3817 extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED);
3986 management_policy_->RegisterProvider(&provider); 3818 GetManagementPolicy()->RegisterProvider(&provider);
3987 3819
3988 // Reinstall the extension. 3820 // Reinstall the extension.
3989 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_UPDATED); 3821 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_UPDATED);
3990 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3822 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3991 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3823 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3992 } 3824 }
3993 3825
3994 // Flaky on windows; http://crbug.com/309833 3826 // Flaky on windows; http://crbug.com/309833
3995 #if defined(OS_WIN) 3827 #if defined(OS_WIN)
3996 #define MAYBE_ExternalExtensionAutoAcknowledgement DISABLED_ExternalExtensionAut oAcknowledgement 3828 #define MAYBE_ExternalExtensionAutoAcknowledgement DISABLED_ExternalExtensionAut oAcknowledgement
3997 #else 3829 #else
3998 #define MAYBE_ExternalExtensionAutoAcknowledgement ExternalExtensionAutoAcknowle dgement 3830 #define MAYBE_ExternalExtensionAutoAcknowledgement ExternalExtensionAutoAcknowle dgement
3999 #endif 3831 #endif
4000 TEST_F(ExtensionServiceTest, MAYBE_ExternalExtensionAutoAcknowledgement) { 3832 TEST_F(ExtensionServiceTest, MAYBE_ExternalExtensionAutoAcknowledgement) {
4001 InitializeEmptyExtensionService(); 3833 InitializeEmptyExtensionService();
4002 set_extensions_enabled(true); 3834 service()->set_extensions_enabled(true);
4003 3835
4004 { 3836 {
4005 // Register and install an external extension. 3837 // Register and install an external extension.
4006 MockExtensionProvider* provider = 3838 MockExtensionProvider* provider =
4007 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 3839 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
4008 AddMockExternalProvider(provider); 3840 AddMockExternalProvider(provider);
4009 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 3841 provider->UpdateOrAddExtension(
4010 data_dir_.AppendASCII("good.crx")); 3842 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx"));
4011 } 3843 }
4012 { 3844 {
4013 // Have policy force-install an extension. 3845 // Have policy force-install an extension.
4014 MockExtensionProvider* provider = 3846 MockExtensionProvider* provider = new MockExtensionProvider(
4015 new MockExtensionProvider(service_, 3847 service(), Manifest::EXTERNAL_POLICY_DOWNLOAD);
4016 Manifest::EXTERNAL_POLICY_DOWNLOAD);
4017 AddMockExternalProvider(provider); 3848 AddMockExternalProvider(provider);
4018 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 3849 provider->UpdateOrAddExtension(
4019 data_dir_.AppendASCII("page_action.crx")); 3850 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
4020 } 3851 }
4021 3852
4022 // Providers are set up. Let them run. 3853 // Providers are set up. Let them run.
4023 int count = 2; 3854 int count = 2;
4024 content::WindowedNotificationObserver observer( 3855 content::WindowedNotificationObserver observer(
4025 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 3856 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4026 base::Bind(&WaitForCountNotificationsCallback, &count)); 3857 base::Bind(&WaitForCountNotificationsCallback, &count));
4027 service_->CheckForExternalUpdates(); 3858 service()->CheckForExternalUpdates();
4028 3859
4029 observer.Wait(); 3860 observer.Wait();
4030 3861
4031 ASSERT_EQ(2u, registry_->enabled_extensions().size()); 3862 ASSERT_EQ(2u, registry()->enabled_extensions().size());
4032 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3863 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
4033 EXPECT_TRUE(service_->GetExtensionById(page_action, false)); 3864 EXPECT_TRUE(service()->GetExtensionById(page_action, false));
4034 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 3865 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
4035 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); 3866 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx));
4036 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); 3867 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action));
4037 } 3868 }
4038 3869
4039 #if !defined(OS_CHROMEOS) 3870 #if !defined(OS_CHROMEOS)
4040 // This tests if default apps are installed correctly. 3871 // This tests if default apps are installed correctly.
4041 TEST_F(ExtensionServiceTest, DefaultAppsInstall) { 3872 TEST_F(ExtensionServiceTest, DefaultAppsInstall) {
4042 InitializeEmptyExtensionService(); 3873 InitializeEmptyExtensionService();
4043 set_extensions_enabled(true); 3874 service()->set_extensions_enabled(true);
4044 3875
4045 { 3876 {
4046 std::string json_data = 3877 std::string json_data =
4047 "{" 3878 "{"
4048 " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {" 3879 " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {"
4049 " \"external_crx\": \"good.crx\"," 3880 " \"external_crx\": \"good.crx\","
4050 " \"external_version\": \"1.0.0.0\"," 3881 " \"external_version\": \"1.0.0.0\","
4051 " \"is_bookmark_app\": false" 3882 " \"is_bookmark_app\": false"
4052 " }" 3883 " }"
4053 "}"; 3884 "}";
4054 default_apps::Provider* provider = 3885 default_apps::Provider* provider = new default_apps::Provider(
4055 new default_apps::Provider( 3886 profile(),
4056 profile_.get(), 3887 service(),
4057 service_, 3888 new extensions::ExternalTestingLoader(json_data, data_dir()),
4058 new extensions::ExternalTestingLoader(json_data, data_dir_), 3889 Manifest::INTERNAL,
4059 Manifest::INTERNAL, 3890 Manifest::INVALID_LOCATION,
4060 Manifest::INVALID_LOCATION, 3891 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT);
4061 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT);
4062 3892
4063 AddMockExternalProvider(provider); 3893 AddMockExternalProvider(provider);
4064 } 3894 }
4065 3895
4066 ASSERT_EQ(0u, registry_->enabled_extensions().size()); 3896 ASSERT_EQ(0u, registry()->enabled_extensions().size());
4067 content::WindowedNotificationObserver observer( 3897 content::WindowedNotificationObserver observer(
4068 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 3898 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4069 content::NotificationService::AllSources()); 3899 content::NotificationService::AllSources());
4070 service_->CheckForExternalUpdates(); 3900 service()->CheckForExternalUpdates();
4071 observer.Wait(); 3901 observer.Wait();
4072 3902
4073 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3903 ASSERT_EQ(1u, registry()->enabled_extensions().size());
4074 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3904 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
4075 const Extension* extension = service_->GetExtensionById(good_crx, false); 3905 const Extension* extension = service()->GetExtensionById(good_crx, false);
4076 EXPECT_TRUE(extension->from_webstore()); 3906 EXPECT_TRUE(extension->from_webstore());
4077 EXPECT_TRUE(extension->was_installed_by_default()); 3907 EXPECT_TRUE(extension->was_installed_by_default());
4078 } 3908 }
4079 #endif 3909 #endif
4080 3910
4081 // Tests disabling extensions 3911 // Tests disabling extensions
4082 TEST_F(ExtensionServiceTest, DisableExtension) { 3912 TEST_F(ExtensionServiceTest, DisableExtension) {
4083 InitializeEmptyExtensionService(); 3913 InitializeEmptyExtensionService();
4084 3914
4085 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3915 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4086 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 3916 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
4087 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3917 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
4088 3918
4089 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3919 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4090 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3920 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4091 EXPECT_EQ(0u, registry_->terminated_extensions().size()); 3921 EXPECT_EQ(0u, registry()->terminated_extensions().size());
4092 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 3922 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
4093 3923
4094 // Disable it. 3924 // Disable it.
4095 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); 3925 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
4096 3926
4097 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 3927 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
4098 EXPECT_FALSE(service_->GetExtensionById(good_crx, false)); 3928 EXPECT_FALSE(service()->GetExtensionById(good_crx, false));
4099 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3929 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4100 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 3930 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4101 EXPECT_EQ(0u, registry_->terminated_extensions().size()); 3931 EXPECT_EQ(0u, registry()->terminated_extensions().size());
4102 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 3932 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
4103 } 3933 }
4104 3934
4105 TEST_F(ExtensionServiceTest, TerminateExtension) { 3935 TEST_F(ExtensionServiceTest, TerminateExtension) {
4106 InitializeEmptyExtensionService(); 3936 InitializeEmptyExtensionService();
4107 3937
4108 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3938 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4109 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3939 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4110 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3940 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4111 EXPECT_EQ(0u, registry_->terminated_extensions().size()); 3941 EXPECT_EQ(0u, registry()->terminated_extensions().size());
4112 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 3942 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
4113 3943
4114 TerminateExtension(good_crx); 3944 TerminateExtension(good_crx);
4115 3945
4116 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3946 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4117 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3947 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4118 EXPECT_EQ(1u, registry_->terminated_extensions().size()); 3948 EXPECT_EQ(1u, registry()->terminated_extensions().size());
4119 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 3949 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
4120 } 3950 }
4121 3951
4122 TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { 3952 TEST_F(ExtensionServiceTest, DisableTerminatedExtension) {
4123 InitializeEmptyExtensionService(); 3953 InitializeEmptyExtensionService();
4124 3954
4125 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3955 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4126 TerminateExtension(good_crx); 3956 TerminateExtension(good_crx);
4127 EXPECT_TRUE(registry_->GetExtensionById( 3957 EXPECT_TRUE(registry()->GetExtensionById(
4128 good_crx, extensions::ExtensionRegistry::TERMINATED)); 3958 good_crx, extensions::ExtensionRegistry::TERMINATED));
4129 3959
4130 // Disable it. 3960 // Disable it.
4131 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); 3961 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
4132 3962
4133 EXPECT_FALSE(registry_->GetExtensionById( 3963 EXPECT_FALSE(registry()->GetExtensionById(
4134 good_crx, extensions::ExtensionRegistry::TERMINATED)); 3964 good_crx, extensions::ExtensionRegistry::TERMINATED));
4135 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 3965 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
4136 3966
4137 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3967 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4138 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 3968 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4139 EXPECT_EQ(0u, registry_->terminated_extensions().size()); 3969 EXPECT_EQ(0u, registry()->terminated_extensions().size());
4140 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 3970 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
4141 } 3971 }
4142 3972
4143 // Tests disabling all extensions (simulating --disable-extensions flag). 3973 // Tests disabling all extensions (simulating --disable-extensions flag).
4144 TEST_F(ExtensionServiceTest, DisableAllExtensions) { 3974 TEST_F(ExtensionServiceTest, DisableAllExtensions) {
4145 InitializeEmptyExtensionService(); 3975 InitializeEmptyExtensionService();
4146 3976
4147 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3977 base::FilePath path = data_dir().AppendASCII("good.crx");
4148 InstallCRX(path, INSTALL_NEW); 3978 InstallCRX(path, INSTALL_NEW);
4149 3979
4150 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3980 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4151 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3981 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4152 3982
4153 // Disable extensions. 3983 // Disable extensions.
4154 service_->set_extensions_enabled(false); 3984 service()->set_extensions_enabled(false);
4155 service_->ReloadExtensionsForTest(); 3985 service()->ReloadExtensionsForTest();
4156 3986
4157 // There shouldn't be extensions in either list. 3987 // There shouldn't be extensions in either list.
4158 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3988 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4159 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3989 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4160 3990
4161 // This shouldn't do anything when all extensions are disabled. 3991 // This shouldn't do anything when all extensions are disabled.
4162 service_->EnableExtension(good_crx); 3992 service()->EnableExtension(good_crx);
4163 service_->ReloadExtensionsForTest(); 3993 service()->ReloadExtensionsForTest();
4164 3994
4165 // There still shouldn't be extensions in either list. 3995 // There still shouldn't be extensions in either list.
4166 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3996 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4167 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3997 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4168 3998
4169 // And then re-enable the extensions. 3999 // And then re-enable the extensions.
4170 service_->set_extensions_enabled(true); 4000 service()->set_extensions_enabled(true);
4171 service_->ReloadExtensionsForTest(); 4001 service()->ReloadExtensionsForTest();
4172 4002
4173 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4003 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4174 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 4004 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4175 } 4005 }
4176 4006
4177 // Tests reloading extensions. 4007 // Tests reloading extensions.
4178 TEST_F(ExtensionServiceTest, ReloadExtensions) { 4008 TEST_F(ExtensionServiceTest, ReloadExtensions) {
4179 InitializeEmptyExtensionService(); 4009 InitializeEmptyExtensionService();
4180 4010
4181 // Simple extension that should install without error. 4011 // Simple extension that should install without error.
4182 base::FilePath path = data_dir_.AppendASCII("good.crx"); 4012 base::FilePath path = data_dir().AppendASCII("good.crx");
4183 InstallCRX(path, INSTALL_NEW, 4013 InstallCRX(path, INSTALL_NEW,
4184 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); 4014 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT);
4185 const char* extension_id = good_crx; 4015 const char* extension_id = good_crx;
4186 service_->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); 4016 service()->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION);
4187 4017
4188 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4018 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4189 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 4019 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4190 4020
4191 service_->ReloadExtensionsForTest(); 4021 service()->ReloadExtensionsForTest();
4192 4022
4193 // The creation flags should not change when reloading the extension. 4023 // The creation flags should not change when reloading the extension.
4194 const Extension* extension = service_->GetExtensionById(good_crx, true); 4024 const Extension* extension = service()->GetExtensionById(good_crx, true);
4195 EXPECT_TRUE(extension->from_webstore()); 4025 EXPECT_TRUE(extension->from_webstore());
4196 EXPECT_TRUE(extension->was_installed_by_default()); 4026 EXPECT_TRUE(extension->was_installed_by_default());
4197 EXPECT_FALSE(extension->from_bookmark()); 4027 EXPECT_FALSE(extension->from_bookmark());
4198 4028
4199 // Extension counts shouldn't change. 4029 // Extension counts shouldn't change.
4200 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4030 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4201 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 4031 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4202 4032
4203 service_->EnableExtension(extension_id); 4033 service()->EnableExtension(extension_id);
4204 4034
4205 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4035 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4206 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 4036 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4207 4037
4208 // Need to clear |loaded_| manually before reloading as the 4038 // Need to clear |loaded_| manually before reloading as the
4209 // EnableExtension() call above inserted into it and 4039 // EnableExtension() call above inserted into it and
4210 // UnloadAllExtensions() doesn't send out notifications. 4040 // UnloadAllExtensions() doesn't send out notifications.
4211 loaded_.clear(); 4041 loaded_.clear();
4212 service_->ReloadExtensionsForTest(); 4042 service()->ReloadExtensionsForTest();
4213 4043
4214 // Extension counts shouldn't change. 4044 // Extension counts shouldn't change.
4215 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4045 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4216 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 4046 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4217 } 4047 }
4218 4048
4219 // Tests reloading an extension. 4049 // Tests reloading an extension.
4220 TEST_F(ExtensionServiceTest, ReloadExtension) { 4050 TEST_F(ExtensionServiceTest, ReloadExtension) {
4221 InitializeEmptyExtensionService(); 4051 InitializeEmptyExtensionService();
4222 InitializeProcessManager(); 4052 InitializeProcessManager();
4223 4053
4224 // Simple extension that should install without error. 4054 // Simple extension that should install without error.
4225 const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj"; 4055 const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj";
4226 base::FilePath ext = data_dir_ 4056 base::FilePath ext = data_dir()
4227 .AppendASCII("good") 4057 .AppendASCII("good")
4228 .AppendASCII("Extensions") 4058 .AppendASCII("Extensions")
4229 .AppendASCII(extension_id) 4059 .AppendASCII(extension_id)
4230 .AppendASCII("1.0.0.0"); 4060 .AppendASCII("1.0.0.0");
4231 extensions::UnpackedInstaller::Create(service_)->Load(ext); 4061 extensions::UnpackedInstaller::Create(service())->Load(ext);
4232 base::RunLoop().RunUntilIdle(); 4062 base::RunLoop().RunUntilIdle();
4233 4063
4234 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4064 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4235 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 4065 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4236 4066
4237 service_->ReloadExtension(extension_id); 4067 service()->ReloadExtension(extension_id);
4238 4068
4239 // Extension should be disabled now, waiting to be reloaded. 4069 // Extension should be disabled now, waiting to be reloaded.
4240 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4070 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4241 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 4071 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4242 EXPECT_EQ( 4072 EXPECT_EQ(Extension::DISABLE_RELOAD,
4243 Extension::DISABLE_RELOAD, 4073 ExtensionPrefs::Get(profile())->GetDisableReasons(extension_id));
4244 ExtensionPrefs::Get(profile_.get())->GetDisableReasons(extension_id));
4245 4074
4246 // Reloading again should not crash. 4075 // Reloading again should not crash.
4247 service_->ReloadExtension(extension_id); 4076 service()->ReloadExtension(extension_id);
4248 4077
4249 // Finish reloading 4078 // Finish reloading
4250 base::RunLoop().RunUntilIdle(); 4079 base::RunLoop().RunUntilIdle();
4251 4080
4252 // Extension should be enabled again. 4081 // Extension should be enabled again.
4253 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4082 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4254 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 4083 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4255 } 4084 }
4256 4085
4257 TEST_F(ExtensionServiceTest, UninstallExtension) { 4086 TEST_F(ExtensionServiceTest, UninstallExtension) {
4258 InitializeEmptyExtensionService(); 4087 InitializeEmptyExtensionService();
4259 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4088 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4260 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4089 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4261 UninstallExtension(good_crx, false); 4090 UninstallExtension(good_crx, false);
4262 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4091 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4263 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_); 4092 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_);
4264 } 4093 }
4265 4094
4266 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { 4095 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) {
4267 InitializeEmptyExtensionService(); 4096 InitializeEmptyExtensionService();
4268 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4097 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4269 TerminateExtension(good_crx); 4098 TerminateExtension(good_crx);
4270 UninstallExtension(good_crx, false); 4099 UninstallExtension(good_crx, false);
4271 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_); 4100 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_);
4272 } 4101 }
4273 4102
4274 // Tests the uninstaller helper. 4103 // Tests the uninstaller helper.
4275 TEST_F(ExtensionServiceTest, UninstallExtensionHelper) { 4104 TEST_F(ExtensionServiceTest, UninstallExtensionHelper) {
4276 InitializeEmptyExtensionService(); 4105 InitializeEmptyExtensionService();
4277 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4106 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4278 UninstallExtension(good_crx, true); 4107 UninstallExtension(good_crx, true);
4279 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_); 4108 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_);
4280 } 4109 }
4281 4110
4282 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { 4111 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) {
4283 InitializeEmptyExtensionService(); 4112 InitializeEmptyExtensionService();
4284 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4113 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4285 TerminateExtension(good_crx); 4114 TerminateExtension(good_crx);
4286 UninstallExtension(good_crx, true); 4115 UninstallExtension(good_crx, true);
4287 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_); 4116 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_);
4288 } 4117 }
4289 4118
4290 // An extension disabled because of unsupported requirements should re-enabled 4119 // An extension disabled because of unsupported requirements should re-enabled
4291 // if updated to a version with supported requirements as long as there are no 4120 // if updated to a version with supported requirements as long as there are no
4292 // other disable reasons. 4121 // other disable reasons.
4293 TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) { 4122 TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) {
4294 InitializeEmptyExtensionService(); 4123 InitializeEmptyExtensionService();
4295 BlackListWebGL(); 4124 BlackListWebGL();
4296 4125
4297 base::FilePath path = data_dir_.AppendASCII("requirements"); 4126 base::FilePath path = data_dir().AppendASCII("requirements");
4298 base::FilePath pem_path = data_dir_.AppendASCII("requirements") 4127 base::FilePath pem_path =
4299 .AppendASCII("v1_good.pem"); 4128 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem");
4300 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), 4129 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"),
4301 pem_path, 4130 pem_path,
4302 INSTALL_NEW); 4131 INSTALL_NEW);
4303 std::string id = extension_v1->id(); 4132 std::string id = extension_v1->id();
4304 EXPECT_TRUE(service_->IsExtensionEnabled(id)); 4133 EXPECT_TRUE(service()->IsExtensionEnabled(id));
4305 4134
4306 base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); 4135 base::FilePath v2_bad_requirements_crx = GetTemporaryFile();
4307 4136
4308 PackCRX(path.AppendASCII("v2_bad_requirements"), 4137 PackCRX(path.AppendASCII("v2_bad_requirements"),
4309 pem_path, 4138 pem_path,
4310 v2_bad_requirements_crx); 4139 v2_bad_requirements_crx);
4311 UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); 4140 UpdateExtension(id, v2_bad_requirements_crx, INSTALLED);
4312 EXPECT_FALSE(service_->IsExtensionEnabled(id)); 4141 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4313 4142
4314 base::FilePath v3_good_crx = GetTemporaryFile(); 4143 base::FilePath v3_good_crx = GetTemporaryFile();
4315 4144
4316 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); 4145 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx);
4317 UpdateExtension(id, v3_good_crx, ENABLED); 4146 UpdateExtension(id, v3_good_crx, ENABLED);
4318 EXPECT_TRUE(service_->IsExtensionEnabled(id)); 4147 EXPECT_TRUE(service()->IsExtensionEnabled(id));
4319 } 4148 }
4320 4149
4321 // Extensions disabled through user action should stay disabled. 4150 // Extensions disabled through user action should stay disabled.
4322 TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) { 4151 TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) {
4323 InitializeEmptyExtensionService(); 4152 InitializeEmptyExtensionService();
4324 BlackListWebGL(); 4153 BlackListWebGL();
4325 4154
4326 base::FilePath path = data_dir_.AppendASCII("requirements"); 4155 base::FilePath path = data_dir().AppendASCII("requirements");
4327 base::FilePath pem_path = data_dir_.AppendASCII("requirements") 4156 base::FilePath pem_path =
4328 .AppendASCII("v1_good.pem"); 4157 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem");
4329 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), 4158 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"),
4330 pem_path, 4159 pem_path,
4331 INSTALL_NEW); 4160 INSTALL_NEW);
4332 std::string id = extension_v1->id(); 4161 std::string id = extension_v1->id();
4333 service_->DisableExtension(id, Extension::DISABLE_USER_ACTION); 4162 service()->DisableExtension(id, Extension::DISABLE_USER_ACTION);
4334 EXPECT_FALSE(service_->IsExtensionEnabled(id)); 4163 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4335 4164
4336 base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); 4165 base::FilePath v2_bad_requirements_crx = GetTemporaryFile();
4337 4166
4338 PackCRX(path.AppendASCII("v2_bad_requirements"), 4167 PackCRX(path.AppendASCII("v2_bad_requirements"),
4339 pem_path, 4168 pem_path,
4340 v2_bad_requirements_crx); 4169 v2_bad_requirements_crx);
4341 UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); 4170 UpdateExtension(id, v2_bad_requirements_crx, INSTALLED);
4342 EXPECT_FALSE(service_->IsExtensionEnabled(id)); 4171 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4343 4172
4344 base::FilePath v3_good_crx = GetTemporaryFile(); 4173 base::FilePath v3_good_crx = GetTemporaryFile();
4345 4174
4346 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); 4175 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx);
4347 UpdateExtension(id, v3_good_crx, INSTALLED); 4176 UpdateExtension(id, v3_good_crx, INSTALLED);
4348 EXPECT_FALSE(service_->IsExtensionEnabled(id)); 4177 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4349 } 4178 }
4350 4179
4351 // The extension should not re-enabled because it was disabled from a 4180 // The extension should not re-enabled because it was disabled from a
4352 // permission increase. 4181 // permission increase.
4353 TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) { 4182 TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) {
4354 InitializeEmptyExtensionService(); 4183 InitializeEmptyExtensionService();
4355 BlackListWebGL(); 4184 BlackListWebGL();
4356 4185
4357 base::FilePath path = data_dir_.AppendASCII("requirements"); 4186 base::FilePath path = data_dir().AppendASCII("requirements");
4358 base::FilePath pem_path = data_dir_.AppendASCII("requirements") 4187 base::FilePath pem_path =
4359 .AppendASCII("v1_good.pem"); 4188 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem");
4360 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), 4189 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"),
4361 pem_path, 4190 pem_path,
4362 INSTALL_NEW); 4191 INSTALL_NEW);
4363 std::string id = extension_v1->id(); 4192 std::string id = extension_v1->id();
4364 EXPECT_TRUE(service_->IsExtensionEnabled(id)); 4193 EXPECT_TRUE(service()->IsExtensionEnabled(id));
4365 4194
4366 base::FilePath v2_bad_requirements_and_permissions_crx = GetTemporaryFile(); 4195 base::FilePath v2_bad_requirements_and_permissions_crx = GetTemporaryFile();
4367 4196
4368 PackCRX(path.AppendASCII("v2_bad_requirements_and_permissions"), 4197 PackCRX(path.AppendASCII("v2_bad_requirements_and_permissions"),
4369 pem_path, 4198 pem_path,
4370 v2_bad_requirements_and_permissions_crx); 4199 v2_bad_requirements_and_permissions_crx);
4371 UpdateExtension(id, v2_bad_requirements_and_permissions_crx, INSTALLED); 4200 UpdateExtension(id, v2_bad_requirements_and_permissions_crx, INSTALLED);
4372 EXPECT_FALSE(service_->IsExtensionEnabled(id)); 4201 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4373 4202
4374 base::FilePath v3_bad_permissions_crx = GetTemporaryFile(); 4203 base::FilePath v3_bad_permissions_crx = GetTemporaryFile();
4375 4204
4376 PackCRX(path.AppendASCII("v3_bad_permissions"), 4205 PackCRX(path.AppendASCII("v3_bad_permissions"),
4377 pem_path, 4206 pem_path,
4378 v3_bad_permissions_crx); 4207 v3_bad_permissions_crx);
4379 UpdateExtension(id, v3_bad_permissions_crx, INSTALLED); 4208 UpdateExtension(id, v3_bad_permissions_crx, INSTALLED);
4380 EXPECT_FALSE(service_->IsExtensionEnabled(id)); 4209 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4381 } 4210 }
4382 4211
4383 // Unpacked extensions are not allowed to be installed if they have unsupported 4212 // Unpacked extensions are not allowed to be installed if they have unsupported
4384 // requirements. 4213 // requirements.
4385 TEST_F(ExtensionServiceTest, UnpackedRequirements) { 4214 TEST_F(ExtensionServiceTest, UnpackedRequirements) {
4386 InitializeEmptyExtensionService(); 4215 InitializeEmptyExtensionService();
4387 BlackListWebGL(); 4216 BlackListWebGL();
4388 4217
4389 base::FilePath path = data_dir_.AppendASCII("requirements") 4218 base::FilePath path =
4390 .AppendASCII("v2_bad_requirements"); 4219 data_dir().AppendASCII("requirements").AppendASCII("v2_bad_requirements");
4391 extensions::UnpackedInstaller::Create(service_)->Load(path); 4220 extensions::UnpackedInstaller::Create(service())->Load(path);
4392 base::RunLoop().RunUntilIdle(); 4221 base::RunLoop().RunUntilIdle();
4393 EXPECT_EQ(1u, GetErrors().size()); 4222 EXPECT_EQ(1u, GetErrors().size());
4394 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4223 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4395 } 4224 }
4396 4225
4397 class ExtensionCookieCallback { 4226 class ExtensionCookieCallback {
4398 public: 4227 public:
4399 ExtensionCookieCallback() 4228 ExtensionCookieCallback()
4400 : result_(false), 4229 : result_(false),
4401 weak_factory_(base::MessageLoop::current()) {} 4230 weak_factory_(base::MessageLoop::current()) {}
4402 4231
4403 void SetCookieCallback(bool result) { 4232 void SetCookieCallback(bool result) {
4404 base::MessageLoop::current()->PostTask(FROM_HERE, 4233 base::MessageLoop::current()->PostTask(FROM_HERE,
(...skipping 10 matching lines...) Expand all
4415 bool result_; 4244 bool result_;
4416 base::WeakPtrFactory<base::MessageLoop> weak_factory_; 4245 base::WeakPtrFactory<base::MessageLoop> weak_factory_;
4417 }; 4246 };
4418 4247
4419 // Verifies extension state is removed upon uninstall. 4248 // Verifies extension state is removed upon uninstall.
4420 TEST_F(ExtensionServiceTest, ClearExtensionData) { 4249 TEST_F(ExtensionServiceTest, ClearExtensionData) {
4421 InitializeEmptyExtensionService(); 4250 InitializeEmptyExtensionService();
4422 ExtensionCookieCallback callback; 4251 ExtensionCookieCallback callback;
4423 4252
4424 // Load a test extension. 4253 // Load a test extension.
4425 base::FilePath path = data_dir_; 4254 base::FilePath path = data_dir();
4426 path = path.AppendASCII("good.crx"); 4255 path = path.AppendASCII("good.crx");
4427 const Extension* extension = InstallCRX(path, INSTALL_NEW); 4256 const Extension* extension = InstallCRX(path, INSTALL_NEW);
4428 ASSERT_TRUE(extension); 4257 ASSERT_TRUE(extension);
4429 GURL ext_url(extension->url()); 4258 GURL ext_url(extension->url());
4430 std::string origin_id = webkit_database::GetIdentifierFromOrigin(ext_url); 4259 std::string origin_id = webkit_database::GetIdentifierFromOrigin(ext_url);
4431 4260
4432 // Set a cookie for the extension. 4261 // Set a cookie for the extension.
4433 net::CookieMonster* cookie_monster = 4262 net::CookieMonster* cookie_monster = profile()
4434 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> 4263 ->GetRequestContextForExtensions()
4435 cookie_store()->GetCookieMonster(); 4264 ->GetURLRequestContext()
4265 ->cookie_store()
4266 ->GetCookieMonster();
4436 ASSERT_TRUE(cookie_monster); 4267 ASSERT_TRUE(cookie_monster);
4437 net::CookieOptions options; 4268 net::CookieOptions options;
4438 cookie_monster->SetCookieWithOptionsAsync( 4269 cookie_monster->SetCookieWithOptionsAsync(
4439 ext_url, "dummy=value", options, 4270 ext_url, "dummy=value", options,
4440 base::Bind(&ExtensionCookieCallback::SetCookieCallback, 4271 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
4441 base::Unretained(&callback))); 4272 base::Unretained(&callback)));
4442 base::RunLoop().RunUntilIdle(); 4273 base::RunLoop().RunUntilIdle();
4443 EXPECT_TRUE(callback.result_); 4274 EXPECT_TRUE(callback.result_);
4444 4275
4445 cookie_monster->GetAllCookiesForURLAsync( 4276 cookie_monster->GetAllCookiesForURLAsync(
4446 ext_url, 4277 ext_url,
4447 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4278 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4448 base::Unretained(&callback))); 4279 base::Unretained(&callback)));
4449 base::RunLoop().RunUntilIdle(); 4280 base::RunLoop().RunUntilIdle();
4450 EXPECT_EQ(1U, callback.list_.size()); 4281 EXPECT_EQ(1U, callback.list_.size());
4451 4282
4452 // Open a database. 4283 // Open a database.
4453 webkit_database::DatabaseTracker* db_tracker = 4284 webkit_database::DatabaseTracker* db_tracker =
4454 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 4285 BrowserContext::GetDefaultStoragePartition(profile())
4455 GetDatabaseTracker(); 4286 ->GetDatabaseTracker();
4456 base::string16 db_name = base::UTF8ToUTF16("db"); 4287 base::string16 db_name = base::UTF8ToUTF16("db");
4457 base::string16 description = base::UTF8ToUTF16("db_description"); 4288 base::string16 description = base::UTF8ToUTF16("db_description");
4458 int64 size; 4289 int64 size;
4459 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); 4290 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size);
4460 db_tracker->DatabaseClosed(origin_id, db_name); 4291 db_tracker->DatabaseClosed(origin_id, db_name);
4461 std::vector<webkit_database::OriginInfo> origins; 4292 std::vector<webkit_database::OriginInfo> origins;
4462 db_tracker->GetAllOriginsInfo(&origins); 4293 db_tracker->GetAllOriginsInfo(&origins);
4463 EXPECT_EQ(1U, origins.size()); 4294 EXPECT_EQ(1U, origins.size());
4464 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); 4295 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier());
4465 4296
4466 // Create local storage. We only simulate this by creating the backing files. 4297 // Create local storage. We only simulate this by creating the backing files.
4467 // Note: This test depends on details of how the dom_storage library 4298 // Note: This test depends on details of how the dom_storage library
4468 // stores data in the host file system. 4299 // stores data in the host file system.
4469 base::FilePath lso_dir_path = 4300 base::FilePath lso_dir_path =
4470 profile_->GetPath().AppendASCII("Local Storage"); 4301 profile()->GetPath().AppendASCII("Local Storage");
4471 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) 4302 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id)
4472 .AddExtension(FILE_PATH_LITERAL(".localstorage")); 4303 .AddExtension(FILE_PATH_LITERAL(".localstorage"));
4473 EXPECT_TRUE(base::CreateDirectory(lso_dir_path)); 4304 EXPECT_TRUE(base::CreateDirectory(lso_dir_path));
4474 EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0)); 4305 EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0));
4475 EXPECT_TRUE(base::PathExists(lso_file_path)); 4306 EXPECT_TRUE(base::PathExists(lso_file_path));
4476 4307
4477 // Create indexed db. Similarly, it is enough to only simulate this by 4308 // Create indexed db. Similarly, it is enough to only simulate this by
4478 // creating the directory on the disk. 4309 // creating the directory on the disk.
4479 IndexedDBContext* idb_context = 4310 IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition(
4480 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 4311 profile())->GetIndexedDBContext();
4481 GetIndexedDBContext();
4482 idb_context->SetTaskRunnerForTesting( 4312 idb_context->SetTaskRunnerForTesting(
4483 base::MessageLoop::current()->message_loop_proxy().get()); 4313 base::MessageLoop::current()->message_loop_proxy().get());
4484 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); 4314 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id);
4485 EXPECT_TRUE(base::CreateDirectory(idb_path)); 4315 EXPECT_TRUE(base::CreateDirectory(idb_path));
4486 EXPECT_TRUE(base::DirectoryExists(idb_path)); 4316 EXPECT_TRUE(base::DirectoryExists(idb_path));
4487 4317
4488 // Uninstall the extension. 4318 // Uninstall the extension.
4489 service_->UninstallExtension(good_crx, false, NULL); 4319 service()->UninstallExtension(good_crx, false, NULL);
4490 base::RunLoop().RunUntilIdle(); 4320 base::RunLoop().RunUntilIdle();
4491 4321
4492 // Check that the cookie is gone. 4322 // Check that the cookie is gone.
4493 cookie_monster->GetAllCookiesForURLAsync( 4323 cookie_monster->GetAllCookiesForURLAsync(
4494 ext_url, 4324 ext_url,
4495 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4325 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4496 base::Unretained(&callback))); 4326 base::Unretained(&callback)));
4497 base::RunLoop().RunUntilIdle(); 4327 base::RunLoop().RunUntilIdle();
4498 EXPECT_EQ(0U, callback.list_.size()); 4328 EXPECT_EQ(0U, callback.list_.size());
4499 4329
(...skipping 11 matching lines...) Expand all
4511 4341
4512 // Verifies app state is removed upon uninstall. 4342 // Verifies app state is removed upon uninstall.
4513 TEST_F(ExtensionServiceTest, ClearAppData) { 4343 TEST_F(ExtensionServiceTest, ClearAppData) {
4514 InitializeEmptyExtensionService(); 4344 InitializeEmptyExtensionService();
4515 ExtensionCookieCallback callback; 4345 ExtensionCookieCallback callback;
4516 4346
4517 int pref_count = 0; 4347 int pref_count = 0;
4518 4348
4519 // Install app1 with unlimited storage. 4349 // Install app1 with unlimited storage.
4520 const Extension* extension = 4350 const Extension* extension =
4521 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 4351 PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
4522 ValidatePrefKeyCount(++pref_count); 4352 ValidatePrefKeyCount(++pref_count);
4523 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 4353 ASSERT_EQ(1u, registry()->enabled_extensions().size());
4524 const std::string id1 = extension->id(); 4354 const std::string id1 = extension->id();
4525 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( 4355 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
4526 APIPermission::kUnlimitedStorage)); 4356 APIPermission::kUnlimitedStorage));
4527 const GURL origin1( 4357 const GURL origin1(
4528 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 4358 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
4529 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 4359 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4530 IsStorageUnlimited(origin1)); 4360 origin1));
4531 std::string origin_id = webkit_database::GetIdentifierFromOrigin(origin1); 4361 std::string origin_id = webkit_database::GetIdentifierFromOrigin(origin1);
4532 4362
4533 // Install app2 from the same origin with unlimited storage. 4363 // Install app2 from the same origin with unlimited storage.
4534 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 4364 extension = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
4535 ValidatePrefKeyCount(++pref_count); 4365 ValidatePrefKeyCount(++pref_count);
4536 ASSERT_EQ(2u, registry_->enabled_extensions().size()); 4366 ASSERT_EQ(2u, registry()->enabled_extensions().size());
4537 const std::string id2 = extension->id(); 4367 const std::string id2 = extension->id();
4538 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( 4368 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
4539 APIPermission::kUnlimitedStorage)); 4369 APIPermission::kUnlimitedStorage));
4540 EXPECT_TRUE(extension->web_extent().MatchesURL( 4370 EXPECT_TRUE(extension->web_extent().MatchesURL(
4541 extensions::AppLaunchInfo::GetFullLaunchURL(extension))); 4371 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
4542 const GURL origin2( 4372 const GURL origin2(
4543 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 4373 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
4544 EXPECT_EQ(origin1, origin2); 4374 EXPECT_EQ(origin1, origin2);
4545 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 4375 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4546 IsStorageUnlimited(origin2)); 4376 origin2));
4547 4377
4548 // Set a cookie for the extension. 4378 // Set a cookie for the extension.
4549 net::CookieMonster* cookie_monster = 4379 net::CookieMonster* cookie_monster = profile()
4550 profile_->GetRequestContext()->GetURLRequestContext()-> 4380 ->GetRequestContext()
4551 cookie_store()->GetCookieMonster(); 4381 ->GetURLRequestContext()
4382 ->cookie_store()
4383 ->GetCookieMonster();
4552 ASSERT_TRUE(cookie_monster); 4384 ASSERT_TRUE(cookie_monster);
4553 net::CookieOptions options; 4385 net::CookieOptions options;
4554 cookie_monster->SetCookieWithOptionsAsync( 4386 cookie_monster->SetCookieWithOptionsAsync(
4555 origin1, "dummy=value", options, 4387 origin1, "dummy=value", options,
4556 base::Bind(&ExtensionCookieCallback::SetCookieCallback, 4388 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
4557 base::Unretained(&callback))); 4389 base::Unretained(&callback)));
4558 base::RunLoop().RunUntilIdle(); 4390 base::RunLoop().RunUntilIdle();
4559 EXPECT_TRUE(callback.result_); 4391 EXPECT_TRUE(callback.result_);
4560 4392
4561 cookie_monster->GetAllCookiesForURLAsync( 4393 cookie_monster->GetAllCookiesForURLAsync(
4562 origin1, 4394 origin1,
4563 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4395 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4564 base::Unretained(&callback))); 4396 base::Unretained(&callback)));
4565 base::RunLoop().RunUntilIdle(); 4397 base::RunLoop().RunUntilIdle();
4566 EXPECT_EQ(1U, callback.list_.size()); 4398 EXPECT_EQ(1U, callback.list_.size());
4567 4399
4568 // Open a database. 4400 // Open a database.
4569 webkit_database::DatabaseTracker* db_tracker = 4401 webkit_database::DatabaseTracker* db_tracker =
4570 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 4402 BrowserContext::GetDefaultStoragePartition(profile())
4571 GetDatabaseTracker(); 4403 ->GetDatabaseTracker();
4572 base::string16 db_name = base::UTF8ToUTF16("db"); 4404 base::string16 db_name = base::UTF8ToUTF16("db");
4573 base::string16 description = base::UTF8ToUTF16("db_description"); 4405 base::string16 description = base::UTF8ToUTF16("db_description");
4574 int64 size; 4406 int64 size;
4575 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); 4407 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size);
4576 db_tracker->DatabaseClosed(origin_id, db_name); 4408 db_tracker->DatabaseClosed(origin_id, db_name);
4577 std::vector<webkit_database::OriginInfo> origins; 4409 std::vector<webkit_database::OriginInfo> origins;
4578 db_tracker->GetAllOriginsInfo(&origins); 4410 db_tracker->GetAllOriginsInfo(&origins);
4579 EXPECT_EQ(1U, origins.size()); 4411 EXPECT_EQ(1U, origins.size());
4580 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); 4412 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier());
4581 4413
4582 // Create local storage. We only simulate this by creating the backing files. 4414 // Create local storage. We only simulate this by creating the backing files.
4583 // Note: This test depends on details of how the dom_storage library 4415 // Note: This test depends on details of how the dom_storage library
4584 // stores data in the host file system. 4416 // stores data in the host file system.
4585 base::FilePath lso_dir_path = 4417 base::FilePath lso_dir_path =
4586 profile_->GetPath().AppendASCII("Local Storage"); 4418 profile()->GetPath().AppendASCII("Local Storage");
4587 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) 4419 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id)
4588 .AddExtension(FILE_PATH_LITERAL(".localstorage")); 4420 .AddExtension(FILE_PATH_LITERAL(".localstorage"));
4589 EXPECT_TRUE(base::CreateDirectory(lso_dir_path)); 4421 EXPECT_TRUE(base::CreateDirectory(lso_dir_path));
4590 EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0)); 4422 EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0));
4591 EXPECT_TRUE(base::PathExists(lso_file_path)); 4423 EXPECT_TRUE(base::PathExists(lso_file_path));
4592 4424
4593 // Create indexed db. Similarly, it is enough to only simulate this by 4425 // Create indexed db. Similarly, it is enough to only simulate this by
4594 // creating the directory on the disk. 4426 // creating the directory on the disk.
4595 IndexedDBContext* idb_context = 4427 IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition(
4596 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 4428 profile())->GetIndexedDBContext();
4597 GetIndexedDBContext();
4598 idb_context->SetTaskRunnerForTesting( 4429 idb_context->SetTaskRunnerForTesting(
4599 base::MessageLoop::current()->message_loop_proxy().get()); 4430 base::MessageLoop::current()->message_loop_proxy().get());
4600 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); 4431 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id);
4601 EXPECT_TRUE(base::CreateDirectory(idb_path)); 4432 EXPECT_TRUE(base::CreateDirectory(idb_path));
4602 EXPECT_TRUE(base::DirectoryExists(idb_path)); 4433 EXPECT_TRUE(base::DirectoryExists(idb_path));
4603 4434
4604 // Uninstall one of them, unlimited storage should still be granted 4435 // Uninstall one of them, unlimited storage should still be granted
4605 // to the origin. 4436 // to the origin.
4606 UninstallExtension(id1, false); 4437 UninstallExtension(id1, false);
4607 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4438 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4608 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 4439 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4609 IsStorageUnlimited(origin1)); 4440 origin1));
4610 4441
4611 // Check that the cookie is still there. 4442 // Check that the cookie is still there.
4612 cookie_monster->GetAllCookiesForURLAsync( 4443 cookie_monster->GetAllCookiesForURLAsync(
4613 origin1, 4444 origin1,
4614 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4445 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4615 base::Unretained(&callback))); 4446 base::Unretained(&callback)));
4616 base::RunLoop().RunUntilIdle(); 4447 base::RunLoop().RunUntilIdle();
4617 EXPECT_EQ(1U, callback.list_.size()); 4448 EXPECT_EQ(1U, callback.list_.size());
4618 4449
4619 // Now uninstall the other. Storage should be cleared for the apps. 4450 // Now uninstall the other. Storage should be cleared for the apps.
4620 UninstallExtension(id2, false); 4451 UninstallExtension(id2, false);
4621 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4452 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4622 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 4453 EXPECT_FALSE(
4623 IsStorageUnlimited(origin1)); 4454 profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4455 origin1));
4624 4456
4625 // Check that the cookie is gone. 4457 // Check that the cookie is gone.
4626 cookie_monster->GetAllCookiesForURLAsync( 4458 cookie_monster->GetAllCookiesForURLAsync(
4627 origin1, 4459 origin1,
4628 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4460 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4629 base::Unretained(&callback))); 4461 base::Unretained(&callback)));
4630 base::RunLoop().RunUntilIdle(); 4462 base::RunLoop().RunUntilIdle();
4631 EXPECT_EQ(0U, callback.list_.size()); 4463 EXPECT_EQ(0U, callback.list_.size());
4632 4464
4633 // The database should have vanished as well. 4465 // The database should have vanished as well.
4634 origins.clear(); 4466 origins.clear();
4635 db_tracker->GetAllOriginsInfo(&origins); 4467 db_tracker->GetAllOriginsInfo(&origins);
4636 EXPECT_EQ(0U, origins.size()); 4468 EXPECT_EQ(0U, origins.size());
4637 4469
4638 // Check that the LSO file has been removed. 4470 // Check that the LSO file has been removed.
4639 EXPECT_FALSE(base::PathExists(lso_file_path)); 4471 EXPECT_FALSE(base::PathExists(lso_file_path));
4640 4472
4641 // Check if the indexed db has disappeared too. 4473 // Check if the indexed db has disappeared too.
4642 EXPECT_FALSE(base::DirectoryExists(idb_path)); 4474 EXPECT_FALSE(base::DirectoryExists(idb_path));
4643 } 4475 }
4644 4476
4645 // Tests loading single extensions (like --load-extension) 4477 // Tests loading single extensions (like --load-extension)
4646 // Flaky crashes. http://crbug.com/231806 4478 // Flaky crashes. http://crbug.com/231806
4647 TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) { 4479 TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) {
4648 InitializeEmptyExtensionService(); 4480 InitializeEmptyExtensionService();
4649 4481
4650 base::FilePath ext1 = data_dir_ 4482 base::FilePath ext1 = data_dir()
4651 .AppendASCII("good") 4483 .AppendASCII("good")
4652 .AppendASCII("Extensions") 4484 .AppendASCII("Extensions")
4653 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 4485 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
4654 .AppendASCII("1.0.0.0"); 4486 .AppendASCII("1.0.0.0");
4655 extensions::UnpackedInstaller::Create(service_)->Load(ext1); 4487 extensions::UnpackedInstaller::Create(service())->Load(ext1);
4656 base::RunLoop().RunUntilIdle(); 4488 base::RunLoop().RunUntilIdle();
4657 EXPECT_EQ(0u, GetErrors().size()); 4489 EXPECT_EQ(0u, GetErrors().size());
4658 ASSERT_EQ(1u, loaded_.size()); 4490 ASSERT_EQ(1u, loaded_.size());
4659 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); 4491 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
4660 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4492 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4661 4493
4662 ValidatePrefKeyCount(1); 4494 ValidatePrefKeyCount(1);
4663 4495
4664 base::FilePath no_manifest = data_dir_ 4496 base::FilePath no_manifest =
4665 .AppendASCII("bad") 4497 data_dir()
4666 // .AppendASCII("Extensions") 4498 .AppendASCII("bad")
4667 .AppendASCII("cccccccccccccccccccccccccccccccc") 4499 // .AppendASCII("Extensions")
4668 .AppendASCII("1"); 4500 .AppendASCII("cccccccccccccccccccccccccccccccc")
4669 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest); 4501 .AppendASCII("1");
4502 extensions::UnpackedInstaller::Create(service())->Load(no_manifest);
4670 base::RunLoop().RunUntilIdle(); 4503 base::RunLoop().RunUntilIdle();
4671 EXPECT_EQ(1u, GetErrors().size()); 4504 EXPECT_EQ(1u, GetErrors().size());
4672 ASSERT_EQ(1u, loaded_.size()); 4505 ASSERT_EQ(1u, loaded_.size());
4673 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4506 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4674 4507
4675 // Test uninstall. 4508 // Test uninstall.
4676 std::string id = loaded_[0]->id(); 4509 std::string id = loaded_[0]->id();
4677 EXPECT_FALSE(unloaded_id_.length()); 4510 EXPECT_FALSE(unloaded_id_.length());
4678 service_->UninstallExtension(id, false, NULL); 4511 service()->UninstallExtension(id, false, NULL);
4679 base::RunLoop().RunUntilIdle(); 4512 base::RunLoop().RunUntilIdle();
4680 EXPECT_EQ(id, unloaded_id_); 4513 EXPECT_EQ(id, unloaded_id_);
4681 ASSERT_EQ(0u, loaded_.size()); 4514 ASSERT_EQ(0u, loaded_.size());
4682 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4515 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4683 } 4516 }
4684 4517
4685 // Tests that we generate IDs when they are not specified in the manifest for 4518 // Tests that we generate IDs when they are not specified in the manifest for
4686 // --load-extension. 4519 // --load-extension.
4687 TEST_F(ExtensionServiceTest, GenerateID) { 4520 TEST_F(ExtensionServiceTest, GenerateID) {
4688 InitializeEmptyExtensionService(); 4521 InitializeEmptyExtensionService();
4689 4522
4690 base::FilePath no_id_ext = data_dir_.AppendASCII("no_id"); 4523 base::FilePath no_id_ext = data_dir().AppendASCII("no_id");
4691 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); 4524 extensions::UnpackedInstaller::Create(service())->Load(no_id_ext);
4692 base::RunLoop().RunUntilIdle(); 4525 base::RunLoop().RunUntilIdle();
4693 EXPECT_EQ(0u, GetErrors().size()); 4526 EXPECT_EQ(0u, GetErrors().size());
4694 ASSERT_EQ(1u, loaded_.size()); 4527 ASSERT_EQ(1u, loaded_.size());
4695 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); 4528 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id()));
4696 EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED); 4529 EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED);
4697 4530
4698 ValidatePrefKeyCount(1); 4531 ValidatePrefKeyCount(1);
4699 4532
4700 std::string previous_id = loaded_[0]->id(); 4533 std::string previous_id = loaded_[0]->id();
4701 4534
4702 // If we reload the same path, we should get the same extension ID. 4535 // If we reload the same path, we should get the same extension ID.
4703 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); 4536 extensions::UnpackedInstaller::Create(service())->Load(no_id_ext);
4704 base::RunLoop().RunUntilIdle(); 4537 base::RunLoop().RunUntilIdle();
4705 ASSERT_EQ(1u, loaded_.size()); 4538 ASSERT_EQ(1u, loaded_.size());
4706 ASSERT_EQ(previous_id, loaded_[0]->id()); 4539 ASSERT_EQ(previous_id, loaded_[0]->id());
4707 } 4540 }
4708 4541
4709 TEST_F(ExtensionServiceTest, UnpackedValidatesLocales) { 4542 TEST_F(ExtensionServiceTest, UnpackedValidatesLocales) {
4710 InitializeEmptyExtensionService(); 4543 InitializeEmptyExtensionService();
4711 4544
4712 base::FilePath bad_locale = data_dir_.AppendASCII("unpacked"). 4545 base::FilePath bad_locale =
4713 AppendASCII("bad_messages_file"); 4546 data_dir().AppendASCII("unpacked").AppendASCII("bad_messages_file");
4714 extensions::UnpackedInstaller::Create(service_)->Load(bad_locale); 4547 extensions::UnpackedInstaller::Create(service())->Load(bad_locale);
4715 base::RunLoop().RunUntilIdle(); 4548 base::RunLoop().RunUntilIdle();
4716 EXPECT_EQ(1u, GetErrors().size()); 4549 EXPECT_EQ(1u, GetErrors().size());
4717 base::FilePath ms_messages_file = bad_locale.AppendASCII("_locales") 4550 base::FilePath ms_messages_file = bad_locale.AppendASCII("_locales")
4718 .AppendASCII("ms") 4551 .AppendASCII("ms")
4719 .AppendASCII("messages.json"); 4552 .AppendASCII("messages.json");
4720 EXPECT_THAT(base::UTF16ToUTF8(GetErrors()[0]), testing::AllOf( 4553 EXPECT_THAT(base::UTF16ToUTF8(GetErrors()[0]), testing::AllOf(
4721 testing::HasSubstr( 4554 testing::HasSubstr(
4722 base::UTF16ToUTF8(ms_messages_file.LossyDisplayName())), 4555 base::UTF16ToUTF8(ms_messages_file.LossyDisplayName())),
4723 testing::HasSubstr("Dictionary keys must be quoted."))); 4556 testing::HasSubstr("Dictionary keys must be quoted.")));
4724 ASSERT_EQ(0u, loaded_.size()); 4557 ASSERT_EQ(0u, loaded_.size());
4725 } 4558 }
4726 4559
4727 void ExtensionServiceTest::TestExternalProvider( 4560 void ExtensionServiceTest::TestExternalProvider(
4728 MockExtensionProvider* provider, Manifest::Location location) { 4561 MockExtensionProvider* provider, Manifest::Location location) {
4729 // Verify that starting with no providers loads no extensions. 4562 // Verify that starting with no providers loads no extensions.
4730 service_->Init(); 4563 service()->Init();
4731 ASSERT_EQ(0u, loaded_.size()); 4564 ASSERT_EQ(0u, loaded_.size());
4732 4565
4733 provider->set_visit_count(0); 4566 provider->set_visit_count(0);
4734 4567
4735 // Register a test extension externally using the mock registry provider. 4568 // Register a test extension externally using the mock registry provider.
4736 base::FilePath source_path = data_dir_.AppendASCII("good.crx"); 4569 base::FilePath source_path = data_dir().AppendASCII("good.crx");
4737 4570
4738 // Add the extension. 4571 // Add the extension.
4739 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4572 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4740 4573
4741 // Reloading extensions should find our externally registered extension 4574 // Reloading extensions should find our externally registered extension
4742 // and install it. 4575 // and install it.
4743 content::WindowedNotificationObserver observer( 4576 content::WindowedNotificationObserver observer(
4744 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4577 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4745 content::NotificationService::AllSources()); 4578 content::NotificationService::AllSources());
4746 service_->CheckForExternalUpdates(); 4579 service()->CheckForExternalUpdates();
4747 observer.Wait(); 4580 observer.Wait();
4748 4581
4749 ASSERT_EQ(0u, GetErrors().size()); 4582 ASSERT_EQ(0u, GetErrors().size());
4750 ASSERT_EQ(1u, loaded_.size()); 4583 ASSERT_EQ(1u, loaded_.size());
4751 ASSERT_EQ(location, loaded_[0]->location()); 4584 ASSERT_EQ(location, loaded_[0]->location());
4752 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4585 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4753 ValidatePrefKeyCount(1); 4586 ValidatePrefKeyCount(1);
4754 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4587 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4755 ValidateIntegerPref(good_crx, "location", location); 4588 ValidateIntegerPref(good_crx, "location", location);
4756 4589
4757 // Reload extensions without changing anything. The extension should be 4590 // Reload extensions without changing anything. The extension should be
4758 // loaded again. 4591 // loaded again.
4759 loaded_.clear(); 4592 loaded_.clear();
4760 service_->ReloadExtensionsForTest(); 4593 service()->ReloadExtensionsForTest();
4761 base::RunLoop().RunUntilIdle(); 4594 base::RunLoop().RunUntilIdle();
4762 ASSERT_EQ(0u, GetErrors().size()); 4595 ASSERT_EQ(0u, GetErrors().size());
4763 ASSERT_EQ(1u, loaded_.size()); 4596 ASSERT_EQ(1u, loaded_.size());
4764 ValidatePrefKeyCount(1); 4597 ValidatePrefKeyCount(1);
4765 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4598 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4766 ValidateIntegerPref(good_crx, "location", location); 4599 ValidateIntegerPref(good_crx, "location", location);
4767 4600
4768 // Now update the extension with a new version. We should get upgraded. 4601 // Now update the extension with a new version. We should get upgraded.
4769 source_path = source_path.DirName().AppendASCII("good2.crx"); 4602 source_path = source_path.DirName().AppendASCII("good2.crx");
4770 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4603 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4771 4604
4772 loaded_.clear(); 4605 loaded_.clear();
4773 content::WindowedNotificationObserver observer_2( 4606 content::WindowedNotificationObserver observer_2(
4774 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4607 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4775 content::NotificationService::AllSources()); 4608 content::NotificationService::AllSources());
4776 service_->CheckForExternalUpdates(); 4609 service()->CheckForExternalUpdates();
4777 observer_2.Wait(); 4610 observer_2.Wait();
4778 ASSERT_EQ(0u, GetErrors().size()); 4611 ASSERT_EQ(0u, GetErrors().size());
4779 ASSERT_EQ(1u, loaded_.size()); 4612 ASSERT_EQ(1u, loaded_.size());
4780 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 4613 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
4781 ValidatePrefKeyCount(1); 4614 ValidatePrefKeyCount(1);
4782 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4615 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4783 ValidateIntegerPref(good_crx, "location", location); 4616 ValidateIntegerPref(good_crx, "location", location);
4784 4617
4785 // Uninstall the extension and reload. Nothing should happen because the 4618 // Uninstall the extension and reload. Nothing should happen because the
4786 // preference should prevent us from reinstalling. 4619 // preference should prevent us from reinstalling.
4787 std::string id = loaded_[0]->id(); 4620 std::string id = loaded_[0]->id();
4788 bool no_uninstall = 4621 bool no_uninstall =
4789 management_policy_->MustRemainEnabled(loaded_[0].get(), NULL); 4622 GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL);
4790 service_->UninstallExtension(id, false, NULL); 4623 service()->UninstallExtension(id, false, NULL);
4791 base::RunLoop().RunUntilIdle(); 4624 base::RunLoop().RunUntilIdle();
4792 4625
4793 base::FilePath install_path = extensions_install_dir_.AppendASCII(id); 4626 base::FilePath install_path = extensions_install_dir().AppendASCII(id);
4794 if (no_uninstall) { 4627 if (no_uninstall) {
4795 // Policy controlled extensions should not have been touched by uninstall. 4628 // Policy controlled extensions should not have been touched by uninstall.
4796 ASSERT_TRUE(base::PathExists(install_path)); 4629 ASSERT_TRUE(base::PathExists(install_path));
4797 } else { 4630 } else {
4798 // The extension should also be gone from the install directory. 4631 // The extension should also be gone from the install directory.
4799 ASSERT_FALSE(base::PathExists(install_path)); 4632 ASSERT_FALSE(base::PathExists(install_path));
4800 loaded_.clear(); 4633 loaded_.clear();
4801 service_->CheckForExternalUpdates(); 4634 service()->CheckForExternalUpdates();
4802 base::RunLoop().RunUntilIdle(); 4635 base::RunLoop().RunUntilIdle();
4803 ASSERT_EQ(0u, loaded_.size()); 4636 ASSERT_EQ(0u, loaded_.size());
4804 ValidatePrefKeyCount(1); 4637 ValidatePrefKeyCount(1);
4805 ValidateIntegerPref(good_crx, "state", 4638 ValidateIntegerPref(good_crx, "state",
4806 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 4639 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
4807 ValidateIntegerPref(good_crx, "location", location); 4640 ValidateIntegerPref(good_crx, "location", location);
4808 4641
4809 // Now clear the preference and reinstall. 4642 // Now clear the preference and reinstall.
4810 SetPrefInteg(good_crx, "state", Extension::ENABLED); 4643 SetPrefInteg(good_crx, "state", Extension::ENABLED);
4811 4644
4812 loaded_.clear(); 4645 loaded_.clear();
4813 content::WindowedNotificationObserver observer( 4646 content::WindowedNotificationObserver observer(
4814 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4647 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4815 content::NotificationService::AllSources()); 4648 content::NotificationService::AllSources());
4816 service_->CheckForExternalUpdates(); 4649 service()->CheckForExternalUpdates();
4817 observer.Wait(); 4650 observer.Wait();
4818 ASSERT_EQ(1u, loaded_.size()); 4651 ASSERT_EQ(1u, loaded_.size());
4819 } 4652 }
4820 ValidatePrefKeyCount(1); 4653 ValidatePrefKeyCount(1);
4821 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4654 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4822 ValidateIntegerPref(good_crx, "location", location); 4655 ValidateIntegerPref(good_crx, "location", location);
4823 4656
4824 if (management_policy_->MustRemainEnabled(loaded_[0].get(), NULL)) { 4657 if (GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL)) {
4825 EXPECT_EQ(2, provider->visit_count()); 4658 EXPECT_EQ(2, provider->visit_count());
4826 } else { 4659 } else {
4827 // Now test an externally triggered uninstall (deleting the registry key or 4660 // Now test an externally triggered uninstall (deleting the registry key or
4828 // the pref entry). 4661 // the pref entry).
4829 provider->RemoveExtension(good_crx); 4662 provider->RemoveExtension(good_crx);
4830 4663
4831 loaded_.clear(); 4664 loaded_.clear();
4832 service_->OnExternalProviderReady(provider); 4665 service()->OnExternalProviderReady(provider);
4833 base::RunLoop().RunUntilIdle(); 4666 base::RunLoop().RunUntilIdle();
4834 ASSERT_EQ(0u, loaded_.size()); 4667 ASSERT_EQ(0u, loaded_.size());
4835 ValidatePrefKeyCount(0); 4668 ValidatePrefKeyCount(0);
4836 4669
4837 // The extension should also be gone from the install directory. 4670 // The extension should also be gone from the install directory.
4838 ASSERT_FALSE(base::PathExists(install_path)); 4671 ASSERT_FALSE(base::PathExists(install_path));
4839 4672
4840 // Now test the case where user uninstalls and then the extension is removed 4673 // Now test the case where user uninstalls and then the extension is removed
4841 // from the external provider. 4674 // from the external provider.
4842 content::WindowedNotificationObserver observer( 4675 content::WindowedNotificationObserver observer(
4843 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4676 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4844 content::NotificationService::AllSources()); 4677 content::NotificationService::AllSources());
4845 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4678 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4846 service_->CheckForExternalUpdates(); 4679 service()->CheckForExternalUpdates();
4847 observer.Wait(); 4680 observer.Wait();
4848 4681
4849 ASSERT_EQ(1u, loaded_.size()); 4682 ASSERT_EQ(1u, loaded_.size());
4850 ASSERT_EQ(0u, GetErrors().size()); 4683 ASSERT_EQ(0u, GetErrors().size());
4851 4684
4852 // User uninstalls. 4685 // User uninstalls.
4853 loaded_.clear(); 4686 loaded_.clear();
4854 service_->UninstallExtension(id, false, NULL); 4687 service()->UninstallExtension(id, false, NULL);
4855 base::RunLoop().RunUntilIdle(); 4688 base::RunLoop().RunUntilIdle();
4856 ASSERT_EQ(0u, loaded_.size()); 4689 ASSERT_EQ(0u, loaded_.size());
4857 4690
4858 // Then remove the extension from the extension provider. 4691 // Then remove the extension from the extension provider.
4859 provider->RemoveExtension(good_crx); 4692 provider->RemoveExtension(good_crx);
4860 4693
4861 // Should still be at 0. 4694 // Should still be at 0.
4862 loaded_.clear(); 4695 loaded_.clear();
4863 extensions::InstalledLoader(service_).LoadAllExtensions(); 4696 extensions::InstalledLoader(service()).LoadAllExtensions();
4864 base::RunLoop().RunUntilIdle(); 4697 base::RunLoop().RunUntilIdle();
4865 ASSERT_EQ(0u, loaded_.size()); 4698 ASSERT_EQ(0u, loaded_.size());
4866 ValidatePrefKeyCount(1); 4699 ValidatePrefKeyCount(1);
4867 4700
4868 EXPECT_EQ(5, provider->visit_count()); 4701 EXPECT_EQ(5, provider->visit_count());
4869 } 4702 }
4870 } 4703 }
4871 4704
4872 // Tests the external installation feature 4705 // Tests the external installation feature
4873 #if defined(OS_WIN) 4706 #if defined(OS_WIN)
4874 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { 4707 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) {
4875 // This should all work, even when normal extension installation is disabled. 4708 // This should all work, even when normal extension installation is disabled.
4876 InitializeEmptyExtensionService(); 4709 InitializeEmptyExtensionService();
4877 set_extensions_enabled(false); 4710 service()->set_extensions_enabled(false);
4878 4711
4879 // Now add providers. Extension system takes ownership of the objects. 4712 // Now add providers. Extension system takes ownership of the objects.
4880 MockExtensionProvider* reg_provider = 4713 MockExtensionProvider* reg_provider =
4881 new MockExtensionProvider(service_, Manifest::EXTERNAL_REGISTRY); 4714 new MockExtensionProvider(service(), Manifest::EXTERNAL_REGISTRY);
4882 AddMockExternalProvider(reg_provider); 4715 AddMockExternalProvider(reg_provider);
4883 TestExternalProvider(reg_provider, Manifest::EXTERNAL_REGISTRY); 4716 TestExternalProvider(reg_provider, Manifest::EXTERNAL_REGISTRY);
4884 } 4717 }
4885 #endif 4718 #endif
4886 4719
4887 TEST_F(ExtensionServiceTest, ExternalInstallPref) { 4720 TEST_F(ExtensionServiceTest, ExternalInstallPref) {
4888 InitializeEmptyExtensionService(); 4721 InitializeEmptyExtensionService();
4889 4722
4890 // Now add providers. Extension system takes ownership of the objects. 4723 // Now add providers. Extension system takes ownership of the objects.
4891 MockExtensionProvider* pref_provider = 4724 MockExtensionProvider* pref_provider =
4892 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 4725 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
4893 4726
4894 AddMockExternalProvider(pref_provider); 4727 AddMockExternalProvider(pref_provider);
4895 TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF); 4728 TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF);
4896 } 4729 }
4897 4730
4898 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { 4731 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) {
4899 // This should all work, even when normal extension installation is disabled. 4732 // This should all work, even when normal extension installation is disabled.
4900 InitializeEmptyExtensionService(); 4733 InitializeEmptyExtensionService();
4901 set_extensions_enabled(false); 4734 service()->set_extensions_enabled(false);
4902 4735
4903 // TODO(skerner): The mock provider is not a good model of a provider 4736 // TODO(skerner): The mock provider is not a good model of a provider
4904 // that works with update URLs, because it adds file and version info. 4737 // that works with update URLs, because it adds file and version info.
4905 // Extend the mock to work with update URLs. This test checks the 4738 // Extend the mock to work with update URLs. This test checks the
4906 // behavior that is common to all external extension visitors. The 4739 // behavior that is common to all external extension visitors. The
4907 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that 4740 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that
4908 // what the visitor does results in an extension being downloaded and 4741 // what the visitor does results in an extension being downloaded and
4909 // installed. 4742 // installed.
4910 MockExtensionProvider* pref_provider = 4743 MockExtensionProvider* pref_provider =
4911 new MockExtensionProvider(service_, 4744 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF_DOWNLOAD);
4912 Manifest::EXTERNAL_PREF_DOWNLOAD);
4913 AddMockExternalProvider(pref_provider); 4745 AddMockExternalProvider(pref_provider);
4914 TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF_DOWNLOAD); 4746 TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF_DOWNLOAD);
4915 } 4747 }
4916 4748
4917 TEST_F(ExtensionServiceTest, ExternalInstallPolicyUpdateUrl) { 4749 TEST_F(ExtensionServiceTest, ExternalInstallPolicyUpdateUrl) {
4918 // This should all work, even when normal extension installation is disabled. 4750 // This should all work, even when normal extension installation is disabled.
4919 InitializeEmptyExtensionService(); 4751 InitializeEmptyExtensionService();
4920 set_extensions_enabled(false); 4752 service()->set_extensions_enabled(false);
4921 4753
4922 // TODO(skerner): The mock provider is not a good model of a provider 4754 // TODO(skerner): The mock provider is not a good model of a provider
4923 // that works with update URLs, because it adds file and version info. 4755 // that works with update URLs, because it adds file and version info.
4924 // Extend the mock to work with update URLs. This test checks the 4756 // Extend the mock to work with update URLs. This test checks the
4925 // behavior that is common to all external extension visitors. The 4757 // behavior that is common to all external extension visitors. The
4926 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that 4758 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that
4927 // what the visitor does results in an extension being downloaded and 4759 // what the visitor does results in an extension being downloaded and
4928 // installed. 4760 // installed.
4929 MockExtensionProvider* pref_provider = 4761 MockExtensionProvider* pref_provider =
4930 new MockExtensionProvider(service_, 4762 new MockExtensionProvider(service(), Manifest::EXTERNAL_POLICY_DOWNLOAD);
4931 Manifest::EXTERNAL_POLICY_DOWNLOAD);
4932 AddMockExternalProvider(pref_provider); 4763 AddMockExternalProvider(pref_provider);
4933 TestExternalProvider(pref_provider, Manifest::EXTERNAL_POLICY_DOWNLOAD); 4764 TestExternalProvider(pref_provider, Manifest::EXTERNAL_POLICY_DOWNLOAD);
4934 } 4765 }
4935 4766
4936 // Tests that external extensions get uninstalled when the external extension 4767 // Tests that external extensions get uninstalled when the external extension
4937 // providers can't account for them. 4768 // providers can't account for them.
4938 TEST_F(ExtensionServiceTest, ExternalUninstall) { 4769 TEST_F(ExtensionServiceTest, ExternalUninstall) {
4939 // Start the extensions service with one external extension already installed. 4770 // Start the extensions service with one external extension already installed.
4940 base::FilePath source_install_dir = data_dir_ 4771 base::FilePath source_install_dir =
4941 .AppendASCII("good") 4772 data_dir().AppendASCII("good").AppendASCII("Extensions");
4942 .AppendASCII("Extensions");
4943 base::FilePath pref_path = source_install_dir 4773 base::FilePath pref_path = source_install_dir
4944 .DirName() 4774 .DirName()
4945 .AppendASCII("PreferencesExternal"); 4775 .AppendASCII("PreferencesExternal");
4946 4776
4947 // This initializes the extensions service with no ExternalProviders. 4777 // This initializes the extensions service with no ExternalProviders.
4948 InitializeInstalledExtensionService(pref_path, source_install_dir); 4778 InitializeInstalledExtensionService(pref_path, source_install_dir);
4949 set_extensions_enabled(false); 4779 service()->set_extensions_enabled(false);
4950 4780
4951 service_->Init(); 4781 service()->Init();
4952 4782
4953 ASSERT_EQ(0u, GetErrors().size()); 4783 ASSERT_EQ(0u, GetErrors().size());
4954 ASSERT_EQ(0u, loaded_.size()); 4784 ASSERT_EQ(0u, loaded_.size());
4955 4785
4956 // Verify that it's not the disabled extensions flag causing it not to load. 4786 // Verify that it's not the disabled extensions flag causing it not to load.
4957 set_extensions_enabled(true); 4787 service()->set_extensions_enabled(true);
4958 service_->ReloadExtensionsForTest(); 4788 service()->ReloadExtensionsForTest();
4959 base::RunLoop().RunUntilIdle(); 4789 base::RunLoop().RunUntilIdle();
4960 4790
4961 ASSERT_EQ(0u, GetErrors().size()); 4791 ASSERT_EQ(0u, GetErrors().size());
4962 ASSERT_EQ(0u, loaded_.size()); 4792 ASSERT_EQ(0u, loaded_.size());
4963 } 4793 }
4964 4794
4965 // Test that running multiple update checks simultaneously does not 4795 // Test that running multiple update checks simultaneously does not
4966 // keep the update from succeeding. 4796 // keep the update from succeeding.
4967 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { 4797 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) {
4968 InitializeEmptyExtensionService(); 4798 InitializeEmptyExtensionService();
4969 4799
4970 MockExtensionProvider* provider = 4800 MockExtensionProvider* provider =
4971 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 4801 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
4972 AddMockExternalProvider(provider); 4802 AddMockExternalProvider(provider);
4973 4803
4974 // Verify that starting with no providers loads no extensions. 4804 // Verify that starting with no providers loads no extensions.
4975 service_->Init(); 4805 service()->Init();
4976 ASSERT_EQ(0u, loaded_.size()); 4806 ASSERT_EQ(0u, loaded_.size());
4977 4807
4978 // Start two checks for updates. 4808 // Start two checks for updates.
4979 provider->set_visit_count(0); 4809 provider->set_visit_count(0);
4980 service_->CheckForExternalUpdates(); 4810 service()->CheckForExternalUpdates();
4981 service_->CheckForExternalUpdates(); 4811 service()->CheckForExternalUpdates();
4982 base::RunLoop().RunUntilIdle(); 4812 base::RunLoop().RunUntilIdle();
4983 4813
4984 // Two calls should cause two checks for external extensions. 4814 // Two calls should cause two checks for external extensions.
4985 EXPECT_EQ(2, provider->visit_count()); 4815 EXPECT_EQ(2, provider->visit_count());
4986 EXPECT_EQ(0u, GetErrors().size()); 4816 EXPECT_EQ(0u, GetErrors().size());
4987 EXPECT_EQ(0u, loaded_.size()); 4817 EXPECT_EQ(0u, loaded_.size());
4988 4818
4989 // Register a test extension externally using the mock registry provider. 4819 // Register a test extension externally using the mock registry provider.
4990 base::FilePath source_path = data_dir_.AppendASCII("good.crx"); 4820 base::FilePath source_path = data_dir().AppendASCII("good.crx");
4991 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4821 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4992 4822
4993 // Two checks for external updates should find the extension, and install it 4823 // Two checks for external updates should find the extension, and install it
4994 // once. 4824 // once.
4995 content::WindowedNotificationObserver observer( 4825 content::WindowedNotificationObserver observer(
4996 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4826 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4997 content::NotificationService::AllSources()); 4827 content::NotificationService::AllSources());
4998 provider->set_visit_count(0); 4828 provider->set_visit_count(0);
4999 service_->CheckForExternalUpdates(); 4829 service()->CheckForExternalUpdates();
5000 service_->CheckForExternalUpdates(); 4830 service()->CheckForExternalUpdates();
5001 observer.Wait(); 4831 observer.Wait();
5002 EXPECT_EQ(2, provider->visit_count()); 4832 EXPECT_EQ(2, provider->visit_count());
5003 ASSERT_EQ(0u, GetErrors().size()); 4833 ASSERT_EQ(0u, GetErrors().size());
5004 ASSERT_EQ(1u, loaded_.size()); 4834 ASSERT_EQ(1u, loaded_.size());
5005 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); 4835 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location());
5006 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4836 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
5007 ValidatePrefKeyCount(1); 4837 ValidatePrefKeyCount(1);
5008 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4838 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
5009 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF); 4839 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF);
5010 4840
5011 provider->RemoveExtension(good_crx); 4841 provider->RemoveExtension(good_crx);
5012 provider->set_visit_count(0); 4842 provider->set_visit_count(0);
5013 service_->CheckForExternalUpdates(); 4843 service()->CheckForExternalUpdates();
5014 service_->CheckForExternalUpdates(); 4844 service()->CheckForExternalUpdates();
5015 base::RunLoop().RunUntilIdle(); 4845 base::RunLoop().RunUntilIdle();
5016 4846
5017 // Two calls should cause two checks for external extensions. 4847 // Two calls should cause two checks for external extensions.
5018 // Because the external source no longer includes good_crx, 4848 // Because the external source no longer includes good_crx,
5019 // good_crx will be uninstalled. So, expect that no extensions 4849 // good_crx will be uninstalled. So, expect that no extensions
5020 // are loaded. 4850 // are loaded.
5021 EXPECT_EQ(2, provider->visit_count()); 4851 EXPECT_EQ(2, provider->visit_count());
5022 EXPECT_EQ(0u, GetErrors().size()); 4852 EXPECT_EQ(0u, GetErrors().size());
5023 EXPECT_EQ(0u, loaded_.size()); 4853 EXPECT_EQ(0u, loaded_.size());
5024 } 4854 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
5207 "}"; 5037 "}";
5208 EXPECT_EQ(1, was_installed_by_eom_visitor.Visit(json_data)); 5038 EXPECT_EQ(1, was_installed_by_eom_visitor.Visit(json_data));
5209 } 5039 }
5210 5040
5211 // Test loading good extensions from the profile directory. 5041 // Test loading good extensions from the profile directory.
5212 TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) { 5042 TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) {
5213 // Ensure we're testing in "en" and leave global state untouched. 5043 // Ensure we're testing in "en" and leave global state untouched.
5214 extension_l10n_util::ScopedLocaleForTest testLocale("en"); 5044 extension_l10n_util::ScopedLocaleForTest testLocale("en");
5215 5045
5216 // Initialize the test dir with a good Preferences/extensions. 5046 // Initialize the test dir with a good Preferences/extensions.
5217 base::FilePath source_install_dir = data_dir_ 5047 base::FilePath source_install_dir = data_dir().AppendASCII("l10n");
5218 .AppendASCII("l10n");
5219 base::FilePath pref_path = 5048 base::FilePath pref_path =
5220 source_install_dir.Append(chrome::kPreferencesFilename); 5049 source_install_dir.Append(chrome::kPreferencesFilename);
5221 InitializeInstalledExtensionService(pref_path, source_install_dir); 5050 InitializeInstalledExtensionService(pref_path, source_install_dir);
5222 5051
5223 service_->Init(); 5052 service()->Init();
5224 5053
5225 ASSERT_EQ(3u, loaded_.size()); 5054 ASSERT_EQ(3u, loaded_.size());
5226 5055
5227 // This was equal to "sr" on load. 5056 // This was equal to "sr" on load.
5228 ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en"); 5057 ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en");
5229 5058
5230 // These are untouched by re-localization. 5059 // These are untouched by re-localization.
5231 ValidateStringPref(loaded_[1]->id(), keys::kCurrentLocale, "en"); 5060 ValidateStringPref(loaded_[1]->id(), keys::kCurrentLocale, "en");
5232 EXPECT_FALSE(IsPrefExist(loaded_[1]->id(), keys::kCurrentLocale)); 5061 EXPECT_FALSE(IsPrefExist(loaded_[1]->id(), keys::kCurrentLocale));
5233 5062
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
5358 profile.reset(); 5187 profile.reset();
5359 service = NULL; 5188 service = NULL;
5360 // Execute any pending deletion tasks. 5189 // Execute any pending deletion tasks.
5361 base::RunLoop().RunUntilIdle(); 5190 base::RunLoop().RunUntilIdle();
5362 } 5191 }
5363 5192
5364 // Test loading extensions that require limited and unlimited storage quotas. 5193 // Test loading extensions that require limited and unlimited storage quotas.
5365 TEST_F(ExtensionServiceTest, StorageQuota) { 5194 TEST_F(ExtensionServiceTest, StorageQuota) {
5366 InitializeEmptyExtensionService(); 5195 InitializeEmptyExtensionService();
5367 5196
5368 base::FilePath extensions_path = data_dir_ 5197 base::FilePath extensions_path = data_dir().AppendASCII("storage_quota");
5369 .AppendASCII("storage_quota");
5370 5198
5371 base::FilePath limited_quota_ext = 5199 base::FilePath limited_quota_ext =
5372 extensions_path.AppendASCII("limited_quota") 5200 extensions_path.AppendASCII("limited_quota")
5373 .AppendASCII("1.0"); 5201 .AppendASCII("1.0");
5374 5202
5375 // The old permission name for unlimited quota was "unlimited_storage", but 5203 // The old permission name for unlimited quota was "unlimited_storage", but
5376 // we changed it to "unlimitedStorage". This tests both versions. 5204 // we changed it to "unlimitedStorage". This tests both versions.
5377 base::FilePath unlimited_quota_ext = 5205 base::FilePath unlimited_quota_ext =
5378 extensions_path.AppendASCII("unlimited_quota") 5206 extensions_path.AppendASCII("unlimited_quota")
5379 .AppendASCII("1.0"); 5207 .AppendASCII("1.0");
5380 base::FilePath unlimited_quota_ext2 = 5208 base::FilePath unlimited_quota_ext2 =
5381 extensions_path.AppendASCII("unlimited_quota") 5209 extensions_path.AppendASCII("unlimited_quota")
5382 .AppendASCII("2.0"); 5210 .AppendASCII("2.0");
5383 extensions::UnpackedInstaller::Create(service_)->Load(limited_quota_ext); 5211 extensions::UnpackedInstaller::Create(service())->Load(limited_quota_ext);
5384 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext); 5212 extensions::UnpackedInstaller::Create(service())->Load(unlimited_quota_ext);
5385 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext2); 5213 extensions::UnpackedInstaller::Create(service())->Load(unlimited_quota_ext2);
5386 base::RunLoop().RunUntilIdle(); 5214 base::RunLoop().RunUntilIdle();
5387 5215
5388 ASSERT_EQ(3u, loaded_.size()); 5216 ASSERT_EQ(3u, loaded_.size());
5389 EXPECT_TRUE(profile_.get()); 5217 EXPECT_TRUE(profile());
5390 EXPECT_FALSE(profile_->IsOffTheRecord()); 5218 EXPECT_FALSE(profile()->IsOffTheRecord());
5391 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 5219 EXPECT_FALSE(
5392 loaded_[0]->url())); 5220 profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
5393 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 5221 loaded_[0]->url()));
5222 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
5394 loaded_[1]->url())); 5223 loaded_[1]->url()));
5395 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 5224 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
5396 loaded_[2]->url())); 5225 loaded_[2]->url()));
5397 } 5226 }
5398 5227
5399 // Tests ComponentLoader::Add(). 5228 // Tests ComponentLoader::Add().
5400 TEST_F(ExtensionServiceTest, ComponentExtensions) { 5229 TEST_F(ExtensionServiceTest, ComponentExtensions) {
5401 InitializeEmptyExtensionService(); 5230 InitializeEmptyExtensionService();
5402 5231
5403 // Component extensions should work even when extensions are disabled. 5232 // Component extensions should work even when extensions are disabled.
5404 set_extensions_enabled(false); 5233 service()->set_extensions_enabled(false);
5405 5234
5406 base::FilePath path = data_dir_ 5235 base::FilePath path = data_dir()
5407 .AppendASCII("good") 5236 .AppendASCII("good")
5408 .AppendASCII("Extensions") 5237 .AppendASCII("Extensions")
5409 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 5238 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
5410 .AppendASCII("1.0.0.0"); 5239 .AppendASCII("1.0.0.0");
5411 5240
5412 std::string manifest; 5241 std::string manifest;
5413 ASSERT_TRUE(base::ReadFileToString( 5242 ASSERT_TRUE(base::ReadFileToString(
5414 path.Append(extensions::kManifestFilename), &manifest)); 5243 path.Append(extensions::kManifestFilename), &manifest));
5415 5244
5416 service_->component_loader()->Add(manifest, path); 5245 service()->component_loader()->Add(manifest, path);
5417 service_->Init(); 5246 service()->Init();
5418 5247
5419 // Note that we do not pump messages -- the extension should be loaded 5248 // Note that we do not pump messages -- the extension should be loaded
5420 // immediately. 5249 // immediately.
5421 5250
5422 EXPECT_EQ(0u, GetErrors().size()); 5251 EXPECT_EQ(0u, GetErrors().size());
5423 ASSERT_EQ(1u, loaded_.size()); 5252 ASSERT_EQ(1u, loaded_.size());
5424 EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location()); 5253 EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location());
5425 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 5254 EXPECT_EQ(1u, registry()->enabled_extensions().size());
5426 5255
5427 // Component extensions get a prefs entry on first install. 5256 // Component extensions get a prefs entry on first install.
5428 ValidatePrefKeyCount(1); 5257 ValidatePrefKeyCount(1);
5429 5258
5430 // Reload all extensions, and make sure it comes back. 5259 // Reload all extensions, and make sure it comes back.
5431 std::string extension_id = (*registry_->enabled_extensions().begin())->id(); 5260 std::string extension_id = (*registry()->enabled_extensions().begin())->id();
5432 loaded_.clear(); 5261 loaded_.clear();
5433 service_->ReloadExtensionsForTest(); 5262 service()->ReloadExtensionsForTest();
5434 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 5263 ASSERT_EQ(1u, registry()->enabled_extensions().size());
5435 EXPECT_EQ(extension_id, (*registry_->enabled_extensions().begin())->id()); 5264 EXPECT_EQ(extension_id, (*registry()->enabled_extensions().begin())->id());
5436 } 5265 }
5437 5266
5438 TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledComponent) { 5267 TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledComponent) {
5439 InitializeEmptyExtensionService(); 5268 InitializeEmptyExtensionService();
5440 InitializeExtensionSyncService(); 5269 InitializeExtensionSyncService();
5441 5270
5442 bool flare_was_called = false; 5271 bool flare_was_called = false;
5443 syncer::ModelType triggered_type(syncer::UNSPECIFIED); 5272 syncer::ModelType triggered_type(syncer::UNSPECIFIED);
5444 base::WeakPtrFactory<ExtensionServiceTest> factory(this); 5273 base::WeakPtrFactory<ExtensionServiceTest> factory(this);
5445 extension_sync_service_->SetSyncStartFlare( 5274 extension_sync_service()->SetSyncStartFlare(
5446 base::Bind(&ExtensionServiceTest::MockSyncStartFlare, 5275 base::Bind(&ExtensionServiceTest::MockSyncStartFlare,
5447 factory.GetWeakPtr(), 5276 factory.GetWeakPtr(),
5448 &flare_was_called, // Safe due to WeakPtrFactory scope. 5277 &flare_was_called, // Safe due to WeakPtrFactory scope.
5449 &triggered_type)); // Safe due to WeakPtrFactory scope. 5278 &triggered_type)); // Safe due to WeakPtrFactory scope.
5450 5279
5451 // Install a component extension. 5280 // Install a component extension.
5452 std::string manifest; 5281 std::string manifest;
5453 ASSERT_TRUE(base::ReadFileToString( 5282 ASSERT_TRUE(base::ReadFileToString(
5454 good0_path().Append(extensions::kManifestFilename), &manifest)); 5283 good0_path().Append(extensions::kManifestFilename), &manifest));
5455 service_->component_loader()->Add(manifest, good0_path()); 5284 service()->component_loader()->Add(manifest, good0_path());
5456 ASSERT_FALSE(service_->is_ready()); 5285 ASSERT_FALSE(service()->is_ready());
5457 service_->Init(); 5286 service()->Init();
5458 ASSERT_TRUE(service_->is_ready()); 5287 ASSERT_TRUE(service()->is_ready());
5459 5288
5460 // Extensions added before service is_ready() don't trigger sync startup. 5289 // Extensions added before service is_ready() don't trigger sync startup.
5461 EXPECT_FALSE(flare_was_called); 5290 EXPECT_FALSE(flare_was_called);
5462 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); 5291 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type);
5463 } 5292 }
5464 5293
5465 TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledNormal) { 5294 TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledNormal) {
5466 InitializeGoodInstalledExtensionService(); 5295 InitializeGoodInstalledExtensionService();
5467 InitializeExtensionSyncService(); 5296 InitializeExtensionSyncService();
5468 5297
5469 bool flare_was_called = false; 5298 bool flare_was_called = false;
5470 syncer::ModelType triggered_type(syncer::UNSPECIFIED); 5299 syncer::ModelType triggered_type(syncer::UNSPECIFIED);
5471 base::WeakPtrFactory<ExtensionServiceTest> factory(this); 5300 base::WeakPtrFactory<ExtensionServiceTest> factory(this);
5472 extension_sync_service_->SetSyncStartFlare( 5301 extension_sync_service()->SetSyncStartFlare(
5473 base::Bind(&ExtensionServiceTest::MockSyncStartFlare, 5302 base::Bind(&ExtensionServiceTest::MockSyncStartFlare,
5474 factory.GetWeakPtr(), 5303 factory.GetWeakPtr(),
5475 &flare_was_called, // Safe due to WeakPtrFactory scope. 5304 &flare_was_called, // Safe due to WeakPtrFactory scope.
5476 &triggered_type)); // Safe due to WeakPtrFactory scope. 5305 &triggered_type)); // Safe due to WeakPtrFactory scope.
5477 5306
5478 ASSERT_FALSE(service_->is_ready()); 5307 ASSERT_FALSE(service()->is_ready());
5479 service_->Init(); 5308 service()->Init();
5480 ASSERT_EQ(3u, loaded_.size()); 5309 ASSERT_EQ(3u, loaded_.size());
5481 ASSERT_TRUE(service_->is_ready()); 5310 ASSERT_TRUE(service()->is_ready());
5482 5311
5483 // Extensions added before service is_ready() don't trigger sync startup. 5312 // Extensions added before service is_ready() don't trigger sync startup.
5484 EXPECT_FALSE(flare_was_called); 5313 EXPECT_FALSE(flare_was_called);
5485 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); 5314 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type);
5486 } 5315 }
5487 5316
5488 TEST_F(ExtensionServiceTest, DeferredSyncStartupOnInstall) { 5317 TEST_F(ExtensionServiceTest, DeferredSyncStartupOnInstall) {
5489 InitializeEmptyExtensionService(); 5318 InitializeEmptyExtensionService();
5490 InitializeExtensionSyncService(); 5319 InitializeExtensionSyncService();
5491 service_->Init(); 5320 service()->Init();
5492 ASSERT_TRUE(service_->is_ready()); 5321 ASSERT_TRUE(service()->is_ready());
5493 5322
5494 bool flare_was_called = false; 5323 bool flare_was_called = false;
5495 syncer::ModelType triggered_type(syncer::UNSPECIFIED); 5324 syncer::ModelType triggered_type(syncer::UNSPECIFIED);
5496 base::WeakPtrFactory<ExtensionServiceTest> factory(this); 5325 base::WeakPtrFactory<ExtensionServiceTest> factory(this);
5497 extension_sync_service_->SetSyncStartFlare( 5326 extension_sync_service()->SetSyncStartFlare(
5498 base::Bind(&ExtensionServiceTest::MockSyncStartFlare, 5327 base::Bind(&ExtensionServiceTest::MockSyncStartFlare,
5499 factory.GetWeakPtr(), 5328 factory.GetWeakPtr(),
5500 &flare_was_called, // Safe due to WeakPtrFactory scope. 5329 &flare_was_called, // Safe due to WeakPtrFactory scope.
5501 &triggered_type)); // Safe due to WeakPtrFactory scope. 5330 &triggered_type)); // Safe due to WeakPtrFactory scope.
5502 5331
5503 base::FilePath path = data_dir_.AppendASCII("good.crx"); 5332 base::FilePath path = data_dir().AppendASCII("good.crx");
5504 InstallCRX(path, INSTALL_NEW); 5333 InstallCRX(path, INSTALL_NEW);
5505 5334
5506 EXPECT_TRUE(flare_was_called); 5335 EXPECT_TRUE(flare_was_called);
5507 EXPECT_EQ(syncer::EXTENSIONS, triggered_type); 5336 EXPECT_EQ(syncer::EXTENSIONS, triggered_type);
5508 5337
5509 // Reset. 5338 // Reset.
5510 flare_was_called = false; 5339 flare_was_called = false;
5511 triggered_type = syncer::UNSPECIFIED; 5340 triggered_type = syncer::UNSPECIFIED;
5512 5341
5513 // Once sync starts, flare should no longer be invoked. 5342 // Once sync starts, flare should no longer be invoked.
5514 extension_sync_service_->MergeDataAndStartSyncing( 5343 extension_sync_service()->MergeDataAndStartSyncing(
5515 syncer::EXTENSIONS, 5344 syncer::EXTENSIONS,
5516 syncer::SyncDataList(), 5345 syncer::SyncDataList(),
5517 scoped_ptr<syncer::SyncChangeProcessor>( 5346 scoped_ptr<syncer::SyncChangeProcessor>(
5518 new syncer::FakeSyncChangeProcessor), 5347 new syncer::FakeSyncChangeProcessor),
5519 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5348 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5520 path = data_dir_.AppendASCII("page_action.crx"); 5349 path = data_dir().AppendASCII("page_action.crx");
5521 InstallCRX(path, INSTALL_NEW); 5350 InstallCRX(path, INSTALL_NEW);
5522 EXPECT_FALSE(flare_was_called); 5351 EXPECT_FALSE(flare_was_called);
5523 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); 5352 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type);
5524 } 5353 }
5525 5354
5526 TEST_F(ExtensionServiceTest, DisableExtensionFromSync) { 5355 TEST_F(ExtensionServiceTest, DisableExtensionFromSync) {
5527 // Start the extensions service with one external extension already installed. 5356 // Start the extensions service with one external extension already installed.
5528 base::FilePath source_install_dir = data_dir_ 5357 base::FilePath source_install_dir =
5529 .AppendASCII("good") 5358 data_dir().AppendASCII("good").AppendASCII("Extensions");
5530 .AppendASCII("Extensions");
5531 base::FilePath pref_path = 5359 base::FilePath pref_path =
5532 source_install_dir.DirName().Append(chrome::kPreferencesFilename); 5360 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
5533 5361
5534 InitializeInstalledExtensionService(pref_path, source_install_dir); 5362 InitializeInstalledExtensionService(pref_path, source_install_dir);
5535 InitializeExtensionSyncService(); 5363 InitializeExtensionSyncService();
5536 5364
5537 // The user has enabled sync. 5365 // The user has enabled sync.
5538 ProfileSyncService* sync_service = 5366 ProfileSyncService* sync_service =
5539 ProfileSyncServiceFactory::GetForProfile(profile_.get()); 5367 ProfileSyncServiceFactory::GetForProfile(profile());
5540 sync_service->SetSyncSetupCompleted(); 5368 sync_service->SetSyncSetupCompleted();
5541 5369
5542 service_->Init(); 5370 service()->Init();
5543 ASSERT_TRUE(service_->is_ready()); 5371 ASSERT_TRUE(service()->is_ready());
5544 5372
5545 ASSERT_EQ(3u, loaded_.size()); 5373 ASSERT_EQ(3u, loaded_.size());
5546 5374
5547 // We start enabled. 5375 // We start enabled.
5548 const Extension* extension = service_->GetExtensionById(good0, true); 5376 const Extension* extension = service()->GetExtensionById(good0, true);
5549 ASSERT_TRUE(extension); 5377 ASSERT_TRUE(extension);
5550 ASSERT_TRUE(service_->IsExtensionEnabled(good0)); 5378 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
5551 extensions::ExtensionSyncData disable_good_crx( 5379 extensions::ExtensionSyncData disable_good_crx(
5552 *extension, false, false, false); 5380 *extension, false, false, false);
5553 5381
5554 // Then sync data arrives telling us to disable |good0|. 5382 // Then sync data arrives telling us to disable |good0|.
5555 syncer::SyncDataList sync_data; 5383 syncer::SyncDataList sync_data;
5556 sync_data.push_back(disable_good_crx.GetSyncData()); 5384 sync_data.push_back(disable_good_crx.GetSyncData());
5557 extension_sync_service_->MergeDataAndStartSyncing( 5385 extension_sync_service()->MergeDataAndStartSyncing(
5558 syncer::EXTENSIONS, 5386 syncer::EXTENSIONS,
5559 sync_data, 5387 sync_data,
5560 scoped_ptr<syncer::SyncChangeProcessor>( 5388 scoped_ptr<syncer::SyncChangeProcessor>(
5561 new syncer::FakeSyncChangeProcessor), 5389 new syncer::FakeSyncChangeProcessor),
5562 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5390 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5563 ASSERT_FALSE(service_->IsExtensionEnabled(good0)); 5391 ASSERT_FALSE(service()->IsExtensionEnabled(good0));
5564 } 5392 }
5565 5393
5566 TEST_F(ExtensionServiceTest, DontDisableExtensionWithPendingEnableFromSync) { 5394 TEST_F(ExtensionServiceTest, DontDisableExtensionWithPendingEnableFromSync) {
5567 // Start the extensions service with one external extension already installed. 5395 // Start the extensions service with one external extension already installed.
5568 base::FilePath source_install_dir = data_dir_ 5396 base::FilePath source_install_dir =
5569 .AppendASCII("good") 5397 data_dir().AppendASCII("good").AppendASCII("Extensions");
5570 .AppendASCII("Extensions");
5571 base::FilePath pref_path = 5398 base::FilePath pref_path =
5572 source_install_dir.DirName().Append(chrome::kPreferencesFilename); 5399 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
5573 5400
5574 InitializeInstalledExtensionService(pref_path, source_install_dir); 5401 InitializeInstalledExtensionService(pref_path, source_install_dir);
5575 InitializeExtensionSyncService(); 5402 InitializeExtensionSyncService();
5576 5403
5577 // The user has enabled sync. 5404 // The user has enabled sync.
5578 ProfileSyncService* sync_service = 5405 ProfileSyncService* sync_service =
5579 ProfileSyncServiceFactory::GetForProfile(profile_.get()); 5406 ProfileSyncServiceFactory::GetForProfile(profile());
5580 sync_service->SetSyncSetupCompleted(); 5407 sync_service->SetSyncSetupCompleted();
5581 5408
5582 service_->Init(); 5409 service()->Init();
5583 ASSERT_TRUE(service_->is_ready()); 5410 ASSERT_TRUE(service()->is_ready());
5584 ASSERT_EQ(3u, loaded_.size()); 5411 ASSERT_EQ(3u, loaded_.size());
5585 5412
5586 const Extension* extension = service_->GetExtensionById(good0, true); 5413 const Extension* extension = service()->GetExtensionById(good0, true);
5587 ASSERT_TRUE(service_->IsExtensionEnabled(good0)); 5414 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
5588 5415
5589 // Disable extension before first sync data arrives. 5416 // Disable extension before first sync data arrives.
5590 service_->DisableExtension(good0, Extension::DISABLE_USER_ACTION); 5417 service()->DisableExtension(good0, Extension::DISABLE_USER_ACTION);
5591 ASSERT_FALSE(service_->IsExtensionEnabled(good0)); 5418 ASSERT_FALSE(service()->IsExtensionEnabled(good0));
5592 5419
5593 // Enable extension - this is now the most recent state. 5420 // Enable extension - this is now the most recent state.
5594 service_->EnableExtension(good0); 5421 service()->EnableExtension(good0);
5595 ASSERT_TRUE(service_->IsExtensionEnabled(good0)); 5422 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
5596 5423
5597 // Now sync data comes in that says to disable good0. This should be 5424 // Now sync data comes in that says to disable good0. This should be
5598 // ignored. 5425 // ignored.
5599 extensions::ExtensionSyncData disable_good_crx( 5426 extensions::ExtensionSyncData disable_good_crx(
5600 *extension, false, false, false); 5427 *extension, false, false, false);
5601 syncer::SyncDataList sync_data; 5428 syncer::SyncDataList sync_data;
5602 sync_data.push_back(disable_good_crx.GetSyncData()); 5429 sync_data.push_back(disable_good_crx.GetSyncData());
5603 extension_sync_service_->MergeDataAndStartSyncing( 5430 extension_sync_service()->MergeDataAndStartSyncing(
5604 syncer::EXTENSIONS, 5431 syncer::EXTENSIONS,
5605 sync_data, 5432 sync_data,
5606 scoped_ptr<syncer::SyncChangeProcessor>( 5433 scoped_ptr<syncer::SyncChangeProcessor>(
5607 new syncer::FakeSyncChangeProcessor), 5434 new syncer::FakeSyncChangeProcessor),
5608 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5435 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5609 5436
5610 // The extension was enabled locally before the sync data arrived, so it 5437 // The extension was enabled locally before the sync data arrived, so it
5611 // should still be enabled now. 5438 // should still be enabled now.
5612 ASSERT_TRUE(service_->IsExtensionEnabled(good0)); 5439 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
5613 } 5440 }
5614 5441
5615 TEST_F(ExtensionServiceTest, GetSyncData) { 5442 TEST_F(ExtensionServiceTest, GetSyncData) {
5616 InitializeEmptyExtensionService(); 5443 InitializeEmptyExtensionService();
5617 InitializeExtensionSyncService(); 5444 InitializeExtensionSyncService();
5618 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5445 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5619 const Extension* extension = service_->GetInstalledExtension(good_crx); 5446 const Extension* extension = service()->GetInstalledExtension(good_crx);
5620 ASSERT_TRUE(extension); 5447 ASSERT_TRUE(extension);
5621 5448
5622 extension_sync_service_->MergeDataAndStartSyncing( 5449 extension_sync_service()->MergeDataAndStartSyncing(
5623 syncer::EXTENSIONS, 5450 syncer::EXTENSIONS,
5624 syncer::SyncDataList(), 5451 syncer::SyncDataList(),
5625 scoped_ptr<syncer::SyncChangeProcessor>( 5452 scoped_ptr<syncer::SyncChangeProcessor>(
5626 new syncer::FakeSyncChangeProcessor), 5453 new syncer::FakeSyncChangeProcessor),
5627 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5454 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5628 5455
5629 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5456 syncer::SyncDataList list =
5630 syncer::EXTENSIONS); 5457 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5631 ASSERT_EQ(list.size(), 1U); 5458 ASSERT_EQ(list.size(), 1U);
5632 extensions::ExtensionSyncData data(list[0]); 5459 extensions::ExtensionSyncData data(list[0]);
5633 EXPECT_EQ(extension->id(), data.id()); 5460 EXPECT_EQ(extension->id(), data.id());
5634 EXPECT_FALSE(data.uninstalled()); 5461 EXPECT_FALSE(data.uninstalled());
5635 EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); 5462 EXPECT_EQ(service()->IsExtensionEnabled(good_crx), data.enabled());
5636 EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile_.get()), 5463 EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile()),
5637 data.incognito_enabled()); 5464 data.incognito_enabled());
5638 EXPECT_TRUE(data.version().Equals(*extension->version())); 5465 EXPECT_TRUE(data.version().Equals(*extension->version()));
5639 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension), 5466 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension),
5640 data.update_url()); 5467 data.update_url());
5641 EXPECT_EQ(extension->name(), data.name()); 5468 EXPECT_EQ(extension->name(), data.name());
5642 } 5469 }
5643 5470
5644 TEST_F(ExtensionServiceTest, GetSyncDataTerminated) { 5471 TEST_F(ExtensionServiceTest, GetSyncDataTerminated) {
5645 InitializeEmptyExtensionService(); 5472 InitializeEmptyExtensionService();
5646 InitializeExtensionSyncService(); 5473 InitializeExtensionSyncService();
5647 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5474 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5648 TerminateExtension(good_crx); 5475 TerminateExtension(good_crx);
5649 const Extension* extension = service_->GetInstalledExtension(good_crx); 5476 const Extension* extension = service()->GetInstalledExtension(good_crx);
5650 ASSERT_TRUE(extension); 5477 ASSERT_TRUE(extension);
5651 5478
5652 syncer::FakeSyncChangeProcessor processor; 5479 syncer::FakeSyncChangeProcessor processor;
5653 extension_sync_service_->MergeDataAndStartSyncing( 5480 extension_sync_service()->MergeDataAndStartSyncing(
5654 syncer::EXTENSIONS, 5481 syncer::EXTENSIONS,
5655 syncer::SyncDataList(), 5482 syncer::SyncDataList(),
5656 scoped_ptr<syncer::SyncChangeProcessor>( 5483 scoped_ptr<syncer::SyncChangeProcessor>(
5657 new syncer::FakeSyncChangeProcessor), 5484 new syncer::FakeSyncChangeProcessor),
5658 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5485 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5659 5486
5660 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5487 syncer::SyncDataList list =
5661 syncer::EXTENSIONS); 5488 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5662 ASSERT_EQ(list.size(), 1U); 5489 ASSERT_EQ(list.size(), 1U);
5663 extensions::ExtensionSyncData data(list[0]); 5490 extensions::ExtensionSyncData data(list[0]);
5664 EXPECT_EQ(extension->id(), data.id()); 5491 EXPECT_EQ(extension->id(), data.id());
5665 EXPECT_FALSE(data.uninstalled()); 5492 EXPECT_FALSE(data.uninstalled());
5666 EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); 5493 EXPECT_EQ(service()->IsExtensionEnabled(good_crx), data.enabled());
5667 EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile_.get()), 5494 EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile()),
5668 data.incognito_enabled()); 5495 data.incognito_enabled());
5669 EXPECT_TRUE(data.version().Equals(*extension->version())); 5496 EXPECT_TRUE(data.version().Equals(*extension->version()));
5670 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension), 5497 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension),
5671 data.update_url()); 5498 data.update_url());
5672 EXPECT_EQ(extension->name(), data.name()); 5499 EXPECT_EQ(extension->name(), data.name());
5673 } 5500 }
5674 5501
5675 TEST_F(ExtensionServiceTest, GetSyncDataFilter) { 5502 TEST_F(ExtensionServiceTest, GetSyncDataFilter) {
5676 InitializeEmptyExtensionService(); 5503 InitializeEmptyExtensionService();
5677 InitializeExtensionSyncService(); 5504 InitializeExtensionSyncService();
5678 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5505 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5679 const Extension* extension = service_->GetInstalledExtension(good_crx); 5506 const Extension* extension = service()->GetInstalledExtension(good_crx);
5680 ASSERT_TRUE(extension); 5507 ASSERT_TRUE(extension);
5681 5508
5682 syncer::FakeSyncChangeProcessor processor; 5509 syncer::FakeSyncChangeProcessor processor;
5683 extension_sync_service_->MergeDataAndStartSyncing( 5510 extension_sync_service()->MergeDataAndStartSyncing(
5684 syncer::APPS, 5511 syncer::APPS,
5685 syncer::SyncDataList(), 5512 syncer::SyncDataList(),
5686 scoped_ptr<syncer::SyncChangeProcessor>( 5513 scoped_ptr<syncer::SyncChangeProcessor>(
5687 new syncer::FakeSyncChangeProcessor), 5514 new syncer::FakeSyncChangeProcessor),
5688 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5515 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5689 5516
5690 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5517 syncer::SyncDataList list =
5691 syncer::EXTENSIONS); 5518 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5692 ASSERT_EQ(list.size(), 0U); 5519 ASSERT_EQ(list.size(), 0U);
5693 } 5520 }
5694 5521
5695 TEST_F(ExtensionServiceTest, GetSyncExtensionDataUserSettings) { 5522 TEST_F(ExtensionServiceTest, GetSyncExtensionDataUserSettings) {
5696 InitializeEmptyExtensionService(); 5523 InitializeEmptyExtensionService();
5697 InitializeProcessManager(); 5524 InitializeProcessManager();
5698 InitializeExtensionSyncService(); 5525 InitializeExtensionSyncService();
5699 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5526 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5700 const Extension* extension = service_->GetInstalledExtension(good_crx); 5527 const Extension* extension = service()->GetInstalledExtension(good_crx);
5701 ASSERT_TRUE(extension); 5528 ASSERT_TRUE(extension);
5702 5529
5703 syncer::FakeSyncChangeProcessor processor; 5530 syncer::FakeSyncChangeProcessor processor;
5704 extension_sync_service_->MergeDataAndStartSyncing( 5531 extension_sync_service()->MergeDataAndStartSyncing(
5705 syncer::EXTENSIONS, 5532 syncer::EXTENSIONS,
5706 syncer::SyncDataList(), 5533 syncer::SyncDataList(),
5707 scoped_ptr<syncer::SyncChangeProcessor>( 5534 scoped_ptr<syncer::SyncChangeProcessor>(
5708 new syncer::FakeSyncChangeProcessor), 5535 new syncer::FakeSyncChangeProcessor),
5709 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5536 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5710 5537
5711 { 5538 {
5712 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5539 syncer::SyncDataList list =
5713 syncer::EXTENSIONS); 5540 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5714 ASSERT_EQ(list.size(), 1U); 5541 ASSERT_EQ(list.size(), 1U);
5715 extensions::ExtensionSyncData data(list[0]); 5542 extensions::ExtensionSyncData data(list[0]);
5716 EXPECT_TRUE(data.enabled()); 5543 EXPECT_TRUE(data.enabled());
5717 EXPECT_FALSE(data.incognito_enabled()); 5544 EXPECT_FALSE(data.incognito_enabled());
5718 } 5545 }
5719 5546
5720 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); 5547 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
5721 { 5548 {
5722 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5549 syncer::SyncDataList list =
5723 syncer::EXTENSIONS); 5550 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5724 ASSERT_EQ(list.size(), 1U); 5551 ASSERT_EQ(list.size(), 1U);
5725 extensions::ExtensionSyncData data(list[0]); 5552 extensions::ExtensionSyncData data(list[0]);
5726 EXPECT_FALSE(data.enabled()); 5553 EXPECT_FALSE(data.enabled());
5727 EXPECT_FALSE(data.incognito_enabled()); 5554 EXPECT_FALSE(data.incognito_enabled());
5728 } 5555 }
5729 5556
5730 extensions::util::SetIsIncognitoEnabled(good_crx, profile_.get(), true); 5557 extensions::util::SetIsIncognitoEnabled(good_crx, profile(), true);
5731 { 5558 {
5732 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5559 syncer::SyncDataList list =
5733 syncer::EXTENSIONS); 5560 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5734 ASSERT_EQ(list.size(), 1U); 5561 ASSERT_EQ(list.size(), 1U);
5735 extensions::ExtensionSyncData data(list[0]); 5562 extensions::ExtensionSyncData data(list[0]);
5736 EXPECT_FALSE(data.enabled()); 5563 EXPECT_FALSE(data.enabled());
5737 EXPECT_TRUE(data.incognito_enabled()); 5564 EXPECT_TRUE(data.incognito_enabled());
5738 } 5565 }
5739 5566
5740 service_->EnableExtension(good_crx); 5567 service()->EnableExtension(good_crx);
5741 { 5568 {
5742 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5569 syncer::SyncDataList list =
5743 syncer::EXTENSIONS); 5570 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5744 ASSERT_EQ(list.size(), 1U); 5571 ASSERT_EQ(list.size(), 1U);
5745 extensions::ExtensionSyncData data(list[0]); 5572 extensions::ExtensionSyncData data(list[0]);
5746 EXPECT_TRUE(data.enabled()); 5573 EXPECT_TRUE(data.enabled());
5747 EXPECT_TRUE(data.incognito_enabled()); 5574 EXPECT_TRUE(data.incognito_enabled());
5748 } 5575 }
5749 } 5576 }
5750 5577
5751 TEST_F(ExtensionServiceTest, SyncForUninstalledExternalExtension) { 5578 TEST_F(ExtensionServiceTest, SyncForUninstalledExternalExtension) {
5752 InitializeEmptyExtensionService(); 5579 InitializeEmptyExtensionService();
5753 InitializeExtensionSyncService(); 5580 InitializeExtensionSyncService();
5754 InstallCRXWithLocation(data_dir_.AppendASCII("good.crx"), 5581 InstallCRXWithLocation(
5755 Manifest::EXTERNAL_PREF, INSTALL_NEW); 5582 data_dir().AppendASCII("good.crx"), Manifest::EXTERNAL_PREF, INSTALL_NEW);
5756 const Extension* extension = service_->GetInstalledExtension(good_crx); 5583 const Extension* extension = service()->GetInstalledExtension(good_crx);
5757 ASSERT_TRUE(extension); 5584 ASSERT_TRUE(extension);
5758 5585
5759 syncer::FakeSyncChangeProcessor processor; 5586 syncer::FakeSyncChangeProcessor processor;
5760 extension_sync_service_->MergeDataAndStartSyncing( 5587 extension_sync_service()->MergeDataAndStartSyncing(
5761 syncer::EXTENSIONS, 5588 syncer::EXTENSIONS,
5762 syncer::SyncDataList(), 5589 syncer::SyncDataList(),
5763 scoped_ptr<syncer::SyncChangeProcessor>( 5590 scoped_ptr<syncer::SyncChangeProcessor>(
5764 new syncer::FakeSyncChangeProcessor), 5591 new syncer::FakeSyncChangeProcessor),
5765 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5592 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5766 5593
5767 UninstallExtension(good_crx, false); 5594 UninstallExtension(good_crx, false);
5768 EXPECT_TRUE(ExtensionPrefs::Get(profile_.get()) 5595 EXPECT_TRUE(
5769 ->IsExternalExtensionUninstalled(good_crx)); 5596 ExtensionPrefs::Get(profile())->IsExternalExtensionUninstalled(good_crx));
5770 5597
5771 sync_pb::EntitySpecifics specifics; 5598 sync_pb::EntitySpecifics specifics;
5772 sync_pb::AppSpecifics* app_specifics = specifics.mutable_app(); 5599 sync_pb::AppSpecifics* app_specifics = specifics.mutable_app();
5773 sync_pb::ExtensionSpecifics* extension_specifics = 5600 sync_pb::ExtensionSpecifics* extension_specifics =
5774 app_specifics->mutable_extension(); 5601 app_specifics->mutable_extension();
5775 extension_specifics->set_id(good_crx); 5602 extension_specifics->set_id(good_crx);
5776 extension_specifics->set_version("1.0"); 5603 extension_specifics->set_version("1.0");
5777 extension_specifics->set_enabled(true); 5604 extension_specifics->set_enabled(true);
5778 5605
5779 syncer::SyncData sync_data = 5606 syncer::SyncData sync_data =
5780 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5607 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
5781 syncer::SyncChange sync_change(FROM_HERE, 5608 syncer::SyncChange sync_change(FROM_HERE,
5782 syncer::SyncChange::ACTION_UPDATE, 5609 syncer::SyncChange::ACTION_UPDATE,
5783 sync_data); 5610 sync_data);
5784 syncer::SyncChangeList list(1); 5611 syncer::SyncChangeList list(1);
5785 list[0] = sync_change; 5612 list[0] = sync_change;
5786 5613
5787 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5614 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5788 EXPECT_TRUE(ExtensionPrefs::Get(profile_.get()) 5615 EXPECT_TRUE(
5789 ->IsExternalExtensionUninstalled(good_crx)); 5616 ExtensionPrefs::Get(profile())->IsExternalExtensionUninstalled(good_crx));
5790 } 5617 }
5791 5618
5792 TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettings) { 5619 TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettings) {
5793 InitializeEmptyExtensionService(); 5620 InitializeEmptyExtensionService();
5794 InitializeExtensionSyncService(); 5621 InitializeExtensionSyncService();
5795 const Extension* app = 5622 const Extension* app =
5796 PackAndInstallCRX(data_dir_.AppendASCII("app"), INSTALL_NEW); 5623 PackAndInstallCRX(data_dir().AppendASCII("app"), INSTALL_NEW);
5797 ASSERT_TRUE(app); 5624 ASSERT_TRUE(app);
5798 ASSERT_TRUE(app->is_app()); 5625 ASSERT_TRUE(app->is_app());
5799 5626
5800 syncer::FakeSyncChangeProcessor processor; 5627 syncer::FakeSyncChangeProcessor processor;
5801 extension_sync_service_->MergeDataAndStartSyncing( 5628 extension_sync_service()->MergeDataAndStartSyncing(
5802 syncer::APPS, 5629 syncer::APPS,
5803 syncer::SyncDataList(), 5630 syncer::SyncDataList(),
5804 scoped_ptr<syncer::SyncChangeProcessor>( 5631 scoped_ptr<syncer::SyncChangeProcessor>(
5805 new syncer::FakeSyncChangeProcessor), 5632 new syncer::FakeSyncChangeProcessor),
5806 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5633 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5807 5634
5808 syncer::StringOrdinal initial_ordinal = 5635 syncer::StringOrdinal initial_ordinal =
5809 syncer::StringOrdinal::CreateInitialOrdinal(); 5636 syncer::StringOrdinal::CreateInitialOrdinal();
5810 { 5637 {
5811 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5638 syncer::SyncDataList list =
5812 syncer::APPS); 5639 extension_sync_service()->GetAllSyncData(syncer::APPS);
5813 ASSERT_EQ(list.size(), 1U); 5640 ASSERT_EQ(list.size(), 1U);
5814 5641
5815 extensions::AppSyncData app_sync_data(list[0]); 5642 extensions::AppSyncData app_sync_data(list[0]);
5816 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.app_launch_ordinal())); 5643 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.app_launch_ordinal()));
5817 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal())); 5644 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal()));
5818 } 5645 }
5819 5646
5820 AppSorting* sorting = ExtensionPrefs::Get(profile_.get())->app_sorting(); 5647 AppSorting* sorting = ExtensionPrefs::Get(profile())->app_sorting();
5821 sorting->SetAppLaunchOrdinal(app->id(), initial_ordinal.CreateAfter()); 5648 sorting->SetAppLaunchOrdinal(app->id(), initial_ordinal.CreateAfter());
5822 { 5649 {
5823 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5650 syncer::SyncDataList list =
5824 syncer::APPS); 5651 extension_sync_service()->GetAllSyncData(syncer::APPS);
5825 ASSERT_EQ(list.size(), 1U); 5652 ASSERT_EQ(list.size(), 1U);
5826 5653
5827 extensions::AppSyncData app_sync_data(list[0]); 5654 extensions::AppSyncData app_sync_data(list[0]);
5828 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal())); 5655 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal()));
5829 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal())); 5656 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal()));
5830 } 5657 }
5831 5658
5832 sorting->SetPageOrdinal(app->id(), initial_ordinal.CreateAfter()); 5659 sorting->SetPageOrdinal(app->id(), initial_ordinal.CreateAfter());
5833 { 5660 {
5834 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5661 syncer::SyncDataList list =
5835 syncer::APPS); 5662 extension_sync_service()->GetAllSyncData(syncer::APPS);
5836 ASSERT_EQ(list.size(), 1U); 5663 ASSERT_EQ(list.size(), 1U);
5837 5664
5838 extensions::AppSyncData app_sync_data(list[0]); 5665 extensions::AppSyncData app_sync_data(list[0]);
5839 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal())); 5666 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal()));
5840 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.page_ordinal())); 5667 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.page_ordinal()));
5841 } 5668 }
5842 } 5669 }
5843 5670
5844 // TODO (rdevlin.cronin): The OnExtensionMoved() method has been removed from 5671 // TODO (rdevlin.cronin): The OnExtensionMoved() method has been removed from
5845 // ExtensionService, so this test probably needs a new home. Unfortunately, it 5672 // ExtensionService, so this test probably needs a new home. Unfortunately, it
5846 // relies pretty heavily on things like InitializeExtension[Sync]Service() and 5673 // relies pretty heavily on things like InitializeExtension[Sync]Service() and
5847 // PackAndInstallCRX(). When we clean up a bit more, this should move out. 5674 // PackAndInstallCRX(). When we clean up a bit more, this should move out.
5848 TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettingsOnExtensionMoved) { 5675 TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettingsOnExtensionMoved) {
5849 InitializeEmptyExtensionService(); 5676 InitializeEmptyExtensionService();
5850 InitializeExtensionSyncService(); 5677 InitializeExtensionSyncService();
5851 const size_t kAppCount = 3; 5678 const size_t kAppCount = 3;
5852 const Extension* apps[kAppCount]; 5679 const Extension* apps[kAppCount];
5853 apps[0] = PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 5680 apps[0] = PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
5854 apps[1] = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 5681 apps[1] = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
5855 apps[2] = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); 5682 apps[2] = PackAndInstallCRX(data_dir().AppendASCII("app4"), INSTALL_NEW);
5856 for (size_t i = 0; i < kAppCount; ++i) { 5683 for (size_t i = 0; i < kAppCount; ++i) {
5857 ASSERT_TRUE(apps[i]); 5684 ASSERT_TRUE(apps[i]);
5858 ASSERT_TRUE(apps[i]->is_app()); 5685 ASSERT_TRUE(apps[i]->is_app());
5859 } 5686 }
5860 5687
5861 syncer::FakeSyncChangeProcessor processor; 5688 syncer::FakeSyncChangeProcessor processor;
5862 extension_sync_service_->MergeDataAndStartSyncing( 5689 extension_sync_service()->MergeDataAndStartSyncing(
5863 syncer::APPS, 5690 syncer::APPS,
5864 syncer::SyncDataList(), 5691 syncer::SyncDataList(),
5865 scoped_ptr<syncer::SyncChangeProcessor>( 5692 scoped_ptr<syncer::SyncChangeProcessor>(
5866 new syncer::FakeSyncChangeProcessor), 5693 new syncer::FakeSyncChangeProcessor),
5867 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5694 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5868 5695
5869 ExtensionPrefs::Get(service_->GetBrowserContext()) 5696 ExtensionPrefs::Get(service()->GetBrowserContext())
5870 ->app_sorting() 5697 ->app_sorting()
5871 ->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id()); 5698 ->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id());
5872 { 5699 {
5873 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5700 syncer::SyncDataList list =
5874 syncer::APPS); 5701 extension_sync_service()->GetAllSyncData(syncer::APPS);
5875 ASSERT_EQ(list.size(), 3U); 5702 ASSERT_EQ(list.size(), 3U);
5876 5703
5877 extensions::AppSyncData data[kAppCount]; 5704 extensions::AppSyncData data[kAppCount];
5878 for (size_t i = 0; i < kAppCount; ++i) { 5705 for (size_t i = 0; i < kAppCount; ++i) {
5879 data[i] = extensions::AppSyncData(list[i]); 5706 data[i] = extensions::AppSyncData(list[i]);
5880 } 5707 }
5881 5708
5882 // The sync data is not always in the same order our apps were installed in, 5709 // The sync data is not always in the same order our apps were installed in,
5883 // so we do that sorting here so we can make sure the values are changed as 5710 // so we do that sorting here so we can make sure the values are changed as
5884 // expected. 5711 // expected.
5885 syncer::StringOrdinal app_launch_ordinals[kAppCount]; 5712 syncer::StringOrdinal app_launch_ordinals[kAppCount];
5886 for (size_t i = 0; i < kAppCount; ++i) { 5713 for (size_t i = 0; i < kAppCount; ++i) {
5887 for (size_t j = 0; j < kAppCount; ++j) { 5714 for (size_t j = 0; j < kAppCount; ++j) {
5888 if (apps[i]->id() == data[j].id()) 5715 if (apps[i]->id() == data[j].id())
5889 app_launch_ordinals[i] = data[j].app_launch_ordinal(); 5716 app_launch_ordinals[i] = data[j].app_launch_ordinal();
5890 } 5717 }
5891 } 5718 }
5892 5719
5893 EXPECT_TRUE(app_launch_ordinals[1].LessThan(app_launch_ordinals[0])); 5720 EXPECT_TRUE(app_launch_ordinals[1].LessThan(app_launch_ordinals[0]));
5894 EXPECT_TRUE(app_launch_ordinals[0].LessThan(app_launch_ordinals[2])); 5721 EXPECT_TRUE(app_launch_ordinals[0].LessThan(app_launch_ordinals[2]));
5895 } 5722 }
5896 } 5723 }
5897 5724
5898 TEST_F(ExtensionServiceTest, GetSyncDataList) { 5725 TEST_F(ExtensionServiceTest, GetSyncDataList) {
5899 InitializeEmptyExtensionService(); 5726 InitializeEmptyExtensionService();
5900 InitializeExtensionSyncService(); 5727 InitializeExtensionSyncService();
5901 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5728 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5902 InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW); 5729 InstallCRX(data_dir().AppendASCII("page_action.crx"), INSTALL_NEW);
5903 InstallCRX(data_dir_.AppendASCII("theme.crx"), INSTALL_NEW); 5730 InstallCRX(data_dir().AppendASCII("theme.crx"), INSTALL_NEW);
5904 InstallCRX(data_dir_.AppendASCII("theme2.crx"), INSTALL_NEW); 5731 InstallCRX(data_dir().AppendASCII("theme2.crx"), INSTALL_NEW);
5905 5732
5906 syncer::FakeSyncChangeProcessor processor; 5733 syncer::FakeSyncChangeProcessor processor;
5907 extension_sync_service_->MergeDataAndStartSyncing( 5734 extension_sync_service()->MergeDataAndStartSyncing(
5908 syncer::APPS, 5735 syncer::APPS,
5909 syncer::SyncDataList(), 5736 syncer::SyncDataList(),
5910 scoped_ptr<syncer::SyncChangeProcessor>( 5737 scoped_ptr<syncer::SyncChangeProcessor>(
5911 new syncer::FakeSyncChangeProcessor), 5738 new syncer::FakeSyncChangeProcessor),
5912 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5739 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5913 extension_sync_service_->MergeDataAndStartSyncing( 5740 extension_sync_service()->MergeDataAndStartSyncing(
5914 syncer::EXTENSIONS, 5741 syncer::EXTENSIONS,
5915 syncer::SyncDataList(), 5742 syncer::SyncDataList(),
5916 scoped_ptr<syncer::SyncChangeProcessor>( 5743 scoped_ptr<syncer::SyncChangeProcessor>(
5917 new syncer::FakeSyncChangeProcessor), 5744 new syncer::FakeSyncChangeProcessor),
5918 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5745 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5919 5746
5920 service_->DisableExtension(page_action, Extension::DISABLE_USER_ACTION); 5747 service()->DisableExtension(page_action, Extension::DISABLE_USER_ACTION);
5921 TerminateExtension(theme2_crx); 5748 TerminateExtension(theme2_crx);
5922 5749
5923 EXPECT_EQ(0u, extension_sync_service_->GetAllSyncData(syncer::APPS).size()); 5750 EXPECT_EQ(0u, extension_sync_service()->GetAllSyncData(syncer::APPS).size());
5924 EXPECT_EQ(2u, extension_sync_service_-> 5751 EXPECT_EQ(
5925 GetAllSyncData(syncer::EXTENSIONS).size()); 5752 2u, extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS).size());
5926 } 5753 }
5927 5754
5928 TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) { 5755 TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) {
5929 InitializeEmptyExtensionService(); 5756 InitializeEmptyExtensionService();
5930 InitializeExtensionSyncService(); 5757 InitializeExtensionSyncService();
5931 syncer::FakeSyncChangeProcessor processor; 5758 syncer::FakeSyncChangeProcessor processor;
5932 extension_sync_service_->MergeDataAndStartSyncing( 5759 extension_sync_service()->MergeDataAndStartSyncing(
5933 syncer::EXTENSIONS, 5760 syncer::EXTENSIONS,
5934 syncer::SyncDataList(), 5761 syncer::SyncDataList(),
5935 scoped_ptr<syncer::SyncChangeProcessor>( 5762 scoped_ptr<syncer::SyncChangeProcessor>(
5936 new syncer::FakeSyncChangeProcessor), 5763 new syncer::FakeSyncChangeProcessor),
5937 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5764 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5938 5765
5939 sync_pb::EntitySpecifics specifics; 5766 sync_pb::EntitySpecifics specifics;
5940 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 5767 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
5941 ext_specifics->set_id(good_crx); 5768 ext_specifics->set_id(good_crx);
5942 ext_specifics->set_version("1.0"); 5769 ext_specifics->set_version("1.0");
5943 syncer::SyncData sync_data = 5770 syncer::SyncData sync_data =
5944 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5771 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
5945 syncer::SyncChange sync_change(FROM_HERE, 5772 syncer::SyncChange sync_change(FROM_HERE,
5946 syncer::SyncChange::ACTION_DELETE, 5773 syncer::SyncChange::ACTION_DELETE,
5947 sync_data); 5774 sync_data);
5948 syncer::SyncChangeList list(1); 5775 syncer::SyncChangeList list(1);
5949 list[0] = sync_change; 5776 list[0] = sync_change;
5950 5777
5951 // Should do nothing. 5778 // Should do nothing.
5952 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5779 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5953 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); 5780 EXPECT_FALSE(service()->GetExtensionById(good_crx, true));
5954 5781
5955 // Install the extension. 5782 // Install the extension.
5956 base::FilePath extension_path = data_dir_.AppendASCII("good.crx"); 5783 base::FilePath extension_path = data_dir().AppendASCII("good.crx");
5957 InstallCRX(extension_path, INSTALL_NEW); 5784 InstallCRX(extension_path, INSTALL_NEW);
5958 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 5785 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
5959 5786
5960 // Should uninstall the extension. 5787 // Should uninstall the extension.
5961 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5788 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5962 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); 5789 EXPECT_FALSE(service()->GetExtensionById(good_crx, true));
5963 5790
5964 // Should again do nothing. 5791 // Should again do nothing.
5965 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5792 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5966 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); 5793 EXPECT_FALSE(service()->GetExtensionById(good_crx, true));
5967 } 5794 }
5968 5795
5969 TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) { 5796 TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) {
5970 InitializeEmptyExtensionService(); 5797 InitializeEmptyExtensionService();
5971 InitializeExtensionSyncService(); 5798 InitializeExtensionSyncService();
5972 5799
5973 // Install the extension. 5800 // Install the extension.
5974 base::FilePath extension_path = data_dir_.AppendASCII("good.crx"); 5801 base::FilePath extension_path = data_dir().AppendASCII("good.crx");
5975 InstallCRX(extension_path, INSTALL_NEW); 5802 InstallCRX(extension_path, INSTALL_NEW);
5976 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 5803 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
5977 5804
5978 sync_pb::EntitySpecifics specifics; 5805 sync_pb::EntitySpecifics specifics;
5979 sync_pb::AppSpecifics* app_specifics = specifics.mutable_app(); 5806 sync_pb::AppSpecifics* app_specifics = specifics.mutable_app();
5980 sync_pb::ExtensionSpecifics* extension_specifics = 5807 sync_pb::ExtensionSpecifics* extension_specifics =
5981 app_specifics->mutable_extension(); 5808 app_specifics->mutable_extension();
5982 extension_specifics->set_id(good_crx); 5809 extension_specifics->set_id(good_crx);
5983 extension_specifics->set_version( 5810 extension_specifics->set_version(
5984 service_->GetInstalledExtension(good_crx)->version()->GetString()); 5811 service()->GetInstalledExtension(good_crx)->version()->GetString());
5985 5812
5986 { 5813 {
5987 extension_specifics->set_enabled(true); 5814 extension_specifics->set_enabled(true);
5988 syncer::SyncData sync_data = 5815 syncer::SyncData sync_data =
5989 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5816 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
5990 syncer::SyncChange sync_change(FROM_HERE, 5817 syncer::SyncChange sync_change(FROM_HERE,
5991 syncer::SyncChange::ACTION_DELETE, 5818 syncer::SyncChange::ACTION_DELETE,
5992 sync_data); 5819 sync_data);
5993 syncer::SyncChangeList list(1); 5820 syncer::SyncChangeList list(1);
5994 list[0] = sync_change; 5821 list[0] = sync_change;
5995 5822
5996 // Should do nothing 5823 // Should do nothing
5997 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5824 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5998 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 5825 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
5999 } 5826 }
6000 5827
6001 { 5828 {
6002 extension_specifics->set_enabled(false); 5829 extension_specifics->set_enabled(false);
6003 syncer::SyncData sync_data = 5830 syncer::SyncData sync_data =
6004 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5831 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6005 syncer::SyncChange sync_change(FROM_HERE, 5832 syncer::SyncChange sync_change(FROM_HERE,
6006 syncer::SyncChange::ACTION_UPDATE, 5833 syncer::SyncChange::ACTION_UPDATE,
6007 sync_data); 5834 sync_data);
6008 syncer::SyncChangeList list(1); 5835 syncer::SyncChangeList list(1);
6009 list[0] = sync_change; 5836 list[0] = sync_change;
6010 5837
6011 // Should again do nothing. 5838 // Should again do nothing.
6012 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5839 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6013 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 5840 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
6014 } 5841 }
6015 } 5842 }
6016 5843
6017 TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) { 5844 TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) {
6018 InitializeEmptyExtensionService(); 5845 InitializeEmptyExtensionService();
6019 InitializeProcessManager(); 5846 InitializeProcessManager();
6020 InitializeExtensionSyncService(); 5847 InitializeExtensionSyncService();
6021 syncer::FakeSyncChangeProcessor processor; 5848 syncer::FakeSyncChangeProcessor processor;
6022 extension_sync_service_->MergeDataAndStartSyncing( 5849 extension_sync_service()->MergeDataAndStartSyncing(
6023 syncer::EXTENSIONS, 5850 syncer::EXTENSIONS,
6024 syncer::SyncDataList(), 5851 syncer::SyncDataList(),
6025 scoped_ptr<syncer::SyncChangeProcessor>( 5852 scoped_ptr<syncer::SyncChangeProcessor>(
6026 new syncer::FakeSyncChangeProcessor), 5853 new syncer::FakeSyncChangeProcessor),
6027 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5854 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
6028 5855
6029 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5856 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
6030 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); 5857 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
6031 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 5858 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6032 5859
6033 sync_pb::EntitySpecifics specifics; 5860 sync_pb::EntitySpecifics specifics;
6034 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 5861 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
6035 ext_specifics->set_id(good_crx); 5862 ext_specifics->set_id(good_crx);
6036 ext_specifics->set_version( 5863 ext_specifics->set_version(
6037 service_->GetInstalledExtension(good_crx)->version()->GetString()); 5864 service()->GetInstalledExtension(good_crx)->version()->GetString());
6038 ext_specifics->set_enabled(false); 5865 ext_specifics->set_enabled(false);
6039 5866
6040 { 5867 {
6041 syncer::SyncData sync_data = 5868 syncer::SyncData sync_data =
6042 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5869 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6043 syncer::SyncChange sync_change(FROM_HERE, 5870 syncer::SyncChange sync_change(FROM_HERE,
6044 syncer::SyncChange::ACTION_UPDATE, 5871 syncer::SyncChange::ACTION_UPDATE,
6045 sync_data); 5872 sync_data);
6046 syncer::SyncChangeList list(1); 5873 syncer::SyncChangeList list(1);
6047 list[0] = sync_change; 5874 list[0] = sync_change;
6048 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5875 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6049 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5876 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6050 EXPECT_FALSE( 5877 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6051 extensions::util::IsIncognitoEnabled(good_crx, profile_.get()));
6052 } 5878 }
6053 5879
6054 { 5880 {
6055 ext_specifics->set_enabled(true); 5881 ext_specifics->set_enabled(true);
6056 ext_specifics->set_incognito_enabled(true); 5882 ext_specifics->set_incognito_enabled(true);
6057 syncer::SyncData sync_data = 5883 syncer::SyncData sync_data =
6058 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5884 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6059 syncer::SyncChange sync_change(FROM_HERE, 5885 syncer::SyncChange sync_change(FROM_HERE,
6060 syncer::SyncChange::ACTION_UPDATE, 5886 syncer::SyncChange::ACTION_UPDATE,
6061 sync_data); 5887 sync_data);
6062 syncer::SyncChangeList list(1); 5888 syncer::SyncChangeList list(1);
6063 list[0] = sync_change; 5889 list[0] = sync_change;
6064 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5890 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6065 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); 5891 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
6066 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 5892 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6067 } 5893 }
6068 5894
6069 { 5895 {
6070 ext_specifics->set_enabled(false); 5896 ext_specifics->set_enabled(false);
6071 ext_specifics->set_incognito_enabled(true); 5897 ext_specifics->set_incognito_enabled(true);
6072 syncer::SyncData sync_data = 5898 syncer::SyncData sync_data =
6073 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5899 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6074 syncer::SyncChange sync_change(FROM_HERE, 5900 syncer::SyncChange sync_change(FROM_HERE,
6075 syncer::SyncChange::ACTION_UPDATE, 5901 syncer::SyncChange::ACTION_UPDATE,
6076 sync_data); 5902 sync_data);
6077 syncer::SyncChangeList list(1); 5903 syncer::SyncChangeList list(1);
6078 list[0] = sync_change; 5904 list[0] = sync_change;
6079 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5905 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6080 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5906 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6081 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 5907 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6082 } 5908 }
6083 5909
6084 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); 5910 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx));
6085 } 5911 }
6086 5912
6087 TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) { 5913 TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) {
6088 InitializeExtensionServiceWithUpdater(); 5914 InitializeExtensionServiceWithUpdater();
6089 InitializeExtensionSyncService(); 5915 InitializeExtensionSyncService();
6090 syncer::FakeSyncChangeProcessor processor; 5916 syncer::FakeSyncChangeProcessor processor;
6091 extension_sync_service_->MergeDataAndStartSyncing( 5917 extension_sync_service()->MergeDataAndStartSyncing(
6092 syncer::EXTENSIONS, 5918 syncer::EXTENSIONS,
6093 syncer::SyncDataList(), 5919 syncer::SyncDataList(),
6094 scoped_ptr<syncer::SyncChangeProcessor>( 5920 scoped_ptr<syncer::SyncChangeProcessor>(
6095 new syncer::FakeSyncChangeProcessor), 5921 new syncer::FakeSyncChangeProcessor),
6096 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5922 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
6097 5923
6098 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5924 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
6099 TerminateExtension(good_crx); 5925 TerminateExtension(good_crx);
6100 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); 5926 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
6101 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 5927 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6102 5928
6103 sync_pb::EntitySpecifics specifics; 5929 sync_pb::EntitySpecifics specifics;
6104 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 5930 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
6105 ext_specifics->set_id(good_crx); 5931 ext_specifics->set_id(good_crx);
6106 ext_specifics->set_version( 5932 ext_specifics->set_version(
6107 service_->GetInstalledExtension(good_crx)->version()->GetString()); 5933 service()->GetInstalledExtension(good_crx)->version()->GetString());
6108 ext_specifics->set_enabled(false); 5934 ext_specifics->set_enabled(false);
6109 ext_specifics->set_incognito_enabled(true); 5935 ext_specifics->set_incognito_enabled(true);
6110 syncer::SyncData sync_data = 5936 syncer::SyncData sync_data =
6111 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5937 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6112 syncer::SyncChange sync_change(FROM_HERE, 5938 syncer::SyncChange sync_change(FROM_HERE,
6113 syncer::SyncChange::ACTION_UPDATE, 5939 syncer::SyncChange::ACTION_UPDATE,
6114 sync_data); 5940 sync_data);
6115 syncer::SyncChangeList list(1); 5941 syncer::SyncChangeList list(1);
6116 list[0] = sync_change; 5942 list[0] = sync_change;
6117 5943
6118 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5944 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6119 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5945 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6120 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 5946 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6121 5947
6122 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); 5948 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx));
6123 } 5949 }
6124 5950
6125 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { 5951 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) {
6126 InitializeExtensionServiceWithUpdater(); 5952 InitializeExtensionServiceWithUpdater();
6127 InitializeExtensionSyncService(); 5953 InitializeExtensionSyncService();
6128 syncer::FakeSyncChangeProcessor processor; 5954 syncer::FakeSyncChangeProcessor processor;
6129 extension_sync_service_->MergeDataAndStartSyncing( 5955 extension_sync_service()->MergeDataAndStartSyncing(
6130 syncer::EXTENSIONS, 5956 syncer::EXTENSIONS,
6131 syncer::SyncDataList(), 5957 syncer::SyncDataList(),
6132 scoped_ptr<syncer::SyncChangeProcessor>( 5958 scoped_ptr<syncer::SyncChangeProcessor>(
6133 new syncer::FakeSyncChangeProcessor), 5959 new syncer::FakeSyncChangeProcessor),
6134 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5960 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
6135 5961
6136 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5962 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
6137 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); 5963 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
6138 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 5964 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6139 5965
6140 sync_pb::EntitySpecifics specifics; 5966 sync_pb::EntitySpecifics specifics;
6141 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 5967 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
6142 ext_specifics->set_id(good_crx); 5968 ext_specifics->set_id(good_crx);
6143 ext_specifics->set_enabled(true); 5969 ext_specifics->set_enabled(true);
6144 5970
6145 { 5971 {
6146 ext_specifics->set_version( 5972 ext_specifics->set_version(
6147 service_->GetInstalledExtension(good_crx)->version()->GetString()); 5973 service()->GetInstalledExtension(good_crx)->version()->GetString());
6148 syncer::SyncData sync_data = 5974 syncer::SyncData sync_data =
6149 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5975 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6150 syncer::SyncChange sync_change(FROM_HERE, 5976 syncer::SyncChange sync_change(FROM_HERE,
6151 syncer::SyncChange::ACTION_UPDATE, 5977 syncer::SyncChange::ACTION_UPDATE,
6152 sync_data); 5978 sync_data);
6153 syncer::SyncChangeList list(1); 5979 syncer::SyncChangeList list(1);
6154 list[0] = sync_change; 5980 list[0] = sync_change;
6155 5981
6156 // Should do nothing if extension version == sync version. 5982 // Should do nothing if extension version == sync version.
6157 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5983 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6158 EXPECT_FALSE(service_->updater()->WillCheckSoon()); 5984 EXPECT_FALSE(service()->updater()->WillCheckSoon());
6159 } 5985 }
6160 5986
6161 // Should do nothing if extension version > sync version (but see 5987 // Should do nothing if extension version > sync version (but see
6162 // the TODO in ProcessExtensionSyncData). 5988 // the TODO in ProcessExtensionSyncData).
6163 { 5989 {
6164 ext_specifics->set_version("0.0.0.0"); 5990 ext_specifics->set_version("0.0.0.0");
6165 syncer::SyncData sync_data = 5991 syncer::SyncData sync_data =
6166 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5992 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6167 syncer::SyncChange sync_change(FROM_HERE, 5993 syncer::SyncChange sync_change(FROM_HERE,
6168 syncer::SyncChange::ACTION_UPDATE, 5994 syncer::SyncChange::ACTION_UPDATE,
6169 sync_data); 5995 sync_data);
6170 syncer::SyncChangeList list(1); 5996 syncer::SyncChangeList list(1);
6171 list[0] = sync_change; 5997 list[0] = sync_change;
6172 5998
6173 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5999 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6174 EXPECT_FALSE(service_->updater()->WillCheckSoon()); 6000 EXPECT_FALSE(service()->updater()->WillCheckSoon());
6175 } 6001 }
6176 6002
6177 // Should kick off an update if extension version < sync version. 6003 // Should kick off an update if extension version < sync version.
6178 { 6004 {
6179 ext_specifics->set_version("9.9.9.9"); 6005 ext_specifics->set_version("9.9.9.9");
6180 syncer::SyncData sync_data = 6006 syncer::SyncData sync_data =
6181 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 6007 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6182 syncer::SyncChange sync_change(FROM_HERE, 6008 syncer::SyncChange sync_change(FROM_HERE,
6183 syncer::SyncChange::ACTION_UPDATE, 6009 syncer::SyncChange::ACTION_UPDATE,
6184 sync_data); 6010 sync_data);
6185 syncer::SyncChangeList list(1); 6011 syncer::SyncChangeList list(1);
6186 list[0] = sync_change; 6012 list[0] = sync_change;
6187 6013
6188 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 6014 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6189 EXPECT_TRUE(service_->updater()->WillCheckSoon()); 6015 EXPECT_TRUE(service()->updater()->WillCheckSoon());
6190 } 6016 }
6191 6017
6192 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); 6018 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx));
6193 } 6019 }
6194 6020
6195 TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { 6021 TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) {
6196 InitializeExtensionServiceWithUpdater(); 6022 InitializeExtensionServiceWithUpdater();
6197 InitializeExtensionSyncService(); 6023 InitializeExtensionSyncService();
6198 syncer::FakeSyncChangeProcessor processor; 6024 syncer::FakeSyncChangeProcessor processor;
6199 extension_sync_service_->MergeDataAndStartSyncing( 6025 extension_sync_service()->MergeDataAndStartSyncing(
6200 syncer::EXTENSIONS, 6026 syncer::EXTENSIONS,
6201 syncer::SyncDataList(), 6027 syncer::SyncDataList(),
6202 scoped_ptr<syncer::SyncChangeProcessor>( 6028 scoped_ptr<syncer::SyncChangeProcessor>(
6203 new syncer::FakeSyncChangeProcessor), 6029 new syncer::FakeSyncChangeProcessor),
6204 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 6030 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
6205 6031
6206 sync_pb::EntitySpecifics specifics; 6032 sync_pb::EntitySpecifics specifics;
6207 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 6033 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
6208 ext_specifics->set_id(good_crx); 6034 ext_specifics->set_id(good_crx);
6209 ext_specifics->set_enabled(false); 6035 ext_specifics->set_enabled(false);
6210 ext_specifics->set_incognito_enabled(true); 6036 ext_specifics->set_incognito_enabled(true);
6211 ext_specifics->set_update_url("http://www.google.com/"); 6037 ext_specifics->set_update_url("http://www.google.com/");
6212 ext_specifics->set_version("1.2.3.4"); 6038 ext_specifics->set_version("1.2.3.4");
6213 syncer::SyncData sync_data = 6039 syncer::SyncData sync_data =
6214 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 6040 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6215 syncer::SyncChange sync_change(FROM_HERE, 6041 syncer::SyncChange sync_change(FROM_HERE,
6216 syncer::SyncChange::ACTION_UPDATE, 6042 syncer::SyncChange::ACTION_UPDATE,
6217 sync_data); 6043 sync_data);
6218 syncer::SyncChangeList list(1); 6044 syncer::SyncChangeList list(1);
6219 list[0] = sync_change; 6045 list[0] = sync_change;
6220 6046
6221 6047 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
6222 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); 6048 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6223 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 6049 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6224 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 6050 EXPECT_TRUE(service()->updater()->WillCheckSoon());
6225 EXPECT_TRUE(service_->updater()->WillCheckSoon()); 6051 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6226 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 6052 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6227 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get()));
6228 6053
6229 const extensions::PendingExtensionInfo* info; 6054 const extensions::PendingExtensionInfo* info;
6230 EXPECT_TRUE((info = service_->pending_extension_manager()-> 6055 EXPECT_TRUE(
6231 GetById(good_crx))); 6056 (info = service()->pending_extension_manager()->GetById(good_crx)));
6232 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); 6057 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec());
6233 EXPECT_TRUE(info->is_from_sync()); 6058 EXPECT_TRUE(info->is_from_sync());
6234 EXPECT_TRUE(info->install_silently()); 6059 EXPECT_TRUE(info->install_silently());
6235 EXPECT_EQ(Manifest::INTERNAL, info->install_source()); 6060 EXPECT_EQ(Manifest::INTERNAL, info->install_source());
6236 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. 6061 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|.
6237 } 6062 }
6238 6063
6239 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { 6064 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) {
6240 InitializeEmptyExtensionService(); 6065 InitializeEmptyExtensionService();
6241 6066
6242 base::FilePath path = data_dir_.AppendASCII("good.crx"); 6067 base::FilePath path = data_dir().AppendASCII("good.crx");
6243 InstallCRX(path, INSTALL_NEW); 6068 InstallCRX(path, INSTALL_NEW);
6244 ValidatePrefKeyCount(1u); 6069 ValidatePrefKeyCount(1u);
6245 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 6070 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
6246 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 6071 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
6247 6072
6248 extensions::PendingExtensionManager* pending = 6073 extensions::PendingExtensionManager* pending =
6249 service_->pending_extension_manager(); 6074 service()->pending_extension_manager();
6250 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6075 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6251 6076
6252 // Skip install when the location is the same. 6077 // Skip install when the location is the same.
6253 EXPECT_FALSE(service_->OnExternalExtensionUpdateUrlFound(kGoodId, 6078 EXPECT_FALSE(
6254 std::string(), 6079 service()->OnExternalExtensionUpdateUrlFound(kGoodId,
6255 GURL(kGoodUpdateURL), 6080 std::string(),
6256 Manifest::INTERNAL, 6081 GURL(kGoodUpdateURL),
6257 Extension::NO_FLAGS, 6082 Manifest::INTERNAL,
6258 false)); 6083 Extension::NO_FLAGS,
6084 false));
6259 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6085 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6260 6086
6261 // Install when the location has higher priority. 6087 // Install when the location has higher priority.
6262 EXPECT_TRUE(service_->OnExternalExtensionUpdateUrlFound( 6088 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(
6263 kGoodId, 6089 kGoodId,
6264 std::string(), 6090 std::string(),
6265 GURL(kGoodUpdateURL), 6091 GURL(kGoodUpdateURL),
6266 Manifest::EXTERNAL_POLICY_DOWNLOAD, 6092 Manifest::EXTERNAL_POLICY_DOWNLOAD,
6267 Extension::NO_FLAGS, 6093 Extension::NO_FLAGS,
6268 false)); 6094 false));
6269 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6095 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6270 6096
6271 // Try the low priority again. Should be rejected. 6097 // Try the low priority again. Should be rejected.
6272 EXPECT_FALSE(service_->OnExternalExtensionUpdateUrlFound( 6098 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(
6273 kGoodId, 6099 kGoodId,
6274 std::string(), 6100 std::string(),
6275 GURL(kGoodUpdateURL), 6101 GURL(kGoodUpdateURL),
6276 Manifest::EXTERNAL_PREF_DOWNLOAD, 6102 Manifest::EXTERNAL_PREF_DOWNLOAD,
6277 Extension::NO_FLAGS, 6103 Extension::NO_FLAGS,
6278 false)); 6104 false));
6279 // The existing record should still be present in the pending extension 6105 // The existing record should still be present in the pending extension
6280 // manager. 6106 // manager.
6281 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6107 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6282 6108
6283 pending->Remove(kGoodId); 6109 pending->Remove(kGoodId);
6284 6110
6285 // Skip install when the location has the same priority as the installed 6111 // Skip install when the location has the same priority as the installed
6286 // location. 6112 // location.
6287 EXPECT_FALSE(service_->OnExternalExtensionUpdateUrlFound(kGoodId, 6113 EXPECT_FALSE(
6288 std::string(), 6114 service()->OnExternalExtensionUpdateUrlFound(kGoodId,
6289 GURL(kGoodUpdateURL), 6115 std::string(),
6290 Manifest::INTERNAL, 6116 GURL(kGoodUpdateURL),
6291 Extension::NO_FLAGS, 6117 Manifest::INTERNAL,
6292 false)); 6118 Extension::NO_FLAGS,
6119 false));
6293 6120
6294 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6121 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6295 } 6122 }
6296 6123
6297 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { 6124 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) {
6298 Version older_version("0.1.0.0"); 6125 Version older_version("0.1.0.0");
6299 Version newer_version("2.0.0.0"); 6126 Version newer_version("2.0.0.0");
6300 6127
6301 // We don't want the extension to be installed. A path that doesn't 6128 // We don't want the extension to be installed. A path that doesn't
6302 // point to a valid CRX ensures this. 6129 // point to a valid CRX ensures this.
(...skipping 13 matching lines...) Expand all
6316 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, 6143 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY,
6317 Manifest::EXTERNAL_PREF)); 6144 Manifest::EXTERNAL_PREF));
6318 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, 6145 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY,
6319 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, 6146 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY,
6320 Manifest::INTERNAL)); 6147 Manifest::INTERNAL));
6321 ASSERT_EQ(Manifest::EXTERNAL_PREF, 6148 ASSERT_EQ(Manifest::EXTERNAL_PREF,
6322 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, 6149 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF,
6323 Manifest::INTERNAL)); 6150 Manifest::INTERNAL));
6324 6151
6325 extensions::PendingExtensionManager* pending = 6152 extensions::PendingExtensionManager* pending =
6326 service_->pending_extension_manager(); 6153 service()->pending_extension_manager();
6327 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6154 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6328 6155
6329 { 6156 {
6330 // Simulate an external source adding the extension as INTERNAL. 6157 // Simulate an external source adding the extension as INTERNAL.
6331 content::WindowedNotificationObserver observer( 6158 content::WindowedNotificationObserver observer(
6332 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6159 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6333 content::NotificationService::AllSources()); 6160 content::NotificationService::AllSources());
6334 EXPECT_TRUE( 6161 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6335 service_->OnExternalExtensionFileFound( 6162 &older_version,
6336 kGoodId, &older_version, kInvalidPathToCrx, 6163 kInvalidPathToCrx,
6337 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 6164 Manifest::INTERNAL,
6165 kCreationFlags,
6166 kDontMarkAcknowledged));
6338 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6167 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6339 observer.Wait(); 6168 observer.Wait();
6340 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); 6169 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6341 } 6170 }
6342 6171
6343 { 6172 {
6344 // Simulate an external source adding the extension as EXTERNAL_PREF. 6173 // Simulate an external source adding the extension as EXTERNAL_PREF.
6345 content::WindowedNotificationObserver observer( 6174 content::WindowedNotificationObserver observer(
6346 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6175 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6347 content::NotificationService::AllSources()); 6176 content::NotificationService::AllSources());
6348 EXPECT_TRUE( 6177 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6349 service_->OnExternalExtensionFileFound( 6178 &older_version,
6350 kGoodId, &older_version, kInvalidPathToCrx, 6179 kInvalidPathToCrx,
6351 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6180 Manifest::EXTERNAL_PREF,
6181 kCreationFlags,
6182 kDontMarkAcknowledged));
6352 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6183 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6353 observer.Wait(); 6184 observer.Wait();
6354 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); 6185 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6355 } 6186 }
6356 6187
6357 // Simulate an external source adding as EXTERNAL_PREF again. 6188 // Simulate an external source adding as EXTERNAL_PREF again.
6358 // This is rejected because the version and the location are the same as 6189 // This is rejected because the version and the location are the same as
6359 // the previous installation, which is still pending. 6190 // the previous installation, which is still pending.
6360 EXPECT_FALSE( 6191 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6361 service_->OnExternalExtensionFileFound( 6192 &older_version,
6362 kGoodId, &older_version, kInvalidPathToCrx, 6193 kInvalidPathToCrx,
6363 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6194 Manifest::EXTERNAL_PREF,
6195 kCreationFlags,
6196 kDontMarkAcknowledged));
6364 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6197 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6365 6198
6366 // Try INTERNAL again. Should fail. 6199 // Try INTERNAL again. Should fail.
6367 EXPECT_FALSE( 6200 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6368 service_->OnExternalExtensionFileFound( 6201 &older_version,
6369 kGoodId, &older_version, kInvalidPathToCrx, 6202 kInvalidPathToCrx,
6370 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 6203 Manifest::INTERNAL,
6204 kCreationFlags,
6205 kDontMarkAcknowledged));
6371 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6206 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6372 6207
6373 { 6208 {
6374 // Now the registry adds the extension. 6209 // Now the registry adds the extension.
6375 content::WindowedNotificationObserver observer( 6210 content::WindowedNotificationObserver observer(
6376 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6211 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6377 content::NotificationService::AllSources()); 6212 content::NotificationService::AllSources());
6378 EXPECT_TRUE( 6213 EXPECT_TRUE(
6379 service_->OnExternalExtensionFileFound(kGoodId, 6214 service()->OnExternalExtensionFileFound(kGoodId,
6380 &older_version, 6215 &older_version,
6381 kInvalidPathToCrx, 6216 kInvalidPathToCrx,
6382 Manifest::EXTERNAL_REGISTRY, 6217 Manifest::EXTERNAL_REGISTRY,
6383 kCreationFlags, 6218 kCreationFlags,
6384 kDontMarkAcknowledged)); 6219 kDontMarkAcknowledged));
6385 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6220 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6386 observer.Wait(); 6221 observer.Wait();
6387 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); 6222 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6388 } 6223 }
6389 6224
6390 // Registry outranks both external pref and internal, so both fail. 6225 // Registry outranks both external pref and internal, so both fail.
6391 EXPECT_FALSE( 6226 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6392 service_->OnExternalExtensionFileFound( 6227 &older_version,
6393 kGoodId, &older_version, kInvalidPathToCrx, 6228 kInvalidPathToCrx,
6394 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6229 Manifest::EXTERNAL_PREF,
6230 kCreationFlags,
6231 kDontMarkAcknowledged));
6395 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6232 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6396 6233
6397 EXPECT_FALSE( 6234 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6398 service_->OnExternalExtensionFileFound( 6235 &older_version,
6399 kGoodId, &older_version, kInvalidPathToCrx, 6236 kInvalidPathToCrx,
6400 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 6237 Manifest::INTERNAL,
6238 kCreationFlags,
6239 kDontMarkAcknowledged));
6401 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6240 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6402 6241
6403 pending->Remove(kGoodId); 6242 pending->Remove(kGoodId);
6404 6243
6405 // Install the extension. 6244 // Install the extension.
6406 base::FilePath path = data_dir_.AppendASCII("good.crx"); 6245 base::FilePath path = data_dir().AppendASCII("good.crx");
6407 const Extension* ext = InstallCRX(path, INSTALL_NEW); 6246 const Extension* ext = InstallCRX(path, INSTALL_NEW);
6408 ValidatePrefKeyCount(1u); 6247 ValidatePrefKeyCount(1u);
6409 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 6248 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
6410 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 6249 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
6411 6250
6412 // Now test the logic of OnExternalExtensionFileFound() when the extension 6251 // Now test the logic of OnExternalExtensionFileFound() when the extension
6413 // being added is already installed. 6252 // being added is already installed.
6414 6253
6415 // Tests assume |older_version| is less than the installed version, and 6254 // Tests assume |older_version| is less than the installed version, and
6416 // |newer_version| is greater. Verify this: 6255 // |newer_version| is greater. Verify this:
6417 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString())); 6256 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString()));
6418 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString())); 6257 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString()));
6419 6258
6420 // An external install for the same location should fail if the version is 6259 // An external install for the same location should fail if the version is
6421 // older, or the same, and succeed if the version is newer. 6260 // older, or the same, and succeed if the version is newer.
6422 6261
6423 // Older than the installed version... 6262 // Older than the installed version...
6424 EXPECT_FALSE( 6263 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6425 service_->OnExternalExtensionFileFound( 6264 &older_version,
6426 kGoodId, &older_version, kInvalidPathToCrx, 6265 kInvalidPathToCrx,
6427 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 6266 Manifest::INTERNAL,
6267 kCreationFlags,
6268 kDontMarkAcknowledged));
6428 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6269 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6429 6270
6430 // Same version as the installed version... 6271 // Same version as the installed version...
6431 EXPECT_FALSE( 6272 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6432 service_->OnExternalExtensionFileFound( 6273 ext->version(),
6433 kGoodId, ext->version(), kInvalidPathToCrx, 6274 kInvalidPathToCrx,
6434 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 6275 Manifest::INTERNAL,
6276 kCreationFlags,
6277 kDontMarkAcknowledged));
6435 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6278 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6436 6279
6437 // Newer than the installed version... 6280 // Newer than the installed version...
6438 EXPECT_TRUE( 6281 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6439 service_->OnExternalExtensionFileFound( 6282 &newer_version,
6440 kGoodId, &newer_version, kInvalidPathToCrx, 6283 kInvalidPathToCrx,
6441 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 6284 Manifest::INTERNAL,
6285 kCreationFlags,
6286 kDontMarkAcknowledged));
6442 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6287 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6443 6288
6444 // An external install for a higher priority install source should succeed 6289 // An external install for a higher priority install source should succeed
6445 // if the version is greater. |older_version| is not... 6290 // if the version is greater. |older_version| is not...
6446 EXPECT_FALSE( 6291 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6447 service_->OnExternalExtensionFileFound( 6292 &older_version,
6448 kGoodId, &older_version, kInvalidPathToCrx, 6293 kInvalidPathToCrx,
6449 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6294 Manifest::EXTERNAL_PREF,
6295 kCreationFlags,
6296 kDontMarkAcknowledged));
6450 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6297 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6451 6298
6452 // |newer_version| is newer. 6299 // |newer_version| is newer.
6453 EXPECT_TRUE( 6300 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6454 service_->OnExternalExtensionFileFound( 6301 &newer_version,
6455 kGoodId, &newer_version, kInvalidPathToCrx, 6302 kInvalidPathToCrx,
6456 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6303 Manifest::EXTERNAL_PREF,
6304 kCreationFlags,
6305 kDontMarkAcknowledged));
6457 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6306 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6458 6307
6459 // An external install for an even higher priority install source should 6308 // An external install for an even higher priority install source should
6460 // succeed if the version is greater. 6309 // succeed if the version is greater.
6461 EXPECT_TRUE( 6310 EXPECT_TRUE(
6462 service_->OnExternalExtensionFileFound( 6311 service()->OnExternalExtensionFileFound(kGoodId,
6463 kGoodId, &newer_version, kInvalidPathToCrx, 6312 &newer_version,
6464 Manifest::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); 6313 kInvalidPathToCrx,
6314 Manifest::EXTERNAL_REGISTRY,
6315 kCreationFlags,
6316 kDontMarkAcknowledged));
6465 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6317 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6466 6318
6467 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, 6319 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY,
6468 // adding from external pref will now fail. 6320 // adding from external pref will now fail.
6469 EXPECT_FALSE( 6321 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6470 service_->OnExternalExtensionFileFound( 6322 &newer_version,
6471 kGoodId, &newer_version, kInvalidPathToCrx, 6323 kInvalidPathToCrx,
6472 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6324 Manifest::EXTERNAL_PREF,
6325 kCreationFlags,
6326 kDontMarkAcknowledged));
6473 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6327 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6474 } 6328 }
6475 6329
6476 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { 6330 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) {
6477 Version kVersion123("1.2.3"); 6331 Version kVersion123("1.2.3");
6478 Version kVersion124("1.2.4"); 6332 Version kVersion124("1.2.4");
6479 Version kVersion125("1.2.5"); 6333 Version kVersion125("1.2.5");
6480 const base::FilePath kInvalidPathToCrx = base::FilePath(); 6334 const base::FilePath kInvalidPathToCrx = base::FilePath();
6481 const int kCreationFlags = 0; 6335 const int kCreationFlags = 0;
6482 const bool kDontMarkAcknowledged = false; 6336 const bool kDontMarkAcknowledged = false;
6483 6337
6484 InitializeEmptyExtensionService(); 6338 InitializeEmptyExtensionService();
6485 6339
6486 extensions::PendingExtensionManager* pending = 6340 extensions::PendingExtensionManager* pending =
6487 service_->pending_extension_manager(); 6341 service()->pending_extension_manager();
6488 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6342 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6489 6343
6490 // An external provider starts installing from a local crx. 6344 // An external provider starts installing from a local crx.
6491 EXPECT_TRUE( 6345 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6492 service_->OnExternalExtensionFileFound( 6346 &kVersion123,
6493 kGoodId, &kVersion123, kInvalidPathToCrx, 6347 kInvalidPathToCrx,
6494 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6348 Manifest::EXTERNAL_PREF,
6349 kCreationFlags,
6350 kDontMarkAcknowledged));
6495 const extensions::PendingExtensionInfo* info; 6351 const extensions::PendingExtensionInfo* info;
6496 EXPECT_TRUE((info = pending->GetById(kGoodId))); 6352 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6497 EXPECT_TRUE(info->version().IsValid()); 6353 EXPECT_TRUE(info->version().IsValid());
6498 EXPECT_TRUE(info->version().Equals(kVersion123)); 6354 EXPECT_TRUE(info->version().Equals(kVersion123));
6499 6355
6500 // Adding a newer version overrides the currently pending version. 6356 // Adding a newer version overrides the currently pending version.
6501 EXPECT_TRUE( 6357 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6502 service_->OnExternalExtensionFileFound( 6358 &kVersion124,
6503 kGoodId, &kVersion124, kInvalidPathToCrx, 6359 kInvalidPathToCrx,
6504 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6360 Manifest::EXTERNAL_PREF,
6361 kCreationFlags,
6362 kDontMarkAcknowledged));
6505 EXPECT_TRUE((info = pending->GetById(kGoodId))); 6363 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6506 EXPECT_TRUE(info->version().IsValid()); 6364 EXPECT_TRUE(info->version().IsValid());
6507 EXPECT_TRUE(info->version().Equals(kVersion124)); 6365 EXPECT_TRUE(info->version().Equals(kVersion124));
6508 6366
6509 // Adding an older version fails. 6367 // Adding an older version fails.
6510 EXPECT_FALSE( 6368 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6511 service_->OnExternalExtensionFileFound( 6369 &kVersion123,
6512 kGoodId, &kVersion123, kInvalidPathToCrx, 6370 kInvalidPathToCrx,
6513 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6371 Manifest::EXTERNAL_PREF,
6372 kCreationFlags,
6373 kDontMarkAcknowledged));
6514 EXPECT_TRUE((info = pending->GetById(kGoodId))); 6374 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6515 EXPECT_TRUE(info->version().IsValid()); 6375 EXPECT_TRUE(info->version().IsValid());
6516 EXPECT_TRUE(info->version().Equals(kVersion124)); 6376 EXPECT_TRUE(info->version().Equals(kVersion124));
6517 6377
6518 // Adding an older version fails even when coming from a higher-priority 6378 // Adding an older version fails even when coming from a higher-priority
6519 // location. 6379 // location.
6520 EXPECT_FALSE( 6380 EXPECT_FALSE(
6521 service_->OnExternalExtensionFileFound( 6381 service()->OnExternalExtensionFileFound(kGoodId,
6522 kGoodId, &kVersion123, kInvalidPathToCrx, 6382 &kVersion123,
6523 Manifest::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); 6383 kInvalidPathToCrx,
6384 Manifest::EXTERNAL_REGISTRY,
6385 kCreationFlags,
6386 kDontMarkAcknowledged));
6524 EXPECT_TRUE((info = pending->GetById(kGoodId))); 6387 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6525 EXPECT_TRUE(info->version().IsValid()); 6388 EXPECT_TRUE(info->version().IsValid());
6526 EXPECT_TRUE(info->version().Equals(kVersion124)); 6389 EXPECT_TRUE(info->version().Equals(kVersion124));
6527 6390
6528 // Adding the latest version from the webstore overrides a specific version. 6391 // Adding the latest version from the webstore overrides a specific version.
6529 GURL kUpdateUrl("http://example.com/update"); 6392 GURL kUpdateUrl("http://example.com/update");
6530 EXPECT_TRUE(service_->OnExternalExtensionUpdateUrlFound( 6393 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(
6531 kGoodId, 6394 kGoodId,
6532 std::string(), 6395 std::string(),
6533 kUpdateUrl, 6396 kUpdateUrl,
6534 Manifest::EXTERNAL_POLICY_DOWNLOAD, 6397 Manifest::EXTERNAL_POLICY_DOWNLOAD,
6535 Extension::NO_FLAGS, 6398 Extension::NO_FLAGS,
6536 false)); 6399 false));
6537 EXPECT_TRUE((info = pending->GetById(kGoodId))); 6400 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6538 EXPECT_FALSE(info->version().IsValid()); 6401 EXPECT_FALSE(info->version().IsValid());
6539 } 6402 }
6540 6403
6541 // This makes sure we can package and install CRX files that use whitelisted 6404 // This makes sure we can package and install CRX files that use whitelisted
6542 // permissions. 6405 // permissions.
6543 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { 6406 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) {
6544 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; 6407 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk";
6545 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 6408 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
6546 extensions::switches::kWhitelistedExtensionID, test_id); 6409 extensions::switches::kWhitelistedExtensionID, test_id);
6547 6410
6548 InitializeEmptyExtensionService(); 6411 InitializeEmptyExtensionService();
6549 base::FilePath path = data_dir_ 6412 base::FilePath path = data_dir().AppendASCII("permissions");
6550 .AppendASCII("permissions");
6551 base::FilePath pem_path = path 6413 base::FilePath pem_path = path
6552 .AppendASCII("whitelist.pem"); 6414 .AppendASCII("whitelist.pem");
6553 path = path 6415 path = path
6554 .AppendASCII("whitelist"); 6416 .AppendASCII("whitelist");
6555 6417
6556 const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); 6418 const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW);
6557 EXPECT_EQ(0u, GetErrors().size()); 6419 EXPECT_EQ(0u, GetErrors().size());
6558 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 6420 ASSERT_EQ(1u, registry()->enabled_extensions().size());
6559 EXPECT_EQ(test_id, extension->id()); 6421 EXPECT_EQ(test_id, extension->id());
6560 } 6422 }
6561 6423
6562 // Test that when multiple sources try to install an extension, 6424 // Test that when multiple sources try to install an extension,
6563 // we consistently choose the right one. To make tests easy to read, 6425 // we consistently choose the right one. To make tests easy to read,
6564 // methods that fake requests to install crx files in several ways 6426 // methods that fake requests to install crx files in several ways
6565 // are provided. 6427 // are provided.
6566 class ExtensionSourcePriorityTest : public ExtensionServiceTest { 6428 class ExtensionSourcePriorityTest : public ExtensionServiceTest {
6567 public: 6429 public:
6568 virtual void SetUp() { 6430 virtual void SetUp() {
6569 ExtensionServiceTest::SetUp(); 6431 ExtensionServiceTest::SetUp();
6570 6432
6571 // All tests use a single extension. Put the id and path in member vars 6433 // All tests use a single extension. Put the id and path in member vars
6572 // that all methods can read. 6434 // that all methods can read.
6573 crx_id_ = kGoodId; 6435 crx_id_ = kGoodId;
6574 crx_path_ = data_dir_.AppendASCII("good.crx"); 6436 crx_path_ = data_dir().AppendASCII("good.crx");
6575 } 6437 }
6576 6438
6577 // Fake an external source adding a URL to fetch an extension from. 6439 // Fake an external source adding a URL to fetch an extension from.
6578 bool AddPendingExternalPrefUrl() { 6440 bool AddPendingExternalPrefUrl() {
6579 return service_->pending_extension_manager()->AddFromExternalUpdateUrl( 6441 return service()->pending_extension_manager()->AddFromExternalUpdateUrl(
6580 crx_id_, 6442 crx_id_,
6581 std::string(), 6443 std::string(),
6582 GURL(), 6444 GURL(),
6583 Manifest::EXTERNAL_PREF_DOWNLOAD, 6445 Manifest::EXTERNAL_PREF_DOWNLOAD,
6584 Extension::NO_FLAGS, 6446 Extension::NO_FLAGS,
6585 false); 6447 false);
6586 } 6448 }
6587 6449
6588 // Fake an external file from external_extensions.json. 6450 // Fake an external file from external_extensions.json.
6589 bool AddPendingExternalPrefFileInstall() { 6451 bool AddPendingExternalPrefFileInstall() {
6590 Version version("1.0.0.0"); 6452 Version version("1.0.0.0");
6591 6453
6592 return service_->OnExternalExtensionFileFound( 6454 return service()->OnExternalExtensionFileFound(crx_id_,
6593 crx_id_, &version, crx_path_, Manifest::EXTERNAL_PREF, 6455 &version,
6594 Extension::NO_FLAGS, false); 6456 crx_path_,
6457 Manifest::EXTERNAL_PREF,
6458 Extension::NO_FLAGS,
6459 false);
6595 } 6460 }
6596 6461
6597 // Fake a request from sync to install an extension. 6462 // Fake a request from sync to install an extension.
6598 bool AddPendingSyncInstall() { 6463 bool AddPendingSyncInstall() {
6599 return service_->pending_extension_manager()->AddFromSync( 6464 return service()->pending_extension_manager()->AddFromSync(
6600 crx_id_, 6465 crx_id_,
6601 GURL(kGoodUpdateURL), 6466 GURL(kGoodUpdateURL),
6602 &IsExtension, 6467 &IsExtension,
6603 kGoodInstallSilently, 6468 kGoodInstallSilently,
6604 kGoodRemoteInstall); 6469 kGoodRemoteInstall);
6605 } 6470 }
6606 6471
6607 // Fake a policy install. 6472 // Fake a policy install.
6608 bool AddPendingPolicyInstall() { 6473 bool AddPendingPolicyInstall() {
6609 // Get path to the CRX with id |kGoodId|. 6474 // Get path to the CRX with id |kGoodId|.
6610 return service_->OnExternalExtensionUpdateUrlFound( 6475 return service()->OnExternalExtensionUpdateUrlFound(
6611 crx_id_, 6476 crx_id_,
6612 std::string(), 6477 std::string(),
6613 GURL(), 6478 GURL(),
6614 Manifest::EXTERNAL_POLICY_DOWNLOAD, 6479 Manifest::EXTERNAL_POLICY_DOWNLOAD,
6615 Extension::NO_FLAGS, 6480 Extension::NO_FLAGS,
6616 false); 6481 false);
6617 } 6482 }
6618 6483
6619 // Get the install source of a pending extension. 6484 // Get the install source of a pending extension.
6620 Manifest::Location GetPendingLocation() { 6485 Manifest::Location GetPendingLocation() {
6621 const extensions::PendingExtensionInfo* info; 6486 const extensions::PendingExtensionInfo* info;
6622 EXPECT_TRUE((info = service_->pending_extension_manager()-> 6487 EXPECT_TRUE(
6623 GetById(crx_id_))); 6488 (info = service()->pending_extension_manager()->GetById(crx_id_)));
6624 return info->install_source(); 6489 return info->install_source();
6625 } 6490 }
6626 6491
6627 // Is an extension pending from a sync request? 6492 // Is an extension pending from a sync request?
6628 bool GetPendingIsFromSync() { 6493 bool GetPendingIsFromSync() {
6629 const extensions::PendingExtensionInfo* info; 6494 const extensions::PendingExtensionInfo* info;
6630 EXPECT_TRUE((info = service_->pending_extension_manager()-> 6495 EXPECT_TRUE(
6631 GetById(crx_id_))); 6496 (info = service()->pending_extension_manager()->GetById(crx_id_)));
6632 return info->is_from_sync(); 6497 return info->is_from_sync();
6633 } 6498 }
6634 6499
6635 // Is the CRX id these tests use pending? 6500 // Is the CRX id these tests use pending?
6636 bool IsCrxPending() { 6501 bool IsCrxPending() {
6637 return service_->pending_extension_manager()->IsIdPending(crx_id_); 6502 return service()->pending_extension_manager()->IsIdPending(crx_id_);
6638 } 6503 }
6639 6504
6640 // Is an extension installed? 6505 // Is an extension installed?
6641 bool IsCrxInstalled() { 6506 bool IsCrxInstalled() {
6642 return (service_->GetExtensionById(crx_id_, true) != NULL); 6507 return (service()->GetExtensionById(crx_id_, true) != NULL);
6643 } 6508 }
6644 6509
6645 protected: 6510 protected:
6646 // All tests use a single extension. Making the id and path member 6511 // All tests use a single extension. Making the id and path member
6647 // vars avoids pasing the same argument to every method. 6512 // vars avoids pasing the same argument to every method.
6648 std::string crx_id_; 6513 std::string crx_id_;
6649 base::FilePath crx_path_; 6514 base::FilePath crx_path_;
6650 }; 6515 };
6651 6516
6652 // Test that a pending request for installation of an external CRX from 6517 // Test that a pending request for installation of an external CRX from
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
6732 ASSERT_FALSE(AddPendingSyncInstall()); 6597 ASSERT_FALSE(AddPendingSyncInstall());
6733 } 6598 }
6734 6599
6735 // Test that installing an external extension displays a GlobalError. 6600 // Test that installing an external extension displays a GlobalError.
6736 TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) { 6601 TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) {
6737 FeatureSwitch::ScopedOverride prompt( 6602 FeatureSwitch::ScopedOverride prompt(
6738 FeatureSwitch::prompt_for_external_extensions(), true); 6603 FeatureSwitch::prompt_for_external_extensions(), true);
6739 6604
6740 InitializeEmptyExtensionService(); 6605 InitializeEmptyExtensionService();
6741 MockExtensionProvider* provider = 6606 MockExtensionProvider* provider =
6742 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6607 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6743 AddMockExternalProvider(provider); 6608 AddMockExternalProvider(provider);
6744 6609
6745 service_->UpdateExternalExtensionAlert(); 6610 service()->UpdateExternalExtensionAlert();
6746 // Should return false, meaning there aren't any extensions that the user 6611 // Should return false, meaning there aren't any extensions that the user
6747 // needs to know about. 6612 // needs to know about.
6748 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6613 EXPECT_FALSE(extensions::HasExternalInstallError(service()));
6749 6614
6750 // This is a normal extension, installed normally. 6615 // This is a normal extension, installed normally.
6751 // This should NOT trigger an alert. 6616 // This should NOT trigger an alert.
6752 set_extensions_enabled(true); 6617 service()->set_extensions_enabled(true);
6753 base::FilePath path = data_dir_.AppendASCII("good.crx"); 6618 base::FilePath path = data_dir().AppendASCII("good.crx");
6754 InstallCRX(path, INSTALL_NEW); 6619 InstallCRX(path, INSTALL_NEW);
6755 6620
6756 service_->CheckForExternalUpdates(); 6621 service()->CheckForExternalUpdates();
6757 base::RunLoop().RunUntilIdle(); 6622 base::RunLoop().RunUntilIdle();
6758 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6623 EXPECT_FALSE(extensions::HasExternalInstallError(service()));
6759 6624
6760 // A hosted app, installed externally. 6625 // A hosted app, installed externally.
6761 // This should NOT trigger an alert. 6626 // This should NOT trigger an alert.
6762 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 6627 provider->UpdateOrAddExtension(
6763 data_dir_.AppendASCII("hosted_app.crx")); 6628 hosted_app, "1.0.0.0", data_dir().AppendASCII("hosted_app.crx"));
6764 6629
6765 content::WindowedNotificationObserver observer( 6630 content::WindowedNotificationObserver observer(
6766 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6631 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6767 content::NotificationService::AllSources()); 6632 content::NotificationService::AllSources());
6768 service_->CheckForExternalUpdates(); 6633 service()->CheckForExternalUpdates();
6769 observer.Wait(); 6634 observer.Wait();
6770 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6635 EXPECT_FALSE(extensions::HasExternalInstallError(service()));
6771 6636
6772 // Another normal extension, but installed externally. 6637 // Another normal extension, but installed externally.
6773 // This SHOULD trigger an alert. 6638 // This SHOULD trigger an alert.
6774 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 6639 provider->UpdateOrAddExtension(
6775 data_dir_.AppendASCII("page_action.crx")); 6640 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
6776 6641
6777 content::WindowedNotificationObserver observer2( 6642 content::WindowedNotificationObserver observer2(
6778 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6643 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6779 content::NotificationService::AllSources()); 6644 content::NotificationService::AllSources());
6780 service_->CheckForExternalUpdates(); 6645 service()->CheckForExternalUpdates();
6781 observer2.Wait(); 6646 observer2.Wait();
6782 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6647 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6783 } 6648 }
6784 6649
6785 // Test that external extensions are initially disabled, and that enabling 6650 // Test that external extensions are initially disabled, and that enabling
6786 // them clears the prompt. 6651 // them clears the prompt.
6787 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { 6652 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) {
6788 FeatureSwitch::ScopedOverride prompt( 6653 FeatureSwitch::ScopedOverride prompt(
6789 FeatureSwitch::prompt_for_external_extensions(), true); 6654 FeatureSwitch::prompt_for_external_extensions(), true);
6790 6655
6791 InitializeEmptyExtensionService(); 6656 InitializeEmptyExtensionService();
6792 MockExtensionProvider* provider = 6657 MockExtensionProvider* provider =
6793 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6658 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6794 AddMockExternalProvider(provider); 6659 AddMockExternalProvider(provider);
6795 6660
6796 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 6661 provider->UpdateOrAddExtension(
6797 data_dir_.AppendASCII("page_action.crx")); 6662 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
6798 6663
6799 content::WindowedNotificationObserver observer( 6664 content::WindowedNotificationObserver observer(
6800 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6665 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6801 content::NotificationService::AllSources()); 6666 content::NotificationService::AllSources());
6802 service_->CheckForExternalUpdates(); 6667 service()->CheckForExternalUpdates();
6803 observer.Wait(); 6668 observer.Wait();
6804 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6669 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6805 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); 6670 EXPECT_FALSE(service()->IsExtensionEnabled(page_action));
6806 6671
6807 const Extension* extension = 6672 const Extension* extension =
6808 registry_->disabled_extensions().GetByID(page_action); 6673 registry()->disabled_extensions().GetByID(page_action);
6809 EXPECT_TRUE(extension); 6674 EXPECT_TRUE(extension);
6810 EXPECT_EQ(page_action, extension->id()); 6675 EXPECT_EQ(page_action, extension->id());
6811 6676
6812 service_->EnableExtension(page_action); 6677 service()->EnableExtension(page_action);
6813 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6678 EXPECT_FALSE(extensions::HasExternalInstallError(service()));
6814 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); 6679 EXPECT_TRUE(service()->IsExtensionEnabled(page_action));
6815 } 6680 }
6816 6681
6817 // Test that installing multiple external extensions works. 6682 // Test that installing multiple external extensions works.
6818 // Flaky on windows; http://crbug.com/295757 . 6683 // Flaky on windows; http://crbug.com/295757 .
6819 #if defined(OS_WIN) 6684 #if defined(OS_WIN)
6820 #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple 6685 #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple
6821 #else 6686 #else
6822 #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple 6687 #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple
6823 #endif 6688 #endif
6824 TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) { 6689 TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) {
6825 FeatureSwitch::ScopedOverride prompt( 6690 FeatureSwitch::ScopedOverride prompt(
6826 FeatureSwitch::prompt_for_external_extensions(), true); 6691 FeatureSwitch::prompt_for_external_extensions(), true);
6827 6692
6828 InitializeEmptyExtensionService(); 6693 InitializeEmptyExtensionService();
6829 MockExtensionProvider* provider = 6694 MockExtensionProvider* provider =
6830 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6695 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6831 AddMockExternalProvider(provider); 6696 AddMockExternalProvider(provider);
6832 6697
6833 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 6698 provider->UpdateOrAddExtension(
6834 data_dir_.AppendASCII("page_action.crx")); 6699 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
6835 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 6700 provider->UpdateOrAddExtension(
6836 data_dir_.AppendASCII("good.crx")); 6701 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx"));
6837 provider->UpdateOrAddExtension(theme_crx, "2.0", 6702 provider->UpdateOrAddExtension(
6838 data_dir_.AppendASCII("theme.crx")); 6703 theme_crx, "2.0", data_dir().AppendASCII("theme.crx"));
6839 6704
6840 int count = 3; 6705 int count = 3;
6841 content::WindowedNotificationObserver observer( 6706 content::WindowedNotificationObserver observer(
6842 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6707 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6843 base::Bind(&WaitForCountNotificationsCallback, &count)); 6708 base::Bind(&WaitForCountNotificationsCallback, &count));
6844 service_->CheckForExternalUpdates(); 6709 service()->CheckForExternalUpdates();
6845 observer.Wait(); 6710 observer.Wait();
6846 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6711 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6847 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); 6712 EXPECT_FALSE(service()->IsExtensionEnabled(page_action));
6848 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 6713 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6849 EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx)); 6714 EXPECT_FALSE(service()->IsExtensionEnabled(theme_crx));
6850 6715
6851 service_->EnableExtension(page_action); 6716 service()->EnableExtension(page_action);
6852 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6717 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6853 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); 6718 EXPECT_FALSE(extensions::HasExternalInstallBubble(service()));
6854 service_->EnableExtension(theme_crx); 6719 service()->EnableExtension(theme_crx);
6855 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6720 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6856 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); 6721 EXPECT_FALSE(extensions::HasExternalInstallBubble(service()));
6857 service_->EnableExtension(good_crx); 6722 service()->EnableExtension(good_crx);
6858 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6723 EXPECT_FALSE(extensions::HasExternalInstallError(service()));
6859 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); 6724 EXPECT_FALSE(extensions::HasExternalInstallBubble(service()));
6860 } 6725 }
6861 6726
6862 // Test that there is a bubble for external extensions that update 6727 // Test that there is a bubble for external extensions that update
6863 // from the webstore if the profile is not new. 6728 // from the webstore if the profile is not new.
6864 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) { 6729 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) {
6865 FeatureSwitch::ScopedOverride prompt( 6730 FeatureSwitch::ScopedOverride prompt(
6866 FeatureSwitch::prompt_for_external_extensions(), true); 6731 FeatureSwitch::prompt_for_external_extensions(), true);
6867 6732
6868 // This sets up the ExtensionPrefs used by our ExtensionService to be 6733 // This sets up the ExtensionPrefs used by our ExtensionService to be
6869 // post-first run. 6734 // post-first run.
6870 ExtensionServiceInitParams params = CreateDefaultInitParams(); 6735 ExtensionServiceInitParams params = CreateDefaultInitParams();
6871 params.is_first_run = false; 6736 params.is_first_run = false;
6872 InitializeExtensionService(params); 6737 InitializeExtensionService(params);
6873 6738
6874 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); 6739 base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx");
6875 PackCRX(data_dir_.AppendASCII("update_from_webstore"), 6740 PackCRX(data_dir().AppendASCII("update_from_webstore"),
6876 data_dir_.AppendASCII("update_from_webstore.pem"), 6741 data_dir().AppendASCII("update_from_webstore.pem"),
6877 crx_path); 6742 crx_path);
6878 6743
6879 MockExtensionProvider* provider = 6744 MockExtensionProvider* provider =
6880 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6745 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6881 AddMockExternalProvider(provider); 6746 AddMockExternalProvider(provider);
6882 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6747 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
6883 6748
6884 content::WindowedNotificationObserver observer( 6749 content::WindowedNotificationObserver observer(
6885 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6750 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6886 content::NotificationService::AllSources()); 6751 content::NotificationService::AllSources());
6887 service_->CheckForExternalUpdates(); 6752 service()->CheckForExternalUpdates();
6888 observer.Wait(); 6753 observer.Wait();
6889 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6754 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6890 EXPECT_TRUE(extensions::HasExternalInstallBubble(service_)); 6755 EXPECT_TRUE(extensions::HasExternalInstallBubble(service()));
6891 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); 6756 EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore));
6892 } 6757 }
6893 6758
6894 // Test that there is no bubble for external extensions if the profile is new. 6759 // Test that there is no bubble for external extensions if the profile is new.
6895 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) { 6760 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) {
6896 FeatureSwitch::ScopedOverride prompt( 6761 FeatureSwitch::ScopedOverride prompt(
6897 FeatureSwitch::prompt_for_external_extensions(), true); 6762 FeatureSwitch::prompt_for_external_extensions(), true);
6898 6763
6899 InitializeEmptyExtensionService(); 6764 InitializeEmptyExtensionService();
6900 6765
6901 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); 6766 base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx");
6902 PackCRX(data_dir_.AppendASCII("update_from_webstore"), 6767 PackCRX(data_dir().AppendASCII("update_from_webstore"),
6903 data_dir_.AppendASCII("update_from_webstore.pem"), 6768 data_dir().AppendASCII("update_from_webstore.pem"),
6904 crx_path); 6769 crx_path);
6905 6770
6906 MockExtensionProvider* provider = 6771 MockExtensionProvider* provider =
6907 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6772 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6908 AddMockExternalProvider(provider); 6773 AddMockExternalProvider(provider);
6909 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6774 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
6910 6775
6911 content::WindowedNotificationObserver observer( 6776 content::WindowedNotificationObserver observer(
6912 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6777 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6913 content::NotificationService::AllSources()); 6778 content::NotificationService::AllSources());
6914 service_->CheckForExternalUpdates(); 6779 service()->CheckForExternalUpdates();
6915 observer.Wait(); 6780 observer.Wait();
6916 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6781 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6917 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); 6782 EXPECT_FALSE(extensions::HasExternalInstallBubble(service()));
6918 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); 6783 EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore));
6919 } 6784 }
6920 6785
6921 TEST_F(ExtensionServiceTest, InstallBlacklistedExtension) { 6786 TEST_F(ExtensionServiceTest, InstallBlacklistedExtension) {
6922 InitializeEmptyExtensionService(); 6787 InitializeEmptyExtensionService();
6923 6788
6924 scoped_refptr<Extension> extension = extensions::ExtensionBuilder() 6789 scoped_refptr<Extension> extension = extensions::ExtensionBuilder()
6925 .SetManifest(extensions::DictionaryBuilder() 6790 .SetManifest(extensions::DictionaryBuilder()
6926 .Set("name", "extension") 6791 .Set("name", "extension")
6927 .Set("version", "1.0") 6792 .Set("version", "1.0")
6928 .Set("manifest_version", 2).Build()) 6793 .Set("manifest_version", 2).Build())
6929 .Build(); 6794 .Build();
6930 ASSERT_TRUE(extension.get()); 6795 ASSERT_TRUE(extension.get());
6931 const std::string& id = extension->id(); 6796 const std::string& id = extension->id();
6932 6797
6933 std::set<std::string> id_set; 6798 std::set<std::string> id_set;
6934 id_set.insert(id); 6799 id_set.insert(id);
6935 extensions::ExtensionNotificationObserver notifications( 6800 extensions::ExtensionNotificationObserver notifications(
6936 content::NotificationService::AllSources(), id_set); 6801 content::NotificationService::AllSources(), id_set);
6937 6802
6938 // Installation should be allowed but the extension should never have been 6803 // Installation should be allowed but the extension should never have been
6939 // loaded and it should be blacklisted in prefs. 6804 // loaded and it should be blacklisted in prefs.
6940 service_->OnExtensionInstalled( 6805 service()->OnExtensionInstalled(extension.get(),
6941 extension.get(), 6806 syncer::StringOrdinal(),
6942 syncer::StringOrdinal(), 6807 false /* has requirement errors */,
6943 false /* has requirement errors */, 6808 extensions::BLACKLISTED_MALWARE,
6944 extensions::BLACKLISTED_MALWARE, 6809 false /* is ephemeral */,
6945 false /* is ephemeral */, 6810 false /* wait for idle */);
6946 false /* wait for idle */);
6947 base::RunLoop().RunUntilIdle(); 6811 base::RunLoop().RunUntilIdle();
6948 6812
6949 // Extension was installed but not loaded. 6813 // Extension was installed but not loaded.
6950 EXPECT_TRUE(notifications.CheckNotifications( 6814 EXPECT_TRUE(notifications.CheckNotifications(
6951 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED)); 6815 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED));
6952 EXPECT_TRUE(service_->GetInstalledExtension(id)); 6816 EXPECT_TRUE(service()->GetInstalledExtension(id));
6953 6817
6954 EXPECT_FALSE(registry_->enabled_extensions().Contains(id)); 6818 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
6955 EXPECT_TRUE(registry_->blacklisted_extensions().Contains(id)); 6819 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(id));
6956 6820
6957 EXPECT_TRUE(ExtensionPrefs::Get(profile_.get())->IsExtensionBlacklisted(id)); 6821 EXPECT_TRUE(ExtensionPrefs::Get(profile())->IsExtensionBlacklisted(id));
6958 EXPECT_TRUE(ExtensionPrefs::Get(profile_.get()) 6822 EXPECT_TRUE(
6959 ->IsBlacklistedExtensionAcknowledged(id)); 6823 ExtensionPrefs::Get(profile())->IsBlacklistedExtensionAcknowledged(id));
6960 } 6824 }
6961 6825
6962 TEST_F(ExtensionServiceTest, ReconcileKnownDisabledNoneDisabled) { 6826 TEST_F(ExtensionServiceTest, ReconcileKnownDisabledNoneDisabled) {
6963 // A profile with 3 extensions installed: good0, good1, and good2. 6827 // A profile with 3 extensions installed: good0, good1, and good2.
6964 InitializeGoodInstalledExtensionService(); 6828 InitializeGoodInstalledExtensionService();
6965 6829
6966 // Initializing shouldn't disable any extensions if none are known to be 6830 // Initializing shouldn't disable any extensions if none are known to be
6967 // disabled. 6831 // disabled.
6968 service_->Init(); 6832 service()->Init();
6969 6833
6970 extensions::ExtensionIdSet expected_extensions; 6834 extensions::ExtensionIdSet expected_extensions;
6971 expected_extensions.insert(good0); 6835 expected_extensions.insert(good0);
6972 expected_extensions.insert(good1); 6836 expected_extensions.insert(good1);
6973 expected_extensions.insert(good2); 6837 expected_extensions.insert(good2);
6974 6838
6975 extensions::ExtensionIdSet expected_disabled_extensions; 6839 extensions::ExtensionIdSet expected_disabled_extensions;
6976 6840
6977 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs()); 6841 EXPECT_EQ(expected_extensions, registry()->enabled_extensions().GetIDs());
6978 EXPECT_EQ(expected_disabled_extensions, 6842 EXPECT_EQ(expected_disabled_extensions,
6979 registry_->disabled_extensions().GetIDs()); 6843 registry()->disabled_extensions().GetIDs());
6980 } 6844 }
6981 6845
6982 TEST_F(ExtensionServiceTest, ReconcileKnownDisabledWithSideEnable) { 6846 TEST_F(ExtensionServiceTest, ReconcileKnownDisabledWithSideEnable) {
6983 // A profile with 3 extensions installed: good0, good1, and good2. 6847 // A profile with 3 extensions installed: good0, good1, and good2.
6984 InitializeGoodInstalledExtensionService(); 6848 InitializeGoodInstalledExtensionService();
6985 6849
6986 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_.get()); 6850 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile());
6987 6851
6988 // Disable good1. 6852 // Disable good1.
6989 extension_prefs->SetExtensionState(good1, Extension::DISABLED); 6853 extension_prefs->SetExtensionState(good1, Extension::DISABLED);
6990 6854
6991 // Mark both good1 and good2 as "known_disabled" (effectively making good2 6855 // Mark both good1 and good2 as "known_disabled" (effectively making good2
6992 // look as if it had been side-enabled). 6856 // look as if it had been side-enabled).
6993 extensions::ExtensionIdSet known_disabled; 6857 extensions::ExtensionIdSet known_disabled;
6994 known_disabled.insert(good1); 6858 known_disabled.insert(good1);
6995 known_disabled.insert(good2); 6859 known_disabled.insert(good2);
6996 extension_prefs->SetKnownDisabled(known_disabled); 6860 extension_prefs->SetKnownDisabled(known_disabled);
6997 6861
6998 // Initialize the service (which should disable good2 since it's known to be 6862 // Initialize the service (which should disable good2 since it's known to be
6999 // disabled). 6863 // disabled).
7000 service_->Init(); 6864 service()->Init();
7001 6865
7002 extensions::ExtensionIdSet expected_extensions; 6866 extensions::ExtensionIdSet expected_extensions;
7003 expected_extensions.insert(good0); 6867 expected_extensions.insert(good0);
7004 6868
7005 extensions::ExtensionIdSet expected_disabled_extensions; 6869 extensions::ExtensionIdSet expected_disabled_extensions;
7006 expected_disabled_extensions.insert(good1); 6870 expected_disabled_extensions.insert(good1);
7007 expected_disabled_extensions.insert(good2); 6871 expected_disabled_extensions.insert(good2);
7008 6872
7009 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs()); 6873 EXPECT_EQ(expected_extensions, registry()->enabled_extensions().GetIDs());
7010 EXPECT_EQ(expected_disabled_extensions, 6874 EXPECT_EQ(expected_disabled_extensions,
7011 registry_->disabled_extensions().GetIDs()); 6875 registry()->disabled_extensions().GetIDs());
7012 6876
7013 // Make sure that re-enabling an extension sticks across calls to 6877 // Make sure that re-enabling an extension sticks across calls to
7014 // ReconcileKnownDisabled(). 6878 // ReconcileKnownDisabled().
7015 service_->EnableExtension(good2); 6879 service()->EnableExtension(good2);
7016 service_->ReconcileKnownDisabled(); 6880 service()->ReconcileKnownDisabled();
7017 expected_extensions.insert(good2); 6881 expected_extensions.insert(good2);
7018 expected_disabled_extensions.erase(good2); 6882 expected_disabled_extensions.erase(good2);
7019 6883
7020 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs()); 6884 EXPECT_EQ(expected_extensions, registry()->enabled_extensions().GetIDs());
7021 EXPECT_EQ(expected_disabled_extensions, 6885 EXPECT_EQ(expected_disabled_extensions,
7022 registry_->disabled_extensions().GetIDs()); 6886 registry()->disabled_extensions().GetIDs());
7023 } 6887 }
7024 6888
7025 // Tests a profile being destroyed correctly disables extensions. 6889 // Tests a profile being destroyed correctly disables extensions.
7026 TEST_F(ExtensionServiceTest, DestroyingProfileClearsExtensions) { 6890 TEST_F(ExtensionServiceTest, DestroyingProfileClearsExtensions) {
7027 InitializeEmptyExtensionService(); 6891 InitializeEmptyExtensionService();
7028 6892
7029 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 6893 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
7030 EXPECT_NE(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 6894 EXPECT_NE(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
7031 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 6895 EXPECT_EQ(1u, registry()->enabled_extensions().size());
7032 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 6896 EXPECT_EQ(0u, registry()->disabled_extensions().size());
7033 EXPECT_EQ(0u, registry_->terminated_extensions().size()); 6897 EXPECT_EQ(0u, registry()->terminated_extensions().size());
7034 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 6898 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
7035 6899
7036 service_->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 6900 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
7037 content::Source<Profile>(profile_.get()), 6901 content::Source<Profile>(profile()),
7038 content::NotificationService::NoDetails()); 6902 content::NotificationService::NoDetails());
7039 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 6903 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
7040 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 6904 EXPECT_EQ(0u, registry()->enabled_extensions().size());
7041 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 6905 EXPECT_EQ(0u, registry()->disabled_extensions().size());
7042 EXPECT_EQ(0u, registry_->terminated_extensions().size()); 6906 EXPECT_EQ(0u, registry()->terminated_extensions().size());
7043 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 6907 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
7044 } 6908 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698