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

Side by Side Diff: chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api_chromeos_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/easy_unlock_private/easy_unlock_private_ api.h" 5 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_ api.h"
6 6
7 #include <memory>
7 #include <string> 8 #include <string>
8 #include <utility> 9 #include <utility>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/ptr_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "chrome/browser/extensions/extension_api_unittest.h" 18 #include "chrome/browser/extensions/extension_api_unittest.h"
18 #include "chrome/browser/extensions/extension_function_test_utils.h" 19 #include "chrome/browser/extensions/extension_function_test_utils.h"
19 #include "chrome/browser/extensions/extension_system_factory.h" 20 #include "chrome/browser/extensions/extension_system_factory.h"
20 #include "chrome/browser/extensions/test_extension_prefs.h" 21 #include "chrome/browser/extensions/test_extension_prefs.h"
21 #include "chrome/browser/extensions/test_extension_system.h" 22 #include "chrome/browser/extensions/test_extension_system.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/signin/easy_unlock_app_manager.h" 24 #include "chrome/browser/signin/easy_unlock_app_manager.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 client_->GenerateEcP256KeyPair( 222 client_->GenerateEcP256KeyPair(
222 base::Bind(&CopyKeyPair, &private_key_2_unused, &public_key_2)); 223 base::Bind(&CopyKeyPair, &private_key_2_unused, &public_key_2));
223 224
224 std::string expected_result; 225 std::string expected_result;
225 client_->PerformECDHKeyAgreement( 226 client_->PerformECDHKeyAgreement(
226 private_key_1, 227 private_key_1,
227 public_key_2, 228 public_key_2,
228 base::Bind(&CopyData, &expected_result)); 229 base::Bind(&CopyData, &expected_result));
229 ASSERT_GT(expected_result.length(), 0u); 230 ASSERT_GT(expected_result.length(), 0u);
230 231
231 scoped_ptr<base::ListValue> args(new base::ListValue); 232 std::unique_ptr<base::ListValue> args(new base::ListValue);
232 args->Append(StringToBinaryValue(private_key_1)); 233 args->Append(StringToBinaryValue(private_key_1));
233 args->Append(StringToBinaryValue(public_key_2)); 234 args->Append(StringToBinaryValue(public_key_2));
234 235
235 ASSERT_TRUE(extension_function_test_utils::RunFunction( 236 ASSERT_TRUE(extension_function_test_utils::RunFunction(
236 function.get(), std::move(args), browser(), 237 function.get(), std::move(args), browser(),
237 extension_function_test_utils::NONE)); 238 extension_function_test_utils::NONE));
238 239
239 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get())); 240 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get()));
240 } 241 }
241 242
(...skipping 11 matching lines...) Expand all
253 create_options.encryption_type = easy_unlock::kEncryptionTypeAES256CBC; 254 create_options.encryption_type = easy_unlock::kEncryptionTypeAES256CBC;
254 create_options.signature_type = easy_unlock::kSignatureTypeHMACSHA256; 255 create_options.signature_type = easy_unlock::kSignatureTypeHMACSHA256;
255 256
256 std::string expected_result; 257 std::string expected_result;
257 client_->CreateSecureMessage( 258 client_->CreateSecureMessage(
258 "PAYLOAD", 259 "PAYLOAD",
259 create_options, 260 create_options,
260 base::Bind(&CopyData, &expected_result)); 261 base::Bind(&CopyData, &expected_result));
261 ASSERT_GT(expected_result.length(), 0u); 262 ASSERT_GT(expected_result.length(), 0u);
262 263
263 scoped_ptr<base::ListValue> args(new base::ListValue); 264 std::unique_ptr<base::ListValue> args(new base::ListValue);
264 args->Append(StringToBinaryValue("PAYLOAD")); 265 args->Append(StringToBinaryValue("PAYLOAD"));
265 args->Append(StringToBinaryValue("KEY")); 266 args->Append(StringToBinaryValue("KEY"));
266 base::DictionaryValue* options = new base::DictionaryValue(); 267 base::DictionaryValue* options = new base::DictionaryValue();
267 args->Append(options); 268 args->Append(options);
268 options->Set("associatedData", StringToBinaryValue("ASSOCIATED_DATA")); 269 options->Set("associatedData", StringToBinaryValue("ASSOCIATED_DATA"));
269 options->Set("publicMetadata", StringToBinaryValue("PUBLIC_METADATA")); 270 options->Set("publicMetadata", StringToBinaryValue("PUBLIC_METADATA"));
270 options->Set("verificationKeyId", 271 options->Set("verificationKeyId",
271 StringToBinaryValue("VERIFICATION_KEY_ID")); 272 StringToBinaryValue("VERIFICATION_KEY_ID"));
272 options->Set("decryptionKeyId", 273 options->Set("decryptionKeyId",
273 StringToBinaryValue("DECRYPTION_KEY_ID")); 274 StringToBinaryValue("DECRYPTION_KEY_ID"));
(...skipping 21 matching lines...) Expand all
295 create_options.encryption_type = easy_unlock::kEncryptionTypeNone; 296 create_options.encryption_type = easy_unlock::kEncryptionTypeNone;
296 create_options.signature_type = easy_unlock::kSignatureTypeHMACSHA256; 297 create_options.signature_type = easy_unlock::kSignatureTypeHMACSHA256;
297 298
298 std::string expected_result; 299 std::string expected_result;
299 client_->CreateSecureMessage( 300 client_->CreateSecureMessage(
300 "PAYLOAD", 301 "PAYLOAD",
301 create_options, 302 create_options,
302 base::Bind(&CopyData, &expected_result)); 303 base::Bind(&CopyData, &expected_result));
303 ASSERT_GT(expected_result.length(), 0u); 304 ASSERT_GT(expected_result.length(), 0u);
304 305
305 scoped_ptr<base::ListValue> args(new base::ListValue); 306 std::unique_ptr<base::ListValue> args(new base::ListValue);
306 args->Append(StringToBinaryValue("PAYLOAD")); 307 args->Append(StringToBinaryValue("PAYLOAD"));
307 args->Append(StringToBinaryValue("KEY")); 308 args->Append(StringToBinaryValue("KEY"));
308 base::DictionaryValue* options = new base::DictionaryValue(); 309 base::DictionaryValue* options = new base::DictionaryValue();
309 args->Append(options); 310 args->Append(options);
310 311
311 ASSERT_TRUE(extension_function_test_utils::RunFunction( 312 ASSERT_TRUE(extension_function_test_utils::RunFunction(
312 function.get(), std::move(args), browser(), 313 function.get(), std::move(args), browser(),
313 extension_function_test_utils::NONE)); 314 extension_function_test_utils::NONE));
314 315
315 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get())); 316 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get()));
(...skipping 11 matching lines...) Expand all
327 create_options.encryption_type = easy_unlock::kEncryptionTypeNone; 328 create_options.encryption_type = easy_unlock::kEncryptionTypeNone;
328 create_options.signature_type = easy_unlock::kSignatureTypeECDSAP256SHA256; 329 create_options.signature_type = easy_unlock::kSignatureTypeECDSAP256SHA256;
329 330
330 std::string expected_result; 331 std::string expected_result;
331 client_->CreateSecureMessage( 332 client_->CreateSecureMessage(
332 "PAYLOAD", 333 "PAYLOAD",
333 create_options, 334 create_options,
334 base::Bind(&CopyData, &expected_result)); 335 base::Bind(&CopyData, &expected_result));
335 ASSERT_GT(expected_result.length(), 0u); 336 ASSERT_GT(expected_result.length(), 0u);
336 337
337 scoped_ptr<base::ListValue> args(new base::ListValue); 338 std::unique_ptr<base::ListValue> args(new base::ListValue);
338 args->Append(StringToBinaryValue("PAYLOAD")); 339 args->Append(StringToBinaryValue("PAYLOAD"));
339 args->Append(StringToBinaryValue("KEY")); 340 args->Append(StringToBinaryValue("KEY"));
340 base::DictionaryValue* options = new base::DictionaryValue(); 341 base::DictionaryValue* options = new base::DictionaryValue();
341 args->Append(options); 342 args->Append(options);
342 options->Set("associatedData", 343 options->Set("associatedData",
343 StringToBinaryValue("ASSOCIATED_DATA")); 344 StringToBinaryValue("ASSOCIATED_DATA"));
344 options->Set("verificationKeyId", 345 options->Set("verificationKeyId",
345 StringToBinaryValue("VERIFICATION_KEY_ID")); 346 StringToBinaryValue("VERIFICATION_KEY_ID"));
346 options->SetString( 347 options->SetString(
347 "signType", 348 "signType",
(...skipping 17 matching lines...) Expand all
365 unwrap_options.encryption_type = easy_unlock::kEncryptionTypeAES256CBC; 366 unwrap_options.encryption_type = easy_unlock::kEncryptionTypeAES256CBC;
366 unwrap_options.signature_type = easy_unlock::kSignatureTypeHMACSHA256; 367 unwrap_options.signature_type = easy_unlock::kSignatureTypeHMACSHA256;
367 368
368 std::string expected_result; 369 std::string expected_result;
369 client_->UnwrapSecureMessage( 370 client_->UnwrapSecureMessage(
370 "MESSAGE", 371 "MESSAGE",
371 unwrap_options, 372 unwrap_options,
372 base::Bind(&CopyData, &expected_result)); 373 base::Bind(&CopyData, &expected_result));
373 ASSERT_GT(expected_result.length(), 0u); 374 ASSERT_GT(expected_result.length(), 0u);
374 375
375 scoped_ptr<base::ListValue> args(new base::ListValue); 376 std::unique_ptr<base::ListValue> args(new base::ListValue);
376 args->Append(StringToBinaryValue("MESSAGE")); 377 args->Append(StringToBinaryValue("MESSAGE"));
377 args->Append(StringToBinaryValue("KEY")); 378 args->Append(StringToBinaryValue("KEY"));
378 base::DictionaryValue* options = new base::DictionaryValue(); 379 base::DictionaryValue* options = new base::DictionaryValue();
379 args->Append(options); 380 args->Append(options);
380 options->Set("associatedData", StringToBinaryValue("ASSOCIATED_DATA")); 381 options->Set("associatedData", StringToBinaryValue("ASSOCIATED_DATA"));
381 options->SetString( 382 options->SetString(
382 "encryptType", 383 "encryptType",
383 api::ToString(api::ENCRYPTION_TYPE_AES_256_CBC)); 384 api::ToString(api::ENCRYPTION_TYPE_AES_256_CBC));
384 options->SetString( 385 options->SetString(
385 "signType", 386 "signType",
(...skipping 16 matching lines...) Expand all
402 unwrap_options.encryption_type = easy_unlock::kEncryptionTypeNone; 403 unwrap_options.encryption_type = easy_unlock::kEncryptionTypeNone;
403 unwrap_options.signature_type = easy_unlock::kSignatureTypeHMACSHA256; 404 unwrap_options.signature_type = easy_unlock::kSignatureTypeHMACSHA256;
404 405
405 std::string expected_result; 406 std::string expected_result;
406 client_->UnwrapSecureMessage( 407 client_->UnwrapSecureMessage(
407 "MESSAGE", 408 "MESSAGE",
408 unwrap_options, 409 unwrap_options,
409 base::Bind(&CopyData, &expected_result)); 410 base::Bind(&CopyData, &expected_result));
410 ASSERT_GT(expected_result.length(), 0u); 411 ASSERT_GT(expected_result.length(), 0u);
411 412
412 scoped_ptr<base::ListValue> args(new base::ListValue); 413 std::unique_ptr<base::ListValue> args(new base::ListValue);
413 args->Append(StringToBinaryValue("MESSAGE")); 414 args->Append(StringToBinaryValue("MESSAGE"));
414 args->Append(StringToBinaryValue("KEY")); 415 args->Append(StringToBinaryValue("KEY"));
415 base::DictionaryValue* options = new base::DictionaryValue(); 416 base::DictionaryValue* options = new base::DictionaryValue();
416 args->Append(options); 417 args->Append(options);
417 418
418 ASSERT_TRUE(extension_function_test_utils::RunFunction( 419 ASSERT_TRUE(extension_function_test_utils::RunFunction(
419 function.get(), std::move(args), browser(), 420 function.get(), std::move(args), browser(),
420 extension_function_test_utils::NONE)); 421 extension_function_test_utils::NONE));
421 422
422 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get())); 423 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get()));
(...skipping 10 matching lines...) Expand all
433 unwrap_options.encryption_type = easy_unlock::kEncryptionTypeNone; 434 unwrap_options.encryption_type = easy_unlock::kEncryptionTypeNone;
434 unwrap_options.signature_type = easy_unlock::kSignatureTypeECDSAP256SHA256; 435 unwrap_options.signature_type = easy_unlock::kSignatureTypeECDSAP256SHA256;
435 436
436 std::string expected_result; 437 std::string expected_result;
437 client_->UnwrapSecureMessage( 438 client_->UnwrapSecureMessage(
438 "MESSAGE", 439 "MESSAGE",
439 unwrap_options, 440 unwrap_options,
440 base::Bind(&CopyData, &expected_result)); 441 base::Bind(&CopyData, &expected_result));
441 ASSERT_GT(expected_result.length(), 0u); 442 ASSERT_GT(expected_result.length(), 0u);
442 443
443 scoped_ptr<base::ListValue> args(new base::ListValue); 444 std::unique_ptr<base::ListValue> args(new base::ListValue);
444 args->Append(StringToBinaryValue("MESSAGE")); 445 args->Append(StringToBinaryValue("MESSAGE"));
445 args->Append(StringToBinaryValue("KEY")); 446 args->Append(StringToBinaryValue("KEY"));
446 base::DictionaryValue* options = new base::DictionaryValue(); 447 base::DictionaryValue* options = new base::DictionaryValue();
447 args->Append(options); 448 args->Append(options);
448 options->Set("associatedData", 449 options->Set("associatedData",
449 StringToBinaryValue("ASSOCIATED_DATA")); 450 StringToBinaryValue("ASSOCIATED_DATA"));
450 options->SetString( 451 options->SetString(
451 "signType", 452 "signType",
452 api::ToString(api::SIGNATURE_TYPE_ECDSA_P256_SHA256)); 453 api::ToString(api::SIGNATURE_TYPE_ECDSA_P256_SHA256));
453 454
(...skipping 10 matching lines...) Expand all
464 void SetResult(bool success, const std::string& error) { 465 void SetResult(bool success, const std::string& error) {
465 this->success = success; 466 this->success = success;
466 this->error = error; 467 this->error = error;
467 } 468 }
468 469
469 bool success; 470 bool success;
470 std::string error; 471 std::string error;
471 }; 472 };
472 473
473 // Test factory to register EasyUnlockService. 474 // Test factory to register EasyUnlockService.
474 scoped_ptr<KeyedService> BuildTestEasyUnlockService( 475 std::unique_ptr<KeyedService> BuildTestEasyUnlockService(
475 content::BrowserContext* context) { 476 content::BrowserContext* context) {
476 scoped_ptr<EasyUnlockServiceRegular> service( 477 std::unique_ptr<EasyUnlockServiceRegular> service(
477 new EasyUnlockServiceRegular(Profile::FromBrowserContext(context))); 478 new EasyUnlockServiceRegular(Profile::FromBrowserContext(context)));
478 service->Initialize( 479 service->Initialize(
479 EasyUnlockAppManager::Create(extensions::ExtensionSystem::Get(context), 480 EasyUnlockAppManager::Create(extensions::ExtensionSystem::Get(context),
480 -1 /* manifest id */, base::FilePath())); 481 -1 /* manifest id */, base::FilePath()));
481 return std::move(service); 482 return std::move(service);
482 } 483 }
483 484
484 // A fake EventRouter that logs event it dispatches for testing. 485 // A fake EventRouter that logs event it dispatches for testing.
485 class FakeEventRouter : public extensions::EventRouter { 486 class FakeEventRouter : public extensions::EventRouter {
486 public: 487 public:
487 FakeEventRouter(Profile* profile, 488 FakeEventRouter(
488 scoped_ptr<extensions::TestExtensionPrefs> extension_prefs) 489 Profile* profile,
490 std::unique_ptr<extensions::TestExtensionPrefs> extension_prefs)
489 : EventRouter(profile, extension_prefs->prefs()), 491 : EventRouter(profile, extension_prefs->prefs()),
490 extension_prefs_(std::move(extension_prefs)), 492 extension_prefs_(std::move(extension_prefs)),
491 event_count_(0) {} 493 event_count_(0) {}
492 494
493 void DispatchEventToExtension(const std::string& extension_id, 495 void DispatchEventToExtension(
494 scoped_ptr<extensions::Event> event) override { 496 const std::string& extension_id,
497 std::unique_ptr<extensions::Event> event) override {
495 ++event_count_; 498 ++event_count_;
496 last_extension_id_ = extension_id; 499 last_extension_id_ = extension_id;
497 last_event_name_ = event ? event->event_name : std::string(); 500 last_event_name_ = event ? event->event_name : std::string();
498 } 501 }
499 502
500 int event_count() const { return event_count_; } 503 int event_count() const { return event_count_; }
501 const std::string& last_extension_id() const { return last_extension_id_; } 504 const std::string& last_extension_id() const { return last_extension_id_; }
502 const std::string& last_event_name() const { return last_event_name_; } 505 const std::string& last_event_name() const { return last_event_name_; }
503 506
504 private: 507 private:
505 scoped_ptr<extensions::TestExtensionPrefs> extension_prefs_; 508 std::unique_ptr<extensions::TestExtensionPrefs> extension_prefs_;
506 int event_count_; 509 int event_count_;
507 std::string last_extension_id_; 510 std::string last_extension_id_;
508 std::string last_event_name_; 511 std::string last_event_name_;
509 }; 512 };
510 513
511 // FakeEventRouter factory function 514 // FakeEventRouter factory function
512 scoped_ptr<KeyedService> FakeEventRouterFactoryFunction( 515 std::unique_ptr<KeyedService> FakeEventRouterFactoryFunction(
513 content::BrowserContext* profile) { 516 content::BrowserContext* profile) {
514 scoped_ptr<extensions::TestExtensionPrefs> extension_prefs( 517 std::unique_ptr<extensions::TestExtensionPrefs> extension_prefs(
515 new extensions::TestExtensionPrefs(base::ThreadTaskRunnerHandle::Get())); 518 new extensions::TestExtensionPrefs(base::ThreadTaskRunnerHandle::Get()));
516 return make_scoped_ptr(new FakeEventRouter(static_cast<Profile*>(profile), 519 return base::WrapUnique(new FakeEventRouter(static_cast<Profile*>(profile),
517 std::move(extension_prefs))); 520 std::move(extension_prefs)));
518 } 521 }
519 522
520 TEST_F(EasyUnlockPrivateApiTest, AutoPairing) { 523 TEST_F(EasyUnlockPrivateApiTest, AutoPairing) {
521 FakeEventRouter* event_router = static_cast<FakeEventRouter*>( 524 FakeEventRouter* event_router = static_cast<FakeEventRouter*>(
522 extensions::EventRouterFactory::GetInstance()->SetTestingFactoryAndUse( 525 extensions::EventRouterFactory::GetInstance()->SetTestingFactoryAndUse(
523 profile(), &FakeEventRouterFactoryFunction)); 526 profile(), &FakeEventRouterFactoryFunction));
524 527
525 EasyUnlockServiceFactory::GetInstance()->SetTestingFactoryAndUse( 528 EasyUnlockServiceFactory::GetInstance()->SetTestingFactoryAndUse(
526 profile(), &BuildTestEasyUnlockService); 529 profile(), &BuildTestEasyUnlockService);
527 530
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 // natively synced devices if the kEnableBluetoothLowEnergyDiscovery switch is 569 // natively synced devices if the kEnableBluetoothLowEnergyDiscovery switch is
567 // set. 570 // set.
568 TEST_F(EasyUnlockPrivateApiTest, GetRemoteDevicesExperimental) { 571 TEST_F(EasyUnlockPrivateApiTest, GetRemoteDevicesExperimental) {
569 base::CommandLine::ForCurrentProcess()->AppendSwitch( 572 base::CommandLine::ForCurrentProcess()->AppendSwitch(
570 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery); 573 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery);
571 EasyUnlockServiceFactory::GetInstance()->SetTestingFactoryAndUse( 574 EasyUnlockServiceFactory::GetInstance()->SetTestingFactoryAndUse(
572 profile(), &BuildTestEasyUnlockService); 575 profile(), &BuildTestEasyUnlockService);
573 576
574 scoped_refptr<TestableGetRemoteDevicesFunction> function( 577 scoped_refptr<TestableGetRemoteDevicesFunction> function(
575 new TestableGetRemoteDevicesFunction()); 578 new TestableGetRemoteDevicesFunction());
576 scoped_ptr<base::Value> value( 579 std::unique_ptr<base::Value> value(
577 extensions::api_test_utils::RunFunctionAndReturnSingleResult( 580 extensions::api_test_utils::RunFunctionAndReturnSingleResult(
578 function.get(), "[]", profile())); 581 function.get(), "[]", profile()));
579 ASSERT_TRUE(value.get()); 582 ASSERT_TRUE(value.get());
580 ASSERT_EQ(base::Value::TYPE_LIST, value->GetType()); 583 ASSERT_EQ(base::Value::TYPE_LIST, value->GetType());
581 584
582 base::ListValue* list_value = static_cast<base::ListValue*>(value.get()); 585 base::ListValue* list_value = static_cast<base::ListValue*>(value.get());
583 EXPECT_EQ(2u, list_value->GetSize()); 586 EXPECT_EQ(2u, list_value->GetSize());
584 587
585 base::Value* remote_device1; 588 base::Value* remote_device1;
586 base::Value* remote_device2; 589 base::Value* remote_device2;
(...skipping 13 matching lines...) Expand all
600 } 603 }
601 604
602 // Checks that the chrome.easyUnlockPrivate.getRemoteDevices API returns the 605 // Checks that the chrome.easyUnlockPrivate.getRemoteDevices API returns the
603 // stored value if the kEnableBluetoothLowEnergyDiscovery switch is not set. 606 // stored value if the kEnableBluetoothLowEnergyDiscovery switch is not set.
604 TEST_F(EasyUnlockPrivateApiTest, GetRemoteDevicesNonExperimental) { 607 TEST_F(EasyUnlockPrivateApiTest, GetRemoteDevicesNonExperimental) {
605 EasyUnlockServiceFactory::GetInstance()->SetTestingFactoryAndUse( 608 EasyUnlockServiceFactory::GetInstance()->SetTestingFactoryAndUse(
606 profile(), &BuildTestEasyUnlockService); 609 profile(), &BuildTestEasyUnlockService);
607 610
608 scoped_refptr<TestableGetRemoteDevicesFunction> function( 611 scoped_refptr<TestableGetRemoteDevicesFunction> function(
609 new TestableGetRemoteDevicesFunction()); 612 new TestableGetRemoteDevicesFunction());
610 scoped_ptr<base::Value> value( 613 std::unique_ptr<base::Value> value(
611 extensions::api_test_utils::RunFunctionAndReturnSingleResult( 614 extensions::api_test_utils::RunFunctionAndReturnSingleResult(
612 function.get(), "[]", profile())); 615 function.get(), "[]", profile()));
613 ASSERT_TRUE(value.get()); 616 ASSERT_TRUE(value.get());
614 ASSERT_EQ(base::Value::TYPE_LIST, value->GetType()); 617 ASSERT_EQ(base::Value::TYPE_LIST, value->GetType());
615 618
616 base::ListValue* list_value = static_cast<base::ListValue*>(value.get()); 619 base::ListValue* list_value = static_cast<base::ListValue*>(value.get());
617 EXPECT_EQ(0u, list_value->GetSize()); 620 EXPECT_EQ(0u, list_value->GetSize());
618 } 621 }
619 622
620 // Checks that the chrome.easyUnlockPrivate.getPermitAccess API returns the 623 // Checks that the chrome.easyUnlockPrivate.getPermitAccess API returns the
621 // native permit access if the kEnableBluetoothLowEnergyDiscovery switch is 624 // native permit access if the kEnableBluetoothLowEnergyDiscovery switch is
622 // set. 625 // set.
623 TEST_F(EasyUnlockPrivateApiTest, GetPermitAccessExperimental) { 626 TEST_F(EasyUnlockPrivateApiTest, GetPermitAccessExperimental) {
624 base::CommandLine::ForCurrentProcess()->AppendSwitch( 627 base::CommandLine::ForCurrentProcess()->AppendSwitch(
625 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery); 628 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery);
626 EasyUnlockServiceFactory::GetInstance()->SetTestingFactoryAndUse( 629 EasyUnlockServiceFactory::GetInstance()->SetTestingFactoryAndUse(
627 profile(), &BuildTestEasyUnlockService); 630 profile(), &BuildTestEasyUnlockService);
628 631
629 scoped_refptr<TestableGetPermitAccessFunction> function( 632 scoped_refptr<TestableGetPermitAccessFunction> function(
630 new TestableGetPermitAccessFunction()); 633 new TestableGetPermitAccessFunction());
631 scoped_ptr<base::Value> value( 634 std::unique_ptr<base::Value> value(
632 extensions::api_test_utils::RunFunctionAndReturnSingleResult( 635 extensions::api_test_utils::RunFunctionAndReturnSingleResult(
633 function.get(), "[]", profile())); 636 function.get(), "[]", profile()));
634 ASSERT_TRUE(value); 637 ASSERT_TRUE(value);
635 ASSERT_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); 638 ASSERT_EQ(base::Value::TYPE_DICTIONARY, value->GetType());
636 base::DictionaryValue* permit_access = 639 base::DictionaryValue* permit_access =
637 static_cast<base::DictionaryValue*>(value.get()); 640 static_cast<base::DictionaryValue*>(value.get());
638 641
639 std::string user_public_key, user_private_key; 642 std::string user_public_key, user_private_key;
640 EXPECT_TRUE(permit_access->GetString("id", &user_public_key)); 643 EXPECT_TRUE(permit_access->GetString("id", &user_public_key));
641 EXPECT_TRUE(permit_access->GetString("data", &user_private_key)); 644 EXPECT_TRUE(permit_access->GetString("data", &user_private_key));
642 EXPECT_EQ("user public key", user_public_key); 645 EXPECT_EQ("user public key", user_public_key);
643 EXPECT_EQ("user private key", user_private_key); 646 EXPECT_EQ("user private key", user_private_key);
644 } 647 }
645 648
646 // Checks that the chrome.easyUnlockPrivate.getPermitAccess API returns the 649 // Checks that the chrome.easyUnlockPrivate.getPermitAccess API returns the
647 // stored value if the kEnableBluetoothLowEnergyDiscovery switch is not set. 650 // stored value if the kEnableBluetoothLowEnergyDiscovery switch is not set.
648 TEST_F(EasyUnlockPrivateApiTest, GetPermitAccessNonExperimental) { 651 TEST_F(EasyUnlockPrivateApiTest, GetPermitAccessNonExperimental) {
649 EasyUnlockServiceFactory::GetInstance()->SetTestingFactoryAndUse( 652 EasyUnlockServiceFactory::GetInstance()->SetTestingFactoryAndUse(
650 profile(), &BuildTestEasyUnlockService); 653 profile(), &BuildTestEasyUnlockService);
651 654
652 scoped_refptr<TestableGetPermitAccessFunction> function( 655 scoped_refptr<TestableGetPermitAccessFunction> function(
653 new TestableGetPermitAccessFunction()); 656 new TestableGetPermitAccessFunction());
654 scoped_ptr<base::Value> value( 657 std::unique_ptr<base::Value> value(
655 extensions::api_test_utils::RunFunctionAndReturnSingleResult( 658 extensions::api_test_utils::RunFunctionAndReturnSingleResult(
656 function.get(), "[]", profile())); 659 function.get(), "[]", profile()));
657 EXPECT_FALSE(value); 660 EXPECT_FALSE(value);
658 } 661 }
659 662
660 } // namespace 663 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698