| 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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/test/scoped_feature_list.h" |
| 13 #include "components/autofill/core/browser/autofill_driver.h" | 14 #include "components/autofill/core/browser/autofill_driver.h" |
| 14 #include "components/autofill/core/browser/autofill_experiments.h" | 15 #include "components/autofill/core/browser/autofill_experiments.h" |
| 15 #include "components/autofill/core/browser/autofill_manager.h" | 16 #include "components/autofill/core/browser/autofill_manager.h" |
| 16 #include "components/autofill/core/browser/autofill_test_utils.h" | 17 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 17 #include "components/autofill/core/browser/credit_card.h" | 18 #include "components/autofill/core/browser/credit_card.h" |
| 18 #include "components/autofill/core/browser/form_structure.h" | 19 #include "components/autofill/core/browser/form_structure.h" |
| 19 #include "components/autofill/core/browser/test_autofill_client.h" | 20 #include "components/autofill/core/browser/test_autofill_client.h" |
| 20 #include "components/autofill/core/browser/test_autofill_driver.h" | 21 #include "components/autofill/core/browser/test_autofill_driver.h" |
| 21 #include "components/autofill/core/common/autofill_constants.h" | 22 #include "components/autofill/core/common/autofill_constants.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 51 class AutofillAssistantTest : public testing::Test { | 52 class AutofillAssistantTest : public testing::Test { |
| 52 protected: | 53 protected: |
| 53 AutofillAssistantTest() | 54 AutofillAssistantTest() |
| 54 : message_loop_(), | 55 : message_loop_(), |
| 55 autofill_client_(), | 56 autofill_client_(), |
| 56 autofill_driver_(), | 57 autofill_driver_(), |
| 57 autofill_manager_(&autofill_driver_, &autofill_client_), | 58 autofill_manager_(&autofill_driver_, &autofill_client_), |
| 58 autofill_assistant_(&autofill_manager_) {} | 59 autofill_assistant_(&autofill_manager_) {} |
| 59 | 60 |
| 60 void EnableAutofillCreditCardAssist() { | 61 void EnableAutofillCreditCardAssist() { |
| 61 base::FeatureList::ClearInstanceForTesting(); | 62 scoped_feature_list_.InitAndEnableFeature(kAutofillCreditCardAssist); |
| 62 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
| 63 feature_list->InitializeFromCommandLine(kAutofillCreditCardAssist.name, | |
| 64 std::string()); | |
| 65 base::FeatureList::SetInstance(std::move(feature_list)); | |
| 66 } | 63 } |
| 67 | 64 |
| 68 // Returns an initialized FormStructure with credit card form data. To be | 65 // Returns an initialized FormStructure with credit card form data. To be |
| 69 // owned by the caller. | 66 // owned by the caller. |
| 70 std::unique_ptr<FormStructure> CreateValidCreditCardForm() { | 67 std::unique_ptr<FormStructure> CreateValidCreditCardForm() { |
| 71 std::unique_ptr<FormStructure> form_structure; | 68 std::unique_ptr<FormStructure> form_structure; |
| 72 FormData form; | 69 FormData form; |
| 73 | 70 |
| 74 FormFieldData field; | 71 FormFieldData field; |
| 75 field.form_control_type = "text"; | 72 field.form_control_type = "text"; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 98 form_structure->DetermineHeuristicTypes(); | 95 form_structure->DetermineHeuristicTypes(); |
| 99 | 96 |
| 100 return form_structure; | 97 return form_structure; |
| 101 } | 98 } |
| 102 | 99 |
| 103 base::MessageLoop message_loop_; | 100 base::MessageLoop message_loop_; |
| 104 TestAutofillClient autofill_client_; | 101 TestAutofillClient autofill_client_; |
| 105 testing::NiceMock<TestAutofillDriver> autofill_driver_; | 102 testing::NiceMock<TestAutofillDriver> autofill_driver_; |
| 106 MockAutofillManager autofill_manager_; | 103 MockAutofillManager autofill_manager_; |
| 107 AutofillAssistant autofill_assistant_; | 104 AutofillAssistant autofill_assistant_; |
| 105 base::test::ScopedFeatureList scoped_feature_list_; |
| 108 }; | 106 }; |
| 109 | 107 |
| 110 MATCHER_P(CreditCardMatches, guid, "") { | 108 MATCHER_P(CreditCardMatches, guid, "") { |
| 111 return arg.guid() == guid; | 109 return arg.guid() == guid; |
| 112 } | 110 } |
| 113 | 111 |
| 114 // If the feature is turned off, CanShowCreditCardAssist() always returns | 112 // If the feature is turned off, CanShowCreditCardAssist() always returns |
| 115 // false. | 113 // false. |
| 116 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOff) { | 114 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOff) { |
| 117 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); | 115 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // prompt. | 148 // prompt. |
| 151 EXPECT_CALL( | 149 EXPECT_CALL( |
| 152 autofill_manager_, | 150 autofill_manager_, |
| 153 FillCreditCardForm(kNoQueryId, _, _, CreditCardMatches(card.guid()), | 151 FillCreditCardForm(kNoQueryId, _, _, CreditCardMatches(card.guid()), |
| 154 /* empty cvc */ base::string16())); | 152 /* empty cvc */ base::string16())); |
| 155 | 153 |
| 156 autofill_assistant_.ShowAssistForCreditCard(card); | 154 autofill_assistant_.ShowAssistForCreditCard(card); |
| 157 } | 155 } |
| 158 | 156 |
| 159 } // namespace autofill | 157 } // namespace autofill |
| OLD | NEW |