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

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

Issue 436903002: Add tests for Extension installation/update for supervised users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" 52 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h"
53 #include "chrome/browser/extensions/installed_loader.h" 53 #include "chrome/browser/extensions/installed_loader.h"
54 #include "chrome/browser/extensions/pack_extension_job.h" 54 #include "chrome/browser/extensions/pack_extension_job.h"
55 #include "chrome/browser/extensions/pending_extension_info.h" 55 #include "chrome/browser/extensions/pending_extension_info.h"
56 #include "chrome/browser/extensions/pending_extension_manager.h" 56 #include "chrome/browser/extensions/pending_extension_manager.h"
57 #include "chrome/browser/extensions/test_blacklist.h" 57 #include "chrome/browser/extensions/test_blacklist.h"
58 #include "chrome/browser/extensions/test_extension_system.h" 58 #include "chrome/browser/extensions/test_extension_system.h"
59 #include "chrome/browser/extensions/unpacked_installer.h" 59 #include "chrome/browser/extensions/unpacked_installer.h"
60 #include "chrome/browser/extensions/updater/extension_updater.h" 60 #include "chrome/browser/extensions/updater/extension_updater.h"
61 #include "chrome/browser/prefs/pref_service_syncable.h" 61 #include "chrome/browser/prefs/pref_service_syncable.h"
62 #include "chrome/browser/supervised_user/supervised_user_service.h"
63 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
62 #include "chrome/browser/sync/profile_sync_service.h" 64 #include "chrome/browser/sync/profile_sync_service.h"
63 #include "chrome/browser/sync/profile_sync_service_factory.h" 65 #include "chrome/browser/sync/profile_sync_service_factory.h"
64 #include "chrome/common/chrome_constants.h" 66 #include "chrome/common/chrome_constants.h"
65 #include "chrome/common/chrome_switches.h" 67 #include "chrome/common/chrome_switches.h"
66 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 68 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
67 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 69 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
68 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" 70 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
69 #include "chrome/common/extensions/manifest_url_handler.h" 71 #include "chrome/common/extensions/manifest_url_handler.h"
70 #include "chrome/common/pref_names.h" 72 #include "chrome/common/pref_names.h"
71 #include "chrome/common/url_constants.h" 73 #include "chrome/common/url_constants.h"
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 loaded_.clear(); 739 loaded_.clear();
738 ExtensionErrorReporter::GetInstance()->ClearErrors(); 740 ExtensionErrorReporter::GetInstance()->ClearErrors();
739 return extension; 741 return extension;
740 } 742 }
741 743
742 enum UpdateState { 744 enum UpdateState {
743 FAILED_SILENTLY, 745 FAILED_SILENTLY,
744 FAILED, 746 FAILED,
745 UPDATED, 747 UPDATED,
746 INSTALLED, 748 INSTALLED,
749 DISABLED,
747 ENABLED 750 ENABLED
748 }; 751 };
749 752
750 void BlackListWebGL() { 753 void BlackListWebGL() {
751 static const std::string json_blacklist = 754 static const std::string json_blacklist =
752 "{\n" 755 "{\n"
753 " \"name\": \"gpu blacklist\",\n" 756 " \"name\": \"gpu blacklist\",\n"
754 " \"version\": \"1.0\",\n" 757 " \"version\": \"1.0\",\n"
755 " \"entries\": [\n" 758 " \"entries\": [\n"
756 " {\n" 759 " {\n"
(...skipping 10 matching lines...) Expand all
767 // Helper method to set up a WindowedNotificationObserver to wait for a 770 // Helper method to set up a WindowedNotificationObserver to wait for a
768 // specific CrxInstaller to finish if we don't know the value of the 771 // specific CrxInstaller to finish if we don't know the value of the
769 // |installer| yet. 772 // |installer| yet.
770 static bool IsCrxInstallerDone(extensions::CrxInstaller** installer, 773 static bool IsCrxInstallerDone(extensions::CrxInstaller** installer,
771 const content::NotificationSource& source, 774 const content::NotificationSource& source,
772 const content::NotificationDetails& details) { 775 const content::NotificationDetails& details) {
773 return content::Source<extensions::CrxInstaller>(source).ptr() == 776 return content::Source<extensions::CrxInstaller>(source).ptr() ==
774 *installer; 777 *installer;
775 } 778 }
776 779
780 void PackCRXAndUpdateExtension(const std::string& id,
not at google - send to devlin 2014/08/01 17:09:15 nit: Crx seems more common in this file, not CRX
Marc Treib 2014/08/04 08:38:12 Hm not really: all the PackCRX, InstallCRX etc fun
not at google - send to devlin 2014/08/04 16:46:08 eh, good point. don't worry about it.
781 const base::FilePath& dir_path,
782 const base::FilePath& pem_path,
783 UpdateState expected_state) {
784 base::FilePath crx_path;
not at google - send to devlin 2014/08/01 17:09:15 nit: initialize this directly on line 787?
Marc Treib 2014/08/04 08:38:12 Done.
785 base::ScopedTempDir temp_dir;
786 EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
787 crx_path = temp_dir.path().AppendASCII("temp.crx");
788
789 PackCRX(dir_path, pem_path, crx_path);
790 UpdateExtension(id, crx_path, expected_state);
791 }
792
777 void UpdateExtension(const std::string& id, 793 void UpdateExtension(const std::string& id,
778 const base::FilePath& in_path, 794 const base::FilePath& in_path,
779 UpdateState expected_state) { 795 UpdateState expected_state) {
780 ASSERT_TRUE(base::PathExists(in_path)); 796 ASSERT_TRUE(base::PathExists(in_path));
781 797
782 // We need to copy this to a temporary location because Update() will delete 798 // We need to copy this to a temporary location because Update() will delete
783 // it. 799 // it.
784 base::FilePath path = temp_dir().path(); 800 base::FilePath path = temp_dir().path();
785 path = path.Append(in_path.BaseName()); 801 path = path.Append(in_path.BaseName());
786 ASSERT_TRUE(base::CopyFile(in_path, path)); 802 ASSERT_TRUE(base::CopyFile(in_path, path));
(...skipping 5310 matching lines...) Expand 10 before | Expand all | Expand 10 after
6097 const extensions::PendingExtensionInfo* info; 6113 const extensions::PendingExtensionInfo* info;
6098 EXPECT_TRUE( 6114 EXPECT_TRUE(
6099 (info = service()->pending_extension_manager()->GetById(good_crx))); 6115 (info = service()->pending_extension_manager()->GetById(good_crx)));
6100 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); 6116 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec());
6101 EXPECT_TRUE(info->is_from_sync()); 6117 EXPECT_TRUE(info->is_from_sync());
6102 EXPECT_TRUE(info->install_silently()); 6118 EXPECT_TRUE(info->install_silently());
6103 EXPECT_EQ(Manifest::INTERNAL, info->install_source()); 6119 EXPECT_EQ(Manifest::INTERNAL, info->install_source());
6104 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. 6120 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|.
6105 } 6121 }
6106 6122
6107 TEST_F(ExtensionServiceTest, SyncUninstallForSupervisedUser) { 6123 TEST_F(ExtensionServiceTest, SupervisedUser_InstallOnlyAllowedByCustodian) {
6124 ExtensionServiceInitParams params = CreateDefaultInitParams();
6125 params.profile_is_supervised = true;
6126 InitializeExtensionService(params);
6127
6128 SupervisedUserService* supervised_user_service =
6129 SupervisedUserServiceFactory::GetForProfile(profile());
6130 GetManagementPolicy()->RegisterProvider(supervised_user_service);
6131
6132 base::FilePath path1 = data_dir().AppendASCII("good.crx");
6133 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
6134 const Extension* extensions[2] = {
not at google - send to devlin 2014/08/01 17:09:16 nit: the [2] should be unnecessary
Marc Treib 2014/08/04 08:38:11 Done.
6135 InstallCRX(path1, INSTALL_FAILED),
6136 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)
not at google - send to devlin 2014/08/01 17:09:15 it would be nicer if instead of using InstallCRX d
Marc Treib 2014/08/04 08:38:12 Can I still make it use a local crx file then? Usu
not at google - send to devlin 2014/08/04 16:46:08 Yeah it doesn't look like we really test basic syn
6137 };
6138
6139 // Only the extension with the "installed by custodian" flag should have been
6140 // installed and enabled.
6141 EXPECT_FALSE(extensions[0]);
6142 EXPECT_TRUE(extensions[1]);
6143 EXPECT_TRUE(service()->GetExtensionById(extensions[1]->id(), false));
not at google - send to devlin 2014/08/01 17:09:15 use registry()->enabled_extensions()->Contains(ext
Marc Treib 2014/08/04 08:38:11 Done.
6144 }
6145
6146 TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithoutPermissionIncrease) {
6147 ExtensionServiceInitParams params = CreateDefaultInitParams();
6148 params.profile_is_supervised = true;
6149 InitializeExtensionService(params);
6150
6151 SupervisedUserService* supervised_user_service =
6152 SupervisedUserServiceFactory::GetForProfile(profile());
6153 GetManagementPolicy()->RegisterProvider(supervised_user_service);
6154
6155 base::FilePath base_path = data_dir().AppendASCII("autoupdate");
6156 base::FilePath pem_path = base_path.AppendASCII("key.pem");
6157
6158 base::FilePath path = base_path.AppendASCII("v1");
6159 const Extension* extension =
6160 PackAndInstallCRX(path, pem_path, INSTALL_NEW,
6161 Extension::WAS_INSTALLED_BY_CUSTODIAN);
6162 // The extension must now be installed and enabled.
6163 ASSERT_TRUE(extension);
6164 ASSERT_TRUE(service()->GetExtensionById(extension->id(), false));
not at google - send to devlin 2014/08/01 17:09:15 registry()...
Marc Treib 2014/08/04 08:38:11 Done.
6165
6166 // Save the id, as the extension object will be destroyed during updating.
6167 std::string id = extension->id();
6168
6169 std::string old_version = extension->VersionString();
6170
6171 // Update to a new version.
6172 path = base_path.AppendASCII("v2");
6173 PackCRXAndUpdateExtension(id, path, pem_path, ENABLED);
6174
6175 // The extension should still be there and enabled.
6176 extension = service()->GetExtensionById(id, false);
not at google - send to devlin 2014/08/01 17:09:15 registry()...
Marc Treib 2014/08/04 08:38:11 Done.
6177 EXPECT_TRUE(extension);
6178 // The version should have changed.
6179 EXPECT_NE(extension->VersionString(), old_version);
6180 }
6181
6182 TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithPermissionIncrease) {
6183 ExtensionServiceInitParams params = CreateDefaultInitParams();
6184 params.profile_is_supervised = true;
6185 InitializeExtensionService(params);
6186
6187 SupervisedUserService* supervised_user_service =
6188 SupervisedUserServiceFactory::GetForProfile(profile());
6189 GetManagementPolicy()->RegisterProvider(supervised_user_service);
6190
6191 base::FilePath base_path = data_dir().AppendASCII("permissions_increase");
6192 base::FilePath pem_path = base_path.AppendASCII("permissions.pem");
6193
6194 base::FilePath path = base_path.AppendASCII("v1");
6195 const Extension* extension =
6196 PackAndInstallCRX(path, pem_path, INSTALL_NEW,
6197 Extension::WAS_INSTALLED_BY_CUSTODIAN);
6198 // The extension must now be installed and enabled.
6199 ASSERT_TRUE(extension);
6200 ASSERT_TRUE(service()->GetExtensionById(extension->id(), false));
not at google - send to devlin 2014/08/01 17:09:15 registry()
Marc Treib 2014/08/04 08:38:11 Done.
6201
6202 // Save the id, as the extension object will be destroyed during updating.
6203 std::string id = extension->id();
6204
6205 std::string old_version = extension->VersionString();
6206
6207 // Update to a new version with increased permissions.
6208 path = base_path.AppendASCII("v2");
6209 PackCRXAndUpdateExtension(id, path, pem_path, DISABLED);
6210
6211 // The extension should still be there, but disabled.
6212 EXPECT_FALSE(service()->GetExtensionById(id, false));
not at google - send to devlin 2014/08/01 17:09:15 registry() x2
Marc Treib 2014/08/04 08:38:11 Done.
6213 extension = service()->GetExtensionById(id, true);
6214 EXPECT_TRUE(extension);
not at google - send to devlin 2014/08/01 17:09:15 should be an ASSERT_TRUE really since the line bel
Marc Treib 2014/08/04 08:38:11 Done.
6215 // The version should have changed.
6216 EXPECT_NE(extension->VersionString(), old_version);
6217 }
6218
6219 TEST_F(ExtensionServiceTest,
6220 SupervisedUser_SyncUninstallByCustodianSkipsPolicy) {
6108 InitializeEmptyExtensionService(); 6221 InitializeEmptyExtensionService();
6109 InitializeExtensionSyncService(); 6222 InitializeExtensionSyncService();
6110 extension_sync_service()->MergeDataAndStartSyncing( 6223 extension_sync_service()->MergeDataAndStartSyncing(
6111 syncer::EXTENSIONS, 6224 syncer::EXTENSIONS,
6112 syncer::SyncDataList(), 6225 syncer::SyncDataList(),
6113 scoped_ptr<syncer::SyncChangeProcessor>( 6226 scoped_ptr<syncer::SyncChangeProcessor>(
6114 new syncer::FakeSyncChangeProcessor), 6227 new syncer::FakeSyncChangeProcessor),
6115 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 6228 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
6116 6229
6117 // Install two extensions. 6230 // Install two extensions.
6118 base::FilePath path1 = data_dir().AppendASCII("good.crx"); 6231 base::FilePath path1 = data_dir().AppendASCII("good.crx");
6119 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); 6232 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
6120 const Extension* extensions[2] = { 6233 const Extension* extensions[2] = {
not at google - send to devlin 2014/08/01 17:09:15 shouldn't need the [2] here either
Marc Treib 2014/08/04 08:38:11 Done.
6121 InstallCRX(path1, INSTALL_NEW), 6234 InstallCRX(path1, INSTALL_NEW),
6122 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) 6235 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)
6123 }; 6236 };
6124 6237
6125 // Add a policy provider that will disallow any changes. 6238 // Add a policy provider that will disallow any changes.
6126 extensions::TestManagementPolicyProvider provider( 6239 extensions::TestManagementPolicyProvider provider(
6127 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); 6240 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
6128 GetManagementPolicy()->RegisterProvider(&provider); 6241 GetManagementPolicy()->RegisterProvider(&provider);
6129 6242
6130 // Create a sync deletion for each extension. 6243 // Create a sync deletion for each extension.
6131 syncer::SyncChangeList change_list; 6244 syncer::SyncChangeList change_list;
6132 for (int i = 0; i < 2; i++) { 6245 for (int i = 0; i < 2; i++) {
not at google - send to devlin 2014/08/01 17:09:16 arraysize(extensions)
Marc Treib 2014/08/04 08:38:11 Done.
6133 const std::string& id = extensions[i]->id(); 6246 const std::string& id = extensions[i]->id();
6134 sync_pb::EntitySpecifics specifics; 6247 sync_pb::EntitySpecifics specifics;
6135 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 6248 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
6136 ext_specifics->set_id(id); 6249 ext_specifics->set_id(id);
6137 ext_specifics->set_version("1.0"); 6250 ext_specifics->set_version("1.0");
6138 ext_specifics->set_installed_by_custodian( 6251 ext_specifics->set_installed_by_custodian(
6139 extensions[i]->was_installed_by_custodian()); 6252 extensions[i]->was_installed_by_custodian());
6140 syncer::SyncData sync_data = 6253 syncer::SyncData sync_data =
6141 syncer::SyncData::CreateLocalData(id, "Name", specifics); 6254 syncer::SyncData::CreateLocalData(id, "Name", specifics);
6142 change_list.push_back(syncer::SyncChange(FROM_HERE, 6255 change_list.push_back(syncer::SyncChange(FROM_HERE,
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
7039 7152
7040 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 7153 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
7041 content::Source<Profile>(profile()), 7154 content::Source<Profile>(profile()),
7042 content::NotificationService::NoDetails()); 7155 content::NotificationService::NoDetails());
7043 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 7156 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
7044 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 7157 EXPECT_EQ(0u, registry()->enabled_extensions().size());
7045 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 7158 EXPECT_EQ(0u, registry()->disabled_extensions().size());
7046 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 7159 EXPECT_EQ(0u, registry()->terminated_extensions().size());
7047 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 7160 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
7048 } 7161 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698