Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 386873002: Reland "Use upstream libaddressinput in Chrome." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix iOS compile. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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/components_strings.h" 56 #include "grit/components_strings.h"
55 #include "grit/generated_resources.h" 57 #include "grit/generated_resources.h"
56 #include "testing/gmock/include/gmock/gmock.h" 58 #include "testing/gmock/include/gmock/gmock.h"
57 #include "testing/gtest/include/gtest/gtest.h" 59 #include "testing/gtest/include/gtest/gtest.h"
58 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h" 60 #include "third_party/libaddressinput/chromium/chrome_address_validator.h"
59 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_validator.h" 61 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi eld.h"
62 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_pr oblem.h"
60 #include "ui/base/l10n/l10n_util.h" 63 #include "ui/base/l10n/l10n_util.h"
61 #include "ui/base/resource/resource_bundle.h" 64 #include "ui/base/resource/resource_bundle.h"
62 65
63 #if defined(OS_WIN) 66 #if defined(OS_WIN)
64 #include "ui/base/win/scoped_ole_initializer.h" 67 #include "ui/base/win/scoped_ole_initializer.h"
65 #endif 68 #endif
66 69
67 using base::ASCIIToUTF16; 70 using base::ASCIIToUTF16;
68 using base::UTF8ToUTF16; 71 using base::UTF8ToUTF16;
69 72
70 namespace autofill { 73 namespace autofill {
71 74
72 namespace { 75 namespace {
73 76
74 using ::i18n::addressinput::AddressData; 77 using ::i18n::addressinput::FieldProblemMap;
75 using ::i18n::addressinput::AddressProblemFilter;
76 using ::i18n::addressinput::AddressProblem;
77 using ::i18n::addressinput::AddressProblems;
78 using ::i18n::addressinput::AddressValidator;
79 using testing::AtLeast; 78 using testing::AtLeast;
80 using testing::DoAll; 79 using testing::DoAll;
81 using testing::Return; 80 using testing::Return;
82 using testing::SetArgPointee; 81 using testing::SetArgPointee;
83 using testing::_; 82 using testing::_;
84 83
85 const char kSourceUrl[] = "http://localbike.shop"; 84 const char kSourceUrl[] = "http://localbike.shop";
86 const char kFakeEmail[] = "user@chromium.org"; 85 const char kFakeEmail[] = "user@chromium.org";
87 const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; 86 const char kFakeFingerprintEncoded[] = "CgVaAwiACA==";
88 const char kEditedBillingAddress[] = "123 edited billing address"; 87 const char kEditedBillingAddress[] = "123 edited billing address";
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 1013
1015 AutofillProfile verified_profile(test::GetVerifiedProfile()); 1014 AutofillProfile verified_profile(test::GetVerifiedProfile());
1016 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); 1015 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
1017 EXPECT_EQ(4, shipping_model->GetItemCount()); 1016 EXPECT_EQ(4, shipping_model->GetItemCount());
1018 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); 1017 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING));
1019 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); 1018 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING));
1020 1019
1021 // Now make up a problem and make sure the profile isn't in the list. 1020 // Now make up a problem and make sure the profile isn't in the list.
1022 Reset(); 1021 Reset();
1023 SwitchToAutofill(); 1022 SwitchToAutofill();
1024 AddressProblems problems; 1023 FieldProblemMap problems;
1025 problems.push_back( 1024 problems.insert(std::make_pair(::i18n::addressinput::POSTAL_CODE,
1026 AddressProblem(::i18n::addressinput::POSTAL_CODE, 1025 ::i18n::addressinput::MISMATCHING_VALUE));
1027 AddressProblem::MISMATCHING_VALUE,
1028 IDS_LEARN_MORE));
1029 EXPECT_CALL(*controller()->GetMockValidator(), 1026 EXPECT_CALL(*controller()->GetMockValidator(),
1030 ValidateAddress(CountryCodeMatcher("US"), _, _)). 1027 ValidateAddress(CountryCodeMatcher("US"), _, _)).
1031 WillRepeatedly(DoAll(SetArgPointee<2>(problems), 1028 WillRepeatedly(DoAll(SetArgPointee<2>(problems),
1032 Return(AddressValidator::SUCCESS))); 1029 Return(AddressValidator::SUCCESS)));
1033 1030
1034 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); 1031 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
1035 shipping_model = GetMenuModelForSection(SECTION_SHIPPING); 1032 shipping_model = GetMenuModelForSection(SECTION_SHIPPING);
1036 EXPECT_EQ(4, shipping_model->GetItemCount()); 1033 EXPECT_EQ(4, shipping_model->GetItemCount());
1037 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); 1034 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING));
1038 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); 1035 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING));
1039 } 1036 }
1040 1037
1041 // Makes sure suggestion profiles are re-validated when validation rules load. 1038 // Makes sure suggestion profiles are re-validated when validation rules load.
1042 TEST_F(AutofillDialogControllerTest, AutofillProfilesRevalidateAfterRulesLoad) { 1039 TEST_F(AutofillDialogControllerTest, AutofillProfilesRevalidateAfterRulesLoad) {
1043 SwitchToAutofill(); 1040 SwitchToAutofill();
1044 SuggestionsMenuModel* shipping_model = 1041 SuggestionsMenuModel* shipping_model =
1045 GetMenuModelForSection(SECTION_SHIPPING); 1042 GetMenuModelForSection(SECTION_SHIPPING);
1046 EXPECT_EQ(3, shipping_model->GetItemCount()); 1043 EXPECT_EQ(3, shipping_model->GetItemCount());
1047 // "Same as billing" is selected. 1044 // "Same as billing" is selected.
1048 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); 1045 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING));
1049 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); 1046 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING));
1050 AutofillProfile verified_profile(test::GetVerifiedProfile()); 1047 AutofillProfile verified_profile(test::GetVerifiedProfile());
1051 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); 1048 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
1052 EXPECT_EQ(4, shipping_model->GetItemCount()); 1049 EXPECT_EQ(4, shipping_model->GetItemCount());
1053 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); 1050 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING));
1054 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); 1051 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING));
1055 1052
1056 AddressProblems problems; 1053 FieldProblemMap problems;
1057 problems.push_back( 1054 problems.insert(std::make_pair(::i18n::addressinput::POSTAL_CODE,
1058 AddressProblem(::i18n::addressinput::POSTAL_CODE, 1055 ::i18n::addressinput::MISMATCHING_VALUE));
1059 AddressProblem::MISMATCHING_VALUE,
1060 IDS_LEARN_MORE));
1061 EXPECT_CALL(*controller()->GetMockValidator(), 1056 EXPECT_CALL(*controller()->GetMockValidator(),
1062 ValidateAddress(CountryCodeMatcher("US"), _, _)). 1057 ValidateAddress(CountryCodeMatcher("US"), _, _)).
1063 WillRepeatedly(DoAll(SetArgPointee<2>(problems), 1058 WillRepeatedly(DoAll(SetArgPointee<2>(problems),
1064 Return(AddressValidator::SUCCESS))); 1059 Return(AddressValidator::SUCCESS)));
1065 1060
1066 controller()->OnAddressValidationRulesLoaded("US", true); 1061 controller()->OnAddressValidationRulesLoaded("US", true);
1067 EXPECT_EQ(4, shipping_model->GetItemCount()); 1062 EXPECT_EQ(4, shipping_model->GetItemCount());
1068 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); 1063 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING));
1069 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING)); 1064 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING));
1070 } 1065 }
(...skipping 2591 matching lines...) Expand 10 before | Expand all | Expand 10 after
3662 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(2)->value); 3657 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(2)->value);
3663 EXPECT_EQ(ADDRESS_HOME_COUNTRY, 3658 EXPECT_EQ(ADDRESS_HOME_COUNTRY,
3664 form_structure()->field(3)->Type().GetStorableType()); 3659 form_structure()->field(3)->Type().GetStorableType());
3665 EXPECT_EQ(ASCIIToUTF16("US"), form_structure()->field(3)->value); 3660 EXPECT_EQ(ASCIIToUTF16("US"), form_structure()->field(3)->value);
3666 EXPECT_EQ(ADDRESS_HOME_COUNTRY, 3661 EXPECT_EQ(ADDRESS_HOME_COUNTRY,
3667 form_structure()->field(4)->Type().GetStorableType()); 3662 form_structure()->field(4)->Type().GetStorableType());
3668 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(4)->value); 3663 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(4)->value);
3669 } 3664 }
3670 3665
3671 } // namespace autofill 3666 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc ('k') | chrome/browser/ui/autofill/autofill_dialog_i18n_input.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698