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

Side by Side Diff: chrome/browser/autofill/autofill_browsertest.cc

Issue 10855253: Convert the autofill pyauto tests to browser tests, and remove all the supporting automation hooks … (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/autofill/personal_data_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <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
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
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 with unicode strings and crazy characters.
872 // TODO(isherman): rewrite as unit test under PersonalDataManagerTest.
873 IN_PROC_BROWSER_TEST_F(AutofillTest, FillProfileCrazyCharacters) {
874 std::vector<AutofillProfile> profiles;
875 AutofillProfile profile1;
876 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"));
877 profile1.SetInfo(NAME_MIDDLE, WideToUTF16(L"BANK\xcBERF\xc4LLE"));
878 profile1.SetInfo(EMAIL_ADDRESS, WideToUTF16(L"\uacbd\uc81c \ub274\uc2a4 \ub354 \ubcf4\uae30@google.com"));
879 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"));
880 profile1.SetInfo(ADDRESS_HOME_CITY, WideToUTF16(L"\u653f\u5e9c\u4e0d\u6392\u96 64\u7acb\u6cd5\u898f\u7ba1\u5c0e\u904a"));
881 profile1.SetInfo(ADDRESS_HOME_ZIP, WideToUTF16(L"YOHO_54676"));
882 profile1.SetInfo(PHONE_HOME_WHOLE_NUMBER, WideToUTF16(L"861088828000"));
883 profile1.SetInfo(ADDRESS_HOME_COUNTRY, WideToUTF16(L"India"));
884 profiles.push_back(profile1);
885
886 AutofillProfile profile2;
887 profile2.SetInfo(NAME_FIRST, WideToUTF16(L"\u4e0a\u6d77\u5e02\u91d1\u5c71\u533 a \u677e\u9690\u9547\u4ead\u67ab\u516c\u8def1915\u53f7"));
888 profile2.SetInfo(NAME_LAST, WideToUTF16(L"aguantó"));
889 profile2.SetInfo(ADDRESS_HOME_ZIP, WideToUTF16(L"HOME 94043"));
890 profiles.push_back(profile2);
891
892 AutofillProfile profile3;
893 profile3.SetInfo(EMAIL_ADDRESS, WideToUTF16(L"sue@example.com"));
894 profile3.SetInfo(COMPANY_NAME, WideToUTF16(L"Company X"));
895 profiles.push_back(profile3);
896
897 AutofillProfile profile4;
898 profile4.SetInfo(NAME_FIRST, WideToUTF16(L"Joe 3254"));
899 profile4.SetInfo(NAME_LAST, WideToUTF16(L"\u8bb0\u8d262\u5e74\u591a"));
900 profile4.SetInfo(ADDRESS_HOME_ZIP, WideToUTF16(L"\uff08\u90ae\u7f16\uff1a20150 4\uff09"));
901 profile4.SetInfo(EMAIL_ADDRESS, WideToUTF16(L"télévision@example.com"));
902 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"));
903 profiles.push_back(profile4);
904
905 AutofillProfile profile5;
906 profile5.SetInfo(NAME_FIRST, WideToUTF16(L"Larry"));
907 profile5.SetInfo(NAME_LAST, WideToUTF16(L"\u0938\u094d\u091f\u093e\u0902\u092a \u0921\u094d\u092f\u0942\u091f\u0940"));
908 profile5.SetInfo(ADDRESS_HOME_ZIP, WideToUTF16(L"111111111111110000GOOGLE"));
909 profile5.SetInfo(EMAIL_ADDRESS, WideToUTF16(L"page@000000.com"));
910 profile5.SetInfo(COMPANY_NAME, WideToUTF16(L"Google"));
911 profiles.push_back(profile5);
912
913 AutofillProfile profile6;
914 profile6.SetInfo(NAME_FIRST, WideToUTF16(L"\u4e0a\u6d77\u5e02\u91d1\u5c71\u533 a \u677e\u9690\u9547\u4ead\u67ab\u516c\u8def1915\u53f7"));
915 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"));
916 profile6.SetInfo(ADDRESS_HOME_ZIP, WideToUTF16(L"HOME 94043"));
917 profiles.push_back(profile6);
918
919 AutofillProfile profile7;
920 profile7.SetInfo(NAME_FIRST, WideToUTF16(L"&$%$$$ TESTO *&*&^&^& MOKO"));
921 profile7.SetInfo(NAME_MIDDLE, WideToUTF16(L"WOHOOOO$$$$$$$$****"));
922 profile7.SetInfo(EMAIL_ADDRESS, WideToUTF16(L"yuvu@example.com"));
923 profile7.SetInfo(ADDRESS_HOME_LINE1, WideToUTF16(L"34544, anderson ST.(120230) "));
924 profile7.SetInfo(ADDRESS_HOME_CITY, WideToUTF16(L"Sunnyvale"));
925 profile7.SetInfo(ADDRESS_HOME_STATE, WideToUTF16(L"CA"));
926 profile7.SetInfo(ADDRESS_HOME_ZIP, WideToUTF16(L"94086"));
927 profile7.SetInfo(PHONE_HOME_WHOLE_NUMBER, WideToUTF16(L"15466784565"));
928 profile7.SetInfo(ADDRESS_HOME_COUNTRY, WideToUTF16(L"United States"));
929 profiles.push_back(profile7);
930
931 SetProfiles(&profiles);
932 ASSERT_EQ(profiles.size(), personal_data_manager()->profiles().size());
933 for (size_t i = 0; i < profiles.size(); ++i)
934 ASSERT_EQ(profiles[i], *personal_data_manager()->profiles()[i]);
935
936 std::vector<CreditCard> cards;
937 CreditCard card1;
938 card1.SetInfo(CREDIT_CARD_NAME, WideToUTF16(L"\u751f\u6d3b\u5f88\u6709\u89c4\u 5f8b \u4ee5\u73a9\u4e3a\u4e3b"));
939 card1.SetInfo(CREDIT_CARD_NUMBER, WideToUTF16(L"6011111111111117"));
940 card1.SetInfo(CREDIT_CARD_EXP_MONTH, WideToUTF16(L"12"));
941 card1.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, WideToUTF16(L"2011"));
942 cards.push_back(card1);
943
944 CreditCard card2;
945 card2.SetInfo(CREDIT_CARD_NAME, WideToUTF16(L"John Williams"));
946 card2.SetInfo(CREDIT_CARD_NUMBER, WideToUTF16(L"WokoAwesome12345"));
947 card2.SetInfo(CREDIT_CARD_EXP_MONTH, WideToUTF16(L"10"));
948 card2.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, WideToUTF16(L"2015"));
949 cards.push_back(card2);
950
951 CreditCard card3;
952 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 "));
953 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"));
954 card3.SetInfo(CREDIT_CARD_EXP_MONTH, WideToUTF16(L"10"));
955 card3.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, WideToUTF16(L"2015"));
956 cards.push_back(card3);
957
958 CreditCard card4;
959 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"));
960 card4.SetInfo(CREDIT_CARD_NUMBER, WideToUTF16(L"00000000000000000000000"));
961 card4.SetInfo(CREDIT_CARD_EXP_MONTH, WideToUTF16(L"01"));
962 card4.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, WideToUTF16(L"2016"));
963 cards.push_back(card4);
964
965 SetCards(&cards);
966 ASSERT_EQ(cards.size(), personal_data_manager()->credit_cards().size());
967 for (size_t i = 0; i < cards.size(); ++i)
968 ASSERT_EQ(cards[i], *personal_data_manager()->credit_cards()[i]);
969 }
970
971 // Test filling in invalid values for profiles are saved as-is. Phone
972 // information entered into the prefs UI is not validated or rejected except for
973 // duplicates.
974 // TODO(isherman): rewrite as WebUI test?
975 IN_PROC_BROWSER_TEST_F(AutofillTest, Invalid) {
976 // First try profiles with invalid ZIP input.
977 AutofillProfile without_invalid;
978 without_invalid.SetInfo(NAME_FIRST, ASCIIToUTF16("Will"));
979 without_invalid.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Sunnyvale"));
980 without_invalid.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
981 without_invalid.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("my_zip"));
982 without_invalid.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States"));
983
984 AutofillProfile with_invalid = without_invalid;
985 with_invalid.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("Invalid_Phone_Numb er"));
986 SetProfile(with_invalid);
987
988 ASSERT_EQ(1u, personal_data_manager()->profiles().size());
989 AutofillProfile profile = *personal_data_manager()->profiles()[0];
990 ASSERT_NE(without_invalid.GetInfo(PHONE_HOME_WHOLE_NUMBER),
991 profile.GetInfo(PHONE_HOME_WHOLE_NUMBER));
992 }
993
994 // Test invalid credit card numbers typed in prefs should be saved as-is.
995 // TODO(isherman): rewrite as WebUI test?
996 IN_PROC_BROWSER_TEST_F(AutofillTest, PrefsStringSavedAsIs) {
997 CreditCard card;
998 card.SetInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("Not_0123-5Checked"));
999 SetCard(card);
1000
1001 ASSERT_EQ(1u, personal_data_manager()->credit_cards().size());
1002 ASSERT_EQ(card, *personal_data_manager()->credit_cards()[0]);
1003 }
1004
1005 // Test credit card info with an invalid number is not aggregated.
1006 // When filling out a form with an invalid credit card number (one that does not
1007 // pass the Luhn test) the credit card info should not be saved into Autofill
1008 // preferences.
1009 IN_PROC_BROWSER_TEST_F(AutofillTest, InvalidCreditCardNumberIsNotAggregated) {
1010 ASSERT_TRUE(test_server()->Start());
1011 std::string card("4408 0412 3456 7890");
1012 ASSERT_FALSE(CreditCard::IsValidCreditCardNumber(ASCIIToUTF16(card)));
1013 SubmitCreditCard("Bob Smith", card.c_str(), "12", "2014");
1014 ASSERT_EQ(0u,
1015 InfoBarTabService::ForTab(chrome::GetActiveTabContents(browser()))->
1016 GetInfoBarCount());
1017 }
1018
1019 // Test whitespaces and separator chars are stripped for valid CC numbers.
1020 // The credit card numbers used in this test pass the Luhn test. For reference:
1021 // http://www.merriampark.com/anatomycc.htm
1022 IN_PROC_BROWSER_TEST_F(AutofillTest,
1023 WhitespacesAndSeparatorCharsStrippedForValidCCNums) {
1024 ASSERT_TRUE(test_server()->Start());
1025 SubmitCreditCard("Bob Smith", "4408 0412 3456 7893", "12", "2014");
1026 SubmitCreditCard("Jane Doe", "4417-1234-5678-9113", "10", "2013");
1027
1028 ASSERT_EQ(2u, personal_data_manager()->credit_cards().size());
1029 string16 cc1 = personal_data_manager()->credit_cards()[0]->GetInfo(
1030 CREDIT_CARD_NUMBER);
1031 ASSERT_TRUE(CreditCard::IsValidCreditCardNumber(cc1));
1032 string16 cc2 = personal_data_manager()->credit_cards()[1]->GetInfo(
1033 CREDIT_CARD_NUMBER);
1034 ASSERT_TRUE(CreditCard::IsValidCreditCardNumber(cc2));
1035 }
1036
1037 // Test that Autofill aggregates a minimum valid profile.
1038 // The minimum required address fields must be specified: First Name, Last Name,
1039 // Address Line 1, City, Zip Code, and State.
1040 IN_PROC_BROWSER_TEST_F(AutofillTest, AggregatesMinValidProfile) {
1041 ASSERT_TRUE(test_server()->Start());
1042 FormMap data;
1043 data["NAME_FIRST"] = "Bob";
1044 data["NAME_LAST"] = "Smith";
1045 data["ADDRESS_HOME_LINE1"] = "1234 H St.";
1046 data["ADDRESS_HOME_CITY"] = "Mountain View";
1047 data["ADDRESS_HOME_STATE"] = "CA";
1048 data["ADDRESS_HOME_ZIP"] = "94043";
1049 FillFormAndSubmit("duplicate_profiles_test.html", data);
1050
1051 ASSERT_EQ(1u, personal_data_manager()->profiles().size());
1052 }
1053
1054 // Test Autofill does not aggregate profiles with no address info.
1055 // The minimum required address fields must be specified: First Name, Last Name,
1056 // Address Line 1, City, Zip Code, and State.
1057 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfilesNotAggregatedWithNoAddress) {
1058 ASSERT_TRUE(test_server()->Start());
1059 FormMap data;
1060 data["NAME_FIRST"] = "Bob";
1061 data["NAME_LAST"] = "Smith";
1062 data["EMAIL_ADDRESS"] = "bsmith@example.com";
1063 data["COMPANY_NAME"] = "Mountain View";
1064 data["ADDRESS_HOME_CITY"] = "Mountain View";
1065 data["PHONE_HOME_WHOLE_NUMBER"] = "650-555-4567";
1066 FillFormAndSubmit("duplicate_profiles_test.html", data);
1067
1068 ASSERT_TRUE(personal_data_manager()->profiles().empty());
1069 }
1070
1071 // Test Autofill does not aggregate profiles with an invalid email.
1072 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfilesNotAggregatedWithInvalidEmail) {
1073 ASSERT_TRUE(test_server()->Start());
1074 FormMap data;
1075 data["NAME_FIRST"] = "Bob";
1076 data["NAME_LAST"] = "Smith";
1077 data["EMAIL_ADDRESS"] = "garbage";
1078 data["ADDRESS_HOME_LINE1"] = "1234 H St.";
1079 data["ADDRESS_HOME_CITY"] = "San Jose";
1080 data["ADDRESS_HOME_STATE"] = "CA";
1081 data["ADDRESS_HOME_ZIP"] = "95110";
1082 data["COMPANY_NAME"] = "Company X";
1083 data["PHONE_HOME_WHOLE_NUMBER"] = "408-871-4567";
1084 FillFormAndSubmit("duplicate_profiles_test.html", data);
1085
1086 ASSERT_TRUE(personal_data_manager()->profiles().empty());
1087 }
1088
1089 // Test phone fields parse correctly from a given profile.
1090 // The high level key presses execute the following: Select the first text
1091 // field, invoke the autofill popup list, select the first profile within the
1092 // list, and commit to the profile to populate the form.
1093 IN_PROC_BROWSER_TEST_F(AutofillTest, ComparePhoneNumbers) {
1094 ASSERT_TRUE(test_server()->Start());
1095
1096 AutofillProfile profile;
1097 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob"));
1098 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith"));
1099 profile.SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 H St."));
1100 profile.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("San Jose"));
1101 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
1102 profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110"));
1103 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1-408-555-4567"));
1104 SetProfile(profile);
1105
1106 GURL url = test_server()->GetURL("files/autofill/form_phones.html");
1107 ui_test_utils::NavigateToURL(browser(), url);
1108 PopulateForm("NAME_FIRST");
1109
1110 ExpectFieldValue(L"NAME_FIRST", "Bob");
1111 ExpectFieldValue(L"NAME_LAST", "Smith");
1112 ExpectFieldValue(L"ADDRESS_HOME_LINE1", "1234 H St.");
1113 ExpectFieldValue(L"ADDRESS_HOME_CITY", "San Jose");
1114 ExpectFieldValue(L"ADDRESS_HOME_STATE", "CA");
1115 ExpectFieldValue(L"ADDRESS_HOME_ZIP", "95110");
1116 ExpectFieldValue(L"PHONE_HOME_WHOLE_NUMBER", "14085554567");
1117 ExpectFieldValue(L"PHONE_HOME_CITY_CODE-1", "408");
1118 ExpectFieldValue(L"PHONE_HOME_CITY_CODE-2", "408");
1119 ExpectFieldValue(L"PHONE_HOME_NUMBER", "5554567");
1120 ExpectFieldValue(L"PHONE_HOME_NUMBER_3-1", "555");
1121 ExpectFieldValue(L"PHONE_HOME_NUMBER_3-2", "555");
1122 ExpectFieldValue(L"PHONE_HOME_NUMBER_4-1", "4567");
1123 ExpectFieldValue(L"PHONE_HOME_NUMBER_4-2", "4567");
1124 ExpectFieldValue(L"PHONE_HOME_EXT-1", "");
1125 ExpectFieldValue(L"PHONE_HOME_EXT-2", "");
1126 ExpectFieldValue(L"PHONE_HOME_COUNTRY_CODE-1", "1");
1127 }
1128
1129 // Test profile is saved if phone number is valid in selected country.
1130 // The data file contains two profiles with valid phone numbers and two
1131 // profiles with invalid phone numbers from their respective country.
1132 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfileSavedWithValidCountryPhone) {
1133 ASSERT_TRUE(test_server()->Start());
1134 std::vector<FormMap> profiles;
1135
1136 FormMap data1;
1137 data1["NAME_FIRST"] = "Bob";
1138 data1["NAME_LAST"] = "Smith";
1139 data1["ADDRESS_HOME_LINE1"] = "123 Cherry Ave";
1140 data1["ADDRESS_HOME_CITY"] = "Mountain View";
1141 data1["ADDRESS_HOME_STATE"] = "CA";
1142 data1["ADDRESS_HOME_ZIP"] = "94043";
1143 data1["ADDRESS_HOME_COUNTRY"] = "United States";
1144 data1["PHONE_HOME_WHOLE_NUMBER"] = "408-871-4567";
1145 profiles.push_back(data1);
1146
1147 FormMap data2;
1148 data2["NAME_FIRST"] = "John";
1149 data2["NAME_LAST"] = "Doe";
1150 data2["ADDRESS_HOME_LINE1"] = "987 H St";
1151 data2["ADDRESS_HOME_CITY"] = "San Jose";
1152 data2["ADDRESS_HOME_STATE"] = "CA";
1153 data2["ADDRESS_HOME_ZIP"] = "95510";
1154 data2["ADDRESS_HOME_COUNTRY"] = "United States";
1155 data2["PHONE_HOME_WHOLE_NUMBER"] = "408-123-456";
1156 profiles.push_back(data2);
1157
1158 FormMap data3;
1159 data3["NAME_FIRST"] = "Jane";
1160 data3["NAME_LAST"] = "Doe";
1161 data3["ADDRESS_HOME_LINE1"] = "1523 Garcia St";
1162 data3["ADDRESS_HOME_CITY"] = "Mountain View";
1163 data3["ADDRESS_HOME_STATE"] = "CA";
1164 data3["ADDRESS_HOME_ZIP"] = "94043";
1165 data3["ADDRESS_HOME_COUNTRY"] = "Germany";
1166 data3["PHONE_HOME_WHOLE_NUMBER"] = "+49 40-80-81-79-000";
1167 profiles.push_back(data3);
1168
1169 FormMap data4;
1170 data4["NAME_FIRST"] = "Bonnie";
1171 data4["NAME_LAST"] = "Smith";
1172 data4["ADDRESS_HOME_LINE1"] = "6723 Roadway Rd";
1173 data4["ADDRESS_HOME_CITY"] = "San Jose";
1174 data4["ADDRESS_HOME_STATE"] = "CA";
1175 data4["ADDRESS_HOME_ZIP"] = "95510";
1176 data4["ADDRESS_HOME_COUNTRY"] = "Germany";
1177 data4["PHONE_HOME_WHOLE_NUMBER"] = "+21 08450 777 777";
1178 profiles.push_back(data4);
1179
1180 for (size_t i = 0; i < profiles.size(); ++i)
1181 FillFormAndSubmit("autofill_test_form.html", profiles[i]);
1182
1183 ASSERT_EQ(2u, personal_data_manager()->profiles().size());
1184 ASSERT_EQ(ASCIIToUTF16("(408) 871-4567"),
1185 personal_data_manager()->profiles()[0]->GetInfo(
1186 PHONE_HOME_WHOLE_NUMBER));
1187 ASSERT_EQ(ASCIIToUTF16("+49 40/808179000"),
1188 personal_data_manager()->profiles()[1]->GetInfo(
1189 PHONE_HOME_WHOLE_NUMBER));
1190 }
1191
1192 // Test Autofill appends country codes to aggregated phone numbers.
1193 // The country code is added for the following case:
1194 // The phone number contains the correct national number size and
1195 // is a valid format.
1196 IN_PROC_BROWSER_TEST_F(AutofillTest, AppendCountryCodeForAggregatedPhones) {
1197 ASSERT_TRUE(test_server()->Start());
1198 FormMap data;
1199 data["NAME_FIRST"] = "Bob";
1200 data["NAME_LAST"] = "Smith";
1201 data["ADDRESS_HOME_LINE1"] = "1234 H St.";
1202 data["ADDRESS_HOME_CITY"] = "San Jose";
1203 data["ADDRESS_HOME_STATE"] = "CA";
1204 data["ADDRESS_HOME_ZIP"] = "95110";
1205 data["ADDRESS_HOME_COUNTRY"] = "Germany";
1206 data["PHONE_HOME_WHOLE_NUMBER"] = "(08) 450 777-777";
1207 FillFormAndSubmit("autofill_test_form.html", data);
1208
1209 ASSERT_EQ(1u, personal_data_manager()->profiles().size());
1210 string16 phone =
1211 personal_data_manager()->profiles()[0]->GetInfo(PHONE_HOME_WHOLE_NUMBER);
1212 ASSERT_TRUE(StartsWith(phone, ASCIIToUTF16("+49"), true));
1213 }
1214
1215 // Test CC info not offered to be saved when autocomplete=off for CC field.
1216 // If the credit card number field has autocomplete turned off, then the credit
1217 // card infobar should not offer to save the credit card info. The credit card
1218 // number must be a valid Luhn number.
1219 IN_PROC_BROWSER_TEST_F(AutofillTest, CCInfoNotStoredWhenAutocompleteOff) {
1220 ASSERT_TRUE(test_server()->Start());
1221 FormMap data;
1222 data["CREDIT_CARD_NAME"] = "Bob Smith";
1223 data["CREDIT_CARD_NUMBER"] = "4408041234567893";
1224 data["CREDIT_CARD_EXP_MONTH"] = "12";
1225 data["CREDIT_CARD_EXP_4_DIGIT_YEAR"] = "2014";
1226 FillFormAndSubmit("cc_autocomplete_off_test.html", data);
1227
1228 ASSERT_EQ(0u,
1229 InfoBarTabService::ForTab(chrome::GetActiveTabContents(browser()))->
1230 GetInfoBarCount());
1231 }
1232
1233 // Test that Autofill does not fill in read-only fields.
1234 IN_PROC_BROWSER_TEST_F(AutofillTest, NoAutofillForReadOnlyFields) {
1235 ASSERT_TRUE(test_server()->Start());
1236
1237 std::string addr_line1("1234 H St.");
1238
1239 AutofillProfile profile;
1240 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob"));
1241 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith"));
1242 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("bsmith@gmail.com"));
1243 profile.SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16(addr_line1));
1244 profile.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("San Jose"));
1245 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
1246 profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110"));
1247 profile.SetInfo(COMPANY_NAME, ASCIIToUTF16("Company X"));
1248 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("408-871-4567"));
1249 SetProfile(profile);
1250
1251 GURL url = test_server()->GetURL("files/autofill/read_only_field_test.html");
1252 ui_test_utils::NavigateToURL(browser(), url);
1253 PopulateForm("firstname");
1254
1255 ExpectFieldValue(L"email", "");
1256 ExpectFieldValue(L"address", addr_line1);
1257 }
1258
1259 // Test form is fillable from a profile after form was reset.
1260 // Steps:
1261 // 1. Fill form using a saved profile.
1262 // 2. Reset the form.
1263 // 3. Fill form using a saved profile.
1264 IN_PROC_BROWSER_TEST_F(AutofillTest, FormFillableOnReset) {
1265 ASSERT_TRUE(test_server()->Start());
1266
1267 CreateTestProfile();
1268
1269 GURL url = test_server()->GetURL("files/autofill/autofill_test_form.html");
1270 ui_test_utils::NavigateToURL(browser(), url);
1271 PopulateForm("NAME_FIRST");
1272
1273 ASSERT_TRUE(content::ExecuteJavaScript(
1274 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"",
1275 L"document.getElementById('testform').reset()"));
1276
1277 PopulateForm("NAME_FIRST");
1278
1279 ExpectFieldValue(L"NAME_FIRST", "Milton");
1280 ExpectFieldValue(L"NAME_LAST", "Waddams");
1281 ExpectFieldValue(L"EMAIL_ADDRESS", "red.swingline@initech.com");
1282 ExpectFieldValue(L"ADDRESS_HOME_LINE1", "4120 Freidrich Lane");
1283 ExpectFieldValue(L"ADDRESS_HOME_CITY", "Austin");
1284 ExpectFieldValue(L"ADDRESS_HOME_STATE", "Texas");
1285 ExpectFieldValue(L"ADDRESS_HOME_ZIP", "78744");
1286 ExpectFieldValue(L"ADDRESS_HOME_COUNTRY", "United States");
1287 ExpectFieldValue(L"PHONE_HOME_WHOLE_NUMBER", "5125551234");
1288 }
1289
1290 // Test Autofill distinguishes a middle initial in a name.
1291 IN_PROC_BROWSER_TEST_F(AutofillTest, DistinguishMiddleInitialWithinName) {
1292 ASSERT_TRUE(test_server()->Start());
1293
1294 CreateTestProfile();
1295
1296 GURL url = test_server()->GetURL(
1297 "files/autofill/autofill_middleinit_form.html");
1298 ui_test_utils::NavigateToURL(browser(), url);
1299 PopulateForm("NAME_FIRST");
1300
1301 ExpectFieldValue(L"NAME_MIDDLE", "C");
1302 }
1303
1304 // Test forms with multiple email addresses are filled properly.
1305 // Entire form should be filled with one user gesture.
1306 IN_PROC_BROWSER_TEST_F(AutofillTest, MultipleEmailFilledByOneUserGesture) {
1307 ASSERT_TRUE(test_server()->Start());
1308
1309 std::string email("bsmith@gmail.com");
1310
1311 AutofillProfile profile;
1312 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob"));
1313 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith"));
1314 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16(email));
1315 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("4088714567"));
1316 SetProfile(profile);
1317
1318 GURL url = test_server()->GetURL(
1319 "files/autofill/autofill_confirmemail_form.html");
1320 ui_test_utils::NavigateToURL(browser(), url);
1321 PopulateForm("NAME_FIRST");
1322
1323 ExpectFieldValue(L"EMAIL_CONFIRM", email);
1324 // TODO(isherman): verify entire form.
1325 }
1326
1327 // Test profile not aggregated if email found in non-email field.
1328 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfileWithEmailInOtherFieldNotSaved) {
1329 ASSERT_TRUE(test_server()->Start());
1330
1331 FormMap data;
1332 data["NAME_FIRST"] = "Bob";
1333 data["NAME_LAST"] = "Smith";
1334 data["ADDRESS_HOME_LINE1"] = "bsmith@gmail.com";
1335 data["ADDRESS_HOME_CITY"] = "San Jose";
1336 data["ADDRESS_HOME_STATE"] = "CA";
1337 data["ADDRESS_HOME_ZIP"] = "95110";
1338 data["COMPANY_NAME"] = "Company X";
1339 data["PHONE_HOME_WHOLE_NUMBER"] = "408-871-4567";
1340 FillFormAndSubmit("duplicate_profiles_test.html", data);
1341
1342 ASSERT_EQ(0u, personal_data_manager()->profiles().size());
1343 }
1344
1345 // Test latency time on form submit with lots of stored Autofill profiles.
1346 // This test verifies when a profile is selected from the Autofill dictionary
1347 // that consists of thousands of profiles, the form does not hang after being
1348 // submitted.
1349 IN_PROC_BROWSER_TEST_F(AutofillTest, FormFillLatencyAfterSubmit) {
1350 ASSERT_TRUE(test_server()->Start());
1351
1352 std::vector<std::string> cities;
1353 cities.push_back("San Jose");
1354 cities.push_back("San Francisco");
1355 cities.push_back("Sacramento");
1356 cities.push_back("Los Angeles");
1357
1358 std::vector<std::string> streets;
1359 streets.push_back("St");
1360 streets.push_back("Ave");
1361 streets.push_back("Ln");
1362 streets.push_back("Ct");
1363
1364 const int kNumProfiles = 1500;
1365 base::Time start_time = base::Time::Now();
1366 std::vector<AutofillProfile> profiles;
1367 for (int i = 0; i < kNumProfiles; i++) {
1368 AutofillProfile profile;
1369 string16 name(base::IntToString16(i));
1370 string16 email(name + ASCIIToUTF16("@example.com"));
1371 string16 street = ASCIIToUTF16(
1372 base::IntToString(base::RandInt(0, 10000)) + " " +
1373 streets[base::RandInt(0, streets.size() - 1)]);
1374 string16 city = ASCIIToUTF16(cities[base::RandInt(0, cities.size() - 1)]);
1375 string16 zip(base::IntToString16(base::RandInt(0, 10000)));
1376 profile.SetInfo(NAME_FIRST, name);
1377 profile.SetInfo(EMAIL_ADDRESS, email);
1378 profile.SetInfo(ADDRESS_HOME_LINE1, street);
1379 profile.SetInfo(ADDRESS_HOME_CITY, city);
1380 profile.SetInfo(ADDRESS_HOME_STATE, WideToUTF16(L"CA"));
1381 profile.SetInfo(ADDRESS_HOME_ZIP, zip);
1382 profile.SetInfo(ADDRESS_HOME_COUNTRY, WideToUTF16(L"United States"));
1383 profiles.push_back(profile);
1384 }
1385 SetProfiles(&profiles);
1386 // TODO(isherman): once we're sure this test doesn't timeout on any bots, this
1387 // can be removd.
1388 LOG(INFO) << "Created " << kNumProfiles << " profiles in " <<
1389 (base::Time::Now() - start_time).InSeconds() << " seconds.";
1390
1391 GURL url = test_server()->GetURL(
1392 "files/autofill/latency_after_submit_test.html");
1393 ui_test_utils::NavigateToURL(browser(), url);
1394 PopulateForm("NAME_FIRST");
1395
1396 content::WindowedNotificationObserver load_stop_observer(
1397 content::NOTIFICATION_LOAD_STOP,
1398 content::Source<content::NavigationController>(
1399 &chrome::GetActiveWebContents(browser())->GetController()));
1400
1401 ASSERT_TRUE(content::ExecuteJavaScript(
1402 render_view_host(), L"",
1403 ASCIIToWide("document.getElementById('testform').submit();")));
1404 // This will ensure the test didn't hang.
1405 load_stop_observer.Wait();
1406 }
1407
1408 // Test that profiles merge for aggregated data with same address.
1409 // The criterion for when two profiles are expected to be merged is when their
1410 // 'Address Line 1' and 'City' data match. When two profiles are merged, any
1411 // remaining address fields are expected to be overwritten. Any non-address
1412 // fields should accumulate multi-valued data.
1413 IN_PROC_BROWSER_TEST_F(AutofillTest, MergeAggregatedProfilesWithSameAddress) {
1414 AggregateProfilesIntoAutofillPrefs("dataset_2.txt");
1415
1416 ASSERT_EQ(3u, personal_data_manager()->profiles().size());
1417 }
1418
1419 // Test profiles are not merged without mininum address values.
1420 // Mininum address values needed during aggregation are: address line 1, city,
1421 // state, and zip code.
1422 // Profiles are merged when data for address line 1 and city match.
1423 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfilesNotMergedWhenNoMinAddressData) {
1424 AggregateProfilesIntoAutofillPrefs("dataset_no_address.txt");
1425
1426 ASSERT_EQ(0u, personal_data_manager()->profiles().size());
1427 }
1428
1429 // Test Autofill ability to merge duplicate profiles and throw away junk.
1430 // TODO(isherman): this looks redundant, consider removing.
1431 IN_PROC_BROWSER_TEST_F(AutofillTest, MergeAggregatedDuplicatedProfiles) {
1432 int num_of_profiles =
1433 AggregateProfilesIntoAutofillPrefs("dataset_no_address.txt");
1434
1435 ASSERT_GT(num_of_profiles,
1436 static_cast<int>(personal_data_manager()->profiles().size()));
1437 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autofill/personal_data_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698