| 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 #include <utility> |
| 8 | 9 |
| 9 #include "base/callback.h" | 10 #include "base/callback.h" |
| 10 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/test/scoped_feature_list.h" | 14 #include "base/test/scoped_feature_list.h" |
| 14 #include "components/autofill/core/browser/autofill_driver.h" | 15 #include "components/autofill/core/browser/autofill_driver.h" |
| 15 #include "components/autofill/core/browser/autofill_experiments.h" | 16 #include "components/autofill/core/browser/autofill_experiments.h" |
| 16 #include "components/autofill/core/browser/autofill_manager.h" | 17 #include "components/autofill/core/browser/autofill_manager.h" |
| 17 #include "components/autofill/core/browser/autofill_test_utils.h" | 18 #include "components/autofill/core/browser/autofill_test_utils.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 EnableAutofillCreditCardAssist(); | 225 EnableAutofillCreditCardAssist(); |
| 225 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); | 226 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); |
| 226 | 227 |
| 227 // Will extract the credit card form data. | 228 // Will extract the credit card form data. |
| 228 std::vector<std::unique_ptr<FormStructure>> form_structures; | 229 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 229 form_structures.push_back(std::move(form_structure)); | 230 form_structures.push_back(std::move(form_structure)); |
| 230 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 231 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 231 | 232 |
| 232 // Create a valid card for the assist. | 233 // Create a valid card for the assist. |
| 233 CreditCard card; | 234 CreditCard card; |
| 234 test::SetCreditCardInfo(&card, "John Doe", "4111111111111111", "05", "2999"); | 235 test::SetCreditCardInfo(&card, "John Doe", "4111111111111111", "05", "2999", |
| 236 "1"); |
| 235 | 237 |
| 236 // FillCreditCardForm should not be called if the user cancelled the CVC. | 238 // FillCreditCardForm should not be called if the user cancelled the CVC. |
| 237 EXPECT_CALL(autofill_manager_, FillCreditCardForm(_, _, _, _, _)).Times(0); | 239 EXPECT_CALL(autofill_manager_, FillCreditCardForm(_, _, _, _, _)).Times(0); |
| 238 | 240 |
| 239 autofill_assistant_.ShowAssistForCreditCard(card); | 241 autofill_assistant_.ShowAssistForCreditCard(card); |
| 240 static_cast<CardUnmaskDelegate*>( | 242 static_cast<CardUnmaskDelegate*>( |
| 241 autofill_manager_.GetOrCreateFullCardRequest()) | 243 autofill_manager_.GetOrCreateFullCardRequest()) |
| 242 ->OnUnmaskPromptClosed(); | 244 ->OnUnmaskPromptClosed(); |
| 243 } | 245 } |
| 244 | 246 |
| 245 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_SubmitCvc) { | 247 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_SubmitCvc) { |
| 246 EnableAutofillCreditCardAssist(); | 248 EnableAutofillCreditCardAssist(); |
| 247 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); | 249 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); |
| 248 | 250 |
| 249 // Will extract the credit card form data. | 251 // Will extract the credit card form data. |
| 250 std::vector<std::unique_ptr<FormStructure>> form_structures; | 252 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 251 form_structures.push_back(std::move(form_structure)); | 253 form_structures.push_back(std::move(form_structure)); |
| 252 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 254 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 253 | 255 |
| 254 // Create a valid card for the assist. | 256 // Create a valid card for the assist. |
| 255 CreditCard card; | 257 CreditCard card; |
| 256 test::SetCreditCardInfo(&card, "John Doe", "4111111111111111", "05", "2999"); | 258 test::SetCreditCardInfo(&card, "John Doe", "4111111111111111", "05", "2999", |
| 259 "1"); |
| 257 | 260 |
| 258 // FillCreditCardForm ends up being called after user has accepted the | 261 // FillCreditCardForm ends up being called after user has accepted the |
| 259 // prompt. | 262 // prompt. |
| 260 EXPECT_CALL( | 263 EXPECT_CALL( |
| 261 autofill_manager_, | 264 autofill_manager_, |
| 262 FillCreditCardForm(kNoQueryId, _, _, CreditCardMatches(card.guid()), | 265 FillCreditCardForm(kNoQueryId, _, _, CreditCardMatches(card.guid()), |
| 263 base::ASCIIToUTF16("123"))); | 266 base::ASCIIToUTF16("123"))); |
| 264 | 267 |
| 265 autofill_assistant_.ShowAssistForCreditCard(card); | 268 autofill_assistant_.ShowAssistForCreditCard(card); |
| 266 | 269 |
| 267 CardUnmaskDelegate::UnmaskResponse unmask_response; | 270 CardUnmaskDelegate::UnmaskResponse unmask_response; |
| 268 unmask_response.cvc = base::ASCIIToUTF16("123"); | 271 unmask_response.cvc = base::ASCIIToUTF16("123"); |
| 269 static_cast<CardUnmaskDelegate*>( | 272 static_cast<CardUnmaskDelegate*>( |
| 270 autofill_manager_.GetOrCreateFullCardRequest()) | 273 autofill_manager_.GetOrCreateFullCardRequest()) |
| 271 ->OnUnmaskResponse(unmask_response); | 274 ->OnUnmaskResponse(unmask_response); |
| 272 } | 275 } |
| 273 | 276 |
| 274 } // namespace autofill | 277 } // namespace autofill |
| OLD | NEW |