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

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

Issue 353493002: Apps&Extensions for supervised users: Add Extension::WAS_INSTALLED_BY_CUSTODIAN flag and proto entry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 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 | Annotate | Revision Log
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 <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 2866 matching lines...) Expand 10 before | Expand all | Expand 10 after
2877 } // namespace 2877 } // namespace
2878 2878
2879 // Test adding a pending extension. 2879 // Test adding a pending extension.
2880 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { 2880 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) {
2881 InitializeEmptyExtensionService(); 2881 InitializeEmptyExtensionService();
2882 2882
2883 const std::string kFakeId(all_zero); 2883 const std::string kFakeId(all_zero);
2884 const GURL kFakeUpdateURL("http:://fake.update/url"); 2884 const GURL kFakeUpdateURL("http:://fake.update/url");
2885 const bool kFakeInstallSilently(true); 2885 const bool kFakeInstallSilently(true);
2886 const bool kFakeRemoteInstall(false); 2886 const bool kFakeRemoteInstall(false);
2887 const bool kFakeInstalledByCustodian(false);
2887 2888
2888 EXPECT_TRUE( 2889 EXPECT_TRUE(
2889 service()->pending_extension_manager()->AddFromSync(kFakeId, 2890 service()->pending_extension_manager()->AddFromSync(
2890 kFakeUpdateURL, 2891 kFakeId,
2891 &IsExtension, 2892 kFakeUpdateURL,
2892 kFakeInstallSilently, 2893 &IsExtension,
2893 kFakeRemoteInstall)); 2894 kFakeInstallSilently,
2895 kFakeRemoteInstall,
2896 kFakeInstalledByCustodian));
2894 2897
2895 const extensions::PendingExtensionInfo* pending_extension_info; 2898 const extensions::PendingExtensionInfo* pending_extension_info;
2896 ASSERT_TRUE((pending_extension_info = 2899 ASSERT_TRUE((pending_extension_info =
2897 service()->pending_extension_manager()->GetById(kFakeId))); 2900 service()->pending_extension_manager()->GetById(kFakeId)));
2898 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); 2901 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url());
2899 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); 2902 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_);
2900 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently()); 2903 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently());
2901 // Use 2904 // Use
2902 // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()) 2905 // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install())
2903 // instead of 2906 // instead of
2904 // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install()) 2907 // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install())
2905 // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is 2908 // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is
2906 // turned into an error with -Werror=conversion-null: 2909 // turned into an error with -Werror=conversion-null:
2907 // converting 'false' to pointer type for argument 1 of 2910 // converting 'false' to pointer type for argument 1 of
2908 // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' 2911 // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)'
2909 // https://code.google.com/p/googletest/issues/detail?id=458 2912 // https://code.google.com/p/googletest/issues/detail?id=458
2910 EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()); 2913 EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install());
2911 } 2914 }
2912 2915
2913 namespace { 2916 namespace {
2914 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 2917 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
2915 const char kGoodUpdateURL[] = "http://good.update/url"; 2918 const char kGoodUpdateURL[] = "http://good.update/url";
2916 const bool kGoodIsFromSync = true; 2919 const bool kGoodIsFromSync = true;
2917 const bool kGoodInstallSilently = true; 2920 const bool kGoodInstallSilently = true;
2918 const bool kGoodRemoteInstall = false; 2921 const bool kGoodRemoteInstall = false;
2922 const bool kGoodInstalledByCustodian = false;
2919 } // namespace 2923 } // namespace
2920 2924
2921 // Test updating a pending extension. 2925 // Test updating a pending extension.
2922 TEST_F(ExtensionServiceTest, UpdatePendingExtension) { 2926 TEST_F(ExtensionServiceTest, UpdatePendingExtension) {
2923 InitializeEmptyExtensionService(); 2927 InitializeEmptyExtensionService();
2924 EXPECT_TRUE( 2928 EXPECT_TRUE(
2925 service()->pending_extension_manager()->AddFromSync(kGoodId, 2929 service()->pending_extension_manager()->AddFromSync(
2926 GURL(kGoodUpdateURL), 2930 kGoodId,
2927 &IsExtension, 2931 GURL(kGoodUpdateURL),
2928 kGoodInstallSilently, 2932 &IsExtension,
2929 kGoodRemoteInstall)); 2933 kGoodInstallSilently,
2934 kGoodRemoteInstall,
2935 kGoodInstalledByCustodian));
2930 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); 2936 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId));
2931 2937
2932 base::FilePath path = data_dir().AppendASCII("good.crx"); 2938 base::FilePath path = data_dir().AppendASCII("good.crx");
2933 UpdateExtension(kGoodId, path, ENABLED); 2939 UpdateExtension(kGoodId, path, ENABLED);
2934 2940
2935 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); 2941 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
2936 2942
2937 const Extension* extension = service()->GetExtensionById(kGoodId, true); 2943 const Extension* extension = service()->GetExtensionById(kGoodId, true);
2938 ASSERT_TRUE(extension); 2944 ASSERT_TRUE(extension);
2939 } 2945 }
2940 2946
2941 namespace { 2947 namespace {
2942 2948
2943 bool IsTheme(const Extension* extension) { 2949 bool IsTheme(const Extension* extension) {
2944 return extension->is_theme(); 2950 return extension->is_theme();
2945 } 2951 }
2946 2952
2947 } // namespace 2953 } // namespace
2948 2954
2949 // Test updating a pending theme. 2955 // Test updating a pending theme.
2950 // Disabled due to ASAN failure. http://crbug.com/108320 2956 // Disabled due to ASAN failure. http://crbug.com/108320
2951 TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) { 2957 TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) {
2952 InitializeEmptyExtensionService(); 2958 InitializeEmptyExtensionService();
2953 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync( 2959 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync(
2954 theme_crx, GURL(), &IsTheme, false, false)); 2960 theme_crx, GURL(), &IsTheme, false, false, false));
2955 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); 2961 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
2956 2962
2957 base::FilePath path = data_dir().AppendASCII("theme.crx"); 2963 base::FilePath path = data_dir().AppendASCII("theme.crx");
2958 UpdateExtension(theme_crx, path, ENABLED); 2964 UpdateExtension(theme_crx, path, ENABLED);
2959 2965
2960 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); 2966 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
2961 2967
2962 const Extension* extension = service()->GetExtensionById(theme_crx, true); 2968 const Extension* extension = service()->GetExtensionById(theme_crx, true);
2963 ASSERT_TRUE(extension); 2969 ASSERT_TRUE(extension);
2964 2970
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3004 } 3010 }
3005 3011
3006 // Test updating a pending CRX as if the source is an external extension 3012 // Test updating a pending CRX as if the source is an external extension
3007 // with an update URL. The external update should overwrite a sync update, 3013 // with an update URL. The external update should overwrite a sync update,
3008 // but a sync update should not overwrite a non-sync update. 3014 // but a sync update should not overwrite a non-sync update.
3009 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { 3015 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) {
3010 InitializeEmptyExtensionService(); 3016 InitializeEmptyExtensionService();
3011 3017
3012 // Add a crx to be installed from the update mechanism. 3018 // Add a crx to be installed from the update mechanism.
3013 EXPECT_TRUE( 3019 EXPECT_TRUE(
3014 service()->pending_extension_manager()->AddFromSync(kGoodId, 3020 service()->pending_extension_manager()->AddFromSync(
3015 GURL(kGoodUpdateURL), 3021 kGoodId,
3016 &IsExtension, 3022 GURL(kGoodUpdateURL),
3017 kGoodInstallSilently, 3023 &IsExtension,
3018 kGoodRemoteInstall)); 3024 kGoodInstallSilently,
3025 kGoodRemoteInstall,
3026 kGoodInstalledByCustodian));
3019 3027
3020 // Check that there is a pending crx, with is_from_sync set to true. 3028 // Check that there is a pending crx, with is_from_sync set to true.
3021 const extensions::PendingExtensionInfo* pending_extension_info; 3029 const extensions::PendingExtensionInfo* pending_extension_info;
3022 ASSERT_TRUE((pending_extension_info = 3030 ASSERT_TRUE((pending_extension_info =
3023 service()->pending_extension_manager()->GetById(kGoodId))); 3031 service()->pending_extension_manager()->GetById(kGoodId)));
3024 EXPECT_TRUE(pending_extension_info->is_from_sync()); 3032 EXPECT_TRUE(pending_extension_info->is_from_sync());
3025 3033
3026 // Add a crx to be updated, with the same ID, from a non-sync source. 3034 // Add a crx to be updated, with the same ID, from a non-sync source.
3027 EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( 3035 EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl(
3028 kGoodId, 3036 kGoodId,
3029 std::string(), 3037 std::string(),
3030 GURL(kGoodUpdateURL), 3038 GURL(kGoodUpdateURL),
3031 Manifest::EXTERNAL_PREF_DOWNLOAD, 3039 Manifest::EXTERNAL_PREF_DOWNLOAD,
3032 Extension::NO_FLAGS, 3040 Extension::NO_FLAGS,
3033 false)); 3041 false));
3034 3042
3035 // Check that there is a pending crx, with is_from_sync set to false. 3043 // Check that there is a pending crx, with is_from_sync set to false.
3036 ASSERT_TRUE((pending_extension_info = 3044 ASSERT_TRUE((pending_extension_info =
3037 service()->pending_extension_manager()->GetById(kGoodId))); 3045 service()->pending_extension_manager()->GetById(kGoodId)));
3038 EXPECT_FALSE(pending_extension_info->is_from_sync()); 3046 EXPECT_FALSE(pending_extension_info->is_from_sync());
3039 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, 3047 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD,
3040 pending_extension_info->install_source()); 3048 pending_extension_info->install_source());
3041 3049
3042 // Add a crx to be installed from the update mechanism. 3050 // Add a crx to be installed from the update mechanism.
3043 EXPECT_FALSE( 3051 EXPECT_FALSE(
3044 service()->pending_extension_manager()->AddFromSync(kGoodId, 3052 service()->pending_extension_manager()->AddFromSync(
3045 GURL(kGoodUpdateURL), 3053 kGoodId,
3046 &IsExtension, 3054 GURL(kGoodUpdateURL),
3047 kGoodInstallSilently, 3055 &IsExtension,
3048 kGoodRemoteInstall)); 3056 kGoodInstallSilently,
3057 kGoodRemoteInstall,
3058 kGoodInstalledByCustodian));
3049 3059
3050 // Check that the external, non-sync update was not overridden. 3060 // Check that the external, non-sync update was not overridden.
3051 ASSERT_TRUE((pending_extension_info = 3061 ASSERT_TRUE((pending_extension_info =
3052 service()->pending_extension_manager()->GetById(kGoodId))); 3062 service()->pending_extension_manager()->GetById(kGoodId)));
3053 EXPECT_FALSE(pending_extension_info->is_from_sync()); 3063 EXPECT_FALSE(pending_extension_info->is_from_sync());
3054 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, 3064 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD,
3055 pending_extension_info->install_source()); 3065 pending_extension_info->install_source());
3056 } 3066 }
3057 3067
3058 // Updating a theme should fail if the updater is explicitly told that 3068 // Updating a theme should fail if the updater is explicitly told that
3059 // the CRX is not a theme. 3069 // the CRX is not a theme.
3060 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { 3070 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) {
3061 InitializeEmptyExtensionService(); 3071 InitializeEmptyExtensionService();
3062 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync( 3072 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync(
3063 theme_crx, GURL(), &IsExtension, true, false)); 3073 theme_crx, GURL(), &IsExtension, true, false, false));
3064 3074
3065 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); 3075 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3066 3076
3067 base::FilePath path = data_dir().AppendASCII("theme.crx"); 3077 base::FilePath path = data_dir().AppendASCII("theme.crx");
3068 UpdateExtension(theme_crx, path, FAILED_SILENTLY); 3078 UpdateExtension(theme_crx, path, FAILED_SILENTLY);
3069 3079
3070 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); 3080 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
3071 3081
3072 const Extension* extension = service()->GetExtensionById(theme_crx, true); 3082 const Extension* extension = service()->GetExtensionById(theme_crx, true);
3073 ASSERT_FALSE(extension); 3083 ASSERT_FALSE(extension);
3074 } 3084 }
3075 3085
3076 // TODO(akalin): Test updating a pending extension non-silently once 3086 // TODO(akalin): Test updating a pending extension non-silently once
3077 // we can mock out ExtensionInstallUI and inject our version into 3087 // we can mock out ExtensionInstallUI and inject our version into
3078 // UpdateExtension(). 3088 // UpdateExtension().
3079 3089
3080 // Test updating a pending extension which fails the should-install test. 3090 // Test updating a pending extension which fails the should-install test.
3081 TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) { 3091 TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) {
3082 InitializeEmptyExtensionService(); 3092 InitializeEmptyExtensionService();
3083 // Add pending extension with a flipped is_theme. 3093 // Add pending extension with a flipped is_theme.
3084 EXPECT_TRUE( 3094 EXPECT_TRUE(
3085 service()->pending_extension_manager()->AddFromSync(kGoodId, 3095 service()->pending_extension_manager()->AddFromSync(
3086 GURL(kGoodUpdateURL), 3096 kGoodId,
3087 &IsTheme, 3097 GURL(kGoodUpdateURL),
3088 kGoodInstallSilently, 3098 &IsTheme,
3089 kGoodRemoteInstall)); 3099 kGoodInstallSilently,
3100 kGoodRemoteInstall,
3101 kGoodInstalledByCustodian));
3090 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); 3102 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3091 3103
3092 base::FilePath path = data_dir().AppendASCII("good.crx"); 3104 base::FilePath path = data_dir().AppendASCII("good.crx");
3093 UpdateExtension(kGoodId, path, UPDATED); 3105 UpdateExtension(kGoodId, path, UPDATED);
3094 3106
3095 // TODO(akalin): Figure out how to check that the extensions 3107 // TODO(akalin): Figure out how to check that the extensions
3096 // directory is cleaned up properly in OnExtensionInstalled(). 3108 // directory is cleaned up properly in OnExtensionInstalled().
3097 3109
3098 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); 3110 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3099 } 3111 }
(...skipping 3367 matching lines...) Expand 10 before | Expand all | Expand 10 after
6467 false); 6479 false);
6468 } 6480 }
6469 6481
6470 // Fake a request from sync to install an extension. 6482 // Fake a request from sync to install an extension.
6471 bool AddPendingSyncInstall() { 6483 bool AddPendingSyncInstall() {
6472 return service()->pending_extension_manager()->AddFromSync( 6484 return service()->pending_extension_manager()->AddFromSync(
6473 crx_id_, 6485 crx_id_,
6474 GURL(kGoodUpdateURL), 6486 GURL(kGoodUpdateURL),
6475 &IsExtension, 6487 &IsExtension,
6476 kGoodInstallSilently, 6488 kGoodInstallSilently,
6477 kGoodRemoteInstall); 6489 kGoodRemoteInstall,
6490 kGoodInstalledByCustodian);
6478 } 6491 }
6479 6492
6480 // Fake a policy install. 6493 // Fake a policy install.
6481 bool AddPendingPolicyInstall() { 6494 bool AddPendingPolicyInstall() {
6482 // Get path to the CRX with id |kGoodId|. 6495 // Get path to the CRX with id |kGoodId|.
6483 return service()->OnExternalExtensionUpdateUrlFound( 6496 return service()->OnExternalExtensionUpdateUrlFound(
6484 crx_id_, 6497 crx_id_,
6485 std::string(), 6498 std::string(),
6486 GURL(), 6499 GURL(),
6487 Manifest::EXTERNAL_POLICY_DOWNLOAD, 6500 Manifest::EXTERNAL_POLICY_DOWNLOAD,
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
6946 6959
6947 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 6960 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
6948 content::Source<Profile>(profile()), 6961 content::Source<Profile>(profile()),
6949 content::NotificationService::NoDetails()); 6962 content::NotificationService::NoDetails());
6950 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 6963 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
6951 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 6964 EXPECT_EQ(0u, registry()->enabled_extensions().size());
6952 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 6965 EXPECT_EQ(0u, registry()->disabled_extensions().size());
6953 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 6966 EXPECT_EQ(0u, registry()->terminated_extensions().size());
6954 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 6967 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
6955 } 6968 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/extension_sync_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698