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

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

Issue 1028123002: Supervised users: Include extension version in update requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tests Created 5 years, 9 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
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 6623 matching lines...) Expand 10 before | Expand all | Expand 10 after
6634 MockPermissionRequestCreator() {} 6634 MockPermissionRequestCreator() {}
6635 ~MockPermissionRequestCreator() override {} 6635 ~MockPermissionRequestCreator() override {}
6636 6636
6637 bool IsEnabled() const override { return true; } 6637 bool IsEnabled() const override { return true; }
6638 6638
6639 void CreateURLAccessRequest(const GURL& url_requested, 6639 void CreateURLAccessRequest(const GURL& url_requested,
6640 const SuccessCallback& callback) override { 6640 const SuccessCallback& callback) override {
6641 FAIL(); 6641 FAIL();
6642 } 6642 }
6643 6643
6644 MOCK_METHOD2(CreateExtensionUpdateRequest, 6644 MOCK_METHOD3(CreateExtensionUpdateRequest,
6645 void(const std::string& extension_id, 6645 void(const std::string& extension_id,
6646 const base::Version& version,
6646 const SupervisedUserService::SuccessCallback& callback)); 6647 const SupervisedUserService::SuccessCallback& callback));
6647 6648
6648 private: 6649 private:
6649 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator); 6650 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator);
6650 }; 6651 };
6651 6652
6652 TEST_F(ExtensionServiceTest, SupervisedUser_InstallOnlyAllowedByCustodian) { 6653 TEST_F(ExtensionServiceTest, SupervisedUser_InstallOnlyAllowedByCustodian) {
6653 ExtensionServiceInitParams params = CreateDefaultInitParams(); 6654 ExtensionServiceInitParams params = CreateDefaultInitParams();
6654 params.profile_is_supervised = true; 6655 params.profile_is_supervised = true;
6655 InitializeExtensionService(params); 6656 InitializeExtensionService(params);
6656 6657
6657 SupervisedUserService* supervised_user_service = 6658 SupervisedUserService* supervised_user_service =
6658 SupervisedUserServiceFactory::GetForProfile(profile()); 6659 SupervisedUserServiceFactory::GetForProfile(profile());
6659 GetManagementPolicy()->RegisterProvider(supervised_user_service); 6660 GetManagementPolicy()->RegisterProvider(supervised_user_service);
6660 6661
6661 base::FilePath path1 = data_dir().AppendASCII("good.crx"); 6662 base::FilePath path1 = data_dir().AppendASCII("good.crx");
6662 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); 6663 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
6663 const Extension* extensions[] = { 6664 const Extension* extensions[] = {
6664 InstallCRX(path1, INSTALL_FAILED), 6665 InstallCRX(path1, INSTALL_FAILED),
6665 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) 6666 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)
6666 }; 6667 };
6667 6668
6668 // Only the extension with the "installed by custodian" flag should have been 6669 // Only the extension with the "installed by custodian" flag should have been
6669 // installed and enabled. 6670 // installed and enabled.
6670 EXPECT_FALSE(extensions[0]); 6671 EXPECT_FALSE(extensions[0]);
6671 ASSERT_TRUE(extensions[1]); 6672 ASSERT_TRUE(extensions[1]);
6672 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); 6673 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id()));
6673 } 6674 }
6674 6675
6676 MATCHER_P(EqualVersion, version, "") { return arg.Equals(version); }
6677
6675 TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithoutPermissionIncrease) { 6678 TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithoutPermissionIncrease) {
6676 ExtensionServiceInitParams params = CreateDefaultInitParams(); 6679 ExtensionServiceInitParams params = CreateDefaultInitParams();
6677 params.profile_is_supervised = true; 6680 params.profile_is_supervised = true;
6678 InitializeExtensionService(params); 6681 InitializeExtensionService(params);
6679 6682
6680 SupervisedUserService* supervised_user_service = 6683 SupervisedUserService* supervised_user_service =
6681 SupervisedUserServiceFactory::GetForProfile(profile()); 6684 SupervisedUserServiceFactory::GetForProfile(profile());
6682 GetManagementPolicy()->RegisterProvider(supervised_user_service); 6685 GetManagementPolicy()->RegisterProvider(supervised_user_service);
6683 6686
6684 base::FilePath base_path = data_dir().AppendASCII("autoupdate"); 6687 base::FilePath base_path = data_dir().AppendASCII("autoupdate");
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
6730 // The extension must now be installed and enabled. 6733 // The extension must now be installed and enabled.
6731 ASSERT_TRUE(extension); 6734 ASSERT_TRUE(extension);
6732 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); 6735 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
6733 6736
6734 // Save the id, as the extension object will be destroyed during updating. 6737 // Save the id, as the extension object will be destroyed during updating.
6735 std::string id = extension->id(); 6738 std::string id = extension->id();
6736 6739
6737 std::string old_version = extension->VersionString(); 6740 std::string old_version = extension->VersionString();
6738 6741
6739 // Update to a new version with increased permissions. 6742 // Update to a new version with increased permissions.
6740 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(id, testing::_)); 6743 EXPECT_CALL(*creator,
6744 CreateExtensionUpdateRequest(id,
6745 EqualVersion(base::Version("2.0.0.0")),
6746 testing::_));
6741 path = base_path.AppendASCII("v2"); 6747 path = base_path.AppendASCII("v2");
6742 PackCRXAndUpdateExtension(id, path, pem_path, DISABLED); 6748 PackCRXAndUpdateExtension(id, path, pem_path, DISABLED);
6743 6749
6744 // The extension should still be there, but disabled. 6750 // The extension should still be there, but disabled.
6745 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 6751 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
6746 extension = registry()->disabled_extensions().GetByID(id); 6752 extension = registry()->disabled_extensions().GetByID(id);
6747 ASSERT_TRUE(extension); 6753 ASSERT_TRUE(extension);
6748 // The version should have changed. 6754 // The version should have changed.
6749 EXPECT_NE(extension->VersionString(), old_version); 6755 EXPECT_NE(extension->VersionString(), old_version);
6750 } 6756 }
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
7722 7728
7723 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 7729 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
7724 content::Source<Profile>(profile()), 7730 content::Source<Profile>(profile()),
7725 content::NotificationService::NoDetails()); 7731 content::NotificationService::NoDetails());
7726 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 7732 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
7727 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 7733 EXPECT_EQ(0u, registry()->enabled_extensions().size());
7728 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 7734 EXPECT_EQ(0u, registry()->disabled_extensions().size());
7729 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 7735 EXPECT_EQ(0u, registry()->terminated_extensions().size());
7730 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 7736 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
7731 } 7737 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698