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

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: Fix merge conflict 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/installed_loader.h" 52 #include "chrome/browser/extensions/installed_loader.h"
56 #include "chrome/browser/extensions/pack_extension_job.h" 53 #include "chrome/browser/extensions/pack_extension_job.h"
57 #include "chrome/browser/extensions/pending_extension_info.h" 54 #include "chrome/browser/extensions/pending_extension_info.h"
58 #include "chrome/browser/extensions/pending_extension_manager.h" 55 #include "chrome/browser/extensions/pending_extension_manager.h"
59 #include "chrome/browser/extensions/test_blacklist.h" 56 #include "chrome/browser/extensions/test_blacklist.h"
60 #include "chrome/browser/extensions/test_extension_system.h" 57 #include "chrome/browser/extensions/test_extension_system.h"
61 #include "chrome/browser/extensions/unpacked_installer.h" 58 #include "chrome/browser/extensions/unpacked_installer.h"
62 #include "chrome/browser/extensions/updater/extension_updater.h" 59 #include "chrome/browser/extensions/updater/extension_updater.h"
63 #include "chrome/browser/prefs/browser_prefs.h"
64 #include "chrome/browser/prefs/pref_service_mock_factory.h"
65 #include "chrome/browser/prefs/pref_service_syncable.h" 60 #include "chrome/browser/prefs/pref_service_syncable.h"
66 #include "chrome/browser/sync/profile_sync_service.h" 61 #include "chrome/browser/sync/profile_sync_service.h"
67 #include "chrome/browser/sync/profile_sync_service_factory.h" 62 #include "chrome/browser/sync/profile_sync_service_factory.h"
68 #include "chrome/common/chrome_constants.h" 63 #include "chrome/common/chrome_constants.h"
69 #include "chrome/common/chrome_paths.h"
70 #include "chrome/common/chrome_switches.h" 64 #include "chrome/common/chrome_switches.h"
71 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 65 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
72 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 66 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
73 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" 67 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
74 #include "chrome/common/extensions/manifest_url_handler.h" 68 #include "chrome/common/extensions/manifest_url_handler.h"
75 #include "chrome/common/pref_names.h" 69 #include "chrome/common/pref_names.h"
76 #include "chrome/common/url_constants.h" 70 #include "chrome/common/url_constants.h"
77 #include "chrome/test/base/scoped_browser_locale.h" 71 #include "chrome/test/base/scoped_browser_locale.h"
78 #include "chrome/test/base/testing_profile.h" 72 #include "chrome/test/base/testing_profile.h"
79 #include "components/pref_registry/pref_registry_syncable.h" 73 #include "components/pref_registry/pref_registry_syncable.h"
(...skipping 11 matching lines...) Expand all
91 #include "extensions/browser/extension_system.h" 85 #include "extensions/browser/extension_system.h"
92 #include "extensions/browser/external_provider_interface.h" 86 #include "extensions/browser/external_provider_interface.h"
93 #include "extensions/browser/management_policy.h" 87 #include "extensions/browser/management_policy.h"
94 #include "extensions/browser/pref_names.h" 88 #include "extensions/browser/pref_names.h"
95 #include "extensions/browser/test_management_policy.h" 89 #include "extensions/browser/test_management_policy.h"
96 #include "extensions/common/constants.h" 90 #include "extensions/common/constants.h"
97 #include "extensions/common/extension.h" 91 #include "extensions/common/extension.h"
98 #include "extensions/common/extension_builder.h" 92 #include "extensions/common/extension_builder.h"
99 #include "extensions/common/extension_l10n_util.h" 93 #include "extensions/common/extension_l10n_util.h"
100 #include "extensions/common/extension_resource.h" 94 #include "extensions/common/extension_resource.h"
95 #include "extensions/common/feature_switch.h"
101 #include "extensions/common/manifest_constants.h" 96 #include "extensions/common/manifest_constants.h"
102 #include "extensions/common/manifest_handlers/background_info.h" 97 #include "extensions/common/manifest_handlers/background_info.h"
103 #include "extensions/common/permissions/permission_set.h" 98 #include "extensions/common/permissions/permission_set.h"
104 #include "extensions/common/permissions/permissions_data.h" 99 #include "extensions/common/permissions/permissions_data.h"
105 #include "extensions/common/switches.h" 100 #include "extensions/common/switches.h"
106 #include "extensions/common/url_pattern.h" 101 #include "extensions/common/url_pattern.h"
107 #include "extensions/common/value_builder.h" 102 #include "extensions/common/value_builder.h"
108 #include "gpu/config/gpu_info.h" 103 #include "gpu/config/gpu_info.h"
109 #include "grit/browser_resources.h" 104 #include "grit/browser_resources.h"
110 #include "net/cookies/canonical_cookie.h" 105 #include "net/cookies/canonical_cookie.h"
(...skipping 11 matching lines...) Expand all
122 #include "sync/protocol/extension_specifics.pb.h" 117 #include "sync/protocol/extension_specifics.pb.h"
123 #include "sync/protocol/sync.pb.h" 118 #include "sync/protocol/sync.pb.h"
124 #include "testing/gtest/include/gtest/gtest.h" 119 #include "testing/gtest/include/gtest/gtest.h"
125 #include "testing/platform_test.h" 120 #include "testing/platform_test.h"
126 #include "url/gurl.h" 121 #include "url/gurl.h"
127 #include "webkit/browser/database/database_tracker.h" 122 #include "webkit/browser/database/database_tracker.h"
128 #include "webkit/browser/quota/quota_manager.h" 123 #include "webkit/browser/quota/quota_manager.h"
129 #include "webkit/common/database/database_identifier.h" 124 #include "webkit/common/database/database_identifier.h"
130 125
131 #if defined(OS_CHROMEOS) 126 #if defined(OS_CHROMEOS)
132 #include "chrome/browser/chromeos/extensions/install_limiter.h"
133 #include "chrome/browser/chromeos/login/users/user_manager.h" 127 #include "chrome/browser/chromeos/login/users/user_manager.h"
134 #include "chrome/browser/chromeos/settings/cros_settings.h" 128 #include "chrome/browser/chromeos/settings/cros_settings.h"
135 #include "chrome/browser/chromeos/settings/device_settings_service.h" 129 #include "chrome/browser/chromeos/settings/device_settings_service.h"
136 #endif 130 #endif
137 131
138 // The blacklist tests rely on safe browsing. 132 // The blacklist tests rely on safe browsing.
139 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) 133 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
140 #define ENABLE_BLACKLIST_TESTS 134 #define ENABLE_BLACKLIST_TESTS
141 #endif 135 #endif
142 136
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 int ids_found_; 448 int ids_found_;
455 base::FilePath fake_base_path_; 449 base::FilePath fake_base_path_;
456 int expected_creation_flags_; 450 int expected_creation_flags_;
457 scoped_ptr<extensions::ExternalProviderImpl> provider_; 451 scoped_ptr<extensions::ExternalProviderImpl> provider_;
458 scoped_ptr<base::DictionaryValue> prefs_; 452 scoped_ptr<base::DictionaryValue> prefs_;
459 scoped_ptr<TestingProfile> profile_; 453 scoped_ptr<TestingProfile> profile_;
460 454
461 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); 455 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
462 }; 456 };
463 457
464 ExtensionServiceTestBase::ExtensionServiceInitParams:: 458 class ExtensionServiceTest : public extensions::ExtensionServiceTestBase,
465 ExtensionServiceInitParams() 459 public content::NotificationObserver {
466 : autoupdate_enabled(false), is_first_run(true), profile_is_managed(false) {
467 }
468
469 // Our message loop may be used in tests which require it to be an IO loop.
470 ExtensionServiceTestBase::ExtensionServiceTestBase()
471 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
472 service_(NULL),
473 management_policy_(NULL),
474 expected_extensions_count_(0),
475 registry_(NULL) {
476 base::FilePath test_data_dir;
477 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
478 ADD_FAILURE();
479 return;
480 }
481 data_dir_ = test_data_dir.AppendASCII("extensions");
482 }
483
484 ExtensionServiceTestBase::~ExtensionServiceTestBase() {
485 service_ = NULL;
486 }
487
488 void ExtensionServiceTestBase::InitializeExtensionService(
489 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) {
490 profile_ = CreateTestingProfile(params);
491 service_ = InitializeExtensionServiceForProfile(params, profile_.get());
492 management_policy_ =
493 ExtensionSystem::Get(profile_.get())->management_policy();
494 extensions_install_dir_ = params.extensions_install_dir;
495 expected_extensions_count_ = 0;
496 registry_ = extensions::ExtensionRegistry::Get(profile_.get());
497 extensions::ExtensionGarbageCollectorFactory::GetInstance()
498 ->SetTestingFactoryAndUse(
499 profile_.get(),
500 &extensions::ExtensionGarbageCollectorFactory::BuildInstanceFor);
501 }
502
503 // static
504 scoped_ptr<TestingProfile> ExtensionServiceTestBase::CreateTestingProfile(
505 const ExtensionServiceInitParams& params) {
506 TestingProfile::Builder profile_builder;
507 // Create a PrefService that only contains user defined preference values.
508 PrefServiceMockFactory factory;
509 // If pref_file is empty, TestingProfile automatically creates
510 // TestingPrefServiceSyncable instance.
511 if (!params.pref_file.empty()) {
512 factory.SetUserPrefsFile(params.pref_file,
513 base::MessageLoopProxy::current().get());
514 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
515 new user_prefs::PrefRegistrySyncable);
516 scoped_ptr<PrefServiceSyncable> prefs(
517 factory.CreateSyncable(registry.get()));
518 chrome::RegisterUserProfilePrefs(registry.get());
519 profile_builder.SetPrefService(prefs.Pass());
520 }
521
522 if (params.profile_is_managed)
523 profile_builder.SetManagedUserId("asdf");
524
525 profile_builder.SetPath(params.profile_path);
526 return profile_builder.Build();
527 }
528
529 // static
530 ExtensionService*
531 ExtensionServiceTestBase::InitializeExtensionServiceForProfile(
532 const ExtensionServiceInitParams& params,
533 Profile* profile) {
534 TestExtensionSystem* system = static_cast<TestExtensionSystem*>(
535 ExtensionSystem::Get(profile));
536 if (!params.is_first_run) {
537 ExtensionPrefs* prefs = system->CreateExtensionPrefs(
538 CommandLine::ForCurrentProcess(),
539 params.extensions_install_dir);
540 prefs->SetAlertSystemFirstRun();
541 }
542
543 ExtensionService* service = system->CreateExtensionService(
544 CommandLine::ForCurrentProcess(),
545 params.extensions_install_dir,
546 params.autoupdate_enabled);
547
548 service->SetFileTaskRunnerForTesting(
549 base::MessageLoopProxy::current().get());
550 service->set_extensions_enabled(true);
551 service->set_show_extensions_prompts(false);
552 service->set_install_updates_when_idle_for_test(false);
553
554 // When we start up, we want to make sure there is no external provider,
555 // since the ExtensionService on Windows will use the Registry as a default
556 // provider and if there is something already registered there then it will
557 // interfere with the tests. Those tests that need an external provider
558 // will register one specifically.
559 service->ClearProvidersForTesting();
560
561 #if defined(OS_CHROMEOS)
562 extensions::InstallLimiter::Get(profile)->DisableForTest();
563 #endif
564 return service;
565 }
566
567 void ExtensionServiceTestBase::InitializeInstalledExtensionService(
568 const base::FilePath& prefs_file,
569 const base::FilePath& source_install_dir) {
570 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
571 base::FilePath path = temp_dir_.path();
572 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
573 EXPECT_TRUE(base::DeleteFile(path, true));
574 base::File::Error error = base::File::FILE_OK;
575 EXPECT_TRUE(base::CreateDirectoryAndGetError(path, &error)) << error;
576 base::FilePath temp_prefs = path.Append(chrome::kPreferencesFilename);
577 EXPECT_TRUE(base::CopyFile(prefs_file, temp_prefs));
578
579 base::FilePath extensions_install_dir =
580 path.Append(FILE_PATH_LITERAL("Extensions"));
581 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true));
582 EXPECT_TRUE(
583 base::CopyDirectory(source_install_dir, extensions_install_dir, true));
584
585 ExtensionServiceInitParams params;
586 params.profile_path = path;
587 params.pref_file = temp_prefs;
588 params.extensions_install_dir = extensions_install_dir;
589 InitializeExtensionService(params);
590 }
591
592 void ExtensionServiceTestBase::InitializeGoodInstalledExtensionService() {
593 base::FilePath source_install_dir = data_dir_
594 .AppendASCII("good")
595 .AppendASCII("Extensions");
596 base::FilePath pref_path =
597 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
598 InitializeInstalledExtensionService(pref_path, source_install_dir);
599 }
600
601 void ExtensionServiceTestBase::InitializeEmptyExtensionService() {
602 InitializeExtensionService(CreateDefaultInitParams());
603 }
604
605 void ExtensionServiceTestBase::InitializeProcessManager() {
606 static_cast<extensions::TestExtensionSystem*>(
607 ExtensionSystem::Get(profile_.get()))->
608 CreateProcessManager();
609 }
610
611 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() {
612 ExtensionServiceInitParams params = CreateDefaultInitParams();
613 params.autoupdate_enabled = true;
614 InitializeExtensionService(params);
615 service_->updater()->Start();
616 }
617
618 void ExtensionServiceTestBase::InitializeExtensionSyncService() {
619 extension_sync_service_.reset(new ExtensionSyncService(
620 profile_.get(), ExtensionPrefs::Get(profile_.get()), service_));
621 }
622
623 // static
624 void ExtensionServiceTestBase::SetUpTestCase() {
625 ExtensionErrorReporter::Init(false); // no noisy errors
626 }
627
628 void ExtensionServiceTestBase::SetUp() {
629 ExtensionErrorReporter::GetInstance()->ClearErrors();
630 }
631
632 void ExtensionServiceTestBase::TearDown() {
633 }
634
635 ExtensionServiceTestBase::ExtensionServiceInitParams
636 ExtensionServiceTestBase::CreateDefaultInitParams() {
637 return CreateDefaultInitParamsInTempDir(&temp_dir_);
638 }
639
640 // static
641 ExtensionServiceTestBase::ExtensionServiceInitParams
642 ExtensionServiceTestBase::CreateDefaultInitParamsInTempDir(
643 base::ScopedTempDir* temp_dir) {
644 ExtensionServiceInitParams params;
645 EXPECT_TRUE(temp_dir->CreateUniqueTempDir());
646 base::FilePath path = temp_dir->path();
647 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
648 EXPECT_TRUE(base::DeleteFile(path, true));
649 base::File::Error error = base::File::FILE_OK;
650 EXPECT_TRUE(base::CreateDirectoryAndGetError(path, &error)) << error;
651 base::FilePath prefs_filename =
652 path.Append(FILE_PATH_LITERAL("TestPreferences"));
653 base::FilePath extensions_install_dir =
654 path.Append(FILE_PATH_LITERAL("Extensions"));
655 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true));
656 EXPECT_TRUE(base::CreateDirectoryAndGetError(extensions_install_dir,
657 &error)) << error;
658
659 params.profile_path = path;
660 params.pref_file = prefs_filename;
661 params.extensions_install_dir = extensions_install_dir;
662 return params;
663 }
664
665 class ExtensionServiceTest
666 : public ExtensionServiceTestBase, public content::NotificationObserver {
667 public: 460 public:
668 ExtensionServiceTest() 461 ExtensionServiceTest()
669 : unloaded_reason_(UnloadedExtensionInfo::REASON_UNDEFINED), 462 : unloaded_reason_(UnloadedExtensionInfo::REASON_UNDEFINED),
670 installed_(NULL), 463 installed_(NULL),
671 was_update_(false), 464 was_update_(false),
672 override_external_install_prompt_( 465 override_external_install_prompt_(
673 FeatureSwitch::prompt_for_external_extensions(), 466 FeatureSwitch::prompt_for_external_extensions(),
674 false) { 467 false),
468 expected_extensions_count_(0) {
675 registrar_.Add(this, 469 registrar_.Add(this,
676 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 470 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
677 content::NotificationService::AllSources()); 471 content::NotificationService::AllSources());
678 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 472 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
679 content::NotificationService::AllSources()); 473 content::NotificationService::AllSources());
680 registrar_.Add(this, 474 registrar_.Add(this,
681 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, 475 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED,
682 content::NotificationService::AllSources()); 476 content::NotificationService::AllSources());
683 } 477 }
684 478
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 break; 515 break;
722 } 516 }
723 517
724 default: 518 default:
725 DCHECK(false); 519 DCHECK(false);
726 } 520 }
727 } 521 }
728 522
729 void AddMockExternalProvider( 523 void AddMockExternalProvider(
730 extensions::ExternalProviderInterface* provider) { 524 extensions::ExternalProviderInterface* provider) {
731 service_->AddProviderForTesting(provider); 525 service()->AddProviderForTesting(provider);
732 } 526 }
733 527
734 void MockSyncStartFlare(bool* was_called, 528 void MockSyncStartFlare(bool* was_called,
735 syncer::ModelType* model_type_passed_in, 529 syncer::ModelType* model_type_passed_in,
736 syncer::ModelType model_type) { 530 syncer::ModelType model_type) {
737 *was_called = true; 531 *was_called = true;
738 *model_type_passed_in = model_type; 532 *model_type_passed_in = model_type;
739 } 533 }
740 534
741 protected: 535 protected:
742 // Paths to some of the fake extensions. 536 // Paths to some of the fake extensions.
743 base::FilePath good0_path() { 537 base::FilePath good0_path() {
744 return data_dir_.AppendASCII("good").AppendASCII("Extensions") 538 return data_dir()
745 .AppendASCII(good0).AppendASCII("1.0.0.0"); 539 .AppendASCII("good")
540 .AppendASCII("Extensions")
541 .AppendASCII(good0)
542 .AppendASCII("1.0.0.0");
746 } 543 }
747 544
748 base::FilePath good1_path() { 545 base::FilePath good1_path() {
749 return data_dir_.AppendASCII("good").AppendASCII("Extensions") 546 return data_dir()
750 .AppendASCII(good1).AppendASCII("2"); 547 .AppendASCII("good")
548 .AppendASCII("Extensions")
549 .AppendASCII(good1)
550 .AppendASCII("2");
751 } 551 }
752 552
753 base::FilePath good2_path() { 553 base::FilePath good2_path() {
754 return data_dir_.AppendASCII("good").AppendASCII("Extensions") 554 return data_dir()
755 .AppendASCII(good2).AppendASCII("1.0"); 555 .AppendASCII("good")
556 .AppendASCII("Extensions")
557 .AppendASCII(good2)
558 .AppendASCII("1.0");
756 } 559 }
757 560
758 void TestExternalProvider(MockExtensionProvider* provider, 561 void TestExternalProvider(MockExtensionProvider* provider,
759 Manifest::Location location); 562 Manifest::Location location);
760 563
761 void PackCRX(const base::FilePath& dir_path, 564 void PackCRX(const base::FilePath& dir_path,
762 const base::FilePath& pem_path, 565 const base::FilePath& pem_path,
763 const base::FilePath& crx_path) { 566 const base::FilePath& crx_path) {
764 // Use the existing pem key, if provided. 567 // Use the existing pem key, if provided.
765 base::FilePath pem_output_path; 568 base::FilePath pem_output_path;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 InstallCRXInternal(path, Extension::FROM_WEBSTORE); 650 InstallCRXInternal(path, Extension::FROM_WEBSTORE);
848 return VerifyCrxInstall(path, install_state); 651 return VerifyCrxInstall(path, install_state);
849 } 652 }
850 653
851 const Extension* InstallCRXWithLocation(const base::FilePath& crx_path, 654 const Extension* InstallCRXWithLocation(const base::FilePath& crx_path,
852 Manifest::Location install_location, 655 Manifest::Location install_location,
853 InstallState install_state) { 656 InstallState install_state) {
854 EXPECT_TRUE(base::PathExists(crx_path)) 657 EXPECT_TRUE(base::PathExists(crx_path))
855 << "Path does not exist: "<< crx_path.value().c_str(); 658 << "Path does not exist: "<< crx_path.value().c_str();
856 // no client (silent install) 659 // no client (silent install)
857 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service_)); 660 scoped_refptr<CrxInstaller> installer(
661 CrxInstaller::CreateSilent(service()));
858 installer->set_install_source(install_location); 662 installer->set_install_source(install_location);
859 663
860 content::WindowedNotificationObserver observer( 664 content::WindowedNotificationObserver observer(
861 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 665 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
862 content::NotificationService::AllSources()); 666 content::NotificationService::AllSources());
863 installer->InstallCrx(crx_path); 667 installer->InstallCrx(crx_path);
864 observer.Wait(); 668 observer.Wait();
865 669
866 return VerifyCrxInstall(crx_path, install_state); 670 return VerifyCrxInstall(crx_path, install_state);
867 } 671 }
(...skipping 27 matching lines...) Expand all
895 << path.value(); 699 << path.value();
896 // If INSTALL_UPDATED, old_name_ should match the given string. 700 // If INSTALL_UPDATED, old_name_ should match the given string.
897 if (install_state == INSTALL_UPDATED && !expected_old_name.empty()) 701 if (install_state == INSTALL_UPDATED && !expected_old_name.empty())
898 EXPECT_EQ(expected_old_name, old_name_); 702 EXPECT_EQ(expected_old_name, old_name_);
899 EXPECT_EQ(0u, errors.size()) << path.value(); 703 EXPECT_EQ(0u, errors.size()) << path.value();
900 704
901 if (install_state == INSTALL_WITHOUT_LOAD) { 705 if (install_state == INSTALL_WITHOUT_LOAD) {
902 EXPECT_EQ(0u, loaded_.size()) << path.value(); 706 EXPECT_EQ(0u, loaded_.size()) << path.value();
903 } else { 707 } else {
904 EXPECT_EQ(1u, loaded_.size()) << path.value(); 708 EXPECT_EQ(1u, loaded_.size()) << path.value();
905 size_t actual_extension_count = registry_->enabled_extensions().size() + 709 size_t actual_extension_count =
906 registry_->disabled_extensions().size(); 710 registry()->enabled_extensions().size() +
711 registry()->disabled_extensions().size();
907 EXPECT_EQ(expected_extensions_count_, actual_extension_count) << 712 EXPECT_EQ(expected_extensions_count_, actual_extension_count) <<
908 path.value(); 713 path.value();
909 extension = loaded_[0].get(); 714 extension = loaded_[0].get();
910 EXPECT_TRUE(service_->GetExtensionById(extension->id(), false)) 715 EXPECT_TRUE(service()->GetExtensionById(extension->id(), false))
911 << path.value(); 716 << path.value();
912 } 717 }
913 718
914 for (std::vector<base::string16>::iterator err = errors.begin(); 719 for (std::vector<base::string16>::iterator err = errors.begin();
915 err != errors.end(); ++err) { 720 err != errors.end(); ++err) {
916 LOG(ERROR) << *err; 721 LOG(ERROR) << *err;
917 } 722 }
918 } else { 723 } else {
919 EXPECT_FALSE(installed_) << path.value(); 724 EXPECT_FALSE(installed_) << path.value();
920 EXPECT_EQ(0u, loaded_.size()) << path.value(); 725 EXPECT_EQ(0u, loaded_.size()) << path.value();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 *installer; 769 *installer;
965 } 770 }
966 771
967 void UpdateExtension(const std::string& id, 772 void UpdateExtension(const std::string& id,
968 const base::FilePath& in_path, 773 const base::FilePath& in_path,
969 UpdateState expected_state) { 774 UpdateState expected_state) {
970 ASSERT_TRUE(base::PathExists(in_path)); 775 ASSERT_TRUE(base::PathExists(in_path));
971 776
972 // We need to copy this to a temporary location because Update() will delete 777 // We need to copy this to a temporary location because Update() will delete
973 // it. 778 // it.
974 base::FilePath path = temp_dir_.path(); 779 base::FilePath path = temp_dir().path();
975 path = path.Append(in_path.BaseName()); 780 path = path.Append(in_path.BaseName());
976 ASSERT_TRUE(base::CopyFile(in_path, path)); 781 ASSERT_TRUE(base::CopyFile(in_path, path));
977 782
978 int previous_enabled_extension_count = 783 int previous_enabled_extension_count =
979 registry_->enabled_extensions().size(); 784 registry()->enabled_extensions().size();
980 int previous_installed_extension_count = 785 int previous_installed_extension_count =
981 previous_enabled_extension_count + 786 previous_enabled_extension_count +
982 registry_->disabled_extensions().size(); 787 registry()->disabled_extensions().size();
983 788
984 extensions::CrxInstaller* installer = NULL; 789 extensions::CrxInstaller* installer = NULL;
985 content::WindowedNotificationObserver observer( 790 content::WindowedNotificationObserver observer(
986 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 791 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
987 base::Bind(&IsCrxInstallerDone, &installer)); 792 base::Bind(&IsCrxInstallerDone, &installer));
988 service_->UpdateExtension(id, path, true, &installer); 793 service()->UpdateExtension(id, path, true, &installer);
989 794
990 if (installer) 795 if (installer)
991 observer.Wait(); 796 observer.Wait();
992 else 797 else
993 base::RunLoop().RunUntilIdle(); 798 base::RunLoop().RunUntilIdle();
994 799
995 std::vector<base::string16> errors = GetErrors(); 800 std::vector<base::string16> errors = GetErrors();
996 int error_count = errors.size(); 801 int error_count = errors.size();
997 int enabled_extension_count = registry_->enabled_extensions().size(); 802 int enabled_extension_count = registry()->enabled_extensions().size();
998 int installed_extension_count = 803 int installed_extension_count =
999 enabled_extension_count + registry_->disabled_extensions().size(); 804 enabled_extension_count + registry()->disabled_extensions().size();
1000 805
1001 int expected_error_count = (expected_state == FAILED) ? 1 : 0; 806 int expected_error_count = (expected_state == FAILED) ? 1 : 0;
1002 EXPECT_EQ(expected_error_count, error_count) << path.value(); 807 EXPECT_EQ(expected_error_count, error_count) << path.value();
1003 808
1004 if (expected_state <= FAILED) { 809 if (expected_state <= FAILED) {
1005 EXPECT_EQ(previous_enabled_extension_count, 810 EXPECT_EQ(previous_enabled_extension_count,
1006 enabled_extension_count); 811 enabled_extension_count);
1007 EXPECT_EQ(previous_installed_extension_count, 812 EXPECT_EQ(previous_installed_extension_count,
1008 installed_extension_count); 813 installed_extension_count);
1009 } else { 814 } else {
1010 int expected_installed_extension_count = 815 int expected_installed_extension_count =
1011 (expected_state >= INSTALLED) ? 1 : 0; 816 (expected_state >= INSTALLED) ? 1 : 0;
1012 int expected_enabled_extension_count = 817 int expected_enabled_extension_count =
1013 (expected_state >= ENABLED) ? 1 : 0; 818 (expected_state >= ENABLED) ? 1 : 0;
1014 EXPECT_EQ(expected_installed_extension_count, 819 EXPECT_EQ(expected_installed_extension_count,
1015 installed_extension_count); 820 installed_extension_count);
1016 EXPECT_EQ(expected_enabled_extension_count, 821 EXPECT_EQ(expected_enabled_extension_count,
1017 enabled_extension_count); 822 enabled_extension_count);
1018 } 823 }
1019 824
1020 // Update() should the temporary input file. 825 // Update() should the temporary input file.
1021 EXPECT_FALSE(base::PathExists(path)); 826 EXPECT_FALSE(base::PathExists(path));
1022 } 827 }
1023 828
1024 void TerminateExtension(const std::string& id) { 829 void TerminateExtension(const std::string& id) {
1025 const Extension* extension = service_->GetInstalledExtension(id); 830 const Extension* extension = service()->GetInstalledExtension(id);
1026 if (!extension) { 831 if (!extension) {
1027 ADD_FAILURE(); 832 ADD_FAILURE();
1028 return; 833 return;
1029 } 834 }
1030 service_->TrackTerminatedExtensionForTest(extension); 835 service()->TrackTerminatedExtensionForTest(extension);
1031 } 836 }
1032 837
1033 size_t GetPrefKeyCount() { 838 size_t GetPrefKeyCount() {
1034 const base::DictionaryValue* dict = 839 const base::DictionaryValue* dict =
1035 profile_->GetPrefs()->GetDictionary("extensions.settings"); 840 profile()->GetPrefs()->GetDictionary("extensions.settings");
1036 if (!dict) { 841 if (!dict) {
1037 ADD_FAILURE(); 842 ADD_FAILURE();
1038 return 0; 843 return 0;
1039 } 844 }
1040 return dict->size(); 845 return dict->size();
1041 } 846 }
1042 847
1043 void UninstallExtension(const std::string& id, bool use_helper) { 848 void UninstallExtension(const std::string& id, bool use_helper) {
1044 // Verify that the extension is installed. 849 // Verify that the extension is installed.
1045 base::FilePath extension_path = extensions_install_dir_.AppendASCII(id); 850 base::FilePath extension_path = extensions_install_dir().AppendASCII(id);
1046 EXPECT_TRUE(base::PathExists(extension_path)); 851 EXPECT_TRUE(base::PathExists(extension_path));
1047 size_t pref_key_count = GetPrefKeyCount(); 852 size_t pref_key_count = GetPrefKeyCount();
1048 EXPECT_GT(pref_key_count, 0u); 853 EXPECT_GT(pref_key_count, 0u);
1049 ValidateIntegerPref(id, "state", Extension::ENABLED); 854 ValidateIntegerPref(id, "state", Extension::ENABLED);
1050 855
1051 // Uninstall it. 856 // Uninstall it.
1052 if (use_helper) { 857 if (use_helper) {
1053 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(service_, id)); 858 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(service(), id));
1054 } else { 859 } else {
1055 EXPECT_TRUE(service_->UninstallExtension(id, false, NULL)); 860 EXPECT_TRUE(service()->UninstallExtension(id, false, NULL));
1056 } 861 }
1057 --expected_extensions_count_; 862 --expected_extensions_count_;
1058 863
1059 // We should get an unload notification. 864 // We should get an unload notification.
1060 EXPECT_FALSE(unloaded_id_.empty()); 865 EXPECT_FALSE(unloaded_id_.empty());
1061 EXPECT_EQ(id, unloaded_id_); 866 EXPECT_EQ(id, unloaded_id_);
1062 867
1063 // Verify uninstalled state. 868 // Verify uninstalled state.
1064 size_t new_pref_key_count = GetPrefKeyCount(); 869 size_t new_pref_key_count = GetPrefKeyCount();
1065 if (new_pref_key_count == pref_key_count) { 870 if (new_pref_key_count == pref_key_count) {
1066 ValidateIntegerPref(id, "location", 871 ValidateIntegerPref(id, "location",
1067 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 872 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1068 } else { 873 } else {
1069 EXPECT_EQ(new_pref_key_count, pref_key_count - 1); 874 EXPECT_EQ(new_pref_key_count, pref_key_count - 1);
1070 } 875 }
1071 876
1072 // The extension should not be in the service anymore. 877 // The extension should not be in the service anymore.
1073 EXPECT_FALSE(service_->GetInstalledExtension(id)); 878 EXPECT_FALSE(service()->GetInstalledExtension(id));
1074 base::RunLoop().RunUntilIdle(); 879 base::RunLoop().RunUntilIdle();
1075 880
1076 // The directory should be gone. 881 // The directory should be gone.
1077 EXPECT_FALSE(base::PathExists(extension_path)); 882 EXPECT_FALSE(base::PathExists(extension_path));
1078 } 883 }
1079 884
1080 void ValidatePrefKeyCount(size_t count) { 885 void ValidatePrefKeyCount(size_t count) {
1081 EXPECT_EQ(count, GetPrefKeyCount()); 886 EXPECT_EQ(count, GetPrefKeyCount());
1082 } 887 }
1083 888
1084 testing::AssertionResult ValidateBooleanPref( 889 testing::AssertionResult ValidateBooleanPref(
1085 const std::string& extension_id, 890 const std::string& extension_id,
1086 const std::string& pref_path, 891 const std::string& pref_path,
1087 bool expected_val) { 892 bool expected_val) {
1088 std::string msg = "while checking: "; 893 std::string msg = "while checking: ";
1089 msg += extension_id; 894 msg += extension_id;
1090 msg += " "; 895 msg += " ";
1091 msg += pref_path; 896 msg += pref_path;
1092 msg += " == "; 897 msg += " == ";
1093 msg += expected_val ? "true" : "false"; 898 msg += expected_val ? "true" : "false";
1094 899
1095 PrefService* prefs = profile_->GetPrefs(); 900 PrefService* prefs = profile()->GetPrefs();
1096 const base::DictionaryValue* dict = 901 const base::DictionaryValue* dict =
1097 prefs->GetDictionary("extensions.settings"); 902 prefs->GetDictionary("extensions.settings");
1098 if (!dict) { 903 if (!dict) {
1099 return testing::AssertionFailure() 904 return testing::AssertionFailure()
1100 << "extension.settings does not exist " << msg; 905 << "extension.settings does not exist " << msg;
1101 } 906 }
1102 907
1103 const base::DictionaryValue* pref = NULL; 908 const base::DictionaryValue* pref = NULL;
1104 if (!dict->GetDictionary(extension_id, &pref)) { 909 if (!dict->GetDictionary(extension_id, &pref)) {
1105 return testing::AssertionFailure() 910 return testing::AssertionFailure()
1106 << "extension pref does not exist " << msg; 911 << "extension pref does not exist " << msg;
1107 } 912 }
1108 913
1109 bool val; 914 bool val;
1110 if (!pref->GetBoolean(pref_path, &val)) { 915 if (!pref->GetBoolean(pref_path, &val)) {
1111 return testing::AssertionFailure() 916 return testing::AssertionFailure()
1112 << pref_path << " pref not found " << msg; 917 << pref_path << " pref not found " << msg;
1113 } 918 }
1114 919
1115 return expected_val == val 920 return expected_val == val
1116 ? testing::AssertionSuccess() 921 ? testing::AssertionSuccess()
1117 : testing::AssertionFailure() << "base::Value is incorrect " << msg; 922 : testing::AssertionFailure() << "base::Value is incorrect " << msg;
1118 } 923 }
1119 924
1120 bool IsPrefExist(const std::string& extension_id, 925 bool IsPrefExist(const std::string& extension_id,
1121 const std::string& pref_path) { 926 const std::string& pref_path) {
1122 const base::DictionaryValue* dict = 927 const base::DictionaryValue* dict =
1123 profile_->GetPrefs()->GetDictionary("extensions.settings"); 928 profile()->GetPrefs()->GetDictionary("extensions.settings");
1124 if (dict == NULL) return false; 929 if (dict == NULL) return false;
1125 const base::DictionaryValue* pref = NULL; 930 const base::DictionaryValue* pref = NULL;
1126 if (!dict->GetDictionary(extension_id, &pref)) { 931 if (!dict->GetDictionary(extension_id, &pref)) {
1127 return false; 932 return false;
1128 } 933 }
1129 if (pref == NULL) { 934 if (pref == NULL) {
1130 return false; 935 return false;
1131 } 936 }
1132 bool val; 937 bool val;
1133 if (!pref->GetBoolean(pref_path, &val)) { 938 if (!pref->GetBoolean(pref_path, &val)) {
1134 return false; 939 return false;
1135 } 940 }
1136 return true; 941 return true;
1137 } 942 }
1138 943
1139 void ValidateIntegerPref(const std::string& extension_id, 944 void ValidateIntegerPref(const std::string& extension_id,
1140 const std::string& pref_path, 945 const std::string& pref_path,
1141 int expected_val) { 946 int expected_val) {
1142 std::string msg = " while checking: "; 947 std::string msg = " while checking: ";
1143 msg += extension_id; 948 msg += extension_id;
1144 msg += " "; 949 msg += " ";
1145 msg += pref_path; 950 msg += pref_path;
1146 msg += " == "; 951 msg += " == ";
1147 msg += base::IntToString(expected_val); 952 msg += base::IntToString(expected_val);
1148 953
1149 PrefService* prefs = profile_->GetPrefs(); 954 PrefService* prefs = profile()->GetPrefs();
1150 const base::DictionaryValue* dict = 955 const base::DictionaryValue* dict =
1151 prefs->GetDictionary("extensions.settings"); 956 prefs->GetDictionary("extensions.settings");
1152 ASSERT_TRUE(dict != NULL) << msg; 957 ASSERT_TRUE(dict != NULL) << msg;
1153 const base::DictionaryValue* pref = NULL; 958 const base::DictionaryValue* pref = NULL;
1154 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; 959 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
1155 EXPECT_TRUE(pref != NULL) << msg; 960 EXPECT_TRUE(pref != NULL) << msg;
1156 int val; 961 int val;
1157 ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg; 962 ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg;
1158 EXPECT_EQ(expected_val, val) << msg; 963 EXPECT_EQ(expected_val, val) << msg;
1159 } 964 }
1160 965
1161 void ValidateStringPref(const std::string& extension_id, 966 void ValidateStringPref(const std::string& extension_id,
1162 const std::string& pref_path, 967 const std::string& pref_path,
1163 const std::string& expected_val) { 968 const std::string& expected_val) {
1164 std::string msg = " while checking: "; 969 std::string msg = " while checking: ";
1165 msg += extension_id; 970 msg += extension_id;
1166 msg += ".manifest."; 971 msg += ".manifest.";
1167 msg += pref_path; 972 msg += pref_path;
1168 msg += " == "; 973 msg += " == ";
1169 msg += expected_val; 974 msg += expected_val;
1170 975
1171 const base::DictionaryValue* dict = 976 const base::DictionaryValue* dict =
1172 profile_->GetPrefs()->GetDictionary("extensions.settings"); 977 profile()->GetPrefs()->GetDictionary("extensions.settings");
1173 ASSERT_TRUE(dict != NULL) << msg; 978 ASSERT_TRUE(dict != NULL) << msg;
1174 const base::DictionaryValue* pref = NULL; 979 const base::DictionaryValue* pref = NULL;
1175 std::string manifest_path = extension_id + ".manifest"; 980 std::string manifest_path = extension_id + ".manifest";
1176 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; 981 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg;
1177 EXPECT_TRUE(pref != NULL) << msg; 982 EXPECT_TRUE(pref != NULL) << msg;
1178 std::string val; 983 std::string val;
1179 ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; 984 ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg;
1180 EXPECT_EQ(expected_val, val) << msg; 985 EXPECT_EQ(expected_val, val) << msg;
1181 } 986 }
1182 987
1183 void SetPref(const std::string& extension_id, 988 void SetPref(const std::string& extension_id,
1184 const std::string& pref_path, 989 const std::string& pref_path,
1185 base::Value* value, 990 base::Value* value,
1186 const std::string& msg) { 991 const std::string& msg) {
1187 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); 992 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings");
1188 base::DictionaryValue* dict = update.Get(); 993 base::DictionaryValue* dict = update.Get();
1189 ASSERT_TRUE(dict != NULL) << msg; 994 ASSERT_TRUE(dict != NULL) << msg;
1190 base::DictionaryValue* pref = NULL; 995 base::DictionaryValue* pref = NULL;
1191 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; 996 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
1192 EXPECT_TRUE(pref != NULL) << msg; 997 EXPECT_TRUE(pref != NULL) << msg;
1193 pref->Set(pref_path, value); 998 pref->Set(pref_path, value);
1194 } 999 }
1195 1000
1196 void SetPrefInteg(const std::string& extension_id, 1001 void SetPrefInteg(const std::string& extension_id,
1197 const std::string& pref_path, 1002 const std::string& pref_path,
(...skipping 17 matching lines...) Expand all
1215 msg += (value ? "true" : "false"); 1020 msg += (value ? "true" : "false");
1216 1021
1217 SetPref(extension_id, pref_path, new base::FundamentalValue(value), msg); 1022 SetPref(extension_id, pref_path, new base::FundamentalValue(value), msg);
1218 } 1023 }
1219 1024
1220 void ClearPref(const std::string& extension_id, 1025 void ClearPref(const std::string& extension_id,
1221 const std::string& pref_path) { 1026 const std::string& pref_path) {
1222 std::string msg = " while clearing: "; 1027 std::string msg = " while clearing: ";
1223 msg += extension_id + " " + pref_path; 1028 msg += extension_id + " " + pref_path;
1224 1029
1225 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); 1030 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings");
1226 base::DictionaryValue* dict = update.Get(); 1031 base::DictionaryValue* dict = update.Get();
1227 ASSERT_TRUE(dict != NULL) << msg; 1032 ASSERT_TRUE(dict != NULL) << msg;
1228 base::DictionaryValue* pref = NULL; 1033 base::DictionaryValue* pref = NULL;
1229 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; 1034 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
1230 EXPECT_TRUE(pref != NULL) << msg; 1035 EXPECT_TRUE(pref != NULL) << msg;
1231 pref->Remove(pref_path, NULL); 1036 pref->Remove(pref_path, NULL);
1232 } 1037 }
1233 1038
1234 void SetPrefStringSet(const std::string& extension_id, 1039 void SetPrefStringSet(const std::string& extension_id,
1235 const std::string& pref_path, 1040 const std::string& pref_path,
1236 const std::set<std::string>& value) { 1041 const std::set<std::string>& value) {
1237 std::string msg = " while setting: "; 1042 std::string msg = " while setting: ";
1238 msg += extension_id + " " + pref_path; 1043 msg += extension_id + " " + pref_path;
1239 1044
1240 base::ListValue* list_value = new base::ListValue(); 1045 base::ListValue* list_value = new base::ListValue();
1241 for (std::set<std::string>::const_iterator iter = value.begin(); 1046 for (std::set<std::string>::const_iterator iter = value.begin();
1242 iter != value.end(); ++iter) 1047 iter != value.end(); ++iter)
1243 list_value->Append(new base::StringValue(*iter)); 1048 list_value->Append(new base::StringValue(*iter));
1244 1049
1245 SetPref(extension_id, pref_path, list_value, msg); 1050 SetPref(extension_id, pref_path, list_value, msg);
1246 } 1051 }
1247 1052
1248 void InitPluginService() { 1053 void InitPluginService() {
1249 #if defined(ENABLE_PLUGINS) 1054 #if defined(ENABLE_PLUGINS)
1250 PluginService::GetInstance()->Init(); 1055 PluginService::GetInstance()->Init();
1251 #endif 1056 #endif
1252 } 1057 }
1253 1058
1059 void InitializeExtensionSyncService() {
1060 extension_sync_service_.reset(new ExtensionSyncService(
1061 profile(), ExtensionPrefs::Get(browser_context()), service()));
1062 }
1063
1064 extensions::ManagementPolicy* GetManagementPolicy() {
1065 return ExtensionSystem::Get(browser_context())->management_policy();
1066 }
1067
1068 ExtensionSyncService* extension_sync_service() {
1069 return extension_sync_service_.get();
1070 }
1071
1254 protected: 1072 protected:
1073 scoped_ptr<ExtensionSyncService> extension_sync_service_;
1255 extensions::ExtensionList loaded_; 1074 extensions::ExtensionList loaded_;
1256 std::string unloaded_id_; 1075 std::string unloaded_id_;
1257 UnloadedExtensionInfo::Reason unloaded_reason_; 1076 UnloadedExtensionInfo::Reason unloaded_reason_;
1258 const Extension* installed_; 1077 const Extension* installed_;
1259 bool was_update_; 1078 bool was_update_;
1260 std::string old_name_; 1079 std::string old_name_;
1261 FeatureSwitch::ScopedOverride override_external_install_prompt_; 1080 FeatureSwitch::ScopedOverride override_external_install_prompt_;
1262 1081
1263 private: 1082 private:
1264 // Create a CrxInstaller and install the CRX file. 1083 // Create a CrxInstaller and install the CRX file.
1265 // Instead of calling this method yourself, use InstallCRX(), which does extra 1084 // Instead of calling this method yourself, use InstallCRX(), which does extra
1266 // error checking. 1085 // error checking.
1267 void InstallCRXInternal(const base::FilePath& crx_path) { 1086 void InstallCRXInternal(const base::FilePath& crx_path) {
1268 InstallCRXInternal(crx_path, Extension::NO_FLAGS); 1087 InstallCRXInternal(crx_path, Extension::NO_FLAGS);
1269 } 1088 }
1270 1089
1271 void InstallCRXInternal(const base::FilePath& crx_path, int creation_flags) { 1090 void InstallCRXInternal(const base::FilePath& crx_path, int creation_flags) {
1272 ASSERT_TRUE(base::PathExists(crx_path)) 1091 ASSERT_TRUE(base::PathExists(crx_path))
1273 << "Path does not exist: "<< crx_path.value().c_str(); 1092 << "Path does not exist: "<< crx_path.value().c_str();
1274 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service_)); 1093 scoped_refptr<CrxInstaller> installer(
1094 CrxInstaller::CreateSilent(service()));
1275 installer->set_creation_flags(creation_flags); 1095 installer->set_creation_flags(creation_flags);
1276 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT)) 1096 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT))
1277 installer->set_allow_silent_install(true); 1097 installer->set_allow_silent_install(true);
1278 1098
1279 content::WindowedNotificationObserver observer( 1099 content::WindowedNotificationObserver observer(
1280 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1100 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1281 content::Source<extensions::CrxInstaller>(installer)); 1101 content::Source<extensions::CrxInstaller>(installer));
1282 1102
1283 installer->InstallCrx(crx_path); 1103 installer->InstallCrx(crx_path);
1284 1104
1285 observer.Wait(); 1105 observer.Wait();
1286 } 1106 }
1287 1107
1108 size_t expected_extensions_count_;
1288 content::NotificationRegistrar registrar_; 1109 content::NotificationRegistrar registrar_;
1289 }; 1110 };
1290 1111
1291 // Receives notifications from a PackExtensionJob, indicating either that 1112 // Receives notifications from a PackExtensionJob, indicating either that
1292 // packing succeeded or that there was some error. 1113 // packing succeeded or that there was some error.
1293 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { 1114 class PackExtensionTestClient : public extensions::PackExtensionJob::Client {
1294 public: 1115 public:
1295 PackExtensionTestClient(const base::FilePath& expected_crx_path, 1116 PackExtensionTestClient(const base::FilePath& expected_crx_path,
1296 const base::FilePath& expected_private_key_path); 1117 const base::FilePath& expected_private_key_path);
1297 virtual void OnPackSuccess(const base::FilePath& crx_path, 1118 virtual void OnPackSuccess(const base::FilePath& crx_path,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 if (type == ExtensionCreator::kCRXExists) 1154 if (type == ExtensionCreator::kCRXExists)
1334 FAIL() << "Packing should not fail."; 1155 FAIL() << "Packing should not fail.";
1335 else 1156 else
1336 FAIL() << "Existing CRX should have been overwritten."; 1157 FAIL() << "Existing CRX should have been overwritten.";
1337 } 1158 }
1338 1159
1339 // Test loading good extensions from the profile directory. 1160 // Test loading good extensions from the profile directory.
1340 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { 1161 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) {
1341 InitPluginService(); 1162 InitPluginService();
1342 InitializeGoodInstalledExtensionService(); 1163 InitializeGoodInstalledExtensionService();
1343 service_->Init(); 1164 service()->Init();
1344 1165
1345 uint32 expected_num_extensions = 3u; 1166 uint32 expected_num_extensions = 3u;
1346 ASSERT_EQ(expected_num_extensions, loaded_.size()); 1167 ASSERT_EQ(expected_num_extensions, loaded_.size());
1347 1168
1348 EXPECT_EQ(std::string(good0), loaded_[0]->id()); 1169 EXPECT_EQ(std::string(good0), loaded_[0]->id());
1349 EXPECT_EQ(std::string("My extension 1"), 1170 EXPECT_EQ(std::string("My extension 1"),
1350 loaded_[0]->name()); 1171 loaded_[0]->name());
1351 EXPECT_EQ(std::string("The first extension that I made."), 1172 EXPECT_EQ(std::string("The first extension that I made."),
1352 loaded_[0]->description()); 1173 loaded_[0]->description());
1353 EXPECT_EQ(Manifest::INTERNAL, loaded_[0]->location()); 1174 EXPECT_EQ(Manifest::INTERNAL, loaded_[0]->location());
1354 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)); 1175 EXPECT_TRUE(service()->GetExtensionById(loaded_[0]->id(), false));
1355 EXPECT_EQ(expected_num_extensions, registry_->enabled_extensions().size()); 1176 EXPECT_EQ(expected_num_extensions, registry()->enabled_extensions().size());
1356 1177
1357 ValidatePrefKeyCount(3); 1178 ValidatePrefKeyCount(3);
1358 ValidateIntegerPref(good0, "state", Extension::ENABLED); 1179 ValidateIntegerPref(good0, "state", Extension::ENABLED);
1359 ValidateIntegerPref(good0, "location", Manifest::INTERNAL); 1180 ValidateIntegerPref(good0, "location", Manifest::INTERNAL);
1360 ValidateIntegerPref(good1, "state", Extension::ENABLED); 1181 ValidateIntegerPref(good1, "state", Extension::ENABLED);
1361 ValidateIntegerPref(good1, "location", Manifest::INTERNAL); 1182 ValidateIntegerPref(good1, "location", Manifest::INTERNAL);
1362 ValidateIntegerPref(good2, "state", Extension::ENABLED); 1183 ValidateIntegerPref(good2, "state", Extension::ENABLED);
1363 ValidateIntegerPref(good2, "location", Manifest::INTERNAL); 1184 ValidateIntegerPref(good2, "location", Manifest::INTERNAL);
1364 1185
1365 URLPatternSet expected_patterns; 1186 URLPatternSet expected_patterns;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 EXPECT_EQ(std::string(), loaded_[index]->description()); 1258 EXPECT_EQ(std::string(), loaded_[index]->description());
1438 EXPECT_EQ(0u, 1259 EXPECT_EQ(0u,
1439 extensions::ContentScriptsInfo::GetContentScripts( 1260 extensions::ContentScriptsInfo::GetContentScripts(
1440 loaded_[index].get()).size()); 1261 loaded_[index].get()).size());
1441 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); 1262 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location());
1442 }; 1263 };
1443 1264
1444 // Test loading bad extensions from the profile directory. 1265 // Test loading bad extensions from the profile directory.
1445 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { 1266 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) {
1446 // Initialize the test dir with a bad Preferences/extensions. 1267 // Initialize the test dir with a bad Preferences/extensions.
1447 base::FilePath source_install_dir = data_dir_ 1268 base::FilePath source_install_dir =
1448 .AppendASCII("bad") 1269 data_dir().AppendASCII("bad").AppendASCII("Extensions");
1449 .AppendASCII("Extensions");
1450 base::FilePath pref_path = 1270 base::FilePath pref_path =
1451 source_install_dir.DirName().Append(chrome::kPreferencesFilename); 1271 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
1452 1272
1453 InitializeInstalledExtensionService(pref_path, source_install_dir); 1273 InitializeInstalledExtensionService(pref_path, source_install_dir);
1454 1274
1455 service_->Init(); 1275 service()->Init();
1456 1276
1457 ASSERT_EQ(4u, GetErrors().size()); 1277 ASSERT_EQ(4u, GetErrors().size());
1458 ASSERT_EQ(0u, loaded_.size()); 1278 ASSERT_EQ(0u, loaded_.size());
1459 1279
1460 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[0]), 1280 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[0]),
1461 std::string("Could not load extension from '*'. ") + 1281 std::string("Could not load extension from '*'. ") +
1462 extensions::manifest_errors::kManifestUnreadable)) << 1282 extensions::manifest_errors::kManifestUnreadable)) <<
1463 base::UTF16ToUTF8(GetErrors()[0]); 1283 base::UTF16ToUTF8(GetErrors()[0]);
1464 1284
1465 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[1]), 1285 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[1]),
1466 std::string("Could not load extension from '*'. ") + 1286 std::string("Could not load extension from '*'. ") +
1467 extensions::manifest_errors::kManifestUnreadable)) << 1287 extensions::manifest_errors::kManifestUnreadable)) <<
1468 base::UTF16ToUTF8(GetErrors()[1]); 1288 base::UTF16ToUTF8(GetErrors()[1]);
1469 1289
1470 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[2]), 1290 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[2]),
1471 std::string("Could not load extension from '*'. ") + 1291 std::string("Could not load extension from '*'. ") +
1472 extensions::manifest_errors::kMissingFile)) << 1292 extensions::manifest_errors::kMissingFile)) <<
1473 base::UTF16ToUTF8(GetErrors()[2]); 1293 base::UTF16ToUTF8(GetErrors()[2]);
1474 1294
1475 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[3]), 1295 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[3]),
1476 std::string("Could not load extension from '*'. ") + 1296 std::string("Could not load extension from '*'. ") +
1477 extensions::manifest_errors::kManifestUnreadable)) << 1297 extensions::manifest_errors::kManifestUnreadable)) <<
1478 base::UTF16ToUTF8(GetErrors()[3]); 1298 base::UTF16ToUTF8(GetErrors()[3]);
1479 }; 1299 };
1480 1300
1481 // Test various cases for delayed install because of missing imports. 1301 // Test various cases for delayed install because of missing imports.
1482 TEST_F(ExtensionServiceTest, PendingImports) { 1302 TEST_F(ExtensionServiceTest, PendingImports) {
1483 InitPluginService(); 1303 InitPluginService();
1484 1304
1485 base::FilePath source_install_dir = data_dir_ 1305 base::FilePath source_install_dir =
1486 .AppendASCII("pending_updates_with_imports") 1306 data_dir().AppendASCII("pending_updates_with_imports").AppendASCII(
1487 .AppendASCII("Extensions"); 1307 "Extensions");
1488 base::FilePath pref_path = 1308 base::FilePath pref_path =
1489 source_install_dir.DirName().Append(chrome::kPreferencesFilename); 1309 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
1490 1310
1491 InitializeInstalledExtensionService(pref_path, source_install_dir); 1311 InitializeInstalledExtensionService(pref_path, source_install_dir);
1492 1312
1493 // Verify there are no pending extensions initially. 1313 // Verify there are no pending extensions initially.
1494 EXPECT_FALSE(service_->pending_extension_manager()->HasPendingExtensions()); 1314 EXPECT_FALSE(service()->pending_extension_manager()->HasPendingExtensions());
1495 1315
1496 service_->Init(); 1316 service()->Init();
1497 // Wait for GarbageCollectExtensions task to complete. 1317 // Wait for GarbageCollectExtensions task to complete.
1498 base::RunLoop().RunUntilIdle(); 1318 base::RunLoop().RunUntilIdle();
1499 1319
1500 // These extensions are used by the extensions we test below, they must be 1320 // These extensions are used by the extensions we test below, they must be
1501 // installed. 1321 // installed.
1502 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1322 EXPECT_TRUE(base::PathExists(extensions_install_dir().AppendASCII(
1503 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); 1323 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0")));
1504 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( 1324 EXPECT_TRUE(base::PathExists(extensions_install_dir().AppendASCII(
1505 "hpiknbiabeeppbpihjehijgoemciehgk/2"))); 1325 "hpiknbiabeeppbpihjehijgoemciehgk/2")));
1506 1326
1507 // Each of these extensions should have been rejected because of dependencies 1327 // Each of these extensions should have been rejected because of dependencies
1508 // that cannot be satisfied. 1328 // that cannot be satisfied.
1509 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 1329 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
1510 EXPECT_FALSE( 1330 EXPECT_FALSE(
1511 prefs->GetDelayedInstallInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); 1331 prefs->GetDelayedInstallInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
1512 EXPECT_FALSE( 1332 EXPECT_FALSE(
1513 prefs->GetInstalledExtensionInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); 1333 prefs->GetInstalledExtensionInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
1514 EXPECT_FALSE( 1334 EXPECT_FALSE(
1515 prefs->GetDelayedInstallInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); 1335 prefs->GetDelayedInstallInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"));
1516 EXPECT_FALSE( 1336 EXPECT_FALSE(
1517 prefs->GetInstalledExtensionInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); 1337 prefs->GetInstalledExtensionInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"));
1518 EXPECT_FALSE( 1338 EXPECT_FALSE(
1519 prefs->GetDelayedInstallInfo("cccccccccccccccccccccccccccccccc")); 1339 prefs->GetDelayedInstallInfo("cccccccccccccccccccccccccccccccc"));
1520 EXPECT_FALSE( 1340 EXPECT_FALSE(
1521 prefs->GetInstalledExtensionInfo("cccccccccccccccccccccccccccccccc")); 1341 prefs->GetInstalledExtensionInfo("cccccccccccccccccccccccccccccccc"));
1522 1342
1523 // Make sure the import started for the extension with a dependency. 1343 // Make sure the import started for the extension with a dependency.
1524 EXPECT_TRUE( 1344 EXPECT_TRUE(
1525 prefs->GetDelayedInstallInfo("behllobkkfkfnphdnhnkndlbkcpglgmj")); 1345 prefs->GetDelayedInstallInfo("behllobkkfkfnphdnhnkndlbkcpglgmj"));
1526 EXPECT_EQ(ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, 1346 EXPECT_EQ(ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
1527 prefs->GetDelayedInstallReason("behllobkkfkfnphdnhnkndlbkcpglgmj")); 1347 prefs->GetDelayedInstallReason("behllobkkfkfnphdnhnkndlbkcpglgmj"));
1528 1348
1529 EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII( 1349 EXPECT_FALSE(base::PathExists(extensions_install_dir().AppendASCII(
1530 "behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0"))); 1350 "behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0")));
1531 1351
1532 EXPECT_TRUE(service_->pending_extension_manager()->HasPendingExtensions()); 1352 EXPECT_TRUE(service()->pending_extension_manager()->HasPendingExtensions());
1533 std::string pending_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); 1353 std::string pending_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
1534 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(pending_id)); 1354 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(pending_id));
1535 // Remove it because we are not testing the pending extension manager's 1355 // Remove it because we are not testing the pending extension manager's
1536 // ability to download and install extensions. 1356 // ability to download and install extensions.
1537 EXPECT_TRUE(service_->pending_extension_manager()->Remove(pending_id)); 1357 EXPECT_TRUE(service()->pending_extension_manager()->Remove(pending_id));
1538 } 1358 }
1539 1359
1540 // Test installing extensions. This test tries to install few extensions using 1360 // Test installing extensions. This test tries to install few extensions using
1541 // crx files. If you need to change those crx files, feel free to repackage 1361 // crx files. If you need to change those crx files, feel free to repackage
1542 // them, throw away the key used and change the id's above. 1362 // them, throw away the key used and change the id's above.
1543 TEST_F(ExtensionServiceTest, InstallExtension) { 1363 TEST_F(ExtensionServiceTest, InstallExtension) {
1544 InitializeEmptyExtensionService(); 1364 InitializeEmptyExtensionService();
1545 1365
1546 // Extensions not enabled. 1366 // Extensions not enabled.
1547 set_extensions_enabled(false); 1367 service()->set_extensions_enabled(false);
1548 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1368 base::FilePath path = data_dir().AppendASCII("good.crx");
1549 InstallCRX(path, INSTALL_FAILED); 1369 InstallCRX(path, INSTALL_FAILED);
1550 set_extensions_enabled(true); 1370 service()->set_extensions_enabled(true);
1551 1371
1552 ValidatePrefKeyCount(0); 1372 ValidatePrefKeyCount(0);
1553 1373
1554 // A simple extension that should install without error. 1374 // A simple extension that should install without error.
1555 path = data_dir_.AppendASCII("good.crx"); 1375 path = data_dir().AppendASCII("good.crx");
1556 InstallCRX(path, INSTALL_NEW); 1376 InstallCRX(path, INSTALL_NEW);
1557 // TODO(erikkay): verify the contents of the installed extension. 1377 // TODO(erikkay): verify the contents of the installed extension.
1558 1378
1559 int pref_count = 0; 1379 int pref_count = 0;
1560 ValidatePrefKeyCount(++pref_count); 1380 ValidatePrefKeyCount(++pref_count);
1561 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 1381 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
1562 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 1382 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
1563 1383
1564 // An extension with page actions. 1384 // An extension with page actions.
1565 path = data_dir_.AppendASCII("page_action.crx"); 1385 path = data_dir().AppendASCII("page_action.crx");
1566 InstallCRX(path, INSTALL_NEW); 1386 InstallCRX(path, INSTALL_NEW);
1567 ValidatePrefKeyCount(++pref_count); 1387 ValidatePrefKeyCount(++pref_count);
1568 ValidateIntegerPref(page_action, "state", Extension::ENABLED); 1388 ValidateIntegerPref(page_action, "state", Extension::ENABLED);
1569 ValidateIntegerPref(page_action, "location", Manifest::INTERNAL); 1389 ValidateIntegerPref(page_action, "location", Manifest::INTERNAL);
1570 1390
1571 // Bad signature. 1391 // Bad signature.
1572 path = data_dir_.AppendASCII("bad_signature.crx"); 1392 path = data_dir().AppendASCII("bad_signature.crx");
1573 InstallCRX(path, INSTALL_FAILED); 1393 InstallCRX(path, INSTALL_FAILED);
1574 ValidatePrefKeyCount(pref_count); 1394 ValidatePrefKeyCount(pref_count);
1575 1395
1576 // 0-length extension file. 1396 // 0-length extension file.
1577 path = data_dir_.AppendASCII("not_an_extension.crx"); 1397 path = data_dir().AppendASCII("not_an_extension.crx");
1578 InstallCRX(path, INSTALL_FAILED); 1398 InstallCRX(path, INSTALL_FAILED);
1579 ValidatePrefKeyCount(pref_count); 1399 ValidatePrefKeyCount(pref_count);
1580 1400
1581 // Bad magic number. 1401 // Bad magic number.
1582 path = data_dir_.AppendASCII("bad_magic.crx"); 1402 path = data_dir().AppendASCII("bad_magic.crx");
1583 InstallCRX(path, INSTALL_FAILED); 1403 InstallCRX(path, INSTALL_FAILED);
1584 ValidatePrefKeyCount(pref_count); 1404 ValidatePrefKeyCount(pref_count);
1585 1405
1586 // Packed extensions may have folders or files that have underscores. 1406 // Packed extensions may have folders or files that have underscores.
1587 // This will only cause a warning, rather than a fatal error. 1407 // This will only cause a warning, rather than a fatal error.
1588 path = data_dir_.AppendASCII("bad_underscore.crx"); 1408 path = data_dir().AppendASCII("bad_underscore.crx");
1589 InstallCRX(path, INSTALL_NEW); 1409 InstallCRX(path, INSTALL_NEW);
1590 ValidatePrefKeyCount(++pref_count); 1410 ValidatePrefKeyCount(++pref_count);
1591 1411
1592 // A test for an extension with a 2048-bit public key. 1412 // A test for an extension with a 2048-bit public key.
1593 path = data_dir_.AppendASCII("good2048.crx"); 1413 path = data_dir().AppendASCII("good2048.crx");
1594 InstallCRX(path, INSTALL_NEW); 1414 InstallCRX(path, INSTALL_NEW);
1595 ValidatePrefKeyCount(++pref_count); 1415 ValidatePrefKeyCount(++pref_count);
1596 ValidateIntegerPref(good2048, "state", Extension::ENABLED); 1416 ValidateIntegerPref(good2048, "state", Extension::ENABLED);
1597 ValidateIntegerPref(good2048, "location", Manifest::INTERNAL); 1417 ValidateIntegerPref(good2048, "location", Manifest::INTERNAL);
1598 1418
1599 // TODO(erikkay): add more tests for many of the failure cases. 1419 // TODO(erikkay): add more tests for many of the failure cases.
1600 // TODO(erikkay): add tests for upgrade cases. 1420 // TODO(erikkay): add tests for upgrade cases.
1601 } 1421 }
1602 1422
1603 struct MockExtensionRegistryObserver 1423 struct MockExtensionRegistryObserver
(...skipping 15 matching lines...) Expand all
1619 std::string last_extension_installed; 1439 std::string last_extension_installed;
1620 std::string last_extension_uninstalled; 1440 std::string last_extension_uninstalled;
1621 }; 1441 };
1622 1442
1623 // Test that correct notifications are sent to ExtensionRegistryObserver on 1443 // Test that correct notifications are sent to ExtensionRegistryObserver on
1624 // extension install and uninstall. 1444 // extension install and uninstall.
1625 TEST_F(ExtensionServiceTest, InstallObserverNotified) { 1445 TEST_F(ExtensionServiceTest, InstallObserverNotified) {
1626 InitializeEmptyExtensionService(); 1446 InitializeEmptyExtensionService();
1627 1447
1628 extensions::ExtensionRegistry* registry( 1448 extensions::ExtensionRegistry* registry(
1629 extensions::ExtensionRegistry::Get(profile_.get())); 1449 extensions::ExtensionRegistry::Get(profile()));
1630 MockExtensionRegistryObserver observer; 1450 MockExtensionRegistryObserver observer;
1631 registry->AddObserver(&observer); 1451 registry->AddObserver(&observer);
1632 1452
1633 // A simple extension that should install without error. 1453 // A simple extension that should install without error.
1634 ASSERT_TRUE(observer.last_extension_installed.empty()); 1454 ASSERT_TRUE(observer.last_extension_installed.empty());
1635 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1455 base::FilePath path = data_dir().AppendASCII("good.crx");
1636 InstallCRX(path, INSTALL_NEW); 1456 InstallCRX(path, INSTALL_NEW);
1637 ASSERT_EQ(good_crx, observer.last_extension_installed); 1457 ASSERT_EQ(good_crx, observer.last_extension_installed);
1638 1458
1639 // Uninstall the extension. 1459 // Uninstall the extension.
1640 ASSERT_TRUE(observer.last_extension_uninstalled.empty()); 1460 ASSERT_TRUE(observer.last_extension_uninstalled.empty());
1641 UninstallExtension(good_crx, false); 1461 UninstallExtension(good_crx, false);
1642 ASSERT_EQ(good_crx, observer.last_extension_uninstalled); 1462 ASSERT_EQ(good_crx, observer.last_extension_uninstalled);
1643 1463
1644 registry->RemoveObserver(&observer); 1464 registry->RemoveObserver(&observer);
1645 } 1465 }
1646 1466
1647 // Tests that flags passed to OnExternalExtensionFileFound() make it to the 1467 // Tests that flags passed to OnExternalExtensionFileFound() make it to the
1648 // extension object. 1468 // extension object.
1649 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { 1469 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) {
1650 const char kPrefFromBookmark[] = "from_bookmark"; 1470 const char kPrefFromBookmark[] = "from_bookmark";
1651 1471
1652 InitializeEmptyExtensionService(); 1472 InitializeEmptyExtensionService();
1653 1473
1654 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1474 base::FilePath path = data_dir().AppendASCII("good.crx");
1655 set_extensions_enabled(true); 1475 service()->set_extensions_enabled(true);
1656 1476
1657 // Register and install an external extension. 1477 // Register and install an external extension.
1658 Version version("1.0.0.0"); 1478 Version version("1.0.0.0");
1659 content::WindowedNotificationObserver observer( 1479 content::WindowedNotificationObserver observer(
1660 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1480 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1661 content::NotificationService::AllSources()); 1481 content::NotificationService::AllSources());
1662 if (service_->OnExternalExtensionFileFound( 1482 if (service()->OnExternalExtensionFileFound(good_crx,
1663 good_crx, 1483 &version,
1664 &version, 1484 path,
1665 path, 1485 Manifest::EXTERNAL_PREF,
1666 Manifest::EXTERNAL_PREF, 1486 Extension::FROM_BOOKMARK,
1667 Extension::FROM_BOOKMARK, 1487 false /* mark_acknowledged */)) {
1668 false /* mark_acknowledged */)) {
1669 observer.Wait(); 1488 observer.Wait();
1670 } 1489 }
1671 1490
1672 const Extension* extension = service_->GetExtensionById(good_crx, false); 1491 const Extension* extension = service()->GetExtensionById(good_crx, false);
1673 ASSERT_TRUE(extension); 1492 ASSERT_TRUE(extension);
1674 ASSERT_TRUE(extension->from_bookmark()); 1493 ASSERT_TRUE(extension->from_bookmark());
1675 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); 1494 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true));
1676 1495
1677 // Upgrade to version 2.0, the flag should be preserved. 1496 // Upgrade to version 2.0, the flag should be preserved.
1678 path = data_dir_.AppendASCII("good2.crx"); 1497 path = data_dir().AppendASCII("good2.crx");
1679 UpdateExtension(good_crx, path, ENABLED); 1498 UpdateExtension(good_crx, path, ENABLED);
1680 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); 1499 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true));
1681 extension = service_->GetExtensionById(good_crx, false); 1500 extension = service()->GetExtensionById(good_crx, false);
1682 ASSERT_TRUE(extension); 1501 ASSERT_TRUE(extension);
1683 ASSERT_TRUE(extension->from_bookmark()); 1502 ASSERT_TRUE(extension->from_bookmark());
1684 } 1503 }
1685 1504
1686 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED 1505 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED
1687 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { 1506 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) {
1688 InitializeEmptyExtensionService(); 1507 InitializeEmptyExtensionService();
1689 1508
1690 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1509 base::FilePath path = data_dir().AppendASCII("good.crx");
1691 set_extensions_enabled(true); 1510 service()->set_extensions_enabled(true);
1692 1511
1693 // Install an external extension. 1512 // Install an external extension.
1694 Version version("1.0.0.0"); 1513 Version version("1.0.0.0");
1695 content::WindowedNotificationObserver observer( 1514 content::WindowedNotificationObserver observer(
1696 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1515 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1697 content::NotificationService::AllSources()); 1516 content::NotificationService::AllSources());
1698 if (service_->OnExternalExtensionFileFound(good_crx, &version, 1517 if (service()->OnExternalExtensionFileFound(good_crx,
1699 path, Manifest::EXTERNAL_PREF, 1518 &version,
1700 Extension::NO_FLAGS, false)) { 1519 path,
1520 Manifest::EXTERNAL_PREF,
1521 Extension::NO_FLAGS,
1522 false)) {
1701 observer.Wait(); 1523 observer.Wait();
1702 } 1524 }
1703 1525
1704 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); 1526 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1705 1527
1706 // Uninstall it and check that its killbit gets set. 1528 // Uninstall it and check that its killbit gets set.
1707 UninstallExtension(good_crx, false); 1529 UninstallExtension(good_crx, false);
1708 ValidateIntegerPref(good_crx, "location", 1530 ValidateIntegerPref(good_crx, "location",
1709 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1531 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1710 1532
1711 // Try to re-install it externally. This should fail because of the killbit. 1533 // Try to re-install it externally. This should fail because of the killbit.
1712 service_->OnExternalExtensionFileFound(good_crx, &version, 1534 service()->OnExternalExtensionFileFound(good_crx,
1713 path, Manifest::EXTERNAL_PREF, 1535 &version,
1714 Extension::NO_FLAGS, false); 1536 path,
1537 Manifest::EXTERNAL_PREF,
1538 Extension::NO_FLAGS,
1539 false);
1715 base::RunLoop().RunUntilIdle(); 1540 base::RunLoop().RunUntilIdle();
1716 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); 1541 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false));
1717 ValidateIntegerPref(good_crx, "location", 1542 ValidateIntegerPref(good_crx, "location",
1718 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1543 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1719 1544
1720 version = Version("1.0.0.1"); 1545 version = Version("1.0.0.1");
1721 // Repeat the same thing with a newer version of the extension. 1546 // Repeat the same thing with a newer version of the extension.
1722 path = data_dir_.AppendASCII("good2.crx"); 1547 path = data_dir().AppendASCII("good2.crx");
1723 service_->OnExternalExtensionFileFound(good_crx, &version, 1548 service()->OnExternalExtensionFileFound(good_crx,
1724 path, Manifest::EXTERNAL_PREF, 1549 &version,
1725 Extension::NO_FLAGS, false); 1550 path,
1551 Manifest::EXTERNAL_PREF,
1552 Extension::NO_FLAGS,
1553 false);
1726 base::RunLoop().RunUntilIdle(); 1554 base::RunLoop().RunUntilIdle();
1727 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); 1555 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false));
1728 ValidateIntegerPref(good_crx, "location", 1556 ValidateIntegerPref(good_crx, "location",
1729 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1557 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1730 1558
1731 // Try adding the same extension from an external update URL. 1559 // Try adding the same extension from an external update URL.
1732 ASSERT_FALSE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( 1560 ASSERT_FALSE(service()->pending_extension_manager()->AddFromExternalUpdateUrl(
1733 good_crx, 1561 good_crx,
1734 std::string(), 1562 std::string(),
1735 GURL("http:://fake.update/url"), 1563 GURL("http:://fake.update/url"),
1736 Manifest::EXTERNAL_PREF_DOWNLOAD, 1564 Manifest::EXTERNAL_PREF_DOWNLOAD,
1737 Extension::NO_FLAGS, 1565 Extension::NO_FLAGS,
1738 false)); 1566 false));
1739 1567
1740 ASSERT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); 1568 ASSERT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx));
1741 } 1569 }
1742 1570
1743 // Test that uninstalling an external extension does not crash when 1571 // Test that uninstalling an external extension does not crash when
1744 // the extension could not be loaded. 1572 // the extension could not be loaded.
1745 // This extension shown in preferences file requires an experimental permission. 1573 // This extension shown in preferences file requires an experimental permission.
1746 // It could not be loaded without such permission. 1574 // It could not be loaded without such permission.
1747 TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) { 1575 TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) {
1748 base::FilePath source_install_dir = data_dir_ 1576 base::FilePath source_install_dir =
1749 .AppendASCII("good") 1577 data_dir().AppendASCII("good").AppendASCII("Extensions");
1750 .AppendASCII("Extensions");
1751 // The preference contains an external extension 1578 // The preference contains an external extension
1752 // that requires 'experimental' permission. 1579 // that requires 'experimental' permission.
1753 base::FilePath pref_path = source_install_dir 1580 base::FilePath pref_path = source_install_dir
1754 .DirName() 1581 .DirName()
1755 .AppendASCII("PreferencesExperimental"); 1582 .AppendASCII("PreferencesExperimental");
1756 1583
1757 // Aforementioned extension will not be loaded if 1584 // Aforementioned extension will not be loaded if
1758 // there is no '--enable-experimental-extension-apis' command line flag. 1585 // there is no '--enable-experimental-extension-apis' command line flag.
1759 InitializeInstalledExtensionService(pref_path, source_install_dir); 1586 InitializeInstalledExtensionService(pref_path, source_install_dir);
1760 1587
1761 service_->Init(); 1588 service()->Init();
1762 1589
1763 // Check and try to uninstall it. 1590 // Check and try to uninstall it.
1764 // If we don't check whether the extension is loaded before we uninstall it 1591 // If we don't check whether the extension is loaded before we uninstall it
1765 // in CheckExternalUninstall, a crash will happen here because we will get or 1592 // in CheckExternalUninstall, a crash will happen here because we will get or
1766 // dereference a NULL pointer (extension) inside UninstallExtension. 1593 // dereference a NULL pointer (extension) inside UninstallExtension.
1767 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); 1594 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY);
1768 service_->OnExternalProviderReady(&provider); 1595 service()->OnExternalProviderReady(&provider);
1769 } 1596 }
1770 1597
1771 // Test that external extensions with incorrect IDs are not installed. 1598 // Test that external extensions with incorrect IDs are not installed.
1772 TEST_F(ExtensionServiceTest, FailOnWrongId) { 1599 TEST_F(ExtensionServiceTest, FailOnWrongId) {
1773 InitializeEmptyExtensionService(); 1600 InitializeEmptyExtensionService();
1774 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1601 base::FilePath path = data_dir().AppendASCII("good.crx");
1775 set_extensions_enabled(true); 1602 service()->set_extensions_enabled(true);
1776 1603
1777 Version version("1.0.0.0"); 1604 Version version("1.0.0.0");
1778 1605
1779 const std::string wrong_id = all_zero; 1606 const std::string wrong_id = all_zero;
1780 const std::string correct_id = good_crx; 1607 const std::string correct_id = good_crx;
1781 ASSERT_NE(correct_id, wrong_id); 1608 ASSERT_NE(correct_id, wrong_id);
1782 1609
1783 // Install an external extension with an ID from the external 1610 // Install an external extension with an ID from the external
1784 // source that is not equal to the ID in the extension manifest. 1611 // source that is not equal to the ID in the extension manifest.
1785 content::WindowedNotificationObserver observer( 1612 content::WindowedNotificationObserver observer(
1786 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1613 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1787 content::NotificationService::AllSources()); 1614 content::NotificationService::AllSources());
1788 service_->OnExternalExtensionFileFound( 1615 service()->OnExternalExtensionFileFound(wrong_id,
1789 wrong_id, &version, path, Manifest::EXTERNAL_PREF, 1616 &version,
1790 Extension::NO_FLAGS, false); 1617 path,
1618 Manifest::EXTERNAL_PREF,
1619 Extension::NO_FLAGS,
1620 false);
1791 1621
1792 observer.Wait(); 1622 observer.Wait();
1793 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); 1623 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
1794 1624
1795 // Try again with the right ID. Expect success. 1625 // Try again with the right ID. Expect success.
1796 content::WindowedNotificationObserver observer2( 1626 content::WindowedNotificationObserver observer2(
1797 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1627 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1798 content::NotificationService::AllSources()); 1628 content::NotificationService::AllSources());
1799 if (service_->OnExternalExtensionFileFound( 1629 if (service()->OnExternalExtensionFileFound(correct_id,
1800 correct_id, &version, path, Manifest::EXTERNAL_PREF, 1630 &version,
1801 Extension::NO_FLAGS, false)) { 1631 path,
1632 Manifest::EXTERNAL_PREF,
1633 Extension::NO_FLAGS,
1634 false)) {
1802 observer2.Wait(); 1635 observer2.Wait();
1803 } 1636 }
1804 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); 1637 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1805 } 1638 }
1806 1639
1807 // Test that external extensions with incorrect versions are not installed. 1640 // Test that external extensions with incorrect versions are not installed.
1808 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { 1641 TEST_F(ExtensionServiceTest, FailOnWrongVersion) {
1809 InitializeEmptyExtensionService(); 1642 InitializeEmptyExtensionService();
1810 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1643 base::FilePath path = data_dir().AppendASCII("good.crx");
1811 set_extensions_enabled(true); 1644 service()->set_extensions_enabled(true);
1812 1645
1813 // Install an external extension with a version from the external 1646 // Install an external extension with a version from the external
1814 // source that is not equal to the version in the extension manifest. 1647 // source that is not equal to the version in the extension manifest.
1815 Version wrong_version("1.2.3.4"); 1648 Version wrong_version("1.2.3.4");
1816 content::WindowedNotificationObserver observer( 1649 content::WindowedNotificationObserver observer(
1817 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1650 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1818 content::NotificationService::AllSources()); 1651 content::NotificationService::AllSources());
1819 service_->OnExternalExtensionFileFound( 1652 service()->OnExternalExtensionFileFound(good_crx,
1820 good_crx, &wrong_version, path, Manifest::EXTERNAL_PREF, 1653 &wrong_version,
1821 Extension::NO_FLAGS, false); 1654 path,
1655 Manifest::EXTERNAL_PREF,
1656 Extension::NO_FLAGS,
1657 false);
1822 1658
1823 observer.Wait(); 1659 observer.Wait();
1824 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); 1660 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
1825 1661
1826 // Try again with the right version. Expect success. 1662 // Try again with the right version. Expect success.
1827 service_->pending_extension_manager()->Remove(good_crx); 1663 service()->pending_extension_manager()->Remove(good_crx);
1828 Version correct_version("1.0.0.0"); 1664 Version correct_version("1.0.0.0");
1829 content::WindowedNotificationObserver observer2( 1665 content::WindowedNotificationObserver observer2(
1830 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1666 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1831 content::NotificationService::AllSources()); 1667 content::NotificationService::AllSources());
1832 if (service_->OnExternalExtensionFileFound( 1668 if (service()->OnExternalExtensionFileFound(good_crx,
1833 good_crx, &correct_version, path, Manifest::EXTERNAL_PREF, 1669 &correct_version,
1834 Extension::NO_FLAGS, false)) { 1670 path,
1671 Manifest::EXTERNAL_PREF,
1672 Extension::NO_FLAGS,
1673 false)) {
1835 observer2.Wait(); 1674 observer2.Wait();
1836 } 1675 }
1837 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); 1676 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1838 } 1677 }
1839 1678
1840 // Install a user script (they get converted automatically to an extension) 1679 // Install a user script (they get converted automatically to an extension)
1841 TEST_F(ExtensionServiceTest, InstallUserScript) { 1680 TEST_F(ExtensionServiceTest, InstallUserScript) {
1842 // The details of script conversion are tested elsewhere, this just tests 1681 // The details of script conversion are tested elsewhere, this just tests
1843 // integration with ExtensionService. 1682 // integration with ExtensionService.
1844 InitializeEmptyExtensionService(); 1683 InitializeEmptyExtensionService();
1845 1684
1846 base::FilePath path = data_dir_ 1685 base::FilePath path = data_dir().AppendASCII("user_script_basic.user.js");
1847 .AppendASCII("user_script_basic.user.js");
1848 1686
1849 ASSERT_TRUE(base::PathExists(path)); 1687 ASSERT_TRUE(base::PathExists(path));
1850 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service_)); 1688 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service()));
1851 installer->set_allow_silent_install(true); 1689 installer->set_allow_silent_install(true);
1852 installer->InstallUserScript( 1690 installer->InstallUserScript(
1853 path, 1691 path,
1854 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); 1692 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js"));
1855 1693
1856 base::RunLoop().RunUntilIdle(); 1694 base::RunLoop().RunUntilIdle();
1857 std::vector<base::string16> errors = GetErrors(); 1695 std::vector<base::string16> errors = GetErrors();
1858 EXPECT_TRUE(installed_) << "Nothing was installed."; 1696 EXPECT_TRUE(installed_) << "Nothing was installed.";
1859 EXPECT_FALSE(was_update_) << path.value(); 1697 EXPECT_FALSE(was_update_) << path.value();
1860 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; 1698 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded.";
1861 EXPECT_EQ(0u, errors.size()) << "There were errors: " 1699 EXPECT_EQ(0u, errors.size()) << "There were errors: "
1862 << JoinString(errors, ','); 1700 << JoinString(errors, ',');
1863 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << 1701 EXPECT_TRUE(service()->GetExtensionById(loaded_[0]->id(), false))
1864 path.value(); 1702 << path.value();
1865 1703
1866 installed_ = NULL; 1704 installed_ = NULL;
1867 was_update_ = false; 1705 was_update_ = false;
1868 loaded_.clear(); 1706 loaded_.clear();
1869 ExtensionErrorReporter::GetInstance()->ClearErrors(); 1707 ExtensionErrorReporter::GetInstance()->ClearErrors();
1870 } 1708 }
1871 1709
1872 // Extensions don't install during shutdown. 1710 // Extensions don't install during shutdown.
1873 TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) { 1711 TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) {
1874 InitializeEmptyExtensionService(); 1712 InitializeEmptyExtensionService();
1875 1713
1876 // Simulate shutdown. 1714 // Simulate shutdown.
1877 service_->set_browser_terminating_for_test(true); 1715 service()->set_browser_terminating_for_test(true);
1878 1716
1879 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1717 base::FilePath path = data_dir().AppendASCII("good.crx");
1880 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service_)); 1718 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service()));
1881 installer->set_allow_silent_install(true); 1719 installer->set_allow_silent_install(true);
1882 installer->InstallCrx(path); 1720 installer->InstallCrx(path);
1883 base::RunLoop().RunUntilIdle(); 1721 base::RunLoop().RunUntilIdle();
1884 1722
1885 EXPECT_FALSE(installed_) << "Extension installed during shutdown."; 1723 EXPECT_FALSE(installed_) << "Extension installed during shutdown.";
1886 ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown."; 1724 ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown.";
1887 } 1725 }
1888 1726
1889 // This tests that the granted permissions preferences are correctly set when 1727 // This tests that the granted permissions preferences are correctly set when
1890 // installing an extension. 1728 // installing an extension.
1891 TEST_F(ExtensionServiceTest, GrantedPermissions) { 1729 TEST_F(ExtensionServiceTest, GrantedPermissions) {
1892 InitializeEmptyExtensionService(); 1730 InitializeEmptyExtensionService();
1893 base::FilePath path = data_dir_ 1731 base::FilePath path = data_dir().AppendASCII("permissions");
1894 .AppendASCII("permissions");
1895 1732
1896 base::FilePath pem_path = path.AppendASCII("unknown.pem"); 1733 base::FilePath pem_path = path.AppendASCII("unknown.pem");
1897 path = path.AppendASCII("unknown"); 1734 path = path.AppendASCII("unknown");
1898 1735
1899 ASSERT_TRUE(base::PathExists(pem_path)); 1736 ASSERT_TRUE(base::PathExists(pem_path));
1900 ASSERT_TRUE(base::PathExists(path)); 1737 ASSERT_TRUE(base::PathExists(path));
1901 1738
1902 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 1739 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
1903 1740
1904 APIPermissionSet expected_api_perms; 1741 APIPermissionSet expected_api_perms;
1905 URLPatternSet expected_host_perms; 1742 URLPatternSet expected_host_perms;
1906 1743
1907 // Make sure there aren't any granted permissions before the 1744 // Make sure there aren't any granted permissions before the
1908 // extension is installed. 1745 // extension is installed.
1909 scoped_refptr<PermissionSet> known_perms( 1746 scoped_refptr<PermissionSet> known_perms(
1910 prefs->GetGrantedPermissions(permissions_crx)); 1747 prefs->GetGrantedPermissions(permissions_crx));
1911 EXPECT_FALSE(known_perms.get()); 1748 EXPECT_FALSE(known_perms.get());
1912 1749
1913 const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); 1750 const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW);
1914 1751
1915 EXPECT_EQ(0u, GetErrors().size()); 1752 EXPECT_EQ(0u, GetErrors().size());
1916 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 1753 ASSERT_EQ(1u, registry()->enabled_extensions().size());
1917 EXPECT_EQ(permissions_crx, extension->id()); 1754 EXPECT_EQ(permissions_crx, extension->id());
1918 1755
1919 // Verify that the valid API permissions have been recognized. 1756 // Verify that the valid API permissions have been recognized.
1920 expected_api_perms.insert(APIPermission::kTab); 1757 expected_api_perms.insert(APIPermission::kTab);
1921 1758
1922 AddPattern(&expected_host_perms, "http://*.google.com/*"); 1759 AddPattern(&expected_host_perms, "http://*.google.com/*");
1923 AddPattern(&expected_host_perms, "https://*.google.com/*"); 1760 AddPattern(&expected_host_perms, "https://*.google.com/*");
1924 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); 1761 AddPattern(&expected_host_perms, "http://*.google.com.hk/*");
1925 AddPattern(&expected_host_perms, "http://www.example.com/*"); 1762 AddPattern(&expected_host_perms, "http://www.example.com/*");
1926 1763
1927 known_perms = prefs->GetGrantedPermissions(extension->id()); 1764 known_perms = prefs->GetGrantedPermissions(extension->id());
1928 EXPECT_TRUE(known_perms.get()); 1765 EXPECT_TRUE(known_perms.get());
1929 EXPECT_FALSE(known_perms->IsEmpty()); 1766 EXPECT_FALSE(known_perms->IsEmpty());
1930 EXPECT_EQ(expected_api_perms, known_perms->apis()); 1767 EXPECT_EQ(expected_api_perms, known_perms->apis());
1931 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); 1768 EXPECT_FALSE(known_perms->HasEffectiveFullAccess());
1932 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); 1769 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts());
1933 } 1770 }
1934 1771
1935 1772
1936 #if !defined(OS_CHROMEOS) 1773 #if !defined(OS_CHROMEOS)
1937 // This tests that the granted permissions preferences are correctly set for 1774 // This tests that the granted permissions preferences are correctly set for
1938 // default apps. 1775 // default apps.
1939 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { 1776 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) {
1940 InitializeEmptyExtensionService(); 1777 InitializeEmptyExtensionService();
1941 base::FilePath path = data_dir_ 1778 base::FilePath path = data_dir().AppendASCII("permissions");
1942 .AppendASCII("permissions");
1943 1779
1944 base::FilePath pem_path = path.AppendASCII("unknown.pem"); 1780 base::FilePath pem_path = path.AppendASCII("unknown.pem");
1945 path = path.AppendASCII("unknown"); 1781 path = path.AppendASCII("unknown");
1946 1782
1947 ASSERT_TRUE(base::PathExists(pem_path)); 1783 ASSERT_TRUE(base::PathExists(pem_path));
1948 ASSERT_TRUE(base::PathExists(path)); 1784 ASSERT_TRUE(base::PathExists(path));
1949 1785
1950 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 1786 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
1951 1787
1952 APIPermissionSet expected_api_perms; 1788 APIPermissionSet expected_api_perms;
1953 URLPatternSet expected_host_perms; 1789 URLPatternSet expected_host_perms;
1954 1790
1955 // Make sure there aren't any granted permissions before the 1791 // Make sure there aren't any granted permissions before the
1956 // extension is installed. 1792 // extension is installed.
1957 scoped_refptr<PermissionSet> known_perms( 1793 scoped_refptr<PermissionSet> known_perms(
1958 prefs->GetGrantedPermissions(permissions_crx)); 1794 prefs->GetGrantedPermissions(permissions_crx));
1959 EXPECT_FALSE(known_perms.get()); 1795 EXPECT_FALSE(known_perms.get());
1960 1796
1961 const Extension* extension = PackAndInstallCRX( 1797 const Extension* extension = PackAndInstallCRX(
1962 path, pem_path, INSTALL_NEW, Extension::WAS_INSTALLED_BY_DEFAULT); 1798 path, pem_path, INSTALL_NEW, Extension::WAS_INSTALLED_BY_DEFAULT);
1963 1799
1964 EXPECT_EQ(0u, GetErrors().size()); 1800 EXPECT_EQ(0u, GetErrors().size());
1965 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 1801 ASSERT_EQ(1u, registry()->enabled_extensions().size());
1966 EXPECT_EQ(permissions_crx, extension->id()); 1802 EXPECT_EQ(permissions_crx, extension->id());
1967 1803
1968 // Verify that the valid API permissions have been recognized. 1804 // Verify that the valid API permissions have been recognized.
1969 expected_api_perms.insert(APIPermission::kTab); 1805 expected_api_perms.insert(APIPermission::kTab);
1970 1806
1971 known_perms = prefs->GetGrantedPermissions(extension->id()); 1807 known_perms = prefs->GetGrantedPermissions(extension->id());
1972 EXPECT_TRUE(known_perms.get()); 1808 EXPECT_TRUE(known_perms.get());
1973 EXPECT_FALSE(known_perms->IsEmpty()); 1809 EXPECT_FALSE(known_perms->IsEmpty());
1974 EXPECT_EQ(expected_api_perms, known_perms->apis()); 1810 EXPECT_EQ(expected_api_perms, known_perms->apis());
1975 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); 1811 EXPECT_FALSE(known_perms->HasEffectiveFullAccess());
1976 } 1812 }
1977 #endif 1813 #endif
1978 1814
1979 #if !defined(OS_POSIX) || defined(OS_MACOSX) 1815 #if !defined(OS_POSIX) || defined(OS_MACOSX)
1980 // Tests that the granted permissions full_access bit gets set correctly when 1816 // Tests that the granted permissions full_access bit gets set correctly when
1981 // an extension contains an NPAPI plugin. 1817 // an extension contains an NPAPI plugin.
1982 // Only run this on platforms that support NPAPI plugins. 1818 // Only run this on platforms that support NPAPI plugins.
1983 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { 1819 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) {
1984 InitPluginService(); 1820 InitPluginService();
1985 1821
1986 InitializeEmptyExtensionService(); 1822 InitializeEmptyExtensionService();
1987 1823
1988 ASSERT_TRUE(base::PathExists(good1_path())); 1824 ASSERT_TRUE(base::PathExists(good1_path()));
1989 const Extension* extension = PackAndInstallCRX(good1_path(), INSTALL_NEW); 1825 const Extension* extension = PackAndInstallCRX(good1_path(), INSTALL_NEW);
1990 EXPECT_EQ(0u, GetErrors().size()); 1826 EXPECT_EQ(0u, GetErrors().size());
1991 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 1827 EXPECT_EQ(1u, registry()->enabled_extensions().size());
1992 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 1828 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
1993 1829
1994 scoped_refptr<PermissionSet> permissions( 1830 scoped_refptr<PermissionSet> permissions(
1995 prefs->GetGrantedPermissions(extension->id())); 1831 prefs->GetGrantedPermissions(extension->id()));
1996 EXPECT_FALSE(permissions->IsEmpty()); 1832 EXPECT_FALSE(permissions->IsEmpty());
1997 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); 1833 EXPECT_TRUE(permissions->HasEffectiveFullAccess());
1998 EXPECT_FALSE(permissions->apis().empty()); 1834 EXPECT_FALSE(permissions->apis().empty());
1999 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); 1835 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin));
2000 1836
2001 // Full access implies full host access too... 1837 // Full access implies full host access too...
2002 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); 1838 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts());
2003 } 1839 }
2004 #endif 1840 #endif
2005 1841
2006 // Tests that the extension is disabled when permissions are missing from 1842 // Tests that the extension is disabled when permissions are missing from
2007 // the extension's granted permissions preferences. (This simulates updating 1843 // the extension's granted permissions preferences. (This simulates updating
2008 // the browser to a version which recognizes more permissions). 1844 // the browser to a version which recognizes more permissions).
2009 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { 1845 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
2010 InitializeEmptyExtensionService(); 1846 InitializeEmptyExtensionService();
2011 1847
2012 base::FilePath path = data_dir_ 1848 base::FilePath path =
2013 .AppendASCII("permissions") 1849 data_dir().AppendASCII("permissions").AppendASCII("unknown");
2014 .AppendASCII("unknown");
2015 1850
2016 ASSERT_TRUE(base::PathExists(path)); 1851 ASSERT_TRUE(base::PathExists(path));
2017 1852
2018 const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW); 1853 const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW);
2019 1854
2020 EXPECT_EQ(0u, GetErrors().size()); 1855 EXPECT_EQ(0u, GetErrors().size());
2021 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 1856 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2022 std::string extension_id = extension->id(); 1857 std::string extension_id = extension->id();
2023 1858
2024 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 1859 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
2025 1860
2026 APIPermissionSet expected_api_permissions; 1861 APIPermissionSet expected_api_permissions;
2027 URLPatternSet expected_host_permissions; 1862 URLPatternSet expected_host_permissions;
2028 1863
2029 expected_api_permissions.insert(APIPermission::kTab); 1864 expected_api_permissions.insert(APIPermission::kTab);
2030 AddPattern(&expected_host_permissions, "http://*.google.com/*"); 1865 AddPattern(&expected_host_permissions, "http://*.google.com/*");
2031 AddPattern(&expected_host_permissions, "https://*.google.com/*"); 1866 AddPattern(&expected_host_permissions, "https://*.google.com/*");
2032 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); 1867 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*");
2033 AddPattern(&expected_host_permissions, "http://www.example.com/*"); 1868 AddPattern(&expected_host_permissions, "http://www.example.com/*");
2034 1869
2035 std::set<std::string> host_permissions; 1870 std::set<std::string> host_permissions;
2036 1871
2037 // Test that the extension is disabled when an API permission is missing from 1872 // Test that the extension is disabled when an API permission is missing from
2038 // the extension's granted api permissions preference. (This simulates 1873 // the extension's granted api permissions preference. (This simulates
2039 // updating the browser to a version which recognizes a new API permission). 1874 // updating the browser to a version which recognizes a new API permission).
2040 SetPref(extension_id, "granted_permissions.api", 1875 SetPref(extension_id, "granted_permissions.api",
2041 new base::ListValue(), "granted_permissions.api"); 1876 new base::ListValue(), "granted_permissions.api");
2042 service_->ReloadExtensionsForTest(); 1877 service()->ReloadExtensionsForTest();
2043 1878
2044 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 1879 EXPECT_EQ(1u, registry()->disabled_extensions().size());
2045 extension = registry_->disabled_extensions().begin()->get(); 1880 extension = registry()->disabled_extensions().begin()->get();
2046 1881
2047 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); 1882 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id));
2048 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); 1883 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id));
2049 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); 1884 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
2050 1885
2051 // Now grant and re-enable the extension, making sure the prefs are updated. 1886 // Now grant and re-enable the extension, making sure the prefs are updated.
2052 service_->GrantPermissionsAndEnableExtension(extension); 1887 service()->GrantPermissionsAndEnableExtension(extension);
2053 1888
2054 ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id)); 1889 ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id));
2055 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); 1890 ASSERT_TRUE(service()->IsExtensionEnabled(extension_id));
2056 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); 1891 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
2057 1892
2058 scoped_refptr<PermissionSet> current_perms( 1893 scoped_refptr<PermissionSet> current_perms(
2059 prefs->GetGrantedPermissions(extension_id)); 1894 prefs->GetGrantedPermissions(extension_id));
2060 ASSERT_TRUE(current_perms.get()); 1895 ASSERT_TRUE(current_perms.get());
2061 ASSERT_FALSE(current_perms->IsEmpty()); 1896 ASSERT_FALSE(current_perms->IsEmpty());
2062 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); 1897 ASSERT_FALSE(current_perms->HasEffectiveFullAccess());
2063 ASSERT_EQ(expected_api_permissions, current_perms->apis()); 1898 ASSERT_EQ(expected_api_permissions, current_perms->apis());
2064 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); 1899 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts());
2065 1900
2066 // Tests that the extension is disabled when a host permission is missing from 1901 // Tests that the extension is disabled when a host permission is missing from
2067 // the extension's granted host permissions preference. (This simulates 1902 // the extension's granted host permissions preference. (This simulates
2068 // updating the browser to a version which recognizes additional host 1903 // updating the browser to a version which recognizes additional host
2069 // permissions). 1904 // permissions).
2070 host_permissions.clear(); 1905 host_permissions.clear();
2071 current_perms = NULL; 1906 current_perms = NULL;
2072 1907
2073 host_permissions.insert("http://*.google.com/*"); 1908 host_permissions.insert("http://*.google.com/*");
2074 host_permissions.insert("https://*.google.com/*"); 1909 host_permissions.insert("https://*.google.com/*");
2075 host_permissions.insert("http://*.google.com.hk/*"); 1910 host_permissions.insert("http://*.google.com.hk/*");
2076 1911
2077 base::ListValue* api_permissions = new base::ListValue(); 1912 base::ListValue* api_permissions = new base::ListValue();
2078 api_permissions->Append( 1913 api_permissions->Append(
2079 new base::StringValue("tabs")); 1914 new base::StringValue("tabs"));
2080 SetPref(extension_id, "granted_permissions.api", 1915 SetPref(extension_id, "granted_permissions.api",
2081 api_permissions, "granted_permissions.api"); 1916 api_permissions, "granted_permissions.api");
2082 SetPrefStringSet( 1917 SetPrefStringSet(
2083 extension_id, "granted_permissions.scriptable_host", host_permissions); 1918 extension_id, "granted_permissions.scriptable_host", host_permissions);
2084 1919
2085 service_->ReloadExtensionsForTest(); 1920 service()->ReloadExtensionsForTest();
2086 1921
2087 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 1922 EXPECT_EQ(1u, registry()->disabled_extensions().size());
2088 extension = registry_->disabled_extensions().begin()->get(); 1923 extension = registry()->disabled_extensions().begin()->get();
2089 1924
2090 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); 1925 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id));
2091 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); 1926 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id));
2092 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); 1927 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
2093 1928
2094 // Now grant and re-enable the extension, making sure the prefs are updated. 1929 // Now grant and re-enable the extension, making sure the prefs are updated.
2095 service_->GrantPermissionsAndEnableExtension(extension); 1930 service()->GrantPermissionsAndEnableExtension(extension);
2096 1931
2097 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); 1932 ASSERT_TRUE(service()->IsExtensionEnabled(extension_id));
2098 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); 1933 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
2099 1934
2100 current_perms = prefs->GetGrantedPermissions(extension_id); 1935 current_perms = prefs->GetGrantedPermissions(extension_id);
2101 ASSERT_TRUE(current_perms.get()); 1936 ASSERT_TRUE(current_perms.get());
2102 ASSERT_FALSE(current_perms->IsEmpty()); 1937 ASSERT_FALSE(current_perms->IsEmpty());
2103 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); 1938 ASSERT_FALSE(current_perms->HasEffectiveFullAccess());
2104 ASSERT_EQ(expected_api_permissions, current_perms->apis()); 1939 ASSERT_EQ(expected_api_permissions, current_perms->apis());
2105 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); 1940 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts());
2106 } 1941 }
2107 1942
2108 // Test Packaging and installing an extension. 1943 // Test Packaging and installing an extension.
2109 TEST_F(ExtensionServiceTest, PackExtension) { 1944 TEST_F(ExtensionServiceTest, PackExtension) {
2110 InitializeEmptyExtensionService(); 1945 InitializeEmptyExtensionService();
2111 base::FilePath input_directory = data_dir_ 1946 base::FilePath input_directory =
2112 .AppendASCII("good") 1947 data_dir()
2113 .AppendASCII("Extensions") 1948 .AppendASCII("good")
2114 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 1949 .AppendASCII("Extensions")
2115 .AppendASCII("1.0.0.0"); 1950 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
1951 .AppendASCII("1.0.0.0");
2116 1952
2117 base::ScopedTempDir temp_dir; 1953 base::ScopedTempDir temp_dir;
2118 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1954 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
2119 base::FilePath output_directory = temp_dir.path(); 1955 base::FilePath output_directory = temp_dir.path();
2120 1956
2121 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); 1957 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
2122 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); 1958 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem"));
2123 1959
2124 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); 1960 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
2125 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), 1961 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 std::string invalid_manifest_content = "I am not a manifest."; 1999 std::string invalid_manifest_content = "I am not a manifest.";
2164 ASSERT_TRUE(base::WriteFile( 2000 ASSERT_TRUE(base::WriteFile(
2165 temp_dir2.path().Append(extensions::kManifestFilename), 2001 temp_dir2.path().Append(extensions::kManifestFilename),
2166 invalid_manifest_content.c_str(), invalid_manifest_content.size())); 2002 invalid_manifest_content.c_str(), invalid_manifest_content.size()));
2167 creator.reset(new ExtensionCreator()); 2003 creator.reset(new ExtensionCreator());
2168 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, 2004 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path,
2169 base::FilePath(), ExtensionCreator::kOverwriteCRX)); 2005 base::FilePath(), ExtensionCreator::kOverwriteCRX));
2170 2006
2171 // Try packing with a private key that is a valid key, but invalid for the 2007 // Try packing with a private key that is a valid key, but invalid for the
2172 // extension. 2008 // extension.
2173 base::FilePath bad_private_key_dir = data_dir_.AppendASCII("bad_private_key"); 2009 base::FilePath bad_private_key_dir =
2010 data_dir().AppendASCII("bad_private_key");
2174 crx_path = output_directory.AppendASCII("bad_private_key.crx"); 2011 crx_path = output_directory.AppendASCII("bad_private_key.crx");
2175 privkey_path = data_dir_.AppendASCII("bad_private_key.pem"); 2012 privkey_path = data_dir().AppendASCII("bad_private_key.pem");
2176 ASSERT_FALSE(creator->Run(bad_private_key_dir, crx_path, base::FilePath(), 2013 ASSERT_FALSE(creator->Run(bad_private_key_dir, crx_path, base::FilePath(),
2177 privkey_path, ExtensionCreator::kOverwriteCRX)); 2014 privkey_path, ExtensionCreator::kOverwriteCRX));
2178 } 2015 }
2179 2016
2180 // Test Packaging and installing an extension whose name contains punctuation. 2017 // Test Packaging and installing an extension whose name contains punctuation.
2181 TEST_F(ExtensionServiceTest, PackPunctuatedExtension) { 2018 TEST_F(ExtensionServiceTest, PackPunctuatedExtension) {
2182 InitializeEmptyExtensionService(); 2019 InitializeEmptyExtensionService();
2183 base::FilePath input_directory = data_dir_ 2020 base::FilePath input_directory = data_dir()
2184 .AppendASCII("good") 2021 .AppendASCII("good")
2185 .AppendASCII("Extensions") 2022 .AppendASCII("Extensions")
2186 .AppendASCII(good0) 2023 .AppendASCII(good0)
2187 .AppendASCII("1.0.0.0"); 2024 .AppendASCII("1.0.0.0");
2188 2025
2189 base::ScopedTempDir temp_dir; 2026 base::ScopedTempDir temp_dir;
2190 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 2027 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
2191 2028
2192 // Extension names containing punctuation, and the expected names for the 2029 // Extension names containing punctuation, and the expected names for the
2193 // packed extensions. 2030 // packed extensions.
2194 const base::FilePath punctuated_names[] = { 2031 const base::FilePath punctuated_names[] = {
2195 base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods")), 2032 base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods")),
2196 base::FilePath(FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod")), 2033 base::FilePath(FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod")),
2197 base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname/")). 2034 base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname/")).
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 InstallCRX(expected_crx_path, INSTALL_NEW); 2080 InstallCRX(expected_crx_path, INSTALL_NEW);
2244 } 2081 }
2245 } 2082 }
2246 2083
2247 TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) { 2084 TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) {
2248 InitializeEmptyExtensionService(); 2085 InitializeEmptyExtensionService();
2249 2086
2250 base::ScopedTempDir extension_temp_dir; 2087 base::ScopedTempDir extension_temp_dir;
2251 ASSERT_TRUE(extension_temp_dir.CreateUniqueTempDir()); 2088 ASSERT_TRUE(extension_temp_dir.CreateUniqueTempDir());
2252 base::FilePath input_directory = extension_temp_dir.path().AppendASCII("ext"); 2089 base::FilePath input_directory = extension_temp_dir.path().AppendASCII("ext");
2253 ASSERT_TRUE(base::CopyDirectory( 2090 ASSERT_TRUE(
2254 data_dir_ 2091 base::CopyDirectory(data_dir()
2255 .AppendASCII("good") 2092 .AppendASCII("good")
2256 .AppendASCII("Extensions") 2093 .AppendASCII("Extensions")
2257 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 2094 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
2258 .AppendASCII("1.0.0.0"), 2095 .AppendASCII("1.0.0.0"),
2259 input_directory, 2096 input_directory,
2260 /*recursive=*/true)); 2097 /*recursive=*/true));
2261 2098
2262 base::ScopedTempDir output_temp_dir; 2099 base::ScopedTempDir output_temp_dir;
2263 ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir()); 2100 ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir());
2264 base::FilePath output_directory = output_temp_dir.path(); 2101 base::FilePath output_directory = output_temp_dir.path();
2265 2102
2266 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); 2103 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
2267 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); 2104 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem"));
2268 2105
2269 // Pack the extension once to get a private key. 2106 // Pack the extension once to get a private key.
2270 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); 2107 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
(...skipping 17 matching lines...) Expand all
2288 } 2125 }
2289 2126
2290 // Test Packaging and installing an extension using an openssl generated key. 2127 // Test Packaging and installing an extension using an openssl generated key.
2291 // The openssl is generated with the following: 2128 // The openssl is generated with the following:
2292 // > openssl genrsa -out privkey.pem 1024 2129 // > openssl genrsa -out privkey.pem 1024
2293 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem 2130 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem
2294 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a 2131 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a
2295 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. 2132 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects.
2296 TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) { 2133 TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) {
2297 InitializeEmptyExtensionService(); 2134 InitializeEmptyExtensionService();
2298 base::FilePath input_directory = data_dir_ 2135 base::FilePath input_directory =
2299 .AppendASCII("good") 2136 data_dir()
2300 .AppendASCII("Extensions") 2137 .AppendASCII("good")
2301 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 2138 .AppendASCII("Extensions")
2302 .AppendASCII("1.0.0.0"); 2139 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
2303 base::FilePath privkey_path(data_dir_.AppendASCII( 2140 .AppendASCII("1.0.0.0");
2304 "openssl_privkey_asn1.pem")); 2141 base::FilePath privkey_path(
2142 data_dir().AppendASCII("openssl_privkey_asn1.pem"));
2305 ASSERT_TRUE(base::PathExists(privkey_path)); 2143 ASSERT_TRUE(base::PathExists(privkey_path));
2306 2144
2307 base::ScopedTempDir temp_dir; 2145 base::ScopedTempDir temp_dir;
2308 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 2146 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
2309 base::FilePath output_directory = temp_dir.path(); 2147 base::FilePath output_directory = temp_dir.path();
2310 2148
2311 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); 2149 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
2312 2150
2313 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); 2151 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
2314 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, 2152 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path,
2315 base::FilePath(), ExtensionCreator::kOverwriteCRX)); 2153 base::FilePath(), ExtensionCreator::kOverwriteCRX));
2316 2154
2317 InstallCRX(crx_path, INSTALL_NEW); 2155 InstallCRX(crx_path, INSTALL_NEW);
2318 } 2156 }
2319 2157
2320 #if defined(THREAD_SANITIZER) 2158 #if defined(THREAD_SANITIZER)
2321 // Flaky under Tsan. http://crbug.com/377702 2159 // Flaky under Tsan. http://crbug.com/377702
2322 #define MAYBE_InstallTheme DISABLED_InstallTheme 2160 #define MAYBE_InstallTheme DISABLED_InstallTheme
2323 #else 2161 #else
2324 #define MAYBE_InstallTheme InstallTheme 2162 #define MAYBE_InstallTheme InstallTheme
2325 #endif 2163 #endif
2326 2164
2327 TEST_F(ExtensionServiceTest, MAYBE_InstallTheme) { 2165 TEST_F(ExtensionServiceTest, MAYBE_InstallTheme) {
2328 InitializeEmptyExtensionService(); 2166 InitializeEmptyExtensionService();
2329 service_->Init(); 2167 service()->Init();
2330 2168
2331 // A theme. 2169 // A theme.
2332 base::FilePath path = data_dir_.AppendASCII("theme.crx"); 2170 base::FilePath path = data_dir().AppendASCII("theme.crx");
2333 InstallCRX(path, INSTALL_NEW); 2171 InstallCRX(path, INSTALL_NEW);
2334 int pref_count = 0; 2172 int pref_count = 0;
2335 ValidatePrefKeyCount(++pref_count); 2173 ValidatePrefKeyCount(++pref_count);
2336 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); 2174 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED);
2337 ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL); 2175 ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL);
2338 2176
2339 // A theme when extensions are disabled. Themes can be installed, even when 2177 // A theme when extensions are disabled. Themes can be installed, even when
2340 // extensions are disabled. 2178 // extensions are disabled.
2341 set_extensions_enabled(false); 2179 service()->set_extensions_enabled(false);
2342 path = data_dir_.AppendASCII("theme2.crx"); 2180 path = data_dir().AppendASCII("theme2.crx");
2343 InstallCRX(path, INSTALL_NEW); 2181 InstallCRX(path, INSTALL_NEW);
2344 ValidatePrefKeyCount(++pref_count); 2182 ValidatePrefKeyCount(++pref_count);
2345 ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED); 2183 ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED);
2346 ValidateIntegerPref(theme2_crx, "location", Manifest::INTERNAL); 2184 ValidateIntegerPref(theme2_crx, "location", Manifest::INTERNAL);
2347 2185
2348 // A theme with extension elements. Themes cannot have extension elements, 2186 // A theme with extension elements. Themes cannot have extension elements,
2349 // so any such elements (like content scripts) should be ignored. 2187 // so any such elements (like content scripts) should be ignored.
2350 set_extensions_enabled(true); 2188 service()->set_extensions_enabled(true);
2351 { 2189 {
2352 path = data_dir_.AppendASCII("theme_with_extension.crx"); 2190 path = data_dir().AppendASCII("theme_with_extension.crx");
2353 const Extension* extension = InstallCRX(path, INSTALL_NEW); 2191 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2354 ValidatePrefKeyCount(++pref_count); 2192 ValidatePrefKeyCount(++pref_count);
2355 ASSERT_TRUE(extension); 2193 ASSERT_TRUE(extension);
2356 EXPECT_TRUE(extension->is_theme()); 2194 EXPECT_TRUE(extension->is_theme());
2357 EXPECT_EQ( 2195 EXPECT_EQ(
2358 0u, 2196 0u,
2359 extensions::ContentScriptsInfo::GetContentScripts(extension).size()); 2197 extensions::ContentScriptsInfo::GetContentScripts(extension).size());
2360 } 2198 }
2361 2199
2362 // A theme with image resources missing (misspelt path). 2200 // A theme with image resources missing (misspelt path).
2363 path = data_dir_.AppendASCII("theme_missing_image.crx"); 2201 path = data_dir().AppendASCII("theme_missing_image.crx");
2364 InstallCRX(path, INSTALL_FAILED); 2202 InstallCRX(path, INSTALL_FAILED);
2365 ValidatePrefKeyCount(pref_count); 2203 ValidatePrefKeyCount(pref_count);
2366 } 2204 }
2367 2205
2368 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { 2206 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) {
2369 // Load. 2207 // Load.
2370 InitializeEmptyExtensionService(); 2208 InitializeEmptyExtensionService();
2371 service_->Init(); 2209 service()->Init();
2372 2210
2373 base::FilePath extension_path = data_dir_ 2211 base::FilePath extension_path = data_dir().AppendASCII("theme_i18n");
2374 .AppendASCII("theme_i18n");
2375 2212
2376 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2213 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
2377 base::RunLoop().RunUntilIdle(); 2214 base::RunLoop().RunUntilIdle();
2378 EXPECT_EQ(0u, GetErrors().size()); 2215 EXPECT_EQ(0u, GetErrors().size());
2379 ASSERT_EQ(1u, loaded_.size()); 2216 ASSERT_EQ(1u, loaded_.size());
2380 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2217 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2381 const Extension* theme = registry_->enabled_extensions().begin()->get(); 2218 const Extension* theme = registry()->enabled_extensions().begin()->get();
2382 EXPECT_EQ("name", theme->name()); 2219 EXPECT_EQ("name", theme->name());
2383 EXPECT_EQ("description", theme->description()); 2220 EXPECT_EQ("description", theme->description());
2384 2221
2385 // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a 2222 // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a
2386 // temporary directory, but it automatically installs to the extension's 2223 // temporary directory, but it automatically installs to the extension's
2387 // directory, and we don't want to copy the whole extension for a unittest. 2224 // directory, and we don't want to copy the whole extension for a unittest.
2388 base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename); 2225 base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename);
2389 ASSERT_TRUE(base::PathExists(theme_file)); 2226 ASSERT_TRUE(base::PathExists(theme_file));
2390 ASSERT_TRUE(base::DeleteFile(theme_file, false)); // Not recursive. 2227 ASSERT_TRUE(base::DeleteFile(theme_file, false)); // Not recursive.
2391 } 2228 }
2392 2229
2393 // Tests that we can change the ID of an unpacked extension by adding a key 2230 // Tests that we can change the ID of an unpacked extension by adding a key
2394 // to its manifest. 2231 // to its manifest.
2395 TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) { 2232 TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) {
2396 InitializeEmptyExtensionService(); 2233 InitializeEmptyExtensionService();
2397 2234
2398 base::ScopedTempDir temp; 2235 base::ScopedTempDir temp;
2399 ASSERT_TRUE(temp.CreateUniqueTempDir()); 2236 ASSERT_TRUE(temp.CreateUniqueTempDir());
2400 2237
2401 base::FilePath extension_path = temp.path(); 2238 base::FilePath extension_path = temp.path();
2402 base::FilePath manifest_path = 2239 base::FilePath manifest_path =
2403 extension_path.Append(extensions::kManifestFilename); 2240 extension_path.Append(extensions::kManifestFilename);
2404 base::FilePath manifest_no_key = data_dir_. 2241 base::FilePath manifest_no_key =
2405 AppendASCII("unpacked"). 2242 data_dir().AppendASCII("unpacked").AppendASCII("manifest_no_key.json");
2406 AppendASCII("manifest_no_key.json");
2407 2243
2408 base::FilePath manifest_with_key = data_dir_. 2244 base::FilePath manifest_with_key =
2409 AppendASCII("unpacked"). 2245 data_dir().AppendASCII("unpacked").AppendASCII("manifest_with_key.json");
2410 AppendASCII("manifest_with_key.json");
2411 2246
2412 ASSERT_TRUE(base::PathExists(manifest_no_key)); 2247 ASSERT_TRUE(base::PathExists(manifest_no_key));
2413 ASSERT_TRUE(base::PathExists(manifest_with_key)); 2248 ASSERT_TRUE(base::PathExists(manifest_with_key));
2414 2249
2415 // Load the unpacked extension with no key. 2250 // Load the unpacked extension with no key.
2416 base::CopyFile(manifest_no_key, manifest_path); 2251 base::CopyFile(manifest_no_key, manifest_path);
2417 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2252 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
2418 2253
2419 base::RunLoop().RunUntilIdle(); 2254 base::RunLoop().RunUntilIdle();
2420 EXPECT_EQ(0u, GetErrors().size()); 2255 EXPECT_EQ(0u, GetErrors().size());
2421 ASSERT_EQ(1u, loaded_.size()); 2256 ASSERT_EQ(1u, loaded_.size());
2422 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2257 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2423 2258
2424 // Add the key to the manifest. 2259 // Add the key to the manifest.
2425 base::CopyFile(manifest_with_key, manifest_path); 2260 base::CopyFile(manifest_with_key, manifest_path);
2426 loaded_.clear(); 2261 loaded_.clear();
2427 2262
2428 // Reload the extensions. 2263 // Reload the extensions.
2429 service_->ReloadExtensionsForTest(); 2264 service()->ReloadExtensionsForTest();
2430 const Extension* extension = service_->GetExtensionById(unpacked, false); 2265 const Extension* extension = service()->GetExtensionById(unpacked, false);
2431 EXPECT_EQ(unpacked, extension->id()); 2266 EXPECT_EQ(unpacked, extension->id());
2432 ASSERT_EQ(1u, loaded_.size()); 2267 ASSERT_EQ(1u, loaded_.size());
2433 2268
2434 // TODO(jstritar): Right now this just makes sure we don't crash and burn, but 2269 // TODO(jstritar): Right now this just makes sure we don't crash and burn, but
2435 // we should also test that preferences are preserved. 2270 // we should also test that preferences are preserved.
2436 } 2271 }
2437 2272
2438 #if defined(OS_POSIX) 2273 #if defined(OS_POSIX)
2439 TEST_F(ExtensionServiceTest, UnpackedExtensionMayContainSymlinkedFiles) { 2274 TEST_F(ExtensionServiceTest, UnpackedExtensionMayContainSymlinkedFiles) {
2440 base::FilePath source_data_dir = data_dir_. 2275 base::FilePath source_data_dir =
2441 AppendASCII("unpacked"). 2276 data_dir().AppendASCII("unpacked").AppendASCII("symlinks_allowed");
2442 AppendASCII("symlinks_allowed");
2443 2277
2444 // Paths to test data files. 2278 // Paths to test data files.
2445 base::FilePath source_manifest = source_data_dir.AppendASCII("manifest.json"); 2279 base::FilePath source_manifest = source_data_dir.AppendASCII("manifest.json");
2446 ASSERT_TRUE(base::PathExists(source_manifest)); 2280 ASSERT_TRUE(base::PathExists(source_manifest));
2447 base::FilePath source_icon = source_data_dir.AppendASCII("icon.png"); 2281 base::FilePath source_icon = source_data_dir.AppendASCII("icon.png");
2448 ASSERT_TRUE(base::PathExists(source_icon)); 2282 ASSERT_TRUE(base::PathExists(source_icon));
2449 2283
2450 // Set up the temporary extension directory. 2284 // Set up the temporary extension directory.
2451 base::ScopedTempDir temp; 2285 base::ScopedTempDir temp;
2452 ASSERT_TRUE(temp.CreateUniqueTempDir()); 2286 ASSERT_TRUE(temp.CreateUniqueTempDir());
2453 base::FilePath extension_path = temp.path(); 2287 base::FilePath extension_path = temp.path();
2454 base::FilePath manifest = extension_path.Append( 2288 base::FilePath manifest = extension_path.Append(
2455 extensions::kManifestFilename); 2289 extensions::kManifestFilename);
2456 base::FilePath icon_symlink = extension_path.AppendASCII("icon.png"); 2290 base::FilePath icon_symlink = extension_path.AppendASCII("icon.png");
2457 base::CopyFile(source_manifest, manifest); 2291 base::CopyFile(source_manifest, manifest);
2458 base::CreateSymbolicLink(source_icon, icon_symlink); 2292 base::CreateSymbolicLink(source_icon, icon_symlink);
2459 2293
2460 // Load extension. 2294 // Load extension.
2461 InitializeEmptyExtensionService(); 2295 InitializeEmptyExtensionService();
2462 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2296 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
2463 base::RunLoop().RunUntilIdle(); 2297 base::RunLoop().RunUntilIdle();
2464 2298
2465 EXPECT_TRUE(GetErrors().empty()); 2299 EXPECT_TRUE(GetErrors().empty());
2466 ASSERT_EQ(1u, loaded_.size()); 2300 ASSERT_EQ(1u, loaded_.size());
2467 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2301 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2468 } 2302 }
2469 #endif 2303 #endif
2470 2304
2471 TEST_F(ExtensionServiceTest, UnpackedExtensionMayNotHaveUnderscore) { 2305 TEST_F(ExtensionServiceTest, UnpackedExtensionMayNotHaveUnderscore) {
2472 InitializeEmptyExtensionService(); 2306 InitializeEmptyExtensionService();
2473 base::FilePath extension_path = data_dir_ 2307 base::FilePath extension_path = data_dir().AppendASCII("underscore_name");
2474 .AppendASCII("underscore_name"); 2308 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
2475 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2476 base::RunLoop().RunUntilIdle(); 2309 base::RunLoop().RunUntilIdle();
2477 EXPECT_EQ(1u, GetErrors().size()); 2310 EXPECT_EQ(1u, GetErrors().size());
2478 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 2311 EXPECT_EQ(0u, registry()->enabled_extensions().size());
2479 } 2312 }
2480 2313
2481 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { 2314 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) {
2482 InitializeEmptyExtensionService(); 2315 InitializeEmptyExtensionService();
2483 service_->Init(); 2316 service()->Init();
2484 2317
2485 base::FilePath theme_path = data_dir_ 2318 base::FilePath theme_path = data_dir().AppendASCII("theme_i18n");
2486 .AppendASCII("theme_i18n");
2487 2319
2488 const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW); 2320 const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW);
2489 2321
2490 EXPECT_EQ(0u, GetErrors().size()); 2322 EXPECT_EQ(0u, GetErrors().size());
2491 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2323 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2492 EXPECT_EQ("name", theme->name()); 2324 EXPECT_EQ("name", theme->name());
2493 EXPECT_EQ("description", theme->description()); 2325 EXPECT_EQ("description", theme->description());
2494 } 2326 }
2495 2327
2496 TEST_F(ExtensionServiceTest, InstallApps) { 2328 TEST_F(ExtensionServiceTest, InstallApps) {
2497 InitializeEmptyExtensionService(); 2329 InitializeEmptyExtensionService();
2498 2330
2499 // An empty app. 2331 // An empty app.
2500 const Extension* app = PackAndInstallCRX(data_dir_.AppendASCII("app1"), 2332 const Extension* app =
2501 INSTALL_NEW); 2333 PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
2502 int pref_count = 0; 2334 int pref_count = 0;
2503 ValidatePrefKeyCount(++pref_count); 2335 ValidatePrefKeyCount(++pref_count);
2504 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 2336 ASSERT_EQ(1u, registry()->enabled_extensions().size());
2505 ValidateIntegerPref(app->id(), "state", Extension::ENABLED); 2337 ValidateIntegerPref(app->id(), "state", Extension::ENABLED);
2506 ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL); 2338 ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL);
2507 2339
2508 // Another app with non-overlapping extent. Should succeed. 2340 // Another app with non-overlapping extent. Should succeed.
2509 PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 2341 PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
2510 ValidatePrefKeyCount(++pref_count); 2342 ValidatePrefKeyCount(++pref_count);
2511 2343
2512 // A third app whose extent overlaps the first. Should fail. 2344 // A third app whose extent overlaps the first. Should fail.
2513 PackAndInstallCRX(data_dir_.AppendASCII("app3"), INSTALL_FAILED); 2345 PackAndInstallCRX(data_dir().AppendASCII("app3"), INSTALL_FAILED);
2514 ValidatePrefKeyCount(pref_count); 2346 ValidatePrefKeyCount(pref_count);
2515 } 2347 }
2516 2348
2517 // Tests that file access is OFF by default. 2349 // Tests that file access is OFF by default.
2518 TEST_F(ExtensionServiceTest, DefaultFileAccess) { 2350 TEST_F(ExtensionServiceTest, DefaultFileAccess) {
2519 InitializeEmptyExtensionService(); 2351 InitializeEmptyExtensionService();
2520 const Extension* extension = 2352 const Extension* extension = PackAndInstallCRX(
2521 PackAndInstallCRX(data_dir_ 2353 data_dir().AppendASCII("permissions").AppendASCII("files"), INSTALL_NEW);
2522 .AppendASCII("permissions")
2523 .AppendASCII("files"),
2524 INSTALL_NEW);
2525 EXPECT_EQ(0u, GetErrors().size()); 2354 EXPECT_EQ(0u, GetErrors().size());
2526 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2355 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2527 EXPECT_FALSE( 2356 EXPECT_FALSE(
2528 ExtensionPrefs::Get(profile_.get())->AllowFileAccess(extension->id())); 2357 ExtensionPrefs::Get(profile())->AllowFileAccess(extension->id()));
2529 } 2358 }
2530 2359
2531 TEST_F(ExtensionServiceTest, UpdateApps) { 2360 TEST_F(ExtensionServiceTest, UpdateApps) {
2532 InitializeEmptyExtensionService(); 2361 InitializeEmptyExtensionService();
2533 base::FilePath extensions_path = data_dir_.AppendASCII("app_update"); 2362 base::FilePath extensions_path = data_dir().AppendASCII("app_update");
2534 2363
2535 // First install v1 of a hosted app. 2364 // First install v1 of a hosted app.
2536 const Extension* extension = 2365 const Extension* extension =
2537 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); 2366 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW);
2538 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 2367 ASSERT_EQ(1u, registry()->enabled_extensions().size());
2539 std::string id = extension->id(); 2368 std::string id = extension->id();
2540 ASSERT_EQ(std::string("1"), extension->version()->GetString()); 2369 ASSERT_EQ(std::string("1"), extension->version()->GetString());
2541 2370
2542 // Now try updating to v2. 2371 // Now try updating to v2.
2543 UpdateExtension(id, 2372 UpdateExtension(id,
2544 extensions_path.AppendASCII("v2.crx"), 2373 extensions_path.AppendASCII("v2.crx"),
2545 ENABLED); 2374 ENABLED);
2546 ASSERT_EQ(std::string("2"), 2375 ASSERT_EQ(std::string("2"),
2547 service_->GetExtensionById(id, false)->version()->GetString()); 2376 service()->GetExtensionById(id, false)->version()->GetString());
2548 } 2377 }
2549 2378
2550 // Verifies that the NTP page and launch ordinals are kept when updating apps. 2379 // Verifies that the NTP page and launch ordinals are kept when updating apps.
2551 TEST_F(ExtensionServiceTest, UpdateAppsRetainOrdinals) { 2380 TEST_F(ExtensionServiceTest, UpdateAppsRetainOrdinals) {
2552 InitializeEmptyExtensionService(); 2381 InitializeEmptyExtensionService();
2553 AppSorting* sorting = ExtensionPrefs::Get(profile_.get())->app_sorting(); 2382 AppSorting* sorting = ExtensionPrefs::Get(profile())->app_sorting();
2554 base::FilePath extensions_path = data_dir_.AppendASCII("app_update"); 2383 base::FilePath extensions_path = data_dir().AppendASCII("app_update");
2555 2384
2556 // First install v1 of a hosted app. 2385 // First install v1 of a hosted app.
2557 const Extension* extension = 2386 const Extension* extension =
2558 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); 2387 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW);
2559 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 2388 ASSERT_EQ(1u, registry()->enabled_extensions().size());
2560 std::string id = extension->id(); 2389 std::string id = extension->id();
2561 ASSERT_EQ(std::string("1"), extension->version()->GetString()); 2390 ASSERT_EQ(std::string("1"), extension->version()->GetString());
2562 2391
2563 // Modify the ordinals so we can distinguish them from the defaults. 2392 // Modify the ordinals so we can distinguish them from the defaults.
2564 syncer::StringOrdinal new_page_ordinal = 2393 syncer::StringOrdinal new_page_ordinal =
2565 sorting->GetPageOrdinal(id).CreateAfter(); 2394 sorting->GetPageOrdinal(id).CreateAfter();
2566 syncer::StringOrdinal new_launch_ordinal = 2395 syncer::StringOrdinal new_launch_ordinal =
2567 sorting->GetAppLaunchOrdinal(id).CreateBefore(); 2396 sorting->GetAppLaunchOrdinal(id).CreateBefore();
2568 2397
2569 sorting->SetPageOrdinal(id, new_page_ordinal); 2398 sorting->SetPageOrdinal(id, new_page_ordinal);
2570 sorting->SetAppLaunchOrdinal(id, new_launch_ordinal); 2399 sorting->SetAppLaunchOrdinal(id, new_launch_ordinal);
2571 2400
2572 // Now try updating to v2. 2401 // Now try updating to v2.
2573 UpdateExtension(id, extensions_path.AppendASCII("v2.crx"), ENABLED); 2402 UpdateExtension(id, extensions_path.AppendASCII("v2.crx"), ENABLED);
2574 ASSERT_EQ(std::string("2"), 2403 ASSERT_EQ(std::string("2"),
2575 service_->GetExtensionById(id, false)->version()->GetString()); 2404 service()->GetExtensionById(id, false)->version()->GetString());
2576 2405
2577 // Verify that the ordinals match. 2406 // Verify that the ordinals match.
2578 ASSERT_TRUE(new_page_ordinal.Equals(sorting->GetPageOrdinal(id))); 2407 ASSERT_TRUE(new_page_ordinal.Equals(sorting->GetPageOrdinal(id)));
2579 ASSERT_TRUE(new_launch_ordinal.Equals(sorting->GetAppLaunchOrdinal(id))); 2408 ASSERT_TRUE(new_launch_ordinal.Equals(sorting->GetAppLaunchOrdinal(id)));
2580 } 2409 }
2581 2410
2582 // Ensures that the CWS has properly initialized ordinals. 2411 // Ensures that the CWS has properly initialized ordinals.
2583 TEST_F(ExtensionServiceTest, EnsureCWSOrdinalsInitialized) { 2412 TEST_F(ExtensionServiceTest, EnsureCWSOrdinalsInitialized) {
2584 InitializeEmptyExtensionService(); 2413 InitializeEmptyExtensionService();
2585 service_->component_loader()->Add( 2414 service()->component_loader()->Add(
2586 IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store"))); 2415 IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store")));
2587 service_->Init(); 2416 service()->Init();
2588 2417
2589 AppSorting* sorting = ExtensionPrefs::Get(profile_.get())->app_sorting(); 2418 AppSorting* sorting = ExtensionPrefs::Get(profile())->app_sorting();
2590 EXPECT_TRUE( 2419 EXPECT_TRUE(
2591 sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid()); 2420 sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid());
2592 EXPECT_TRUE( 2421 EXPECT_TRUE(
2593 sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid()); 2422 sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid());
2594 } 2423 }
2595 2424
2596 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { 2425 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
2597 InitializeEmptyExtensionService(); 2426 InitializeEmptyExtensionService();
2598 EXPECT_TRUE(registry_->enabled_extensions().is_empty()); 2427 EXPECT_TRUE(registry()->enabled_extensions().is_empty());
2599 2428
2600 int pref_count = 0; 2429 int pref_count = 0;
2601 2430
2602 // Install app1 with unlimited storage. 2431 // Install app1 with unlimited storage.
2603 const Extension* extension = 2432 const Extension* extension =
2604 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 2433 PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
2605 ValidatePrefKeyCount(++pref_count); 2434 ValidatePrefKeyCount(++pref_count);
2606 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 2435 ASSERT_EQ(1u, registry()->enabled_extensions().size());
2607 const std::string id1 = extension->id(); 2436 const std::string id1 = extension->id();
2608 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( 2437 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
2609 APIPermission::kUnlimitedStorage)); 2438 APIPermission::kUnlimitedStorage));
2610 EXPECT_TRUE(extension->web_extent().MatchesURL( 2439 EXPECT_TRUE(extension->web_extent().MatchesURL(
2611 extensions::AppLaunchInfo::GetFullLaunchURL(extension))); 2440 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
2612 const GURL origin1( 2441 const GURL origin1(
2613 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 2442 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2614 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2443 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
2615 IsStorageUnlimited(origin1)); 2444 origin1));
2616 2445
2617 // Install app2 from the same origin with unlimited storage. 2446 // Install app2 from the same origin with unlimited storage.
2618 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 2447 extension = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
2619 ValidatePrefKeyCount(++pref_count); 2448 ValidatePrefKeyCount(++pref_count);
2620 ASSERT_EQ(2u, registry_->enabled_extensions().size()); 2449 ASSERT_EQ(2u, registry()->enabled_extensions().size());
2621 const std::string id2 = extension->id(); 2450 const std::string id2 = extension->id();
2622 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( 2451 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
2623 APIPermission::kUnlimitedStorage)); 2452 APIPermission::kUnlimitedStorage));
2624 EXPECT_TRUE(extension->web_extent().MatchesURL( 2453 EXPECT_TRUE(extension->web_extent().MatchesURL(
2625 extensions::AppLaunchInfo::GetFullLaunchURL(extension))); 2454 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
2626 const GURL origin2( 2455 const GURL origin2(
2627 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 2456 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2628 EXPECT_EQ(origin1, origin2); 2457 EXPECT_EQ(origin1, origin2);
2629 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2458 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
2630 IsStorageUnlimited(origin2)); 2459 origin2));
2631 2460
2632 // Uninstall one of them, unlimited storage should still be granted 2461 // Uninstall one of them, unlimited storage should still be granted
2633 // to the origin. 2462 // to the origin.
2634 UninstallExtension(id1, false); 2463 UninstallExtension(id1, false);
2635 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2464 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2636 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2465 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
2637 IsStorageUnlimited(origin1)); 2466 origin1));
2638 2467
2639 // Uninstall the other, unlimited storage should be revoked. 2468 // Uninstall the other, unlimited storage should be revoked.
2640 UninstallExtension(id2, false); 2469 UninstallExtension(id2, false);
2641 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 2470 EXPECT_EQ(0u, registry()->enabled_extensions().size());
2642 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 2471 EXPECT_FALSE(
2643 IsStorageUnlimited(origin2)); 2472 profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
2473 origin2));
2644 } 2474 }
2645 2475
2646 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { 2476 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
2647 InitializeEmptyExtensionService(); 2477 InitializeEmptyExtensionService();
2648 EXPECT_TRUE(registry_->enabled_extensions().is_empty()); 2478 EXPECT_TRUE(registry()->enabled_extensions().is_empty());
2649 2479
2650 int pref_count = 0; 2480 int pref_count = 0;
2651 2481
2652 const Extension* extension = 2482 const Extension* extension =
2653 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 2483 PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
2654 ValidatePrefKeyCount(++pref_count); 2484 ValidatePrefKeyCount(++pref_count);
2655 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 2485 ASSERT_EQ(1u, registry()->enabled_extensions().size());
2656 EXPECT_TRUE(extension->is_app()); 2486 EXPECT_TRUE(extension->is_app());
2657 const std::string id1 = extension->id(); 2487 const std::string id1 = extension->id();
2658 const GURL origin1( 2488 const GURL origin1(
2659 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 2489 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2660 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2490 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected(
2661 IsStorageProtected(origin1)); 2491 origin1));
2662 2492
2663 // App 4 has a different origin (maps.google.com). 2493 // App 4 has a different origin (maps.google.com).
2664 extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); 2494 extension = PackAndInstallCRX(data_dir().AppendASCII("app4"), INSTALL_NEW);
2665 ValidatePrefKeyCount(++pref_count); 2495 ValidatePrefKeyCount(++pref_count);
2666 ASSERT_EQ(2u, registry_->enabled_extensions().size()); 2496 ASSERT_EQ(2u, registry()->enabled_extensions().size());
2667 const std::string id2 = extension->id(); 2497 const std::string id2 = extension->id();
2668 const GURL origin2( 2498 const GURL origin2(
2669 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 2499 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2670 ASSERT_NE(origin1, origin2); 2500 ASSERT_NE(origin1, origin2);
2671 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2501 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected(
2672 IsStorageProtected(origin2)); 2502 origin2));
2673 2503
2674 UninstallExtension(id1, false); 2504 UninstallExtension(id1, false);
2675 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2505 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2676 2506
2677 UninstallExtension(id2, false); 2507 UninstallExtension(id2, false);
2678 2508
2679 EXPECT_TRUE(registry_->enabled_extensions().is_empty()); 2509 EXPECT_TRUE(registry()->enabled_extensions().is_empty());
2680 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 2510 EXPECT_FALSE(
2681 IsStorageProtected(origin1)); 2511 profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected(
2682 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 2512 origin1));
2683 IsStorageProtected(origin2)); 2513 EXPECT_FALSE(
2514 profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected(
2515 origin2));
2684 } 2516 }
2685 2517
2686 // Test that when an extension version is reinstalled, nothing happens. 2518 // Test that when an extension version is reinstalled, nothing happens.
2687 TEST_F(ExtensionServiceTest, Reinstall) { 2519 TEST_F(ExtensionServiceTest, Reinstall) {
2688 InitializeEmptyExtensionService(); 2520 InitializeEmptyExtensionService();
2689 2521
2690 // A simple extension that should install without error. 2522 // A simple extension that should install without error.
2691 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2523 base::FilePath path = data_dir().AppendASCII("good.crx");
2692 InstallCRX(path, INSTALL_NEW); 2524 InstallCRX(path, INSTALL_NEW);
2693 2525
2694 ValidatePrefKeyCount(1); 2526 ValidatePrefKeyCount(1);
2695 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 2527 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
2696 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 2528 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
2697 2529
2698 // Reinstall the same version, it should overwrite the previous one. 2530 // Reinstall the same version, it should overwrite the previous one.
2699 InstallCRX(path, INSTALL_UPDATED); 2531 InstallCRX(path, INSTALL_UPDATED);
2700 2532
2701 ValidatePrefKeyCount(1); 2533 ValidatePrefKeyCount(1);
2702 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 2534 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
2703 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 2535 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
2704 } 2536 }
2705 2537
2706 // Test that we can determine if extensions came from the 2538 // Test that we can determine if extensions came from the
2707 // Chrome web store. 2539 // Chrome web store.
2708 TEST_F(ExtensionServiceTest, FromWebStore) { 2540 TEST_F(ExtensionServiceTest, FromWebStore) {
2709 InitializeEmptyExtensionService(); 2541 InitializeEmptyExtensionService();
2710 2542
2711 // A simple extension that should install without error. 2543 // A simple extension that should install without error.
2712 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2544 base::FilePath path = data_dir().AppendASCII("good.crx");
2713 // Not from web store. 2545 // Not from web store.
2714 const Extension* extension = InstallCRX(path, INSTALL_NEW); 2546 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2715 std::string id = extension->id(); 2547 std::string id = extension->id();
2716 2548
2717 ValidatePrefKeyCount(1); 2549 ValidatePrefKeyCount(1);
2718 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", false)); 2550 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", false));
2719 ASSERT_FALSE(extension->from_webstore()); 2551 ASSERT_FALSE(extension->from_webstore());
2720 2552
2721 // Test install from web store. 2553 // Test install from web store.
2722 InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store. 2554 InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store.
2723 2555
2724 ValidatePrefKeyCount(1); 2556 ValidatePrefKeyCount(1);
2725 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true)); 2557 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true));
2726 2558
2727 // Reload so extension gets reinitialized with new value. 2559 // Reload so extension gets reinitialized with new value.
2728 service_->ReloadExtensionsForTest(); 2560 service()->ReloadExtensionsForTest();
2729 extension = service_->GetExtensionById(id, false); 2561 extension = service()->GetExtensionById(id, false);
2730 ASSERT_TRUE(extension->from_webstore()); 2562 ASSERT_TRUE(extension->from_webstore());
2731 2563
2732 // Upgrade to version 2.0 2564 // Upgrade to version 2.0
2733 path = data_dir_.AppendASCII("good2.crx"); 2565 path = data_dir().AppendASCII("good2.crx");
2734 UpdateExtension(good_crx, path, ENABLED); 2566 UpdateExtension(good_crx, path, ENABLED);
2735 ValidatePrefKeyCount(1); 2567 ValidatePrefKeyCount(1);
2736 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true)); 2568 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true));
2737 } 2569 }
2738 2570
2739 // Test upgrading a signed extension. 2571 // Test upgrading a signed extension.
2740 TEST_F(ExtensionServiceTest, UpgradeSignedGood) { 2572 TEST_F(ExtensionServiceTest, UpgradeSignedGood) {
2741 InitializeEmptyExtensionService(); 2573 InitializeEmptyExtensionService();
2742 2574
2743 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2575 base::FilePath path = data_dir().AppendASCII("good.crx");
2744 const Extension* extension = InstallCRX(path, INSTALL_NEW); 2576 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2745 std::string id = extension->id(); 2577 std::string id = extension->id();
2746 2578
2747 ASSERT_EQ("1.0.0.0", extension->version()->GetString()); 2579 ASSERT_EQ("1.0.0.0", extension->version()->GetString());
2748 ASSERT_EQ(0u, GetErrors().size()); 2580 ASSERT_EQ(0u, GetErrors().size());
2749 2581
2750 // Upgrade to version 1.0.0.1. 2582 // Upgrade to version 1.0.0.1.
2751 // Also test that the extension's old and new title are correctly retrieved. 2583 // Also test that the extension's old and new title are correctly retrieved.
2752 path = data_dir_.AppendASCII("good2.crx"); 2584 path = data_dir().AppendASCII("good2.crx");
2753 InstallCRX(path, INSTALL_UPDATED, Extension::NO_FLAGS, "My extension 1"); 2585 InstallCRX(path, INSTALL_UPDATED, Extension::NO_FLAGS, "My extension 1");
2754 extension = service_->GetExtensionById(id, false); 2586 extension = service()->GetExtensionById(id, false);
2755 2587
2756 ASSERT_EQ("1.0.0.1", extension->version()->GetString()); 2588 ASSERT_EQ("1.0.0.1", extension->version()->GetString());
2757 ASSERT_EQ("My updated extension 1", extension->name()); 2589 ASSERT_EQ("My updated extension 1", extension->name());
2758 ASSERT_EQ(0u, GetErrors().size()); 2590 ASSERT_EQ(0u, GetErrors().size());
2759 } 2591 }
2760 2592
2761 // Test upgrading a signed extension with a bad signature. 2593 // Test upgrading a signed extension with a bad signature.
2762 TEST_F(ExtensionServiceTest, UpgradeSignedBad) { 2594 TEST_F(ExtensionServiceTest, UpgradeSignedBad) {
2763 InitializeEmptyExtensionService(); 2595 InitializeEmptyExtensionService();
2764 2596
2765 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2597 base::FilePath path = data_dir().AppendASCII("good.crx");
2766 InstallCRX(path, INSTALL_NEW); 2598 InstallCRX(path, INSTALL_NEW);
2767 2599
2768 // Try upgrading with a bad signature. This should fail during the unpack, 2600 // Try upgrading with a bad signature. This should fail during the unpack,
2769 // because the key will not match the signature. 2601 // because the key will not match the signature.
2770 path = data_dir_.AppendASCII("bad_signature.crx"); 2602 path = data_dir().AppendASCII("bad_signature.crx");
2771 InstallCRX(path, INSTALL_FAILED); 2603 InstallCRX(path, INSTALL_FAILED);
2772 } 2604 }
2773 2605
2774 // Test a normal update via the UpdateExtension API 2606 // Test a normal update via the UpdateExtension API
2775 TEST_F(ExtensionServiceTest, UpdateExtension) { 2607 TEST_F(ExtensionServiceTest, UpdateExtension) {
2776 InitializeEmptyExtensionService(); 2608 InitializeEmptyExtensionService();
2777 2609
2778 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2610 base::FilePath path = data_dir().AppendASCII("good.crx");
2779 2611
2780 const Extension* good = InstallCRX(path, INSTALL_NEW); 2612 const Extension* good = InstallCRX(path, INSTALL_NEW);
2781 ASSERT_EQ("1.0.0.0", good->VersionString()); 2613 ASSERT_EQ("1.0.0.0", good->VersionString());
2782 ASSERT_EQ(good_crx, good->id()); 2614 ASSERT_EQ(good_crx, good->id());
2783 2615
2784 path = data_dir_.AppendASCII("good2.crx"); 2616 path = data_dir().AppendASCII("good2.crx");
2785 UpdateExtension(good_crx, path, ENABLED); 2617 UpdateExtension(good_crx, path, ENABLED);
2786 ASSERT_EQ("1.0.0.1", 2618 ASSERT_EQ(
2787 service_->GetExtensionById(good_crx, false)-> 2619 "1.0.0.1",
2788 version()->GetString()); 2620 service()->GetExtensionById(good_crx, false)->version()->GetString());
2789 } 2621 }
2790 2622
2791 // Extensions should not be updated during browser shutdown. 2623 // Extensions should not be updated during browser shutdown.
2792 TEST_F(ExtensionServiceTest, UpdateExtensionDuringShutdown) { 2624 TEST_F(ExtensionServiceTest, UpdateExtensionDuringShutdown) {
2793 InitializeEmptyExtensionService(); 2625 InitializeEmptyExtensionService();
2794 2626
2795 // Install an extension. 2627 // Install an extension.
2796 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2628 base::FilePath path = data_dir().AppendASCII("good.crx");
2797 const Extension* good = InstallCRX(path, INSTALL_NEW); 2629 const Extension* good = InstallCRX(path, INSTALL_NEW);
2798 ASSERT_EQ(good_crx, good->id()); 2630 ASSERT_EQ(good_crx, good->id());
2799 2631
2800 // Simulate shutdown. 2632 // Simulate shutdown.
2801 service_->set_browser_terminating_for_test(true); 2633 service()->set_browser_terminating_for_test(true);
2802 2634
2803 // Update should fail and extension should not be updated. 2635 // Update should fail and extension should not be updated.
2804 path = data_dir_.AppendASCII("good2.crx"); 2636 path = data_dir().AppendASCII("good2.crx");
2805 bool updated = service_->UpdateExtension(good_crx, path, true, NULL); 2637 bool updated = service()->UpdateExtension(good_crx, path, true, NULL);
2806 ASSERT_FALSE(updated); 2638 ASSERT_FALSE(updated);
2807 ASSERT_EQ("1.0.0.0", 2639 ASSERT_EQ(
2808 service_->GetExtensionById(good_crx, false)-> 2640 "1.0.0.0",
2809 version()->GetString()); 2641 service()->GetExtensionById(good_crx, false)->version()->GetString());
2810 } 2642 }
2811 2643
2812 // Test updating a not-already-installed extension - this should fail 2644 // Test updating a not-already-installed extension - this should fail
2813 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) { 2645 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) {
2814 InitializeEmptyExtensionService(); 2646 InitializeEmptyExtensionService();
2815 2647
2816 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2648 base::FilePath path = data_dir().AppendASCII("good.crx");
2817 UpdateExtension(good_crx, path, UPDATED); 2649 UpdateExtension(good_crx, path, UPDATED);
2818 base::RunLoop().RunUntilIdle(); 2650 base::RunLoop().RunUntilIdle();
2819 2651
2820 ASSERT_EQ(0u, registry_->enabled_extensions().size()); 2652 ASSERT_EQ(0u, registry()->enabled_extensions().size());
2821 ASSERT_FALSE(installed_); 2653 ASSERT_FALSE(installed_);
2822 ASSERT_EQ(0u, loaded_.size()); 2654 ASSERT_EQ(0u, loaded_.size());
2823 } 2655 }
2824 2656
2825 // Makes sure you can't downgrade an extension via UpdateExtension 2657 // Makes sure you can't downgrade an extension via UpdateExtension
2826 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { 2658 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) {
2827 InitializeEmptyExtensionService(); 2659 InitializeEmptyExtensionService();
2828 2660
2829 base::FilePath path = data_dir_.AppendASCII("good2.crx"); 2661 base::FilePath path = data_dir().AppendASCII("good2.crx");
2830 2662
2831 const Extension* good = InstallCRX(path, INSTALL_NEW); 2663 const Extension* good = InstallCRX(path, INSTALL_NEW);
2832 ASSERT_EQ("1.0.0.1", good->VersionString()); 2664 ASSERT_EQ("1.0.0.1", good->VersionString());
2833 ASSERT_EQ(good_crx, good->id()); 2665 ASSERT_EQ(good_crx, good->id());
2834 2666
2835 // Change path from good2.crx -> good.crx 2667 // Change path from good2.crx -> good.crx
2836 path = data_dir_.AppendASCII("good.crx"); 2668 path = data_dir().AppendASCII("good.crx");
2837 UpdateExtension(good_crx, path, FAILED); 2669 UpdateExtension(good_crx, path, FAILED);
2838 ASSERT_EQ("1.0.0.1", 2670 ASSERT_EQ(
2839 service_->GetExtensionById(good_crx, false)-> 2671 "1.0.0.1",
2840 version()->GetString()); 2672 service()->GetExtensionById(good_crx, false)->version()->GetString());
2841 } 2673 }
2842 2674
2843 // Make sure calling update with an identical version does nothing 2675 // Make sure calling update with an identical version does nothing
2844 TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) { 2676 TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) {
2845 InitializeEmptyExtensionService(); 2677 InitializeEmptyExtensionService();
2846 2678
2847 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2679 base::FilePath path = data_dir().AppendASCII("good.crx");
2848 2680
2849 const Extension* good = InstallCRX(path, INSTALL_NEW); 2681 const Extension* good = InstallCRX(path, INSTALL_NEW);
2850 ASSERT_EQ(good_crx, good->id()); 2682 ASSERT_EQ(good_crx, good->id());
2851 UpdateExtension(good_crx, path, FAILED_SILENTLY); 2683 UpdateExtension(good_crx, path, FAILED_SILENTLY);
2852 } 2684 }
2853 2685
2854 // Tests that updating an extension does not clobber old state. 2686 // Tests that updating an extension does not clobber old state.
2855 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) { 2687 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) {
2856 InitializeEmptyExtensionService(); 2688 InitializeEmptyExtensionService();
2857 2689
2858 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2690 base::FilePath path = data_dir().AppendASCII("good.crx");
2859 2691
2860 const Extension* good = InstallCRX(path, INSTALL_NEW); 2692 const Extension* good = InstallCRX(path, INSTALL_NEW);
2861 ASSERT_EQ("1.0.0.0", good->VersionString()); 2693 ASSERT_EQ("1.0.0.0", good->VersionString());
2862 ASSERT_EQ(good_crx, good->id()); 2694 ASSERT_EQ(good_crx, good->id());
2863 2695
2864 // Disable it and allow it to run in incognito. These settings should carry 2696 // Disable it and allow it to run in incognito. These settings should carry
2865 // over to the updated version. 2697 // over to the updated version.
2866 service_->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION); 2698 service()->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION);
2867 extensions::util::SetIsIncognitoEnabled(good->id(), profile_.get(), true); 2699 extensions::util::SetIsIncognitoEnabled(good->id(), profile(), true);
2868 ExtensionPrefs::Get(profile_.get()) 2700 ExtensionPrefs::Get(profile())
2869 ->SetDidExtensionEscalatePermissions(good, true); 2701 ->SetDidExtensionEscalatePermissions(good, true);
2870 2702
2871 path = data_dir_.AppendASCII("good2.crx"); 2703 path = data_dir().AppendASCII("good2.crx");
2872 UpdateExtension(good_crx, path, INSTALLED); 2704 UpdateExtension(good_crx, path, INSTALLED);
2873 ASSERT_EQ(1u, registry_->disabled_extensions().size()); 2705 ASSERT_EQ(1u, registry()->disabled_extensions().size());
2874 const Extension* good2 = service_->GetExtensionById(good_crx, true); 2706 const Extension* good2 = service()->GetExtensionById(good_crx, true);
2875 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); 2707 ASSERT_EQ("1.0.0.1", good2->version()->GetString());
2876 EXPECT_TRUE(extensions::util::IsIncognitoEnabled( 2708 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good2->id(), profile()));
2877 good2->id(), profile_.get())); 2709 EXPECT_TRUE(ExtensionPrefs::Get(profile())
2878 EXPECT_TRUE(ExtensionPrefs::Get(profile_.get())
2879 ->DidExtensionEscalatePermissions(good2->id())); 2710 ->DidExtensionEscalatePermissions(good2->id()));
2880 } 2711 }
2881 2712
2882 // Tests that updating preserves extension location. 2713 // Tests that updating preserves extension location.
2883 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { 2714 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) {
2884 InitializeEmptyExtensionService(); 2715 InitializeEmptyExtensionService();
2885 2716
2886 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2717 base::FilePath path = data_dir().AppendASCII("good.crx");
2887 2718
2888 const Extension* good = 2719 const Extension* good =
2889 InstallCRXWithLocation(path, Manifest::EXTERNAL_PREF, INSTALL_NEW); 2720 InstallCRXWithLocation(path, Manifest::EXTERNAL_PREF, INSTALL_NEW);
2890 2721
2891 ASSERT_EQ("1.0.0.0", good->VersionString()); 2722 ASSERT_EQ("1.0.0.0", good->VersionString());
2892 ASSERT_EQ(good_crx, good->id()); 2723 ASSERT_EQ(good_crx, good->id());
2893 2724
2894 path = data_dir_.AppendASCII("good2.crx"); 2725 path = data_dir().AppendASCII("good2.crx");
2895 UpdateExtension(good_crx, path, ENABLED); 2726 UpdateExtension(good_crx, path, ENABLED);
2896 const Extension* good2 = service_->GetExtensionById(good_crx, false); 2727 const Extension* good2 = service()->GetExtensionById(good_crx, false);
2897 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); 2728 ASSERT_EQ("1.0.0.1", good2->version()->GetString());
2898 EXPECT_EQ(good2->location(), Manifest::EXTERNAL_PREF); 2729 EXPECT_EQ(good2->location(), Manifest::EXTERNAL_PREF);
2899 } 2730 }
2900 2731
2901 // Makes sure that LOAD extension types can downgrade. 2732 // Makes sure that LOAD extension types can downgrade.
2902 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { 2733 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) {
2903 InitializeEmptyExtensionService(); 2734 InitializeEmptyExtensionService();
2904 2735
2905 base::ScopedTempDir temp; 2736 base::ScopedTempDir temp;
2906 ASSERT_TRUE(temp.CreateUniqueTempDir()); 2737 ASSERT_TRUE(temp.CreateUniqueTempDir());
2907 2738
2908 // We'll write the extension manifest dynamically to a temporary path 2739 // We'll write the extension manifest dynamically to a temporary path
2909 // to make it easier to change the version number. 2740 // to make it easier to change the version number.
2910 base::FilePath extension_path = temp.path(); 2741 base::FilePath extension_path = temp.path();
2911 base::FilePath manifest_path = 2742 base::FilePath manifest_path =
2912 extension_path.Append(extensions::kManifestFilename); 2743 extension_path.Append(extensions::kManifestFilename);
2913 ASSERT_FALSE(base::PathExists(manifest_path)); 2744 ASSERT_FALSE(base::PathExists(manifest_path));
2914 2745
2915 // Start with version 2.0. 2746 // Start with version 2.0.
2916 base::DictionaryValue manifest; 2747 base::DictionaryValue manifest;
2917 manifest.SetString("version", "2.0"); 2748 manifest.SetString("version", "2.0");
2918 manifest.SetString("name", "LOAD Downgrade Test"); 2749 manifest.SetString("name", "LOAD Downgrade Test");
2919 manifest.SetInteger("manifest_version", 2); 2750 manifest.SetInteger("manifest_version", 2);
2920 2751
2921 JSONFileValueSerializer serializer(manifest_path); 2752 JSONFileValueSerializer serializer(manifest_path);
2922 ASSERT_TRUE(serializer.Serialize(manifest)); 2753 ASSERT_TRUE(serializer.Serialize(manifest));
2923 2754
2924 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2755 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
2925 base::RunLoop().RunUntilIdle(); 2756 base::RunLoop().RunUntilIdle();
2926 2757
2927 EXPECT_EQ(0u, GetErrors().size()); 2758 EXPECT_EQ(0u, GetErrors().size());
2928 ASSERT_EQ(1u, loaded_.size()); 2759 ASSERT_EQ(1u, loaded_.size());
2929 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); 2760 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
2930 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2761 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2931 EXPECT_EQ("2.0", loaded_[0]->VersionString()); 2762 EXPECT_EQ("2.0", loaded_[0]->VersionString());
2932 2763
2933 // Now set the version number to 1.0, reload the extensions and verify that 2764 // Now set the version number to 1.0, reload the extensions and verify that
2934 // the downgrade was accepted. 2765 // the downgrade was accepted.
2935 manifest.SetString("version", "1.0"); 2766 manifest.SetString("version", "1.0");
2936 ASSERT_TRUE(serializer.Serialize(manifest)); 2767 ASSERT_TRUE(serializer.Serialize(manifest));
2937 2768
2938 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2769 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
2939 base::RunLoop().RunUntilIdle(); 2770 base::RunLoop().RunUntilIdle();
2940 2771
2941 EXPECT_EQ(0u, GetErrors().size()); 2772 EXPECT_EQ(0u, GetErrors().size());
2942 ASSERT_EQ(1u, loaded_.size()); 2773 ASSERT_EQ(1u, loaded_.size());
2943 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); 2774 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
2944 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2775 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2945 EXPECT_EQ("1.0", loaded_[0]->VersionString()); 2776 EXPECT_EQ("1.0", loaded_[0]->VersionString());
2946 } 2777 }
2947 2778
2948 #if !defined(OS_POSIX) || defined(OS_MACOSX) 2779 #if !defined(OS_POSIX) || defined(OS_MACOSX)
2949 // LOAD extensions with plugins require approval. 2780 // LOAD extensions with plugins require approval.
2950 // Only run this on platforms that support NPAPI plugins. 2781 // Only run this on platforms that support NPAPI plugins.
2951 TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) { 2782 TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) {
2952 base::FilePath extension_with_plugin_path = good1_path(); 2783 base::FilePath extension_with_plugin_path = good1_path();
2953 base::FilePath extension_no_plugin_path = good2_path(); 2784 base::FilePath extension_no_plugin_path = good2_path();
2954 2785
2955 InitPluginService(); 2786 InitPluginService();
2956 InitializeEmptyExtensionService(); 2787 InitializeEmptyExtensionService();
2957 InitializeProcessManager(); 2788 InitializeProcessManager();
2958 service_->set_show_extensions_prompts(true); 2789 service()->set_show_extensions_prompts(true);
2959 2790
2960 // Start by canceling any install prompts. 2791 // Start by canceling any install prompts.
2961 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2792 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2962 switches::kAppsGalleryInstallAutoConfirmForTests, 2793 switches::kAppsGalleryInstallAutoConfirmForTests,
2963 "cancel"); 2794 "cancel");
2964 2795
2965 // The extension that has a plugin should not install. 2796 // The extension that has a plugin should not install.
2966 extensions::UnpackedInstaller::Create(service_)->Load( 2797 extensions::UnpackedInstaller::Create(service())
2967 extension_with_plugin_path); 2798 ->Load(extension_with_plugin_path);
2968 base::RunLoop().RunUntilIdle(); 2799 base::RunLoop().RunUntilIdle();
2969 EXPECT_EQ(0u, GetErrors().size()); 2800 EXPECT_EQ(0u, GetErrors().size());
2970 EXPECT_EQ(0u, loaded_.size()); 2801 EXPECT_EQ(0u, loaded_.size());
2971 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 2802 EXPECT_EQ(0u, registry()->enabled_extensions().size());
2972 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 2803 EXPECT_EQ(0u, registry()->disabled_extensions().size());
2973 2804
2974 // But the extension with no plugin should since there's no prompt. 2805 // But the extension with no plugin should since there's no prompt.
2975 ExtensionErrorReporter::GetInstance()->ClearErrors(); 2806 ExtensionErrorReporter::GetInstance()->ClearErrors();
2976 extensions::UnpackedInstaller::Create(service_)->Load( 2807 extensions::UnpackedInstaller::Create(service())
2977 extension_no_plugin_path); 2808 ->Load(extension_no_plugin_path);
2978 base::RunLoop().RunUntilIdle(); 2809 base::RunLoop().RunUntilIdle();
2979 EXPECT_EQ(0u, GetErrors().size()); 2810 EXPECT_EQ(0u, GetErrors().size());
2980 EXPECT_EQ(1u, loaded_.size()); 2811 EXPECT_EQ(1u, loaded_.size());
2981 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 2812 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2982 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 2813 EXPECT_EQ(0u, registry()->disabled_extensions().size());
2983 EXPECT_TRUE(registry_->enabled_extensions().Contains(good2)); 2814 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
2984 2815
2985 // The plugin extension should install if we accept the dialog. 2816 // The plugin extension should install if we accept the dialog.
2986 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2817 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2987 switches::kAppsGalleryInstallAutoConfirmForTests, 2818 switches::kAppsGalleryInstallAutoConfirmForTests,
2988 "accept"); 2819 "accept");
2989 2820
2990 ExtensionErrorReporter::GetInstance()->ClearErrors(); 2821 ExtensionErrorReporter::GetInstance()->ClearErrors();
2991 extensions::UnpackedInstaller::Create(service_)->Load( 2822 extensions::UnpackedInstaller::Create(service())
2992 extension_with_plugin_path); 2823 ->Load(extension_with_plugin_path);
2993 base::RunLoop().RunUntilIdle(); 2824 base::RunLoop().RunUntilIdle();
2994 EXPECT_EQ(0u, GetErrors().size()); 2825 EXPECT_EQ(0u, GetErrors().size());
2995 EXPECT_EQ(2u, loaded_.size()); 2826 EXPECT_EQ(2u, loaded_.size());
2996 EXPECT_EQ(2u, registry_->enabled_extensions().size()); 2827 EXPECT_EQ(2u, registry()->enabled_extensions().size());
2997 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 2828 EXPECT_EQ(0u, registry()->disabled_extensions().size());
2998 EXPECT_TRUE(registry_->enabled_extensions().Contains(good1)); 2829 EXPECT_TRUE(registry()->enabled_extensions().Contains(good1));
2999 EXPECT_TRUE(registry_->enabled_extensions().Contains(good2)); 2830 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
3000 2831
3001 // Make sure the granted permissions have been setup. 2832 // Make sure the granted permissions have been setup.
3002 scoped_refptr<PermissionSet> permissions( 2833 scoped_refptr<PermissionSet> permissions(
3003 ExtensionPrefs::Get(profile_.get())->GetGrantedPermissions(good1)); 2834 ExtensionPrefs::Get(profile())->GetGrantedPermissions(good1));
3004 EXPECT_FALSE(permissions->IsEmpty()); 2835 EXPECT_FALSE(permissions->IsEmpty());
3005 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); 2836 EXPECT_TRUE(permissions->HasEffectiveFullAccess());
3006 EXPECT_FALSE(permissions->apis().empty()); 2837 EXPECT_FALSE(permissions->apis().empty());
3007 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); 2838 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin));
3008 2839
3009 // We should be able to reload the extension without getting another prompt. 2840 // We should be able to reload the extension without getting another prompt.
3010 loaded_.clear(); 2841 loaded_.clear();
3011 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2842 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
3012 switches::kAppsGalleryInstallAutoConfirmForTests, 2843 switches::kAppsGalleryInstallAutoConfirmForTests,
3013 "cancel"); 2844 "cancel");
3014 2845
3015 service_->ReloadExtension(good1); 2846 service()->ReloadExtension(good1);
3016 base::RunLoop().RunUntilIdle(); 2847 base::RunLoop().RunUntilIdle();
3017 EXPECT_EQ(1u, loaded_.size()); 2848 EXPECT_EQ(1u, loaded_.size());
3018 EXPECT_EQ(2u, registry_->enabled_extensions().size()); 2849 EXPECT_EQ(2u, registry()->enabled_extensions().size());
3019 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 2850 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3020 } 2851 }
3021 #endif // !defined(OS_POSIX) || defined(OS_MACOSX) 2852 #endif // !defined(OS_POSIX) || defined(OS_MACOSX)
3022 2853
3023 namespace { 2854 namespace {
3024 2855
3025 bool IsExtension(const Extension* extension) { 2856 bool IsExtension(const Extension* extension) {
3026 return extension->GetType() == Manifest::TYPE_EXTENSION; 2857 return extension->GetType() == Manifest::TYPE_EXTENSION;
3027 } 2858 }
3028 2859
3029 #if defined(ENABLE_BLACKLIST_TESTS) 2860 #if defined(ENABLE_BLACKLIST_TESTS)
(...skipping 14 matching lines...) Expand all
3044 // Test adding a pending extension. 2875 // Test adding a pending extension.
3045 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { 2876 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) {
3046 InitializeEmptyExtensionService(); 2877 InitializeEmptyExtensionService();
3047 2878
3048 const std::string kFakeId(all_zero); 2879 const std::string kFakeId(all_zero);
3049 const GURL kFakeUpdateURL("http:://fake.update/url"); 2880 const GURL kFakeUpdateURL("http:://fake.update/url");
3050 const bool kFakeInstallSilently(true); 2881 const bool kFakeInstallSilently(true);
3051 const bool kFakeRemoteInstall(false); 2882 const bool kFakeRemoteInstall(false);
3052 2883
3053 EXPECT_TRUE( 2884 EXPECT_TRUE(
3054 service_->pending_extension_manager()->AddFromSync(kFakeId, 2885 service()->pending_extension_manager()->AddFromSync(kFakeId,
3055 kFakeUpdateURL, 2886 kFakeUpdateURL,
3056 &IsExtension, 2887 &IsExtension,
3057 kFakeInstallSilently, 2888 kFakeInstallSilently,
3058 kFakeRemoteInstall)); 2889 kFakeRemoteInstall));
3059 2890
3060 const extensions::PendingExtensionInfo* pending_extension_info; 2891 const extensions::PendingExtensionInfo* pending_extension_info;
3061 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> 2892 ASSERT_TRUE((pending_extension_info =
3062 GetById(kFakeId))); 2893 service()->pending_extension_manager()->GetById(kFakeId)));
3063 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); 2894 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url());
3064 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); 2895 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_);
3065 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently()); 2896 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently());
3066 // Use 2897 // Use
3067 // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()) 2898 // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install())
3068 // instead of 2899 // instead of
3069 // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install()) 2900 // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install())
3070 // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is 2901 // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is
3071 // turned into an error with -Werror=conversion-null: 2902 // turned into an error with -Werror=conversion-null:
3072 // converting 'false' to pointer type for argument 1 of 2903 // converting 'false' to pointer type for argument 1 of
3073 // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' 2904 // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)'
3074 // https://code.google.com/p/googletest/issues/detail?id=458 2905 // https://code.google.com/p/googletest/issues/detail?id=458
3075 EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()); 2906 EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install());
3076 } 2907 }
3077 2908
3078 namespace { 2909 namespace {
3079 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 2910 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
3080 const char kGoodUpdateURL[] = "http://good.update/url"; 2911 const char kGoodUpdateURL[] = "http://good.update/url";
3081 const bool kGoodIsFromSync = true; 2912 const bool kGoodIsFromSync = true;
3082 const bool kGoodInstallSilently = true; 2913 const bool kGoodInstallSilently = true;
3083 const bool kGoodRemoteInstall = false; 2914 const bool kGoodRemoteInstall = false;
3084 } // namespace 2915 } // namespace
3085 2916
3086 // Test updating a pending extension. 2917 // Test updating a pending extension.
3087 TEST_F(ExtensionServiceTest, UpdatePendingExtension) { 2918 TEST_F(ExtensionServiceTest, UpdatePendingExtension) {
3088 InitializeEmptyExtensionService(); 2919 InitializeEmptyExtensionService();
3089 EXPECT_TRUE( 2920 EXPECT_TRUE(
3090 service_->pending_extension_manager()->AddFromSync(kGoodId, 2921 service()->pending_extension_manager()->AddFromSync(kGoodId,
3091 GURL(kGoodUpdateURL), 2922 GURL(kGoodUpdateURL),
3092 &IsExtension, 2923 &IsExtension,
3093 kGoodInstallSilently, 2924 kGoodInstallSilently,
3094 kGoodRemoteInstall)); 2925 kGoodRemoteInstall));
3095 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(kGoodId)); 2926 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3096 2927
3097 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2928 base::FilePath path = data_dir().AppendASCII("good.crx");
3098 UpdateExtension(kGoodId, path, ENABLED); 2929 UpdateExtension(kGoodId, path, ENABLED);
3099 2930
3100 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); 2931 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3101 2932
3102 const Extension* extension = service_->GetExtensionById(kGoodId, true); 2933 const Extension* extension = service()->GetExtensionById(kGoodId, true);
3103 ASSERT_TRUE(extension); 2934 ASSERT_TRUE(extension);
3104 } 2935 }
3105 2936
3106 namespace { 2937 namespace {
3107 2938
3108 bool IsTheme(const Extension* extension) { 2939 bool IsTheme(const Extension* extension) {
3109 return extension->is_theme(); 2940 return extension->is_theme();
3110 } 2941 }
3111 2942
3112 } // namespace 2943 } // namespace
3113 2944
3114 // Test updating a pending theme. 2945 // Test updating a pending theme.
3115 // Disabled due to ASAN failure. http://crbug.com/108320 2946 // Disabled due to ASAN failure. http://crbug.com/108320
3116 TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) { 2947 TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) {
3117 InitializeEmptyExtensionService(); 2948 InitializeEmptyExtensionService();
3118 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( 2949 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync(
3119 theme_crx, GURL(), &IsTheme, false, false)); 2950 theme_crx, GURL(), &IsTheme, false, false));
3120 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 2951 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3121 2952
3122 base::FilePath path = data_dir_.AppendASCII("theme.crx"); 2953 base::FilePath path = data_dir().AppendASCII("theme.crx");
3123 UpdateExtension(theme_crx, path, ENABLED); 2954 UpdateExtension(theme_crx, path, ENABLED);
3124 2955
3125 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 2956 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3126 2957
3127 const Extension* extension = service_->GetExtensionById(theme_crx, true); 2958 const Extension* extension = service()->GetExtensionById(theme_crx, true);
3128 ASSERT_TRUE(extension); 2959 ASSERT_TRUE(extension);
3129 2960
3130 EXPECT_FALSE(ExtensionPrefs::Get(profile_.get()) 2961 EXPECT_FALSE(
3131 ->IsExtensionDisabled(extension->id())); 2962 ExtensionPrefs::Get(profile())->IsExtensionDisabled(extension->id()));
3132 EXPECT_TRUE(service_->IsExtensionEnabled(theme_crx)); 2963 EXPECT_TRUE(service()->IsExtensionEnabled(theme_crx));
3133 } 2964 }
3134 2965
3135 #if defined(OS_CHROMEOS) 2966 #if defined(OS_CHROMEOS)
3136 // Always fails on ChromeOS: http://crbug.com/79737 2967 // Always fails on ChromeOS: http://crbug.com/79737
3137 #define MAYBE_UpdatePendingExternalCrx DISABLED_UpdatePendingExternalCrx 2968 #define MAYBE_UpdatePendingExternalCrx DISABLED_UpdatePendingExternalCrx
3138 #else 2969 #else
3139 #define MAYBE_UpdatePendingExternalCrx UpdatePendingExternalCrx 2970 #define MAYBE_UpdatePendingExternalCrx UpdatePendingExternalCrx
3140 #endif 2971 #endif
3141 // Test updating a pending CRX as if the source is an external extension 2972 // Test updating a pending CRX as if the source is an external extension
3142 // with an update URL. In this case we don't know if the CRX is a theme 2973 // with an update URL. In this case we don't know if the CRX is a theme
3143 // or not. 2974 // or not.
3144 TEST_F(ExtensionServiceTest, MAYBE_UpdatePendingExternalCrx) { 2975 TEST_F(ExtensionServiceTest, MAYBE_UpdatePendingExternalCrx) {
3145 InitializeEmptyExtensionService(); 2976 InitializeEmptyExtensionService();
3146 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( 2977 EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl(
3147 theme_crx, 2978 theme_crx,
3148 std::string(), 2979 std::string(),
3149 GURL(), 2980 GURL(),
3150 Manifest::EXTERNAL_PREF_DOWNLOAD, 2981 Manifest::EXTERNAL_PREF_DOWNLOAD,
3151 Extension::NO_FLAGS, 2982 Extension::NO_FLAGS,
3152 false)); 2983 false));
3153 2984
3154 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 2985 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3155 2986
3156 base::FilePath path = data_dir_.AppendASCII("theme.crx"); 2987 base::FilePath path = data_dir().AppendASCII("theme.crx");
3157 UpdateExtension(theme_crx, path, ENABLED); 2988 UpdateExtension(theme_crx, path, ENABLED);
3158 2989
3159 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 2990 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3160 2991
3161 const Extension* extension = service_->GetExtensionById(theme_crx, true); 2992 const Extension* extension = service()->GetExtensionById(theme_crx, true);
3162 ASSERT_TRUE(extension); 2993 ASSERT_TRUE(extension);
3163 2994
3164 EXPECT_FALSE(ExtensionPrefs::Get(profile_.get()) 2995 EXPECT_FALSE(
3165 ->IsExtensionDisabled(extension->id())); 2996 ExtensionPrefs::Get(profile())->IsExtensionDisabled(extension->id()));
3166 EXPECT_TRUE(service_->IsExtensionEnabled(extension->id())); 2997 EXPECT_TRUE(service()->IsExtensionEnabled(extension->id()));
3167 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(extension->id(), 2998 EXPECT_FALSE(
3168 profile_.get())); 2999 extensions::util::IsIncognitoEnabled(extension->id(), profile()));
3169 } 3000 }
3170 3001
3171 // Test updating a pending CRX as if the source is an external extension 3002 // Test updating a pending CRX as if the source is an external extension
3172 // with an update URL. The external update should overwrite a sync update, 3003 // with an update URL. The external update should overwrite a sync update,
3173 // but a sync update should not overwrite a non-sync update. 3004 // but a sync update should not overwrite a non-sync update.
3174 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { 3005 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) {
3175 InitializeEmptyExtensionService(); 3006 InitializeEmptyExtensionService();
3176 3007
3177 // Add a crx to be installed from the update mechanism. 3008 // Add a crx to be installed from the update mechanism.
3178 EXPECT_TRUE( 3009 EXPECT_TRUE(
3179 service_->pending_extension_manager()->AddFromSync(kGoodId, 3010 service()->pending_extension_manager()->AddFromSync(kGoodId,
3180 GURL(kGoodUpdateURL), 3011 GURL(kGoodUpdateURL),
3181 &IsExtension, 3012 &IsExtension,
3182 kGoodInstallSilently, 3013 kGoodInstallSilently,
3183 kGoodRemoteInstall)); 3014 kGoodRemoteInstall));
3184 3015
3185 // Check that there is a pending crx, with is_from_sync set to true. 3016 // Check that there is a pending crx, with is_from_sync set to true.
3186 const extensions::PendingExtensionInfo* pending_extension_info; 3017 const extensions::PendingExtensionInfo* pending_extension_info;
3187 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> 3018 ASSERT_TRUE((pending_extension_info =
3188 GetById(kGoodId))); 3019 service()->pending_extension_manager()->GetById(kGoodId)));
3189 EXPECT_TRUE(pending_extension_info->is_from_sync()); 3020 EXPECT_TRUE(pending_extension_info->is_from_sync());
3190 3021
3191 // Add a crx to be updated, with the same ID, from a non-sync source. 3022 // Add a crx to be updated, with the same ID, from a non-sync source.
3192 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( 3023 EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl(
3193 kGoodId, 3024 kGoodId,
3194 std::string(), 3025 std::string(),
3195 GURL(kGoodUpdateURL), 3026 GURL(kGoodUpdateURL),
3196 Manifest::EXTERNAL_PREF_DOWNLOAD, 3027 Manifest::EXTERNAL_PREF_DOWNLOAD,
3197 Extension::NO_FLAGS, 3028 Extension::NO_FLAGS,
3198 false)); 3029 false));
3199 3030
3200 // Check that there is a pending crx, with is_from_sync set to false. 3031 // Check that there is a pending crx, with is_from_sync set to false.
3201 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> 3032 ASSERT_TRUE((pending_extension_info =
3202 GetById(kGoodId))); 3033 service()->pending_extension_manager()->GetById(kGoodId)));
3203 EXPECT_FALSE(pending_extension_info->is_from_sync()); 3034 EXPECT_FALSE(pending_extension_info->is_from_sync());
3204 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, 3035 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD,
3205 pending_extension_info->install_source()); 3036 pending_extension_info->install_source());
3206 3037
3207 // Add a crx to be installed from the update mechanism. 3038 // Add a crx to be installed from the update mechanism.
3208 EXPECT_FALSE( 3039 EXPECT_FALSE(
3209 service_->pending_extension_manager()->AddFromSync(kGoodId, 3040 service()->pending_extension_manager()->AddFromSync(kGoodId,
3210 GURL(kGoodUpdateURL), 3041 GURL(kGoodUpdateURL),
3211 &IsExtension, 3042 &IsExtension,
3212 kGoodInstallSilently, 3043 kGoodInstallSilently,
3213 kGoodRemoteInstall)); 3044 kGoodRemoteInstall));
3214 3045
3215 // Check that the external, non-sync update was not overridden. 3046 // Check that the external, non-sync update was not overridden.
3216 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> 3047 ASSERT_TRUE((pending_extension_info =
3217 GetById(kGoodId))); 3048 service()->pending_extension_manager()->GetById(kGoodId)));
3218 EXPECT_FALSE(pending_extension_info->is_from_sync()); 3049 EXPECT_FALSE(pending_extension_info->is_from_sync());
3219 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, 3050 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD,
3220 pending_extension_info->install_source()); 3051 pending_extension_info->install_source());
3221 } 3052 }
3222 3053
3223 // Updating a theme should fail if the updater is explicitly told that 3054 // Updating a theme should fail if the updater is explicitly told that
3224 // the CRX is not a theme. 3055 // the CRX is not a theme.
3225 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { 3056 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) {
3226 InitializeEmptyExtensionService(); 3057 InitializeEmptyExtensionService();
3227 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( 3058 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync(
3228 theme_crx, GURL(), &IsExtension, true, false)); 3059 theme_crx, GURL(), &IsExtension, true, false));
3229 3060
3230 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 3061 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3231 3062
3232 base::FilePath path = data_dir_.AppendASCII("theme.crx"); 3063 base::FilePath path = data_dir().AppendASCII("theme.crx");
3233 UpdateExtension(theme_crx, path, FAILED_SILENTLY); 3064 UpdateExtension(theme_crx, path, FAILED_SILENTLY);
3234 3065
3235 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 3066 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3236 3067
3237 const Extension* extension = service_->GetExtensionById(theme_crx, true); 3068 const Extension* extension = service()->GetExtensionById(theme_crx, true);
3238 ASSERT_FALSE(extension); 3069 ASSERT_FALSE(extension);
3239 } 3070 }
3240 3071
3241 // TODO(akalin): Test updating a pending extension non-silently once 3072 // TODO(akalin): Test updating a pending extension non-silently once
3242 // we can mock out ExtensionInstallUI and inject our version into 3073 // we can mock out ExtensionInstallUI and inject our version into
3243 // UpdateExtension(). 3074 // UpdateExtension().
3244 3075
3245 // Test updating a pending extension which fails the should-install test. 3076 // Test updating a pending extension which fails the should-install test.
3246 TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) { 3077 TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) {
3247 InitializeEmptyExtensionService(); 3078 InitializeEmptyExtensionService();
3248 // Add pending extension with a flipped is_theme. 3079 // Add pending extension with a flipped is_theme.
3249 EXPECT_TRUE( 3080 EXPECT_TRUE(
3250 service_->pending_extension_manager()->AddFromSync(kGoodId, 3081 service()->pending_extension_manager()->AddFromSync(kGoodId,
3251 GURL(kGoodUpdateURL), 3082 GURL(kGoodUpdateURL),
3252 &IsTheme, 3083 &IsTheme,
3253 kGoodInstallSilently, 3084 kGoodInstallSilently,
3254 kGoodRemoteInstall)); 3085 kGoodRemoteInstall));
3255 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(kGoodId)); 3086 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3256 3087
3257 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3088 base::FilePath path = data_dir().AppendASCII("good.crx");
3258 UpdateExtension(kGoodId, path, UPDATED); 3089 UpdateExtension(kGoodId, path, UPDATED);
3259 3090
3260 // TODO(akalin): Figure out how to check that the extensions 3091 // TODO(akalin): Figure out how to check that the extensions
3261 // directory is cleaned up properly in OnExtensionInstalled(). 3092 // directory is cleaned up properly in OnExtensionInstalled().
3262 3093
3263 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); 3094 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3264 } 3095 }
3265 3096
3266 // TODO(akalin): Figure out how to test that installs of pending 3097 // TODO(akalin): Figure out how to test that installs of pending
3267 // unsyncable extensions are blocked. 3098 // unsyncable extensions are blocked.
3268 3099
3269 // Test updating a pending extension for one that is not pending. 3100 // Test updating a pending extension for one that is not pending.
3270 TEST_F(ExtensionServiceTest, UpdatePendingExtensionNotPending) { 3101 TEST_F(ExtensionServiceTest, UpdatePendingExtensionNotPending) {
3271 InitializeEmptyExtensionService(); 3102 InitializeEmptyExtensionService();
3272 3103
3273 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3104 base::FilePath path = data_dir().AppendASCII("good.crx");
3274 UpdateExtension(kGoodId, path, UPDATED); 3105 UpdateExtension(kGoodId, path, UPDATED);
3275 3106
3276 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); 3107 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3277 } 3108 }
3278 3109
3279 // Test updating a pending extension for one that is already 3110 // Test updating a pending extension for one that is already
3280 // installed. 3111 // installed.
3281 TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) { 3112 TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) {
3282 InitializeEmptyExtensionService(); 3113 InitializeEmptyExtensionService();
3283 3114
3284 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3115 base::FilePath path = data_dir().AppendASCII("good.crx");
3285 const Extension* good = InstallCRX(path, INSTALL_NEW); 3116 const Extension* good = InstallCRX(path, INSTALL_NEW);
3286 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3117 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3287 3118
3288 EXPECT_FALSE(good->is_theme()); 3119 EXPECT_FALSE(good->is_theme());
3289 3120
3290 // Use AddExtensionImpl() as AddFrom*() would balk. 3121 // Use AddExtensionImpl() as AddFrom*() would balk.
3291 service_->pending_extension_manager()->AddExtensionImpl( 3122 service()->pending_extension_manager()->AddExtensionImpl(
3292 good->id(), 3123 good->id(),
3293 std::string(), 3124 std::string(),
3294 extensions::ManifestURL::GetUpdateURL(good), 3125 extensions::ManifestURL::GetUpdateURL(good),
3295 Version(), 3126 Version(),
3296 &IsExtension, 3127 &IsExtension,
3297 kGoodIsFromSync, 3128 kGoodIsFromSync,
3298 kGoodInstallSilently, 3129 kGoodInstallSilently,
3299 Manifest::INTERNAL, 3130 Manifest::INTERNAL,
3300 Extension::NO_FLAGS, 3131 Extension::NO_FLAGS,
3301 false, 3132 false,
3302 kGoodRemoteInstall); 3133 kGoodRemoteInstall);
3303 UpdateExtension(good->id(), path, ENABLED); 3134 UpdateExtension(good->id(), path, ENABLED);
3304 3135
3305 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); 3136 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3306 } 3137 }
3307 3138
3308 #if defined(ENABLE_BLACKLIST_TESTS) 3139 #if defined(ENABLE_BLACKLIST_TESTS)
3309 // Tests blacklisting then unblacklisting extensions after the service has been 3140 // Tests blacklisting then unblacklisting extensions after the service has been
3310 // initialized. 3141 // initialized.
3311 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { 3142 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) {
3312 extensions::TestBlacklist test_blacklist; 3143 extensions::TestBlacklist test_blacklist;
3313 // A profile with 3 extensions installed: good0, good1, and good2. 3144 // A profile with 3 extensions installed: good0, good1, and good2.
3314 InitializeGoodInstalledExtensionService(); 3145 InitializeGoodInstalledExtensionService();
3315 test_blacklist.Attach(service_->blacklist_); 3146 test_blacklist.Attach(service()->blacklist_);
3316 service_->Init(); 3147 service()->Init();
3317 3148
3318 const extensions::ExtensionSet& enabled_extensions = 3149 const extensions::ExtensionSet& enabled_extensions =
3319 registry_->enabled_extensions(); 3150 registry()->enabled_extensions();
3320 const extensions::ExtensionSet& blacklisted_extensions = 3151 const extensions::ExtensionSet& blacklisted_extensions =
3321 registry_->blacklisted_extensions(); 3152 registry()->blacklisted_extensions();
3322 3153
3323 EXPECT_TRUE(enabled_extensions.Contains(good0) && 3154 EXPECT_TRUE(enabled_extensions.Contains(good0) &&
3324 !blacklisted_extensions.Contains(good0)); 3155 !blacklisted_extensions.Contains(good0));
3325 EXPECT_TRUE(enabled_extensions.Contains(good1) && 3156 EXPECT_TRUE(enabled_extensions.Contains(good1) &&
3326 !blacklisted_extensions.Contains(good1)); 3157 !blacklisted_extensions.Contains(good1));
3327 EXPECT_TRUE(enabled_extensions.Contains(good2) && 3158 EXPECT_TRUE(enabled_extensions.Contains(good2) &&
3328 !blacklisted_extensions.Contains(good2)); 3159 !blacklisted_extensions.Contains(good2));
3329 3160
3330 EXPECT_FALSE(IsPrefExist(good0, "blacklist")); 3161 EXPECT_FALSE(IsPrefExist(good0, "blacklist"));
3331 EXPECT_FALSE(IsPrefExist(good1, "blacklist")); 3162 EXPECT_FALSE(IsPrefExist(good1, "blacklist"));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3378 #endif // defined(ENABLE_BLACKLIST_TESTS) 3209 #endif // defined(ENABLE_BLACKLIST_TESTS)
3379 3210
3380 #if defined(ENABLE_BLACKLIST_TESTS) 3211 #if defined(ENABLE_BLACKLIST_TESTS)
3381 // Tests trying to install a blacklisted extension. 3212 // Tests trying to install a blacklisted extension.
3382 TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) { 3213 TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) {
3383 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( 3214 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db(
3384 new FakeSafeBrowsingDatabaseManager(true)); 3215 new FakeSafeBrowsingDatabaseManager(true));
3385 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); 3216 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db);
3386 3217
3387 InitializeEmptyExtensionService(); 3218 InitializeEmptyExtensionService();
3388 service_->Init(); 3219 service()->Init();
3389 3220
3390 // After blacklisting good_crx, we cannot install it. 3221 // After blacklisting good_crx, we cannot install it.
3391 blacklist_db->SetUnsafe(good_crx).NotifyUpdate(); 3222 blacklist_db->SetUnsafe(good_crx).NotifyUpdate();
3392 base::RunLoop().RunUntilIdle(); 3223 base::RunLoop().RunUntilIdle();
3393 3224
3394 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3225 base::FilePath path = data_dir().AppendASCII("good.crx");
3395 // HACK: specify WAS_INSTALLED_BY_DEFAULT so that test machinery doesn't 3226 // HACK: specify WAS_INSTALLED_BY_DEFAULT so that test machinery doesn't
3396 // decide to install this silently. Somebody should fix these tests, all 3227 // decide to install this silently. Somebody should fix these tests, all
3397 // 6,000 lines of them. Hah! 3228 // 6,000 lines of them. Hah!
3398 InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT); 3229 InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT);
3399 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3230 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3400 } 3231 }
3401 #endif // defined(ENABLE_BLACKLIST_TESTS) 3232 #endif // defined(ENABLE_BLACKLIST_TESTS)
3402 3233
3403 #if defined(ENABLE_BLACKLIST_TESTS) 3234 #if defined(ENABLE_BLACKLIST_TESTS)
3404 // Unload blacklisted extension on policy change. 3235 // Unload blacklisted extension on policy change.
3405 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) { 3236 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) {
3406 extensions::TestBlacklist test_blacklist; 3237 extensions::TestBlacklist test_blacklist;
3407 3238
3408 // A profile with no extensions installed. 3239 // A profile with no extensions installed.
3409 InitializeEmptyExtensionService(); 3240 InitializeEmptyExtensionService();
3410 test_blacklist.Attach(service_->blacklist_); 3241 test_blacklist.Attach(service()->blacklist_);
3411 3242
3412 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3243 base::FilePath path = data_dir().AppendASCII("good.crx");
3413 3244
3414 const Extension* good = InstallCRX(path, INSTALL_NEW); 3245 const Extension* good = InstallCRX(path, INSTALL_NEW);
3415 EXPECT_EQ(good_crx, good->id()); 3246 EXPECT_EQ(good_crx, good->id());
3416 UpdateExtension(good_crx, path, FAILED_SILENTLY); 3247 UpdateExtension(good_crx, path, FAILED_SILENTLY);
3417 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3248 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3418 3249
3419 base::ListValue whitelist; 3250 base::ListValue whitelist;
3420 PrefService* prefs = ExtensionPrefs::Get(profile_.get())->pref_service(); 3251 PrefService* prefs = ExtensionPrefs::Get(profile())->pref_service();
3421 whitelist.Append(new base::StringValue(good_crx)); 3252 whitelist.Append(new base::StringValue(good_crx));
3422 prefs->Set(extensions::pref_names::kInstallAllowList, whitelist); 3253 prefs->Set(extensions::pref_names::kInstallAllowList, whitelist);
3423 3254
3424 test_blacklist.SetBlacklistState( 3255 test_blacklist.SetBlacklistState(
3425 good_crx, extensions::BLACKLISTED_MALWARE, true); 3256 good_crx, extensions::BLACKLISTED_MALWARE, true);
3426 base::RunLoop().RunUntilIdle(); 3257 base::RunLoop().RunUntilIdle();
3427 3258
3428 // The good_crx is blacklisted and the whitelist doesn't negate it. 3259 // The good_crx is blacklisted and the whitelist doesn't negate it.
3429 ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true)); 3260 ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true));
3430 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3261 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3431 } 3262 }
3432 #endif // defined(ENABLE_BLACKLIST_TESTS) 3263 #endif // defined(ENABLE_BLACKLIST_TESTS)
3433 3264
3434 #if defined(ENABLE_BLACKLIST_TESTS) 3265 #if defined(ENABLE_BLACKLIST_TESTS)
3435 // Tests that a blacklisted extension is eventually unloaded on startup, if it 3266 // Tests that a blacklisted extension is eventually unloaded on startup, if it
3436 // wasn't already. 3267 // wasn't already.
3437 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { 3268 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) {
3438 extensions::TestBlacklist test_blacklist; 3269 extensions::TestBlacklist test_blacklist;
3439 3270
3440 // A profile with 3 extensions installed: good0, good1, and good2. 3271 // A profile with 3 extensions installed: good0, good1, and good2.
3441 InitializeGoodInstalledExtensionService(); 3272 InitializeGoodInstalledExtensionService();
3442 test_blacklist.Attach(service_->blacklist_); 3273 test_blacklist.Attach(service()->blacklist_);
3443 3274
3444 // Blacklist good1 before the service initializes. 3275 // Blacklist good1 before the service initializes.
3445 test_blacklist.SetBlacklistState( 3276 test_blacklist.SetBlacklistState(
3446 good1, extensions::BLACKLISTED_MALWARE, false); 3277 good1, extensions::BLACKLISTED_MALWARE, false);
3447 3278
3448 // Load extensions. 3279 // Load extensions.
3449 service_->Init(); 3280 service()->Init();
3450 ASSERT_EQ(3u, loaded_.size()); // hasn't had time to blacklist yet 3281 ASSERT_EQ(3u, loaded_.size()); // hasn't had time to blacklist yet
3451 3282
3452 base::RunLoop().RunUntilIdle(); 3283 base::RunLoop().RunUntilIdle();
3453 3284
3454 ASSERT_EQ(1u, registry_->blacklisted_extensions().size()); 3285 ASSERT_EQ(1u, registry()->blacklisted_extensions().size());
3455 ASSERT_EQ(2u, registry_->enabled_extensions().size()); 3286 ASSERT_EQ(2u, registry()->enabled_extensions().size());
3456 3287
3457 ASSERT_TRUE(registry_->enabled_extensions().Contains(good0)); 3288 ASSERT_TRUE(registry()->enabled_extensions().Contains(good0));
3458 ASSERT_TRUE(registry_->blacklisted_extensions().Contains(good1)); 3289 ASSERT_TRUE(registry()->blacklisted_extensions().Contains(good1));
3459 ASSERT_TRUE(registry_->enabled_extensions().Contains(good2)); 3290 ASSERT_TRUE(registry()->enabled_extensions().Contains(good2));
3460 } 3291 }
3461 #endif // defined(ENABLE_BLACKLIST_TESTS) 3292 #endif // defined(ENABLE_BLACKLIST_TESTS)
3462 3293
3463 #if defined(ENABLE_BLACKLIST_TESTS) 3294 #if defined(ENABLE_BLACKLIST_TESTS)
3464 // Tests extensions blacklisted in prefs on startup; one still blacklisted by 3295 // Tests extensions blacklisted in prefs on startup; one still blacklisted by
3465 // safe browsing, the other not. The not-blacklisted one should recover. 3296 // safe browsing, the other not. The not-blacklisted one should recover.
3466 TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) { 3297 TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) {
3467 extensions::TestBlacklist test_blacklist; 3298 extensions::TestBlacklist test_blacklist;
3468 3299
3469 InitializeGoodInstalledExtensionService(); 3300 InitializeGoodInstalledExtensionService();
3470 test_blacklist.Attach(service_->blacklist_); 3301 test_blacklist.Attach(service()->blacklist_);
3471 ExtensionPrefs::Get(profile_.get())->SetExtensionBlacklisted(good0, true); 3302 ExtensionPrefs::Get(profile())->SetExtensionBlacklisted(good0, true);
3472 ExtensionPrefs::Get(profile_.get())->SetExtensionBlacklisted(good1, true); 3303 ExtensionPrefs::Get(profile())->SetExtensionBlacklisted(good1, true);
3473 3304
3474 test_blacklist.SetBlacklistState( 3305 test_blacklist.SetBlacklistState(
3475 good1, extensions::BLACKLISTED_MALWARE, false); 3306 good1, extensions::BLACKLISTED_MALWARE, false);
3476 3307
3477 // Extension service hasn't loaded yet, but IsExtensionEnabled reads out of 3308 // Extension service hasn't loaded yet, but IsExtensionEnabled reads out of
3478 // prefs. Ensure it takes into account the blacklist state (crbug.com/373842). 3309 // prefs. Ensure it takes into account the blacklist state (crbug.com/373842).
3479 EXPECT_FALSE(service_->IsExtensionEnabled(good0)); 3310 EXPECT_FALSE(service()->IsExtensionEnabled(good0));
3480 EXPECT_FALSE(service_->IsExtensionEnabled(good1)); 3311 EXPECT_FALSE(service()->IsExtensionEnabled(good1));
3481 EXPECT_TRUE(service_->IsExtensionEnabled(good2)); 3312 EXPECT_TRUE(service()->IsExtensionEnabled(good2));
3482 3313
3483 service_->Init(); 3314 service()->Init();
3484 3315
3485 EXPECT_EQ(2u, registry_->blacklisted_extensions().size()); 3316 EXPECT_EQ(2u, registry()->blacklisted_extensions().size());
3486 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3317 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3487 3318
3488 EXPECT_TRUE(registry_->blacklisted_extensions().Contains(good0)); 3319 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good0));
3489 EXPECT_TRUE(registry_->blacklisted_extensions().Contains(good1)); 3320 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good1));
3490 EXPECT_TRUE(registry_->enabled_extensions().Contains(good2)); 3321 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
3491 3322
3492 // Give time for the blacklist to update. 3323 // Give time for the blacklist to update.
3493 base::RunLoop().RunUntilIdle(); 3324 base::RunLoop().RunUntilIdle();
3494 3325
3495 EXPECT_EQ(1u, registry_->blacklisted_extensions().size()); 3326 EXPECT_EQ(1u, registry()->blacklisted_extensions().size());
3496 EXPECT_EQ(2u, registry_->enabled_extensions().size()); 3327 EXPECT_EQ(2u, registry()->enabled_extensions().size());
3497 3328
3498 EXPECT_TRUE(registry_->enabled_extensions().Contains(good0)); 3329 EXPECT_TRUE(registry()->enabled_extensions().Contains(good0));
3499 EXPECT_TRUE(registry_->blacklisted_extensions().Contains(good1)); 3330 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good1));
3500 EXPECT_TRUE(registry_->enabled_extensions().Contains(good2)); 3331 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
3501 } 3332 }
3502 #endif // defined(ENABLE_BLACKLIST_TESTS) 3333 #endif // defined(ENABLE_BLACKLIST_TESTS)
3503 3334
3504 #if defined(ENABLE_BLACKLIST_TESTS) 3335 #if defined(ENABLE_BLACKLIST_TESTS)
3505 // Extension is added to blacklist with BLACKLISTED_POTENTIALLY_UNWANTED state 3336 // Extension is added to blacklist with BLACKLISTED_POTENTIALLY_UNWANTED state
3506 // after it is installed. It is then successfully re-enabled by the user. 3337 // after it is installed. It is then successfully re-enabled by the user.
3507 TEST_F(ExtensionServiceTest, GreylistedExtensionDisabled) { 3338 TEST_F(ExtensionServiceTest, GreylistedExtensionDisabled) {
3508 extensions::TestBlacklist test_blacklist; 3339 extensions::TestBlacklist test_blacklist;
3509 // A profile with 3 extensions installed: good0, good1, and good2. 3340 // A profile with 3 extensions installed: good0, good1, and good2.
3510 InitializeGoodInstalledExtensionService(); 3341 InitializeGoodInstalledExtensionService();
3511 test_blacklist.Attach(service_->blacklist_); 3342 test_blacklist.Attach(service()->blacklist_);
3512 service_->Init(); 3343 service()->Init();
3513 3344
3514 const extensions::ExtensionSet& enabled_extensions = 3345 const extensions::ExtensionSet& enabled_extensions =
3515 registry_->enabled_extensions(); 3346 registry()->enabled_extensions();
3516 const extensions::ExtensionSet& disabled_extensions = 3347 const extensions::ExtensionSet& disabled_extensions =
3517 registry_->disabled_extensions(); 3348 registry()->disabled_extensions();
3518 3349
3519 EXPECT_TRUE(enabled_extensions.Contains(good0)); 3350 EXPECT_TRUE(enabled_extensions.Contains(good0));
3520 EXPECT_TRUE(enabled_extensions.Contains(good1)); 3351 EXPECT_TRUE(enabled_extensions.Contains(good1));
3521 EXPECT_TRUE(enabled_extensions.Contains(good2)); 3352 EXPECT_TRUE(enabled_extensions.Contains(good2));
3522 3353
3523 // Blacklist good0 and good1 (and an invalid extension ID). 3354 // Blacklist good0 and good1 (and an invalid extension ID).
3524 test_blacklist.SetBlacklistState( 3355 test_blacklist.SetBlacklistState(
3525 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); 3356 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true);
3526 test_blacklist.SetBlacklistState( 3357 test_blacklist.SetBlacklistState(
3527 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); 3358 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true);
3528 test_blacklist.SetBlacklistState( 3359 test_blacklist.SetBlacklistState(
3529 "invalid_id", extensions::BLACKLISTED_MALWARE, true); 3360 "invalid_id", extensions::BLACKLISTED_MALWARE, true);
3530 base::RunLoop().RunUntilIdle(); 3361 base::RunLoop().RunUntilIdle();
3531 3362
3532 EXPECT_FALSE(enabled_extensions.Contains(good0)); 3363 EXPECT_FALSE(enabled_extensions.Contains(good0));
3533 EXPECT_TRUE(disabled_extensions.Contains(good0)); 3364 EXPECT_TRUE(disabled_extensions.Contains(good0));
3534 EXPECT_FALSE(enabled_extensions.Contains(good1)); 3365 EXPECT_FALSE(enabled_extensions.Contains(good1));
3535 EXPECT_TRUE(disabled_extensions.Contains(good1)); 3366 EXPECT_TRUE(disabled_extensions.Contains(good1));
3536 EXPECT_TRUE(enabled_extensions.Contains(good2)); 3367 EXPECT_TRUE(enabled_extensions.Contains(good2));
3537 EXPECT_FALSE(disabled_extensions.Contains(good2)); 3368 EXPECT_FALSE(disabled_extensions.Contains(good2));
3538 3369
3539 ValidateIntegerPref( 3370 ValidateIntegerPref(
3540 good0, "blacklist_state", extensions::BLACKLISTED_CWS_POLICY_VIOLATION); 3371 good0, "blacklist_state", extensions::BLACKLISTED_CWS_POLICY_VIOLATION);
3541 ValidateIntegerPref( 3372 ValidateIntegerPref(
3542 good1, "blacklist_state", extensions::BLACKLISTED_POTENTIALLY_UNWANTED); 3373 good1, "blacklist_state", extensions::BLACKLISTED_POTENTIALLY_UNWANTED);
3543 3374
3544 // Now user enables good0. 3375 // Now user enables good0.
3545 service_->EnableExtension(good0); 3376 service()->EnableExtension(good0);
3546 3377
3547 EXPECT_TRUE(enabled_extensions.Contains(good0)); 3378 EXPECT_TRUE(enabled_extensions.Contains(good0));
3548 EXPECT_FALSE(disabled_extensions.Contains(good0)); 3379 EXPECT_FALSE(disabled_extensions.Contains(good0));
3549 EXPECT_FALSE(enabled_extensions.Contains(good1)); 3380 EXPECT_FALSE(enabled_extensions.Contains(good1));
3550 EXPECT_TRUE(disabled_extensions.Contains(good1)); 3381 EXPECT_TRUE(disabled_extensions.Contains(good1));
3551 3382
3552 // Remove extensions from blacklist. 3383 // Remove extensions from blacklist.
3553 test_blacklist.SetBlacklistState( 3384 test_blacklist.SetBlacklistState(
3554 good0, extensions::NOT_BLACKLISTED, true); 3385 good0, extensions::NOT_BLACKLISTED, true);
3555 test_blacklist.SetBlacklistState( 3386 test_blacklist.SetBlacklistState(
(...skipping 10 matching lines...) Expand all
3566 } 3397 }
3567 #endif // defined(ENABLE_BLACKLIST_TESTS) 3398 #endif // defined(ENABLE_BLACKLIST_TESTS)
3568 3399
3569 #if defined(ENABLE_BLACKLIST_TESTS) 3400 #if defined(ENABLE_BLACKLIST_TESTS)
3570 // When extension is removed from greylist, do not re-enable it if it is 3401 // When extension is removed from greylist, do not re-enable it if it is
3571 // disabled by user. 3402 // disabled by user.
3572 TEST_F(ExtensionServiceTest, GreylistDontEnableManuallyDisabled) { 3403 TEST_F(ExtensionServiceTest, GreylistDontEnableManuallyDisabled) {
3573 extensions::TestBlacklist test_blacklist; 3404 extensions::TestBlacklist test_blacklist;
3574 // A profile with 3 extensions installed: good0, good1, and good2. 3405 // A profile with 3 extensions installed: good0, good1, and good2.
3575 InitializeGoodInstalledExtensionService(); 3406 InitializeGoodInstalledExtensionService();
3576 test_blacklist.Attach(service_->blacklist_); 3407 test_blacklist.Attach(service()->blacklist_);
3577 service_->Init(); 3408 service()->Init();
3578 3409
3579 const extensions::ExtensionSet& enabled_extensions = 3410 const extensions::ExtensionSet& enabled_extensions =
3580 registry_->enabled_extensions(); 3411 registry()->enabled_extensions();
3581 const extensions::ExtensionSet& disabled_extensions = 3412 const extensions::ExtensionSet& disabled_extensions =
3582 registry_->disabled_extensions(); 3413 registry()->disabled_extensions();
3583 3414
3584 // Manually disable. 3415 // Manually disable.
3585 service_->DisableExtension(good0, extensions::Extension::DISABLE_USER_ACTION); 3416 service()->DisableExtension(good0,
3417 extensions::Extension::DISABLE_USER_ACTION);
3586 3418
3587 test_blacklist.SetBlacklistState( 3419 test_blacklist.SetBlacklistState(
3588 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); 3420 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true);
3589 test_blacklist.SetBlacklistState( 3421 test_blacklist.SetBlacklistState(
3590 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); 3422 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true);
3591 test_blacklist.SetBlacklistState( 3423 test_blacklist.SetBlacklistState(
3592 good2, extensions::BLACKLISTED_SECURITY_VULNERABILITY, true); 3424 good2, extensions::BLACKLISTED_SECURITY_VULNERABILITY, true);
3593 base::RunLoop().RunUntilIdle(); 3425 base::RunLoop().RunUntilIdle();
3594 3426
3595 // All extensions disabled. 3427 // All extensions disabled.
3596 EXPECT_FALSE(enabled_extensions.Contains(good0)); 3428 EXPECT_FALSE(enabled_extensions.Contains(good0));
3597 EXPECT_TRUE(disabled_extensions.Contains(good0)); 3429 EXPECT_TRUE(disabled_extensions.Contains(good0));
3598 EXPECT_FALSE(enabled_extensions.Contains(good1)); 3430 EXPECT_FALSE(enabled_extensions.Contains(good1));
3599 EXPECT_TRUE(disabled_extensions.Contains(good1)); 3431 EXPECT_TRUE(disabled_extensions.Contains(good1));
3600 EXPECT_FALSE(enabled_extensions.Contains(good2)); 3432 EXPECT_FALSE(enabled_extensions.Contains(good2));
3601 EXPECT_TRUE(disabled_extensions.Contains(good2)); 3433 EXPECT_TRUE(disabled_extensions.Contains(good2));
3602 3434
3603 // Greylisted extension can be enabled. 3435 // Greylisted extension can be enabled.
3604 service_->EnableExtension(good1); 3436 service()->EnableExtension(good1);
3605 EXPECT_TRUE(enabled_extensions.Contains(good1)); 3437 EXPECT_TRUE(enabled_extensions.Contains(good1));
3606 EXPECT_FALSE(disabled_extensions.Contains(good1)); 3438 EXPECT_FALSE(disabled_extensions.Contains(good1));
3607 3439
3608 // good1 is now manually disabled. 3440 // good1 is now manually disabled.
3609 service_->DisableExtension(good1, extensions::Extension::DISABLE_USER_ACTION); 3441 service()->DisableExtension(good1,
3442 extensions::Extension::DISABLE_USER_ACTION);
3610 EXPECT_FALSE(enabled_extensions.Contains(good1)); 3443 EXPECT_FALSE(enabled_extensions.Contains(good1));
3611 EXPECT_TRUE(disabled_extensions.Contains(good1)); 3444 EXPECT_TRUE(disabled_extensions.Contains(good1));
3612 3445
3613 // Remove extensions from blacklist. 3446 // Remove extensions from blacklist.
3614 test_blacklist.SetBlacklistState( 3447 test_blacklist.SetBlacklistState(
3615 good0, extensions::NOT_BLACKLISTED, true); 3448 good0, extensions::NOT_BLACKLISTED, true);
3616 test_blacklist.SetBlacklistState( 3449 test_blacklist.SetBlacklistState(
3617 good1, extensions::NOT_BLACKLISTED, true); 3450 good1, extensions::NOT_BLACKLISTED, true);
3618 test_blacklist.SetBlacklistState( 3451 test_blacklist.SetBlacklistState(
3619 good2, extensions::NOT_BLACKLISTED, true); 3452 good2, extensions::NOT_BLACKLISTED, true);
3620 base::RunLoop().RunUntilIdle(); 3453 base::RunLoop().RunUntilIdle();
3621 3454
3622 // good0 and good1 remain disabled. 3455 // good0 and good1 remain disabled.
3623 EXPECT_FALSE(enabled_extensions.Contains(good0)); 3456 EXPECT_FALSE(enabled_extensions.Contains(good0));
3624 EXPECT_TRUE(disabled_extensions.Contains(good0)); 3457 EXPECT_TRUE(disabled_extensions.Contains(good0));
3625 EXPECT_FALSE(enabled_extensions.Contains(good1)); 3458 EXPECT_FALSE(enabled_extensions.Contains(good1));
3626 EXPECT_TRUE(disabled_extensions.Contains(good1)); 3459 EXPECT_TRUE(disabled_extensions.Contains(good1));
3627 EXPECT_TRUE(enabled_extensions.Contains(good2)); 3460 EXPECT_TRUE(enabled_extensions.Contains(good2));
3628 EXPECT_FALSE(disabled_extensions.Contains(good2)); 3461 EXPECT_FALSE(disabled_extensions.Contains(good2));
3629 } 3462 }
3630 #endif // defined(ENABLE_BLACKLIST_TESTS) 3463 #endif // defined(ENABLE_BLACKLIST_TESTS)
3631 3464
3632 #if defined(ENABLE_BLACKLIST_TESTS) 3465 #if defined(ENABLE_BLACKLIST_TESTS)
3633 // Blacklisted extension with unknown state are not enabled/disabled. 3466 // Blacklisted extension with unknown state are not enabled/disabled.
3634 TEST_F(ExtensionServiceTest, GreylistUnknownDontChange) { 3467 TEST_F(ExtensionServiceTest, GreylistUnknownDontChange) {
3635 extensions::TestBlacklist test_blacklist; 3468 extensions::TestBlacklist test_blacklist;
3636 // A profile with 3 extensions installed: good0, good1, and good2. 3469 // A profile with 3 extensions installed: good0, good1, and good2.
3637 InitializeGoodInstalledExtensionService(); 3470 InitializeGoodInstalledExtensionService();
3638 test_blacklist.Attach(service_->blacklist_); 3471 test_blacklist.Attach(service()->blacklist_);
3639 service_->Init(); 3472 service()->Init();
3640 3473
3641 const extensions::ExtensionSet& enabled_extensions = 3474 const extensions::ExtensionSet& enabled_extensions =
3642 registry_->enabled_extensions(); 3475 registry()->enabled_extensions();
3643 const extensions::ExtensionSet& disabled_extensions = 3476 const extensions::ExtensionSet& disabled_extensions =
3644 registry_->disabled_extensions(); 3477 registry()->disabled_extensions();
3645 3478
3646 test_blacklist.SetBlacklistState( 3479 test_blacklist.SetBlacklistState(
3647 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); 3480 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true);
3648 test_blacklist.SetBlacklistState( 3481 test_blacklist.SetBlacklistState(
3649 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); 3482 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true);
3650 base::RunLoop().RunUntilIdle(); 3483 base::RunLoop().RunUntilIdle();
3651 3484
3652 EXPECT_FALSE(enabled_extensions.Contains(good0)); 3485 EXPECT_FALSE(enabled_extensions.Contains(good0));
3653 EXPECT_TRUE(disabled_extensions.Contains(good0)); 3486 EXPECT_TRUE(disabled_extensions.Contains(good0));
3654 EXPECT_FALSE(enabled_extensions.Contains(good1)); 3487 EXPECT_FALSE(enabled_extensions.Contains(good1));
(...skipping 17 matching lines...) Expand all
3672 EXPECT_TRUE(enabled_extensions.Contains(good2)); 3505 EXPECT_TRUE(enabled_extensions.Contains(good2));
3673 EXPECT_FALSE(disabled_extensions.Contains(good2)); 3506 EXPECT_FALSE(disabled_extensions.Contains(good2));
3674 } 3507 }
3675 3508
3676 // Tests that blacklisted extensions cannot be reloaded, both those loaded 3509 // Tests that blacklisted extensions cannot be reloaded, both those loaded
3677 // before and after extension service startup. 3510 // before and after extension service startup.
3678 TEST_F(ExtensionServiceTest, ReloadBlacklistedExtension) { 3511 TEST_F(ExtensionServiceTest, ReloadBlacklistedExtension) {
3679 extensions::TestBlacklist test_blacklist; 3512 extensions::TestBlacklist test_blacklist;
3680 3513
3681 InitializeGoodInstalledExtensionService(); 3514 InitializeGoodInstalledExtensionService();
3682 test_blacklist.Attach(service_->blacklist_); 3515 test_blacklist.Attach(service()->blacklist_);
3683 3516
3684 test_blacklist.SetBlacklistState( 3517 test_blacklist.SetBlacklistState(
3685 good1, extensions::BLACKLISTED_MALWARE, false); 3518 good1, extensions::BLACKLISTED_MALWARE, false);
3686 service_->Init(); 3519 service()->Init();
3687 test_blacklist.SetBlacklistState( 3520 test_blacklist.SetBlacklistState(
3688 good2, extensions::BLACKLISTED_MALWARE, false); 3521 good2, extensions::BLACKLISTED_MALWARE, false);
3689 base::RunLoop().RunUntilIdle(); 3522 base::RunLoop().RunUntilIdle();
3690 3523
3691 EXPECT_EQ(StringSet(good0), registry_->enabled_extensions().GetIDs()); 3524 EXPECT_EQ(StringSet(good0), registry()->enabled_extensions().GetIDs());
3692 EXPECT_EQ(StringSet(good1, good2), 3525 EXPECT_EQ(StringSet(good1, good2),
3693 registry_->blacklisted_extensions().GetIDs()); 3526 registry()->blacklisted_extensions().GetIDs());
3694 3527
3695 service_->ReloadExtension(good1); 3528 service()->ReloadExtension(good1);
3696 service_->ReloadExtension(good2); 3529 service()->ReloadExtension(good2);
3697 base::RunLoop().RunUntilIdle(); 3530 base::RunLoop().RunUntilIdle();
3698 3531
3699 EXPECT_EQ(StringSet(good0), registry_->enabled_extensions().GetIDs()); 3532 EXPECT_EQ(StringSet(good0), registry()->enabled_extensions().GetIDs());
3700 EXPECT_EQ(StringSet(good1, good2), 3533 EXPECT_EQ(StringSet(good1, good2),
3701 registry_->blacklisted_extensions().GetIDs()); 3534 registry()->blacklisted_extensions().GetIDs());
3702 } 3535 }
3703 3536
3704 #endif // defined(ENABLE_BLACKLIST_TESTS) 3537 #endif // defined(ENABLE_BLACKLIST_TESTS)
3705 3538
3706 // Will not install extension blacklisted by policy. 3539 // Will not install extension blacklisted by policy.
3707 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { 3540 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) {
3708 InitializeEmptyExtensionService(); 3541 InitializeEmptyExtensionService();
3709 3542
3710 // Blacklist everything. 3543 // Blacklist everything.
3711 { 3544 {
3712 ListPrefUpdate update(profile_->GetPrefs(), 3545 ListPrefUpdate update(profile()->GetPrefs(),
3713 extensions::pref_names::kInstallDenyList); 3546 extensions::pref_names::kInstallDenyList);
3714 base::ListValue* blacklist = update.Get(); 3547 base::ListValue* blacklist = update.Get();
3715 blacklist->Append(new base::StringValue("*")); 3548 blacklist->Append(new base::StringValue("*"));
3716 } 3549 }
3717 3550
3718 // Blacklist prevents us from installing good_crx. 3551 // Blacklist prevents us from installing good_crx.
3719 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3552 base::FilePath path = data_dir().AppendASCII("good.crx");
3720 InstallCRX(path, INSTALL_FAILED); 3553 InstallCRX(path, INSTALL_FAILED);
3721 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3554 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3722 3555
3723 // Now whitelist this particular extension. 3556 // Now whitelist this particular extension.
3724 { 3557 {
3725 ListPrefUpdate update(profile_->GetPrefs(), 3558 ListPrefUpdate update(profile()->GetPrefs(),
3726 extensions::pref_names::kInstallAllowList); 3559 extensions::pref_names::kInstallAllowList);
3727 base::ListValue* whitelist = update.Get(); 3560 base::ListValue* whitelist = update.Get();
3728 whitelist->Append(new base::StringValue(good_crx)); 3561 whitelist->Append(new base::StringValue(good_crx));
3729 } 3562 }
3730 3563
3731 // Ensure we can now install good_crx. 3564 // Ensure we can now install good_crx.
3732 InstallCRX(path, INSTALL_NEW); 3565 InstallCRX(path, INSTALL_NEW);
3733 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3566 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3734 } 3567 }
3735 3568
3736 // Extension blacklisted by policy get unloaded after installing. 3569 // Extension blacklisted by policy get unloaded after installing.
3737 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { 3570 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) {
3738 InitializeEmptyExtensionService(); 3571 InitializeEmptyExtensionService();
3739 3572
3740 // Install good_crx. 3573 // Install good_crx.
3741 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3574 base::FilePath path = data_dir().AppendASCII("good.crx");
3742 InstallCRX(path, INSTALL_NEW); 3575 InstallCRX(path, INSTALL_NEW);
3743 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3576 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3744 3577
3745 { // Scope for pref update notification. 3578 { // Scope for pref update notification.
3746 PrefService* prefs = profile_->GetPrefs(); 3579 PrefService* prefs = profile()->GetPrefs();
3747 ListPrefUpdate update(prefs, extensions::pref_names::kInstallDenyList); 3580 ListPrefUpdate update(prefs, extensions::pref_names::kInstallDenyList);
3748 base::ListValue* blacklist = update.Get(); 3581 base::ListValue* blacklist = update.Get();
3749 ASSERT_TRUE(blacklist != NULL); 3582 ASSERT_TRUE(blacklist != NULL);
3750 3583
3751 // Blacklist this extension. 3584 // Blacklist this extension.
3752 blacklist->Append(new base::StringValue(good_crx)); 3585 blacklist->Append(new base::StringValue(good_crx));
3753 } 3586 }
3754 3587
3755 // Extension should not be running now. 3588 // Extension should not be running now.
3756 base::RunLoop().RunUntilIdle(); 3589 base::RunLoop().RunUntilIdle();
3757 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3590 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3758 } 3591 }
3759 3592
3760 // Tests that component extensions are not blacklisted by policy. 3593 // Tests that component extensions are not blacklisted by policy.
3761 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { 3594 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) {
3762 InitializeEmptyExtensionService(); 3595 InitializeEmptyExtensionService();
3763 3596
3764 // Blacklist everything. 3597 // Blacklist everything.
3765 { 3598 {
3766 ListPrefUpdate update(profile_->GetPrefs(), 3599 ListPrefUpdate update(profile()->GetPrefs(),
3767 extensions::pref_names::kInstallDenyList); 3600 extensions::pref_names::kInstallDenyList);
3768 base::ListValue* blacklist = update.Get(); 3601 base::ListValue* blacklist = update.Get();
3769 blacklist->Append(new base::StringValue("*")); 3602 blacklist->Append(new base::StringValue("*"));
3770 } 3603 }
3771 3604
3772 // Install a component extension. 3605 // Install a component extension.
3773 base::FilePath path = data_dir_ 3606 base::FilePath path = data_dir()
3774 .AppendASCII("good") 3607 .AppendASCII("good")
3775 .AppendASCII("Extensions") 3608 .AppendASCII("Extensions")
3776 .AppendASCII(good0) 3609 .AppendASCII(good0)
3777 .AppendASCII("1.0.0.0"); 3610 .AppendASCII("1.0.0.0");
3778 std::string manifest; 3611 std::string manifest;
3779 ASSERT_TRUE(base::ReadFileToString( 3612 ASSERT_TRUE(base::ReadFileToString(
3780 path.Append(extensions::kManifestFilename), &manifest)); 3613 path.Append(extensions::kManifestFilename), &manifest));
3781 service_->component_loader()->Add(manifest, path); 3614 service()->component_loader()->Add(manifest, path);
3782 service_->Init(); 3615 service()->Init();
3783 3616
3784 // Extension should be installed despite blacklist. 3617 // Extension should be installed despite blacklist.
3785 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3618 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3786 EXPECT_TRUE(service_->GetExtensionById(good0, false)); 3619 EXPECT_TRUE(service()->GetExtensionById(good0, false));
3787 3620
3788 // Poke external providers and make sure the extension is still present. 3621 // Poke external providers and make sure the extension is still present.
3789 service_->CheckForExternalUpdates(); 3622 service()->CheckForExternalUpdates();
3790 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3623 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3791 EXPECT_TRUE(service_->GetExtensionById(good0, false)); 3624 EXPECT_TRUE(service()->GetExtensionById(good0, false));
3792 3625
3793 // Extension should not be uninstalled on blacklist changes. 3626 // Extension should not be uninstalled on blacklist changes.
3794 { 3627 {
3795 ListPrefUpdate update(profile_->GetPrefs(), 3628 ListPrefUpdate update(profile()->GetPrefs(),
3796 extensions::pref_names::kInstallDenyList); 3629 extensions::pref_names::kInstallDenyList);
3797 base::ListValue* blacklist = update.Get(); 3630 base::ListValue* blacklist = update.Get();
3798 blacklist->Append(new base::StringValue(good0)); 3631 blacklist->Append(new base::StringValue(good0));
3799 } 3632 }
3800 base::RunLoop().RunUntilIdle(); 3633 base::RunLoop().RunUntilIdle();
3801 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3634 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3802 EXPECT_TRUE(service_->GetExtensionById(good0, false)); 3635 EXPECT_TRUE(service()->GetExtensionById(good0, false));
3803 } 3636 }
3804 3637
3805 // Tests that policy-installed extensions are not blacklisted by policy. 3638 // Tests that policy-installed extensions are not blacklisted by policy.
3806 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { 3639 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) {
3807 InitializeEmptyExtensionService(); 3640 InitializeEmptyExtensionService();
3808 3641
3809 { 3642 {
3810 // Blacklist everything. 3643 // Blacklist everything.
3811 ListPrefUpdate blacklist_update( 3644 ListPrefUpdate blacklist_update(profile()->GetPrefs(),
3812 profile_->GetPrefs(), extensions::pref_names::kInstallDenyList); 3645 extensions::pref_names::kInstallDenyList);
3813 base::ListValue* blacklist = blacklist_update.Get(); 3646 base::ListValue* blacklist = blacklist_update.Get();
3814 blacklist->AppendString("*"); 3647 blacklist->AppendString("*");
3815 3648
3816 // Mark good.crx for force-installation. 3649 // Mark good.crx for force-installation.
3817 DictionaryPrefUpdate forcelist_update( 3650 DictionaryPrefUpdate forcelist_update(
3818 profile_->GetPrefs(), 3651 profile()->GetPrefs(), extensions::pref_names::kInstallForceList);
3819 extensions::pref_names::kInstallForceList);
3820 extensions::ExternalPolicyLoader::AddExtension( 3652 extensions::ExternalPolicyLoader::AddExtension(
3821 forcelist_update.Get(), good_crx, "http://example.com/update_url"); 3653 forcelist_update.Get(), good_crx, "http://example.com/update_url");
3822 } 3654 }
3823 3655
3824 // Have policy force-install an extension. 3656 // Have policy force-install an extension.
3825 MockExtensionProvider* provider = 3657 MockExtensionProvider* provider =
3826 new MockExtensionProvider(service_, 3658 new MockExtensionProvider(service(), Manifest::EXTERNAL_POLICY_DOWNLOAD);
3827 Manifest::EXTERNAL_POLICY_DOWNLOAD);
3828 AddMockExternalProvider(provider); 3659 AddMockExternalProvider(provider);
3829 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 3660 provider->UpdateOrAddExtension(
3830 data_dir_.AppendASCII("good.crx")); 3661 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx"));
3831 3662
3832 // Reloading extensions should find our externally registered extension 3663 // Reloading extensions should find our externally registered extension
3833 // and install it. 3664 // and install it.
3834 content::WindowedNotificationObserver observer( 3665 content::WindowedNotificationObserver observer(
3835 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 3666 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
3836 content::NotificationService::AllSources()); 3667 content::NotificationService::AllSources());
3837 service_->CheckForExternalUpdates(); 3668 service()->CheckForExternalUpdates();
3838 observer.Wait(); 3669 observer.Wait();
3839 3670
3840 // Extension should be installed despite blacklist. 3671 // Extension should be installed despite blacklist.
3841 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3672 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3842 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3673 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3843 3674
3844 // Blacklist update should not uninstall the extension. 3675 // Blacklist update should not uninstall the extension.
3845 { 3676 {
3846 ListPrefUpdate update(profile_->GetPrefs(), 3677 ListPrefUpdate update(profile()->GetPrefs(),
3847 extensions::pref_names::kInstallDenyList); 3678 extensions::pref_names::kInstallDenyList);
3848 base::ListValue* blacklist = update.Get(); 3679 base::ListValue* blacklist = update.Get();
3849 blacklist->Append(new base::StringValue(good0)); 3680 blacklist->Append(new base::StringValue(good0));
3850 } 3681 }
3851 base::RunLoop().RunUntilIdle(); 3682 base::RunLoop().RunUntilIdle();
3852 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3683 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3853 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3684 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3854 } 3685 }
3855 3686
3856 // Tests that extensions cannot be installed if the policy provider prohibits 3687 // Tests that extensions cannot be installed if the policy provider prohibits
3857 // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). 3688 // it. This functionality is implemented in CrxInstaller::ConfirmInstall().
3858 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) { 3689 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) {
3859 InitializeEmptyExtensionService(); 3690 InitializeEmptyExtensionService();
3860 3691
3861 management_policy_->UnregisterAllProviders(); 3692 GetManagementPolicy()->UnregisterAllProviders();
3862 extensions::TestManagementPolicyProvider provider_( 3693 extensions::TestManagementPolicyProvider provider_(
3863 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); 3694 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
3864 management_policy_->RegisterProvider(&provider_); 3695 GetManagementPolicy()->RegisterProvider(&provider_);
3865 3696
3866 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_FAILED); 3697 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_FAILED);
3867 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3698 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3868 } 3699 }
3869 3700
3870 // Tests that extensions cannot be loaded from prefs if the policy provider 3701 // Tests that extensions cannot be loaded from prefs if the policy provider
3871 // prohibits it. This functionality is implemented in InstalledLoader::Load(). 3702 // prohibits it. This functionality is implemented in InstalledLoader::Load().
3872 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) { 3703 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) {
3873 InitializeEmptyExtensionService(); 3704 InitializeEmptyExtensionService();
3874 3705
3875 // Create a fake extension to be loaded as though it were read from prefs. 3706 // Create a fake extension to be loaded as though it were read from prefs.
3876 base::FilePath path = data_dir_.AppendASCII("management") 3707 base::FilePath path =
3877 .AppendASCII("simple_extension"); 3708 data_dir().AppendASCII("management").AppendASCII("simple_extension");
3878 base::DictionaryValue manifest; 3709 base::DictionaryValue manifest;
3879 manifest.SetString(keys::kName, "simple_extension"); 3710 manifest.SetString(keys::kName, "simple_extension");
3880 manifest.SetString(keys::kVersion, "1"); 3711 manifest.SetString(keys::kVersion, "1");
3881 // UNPACKED is for extensions loaded from a directory. We use it here, even 3712 // UNPACKED is for extensions loaded from a directory. We use it here, even
3882 // though we're testing loading from prefs, so that we don't need to provide 3713 // though we're testing loading from prefs, so that we don't need to provide
3883 // an extension key. 3714 // an extension key.
3884 extensions::ExtensionInfo extension_info( 3715 extensions::ExtensionInfo extension_info(
3885 &manifest, std::string(), path, Manifest::UNPACKED); 3716 &manifest, std::string(), path, Manifest::UNPACKED);
3886 3717
3887 // Ensure we can load it with no management policy in place. 3718 // Ensure we can load it with no management policy in place.
3888 management_policy_->UnregisterAllProviders(); 3719 GetManagementPolicy()->UnregisterAllProviders();
3889 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3720 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3890 extensions::InstalledLoader(service_).Load(extension_info, false); 3721 extensions::InstalledLoader(service()).Load(extension_info, false);
3891 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3722 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3892 3723
3893 const Extension* extension = (registry_->enabled_extensions().begin())->get(); 3724 const Extension* extension =
3894 EXPECT_TRUE(service_->UninstallExtension(extension->id(), false, NULL)); 3725 (registry()->enabled_extensions().begin())->get();
3895 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3726 EXPECT_TRUE(service()->UninstallExtension(extension->id(), false, NULL));
3727 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3896 3728
3897 // Ensure we cannot load it if management policy prohibits installation. 3729 // Ensure we cannot load it if management policy prohibits installation.
3898 extensions::TestManagementPolicyProvider provider_( 3730 extensions::TestManagementPolicyProvider provider_(
3899 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); 3731 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
3900 management_policy_->RegisterProvider(&provider_); 3732 GetManagementPolicy()->RegisterProvider(&provider_);
3901 3733
3902 extensions::InstalledLoader(service_).Load(extension_info, false); 3734 extensions::InstalledLoader(service()).Load(extension_info, false);
3903 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3735 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3904 } 3736 }
3905 3737
3906 // Tests disabling an extension when prohibited by the ManagementPolicy. 3738 // Tests disabling an extension when prohibited by the ManagementPolicy.
3907 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) { 3739 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) {
3908 InitializeEmptyExtensionService(); 3740 InitializeEmptyExtensionService();
3909 3741
3910 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3742 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3911 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3743 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3912 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3744 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3913 3745
3914 management_policy_->UnregisterAllProviders(); 3746 GetManagementPolicy()->UnregisterAllProviders();
3915 extensions::TestManagementPolicyProvider provider( 3747 extensions::TestManagementPolicyProvider provider(
3916 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); 3748 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
3917 management_policy_->RegisterProvider(&provider); 3749 GetManagementPolicy()->RegisterProvider(&provider);
3918 3750
3919 // Attempt to disable it. 3751 // Attempt to disable it.
3920 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); 3752 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
3921 3753
3922 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3754 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3923 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3755 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3924 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3756 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3925 } 3757 }
3926 3758
3927 // Tests uninstalling an extension when prohibited by the ManagementPolicy. 3759 // Tests uninstalling an extension when prohibited by the ManagementPolicy.
3928 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) { 3760 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) {
3929 InitializeEmptyExtensionService(); 3761 InitializeEmptyExtensionService();
3930 3762
3931 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3763 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3932 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3764 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3933 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3765 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3934 3766
3935 management_policy_->UnregisterAllProviders(); 3767 GetManagementPolicy()->UnregisterAllProviders();
3936 extensions::TestManagementPolicyProvider provider( 3768 extensions::TestManagementPolicyProvider provider(
3937 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); 3769 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
3938 management_policy_->RegisterProvider(&provider); 3770 GetManagementPolicy()->RegisterProvider(&provider);
3939 3771
3940 // Attempt to uninstall it. 3772 // Attempt to uninstall it.
3941 EXPECT_FALSE(service_->UninstallExtension(good_crx, false, NULL)); 3773 EXPECT_FALSE(service()->UninstallExtension(good_crx, false, NULL));
3942 3774
3943 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3775 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3944 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3776 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3945 } 3777 }
3946 3778
3947 // Tests that previously installed extensions that are now prohibited from 3779 // Tests that previously installed extensions that are now prohibited from
3948 // being installed are removed. 3780 // being installed are removed.
3949 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { 3781 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) {
3950 InitializeEmptyExtensionService(); 3782 InitializeEmptyExtensionService();
3951 3783
3952 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3784 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3953 InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW); 3785 InstallCRX(data_dir().AppendASCII("page_action.crx"), INSTALL_NEW);
3954 EXPECT_EQ(2u, registry_->enabled_extensions().size()); 3786 EXPECT_EQ(2u, registry()->enabled_extensions().size());
3955 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3787 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3956 3788
3957 management_policy_->UnregisterAllProviders(); 3789 GetManagementPolicy()->UnregisterAllProviders();
3958 extensions::TestManagementPolicyProvider provider( 3790 extensions::TestManagementPolicyProvider provider(
3959 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); 3791 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
3960 management_policy_->RegisterProvider(&provider); 3792 GetManagementPolicy()->RegisterProvider(&provider);
3961 3793
3962 // Run the policy check. 3794 // Run the policy check.
3963 service_->CheckManagementPolicy(); 3795 service()->CheckManagementPolicy();
3964 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3796 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3965 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3797 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3966 } 3798 }
3967 3799
3968 // Tests that previously disabled extensions that are now required to be 3800 // Tests that previously disabled extensions that are now required to be
3969 // enabled are re-enabled on reinstall. 3801 // enabled are re-enabled on reinstall.
3970 TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) { 3802 TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) {
3971 InitializeEmptyExtensionService(); 3803 InitializeEmptyExtensionService();
3972 3804
3973 // Install, then disable, an extension. 3805 // Install, then disable, an extension.
3974 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3806 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3975 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3807 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3976 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); 3808 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
3977 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 3809 EXPECT_EQ(1u, registry()->disabled_extensions().size());
3978 3810
3979 // Register an ExtensionMnagementPolicy that requires the extension to remain 3811 // Register an ExtensionMnagementPolicy that requires the extension to remain
3980 // enabled. 3812 // enabled.
3981 management_policy_->UnregisterAllProviders(); 3813 GetManagementPolicy()->UnregisterAllProviders();
3982 extensions::TestManagementPolicyProvider provider( 3814 extensions::TestManagementPolicyProvider provider(
3983 extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED); 3815 extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED);
3984 management_policy_->RegisterProvider(&provider); 3816 GetManagementPolicy()->RegisterProvider(&provider);
3985 3817
3986 // Reinstall the extension. 3818 // Reinstall the extension.
3987 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_UPDATED); 3819 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_UPDATED);
3988 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3820 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3989 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3821 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3990 } 3822 }
3991 3823
3992 // Flaky on windows; http://crbug.com/309833 3824 // Flaky on windows; http://crbug.com/309833
3993 #if defined(OS_WIN) 3825 #if defined(OS_WIN)
3994 #define MAYBE_ExternalExtensionAutoAcknowledgement DISABLED_ExternalExtensionAut oAcknowledgement 3826 #define MAYBE_ExternalExtensionAutoAcknowledgement DISABLED_ExternalExtensionAut oAcknowledgement
3995 #else 3827 #else
3996 #define MAYBE_ExternalExtensionAutoAcknowledgement ExternalExtensionAutoAcknowle dgement 3828 #define MAYBE_ExternalExtensionAutoAcknowledgement ExternalExtensionAutoAcknowle dgement
3997 #endif 3829 #endif
3998 TEST_F(ExtensionServiceTest, MAYBE_ExternalExtensionAutoAcknowledgement) { 3830 TEST_F(ExtensionServiceTest, MAYBE_ExternalExtensionAutoAcknowledgement) {
3999 InitializeEmptyExtensionService(); 3831 InitializeEmptyExtensionService();
4000 set_extensions_enabled(true); 3832 service()->set_extensions_enabled(true);
4001 3833
4002 { 3834 {
4003 // Register and install an external extension. 3835 // Register and install an external extension.
4004 MockExtensionProvider* provider = 3836 MockExtensionProvider* provider =
4005 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 3837 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
4006 AddMockExternalProvider(provider); 3838 AddMockExternalProvider(provider);
4007 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 3839 provider->UpdateOrAddExtension(
4008 data_dir_.AppendASCII("good.crx")); 3840 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx"));
4009 } 3841 }
4010 { 3842 {
4011 // Have policy force-install an extension. 3843 // Have policy force-install an extension.
4012 MockExtensionProvider* provider = 3844 MockExtensionProvider* provider = new MockExtensionProvider(
4013 new MockExtensionProvider(service_, 3845 service(), Manifest::EXTERNAL_POLICY_DOWNLOAD);
4014 Manifest::EXTERNAL_POLICY_DOWNLOAD);
4015 AddMockExternalProvider(provider); 3846 AddMockExternalProvider(provider);
4016 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 3847 provider->UpdateOrAddExtension(
4017 data_dir_.AppendASCII("page_action.crx")); 3848 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
4018 } 3849 }
4019 3850
4020 // Providers are set up. Let them run. 3851 // Providers are set up. Let them run.
4021 int count = 2; 3852 int count = 2;
4022 content::WindowedNotificationObserver observer( 3853 content::WindowedNotificationObserver observer(
4023 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 3854 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4024 base::Bind(&WaitForCountNotificationsCallback, &count)); 3855 base::Bind(&WaitForCountNotificationsCallback, &count));
4025 service_->CheckForExternalUpdates(); 3856 service()->CheckForExternalUpdates();
4026 3857
4027 observer.Wait(); 3858 observer.Wait();
4028 3859
4029 ASSERT_EQ(2u, registry_->enabled_extensions().size()); 3860 ASSERT_EQ(2u, registry()->enabled_extensions().size());
4030 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3861 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
4031 EXPECT_TRUE(service_->GetExtensionById(page_action, false)); 3862 EXPECT_TRUE(service()->GetExtensionById(page_action, false));
4032 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 3863 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
4033 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); 3864 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx));
4034 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); 3865 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action));
4035 } 3866 }
4036 3867
4037 #if !defined(OS_CHROMEOS) 3868 #if !defined(OS_CHROMEOS)
4038 // This tests if default apps are installed correctly. 3869 // This tests if default apps are installed correctly.
4039 TEST_F(ExtensionServiceTest, DefaultAppsInstall) { 3870 TEST_F(ExtensionServiceTest, DefaultAppsInstall) {
4040 InitializeEmptyExtensionService(); 3871 InitializeEmptyExtensionService();
4041 set_extensions_enabled(true); 3872 service()->set_extensions_enabled(true);
4042 3873
4043 { 3874 {
4044 std::string json_data = 3875 std::string json_data =
4045 "{" 3876 "{"
4046 " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {" 3877 " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {"
4047 " \"external_crx\": \"good.crx\"," 3878 " \"external_crx\": \"good.crx\","
4048 " \"external_version\": \"1.0.0.0\"," 3879 " \"external_version\": \"1.0.0.0\","
4049 " \"is_bookmark_app\": false" 3880 " \"is_bookmark_app\": false"
4050 " }" 3881 " }"
4051 "}"; 3882 "}";
4052 default_apps::Provider* provider = 3883 default_apps::Provider* provider = new default_apps::Provider(
4053 new default_apps::Provider( 3884 profile(),
4054 profile_.get(), 3885 service(),
4055 service_, 3886 new extensions::ExternalTestingLoader(json_data, data_dir()),
4056 new extensions::ExternalTestingLoader(json_data, data_dir_), 3887 Manifest::INTERNAL,
4057 Manifest::INTERNAL, 3888 Manifest::INVALID_LOCATION,
4058 Manifest::INVALID_LOCATION, 3889 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT);
4059 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT);
4060 3890
4061 AddMockExternalProvider(provider); 3891 AddMockExternalProvider(provider);
4062 } 3892 }
4063 3893
4064 ASSERT_EQ(0u, registry_->enabled_extensions().size()); 3894 ASSERT_EQ(0u, registry()->enabled_extensions().size());
4065 content::WindowedNotificationObserver observer( 3895 content::WindowedNotificationObserver observer(
4066 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 3896 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4067 content::NotificationService::AllSources()); 3897 content::NotificationService::AllSources());
4068 service_->CheckForExternalUpdates(); 3898 service()->CheckForExternalUpdates();
4069 observer.Wait(); 3899 observer.Wait();
4070 3900
4071 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 3901 ASSERT_EQ(1u, registry()->enabled_extensions().size());
4072 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3902 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
4073 const Extension* extension = service_->GetExtensionById(good_crx, false); 3903 const Extension* extension = service()->GetExtensionById(good_crx, false);
4074 EXPECT_TRUE(extension->from_webstore()); 3904 EXPECT_TRUE(extension->from_webstore());
4075 EXPECT_TRUE(extension->was_installed_by_default()); 3905 EXPECT_TRUE(extension->was_installed_by_default());
4076 } 3906 }
4077 #endif 3907 #endif
4078 3908
4079 // Tests disabling extensions 3909 // Tests disabling extensions
4080 TEST_F(ExtensionServiceTest, DisableExtension) { 3910 TEST_F(ExtensionServiceTest, DisableExtension) {
4081 InitializeEmptyExtensionService(); 3911 InitializeEmptyExtensionService();
4082 3912
4083 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3913 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4084 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 3914 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
4085 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3915 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
4086 3916
4087 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3917 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4088 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3918 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4089 EXPECT_EQ(0u, registry_->terminated_extensions().size()); 3919 EXPECT_EQ(0u, registry()->terminated_extensions().size());
4090 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 3920 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
4091 3921
4092 // Disable it. 3922 // Disable it.
4093 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); 3923 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
4094 3924
4095 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 3925 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
4096 EXPECT_FALSE(service_->GetExtensionById(good_crx, false)); 3926 EXPECT_FALSE(service()->GetExtensionById(good_crx, false));
4097 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3927 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4098 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 3928 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4099 EXPECT_EQ(0u, registry_->terminated_extensions().size()); 3929 EXPECT_EQ(0u, registry()->terminated_extensions().size());
4100 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 3930 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
4101 } 3931 }
4102 3932
4103 TEST_F(ExtensionServiceTest, TerminateExtension) { 3933 TEST_F(ExtensionServiceTest, TerminateExtension) {
4104 InitializeEmptyExtensionService(); 3934 InitializeEmptyExtensionService();
4105 3935
4106 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3936 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4107 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3937 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4108 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3938 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4109 EXPECT_EQ(0u, registry_->terminated_extensions().size()); 3939 EXPECT_EQ(0u, registry()->terminated_extensions().size());
4110 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 3940 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
4111 3941
4112 TerminateExtension(good_crx); 3942 TerminateExtension(good_crx);
4113 3943
4114 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3944 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4115 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3945 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4116 EXPECT_EQ(1u, registry_->terminated_extensions().size()); 3946 EXPECT_EQ(1u, registry()->terminated_extensions().size());
4117 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 3947 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
4118 } 3948 }
4119 3949
4120 TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { 3950 TEST_F(ExtensionServiceTest, DisableTerminatedExtension) {
4121 InitializeEmptyExtensionService(); 3951 InitializeEmptyExtensionService();
4122 3952
4123 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3953 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4124 TerminateExtension(good_crx); 3954 TerminateExtension(good_crx);
4125 EXPECT_TRUE(registry_->GetExtensionById( 3955 EXPECT_TRUE(registry()->GetExtensionById(
4126 good_crx, extensions::ExtensionRegistry::TERMINATED)); 3956 good_crx, extensions::ExtensionRegistry::TERMINATED));
4127 3957
4128 // Disable it. 3958 // Disable it.
4129 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); 3959 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
4130 3960
4131 EXPECT_FALSE(registry_->GetExtensionById( 3961 EXPECT_FALSE(registry()->GetExtensionById(
4132 good_crx, extensions::ExtensionRegistry::TERMINATED)); 3962 good_crx, extensions::ExtensionRegistry::TERMINATED));
4133 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 3963 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
4134 3964
4135 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3965 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4136 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 3966 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4137 EXPECT_EQ(0u, registry_->terminated_extensions().size()); 3967 EXPECT_EQ(0u, registry()->terminated_extensions().size());
4138 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 3968 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
4139 } 3969 }
4140 3970
4141 // Tests disabling all extensions (simulating --disable-extensions flag). 3971 // Tests disabling all extensions (simulating --disable-extensions flag).
4142 TEST_F(ExtensionServiceTest, DisableAllExtensions) { 3972 TEST_F(ExtensionServiceTest, DisableAllExtensions) {
4143 InitializeEmptyExtensionService(); 3973 InitializeEmptyExtensionService();
4144 3974
4145 base::FilePath path = data_dir_.AppendASCII("good.crx"); 3975 base::FilePath path = data_dir().AppendASCII("good.crx");
4146 InstallCRX(path, INSTALL_NEW); 3976 InstallCRX(path, INSTALL_NEW);
4147 3977
4148 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 3978 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4149 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3979 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4150 3980
4151 // Disable extensions. 3981 // Disable extensions.
4152 service_->set_extensions_enabled(false); 3982 service()->set_extensions_enabled(false);
4153 service_->ReloadExtensionsForTest(); 3983 service()->ReloadExtensionsForTest();
4154 3984
4155 // There shouldn't be extensions in either list. 3985 // There shouldn't be extensions in either list.
4156 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3986 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4157 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3987 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4158 3988
4159 // This shouldn't do anything when all extensions are disabled. 3989 // This shouldn't do anything when all extensions are disabled.
4160 service_->EnableExtension(good_crx); 3990 service()->EnableExtension(good_crx);
4161 service_->ReloadExtensionsForTest(); 3991 service()->ReloadExtensionsForTest();
4162 3992
4163 // There still shouldn't be extensions in either list. 3993 // There still shouldn't be extensions in either list.
4164 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 3994 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4165 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 3995 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4166 3996
4167 // And then re-enable the extensions. 3997 // And then re-enable the extensions.
4168 service_->set_extensions_enabled(true); 3998 service()->set_extensions_enabled(true);
4169 service_->ReloadExtensionsForTest(); 3999 service()->ReloadExtensionsForTest();
4170 4000
4171 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4001 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4172 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 4002 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4173 } 4003 }
4174 4004
4175 // Tests reloading extensions. 4005 // Tests reloading extensions.
4176 TEST_F(ExtensionServiceTest, ReloadExtensions) { 4006 TEST_F(ExtensionServiceTest, ReloadExtensions) {
4177 InitializeEmptyExtensionService(); 4007 InitializeEmptyExtensionService();
4178 4008
4179 // Simple extension that should install without error. 4009 // Simple extension that should install without error.
4180 base::FilePath path = data_dir_.AppendASCII("good.crx"); 4010 base::FilePath path = data_dir().AppendASCII("good.crx");
4181 InstallCRX(path, INSTALL_NEW, 4011 InstallCRX(path, INSTALL_NEW,
4182 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); 4012 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT);
4183 const char* extension_id = good_crx; 4013 const char* extension_id = good_crx;
4184 service_->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); 4014 service()->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION);
4185 4015
4186 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4016 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4187 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 4017 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4188 4018
4189 service_->ReloadExtensionsForTest(); 4019 service()->ReloadExtensionsForTest();
4190 4020
4191 // The creation flags should not change when reloading the extension. 4021 // The creation flags should not change when reloading the extension.
4192 const Extension* extension = service_->GetExtensionById(good_crx, true); 4022 const Extension* extension = service()->GetExtensionById(good_crx, true);
4193 EXPECT_TRUE(extension->from_webstore()); 4023 EXPECT_TRUE(extension->from_webstore());
4194 EXPECT_TRUE(extension->was_installed_by_default()); 4024 EXPECT_TRUE(extension->was_installed_by_default());
4195 EXPECT_FALSE(extension->from_bookmark()); 4025 EXPECT_FALSE(extension->from_bookmark());
4196 4026
4197 // Extension counts shouldn't change. 4027 // Extension counts shouldn't change.
4198 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4028 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4199 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 4029 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4200 4030
4201 service_->EnableExtension(extension_id); 4031 service()->EnableExtension(extension_id);
4202 4032
4203 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4033 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4204 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 4034 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4205 4035
4206 // Need to clear |loaded_| manually before reloading as the 4036 // Need to clear |loaded_| manually before reloading as the
4207 // EnableExtension() call above inserted into it and 4037 // EnableExtension() call above inserted into it and
4208 // UnloadAllExtensions() doesn't send out notifications. 4038 // UnloadAllExtensions() doesn't send out notifications.
4209 loaded_.clear(); 4039 loaded_.clear();
4210 service_->ReloadExtensionsForTest(); 4040 service()->ReloadExtensionsForTest();
4211 4041
4212 // Extension counts shouldn't change. 4042 // Extension counts shouldn't change.
4213 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4043 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4214 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 4044 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4215 } 4045 }
4216 4046
4217 // Tests reloading an extension. 4047 // Tests reloading an extension.
4218 TEST_F(ExtensionServiceTest, ReloadExtension) { 4048 TEST_F(ExtensionServiceTest, ReloadExtension) {
4219 InitializeEmptyExtensionService(); 4049 InitializeEmptyExtensionService();
4220 InitializeProcessManager(); 4050 InitializeProcessManager();
4221 4051
4222 // Simple extension that should install without error. 4052 // Simple extension that should install without error.
4223 const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj"; 4053 const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj";
4224 base::FilePath ext = data_dir_ 4054 base::FilePath ext = data_dir()
4225 .AppendASCII("good") 4055 .AppendASCII("good")
4226 .AppendASCII("Extensions") 4056 .AppendASCII("Extensions")
4227 .AppendASCII(extension_id) 4057 .AppendASCII(extension_id)
4228 .AppendASCII("1.0.0.0"); 4058 .AppendASCII("1.0.0.0");
4229 extensions::UnpackedInstaller::Create(service_)->Load(ext); 4059 extensions::UnpackedInstaller::Create(service())->Load(ext);
4230 base::RunLoop().RunUntilIdle(); 4060 base::RunLoop().RunUntilIdle();
4231 4061
4232 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4062 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4233 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 4063 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4234 4064
4235 service_->ReloadExtension(extension_id); 4065 service()->ReloadExtension(extension_id);
4236 4066
4237 // Extension should be disabled now, waiting to be reloaded. 4067 // Extension should be disabled now, waiting to be reloaded.
4238 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4068 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4239 EXPECT_EQ(1u, registry_->disabled_extensions().size()); 4069 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4240 EXPECT_EQ( 4070 EXPECT_EQ(Extension::DISABLE_RELOAD,
4241 Extension::DISABLE_RELOAD, 4071 ExtensionPrefs::Get(profile())->GetDisableReasons(extension_id));
4242 ExtensionPrefs::Get(profile_.get())->GetDisableReasons(extension_id));
4243 4072
4244 // Reloading again should not crash. 4073 // Reloading again should not crash.
4245 service_->ReloadExtension(extension_id); 4074 service()->ReloadExtension(extension_id);
4246 4075
4247 // Finish reloading 4076 // Finish reloading
4248 base::RunLoop().RunUntilIdle(); 4077 base::RunLoop().RunUntilIdle();
4249 4078
4250 // Extension should be enabled again. 4079 // Extension should be enabled again.
4251 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4080 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4252 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 4081 EXPECT_EQ(0u, registry()->disabled_extensions().size());
4253 } 4082 }
4254 4083
4255 TEST_F(ExtensionServiceTest, UninstallExtension) { 4084 TEST_F(ExtensionServiceTest, UninstallExtension) {
4256 InitializeEmptyExtensionService(); 4085 InitializeEmptyExtensionService();
4257 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4086 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4258 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4087 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4259 UninstallExtension(good_crx, false); 4088 UninstallExtension(good_crx, false);
4260 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4089 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4261 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_); 4090 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_);
4262 } 4091 }
4263 4092
4264 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { 4093 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) {
4265 InitializeEmptyExtensionService(); 4094 InitializeEmptyExtensionService();
4266 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4095 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4267 TerminateExtension(good_crx); 4096 TerminateExtension(good_crx);
4268 UninstallExtension(good_crx, false); 4097 UninstallExtension(good_crx, false);
4269 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_); 4098 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_);
4270 } 4099 }
4271 4100
4272 // Tests the uninstaller helper. 4101 // Tests the uninstaller helper.
4273 TEST_F(ExtensionServiceTest, UninstallExtensionHelper) { 4102 TEST_F(ExtensionServiceTest, UninstallExtensionHelper) {
4274 InitializeEmptyExtensionService(); 4103 InitializeEmptyExtensionService();
4275 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4104 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4276 UninstallExtension(good_crx, true); 4105 UninstallExtension(good_crx, true);
4277 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_); 4106 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_);
4278 } 4107 }
4279 4108
4280 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { 4109 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) {
4281 InitializeEmptyExtensionService(); 4110 InitializeEmptyExtensionService();
4282 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 4111 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4283 TerminateExtension(good_crx); 4112 TerminateExtension(good_crx);
4284 UninstallExtension(good_crx, true); 4113 UninstallExtension(good_crx, true);
4285 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_); 4114 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_);
4286 } 4115 }
4287 4116
4288 // An extension disabled because of unsupported requirements should re-enabled 4117 // An extension disabled because of unsupported requirements should re-enabled
4289 // if updated to a version with supported requirements as long as there are no 4118 // if updated to a version with supported requirements as long as there are no
4290 // other disable reasons. 4119 // other disable reasons.
4291 TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) { 4120 TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) {
4292 InitializeEmptyExtensionService(); 4121 InitializeEmptyExtensionService();
4293 BlackListWebGL(); 4122 BlackListWebGL();
4294 4123
4295 base::FilePath path = data_dir_.AppendASCII("requirements"); 4124 base::FilePath path = data_dir().AppendASCII("requirements");
4296 base::FilePath pem_path = data_dir_.AppendASCII("requirements") 4125 base::FilePath pem_path =
4297 .AppendASCII("v1_good.pem"); 4126 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem");
4298 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), 4127 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"),
4299 pem_path, 4128 pem_path,
4300 INSTALL_NEW); 4129 INSTALL_NEW);
4301 std::string id = extension_v1->id(); 4130 std::string id = extension_v1->id();
4302 EXPECT_TRUE(service_->IsExtensionEnabled(id)); 4131 EXPECT_TRUE(service()->IsExtensionEnabled(id));
4303 4132
4304 base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); 4133 base::FilePath v2_bad_requirements_crx = GetTemporaryFile();
4305 4134
4306 PackCRX(path.AppendASCII("v2_bad_requirements"), 4135 PackCRX(path.AppendASCII("v2_bad_requirements"),
4307 pem_path, 4136 pem_path,
4308 v2_bad_requirements_crx); 4137 v2_bad_requirements_crx);
4309 UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); 4138 UpdateExtension(id, v2_bad_requirements_crx, INSTALLED);
4310 EXPECT_FALSE(service_->IsExtensionEnabled(id)); 4139 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4311 4140
4312 base::FilePath v3_good_crx = GetTemporaryFile(); 4141 base::FilePath v3_good_crx = GetTemporaryFile();
4313 4142
4314 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); 4143 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx);
4315 UpdateExtension(id, v3_good_crx, ENABLED); 4144 UpdateExtension(id, v3_good_crx, ENABLED);
4316 EXPECT_TRUE(service_->IsExtensionEnabled(id)); 4145 EXPECT_TRUE(service()->IsExtensionEnabled(id));
4317 } 4146 }
4318 4147
4319 // Extensions disabled through user action should stay disabled. 4148 // Extensions disabled through user action should stay disabled.
4320 TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) { 4149 TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) {
4321 InitializeEmptyExtensionService(); 4150 InitializeEmptyExtensionService();
4322 BlackListWebGL(); 4151 BlackListWebGL();
4323 4152
4324 base::FilePath path = data_dir_.AppendASCII("requirements"); 4153 base::FilePath path = data_dir().AppendASCII("requirements");
4325 base::FilePath pem_path = data_dir_.AppendASCII("requirements") 4154 base::FilePath pem_path =
4326 .AppendASCII("v1_good.pem"); 4155 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem");
4327 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), 4156 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"),
4328 pem_path, 4157 pem_path,
4329 INSTALL_NEW); 4158 INSTALL_NEW);
4330 std::string id = extension_v1->id(); 4159 std::string id = extension_v1->id();
4331 service_->DisableExtension(id, Extension::DISABLE_USER_ACTION); 4160 service()->DisableExtension(id, Extension::DISABLE_USER_ACTION);
4332 EXPECT_FALSE(service_->IsExtensionEnabled(id)); 4161 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4333 4162
4334 base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); 4163 base::FilePath v2_bad_requirements_crx = GetTemporaryFile();
4335 4164
4336 PackCRX(path.AppendASCII("v2_bad_requirements"), 4165 PackCRX(path.AppendASCII("v2_bad_requirements"),
4337 pem_path, 4166 pem_path,
4338 v2_bad_requirements_crx); 4167 v2_bad_requirements_crx);
4339 UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); 4168 UpdateExtension(id, v2_bad_requirements_crx, INSTALLED);
4340 EXPECT_FALSE(service_->IsExtensionEnabled(id)); 4169 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4341 4170
4342 base::FilePath v3_good_crx = GetTemporaryFile(); 4171 base::FilePath v3_good_crx = GetTemporaryFile();
4343 4172
4344 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); 4173 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx);
4345 UpdateExtension(id, v3_good_crx, INSTALLED); 4174 UpdateExtension(id, v3_good_crx, INSTALLED);
4346 EXPECT_FALSE(service_->IsExtensionEnabled(id)); 4175 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4347 } 4176 }
4348 4177
4349 // The extension should not re-enabled because it was disabled from a 4178 // The extension should not re-enabled because it was disabled from a
4350 // permission increase. 4179 // permission increase.
4351 TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) { 4180 TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) {
4352 InitializeEmptyExtensionService(); 4181 InitializeEmptyExtensionService();
4353 BlackListWebGL(); 4182 BlackListWebGL();
4354 4183
4355 base::FilePath path = data_dir_.AppendASCII("requirements"); 4184 base::FilePath path = data_dir().AppendASCII("requirements");
4356 base::FilePath pem_path = data_dir_.AppendASCII("requirements") 4185 base::FilePath pem_path =
4357 .AppendASCII("v1_good.pem"); 4186 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem");
4358 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), 4187 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"),
4359 pem_path, 4188 pem_path,
4360 INSTALL_NEW); 4189 INSTALL_NEW);
4361 std::string id = extension_v1->id(); 4190 std::string id = extension_v1->id();
4362 EXPECT_TRUE(service_->IsExtensionEnabled(id)); 4191 EXPECT_TRUE(service()->IsExtensionEnabled(id));
4363 4192
4364 base::FilePath v2_bad_requirements_and_permissions_crx = GetTemporaryFile(); 4193 base::FilePath v2_bad_requirements_and_permissions_crx = GetTemporaryFile();
4365 4194
4366 PackCRX(path.AppendASCII("v2_bad_requirements_and_permissions"), 4195 PackCRX(path.AppendASCII("v2_bad_requirements_and_permissions"),
4367 pem_path, 4196 pem_path,
4368 v2_bad_requirements_and_permissions_crx); 4197 v2_bad_requirements_and_permissions_crx);
4369 UpdateExtension(id, v2_bad_requirements_and_permissions_crx, INSTALLED); 4198 UpdateExtension(id, v2_bad_requirements_and_permissions_crx, INSTALLED);
4370 EXPECT_FALSE(service_->IsExtensionEnabled(id)); 4199 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4371 4200
4372 base::FilePath v3_bad_permissions_crx = GetTemporaryFile(); 4201 base::FilePath v3_bad_permissions_crx = GetTemporaryFile();
4373 4202
4374 PackCRX(path.AppendASCII("v3_bad_permissions"), 4203 PackCRX(path.AppendASCII("v3_bad_permissions"),
4375 pem_path, 4204 pem_path,
4376 v3_bad_permissions_crx); 4205 v3_bad_permissions_crx);
4377 UpdateExtension(id, v3_bad_permissions_crx, INSTALLED); 4206 UpdateExtension(id, v3_bad_permissions_crx, INSTALLED);
4378 EXPECT_FALSE(service_->IsExtensionEnabled(id)); 4207 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4379 } 4208 }
4380 4209
4381 // Unpacked extensions are not allowed to be installed if they have unsupported 4210 // Unpacked extensions are not allowed to be installed if they have unsupported
4382 // requirements. 4211 // requirements.
4383 TEST_F(ExtensionServiceTest, UnpackedRequirements) { 4212 TEST_F(ExtensionServiceTest, UnpackedRequirements) {
4384 InitializeEmptyExtensionService(); 4213 InitializeEmptyExtensionService();
4385 BlackListWebGL(); 4214 BlackListWebGL();
4386 4215
4387 base::FilePath path = data_dir_.AppendASCII("requirements") 4216 base::FilePath path =
4388 .AppendASCII("v2_bad_requirements"); 4217 data_dir().AppendASCII("requirements").AppendASCII("v2_bad_requirements");
4389 extensions::UnpackedInstaller::Create(service_)->Load(path); 4218 extensions::UnpackedInstaller::Create(service())->Load(path);
4390 base::RunLoop().RunUntilIdle(); 4219 base::RunLoop().RunUntilIdle();
4391 EXPECT_EQ(1u, GetErrors().size()); 4220 EXPECT_EQ(1u, GetErrors().size());
4392 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4221 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4393 } 4222 }
4394 4223
4395 class ExtensionCookieCallback { 4224 class ExtensionCookieCallback {
4396 public: 4225 public:
4397 ExtensionCookieCallback() 4226 ExtensionCookieCallback()
4398 : result_(false), 4227 : result_(false),
4399 weak_factory_(base::MessageLoop::current()) {} 4228 weak_factory_(base::MessageLoop::current()) {}
4400 4229
4401 void SetCookieCallback(bool result) { 4230 void SetCookieCallback(bool result) {
4402 base::MessageLoop::current()->PostTask(FROM_HERE, 4231 base::MessageLoop::current()->PostTask(FROM_HERE,
(...skipping 10 matching lines...) Expand all
4413 bool result_; 4242 bool result_;
4414 base::WeakPtrFactory<base::MessageLoop> weak_factory_; 4243 base::WeakPtrFactory<base::MessageLoop> weak_factory_;
4415 }; 4244 };
4416 4245
4417 // Verifies extension state is removed upon uninstall. 4246 // Verifies extension state is removed upon uninstall.
4418 TEST_F(ExtensionServiceTest, ClearExtensionData) { 4247 TEST_F(ExtensionServiceTest, ClearExtensionData) {
4419 InitializeEmptyExtensionService(); 4248 InitializeEmptyExtensionService();
4420 ExtensionCookieCallback callback; 4249 ExtensionCookieCallback callback;
4421 4250
4422 // Load a test extension. 4251 // Load a test extension.
4423 base::FilePath path = data_dir_; 4252 base::FilePath path = data_dir();
4424 path = path.AppendASCII("good.crx"); 4253 path = path.AppendASCII("good.crx");
4425 const Extension* extension = InstallCRX(path, INSTALL_NEW); 4254 const Extension* extension = InstallCRX(path, INSTALL_NEW);
4426 ASSERT_TRUE(extension); 4255 ASSERT_TRUE(extension);
4427 GURL ext_url(extension->url()); 4256 GURL ext_url(extension->url());
4428 std::string origin_id = webkit_database::GetIdentifierFromOrigin(ext_url); 4257 std::string origin_id = webkit_database::GetIdentifierFromOrigin(ext_url);
4429 4258
4430 // Set a cookie for the extension. 4259 // Set a cookie for the extension.
4431 net::CookieMonster* cookie_monster = 4260 net::CookieMonster* cookie_monster = profile()
4432 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> 4261 ->GetRequestContextForExtensions()
4433 cookie_store()->GetCookieMonster(); 4262 ->GetURLRequestContext()
4263 ->cookie_store()
4264 ->GetCookieMonster();
4434 ASSERT_TRUE(cookie_monster); 4265 ASSERT_TRUE(cookie_monster);
4435 net::CookieOptions options; 4266 net::CookieOptions options;
4436 cookie_monster->SetCookieWithOptionsAsync( 4267 cookie_monster->SetCookieWithOptionsAsync(
4437 ext_url, "dummy=value", options, 4268 ext_url, "dummy=value", options,
4438 base::Bind(&ExtensionCookieCallback::SetCookieCallback, 4269 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
4439 base::Unretained(&callback))); 4270 base::Unretained(&callback)));
4440 base::RunLoop().RunUntilIdle(); 4271 base::RunLoop().RunUntilIdle();
4441 EXPECT_TRUE(callback.result_); 4272 EXPECT_TRUE(callback.result_);
4442 4273
4443 cookie_monster->GetAllCookiesForURLAsync( 4274 cookie_monster->GetAllCookiesForURLAsync(
4444 ext_url, 4275 ext_url,
4445 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4276 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4446 base::Unretained(&callback))); 4277 base::Unretained(&callback)));
4447 base::RunLoop().RunUntilIdle(); 4278 base::RunLoop().RunUntilIdle();
4448 EXPECT_EQ(1U, callback.list_.size()); 4279 EXPECT_EQ(1U, callback.list_.size());
4449 4280
4450 // Open a database. 4281 // Open a database.
4451 webkit_database::DatabaseTracker* db_tracker = 4282 webkit_database::DatabaseTracker* db_tracker =
4452 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 4283 BrowserContext::GetDefaultStoragePartition(profile())
4453 GetDatabaseTracker(); 4284 ->GetDatabaseTracker();
4454 base::string16 db_name = base::UTF8ToUTF16("db"); 4285 base::string16 db_name = base::UTF8ToUTF16("db");
4455 base::string16 description = base::UTF8ToUTF16("db_description"); 4286 base::string16 description = base::UTF8ToUTF16("db_description");
4456 int64 size; 4287 int64 size;
4457 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); 4288 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size);
4458 db_tracker->DatabaseClosed(origin_id, db_name); 4289 db_tracker->DatabaseClosed(origin_id, db_name);
4459 std::vector<webkit_database::OriginInfo> origins; 4290 std::vector<webkit_database::OriginInfo> origins;
4460 db_tracker->GetAllOriginsInfo(&origins); 4291 db_tracker->GetAllOriginsInfo(&origins);
4461 EXPECT_EQ(1U, origins.size()); 4292 EXPECT_EQ(1U, origins.size());
4462 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); 4293 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier());
4463 4294
4464 // Create local storage. We only simulate this by creating the backing files. 4295 // Create local storage. We only simulate this by creating the backing files.
4465 // Note: This test depends on details of how the dom_storage library 4296 // Note: This test depends on details of how the dom_storage library
4466 // stores data in the host file system. 4297 // stores data in the host file system.
4467 base::FilePath lso_dir_path = 4298 base::FilePath lso_dir_path =
4468 profile_->GetPath().AppendASCII("Local Storage"); 4299 profile()->GetPath().AppendASCII("Local Storage");
4469 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) 4300 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id)
4470 .AddExtension(FILE_PATH_LITERAL(".localstorage")); 4301 .AddExtension(FILE_PATH_LITERAL(".localstorage"));
4471 EXPECT_TRUE(base::CreateDirectory(lso_dir_path)); 4302 EXPECT_TRUE(base::CreateDirectory(lso_dir_path));
4472 EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0)); 4303 EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0));
4473 EXPECT_TRUE(base::PathExists(lso_file_path)); 4304 EXPECT_TRUE(base::PathExists(lso_file_path));
4474 4305
4475 // Create indexed db. Similarly, it is enough to only simulate this by 4306 // Create indexed db. Similarly, it is enough to only simulate this by
4476 // creating the directory on the disk. 4307 // creating the directory on the disk.
4477 IndexedDBContext* idb_context = 4308 IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition(
4478 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 4309 profile())->GetIndexedDBContext();
4479 GetIndexedDBContext();
4480 idb_context->SetTaskRunnerForTesting( 4310 idb_context->SetTaskRunnerForTesting(
4481 base::MessageLoop::current()->message_loop_proxy().get()); 4311 base::MessageLoop::current()->message_loop_proxy().get());
4482 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); 4312 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id);
4483 EXPECT_TRUE(base::CreateDirectory(idb_path)); 4313 EXPECT_TRUE(base::CreateDirectory(idb_path));
4484 EXPECT_TRUE(base::DirectoryExists(idb_path)); 4314 EXPECT_TRUE(base::DirectoryExists(idb_path));
4485 4315
4486 // Uninstall the extension. 4316 // Uninstall the extension.
4487 service_->UninstallExtension(good_crx, false, NULL); 4317 service()->UninstallExtension(good_crx, false, NULL);
4488 base::RunLoop().RunUntilIdle(); 4318 base::RunLoop().RunUntilIdle();
4489 4319
4490 // Check that the cookie is gone. 4320 // Check that the cookie is gone.
4491 cookie_monster->GetAllCookiesForURLAsync( 4321 cookie_monster->GetAllCookiesForURLAsync(
4492 ext_url, 4322 ext_url,
4493 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4323 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4494 base::Unretained(&callback))); 4324 base::Unretained(&callback)));
4495 base::RunLoop().RunUntilIdle(); 4325 base::RunLoop().RunUntilIdle();
4496 EXPECT_EQ(0U, callback.list_.size()); 4326 EXPECT_EQ(0U, callback.list_.size());
4497 4327
(...skipping 11 matching lines...) Expand all
4509 4339
4510 // Verifies app state is removed upon uninstall. 4340 // Verifies app state is removed upon uninstall.
4511 TEST_F(ExtensionServiceTest, ClearAppData) { 4341 TEST_F(ExtensionServiceTest, ClearAppData) {
4512 InitializeEmptyExtensionService(); 4342 InitializeEmptyExtensionService();
4513 ExtensionCookieCallback callback; 4343 ExtensionCookieCallback callback;
4514 4344
4515 int pref_count = 0; 4345 int pref_count = 0;
4516 4346
4517 // Install app1 with unlimited storage. 4347 // Install app1 with unlimited storage.
4518 const Extension* extension = 4348 const Extension* extension =
4519 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 4349 PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
4520 ValidatePrefKeyCount(++pref_count); 4350 ValidatePrefKeyCount(++pref_count);
4521 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 4351 ASSERT_EQ(1u, registry()->enabled_extensions().size());
4522 const std::string id1 = extension->id(); 4352 const std::string id1 = extension->id();
4523 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( 4353 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
4524 APIPermission::kUnlimitedStorage)); 4354 APIPermission::kUnlimitedStorage));
4525 const GURL origin1( 4355 const GURL origin1(
4526 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 4356 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
4527 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 4357 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4528 IsStorageUnlimited(origin1)); 4358 origin1));
4529 std::string origin_id = webkit_database::GetIdentifierFromOrigin(origin1); 4359 std::string origin_id = webkit_database::GetIdentifierFromOrigin(origin1);
4530 4360
4531 // Install app2 from the same origin with unlimited storage. 4361 // Install app2 from the same origin with unlimited storage.
4532 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 4362 extension = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
4533 ValidatePrefKeyCount(++pref_count); 4363 ValidatePrefKeyCount(++pref_count);
4534 ASSERT_EQ(2u, registry_->enabled_extensions().size()); 4364 ASSERT_EQ(2u, registry()->enabled_extensions().size());
4535 const std::string id2 = extension->id(); 4365 const std::string id2 = extension->id();
4536 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( 4366 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
4537 APIPermission::kUnlimitedStorage)); 4367 APIPermission::kUnlimitedStorage));
4538 EXPECT_TRUE(extension->web_extent().MatchesURL( 4368 EXPECT_TRUE(extension->web_extent().MatchesURL(
4539 extensions::AppLaunchInfo::GetFullLaunchURL(extension))); 4369 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
4540 const GURL origin2( 4370 const GURL origin2(
4541 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 4371 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
4542 EXPECT_EQ(origin1, origin2); 4372 EXPECT_EQ(origin1, origin2);
4543 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 4373 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4544 IsStorageUnlimited(origin2)); 4374 origin2));
4545 4375
4546 // Set a cookie for the extension. 4376 // Set a cookie for the extension.
4547 net::CookieMonster* cookie_monster = 4377 net::CookieMonster* cookie_monster = profile()
4548 profile_->GetRequestContext()->GetURLRequestContext()-> 4378 ->GetRequestContext()
4549 cookie_store()->GetCookieMonster(); 4379 ->GetURLRequestContext()
4380 ->cookie_store()
4381 ->GetCookieMonster();
4550 ASSERT_TRUE(cookie_monster); 4382 ASSERT_TRUE(cookie_monster);
4551 net::CookieOptions options; 4383 net::CookieOptions options;
4552 cookie_monster->SetCookieWithOptionsAsync( 4384 cookie_monster->SetCookieWithOptionsAsync(
4553 origin1, "dummy=value", options, 4385 origin1, "dummy=value", options,
4554 base::Bind(&ExtensionCookieCallback::SetCookieCallback, 4386 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
4555 base::Unretained(&callback))); 4387 base::Unretained(&callback)));
4556 base::RunLoop().RunUntilIdle(); 4388 base::RunLoop().RunUntilIdle();
4557 EXPECT_TRUE(callback.result_); 4389 EXPECT_TRUE(callback.result_);
4558 4390
4559 cookie_monster->GetAllCookiesForURLAsync( 4391 cookie_monster->GetAllCookiesForURLAsync(
4560 origin1, 4392 origin1,
4561 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4393 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4562 base::Unretained(&callback))); 4394 base::Unretained(&callback)));
4563 base::RunLoop().RunUntilIdle(); 4395 base::RunLoop().RunUntilIdle();
4564 EXPECT_EQ(1U, callback.list_.size()); 4396 EXPECT_EQ(1U, callback.list_.size());
4565 4397
4566 // Open a database. 4398 // Open a database.
4567 webkit_database::DatabaseTracker* db_tracker = 4399 webkit_database::DatabaseTracker* db_tracker =
4568 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 4400 BrowserContext::GetDefaultStoragePartition(profile())
4569 GetDatabaseTracker(); 4401 ->GetDatabaseTracker();
4570 base::string16 db_name = base::UTF8ToUTF16("db"); 4402 base::string16 db_name = base::UTF8ToUTF16("db");
4571 base::string16 description = base::UTF8ToUTF16("db_description"); 4403 base::string16 description = base::UTF8ToUTF16("db_description");
4572 int64 size; 4404 int64 size;
4573 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); 4405 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size);
4574 db_tracker->DatabaseClosed(origin_id, db_name); 4406 db_tracker->DatabaseClosed(origin_id, db_name);
4575 std::vector<webkit_database::OriginInfo> origins; 4407 std::vector<webkit_database::OriginInfo> origins;
4576 db_tracker->GetAllOriginsInfo(&origins); 4408 db_tracker->GetAllOriginsInfo(&origins);
4577 EXPECT_EQ(1U, origins.size()); 4409 EXPECT_EQ(1U, origins.size());
4578 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); 4410 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier());
4579 4411
4580 // Create local storage. We only simulate this by creating the backing files. 4412 // Create local storage. We only simulate this by creating the backing files.
4581 // Note: This test depends on details of how the dom_storage library 4413 // Note: This test depends on details of how the dom_storage library
4582 // stores data in the host file system. 4414 // stores data in the host file system.
4583 base::FilePath lso_dir_path = 4415 base::FilePath lso_dir_path =
4584 profile_->GetPath().AppendASCII("Local Storage"); 4416 profile()->GetPath().AppendASCII("Local Storage");
4585 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) 4417 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id)
4586 .AddExtension(FILE_PATH_LITERAL(".localstorage")); 4418 .AddExtension(FILE_PATH_LITERAL(".localstorage"));
4587 EXPECT_TRUE(base::CreateDirectory(lso_dir_path)); 4419 EXPECT_TRUE(base::CreateDirectory(lso_dir_path));
4588 EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0)); 4420 EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0));
4589 EXPECT_TRUE(base::PathExists(lso_file_path)); 4421 EXPECT_TRUE(base::PathExists(lso_file_path));
4590 4422
4591 // Create indexed db. Similarly, it is enough to only simulate this by 4423 // Create indexed db. Similarly, it is enough to only simulate this by
4592 // creating the directory on the disk. 4424 // creating the directory on the disk.
4593 IndexedDBContext* idb_context = 4425 IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition(
4594 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 4426 profile())->GetIndexedDBContext();
4595 GetIndexedDBContext();
4596 idb_context->SetTaskRunnerForTesting( 4427 idb_context->SetTaskRunnerForTesting(
4597 base::MessageLoop::current()->message_loop_proxy().get()); 4428 base::MessageLoop::current()->message_loop_proxy().get());
4598 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); 4429 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id);
4599 EXPECT_TRUE(base::CreateDirectory(idb_path)); 4430 EXPECT_TRUE(base::CreateDirectory(idb_path));
4600 EXPECT_TRUE(base::DirectoryExists(idb_path)); 4431 EXPECT_TRUE(base::DirectoryExists(idb_path));
4601 4432
4602 // Uninstall one of them, unlimited storage should still be granted 4433 // Uninstall one of them, unlimited storage should still be granted
4603 // to the origin. 4434 // to the origin.
4604 UninstallExtension(id1, false); 4435 UninstallExtension(id1, false);
4605 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4436 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4606 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 4437 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4607 IsStorageUnlimited(origin1)); 4438 origin1));
4608 4439
4609 // Check that the cookie is still there. 4440 // Check that the cookie is still there.
4610 cookie_monster->GetAllCookiesForURLAsync( 4441 cookie_monster->GetAllCookiesForURLAsync(
4611 origin1, 4442 origin1,
4612 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4443 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4613 base::Unretained(&callback))); 4444 base::Unretained(&callback)));
4614 base::RunLoop().RunUntilIdle(); 4445 base::RunLoop().RunUntilIdle();
4615 EXPECT_EQ(1U, callback.list_.size()); 4446 EXPECT_EQ(1U, callback.list_.size());
4616 4447
4617 // Now uninstall the other. Storage should be cleared for the apps. 4448 // Now uninstall the other. Storage should be cleared for the apps.
4618 UninstallExtension(id2, false); 4449 UninstallExtension(id2, false);
4619 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4450 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4620 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 4451 EXPECT_FALSE(
4621 IsStorageUnlimited(origin1)); 4452 profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4453 origin1));
4622 4454
4623 // Check that the cookie is gone. 4455 // Check that the cookie is gone.
4624 cookie_monster->GetAllCookiesForURLAsync( 4456 cookie_monster->GetAllCookiesForURLAsync(
4625 origin1, 4457 origin1,
4626 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4458 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4627 base::Unretained(&callback))); 4459 base::Unretained(&callback)));
4628 base::RunLoop().RunUntilIdle(); 4460 base::RunLoop().RunUntilIdle();
4629 EXPECT_EQ(0U, callback.list_.size()); 4461 EXPECT_EQ(0U, callback.list_.size());
4630 4462
4631 // The database should have vanished as well. 4463 // The database should have vanished as well.
4632 origins.clear(); 4464 origins.clear();
4633 db_tracker->GetAllOriginsInfo(&origins); 4465 db_tracker->GetAllOriginsInfo(&origins);
4634 EXPECT_EQ(0U, origins.size()); 4466 EXPECT_EQ(0U, origins.size());
4635 4467
4636 // Check that the LSO file has been removed. 4468 // Check that the LSO file has been removed.
4637 EXPECT_FALSE(base::PathExists(lso_file_path)); 4469 EXPECT_FALSE(base::PathExists(lso_file_path));
4638 4470
4639 // Check if the indexed db has disappeared too. 4471 // Check if the indexed db has disappeared too.
4640 EXPECT_FALSE(base::DirectoryExists(idb_path)); 4472 EXPECT_FALSE(base::DirectoryExists(idb_path));
4641 } 4473 }
4642 4474
4643 // Tests loading single extensions (like --load-extension) 4475 // Tests loading single extensions (like --load-extension)
4644 // Flaky crashes. http://crbug.com/231806 4476 // Flaky crashes. http://crbug.com/231806
4645 TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) { 4477 TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) {
4646 InitializeEmptyExtensionService(); 4478 InitializeEmptyExtensionService();
4647 4479
4648 base::FilePath ext1 = data_dir_ 4480 base::FilePath ext1 = data_dir()
4649 .AppendASCII("good") 4481 .AppendASCII("good")
4650 .AppendASCII("Extensions") 4482 .AppendASCII("Extensions")
4651 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 4483 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
4652 .AppendASCII("1.0.0.0"); 4484 .AppendASCII("1.0.0.0");
4653 extensions::UnpackedInstaller::Create(service_)->Load(ext1); 4485 extensions::UnpackedInstaller::Create(service())->Load(ext1);
4654 base::RunLoop().RunUntilIdle(); 4486 base::RunLoop().RunUntilIdle();
4655 EXPECT_EQ(0u, GetErrors().size()); 4487 EXPECT_EQ(0u, GetErrors().size());
4656 ASSERT_EQ(1u, loaded_.size()); 4488 ASSERT_EQ(1u, loaded_.size());
4657 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); 4489 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
4658 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4490 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4659 4491
4660 ValidatePrefKeyCount(1); 4492 ValidatePrefKeyCount(1);
4661 4493
4662 base::FilePath no_manifest = data_dir_ 4494 base::FilePath no_manifest =
4663 .AppendASCII("bad") 4495 data_dir()
4664 // .AppendASCII("Extensions") 4496 .AppendASCII("bad")
4665 .AppendASCII("cccccccccccccccccccccccccccccccc") 4497 // .AppendASCII("Extensions")
4666 .AppendASCII("1"); 4498 .AppendASCII("cccccccccccccccccccccccccccccccc")
4667 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest); 4499 .AppendASCII("1");
4500 extensions::UnpackedInstaller::Create(service())->Load(no_manifest);
4668 base::RunLoop().RunUntilIdle(); 4501 base::RunLoop().RunUntilIdle();
4669 EXPECT_EQ(1u, GetErrors().size()); 4502 EXPECT_EQ(1u, GetErrors().size());
4670 ASSERT_EQ(1u, loaded_.size()); 4503 ASSERT_EQ(1u, loaded_.size());
4671 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 4504 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4672 4505
4673 // Test uninstall. 4506 // Test uninstall.
4674 std::string id = loaded_[0]->id(); 4507 std::string id = loaded_[0]->id();
4675 EXPECT_FALSE(unloaded_id_.length()); 4508 EXPECT_FALSE(unloaded_id_.length());
4676 service_->UninstallExtension(id, false, NULL); 4509 service()->UninstallExtension(id, false, NULL);
4677 base::RunLoop().RunUntilIdle(); 4510 base::RunLoop().RunUntilIdle();
4678 EXPECT_EQ(id, unloaded_id_); 4511 EXPECT_EQ(id, unloaded_id_);
4679 ASSERT_EQ(0u, loaded_.size()); 4512 ASSERT_EQ(0u, loaded_.size());
4680 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 4513 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4681 } 4514 }
4682 4515
4683 // Tests that we generate IDs when they are not specified in the manifest for 4516 // Tests that we generate IDs when they are not specified in the manifest for
4684 // --load-extension. 4517 // --load-extension.
4685 TEST_F(ExtensionServiceTest, GenerateID) { 4518 TEST_F(ExtensionServiceTest, GenerateID) {
4686 InitializeEmptyExtensionService(); 4519 InitializeEmptyExtensionService();
4687 4520
4688 base::FilePath no_id_ext = data_dir_.AppendASCII("no_id"); 4521 base::FilePath no_id_ext = data_dir().AppendASCII("no_id");
4689 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); 4522 extensions::UnpackedInstaller::Create(service())->Load(no_id_ext);
4690 base::RunLoop().RunUntilIdle(); 4523 base::RunLoop().RunUntilIdle();
4691 EXPECT_EQ(0u, GetErrors().size()); 4524 EXPECT_EQ(0u, GetErrors().size());
4692 ASSERT_EQ(1u, loaded_.size()); 4525 ASSERT_EQ(1u, loaded_.size());
4693 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); 4526 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id()));
4694 EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED); 4527 EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED);
4695 4528
4696 ValidatePrefKeyCount(1); 4529 ValidatePrefKeyCount(1);
4697 4530
4698 std::string previous_id = loaded_[0]->id(); 4531 std::string previous_id = loaded_[0]->id();
4699 4532
4700 // If we reload the same path, we should get the same extension ID. 4533 // If we reload the same path, we should get the same extension ID.
4701 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); 4534 extensions::UnpackedInstaller::Create(service())->Load(no_id_ext);
4702 base::RunLoop().RunUntilIdle(); 4535 base::RunLoop().RunUntilIdle();
4703 ASSERT_EQ(1u, loaded_.size()); 4536 ASSERT_EQ(1u, loaded_.size());
4704 ASSERT_EQ(previous_id, loaded_[0]->id()); 4537 ASSERT_EQ(previous_id, loaded_[0]->id());
4705 } 4538 }
4706 4539
4707 TEST_F(ExtensionServiceTest, UnpackedValidatesLocales) { 4540 TEST_F(ExtensionServiceTest, UnpackedValidatesLocales) {
4708 InitializeEmptyExtensionService(); 4541 InitializeEmptyExtensionService();
4709 4542
4710 base::FilePath bad_locale = data_dir_.AppendASCII("unpacked"). 4543 base::FilePath bad_locale =
4711 AppendASCII("bad_messages_file"); 4544 data_dir().AppendASCII("unpacked").AppendASCII("bad_messages_file");
4712 extensions::UnpackedInstaller::Create(service_)->Load(bad_locale); 4545 extensions::UnpackedInstaller::Create(service())->Load(bad_locale);
4713 base::RunLoop().RunUntilIdle(); 4546 base::RunLoop().RunUntilIdle();
4714 EXPECT_EQ(1u, GetErrors().size()); 4547 EXPECT_EQ(1u, GetErrors().size());
4715 base::FilePath ms_messages_file = bad_locale.AppendASCII("_locales") 4548 base::FilePath ms_messages_file = bad_locale.AppendASCII("_locales")
4716 .AppendASCII("ms") 4549 .AppendASCII("ms")
4717 .AppendASCII("messages.json"); 4550 .AppendASCII("messages.json");
4718 EXPECT_THAT(base::UTF16ToUTF8(GetErrors()[0]), testing::AllOf( 4551 EXPECT_THAT(base::UTF16ToUTF8(GetErrors()[0]), testing::AllOf(
4719 testing::HasSubstr( 4552 testing::HasSubstr(
4720 base::UTF16ToUTF8(ms_messages_file.LossyDisplayName())), 4553 base::UTF16ToUTF8(ms_messages_file.LossyDisplayName())),
4721 testing::HasSubstr("Dictionary keys must be quoted."))); 4554 testing::HasSubstr("Dictionary keys must be quoted.")));
4722 ASSERT_EQ(0u, loaded_.size()); 4555 ASSERT_EQ(0u, loaded_.size());
4723 } 4556 }
4724 4557
4725 void ExtensionServiceTest::TestExternalProvider( 4558 void ExtensionServiceTest::TestExternalProvider(
4726 MockExtensionProvider* provider, Manifest::Location location) { 4559 MockExtensionProvider* provider, Manifest::Location location) {
4727 // Verify that starting with no providers loads no extensions. 4560 // Verify that starting with no providers loads no extensions.
4728 service_->Init(); 4561 service()->Init();
4729 ASSERT_EQ(0u, loaded_.size()); 4562 ASSERT_EQ(0u, loaded_.size());
4730 4563
4731 provider->set_visit_count(0); 4564 provider->set_visit_count(0);
4732 4565
4733 // Register a test extension externally using the mock registry provider. 4566 // Register a test extension externally using the mock registry provider.
4734 base::FilePath source_path = data_dir_.AppendASCII("good.crx"); 4567 base::FilePath source_path = data_dir().AppendASCII("good.crx");
4735 4568
4736 // Add the extension. 4569 // Add the extension.
4737 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4570 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4738 4571
4739 // Reloading extensions should find our externally registered extension 4572 // Reloading extensions should find our externally registered extension
4740 // and install it. 4573 // and install it.
4741 content::WindowedNotificationObserver observer( 4574 content::WindowedNotificationObserver observer(
4742 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4575 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4743 content::NotificationService::AllSources()); 4576 content::NotificationService::AllSources());
4744 service_->CheckForExternalUpdates(); 4577 service()->CheckForExternalUpdates();
4745 observer.Wait(); 4578 observer.Wait();
4746 4579
4747 ASSERT_EQ(0u, GetErrors().size()); 4580 ASSERT_EQ(0u, GetErrors().size());
4748 ASSERT_EQ(1u, loaded_.size()); 4581 ASSERT_EQ(1u, loaded_.size());
4749 ASSERT_EQ(location, loaded_[0]->location()); 4582 ASSERT_EQ(location, loaded_[0]->location());
4750 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4583 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4751 ValidatePrefKeyCount(1); 4584 ValidatePrefKeyCount(1);
4752 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4585 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4753 ValidateIntegerPref(good_crx, "location", location); 4586 ValidateIntegerPref(good_crx, "location", location);
4754 4587
4755 // Reload extensions without changing anything. The extension should be 4588 // Reload extensions without changing anything. The extension should be
4756 // loaded again. 4589 // loaded again.
4757 loaded_.clear(); 4590 loaded_.clear();
4758 service_->ReloadExtensionsForTest(); 4591 service()->ReloadExtensionsForTest();
4759 base::RunLoop().RunUntilIdle(); 4592 base::RunLoop().RunUntilIdle();
4760 ASSERT_EQ(0u, GetErrors().size()); 4593 ASSERT_EQ(0u, GetErrors().size());
4761 ASSERT_EQ(1u, loaded_.size()); 4594 ASSERT_EQ(1u, loaded_.size());
4762 ValidatePrefKeyCount(1); 4595 ValidatePrefKeyCount(1);
4763 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4596 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4764 ValidateIntegerPref(good_crx, "location", location); 4597 ValidateIntegerPref(good_crx, "location", location);
4765 4598
4766 // Now update the extension with a new version. We should get upgraded. 4599 // Now update the extension with a new version. We should get upgraded.
4767 source_path = source_path.DirName().AppendASCII("good2.crx"); 4600 source_path = source_path.DirName().AppendASCII("good2.crx");
4768 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4601 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4769 4602
4770 loaded_.clear(); 4603 loaded_.clear();
4771 content::WindowedNotificationObserver observer_2( 4604 content::WindowedNotificationObserver observer_2(
4772 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4605 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4773 content::NotificationService::AllSources()); 4606 content::NotificationService::AllSources());
4774 service_->CheckForExternalUpdates(); 4607 service()->CheckForExternalUpdates();
4775 observer_2.Wait(); 4608 observer_2.Wait();
4776 ASSERT_EQ(0u, GetErrors().size()); 4609 ASSERT_EQ(0u, GetErrors().size());
4777 ASSERT_EQ(1u, loaded_.size()); 4610 ASSERT_EQ(1u, loaded_.size());
4778 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 4611 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
4779 ValidatePrefKeyCount(1); 4612 ValidatePrefKeyCount(1);
4780 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4613 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4781 ValidateIntegerPref(good_crx, "location", location); 4614 ValidateIntegerPref(good_crx, "location", location);
4782 4615
4783 // Uninstall the extension and reload. Nothing should happen because the 4616 // Uninstall the extension and reload. Nothing should happen because the
4784 // preference should prevent us from reinstalling. 4617 // preference should prevent us from reinstalling.
4785 std::string id = loaded_[0]->id(); 4618 std::string id = loaded_[0]->id();
4786 bool no_uninstall = 4619 bool no_uninstall =
4787 management_policy_->MustRemainEnabled(loaded_[0].get(), NULL); 4620 GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL);
4788 service_->UninstallExtension(id, false, NULL); 4621 service()->UninstallExtension(id, false, NULL);
4789 base::RunLoop().RunUntilIdle(); 4622 base::RunLoop().RunUntilIdle();
4790 4623
4791 base::FilePath install_path = extensions_install_dir_.AppendASCII(id); 4624 base::FilePath install_path = extensions_install_dir().AppendASCII(id);
4792 if (no_uninstall) { 4625 if (no_uninstall) {
4793 // Policy controlled extensions should not have been touched by uninstall. 4626 // Policy controlled extensions should not have been touched by uninstall.
4794 ASSERT_TRUE(base::PathExists(install_path)); 4627 ASSERT_TRUE(base::PathExists(install_path));
4795 } else { 4628 } else {
4796 // The extension should also be gone from the install directory. 4629 // The extension should also be gone from the install directory.
4797 ASSERT_FALSE(base::PathExists(install_path)); 4630 ASSERT_FALSE(base::PathExists(install_path));
4798 loaded_.clear(); 4631 loaded_.clear();
4799 service_->CheckForExternalUpdates(); 4632 service()->CheckForExternalUpdates();
4800 base::RunLoop().RunUntilIdle(); 4633 base::RunLoop().RunUntilIdle();
4801 ASSERT_EQ(0u, loaded_.size()); 4634 ASSERT_EQ(0u, loaded_.size());
4802 ValidatePrefKeyCount(1); 4635 ValidatePrefKeyCount(1);
4803 ValidateIntegerPref(good_crx, "state", 4636 ValidateIntegerPref(good_crx, "state",
4804 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 4637 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
4805 ValidateIntegerPref(good_crx, "location", location); 4638 ValidateIntegerPref(good_crx, "location", location);
4806 4639
4807 // Now clear the preference and reinstall. 4640 // Now clear the preference and reinstall.
4808 SetPrefInteg(good_crx, "state", Extension::ENABLED); 4641 SetPrefInteg(good_crx, "state", Extension::ENABLED);
4809 4642
4810 loaded_.clear(); 4643 loaded_.clear();
4811 content::WindowedNotificationObserver observer( 4644 content::WindowedNotificationObserver observer(
4812 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4645 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4813 content::NotificationService::AllSources()); 4646 content::NotificationService::AllSources());
4814 service_->CheckForExternalUpdates(); 4647 service()->CheckForExternalUpdates();
4815 observer.Wait(); 4648 observer.Wait();
4816 ASSERT_EQ(1u, loaded_.size()); 4649 ASSERT_EQ(1u, loaded_.size());
4817 } 4650 }
4818 ValidatePrefKeyCount(1); 4651 ValidatePrefKeyCount(1);
4819 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4652 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4820 ValidateIntegerPref(good_crx, "location", location); 4653 ValidateIntegerPref(good_crx, "location", location);
4821 4654
4822 if (management_policy_->MustRemainEnabled(loaded_[0].get(), NULL)) { 4655 if (GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL)) {
4823 EXPECT_EQ(2, provider->visit_count()); 4656 EXPECT_EQ(2, provider->visit_count());
4824 } else { 4657 } else {
4825 // Now test an externally triggered uninstall (deleting the registry key or 4658 // Now test an externally triggered uninstall (deleting the registry key or
4826 // the pref entry). 4659 // the pref entry).
4827 provider->RemoveExtension(good_crx); 4660 provider->RemoveExtension(good_crx);
4828 4661
4829 loaded_.clear(); 4662 loaded_.clear();
4830 service_->OnExternalProviderReady(provider); 4663 service()->OnExternalProviderReady(provider);
4831 base::RunLoop().RunUntilIdle(); 4664 base::RunLoop().RunUntilIdle();
4832 ASSERT_EQ(0u, loaded_.size()); 4665 ASSERT_EQ(0u, loaded_.size());
4833 ValidatePrefKeyCount(0); 4666 ValidatePrefKeyCount(0);
4834 4667
4835 // The extension should also be gone from the install directory. 4668 // The extension should also be gone from the install directory.
4836 ASSERT_FALSE(base::PathExists(install_path)); 4669 ASSERT_FALSE(base::PathExists(install_path));
4837 4670
4838 // Now test the case where user uninstalls and then the extension is removed 4671 // Now test the case where user uninstalls and then the extension is removed
4839 // from the external provider. 4672 // from the external provider.
4840 content::WindowedNotificationObserver observer( 4673 content::WindowedNotificationObserver observer(
4841 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4674 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4842 content::NotificationService::AllSources()); 4675 content::NotificationService::AllSources());
4843 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4676 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4844 service_->CheckForExternalUpdates(); 4677 service()->CheckForExternalUpdates();
4845 observer.Wait(); 4678 observer.Wait();
4846 4679
4847 ASSERT_EQ(1u, loaded_.size()); 4680 ASSERT_EQ(1u, loaded_.size());
4848 ASSERT_EQ(0u, GetErrors().size()); 4681 ASSERT_EQ(0u, GetErrors().size());
4849 4682
4850 // User uninstalls. 4683 // User uninstalls.
4851 loaded_.clear(); 4684 loaded_.clear();
4852 service_->UninstallExtension(id, false, NULL); 4685 service()->UninstallExtension(id, false, NULL);
4853 base::RunLoop().RunUntilIdle(); 4686 base::RunLoop().RunUntilIdle();
4854 ASSERT_EQ(0u, loaded_.size()); 4687 ASSERT_EQ(0u, loaded_.size());
4855 4688
4856 // Then remove the extension from the extension provider. 4689 // Then remove the extension from the extension provider.
4857 provider->RemoveExtension(good_crx); 4690 provider->RemoveExtension(good_crx);
4858 4691
4859 // Should still be at 0. 4692 // Should still be at 0.
4860 loaded_.clear(); 4693 loaded_.clear();
4861 extensions::InstalledLoader(service_).LoadAllExtensions(); 4694 extensions::InstalledLoader(service()).LoadAllExtensions();
4862 base::RunLoop().RunUntilIdle(); 4695 base::RunLoop().RunUntilIdle();
4863 ASSERT_EQ(0u, loaded_.size()); 4696 ASSERT_EQ(0u, loaded_.size());
4864 ValidatePrefKeyCount(1); 4697 ValidatePrefKeyCount(1);
4865 4698
4866 EXPECT_EQ(5, provider->visit_count()); 4699 EXPECT_EQ(5, provider->visit_count());
4867 } 4700 }
4868 } 4701 }
4869 4702
4870 // Tests the external installation feature 4703 // Tests the external installation feature
4871 #if defined(OS_WIN) 4704 #if defined(OS_WIN)
4872 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { 4705 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) {
4873 // This should all work, even when normal extension installation is disabled. 4706 // This should all work, even when normal extension installation is disabled.
4874 InitializeEmptyExtensionService(); 4707 InitializeEmptyExtensionService();
4875 set_extensions_enabled(false); 4708 service()->set_extensions_enabled(false);
4876 4709
4877 // Now add providers. Extension system takes ownership of the objects. 4710 // Now add providers. Extension system takes ownership of the objects.
4878 MockExtensionProvider* reg_provider = 4711 MockExtensionProvider* reg_provider =
4879 new MockExtensionProvider(service_, Manifest::EXTERNAL_REGISTRY); 4712 new MockExtensionProvider(service(), Manifest::EXTERNAL_REGISTRY);
4880 AddMockExternalProvider(reg_provider); 4713 AddMockExternalProvider(reg_provider);
4881 TestExternalProvider(reg_provider, Manifest::EXTERNAL_REGISTRY); 4714 TestExternalProvider(reg_provider, Manifest::EXTERNAL_REGISTRY);
4882 } 4715 }
4883 #endif 4716 #endif
4884 4717
4885 TEST_F(ExtensionServiceTest, ExternalInstallPref) { 4718 TEST_F(ExtensionServiceTest, ExternalInstallPref) {
4886 InitializeEmptyExtensionService(); 4719 InitializeEmptyExtensionService();
4887 4720
4888 // Now add providers. Extension system takes ownership of the objects. 4721 // Now add providers. Extension system takes ownership of the objects.
4889 MockExtensionProvider* pref_provider = 4722 MockExtensionProvider* pref_provider =
4890 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 4723 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
4891 4724
4892 AddMockExternalProvider(pref_provider); 4725 AddMockExternalProvider(pref_provider);
4893 TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF); 4726 TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF);
4894 } 4727 }
4895 4728
4896 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { 4729 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) {
4897 // This should all work, even when normal extension installation is disabled. 4730 // This should all work, even when normal extension installation is disabled.
4898 InitializeEmptyExtensionService(); 4731 InitializeEmptyExtensionService();
4899 set_extensions_enabled(false); 4732 service()->set_extensions_enabled(false);
4900 4733
4901 // TODO(skerner): The mock provider is not a good model of a provider 4734 // TODO(skerner): The mock provider is not a good model of a provider
4902 // that works with update URLs, because it adds file and version info. 4735 // that works with update URLs, because it adds file and version info.
4903 // Extend the mock to work with update URLs. This test checks the 4736 // Extend the mock to work with update URLs. This test checks the
4904 // behavior that is common to all external extension visitors. The 4737 // behavior that is common to all external extension visitors. The
4905 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that 4738 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that
4906 // what the visitor does results in an extension being downloaded and 4739 // what the visitor does results in an extension being downloaded and
4907 // installed. 4740 // installed.
4908 MockExtensionProvider* pref_provider = 4741 MockExtensionProvider* pref_provider =
4909 new MockExtensionProvider(service_, 4742 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF_DOWNLOAD);
4910 Manifest::EXTERNAL_PREF_DOWNLOAD);
4911 AddMockExternalProvider(pref_provider); 4743 AddMockExternalProvider(pref_provider);
4912 TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF_DOWNLOAD); 4744 TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF_DOWNLOAD);
4913 } 4745 }
4914 4746
4915 TEST_F(ExtensionServiceTest, ExternalInstallPolicyUpdateUrl) { 4747 TEST_F(ExtensionServiceTest, ExternalInstallPolicyUpdateUrl) {
4916 // This should all work, even when normal extension installation is disabled. 4748 // This should all work, even when normal extension installation is disabled.
4917 InitializeEmptyExtensionService(); 4749 InitializeEmptyExtensionService();
4918 set_extensions_enabled(false); 4750 service()->set_extensions_enabled(false);
4919 4751
4920 // TODO(skerner): The mock provider is not a good model of a provider 4752 // TODO(skerner): The mock provider is not a good model of a provider
4921 // that works with update URLs, because it adds file and version info. 4753 // that works with update URLs, because it adds file and version info.
4922 // Extend the mock to work with update URLs. This test checks the 4754 // Extend the mock to work with update URLs. This test checks the
4923 // behavior that is common to all external extension visitors. The 4755 // behavior that is common to all external extension visitors. The
4924 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that 4756 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that
4925 // what the visitor does results in an extension being downloaded and 4757 // what the visitor does results in an extension being downloaded and
4926 // installed. 4758 // installed.
4927 MockExtensionProvider* pref_provider = 4759 MockExtensionProvider* pref_provider =
4928 new MockExtensionProvider(service_, 4760 new MockExtensionProvider(service(), Manifest::EXTERNAL_POLICY_DOWNLOAD);
4929 Manifest::EXTERNAL_POLICY_DOWNLOAD);
4930 AddMockExternalProvider(pref_provider); 4761 AddMockExternalProvider(pref_provider);
4931 TestExternalProvider(pref_provider, Manifest::EXTERNAL_POLICY_DOWNLOAD); 4762 TestExternalProvider(pref_provider, Manifest::EXTERNAL_POLICY_DOWNLOAD);
4932 } 4763 }
4933 4764
4934 // Tests that external extensions get uninstalled when the external extension 4765 // Tests that external extensions get uninstalled when the external extension
4935 // providers can't account for them. 4766 // providers can't account for them.
4936 TEST_F(ExtensionServiceTest, ExternalUninstall) { 4767 TEST_F(ExtensionServiceTest, ExternalUninstall) {
4937 // Start the extensions service with one external extension already installed. 4768 // Start the extensions service with one external extension already installed.
4938 base::FilePath source_install_dir = data_dir_ 4769 base::FilePath source_install_dir =
4939 .AppendASCII("good") 4770 data_dir().AppendASCII("good").AppendASCII("Extensions");
4940 .AppendASCII("Extensions");
4941 base::FilePath pref_path = source_install_dir 4771 base::FilePath pref_path = source_install_dir
4942 .DirName() 4772 .DirName()
4943 .AppendASCII("PreferencesExternal"); 4773 .AppendASCII("PreferencesExternal");
4944 4774
4945 // This initializes the extensions service with no ExternalProviders. 4775 // This initializes the extensions service with no ExternalProviders.
4946 InitializeInstalledExtensionService(pref_path, source_install_dir); 4776 InitializeInstalledExtensionService(pref_path, source_install_dir);
4947 set_extensions_enabled(false); 4777 service()->set_extensions_enabled(false);
4948 4778
4949 service_->Init(); 4779 service()->Init();
4950 4780
4951 ASSERT_EQ(0u, GetErrors().size()); 4781 ASSERT_EQ(0u, GetErrors().size());
4952 ASSERT_EQ(0u, loaded_.size()); 4782 ASSERT_EQ(0u, loaded_.size());
4953 4783
4954 // Verify that it's not the disabled extensions flag causing it not to load. 4784 // Verify that it's not the disabled extensions flag causing it not to load.
4955 set_extensions_enabled(true); 4785 service()->set_extensions_enabled(true);
4956 service_->ReloadExtensionsForTest(); 4786 service()->ReloadExtensionsForTest();
4957 base::RunLoop().RunUntilIdle(); 4787 base::RunLoop().RunUntilIdle();
4958 4788
4959 ASSERT_EQ(0u, GetErrors().size()); 4789 ASSERT_EQ(0u, GetErrors().size());
4960 ASSERT_EQ(0u, loaded_.size()); 4790 ASSERT_EQ(0u, loaded_.size());
4961 } 4791 }
4962 4792
4963 // Test that running multiple update checks simultaneously does not 4793 // Test that running multiple update checks simultaneously does not
4964 // keep the update from succeeding. 4794 // keep the update from succeeding.
4965 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { 4795 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) {
4966 InitializeEmptyExtensionService(); 4796 InitializeEmptyExtensionService();
4967 4797
4968 MockExtensionProvider* provider = 4798 MockExtensionProvider* provider =
4969 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 4799 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
4970 AddMockExternalProvider(provider); 4800 AddMockExternalProvider(provider);
4971 4801
4972 // Verify that starting with no providers loads no extensions. 4802 // Verify that starting with no providers loads no extensions.
4973 service_->Init(); 4803 service()->Init();
4974 ASSERT_EQ(0u, loaded_.size()); 4804 ASSERT_EQ(0u, loaded_.size());
4975 4805
4976 // Start two checks for updates. 4806 // Start two checks for updates.
4977 provider->set_visit_count(0); 4807 provider->set_visit_count(0);
4978 service_->CheckForExternalUpdates(); 4808 service()->CheckForExternalUpdates();
4979 service_->CheckForExternalUpdates(); 4809 service()->CheckForExternalUpdates();
4980 base::RunLoop().RunUntilIdle(); 4810 base::RunLoop().RunUntilIdle();
4981 4811
4982 // Two calls should cause two checks for external extensions. 4812 // Two calls should cause two checks for external extensions.
4983 EXPECT_EQ(2, provider->visit_count()); 4813 EXPECT_EQ(2, provider->visit_count());
4984 EXPECT_EQ(0u, GetErrors().size()); 4814 EXPECT_EQ(0u, GetErrors().size());
4985 EXPECT_EQ(0u, loaded_.size()); 4815 EXPECT_EQ(0u, loaded_.size());
4986 4816
4987 // Register a test extension externally using the mock registry provider. 4817 // Register a test extension externally using the mock registry provider.
4988 base::FilePath source_path = data_dir_.AppendASCII("good.crx"); 4818 base::FilePath source_path = data_dir().AppendASCII("good.crx");
4989 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4819 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4990 4820
4991 // Two checks for external updates should find the extension, and install it 4821 // Two checks for external updates should find the extension, and install it
4992 // once. 4822 // once.
4993 content::WindowedNotificationObserver observer( 4823 content::WindowedNotificationObserver observer(
4994 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4824 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4995 content::NotificationService::AllSources()); 4825 content::NotificationService::AllSources());
4996 provider->set_visit_count(0); 4826 provider->set_visit_count(0);
4997 service_->CheckForExternalUpdates(); 4827 service()->CheckForExternalUpdates();
4998 service_->CheckForExternalUpdates(); 4828 service()->CheckForExternalUpdates();
4999 observer.Wait(); 4829 observer.Wait();
5000 EXPECT_EQ(2, provider->visit_count()); 4830 EXPECT_EQ(2, provider->visit_count());
5001 ASSERT_EQ(0u, GetErrors().size()); 4831 ASSERT_EQ(0u, GetErrors().size());
5002 ASSERT_EQ(1u, loaded_.size()); 4832 ASSERT_EQ(1u, loaded_.size());
5003 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); 4833 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location());
5004 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4834 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
5005 ValidatePrefKeyCount(1); 4835 ValidatePrefKeyCount(1);
5006 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4836 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
5007 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF); 4837 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF);
5008 4838
5009 provider->RemoveExtension(good_crx); 4839 provider->RemoveExtension(good_crx);
5010 provider->set_visit_count(0); 4840 provider->set_visit_count(0);
5011 service_->CheckForExternalUpdates(); 4841 service()->CheckForExternalUpdates();
5012 service_->CheckForExternalUpdates(); 4842 service()->CheckForExternalUpdates();
5013 base::RunLoop().RunUntilIdle(); 4843 base::RunLoop().RunUntilIdle();
5014 4844
5015 // Two calls should cause two checks for external extensions. 4845 // Two calls should cause two checks for external extensions.
5016 // Because the external source no longer includes good_crx, 4846 // Because the external source no longer includes good_crx,
5017 // good_crx will be uninstalled. So, expect that no extensions 4847 // good_crx will be uninstalled. So, expect that no extensions
5018 // are loaded. 4848 // are loaded.
5019 EXPECT_EQ(2, provider->visit_count()); 4849 EXPECT_EQ(2, provider->visit_count());
5020 EXPECT_EQ(0u, GetErrors().size()); 4850 EXPECT_EQ(0u, GetErrors().size());
5021 EXPECT_EQ(0u, loaded_.size()); 4851 EXPECT_EQ(0u, loaded_.size());
5022 } 4852 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
5205 "}"; 5035 "}";
5206 EXPECT_EQ(1, was_installed_by_eom_visitor.Visit(json_data)); 5036 EXPECT_EQ(1, was_installed_by_eom_visitor.Visit(json_data));
5207 } 5037 }
5208 5038
5209 // Test loading good extensions from the profile directory. 5039 // Test loading good extensions from the profile directory.
5210 TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) { 5040 TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) {
5211 // Ensure we're testing in "en" and leave global state untouched. 5041 // Ensure we're testing in "en" and leave global state untouched.
5212 extension_l10n_util::ScopedLocaleForTest testLocale("en"); 5042 extension_l10n_util::ScopedLocaleForTest testLocale("en");
5213 5043
5214 // Initialize the test dir with a good Preferences/extensions. 5044 // Initialize the test dir with a good Preferences/extensions.
5215 base::FilePath source_install_dir = data_dir_ 5045 base::FilePath source_install_dir = data_dir().AppendASCII("l10n");
5216 .AppendASCII("l10n");
5217 base::FilePath pref_path = 5046 base::FilePath pref_path =
5218 source_install_dir.Append(chrome::kPreferencesFilename); 5047 source_install_dir.Append(chrome::kPreferencesFilename);
5219 InitializeInstalledExtensionService(pref_path, source_install_dir); 5048 InitializeInstalledExtensionService(pref_path, source_install_dir);
5220 5049
5221 service_->Init(); 5050 service()->Init();
5222 5051
5223 ASSERT_EQ(3u, loaded_.size()); 5052 ASSERT_EQ(3u, loaded_.size());
5224 5053
5225 // This was equal to "sr" on load. 5054 // This was equal to "sr" on load.
5226 ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en"); 5055 ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en");
5227 5056
5228 // These are untouched by re-localization. 5057 // These are untouched by re-localization.
5229 ValidateStringPref(loaded_[1]->id(), keys::kCurrentLocale, "en"); 5058 ValidateStringPref(loaded_[1]->id(), keys::kCurrentLocale, "en");
5230 EXPECT_FALSE(IsPrefExist(loaded_[1]->id(), keys::kCurrentLocale)); 5059 EXPECT_FALSE(IsPrefExist(loaded_[1]->id(), keys::kCurrentLocale));
5231 5060
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
5356 profile.reset(); 5185 profile.reset();
5357 service = NULL; 5186 service = NULL;
5358 // Execute any pending deletion tasks. 5187 // Execute any pending deletion tasks.
5359 base::RunLoop().RunUntilIdle(); 5188 base::RunLoop().RunUntilIdle();
5360 } 5189 }
5361 5190
5362 // Test loading extensions that require limited and unlimited storage quotas. 5191 // Test loading extensions that require limited and unlimited storage quotas.
5363 TEST_F(ExtensionServiceTest, StorageQuota) { 5192 TEST_F(ExtensionServiceTest, StorageQuota) {
5364 InitializeEmptyExtensionService(); 5193 InitializeEmptyExtensionService();
5365 5194
5366 base::FilePath extensions_path = data_dir_ 5195 base::FilePath extensions_path = data_dir().AppendASCII("storage_quota");
5367 .AppendASCII("storage_quota");
5368 5196
5369 base::FilePath limited_quota_ext = 5197 base::FilePath limited_quota_ext =
5370 extensions_path.AppendASCII("limited_quota") 5198 extensions_path.AppendASCII("limited_quota")
5371 .AppendASCII("1.0"); 5199 .AppendASCII("1.0");
5372 5200
5373 // The old permission name for unlimited quota was "unlimited_storage", but 5201 // The old permission name for unlimited quota was "unlimited_storage", but
5374 // we changed it to "unlimitedStorage". This tests both versions. 5202 // we changed it to "unlimitedStorage". This tests both versions.
5375 base::FilePath unlimited_quota_ext = 5203 base::FilePath unlimited_quota_ext =
5376 extensions_path.AppendASCII("unlimited_quota") 5204 extensions_path.AppendASCII("unlimited_quota")
5377 .AppendASCII("1.0"); 5205 .AppendASCII("1.0");
5378 base::FilePath unlimited_quota_ext2 = 5206 base::FilePath unlimited_quota_ext2 =
5379 extensions_path.AppendASCII("unlimited_quota") 5207 extensions_path.AppendASCII("unlimited_quota")
5380 .AppendASCII("2.0"); 5208 .AppendASCII("2.0");
5381 extensions::UnpackedInstaller::Create(service_)->Load(limited_quota_ext); 5209 extensions::UnpackedInstaller::Create(service())->Load(limited_quota_ext);
5382 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext); 5210 extensions::UnpackedInstaller::Create(service())->Load(unlimited_quota_ext);
5383 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext2); 5211 extensions::UnpackedInstaller::Create(service())->Load(unlimited_quota_ext2);
5384 base::RunLoop().RunUntilIdle(); 5212 base::RunLoop().RunUntilIdle();
5385 5213
5386 ASSERT_EQ(3u, loaded_.size()); 5214 ASSERT_EQ(3u, loaded_.size());
5387 EXPECT_TRUE(profile_.get()); 5215 EXPECT_TRUE(profile());
5388 EXPECT_FALSE(profile_->IsOffTheRecord()); 5216 EXPECT_FALSE(profile()->IsOffTheRecord());
5389 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 5217 EXPECT_FALSE(
5390 loaded_[0]->url())); 5218 profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
5391 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 5219 loaded_[0]->url()));
5220 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
5392 loaded_[1]->url())); 5221 loaded_[1]->url()));
5393 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 5222 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
5394 loaded_[2]->url())); 5223 loaded_[2]->url()));
5395 } 5224 }
5396 5225
5397 // Tests ComponentLoader::Add(). 5226 // Tests ComponentLoader::Add().
5398 TEST_F(ExtensionServiceTest, ComponentExtensions) { 5227 TEST_F(ExtensionServiceTest, ComponentExtensions) {
5399 InitializeEmptyExtensionService(); 5228 InitializeEmptyExtensionService();
5400 5229
5401 // Component extensions should work even when extensions are disabled. 5230 // Component extensions should work even when extensions are disabled.
5402 set_extensions_enabled(false); 5231 service()->set_extensions_enabled(false);
5403 5232
5404 base::FilePath path = data_dir_ 5233 base::FilePath path = data_dir()
5405 .AppendASCII("good") 5234 .AppendASCII("good")
5406 .AppendASCII("Extensions") 5235 .AppendASCII("Extensions")
5407 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 5236 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
5408 .AppendASCII("1.0.0.0"); 5237 .AppendASCII("1.0.0.0");
5409 5238
5410 std::string manifest; 5239 std::string manifest;
5411 ASSERT_TRUE(base::ReadFileToString( 5240 ASSERT_TRUE(base::ReadFileToString(
5412 path.Append(extensions::kManifestFilename), &manifest)); 5241 path.Append(extensions::kManifestFilename), &manifest));
5413 5242
5414 service_->component_loader()->Add(manifest, path); 5243 service()->component_loader()->Add(manifest, path);
5415 service_->Init(); 5244 service()->Init();
5416 5245
5417 // Note that we do not pump messages -- the extension should be loaded 5246 // Note that we do not pump messages -- the extension should be loaded
5418 // immediately. 5247 // immediately.
5419 5248
5420 EXPECT_EQ(0u, GetErrors().size()); 5249 EXPECT_EQ(0u, GetErrors().size());
5421 ASSERT_EQ(1u, loaded_.size()); 5250 ASSERT_EQ(1u, loaded_.size());
5422 EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location()); 5251 EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location());
5423 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 5252 EXPECT_EQ(1u, registry()->enabled_extensions().size());
5424 5253
5425 // Component extensions get a prefs entry on first install. 5254 // Component extensions get a prefs entry on first install.
5426 ValidatePrefKeyCount(1); 5255 ValidatePrefKeyCount(1);
5427 5256
5428 // Reload all extensions, and make sure it comes back. 5257 // Reload all extensions, and make sure it comes back.
5429 std::string extension_id = (*registry_->enabled_extensions().begin())->id(); 5258 std::string extension_id = (*registry()->enabled_extensions().begin())->id();
5430 loaded_.clear(); 5259 loaded_.clear();
5431 service_->ReloadExtensionsForTest(); 5260 service()->ReloadExtensionsForTest();
5432 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 5261 ASSERT_EQ(1u, registry()->enabled_extensions().size());
5433 EXPECT_EQ(extension_id, (*registry_->enabled_extensions().begin())->id()); 5262 EXPECT_EQ(extension_id, (*registry()->enabled_extensions().begin())->id());
5434 } 5263 }
5435 5264
5436 TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledComponent) { 5265 TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledComponent) {
5437 InitializeEmptyExtensionService(); 5266 InitializeEmptyExtensionService();
5438 InitializeExtensionSyncService(); 5267 InitializeExtensionSyncService();
5439 5268
5440 bool flare_was_called = false; 5269 bool flare_was_called = false;
5441 syncer::ModelType triggered_type(syncer::UNSPECIFIED); 5270 syncer::ModelType triggered_type(syncer::UNSPECIFIED);
5442 base::WeakPtrFactory<ExtensionServiceTest> factory(this); 5271 base::WeakPtrFactory<ExtensionServiceTest> factory(this);
5443 extension_sync_service_->SetSyncStartFlare( 5272 extension_sync_service()->SetSyncStartFlare(
5444 base::Bind(&ExtensionServiceTest::MockSyncStartFlare, 5273 base::Bind(&ExtensionServiceTest::MockSyncStartFlare,
5445 factory.GetWeakPtr(), 5274 factory.GetWeakPtr(),
5446 &flare_was_called, // Safe due to WeakPtrFactory scope. 5275 &flare_was_called, // Safe due to WeakPtrFactory scope.
5447 &triggered_type)); // Safe due to WeakPtrFactory scope. 5276 &triggered_type)); // Safe due to WeakPtrFactory scope.
5448 5277
5449 // Install a component extension. 5278 // Install a component extension.
5450 std::string manifest; 5279 std::string manifest;
5451 ASSERT_TRUE(base::ReadFileToString( 5280 ASSERT_TRUE(base::ReadFileToString(
5452 good0_path().Append(extensions::kManifestFilename), &manifest)); 5281 good0_path().Append(extensions::kManifestFilename), &manifest));
5453 service_->component_loader()->Add(manifest, good0_path()); 5282 service()->component_loader()->Add(manifest, good0_path());
5454 ASSERT_FALSE(service_->is_ready()); 5283 ASSERT_FALSE(service()->is_ready());
5455 service_->Init(); 5284 service()->Init();
5456 ASSERT_TRUE(service_->is_ready()); 5285 ASSERT_TRUE(service()->is_ready());
5457 5286
5458 // Extensions added before service is_ready() don't trigger sync startup. 5287 // Extensions added before service is_ready() don't trigger sync startup.
5459 EXPECT_FALSE(flare_was_called); 5288 EXPECT_FALSE(flare_was_called);
5460 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); 5289 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type);
5461 } 5290 }
5462 5291
5463 TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledNormal) { 5292 TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledNormal) {
5464 InitializeGoodInstalledExtensionService(); 5293 InitializeGoodInstalledExtensionService();
5465 InitializeExtensionSyncService(); 5294 InitializeExtensionSyncService();
5466 5295
5467 bool flare_was_called = false; 5296 bool flare_was_called = false;
5468 syncer::ModelType triggered_type(syncer::UNSPECIFIED); 5297 syncer::ModelType triggered_type(syncer::UNSPECIFIED);
5469 base::WeakPtrFactory<ExtensionServiceTest> factory(this); 5298 base::WeakPtrFactory<ExtensionServiceTest> factory(this);
5470 extension_sync_service_->SetSyncStartFlare( 5299 extension_sync_service()->SetSyncStartFlare(
5471 base::Bind(&ExtensionServiceTest::MockSyncStartFlare, 5300 base::Bind(&ExtensionServiceTest::MockSyncStartFlare,
5472 factory.GetWeakPtr(), 5301 factory.GetWeakPtr(),
5473 &flare_was_called, // Safe due to WeakPtrFactory scope. 5302 &flare_was_called, // Safe due to WeakPtrFactory scope.
5474 &triggered_type)); // Safe due to WeakPtrFactory scope. 5303 &triggered_type)); // Safe due to WeakPtrFactory scope.
5475 5304
5476 ASSERT_FALSE(service_->is_ready()); 5305 ASSERT_FALSE(service()->is_ready());
5477 service_->Init(); 5306 service()->Init();
5478 ASSERT_EQ(3u, loaded_.size()); 5307 ASSERT_EQ(3u, loaded_.size());
5479 ASSERT_TRUE(service_->is_ready()); 5308 ASSERT_TRUE(service()->is_ready());
5480 5309
5481 // Extensions added before service is_ready() don't trigger sync startup. 5310 // Extensions added before service is_ready() don't trigger sync startup.
5482 EXPECT_FALSE(flare_was_called); 5311 EXPECT_FALSE(flare_was_called);
5483 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); 5312 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type);
5484 } 5313 }
5485 5314
5486 TEST_F(ExtensionServiceTest, DeferredSyncStartupOnInstall) { 5315 TEST_F(ExtensionServiceTest, DeferredSyncStartupOnInstall) {
5487 InitializeEmptyExtensionService(); 5316 InitializeEmptyExtensionService();
5488 InitializeExtensionSyncService(); 5317 InitializeExtensionSyncService();
5489 service_->Init(); 5318 service()->Init();
5490 ASSERT_TRUE(service_->is_ready()); 5319 ASSERT_TRUE(service()->is_ready());
5491 5320
5492 bool flare_was_called = false; 5321 bool flare_was_called = false;
5493 syncer::ModelType triggered_type(syncer::UNSPECIFIED); 5322 syncer::ModelType triggered_type(syncer::UNSPECIFIED);
5494 base::WeakPtrFactory<ExtensionServiceTest> factory(this); 5323 base::WeakPtrFactory<ExtensionServiceTest> factory(this);
5495 extension_sync_service_->SetSyncStartFlare( 5324 extension_sync_service()->SetSyncStartFlare(
5496 base::Bind(&ExtensionServiceTest::MockSyncStartFlare, 5325 base::Bind(&ExtensionServiceTest::MockSyncStartFlare,
5497 factory.GetWeakPtr(), 5326 factory.GetWeakPtr(),
5498 &flare_was_called, // Safe due to WeakPtrFactory scope. 5327 &flare_was_called, // Safe due to WeakPtrFactory scope.
5499 &triggered_type)); // Safe due to WeakPtrFactory scope. 5328 &triggered_type)); // Safe due to WeakPtrFactory scope.
5500 5329
5501 base::FilePath path = data_dir_.AppendASCII("good.crx"); 5330 base::FilePath path = data_dir().AppendASCII("good.crx");
5502 InstallCRX(path, INSTALL_NEW); 5331 InstallCRX(path, INSTALL_NEW);
5503 5332
5504 EXPECT_TRUE(flare_was_called); 5333 EXPECT_TRUE(flare_was_called);
5505 EXPECT_EQ(syncer::EXTENSIONS, triggered_type); 5334 EXPECT_EQ(syncer::EXTENSIONS, triggered_type);
5506 5335
5507 // Reset. 5336 // Reset.
5508 flare_was_called = false; 5337 flare_was_called = false;
5509 triggered_type = syncer::UNSPECIFIED; 5338 triggered_type = syncer::UNSPECIFIED;
5510 5339
5511 // Once sync starts, flare should no longer be invoked. 5340 // Once sync starts, flare should no longer be invoked.
5512 extension_sync_service_->MergeDataAndStartSyncing( 5341 extension_sync_service()->MergeDataAndStartSyncing(
5513 syncer::EXTENSIONS, 5342 syncer::EXTENSIONS,
5514 syncer::SyncDataList(), 5343 syncer::SyncDataList(),
5515 scoped_ptr<syncer::SyncChangeProcessor>( 5344 scoped_ptr<syncer::SyncChangeProcessor>(
5516 new syncer::FakeSyncChangeProcessor), 5345 new syncer::FakeSyncChangeProcessor),
5517 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5346 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5518 path = data_dir_.AppendASCII("page_action.crx"); 5347 path = data_dir().AppendASCII("page_action.crx");
5519 InstallCRX(path, INSTALL_NEW); 5348 InstallCRX(path, INSTALL_NEW);
5520 EXPECT_FALSE(flare_was_called); 5349 EXPECT_FALSE(flare_was_called);
5521 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); 5350 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type);
5522 } 5351 }
5523 5352
5524 TEST_F(ExtensionServiceTest, DisableExtensionFromSync) { 5353 TEST_F(ExtensionServiceTest, DisableExtensionFromSync) {
5525 // Start the extensions service with one external extension already installed. 5354 // Start the extensions service with one external extension already installed.
5526 base::FilePath source_install_dir = data_dir_ 5355 base::FilePath source_install_dir =
5527 .AppendASCII("good") 5356 data_dir().AppendASCII("good").AppendASCII("Extensions");
5528 .AppendASCII("Extensions");
5529 base::FilePath pref_path = 5357 base::FilePath pref_path =
5530 source_install_dir.DirName().Append(chrome::kPreferencesFilename); 5358 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
5531 5359
5532 InitializeInstalledExtensionService(pref_path, source_install_dir); 5360 InitializeInstalledExtensionService(pref_path, source_install_dir);
5533 InitializeExtensionSyncService(); 5361 InitializeExtensionSyncService();
5534 5362
5535 // The user has enabled sync. 5363 // The user has enabled sync.
5536 ProfileSyncService* sync_service = 5364 ProfileSyncService* sync_service =
5537 ProfileSyncServiceFactory::GetForProfile(profile_.get()); 5365 ProfileSyncServiceFactory::GetForProfile(profile());
5538 sync_service->SetSyncSetupCompleted(); 5366 sync_service->SetSyncSetupCompleted();
5539 5367
5540 service_->Init(); 5368 service()->Init();
5541 ASSERT_TRUE(service_->is_ready()); 5369 ASSERT_TRUE(service()->is_ready());
5542 5370
5543 ASSERT_EQ(3u, loaded_.size()); 5371 ASSERT_EQ(3u, loaded_.size());
5544 5372
5545 // We start enabled. 5373 // We start enabled.
5546 const Extension* extension = service_->GetExtensionById(good0, true); 5374 const Extension* extension = service()->GetExtensionById(good0, true);
5547 ASSERT_TRUE(extension); 5375 ASSERT_TRUE(extension);
5548 ASSERT_TRUE(service_->IsExtensionEnabled(good0)); 5376 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
5549 extensions::ExtensionSyncData disable_good_crx( 5377 extensions::ExtensionSyncData disable_good_crx(
5550 *extension, false, false, false); 5378 *extension, false, false, false);
5551 5379
5552 // Then sync data arrives telling us to disable |good0|. 5380 // Then sync data arrives telling us to disable |good0|.
5553 syncer::SyncDataList sync_data; 5381 syncer::SyncDataList sync_data;
5554 sync_data.push_back(disable_good_crx.GetSyncData()); 5382 sync_data.push_back(disable_good_crx.GetSyncData());
5555 extension_sync_service_->MergeDataAndStartSyncing( 5383 extension_sync_service()->MergeDataAndStartSyncing(
5556 syncer::EXTENSIONS, 5384 syncer::EXTENSIONS,
5557 sync_data, 5385 sync_data,
5558 scoped_ptr<syncer::SyncChangeProcessor>( 5386 scoped_ptr<syncer::SyncChangeProcessor>(
5559 new syncer::FakeSyncChangeProcessor), 5387 new syncer::FakeSyncChangeProcessor),
5560 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5388 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5561 ASSERT_FALSE(service_->IsExtensionEnabled(good0)); 5389 ASSERT_FALSE(service()->IsExtensionEnabled(good0));
5562 } 5390 }
5563 5391
5564 TEST_F(ExtensionServiceTest, DontDisableExtensionWithPendingEnableFromSync) { 5392 TEST_F(ExtensionServiceTest, DontDisableExtensionWithPendingEnableFromSync) {
5565 // Start the extensions service with one external extension already installed. 5393 // Start the extensions service with one external extension already installed.
5566 base::FilePath source_install_dir = data_dir_ 5394 base::FilePath source_install_dir =
5567 .AppendASCII("good") 5395 data_dir().AppendASCII("good").AppendASCII("Extensions");
5568 .AppendASCII("Extensions");
5569 base::FilePath pref_path = 5396 base::FilePath pref_path =
5570 source_install_dir.DirName().Append(chrome::kPreferencesFilename); 5397 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
5571 5398
5572 InitializeInstalledExtensionService(pref_path, source_install_dir); 5399 InitializeInstalledExtensionService(pref_path, source_install_dir);
5573 InitializeExtensionSyncService(); 5400 InitializeExtensionSyncService();
5574 5401
5575 // The user has enabled sync. 5402 // The user has enabled sync.
5576 ProfileSyncService* sync_service = 5403 ProfileSyncService* sync_service =
5577 ProfileSyncServiceFactory::GetForProfile(profile_.get()); 5404 ProfileSyncServiceFactory::GetForProfile(profile());
5578 sync_service->SetSyncSetupCompleted(); 5405 sync_service->SetSyncSetupCompleted();
5579 5406
5580 service_->Init(); 5407 service()->Init();
5581 ASSERT_TRUE(service_->is_ready()); 5408 ASSERT_TRUE(service()->is_ready());
5582 ASSERT_EQ(3u, loaded_.size()); 5409 ASSERT_EQ(3u, loaded_.size());
5583 5410
5584 const Extension* extension = service_->GetExtensionById(good0, true); 5411 const Extension* extension = service()->GetExtensionById(good0, true);
5585 ASSERT_TRUE(service_->IsExtensionEnabled(good0)); 5412 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
5586 5413
5587 // Disable extension before first sync data arrives. 5414 // Disable extension before first sync data arrives.
5588 service_->DisableExtension(good0, Extension::DISABLE_USER_ACTION); 5415 service()->DisableExtension(good0, Extension::DISABLE_USER_ACTION);
5589 ASSERT_FALSE(service_->IsExtensionEnabled(good0)); 5416 ASSERT_FALSE(service()->IsExtensionEnabled(good0));
5590 5417
5591 // Enable extension - this is now the most recent state. 5418 // Enable extension - this is now the most recent state.
5592 service_->EnableExtension(good0); 5419 service()->EnableExtension(good0);
5593 ASSERT_TRUE(service_->IsExtensionEnabled(good0)); 5420 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
5594 5421
5595 // Now sync data comes in that says to disable good0. This should be 5422 // Now sync data comes in that says to disable good0. This should be
5596 // ignored. 5423 // ignored.
5597 extensions::ExtensionSyncData disable_good_crx( 5424 extensions::ExtensionSyncData disable_good_crx(
5598 *extension, false, false, false); 5425 *extension, false, false, false);
5599 syncer::SyncDataList sync_data; 5426 syncer::SyncDataList sync_data;
5600 sync_data.push_back(disable_good_crx.GetSyncData()); 5427 sync_data.push_back(disable_good_crx.GetSyncData());
5601 extension_sync_service_->MergeDataAndStartSyncing( 5428 extension_sync_service()->MergeDataAndStartSyncing(
5602 syncer::EXTENSIONS, 5429 syncer::EXTENSIONS,
5603 sync_data, 5430 sync_data,
5604 scoped_ptr<syncer::SyncChangeProcessor>( 5431 scoped_ptr<syncer::SyncChangeProcessor>(
5605 new syncer::FakeSyncChangeProcessor), 5432 new syncer::FakeSyncChangeProcessor),
5606 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5433 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5607 5434
5608 // The extension was enabled locally before the sync data arrived, so it 5435 // The extension was enabled locally before the sync data arrived, so it
5609 // should still be enabled now. 5436 // should still be enabled now.
5610 ASSERT_TRUE(service_->IsExtensionEnabled(good0)); 5437 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
5611 } 5438 }
5612 5439
5613 TEST_F(ExtensionServiceTest, GetSyncData) { 5440 TEST_F(ExtensionServiceTest, GetSyncData) {
5614 InitializeEmptyExtensionService(); 5441 InitializeEmptyExtensionService();
5615 InitializeExtensionSyncService(); 5442 InitializeExtensionSyncService();
5616 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5443 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5617 const Extension* extension = service_->GetInstalledExtension(good_crx); 5444 const Extension* extension = service()->GetInstalledExtension(good_crx);
5618 ASSERT_TRUE(extension); 5445 ASSERT_TRUE(extension);
5619 5446
5620 extension_sync_service_->MergeDataAndStartSyncing( 5447 extension_sync_service()->MergeDataAndStartSyncing(
5621 syncer::EXTENSIONS, 5448 syncer::EXTENSIONS,
5622 syncer::SyncDataList(), 5449 syncer::SyncDataList(),
5623 scoped_ptr<syncer::SyncChangeProcessor>( 5450 scoped_ptr<syncer::SyncChangeProcessor>(
5624 new syncer::FakeSyncChangeProcessor), 5451 new syncer::FakeSyncChangeProcessor),
5625 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5452 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5626 5453
5627 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5454 syncer::SyncDataList list =
5628 syncer::EXTENSIONS); 5455 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5629 ASSERT_EQ(list.size(), 1U); 5456 ASSERT_EQ(list.size(), 1U);
5630 extensions::ExtensionSyncData data(list[0]); 5457 extensions::ExtensionSyncData data(list[0]);
5631 EXPECT_EQ(extension->id(), data.id()); 5458 EXPECT_EQ(extension->id(), data.id());
5632 EXPECT_FALSE(data.uninstalled()); 5459 EXPECT_FALSE(data.uninstalled());
5633 EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); 5460 EXPECT_EQ(service()->IsExtensionEnabled(good_crx), data.enabled());
5634 EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile_.get()), 5461 EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile()),
5635 data.incognito_enabled()); 5462 data.incognito_enabled());
5636 EXPECT_TRUE(data.version().Equals(*extension->version())); 5463 EXPECT_TRUE(data.version().Equals(*extension->version()));
5637 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension), 5464 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension),
5638 data.update_url()); 5465 data.update_url());
5639 EXPECT_EQ(extension->name(), data.name()); 5466 EXPECT_EQ(extension->name(), data.name());
5640 } 5467 }
5641 5468
5642 TEST_F(ExtensionServiceTest, GetSyncDataTerminated) { 5469 TEST_F(ExtensionServiceTest, GetSyncDataTerminated) {
5643 InitializeEmptyExtensionService(); 5470 InitializeEmptyExtensionService();
5644 InitializeExtensionSyncService(); 5471 InitializeExtensionSyncService();
5645 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5472 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5646 TerminateExtension(good_crx); 5473 TerminateExtension(good_crx);
5647 const Extension* extension = service_->GetInstalledExtension(good_crx); 5474 const Extension* extension = service()->GetInstalledExtension(good_crx);
5648 ASSERT_TRUE(extension); 5475 ASSERT_TRUE(extension);
5649 5476
5650 syncer::FakeSyncChangeProcessor processor; 5477 syncer::FakeSyncChangeProcessor processor;
5651 extension_sync_service_->MergeDataAndStartSyncing( 5478 extension_sync_service()->MergeDataAndStartSyncing(
5652 syncer::EXTENSIONS, 5479 syncer::EXTENSIONS,
5653 syncer::SyncDataList(), 5480 syncer::SyncDataList(),
5654 scoped_ptr<syncer::SyncChangeProcessor>( 5481 scoped_ptr<syncer::SyncChangeProcessor>(
5655 new syncer::FakeSyncChangeProcessor), 5482 new syncer::FakeSyncChangeProcessor),
5656 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5483 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5657 5484
5658 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5485 syncer::SyncDataList list =
5659 syncer::EXTENSIONS); 5486 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5660 ASSERT_EQ(list.size(), 1U); 5487 ASSERT_EQ(list.size(), 1U);
5661 extensions::ExtensionSyncData data(list[0]); 5488 extensions::ExtensionSyncData data(list[0]);
5662 EXPECT_EQ(extension->id(), data.id()); 5489 EXPECT_EQ(extension->id(), data.id());
5663 EXPECT_FALSE(data.uninstalled()); 5490 EXPECT_FALSE(data.uninstalled());
5664 EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); 5491 EXPECT_EQ(service()->IsExtensionEnabled(good_crx), data.enabled());
5665 EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile_.get()), 5492 EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile()),
5666 data.incognito_enabled()); 5493 data.incognito_enabled());
5667 EXPECT_TRUE(data.version().Equals(*extension->version())); 5494 EXPECT_TRUE(data.version().Equals(*extension->version()));
5668 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension), 5495 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension),
5669 data.update_url()); 5496 data.update_url());
5670 EXPECT_EQ(extension->name(), data.name()); 5497 EXPECT_EQ(extension->name(), data.name());
5671 } 5498 }
5672 5499
5673 TEST_F(ExtensionServiceTest, GetSyncDataFilter) { 5500 TEST_F(ExtensionServiceTest, GetSyncDataFilter) {
5674 InitializeEmptyExtensionService(); 5501 InitializeEmptyExtensionService();
5675 InitializeExtensionSyncService(); 5502 InitializeExtensionSyncService();
5676 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5503 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5677 const Extension* extension = service_->GetInstalledExtension(good_crx); 5504 const Extension* extension = service()->GetInstalledExtension(good_crx);
5678 ASSERT_TRUE(extension); 5505 ASSERT_TRUE(extension);
5679 5506
5680 syncer::FakeSyncChangeProcessor processor; 5507 syncer::FakeSyncChangeProcessor processor;
5681 extension_sync_service_->MergeDataAndStartSyncing( 5508 extension_sync_service()->MergeDataAndStartSyncing(
5682 syncer::APPS, 5509 syncer::APPS,
5683 syncer::SyncDataList(), 5510 syncer::SyncDataList(),
5684 scoped_ptr<syncer::SyncChangeProcessor>( 5511 scoped_ptr<syncer::SyncChangeProcessor>(
5685 new syncer::FakeSyncChangeProcessor), 5512 new syncer::FakeSyncChangeProcessor),
5686 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5513 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5687 5514
5688 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5515 syncer::SyncDataList list =
5689 syncer::EXTENSIONS); 5516 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5690 ASSERT_EQ(list.size(), 0U); 5517 ASSERT_EQ(list.size(), 0U);
5691 } 5518 }
5692 5519
5693 TEST_F(ExtensionServiceTest, GetSyncExtensionDataUserSettings) { 5520 TEST_F(ExtensionServiceTest, GetSyncExtensionDataUserSettings) {
5694 InitializeEmptyExtensionService(); 5521 InitializeEmptyExtensionService();
5695 InitializeProcessManager(); 5522 InitializeProcessManager();
5696 InitializeExtensionSyncService(); 5523 InitializeExtensionSyncService();
5697 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5524 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5698 const Extension* extension = service_->GetInstalledExtension(good_crx); 5525 const Extension* extension = service()->GetInstalledExtension(good_crx);
5699 ASSERT_TRUE(extension); 5526 ASSERT_TRUE(extension);
5700 5527
5701 syncer::FakeSyncChangeProcessor processor; 5528 syncer::FakeSyncChangeProcessor processor;
5702 extension_sync_service_->MergeDataAndStartSyncing( 5529 extension_sync_service()->MergeDataAndStartSyncing(
5703 syncer::EXTENSIONS, 5530 syncer::EXTENSIONS,
5704 syncer::SyncDataList(), 5531 syncer::SyncDataList(),
5705 scoped_ptr<syncer::SyncChangeProcessor>( 5532 scoped_ptr<syncer::SyncChangeProcessor>(
5706 new syncer::FakeSyncChangeProcessor), 5533 new syncer::FakeSyncChangeProcessor),
5707 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5534 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5708 5535
5709 { 5536 {
5710 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5537 syncer::SyncDataList list =
5711 syncer::EXTENSIONS); 5538 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5712 ASSERT_EQ(list.size(), 1U); 5539 ASSERT_EQ(list.size(), 1U);
5713 extensions::ExtensionSyncData data(list[0]); 5540 extensions::ExtensionSyncData data(list[0]);
5714 EXPECT_TRUE(data.enabled()); 5541 EXPECT_TRUE(data.enabled());
5715 EXPECT_FALSE(data.incognito_enabled()); 5542 EXPECT_FALSE(data.incognito_enabled());
5716 } 5543 }
5717 5544
5718 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); 5545 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
5719 { 5546 {
5720 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5547 syncer::SyncDataList list =
5721 syncer::EXTENSIONS); 5548 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5722 ASSERT_EQ(list.size(), 1U); 5549 ASSERT_EQ(list.size(), 1U);
5723 extensions::ExtensionSyncData data(list[0]); 5550 extensions::ExtensionSyncData data(list[0]);
5724 EXPECT_FALSE(data.enabled()); 5551 EXPECT_FALSE(data.enabled());
5725 EXPECT_FALSE(data.incognito_enabled()); 5552 EXPECT_FALSE(data.incognito_enabled());
5726 } 5553 }
5727 5554
5728 extensions::util::SetIsIncognitoEnabled(good_crx, profile_.get(), true); 5555 extensions::util::SetIsIncognitoEnabled(good_crx, profile(), true);
5729 { 5556 {
5730 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5557 syncer::SyncDataList list =
5731 syncer::EXTENSIONS); 5558 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5732 ASSERT_EQ(list.size(), 1U); 5559 ASSERT_EQ(list.size(), 1U);
5733 extensions::ExtensionSyncData data(list[0]); 5560 extensions::ExtensionSyncData data(list[0]);
5734 EXPECT_FALSE(data.enabled()); 5561 EXPECT_FALSE(data.enabled());
5735 EXPECT_TRUE(data.incognito_enabled()); 5562 EXPECT_TRUE(data.incognito_enabled());
5736 } 5563 }
5737 5564
5738 service_->EnableExtension(good_crx); 5565 service()->EnableExtension(good_crx);
5739 { 5566 {
5740 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5567 syncer::SyncDataList list =
5741 syncer::EXTENSIONS); 5568 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
5742 ASSERT_EQ(list.size(), 1U); 5569 ASSERT_EQ(list.size(), 1U);
5743 extensions::ExtensionSyncData data(list[0]); 5570 extensions::ExtensionSyncData data(list[0]);
5744 EXPECT_TRUE(data.enabled()); 5571 EXPECT_TRUE(data.enabled());
5745 EXPECT_TRUE(data.incognito_enabled()); 5572 EXPECT_TRUE(data.incognito_enabled());
5746 } 5573 }
5747 } 5574 }
5748 5575
5749 TEST_F(ExtensionServiceTest, SyncForUninstalledExternalExtension) { 5576 TEST_F(ExtensionServiceTest, SyncForUninstalledExternalExtension) {
5750 InitializeEmptyExtensionService(); 5577 InitializeEmptyExtensionService();
5751 InitializeExtensionSyncService(); 5578 InitializeExtensionSyncService();
5752 InstallCRXWithLocation(data_dir_.AppendASCII("good.crx"), 5579 InstallCRXWithLocation(
5753 Manifest::EXTERNAL_PREF, INSTALL_NEW); 5580 data_dir().AppendASCII("good.crx"), Manifest::EXTERNAL_PREF, INSTALL_NEW);
5754 const Extension* extension = service_->GetInstalledExtension(good_crx); 5581 const Extension* extension = service()->GetInstalledExtension(good_crx);
5755 ASSERT_TRUE(extension); 5582 ASSERT_TRUE(extension);
5756 5583
5757 syncer::FakeSyncChangeProcessor processor; 5584 syncer::FakeSyncChangeProcessor processor;
5758 extension_sync_service_->MergeDataAndStartSyncing( 5585 extension_sync_service()->MergeDataAndStartSyncing(
5759 syncer::EXTENSIONS, 5586 syncer::EXTENSIONS,
5760 syncer::SyncDataList(), 5587 syncer::SyncDataList(),
5761 scoped_ptr<syncer::SyncChangeProcessor>( 5588 scoped_ptr<syncer::SyncChangeProcessor>(
5762 new syncer::FakeSyncChangeProcessor), 5589 new syncer::FakeSyncChangeProcessor),
5763 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5590 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5764 5591
5765 UninstallExtension(good_crx, false); 5592 UninstallExtension(good_crx, false);
5766 EXPECT_TRUE(ExtensionPrefs::Get(profile_.get()) 5593 EXPECT_TRUE(
5767 ->IsExternalExtensionUninstalled(good_crx)); 5594 ExtensionPrefs::Get(profile())->IsExternalExtensionUninstalled(good_crx));
5768 5595
5769 sync_pb::EntitySpecifics specifics; 5596 sync_pb::EntitySpecifics specifics;
5770 sync_pb::AppSpecifics* app_specifics = specifics.mutable_app(); 5597 sync_pb::AppSpecifics* app_specifics = specifics.mutable_app();
5771 sync_pb::ExtensionSpecifics* extension_specifics = 5598 sync_pb::ExtensionSpecifics* extension_specifics =
5772 app_specifics->mutable_extension(); 5599 app_specifics->mutable_extension();
5773 extension_specifics->set_id(good_crx); 5600 extension_specifics->set_id(good_crx);
5774 extension_specifics->set_version("1.0"); 5601 extension_specifics->set_version("1.0");
5775 extension_specifics->set_enabled(true); 5602 extension_specifics->set_enabled(true);
5776 5603
5777 syncer::SyncData sync_data = 5604 syncer::SyncData sync_data =
5778 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5605 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
5779 syncer::SyncChange sync_change(FROM_HERE, 5606 syncer::SyncChange sync_change(FROM_HERE,
5780 syncer::SyncChange::ACTION_UPDATE, 5607 syncer::SyncChange::ACTION_UPDATE,
5781 sync_data); 5608 sync_data);
5782 syncer::SyncChangeList list(1); 5609 syncer::SyncChangeList list(1);
5783 list[0] = sync_change; 5610 list[0] = sync_change;
5784 5611
5785 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5612 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5786 EXPECT_TRUE(ExtensionPrefs::Get(profile_.get()) 5613 EXPECT_TRUE(
5787 ->IsExternalExtensionUninstalled(good_crx)); 5614 ExtensionPrefs::Get(profile())->IsExternalExtensionUninstalled(good_crx));
5788 } 5615 }
5789 5616
5790 TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettings) { 5617 TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettings) {
5791 InitializeEmptyExtensionService(); 5618 InitializeEmptyExtensionService();
5792 InitializeExtensionSyncService(); 5619 InitializeExtensionSyncService();
5793 const Extension* app = 5620 const Extension* app =
5794 PackAndInstallCRX(data_dir_.AppendASCII("app"), INSTALL_NEW); 5621 PackAndInstallCRX(data_dir().AppendASCII("app"), INSTALL_NEW);
5795 ASSERT_TRUE(app); 5622 ASSERT_TRUE(app);
5796 ASSERT_TRUE(app->is_app()); 5623 ASSERT_TRUE(app->is_app());
5797 5624
5798 syncer::FakeSyncChangeProcessor processor; 5625 syncer::FakeSyncChangeProcessor processor;
5799 extension_sync_service_->MergeDataAndStartSyncing( 5626 extension_sync_service()->MergeDataAndStartSyncing(
5800 syncer::APPS, 5627 syncer::APPS,
5801 syncer::SyncDataList(), 5628 syncer::SyncDataList(),
5802 scoped_ptr<syncer::SyncChangeProcessor>( 5629 scoped_ptr<syncer::SyncChangeProcessor>(
5803 new syncer::FakeSyncChangeProcessor), 5630 new syncer::FakeSyncChangeProcessor),
5804 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5631 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5805 5632
5806 syncer::StringOrdinal initial_ordinal = 5633 syncer::StringOrdinal initial_ordinal =
5807 syncer::StringOrdinal::CreateInitialOrdinal(); 5634 syncer::StringOrdinal::CreateInitialOrdinal();
5808 { 5635 {
5809 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5636 syncer::SyncDataList list =
5810 syncer::APPS); 5637 extension_sync_service()->GetAllSyncData(syncer::APPS);
5811 ASSERT_EQ(list.size(), 1U); 5638 ASSERT_EQ(list.size(), 1U);
5812 5639
5813 extensions::AppSyncData app_sync_data(list[0]); 5640 extensions::AppSyncData app_sync_data(list[0]);
5814 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.app_launch_ordinal())); 5641 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.app_launch_ordinal()));
5815 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal())); 5642 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal()));
5816 } 5643 }
5817 5644
5818 AppSorting* sorting = ExtensionPrefs::Get(profile_.get())->app_sorting(); 5645 AppSorting* sorting = ExtensionPrefs::Get(profile())->app_sorting();
5819 sorting->SetAppLaunchOrdinal(app->id(), initial_ordinal.CreateAfter()); 5646 sorting->SetAppLaunchOrdinal(app->id(), initial_ordinal.CreateAfter());
5820 { 5647 {
5821 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5648 syncer::SyncDataList list =
5822 syncer::APPS); 5649 extension_sync_service()->GetAllSyncData(syncer::APPS);
5823 ASSERT_EQ(list.size(), 1U); 5650 ASSERT_EQ(list.size(), 1U);
5824 5651
5825 extensions::AppSyncData app_sync_data(list[0]); 5652 extensions::AppSyncData app_sync_data(list[0]);
5826 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal())); 5653 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal()));
5827 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal())); 5654 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal()));
5828 } 5655 }
5829 5656
5830 sorting->SetPageOrdinal(app->id(), initial_ordinal.CreateAfter()); 5657 sorting->SetPageOrdinal(app->id(), initial_ordinal.CreateAfter());
5831 { 5658 {
5832 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5659 syncer::SyncDataList list =
5833 syncer::APPS); 5660 extension_sync_service()->GetAllSyncData(syncer::APPS);
5834 ASSERT_EQ(list.size(), 1U); 5661 ASSERT_EQ(list.size(), 1U);
5835 5662
5836 extensions::AppSyncData app_sync_data(list[0]); 5663 extensions::AppSyncData app_sync_data(list[0]);
5837 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal())); 5664 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal()));
5838 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.page_ordinal())); 5665 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.page_ordinal()));
5839 } 5666 }
5840 } 5667 }
5841 5668
5842 // TODO (rdevlin.cronin): The OnExtensionMoved() method has been removed from 5669 // TODO (rdevlin.cronin): The OnExtensionMoved() method has been removed from
5843 // ExtensionService, so this test probably needs a new home. Unfortunately, it 5670 // ExtensionService, so this test probably needs a new home. Unfortunately, it
5844 // relies pretty heavily on things like InitializeExtension[Sync]Service() and 5671 // relies pretty heavily on things like InitializeExtension[Sync]Service() and
5845 // PackAndInstallCRX(). When we clean up a bit more, this should move out. 5672 // PackAndInstallCRX(). When we clean up a bit more, this should move out.
5846 TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettingsOnExtensionMoved) { 5673 TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettingsOnExtensionMoved) {
5847 InitializeEmptyExtensionService(); 5674 InitializeEmptyExtensionService();
5848 InitializeExtensionSyncService(); 5675 InitializeExtensionSyncService();
5849 const size_t kAppCount = 3; 5676 const size_t kAppCount = 3;
5850 const Extension* apps[kAppCount]; 5677 const Extension* apps[kAppCount];
5851 apps[0] = PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 5678 apps[0] = PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
5852 apps[1] = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 5679 apps[1] = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
5853 apps[2] = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); 5680 apps[2] = PackAndInstallCRX(data_dir().AppendASCII("app4"), INSTALL_NEW);
5854 for (size_t i = 0; i < kAppCount; ++i) { 5681 for (size_t i = 0; i < kAppCount; ++i) {
5855 ASSERT_TRUE(apps[i]); 5682 ASSERT_TRUE(apps[i]);
5856 ASSERT_TRUE(apps[i]->is_app()); 5683 ASSERT_TRUE(apps[i]->is_app());
5857 } 5684 }
5858 5685
5859 syncer::FakeSyncChangeProcessor processor; 5686 syncer::FakeSyncChangeProcessor processor;
5860 extension_sync_service_->MergeDataAndStartSyncing( 5687 extension_sync_service()->MergeDataAndStartSyncing(
5861 syncer::APPS, 5688 syncer::APPS,
5862 syncer::SyncDataList(), 5689 syncer::SyncDataList(),
5863 scoped_ptr<syncer::SyncChangeProcessor>( 5690 scoped_ptr<syncer::SyncChangeProcessor>(
5864 new syncer::FakeSyncChangeProcessor), 5691 new syncer::FakeSyncChangeProcessor),
5865 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5692 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5866 5693
5867 ExtensionPrefs::Get(service_->GetBrowserContext()) 5694 ExtensionPrefs::Get(service()->GetBrowserContext())
5868 ->app_sorting() 5695 ->app_sorting()
5869 ->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id()); 5696 ->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id());
5870 { 5697 {
5871 syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( 5698 syncer::SyncDataList list =
5872 syncer::APPS); 5699 extension_sync_service()->GetAllSyncData(syncer::APPS);
5873 ASSERT_EQ(list.size(), 3U); 5700 ASSERT_EQ(list.size(), 3U);
5874 5701
5875 extensions::AppSyncData data[kAppCount]; 5702 extensions::AppSyncData data[kAppCount];
5876 for (size_t i = 0; i < kAppCount; ++i) { 5703 for (size_t i = 0; i < kAppCount; ++i) {
5877 data[i] = extensions::AppSyncData(list[i]); 5704 data[i] = extensions::AppSyncData(list[i]);
5878 } 5705 }
5879 5706
5880 // The sync data is not always in the same order our apps were installed in, 5707 // The sync data is not always in the same order our apps were installed in,
5881 // so we do that sorting here so we can make sure the values are changed as 5708 // so we do that sorting here so we can make sure the values are changed as
5882 // expected. 5709 // expected.
5883 syncer::StringOrdinal app_launch_ordinals[kAppCount]; 5710 syncer::StringOrdinal app_launch_ordinals[kAppCount];
5884 for (size_t i = 0; i < kAppCount; ++i) { 5711 for (size_t i = 0; i < kAppCount; ++i) {
5885 for (size_t j = 0; j < kAppCount; ++j) { 5712 for (size_t j = 0; j < kAppCount; ++j) {
5886 if (apps[i]->id() == data[j].id()) 5713 if (apps[i]->id() == data[j].id())
5887 app_launch_ordinals[i] = data[j].app_launch_ordinal(); 5714 app_launch_ordinals[i] = data[j].app_launch_ordinal();
5888 } 5715 }
5889 } 5716 }
5890 5717
5891 EXPECT_TRUE(app_launch_ordinals[1].LessThan(app_launch_ordinals[0])); 5718 EXPECT_TRUE(app_launch_ordinals[1].LessThan(app_launch_ordinals[0]));
5892 EXPECT_TRUE(app_launch_ordinals[0].LessThan(app_launch_ordinals[2])); 5719 EXPECT_TRUE(app_launch_ordinals[0].LessThan(app_launch_ordinals[2]));
5893 } 5720 }
5894 } 5721 }
5895 5722
5896 TEST_F(ExtensionServiceTest, GetSyncDataList) { 5723 TEST_F(ExtensionServiceTest, GetSyncDataList) {
5897 InitializeEmptyExtensionService(); 5724 InitializeEmptyExtensionService();
5898 InitializeExtensionSyncService(); 5725 InitializeExtensionSyncService();
5899 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5726 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5900 InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW); 5727 InstallCRX(data_dir().AppendASCII("page_action.crx"), INSTALL_NEW);
5901 InstallCRX(data_dir_.AppendASCII("theme.crx"), INSTALL_NEW); 5728 InstallCRX(data_dir().AppendASCII("theme.crx"), INSTALL_NEW);
5902 InstallCRX(data_dir_.AppendASCII("theme2.crx"), INSTALL_NEW); 5729 InstallCRX(data_dir().AppendASCII("theme2.crx"), INSTALL_NEW);
5903 5730
5904 syncer::FakeSyncChangeProcessor processor; 5731 syncer::FakeSyncChangeProcessor processor;
5905 extension_sync_service_->MergeDataAndStartSyncing( 5732 extension_sync_service()->MergeDataAndStartSyncing(
5906 syncer::APPS, 5733 syncer::APPS,
5907 syncer::SyncDataList(), 5734 syncer::SyncDataList(),
5908 scoped_ptr<syncer::SyncChangeProcessor>( 5735 scoped_ptr<syncer::SyncChangeProcessor>(
5909 new syncer::FakeSyncChangeProcessor), 5736 new syncer::FakeSyncChangeProcessor),
5910 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5737 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5911 extension_sync_service_->MergeDataAndStartSyncing( 5738 extension_sync_service()->MergeDataAndStartSyncing(
5912 syncer::EXTENSIONS, 5739 syncer::EXTENSIONS,
5913 syncer::SyncDataList(), 5740 syncer::SyncDataList(),
5914 scoped_ptr<syncer::SyncChangeProcessor>( 5741 scoped_ptr<syncer::SyncChangeProcessor>(
5915 new syncer::FakeSyncChangeProcessor), 5742 new syncer::FakeSyncChangeProcessor),
5916 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5743 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5917 5744
5918 service_->DisableExtension(page_action, Extension::DISABLE_USER_ACTION); 5745 service()->DisableExtension(page_action, Extension::DISABLE_USER_ACTION);
5919 TerminateExtension(theme2_crx); 5746 TerminateExtension(theme2_crx);
5920 5747
5921 EXPECT_EQ(0u, extension_sync_service_->GetAllSyncData(syncer::APPS).size()); 5748 EXPECT_EQ(0u, extension_sync_service()->GetAllSyncData(syncer::APPS).size());
5922 EXPECT_EQ(2u, extension_sync_service_-> 5749 EXPECT_EQ(
5923 GetAllSyncData(syncer::EXTENSIONS).size()); 5750 2u, extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS).size());
5924 } 5751 }
5925 5752
5926 TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) { 5753 TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) {
5927 InitializeEmptyExtensionService(); 5754 InitializeEmptyExtensionService();
5928 InitializeExtensionSyncService(); 5755 InitializeExtensionSyncService();
5929 syncer::FakeSyncChangeProcessor processor; 5756 syncer::FakeSyncChangeProcessor processor;
5930 extension_sync_service_->MergeDataAndStartSyncing( 5757 extension_sync_service()->MergeDataAndStartSyncing(
5931 syncer::EXTENSIONS, 5758 syncer::EXTENSIONS,
5932 syncer::SyncDataList(), 5759 syncer::SyncDataList(),
5933 scoped_ptr<syncer::SyncChangeProcessor>( 5760 scoped_ptr<syncer::SyncChangeProcessor>(
5934 new syncer::FakeSyncChangeProcessor), 5761 new syncer::FakeSyncChangeProcessor),
5935 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5762 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5936 5763
5937 sync_pb::EntitySpecifics specifics; 5764 sync_pb::EntitySpecifics specifics;
5938 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 5765 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
5939 ext_specifics->set_id(good_crx); 5766 ext_specifics->set_id(good_crx);
5940 ext_specifics->set_version("1.0"); 5767 ext_specifics->set_version("1.0");
5941 syncer::SyncData sync_data = 5768 syncer::SyncData sync_data =
5942 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5769 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
5943 syncer::SyncChange sync_change(FROM_HERE, 5770 syncer::SyncChange sync_change(FROM_HERE,
5944 syncer::SyncChange::ACTION_DELETE, 5771 syncer::SyncChange::ACTION_DELETE,
5945 sync_data); 5772 sync_data);
5946 syncer::SyncChangeList list(1); 5773 syncer::SyncChangeList list(1);
5947 list[0] = sync_change; 5774 list[0] = sync_change;
5948 5775
5949 // Should do nothing. 5776 // Should do nothing.
5950 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5777 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5951 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); 5778 EXPECT_FALSE(service()->GetExtensionById(good_crx, true));
5952 5779
5953 // Install the extension. 5780 // Install the extension.
5954 base::FilePath extension_path = data_dir_.AppendASCII("good.crx"); 5781 base::FilePath extension_path = data_dir().AppendASCII("good.crx");
5955 InstallCRX(extension_path, INSTALL_NEW); 5782 InstallCRX(extension_path, INSTALL_NEW);
5956 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 5783 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
5957 5784
5958 // Should uninstall the extension. 5785 // Should uninstall the extension.
5959 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5786 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5960 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); 5787 EXPECT_FALSE(service()->GetExtensionById(good_crx, true));
5961 5788
5962 // Should again do nothing. 5789 // Should again do nothing.
5963 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5790 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5964 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); 5791 EXPECT_FALSE(service()->GetExtensionById(good_crx, true));
5965 } 5792 }
5966 5793
5967 TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) { 5794 TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) {
5968 InitializeEmptyExtensionService(); 5795 InitializeEmptyExtensionService();
5969 InitializeExtensionSyncService(); 5796 InitializeExtensionSyncService();
5970 5797
5971 // Install the extension. 5798 // Install the extension.
5972 base::FilePath extension_path = data_dir_.AppendASCII("good.crx"); 5799 base::FilePath extension_path = data_dir().AppendASCII("good.crx");
5973 InstallCRX(extension_path, INSTALL_NEW); 5800 InstallCRX(extension_path, INSTALL_NEW);
5974 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 5801 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
5975 5802
5976 sync_pb::EntitySpecifics specifics; 5803 sync_pb::EntitySpecifics specifics;
5977 sync_pb::AppSpecifics* app_specifics = specifics.mutable_app(); 5804 sync_pb::AppSpecifics* app_specifics = specifics.mutable_app();
5978 sync_pb::ExtensionSpecifics* extension_specifics = 5805 sync_pb::ExtensionSpecifics* extension_specifics =
5979 app_specifics->mutable_extension(); 5806 app_specifics->mutable_extension();
5980 extension_specifics->set_id(good_crx); 5807 extension_specifics->set_id(good_crx);
5981 extension_specifics->set_version( 5808 extension_specifics->set_version(
5982 service_->GetInstalledExtension(good_crx)->version()->GetString()); 5809 service()->GetInstalledExtension(good_crx)->version()->GetString());
5983 5810
5984 { 5811 {
5985 extension_specifics->set_enabled(true); 5812 extension_specifics->set_enabled(true);
5986 syncer::SyncData sync_data = 5813 syncer::SyncData sync_data =
5987 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5814 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
5988 syncer::SyncChange sync_change(FROM_HERE, 5815 syncer::SyncChange sync_change(FROM_HERE,
5989 syncer::SyncChange::ACTION_DELETE, 5816 syncer::SyncChange::ACTION_DELETE,
5990 sync_data); 5817 sync_data);
5991 syncer::SyncChangeList list(1); 5818 syncer::SyncChangeList list(1);
5992 list[0] = sync_change; 5819 list[0] = sync_change;
5993 5820
5994 // Should do nothing 5821 // Should do nothing
5995 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5822 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5996 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 5823 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
5997 } 5824 }
5998 5825
5999 { 5826 {
6000 extension_specifics->set_enabled(false); 5827 extension_specifics->set_enabled(false);
6001 syncer::SyncData sync_data = 5828 syncer::SyncData sync_data =
6002 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5829 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6003 syncer::SyncChange sync_change(FROM_HERE, 5830 syncer::SyncChange sync_change(FROM_HERE,
6004 syncer::SyncChange::ACTION_UPDATE, 5831 syncer::SyncChange::ACTION_UPDATE,
6005 sync_data); 5832 sync_data);
6006 syncer::SyncChangeList list(1); 5833 syncer::SyncChangeList list(1);
6007 list[0] = sync_change; 5834 list[0] = sync_change;
6008 5835
6009 // Should again do nothing. 5836 // Should again do nothing.
6010 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5837 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6011 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 5838 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
6012 } 5839 }
6013 } 5840 }
6014 5841
6015 TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) { 5842 TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) {
6016 InitializeEmptyExtensionService(); 5843 InitializeEmptyExtensionService();
6017 InitializeProcessManager(); 5844 InitializeProcessManager();
6018 InitializeExtensionSyncService(); 5845 InitializeExtensionSyncService();
6019 syncer::FakeSyncChangeProcessor processor; 5846 syncer::FakeSyncChangeProcessor processor;
6020 extension_sync_service_->MergeDataAndStartSyncing( 5847 extension_sync_service()->MergeDataAndStartSyncing(
6021 syncer::EXTENSIONS, 5848 syncer::EXTENSIONS,
6022 syncer::SyncDataList(), 5849 syncer::SyncDataList(),
6023 scoped_ptr<syncer::SyncChangeProcessor>( 5850 scoped_ptr<syncer::SyncChangeProcessor>(
6024 new syncer::FakeSyncChangeProcessor), 5851 new syncer::FakeSyncChangeProcessor),
6025 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5852 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
6026 5853
6027 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5854 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
6028 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); 5855 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
6029 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 5856 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6030 5857
6031 sync_pb::EntitySpecifics specifics; 5858 sync_pb::EntitySpecifics specifics;
6032 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 5859 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
6033 ext_specifics->set_id(good_crx); 5860 ext_specifics->set_id(good_crx);
6034 ext_specifics->set_version( 5861 ext_specifics->set_version(
6035 service_->GetInstalledExtension(good_crx)->version()->GetString()); 5862 service()->GetInstalledExtension(good_crx)->version()->GetString());
6036 ext_specifics->set_enabled(false); 5863 ext_specifics->set_enabled(false);
6037 5864
6038 { 5865 {
6039 syncer::SyncData sync_data = 5866 syncer::SyncData sync_data =
6040 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5867 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6041 syncer::SyncChange sync_change(FROM_HERE, 5868 syncer::SyncChange sync_change(FROM_HERE,
6042 syncer::SyncChange::ACTION_UPDATE, 5869 syncer::SyncChange::ACTION_UPDATE,
6043 sync_data); 5870 sync_data);
6044 syncer::SyncChangeList list(1); 5871 syncer::SyncChangeList list(1);
6045 list[0] = sync_change; 5872 list[0] = sync_change;
6046 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5873 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6047 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5874 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6048 EXPECT_FALSE( 5875 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6049 extensions::util::IsIncognitoEnabled(good_crx, profile_.get()));
6050 } 5876 }
6051 5877
6052 { 5878 {
6053 ext_specifics->set_enabled(true); 5879 ext_specifics->set_enabled(true);
6054 ext_specifics->set_incognito_enabled(true); 5880 ext_specifics->set_incognito_enabled(true);
6055 syncer::SyncData sync_data = 5881 syncer::SyncData sync_data =
6056 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5882 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6057 syncer::SyncChange sync_change(FROM_HERE, 5883 syncer::SyncChange sync_change(FROM_HERE,
6058 syncer::SyncChange::ACTION_UPDATE, 5884 syncer::SyncChange::ACTION_UPDATE,
6059 sync_data); 5885 sync_data);
6060 syncer::SyncChangeList list(1); 5886 syncer::SyncChangeList list(1);
6061 list[0] = sync_change; 5887 list[0] = sync_change;
6062 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5888 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6063 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); 5889 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
6064 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 5890 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6065 } 5891 }
6066 5892
6067 { 5893 {
6068 ext_specifics->set_enabled(false); 5894 ext_specifics->set_enabled(false);
6069 ext_specifics->set_incognito_enabled(true); 5895 ext_specifics->set_incognito_enabled(true);
6070 syncer::SyncData sync_data = 5896 syncer::SyncData sync_data =
6071 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5897 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6072 syncer::SyncChange sync_change(FROM_HERE, 5898 syncer::SyncChange sync_change(FROM_HERE,
6073 syncer::SyncChange::ACTION_UPDATE, 5899 syncer::SyncChange::ACTION_UPDATE,
6074 sync_data); 5900 sync_data);
6075 syncer::SyncChangeList list(1); 5901 syncer::SyncChangeList list(1);
6076 list[0] = sync_change; 5902 list[0] = sync_change;
6077 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5903 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6078 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5904 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6079 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 5905 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6080 } 5906 }
6081 5907
6082 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); 5908 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx));
6083 } 5909 }
6084 5910
6085 TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) { 5911 TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) {
6086 InitializeExtensionServiceWithUpdater(); 5912 InitializeExtensionServiceWithUpdater();
6087 InitializeExtensionSyncService(); 5913 InitializeExtensionSyncService();
6088 syncer::FakeSyncChangeProcessor processor; 5914 syncer::FakeSyncChangeProcessor processor;
6089 extension_sync_service_->MergeDataAndStartSyncing( 5915 extension_sync_service()->MergeDataAndStartSyncing(
6090 syncer::EXTENSIONS, 5916 syncer::EXTENSIONS,
6091 syncer::SyncDataList(), 5917 syncer::SyncDataList(),
6092 scoped_ptr<syncer::SyncChangeProcessor>( 5918 scoped_ptr<syncer::SyncChangeProcessor>(
6093 new syncer::FakeSyncChangeProcessor), 5919 new syncer::FakeSyncChangeProcessor),
6094 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5920 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
6095 5921
6096 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5922 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
6097 TerminateExtension(good_crx); 5923 TerminateExtension(good_crx);
6098 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); 5924 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
6099 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 5925 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6100 5926
6101 sync_pb::EntitySpecifics specifics; 5927 sync_pb::EntitySpecifics specifics;
6102 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 5928 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
6103 ext_specifics->set_id(good_crx); 5929 ext_specifics->set_id(good_crx);
6104 ext_specifics->set_version( 5930 ext_specifics->set_version(
6105 service_->GetInstalledExtension(good_crx)->version()->GetString()); 5931 service()->GetInstalledExtension(good_crx)->version()->GetString());
6106 ext_specifics->set_enabled(false); 5932 ext_specifics->set_enabled(false);
6107 ext_specifics->set_incognito_enabled(true); 5933 ext_specifics->set_incognito_enabled(true);
6108 syncer::SyncData sync_data = 5934 syncer::SyncData sync_data =
6109 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5935 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6110 syncer::SyncChange sync_change(FROM_HERE, 5936 syncer::SyncChange sync_change(FROM_HERE,
6111 syncer::SyncChange::ACTION_UPDATE, 5937 syncer::SyncChange::ACTION_UPDATE,
6112 sync_data); 5938 sync_data);
6113 syncer::SyncChangeList list(1); 5939 syncer::SyncChangeList list(1);
6114 list[0] = sync_change; 5940 list[0] = sync_change;
6115 5941
6116 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5942 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6117 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5943 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6118 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 5944 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6119 5945
6120 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); 5946 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx));
6121 } 5947 }
6122 5948
6123 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { 5949 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) {
6124 InitializeExtensionServiceWithUpdater(); 5950 InitializeExtensionServiceWithUpdater();
6125 InitializeExtensionSyncService(); 5951 InitializeExtensionSyncService();
6126 syncer::FakeSyncChangeProcessor processor; 5952 syncer::FakeSyncChangeProcessor processor;
6127 extension_sync_service_->MergeDataAndStartSyncing( 5953 extension_sync_service()->MergeDataAndStartSyncing(
6128 syncer::EXTENSIONS, 5954 syncer::EXTENSIONS,
6129 syncer::SyncDataList(), 5955 syncer::SyncDataList(),
6130 scoped_ptr<syncer::SyncChangeProcessor>( 5956 scoped_ptr<syncer::SyncChangeProcessor>(
6131 new syncer::FakeSyncChangeProcessor), 5957 new syncer::FakeSyncChangeProcessor),
6132 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5958 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
6133 5959
6134 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 5960 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
6135 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); 5961 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
6136 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 5962 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6137 5963
6138 sync_pb::EntitySpecifics specifics; 5964 sync_pb::EntitySpecifics specifics;
6139 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 5965 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
6140 ext_specifics->set_id(good_crx); 5966 ext_specifics->set_id(good_crx);
6141 ext_specifics->set_enabled(true); 5967 ext_specifics->set_enabled(true);
6142 5968
6143 { 5969 {
6144 ext_specifics->set_version( 5970 ext_specifics->set_version(
6145 service_->GetInstalledExtension(good_crx)->version()->GetString()); 5971 service()->GetInstalledExtension(good_crx)->version()->GetString());
6146 syncer::SyncData sync_data = 5972 syncer::SyncData sync_data =
6147 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5973 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6148 syncer::SyncChange sync_change(FROM_HERE, 5974 syncer::SyncChange sync_change(FROM_HERE,
6149 syncer::SyncChange::ACTION_UPDATE, 5975 syncer::SyncChange::ACTION_UPDATE,
6150 sync_data); 5976 sync_data);
6151 syncer::SyncChangeList list(1); 5977 syncer::SyncChangeList list(1);
6152 list[0] = sync_change; 5978 list[0] = sync_change;
6153 5979
6154 // Should do nothing if extension version == sync version. 5980 // Should do nothing if extension version == sync version.
6155 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5981 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6156 EXPECT_FALSE(service_->updater()->WillCheckSoon()); 5982 EXPECT_FALSE(service()->updater()->WillCheckSoon());
6157 } 5983 }
6158 5984
6159 // Should do nothing if extension version > sync version (but see 5985 // Should do nothing if extension version > sync version (but see
6160 // the TODO in ProcessExtensionSyncData). 5986 // the TODO in ProcessExtensionSyncData).
6161 { 5987 {
6162 ext_specifics->set_version("0.0.0.0"); 5988 ext_specifics->set_version("0.0.0.0");
6163 syncer::SyncData sync_data = 5989 syncer::SyncData sync_data =
6164 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 5990 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6165 syncer::SyncChange sync_change(FROM_HERE, 5991 syncer::SyncChange sync_change(FROM_HERE,
6166 syncer::SyncChange::ACTION_UPDATE, 5992 syncer::SyncChange::ACTION_UPDATE,
6167 sync_data); 5993 sync_data);
6168 syncer::SyncChangeList list(1); 5994 syncer::SyncChangeList list(1);
6169 list[0] = sync_change; 5995 list[0] = sync_change;
6170 5996
6171 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 5997 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6172 EXPECT_FALSE(service_->updater()->WillCheckSoon()); 5998 EXPECT_FALSE(service()->updater()->WillCheckSoon());
6173 } 5999 }
6174 6000
6175 // Should kick off an update if extension version < sync version. 6001 // Should kick off an update if extension version < sync version.
6176 { 6002 {
6177 ext_specifics->set_version("9.9.9.9"); 6003 ext_specifics->set_version("9.9.9.9");
6178 syncer::SyncData sync_data = 6004 syncer::SyncData sync_data =
6179 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 6005 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6180 syncer::SyncChange sync_change(FROM_HERE, 6006 syncer::SyncChange sync_change(FROM_HERE,
6181 syncer::SyncChange::ACTION_UPDATE, 6007 syncer::SyncChange::ACTION_UPDATE,
6182 sync_data); 6008 sync_data);
6183 syncer::SyncChangeList list(1); 6009 syncer::SyncChangeList list(1);
6184 list[0] = sync_change; 6010 list[0] = sync_change;
6185 6011
6186 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 6012 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6187 EXPECT_TRUE(service_->updater()->WillCheckSoon()); 6013 EXPECT_TRUE(service()->updater()->WillCheckSoon());
6188 } 6014 }
6189 6015
6190 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); 6016 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx));
6191 } 6017 }
6192 6018
6193 TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { 6019 TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) {
6194 InitializeExtensionServiceWithUpdater(); 6020 InitializeExtensionServiceWithUpdater();
6195 InitializeExtensionSyncService(); 6021 InitializeExtensionSyncService();
6196 syncer::FakeSyncChangeProcessor processor; 6022 syncer::FakeSyncChangeProcessor processor;
6197 extension_sync_service_->MergeDataAndStartSyncing( 6023 extension_sync_service()->MergeDataAndStartSyncing(
6198 syncer::EXTENSIONS, 6024 syncer::EXTENSIONS,
6199 syncer::SyncDataList(), 6025 syncer::SyncDataList(),
6200 scoped_ptr<syncer::SyncChangeProcessor>( 6026 scoped_ptr<syncer::SyncChangeProcessor>(
6201 new syncer::FakeSyncChangeProcessor), 6027 new syncer::FakeSyncChangeProcessor),
6202 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 6028 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
6203 6029
6204 sync_pb::EntitySpecifics specifics; 6030 sync_pb::EntitySpecifics specifics;
6205 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 6031 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
6206 ext_specifics->set_id(good_crx); 6032 ext_specifics->set_id(good_crx);
6207 ext_specifics->set_enabled(false); 6033 ext_specifics->set_enabled(false);
6208 ext_specifics->set_incognito_enabled(true); 6034 ext_specifics->set_incognito_enabled(true);
6209 ext_specifics->set_update_url("http://www.google.com/"); 6035 ext_specifics->set_update_url("http://www.google.com/");
6210 ext_specifics->set_version("1.2.3.4"); 6036 ext_specifics->set_version("1.2.3.4");
6211 syncer::SyncData sync_data = 6037 syncer::SyncData sync_data =
6212 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); 6038 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
6213 syncer::SyncChange sync_change(FROM_HERE, 6039 syncer::SyncChange sync_change(FROM_HERE,
6214 syncer::SyncChange::ACTION_UPDATE, 6040 syncer::SyncChange::ACTION_UPDATE,
6215 sync_data); 6041 sync_data);
6216 syncer::SyncChangeList list(1); 6042 syncer::SyncChangeList list(1);
6217 list[0] = sync_change; 6043 list[0] = sync_change;
6218 6044
6219 6045 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
6220 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); 6046 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6221 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); 6047 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6222 extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); 6048 EXPECT_TRUE(service()->updater()->WillCheckSoon());
6223 EXPECT_TRUE(service_->updater()->WillCheckSoon()); 6049 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6224 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 6050 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6225 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get()));
6226 6051
6227 const extensions::PendingExtensionInfo* info; 6052 const extensions::PendingExtensionInfo* info;
6228 EXPECT_TRUE((info = service_->pending_extension_manager()-> 6053 EXPECT_TRUE(
6229 GetById(good_crx))); 6054 (info = service()->pending_extension_manager()->GetById(good_crx)));
6230 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); 6055 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec());
6231 EXPECT_TRUE(info->is_from_sync()); 6056 EXPECT_TRUE(info->is_from_sync());
6232 EXPECT_TRUE(info->install_silently()); 6057 EXPECT_TRUE(info->install_silently());
6233 EXPECT_EQ(Manifest::INTERNAL, info->install_source()); 6058 EXPECT_EQ(Manifest::INTERNAL, info->install_source());
6234 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. 6059 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|.
6235 } 6060 }
6236 6061
6237 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { 6062 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) {
6238 InitializeEmptyExtensionService(); 6063 InitializeEmptyExtensionService();
6239 6064
6240 base::FilePath path = data_dir_.AppendASCII("good.crx"); 6065 base::FilePath path = data_dir().AppendASCII("good.crx");
6241 InstallCRX(path, INSTALL_NEW); 6066 InstallCRX(path, INSTALL_NEW);
6242 ValidatePrefKeyCount(1u); 6067 ValidatePrefKeyCount(1u);
6243 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 6068 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
6244 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 6069 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
6245 6070
6246 extensions::PendingExtensionManager* pending = 6071 extensions::PendingExtensionManager* pending =
6247 service_->pending_extension_manager(); 6072 service()->pending_extension_manager();
6248 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6073 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6249 6074
6250 // Skip install when the location is the same. 6075 // Skip install when the location is the same.
6251 EXPECT_FALSE(service_->OnExternalExtensionUpdateUrlFound(kGoodId, 6076 EXPECT_FALSE(
6252 std::string(), 6077 service()->OnExternalExtensionUpdateUrlFound(kGoodId,
6253 GURL(kGoodUpdateURL), 6078 std::string(),
6254 Manifest::INTERNAL, 6079 GURL(kGoodUpdateURL),
6255 Extension::NO_FLAGS, 6080 Manifest::INTERNAL,
6256 false)); 6081 Extension::NO_FLAGS,
6082 false));
6257 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6083 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6258 6084
6259 // Install when the location has higher priority. 6085 // Install when the location has higher priority.
6260 EXPECT_TRUE(service_->OnExternalExtensionUpdateUrlFound( 6086 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(
6261 kGoodId, 6087 kGoodId,
6262 std::string(), 6088 std::string(),
6263 GURL(kGoodUpdateURL), 6089 GURL(kGoodUpdateURL),
6264 Manifest::EXTERNAL_POLICY_DOWNLOAD, 6090 Manifest::EXTERNAL_POLICY_DOWNLOAD,
6265 Extension::NO_FLAGS, 6091 Extension::NO_FLAGS,
6266 false)); 6092 false));
6267 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6093 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6268 6094
6269 // Try the low priority again. Should be rejected. 6095 // Try the low priority again. Should be rejected.
6270 EXPECT_FALSE(service_->OnExternalExtensionUpdateUrlFound( 6096 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(
6271 kGoodId, 6097 kGoodId,
6272 std::string(), 6098 std::string(),
6273 GURL(kGoodUpdateURL), 6099 GURL(kGoodUpdateURL),
6274 Manifest::EXTERNAL_PREF_DOWNLOAD, 6100 Manifest::EXTERNAL_PREF_DOWNLOAD,
6275 Extension::NO_FLAGS, 6101 Extension::NO_FLAGS,
6276 false)); 6102 false));
6277 // The existing record should still be present in the pending extension 6103 // The existing record should still be present in the pending extension
6278 // manager. 6104 // manager.
6279 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6105 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6280 6106
6281 pending->Remove(kGoodId); 6107 pending->Remove(kGoodId);
6282 6108
6283 // Skip install when the location has the same priority as the installed 6109 // Skip install when the location has the same priority as the installed
6284 // location. 6110 // location.
6285 EXPECT_FALSE(service_->OnExternalExtensionUpdateUrlFound(kGoodId, 6111 EXPECT_FALSE(
6286 std::string(), 6112 service()->OnExternalExtensionUpdateUrlFound(kGoodId,
6287 GURL(kGoodUpdateURL), 6113 std::string(),
6288 Manifest::INTERNAL, 6114 GURL(kGoodUpdateURL),
6289 Extension::NO_FLAGS, 6115 Manifest::INTERNAL,
6290 false)); 6116 Extension::NO_FLAGS,
6117 false));
6291 6118
6292 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6119 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6293 } 6120 }
6294 6121
6295 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { 6122 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) {
6296 Version older_version("0.1.0.0"); 6123 Version older_version("0.1.0.0");
6297 Version newer_version("2.0.0.0"); 6124 Version newer_version("2.0.0.0");
6298 6125
6299 // We don't want the extension to be installed. A path that doesn't 6126 // We don't want the extension to be installed. A path that doesn't
6300 // point to a valid CRX ensures this. 6127 // point to a valid CRX ensures this.
(...skipping 13 matching lines...) Expand all
6314 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, 6141 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY,
6315 Manifest::EXTERNAL_PREF)); 6142 Manifest::EXTERNAL_PREF));
6316 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, 6143 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY,
6317 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, 6144 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY,
6318 Manifest::INTERNAL)); 6145 Manifest::INTERNAL));
6319 ASSERT_EQ(Manifest::EXTERNAL_PREF, 6146 ASSERT_EQ(Manifest::EXTERNAL_PREF,
6320 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, 6147 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF,
6321 Manifest::INTERNAL)); 6148 Manifest::INTERNAL));
6322 6149
6323 extensions::PendingExtensionManager* pending = 6150 extensions::PendingExtensionManager* pending =
6324 service_->pending_extension_manager(); 6151 service()->pending_extension_manager();
6325 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6152 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6326 6153
6327 { 6154 {
6328 // Simulate an external source adding the extension as INTERNAL. 6155 // Simulate an external source adding the extension as INTERNAL.
6329 content::WindowedNotificationObserver observer( 6156 content::WindowedNotificationObserver observer(
6330 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6157 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6331 content::NotificationService::AllSources()); 6158 content::NotificationService::AllSources());
6332 EXPECT_TRUE( 6159 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6333 service_->OnExternalExtensionFileFound( 6160 &older_version,
6334 kGoodId, &older_version, kInvalidPathToCrx, 6161 kInvalidPathToCrx,
6335 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 6162 Manifest::INTERNAL,
6163 kCreationFlags,
6164 kDontMarkAcknowledged));
6336 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6165 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6337 observer.Wait(); 6166 observer.Wait();
6338 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); 6167 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6339 } 6168 }
6340 6169
6341 { 6170 {
6342 // Simulate an external source adding the extension as EXTERNAL_PREF. 6171 // Simulate an external source adding the extension as EXTERNAL_PREF.
6343 content::WindowedNotificationObserver observer( 6172 content::WindowedNotificationObserver observer(
6344 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6173 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6345 content::NotificationService::AllSources()); 6174 content::NotificationService::AllSources());
6346 EXPECT_TRUE( 6175 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6347 service_->OnExternalExtensionFileFound( 6176 &older_version,
6348 kGoodId, &older_version, kInvalidPathToCrx, 6177 kInvalidPathToCrx,
6349 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6178 Manifest::EXTERNAL_PREF,
6179 kCreationFlags,
6180 kDontMarkAcknowledged));
6350 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6181 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6351 observer.Wait(); 6182 observer.Wait();
6352 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); 6183 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6353 } 6184 }
6354 6185
6355 // Simulate an external source adding as EXTERNAL_PREF again. 6186 // Simulate an external source adding as EXTERNAL_PREF again.
6356 // This is rejected because the version and the location are the same as 6187 // This is rejected because the version and the location are the same as
6357 // the previous installation, which is still pending. 6188 // the previous installation, which is still pending.
6358 EXPECT_FALSE( 6189 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6359 service_->OnExternalExtensionFileFound( 6190 &older_version,
6360 kGoodId, &older_version, kInvalidPathToCrx, 6191 kInvalidPathToCrx,
6361 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6192 Manifest::EXTERNAL_PREF,
6193 kCreationFlags,
6194 kDontMarkAcknowledged));
6362 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6195 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6363 6196
6364 // Try INTERNAL again. Should fail. 6197 // Try INTERNAL again. Should fail.
6365 EXPECT_FALSE( 6198 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6366 service_->OnExternalExtensionFileFound( 6199 &older_version,
6367 kGoodId, &older_version, kInvalidPathToCrx, 6200 kInvalidPathToCrx,
6368 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 6201 Manifest::INTERNAL,
6202 kCreationFlags,
6203 kDontMarkAcknowledged));
6369 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6204 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6370 6205
6371 { 6206 {
6372 // Now the registry adds the extension. 6207 // Now the registry adds the extension.
6373 content::WindowedNotificationObserver observer( 6208 content::WindowedNotificationObserver observer(
6374 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6209 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6375 content::NotificationService::AllSources()); 6210 content::NotificationService::AllSources());
6376 EXPECT_TRUE( 6211 EXPECT_TRUE(
6377 service_->OnExternalExtensionFileFound(kGoodId, 6212 service()->OnExternalExtensionFileFound(kGoodId,
6378 &older_version, 6213 &older_version,
6379 kInvalidPathToCrx, 6214 kInvalidPathToCrx,
6380 Manifest::EXTERNAL_REGISTRY, 6215 Manifest::EXTERNAL_REGISTRY,
6381 kCreationFlags, 6216 kCreationFlags,
6382 kDontMarkAcknowledged)); 6217 kDontMarkAcknowledged));
6383 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6218 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6384 observer.Wait(); 6219 observer.Wait();
6385 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); 6220 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6386 } 6221 }
6387 6222
6388 // Registry outranks both external pref and internal, so both fail. 6223 // Registry outranks both external pref and internal, so both fail.
6389 EXPECT_FALSE( 6224 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6390 service_->OnExternalExtensionFileFound( 6225 &older_version,
6391 kGoodId, &older_version, kInvalidPathToCrx, 6226 kInvalidPathToCrx,
6392 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6227 Manifest::EXTERNAL_PREF,
6228 kCreationFlags,
6229 kDontMarkAcknowledged));
6393 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6230 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6394 6231
6395 EXPECT_FALSE( 6232 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6396 service_->OnExternalExtensionFileFound( 6233 &older_version,
6397 kGoodId, &older_version, kInvalidPathToCrx, 6234 kInvalidPathToCrx,
6398 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 6235 Manifest::INTERNAL,
6236 kCreationFlags,
6237 kDontMarkAcknowledged));
6399 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6238 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6400 6239
6401 pending->Remove(kGoodId); 6240 pending->Remove(kGoodId);
6402 6241
6403 // Install the extension. 6242 // Install the extension.
6404 base::FilePath path = data_dir_.AppendASCII("good.crx"); 6243 base::FilePath path = data_dir().AppendASCII("good.crx");
6405 const Extension* ext = InstallCRX(path, INSTALL_NEW); 6244 const Extension* ext = InstallCRX(path, INSTALL_NEW);
6406 ValidatePrefKeyCount(1u); 6245 ValidatePrefKeyCount(1u);
6407 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 6246 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
6408 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 6247 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
6409 6248
6410 // Now test the logic of OnExternalExtensionFileFound() when the extension 6249 // Now test the logic of OnExternalExtensionFileFound() when the extension
6411 // being added is already installed. 6250 // being added is already installed.
6412 6251
6413 // Tests assume |older_version| is less than the installed version, and 6252 // Tests assume |older_version| is less than the installed version, and
6414 // |newer_version| is greater. Verify this: 6253 // |newer_version| is greater. Verify this:
6415 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString())); 6254 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString()));
6416 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString())); 6255 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString()));
6417 6256
6418 // An external install for the same location should fail if the version is 6257 // An external install for the same location should fail if the version is
6419 // older, or the same, and succeed if the version is newer. 6258 // older, or the same, and succeed if the version is newer.
6420 6259
6421 // Older than the installed version... 6260 // Older than the installed version...
6422 EXPECT_FALSE( 6261 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6423 service_->OnExternalExtensionFileFound( 6262 &older_version,
6424 kGoodId, &older_version, kInvalidPathToCrx, 6263 kInvalidPathToCrx,
6425 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 6264 Manifest::INTERNAL,
6265 kCreationFlags,
6266 kDontMarkAcknowledged));
6426 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6267 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6427 6268
6428 // Same version as the installed version... 6269 // Same version as the installed version...
6429 EXPECT_FALSE( 6270 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6430 service_->OnExternalExtensionFileFound( 6271 ext->version(),
6431 kGoodId, ext->version(), kInvalidPathToCrx, 6272 kInvalidPathToCrx,
6432 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 6273 Manifest::INTERNAL,
6274 kCreationFlags,
6275 kDontMarkAcknowledged));
6433 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6276 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6434 6277
6435 // Newer than the installed version... 6278 // Newer than the installed version...
6436 EXPECT_TRUE( 6279 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6437 service_->OnExternalExtensionFileFound( 6280 &newer_version,
6438 kGoodId, &newer_version, kInvalidPathToCrx, 6281 kInvalidPathToCrx,
6439 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 6282 Manifest::INTERNAL,
6283 kCreationFlags,
6284 kDontMarkAcknowledged));
6440 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6285 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6441 6286
6442 // An external install for a higher priority install source should succeed 6287 // An external install for a higher priority install source should succeed
6443 // if the version is greater. |older_version| is not... 6288 // if the version is greater. |older_version| is not...
6444 EXPECT_FALSE( 6289 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6445 service_->OnExternalExtensionFileFound( 6290 &older_version,
6446 kGoodId, &older_version, kInvalidPathToCrx, 6291 kInvalidPathToCrx,
6447 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6292 Manifest::EXTERNAL_PREF,
6293 kCreationFlags,
6294 kDontMarkAcknowledged));
6448 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6295 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6449 6296
6450 // |newer_version| is newer. 6297 // |newer_version| is newer.
6451 EXPECT_TRUE( 6298 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6452 service_->OnExternalExtensionFileFound( 6299 &newer_version,
6453 kGoodId, &newer_version, kInvalidPathToCrx, 6300 kInvalidPathToCrx,
6454 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6301 Manifest::EXTERNAL_PREF,
6302 kCreationFlags,
6303 kDontMarkAcknowledged));
6455 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6304 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6456 6305
6457 // An external install for an even higher priority install source should 6306 // An external install for an even higher priority install source should
6458 // succeed if the version is greater. 6307 // succeed if the version is greater.
6459 EXPECT_TRUE( 6308 EXPECT_TRUE(
6460 service_->OnExternalExtensionFileFound( 6309 service()->OnExternalExtensionFileFound(kGoodId,
6461 kGoodId, &newer_version, kInvalidPathToCrx, 6310 &newer_version,
6462 Manifest::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); 6311 kInvalidPathToCrx,
6312 Manifest::EXTERNAL_REGISTRY,
6313 kCreationFlags,
6314 kDontMarkAcknowledged));
6463 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6315 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6464 6316
6465 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, 6317 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY,
6466 // adding from external pref will now fail. 6318 // adding from external pref will now fail.
6467 EXPECT_FALSE( 6319 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6468 service_->OnExternalExtensionFileFound( 6320 &newer_version,
6469 kGoodId, &newer_version, kInvalidPathToCrx, 6321 kInvalidPathToCrx,
6470 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6322 Manifest::EXTERNAL_PREF,
6323 kCreationFlags,
6324 kDontMarkAcknowledged));
6471 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6325 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6472 } 6326 }
6473 6327
6474 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { 6328 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) {
6475 Version kVersion123("1.2.3"); 6329 Version kVersion123("1.2.3");
6476 Version kVersion124("1.2.4"); 6330 Version kVersion124("1.2.4");
6477 Version kVersion125("1.2.5"); 6331 Version kVersion125("1.2.5");
6478 const base::FilePath kInvalidPathToCrx = base::FilePath(); 6332 const base::FilePath kInvalidPathToCrx = base::FilePath();
6479 const int kCreationFlags = 0; 6333 const int kCreationFlags = 0;
6480 const bool kDontMarkAcknowledged = false; 6334 const bool kDontMarkAcknowledged = false;
6481 6335
6482 InitializeEmptyExtensionService(); 6336 InitializeEmptyExtensionService();
6483 6337
6484 extensions::PendingExtensionManager* pending = 6338 extensions::PendingExtensionManager* pending =
6485 service_->pending_extension_manager(); 6339 service()->pending_extension_manager();
6486 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6340 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6487 6341
6488 // An external provider starts installing from a local crx. 6342 // An external provider starts installing from a local crx.
6489 EXPECT_TRUE( 6343 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6490 service_->OnExternalExtensionFileFound( 6344 &kVersion123,
6491 kGoodId, &kVersion123, kInvalidPathToCrx, 6345 kInvalidPathToCrx,
6492 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6346 Manifest::EXTERNAL_PREF,
6347 kCreationFlags,
6348 kDontMarkAcknowledged));
6493 const extensions::PendingExtensionInfo* info; 6349 const extensions::PendingExtensionInfo* info;
6494 EXPECT_TRUE((info = pending->GetById(kGoodId))); 6350 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6495 EXPECT_TRUE(info->version().IsValid()); 6351 EXPECT_TRUE(info->version().IsValid());
6496 EXPECT_TRUE(info->version().Equals(kVersion123)); 6352 EXPECT_TRUE(info->version().Equals(kVersion123));
6497 6353
6498 // Adding a newer version overrides the currently pending version. 6354 // Adding a newer version overrides the currently pending version.
6499 EXPECT_TRUE( 6355 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6500 service_->OnExternalExtensionFileFound( 6356 &kVersion124,
6501 kGoodId, &kVersion124, kInvalidPathToCrx, 6357 kInvalidPathToCrx,
6502 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6358 Manifest::EXTERNAL_PREF,
6359 kCreationFlags,
6360 kDontMarkAcknowledged));
6503 EXPECT_TRUE((info = pending->GetById(kGoodId))); 6361 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6504 EXPECT_TRUE(info->version().IsValid()); 6362 EXPECT_TRUE(info->version().IsValid());
6505 EXPECT_TRUE(info->version().Equals(kVersion124)); 6363 EXPECT_TRUE(info->version().Equals(kVersion124));
6506 6364
6507 // Adding an older version fails. 6365 // Adding an older version fails.
6508 EXPECT_FALSE( 6366 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6509 service_->OnExternalExtensionFileFound( 6367 &kVersion123,
6510 kGoodId, &kVersion123, kInvalidPathToCrx, 6368 kInvalidPathToCrx,
6511 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 6369 Manifest::EXTERNAL_PREF,
6370 kCreationFlags,
6371 kDontMarkAcknowledged));
6512 EXPECT_TRUE((info = pending->GetById(kGoodId))); 6372 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6513 EXPECT_TRUE(info->version().IsValid()); 6373 EXPECT_TRUE(info->version().IsValid());
6514 EXPECT_TRUE(info->version().Equals(kVersion124)); 6374 EXPECT_TRUE(info->version().Equals(kVersion124));
6515 6375
6516 // Adding an older version fails even when coming from a higher-priority 6376 // Adding an older version fails even when coming from a higher-priority
6517 // location. 6377 // location.
6518 EXPECT_FALSE( 6378 EXPECT_FALSE(
6519 service_->OnExternalExtensionFileFound( 6379 service()->OnExternalExtensionFileFound(kGoodId,
6520 kGoodId, &kVersion123, kInvalidPathToCrx, 6380 &kVersion123,
6521 Manifest::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); 6381 kInvalidPathToCrx,
6382 Manifest::EXTERNAL_REGISTRY,
6383 kCreationFlags,
6384 kDontMarkAcknowledged));
6522 EXPECT_TRUE((info = pending->GetById(kGoodId))); 6385 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6523 EXPECT_TRUE(info->version().IsValid()); 6386 EXPECT_TRUE(info->version().IsValid());
6524 EXPECT_TRUE(info->version().Equals(kVersion124)); 6387 EXPECT_TRUE(info->version().Equals(kVersion124));
6525 6388
6526 // Adding the latest version from the webstore overrides a specific version. 6389 // Adding the latest version from the webstore overrides a specific version.
6527 GURL kUpdateUrl("http://example.com/update"); 6390 GURL kUpdateUrl("http://example.com/update");
6528 EXPECT_TRUE(service_->OnExternalExtensionUpdateUrlFound( 6391 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(
6529 kGoodId, 6392 kGoodId,
6530 std::string(), 6393 std::string(),
6531 kUpdateUrl, 6394 kUpdateUrl,
6532 Manifest::EXTERNAL_POLICY_DOWNLOAD, 6395 Manifest::EXTERNAL_POLICY_DOWNLOAD,
6533 Extension::NO_FLAGS, 6396 Extension::NO_FLAGS,
6534 false)); 6397 false));
6535 EXPECT_TRUE((info = pending->GetById(kGoodId))); 6398 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6536 EXPECT_FALSE(info->version().IsValid()); 6399 EXPECT_FALSE(info->version().IsValid());
6537 } 6400 }
6538 6401
6539 // This makes sure we can package and install CRX files that use whitelisted 6402 // This makes sure we can package and install CRX files that use whitelisted
6540 // permissions. 6403 // permissions.
6541 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { 6404 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) {
6542 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; 6405 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk";
6543 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 6406 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
6544 extensions::switches::kWhitelistedExtensionID, test_id); 6407 extensions::switches::kWhitelistedExtensionID, test_id);
6545 6408
6546 InitializeEmptyExtensionService(); 6409 InitializeEmptyExtensionService();
6547 base::FilePath path = data_dir_ 6410 base::FilePath path = data_dir().AppendASCII("permissions");
6548 .AppendASCII("permissions");
6549 base::FilePath pem_path = path 6411 base::FilePath pem_path = path
6550 .AppendASCII("whitelist.pem"); 6412 .AppendASCII("whitelist.pem");
6551 path = path 6413 path = path
6552 .AppendASCII("whitelist"); 6414 .AppendASCII("whitelist");
6553 6415
6554 const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); 6416 const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW);
6555 EXPECT_EQ(0u, GetErrors().size()); 6417 EXPECT_EQ(0u, GetErrors().size());
6556 ASSERT_EQ(1u, registry_->enabled_extensions().size()); 6418 ASSERT_EQ(1u, registry()->enabled_extensions().size());
6557 EXPECT_EQ(test_id, extension->id()); 6419 EXPECT_EQ(test_id, extension->id());
6558 } 6420 }
6559 6421
6560 // Test that when multiple sources try to install an extension, 6422 // Test that when multiple sources try to install an extension,
6561 // we consistently choose the right one. To make tests easy to read, 6423 // we consistently choose the right one. To make tests easy to read,
6562 // methods that fake requests to install crx files in several ways 6424 // methods that fake requests to install crx files in several ways
6563 // are provided. 6425 // are provided.
6564 class ExtensionSourcePriorityTest : public ExtensionServiceTest { 6426 class ExtensionSourcePriorityTest : public ExtensionServiceTest {
6565 public: 6427 public:
6566 virtual void SetUp() { 6428 virtual void SetUp() {
6567 ExtensionServiceTest::SetUp(); 6429 ExtensionServiceTest::SetUp();
6568 6430
6569 // All tests use a single extension. Put the id and path in member vars 6431 // All tests use a single extension. Put the id and path in member vars
6570 // that all methods can read. 6432 // that all methods can read.
6571 crx_id_ = kGoodId; 6433 crx_id_ = kGoodId;
6572 crx_path_ = data_dir_.AppendASCII("good.crx"); 6434 crx_path_ = data_dir().AppendASCII("good.crx");
6573 } 6435 }
6574 6436
6575 // Fake an external source adding a URL to fetch an extension from. 6437 // Fake an external source adding a URL to fetch an extension from.
6576 bool AddPendingExternalPrefUrl() { 6438 bool AddPendingExternalPrefUrl() {
6577 return service_->pending_extension_manager()->AddFromExternalUpdateUrl( 6439 return service()->pending_extension_manager()->AddFromExternalUpdateUrl(
6578 crx_id_, 6440 crx_id_,
6579 std::string(), 6441 std::string(),
6580 GURL(), 6442 GURL(),
6581 Manifest::EXTERNAL_PREF_DOWNLOAD, 6443 Manifest::EXTERNAL_PREF_DOWNLOAD,
6582 Extension::NO_FLAGS, 6444 Extension::NO_FLAGS,
6583 false); 6445 false);
6584 } 6446 }
6585 6447
6586 // Fake an external file from external_extensions.json. 6448 // Fake an external file from external_extensions.json.
6587 bool AddPendingExternalPrefFileInstall() { 6449 bool AddPendingExternalPrefFileInstall() {
6588 Version version("1.0.0.0"); 6450 Version version("1.0.0.0");
6589 6451
6590 return service_->OnExternalExtensionFileFound( 6452 return service()->OnExternalExtensionFileFound(crx_id_,
6591 crx_id_, &version, crx_path_, Manifest::EXTERNAL_PREF, 6453 &version,
6592 Extension::NO_FLAGS, false); 6454 crx_path_,
6455 Manifest::EXTERNAL_PREF,
6456 Extension::NO_FLAGS,
6457 false);
6593 } 6458 }
6594 6459
6595 // Fake a request from sync to install an extension. 6460 // Fake a request from sync to install an extension.
6596 bool AddPendingSyncInstall() { 6461 bool AddPendingSyncInstall() {
6597 return service_->pending_extension_manager()->AddFromSync( 6462 return service()->pending_extension_manager()->AddFromSync(
6598 crx_id_, 6463 crx_id_,
6599 GURL(kGoodUpdateURL), 6464 GURL(kGoodUpdateURL),
6600 &IsExtension, 6465 &IsExtension,
6601 kGoodInstallSilently, 6466 kGoodInstallSilently,
6602 kGoodRemoteInstall); 6467 kGoodRemoteInstall);
6603 } 6468 }
6604 6469
6605 // Fake a policy install. 6470 // Fake a policy install.
6606 bool AddPendingPolicyInstall() { 6471 bool AddPendingPolicyInstall() {
6607 // Get path to the CRX with id |kGoodId|. 6472 // Get path to the CRX with id |kGoodId|.
6608 return service_->OnExternalExtensionUpdateUrlFound( 6473 return service()->OnExternalExtensionUpdateUrlFound(
6609 crx_id_, 6474 crx_id_,
6610 std::string(), 6475 std::string(),
6611 GURL(), 6476 GURL(),
6612 Manifest::EXTERNAL_POLICY_DOWNLOAD, 6477 Manifest::EXTERNAL_POLICY_DOWNLOAD,
6613 Extension::NO_FLAGS, 6478 Extension::NO_FLAGS,
6614 false); 6479 false);
6615 } 6480 }
6616 6481
6617 // Get the install source of a pending extension. 6482 // Get the install source of a pending extension.
6618 Manifest::Location GetPendingLocation() { 6483 Manifest::Location GetPendingLocation() {
6619 const extensions::PendingExtensionInfo* info; 6484 const extensions::PendingExtensionInfo* info;
6620 EXPECT_TRUE((info = service_->pending_extension_manager()-> 6485 EXPECT_TRUE(
6621 GetById(crx_id_))); 6486 (info = service()->pending_extension_manager()->GetById(crx_id_)));
6622 return info->install_source(); 6487 return info->install_source();
6623 } 6488 }
6624 6489
6625 // Is an extension pending from a sync request? 6490 // Is an extension pending from a sync request?
6626 bool GetPendingIsFromSync() { 6491 bool GetPendingIsFromSync() {
6627 const extensions::PendingExtensionInfo* info; 6492 const extensions::PendingExtensionInfo* info;
6628 EXPECT_TRUE((info = service_->pending_extension_manager()-> 6493 EXPECT_TRUE(
6629 GetById(crx_id_))); 6494 (info = service()->pending_extension_manager()->GetById(crx_id_)));
6630 return info->is_from_sync(); 6495 return info->is_from_sync();
6631 } 6496 }
6632 6497
6633 // Is the CRX id these tests use pending? 6498 // Is the CRX id these tests use pending?
6634 bool IsCrxPending() { 6499 bool IsCrxPending() {
6635 return service_->pending_extension_manager()->IsIdPending(crx_id_); 6500 return service()->pending_extension_manager()->IsIdPending(crx_id_);
6636 } 6501 }
6637 6502
6638 // Is an extension installed? 6503 // Is an extension installed?
6639 bool IsCrxInstalled() { 6504 bool IsCrxInstalled() {
6640 return (service_->GetExtensionById(crx_id_, true) != NULL); 6505 return (service()->GetExtensionById(crx_id_, true) != NULL);
6641 } 6506 }
6642 6507
6643 protected: 6508 protected:
6644 // All tests use a single extension. Making the id and path member 6509 // All tests use a single extension. Making the id and path member
6645 // vars avoids pasing the same argument to every method. 6510 // vars avoids pasing the same argument to every method.
6646 std::string crx_id_; 6511 std::string crx_id_;
6647 base::FilePath crx_path_; 6512 base::FilePath crx_path_;
6648 }; 6513 };
6649 6514
6650 // Test that a pending request for installation of an external CRX from 6515 // Test that a pending request for installation of an external CRX from
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
6730 ASSERT_FALSE(AddPendingSyncInstall()); 6595 ASSERT_FALSE(AddPendingSyncInstall());
6731 } 6596 }
6732 6597
6733 // Test that installing an external extension displays a GlobalError. 6598 // Test that installing an external extension displays a GlobalError.
6734 TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) { 6599 TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) {
6735 FeatureSwitch::ScopedOverride prompt( 6600 FeatureSwitch::ScopedOverride prompt(
6736 FeatureSwitch::prompt_for_external_extensions(), true); 6601 FeatureSwitch::prompt_for_external_extensions(), true);
6737 6602
6738 InitializeEmptyExtensionService(); 6603 InitializeEmptyExtensionService();
6739 MockExtensionProvider* provider = 6604 MockExtensionProvider* provider =
6740 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6605 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6741 AddMockExternalProvider(provider); 6606 AddMockExternalProvider(provider);
6742 6607
6743 service_->UpdateExternalExtensionAlert(); 6608 service()->UpdateExternalExtensionAlert();
6744 // Should return false, meaning there aren't any extensions that the user 6609 // Should return false, meaning there aren't any extensions that the user
6745 // needs to know about. 6610 // needs to know about.
6746 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6611 EXPECT_FALSE(extensions::HasExternalInstallError(service()));
6747 6612
6748 // This is a normal extension, installed normally. 6613 // This is a normal extension, installed normally.
6749 // This should NOT trigger an alert. 6614 // This should NOT trigger an alert.
6750 set_extensions_enabled(true); 6615 service()->set_extensions_enabled(true);
6751 base::FilePath path = data_dir_.AppendASCII("good.crx"); 6616 base::FilePath path = data_dir().AppendASCII("good.crx");
6752 InstallCRX(path, INSTALL_NEW); 6617 InstallCRX(path, INSTALL_NEW);
6753 6618
6754 service_->CheckForExternalUpdates(); 6619 service()->CheckForExternalUpdates();
6755 base::RunLoop().RunUntilIdle(); 6620 base::RunLoop().RunUntilIdle();
6756 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6621 EXPECT_FALSE(extensions::HasExternalInstallError(service()));
6757 6622
6758 // A hosted app, installed externally. 6623 // A hosted app, installed externally.
6759 // This should NOT trigger an alert. 6624 // This should NOT trigger an alert.
6760 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 6625 provider->UpdateOrAddExtension(
6761 data_dir_.AppendASCII("hosted_app.crx")); 6626 hosted_app, "1.0.0.0", data_dir().AppendASCII("hosted_app.crx"));
6762 6627
6763 content::WindowedNotificationObserver observer( 6628 content::WindowedNotificationObserver observer(
6764 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6629 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6765 content::NotificationService::AllSources()); 6630 content::NotificationService::AllSources());
6766 service_->CheckForExternalUpdates(); 6631 service()->CheckForExternalUpdates();
6767 observer.Wait(); 6632 observer.Wait();
6768 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6633 EXPECT_FALSE(extensions::HasExternalInstallError(service()));
6769 6634
6770 // Another normal extension, but installed externally. 6635 // Another normal extension, but installed externally.
6771 // This SHOULD trigger an alert. 6636 // This SHOULD trigger an alert.
6772 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 6637 provider->UpdateOrAddExtension(
6773 data_dir_.AppendASCII("page_action.crx")); 6638 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
6774 6639
6775 content::WindowedNotificationObserver observer2( 6640 content::WindowedNotificationObserver observer2(
6776 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6641 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6777 content::NotificationService::AllSources()); 6642 content::NotificationService::AllSources());
6778 service_->CheckForExternalUpdates(); 6643 service()->CheckForExternalUpdates();
6779 observer2.Wait(); 6644 observer2.Wait();
6780 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6645 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6781 } 6646 }
6782 6647
6783 // Test that external extensions are initially disabled, and that enabling 6648 // Test that external extensions are initially disabled, and that enabling
6784 // them clears the prompt. 6649 // them clears the prompt.
6785 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { 6650 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) {
6786 FeatureSwitch::ScopedOverride prompt( 6651 FeatureSwitch::ScopedOverride prompt(
6787 FeatureSwitch::prompt_for_external_extensions(), true); 6652 FeatureSwitch::prompt_for_external_extensions(), true);
6788 6653
6789 InitializeEmptyExtensionService(); 6654 InitializeEmptyExtensionService();
6790 MockExtensionProvider* provider = 6655 MockExtensionProvider* provider =
6791 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6656 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6792 AddMockExternalProvider(provider); 6657 AddMockExternalProvider(provider);
6793 6658
6794 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 6659 provider->UpdateOrAddExtension(
6795 data_dir_.AppendASCII("page_action.crx")); 6660 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
6796 6661
6797 content::WindowedNotificationObserver observer( 6662 content::WindowedNotificationObserver observer(
6798 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6663 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6799 content::NotificationService::AllSources()); 6664 content::NotificationService::AllSources());
6800 service_->CheckForExternalUpdates(); 6665 service()->CheckForExternalUpdates();
6801 observer.Wait(); 6666 observer.Wait();
6802 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6667 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6803 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); 6668 EXPECT_FALSE(service()->IsExtensionEnabled(page_action));
6804 6669
6805 const Extension* extension = 6670 const Extension* extension =
6806 registry_->disabled_extensions().GetByID(page_action); 6671 registry()->disabled_extensions().GetByID(page_action);
6807 EXPECT_TRUE(extension); 6672 EXPECT_TRUE(extension);
6808 EXPECT_EQ(page_action, extension->id()); 6673 EXPECT_EQ(page_action, extension->id());
6809 6674
6810 service_->EnableExtension(page_action); 6675 service()->EnableExtension(page_action);
6811 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6676 EXPECT_FALSE(extensions::HasExternalInstallError(service()));
6812 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); 6677 EXPECT_TRUE(service()->IsExtensionEnabled(page_action));
6813 } 6678 }
6814 6679
6815 // Test that installing multiple external extensions works. 6680 // Test that installing multiple external extensions works.
6816 // Flaky on windows; http://crbug.com/295757 . 6681 // Flaky on windows; http://crbug.com/295757 .
6817 #if defined(OS_WIN) 6682 #if defined(OS_WIN)
6818 #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple 6683 #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple
6819 #else 6684 #else
6820 #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple 6685 #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple
6821 #endif 6686 #endif
6822 TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) { 6687 TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) {
6823 FeatureSwitch::ScopedOverride prompt( 6688 FeatureSwitch::ScopedOverride prompt(
6824 FeatureSwitch::prompt_for_external_extensions(), true); 6689 FeatureSwitch::prompt_for_external_extensions(), true);
6825 6690
6826 InitializeEmptyExtensionService(); 6691 InitializeEmptyExtensionService();
6827 MockExtensionProvider* provider = 6692 MockExtensionProvider* provider =
6828 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6693 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6829 AddMockExternalProvider(provider); 6694 AddMockExternalProvider(provider);
6830 6695
6831 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 6696 provider->UpdateOrAddExtension(
6832 data_dir_.AppendASCII("page_action.crx")); 6697 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
6833 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 6698 provider->UpdateOrAddExtension(
6834 data_dir_.AppendASCII("good.crx")); 6699 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx"));
6835 provider->UpdateOrAddExtension(theme_crx, "2.0", 6700 provider->UpdateOrAddExtension(
6836 data_dir_.AppendASCII("theme.crx")); 6701 theme_crx, "2.0", data_dir().AppendASCII("theme.crx"));
6837 6702
6838 int count = 3; 6703 int count = 3;
6839 content::WindowedNotificationObserver observer( 6704 content::WindowedNotificationObserver observer(
6840 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6705 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6841 base::Bind(&WaitForCountNotificationsCallback, &count)); 6706 base::Bind(&WaitForCountNotificationsCallback, &count));
6842 service_->CheckForExternalUpdates(); 6707 service()->CheckForExternalUpdates();
6843 observer.Wait(); 6708 observer.Wait();
6844 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6709 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6845 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); 6710 EXPECT_FALSE(service()->IsExtensionEnabled(page_action));
6846 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 6711 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6847 EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx)); 6712 EXPECT_FALSE(service()->IsExtensionEnabled(theme_crx));
6848 6713
6849 service_->EnableExtension(page_action); 6714 service()->EnableExtension(page_action);
6850 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6715 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6851 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); 6716 EXPECT_FALSE(extensions::HasExternalInstallBubble(service()));
6852 service_->EnableExtension(theme_crx); 6717 service()->EnableExtension(theme_crx);
6853 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6718 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6854 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); 6719 EXPECT_FALSE(extensions::HasExternalInstallBubble(service()));
6855 service_->EnableExtension(good_crx); 6720 service()->EnableExtension(good_crx);
6856 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6721 EXPECT_FALSE(extensions::HasExternalInstallError(service()));
6857 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); 6722 EXPECT_FALSE(extensions::HasExternalInstallBubble(service()));
6858 } 6723 }
6859 6724
6860 // Test that there is a bubble for external extensions that update 6725 // Test that there is a bubble for external extensions that update
6861 // from the webstore if the profile is not new. 6726 // from the webstore if the profile is not new.
6862 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) { 6727 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) {
6863 FeatureSwitch::ScopedOverride prompt( 6728 FeatureSwitch::ScopedOverride prompt(
6864 FeatureSwitch::prompt_for_external_extensions(), true); 6729 FeatureSwitch::prompt_for_external_extensions(), true);
6865 6730
6866 // This sets up the ExtensionPrefs used by our ExtensionService to be 6731 // This sets up the ExtensionPrefs used by our ExtensionService to be
6867 // post-first run. 6732 // post-first run.
6868 ExtensionServiceInitParams params = CreateDefaultInitParams(); 6733 ExtensionServiceInitParams params = CreateDefaultInitParams();
6869 params.is_first_run = false; 6734 params.is_first_run = false;
6870 InitializeExtensionService(params); 6735 InitializeExtensionService(params);
6871 6736
6872 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); 6737 base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx");
6873 PackCRX(data_dir_.AppendASCII("update_from_webstore"), 6738 PackCRX(data_dir().AppendASCII("update_from_webstore"),
6874 data_dir_.AppendASCII("update_from_webstore.pem"), 6739 data_dir().AppendASCII("update_from_webstore.pem"),
6875 crx_path); 6740 crx_path);
6876 6741
6877 MockExtensionProvider* provider = 6742 MockExtensionProvider* provider =
6878 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6743 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6879 AddMockExternalProvider(provider); 6744 AddMockExternalProvider(provider);
6880 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6745 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
6881 6746
6882 content::WindowedNotificationObserver observer( 6747 content::WindowedNotificationObserver observer(
6883 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6748 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6884 content::NotificationService::AllSources()); 6749 content::NotificationService::AllSources());
6885 service_->CheckForExternalUpdates(); 6750 service()->CheckForExternalUpdates();
6886 observer.Wait(); 6751 observer.Wait();
6887 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6752 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6888 EXPECT_TRUE(extensions::HasExternalInstallBubble(service_)); 6753 EXPECT_TRUE(extensions::HasExternalInstallBubble(service()));
6889 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); 6754 EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore));
6890 } 6755 }
6891 6756
6892 // Test that there is no bubble for external extensions if the profile is new. 6757 // Test that there is no bubble for external extensions if the profile is new.
6893 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) { 6758 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) {
6894 FeatureSwitch::ScopedOverride prompt( 6759 FeatureSwitch::ScopedOverride prompt(
6895 FeatureSwitch::prompt_for_external_extensions(), true); 6760 FeatureSwitch::prompt_for_external_extensions(), true);
6896 6761
6897 InitializeEmptyExtensionService(); 6762 InitializeEmptyExtensionService();
6898 6763
6899 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); 6764 base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx");
6900 PackCRX(data_dir_.AppendASCII("update_from_webstore"), 6765 PackCRX(data_dir().AppendASCII("update_from_webstore"),
6901 data_dir_.AppendASCII("update_from_webstore.pem"), 6766 data_dir().AppendASCII("update_from_webstore.pem"),
6902 crx_path); 6767 crx_path);
6903 6768
6904 MockExtensionProvider* provider = 6769 MockExtensionProvider* provider =
6905 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6770 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6906 AddMockExternalProvider(provider); 6771 AddMockExternalProvider(provider);
6907 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6772 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
6908 6773
6909 content::WindowedNotificationObserver observer( 6774 content::WindowedNotificationObserver observer(
6910 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6775 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6911 content::NotificationService::AllSources()); 6776 content::NotificationService::AllSources());
6912 service_->CheckForExternalUpdates(); 6777 service()->CheckForExternalUpdates();
6913 observer.Wait(); 6778 observer.Wait();
6914 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6779 EXPECT_TRUE(extensions::HasExternalInstallError(service()));
6915 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); 6780 EXPECT_FALSE(extensions::HasExternalInstallBubble(service()));
6916 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); 6781 EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore));
6917 } 6782 }
6918 6783
6919 TEST_F(ExtensionServiceTest, InstallBlacklistedExtension) { 6784 TEST_F(ExtensionServiceTest, InstallBlacklistedExtension) {
6920 InitializeEmptyExtensionService(); 6785 InitializeEmptyExtensionService();
6921 6786
6922 scoped_refptr<Extension> extension = extensions::ExtensionBuilder() 6787 scoped_refptr<Extension> extension = extensions::ExtensionBuilder()
6923 .SetManifest(extensions::DictionaryBuilder() 6788 .SetManifest(extensions::DictionaryBuilder()
6924 .Set("name", "extension") 6789 .Set("name", "extension")
6925 .Set("version", "1.0") 6790 .Set("version", "1.0")
6926 .Set("manifest_version", 2).Build()) 6791 .Set("manifest_version", 2).Build())
6927 .Build(); 6792 .Build();
6928 ASSERT_TRUE(extension.get()); 6793 ASSERT_TRUE(extension.get());
6929 const std::string& id = extension->id(); 6794 const std::string& id = extension->id();
6930 6795
6931 std::set<std::string> id_set; 6796 std::set<std::string> id_set;
6932 id_set.insert(id); 6797 id_set.insert(id);
6933 extensions::ExtensionNotificationObserver notifications( 6798 extensions::ExtensionNotificationObserver notifications(
6934 content::NotificationService::AllSources(), id_set); 6799 content::NotificationService::AllSources(), id_set);
6935 6800
6936 // Installation should be allowed but the extension should never have been 6801 // Installation should be allowed but the extension should never have been
6937 // loaded and it should be blacklisted in prefs. 6802 // loaded and it should be blacklisted in prefs.
6938 service_->OnExtensionInstalled( 6803 service()->OnExtensionInstalled(extension.get(),
6939 extension.get(), 6804 syncer::StringOrdinal(),
6940 syncer::StringOrdinal(), 6805 false /* has requirement errors */,
6941 false /* has requirement errors */, 6806 extensions::BLACKLISTED_MALWARE,
6942 extensions::BLACKLISTED_MALWARE, 6807 false /* is ephemeral */,
6943 false /* is ephemeral */, 6808 false /* wait for idle */);
6944 false /* wait for idle */);
6945 base::RunLoop().RunUntilIdle(); 6809 base::RunLoop().RunUntilIdle();
6946 6810
6947 // Extension was installed but not loaded. 6811 // Extension was installed but not loaded.
6948 EXPECT_TRUE(notifications.CheckNotifications( 6812 EXPECT_TRUE(notifications.CheckNotifications(
6949 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED)); 6813 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED));
6950 EXPECT_TRUE(service_->GetInstalledExtension(id)); 6814 EXPECT_TRUE(service()->GetInstalledExtension(id));
6951 6815
6952 EXPECT_FALSE(registry_->enabled_extensions().Contains(id)); 6816 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
6953 EXPECT_TRUE(registry_->blacklisted_extensions().Contains(id)); 6817 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(id));
6954 6818
6955 EXPECT_TRUE(ExtensionPrefs::Get(profile_.get())->IsExtensionBlacklisted(id)); 6819 EXPECT_TRUE(ExtensionPrefs::Get(profile())->IsExtensionBlacklisted(id));
6956 EXPECT_TRUE(ExtensionPrefs::Get(profile_.get()) 6820 EXPECT_TRUE(
6957 ->IsBlacklistedExtensionAcknowledged(id)); 6821 ExtensionPrefs::Get(profile())->IsBlacklistedExtensionAcknowledged(id));
6958 } 6822 }
6959 6823
6960 TEST_F(ExtensionServiceTest, ReconcileKnownDisabledNoneDisabled) { 6824 TEST_F(ExtensionServiceTest, ReconcileKnownDisabledNoneDisabled) {
6961 // A profile with 3 extensions installed: good0, good1, and good2. 6825 // A profile with 3 extensions installed: good0, good1, and good2.
6962 InitializeGoodInstalledExtensionService(); 6826 InitializeGoodInstalledExtensionService();
6963 6827
6964 // Initializing shouldn't disable any extensions if none are known to be 6828 // Initializing shouldn't disable any extensions if none are known to be
6965 // disabled. 6829 // disabled.
6966 service_->Init(); 6830 service()->Init();
6967 6831
6968 extensions::ExtensionIdSet expected_extensions; 6832 extensions::ExtensionIdSet expected_extensions;
6969 expected_extensions.insert(good0); 6833 expected_extensions.insert(good0);
6970 expected_extensions.insert(good1); 6834 expected_extensions.insert(good1);
6971 expected_extensions.insert(good2); 6835 expected_extensions.insert(good2);
6972 6836
6973 extensions::ExtensionIdSet expected_disabled_extensions; 6837 extensions::ExtensionIdSet expected_disabled_extensions;
6974 6838
6975 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs()); 6839 EXPECT_EQ(expected_extensions, registry()->enabled_extensions().GetIDs());
6976 EXPECT_EQ(expected_disabled_extensions, 6840 EXPECT_EQ(expected_disabled_extensions,
6977 registry_->disabled_extensions().GetIDs()); 6841 registry()->disabled_extensions().GetIDs());
6978 } 6842 }
6979 6843
6980 TEST_F(ExtensionServiceTest, ReconcileKnownDisabledWithSideEnable) { 6844 TEST_F(ExtensionServiceTest, ReconcileKnownDisabledWithSideEnable) {
6981 // A profile with 3 extensions installed: good0, good1, and good2. 6845 // A profile with 3 extensions installed: good0, good1, and good2.
6982 InitializeGoodInstalledExtensionService(); 6846 InitializeGoodInstalledExtensionService();
6983 6847
6984 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_.get()); 6848 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile());
6985 6849
6986 // Disable good1. 6850 // Disable good1.
6987 extension_prefs->SetExtensionState(good1, Extension::DISABLED); 6851 extension_prefs->SetExtensionState(good1, Extension::DISABLED);
6988 6852
6989 // Mark both good1 and good2 as "known_disabled" (effectively making good2 6853 // Mark both good1 and good2 as "known_disabled" (effectively making good2
6990 // look as if it had been side-enabled). 6854 // look as if it had been side-enabled).
6991 extensions::ExtensionIdSet known_disabled; 6855 extensions::ExtensionIdSet known_disabled;
6992 known_disabled.insert(good1); 6856 known_disabled.insert(good1);
6993 known_disabled.insert(good2); 6857 known_disabled.insert(good2);
6994 extension_prefs->SetKnownDisabled(known_disabled); 6858 extension_prefs->SetKnownDisabled(known_disabled);
6995 6859
6996 // Initialize the service (which should disable good2 since it's known to be 6860 // Initialize the service (which should disable good2 since it's known to be
6997 // disabled). 6861 // disabled).
6998 service_->Init(); 6862 service()->Init();
6999 6863
7000 extensions::ExtensionIdSet expected_extensions; 6864 extensions::ExtensionIdSet expected_extensions;
7001 expected_extensions.insert(good0); 6865 expected_extensions.insert(good0);
7002 6866
7003 extensions::ExtensionIdSet expected_disabled_extensions; 6867 extensions::ExtensionIdSet expected_disabled_extensions;
7004 expected_disabled_extensions.insert(good1); 6868 expected_disabled_extensions.insert(good1);
7005 expected_disabled_extensions.insert(good2); 6869 expected_disabled_extensions.insert(good2);
7006 6870
7007 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs()); 6871 EXPECT_EQ(expected_extensions, registry()->enabled_extensions().GetIDs());
7008 EXPECT_EQ(expected_disabled_extensions, 6872 EXPECT_EQ(expected_disabled_extensions,
7009 registry_->disabled_extensions().GetIDs()); 6873 registry()->disabled_extensions().GetIDs());
7010 6874
7011 // Make sure that re-enabling an extension sticks across calls to 6875 // Make sure that re-enabling an extension sticks across calls to
7012 // ReconcileKnownDisabled(). 6876 // ReconcileKnownDisabled().
7013 service_->EnableExtension(good2); 6877 service()->EnableExtension(good2);
7014 service_->ReconcileKnownDisabled(); 6878 service()->ReconcileKnownDisabled();
7015 expected_extensions.insert(good2); 6879 expected_extensions.insert(good2);
7016 expected_disabled_extensions.erase(good2); 6880 expected_disabled_extensions.erase(good2);
7017 6881
7018 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs()); 6882 EXPECT_EQ(expected_extensions, registry()->enabled_extensions().GetIDs());
7019 EXPECT_EQ(expected_disabled_extensions, 6883 EXPECT_EQ(expected_disabled_extensions,
7020 registry_->disabled_extensions().GetIDs()); 6884 registry()->disabled_extensions().GetIDs());
7021 } 6885 }
7022 6886
7023 // Tests a profile being destroyed correctly disables extensions. 6887 // Tests a profile being destroyed correctly disables extensions.
7024 TEST_F(ExtensionServiceTest, DestroyingProfileClearsExtensions) { 6888 TEST_F(ExtensionServiceTest, DestroyingProfileClearsExtensions) {
7025 InitializeEmptyExtensionService(); 6889 InitializeEmptyExtensionService();
7026 6890
7027 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 6891 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
7028 EXPECT_NE(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 6892 EXPECT_NE(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
7029 EXPECT_EQ(1u, registry_->enabled_extensions().size()); 6893 EXPECT_EQ(1u, registry()->enabled_extensions().size());
7030 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 6894 EXPECT_EQ(0u, registry()->disabled_extensions().size());
7031 EXPECT_EQ(0u, registry_->terminated_extensions().size()); 6895 EXPECT_EQ(0u, registry()->terminated_extensions().size());
7032 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 6896 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
7033 6897
7034 service_->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 6898 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
7035 content::Source<Profile>(profile_.get()), 6899 content::Source<Profile>(profile()),
7036 content::NotificationService::NoDetails()); 6900 content::NotificationService::NoDetails());
7037 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 6901 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
7038 EXPECT_EQ(0u, registry_->enabled_extensions().size()); 6902 EXPECT_EQ(0u, registry()->enabled_extensions().size());
7039 EXPECT_EQ(0u, registry_->disabled_extensions().size()); 6903 EXPECT_EQ(0u, registry()->disabled_extensions().size());
7040 EXPECT_EQ(0u, registry_->terminated_extensions().size()); 6904 EXPECT_EQ(0u, registry()->terminated_extensions().size());
7041 EXPECT_EQ(0u, registry_->blacklisted_extensions().size()); 6905 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
7042 } 6906 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698