| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 void CreateTestCreditCardFormData(FormData* form, | 883 void CreateTestCreditCardFormData(FormData* form, |
| 884 bool is_https, | 884 bool is_https, |
| 885 bool use_month_type) { | 885 bool use_month_type) { |
| 886 form->name = ASCIIToUTF16("MyForm"); | 886 form->name = ASCIIToUTF16("MyForm"); |
| 887 if (is_https) { | 887 if (is_https) { |
| 888 form->origin = GURL("https://myform.com/form.html"); | 888 form->origin = GURL("https://myform.com/form.html"); |
| 889 form->action = GURL("https://myform.com/submit.html"); | 889 form->action = GURL("https://myform.com/submit.html"); |
| 890 } else { | 890 } else { |
| 891 form->origin = GURL("http://myform.com/form.html"); | 891 form->origin = GURL("http://myform.com/form.html"); |
| 892 form->action = GURL("http://myform.com/submit.html"); | 892 form->action = GURL("http://myform.com/submit.html"); |
| 893 autofill_client_.set_is_context_secure(false); | |
| 894 } | 893 } |
| 895 | 894 |
| 896 FormFieldData field; | 895 FormFieldData field; |
| 897 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); | 896 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); |
| 898 form->fields.push_back(field); | 897 form->fields.push_back(field); |
| 899 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | 898 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 900 form->fields.push_back(field); | 899 form->fields.push_back(field); |
| 901 if (use_month_type) { | 900 if (use_month_type) { |
| 902 test::CreateTestFormField( | 901 test::CreateTestFormField( |
| 903 "Expiration Date", "ccmonth", "", "month", &field); | 902 "Expiration Date", "ccmonth", "", "month", &field); |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 // Test that we sent the right values to the external delegate. | 1546 // Test that we sent the right values to the external delegate. |
| 1548 external_delegate_->CheckSuggestions( | 1547 external_delegate_->CheckSuggestions( |
| 1549 kDefaultPageID, | 1548 kDefaultPageID, |
| 1550 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, | 1549 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, |
| 1551 autofill_manager_->GetPackedCreditCardID(4)), | 1550 autofill_manager_->GetPackedCreditCardID(4)), |
| 1552 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, | 1551 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, |
| 1553 autofill_manager_->GetPackedCreditCardID(5))); | 1552 autofill_manager_->GetPackedCreditCardID(5))); |
| 1554 } | 1553 } |
| 1555 | 1554 |
| 1556 // Test that we return a warning explaining that credit card profile suggestions | 1555 // Test that we return a warning explaining that credit card profile suggestions |
| 1557 // are unavailable when the form is not secure. | 1556 // are unavailable when the page and the form target URL are not secure. |
| 1558 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonHTTPS) { | 1557 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonHTTPS) { |
| 1559 // Set up our form data. | 1558 // Set up our form data. |
| 1560 FormData form; | 1559 FormData form; |
| 1561 CreateTestCreditCardFormData(&form, false, false); | 1560 CreateTestCreditCardFormData(&form, false, false); |
| 1562 std::vector<FormData> forms(1, form); | 1561 std::vector<FormData> forms(1, form); |
| 1563 FormsSeen(forms); | 1562 FormsSeen(forms); |
| 1564 | 1563 |
| 1565 const FormFieldData& field = form.fields[0]; | 1564 const FormFieldData& field = form.fields[0]; |
| 1566 GetAutofillSuggestions(form, field); | 1565 GetAutofillSuggestions(form, field); |
| 1567 | 1566 |
| 1568 // Test that we sent the right values to the external delegate. | 1567 // Test that we sent the right values to the external delegate. |
| 1569 external_delegate_->CheckSuggestions( | 1568 external_delegate_->CheckSuggestions( |
| 1570 kDefaultPageID, | 1569 kDefaultPageID, |
| 1571 Suggestion( | 1570 Suggestion( |
| 1572 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), | 1571 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 1573 "", "", -1)); | 1572 "", "", -1)); |
| 1574 | 1573 |
| 1575 // Clear the test credit cards and try again -- we shouldn't return a warning. | 1574 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 1576 personal_data_.ClearCreditCards(); | 1575 personal_data_.ClearCreditCards(); |
| 1577 GetAutofillSuggestions(form, field); | 1576 GetAutofillSuggestions(form, field); |
| 1578 // Autocomplete suggestions are queried, but not Autofill. | 1577 // Autocomplete suggestions are queried, but not Autofill. |
| 1579 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1578 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1580 } | 1579 } |
| 1581 | 1580 |
| 1581 // Test that we return a warning explaining that credit card profile suggestions |
| 1582 // are unavailable when the page is secure, but the form target URL is not |
| 1583 // secure. |
| 1584 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_TargetURLNonHTTPS) { |
| 1585 // Set up our form data. |
| 1586 FormData form; |
| 1587 CreateTestCreditCardFormData(&form, /* is_https= */ true, false); |
| 1588 // However we set the action (target URL) to be HTTP after all. |
| 1589 form.action = GURL("http://myform.com/submit.html"); |
| 1590 std::vector<FormData> forms(1, form); |
| 1591 FormsSeen(forms); |
| 1592 |
| 1593 const FormFieldData& field = form.fields[0]; |
| 1594 GetAutofillSuggestions(form, field); |
| 1595 |
| 1596 // Test that we sent the right values to the external delegate. |
| 1597 external_delegate_->CheckSuggestions( |
| 1598 kDefaultPageID, Suggestion(l10n_util::GetStringUTF8( |
| 1599 IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 1600 "", "", -1)); |
| 1601 |
| 1602 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 1603 personal_data_.ClearCreditCards(); |
| 1604 GetAutofillSuggestions(form, field); |
| 1605 // Autocomplete suggestions are queried, but not Autofill. |
| 1606 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1607 } |
| 1608 |
| 1582 // Test that we return all credit card suggestions in the case that two cards | 1609 // Test that we return all credit card suggestions in the case that two cards |
| 1583 // have the same obfuscated number. | 1610 // have the same obfuscated number. |
| 1584 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { | 1611 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { |
| 1585 // Add a credit card with the same obfuscated number as Elvis's. | 1612 // Add a credit card with the same obfuscated number as Elvis's. |
| 1586 // |credit_card| will be owned by the mock PersonalDataManager. | 1613 // |credit_card| will be owned by the mock PersonalDataManager. |
| 1587 CreditCard* credit_card = new CreditCard; | 1614 CreditCard* credit_card = new CreditCard; |
| 1588 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 1615 test::SetCreditCardInfo(credit_card, "Elvis Presley", |
| 1589 "5231567890123456", // Mastercard | 1616 "5231567890123456", // Mastercard |
| 1590 "05", "2999"); | 1617 "05", "2999"); |
| 1591 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 1618 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| (...skipping 3622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5214 FormsSeen(mixed_forms); | 5241 FormsSeen(mixed_forms); |
| 5215 | 5242 |
| 5216 // Suggestions should always be displayed. | 5243 // Suggestions should always be displayed. |
| 5217 for (const FormFieldData& field : mixed_form.fields) { | 5244 for (const FormFieldData& field : mixed_form.fields) { |
| 5218 GetAutofillSuggestions(mixed_form, field); | 5245 GetAutofillSuggestions(mixed_form, field); |
| 5219 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 5246 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 5220 } | 5247 } |
| 5221 } | 5248 } |
| 5222 | 5249 |
| 5223 } // namespace autofill | 5250 } // namespace autofill |
| OLD | NEW |