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/preload_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" |
| 62 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_va
lidator.h" |
59 #include "ui/base/resource/resource_bundle.h" | 63 #include "ui/base/resource/resource_bundle.h" |
60 | 64 |
61 #if defined(OS_WIN) | 65 #if defined(OS_WIN) |
62 #include "ui/base/win/scoped_ole_initializer.h" | 66 #include "ui/base/win/scoped_ole_initializer.h" |
63 #endif | 67 #endif |
64 | 68 |
65 using base::ASCIIToUTF16; | 69 using base::ASCIIToUTF16; |
66 using base::UTF8ToUTF16; | 70 using base::UTF8ToUTF16; |
67 | 71 |
68 namespace autofill { | 72 namespace autofill { |
69 | 73 |
70 namespace { | 74 namespace { |
71 | 75 |
72 using ::i18n::addressinput::AddressData; | 76 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; | 77 using testing::AtLeast; |
78 using testing::DoAll; | 78 using testing::DoAll; |
79 using testing::Return; | 79 using testing::Return; |
80 using testing::SetArgPointee; | 80 using testing::SetArgPointee; |
81 using testing::_; | 81 using testing::_; |
82 | 82 |
83 const char kSourceUrl[] = "http://localbike.shop"; | 83 const char kSourceUrl[] = "http://localbike.shop"; |
84 const char kFakeEmail[] = "user@chromium.org"; | 84 const char kFakeEmail[] = "user@chromium.org"; |
85 const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; | 85 const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; |
86 const char kEditedBillingAddress[] = "123 edited billing address"; | 86 const char kEditedBillingAddress[] = "123 edited billing address"; |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 | 1002 |
1003 AutofillProfile verified_profile(test::GetVerifiedProfile()); | 1003 AutofillProfile verified_profile(test::GetVerifiedProfile()); |
1004 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); | 1004 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); |
1005 EXPECT_EQ(4, shipping_model->GetItemCount()); | 1005 EXPECT_EQ(4, shipping_model->GetItemCount()); |
1006 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | 1006 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
1007 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); | 1007 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
1008 | 1008 |
1009 // Now make up a problem and make sure the profile isn't in the list. | 1009 // Now make up a problem and make sure the profile isn't in the list. |
1010 Reset(); | 1010 Reset(); |
1011 SwitchToAutofill(); | 1011 SwitchToAutofill(); |
1012 AddressProblems problems; | 1012 FieldProblemMap problems; |
1013 problems.push_back( | 1013 problems.insert(std::make_pair(::i18n::addressinput::POSTAL_CODE, |
1014 AddressProblem(::i18n::addressinput::POSTAL_CODE, | 1014 ::i18n::addressinput::MISMATCHING_VALUE)); |
1015 AddressProblem::MISMATCHING_VALUE, | |
1016 IDS_LEARN_MORE)); | |
1017 EXPECT_CALL(*controller()->GetMockValidator(), | 1015 EXPECT_CALL(*controller()->GetMockValidator(), |
1018 ValidateAddress(CountryCodeMatcher("US"), _, _)). | 1016 ValidateAddress(CountryCodeMatcher("US"), _, _)). |
1019 WillRepeatedly(DoAll(SetArgPointee<2>(problems), | 1017 WillRepeatedly(DoAll(SetArgPointee<2>(problems), |
1020 Return(AddressValidator::SUCCESS))); | 1018 Return(AddressValidator::SUCCESS))); |
1021 | 1019 |
1022 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); | 1020 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); |
1023 shipping_model = GetMenuModelForSection(SECTION_SHIPPING); | 1021 shipping_model = GetMenuModelForSection(SECTION_SHIPPING); |
1024 EXPECT_EQ(4, shipping_model->GetItemCount()); | 1022 EXPECT_EQ(4, shipping_model->GetItemCount()); |
1025 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | 1023 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
1026 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); | 1024 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
1027 } | 1025 } |
1028 | 1026 |
1029 // Makes sure suggestion profiles are re-validated when validation rules load. | 1027 // Makes sure suggestion profiles are re-validated when validation rules load. |
1030 TEST_F(AutofillDialogControllerTest, AutofillProfilesRevalidateAfterRulesLoad) { | 1028 TEST_F(AutofillDialogControllerTest, AutofillProfilesRevalidateAfterRulesLoad) { |
1031 SwitchToAutofill(); | 1029 SwitchToAutofill(); |
1032 SuggestionsMenuModel* shipping_model = | 1030 SuggestionsMenuModel* shipping_model = |
1033 GetMenuModelForSection(SECTION_SHIPPING); | 1031 GetMenuModelForSection(SECTION_SHIPPING); |
1034 EXPECT_EQ(3, shipping_model->GetItemCount()); | 1032 EXPECT_EQ(3, shipping_model->GetItemCount()); |
1035 // "Same as billing" is selected. | 1033 // "Same as billing" is selected. |
1036 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | 1034 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
1037 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); | 1035 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
1038 AutofillProfile verified_profile(test::GetVerifiedProfile()); | 1036 AutofillProfile verified_profile(test::GetVerifiedProfile()); |
1039 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); | 1037 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); |
1040 EXPECT_EQ(4, shipping_model->GetItemCount()); | 1038 EXPECT_EQ(4, shipping_model->GetItemCount()); |
1041 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | 1039 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
1042 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); | 1040 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
1043 | 1041 |
1044 AddressProblems problems; | 1042 FieldProblemMap problems; |
1045 problems.push_back( | 1043 problems.insert(std::make_pair(::i18n::addressinput::POSTAL_CODE, |
1046 AddressProblem(::i18n::addressinput::POSTAL_CODE, | 1044 ::i18n::addressinput::MISMATCHING_VALUE)); |
1047 AddressProblem::MISMATCHING_VALUE, | |
1048 IDS_LEARN_MORE)); | |
1049 EXPECT_CALL(*controller()->GetMockValidator(), | 1045 EXPECT_CALL(*controller()->GetMockValidator(), |
1050 ValidateAddress(CountryCodeMatcher("US"), _, _)). | 1046 ValidateAddress(CountryCodeMatcher("US"), _, _)). |
1051 WillRepeatedly(DoAll(SetArgPointee<2>(problems), | 1047 WillRepeatedly(DoAll(SetArgPointee<2>(problems), |
1052 Return(AddressValidator::SUCCESS))); | 1048 Return(AddressValidator::SUCCESS))); |
1053 | 1049 |
1054 controller()->OnAddressValidationRulesLoaded("US", true); | 1050 controller()->OnAddressValidationRulesLoaded("US", true); |
1055 EXPECT_EQ(4, shipping_model->GetItemCount()); | 1051 EXPECT_EQ(4, shipping_model->GetItemCount()); |
1056 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | 1052 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
1057 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); | 1053 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); |
1058 } | 1054 } |
(...skipping 2470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3529 controller()->MenuModelForSection(SECTION_CC_BILLING)->ActivatedAt(2); | 3525 controller()->MenuModelForSection(SECTION_CC_BILLING)->ActivatedAt(2); |
3530 | 3526 |
3531 FieldValueMap outputs; | 3527 FieldValueMap outputs; |
3532 outputs[NAME_FULL] = ASCIIToUTF16("madonna"); | 3528 outputs[NAME_FULL] = ASCIIToUTF16("madonna"); |
3533 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); | 3529 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); |
3534 | 3530 |
3535 ASSERT_NO_FATAL_FAILURE(SwitchToAutofill()); | 3531 ASSERT_NO_FATAL_FAILURE(SwitchToAutofill()); |
3536 } | 3532 } |
3537 | 3533 |
3538 } // namespace autofill | 3534 } // namespace autofill |
OLD | NEW |