OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/string_split.h" | 14 #include "base/string_split.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 17 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
18 #include "chrome/browser/api/infobars/infobar_tab_service.h" | 18 #include "chrome/browser/api/infobars/infobar_service.h" |
19 #include "chrome/browser/autofill/autofill_common_test.h" | 19 #include "chrome/browser/autofill/autofill_common_test.h" |
20 #include "chrome/browser/autofill/autofill_profile.h" | 20 #include "chrome/browser/autofill/autofill_profile.h" |
21 #include "chrome/browser/autofill/credit_card.h" | 21 #include "chrome/browser/autofill/credit_card.h" |
22 #include "chrome/browser/autofill/personal_data_manager.h" | 22 #include "chrome/browser/autofill/personal_data_manager.h" |
23 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 23 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
24 #include "chrome/browser/autofill/personal_data_manager_observer.h" | 24 #include "chrome/browser/autofill/personal_data_manager_observer.h" |
25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/translate/translate_infobar_delegate.h" | 26 #include "chrome/browser/translate/translate_infobar_delegate.h" |
27 #include "chrome/browser/translate/translate_manager.h" | 27 #include "chrome/browser/translate/translate_manager.h" |
28 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 virtual void OnInsufficientFormData() OVERRIDE { | 128 virtual void OnInsufficientFormData() OVERRIDE { |
129 OnPersonalDataChanged(); | 129 OnPersonalDataChanged(); |
130 } | 130 } |
131 | 131 |
132 // content::NotificationObserver: | 132 // content::NotificationObserver: |
133 virtual void Observe(int type, | 133 virtual void Observe(int type, |
134 const content::NotificationSource& source, | 134 const content::NotificationSource& source, |
135 const content::NotificationDetails& details) OVERRIDE { | 135 const content::NotificationDetails& details) OVERRIDE { |
136 // Accept in the infobar. | 136 // Accept in the infobar. |
137 infobar_service_ = | 137 infobar_service_ = |
138 InfoBarTabService::ForTab(chrome::GetActiveTabContents(browser_)); | 138 InfoBarService::ForTab(chrome::GetActiveTabContents(browser_)); |
139 InfoBarDelegate* infobar = infobar_service_->GetInfoBarDelegateAt(0); | 139 InfoBarDelegate* infobar = infobar_service_->GetInfoBarDelegateAt(0); |
140 | 140 |
141 ConfirmInfoBarDelegate* confirm_infobar = | 141 ConfirmInfoBarDelegate* confirm_infobar = |
142 infobar->AsConfirmInfoBarDelegate(); | 142 infobar->AsConfirmInfoBarDelegate(); |
143 confirm_infobar->Accept(); | 143 confirm_infobar->Accept(); |
144 } | 144 } |
145 | 145 |
146 private: | 146 private: |
147 bool alerted_; | 147 bool alerted_; |
148 bool has_run_message_loop_; | 148 bool has_run_message_loop_; |
149 Browser* browser_; | 149 Browser* browser_; |
150 content::NotificationRegistrar registrar_; | 150 content::NotificationRegistrar registrar_; |
151 InfoBarTabService* infobar_service_; | 151 InfoBarService* infobar_service_; |
152 }; | 152 }; |
153 | 153 |
154 class AutofillTest : public InProcessBrowserTest { | 154 class AutofillTest : public InProcessBrowserTest { |
155 protected: | 155 protected: |
156 AutofillTest() {} | 156 AutofillTest() {} |
157 | 157 |
158 virtual void SetUpOnMainThread() OVERRIDE { | 158 virtual void SetUpOnMainThread() OVERRIDE { |
159 // Don't want Keychain coming up on Mac. | 159 // Don't want Keychain coming up on Mac. |
160 autofill_test::DisableSystemServices(browser()->profile()); | 160 autofill_test::DisableSystemServices(browser()->profile()); |
161 } | 161 } |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 " <input type=\"text\" id=\"ph\"><br>" | 834 " <input type=\"text\" id=\"ph\"><br>" |
835 "</form>"); | 835 "</form>"); |
836 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 836 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
837 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), url)); | 837 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), url)); |
838 | 838 |
839 // Get translation bar. | 839 // Get translation bar. |
840 RenderViewHostTester::TestOnMessageReceived( | 840 RenderViewHostTester::TestOnMessageReceived( |
841 render_view_host(), | 841 render_view_host(), |
842 ChromeViewHostMsg_TranslateLanguageDetermined(0, "ja", true)); | 842 ChromeViewHostMsg_TranslateLanguageDetermined(0, "ja", true)); |
843 TranslateInfoBarDelegate* infobar = | 843 TranslateInfoBarDelegate* infobar = |
844 InfoBarTabService::ForTab(chrome::GetActiveTabContents(browser()))-> | 844 InfoBarService::ForTab(chrome::GetActiveTabContents(browser()))-> |
845 GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate(); | 845 GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate(); |
846 | 846 |
847 ASSERT_TRUE(infobar != NULL); | 847 ASSERT_TRUE(infobar != NULL); |
848 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); | 848 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); |
849 | 849 |
850 // Simulate translation button press. | 850 // Simulate translation button press. |
851 infobar->Translate(); | 851 infobar->Translate(); |
852 | 852 |
853 // Simulate the translate script being retrieved. | 853 // Simulate the translate script being retrieved. |
854 // Pass fake google.translate lib as the translate script. | 854 // Pass fake google.translate lib as the translate script. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 // Test credit card info with an invalid number is not aggregated. | 1008 // Test credit card info with an invalid number is not aggregated. |
1009 // When filling out a form with an invalid credit card number (one that does not | 1009 // When filling out a form with an invalid credit card number (one that does not |
1010 // pass the Luhn test) the credit card info should not be saved into Autofill | 1010 // pass the Luhn test) the credit card info should not be saved into Autofill |
1011 // preferences. | 1011 // preferences. |
1012 IN_PROC_BROWSER_TEST_F(AutofillTest, InvalidCreditCardNumberIsNotAggregated) { | 1012 IN_PROC_BROWSER_TEST_F(AutofillTest, InvalidCreditCardNumberIsNotAggregated) { |
1013 ASSERT_TRUE(test_server()->Start()); | 1013 ASSERT_TRUE(test_server()->Start()); |
1014 std::string card("4408 0412 3456 7890"); | 1014 std::string card("4408 0412 3456 7890"); |
1015 ASSERT_FALSE(CreditCard::IsValidCreditCardNumber(ASCIIToUTF16(card))); | 1015 ASSERT_FALSE(CreditCard::IsValidCreditCardNumber(ASCIIToUTF16(card))); |
1016 SubmitCreditCard("Bob Smith", card.c_str(), "12", "2014"); | 1016 SubmitCreditCard("Bob Smith", card.c_str(), "12", "2014"); |
1017 ASSERT_EQ(0u, | 1017 ASSERT_EQ(0u, |
1018 InfoBarTabService::ForTab(chrome::GetActiveTabContents(browser()))-> | 1018 InfoBarService::ForTab(chrome::GetActiveTabContents(browser()))-> |
1019 GetInfoBarCount()); | 1019 GetInfoBarCount()); |
1020 } | 1020 } |
1021 | 1021 |
1022 // Test whitespaces and separator chars are stripped for valid CC numbers. | 1022 // Test whitespaces and separator chars are stripped for valid CC numbers. |
1023 // The credit card numbers used in this test pass the Luhn test. For reference: | 1023 // The credit card numbers used in this test pass the Luhn test. For reference: |
1024 // http://www.merriampark.com/anatomycc.htm | 1024 // http://www.merriampark.com/anatomycc.htm |
1025 IN_PROC_BROWSER_TEST_F(AutofillTest, | 1025 IN_PROC_BROWSER_TEST_F(AutofillTest, |
1026 WhitespacesAndSeparatorCharsStrippedForValidCCNums) { | 1026 WhitespacesAndSeparatorCharsStrippedForValidCCNums) { |
1027 ASSERT_TRUE(test_server()->Start()); | 1027 ASSERT_TRUE(test_server()->Start()); |
1028 SubmitCreditCard("Bob Smith", "4408 0412 3456 7893", "12", "2014"); | 1028 SubmitCreditCard("Bob Smith", "4408 0412 3456 7893", "12", "2014"); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 IN_PROC_BROWSER_TEST_F(AutofillTest, CCInfoNotStoredWhenAutocompleteOff) { | 1222 IN_PROC_BROWSER_TEST_F(AutofillTest, CCInfoNotStoredWhenAutocompleteOff) { |
1223 ASSERT_TRUE(test_server()->Start()); | 1223 ASSERT_TRUE(test_server()->Start()); |
1224 FormMap data; | 1224 FormMap data; |
1225 data["CREDIT_CARD_NAME"] = "Bob Smith"; | 1225 data["CREDIT_CARD_NAME"] = "Bob Smith"; |
1226 data["CREDIT_CARD_NUMBER"] = "4408041234567893"; | 1226 data["CREDIT_CARD_NUMBER"] = "4408041234567893"; |
1227 data["CREDIT_CARD_EXP_MONTH"] = "12"; | 1227 data["CREDIT_CARD_EXP_MONTH"] = "12"; |
1228 data["CREDIT_CARD_EXP_4_DIGIT_YEAR"] = "2014"; | 1228 data["CREDIT_CARD_EXP_4_DIGIT_YEAR"] = "2014"; |
1229 FillFormAndSubmit("cc_autocomplete_off_test.html", data); | 1229 FillFormAndSubmit("cc_autocomplete_off_test.html", data); |
1230 | 1230 |
1231 ASSERT_EQ(0u, | 1231 ASSERT_EQ(0u, |
1232 InfoBarTabService::ForTab(chrome::GetActiveTabContents(browser()))-> | 1232 InfoBarService::ForTab(chrome::GetActiveTabContents(browser()))-> |
1233 GetInfoBarCount()); | 1233 GetInfoBarCount()); |
1234 } | 1234 } |
1235 | 1235 |
1236 // Test that Autofill does not fill in read-only fields. | 1236 // Test that Autofill does not fill in read-only fields. |
1237 IN_PROC_BROWSER_TEST_F(AutofillTest, NoAutofillForReadOnlyFields) { | 1237 IN_PROC_BROWSER_TEST_F(AutofillTest, NoAutofillForReadOnlyFields) { |
1238 ASSERT_TRUE(test_server()->Start()); | 1238 ASSERT_TRUE(test_server()->Start()); |
1239 | 1239 |
1240 std::string addr_line1("1234 H St."); | 1240 std::string addr_line1("1234 H St."); |
1241 | 1241 |
1242 AutofillProfile profile; | 1242 AutofillProfile profile; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 | 1431 |
1432 // Test Autofill ability to merge duplicate profiles and throw away junk. | 1432 // Test Autofill ability to merge duplicate profiles and throw away junk. |
1433 // TODO(isherman): this looks redundant, consider removing. | 1433 // TODO(isherman): this looks redundant, consider removing. |
1434 IN_PROC_BROWSER_TEST_F(AutofillTest, MergeAggregatedDuplicatedProfiles) { | 1434 IN_PROC_BROWSER_TEST_F(AutofillTest, MergeAggregatedDuplicatedProfiles) { |
1435 int num_of_profiles = | 1435 int num_of_profiles = |
1436 AggregateProfilesIntoAutofillPrefs("dataset_no_address.txt"); | 1436 AggregateProfilesIntoAutofillPrefs("dataset_no_address.txt"); |
1437 | 1437 |
1438 ASSERT_GT(num_of_profiles, | 1438 ASSERT_GT(num_of_profiles, |
1439 static_cast<int>(personal_data_manager()->profiles().size())); | 1439 static_cast<int>(personal_data_manager()->profiles().size())); |
1440 } | 1440 } |
OLD | NEW |