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

Side by Side Diff: chrome/browser/chromeos/settings/session_manager_operation_unittest.cc

Issue 548323003: Non-plafrom-specific part of an OwnerSettingsService is moved to components/ownership/*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes to *.gypi and *.gn files. Created 6 years, 3 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) 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.h" 14 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
15 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" 15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.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 OwnerSettingsServiceFactory::GetInstance()->SetOwnerKeyUtilForTesting( 43 OwnerSettingsServiceChromeOSFactory::GetInstance()
44 owner_key_util_); 44 ->SetOwnerKeyUtilForTesting(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_ = OwnerSettingsServiceFactory::GetForProfile(profile_.get()); 52 service_ =
53 OwnerSettingsServiceChromeOSFactory::GetForProfile(profile_.get());
53 } 54 }
54 55
55 MOCK_METHOD2(OnOperationCompleted, 56 MOCK_METHOD2(OnOperationCompleted,
56 void(SessionManagerOperation*, DeviceSettingsService::Status)); 57 void(SessionManagerOperation*, DeviceSettingsService::Status));
57 58
58 void CheckSuccessfulValidation( 59 void CheckSuccessfulValidation(
59 policy::DeviceCloudPolicyValidator* validator) { 60 policy::DeviceCloudPolicyValidator* validator) {
60 EXPECT_TRUE(validator->success()); 61 EXPECT_TRUE(validator->success());
61 EXPECT_TRUE(validator->payload().get()); 62 EXPECT_TRUE(validator->payload().get());
62 EXPECT_EQ(validator->payload()->SerializeAsString(), 63 EXPECT_EQ(validator->payload()->SerializeAsString(),
(...skipping 12 matching lines...) Expand all
75 protected: 76 protected:
76 base::MessageLoop message_loop_; 77 base::MessageLoop message_loop_;
77 content::TestBrowserThread ui_thread_; 78 content::TestBrowserThread ui_thread_;
78 content::TestBrowserThread file_thread_; 79 content::TestBrowserThread file_thread_;
79 80
80 policy::DevicePolicyBuilder policy_; 81 policy::DevicePolicyBuilder policy_;
81 DeviceSettingsTestHelper device_settings_test_helper_; 82 DeviceSettingsTestHelper device_settings_test_helper_;
82 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_; 83 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_;
83 84
84 scoped_ptr<TestingProfile> profile_; 85 scoped_ptr<TestingProfile> profile_;
85 OwnerSettingsService* service_; 86 OwnerSettingsServiceChromeOS* service_;
86 87
87 bool validated_; 88 bool validated_;
88 89
89 private: 90 private:
90 DISALLOW_COPY_AND_ASSIGN(SessionManagerOperationTest); 91 DISALLOW_COPY_AND_ASSIGN(SessionManagerOperationTest);
91 }; 92 };
92 93
93 TEST_F(SessionManagerOperationTest, LoadNoPolicyNoKey) { 94 TEST_F(SessionManagerOperationTest, LoadNoPolicyNoKey) {
94 LoadSettingsOperation op( 95 LoadSettingsOperation op(
95 base::Bind(&SessionManagerOperationTest::OnOperationCompleted, 96 base::Bind(&SessionManagerOperationTest::OnOperationCompleted,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 214
214 TEST_F(SessionManagerOperationTest, SignAndStoreSettings) { 215 TEST_F(SessionManagerOperationTest, SignAndStoreSettings) {
215 owner_key_util_->SetPrivateKey(policy_.GetSigningKey()); 216 owner_key_util_->SetPrivateKey(policy_.GetSigningKey());
216 service_->OnTPMTokenReady(true /* is ready */); 217 service_->OnTPMTokenReady(true /* is ready */);
217 218
218 scoped_ptr<em::PolicyData> policy(new em::PolicyData(policy_.policy_data())); 219 scoped_ptr<em::PolicyData> policy(new em::PolicyData(policy_.policy_data()));
219 SignAndStoreSettingsOperation op( 220 SignAndStoreSettingsOperation op(
220 base::Bind(&SessionManagerOperationTest::OnOperationCompleted, 221 base::Bind(&SessionManagerOperationTest::OnOperationCompleted,
221 base::Unretained(this)), 222 base::Unretained(this)),
222 policy.Pass()); 223 policy.Pass());
223 op.set_delegate(service_->as_weak_ptr()); 224 op.set_owner_settings_service(service_->as_weak_ptr());
224 225
225 EXPECT_CALL(*this, 226 EXPECT_CALL(*this,
226 OnOperationCompleted( 227 OnOperationCompleted(
227 &op, DeviceSettingsService::STORE_SUCCESS)); 228 &op, DeviceSettingsService::STORE_SUCCESS));
228 op.Start(&device_settings_test_helper_, owner_key_util_, NULL); 229 op.Start(&device_settings_test_helper_, owner_key_util_, NULL);
229 device_settings_test_helper_.Flush(); 230 device_settings_test_helper_.Flush();
230 Mock::VerifyAndClearExpectations(this); 231 Mock::VerifyAndClearExpectations(this);
231 232
232 // The blob should validate. 233 // The blob should validate.
233 scoped_ptr<em::PolicyFetchResponse> policy_response( 234 scoped_ptr<em::PolicyFetchResponse> policy_response(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 message_loop_.RunUntilIdle(); 267 message_loop_.RunUntilIdle();
267 EXPECT_TRUE(validated_); 268 EXPECT_TRUE(validated_);
268 269
269 // Loaded device settings should match what the operation received. 270 // Loaded device settings should match what the operation received.
270 ASSERT_TRUE(op.device_settings().get()); 271 ASSERT_TRUE(op.device_settings().get());
271 EXPECT_EQ(policy_.payload().SerializeAsString(), 272 EXPECT_EQ(policy_.payload().SerializeAsString(),
272 op.device_settings()->SerializeAsString()); 273 op.device_settings()->SerializeAsString());
273 } 274 }
274 275
275 } // namespace chromeos 276 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698