| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 class MockAutofillClient : public TestAutofillClient { | 67 class MockAutofillClient : public TestAutofillClient { |
| 68 public: | 68 public: |
| 69 MockAutofillClient() {} | 69 MockAutofillClient() {} |
| 70 | 70 |
| 71 ~MockAutofillClient() override {} | 71 ~MockAutofillClient() override {} |
| 72 | 72 |
| 73 MOCK_METHOD2(ConfirmSaveCreditCardLocally, | 73 MOCK_METHOD2(ConfirmSaveCreditCardLocally, |
| 74 void(const CreditCard& card, const base::Closure& callback)); | 74 void(const CreditCard& card, const base::Closure& callback)); |
| 75 | 75 |
| 76 MOCK_METHOD0(ShouldShowSigninPromo, bool()); |
| 77 |
| 76 private: | 78 private: |
| 77 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); | 79 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); |
| 78 }; | 80 }; |
| 79 | 81 |
| 80 class TestPaymentsClient : public payments::PaymentsClient { | 82 class TestPaymentsClient : public payments::PaymentsClient { |
| 81 public: | 83 public: |
| 82 TestPaymentsClient(net::URLRequestContextGetter* context_getter, | 84 TestPaymentsClient(net::URLRequestContextGetter* context_getter, |
| 83 payments::PaymentsClientDelegate* delegate) | 85 payments::PaymentsClientDelegate* delegate) |
| 84 : PaymentsClient(context_getter, delegate), delegate_(delegate) {} | 86 : PaymentsClient(context_getter, delegate), delegate_(delegate) {} |
| 85 | 87 |
| (...skipping 4814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4900 FormsSeen(forms); | 4902 FormsSeen(forms); |
| 4901 | 4903 |
| 4902 FormFieldData field; | 4904 FormFieldData field; |
| 4903 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text", | 4905 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text", |
| 4904 &field); | 4906 &field); |
| 4905 GetAutofillSuggestions(form, field); | 4907 GetAutofillSuggestions(form, field); |
| 4906 // Autocomplete suggestions are queried, but not Autofill. | 4908 // Autocomplete suggestions are queried, but not Autofill. |
| 4907 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 4909 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 4908 } | 4910 } |
| 4909 | 4911 |
| 4912 // Test that ShouldShowCreditCardSigninPromo behaves as expected for a credit |
| 4913 // card form. |
| 4914 TEST_F(AutofillManagerTest, ShouldShowCreditCardSigninPromo_CreditCardField) { |
| 4915 // Set up our form data. |
| 4916 FormData form; |
| 4917 CreateTestCreditCardFormData(&form, true, false); |
| 4918 std::vector<FormData> forms(1, form); |
| 4919 FormsSeen(forms); |
| 4920 |
| 4921 FormFieldData field; |
| 4922 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); |
| 4923 |
| 4924 EXPECT_CALL(autofill_client_, ShouldShowSigninPromo()) |
| 4925 .WillOnce(testing::Return(true)); |
| 4926 EXPECT_TRUE(autofill_manager_->ShouldShowCreditCardSigninPromo(form, field)); |
| 4927 |
| 4928 EXPECT_CALL(autofill_client_, ShouldShowSigninPromo()) |
| 4929 .WillOnce(testing::Return(false)); |
| 4930 EXPECT_FALSE(autofill_manager_->ShouldShowCreditCardSigninPromo(form, field)); |
| 4931 } |
| 4932 |
| 4933 // Test that ShouldShowCreditCardSigninPromo behaves as expected for an address |
| 4934 // form. |
| 4935 TEST_F(AutofillManagerTest, ShouldShowCreditCardSigninPromo_AddressField) { |
| 4936 // Set up our form data. |
| 4937 FormData form; |
| 4938 test::CreateTestAddressFormData(&form); |
| 4939 std::vector<FormData> forms(1, form); |
| 4940 FormsSeen(forms); |
| 4941 |
| 4942 FormFieldData field; |
| 4943 test::CreateTestFormField("First Name", "firstname", "", "text", &field); |
| 4944 |
| 4945 // Call will now return false, because it is initiated from an address field. |
| 4946 EXPECT_CALL(autofill_client_, ShouldShowSigninPromo()).Times(0); |
| 4947 EXPECT_FALSE(autofill_manager_->ShouldShowCreditCardSigninPromo(form, field)); |
| 4948 } |
| 4949 |
| 4910 // Verify that typing "S" into the middle name field will match and order middle | 4950 // Verify that typing "S" into the middle name field will match and order middle |
| 4911 // names "Shawn Smith" followed by "Adam Smith" i.e. prefix matched followed by | 4951 // names "Shawn Smith" followed by "Adam Smith" i.e. prefix matched followed by |
| 4912 // substring matched. | 4952 // substring matched. |
| 4913 TEST_F(AutofillManagerTest, | 4953 TEST_F(AutofillManagerTest, |
| 4914 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) { | 4954 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) { |
| 4915 // Token matching is currently behind a flag. | 4955 // Token matching is currently behind a flag. |
| 4916 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 4956 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 4917 switches::kEnableSuggestionsWithSubstringMatch); | 4957 switches::kEnableSuggestionsWithSubstringMatch); |
| 4918 | 4958 |
| 4919 // Set up our form data. | 4959 // Set up our form data. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5076 FormsSeen(mixed_forms); | 5116 FormsSeen(mixed_forms); |
| 5077 | 5117 |
| 5078 // Suggestions should always be displayed. | 5118 // Suggestions should always be displayed. |
| 5079 for (const FormFieldData& field : mixed_form.fields) { | 5119 for (const FormFieldData& field : mixed_form.fields) { |
| 5080 GetAutofillSuggestions(mixed_form, field); | 5120 GetAutofillSuggestions(mixed_form, field); |
| 5081 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 5121 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 5082 } | 5122 } |
| 5083 } | 5123 } |
| 5084 | 5124 |
| 5085 } // namespace autofill | 5125 } // namespace autofill |
| OLD | NEW |