| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 form.fields.push_back(field); | 96 form.fields.push_back(field); |
| 97 | 97 |
| 98 return form; | 98 return form; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Returns an initialized FormStructure with credit card form data. To be | 101 // Returns an initialized FormStructure with credit card form data. To be |
| 102 // owned by the caller. | 102 // owned by the caller. |
| 103 std::unique_ptr<FormStructure> CreateValidCreditCardForm() { | 103 std::unique_ptr<FormStructure> CreateValidCreditCardForm() { |
| 104 std::unique_ptr<FormStructure> form_structure; | 104 std::unique_ptr<FormStructure> form_structure; |
| 105 form_structure.reset(new FormStructure(CreateValidCreditCardFormData())); | 105 form_structure.reset(new FormStructure(CreateValidCreditCardFormData())); |
| 106 form_structure->DetermineHeuristicTypes(); | 106 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 107 return form_structure; | 107 return form_structure; |
| 108 } | 108 } |
| 109 | 109 |
| 110 base::MessageLoop message_loop_; | 110 base::MessageLoop message_loop_; |
| 111 TestAutofillClient autofill_client_; | 111 TestAutofillClient autofill_client_; |
| 112 testing::NiceMock<TestAutofillDriver> autofill_driver_; | 112 testing::NiceMock<TestAutofillDriver> autofill_driver_; |
| 113 TestPersonalDataManager pdm_; | 113 TestPersonalDataManager pdm_; |
| 114 MockAutofillManager autofill_manager_; | 114 MockAutofillManager autofill_manager_; |
| 115 AutofillAssistant autofill_assistant_; | 115 AutofillAssistant autofill_assistant_; |
| 116 base::test::ScopedFeatureList scoped_feature_list_; | 116 base::test::ScopedFeatureList scoped_feature_list_; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 145 } | 145 } |
| 146 | 146 |
| 147 // Tests that with the feature enabled and proper input, | 147 // Tests that with the feature enabled and proper input, |
| 148 // CanShowCreditCardAssist() behaves as expected for secure contexts. | 148 // CanShowCreditCardAssist() behaves as expected for secure contexts. |
| 149 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_Secure) { | 149 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_Secure) { |
| 150 EnableAutofillCreditCardAssist(); | 150 EnableAutofillCreditCardAssist(); |
| 151 | 151 |
| 152 // Can be shown if the context is secure. | 152 // Can be shown if the context is secure. |
| 153 FormData form = CreateValidCreditCardFormData(); | 153 FormData form = CreateValidCreditCardFormData(); |
| 154 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); | 154 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); |
| 155 form_structure->DetermineHeuristicTypes(); | 155 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 156 | 156 |
| 157 std::vector<std::unique_ptr<FormStructure>> form_structures; | 157 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 158 form_structures.push_back(std::move(form_structure)); | 158 form_structures.push_back(std::move(form_structure)); |
| 159 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 159 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // Tests that with the feature enabled and proper input, | 162 // Tests that with the feature enabled and proper input, |
| 163 // CanShowCreditCardAssist() behaves as expected for insecure contexts. | 163 // CanShowCreditCardAssist() behaves as expected for insecure contexts. |
| 164 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_NotSecure) { | 164 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_NotSecure) { |
| 165 EnableAutofillCreditCardAssist(); | 165 EnableAutofillCreditCardAssist(); |
| 166 | 166 |
| 167 // Cannot be shown if the context is not secure. | 167 // Cannot be shown if the context is not secure. |
| 168 FormData form = CreateValidCreditCardFormData(); | 168 FormData form = CreateValidCreditCardFormData(); |
| 169 form.origin = GURL("http://myform.com"); | 169 form.origin = GURL("http://myform.com"); |
| 170 form.action = GURL("http://myform.com/submit"); | 170 form.action = GURL("http://myform.com/submit"); |
| 171 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); | 171 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); |
| 172 form_structure->DetermineHeuristicTypes(); | 172 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 173 | 173 |
| 174 std::vector<std::unique_ptr<FormStructure>> form_structures; | 174 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 175 form_structures.push_back(std::move(form_structure)); | 175 form_structures.push_back(std::move(form_structure)); |
| 176 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 176 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 177 } | 177 } |
| 178 | 178 |
| 179 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_Javascript) { | 179 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_Javascript) { |
| 180 EnableAutofillCreditCardAssist(); | 180 EnableAutofillCreditCardAssist(); |
| 181 | 181 |
| 182 // Can be shown if the context is secure and the form action is a javascript | 182 // Can be shown if the context is secure and the form action is a javascript |
| 183 // function (which is a valid url). | 183 // function (which is a valid url). |
| 184 FormData form = CreateValidCreditCardFormData(); | 184 FormData form = CreateValidCreditCardFormData(); |
| 185 form.action = GURL("javascript:alert('hello');"); | 185 form.action = GURL("javascript:alert('hello');"); |
| 186 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); | 186 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); |
| 187 form_structure->DetermineHeuristicTypes(); | 187 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 188 | 188 |
| 189 std::vector<std::unique_ptr<FormStructure>> form_structures; | 189 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 190 form_structures.push_back(std::move(form_structure)); | 190 form_structures.push_back(std::move(form_structure)); |
| 191 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 191 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_WeirdJs) { | 194 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_WeirdJs) { |
| 195 EnableAutofillCreditCardAssist(); | 195 EnableAutofillCreditCardAssist(); |
| 196 | 196 |
| 197 // Can be shown if the context is secure and the form action is a javascript | 197 // Can be shown if the context is secure and the form action is a javascript |
| 198 // function that may or may not be valid. | 198 // function that may or may not be valid. |
| 199 FormData form = CreateValidCreditCardFormData(); | 199 FormData form = CreateValidCreditCardFormData(); |
| 200 form.action = GURL("javascript:myFunc"); | 200 form.action = GURL("javascript:myFunc"); |
| 201 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); | 201 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); |
| 202 form_structure->DetermineHeuristicTypes(); | 202 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 203 | 203 |
| 204 std::vector<std::unique_ptr<FormStructure>> form_structures; | 204 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 205 form_structures.push_back(std::move(form_structure)); | 205 form_structures.push_back(std::move(form_structure)); |
| 206 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 206 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 207 } | 207 } |
| 208 | 208 |
| 209 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_EmptyAction) { | 209 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_EmptyAction) { |
| 210 EnableAutofillCreditCardAssist(); | 210 EnableAutofillCreditCardAssist(); |
| 211 | 211 |
| 212 // Can be shown if the context is secure and the form action is empty. | 212 // Can be shown if the context is secure and the form action is empty. |
| 213 FormData form = CreateValidCreditCardFormData(); | 213 FormData form = CreateValidCreditCardFormData(); |
| 214 form.action = GURL(); | 214 form.action = GURL(); |
| 215 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); | 215 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); |
| 216 form_structure->DetermineHeuristicTypes(); | 216 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 217 | 217 |
| 218 std::vector<std::unique_ptr<FormStructure>> form_structures; | 218 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 219 form_structures.push_back(std::move(form_structure)); | 219 form_structures.push_back(std::move(form_structure)); |
| 220 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 220 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_CancelCvc) { | 223 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_CancelCvc) { |
| 224 EnableAutofillCreditCardAssist(); | 224 EnableAutofillCreditCardAssist(); |
| 225 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); | 225 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); |
| 226 | 226 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 autofill_assistant_.ShowAssistForCreditCard(card); | 265 autofill_assistant_.ShowAssistForCreditCard(card); |
| 266 | 266 |
| 267 CardUnmaskDelegate::UnmaskResponse unmask_response; | 267 CardUnmaskDelegate::UnmaskResponse unmask_response; |
| 268 unmask_response.cvc = base::ASCIIToUTF16("123"); | 268 unmask_response.cvc = base::ASCIIToUTF16("123"); |
| 269 static_cast<CardUnmaskDelegate*>( | 269 static_cast<CardUnmaskDelegate*>( |
| 270 autofill_manager_.GetOrCreateFullCardRequest()) | 270 autofill_manager_.GetOrCreateFullCardRequest()) |
| 271 ->OnUnmaskResponse(unmask_response); | 271 ->OnUnmaskResponse(unmask_response); |
| 272 } | 272 } |
| 273 | 273 |
| 274 } // namespace autofill | 274 } // namespace autofill |
| OLD | NEW |