| 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" | |
| 34 #include "chrome/browser/extensions/extension_creator.h" | 33 #include "chrome/browser/extensions/extension_creator.h" |
| 35 #include "chrome/browser/extensions/extension_error_reporter.h" | 34 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 36 #include "chrome/browser/extensions/extension_error_ui.h" | 35 #include "chrome/browser/extensions/extension_error_ui.h" |
| 37 #include "chrome/browser/extensions/extension_service.h" | 36 #include "chrome/browser/extensions/extension_service.h" |
| 38 #include "chrome/browser/extensions/extension_sorting.h" | 37 #include "chrome/browser/extensions/extension_sorting.h" |
| 39 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 38 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 40 #include "chrome/browser/extensions/extension_sync_data.h" | 39 #include "chrome/browser/extensions/extension_sync_data.h" |
| 41 #include "chrome/browser/extensions/extension_system.h" | 40 #include "chrome/browser/extensions/extension_system.h" |
| 42 #include "chrome/browser/extensions/external_pref_loader.h" | 41 #include "chrome/browser/extensions/external_pref_loader.h" |
| 43 #include "chrome/browser/extensions/external_provider_impl.h" | 42 #include "chrome/browser/extensions/external_provider_impl.h" |
| (...skipping 3780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3824 InitializeEmptyExtensionService(); | 3823 InitializeEmptyExtensionService(); |
| 3825 | 3824 |
| 3826 // Now add providers. Extension system takes ownership of the objects. | 3825 // Now add providers. Extension system takes ownership of the objects. |
| 3827 MockExtensionProvider* pref_provider = | 3826 MockExtensionProvider* pref_provider = |
| 3828 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 3827 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); |
| 3829 | 3828 |
| 3830 AddMockExternalProvider(pref_provider); | 3829 AddMockExternalProvider(pref_provider); |
| 3831 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF); | 3830 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF); |
| 3832 } | 3831 } |
| 3833 | 3832 |
| 3834 #if !defined(OS_CHROMEOS) | |
| 3835 // Chrome OS has different way of installing default apps. | |
| 3836 TEST_F(ExtensionServiceTest, DefaultAppsInstall) { | |
| 3837 scoped_ptr<TestingProfile> profile(new TestingProfile()); | |
| 3838 | |
| 3839 // The default apps should be installed if kDefaultAppsInstallState | |
| 3840 // is unknown. | |
| 3841 EXPECT_TRUE(default_apps::ShouldInstallInProfile(profile.get())); | |
| 3842 int state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState); | |
| 3843 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps); | |
| 3844 | |
| 3845 // The default apps should only be installed once. | |
| 3846 EXPECT_FALSE(default_apps::ShouldInstallInProfile(profile.get())); | |
| 3847 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState); | |
| 3848 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps); | |
| 3849 | |
| 3850 // The default apps should not be installed if the state is | |
| 3851 // kNeverProvideDefaultApps | |
| 3852 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, | |
| 3853 default_apps::kNeverInstallDefaultApps); | |
| 3854 EXPECT_FALSE(default_apps::ShouldInstallInProfile(profile.get())); | |
| 3855 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState); | |
| 3856 EXPECT_TRUE(state == default_apps::kNeverInstallDefaultApps); | |
| 3857 | |
| 3858 // The old default apps with kAlwaysInstallDefaultAppss should be migrated. | |
| 3859 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, | |
| 3860 default_apps::kProvideLegacyDefaultApps); | |
| 3861 EXPECT_TRUE(default_apps::ShouldInstallInProfile(profile.get())); | |
| 3862 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState); | |
| 3863 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps); | |
| 3864 | |
| 3865 class DefaultTestingProfile : public TestingProfile { | |
| 3866 virtual bool WasCreatedByVersionOrLater( | |
| 3867 const std::string& version) OVERRIDE { | |
| 3868 return false; | |
| 3869 } | |
| 3870 }; | |
| 3871 profile.reset(new DefaultTestingProfile); | |
| 3872 // The old default apps with kProvideLegacyDefaultApps should be migrated | |
| 3873 // even if the profile version is older than Chrome version. | |
| 3874 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState, | |
| 3875 default_apps::kProvideLegacyDefaultApps); | |
| 3876 EXPECT_TRUE(default_apps::ShouldInstallInProfile(profile.get())); | |
| 3877 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState); | |
| 3878 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps); | |
| 3879 } | |
| 3880 #endif | |
| 3881 | |
| 3882 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { | 3833 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { |
| 3883 // This should all work, even when normal extension installation is disabled. | 3834 // This should all work, even when normal extension installation is disabled. |
| 3884 InitializeEmptyExtensionService(); | 3835 InitializeEmptyExtensionService(); |
| 3885 set_extensions_enabled(false); | 3836 set_extensions_enabled(false); |
| 3886 | 3837 |
| 3887 // TODO(skerner): The mock provider is not a good model of a provider | 3838 // TODO(skerner): The mock provider is not a good model of a provider |
| 3888 // that works with update URLs, because it adds file and version info. | 3839 // that works with update URLs, because it adds file and version info. |
| 3889 // Extend the mock to work with update URLs. This test checks the | 3840 // Extend the mock to work with update URLs. This test checks the |
| 3890 // behavior that is common to all external extension visitors. The | 3841 // behavior that is common to all external extension visitors. The |
| 3891 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that | 3842 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
| (...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5404 // This should NOT trigger an alert. | 5355 // This should NOT trigger an alert. |
| 5405 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", | 5356 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
| 5406 data_dir_.AppendASCII("hosted_app.crx")); | 5357 data_dir_.AppendASCII("hosted_app.crx")); |
| 5407 | 5358 |
| 5408 service_->CheckForExternalUpdates(); | 5359 service_->CheckForExternalUpdates(); |
| 5409 loop_.RunAllPending(); | 5360 loop_.RunAllPending(); |
| 5410 | 5361 |
| 5411 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); | 5362 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); |
| 5412 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); | 5363 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); |
| 5413 } | 5364 } |
| OLD | NEW |