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

Side by Side Diff: chrome/browser/ui/webui/settings/people_handler_unittest.cc

Issue 2030013003: Remove ListValue::Append(new {Fundamental,String}Value(...)) pattern in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ui/webui/settings/people_handler.h" 5 #include "chrome/browser/ui/webui/settings/people_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 505
506 ASSERT_FALSE(handler_->is_configuring_sync()); 506 ASSERT_FALSE(handler_->is_configuring_sync());
507 } 507 }
508 508
509 #endif // #if !defined(OS_CHROMEOS) 509 #endif // #if !defined(OS_CHROMEOS)
510 510
511 TEST_F(PeopleHandlerTest, TestSyncEverything) { 511 TEST_F(PeopleHandlerTest, TestSyncEverything) {
512 std::string args = GetConfiguration( 512 std::string args = GetConfiguration(
513 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); 513 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
514 base::ListValue list_args; 514 base::ListValue list_args;
515 list_args.Append(new base::StringValue(kTestCallbackId)); 515 list_args.AppendString(kTestCallbackId);
516 list_args.Append(new base::StringValue(args)); 516 list_args.AppendString(args);
517 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 517 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
518 .WillRepeatedly(Return(false)); 518 .WillRepeatedly(Return(false));
519 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 519 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
520 .WillRepeatedly(Return(false)); 520 .WillRepeatedly(Return(false));
521 SetupInitializedProfileSyncService(); 521 SetupInitializedProfileSyncService();
522 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); 522 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
523 handler_->HandleSetDatatypes(&list_args); 523 handler_->HandleSetDatatypes(&list_args);
524 524
525 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus); 525 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus);
526 } 526 }
527 527
528 TEST_F(PeopleHandlerTest, TestPassphraseStillRequired) { 528 TEST_F(PeopleHandlerTest, TestPassphraseStillRequired) {
529 std::string args = GetConfiguration( 529 std::string args = GetConfiguration(
530 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); 530 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
531 base::ListValue list_args; 531 base::ListValue list_args;
532 list_args.Append(new base::StringValue(kTestCallbackId)); 532 list_args.AppendString(kTestCallbackId);
533 list_args.Append(new base::StringValue(args)); 533 list_args.AppendString(args);
534 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 534 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
535 .WillRepeatedly(Return(true)); 535 .WillRepeatedly(Return(true));
536 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 536 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
537 .WillRepeatedly(Return(true)); 537 .WillRepeatedly(Return(true));
538 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 538 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
539 .WillRepeatedly(Return(false)); 539 .WillRepeatedly(Return(false));
540 SetupInitializedProfileSyncService(); 540 SetupInitializedProfileSyncService();
541 SetDefaultExpectationsForConfigPage(); 541 SetDefaultExpectationsForConfigPage();
542 542
543 handler_->HandleSetEncryption(&list_args); 543 handler_->HandleSetEncryption(&list_args);
544 // We should navigate back to the configure page since we need a passphrase. 544 // We should navigate back to the configure page since we need a passphrase.
545 ExpectPageStatusResponse(PeopleHandler::kPassphraseFailedPageStatus); 545 ExpectPageStatusResponse(PeopleHandler::kPassphraseFailedPageStatus);
546 } 546 }
547 547
548 TEST_F(PeopleHandlerTest, EnterExistingFrozenImplicitPassword) { 548 TEST_F(PeopleHandlerTest, EnterExistingFrozenImplicitPassword) {
549 base::DictionaryValue dict; 549 base::DictionaryValue dict;
550 dict.SetBoolean("setNewPassphrase", false); 550 dict.SetBoolean("setNewPassphrase", false);
551 std::string args = GetConfiguration(&dict, SYNC_ALL_DATA, GetAllTypes(), 551 std::string args = GetConfiguration(&dict, SYNC_ALL_DATA, GetAllTypes(),
552 "oldGaiaPassphrase", ENCRYPT_PASSWORDS); 552 "oldGaiaPassphrase", ENCRYPT_PASSWORDS);
553 base::ListValue list_args; 553 base::ListValue list_args;
554 list_args.Append(new base::StringValue(kTestCallbackId)); 554 list_args.AppendString(kTestCallbackId);
555 list_args.Append(new base::StringValue(args)); 555 list_args.AppendString(args);
556 // Act as if an encryption passphrase is required the first time, then never 556 // Act as if an encryption passphrase is required the first time, then never
557 // again after that. 557 // again after that.
558 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillOnce(Return(true)); 558 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillOnce(Return(true));
559 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 559 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
560 .WillRepeatedly(Return(false)); 560 .WillRepeatedly(Return(false));
561 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 561 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
562 .WillRepeatedly(Return(false)); 562 .WillRepeatedly(Return(false));
563 SetupInitializedProfileSyncService(); 563 SetupInitializedProfileSyncService();
564 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("oldGaiaPassphrase")) 564 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("oldGaiaPassphrase"))
565 .WillOnce(Return(true)); 565 .WillOnce(Return(true));
566 566
567 handler_->HandleSetEncryption(&list_args); 567 handler_->HandleSetEncryption(&list_args);
568 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus); 568 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus);
569 } 569 }
570 570
571 TEST_F(PeopleHandlerTest, SetNewCustomPassphrase) { 571 TEST_F(PeopleHandlerTest, SetNewCustomPassphrase) {
572 base::DictionaryValue dict; 572 base::DictionaryValue dict;
573 dict.SetBoolean("setNewPassphrase", true); 573 dict.SetBoolean("setNewPassphrase", true);
574 std::string args = GetConfiguration(&dict, SYNC_ALL_DATA, GetAllTypes(), 574 std::string args = GetConfiguration(&dict, SYNC_ALL_DATA, GetAllTypes(),
575 "custom_passphrase", ENCRYPT_ALL_DATA); 575 "custom_passphrase", ENCRYPT_ALL_DATA);
576 base::ListValue list_args; 576 base::ListValue list_args;
577 list_args.Append(new base::StringValue(kTestCallbackId)); 577 list_args.AppendString(kTestCallbackId);
578 list_args.Append(new base::StringValue(args)); 578 list_args.AppendString(args);
579 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 579 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
580 .WillRepeatedly(Return(false)); 580 .WillRepeatedly(Return(false));
581 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 581 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
582 .WillRepeatedly(Return(false)); 582 .WillRepeatedly(Return(false));
583 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 583 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
584 .WillRepeatedly(Return(false)); 584 .WillRepeatedly(Return(false));
585 SetupInitializedProfileSyncService(); 585 SetupInitializedProfileSyncService();
586 EXPECT_CALL(*mock_pss_, 586 EXPECT_CALL(*mock_pss_,
587 SetEncryptionPassphrase("custom_passphrase", 587 SetEncryptionPassphrase("custom_passphrase",
588 ProfileSyncService::EXPLICIT)); 588 ProfileSyncService::EXPLICIT));
589 589
590 handler_->HandleSetEncryption(&list_args); 590 handler_->HandleSetEncryption(&list_args);
591 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus); 591 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus);
592 } 592 }
593 593
594 TEST_F(PeopleHandlerTest, EnterWrongExistingPassphrase) { 594 TEST_F(PeopleHandlerTest, EnterWrongExistingPassphrase) {
595 base::DictionaryValue dict; 595 base::DictionaryValue dict;
596 dict.SetBoolean("setNewPassphrase", false); 596 dict.SetBoolean("setNewPassphrase", false);
597 std::string args = GetConfiguration(&dict, SYNC_ALL_DATA, GetAllTypes(), 597 std::string args = GetConfiguration(&dict, SYNC_ALL_DATA, GetAllTypes(),
598 "invalid_passphrase", ENCRYPT_ALL_DATA); 598 "invalid_passphrase", ENCRYPT_ALL_DATA);
599 base::ListValue list_args; 599 base::ListValue list_args;
600 list_args.Append(new base::StringValue(kTestCallbackId)); 600 list_args.AppendString(kTestCallbackId);
601 list_args.Append(new base::StringValue(args)); 601 list_args.AppendString(args);
602 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 602 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
603 .WillRepeatedly(Return(true)); 603 .WillRepeatedly(Return(true));
604 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 604 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
605 .WillRepeatedly(Return(true)); 605 .WillRepeatedly(Return(true));
606 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 606 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
607 .WillRepeatedly(Return(false)); 607 .WillRepeatedly(Return(false));
608 SetupInitializedProfileSyncService(); 608 SetupInitializedProfileSyncService();
609 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("invalid_passphrase")). 609 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("invalid_passphrase")).
610 WillOnce(Return(false)); 610 WillOnce(Return(false));
611 611
612 SetDefaultExpectationsForConfigPage(); 612 SetDefaultExpectationsForConfigPage();
613 613
614 handler_->HandleSetEncryption(&list_args); 614 handler_->HandleSetEncryption(&list_args);
615 // We should navigate back to the configure page since we need a passphrase. 615 // We should navigate back to the configure page since we need a passphrase.
616 ExpectPageStatusResponse(PeopleHandler::kPassphraseFailedPageStatus); 616 ExpectPageStatusResponse(PeopleHandler::kPassphraseFailedPageStatus);
617 } 617 }
618 618
619 TEST_F(PeopleHandlerTest, EnterBlankExistingPassphrase) { 619 TEST_F(PeopleHandlerTest, EnterBlankExistingPassphrase) {
620 base::DictionaryValue dict; 620 base::DictionaryValue dict;
621 dict.SetBoolean("setNewPassphrase", false); 621 dict.SetBoolean("setNewPassphrase", false);
622 std::string args = GetConfiguration(&dict, 622 std::string args = GetConfiguration(&dict,
623 SYNC_ALL_DATA, 623 SYNC_ALL_DATA,
624 GetAllTypes(), 624 GetAllTypes(),
625 "", 625 "",
626 ENCRYPT_PASSWORDS); 626 ENCRYPT_PASSWORDS);
627 base::ListValue list_args; 627 base::ListValue list_args;
628 list_args.Append(new base::StringValue(kTestCallbackId)); 628 list_args.AppendString(kTestCallbackId);
629 list_args.Append(new base::StringValue(args)); 629 list_args.AppendString(args);
630 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 630 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
631 .WillRepeatedly(Return(true)); 631 .WillRepeatedly(Return(true));
632 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 632 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
633 .WillRepeatedly(Return(true)); 633 .WillRepeatedly(Return(true));
634 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 634 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
635 .WillRepeatedly(Return(false)); 635 .WillRepeatedly(Return(false));
636 SetupInitializedProfileSyncService(); 636 SetupInitializedProfileSyncService();
637 637
638 SetDefaultExpectationsForConfigPage(); 638 SetDefaultExpectationsForConfigPage();
639 639
640 handler_->HandleSetEncryption(&list_args); 640 handler_->HandleSetEncryption(&list_args);
641 // We should navigate back to the configure page since we need a passphrase. 641 // We should navigate back to the configure page since we need a passphrase.
642 ExpectPageStatusResponse(PeopleHandler::kPassphraseFailedPageStatus); 642 ExpectPageStatusResponse(PeopleHandler::kPassphraseFailedPageStatus);
643 } 643 }
644 644
645 // Walks through each user selectable type, and tries to sync just that single 645 // Walks through each user selectable type, and tries to sync just that single
646 // data type. 646 // data type.
647 TEST_F(PeopleHandlerTest, TestSyncIndividualTypes) { 647 TEST_F(PeopleHandlerTest, TestSyncIndividualTypes) {
648 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); 648 syncer::ModelTypeSet user_selectable_types = GetAllTypes();
649 syncer::ModelTypeSet::Iterator it; 649 syncer::ModelTypeSet::Iterator it;
650 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { 650 for (it = user_selectable_types.First(); it.Good(); it.Inc()) {
651 syncer::ModelTypeSet type_to_set; 651 syncer::ModelTypeSet type_to_set;
652 type_to_set.Put(it.Get()); 652 type_to_set.Put(it.Get());
653 std::string args = GetConfiguration(NULL, 653 std::string args = GetConfiguration(NULL,
654 CHOOSE_WHAT_TO_SYNC, 654 CHOOSE_WHAT_TO_SYNC,
655 type_to_set, 655 type_to_set,
656 std::string(), 656 std::string(),
657 ENCRYPT_PASSWORDS); 657 ENCRYPT_PASSWORDS);
658 base::ListValue list_args; 658 base::ListValue list_args;
659 list_args.Append(new base::StringValue(kTestCallbackId)); 659 list_args.AppendString(kTestCallbackId);
660 list_args.Append(new base::StringValue(args)); 660 list_args.AppendString(args);
661 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 661 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
662 .WillRepeatedly(Return(false)); 662 .WillRepeatedly(Return(false));
663 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 663 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
664 .WillRepeatedly(Return(false)); 664 .WillRepeatedly(Return(false));
665 SetupInitializedProfileSyncService(); 665 SetupInitializedProfileSyncService();
666 EXPECT_CALL(*mock_pss_, 666 EXPECT_CALL(*mock_pss_,
667 OnUserChoseDatatypes(false, ModelTypeSetMatches(type_to_set))); 667 OnUserChoseDatatypes(false, ModelTypeSetMatches(type_to_set)));
668 668
669 handler_->HandleSetDatatypes(&list_args); 669 handler_->HandleSetDatatypes(&list_args);
670 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus); 670 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus);
671 Mock::VerifyAndClearExpectations(mock_pss_); 671 Mock::VerifyAndClearExpectations(mock_pss_);
672 } 672 }
673 } 673 }
674 674
675 TEST_F(PeopleHandlerTest, TestSyncAllManually) { 675 TEST_F(PeopleHandlerTest, TestSyncAllManually) {
676 std::string args = GetConfiguration(NULL, 676 std::string args = GetConfiguration(NULL,
677 CHOOSE_WHAT_TO_SYNC, 677 CHOOSE_WHAT_TO_SYNC,
678 GetAllTypes(), 678 GetAllTypes(),
679 std::string(), 679 std::string(),
680 ENCRYPT_PASSWORDS); 680 ENCRYPT_PASSWORDS);
681 base::ListValue list_args; 681 base::ListValue list_args;
682 list_args.Append(new base::StringValue(kTestCallbackId)); 682 list_args.AppendString(kTestCallbackId);
683 list_args.Append(new base::StringValue(args)); 683 list_args.AppendString(args);
684 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 684 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
685 .WillRepeatedly(Return(false)); 685 .WillRepeatedly(Return(false));
686 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 686 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
687 .WillRepeatedly(Return(false)); 687 .WillRepeatedly(Return(false));
688 SetupInitializedProfileSyncService(); 688 SetupInitializedProfileSyncService();
689 EXPECT_CALL(*mock_pss_, 689 EXPECT_CALL(*mock_pss_,
690 OnUserChoseDatatypes(false, ModelTypeSetMatches(GetAllTypes()))); 690 OnUserChoseDatatypes(false, ModelTypeSetMatches(GetAllTypes())));
691 handler_->HandleSetDatatypes(&list_args); 691 handler_->HandleSetDatatypes(&list_args);
692 692
693 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus); 693 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 886
887 const base::DictionaryValue* dictionary = ExpectSyncPrefsChanged(); 887 const base::DictionaryValue* dictionary = ExpectSyncPrefsChanged();
888 CheckBool(dictionary, "encryptAllData", false); 888 CheckBool(dictionary, "encryptAllData", false);
889 CheckBool(dictionary, "encryptAllDataAllowed", false); 889 CheckBool(dictionary, "encryptAllDataAllowed", false);
890 } 890 }
891 891
892 TEST_F(PeopleHandlerTest, TurnOnEncryptAllDisallowed) { 892 TEST_F(PeopleHandlerTest, TurnOnEncryptAllDisallowed) {
893 std::string args = GetConfiguration( 893 std::string args = GetConfiguration(
894 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA); 894 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA);
895 base::ListValue list_args; 895 base::ListValue list_args;
896 list_args.Append(new base::StringValue(kTestCallbackId)); 896 list_args.AppendString(kTestCallbackId);
897 list_args.Append(new base::StringValue(args)); 897 list_args.AppendString(args);
898 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 898 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
899 .WillRepeatedly(Return(false)); 899 .WillRepeatedly(Return(false));
900 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 900 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
901 .WillRepeatedly(Return(false)); 901 .WillRepeatedly(Return(false));
902 SetupInitializedProfileSyncService(); 902 SetupInitializedProfileSyncService();
903 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 903 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
904 .WillRepeatedly(Return(false)); 904 .WillRepeatedly(Return(false));
905 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); 905 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0);
906 handler_->HandleSetEncryption(&list_args); 906 handler_->HandleSetEncryption(&list_args);
907 907
908 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus); 908 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus);
909 } 909 }
910 910
911 } // namespace settings 911 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/font_handler.cc ('k') | chrome/browser/ui/webui/settings/profile_info_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698