| OLD | NEW |
| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 2863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2874 } // namespace | 2874 } // namespace |
| 2875 | 2875 |
| 2876 // Test adding a pending extension. | 2876 // Test adding a pending extension. |
| 2877 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { | 2877 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { |
| 2878 InitializeEmptyExtensionService(); | 2878 InitializeEmptyExtensionService(); |
| 2879 | 2879 |
| 2880 const std::string kFakeId(all_zero); | 2880 const std::string kFakeId(all_zero); |
| 2881 const GURL kFakeUpdateURL("http:://fake.update/url"); | 2881 const GURL kFakeUpdateURL("http:://fake.update/url"); |
| 2882 const bool kFakeInstallSilently(true); | 2882 const bool kFakeInstallSilently(true); |
| 2883 const bool kFakeRemoteInstall(false); | 2883 const bool kFakeRemoteInstall(false); |
| 2884 const bool kFakeInstalledByCustodian(false); |
| 2884 | 2885 |
| 2885 EXPECT_TRUE( | 2886 EXPECT_TRUE( |
| 2886 service()->pending_extension_manager()->AddFromSync(kFakeId, | 2887 service()->pending_extension_manager()->AddFromSync( |
| 2887 kFakeUpdateURL, | 2888 kFakeId, |
| 2888 &IsExtension, | 2889 kFakeUpdateURL, |
| 2889 kFakeInstallSilently, | 2890 &IsExtension, |
| 2890 kFakeRemoteInstall)); | 2891 kFakeInstallSilently, |
| 2892 kFakeRemoteInstall, |
| 2893 kFakeInstalledByCustodian)); |
| 2891 | 2894 |
| 2892 const extensions::PendingExtensionInfo* pending_extension_info; | 2895 const extensions::PendingExtensionInfo* pending_extension_info; |
| 2893 ASSERT_TRUE((pending_extension_info = | 2896 ASSERT_TRUE((pending_extension_info = |
| 2894 service()->pending_extension_manager()->GetById(kFakeId))); | 2897 service()->pending_extension_manager()->GetById(kFakeId))); |
| 2895 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); | 2898 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); |
| 2896 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); | 2899 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); |
| 2897 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently()); | 2900 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently()); |
| 2898 // Use | 2901 // Use |
| 2899 // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()) | 2902 // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()) |
| 2900 // instead of | 2903 // instead of |
| 2901 // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install()) | 2904 // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install()) |
| 2902 // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is | 2905 // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is |
| 2903 // turned into an error with -Werror=conversion-null: | 2906 // turned into an error with -Werror=conversion-null: |
| 2904 // converting 'false' to pointer type for argument 1 of | 2907 // converting 'false' to pointer type for argument 1 of |
| 2905 // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' | 2908 // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' |
| 2906 // https://code.google.com/p/googletest/issues/detail?id=458 | 2909 // https://code.google.com/p/googletest/issues/detail?id=458 |
| 2907 EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()); | 2910 EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()); |
| 2908 } | 2911 } |
| 2909 | 2912 |
| 2910 namespace { | 2913 namespace { |
| 2911 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 2914 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 2912 const char kGoodUpdateURL[] = "http://good.update/url"; | 2915 const char kGoodUpdateURL[] = "http://good.update/url"; |
| 2913 const bool kGoodIsFromSync = true; | 2916 const bool kGoodIsFromSync = true; |
| 2914 const bool kGoodInstallSilently = true; | 2917 const bool kGoodInstallSilently = true; |
| 2915 const bool kGoodRemoteInstall = false; | 2918 const bool kGoodRemoteInstall = false; |
| 2919 const bool kGoodInstalledByCustodian = false; |
| 2916 } // namespace | 2920 } // namespace |
| 2917 | 2921 |
| 2918 // Test updating a pending extension. | 2922 // Test updating a pending extension. |
| 2919 TEST_F(ExtensionServiceTest, UpdatePendingExtension) { | 2923 TEST_F(ExtensionServiceTest, UpdatePendingExtension) { |
| 2920 InitializeEmptyExtensionService(); | 2924 InitializeEmptyExtensionService(); |
| 2921 EXPECT_TRUE( | 2925 EXPECT_TRUE( |
| 2922 service()->pending_extension_manager()->AddFromSync(kGoodId, | 2926 service()->pending_extension_manager()->AddFromSync( |
| 2923 GURL(kGoodUpdateURL), | 2927 kGoodId, |
| 2924 &IsExtension, | 2928 GURL(kGoodUpdateURL), |
| 2925 kGoodInstallSilently, | 2929 &IsExtension, |
| 2926 kGoodRemoteInstall)); | 2930 kGoodInstallSilently, |
| 2931 kGoodRemoteInstall, |
| 2932 kGoodInstalledByCustodian)); |
| 2927 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); | 2933 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
| 2928 | 2934 |
| 2929 base::FilePath path = data_dir().AppendASCII("good.crx"); | 2935 base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 2930 UpdateExtension(kGoodId, path, ENABLED); | 2936 UpdateExtension(kGoodId, path, ENABLED); |
| 2931 | 2937 |
| 2932 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); | 2938 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
| 2933 | 2939 |
| 2934 const Extension* extension = service()->GetExtensionById(kGoodId, true); | 2940 const Extension* extension = service()->GetExtensionById(kGoodId, true); |
| 2935 ASSERT_TRUE(extension); | 2941 ASSERT_TRUE(extension); |
| 2936 } | 2942 } |
| 2937 | 2943 |
| 2938 namespace { | 2944 namespace { |
| 2939 | 2945 |
| 2940 bool IsTheme(const Extension* extension) { | 2946 bool IsTheme(const Extension* extension) { |
| 2941 return extension->is_theme(); | 2947 return extension->is_theme(); |
| 2942 } | 2948 } |
| 2943 | 2949 |
| 2944 } // namespace | 2950 } // namespace |
| 2945 | 2951 |
| 2946 // Test updating a pending theme. | 2952 // Test updating a pending theme. |
| 2947 // Disabled due to ASAN failure. http://crbug.com/108320 | 2953 // Disabled due to ASAN failure. http://crbug.com/108320 |
| 2948 TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) { | 2954 TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) { |
| 2949 InitializeEmptyExtensionService(); | 2955 InitializeEmptyExtensionService(); |
| 2950 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync( | 2956 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync( |
| 2951 theme_crx, GURL(), &IsTheme, false, false)); | 2957 theme_crx, GURL(), &IsTheme, false, false, false)); |
| 2952 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); | 2958 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
| 2953 | 2959 |
| 2954 base::FilePath path = data_dir().AppendASCII("theme.crx"); | 2960 base::FilePath path = data_dir().AppendASCII("theme.crx"); |
| 2955 UpdateExtension(theme_crx, path, ENABLED); | 2961 UpdateExtension(theme_crx, path, ENABLED); |
| 2956 | 2962 |
| 2957 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); | 2963 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
| 2958 | 2964 |
| 2959 const Extension* extension = service()->GetExtensionById(theme_crx, true); | 2965 const Extension* extension = service()->GetExtensionById(theme_crx, true); |
| 2960 ASSERT_TRUE(extension); | 2966 ASSERT_TRUE(extension); |
| 2961 | 2967 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3001 } | 3007 } |
| 3002 | 3008 |
| 3003 // Test updating a pending CRX as if the source is an external extension | 3009 // Test updating a pending CRX as if the source is an external extension |
| 3004 // with an update URL. The external update should overwrite a sync update, | 3010 // with an update URL. The external update should overwrite a sync update, |
| 3005 // but a sync update should not overwrite a non-sync update. | 3011 // but a sync update should not overwrite a non-sync update. |
| 3006 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { | 3012 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { |
| 3007 InitializeEmptyExtensionService(); | 3013 InitializeEmptyExtensionService(); |
| 3008 | 3014 |
| 3009 // Add a crx to be installed from the update mechanism. | 3015 // Add a crx to be installed from the update mechanism. |
| 3010 EXPECT_TRUE( | 3016 EXPECT_TRUE( |
| 3011 service()->pending_extension_manager()->AddFromSync(kGoodId, | 3017 service()->pending_extension_manager()->AddFromSync( |
| 3012 GURL(kGoodUpdateURL), | 3018 kGoodId, |
| 3013 &IsExtension, | 3019 GURL(kGoodUpdateURL), |
| 3014 kGoodInstallSilently, | 3020 &IsExtension, |
| 3015 kGoodRemoteInstall)); | 3021 kGoodInstallSilently, |
| 3022 kGoodRemoteInstall, |
| 3023 kGoodInstalledByCustodian)); |
| 3016 | 3024 |
| 3017 // Check that there is a pending crx, with is_from_sync set to true. | 3025 // Check that there is a pending crx, with is_from_sync set to true. |
| 3018 const extensions::PendingExtensionInfo* pending_extension_info; | 3026 const extensions::PendingExtensionInfo* pending_extension_info; |
| 3019 ASSERT_TRUE((pending_extension_info = | 3027 ASSERT_TRUE((pending_extension_info = |
| 3020 service()->pending_extension_manager()->GetById(kGoodId))); | 3028 service()->pending_extension_manager()->GetById(kGoodId))); |
| 3021 EXPECT_TRUE(pending_extension_info->is_from_sync()); | 3029 EXPECT_TRUE(pending_extension_info->is_from_sync()); |
| 3022 | 3030 |
| 3023 // Add a crx to be updated, with the same ID, from a non-sync source. | 3031 // Add a crx to be updated, with the same ID, from a non-sync source. |
| 3024 EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( | 3032 EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( |
| 3025 kGoodId, | 3033 kGoodId, |
| 3026 std::string(), | 3034 std::string(), |
| 3027 GURL(kGoodUpdateURL), | 3035 GURL(kGoodUpdateURL), |
| 3028 Manifest::EXTERNAL_PREF_DOWNLOAD, | 3036 Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 3029 Extension::NO_FLAGS, | 3037 Extension::NO_FLAGS, |
| 3030 false)); | 3038 false)); |
| 3031 | 3039 |
| 3032 // Check that there is a pending crx, with is_from_sync set to false. | 3040 // Check that there is a pending crx, with is_from_sync set to false. |
| 3033 ASSERT_TRUE((pending_extension_info = | 3041 ASSERT_TRUE((pending_extension_info = |
| 3034 service()->pending_extension_manager()->GetById(kGoodId))); | 3042 service()->pending_extension_manager()->GetById(kGoodId))); |
| 3035 EXPECT_FALSE(pending_extension_info->is_from_sync()); | 3043 EXPECT_FALSE(pending_extension_info->is_from_sync()); |
| 3036 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, | 3044 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 3037 pending_extension_info->install_source()); | 3045 pending_extension_info->install_source()); |
| 3038 | 3046 |
| 3039 // Add a crx to be installed from the update mechanism. | 3047 // Add a crx to be installed from the update mechanism. |
| 3040 EXPECT_FALSE( | 3048 EXPECT_FALSE( |
| 3041 service()->pending_extension_manager()->AddFromSync(kGoodId, | 3049 service()->pending_extension_manager()->AddFromSync( |
| 3042 GURL(kGoodUpdateURL), | 3050 kGoodId, |
| 3043 &IsExtension, | 3051 GURL(kGoodUpdateURL), |
| 3044 kGoodInstallSilently, | 3052 &IsExtension, |
| 3045 kGoodRemoteInstall)); | 3053 kGoodInstallSilently, |
| 3054 kGoodRemoteInstall, |
| 3055 kGoodInstalledByCustodian)); |
| 3046 | 3056 |
| 3047 // Check that the external, non-sync update was not overridden. | 3057 // Check that the external, non-sync update was not overridden. |
| 3048 ASSERT_TRUE((pending_extension_info = | 3058 ASSERT_TRUE((pending_extension_info = |
| 3049 service()->pending_extension_manager()->GetById(kGoodId))); | 3059 service()->pending_extension_manager()->GetById(kGoodId))); |
| 3050 EXPECT_FALSE(pending_extension_info->is_from_sync()); | 3060 EXPECT_FALSE(pending_extension_info->is_from_sync()); |
| 3051 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, | 3061 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 3052 pending_extension_info->install_source()); | 3062 pending_extension_info->install_source()); |
| 3053 } | 3063 } |
| 3054 | 3064 |
| 3055 // Updating a theme should fail if the updater is explicitly told that | 3065 // Updating a theme should fail if the updater is explicitly told that |
| 3056 // the CRX is not a theme. | 3066 // the CRX is not a theme. |
| 3057 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { | 3067 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { |
| 3058 InitializeEmptyExtensionService(); | 3068 InitializeEmptyExtensionService(); |
| 3059 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync( | 3069 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync( |
| 3060 theme_crx, GURL(), &IsExtension, true, false)); | 3070 theme_crx, GURL(), &IsExtension, true, false, false)); |
| 3061 | 3071 |
| 3062 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); | 3072 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
| 3063 | 3073 |
| 3064 base::FilePath path = data_dir().AppendASCII("theme.crx"); | 3074 base::FilePath path = data_dir().AppendASCII("theme.crx"); |
| 3065 UpdateExtension(theme_crx, path, FAILED_SILENTLY); | 3075 UpdateExtension(theme_crx, path, FAILED_SILENTLY); |
| 3066 | 3076 |
| 3067 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); | 3077 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
| 3068 | 3078 |
| 3069 const Extension* extension = service()->GetExtensionById(theme_crx, true); | 3079 const Extension* extension = service()->GetExtensionById(theme_crx, true); |
| 3070 ASSERT_FALSE(extension); | 3080 ASSERT_FALSE(extension); |
| 3071 } | 3081 } |
| 3072 | 3082 |
| 3073 // TODO(akalin): Test updating a pending extension non-silently once | 3083 // TODO(akalin): Test updating a pending extension non-silently once |
| 3074 // we can mock out ExtensionInstallUI and inject our version into | 3084 // we can mock out ExtensionInstallUI and inject our version into |
| 3075 // UpdateExtension(). | 3085 // UpdateExtension(). |
| 3076 | 3086 |
| 3077 // Test updating a pending extension which fails the should-install test. | 3087 // Test updating a pending extension which fails the should-install test. |
| 3078 TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) { | 3088 TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) { |
| 3079 InitializeEmptyExtensionService(); | 3089 InitializeEmptyExtensionService(); |
| 3080 // Add pending extension with a flipped is_theme. | 3090 // Add pending extension with a flipped is_theme. |
| 3081 EXPECT_TRUE( | 3091 EXPECT_TRUE( |
| 3082 service()->pending_extension_manager()->AddFromSync(kGoodId, | 3092 service()->pending_extension_manager()->AddFromSync( |
| 3083 GURL(kGoodUpdateURL), | 3093 kGoodId, |
| 3084 &IsTheme, | 3094 GURL(kGoodUpdateURL), |
| 3085 kGoodInstallSilently, | 3095 &IsTheme, |
| 3086 kGoodRemoteInstall)); | 3096 kGoodInstallSilently, |
| 3097 kGoodRemoteInstall, |
| 3098 kGoodInstalledByCustodian)); |
| 3087 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); | 3099 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
| 3088 | 3100 |
| 3089 base::FilePath path = data_dir().AppendASCII("good.crx"); | 3101 base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 3090 UpdateExtension(kGoodId, path, UPDATED); | 3102 UpdateExtension(kGoodId, path, UPDATED); |
| 3091 | 3103 |
| 3092 // TODO(akalin): Figure out how to check that the extensions | 3104 // TODO(akalin): Figure out how to check that the extensions |
| 3093 // directory is cleaned up properly in OnExtensionInstalled(). | 3105 // directory is cleaned up properly in OnExtensionInstalled(). |
| 3094 | 3106 |
| 3095 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); | 3107 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
| 3096 } | 3108 } |
| (...skipping 3361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6458 false); | 6470 false); |
| 6459 } | 6471 } |
| 6460 | 6472 |
| 6461 // Fake a request from sync to install an extension. | 6473 // Fake a request from sync to install an extension. |
| 6462 bool AddPendingSyncInstall() { | 6474 bool AddPendingSyncInstall() { |
| 6463 return service()->pending_extension_manager()->AddFromSync( | 6475 return service()->pending_extension_manager()->AddFromSync( |
| 6464 crx_id_, | 6476 crx_id_, |
| 6465 GURL(kGoodUpdateURL), | 6477 GURL(kGoodUpdateURL), |
| 6466 &IsExtension, | 6478 &IsExtension, |
| 6467 kGoodInstallSilently, | 6479 kGoodInstallSilently, |
| 6468 kGoodRemoteInstall); | 6480 kGoodRemoteInstall, |
| 6481 kGoodInstalledByCustodian); |
| 6469 } | 6482 } |
| 6470 | 6483 |
| 6471 // Fake a policy install. | 6484 // Fake a policy install. |
| 6472 bool AddPendingPolicyInstall() { | 6485 bool AddPendingPolicyInstall() { |
| 6473 // Get path to the CRX with id |kGoodId|. | 6486 // Get path to the CRX with id |kGoodId|. |
| 6474 return service()->OnExternalExtensionUpdateUrlFound( | 6487 return service()->OnExternalExtensionUpdateUrlFound( |
| 6475 crx_id_, | 6488 crx_id_, |
| 6476 std::string(), | 6489 std::string(), |
| 6477 GURL(), | 6490 GURL(), |
| 6478 Manifest::EXTERNAL_POLICY_DOWNLOAD, | 6491 Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6897 | 6910 |
| 6898 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 6911 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 6899 content::Source<Profile>(profile()), | 6912 content::Source<Profile>(profile()), |
| 6900 content::NotificationService::NoDetails()); | 6913 content::NotificationService::NoDetails()); |
| 6901 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 6914 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
| 6902 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 6915 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 6903 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 6916 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 6904 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 6917 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 6905 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 6918 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
| 6906 } | 6919 } |
| OLD | NEW |