| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_assistant.h" | 5 #include "components/autofill/core/browser/autofill_assistant.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 MATCHER_P(CreditCardMatches, guid, "") { | 119 MATCHER_P(CreditCardMatches, guid, "") { |
| 120 return arg.guid() == guid; | 120 return arg.guid() == guid; |
| 121 } | 121 } |
| 122 | 122 |
| 123 // If the feature is turned off, CanShowCreditCardAssist() always returns | 123 // If the feature is turned off, CanShowCreditCardAssist() always returns |
| 124 // false. | 124 // false. |
| 125 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOff) { | 125 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOff) { |
| 126 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); | 126 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); |
| 127 | 127 |
| 128 std::vector<FormStructure*> form_structures{form_structure.get()}; | 128 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 129 form_structures.push_back(std::move(form_structure)); |
| 129 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 130 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 130 } | 131 } |
| 131 | 132 |
| 132 // Tests that with the feature enabled and proper input, | 133 // Tests that with the feature enabled and proper input, |
| 133 // CanShowCreditCardAssist() behaves as expected. | 134 // CanShowCreditCardAssist() behaves as expected. |
| 134 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn) { | 135 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn) { |
| 135 EnableAutofillCreditCardAssist(); | 136 EnableAutofillCreditCardAssist(); |
| 136 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); | 137 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); |
| 137 | 138 |
| 138 std::vector<FormStructure*> form_structures; | 139 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 139 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 140 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 140 | 141 |
| 141 // With valid input, the function extracts the credit card form properly. | 142 // With valid input, the function extracts the credit card form properly. |
| 142 form_structures.push_back(form_structure.get()); | 143 form_structures.push_back(std::move(form_structure)); |
| 143 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 144 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 144 } | 145 } |
| 145 | 146 |
| 146 // Tests that with the feature enabled and proper input, | 147 // Tests that with the feature enabled and proper input, |
| 147 // CanShowCreditCardAssist() behaves as expected for secure vs insecure | 148 // CanShowCreditCardAssist() behaves as expected for secure vs insecure |
| 148 // contexts. | 149 // contexts. |
| 149 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_NotSecure) { | 150 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_NotSecure) { |
| 150 EnableAutofillCreditCardAssist(); | 151 EnableAutofillCreditCardAssist(); |
| 151 | 152 |
| 152 { | 153 { |
| 153 // Cannot be shown if the context is not secure. | 154 // Cannot be shown if the context is not secure. |
| 154 FormData form = CreateValidCreditCardFormData(); | 155 FormData form = CreateValidCreditCardFormData(); |
| 155 form.action = GURL("http://myform.com"); | 156 form.action = GURL("http://myform.com"); |
| 156 form.action = GURL("http://myform.com/submit"); | 157 form.action = GURL("http://myform.com/submit"); |
| 157 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); | 158 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); |
| 158 form_structure->DetermineHeuristicTypes(); | 159 form_structure->DetermineHeuristicTypes(); |
| 159 | 160 |
| 160 std::vector<FormStructure*> form_structures; | 161 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 161 form_structures.push_back(form_structure.get()); | 162 form_structures.push_back(std::move(form_structure)); |
| 162 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 163 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 163 } | 164 } |
| 164 | 165 |
| 165 { | 166 { |
| 166 // Can be shown if the context is secure. | 167 // Can be shown if the context is secure. |
| 167 FormData form = CreateValidCreditCardFormData(); | 168 FormData form = CreateValidCreditCardFormData(); |
| 168 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); | 169 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); |
| 169 form_structure->DetermineHeuristicTypes(); | 170 form_structure->DetermineHeuristicTypes(); |
| 170 | 171 |
| 171 std::vector<FormStructure*> form_structures; | 172 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 172 form_structures.push_back(form_structure.get()); | 173 form_structures.push_back(std::move(form_structure)); |
| 173 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 174 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 | 177 |
| 177 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_CancelCvc) { | 178 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_CancelCvc) { |
| 178 EnableAutofillCreditCardAssist(); | 179 EnableAutofillCreditCardAssist(); |
| 179 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); | 180 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); |
| 180 | 181 |
| 181 // Will extract the credit card form data. | 182 // Will extract the credit card form data. |
| 182 std::vector<FormStructure*> form_structures{form_structure.get()}; | 183 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 184 form_structures.push_back(std::move(form_structure)); |
| 183 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 185 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 184 | 186 |
| 185 // Create a valid card for the assist. | 187 // Create a valid card for the assist. |
| 186 CreditCard card; | 188 CreditCard card; |
| 187 test::SetCreditCardInfo(&card, "John Doe", "4111111111111111", "05", "2999"); | 189 test::SetCreditCardInfo(&card, "John Doe", "4111111111111111", "05", "2999"); |
| 188 | 190 |
| 189 // FillCreditCardForm should not be called if the user cancelled the CVC. | 191 // FillCreditCardForm should not be called if the user cancelled the CVC. |
| 190 EXPECT_CALL(autofill_manager_, FillCreditCardForm(_, _, _, _, _)).Times(0); | 192 EXPECT_CALL(autofill_manager_, FillCreditCardForm(_, _, _, _, _)).Times(0); |
| 191 | 193 |
| 192 autofill_assistant_.ShowAssistForCreditCard(card); | 194 autofill_assistant_.ShowAssistForCreditCard(card); |
| 193 static_cast<CardUnmaskDelegate*>( | 195 static_cast<CardUnmaskDelegate*>( |
| 194 autofill_manager_.GetOrCreateFullCardRequest()) | 196 autofill_manager_.GetOrCreateFullCardRequest()) |
| 195 ->OnUnmaskPromptClosed(); | 197 ->OnUnmaskPromptClosed(); |
| 196 } | 198 } |
| 197 | 199 |
| 198 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_SubmitCvc) { | 200 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_SubmitCvc) { |
| 199 EnableAutofillCreditCardAssist(); | 201 EnableAutofillCreditCardAssist(); |
| 200 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); | 202 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); |
| 201 | 203 |
| 202 // Will extract the credit card form data. | 204 // Will extract the credit card form data. |
| 203 std::vector<FormStructure*> form_structures{form_structure.get()}; | 205 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 206 form_structures.push_back(std::move(form_structure)); |
| 204 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 207 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 205 | 208 |
| 206 // Create a valid card for the assist. | 209 // Create a valid card for the assist. |
| 207 CreditCard card; | 210 CreditCard card; |
| 208 test::SetCreditCardInfo(&card, "John Doe", "4111111111111111", "05", "2999"); | 211 test::SetCreditCardInfo(&card, "John Doe", "4111111111111111", "05", "2999"); |
| 209 | 212 |
| 210 // FillCreditCardForm ends up being called after user has accepted the | 213 // FillCreditCardForm ends up being called after user has accepted the |
| 211 // prompt. | 214 // prompt. |
| 212 EXPECT_CALL( | 215 EXPECT_CALL( |
| 213 autofill_manager_, | 216 autofill_manager_, |
| 214 FillCreditCardForm(kNoQueryId, _, _, CreditCardMatches(card.guid()), | 217 FillCreditCardForm(kNoQueryId, _, _, CreditCardMatches(card.guid()), |
| 215 base::ASCIIToUTF16("123"))); | 218 base::ASCIIToUTF16("123"))); |
| 216 | 219 |
| 217 autofill_assistant_.ShowAssistForCreditCard(card); | 220 autofill_assistant_.ShowAssistForCreditCard(card); |
| 218 | 221 |
| 219 CardUnmaskDelegate::UnmaskResponse unmask_response; | 222 CardUnmaskDelegate::UnmaskResponse unmask_response; |
| 220 unmask_response.cvc = base::ASCIIToUTF16("123"); | 223 unmask_response.cvc = base::ASCIIToUTF16("123"); |
| 221 static_cast<CardUnmaskDelegate*>( | 224 static_cast<CardUnmaskDelegate*>( |
| 222 autofill_manager_.GetOrCreateFullCardRequest()) | 225 autofill_manager_.GetOrCreateFullCardRequest()) |
| 223 ->OnUnmaskResponse(unmask_response); | 226 ->OnUnmaskResponse(unmask_response); |
| 224 } | 227 } |
| 225 | 228 |
| 226 } // namespace autofill | 229 } // namespace autofill |
| OLD | NEW |