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