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