| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/settings/session_manager_operation.h" | 5 #include "chrome/browser/chromeos/settings/session_manager_operation.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 14 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" |
| 15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" | 15 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" |
| 16 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 16 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 17 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 17 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "components/ownership/mock_owner_key_util.h" | 19 #include "components/ownership/mock_owner_key_util.h" |
| 20 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 20 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 21 #include "components/policy/core/common/cloud/cloud_policy_validator.h" | 21 #include "components/policy/core/common/cloud/cloud_policy_validator.h" |
| 22 #include "components/policy/core/common/cloud/policy_builder.h" | 22 #include "components/policy/core/common/cloud/policy_builder.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
| 24 #include "crypto/rsa_private_key.h" | 24 #include "crypto/rsa_private_key.h" |
| 25 #include "policy/proto/device_management_backend.pb.h" | 25 #include "policy/proto/device_management_backend.pb.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 namespace em = enterprise_management; | 29 namespace em = enterprise_management; |
| 30 | 30 |
| 31 using testing::Mock; | 31 using testing::Mock; |
| 32 using testing::_; | 32 using testing::_; |
| 33 | 33 |
| 34 namespace chromeos { | 34 namespace chromeos { |
| 35 | 35 |
| 36 class SessionManagerOperationTest : public testing::Test { | 36 class SessionManagerOperationTest : public testing::Test { |
| 37 public: | 37 public: |
| 38 SessionManagerOperationTest() | 38 SessionManagerOperationTest() |
| 39 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 39 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 40 file_thread_(content::BrowserThread::FILE, &message_loop_), | 40 file_thread_(content::BrowserThread::FILE, &message_loop_), |
| 41 owner_key_util_(new ownership::MockOwnerKeyUtil()), | 41 owner_key_util_(new ownership::MockOwnerKeyUtil()), |
| 42 validated_(false) { | 42 validated_(false) { |
| 43 OwnerSettingsServiceChromeOSFactory::GetInstance() | 43 OwnerSettingsServiceFactory::GetInstance()->SetOwnerKeyUtilForTesting( |
| 44 ->SetOwnerKeyUtilForTesting(owner_key_util_); | 44 owner_key_util_); |
| 45 } | 45 } |
| 46 | 46 |
| 47 virtual void SetUp() OVERRIDE { | 47 virtual void SetUp() OVERRIDE { |
| 48 policy_.payload().mutable_pinned_apps()->add_app_id("fake-app"); | 48 policy_.payload().mutable_pinned_apps()->add_app_id("fake-app"); |
| 49 policy_.Build(); | 49 policy_.Build(); |
| 50 | 50 |
| 51 profile_.reset(new TestingProfile()); | 51 profile_.reset(new TestingProfile()); |
| 52 service_ = | 52 service_ = OwnerSettingsServiceFactory::GetForProfile(profile_.get()); |
| 53 OwnerSettingsServiceChromeOSFactory::GetForProfile(profile_.get()); | |
| 54 } | 53 } |
| 55 | 54 |
| 56 MOCK_METHOD2(OnOperationCompleted, | 55 MOCK_METHOD2(OnOperationCompleted, |
| 57 void(SessionManagerOperation*, DeviceSettingsService::Status)); | 56 void(SessionManagerOperation*, DeviceSettingsService::Status)); |
| 58 | 57 |
| 59 void CheckSuccessfulValidation( | 58 void CheckSuccessfulValidation( |
| 60 policy::DeviceCloudPolicyValidator* validator) { | 59 policy::DeviceCloudPolicyValidator* validator) { |
| 61 EXPECT_TRUE(validator->success()); | 60 EXPECT_TRUE(validator->success()); |
| 62 EXPECT_TRUE(validator->payload().get()); | 61 EXPECT_TRUE(validator->payload().get()); |
| 63 EXPECT_EQ(validator->payload()->SerializeAsString(), | 62 EXPECT_EQ(validator->payload()->SerializeAsString(), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 76 protected: | 75 protected: |
| 77 base::MessageLoop message_loop_; | 76 base::MessageLoop message_loop_; |
| 78 content::TestBrowserThread ui_thread_; | 77 content::TestBrowserThread ui_thread_; |
| 79 content::TestBrowserThread file_thread_; | 78 content::TestBrowserThread file_thread_; |
| 80 | 79 |
| 81 policy::DevicePolicyBuilder policy_; | 80 policy::DevicePolicyBuilder policy_; |
| 82 DeviceSettingsTestHelper device_settings_test_helper_; | 81 DeviceSettingsTestHelper device_settings_test_helper_; |
| 83 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_; | 82 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_; |
| 84 | 83 |
| 85 scoped_ptr<TestingProfile> profile_; | 84 scoped_ptr<TestingProfile> profile_; |
| 86 OwnerSettingsServiceChromeOS* service_; | 85 OwnerSettingsService* service_; |
| 87 | 86 |
| 88 bool validated_; | 87 bool validated_; |
| 89 | 88 |
| 90 private: | 89 private: |
| 91 DISALLOW_COPY_AND_ASSIGN(SessionManagerOperationTest); | 90 DISALLOW_COPY_AND_ASSIGN(SessionManagerOperationTest); |
| 92 }; | 91 }; |
| 93 | 92 |
| 94 TEST_F(SessionManagerOperationTest, LoadNoPolicyNoKey) { | 93 TEST_F(SessionManagerOperationTest, LoadNoPolicyNoKey) { |
| 95 LoadSettingsOperation op( | 94 LoadSettingsOperation op( |
| 96 base::Bind(&SessionManagerOperationTest::OnOperationCompleted, | 95 base::Bind(&SessionManagerOperationTest::OnOperationCompleted, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 213 |
| 215 TEST_F(SessionManagerOperationTest, SignAndStoreSettings) { | 214 TEST_F(SessionManagerOperationTest, SignAndStoreSettings) { |
| 216 owner_key_util_->SetPrivateKey(policy_.GetSigningKey()); | 215 owner_key_util_->SetPrivateKey(policy_.GetSigningKey()); |
| 217 service_->OnTPMTokenReady(true /* is ready */); | 216 service_->OnTPMTokenReady(true /* is ready */); |
| 218 | 217 |
| 219 scoped_ptr<em::PolicyData> policy(new em::PolicyData(policy_.policy_data())); | 218 scoped_ptr<em::PolicyData> policy(new em::PolicyData(policy_.policy_data())); |
| 220 SignAndStoreSettingsOperation op( | 219 SignAndStoreSettingsOperation op( |
| 221 base::Bind(&SessionManagerOperationTest::OnOperationCompleted, | 220 base::Bind(&SessionManagerOperationTest::OnOperationCompleted, |
| 222 base::Unretained(this)), | 221 base::Unretained(this)), |
| 223 policy.Pass()); | 222 policy.Pass()); |
| 224 op.set_owner_settings_service(service_->as_weak_ptr()); | 223 op.set_delegate(service_->as_weak_ptr()); |
| 225 | 224 |
| 226 EXPECT_CALL(*this, | 225 EXPECT_CALL(*this, |
| 227 OnOperationCompleted( | 226 OnOperationCompleted( |
| 228 &op, DeviceSettingsService::STORE_SUCCESS)); | 227 &op, DeviceSettingsService::STORE_SUCCESS)); |
| 229 op.Start(&device_settings_test_helper_, owner_key_util_, NULL); | 228 op.Start(&device_settings_test_helper_, owner_key_util_, NULL); |
| 230 device_settings_test_helper_.Flush(); | 229 device_settings_test_helper_.Flush(); |
| 231 Mock::VerifyAndClearExpectations(this); | 230 Mock::VerifyAndClearExpectations(this); |
| 232 | 231 |
| 233 // The blob should validate. | 232 // The blob should validate. |
| 234 scoped_ptr<em::PolicyFetchResponse> policy_response( | 233 scoped_ptr<em::PolicyFetchResponse> policy_response( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 message_loop_.RunUntilIdle(); | 266 message_loop_.RunUntilIdle(); |
| 268 EXPECT_TRUE(validated_); | 267 EXPECT_TRUE(validated_); |
| 269 | 268 |
| 270 // Loaded device settings should match what the operation received. | 269 // Loaded device settings should match what the operation received. |
| 271 ASSERT_TRUE(op.device_settings().get()); | 270 ASSERT_TRUE(op.device_settings().get()); |
| 272 EXPECT_EQ(policy_.payload().SerializeAsString(), | 271 EXPECT_EQ(policy_.payload().SerializeAsString(), |
| 273 op.device_settings()->SerializeAsString()); | 272 op.device_settings()->SerializeAsString()); |
| 274 } | 273 } |
| 275 | 274 |
| 276 } // namespace chromeos | 275 } // namespace chromeos |
| OLD | NEW |