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" | |
9 #include "base/hash_tables.h" | |
8 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/rand_util.h" | |
10 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "base/string_number_conversions.h" | |
15 #include "base/string_split.h" | |
16 #include "base/time.h" | |
11 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | |
12 #include "chrome/browser/api/infobars/infobar_tab_service.h" | 19 #include "chrome/browser/api/infobars/infobar_tab_service.h" |
13 #include "chrome/browser/autofill/autofill_common_test.h" | 20 #include "chrome/browser/autofill/autofill_common_test.h" |
14 #include "chrome/browser/autofill/autofill_profile.h" | 21 #include "chrome/browser/autofill/autofill_profile.h" |
22 #include "chrome/browser/autofill/credit_card.h" | |
15 #include "chrome/browser/autofill/personal_data_manager.h" | 23 #include "chrome/browser/autofill/personal_data_manager.h" |
16 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 24 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
17 #include "chrome/browser/autofill/personal_data_manager_observer.h" | 25 #include "chrome/browser/autofill/personal_data_manager_observer.h" |
18 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/translate/translate_infobar_delegate.h" | 27 #include "chrome/browser/translate/translate_infobar_delegate.h" |
20 #include "chrome/browser/translate/translate_manager.h" | 28 #include "chrome/browser/translate/translate_manager.h" |
21 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/browser_tabstrip.h" | 30 #include "chrome/browser/ui/browser_tabstrip.h" |
23 #include "chrome/browser/ui/browser_window.h" | 31 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 32 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
25 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/render_messages.h" | 34 #include "chrome/common/render_messages.h" |
27 #include "chrome/test/base/in_process_browser_test.h" | 35 #include "chrome/test/base/in_process_browser_test.h" |
28 #include "chrome/test/base/ui_test_utils.h" | 36 #include "chrome/test/base/ui_test_utils.h" |
29 #include "content/public/browser/navigation_controller.h" | 37 #include "content/public/browser/navigation_controller.h" |
38 #include "content/public/browser/notification_observer.h" | |
39 #include "content/public/browser/notification_registrar.h" | |
30 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
31 #include "content/public/browser/render_view_host.h" | 41 #include "content/public/browser/render_view_host.h" |
32 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
33 #include "content/public/test/browser_test_utils.h" | 43 #include "content/public/test/browser_test_utils.h" |
34 #include "content/public/test/test_renderer_host.h" | 44 #include "content/public/test/test_renderer_host.h" |
35 #include "net/url_request/test_url_fetcher_factory.h" | 45 #include "net/url_request/test_url_fetcher_factory.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
37 #include "ui/base/keycodes/keyboard_codes.h" | 47 #include "ui/base/keycodes/keyboard_codes.h" |
38 | 48 |
39 using content::RenderViewHost; | 49 using content::RenderViewHost; |
(...skipping 25 matching lines...) Expand all Loading... | |
65 "<label for=\"country\">Country:</label>" | 75 "<label for=\"country\">Country:</label>" |
66 " <select id=\"country\">" | 76 " <select id=\"country\">" |
67 " <option value=\"\" selected=\"yes\">--</option>" | 77 " <option value=\"\" selected=\"yes\">--</option>" |
68 " <option value=\"CA\">Canada</option>" | 78 " <option value=\"CA\">Canada</option>" |
69 " <option value=\"US\">United States</option>" | 79 " <option value=\"US\">United States</option>" |
70 " </select><br>" | 80 " </select><br>" |
71 "<label for=\"phone\">Phone number:</label>" | 81 "<label for=\"phone\">Phone number:</label>" |
72 " <input type=\"text\" id=\"phone\"><br>" | 82 " <input type=\"text\" id=\"phone\"><br>" |
73 "</form>"; | 83 "</form>"; |
74 | 84 |
75 class WindowedPersonalDataManagerObserver : public PersonalDataManagerObserver { | 85 class WindowedPersonalDataManagerObserver |
86 : public PersonalDataManagerObserver, | |
87 public content::NotificationObserver { | |
76 public: | 88 public: |
77 WindowedPersonalDataManagerObserver() : | 89 explicit WindowedPersonalDataManagerObserver(Browser* browser) : |
78 personal_data_changed_(false), | 90 alerted_(false), |
79 has_run_message_loop_(false) { | 91 has_run_message_loop_(false), |
92 browser_(browser), | |
93 infobar_service_(NULL) { | |
94 PersonalDataManagerFactory::GetForProfile(browser_->profile())-> | |
95 SetObserver(this); | |
96 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | |
97 content::NotificationService::AllSources()); | |
Ilya Sherman
2012/08/21 03:04:28
This doesn't really seem to fit with the rest of t
jam
2012/08/21 06:20:06
I had kept it like because there didn't seem to be
| |
98 } | |
99 | |
100 ~WindowedPersonalDataManagerObserver() { | |
101 if (!infobar_service_) | |
102 return; | |
103 | |
104 InfoBarDelegate* infobar = NULL; | |
105 if (infobar_service_->GetInfoBarCount() > 0 && | |
106 (infobar = infobar_service_->GetInfoBarDelegateAt(0))) { | |
107 infobar_service_->RemoveInfoBar(infobar); | |
108 } | |
80 } | 109 } |
81 | 110 |
82 void Wait() { | 111 void Wait() { |
83 if (!personal_data_changed_) { | 112 if (!alerted_) { |
84 has_run_message_loop_ = true; | 113 has_run_message_loop_ = true; |
85 content::RunMessageLoop(); | 114 content::RunMessageLoop(); |
86 } | 115 } |
116 PersonalDataManagerFactory::GetForProfile(browser_->profile())-> | |
117 RemoveObserver(this); | |
87 } | 118 } |
88 | 119 |
89 void OnPersonalDataChanged() OVERRIDE { | 120 // PersonalDataManagerObserver: |
121 virtual void OnPersonalDataChanged() OVERRIDE { | |
90 if (has_run_message_loop_) { | 122 if (has_run_message_loop_) { |
91 MessageLoopForUI::current()->Quit(); | 123 MessageLoopForUI::current()->Quit(); |
92 has_run_message_loop_ = false; | 124 has_run_message_loop_ = false; |
93 } | 125 } |
94 personal_data_changed_ = true; | 126 alerted_ = true; |
127 } | |
128 | |
129 virtual void OnInsufficientFormData() OVERRIDE { | |
130 OnPersonalDataChanged(); | |
131 } | |
132 | |
133 // content::NotificationObserver: | |
134 virtual void Observe(int type, | |
135 const content::NotificationSource& source, | |
136 const content::NotificationDetails& details) OVERRIDE { | |
Ilya Sherman
2012/08/21 03:04:28
nit: Please add ASSERTs to verify that the type/so
jam
2012/08/21 06:20:06
I think this is unnecessary at this point.. if som
| |
137 // Accept in the infobar. | |
138 infobar_service_ = | |
139 InfoBarTabService::ForTab(chrome::GetActiveTabContents(browser_)); | |
140 InfoBarDelegate* infobar = infobar_service_->GetInfoBarDelegateAt(0); | |
141 | |
142 ConfirmInfoBarDelegate* confirm_infobar = | |
143 infobar->AsConfirmInfoBarDelegate(); | |
144 confirm_infobar->Accept(); | |
95 } | 145 } |
96 | 146 |
97 private: | 147 private: |
98 bool personal_data_changed_; | 148 bool alerted_; |
99 bool has_run_message_loop_; | 149 bool has_run_message_loop_; |
150 Browser* browser_; | |
151 content::NotificationRegistrar registrar_; | |
152 InfoBarTabService* infobar_service_; | |
100 }; | 153 }; |
101 | 154 |
102 class AutofillTest : public InProcessBrowserTest { | 155 class AutofillTest : public InProcessBrowserTest { |
103 protected: | 156 protected: |
104 AutofillTest() {} | 157 AutofillTest() {} |
105 | 158 |
159 PersonalDataManager* personal_data_manager() { | |
160 return PersonalDataManagerFactory::GetForProfile(browser()->profile()); | |
161 } | |
162 | |
106 void CreateTestProfile() { | 163 void CreateTestProfile() { |
107 autofill_test::DisableSystemServices(browser()->profile()); | 164 autofill_test::DisableSystemServices(browser()->profile()); |
108 | 165 |
109 AutofillProfile profile; | 166 AutofillProfile profile; |
110 autofill_test::SetProfileInfo( | 167 autofill_test::SetProfileInfo( |
111 &profile, "Milton", "C.", "Waddams", | 168 &profile, "Milton", "C.", "Waddams", |
112 "red.swingline@initech.com", "Initech", "4120 Freidrich Lane", | 169 "red.swingline@initech.com", "Initech", "4120 Freidrich Lane", |
113 "Basement", "Austin", "Texas", "78744", "United States", "5125551234"); | 170 "Basement", "Austin", "Texas", "78744", "United States", "5125551234"); |
114 | 171 |
115 PersonalDataManager* personal_data_manager = | 172 WindowedPersonalDataManagerObserver observer(browser()); |
116 PersonalDataManagerFactory::GetForProfile(browser()->profile()); | 173 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 | 174 |
124 // AddProfile is asynchronous. Wait for it to finish before continuing the | 175 // AddProfile is asynchronous. Wait for it to finish before continuing the |
125 // tests. | 176 // tests. |
126 observer.Wait(); | 177 observer.Wait(); |
127 personal_data_manager->RemoveObserver(&observer); | 178 } |
179 | |
180 void SetProfiles(std::vector<AutofillProfile>* profiles) { | |
181 WindowedPersonalDataManagerObserver observer(browser()); | |
182 personal_data_manager()->SetProfiles(profiles); | |
183 observer.Wait(); | |
184 } | |
185 | |
186 void SetProfile(const AutofillProfile& profile) { | |
187 std::vector<AutofillProfile> profiles; | |
188 profiles.push_back(profile); | |
189 SetProfiles(&profiles); | |
190 } | |
191 | |
192 void SetCards(std::vector<CreditCard>* cards) { | |
193 WindowedPersonalDataManagerObserver observer(browser()); | |
194 personal_data_manager()->SetCreditCards(cards); | |
195 observer.Wait(); | |
196 } | |
197 | |
198 void SetCard(const CreditCard& card) { | |
199 std::vector<CreditCard> cards; | |
200 cards.push_back(card); | |
201 SetCards(&cards); | |
202 } | |
203 | |
204 typedef base::hash_map<std::string, std::string> FormData; | |
Ilya Sherman
2012/08/21 03:04:28
FormData is already a type defined in webkit/forms
jam
2012/08/21 06:20:06
renamed to FormMap
| |
205 void FillFormAndSubmit(const std::string filename, const FormData& data) { | |
Ilya Sherman
2012/08/21 03:04:28
nit: Pass the filename by reference
Ilya Sherman
2012/08/21 03:04:28
nit: Please add a comment describing this method -
jam
2012/08/21 06:20:06
Done.
jam
2012/08/21 06:20:06
Done.
| |
206 GURL url = test_server()->GetURL(std::string("files/autofill/") + filename); | |
Ilya Sherman
2012/08/21 03:04:28
nit: No need to explicitly construct a C++ string
jam
2012/08/21 06:20:06
Done.
| |
207 ui_test_utils::NavigateToURL(browser(), url); | |
208 | |
209 std::string js; | |
210 for (FormData::const_iterator i = data.begin(); i != data.end(); ++i) { | |
211 js += "document.getElementById('" + i->first + "').value = '" + | |
212 i->second + "';"; | |
213 } | |
214 js += "document.getElementById('testform').submit();"; | |
215 | |
216 WindowedPersonalDataManagerObserver observer(browser()); | |
217 ASSERT_TRUE( | |
218 content::ExecuteJavaScript(render_view_host(), L"", ASCIIToWide(js))); | |
219 observer.Wait(); | |
220 } | |
221 | |
222 void SubmitCreditCard(const char* name, | |
223 const char* number, | |
224 const char* exp_month, | |
225 const char* exp_year) { | |
226 FormData data; | |
227 data["CREDIT_CARD_NAME"] = name; | |
228 data["CREDIT_CARD_NUMBER"] = number; | |
229 data["CREDIT_CARD_EXP_MONTH"] = exp_month; | |
230 data["CREDIT_CARD_EXP_4_DIGIT_YEAR"] = exp_year; | |
231 FillFormAndSubmit("autofill_creditcard_form.html", data); | |
232 } | |
233 | |
234 // Populates a webpage form using autofill data and keypress events. | |
235 // This function focuses the specified input field in the form, and then | |
236 // sends keypress events to the tab to cause the form to be populated. | |
237 void PopulateForm(const std::string& field_id) { | |
238 std::string js("document.getElementById('"); | |
239 js += field_id + "').focus();"; | |
Ilya Sherman
2012/08/21 03:04:28
nit: Move the rest of this string definition up on
jam
2012/08/21 06:20:06
Done.
| |
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()); | |
Ilya Sherman
2012/08/21 03:04:28
If the CHECK fails, the whole test suite will cras
jam
2012/08/21 06:20:06
yep & yep. if the test sever can't be started, the
| |
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 FormData 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 } | |
Ilya Sherman
2012/08/21 03:04:28
I think this test is redundant with tests in chrom
jam
2012/08/21 06:20:06
I have ported all the tests and tried to do a stra
Ilya Sherman
2012/08/21 07:24:17
This test is redundant with the unit test Personal
jam
2012/08/21 14:49:11
Done.
| |
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 03:04:28
Ditto.
jam
2012/08/21 14:49:11
Done.
| |
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 } | |
Ilya Sherman
2012/08/21 03:04:28
If this test is not redundant with existing Person
jam
2012/08/21 06:20:06
I don't know all the tests there. if you find one
Ilya Sherman
2012/08/21 07:24:17
This test does not need to be a browser_test; it c
jam
2012/08/21 14:49:11
Done.
| |
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 } | |
Ilya Sherman
2012/08/21 03:04:28
I think this test is redundant with tests in chrom
jam
2012/08/21 06:20:06
ditto
Ilya Sherman
2012/08/21 07:24:17
This test is meant to be a test of the WebUI at ch
jam
2012/08/21 14:49:11
Done.
| |
1037 | |
1038 // Test invalid credit card numbers typed in prefs should be saved as-is. | |
Ilya Sherman
2012/08/21 03:04:28
This test is meant to be testing the settings page
jam
2012/08/21 06:20:06
I think there is webui js harness already that is
Ilya Sherman
2012/08/21 07:24:17
Ditto with the above: This test is meant to be a t
jam
2012/08/21 14:49:11
Done.
| |
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 FormData 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 FormData 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 FormData 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); | |
Ilya Sherman
2012/08/21 03:04:28
Optional nit: Perhaps re-use CreateTestProfile(),
jam
2012/08/21 06:20:06
I didn't want to change the previous autofill test
| |
1148 | |
1149 GURL url = | |
1150 test_server()->GetURL(std::string("files/autofill/form_phones.html")); | |
1151 ui_test_utils::NavigateToURL(browser(), url); | |
1152 PopulateForm("NAME_FIRST"); | |
1153 | |
1154 FormData expected; | |
1155 expected["NAME_FIRST"] = "Bob"; | |
1156 expected["NAME_LAST"] = "Smith"; | |
1157 expected["ADDRESS_HOME_LINE1"] = "1234 H St."; | |
1158 expected["ADDRESS_HOME_CITY"] = "San Jose"; | |
1159 expected["ADDRESS_HOME_STATE"] = "CA"; | |
1160 expected["ADDRESS_HOME_ZIP"] = "95110"; | |
1161 expected["PHONE_HOME_WHOLE_NUMBER"] = "14085554567"; | |
1162 expected["PHONE_HOME_CITY_CODE-1"] = "408"; | |
1163 expected["PHONE_HOME_CITY_CODE-2"] = "408"; | |
1164 expected["PHONE_HOME_NUMBER"] = "5554567"; | |
1165 expected["PHONE_HOME_NUMBER_3-1"] = "555"; | |
1166 expected["PHONE_HOME_NUMBER_3-2"] = "555"; | |
1167 expected["PHONE_HOME_NUMBER_4-1"] = "4567"; | |
1168 expected["PHONE_HOME_NUMBER_4-2"] = "4567"; | |
1169 expected["PHONE_HOME_EXT-1"] = ""; | |
1170 expected["PHONE_HOME_EXT-2"] = ""; | |
1171 expected["PHONE_HOME_COUNTRY_CODE-1"] = "1"; | |
1172 | |
1173 for (FormData::const_iterator i = expected.begin(); i != expected.end(); | |
1174 ++i) { | |
1175 std::string js = "window.domAutomationController.send(" | |
1176 "document.getElementById('"; | |
1177 js += i->first + "').value)"; | |
1178 std::string value; | |
1179 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | |
1180 render_view_host(), L"", ASCIIToWide(js), &value)); | |
1181 ASSERT_EQ(i->second, value); | |
Ilya Sherman
2012/08/21 03:04:28
Can you use ExpectFieldValue() for the body of thi
jam
2012/08/21 06:20:06
Thanks, I didn't see that function before. also fi
| |
1182 } | |
1183 } | |
1184 | |
1185 // Test profile is saved if phone number is valid in selected country. | |
1186 // The data file contains two profiles with valid phone numbers and two | |
1187 // profiles with invalid phone numbers from their respective country. | |
1188 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfileSavedWithValidCountryPhone) { | |
1189 ASSERT_TRUE(test_server()->Start()); | |
1190 std::vector<FormData> profiles; | |
1191 | |
1192 FormData data1; | |
1193 data1["NAME_FIRST"] = "Bob"; | |
1194 data1["NAME_LAST"] = "Smith"; | |
1195 data1["ADDRESS_HOME_LINE1"] = "123 Cherry Ave"; | |
1196 data1["ADDRESS_HOME_CITY"] = "Mountain View"; | |
1197 data1["ADDRESS_HOME_STATE"] = "CA"; | |
1198 data1["ADDRESS_HOME_ZIP"] = "94043"; | |
1199 data1["ADDRESS_HOME_COUNTRY"] = "United States"; | |
1200 data1["PHONE_HOME_WHOLE_NUMBER"] = "408-871-4567"; | |
1201 profiles.push_back(data1); | |
1202 | |
1203 FormData data2; | |
1204 data2["NAME_FIRST"] = "John"; | |
1205 data2["NAME_LAST"] = "Doe"; | |
1206 data2["ADDRESS_HOME_LINE1"] = "987 H St"; | |
1207 data2["ADDRESS_HOME_CITY"] = "San Jose"; | |
1208 data2["ADDRESS_HOME_STATE"] = "CA"; | |
1209 data2["ADDRESS_HOME_ZIP"] = "95510"; | |
1210 data2["ADDRESS_HOME_COUNTRY"] = "United States"; | |
1211 data2["PHONE_HOME_WHOLE_NUMBER"] = "408-123-456"; | |
1212 profiles.push_back(data2); | |
1213 | |
1214 FormData data3; | |
1215 data3["NAME_FIRST"] = "Jane"; | |
1216 data3["NAME_LAST"] = "Doe"; | |
1217 data3["ADDRESS_HOME_LINE1"] = "1523 Garcia St"; | |
1218 data3["ADDRESS_HOME_CITY"] = "Mountain View"; | |
1219 data3["ADDRESS_HOME_STATE"] = "CA"; | |
1220 data3["ADDRESS_HOME_ZIP"] = "94043"; | |
1221 data3["ADDRESS_HOME_COUNTRY"] = "Germany"; | |
1222 data3["PHONE_HOME_WHOLE_NUMBER"] = "+49 40-80-81-79-000"; | |
1223 profiles.push_back(data3); | |
1224 | |
1225 FormData data4; | |
1226 data4["NAME_FIRST"] = "Bonnie"; | |
1227 data4["NAME_LAST"] = "Smith"; | |
1228 data4["ADDRESS_HOME_LINE1"] = "6723 Roadway Rd"; | |
1229 data4["ADDRESS_HOME_CITY"] = "San Jose"; | |
1230 data4["ADDRESS_HOME_STATE"] = "CA"; | |
1231 data4["ADDRESS_HOME_ZIP"] = "95510"; | |
1232 data4["ADDRESS_HOME_COUNTRY"] = "Germany"; | |
1233 data4["PHONE_HOME_WHOLE_NUMBER"] = "+21 08450 777 777"; | |
1234 profiles.push_back(data4); | |
1235 | |
1236 for (size_t i = 0; i < profiles.size(); ++i) | |
1237 FillFormAndSubmit("autofill_test_form.html", profiles[i]); | |
1238 | |
1239 ASSERT_EQ(2u, personal_data_manager()->profiles().size()); | |
Ilya Sherman
2012/08/21 03:04:28
Please add checks to verify that the correct profi
jam
2012/08/21 06:20:06
Done.
| |
1240 } | |
1241 | |
1242 // Test Autofill appends country codes to aggregated phone numbers. | |
1243 // The country code is added for the following case: | |
1244 // The phone number contains the correct national number size and | |
1245 // is a valid format. | |
1246 IN_PROC_BROWSER_TEST_F(AutofillTest, AppendCountryCodeForAggregatedPhones) { | |
1247 ASSERT_TRUE(test_server()->Start()); | |
1248 FormData data; | |
1249 data["NAME_FIRST"] = "Bob"; | |
1250 data["NAME_LAST"] = "Smith"; | |
1251 data["ADDRESS_HOME_LINE1"] = "1234 H St."; | |
1252 data["ADDRESS_HOME_CITY"] = "San Jose"; | |
1253 data["ADDRESS_HOME_STATE"] = "CA"; | |
1254 data["ADDRESS_HOME_ZIP"] = "95110"; | |
1255 data["ADDRESS_HOME_COUNTRY"] = "Germany"; | |
1256 data["PHONE_HOME_WHOLE_NUMBER"] = "(08) 450 777-777"; | |
1257 FillFormAndSubmit("autofill_test_form.html", data); | |
1258 | |
1259 ASSERT_EQ(1u, personal_data_manager()->profiles().size()); | |
1260 string16 phone = | |
1261 personal_data_manager()->profiles()[0]->GetInfo(PHONE_HOME_WHOLE_NUMBER); | |
1262 ASSERT_TRUE(StartsWith(phone, ASCIIToUTF16("+49"), true)); | |
1263 } | |
1264 | |
1265 // Test CC info not offered to be saved when autocomplete=off for CC field. | |
1266 // If the credit card number field has autocomplete turned off, then the credit | |
1267 // card infobar should not offer to save the credit card info. The credit card | |
1268 // number must be a valid Luhn number. | |
1269 IN_PROC_BROWSER_TEST_F(AutofillTest, CCInfoNotStoredWhenAutocompleteOff) { | |
1270 ASSERT_TRUE(test_server()->Start()); | |
1271 FormData data; | |
1272 data["CREDIT_CARD_NAME"] = "Bob Smith"; | |
1273 data["CREDIT_CARD_NUMBER"] = "4408041234567893"; | |
1274 data["CREDIT_CARD_EXP_MONTH"] = "12"; | |
1275 data["CREDIT_CARD_EXP_4_DIGIT_YEAR"] = "2014"; | |
1276 FillFormAndSubmit("cc_autocomplete_off_test.html", data); | |
1277 | |
1278 ASSERT_EQ(0u, | |
1279 InfoBarTabService::ForTab(chrome::GetActiveTabContents(browser()))-> | |
1280 GetInfoBarCount()); | |
1281 } | |
1282 | |
1283 // Test that Autofill does not fill in read-only fields. | |
1284 IN_PROC_BROWSER_TEST_F(AutofillTest, NoAutofillForReadOnlyFields) { | |
1285 ASSERT_TRUE(test_server()->Start()); | |
1286 | |
1287 std::string email("bsmith@gmail.com"); | |
1288 std::string addr_line1("1234 H St."); | |
1289 | |
1290 AutofillProfile profile; | |
1291 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob")); | |
1292 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); | |
1293 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16(email)); | |
1294 profile.SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16(addr_line1)); | |
1295 profile.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("San Jose")); | |
1296 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); | |
1297 profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110")); | |
1298 profile.SetInfo(COMPANY_NAME, ASCIIToUTF16("Company X")); | |
1299 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("408-871-4567")); | |
1300 SetProfile(profile); | |
1301 | |
1302 GURL url = test_server()->GetURL(std::string( | |
1303 "files/autofill/read_only_field_test.html")); | |
1304 ui_test_utils::NavigateToURL(browser(), url); | |
1305 PopulateForm("firstname"); | |
1306 | |
1307 std::string readonly_field_value; | |
1308 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | |
1309 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | |
1310 L"window.domAutomationController.send(" | |
1311 L"document.getElementById('email').value);", &readonly_field_value)); | |
1312 ASSERT_NE(email, readonly_field_value); | |
Ilya Sherman
2012/08/21 03:04:28
nit: ExpectFieldValue(), and compare to the field'
jam
2012/08/21 06:20:06
this is ASSERT_NE
Ilya Sherman
2012/08/21 07:24:17
Please add a TODO(isherman): to fix this to be an
jam
2012/08/21 14:49:11
ah I think I didn't understand you originally. now
| |
1313 | |
1314 std::string addr1_field_value; | |
1315 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | |
1316 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | |
1317 L"window.domAutomationController.send(" | |
1318 L"document.getElementById('address').value);", &addr1_field_value)); | |
1319 ASSERT_EQ(addr_line1, addr1_field_value); | |
Ilya Sherman
2012/08/21 03:04:28
nit: ExpectFieldValue()?
jam
2012/08/21 06:20:06
Done.
| |
1320 } | |
1321 | |
1322 // Test form is fillable from a profile after form was reset. | |
1323 // Steps: | |
1324 // 1. Fill form using a saved profile. | |
1325 // 2. Reset the form. | |
1326 // 3. Fill form using a saved profile. | |
1327 IN_PROC_BROWSER_TEST_F(AutofillTest, FormFillableOnReset) { | |
1328 ASSERT_TRUE(test_server()->Start()); | |
1329 | |
1330 AutofillProfile profile; | |
1331 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob")); | |
1332 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); | |
1333 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("bsmith@gmail.com")); | |
1334 profile.SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 H St.")); | |
1335 profile.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("San Jose")); | |
1336 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("4088714567")); | |
1337 SetProfile(profile); | |
Ilya Sherman
2012/08/21 03:04:28
nit: CreateTestProfile()?
jam
2012/08/21 06:20:06
Done.
| |
1338 | |
1339 GURL url = test_server()->GetURL(std::string( | |
1340 "files/autofill/autofill_test_form.html")); | |
1341 ui_test_utils::NavigateToURL(browser(), url); | |
1342 PopulateForm("NAME_FIRST"); | |
1343 | |
1344 ASSERT_TRUE(content::ExecuteJavaScript( | |
1345 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | |
1346 L"document.getElementById('testform').reset()")); | |
1347 | |
1348 PopulateForm("NAME_FIRST"); | |
1349 | |
1350 bool result; | |
1351 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | |
1352 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | |
1353 L"window.domAutomationController.send(" | |
1354 L"document.getElementById('NAME_FIRST').value == 'Bob' &&" | |
1355 L"document.getElementById('NAME_LAST').value == 'Smith' &&" | |
1356 L"document.getElementById('EMAIL_ADDRESS').value == 'bsmith@gmail.com' &&" | |
1357 L"document.getElementById('ADDRESS_HOME_LINE1').value == '1234 H St.' &&" | |
1358 L"document.getElementById('ADDRESS_HOME_CITY').value == 'San Jose' &&" | |
1359 L"document.getElementById('PHONE_HOME_WHOLE_NUMBER').value == '4088714567' )", | |
1360 &result)); | |
1361 ASSERT_TRUE(result); | |
1362 } | |
1363 | |
1364 // Test Autofill distinguishes a middle initial in a name. | |
1365 IN_PROC_BROWSER_TEST_F(AutofillTest, DistinguishMiddleInitialWithinName) { | |
1366 ASSERT_TRUE(test_server()->Start()); | |
1367 | |
1368 AutofillProfile profile; | |
1369 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob")); | |
1370 profile.SetInfo(NAME_MIDDLE, ASCIIToUTF16("Leo")); | |
1371 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); | |
1372 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("bsmith@gmail.com")); | |
1373 profile.SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 H St.")); | |
1374 profile.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("San Jose")); | |
1375 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("4088714567")); | |
1376 SetProfile(profile); | |
Ilya Sherman
2012/08/21 03:04:28
nit: CreateTestProfile()?
jam
2012/08/21 06:20:06
Done.
| |
1377 | |
1378 GURL url = test_server()->GetURL(std::string( | |
1379 "files/autofill/autofill_middleinit_form.html")); | |
1380 ui_test_utils::NavigateToURL(browser(), url); | |
1381 PopulateForm("NAME_FIRST"); | |
1382 | |
1383 std::string middleinit_field_value; | |
1384 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | |
1385 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | |
1386 L"window.domAutomationController.send(" | |
1387 L"document.getElementById('NAME_MIDDLE').value)", | |
1388 &middleinit_field_value)); | |
1389 ASSERT_EQ("L", middleinit_field_value); | |
Ilya Sherman
2012/08/21 03:04:28
nit: ExpectFieldValue()?
jam
2012/08/21 06:20:06
Done.
| |
1390 } | |
1391 | |
1392 // Test forms with multiple email addresses are filled properly. | |
1393 // Entire form should be filled with one user gesture. | |
Ilya Sherman
2012/08/21 03:04:28
This description makes me think that we should be
jam
2012/08/21 06:20:06
please feel free to improve the tests in followup
Ilya Sherman
2012/08/21 07:24:17
Please add a TODO(isherman): to verify the entire
jam
2012/08/21 14:49:11
Done.
| |
1394 IN_PROC_BROWSER_TEST_F(AutofillTest, MultipleEmailFilledByOneUserGesture) { | |
1395 ASSERT_TRUE(test_server()->Start()); | |
1396 | |
1397 std::string email("bsmith@gmail.com"); | |
1398 | |
1399 AutofillProfile profile; | |
1400 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob")); | |
1401 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); | |
1402 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16(email)); | |
1403 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("4088714567")); | |
1404 SetProfile(profile); | |
Ilya Sherman
2012/08/21 03:04:28
nit: CreateTestProfile()?
| |
1405 | |
1406 GURL url = test_server()->GetURL(std::string( | |
1407 "files/autofill/autofill_confirmemail_form.html")); | |
1408 ui_test_utils::NavigateToURL(browser(), url); | |
1409 PopulateForm("NAME_FIRST"); | |
1410 | |
1411 std::string js_return_confirmemail_field; | |
1412 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | |
1413 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | |
1414 L"window.domAutomationController.send(" | |
1415 L"document.getElementById('EMAIL_CONFIRM').value)", | |
1416 &js_return_confirmemail_field)); | |
1417 ASSERT_EQ(email, js_return_confirmemail_field); | |
Ilya Sherman
2012/08/21 03:04:28
nit: ExpectFieldValue()?
jam
2012/08/21 06:20:06
Done.
| |
1418 } | |
1419 | |
1420 // Test profile not aggregated if email found in non-email field. | |
1421 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfileWithEmailInOtherFieldNotSaved) { | |
1422 ASSERT_TRUE(test_server()->Start()); | |
1423 | |
1424 FormData data; | |
1425 data["NAME_FIRST"] = "Bob"; | |
1426 data["NAME_LAST"] = "Smith"; | |
1427 data["ADDRESS_HOME_LINE1"] = "bsmith@gmail.com"; | |
1428 data["ADDRESS_HOME_CITY"] = "San Jose"; | |
1429 data["ADDRESS_HOME_STATE"] = "CA"; | |
1430 data["ADDRESS_HOME_ZIP"] = "95110"; | |
1431 data["COMPANY_NAME"] = "Company X"; | |
1432 data["PHONE_HOME_WHOLE_NUMBER"] = "408-871-4567"; | |
1433 FillFormAndSubmit("duplicate_profiles_test.html", data); | |
1434 | |
1435 ASSERT_EQ(0u, personal_data_manager()->profiles().size()); | |
1436 } | |
1437 | |
1438 // Test latency time on form submit with lots of stored Autofill profiles. | |
1439 // This test verifies when a profile is selected from the Autofill dictionary | |
1440 // that consists of thousands of profiles, the form does not hang after being | |
1441 // submitted. | |
1442 IN_PROC_BROWSER_TEST_F(AutofillTest, FormFillLatencyAfterSubmit) { | |
1443 ASSERT_TRUE(test_server()->Start()); | |
1444 | |
1445 std::vector<std::string> cities; | |
1446 cities.push_back("San Jose"); | |
1447 cities.push_back("San Francisco"); | |
1448 cities.push_back("Sacramento"); | |
1449 cities.push_back("Los Angeles"); | |
1450 | |
1451 std::vector<std::string> streets; | |
1452 streets.push_back("St"); | |
1453 streets.push_back("Ave"); | |
1454 streets.push_back("Ln"); | |
1455 streets.push_back("Ct"); | |
1456 | |
1457 const int kNumProfiles = 1500; | |
1458 base::Time start_time = base::Time::Now(); | |
1459 std::vector<AutofillProfile> profiles; | |
1460 for (int i = 0; i < kNumProfiles; i++) { | |
1461 AutofillProfile profile; | |
1462 string16 name(base::IntToString16(i)); | |
1463 string16 email(name + ASCIIToUTF16("@example.com")); | |
1464 string16 street = ASCIIToUTF16( | |
1465 base::IntToString(base::RandInt(0, 10000)) + " " + | |
1466 streets[base::RandInt(0, streets.size() - 1)]); | |
1467 string16 city = ASCIIToUTF16(cities[base::RandInt(0, cities.size() - 1)]); | |
1468 string16 zip(base::IntToString16(base::RandInt(0, 10000))); | |
1469 profile.SetInfo(NAME_FIRST, name); | |
1470 profile.SetInfo(EMAIL_ADDRESS, email); | |
1471 profile.SetInfo(ADDRESS_HOME_LINE1, street); | |
1472 profile.SetInfo(ADDRESS_HOME_CITY, city); | |
1473 profile.SetInfo(ADDRESS_HOME_STATE, WideToUTF16(L"CA")); | |
1474 profile.SetInfo(ADDRESS_HOME_ZIP, zip); | |
1475 profile.SetInfo(ADDRESS_HOME_COUNTRY, WideToUTF16(L"United States")); | |
1476 profiles.push_back(profile); | |
1477 } | |
1478 SetProfiles(&profiles); | |
1479 LOG(INFO) << "Created " << kNumProfiles << " profiles in " << | |
1480 (base::Time::Now() - start_time).InSeconds() << " seconds."; | |
Ilya Sherman
2012/08/21 03:04:28
nit: Passing tests should be silent. Is this log
jam
2012/08/21 06:20:06
I think one line is ok, at least in the beginning
Ilya Sherman
2012/08/21 07:24:17
Ok. In that case, please add a TODO or file a bug
jam
2012/08/21 14:49:11
Done.
| |
1481 | |
1482 GURL url = test_server()->GetURL(std::string( | |
1483 "files/autofill/latency_after_submit_test.html")); | |
1484 ui_test_utils::NavigateToURL(browser(), url); | |
1485 PopulateForm("NAME_FIRST"); | |
1486 | |
1487 content::WindowedNotificationObserver load_stop_observer( | |
1488 content::NOTIFICATION_LOAD_STOP, | |
1489 content::Source<content::NavigationController>( | |
1490 &chrome::GetActiveWebContents(browser())->GetController())); | |
1491 | |
1492 ASSERT_TRUE(content::ExecuteJavaScript( | |
1493 render_view_host(), L"", | |
1494 ASCIIToWide("document.getElementById('testform').submit();"))); | |
1495 load_stop_observer.Wait(); | |
Ilya Sherman
2012/08/21 03:04:28
I'd expect to see some EXPECT or ASSERT here verif
jam
2012/08/21 06:20:06
right. the comment said a browser hang. so this wi
| |
1496 } | |
1497 | |
1498 // Test that profiles merge for aggregated data with same address. | |
1499 // The criterion for when two profiles are expected to be merged is when their | |
1500 // 'Address Line 1' and 'City' data match. When two profiles are merged, any | |
1501 // remaining address fields are expected to be overwritten. Any non-address | |
1502 // fields should accumulate multi-valued data. | |
1503 IN_PROC_BROWSER_TEST_F(AutofillTest, MergeAggregatedProfilesWithSameAddress) { | |
1504 AggregateProfilesIntoAutofillPrefs("dataset_2.txt"); | |
1505 | |
1506 ASSERT_EQ(3u, personal_data_manager()->profiles().size()); | |
1507 } | |
1508 | |
1509 // Test profiles are not merged without mininum address values. | |
1510 // Mininum address values needed during aggregation are: address line 1, city, | |
1511 // state, and zip code. | |
1512 // Profiles are merged when data for address line 1 and city match. | |
1513 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfilesNotMergedWhenNoMinAddressData) { | |
1514 AggregateProfilesIntoAutofillPrefs("dataset_no_address.txt"); | |
1515 | |
1516 ASSERT_EQ(0u, personal_data_manager()->profiles().size()); | |
1517 } | |
1518 | |
1519 // Test Autofill ability to merge duplicate profiles and throw away junk. | |
1520 IN_PROC_BROWSER_TEST_F(AutofillTest, MergeAggregatedDuplicatedProfiles) { | |
1521 int num_of_profiles = | |
1522 AggregateProfilesIntoAutofillPrefs("dataset_no_address.txt"); | |
1523 | |
1524 ASSERT_GT(num_of_profiles, | |
1525 static_cast<int>(personal_data_manager()->profiles().size())); | |
Ilya Sherman
2012/08/21 03:04:28
This looks like it's only testing that we throw aw
jam
2012/08/21 06:20:06
again, I don't know enough about autofill to know
Ilya Sherman
2012/08/21 07:24:17
Please add a TODO(isherman): to investigate removi
jam
2012/08/21 14:49:11
Done.
| |
1526 } | |
OLD | NEW |