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

Side by Side Diff: chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api_unittest.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 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 "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_plat form_keys_api.h" 5 #include "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_plat form_keys_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // Derived classes can override this method to set the required authenticated 201 // Derived classes can override this method to set the required authenticated
202 // user in the SigninManager class. 202 // user in the SigninManager class.
203 virtual void SetAuthenticatedUser() { 203 virtual void SetAuthenticatedUser() {
204 SigninManagerFactory::GetForProfile(browser()->profile()) 204 SigninManagerFactory::GetForProfile(browser()->profile())
205 ->SetAuthenticatedAccountInfo("12345", kUserEmail); 205 ->SetAuthenticatedAccountInfo("12345", kUserEmail);
206 } 206 }
207 207
208 // Like extension_function_test_utils::RunFunctionAndReturnError but with an 208 // Like extension_function_test_utils::RunFunctionAndReturnError but with an
209 // explicit ListValue. 209 // explicit ListValue.
210 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, 210 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function,
211 scoped_ptr<base::ListValue> args, 211 std::unique_ptr<base::ListValue> args,
212 Browser* browser) { 212 Browser* browser) {
213 scoped_refptr<ExtensionFunction> function_owner(function); 213 scoped_refptr<ExtensionFunction> function_owner(function);
214 // Without a callback the function will not generate a result. 214 // Without a callback the function will not generate a result.
215 function->set_has_callback(true); 215 function->set_has_callback(true);
216 utils::RunFunction(function, std::move(args), browser, utils::NONE); 216 utils::RunFunction(function, std::move(args), browser, utils::NONE);
217 EXPECT_FALSE(function->GetResultList()) << "Did not expect a result"; 217 EXPECT_FALSE(function->GetResultList()) << "Did not expect a result";
218 return function->GetError(); 218 return function->GetError();
219 } 219 }
220 220
221 // Like extension_function_test_utils::RunFunctionAndReturnSingleResult but 221 // Like extension_function_test_utils::RunFunctionAndReturnSingleResult but
222 // with an explicit ListValue. 222 // with an explicit ListValue.
223 base::Value* RunFunctionAndReturnSingleResult( 223 base::Value* RunFunctionAndReturnSingleResult(
224 UIThreadExtensionFunction* function, 224 UIThreadExtensionFunction* function,
225 scoped_ptr<base::ListValue> args, 225 std::unique_ptr<base::ListValue> args,
226 Browser* browser) { 226 Browser* browser) {
227 scoped_refptr<ExtensionFunction> function_owner(function); 227 scoped_refptr<ExtensionFunction> function_owner(function);
228 // Without a callback the function will not generate a result. 228 // Without a callback the function will not generate a result.
229 function->set_has_callback(true); 229 function->set_has_callback(true);
230 utils::RunFunction(function, std::move(args), browser, utils::NONE); 230 utils::RunFunction(function, std::move(args), browser, utils::NONE);
231 EXPECT_TRUE(function->GetError().empty()) << "Unexpected error: " 231 EXPECT_TRUE(function->GetError().empty()) << "Unexpected error: "
232 << function->GetError(); 232 << function->GetError();
233 const base::Value* single_result = NULL; 233 const base::Value* single_result = NULL;
234 if (function->GetResultList() != NULL && 234 if (function->GetResultList() != NULL &&
235 function->GetResultList()->Get(0, &single_result)) { 235 function->GetResultList()->Get(0, &single_result)) {
(...skipping 25 matching lines...) Expand all
261 func_(new EnterprisePlatformKeysChallengeMachineKeyFunction(&impl_)) { 261 func_(new EnterprisePlatformKeysChallengeMachineKeyFunction(&impl_)) {
262 func_->set_extension(extension_.get()); 262 func_->set_extension(extension_.get());
263 } 263 }
264 264
265 // Returns an error string for the given code. 265 // Returns an error string for the given code.
266 std::string GetCertificateError(int error_code) { 266 std::string GetCertificateError(int error_code) {
267 return base::StringPrintf( 267 return base::StringPrintf(
268 EPKPChallengeMachineKey::kGetCertificateFailedError, error_code); 268 EPKPChallengeMachineKey::kGetCertificateFailedError, error_code);
269 } 269 }
270 270
271 scoped_ptr<base::ListValue> CreateArgs() { 271 std::unique_ptr<base::ListValue> CreateArgs() {
272 scoped_ptr<base::ListValue> args(new base::ListValue); 272 std::unique_ptr<base::ListValue> args(new base::ListValue);
273 args->Append(base::BinaryValue::CreateWithCopiedBuffer("challenge", 9)); 273 args->Append(base::BinaryValue::CreateWithCopiedBuffer("challenge", 9));
274 return args; 274 return args;
275 } 275 }
276 276
277 EPKPChallengeMachineKey impl_; 277 EPKPChallengeMachineKey impl_;
278 scoped_refptr<EnterprisePlatformKeysChallengeMachineKeyFunction> func_; 278 scoped_refptr<EnterprisePlatformKeysChallengeMachineKeyFunction> func_;
279 base::ListValue args_; 279 base::ListValue args_;
280 }; 280 };
281 281
282 TEST_F(EPKChallengeMachineKeyTest, NonEnterpriseDevice) { 282 TEST_F(EPKChallengeMachineKeyTest, NonEnterpriseDevice) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 _, _, _, _)) 346 _, _, _, _))
347 .Times(1); 347 .Times(1);
348 // SignEnterpriseChallenge must be called exactly once. 348 // SignEnterpriseChallenge must be called exactly once.
349 EXPECT_CALL( 349 EXPECT_CALL(
350 mock_async_method_caller_, 350 mock_async_method_caller_,
351 TpmAttestationSignEnterpriseChallenge( 351 TpmAttestationSignEnterpriseChallenge(
352 chromeos::attestation::KEY_DEVICE, cryptohome::Identification(), 352 chromeos::attestation::KEY_DEVICE, cryptohome::Identification(),
353 "attest-ent-machine", "google.com", "device_id", _, "challenge", _)) 353 "attest-ent-machine", "google.com", "device_id", _, "challenge", _))
354 .Times(1); 354 .Times(1);
355 355
356 scoped_ptr<base::Value> value( 356 std::unique_ptr<base::Value> value(
357 RunFunctionAndReturnSingleResult(func_.get(), CreateArgs(), browser())); 357 RunFunctionAndReturnSingleResult(func_.get(), CreateArgs(), browser()));
358 358
359 const base::BinaryValue* response; 359 const base::BinaryValue* response;
360 ASSERT_TRUE(value->GetAsBinary(&response)); 360 ASSERT_TRUE(value->GetAsBinary(&response));
361 EXPECT_EQ("response", 361 EXPECT_EQ("response",
362 std::string(response->GetBuffer(), response->GetSize())); 362 std::string(response->GetBuffer(), response->GetSize()));
363 } 363 }
364 364
365 TEST_F(EPKChallengeMachineKeyTest, AttestationNotPrepared) { 365 TEST_F(EPKChallengeMachineKeyTest, AttestationNotPrepared) {
366 EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) 366 EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_))
(...skipping 30 matching lines...) Expand all
397 // Set the user preferences. 397 // Set the user preferences.
398 prefs_->SetBoolean(prefs::kAttestationEnabled, true); 398 prefs_->SetBoolean(prefs::kAttestationEnabled, true);
399 } 399 }
400 400
401 // Returns an error string for the given code. 401 // Returns an error string for the given code.
402 std::string GetCertificateError(int error_code) { 402 std::string GetCertificateError(int error_code) {
403 return base::StringPrintf(EPKPChallengeUserKey::kGetCertificateFailedError, 403 return base::StringPrintf(EPKPChallengeUserKey::kGetCertificateFailedError,
404 error_code); 404 error_code);
405 } 405 }
406 406
407 scoped_ptr<base::ListValue> CreateArgs() { return CreateArgsInternal(true); } 407 std::unique_ptr<base::ListValue> CreateArgs() {
408 return CreateArgsInternal(true);
409 }
408 410
409 scoped_ptr<base::ListValue> CreateArgsNoRegister() { 411 std::unique_ptr<base::ListValue> CreateArgsNoRegister() {
410 return CreateArgsInternal(false); 412 return CreateArgsInternal(false);
411 } 413 }
412 414
413 scoped_ptr<base::ListValue> CreateArgsInternal(bool register_key) { 415 std::unique_ptr<base::ListValue> CreateArgsInternal(bool register_key) {
414 scoped_ptr<base::ListValue> args(new base::ListValue); 416 std::unique_ptr<base::ListValue> args(new base::ListValue);
415 args->Append(base::BinaryValue::CreateWithCopiedBuffer("challenge", 9)); 417 args->Append(base::BinaryValue::CreateWithCopiedBuffer("challenge", 9));
416 args->Append(new base::FundamentalValue(register_key)); 418 args->Append(new base::FundamentalValue(register_key));
417 return args; 419 return args;
418 } 420 }
419 421
420 EPKPChallengeUserKey impl_; 422 EPKPChallengeUserKey impl_;
421 scoped_refptr<EnterprisePlatformKeysChallengeUserKeyFunction> func_; 423 scoped_refptr<EnterprisePlatformKeysChallengeUserKeyFunction> func_;
422 }; 424 };
423 425
424 TEST_F(EPKChallengeUserKeyTest, UserPolicyDisabled) { 426 TEST_F(EPKChallengeUserKeyTest, UserPolicyDisabled) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 TpmAttestationSignEnterpriseChallenge( 521 TpmAttestationSignEnterpriseChallenge(
520 chromeos::attestation::KEY_USER, cryptohome_id, "attest-ent-user", 522 chromeos::attestation::KEY_USER, cryptohome_id, "attest-ent-user",
521 kUserEmail, "device_id", _, "challenge", _)) 523 kUserEmail, "device_id", _, "challenge", _))
522 .Times(1); 524 .Times(1);
523 // RegisterKey must be called exactly once. 525 // RegisterKey must be called exactly once.
524 EXPECT_CALL(mock_async_method_caller_, 526 EXPECT_CALL(mock_async_method_caller_,
525 TpmAttestationRegisterKey(chromeos::attestation::KEY_USER, 527 TpmAttestationRegisterKey(chromeos::attestation::KEY_USER,
526 cryptohome_id, "attest-ent-user", _)) 528 cryptohome_id, "attest-ent-user", _))
527 .Times(1); 529 .Times(1);
528 530
529 scoped_ptr<base::Value> value( 531 std::unique_ptr<base::Value> value(
530 RunFunctionAndReturnSingleResult(func_.get(), CreateArgs(), browser())); 532 RunFunctionAndReturnSingleResult(func_.get(), CreateArgs(), browser()));
531 533
532 const base::BinaryValue* response; 534 const base::BinaryValue* response;
533 ASSERT_TRUE(value->GetAsBinary(&response)); 535 ASSERT_TRUE(value->GetAsBinary(&response));
534 EXPECT_EQ("response", 536 EXPECT_EQ("response",
535 std::string(response->GetBuffer(), response->GetSize())); 537 std::string(response->GetBuffer(), response->GetSize()));
536 } 538 }
537 539
538 TEST_F(EPKChallengeUserKeyTest, AttestationNotPrepared) { 540 TEST_F(EPKChallengeUserKeyTest, AttestationNotPrepared) {
539 EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) 541 EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_))
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 AccountId::FromUserEmailGaiaId("test@chromium.com", "12345"); 599 AccountId::FromUserEmailGaiaId("test@chromium.com", "12345");
598 }; 600 };
599 601
600 TEST_F(EPKChallengeUserKeyUnmanagedUserTest, UserNotManaged) { 602 TEST_F(EPKChallengeUserKeyUnmanagedUserTest, UserNotManaged) {
601 EXPECT_EQ(EPKPChallengeKeyBase::kUserNotManaged, 603 EXPECT_EQ(EPKPChallengeKeyBase::kUserNotManaged,
602 RunFunctionAndReturnError(func_.get(), CreateArgs(), browser())); 604 RunFunctionAndReturnError(func_.get(), CreateArgs(), browser()));
603 } 605 }
604 606
605 } // namespace 607 } // namespace
606 } // namespace extensions 608 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698