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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_service_unittest.cc
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 634ce5999535c57dcc75c09d786331fed877acea..440452c358a90fa3113cef0133db0cfcf4bdc893 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -59,6 +59,8 @@
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/extensions/updater/extension_updater.h"
#include "chrome/browser/prefs/pref_service_syncable.h"
+#include "chrome/browser/supervised_user/supervised_user_service.h"
+#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/common/chrome_constants.h"
@@ -744,6 +746,7 @@ class ExtensionServiceTest : public extensions::ExtensionServiceTestBase,
FAILED,
UPDATED,
INSTALLED,
+ DISABLED,
ENABLED
};
@@ -774,6 +777,19 @@ class ExtensionServiceTest : public extensions::ExtensionServiceTestBase,
*installer;
}
+ 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.
+ const base::FilePath& dir_path,
+ const base::FilePath& pem_path,
+ UpdateState expected_state) {
+ 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.
+ base::ScopedTempDir temp_dir;
+ EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
+ crx_path = temp_dir.path().AppendASCII("temp.crx");
+
+ PackCRX(dir_path, pem_path, crx_path);
+ UpdateExtension(id, crx_path, expected_state);
+ }
+
void UpdateExtension(const std::string& id,
const base::FilePath& in_path,
UpdateState expected_state) {
@@ -6104,7 +6120,104 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) {
// TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|.
}
-TEST_F(ExtensionServiceTest, SyncUninstallForSupervisedUser) {
+TEST_F(ExtensionServiceTest, SupervisedUser_InstallOnlyAllowedByCustodian) {
+ ExtensionServiceInitParams params = CreateDefaultInitParams();
+ params.profile_is_supervised = true;
+ InitializeExtensionService(params);
+
+ SupervisedUserService* supervised_user_service =
+ SupervisedUserServiceFactory::GetForProfile(profile());
+ GetManagementPolicy()->RegisterProvider(supervised_user_service);
+
+ base::FilePath path1 = data_dir().AppendASCII("good.crx");
+ base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
+ 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.
+ InstallCRX(path1, INSTALL_FAILED),
+ 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
+ };
+
+ // Only the extension with the "installed by custodian" flag should have been
+ // installed and enabled.
+ EXPECT_FALSE(extensions[0]);
+ EXPECT_TRUE(extensions[1]);
+ 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.
+}
+
+TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithoutPermissionIncrease) {
+ ExtensionServiceInitParams params = CreateDefaultInitParams();
+ params.profile_is_supervised = true;
+ InitializeExtensionService(params);
+
+ SupervisedUserService* supervised_user_service =
+ SupervisedUserServiceFactory::GetForProfile(profile());
+ GetManagementPolicy()->RegisterProvider(supervised_user_service);
+
+ base::FilePath base_path = data_dir().AppendASCII("autoupdate");
+ base::FilePath pem_path = base_path.AppendASCII("key.pem");
+
+ base::FilePath path = base_path.AppendASCII("v1");
+ const Extension* extension =
+ PackAndInstallCRX(path, pem_path, INSTALL_NEW,
+ Extension::WAS_INSTALLED_BY_CUSTODIAN);
+ // The extension must now be installed and enabled.
+ ASSERT_TRUE(extension);
+ 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.
+
+ // Save the id, as the extension object will be destroyed during updating.
+ std::string id = extension->id();
+
+ std::string old_version = extension->VersionString();
+
+ // Update to a new version.
+ path = base_path.AppendASCII("v2");
+ PackCRXAndUpdateExtension(id, path, pem_path, ENABLED);
+
+ // The extension should still be there and enabled.
+ 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.
+ EXPECT_TRUE(extension);
+ // The version should have changed.
+ EXPECT_NE(extension->VersionString(), old_version);
+}
+
+TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithPermissionIncrease) {
+ ExtensionServiceInitParams params = CreateDefaultInitParams();
+ params.profile_is_supervised = true;
+ InitializeExtensionService(params);
+
+ SupervisedUserService* supervised_user_service =
+ SupervisedUserServiceFactory::GetForProfile(profile());
+ GetManagementPolicy()->RegisterProvider(supervised_user_service);
+
+ base::FilePath base_path = data_dir().AppendASCII("permissions_increase");
+ base::FilePath pem_path = base_path.AppendASCII("permissions.pem");
+
+ base::FilePath path = base_path.AppendASCII("v1");
+ const Extension* extension =
+ PackAndInstallCRX(path, pem_path, INSTALL_NEW,
+ Extension::WAS_INSTALLED_BY_CUSTODIAN);
+ // The extension must now be installed and enabled.
+ ASSERT_TRUE(extension);
+ 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.
+
+ // Save the id, as the extension object will be destroyed during updating.
+ std::string id = extension->id();
+
+ std::string old_version = extension->VersionString();
+
+ // Update to a new version with increased permissions.
+ path = base_path.AppendASCII("v2");
+ PackCRXAndUpdateExtension(id, path, pem_path, DISABLED);
+
+ // The extension should still be there, but disabled.
+ 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.
+ extension = service()->GetExtensionById(id, true);
+ 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.
+ // The version should have changed.
+ EXPECT_NE(extension->VersionString(), old_version);
+}
+
+TEST_F(ExtensionServiceTest,
+ SupervisedUser_SyncUninstallByCustodianSkipsPolicy) {
InitializeEmptyExtensionService();
InitializeExtensionSyncService();
extension_sync_service()->MergeDataAndStartSyncing(
« 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