Chromium Code Reviews| Index: ios/chrome/browser/ui/settings/autofill_collection_view_controller_unittest.mm |
| diff --git a/ios/chrome/browser/ui/settings/autofill_collection_view_controller_unittest.mm b/ios/chrome/browser/ui/settings/autofill_collection_view_controller_unittest.mm |
| index 9cfbadc32ab567a0b11eb26be3f00d34c258ee48..aa059d0e91a022729640ac1719164150d8178e05 100644 |
| --- a/ios/chrome/browser/ui/settings/autofill_collection_view_controller_unittest.mm |
| +++ b/ios/chrome/browser/ui/settings/autofill_collection_view_controller_unittest.mm |
| @@ -14,6 +14,7 @@ |
| #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" |
| #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h" |
| +#include "ios/chrome/browser/ui/settings/personal_data_manager_data_changed_observer.h" |
| #include "ios/web/public/test/test_web_thread_bundle.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -26,8 +27,7 @@ namespace { |
| class AutofillCollectionViewControllerTest |
| : public CollectionViewControllerTest { |
| protected: |
| - void SetUp() override { |
| - CollectionViewControllerTest::SetUp(); |
| + AutofillCollectionViewControllerTest() { |
| TestChromeBrowserState::Builder test_cbs_builder; |
| chrome_browser_state_ = test_cbs_builder.Build(); |
| // Profile import requires a PersonalDataManager which itself needs the |
| @@ -44,14 +44,17 @@ class AutofillCollectionViewControllerTest |
| void AddProfile(const std::string& origin, |
| const std::string& name, |
| const std::string& address) { |
| - autofill::PersonalDataManager* personalDataManager = |
| + autofill::PersonalDataManager* personal_data_manager = |
| autofill::PersonalDataManagerFactory::GetForBrowserState( |
| chrome_browser_state_.get()); |
| - autofill::AutofillProfile autofillProfile(base::GenerateGUID(), origin); |
| - autofillProfile.SetRawInfo(autofill::NAME_FULL, base::ASCIIToUTF16(name)); |
| - autofillProfile.SetRawInfo(autofill::ADDRESS_HOME_LINE1, |
| - base::ASCIIToUTF16(address)); |
| - personalDataManager->SaveImportedProfile(autofillProfile); |
| + PersonalDataManagerDataChangedObserver observer(personal_data_manager); |
| + |
| + autofill::AutofillProfile autofill_profile(base::GenerateGUID(), origin); |
| + autofill_profile.SetRawInfo(autofill::NAME_FULL, base::ASCIIToUTF16(name)); |
| + autofill_profile.SetRawInfo(autofill::ADDRESS_HOME_LINE1, |
| + base::ASCIIToUTF16(address)); |
| + personal_data_manager->SaveImportedProfile(autofill_profile); |
| + observer.Wait(); |
|
noyau (Ping after 24h)
2016/12/22 13:17:22
I would suggest a comment on all uses of Wait().
sdefresne
2016/12/22 13:28:12
Done.
|
| } |
| web::TestWebThreadBundle thread_bundle_; |
| @@ -83,16 +86,20 @@ TEST_F(AutofillCollectionViewControllerTest, TestOneProfile) { |
| // Adding a single credit card results in a credit card section. |
| TEST_F(AutofillCollectionViewControllerTest, TestOneCreditCard) { |
| - autofill::PersonalDataManager* personalDataManager = |
| + autofill::PersonalDataManager* personal_data_manager = |
| autofill::PersonalDataManagerFactory::GetForBrowserState( |
| chrome_browser_state_.get()); |
| - autofill::CreditCard creditCard(base::GenerateGUID(), |
| - "https://www.example.com/"); |
| - creditCard.SetRawInfo(autofill::CREDIT_CARD_NAME_FULL, |
| - base::ASCIIToUTF16("Alan Smithee")); |
| - creditCard.SetRawInfo(autofill::CREDIT_CARD_NUMBER, |
| - base::ASCIIToUTF16("378282246310005")); |
| - personalDataManager->SaveImportedCreditCard(creditCard); |
| + PersonalDataManagerDataChangedObserver observer(personal_data_manager); |
| + |
| + autofill::CreditCard credit_card(base::GenerateGUID(), |
| + "https://www.example.com/"); |
| + credit_card.SetRawInfo(autofill::CREDIT_CARD_NAME_FULL, |
| + base::ASCIIToUTF16("Alan Smithee")); |
| + credit_card.SetRawInfo(autofill::CREDIT_CARD_NUMBER, |
| + base::ASCIIToUTF16("378282246310005")); |
| + personal_data_manager->SaveImportedCreditCard(credit_card); |
| + observer.Wait(); |
| + |
| CreateController(); |
| // Expect two sections (header and credit card section). |
| EXPECT_EQ(2, NumberOfSections()); |
| @@ -117,6 +124,7 @@ TEST_F(AutofillCollectionViewControllerTest, TestOneProfileItemDeleted) { |
| base::mac::ObjCCastStrict<AutofillCollectionViewController>(controller()); |
| // Put the collectionView in 'edit' mode. |
| [view_controller editButtonPressed]; |
| + |
| // This is a bit of a shortcut, since actually clicking on the 'delete' |
| // button would be tough. |
| void (^delete_item_with_wait)(int, int) = ^(int i, int j) { |
| @@ -129,7 +137,16 @@ TEST_F(AutofillCollectionViewControllerTest, TestOneProfileItemDeleted) { |
| }); |
| }; |
| + autofill::PersonalDataManager* personal_data_manager = |
| + autofill::PersonalDataManagerFactory::GetForBrowserState( |
| + chrome_browser_state_.get()); |
| + PersonalDataManagerDataChangedObserver observer(personal_data_manager); |
| + |
| + // This call cause a modification of the PersonalDataManager, so wait until |
| + // the asynchronous task complete in addition to waiting for the UI update. |
| delete_item_with_wait(1, 0); |
| + observer.Wait(); |
| + |
| // Exit 'edit' mode. |
| [view_controller editButtonPressed]; |