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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/file_util.h" | |
8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/rand_util.h" | |
10 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/string_number_conversions.h" | |
14 #include "base/string_split.h" | |
15 #include "base/time.h" | |
11 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | |
12 #include "chrome/browser/api/infobars/infobar_tab_service.h" | 18 #include "chrome/browser/api/infobars/infobar_tab_service.h" |
13 #include "chrome/browser/autofill/autofill_common_test.h" | 19 #include "chrome/browser/autofill/autofill_common_test.h" |
14 #include "chrome/browser/autofill/autofill_profile.h" | 20 #include "chrome/browser/autofill/autofill_profile.h" |
21 #include "chrome/browser/autofill/credit_card.h" | |
15 #include "chrome/browser/autofill/personal_data_manager.h" | 22 #include "chrome/browser/autofill/personal_data_manager.h" |
16 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 23 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
17 #include "chrome/browser/autofill/personal_data_manager_observer.h" | 24 #include "chrome/browser/autofill/personal_data_manager_observer.h" |
18 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/translate/translate_infobar_delegate.h" | 26 #include "chrome/browser/translate/translate_infobar_delegate.h" |
20 #include "chrome/browser/translate/translate_manager.h" | 27 #include "chrome/browser/translate/translate_manager.h" |
21 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/browser_tabstrip.h" | 29 #include "chrome/browser/ui/browser_tabstrip.h" |
23 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 31 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
25 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/render_messages.h" | 33 #include "chrome/common/render_messages.h" |
27 #include "chrome/test/base/in_process_browser_test.h" | 34 #include "chrome/test/base/in_process_browser_test.h" |
28 #include "chrome/test/base/ui_test_utils.h" | 35 #include "chrome/test/base/ui_test_utils.h" |
29 #include "content/public/browser/navigation_controller.h" | 36 #include "content/public/browser/navigation_controller.h" |
37 #include "content/public/browser/notification_observer.h" | |
38 #include "content/public/browser/notification_registrar.h" | |
30 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
31 #include "content/public/browser/render_view_host.h" | 40 #include "content/public/browser/render_view_host.h" |
32 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
33 #include "content/public/test/browser_test_utils.h" | 42 #include "content/public/test/browser_test_utils.h" |
34 #include "content/public/test/test_renderer_host.h" | 43 #include "content/public/test/test_renderer_host.h" |
35 #include "net/url_request/test_url_fetcher_factory.h" | 44 #include "net/url_request/test_url_fetcher_factory.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
37 #include "ui/base/keycodes/keyboard_codes.h" | 46 #include "ui/base/keycodes/keyboard_codes.h" |
38 | 47 |
39 using content::RenderViewHost; | 48 using content::RenderViewHost; |
(...skipping 25 matching lines...) Expand all Loading... | |
65 "<label for=\"country\">Country:</label>" | 74 "<label for=\"country\">Country:</label>" |
66 " <select id=\"country\">" | 75 " <select id=\"country\">" |
67 " <option value=\"\" selected=\"yes\">--</option>" | 76 " <option value=\"\" selected=\"yes\">--</option>" |
68 " <option value=\"CA\">Canada</option>" | 77 " <option value=\"CA\">Canada</option>" |
69 " <option value=\"US\">United States</option>" | 78 " <option value=\"US\">United States</option>" |
70 " </select><br>" | 79 " </select><br>" |
71 "<label for=\"phone\">Phone number:</label>" | 80 "<label for=\"phone\">Phone number:</label>" |
72 " <input type=\"text\" id=\"phone\"><br>" | 81 " <input type=\"text\" id=\"phone\"><br>" |
73 "</form>"; | 82 "</form>"; |
74 | 83 |
75 class WindowedPersonalDataManagerObserver : public PersonalDataManagerObserver { | 84 class WindowedPersonalDataManagerObserver |
85 : public PersonalDataManagerObserver, | |
86 public content::NotificationObserver { | |
76 public: | 87 public: |
77 WindowedPersonalDataManagerObserver() : | 88 explicit WindowedPersonalDataManagerObserver(Browser* browser) : |
78 personal_data_changed_(false), | 89 alerted_(false), |
79 has_run_message_loop_(false) { | 90 has_run_message_loop_(false), |
91 browser_(browser), | |
92 infobar_service_(NULL) { | |
93 PersonalDataManagerFactory::GetForProfile(browser_->profile())-> | |
94 SetObserver(this); | |
95 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | |
96 content::NotificationService::AllSources()); | |
97 } | |
98 | |
99 ~WindowedPersonalDataManagerObserver() { | |
100 if (!infobar_service_) | |
101 return; | |
102 | |
103 InfoBarDelegate* infobar = NULL; | |
104 if (infobar_service_->GetInfoBarCount() > 0 && | |
105 (infobar = infobar_service_->GetInfoBarDelegateAt(0))) { | |
106 infobar_service_->RemoveInfoBar(infobar); | |
107 } | |
80 } | 108 } |
81 | 109 |
82 void Wait() { | 110 void Wait() { |
83 if (!personal_data_changed_) { | 111 if (!alerted_) { |
84 has_run_message_loop_ = true; | 112 has_run_message_loop_ = true; |
85 content::RunMessageLoop(); | 113 content::RunMessageLoop(); |
86 } | 114 } |
115 PersonalDataManagerFactory::GetForProfile(browser_->profile())-> | |
116 RemoveObserver(this); | |
87 } | 117 } |
88 | 118 |
89 void OnPersonalDataChanged() OVERRIDE { | 119 // PersonalDataManagerObserver: |
120 virtual void OnPersonalDataChanged() OVERRIDE { | |
90 if (has_run_message_loop_) { | 121 if (has_run_message_loop_) { |
91 MessageLoopForUI::current()->Quit(); | 122 MessageLoopForUI::current()->Quit(); |
92 has_run_message_loop_ = false; | 123 has_run_message_loop_ = false; |
93 } | 124 } |
94 personal_data_changed_ = true; | 125 alerted_ = true; |
126 } | |
127 | |
128 virtual void OnInsufficientFormData() OVERRIDE { | |
129 OnPersonalDataChanged(); | |
130 } | |
131 | |
132 // content::NotificationObserver: | |
133 virtual void Observe(int type, | |
134 const content::NotificationSource& source, | |
135 const content::NotificationDetails& details) OVERRIDE { | |
136 // Accept in the infobar. | |
137 infobar_service_ = | |
138 InfoBarTabService::ForTab(chrome::GetActiveTabContents(browser_)); | |
139 InfoBarDelegate* infobar = infobar_service_->GetInfoBarDelegateAt(0); | |
140 | |
141 ConfirmInfoBarDelegate* confirm_infobar = | |
142 infobar->AsConfirmInfoBarDelegate(); | |
143 confirm_infobar->Accept(); | |
95 } | 144 } |
96 | 145 |
97 private: | 146 private: |
98 bool personal_data_changed_; | 147 bool alerted_; |
99 bool has_run_message_loop_; | 148 bool has_run_message_loop_; |
149 Browser* browser_; | |
150 content::NotificationRegistrar registrar_; | |
151 InfoBarTabService* infobar_service_; | |
100 }; | 152 }; |
101 | 153 |
102 class AutofillTest : public InProcessBrowserTest { | 154 class AutofillTest : public InProcessBrowserTest { |
103 protected: | 155 protected: |
104 AutofillTest() {} | 156 AutofillTest() {} |
105 | 157 |
158 PersonalDataManager* personal_data_manager() { | |
159 return PersonalDataManagerFactory::GetForProfile(browser()->profile()); | |
160 } | |
161 | |
106 void CreateTestProfile() { | 162 void CreateTestProfile() { |
107 autofill_test::DisableSystemServices(browser()->profile()); | 163 autofill_test::DisableSystemServices(browser()->profile()); |
108 | 164 |
109 AutofillProfile profile; | 165 AutofillProfile profile; |
110 autofill_test::SetProfileInfo( | 166 autofill_test::SetProfileInfo( |
111 &profile, "Milton", "C.", "Waddams", | 167 &profile, "Milton", "C.", "Waddams", |
112 "red.swingline@initech.com", "Initech", "4120 Freidrich Lane", | 168 "red.swingline@initech.com", "Initech", "4120 Freidrich Lane", |
113 "Basement", "Austin", "Texas", "78744", "United States", "5125551234"); | 169 "Basement", "Austin", "Texas", "78744", "United States", "5125551234"); |
114 | 170 |
115 PersonalDataManager* personal_data_manager = | 171 WindowedPersonalDataManagerObserver observer(browser()); |
116 PersonalDataManagerFactory::GetForProfile(browser()->profile()); | 172 personal_data_manager()->AddProfile(profile); |
117 ASSERT_TRUE(personal_data_manager); | |
118 | |
119 WindowedPersonalDataManagerObserver observer; | |
120 personal_data_manager->SetObserver(&observer); | |
121 | |
122 personal_data_manager->AddProfile(profile); | |
123 | 173 |
124 // AddProfile is asynchronous. Wait for it to finish before continuing the | 174 // AddProfile is asynchronous. Wait for it to finish before continuing the |
125 // tests. | 175 // tests. |
126 observer.Wait(); | 176 observer.Wait(); |
127 personal_data_manager->RemoveObserver(&observer); | 177 } |
178 | |
179 void SetProfiles(std::vector<AutofillProfile>* profiles) { | |
180 WindowedPersonalDataManagerObserver observer(browser()); | |
181 personal_data_manager()->SetProfiles(profiles); | |
182 observer.Wait(); | |
183 } | |
184 | |
185 void SetProfile(const AutofillProfile& profile) { | |
186 std::vector<AutofillProfile> profiles; | |
187 profiles.push_back(profile); | |
188 SetProfiles(&profiles); | |
189 } | |
190 | |
191 void SetCards(std::vector<CreditCard>* cards) { | |
192 WindowedPersonalDataManagerObserver observer(browser()); | |
193 personal_data_manager()->SetCreditCards(cards); | |
194 observer.Wait(); | |
195 } | |
196 | |
197 void SetCard(const CreditCard& card) { | |
198 std::vector<CreditCard> cards; | |
199 cards.push_back(card); | |
200 SetCards(&cards); | |
201 } | |
202 | |
203 typedef std::map<std::string, std::string> FormMap; | |
204 // Navigate to the form, input values into the fields, and submit the form. | |
205 // The function returns after the PersonalDataManager is updated. | |
206 void FillFormAndSubmit(const std::string& filename, const FormMap& data) { | |
207 GURL url = test_server()->GetURL("files/autofill/" + filename); | |
208 ui_test_utils::NavigateToURL(browser(), url); | |
209 | |
210 std::string js; | |
211 for (FormMap::const_iterator i = data.begin(); i != data.end(); ++i) { | |
212 js += "document.getElementById('" + i->first + "').value = '" + | |
213 i->second + "';"; | |
214 } | |
215 js += "document.getElementById('testform').submit();"; | |
216 | |
217 WindowedPersonalDataManagerObserver observer(browser()); | |
218 ASSERT_TRUE( | |
219 content::ExecuteJavaScript(render_view_host(), L"", ASCIIToWide(js))); | |
220 observer.Wait(); | |
221 } | |
222 | |
223 void SubmitCreditCard(const char* name, | |
224 const char* number, | |
225 const char* exp_month, | |
226 const char* exp_year) { | |
227 FormMap data; | |
228 data["CREDIT_CARD_NAME"] = name; | |
229 data["CREDIT_CARD_NUMBER"] = number; | |
230 data["CREDIT_CARD_EXP_MONTH"] = exp_month; | |
231 data["CREDIT_CARD_EXP_4_DIGIT_YEAR"] = exp_year; | |
232 FillFormAndSubmit("autofill_creditcard_form.html", data); | |
233 } | |
234 | |
235 // Populates a webpage form using autofill data and keypress events. | |
236 // This function focuses the specified input field in the form, and then | |
237 // sends keypress events to the tab to cause the form to be populated. | |
238 void PopulateForm(const std::string& field_id) { | |
239 std::string js("document.getElementById('" + field_id + "').focus();"); | |
240 ASSERT_TRUE( | |
241 content::ExecuteJavaScript(render_view_host(), L"", ASCIIToWide(js))); | |
242 | |
243 SendKeyAndWait(ui::VKEY_DOWN, | |
244 chrome::NOTIFICATION_AUTOFILL_DID_SHOW_SUGGESTIONS); | |
245 SendKeyAndWait(ui::VKEY_DOWN, | |
246 chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA); | |
247 SendKeyAndWait(ui::VKEY_RETURN, | |
248 chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA); | |
249 } | |
250 | |
251 // Aggregate profiles from forms into Autofill preferences. Returns the number | |
252 // of parsed profiles. | |
253 int AggregateProfilesIntoAutofillPrefs(const std::string& filename) { | |
254 CHECK(test_server()->Start()); | |
255 | |
256 std::string data; | |
257 FilePath data_file = ui_test_utils::GetTestFilePath( | |
258 FilePath().AppendASCII("autofill"), FilePath().AppendASCII(filename)); | |
259 CHECK(file_util::ReadFileToString(data_file, &data)); | |
260 std::vector<std::string> lines; | |
261 base::SplitString(data, '\n', &lines); | |
262 for (size_t i = 0; i < lines.size(); ++i) { | |
263 if (StartsWithASCII(lines[i], "#", false)) | |
264 continue; | |
265 std::vector<std::string> fields; | |
266 base::SplitString(lines[i], '|', &fields); | |
267 if (fields.empty()) | |
268 continue; // Blank line. | |
269 CHECK_EQ(12u, fields.size()); | |
270 | |
271 FormMap data; | |
272 data["NAME_FIRST"] = fields[0]; | |
273 data["NAME_MIDDLE"] = fields[1]; | |
274 data["NAME_LAST"] = fields[2]; | |
275 data["EMAIL_ADDRESS"] = fields[3]; | |
276 data["COMPANY_NAME"] = fields[4]; | |
277 data["ADDRESS_HOME_LINE1"] = fields[5]; | |
278 data["ADDRESS_HOME_LINE2"] = fields[6]; | |
279 data["ADDRESS_HOME_CITY"] = fields[7]; | |
280 data["ADDRESS_HOME_STATE"] = fields[8]; | |
281 data["ADDRESS_HOME_ZIP"] = fields[9]; | |
282 data["ADDRESS_HOME_COUNTRY"] = fields[10]; | |
283 data["PHONE_HOME_WHOLE_NUMBER"] = fields[11]; | |
284 | |
285 FillFormAndSubmit("duplicate_profiles_test.html", data); | |
286 } | |
287 return lines.size(); | |
128 } | 288 } |
129 | 289 |
130 void ExpectFieldValue(const std::wstring& field_name, | 290 void ExpectFieldValue(const std::wstring& field_name, |
131 const std::string& expected_value) { | 291 const std::string& expected_value) { |
132 std::string value; | 292 std::string value; |
133 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 293 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
134 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 294 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
135 L"window.domAutomationController.send(" | 295 L"window.domAutomationController.send(" |
136 L"document.getElementById('" + field_name + L"').value);", &value)); | 296 L"document.getElementById('" + field_name + L"').value);", &value)); |
137 EXPECT_EQ(expected_value, value); | 297 EXPECT_EQ(expected_value, value); |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
700 // Once click the text field, it starts again. | 860 // Once click the text field, it starts again. |
701 ASSERT_TRUE(content::ExecuteJavaScript( | 861 ASSERT_TRUE(content::ExecuteJavaScript( |
702 render_view_host(), L"", | 862 render_view_host(), L"", |
703 L"cr.googleTranslate.onTranslateElementLoad();")); | 863 L"cr.googleTranslate.onTranslateElementLoad();")); |
704 | 864 |
705 // Simulate the render notifying the translation has been done. | 865 // Simulate the render notifying the translation has been done. |
706 translation_observer.Wait(); | 866 translation_observer.Wait(); |
707 | 867 |
708 TryBasicFormFill(); | 868 TryBasicFormFill(); |
709 } | 869 } |
870 | |
871 // Test filling profiles and overwriting with new profiles. | |
872 IN_PROC_BROWSER_TEST_F(AutofillTest, FillProfile) { | |
873 // Test getting profiles when none have been filled. | |
874 ASSERT_TRUE(personal_data_manager()->profiles().empty()); | |
875 ASSERT_TRUE(personal_data_manager()->credit_cards().empty()); | |
876 | |
877 AutofillProfile profile; | |
878 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob")); | |
879 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); | |
880 profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("94043")); | |
881 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("sue@example.com")); | |
882 profile.SetInfo(COMPANY_NAME, ASCIIToUTF16("Company X")); | |
883 | |
884 CreditCard credit_card; | |
885 credit_card.SetInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("6011111111111117")); | |
886 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("12")); | |
887 credit_card.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2011")); | |
888 credit_card.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bob C. Smith")); | |
889 | |
890 SetProfile(profile); | |
891 SetCard(credit_card); | |
892 | |
893 ASSERT_EQ(1u, personal_data_manager()->profiles().size()); | |
894 ASSERT_EQ(profile, *personal_data_manager()->profiles()[0]); | |
895 | |
896 ASSERT_EQ(1u, personal_data_manager()->credit_cards().size()); | |
897 ASSERT_EQ(credit_card, *personal_data_manager()->credit_cards()[0]); | |
898 } | |
899 | |
900 // Test filling a profile with multi-value data. | |
901 IN_PROC_BROWSER_TEST_F(AutofillTest, FillProfileMultiValue) { | |
902 AutofillProfile profile; | |
903 std::vector<string16> first_names, last_names; | |
904 first_names.push_back(ASCIIToUTF16("Bob")); | |
905 first_names.push_back(ASCIIToUTF16("Joe")); | |
906 profile.SetMultiInfo(NAME_FIRST, first_names); | |
907 last_names.push_back(ASCIIToUTF16("Smith")); | |
908 last_names.push_back(ASCIIToUTF16("Jones")); | |
909 profile.SetMultiInfo(NAME_LAST, last_names); | |
910 profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("94043")); | |
911 | |
912 SetProfile(profile); | |
913 ASSERT_EQ(1u, personal_data_manager()->profiles().size()); | |
914 ASSERT_EQ(profile, *personal_data_manager()->profiles()[0]); | |
915 } | |
Ilya Sherman
2012/08/21 07:24:17
This test is redundant with PersonalDataManagerTes
| |
916 | |
917 // Test filling profiles with unicode strings and crazy characters. | |
918 IN_PROC_BROWSER_TEST_F(AutofillTest, FillProfileCrazyCharacters) { | |
919 std::vector<AutofillProfile> profiles; | |
920 AutofillProfile profile1; | |
921 profile1.SetInfo(NAME_FIRST, WideToUTF16(L"\u0623\u0648\u0628\u0627\u0645\u062 7 \u064a\u0639\u062a\u0630\u0631 \u0647\u0627\u062a\u0641\u064a\u0627 \u0644\u06 45\u0648\u0638\u0641\u0629 \u0633\u0648\u062f\u0627\u0621 \u0627\u0633\u062a\u06 42\u0627\u0644\u062a \u0628\u0633\u0628\u0628 \u062a\u0635\u0631\u064a\u062d\u06 27\u062a \u0645\u062c\u062a\u0632\u0623\u0629")); | |
922 profile1.SetInfo(NAME_MIDDLE, WideToUTF16(L"BANK\xcBERF\xc4LLE")); | |
923 profile1.SetInfo(EMAIL_ADDRESS, WideToUTF16(L"\uacbd\uc81c \ub274\uc2a4 \ub354 \ubcf4\uae30@google.com")); | |
924 profile1.SetInfo(ADDRESS_HOME_LINE1, WideToUTF16(L"\uad6d\uc815\uc6d0\xb7\uac8 0\ucc30, \ub178\ubb34\ud604\uc815\ubd80 \ub300\ubd81\uc811\ucd09 \ub2f4\ub2f9 \u c778\uc0ac\ub4e4 \uc870\uc0ac")); | |
925 profile1.SetInfo(ADDRESS_HOME_CITY, WideToUTF16(L"\u653f\u5e9c\u4e0d\u6392\u96 64\u7acb\u6cd5\u898f\u7ba1\u5c0e\u904a")); | |
926 profile1.SetInfo(ADDRESS_HOME_ZIP, WideToUTF16(L"YOHO_54676")); | |
927 profile1.SetInfo(PHONE_HOME_WHOLE_NUMBER, WideToUTF16(L"861088828000")); | |
928 profile1.SetInfo(ADDRESS_HOME_COUNTRY, WideToUTF16(L"India")); | |
929 profiles.push_back(profile1); | |
930 | |
931 AutofillProfile profile2; | |
932 profile2.SetInfo(NAME_FIRST, WideToUTF16(L"\u4e0a\u6d77\u5e02\u91d1\u5c71\u533 a \u677e\u9690\u9547\u4ead\u67ab\u516c\u8def1915\u53f7")); | |
933 profile2.SetInfo(NAME_LAST, WideToUTF16(L"aguantó")); | |
934 profile2.SetInfo(ADDRESS_HOME_ZIP, WideToUTF16(L"HOME 94043")); | |
935 profiles.push_back(profile2); | |
936 | |
937 AutofillProfile profile3; | |
938 profile3.SetInfo(EMAIL_ADDRESS, WideToUTF16(L"sue@example.com")); | |
939 profile3.SetInfo(COMPANY_NAME, WideToUTF16(L"Company X")); | |
940 profiles.push_back(profile3); | |
941 | |
942 AutofillProfile profile4; | |
943 profile4.SetInfo(NAME_FIRST, WideToUTF16(L"Joe 3254")); | |
944 profile4.SetInfo(NAME_LAST, WideToUTF16(L"\u8bb0\u8d262\u5e74\u591a")); | |
945 profile4.SetInfo(ADDRESS_HOME_ZIP, WideToUTF16(L"\uff08\u90ae\u7f16\uff1a20150 4\uff09")); | |
946 profile4.SetInfo(EMAIL_ADDRESS, WideToUTF16(L"télévision@example.com")); | |
947 profile4.SetInfo(COMPANY_NAME, WideToUTF16(L"\u0907\u0932\u0947\u0915\u093f\u0 91f\u094d\u0930\u0928\u093f\u0915\u094d\u0938, \u0905\u092a\u094b\u0932\u094b \u 091f\u093e\u092f\u0930\u094d\u0938 \u0906\u0926\u093f")); | |
948 profiles.push_back(profile4); | |
949 | |
950 AutofillProfile profile5; | |
951 profile5.SetInfo(NAME_FIRST, WideToUTF16(L"Larry")); | |
952 profile5.SetInfo(NAME_LAST, WideToUTF16(L"\u0938\u094d\u091f\u093e\u0902\u092a \u0921\u094d\u092f\u0942\u091f\u0940")); | |
953 profile5.SetInfo(ADDRESS_HOME_ZIP, WideToUTF16(L"111111111111110000GOOGLE")); | |
954 profile5.SetInfo(EMAIL_ADDRESS, WideToUTF16(L"page@000000.com")); | |
955 profile5.SetInfo(COMPANY_NAME, WideToUTF16(L"Google")); | |
956 profiles.push_back(profile5); | |
957 | |
958 AutofillProfile profile6; | |
959 profile6.SetInfo(NAME_FIRST, WideToUTF16(L"\u4e0a\u6d77\u5e02\u91d1\u5c71\u533 a \u677e\u9690\u9547\u4ead\u67ab\u516c\u8def1915\u53f7")); | |
960 profile6.SetInfo(NAME_LAST, WideToUTF16(L"\u0646\u062c\u0627\u0645\u064a\u0646 \u0627 \u062f\u0639\u0645\u0647\u0627 \u0644\u0644\u0631\u0626\u064a\u0633 \u062 7\u0644\u0633\u0648\u062f\u0627\u0646\u064a \u0639\u0645\u0631 \u0627\u0644\u062 8\u0634\u064a\u0631")); | |
961 profile6.SetInfo(ADDRESS_HOME_ZIP, WideToUTF16(L"HOME 94043")); | |
962 profiles.push_back(profile6); | |
963 | |
964 AutofillProfile profile7; | |
965 profile7.SetInfo(NAME_FIRST, WideToUTF16(L"&$%$$$ TESTO *&*&^&^& MOKO")); | |
966 profile7.SetInfo(NAME_MIDDLE, WideToUTF16(L"WOHOOOO$$$$$$$$****")); | |
967 profile7.SetInfo(EMAIL_ADDRESS, WideToUTF16(L"yuvu@example.com")); | |
968 profile7.SetInfo(ADDRESS_HOME_LINE1, WideToUTF16(L"34544, anderson ST.(120230) ")); | |
969 profile7.SetInfo(ADDRESS_HOME_CITY, WideToUTF16(L"Sunnyvale")); | |
970 profile7.SetInfo(ADDRESS_HOME_STATE, WideToUTF16(L"CA")); | |
971 profile7.SetInfo(ADDRESS_HOME_ZIP, WideToUTF16(L"94086")); | |
972 profile7.SetInfo(PHONE_HOME_WHOLE_NUMBER, WideToUTF16(L"15466784565")); | |
973 profile7.SetInfo(ADDRESS_HOME_COUNTRY, WideToUTF16(L"United States")); | |
974 profiles.push_back(profile7); | |
975 | |
976 SetProfiles(&profiles); | |
977 ASSERT_EQ(profiles.size(), personal_data_manager()->profiles().size()); | |
978 for (size_t i = 0; i < profiles.size(); ++i) | |
979 ASSERT_EQ(profiles[i], *personal_data_manager()->profiles()[i]); | |
980 | |
981 std::vector<CreditCard> cards; | |
982 CreditCard card1; | |
983 card1.SetInfo(CREDIT_CARD_NAME, WideToUTF16(L"\u751f\u6d3b\u5f88\u6709\u89c4\u 5f8b \u4ee5\u73a9\u4e3a\u4e3b")); | |
984 card1.SetInfo(CREDIT_CARD_NUMBER, WideToUTF16(L"6011111111111117")); | |
985 card1.SetInfo(CREDIT_CARD_EXP_MONTH, WideToUTF16(L"12")); | |
986 card1.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, WideToUTF16(L"2011")); | |
987 cards.push_back(card1); | |
988 | |
989 CreditCard card2; | |
990 card2.SetInfo(CREDIT_CARD_NAME, WideToUTF16(L"John Williams")); | |
991 card2.SetInfo(CREDIT_CARD_NUMBER, WideToUTF16(L"WokoAwesome12345")); | |
992 card2.SetInfo(CREDIT_CARD_EXP_MONTH, WideToUTF16(L"10")); | |
993 card2.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, WideToUTF16(L"2015")); | |
994 cards.push_back(card2); | |
995 | |
996 CreditCard card3; | |
997 card3.SetInfo(CREDIT_CARD_NAME, WideToUTF16(L"\u0623\u062d\u0645\u062f\u064a \ u0646\u062c\u0627\u062f \u0644\u0645\u062d\u0627\u0648\u0644\u0647 \u0627\u063a\ u062a\u064a\u0627\u0644 \u0641\u064a \u0645\u062f\u064a\u0646\u0629 \u0647\u0645 \u062f\u0627\u0646 ")); | |
998 card3.SetInfo(CREDIT_CARD_NUMBER, WideToUTF16(L"\u092a\u0941\u0928\u0930\u094d \u091c\u0940\u0935\u093f\u0924 \u0939\u094b\u0917\u093e \u0928\u093e\u0932\u0902 \u0926\u093e")); | |
999 card3.SetInfo(CREDIT_CARD_EXP_MONTH, WideToUTF16(L"10")); | |
1000 card3.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, WideToUTF16(L"2015")); | |
1001 cards.push_back(card3); | |
1002 | |
1003 CreditCard card4; | |
1004 card4.SetInfo(CREDIT_CARD_NAME, WideToUTF16(L"\u039d\u03ad\u03b5\u03c2 \u03c3\ u03c5\u03b3\u03c7\u03c9\u03bd\u03b5\u03cd\u03c3\u03b5\u03b9\u03c2 \u03ba\u03b1\u 03b9 \u03ba\u03b1\u03c4\u03b1\u03c1\u03b3\u03ae\u03c3\u03b5\u03b9\u03c2")); | |
1005 card4.SetInfo(CREDIT_CARD_NUMBER, WideToUTF16(L"00000000000000000000000")); | |
1006 card4.SetInfo(CREDIT_CARD_EXP_MONTH, WideToUTF16(L"01")); | |
1007 card4.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, WideToUTF16(L"2016")); | |
1008 cards.push_back(card4); | |
1009 | |
1010 SetCards(&cards); | |
1011 ASSERT_EQ(cards.size(), personal_data_manager()->credit_cards().size()); | |
1012 for (size_t i = 0; i < cards.size(); ++i) | |
1013 ASSERT_EQ(cards[i], *personal_data_manager()->credit_cards()[i]); | |
1014 } | |
1015 | |
1016 // Test filling in invalid values for profiles are saved as-is. Phone | |
1017 // information entered into the prefs UI is not validated or rejected except for | |
1018 // duplicates. | |
1019 IN_PROC_BROWSER_TEST_F(AutofillTest, Invalid) { | |
1020 // First try profiles with invalid ZIP input. | |
1021 AutofillProfile without_invalid; | |
1022 without_invalid.SetInfo(NAME_FIRST, ASCIIToUTF16("Will")); | |
1023 without_invalid.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Sunnyvale")); | |
1024 without_invalid.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); | |
1025 without_invalid.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("my_zip")); | |
1026 without_invalid.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States")); | |
1027 | |
1028 AutofillProfile with_invalid = without_invalid; | |
1029 with_invalid.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("Invalid_Phone_Numb er")); | |
1030 SetProfile(with_invalid); | |
1031 | |
1032 ASSERT_EQ(1u, personal_data_manager()->profiles().size()); | |
1033 AutofillProfile profile = *personal_data_manager()->profiles()[0]; | |
1034 ASSERT_NE(without_invalid.GetInfo(PHONE_HOME_WHOLE_NUMBER), | |
1035 profile.GetInfo(PHONE_HOME_WHOLE_NUMBER)); | |
1036 } | |
1037 | |
1038 // Test invalid credit card numbers typed in prefs should be saved as-is. | |
1039 IN_PROC_BROWSER_TEST_F(AutofillTest, PrefsStringSavedAsIs) { | |
1040 CreditCard card; | |
1041 card.SetInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("Not_0123-5Checked")); | |
1042 SetCard(card); | |
1043 | |
1044 ASSERT_EQ(1u, personal_data_manager()->credit_cards().size()); | |
1045 ASSERT_EQ(card, *personal_data_manager()->credit_cards()[0]); | |
1046 } | |
1047 | |
1048 // Test credit card info with an invalid number is not aggregated. | |
1049 // When filling out a form with an invalid credit card number (one that does not | |
1050 // pass the Luhn test) the credit card info should not be saved into Autofill | |
1051 // preferences. | |
1052 IN_PROC_BROWSER_TEST_F(AutofillTest, InvalidCreditCardNumberIsNotAggregated) { | |
1053 ASSERT_TRUE(test_server()->Start()); | |
1054 std::string card("4408 0412 3456 7890"); | |
1055 ASSERT_FALSE(CreditCard::IsValidCreditCardNumber(ASCIIToUTF16(card))); | |
1056 SubmitCreditCard("Bob Smith", card.c_str(), "12", "2014"); | |
1057 ASSERT_EQ(0u, | |
1058 InfoBarTabService::ForTab(chrome::GetActiveTabContents(browser()))-> | |
1059 GetInfoBarCount()); | |
1060 } | |
1061 | |
1062 // Test whitespaces and separator chars are stripped for valid CC numbers. | |
1063 // The credit card numbers used in this test pass the Luhn test. For reference: | |
1064 // http://www.merriampark.com/anatomycc.htm | |
1065 IN_PROC_BROWSER_TEST_F(AutofillTest, | |
1066 WhitespacesAndSeparatorCharsStrippedForValidCCNums) { | |
1067 ASSERT_TRUE(test_server()->Start()); | |
1068 SubmitCreditCard("Bob Smith", "4408 0412 3456 7893", "12", "2014"); | |
1069 SubmitCreditCard("Jane Doe", "4417-1234-5678-9113", "10", "2013"); | |
1070 | |
1071 ASSERT_EQ(2u, personal_data_manager()->credit_cards().size()); | |
1072 string16 cc1 = personal_data_manager()->credit_cards()[0]->GetInfo( | |
1073 CREDIT_CARD_NUMBER); | |
1074 ASSERT_TRUE(CreditCard::IsValidCreditCardNumber(cc1)); | |
1075 string16 cc2 = personal_data_manager()->credit_cards()[1]->GetInfo( | |
1076 CREDIT_CARD_NUMBER); | |
1077 ASSERT_TRUE(CreditCard::IsValidCreditCardNumber(cc2)); | |
1078 } | |
1079 | |
1080 // Test that Autofill aggregates a minimum valid profile. | |
1081 // The minimum required address fields must be specified: First Name, Last Name, | |
1082 // Address Line 1, City, Zip Code, and State. | |
1083 IN_PROC_BROWSER_TEST_F(AutofillTest, AggregatesMinValidProfile) { | |
1084 ASSERT_TRUE(test_server()->Start()); | |
1085 FormMap data; | |
1086 data["NAME_FIRST"] = "Bob"; | |
1087 data["NAME_LAST"] = "Smith"; | |
1088 data["ADDRESS_HOME_LINE1"] = "1234 H St."; | |
1089 data["ADDRESS_HOME_CITY"] = "Mountain View"; | |
1090 data["ADDRESS_HOME_STATE"] = "CA"; | |
1091 data["ADDRESS_HOME_ZIP"] = "94043"; | |
1092 FillFormAndSubmit("duplicate_profiles_test.html", data); | |
1093 | |
1094 ASSERT_EQ(1u, personal_data_manager()->profiles().size()); | |
1095 } | |
1096 | |
1097 // Test Autofill does not aggregate profiles with no address info. | |
1098 // The minimum required address fields must be specified: First Name, Last Name, | |
1099 // Address Line 1, City, Zip Code, and State. | |
1100 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfilesNotAggregatedWithNoAddress) { | |
1101 ASSERT_TRUE(test_server()->Start()); | |
1102 FormMap data; | |
1103 data["NAME_FIRST"] = "Bob"; | |
1104 data["NAME_LAST"] = "Smith"; | |
1105 data["EMAIL_ADDRESS"] = "bsmith@example.com"; | |
1106 data["COMPANY_NAME"] = "Mountain View"; | |
1107 data["ADDRESS_HOME_CITY"] = "Mountain View"; | |
1108 data["PHONE_HOME_WHOLE_NUMBER"] = "650-555-4567"; | |
1109 FillFormAndSubmit("duplicate_profiles_test.html", data); | |
1110 | |
1111 ASSERT_TRUE(personal_data_manager()->profiles().empty()); | |
1112 } | |
1113 | |
1114 // Test Autofill does not aggregate profiles with an invalid email. | |
1115 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfilesNotAggregatedWithInvalidEmail) { | |
1116 ASSERT_TRUE(test_server()->Start()); | |
1117 FormMap data; | |
1118 data["NAME_FIRST"] = "Bob"; | |
1119 data["NAME_LAST"] = "Smith"; | |
1120 data["EMAIL_ADDRESS"] = "garbage"; | |
1121 data["ADDRESS_HOME_LINE1"] = "1234 H St."; | |
1122 data["ADDRESS_HOME_CITY"] = "San Jose"; | |
1123 data["ADDRESS_HOME_STATE"] = "CA"; | |
1124 data["ADDRESS_HOME_ZIP"] = "95110"; | |
1125 data["COMPANY_NAME"] = "Company X"; | |
1126 data["PHONE_HOME_WHOLE_NUMBER"] = "408-871-4567"; | |
1127 FillFormAndSubmit("duplicate_profiles_test.html", data); | |
1128 | |
1129 ASSERT_TRUE(personal_data_manager()->profiles().empty()); | |
1130 } | |
1131 | |
1132 // Test phone fields parse correctly from a given profile. | |
1133 // The high level key presses execute the following: Select the first text | |
1134 // field, invoke the autofill popup list, select the first profile within the | |
1135 // list, and commit to the profile to populate the form. | |
1136 IN_PROC_BROWSER_TEST_F(AutofillTest, ComparePhoneNumbers) { | |
1137 ASSERT_TRUE(test_server()->Start()); | |
1138 | |
1139 AutofillProfile profile; | |
1140 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob")); | |
1141 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); | |
1142 profile.SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 H St.")); | |
1143 profile.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("San Jose")); | |
1144 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); | |
1145 profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110")); | |
1146 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1-408-555-4567")); | |
1147 SetProfile(profile); | |
1148 | |
1149 GURL url = test_server()->GetURL("files/autofill/form_phones.html"); | |
1150 ui_test_utils::NavigateToURL(browser(), url); | |
1151 PopulateForm("NAME_FIRST"); | |
1152 | |
1153 ExpectFieldValue(L"NAME_FIRST", "Bob"); | |
1154 ExpectFieldValue(L"NAME_LAST", "Smith"); | |
1155 ExpectFieldValue(L"ADDRESS_HOME_LINE1", "1234 H St."); | |
1156 ExpectFieldValue(L"ADDRESS_HOME_CITY", "San Jose"); | |
1157 ExpectFieldValue(L"ADDRESS_HOME_STATE", "CA"); | |
1158 ExpectFieldValue(L"ADDRESS_HOME_ZIP", "95110"); | |
1159 ExpectFieldValue(L"PHONE_HOME_WHOLE_NUMBER", "14085554567"); | |
1160 ExpectFieldValue(L"PHONE_HOME_CITY_CODE-1", "408"); | |
1161 ExpectFieldValue(L"PHONE_HOME_CITY_CODE-2", "408"); | |
1162 ExpectFieldValue(L"PHONE_HOME_NUMBER", "5554567"); | |
1163 ExpectFieldValue(L"PHONE_HOME_NUMBER_3-1", "555"); | |
1164 ExpectFieldValue(L"PHONE_HOME_NUMBER_3-2", "555"); | |
1165 ExpectFieldValue(L"PHONE_HOME_NUMBER_4-1", "4567"); | |
1166 ExpectFieldValue(L"PHONE_HOME_NUMBER_4-2", "4567"); | |
1167 ExpectFieldValue(L"PHONE_HOME_EXT-1", ""); | |
1168 ExpectFieldValue(L"PHONE_HOME_EXT-2", ""); | |
1169 ExpectFieldValue(L"PHONE_HOME_COUNTRY_CODE-1", "1"); | |
1170 } | |
1171 | |
1172 // Test profile is saved if phone number is valid in selected country. | |
1173 // The data file contains two profiles with valid phone numbers and two | |
1174 // profiles with invalid phone numbers from their respective country. | |
1175 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfileSavedWithValidCountryPhone) { | |
1176 ASSERT_TRUE(test_server()->Start()); | |
1177 std::vector<FormMap> profiles; | |
1178 | |
1179 FormMap data1; | |
1180 data1["NAME_FIRST"] = "Bob"; | |
1181 data1["NAME_LAST"] = "Smith"; | |
1182 data1["ADDRESS_HOME_LINE1"] = "123 Cherry Ave"; | |
1183 data1["ADDRESS_HOME_CITY"] = "Mountain View"; | |
1184 data1["ADDRESS_HOME_STATE"] = "CA"; | |
1185 data1["ADDRESS_HOME_ZIP"] = "94043"; | |
1186 data1["ADDRESS_HOME_COUNTRY"] = "United States"; | |
1187 data1["PHONE_HOME_WHOLE_NUMBER"] = "408-871-4567"; | |
1188 profiles.push_back(data1); | |
1189 | |
1190 FormMap data2; | |
1191 data2["NAME_FIRST"] = "John"; | |
1192 data2["NAME_LAST"] = "Doe"; | |
1193 data2["ADDRESS_HOME_LINE1"] = "987 H St"; | |
1194 data2["ADDRESS_HOME_CITY"] = "San Jose"; | |
1195 data2["ADDRESS_HOME_STATE"] = "CA"; | |
1196 data2["ADDRESS_HOME_ZIP"] = "95510"; | |
1197 data2["ADDRESS_HOME_COUNTRY"] = "United States"; | |
1198 data2["PHONE_HOME_WHOLE_NUMBER"] = "408-123-456"; | |
1199 profiles.push_back(data2); | |
1200 | |
1201 FormMap data3; | |
1202 data3["NAME_FIRST"] = "Jane"; | |
1203 data3["NAME_LAST"] = "Doe"; | |
1204 data3["ADDRESS_HOME_LINE1"] = "1523 Garcia St"; | |
1205 data3["ADDRESS_HOME_CITY"] = "Mountain View"; | |
1206 data3["ADDRESS_HOME_STATE"] = "CA"; | |
1207 data3["ADDRESS_HOME_ZIP"] = "94043"; | |
1208 data3["ADDRESS_HOME_COUNTRY"] = "Germany"; | |
1209 data3["PHONE_HOME_WHOLE_NUMBER"] = "+49 40-80-81-79-000"; | |
1210 profiles.push_back(data3); | |
1211 | |
1212 FormMap data4; | |
1213 data4["NAME_FIRST"] = "Bonnie"; | |
1214 data4["NAME_LAST"] = "Smith"; | |
1215 data4["ADDRESS_HOME_LINE1"] = "6723 Roadway Rd"; | |
1216 data4["ADDRESS_HOME_CITY"] = "San Jose"; | |
1217 data4["ADDRESS_HOME_STATE"] = "CA"; | |
1218 data4["ADDRESS_HOME_ZIP"] = "95510"; | |
1219 data4["ADDRESS_HOME_COUNTRY"] = "Germany"; | |
1220 data4["PHONE_HOME_WHOLE_NUMBER"] = "+21 08450 777 777"; | |
1221 profiles.push_back(data4); | |
1222 | |
1223 for (size_t i = 0; i < profiles.size(); ++i) | |
1224 FillFormAndSubmit("autofill_test_form.html", profiles[i]); | |
1225 | |
1226 ASSERT_EQ(2u, personal_data_manager()->profiles().size()); | |
1227 ASSERT_EQ(ASCIIToUTF16("(408) 871-4567"), | |
1228 personal_data_manager()->profiles()[0]->GetInfo( | |
1229 PHONE_HOME_WHOLE_NUMBER)); | |
1230 ASSERT_EQ(ASCIIToUTF16("+49 40/808179000"), | |
1231 personal_data_manager()->profiles()[1]->GetInfo( | |
1232 PHONE_HOME_WHOLE_NUMBER)); | |
1233 } | |
1234 | |
1235 // Test Autofill appends country codes to aggregated phone numbers. | |
1236 // The country code is added for the following case: | |
1237 // The phone number contains the correct national number size and | |
1238 // is a valid format. | |
1239 IN_PROC_BROWSER_TEST_F(AutofillTest, AppendCountryCodeForAggregatedPhones) { | |
1240 ASSERT_TRUE(test_server()->Start()); | |
1241 FormMap data; | |
1242 data["NAME_FIRST"] = "Bob"; | |
1243 data["NAME_LAST"] = "Smith"; | |
1244 data["ADDRESS_HOME_LINE1"] = "1234 H St."; | |
1245 data["ADDRESS_HOME_CITY"] = "San Jose"; | |
1246 data["ADDRESS_HOME_STATE"] = "CA"; | |
1247 data["ADDRESS_HOME_ZIP"] = "95110"; | |
1248 data["ADDRESS_HOME_COUNTRY"] = "Germany"; | |
1249 data["PHONE_HOME_WHOLE_NUMBER"] = "(08) 450 777-777"; | |
1250 FillFormAndSubmit("autofill_test_form.html", data); | |
1251 | |
1252 ASSERT_EQ(1u, personal_data_manager()->profiles().size()); | |
1253 string16 phone = | |
1254 personal_data_manager()->profiles()[0]->GetInfo(PHONE_HOME_WHOLE_NUMBER); | |
1255 ASSERT_TRUE(StartsWith(phone, ASCIIToUTF16("+49"), true)); | |
1256 } | |
1257 | |
1258 // Test CC info not offered to be saved when autocomplete=off for CC field. | |
1259 // If the credit card number field has autocomplete turned off, then the credit | |
1260 // card infobar should not offer to save the credit card info. The credit card | |
1261 // number must be a valid Luhn number. | |
1262 IN_PROC_BROWSER_TEST_F(AutofillTest, CCInfoNotStoredWhenAutocompleteOff) { | |
1263 ASSERT_TRUE(test_server()->Start()); | |
1264 FormMap data; | |
1265 data["CREDIT_CARD_NAME"] = "Bob Smith"; | |
1266 data["CREDIT_CARD_NUMBER"] = "4408041234567893"; | |
1267 data["CREDIT_CARD_EXP_MONTH"] = "12"; | |
1268 data["CREDIT_CARD_EXP_4_DIGIT_YEAR"] = "2014"; | |
1269 FillFormAndSubmit("cc_autocomplete_off_test.html", data); | |
1270 | |
1271 ASSERT_EQ(0u, | |
1272 InfoBarTabService::ForTab(chrome::GetActiveTabContents(browser()))-> | |
1273 GetInfoBarCount()); | |
1274 } | |
1275 | |
1276 // Test that Autofill does not fill in read-only fields. | |
1277 IN_PROC_BROWSER_TEST_F(AutofillTest, NoAutofillForReadOnlyFields) { | |
1278 ASSERT_TRUE(test_server()->Start()); | |
1279 | |
1280 std::string email("bsmith@gmail.com"); | |
1281 std::string addr_line1("1234 H St."); | |
1282 | |
1283 AutofillProfile profile; | |
1284 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob")); | |
1285 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); | |
1286 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16(email)); | |
1287 profile.SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16(addr_line1)); | |
1288 profile.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("San Jose")); | |
1289 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); | |
1290 profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110")); | |
1291 profile.SetInfo(COMPANY_NAME, ASCIIToUTF16("Company X")); | |
1292 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("408-871-4567")); | |
1293 SetProfile(profile); | |
1294 | |
1295 GURL url = test_server()->GetURL("files/autofill/read_only_field_test.html"); | |
1296 ui_test_utils::NavigateToURL(browser(), url); | |
1297 PopulateForm("firstname"); | |
1298 | |
1299 std::string readonly_field_value; | |
1300 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | |
1301 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | |
1302 L"window.domAutomationController.send(" | |
1303 L"document.getElementById('email').value);", &readonly_field_value)); | |
1304 ASSERT_NE(email, readonly_field_value); | |
1305 | |
1306 ExpectFieldValue(L"address", addr_line1); | |
1307 } | |
1308 | |
1309 // Test form is fillable from a profile after form was reset. | |
1310 // Steps: | |
1311 // 1. Fill form using a saved profile. | |
1312 // 2. Reset the form. | |
1313 // 3. Fill form using a saved profile. | |
1314 IN_PROC_BROWSER_TEST_F(AutofillTest, FormFillableOnReset) { | |
1315 ASSERT_TRUE(test_server()->Start()); | |
1316 | |
1317 CreateTestProfile(); | |
1318 | |
1319 GURL url = test_server()->GetURL("files/autofill/autofill_test_form.html"); | |
1320 ui_test_utils::NavigateToURL(browser(), url); | |
1321 PopulateForm("NAME_FIRST"); | |
1322 | |
1323 ASSERT_TRUE(content::ExecuteJavaScript( | |
1324 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | |
1325 L"document.getElementById('testform').reset()")); | |
1326 | |
1327 PopulateForm("NAME_FIRST"); | |
1328 | |
1329 ExpectFieldValue(L"NAME_FIRST", "Milton"); | |
1330 ExpectFieldValue(L"NAME_LAST", "Waddams"); | |
1331 ExpectFieldValue(L"EMAIL_ADDRESS", "red.swingline@initech.com"); | |
1332 ExpectFieldValue(L"ADDRESS_HOME_LINE1", "4120 Freidrich Lane"); | |
1333 ExpectFieldValue(L"ADDRESS_HOME_CITY", "Austin"); | |
1334 ExpectFieldValue(L"ADDRESS_HOME_STATE", "Texas"); | |
1335 ExpectFieldValue(L"ADDRESS_HOME_ZIP", "78744"); | |
1336 ExpectFieldValue(L"ADDRESS_HOME_COUNTRY", "United States"); | |
1337 ExpectFieldValue(L"PHONE_HOME_WHOLE_NUMBER", "5125551234"); | |
1338 } | |
1339 | |
1340 // Test Autofill distinguishes a middle initial in a name. | |
1341 IN_PROC_BROWSER_TEST_F(AutofillTest, DistinguishMiddleInitialWithinName) { | |
1342 ASSERT_TRUE(test_server()->Start()); | |
1343 | |
1344 CreateTestProfile(); | |
1345 | |
1346 GURL url = test_server()->GetURL( | |
1347 "files/autofill/autofill_middleinit_form.html"); | |
1348 ui_test_utils::NavigateToURL(browser(), url); | |
1349 PopulateForm("NAME_FIRST"); | |
1350 | |
1351 ExpectFieldValue(L"NAME_MIDDLE", "C"); | |
1352 } | |
1353 | |
1354 // Test forms with multiple email addresses are filled properly. | |
1355 // Entire form should be filled with one user gesture. | |
1356 IN_PROC_BROWSER_TEST_F(AutofillTest, MultipleEmailFilledByOneUserGesture) { | |
1357 ASSERT_TRUE(test_server()->Start()); | |
1358 | |
1359 std::string email("bsmith@gmail.com"); | |
1360 | |
1361 AutofillProfile profile; | |
1362 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob")); | |
1363 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); | |
1364 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16(email)); | |
1365 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("4088714567")); | |
1366 SetProfile(profile); | |
1367 | |
1368 GURL url = test_server()->GetURL( | |
1369 "files/autofill/autofill_confirmemail_form.html"); | |
1370 ui_test_utils::NavigateToURL(browser(), url); | |
1371 PopulateForm("NAME_FIRST"); | |
1372 | |
1373 ExpectFieldValue(L"EMAIL_CONFIRM", email); | |
1374 } | |
1375 | |
1376 // Test profile not aggregated if email found in non-email field. | |
1377 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfileWithEmailInOtherFieldNotSaved) { | |
1378 ASSERT_TRUE(test_server()->Start()); | |
1379 | |
1380 FormMap data; | |
1381 data["NAME_FIRST"] = "Bob"; | |
1382 data["NAME_LAST"] = "Smith"; | |
1383 data["ADDRESS_HOME_LINE1"] = "bsmith@gmail.com"; | |
1384 data["ADDRESS_HOME_CITY"] = "San Jose"; | |
1385 data["ADDRESS_HOME_STATE"] = "CA"; | |
1386 data["ADDRESS_HOME_ZIP"] = "95110"; | |
1387 data["COMPANY_NAME"] = "Company X"; | |
1388 data["PHONE_HOME_WHOLE_NUMBER"] = "408-871-4567"; | |
1389 FillFormAndSubmit("duplicate_profiles_test.html", data); | |
1390 | |
1391 ASSERT_EQ(0u, personal_data_manager()->profiles().size()); | |
1392 } | |
1393 | |
1394 // Test latency time on form submit with lots of stored Autofill profiles. | |
1395 // This test verifies when a profile is selected from the Autofill dictionary | |
1396 // that consists of thousands of profiles, the form does not hang after being | |
1397 // submitted. | |
1398 IN_PROC_BROWSER_TEST_F(AutofillTest, FormFillLatencyAfterSubmit) { | |
1399 ASSERT_TRUE(test_server()->Start()); | |
1400 | |
1401 std::vector<std::string> cities; | |
1402 cities.push_back("San Jose"); | |
1403 cities.push_back("San Francisco"); | |
1404 cities.push_back("Sacramento"); | |
1405 cities.push_back("Los Angeles"); | |
1406 | |
1407 std::vector<std::string> streets; | |
1408 streets.push_back("St"); | |
1409 streets.push_back("Ave"); | |
1410 streets.push_back("Ln"); | |
1411 streets.push_back("Ct"); | |
1412 | |
1413 const int kNumProfiles = 1500; | |
1414 base::Time start_time = base::Time::Now(); | |
1415 std::vector<AutofillProfile> profiles; | |
1416 for (int i = 0; i < kNumProfiles; i++) { | |
1417 AutofillProfile profile; | |
1418 string16 name(base::IntToString16(i)); | |
1419 string16 email(name + ASCIIToUTF16("@example.com")); | |
1420 string16 street = ASCIIToUTF16( | |
1421 base::IntToString(base::RandInt(0, 10000)) + " " + | |
1422 streets[base::RandInt(0, streets.size() - 1)]); | |
1423 string16 city = ASCIIToUTF16(cities[base::RandInt(0, cities.size() - 1)]); | |
1424 string16 zip(base::IntToString16(base::RandInt(0, 10000))); | |
1425 profile.SetInfo(NAME_FIRST, name); | |
1426 profile.SetInfo(EMAIL_ADDRESS, email); | |
1427 profile.SetInfo(ADDRESS_HOME_LINE1, street); | |
1428 profile.SetInfo(ADDRESS_HOME_CITY, city); | |
1429 profile.SetInfo(ADDRESS_HOME_STATE, WideToUTF16(L"CA")); | |
1430 profile.SetInfo(ADDRESS_HOME_ZIP, zip); | |
1431 profile.SetInfo(ADDRESS_HOME_COUNTRY, WideToUTF16(L"United States")); | |
1432 profiles.push_back(profile); | |
1433 } | |
1434 SetProfiles(&profiles); | |
1435 LOG(INFO) << "Created " << kNumProfiles << " profiles in " << | |
1436 (base::Time::Now() - start_time).InSeconds() << " seconds."; | |
1437 | |
1438 GURL url = test_server()->GetURL( | |
1439 "files/autofill/latency_after_submit_test.html"); | |
1440 ui_test_utils::NavigateToURL(browser(), url); | |
1441 PopulateForm("NAME_FIRST"); | |
1442 | |
1443 content::WindowedNotificationObserver load_stop_observer( | |
1444 content::NOTIFICATION_LOAD_STOP, | |
1445 content::Source<content::NavigationController>( | |
1446 &chrome::GetActiveWebContents(browser())->GetController())); | |
1447 | |
1448 ASSERT_TRUE(content::ExecuteJavaScript( | |
1449 render_view_host(), L"", | |
1450 ASCIIToWide("document.getElementById('testform').submit();"))); | |
1451 // This will ensure the test didn't hang. | |
1452 load_stop_observer.Wait(); | |
1453 } | |
1454 | |
1455 // Test that profiles merge for aggregated data with same address. | |
1456 // The criterion for when two profiles are expected to be merged is when their | |
1457 // 'Address Line 1' and 'City' data match. When two profiles are merged, any | |
1458 // remaining address fields are expected to be overwritten. Any non-address | |
1459 // fields should accumulate multi-valued data. | |
1460 IN_PROC_BROWSER_TEST_F(AutofillTest, MergeAggregatedProfilesWithSameAddress) { | |
1461 AggregateProfilesIntoAutofillPrefs("dataset_2.txt"); | |
1462 | |
1463 ASSERT_EQ(3u, personal_data_manager()->profiles().size()); | |
1464 } | |
1465 | |
1466 // Test profiles are not merged without mininum address values. | |
1467 // Mininum address values needed during aggregation are: address line 1, city, | |
1468 // state, and zip code. | |
1469 // Profiles are merged when data for address line 1 and city match. | |
1470 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfilesNotMergedWhenNoMinAddressData) { | |
1471 AggregateProfilesIntoAutofillPrefs("dataset_no_address.txt"); | |
1472 | |
1473 ASSERT_EQ(0u, personal_data_manager()->profiles().size()); | |
1474 } | |
1475 | |
1476 // Test Autofill ability to merge duplicate profiles and throw away junk. | |
1477 IN_PROC_BROWSER_TEST_F(AutofillTest, MergeAggregatedDuplicatedProfiles) { | |
1478 int num_of_profiles = | |
1479 AggregateProfilesIntoAutofillPrefs("dataset_no_address.txt"); | |
1480 | |
1481 ASSERT_GT(num_of_profiles, | |
1482 static_cast<int>(personal_data_manager()->profiles().size())); | |
1483 } | |
OLD | NEW |