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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 #include "sync/api/syncable_service.h" | 127 #include "sync/api/syncable_service.h" |
128 #include "sync/protocol/app_specifics.pb.h" | 128 #include "sync/protocol/app_specifics.pb.h" |
129 #include "sync/protocol/extension_specifics.pb.h" | 129 #include "sync/protocol/extension_specifics.pb.h" |
130 #include "sync/protocol/sync.pb.h" | 130 #include "sync/protocol/sync.pb.h" |
131 #include "testing/gtest/include/gtest/gtest.h" | 131 #include "testing/gtest/include/gtest/gtest.h" |
132 #include "testing/platform_test.h" | 132 #include "testing/platform_test.h" |
133 #include "ui/base/l10n/l10n_util.h" | 133 #include "ui/base/l10n/l10n_util.h" |
134 #include "url/gurl.h" | 134 #include "url/gurl.h" |
135 | 135 |
136 #if defined(ENABLE_SUPERVISED_USERS) | 136 #if defined(ENABLE_SUPERVISED_USERS) |
| 137 #include "chrome/browser/supervised_user/permission_request_creator.h" |
137 #include "chrome/browser/supervised_user/supervised_user_service.h" | 138 #include "chrome/browser/supervised_user/supervised_user_service.h" |
138 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 139 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
139 #endif | 140 #endif |
140 | 141 |
141 #if defined(OS_CHROMEOS) | 142 #if defined(OS_CHROMEOS) |
142 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | 143 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" |
143 #include "chrome/browser/chromeos/settings/cros_settings.h" | 144 #include "chrome/browser/chromeos/settings/cros_settings.h" |
144 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 145 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
145 #endif | 146 #endif |
146 | 147 |
(...skipping 6455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6602 const extensions::PendingExtensionInfo* info; | 6603 const extensions::PendingExtensionInfo* info; |
6603 EXPECT_TRUE( | 6604 EXPECT_TRUE( |
6604 (info = service()->pending_extension_manager()->GetById(good_crx))); | 6605 (info = service()->pending_extension_manager()->GetById(good_crx))); |
6605 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); | 6606 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); |
6606 EXPECT_TRUE(info->is_from_sync()); | 6607 EXPECT_TRUE(info->is_from_sync()); |
6607 EXPECT_EQ(Manifest::INTERNAL, info->install_source()); | 6608 EXPECT_EQ(Manifest::INTERNAL, info->install_source()); |
6608 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. | 6609 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. |
6609 } | 6610 } |
6610 | 6611 |
6611 #if defined(ENABLE_SUPERVISED_USERS) | 6612 #if defined(ENABLE_SUPERVISED_USERS) |
| 6613 class MockPermissionRequestCreator : public PermissionRequestCreator { |
| 6614 public: |
| 6615 MockPermissionRequestCreator() {} |
| 6616 ~MockPermissionRequestCreator() override {} |
| 6617 |
| 6618 bool IsEnabled() const override { return true; } |
| 6619 |
| 6620 void CreateURLAccessRequest(const GURL& url_requested, |
| 6621 const SuccessCallback& callback) override { |
| 6622 FAIL(); |
| 6623 } |
| 6624 |
| 6625 MOCK_METHOD2(CreateExtensionUpdateRequest, |
| 6626 void(const std::string& extension_id, |
| 6627 const SupervisedUserService::SuccessCallback& callback)); |
| 6628 |
| 6629 private: |
| 6630 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator); |
| 6631 }; |
| 6632 |
6612 TEST_F(ExtensionServiceTest, SupervisedUser_InstallOnlyAllowedByCustodian) { | 6633 TEST_F(ExtensionServiceTest, SupervisedUser_InstallOnlyAllowedByCustodian) { |
6613 ExtensionServiceInitParams params = CreateDefaultInitParams(); | 6634 ExtensionServiceInitParams params = CreateDefaultInitParams(); |
6614 params.profile_is_supervised = true; | 6635 params.profile_is_supervised = true; |
6615 InitializeExtensionService(params); | 6636 InitializeExtensionService(params); |
6616 | 6637 |
6617 SupervisedUserService* supervised_user_service = | 6638 SupervisedUserService* supervised_user_service = |
6618 SupervisedUserServiceFactory::GetForProfile(profile()); | 6639 SupervisedUserServiceFactory::GetForProfile(profile()); |
6619 GetManagementPolicy()->RegisterProvider(supervised_user_service); | 6640 GetManagementPolicy()->RegisterProvider(supervised_user_service); |
6620 | 6641 |
6621 base::FilePath path1 = data_dir().AppendASCII("good.crx"); | 6642 base::FilePath path1 = data_dir().AppendASCII("good.crx"); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6669 } | 6690 } |
6670 | 6691 |
6671 TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithPermissionIncrease) { | 6692 TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithPermissionIncrease) { |
6672 ExtensionServiceInitParams params = CreateDefaultInitParams(); | 6693 ExtensionServiceInitParams params = CreateDefaultInitParams(); |
6673 params.profile_is_supervised = true; | 6694 params.profile_is_supervised = true; |
6674 InitializeExtensionService(params); | 6695 InitializeExtensionService(params); |
6675 | 6696 |
6676 SupervisedUserService* supervised_user_service = | 6697 SupervisedUserService* supervised_user_service = |
6677 SupervisedUserServiceFactory::GetForProfile(profile()); | 6698 SupervisedUserServiceFactory::GetForProfile(profile()); |
6678 GetManagementPolicy()->RegisterProvider(supervised_user_service); | 6699 GetManagementPolicy()->RegisterProvider(supervised_user_service); |
| 6700 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
| 6701 supervised_user_service->AddPermissionRequestCreator( |
| 6702 make_scoped_ptr(creator)); |
6679 | 6703 |
6680 base::FilePath base_path = data_dir().AppendASCII("permissions_increase"); | 6704 base::FilePath base_path = data_dir().AppendASCII("permissions_increase"); |
6681 base::FilePath pem_path = base_path.AppendASCII("permissions.pem"); | 6705 base::FilePath pem_path = base_path.AppendASCII("permissions.pem"); |
6682 | 6706 |
6683 base::FilePath path = base_path.AppendASCII("v1"); | 6707 base::FilePath path = base_path.AppendASCII("v1"); |
6684 const Extension* extension = | 6708 const Extension* extension = |
6685 PackAndInstallCRX(path, pem_path, INSTALL_NEW, | 6709 PackAndInstallCRX(path, pem_path, INSTALL_NEW, |
6686 Extension::WAS_INSTALLED_BY_CUSTODIAN); | 6710 Extension::WAS_INSTALLED_BY_CUSTODIAN); |
6687 // The extension must now be installed and enabled. | 6711 // The extension must now be installed and enabled. |
6688 ASSERT_TRUE(extension); | 6712 ASSERT_TRUE(extension); |
6689 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); | 6713 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); |
6690 | 6714 |
6691 // Save the id, as the extension object will be destroyed during updating. | 6715 // Save the id, as the extension object will be destroyed during updating. |
6692 std::string id = extension->id(); | 6716 std::string id = extension->id(); |
6693 | 6717 |
6694 std::string old_version = extension->VersionString(); | 6718 std::string old_version = extension->VersionString(); |
6695 | 6719 |
6696 // Update to a new version with increased permissions. | 6720 // Update to a new version with increased permissions. |
| 6721 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(id, testing::_)); |
6697 path = base_path.AppendASCII("v2"); | 6722 path = base_path.AppendASCII("v2"); |
6698 PackCRXAndUpdateExtension(id, path, pem_path, DISABLED); | 6723 PackCRXAndUpdateExtension(id, path, pem_path, DISABLED); |
6699 | 6724 |
6700 // The extension should still be there, but disabled. | 6725 // The extension should still be there, but disabled. |
6701 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 6726 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
6702 extension = registry()->disabled_extensions().GetByID(id); | 6727 extension = registry()->disabled_extensions().GetByID(id); |
6703 ASSERT_TRUE(extension); | 6728 ASSERT_TRUE(extension); |
6704 // The version should have changed. | 6729 // The version should have changed. |
6705 EXPECT_NE(extension->VersionString(), old_version); | 6730 EXPECT_NE(extension->VersionString(), old_version); |
6706 } | 6731 } |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7678 | 7703 |
7679 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 7704 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
7680 content::Source<Profile>(profile()), | 7705 content::Source<Profile>(profile()), |
7681 content::NotificationService::NoDetails()); | 7706 content::NotificationService::NoDetails()); |
7682 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 7707 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
7683 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 7708 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
7684 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 7709 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
7685 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 7710 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
7686 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 7711 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
7687 } | 7712 } |
OLD | NEW |