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

Side by Side Diff: chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos_unittest.cc

Issue 1940153002: Use std::unique_ptr to express ownership of base::Value in PolicyMap::Entry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another-fix Created 4 years, 7 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/policy/user_cloud_policy_store_chromeos.h" 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h"
16 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
17 #include "base/threading/sequenced_worker_pool.h" 18 #include "base/threading/sequenced_worker_pool.h"
18 #include "chromeos/dbus/mock_cryptohome_client.h" 19 #include "chromeos/dbus/mock_cryptohome_client.h"
19 #include "chromeos/dbus/mock_session_manager_client.h" 20 #include "chromeos/dbus/mock_session_manager_client.h"
20 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 21 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
21 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" 22 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
22 #include "components/policy/core/common/cloud/policy_builder.h" 23 #include "components/policy/core/common/cloud/policy_builder.h"
23 #include "components/policy/core/common/policy_types.h" 24 #include "components/policy/core/common/policy_types.h"
24 #include "policy/policy_constants.h" 25 #include "policy/policy_constants.h"
25 #include "policy/proto/cloud_policy.pb.h" 26 #include "policy/proto/cloud_policy.pb.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 RunUntilIdle(); 112 RunUntilIdle();
112 } 113 }
113 114
114 // Verifies that store_->policy_map() has the HomepageLocation entry with 115 // Verifies that store_->policy_map() has the HomepageLocation entry with
115 // the |expected_value|. 116 // the |expected_value|.
116 void VerifyPolicyMap(const char* expected_value) { 117 void VerifyPolicyMap(const char* expected_value) {
117 EXPECT_EQ(1U, store_->policy_map().size()); 118 EXPECT_EQ(1U, store_->policy_map().size());
118 const PolicyMap::Entry* entry = 119 const PolicyMap::Entry* entry =
119 store_->policy_map().Get(key::kHomepageLocation); 120 store_->policy_map().Get(key::kHomepageLocation);
120 ASSERT_TRUE(entry); 121 ASSERT_TRUE(entry);
121 EXPECT_TRUE(base::StringValue(expected_value).Equals(entry->value)); 122 EXPECT_TRUE(base::StringValue(expected_value).Equals(entry->value.get()));
122 } 123 }
123 124
124 void StoreUserPolicyKey(const std::vector<uint8_t>& public_key) { 125 void StoreUserPolicyKey(const std::vector<uint8_t>& public_key) {
125 ASSERT_TRUE(base::CreateDirectory(user_policy_key_file().DirName())); 126 ASSERT_TRUE(base::CreateDirectory(user_policy_key_file().DirName()));
126 ASSERT_TRUE( 127 ASSERT_TRUE(
127 base::WriteFile(user_policy_key_file(), 128 base::WriteFile(user_policy_key_file(),
128 reinterpret_cast<const char*>(public_key.data()), 129 reinterpret_cast<const char*>(public_key.data()),
129 public_key.size())); 130 public_key.size()));
130 } 131 }
131 132
(...skipping 13 matching lines...) Expand all
145 .WillOnce(SaveArg<2>(&store_callback)); 146 .WillOnce(SaveArg<2>(&store_callback));
146 store_->Store(policy_.policy()); 147 store_->Store(policy_.policy());
147 RunUntilIdle(); 148 RunUntilIdle();
148 Mock::VerifyAndClearExpectations(&session_manager_client_); 149 Mock::VerifyAndClearExpectations(&session_manager_client_);
149 ASSERT_FALSE(store_callback.is_null()); 150 ASSERT_FALSE(store_callback.is_null());
150 151
151 // The new policy shouldn't be present yet. 152 // The new policy shouldn't be present yet.
152 PolicyMap previous_policy; 153 PolicyMap previous_policy;
153 EXPECT_EQ(previous_value != NULL, store_->policy() != NULL); 154 EXPECT_EQ(previous_value != NULL, store_->policy() != NULL);
154 if (previous_value) { 155 if (previous_value) {
155 previous_policy.Set(key::kHomepageLocation, 156 previous_policy.Set(
156 POLICY_LEVEL_MANDATORY, 157 key::kHomepageLocation, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
157 POLICY_SCOPE_USER, 158 POLICY_SOURCE_CLOUD,
158 POLICY_SOURCE_CLOUD, 159 base::WrapUnique(new base::StringValue(previous_value)), nullptr);
159 new base::StringValue(previous_value), NULL);
160 } 160 }
161 EXPECT_TRUE(previous_policy.Equals(store_->policy_map())); 161 EXPECT_TRUE(previous_policy.Equals(store_->policy_map()));
162 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); 162 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status());
163 163
164 // Store the new public key so that the validation after the retrieve 164 // Store the new public key so that the validation after the retrieve
165 // operation completes can verify the signature. 165 // operation completes can verify the signature.
166 if (new_public_key) 166 if (new_public_key)
167 StoreUserPolicyKey(*new_public_key); 167 StoreUserPolicyKey(*new_public_key);
168 168
169 // Let the store operation complete. 169 // Let the store operation complete.
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 Mock::VerifyAndClearExpectations(&cryptohome_client_); 663 Mock::VerifyAndClearExpectations(&cryptohome_client_);
664 664
665 EXPECT_FALSE(store_->policy()); 665 EXPECT_FALSE(store_->policy());
666 EXPECT_TRUE(store_->policy_map().empty()); 666 EXPECT_TRUE(store_->policy_map().empty());
667 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status()); 667 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status());
668 } 668 }
669 669
670 } // namespace 670 } // namespace
671 671
672 } // namespace policy 672 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698