Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "base/stl_util.h" | 23 #include "base/stl_util.h" |
| 24 #include "base/string16.h" | 24 #include "base/string16.h" |
| 25 #include "base/string_number_conversions.h" | 25 #include "base/string_number_conversions.h" |
| 26 #include "base/string_util.h" | 26 #include "base/string_util.h" |
| 27 #include "base/utf_string_conversions.h" | 27 #include "base/utf_string_conversions.h" |
| 28 #include "base/version.h" | 28 #include "base/version.h" |
| 29 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
| 30 #include "chrome/browser/extensions/app_sync_data.h" | 30 #include "chrome/browser/extensions/app_sync_data.h" |
| 31 #include "chrome/browser/extensions/component_loader.h" | 31 #include "chrome/browser/extensions/component_loader.h" |
| 32 #include "chrome/browser/extensions/crx_installer.h" | 32 #include "chrome/browser/extensions/crx_installer.h" |
| 33 #include "chrome/browser/extensions/default_apps.h" | |
| 33 #include "chrome/browser/extensions/extension_creator.h" | 34 #include "chrome/browser/extensions/extension_creator.h" |
| 34 #include "chrome/browser/extensions/extension_error_reporter.h" | 35 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 35 #include "chrome/browser/extensions/extension_error_ui.h" | 36 #include "chrome/browser/extensions/extension_error_ui.h" |
| 36 #include "chrome/browser/extensions/extension_service.h" | 37 #include "chrome/browser/extensions/extension_service.h" |
| 37 #include "chrome/browser/extensions/extension_sorting.h" | 38 #include "chrome/browser/extensions/extension_sorting.h" |
| 38 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 39 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 39 #include "chrome/browser/extensions/extension_sync_data.h" | 40 #include "chrome/browser/extensions/extension_sync_data.h" |
| 40 #include "chrome/browser/extensions/extension_system.h" | 41 #include "chrome/browser/extensions/extension_system.h" |
| 41 #include "chrome/browser/extensions/external_pref_loader.h" | 42 #include "chrome/browser/extensions/external_pref_loader.h" |
| 42 #include "chrome/browser/extensions/external_provider_impl.h" | 43 #include "chrome/browser/extensions/external_provider_impl.h" |
| (...skipping 3671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3714 InitializeEmptyExtensionService(); | 3715 InitializeEmptyExtensionService(); |
| 3715 | 3716 |
| 3716 // Now add providers. Extension system takes ownership of the objects. | 3717 // Now add providers. Extension system takes ownership of the objects. |
| 3717 MockExtensionProvider* pref_provider = | 3718 MockExtensionProvider* pref_provider = |
| 3718 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 3719 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); |
| 3719 | 3720 |
| 3720 AddMockExternalProvider(pref_provider); | 3721 AddMockExternalProvider(pref_provider); |
| 3721 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF); | 3722 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF); |
| 3722 } | 3723 } |
| 3723 | 3724 |
| 3725 TEST_F(ExtensionServiceTest, DefaultAppsInstall) { | |
| 3726 scoped_ptr<TestingProfile> profile(new TestingProfile()); | |
| 3727 | |
| 3728 // The default apps should be installed if kDefaultAppsInstallState | |
| 3729 // is unknown. | |
| 3730 EXPECT_TRUE(default_apps::ShouldInstallInProfile(profile.get())); | |
| 3731 int state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState); | |
| 3732 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps); | |
| 3733 | |
| 3734 // The default apps should only be installed once. | |
| 3735 EXPECT_FALSE(default_apps::ShouldInstallInProfile(profile.get())); | |
| 3736 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState); | |
| 3737 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps); | |
| 3738 | |
| 3739 // The default apps should not be installed if the state is | |
| 3740 // kNeverProvideDefaultApps | |
| 3741 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, | |
| 3742 default_apps::kNeverInstallDefaultApps); | |
| 3743 EXPECT_FALSE(default_apps::ShouldInstallInProfile(profile.get())); | |
| 3744 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState); | |
| 3745 EXPECT_TRUE(state == default_apps::kNeverInstallDefaultApps); | |
| 3746 | |
| 3747 // The old default apps with kAlwaysInstallDefaultAppss should be migrated. | |
| 3748 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, | |
| 3749 default_apps::kProvideLegacyDefaultApps); | |
| 3750 EXPECT_TRUE(default_apps::ShouldInstallInProfile(profile.get())); | |
| 3751 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState); | |
| 3752 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps); | |
| 3753 | |
| 3754 class DefaultTestingProfile : public TestingProfile { | |
| 3755 bool WasCreatedByVersionOrLater(const std::string& version) { | |
|
Mihai Parparita -not on Chrome
2012/08/21 22:03:56
Seems like this needs virtual and OVERRIDE annotat
| |
| 3756 return false; | |
| 3757 } | |
| 3758 }; | |
| 3759 profile.reset(new DefaultTestingProfile); | |
| 3760 // The old default apps with kProvideLegacyDefaultApps should be migrated | |
| 3761 // even if the profile version is older than Chrome version. | |
| 3762 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, | |
| 3763 default_apps::kProvideLegacyDefaultApps); | |
| 3764 EXPECT_TRUE(default_apps::ShouldInstallInProfile(profile.get())); | |
| 3765 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState); | |
| 3766 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps); | |
| 3767 } | |
| 3768 | |
| 3724 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { | 3769 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { |
| 3725 // This should all work, even when normal extension installation is disabled. | 3770 // This should all work, even when normal extension installation is disabled. |
| 3726 InitializeEmptyExtensionService(); | 3771 InitializeEmptyExtensionService(); |
| 3727 set_extensions_enabled(false); | 3772 set_extensions_enabled(false); |
| 3728 | 3773 |
| 3729 // TODO(skerner): The mock provider is not a good model of a provider | 3774 // TODO(skerner): The mock provider is not a good model of a provider |
| 3730 // that works with update URLs, because it adds file and version info. | 3775 // that works with update URLs, because it adds file and version info. |
| 3731 // Extend the mock to work with update URLs. This test checks the | 3776 // Extend the mock to work with update URLs. This test checks the |
| 3732 // behavior that is common to all external extension visitors. The | 3777 // behavior that is common to all external extension visitors. The |
| 3733 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that | 3778 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
| (...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5246 // This should NOT trigger an alert. | 5291 // This should NOT trigger an alert. |
| 5247 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", | 5292 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
| 5248 data_dir_.AppendASCII("hosted_app.crx")); | 5293 data_dir_.AppendASCII("hosted_app.crx")); |
| 5249 | 5294 |
| 5250 service_->CheckForExternalUpdates(); | 5295 service_->CheckForExternalUpdates(); |
| 5251 loop_.RunAllPending(); | 5296 loop_.RunAllPending(); |
| 5252 | 5297 |
| 5253 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); | 5298 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); |
| 5254 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); | 5299 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); |
| 5255 } | 5300 } |
| OLD | NEW |