| 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 <map> | 5 #include <map> |
| 6 #include <utility> |
| 6 | 7 |
| 8 #include "base/basictypes.h" |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 11 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 11 #include "base/guid.h" | 13 #include "base/guid.h" |
| 12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 14 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 15 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 16 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 47 #include "components/autofill/core/common/autofill_switches.h" | 49 #include "components/autofill/core/common/autofill_switches.h" |
| 48 #include "components/autofill/core/common/form_data.h" | 50 #include "components/autofill/core/common/form_data.h" |
| 49 #include "components/user_prefs/user_prefs.h" | 51 #include "components/user_prefs/user_prefs.h" |
| 50 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
| 51 #include "content/public/test/mock_render_process_host.h" | 53 #include "content/public/test/mock_render_process_host.h" |
| 52 #include "google_apis/gaia/google_service_auth_error.h" | 54 #include "google_apis/gaia/google_service_auth_error.h" |
| 53 #include "grit/component_scaled_resources.h" | 55 #include "grit/component_scaled_resources.h" |
| 54 #include "grit/generated_resources.h" | 56 #include "grit/generated_resources.h" |
| 55 #include "testing/gmock/include/gmock/gmock.h" | 57 #include "testing/gmock/include/gmock/gmock.h" |
| 56 #include "testing/gtest/include/gtest/gtest.h" | 58 #include "testing/gtest/include/gtest/gtest.h" |
| 57 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_data.h" | 59 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" |
| 58 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_validator.h" | 60 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi
eld.h" |
| 61 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_pr
oblem.h" |
| 59 #include "ui/base/resource/resource_bundle.h" | 62 #include "ui/base/resource/resource_bundle.h" |
| 60 | 63 |
| 61 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
| 62 #include "ui/base/win/scoped_ole_initializer.h" | 65 #include "ui/base/win/scoped_ole_initializer.h" |
| 63 #endif | 66 #endif |
| 64 | 67 |
| 65 using base::ASCIIToUTF16; | 68 using base::ASCIIToUTF16; |
| 66 using base::UTF8ToUTF16; | 69 using base::UTF8ToUTF16; |
| 67 | 70 |
| 68 namespace autofill { | 71 namespace autofill { |
| 69 | 72 |
| 70 namespace { | 73 namespace { |
| 71 | 74 |
| 72 using ::i18n::addressinput::AddressData; | 75 using ::i18n::addressinput::FieldProblemMap; |
| 73 using ::i18n::addressinput::AddressProblemFilter; | |
| 74 using ::i18n::addressinput::AddressProblem; | |
| 75 using ::i18n::addressinput::AddressProblems; | |
| 76 using ::i18n::addressinput::AddressValidator; | |
| 77 using testing::AtLeast; | 76 using testing::AtLeast; |
| 78 using testing::DoAll; | 77 using testing::DoAll; |
| 79 using testing::Return; | 78 using testing::Return; |
| 80 using testing::SetArgPointee; | 79 using testing::SetArgPointee; |
| 81 using testing::_; | 80 using testing::_; |
| 82 | 81 |
| 83 const char kSourceUrl[] = "http://localbike.shop"; | 82 const char kSourceUrl[] = "http://localbike.shop"; |
| 84 const char kFakeEmail[] = "user@chromium.org"; | 83 const char kFakeEmail[] = "user@chromium.org"; |
| 85 const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; | 84 const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; |
| 86 const char kEditedBillingAddress[] = "123 edited billing address"; | 85 const char kEditedBillingAddress[] = "123 edited billing address"; |
| (...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 | 1001 |
| 1003 AutofillProfile verified_profile(test::GetVerifiedProfile()); | 1002 AutofillProfile verified_profile(test::GetVerifiedProfile()); |
| 1004 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); | 1003 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); |
| 1005 EXPECT_EQ(4, shipping_model->GetItemCount()); | 1004 EXPECT_EQ(4, shipping_model->GetItemCount()); |
| 1006 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | 1005 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
| 1007 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); | 1006 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
| 1008 | 1007 |
| 1009 // Now make up a problem and make sure the profile isn't in the list. | 1008 // Now make up a problem and make sure the profile isn't in the list. |
| 1010 Reset(); | 1009 Reset(); |
| 1011 SwitchToAutofill(); | 1010 SwitchToAutofill(); |
| 1012 AddressProblems problems; | 1011 FieldProblemMap problems; |
| 1013 problems.push_back( | 1012 problems.insert(std::make_pair(::i18n::addressinput::POSTAL_CODE, |
| 1014 AddressProblem(::i18n::addressinput::POSTAL_CODE, | 1013 ::i18n::addressinput::MISMATCHING_VALUE)); |
| 1015 AddressProblem::MISMATCHING_VALUE, | |
| 1016 IDS_LEARN_MORE)); | |
| 1017 EXPECT_CALL(*controller()->GetMockValidator(), | 1014 EXPECT_CALL(*controller()->GetMockValidator(), |
| 1018 ValidateAddress(CountryCodeMatcher("US"), _, _)). | 1015 ValidateAddress(CountryCodeMatcher("US"), _, _)). |
| 1019 WillRepeatedly(DoAll(SetArgPointee<2>(problems), | 1016 WillRepeatedly(DoAll(SetArgPointee<2>(problems), |
| 1020 Return(AddressValidator::SUCCESS))); | 1017 Return(AddressValidator::SUCCESS))); |
| 1021 | 1018 |
| 1022 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); | 1019 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); |
| 1023 shipping_model = GetMenuModelForSection(SECTION_SHIPPING); | 1020 shipping_model = GetMenuModelForSection(SECTION_SHIPPING); |
| 1024 EXPECT_EQ(4, shipping_model->GetItemCount()); | 1021 EXPECT_EQ(4, shipping_model->GetItemCount()); |
| 1025 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | 1022 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
| 1026 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); | 1023 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
| 1027 } | 1024 } |
| 1028 | 1025 |
| 1029 // Makes sure suggestion profiles are re-validated when validation rules load. | 1026 // Makes sure suggestion profiles are re-validated when validation rules load. |
| 1030 TEST_F(AutofillDialogControllerTest, AutofillProfilesRevalidateAfterRulesLoad) { | 1027 TEST_F(AutofillDialogControllerTest, AutofillProfilesRevalidateAfterRulesLoad) { |
| 1031 SwitchToAutofill(); | 1028 SwitchToAutofill(); |
| 1032 SuggestionsMenuModel* shipping_model = | 1029 SuggestionsMenuModel* shipping_model = |
| 1033 GetMenuModelForSection(SECTION_SHIPPING); | 1030 GetMenuModelForSection(SECTION_SHIPPING); |
| 1034 EXPECT_EQ(3, shipping_model->GetItemCount()); | 1031 EXPECT_EQ(3, shipping_model->GetItemCount()); |
| 1035 // "Same as billing" is selected. | 1032 // "Same as billing" is selected. |
| 1036 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | 1033 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
| 1037 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); | 1034 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
| 1038 AutofillProfile verified_profile(test::GetVerifiedProfile()); | 1035 AutofillProfile verified_profile(test::GetVerifiedProfile()); |
| 1039 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); | 1036 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); |
| 1040 EXPECT_EQ(4, shipping_model->GetItemCount()); | 1037 EXPECT_EQ(4, shipping_model->GetItemCount()); |
| 1041 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | 1038 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
| 1042 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); | 1039 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
| 1043 | 1040 |
| 1044 AddressProblems problems; | 1041 FieldProblemMap problems; |
| 1045 problems.push_back( | 1042 problems.insert(std::make_pair(::i18n::addressinput::POSTAL_CODE, |
| 1046 AddressProblem(::i18n::addressinput::POSTAL_CODE, | 1043 ::i18n::addressinput::MISMATCHING_VALUE)); |
| 1047 AddressProblem::MISMATCHING_VALUE, | |
| 1048 IDS_LEARN_MORE)); | |
| 1049 EXPECT_CALL(*controller()->GetMockValidator(), | 1044 EXPECT_CALL(*controller()->GetMockValidator(), |
| 1050 ValidateAddress(CountryCodeMatcher("US"), _, _)). | 1045 ValidateAddress(CountryCodeMatcher("US"), _, _)). |
| 1051 WillRepeatedly(DoAll(SetArgPointee<2>(problems), | 1046 WillRepeatedly(DoAll(SetArgPointee<2>(problems), |
| 1052 Return(AddressValidator::SUCCESS))); | 1047 Return(AddressValidator::SUCCESS))); |
| 1053 | 1048 |
| 1054 controller()->OnAddressValidationRulesLoaded("US", true); | 1049 controller()->OnAddressValidationRulesLoaded("US", true); |
| 1055 EXPECT_EQ(4, shipping_model->GetItemCount()); | 1050 EXPECT_EQ(4, shipping_model->GetItemCount()); |
| 1056 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | 1051 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
| 1057 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); | 1052 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
| 1058 } | 1053 } |
| (...skipping 2440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3499 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(2)->value); | 3494 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(2)->value); |
| 3500 EXPECT_EQ(ADDRESS_HOME_COUNTRY, | 3495 EXPECT_EQ(ADDRESS_HOME_COUNTRY, |
| 3501 form_structure()->field(3)->Type().GetStorableType()); | 3496 form_structure()->field(3)->Type().GetStorableType()); |
| 3502 EXPECT_EQ(ASCIIToUTF16("US"), form_structure()->field(3)->value); | 3497 EXPECT_EQ(ASCIIToUTF16("US"), form_structure()->field(3)->value); |
| 3503 EXPECT_EQ(ADDRESS_HOME_COUNTRY, | 3498 EXPECT_EQ(ADDRESS_HOME_COUNTRY, |
| 3504 form_structure()->field(4)->Type().GetStorableType()); | 3499 form_structure()->field(4)->Type().GetStorableType()); |
| 3505 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(4)->value); | 3500 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(4)->value); |
| 3506 } | 3501 } |
| 3507 | 3502 |
| 3508 } // namespace autofill | 3503 } // namespace autofill |
| OLD | NEW |