| OLD | NEW |
| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 #endif | 74 #endif |
| 75 | 75 |
| 76 using base::ASCIIToUTF16; | 76 using base::ASCIIToUTF16; |
| 77 | 77 |
| 78 namespace autofill { | 78 namespace autofill { |
| 79 | 79 |
| 80 namespace { | 80 namespace { |
| 81 | 81 |
| 82 using testing::Return; | 82 using testing::Return; |
| 83 using testing::_; | 83 using testing::_; |
| 84 using ::i18n::addressinput::AddressValidator; | |
| 85 | 84 |
| 86 void MockCallback(AutofillManagerDelegate::RequestAutocompleteResult, | 85 void MockCallback(AutofillManagerDelegate::RequestAutocompleteResult, |
| 87 const base::string16& message, | 86 const base::string16& message, |
| 88 const FormStructure*) {} | 87 const FormStructure*) {} |
| 89 | 88 |
| 90 class MockAutofillMetrics : public AutofillMetrics { | 89 class MockAutofillMetrics : public AutofillMetrics { |
| 91 public: | 90 public: |
| 92 MockAutofillMetrics() | 91 MockAutofillMetrics() |
| 93 : dialog_dismissal_action_(static_cast<DialogDismissalAction>(-1)) {} | 92 : dialog_dismissal_action_(static_cast<DialogDismissalAction>(-1)) {} |
| 94 virtual ~MockAutofillMetrics() {} | 93 virtual ~MockAutofillMetrics() {} |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 222 |
| 224 void set_sign_in_user_index(size_t sign_in_user_index) { | 223 void set_sign_in_user_index(size_t sign_in_user_index) { |
| 225 sign_in_user_index_ = sign_in_user_index; | 224 sign_in_user_index_ = sign_in_user_index; |
| 226 } | 225 } |
| 227 | 226 |
| 228 protected: | 227 protected: |
| 229 virtual PersonalDataManager* GetManager() const OVERRIDE { | 228 virtual PersonalDataManager* GetManager() const OVERRIDE { |
| 230 return &const_cast<TestAutofillDialogController*>(this)->test_manager_; | 229 return &const_cast<TestAutofillDialogController*>(this)->test_manager_; |
| 231 } | 230 } |
| 232 | 231 |
| 233 virtual AddressValidator* GetValidator() OVERRIDE { | 232 virtual PreloadAddressValidator* GetValidator() OVERRIDE { |
| 234 return &mock_validator_; | 233 return &mock_validator_; |
| 235 } | 234 } |
| 236 | 235 |
| 237 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { | 236 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { |
| 238 return &mock_wallet_client_; | 237 return &mock_wallet_client_; |
| 239 } | 238 } |
| 240 | 239 |
| 241 virtual bool IsSignInContinueUrl(const GURL& url, size_t* user_index) const | 240 virtual bool IsSignInContinueUrl(const GURL& url, size_t* user_index) const |
| 242 OVERRIDE { | 241 OVERRIDE { |
| 243 *user_index = sign_in_user_index_; | 242 *user_index = sign_in_user_index_; |
| (...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1709 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY)); | 1708 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY)); |
| 1710 } | 1709 } |
| 1711 | 1710 |
| 1712 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, RulesLoaded) { | 1711 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, RulesLoaded) { |
| 1713 // Select "Add new shipping address...". | 1712 // Select "Add new shipping address...". |
| 1714 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1); | 1713 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1); |
| 1715 controller()->set_use_validation(true); | 1714 controller()->set_use_validation(true); |
| 1716 | 1715 |
| 1717 EXPECT_CALL(*controller()->GetMockValidator(), | 1716 EXPECT_CALL(*controller()->GetMockValidator(), |
| 1718 ValidateAddress(CountryCodeMatcher("DE"), _, _)).Times(2). | 1717 ValidateAddress(CountryCodeMatcher("DE"), _, _)).Times(2). |
| 1719 WillOnce(Return(AddressValidator::RULES_NOT_READY)); | 1718 WillOnce(Return(PreloadAddressValidator::RULES_NOT_READY)); |
| 1720 | 1719 |
| 1721 // Validation should occur on country change and see the rules haven't loaded. | 1720 // Validation should occur on country change and see the rules haven't loaded. |
| 1722 scoped_ptr<AutofillDialogViewTester> view = GetViewTester(); | 1721 scoped_ptr<AutofillDialogViewTester> view = GetViewTester(); |
| 1723 view->SetTextContentsOfInput(ADDRESS_HOME_ZIP, ASCIIToUTF16("123")); | 1722 view->SetTextContentsOfInput(ADDRESS_HOME_ZIP, ASCIIToUTF16("123")); |
| 1724 view->SetTextContentsOfInput(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Germany")); | 1723 view->SetTextContentsOfInput(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Germany")); |
| 1725 view->ActivateInput(ADDRESS_HOME_COUNTRY); | 1724 view->ActivateInput(ADDRESS_HOME_COUNTRY); |
| 1726 | 1725 |
| 1727 // Different country loaded, validation should not occur. | 1726 // Different country loaded, validation should not occur. |
| 1728 controller()->OnAddressValidationRulesLoaded("FR", true); | 1727 controller()->OnAddressValidationRulesLoaded("FR", true); |
| 1729 | 1728 |
| 1730 // Relevant country loaded, validation should occur. | 1729 // Relevant country loaded, validation should occur. |
| 1731 controller()->OnAddressValidationRulesLoaded("DE", true); | 1730 controller()->OnAddressValidationRulesLoaded("DE", true); |
| 1732 | 1731 |
| 1733 // Relevant country loaded but revalidation already happened, no further | 1732 // Relevant country loaded but revalidation already happened, no further |
| 1734 // validation should occur. | 1733 // validation should occur. |
| 1735 controller()->OnAddressValidationRulesLoaded("DE", false); | 1734 controller()->OnAddressValidationRulesLoaded("DE", false); |
| 1736 | 1735 |
| 1737 // Cancelling the dialog causes additional validation to see if the user | 1736 // Cancelling the dialog causes additional validation to see if the user |
| 1738 // cancelled with invalid fields, so verify and clear here. | 1737 // cancelled with invalid fields, so verify and clear here. |
| 1739 testing::Mock::VerifyAndClearExpectations(controller()->GetMockValidator()); | 1738 testing::Mock::VerifyAndClearExpectations(controller()->GetMockValidator()); |
| 1740 } | 1739 } |
| 1741 | 1740 |
| 1742 } // namespace autofill | 1741 } // namespace autofill |
| OLD | NEW |