Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Side by Side Diff: components/autofill/core/browser/autofill_assistant_unittest.cc

Issue 2432063003: [Autofill] Offer credit card suggestions for some form action. (Closed)
Patch Set: added a test Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 std::vector<std::unique_ptr<FormStructure>> form_structures; 139 std::vector<std::unique_ptr<FormStructure>> form_structures;
140 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); 140 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
141 141
142 // With valid input, the function extracts the credit card form properly. 142 // With valid input, the function extracts the credit card form properly.
143 form_structures.push_back(std::move(form_structure)); 143 form_structures.push_back(std::move(form_structure));
144 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); 144 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
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 vs insecure 148 // CanShowCreditCardAssist() behaves as expected for secure contexts.
149 // contexts. 149 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_Secure) {
150 EnableAutofillCreditCardAssist();
151
152 // Can be shown if the context is secure.
153 FormData form = CreateValidCreditCardFormData();
154 std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
155 form_structure->DetermineHeuristicTypes();
156
157 std::vector<std::unique_ptr<FormStructure>> form_structures;
158 form_structures.push_back(std::move(form_structure));
159 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
160 }
161
162 // Tests that with the feature enabled and proper input,
163 // CanShowCreditCardAssist() behaves as expected for insecure contexts.
150 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_NotSecure) { 164 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_NotSecure) {
151 EnableAutofillCreditCardAssist(); 165 EnableAutofillCreditCardAssist();
152 166
153 { 167 // Cannot be shown if the context is not secure.
154 // Cannot be shown if the context is not secure. 168 FormData form = CreateValidCreditCardFormData();
155 FormData form = CreateValidCreditCardFormData(); 169 form.origin = GURL("http://myform.com");
156 form.action = GURL("http://myform.com"); 170 form.action = GURL("http://myform.com/submit");
157 form.action = GURL("http://myform.com/submit"); 171 std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
158 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); 172 form_structure->DetermineHeuristicTypes();
159 form_structure->DetermineHeuristicTypes();
160 173
161 std::vector<std::unique_ptr<FormStructure>> form_structures; 174 std::vector<std::unique_ptr<FormStructure>> form_structures;
162 form_structures.push_back(std::move(form_structure)); 175 form_structures.push_back(std::move(form_structure));
163 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); 176 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
164 } 177 }
165 178
166 { 179 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_Javascript) {
167 // Can be shown if the context is secure. 180 EnableAutofillCreditCardAssist();
168 FormData form = CreateValidCreditCardFormData();
169 std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
170 form_structure->DetermineHeuristicTypes();
171 181
172 std::vector<std::unique_ptr<FormStructure>> form_structures; 182 // Can be shown if the context is secure and the form action is a javascript
173 form_structures.push_back(std::move(form_structure)); 183 // function (which is a valid url).
174 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); 184 FormData form = CreateValidCreditCardFormData();
175 } 185 form.action = GURL("javascript:alert('hello');");
186 std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
187 form_structure->DetermineHeuristicTypes();
188
189 std::vector<std::unique_ptr<FormStructure>> form_structures;
190 form_structures.push_back(std::move(form_structure));
191 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
192 }
193
194 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_WeirdJs) {
195 EnableAutofillCreditCardAssist();
196
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.
199 FormData form = CreateValidCreditCardFormData();
200 form.action = GURL("javascript:myFunc");
201 std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
202 form_structure->DetermineHeuristicTypes();
203
204 std::vector<std::unique_ptr<FormStructure>> form_structures;
205 form_structures.push_back(std::move(form_structure));
206 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
207 }
208
209 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_EmptyAction) {
210 EnableAutofillCreditCardAssist();
211
212 // Can be shown if the context is secure and the form action is empty.
213 FormData form = CreateValidCreditCardFormData();
214 form.action = GURL();
215 std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
216 form_structure->DetermineHeuristicTypes();
217
218 std::vector<std::unique_ptr<FormStructure>> form_structures;
219 form_structures.push_back(std::move(form_structure));
220 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
176 } 221 }
177 222
178 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_CancelCvc) { 223 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_CancelCvc) {
179 EnableAutofillCreditCardAssist(); 224 EnableAutofillCreditCardAssist();
180 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); 225 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm();
181 226
182 // Will extract the credit card form data. 227 // Will extract the credit card form data.
183 std::vector<std::unique_ptr<FormStructure>> form_structures; 228 std::vector<std::unique_ptr<FormStructure>> form_structures;
184 form_structures.push_back(std::move(form_structure)); 229 form_structures.push_back(std::move(form_structure));
185 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); 230 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 autofill_assistant_.ShowAssistForCreditCard(card); 265 autofill_assistant_.ShowAssistForCreditCard(card);
221 266
222 CardUnmaskDelegate::UnmaskResponse unmask_response; 267 CardUnmaskDelegate::UnmaskResponse unmask_response;
223 unmask_response.cvc = base::ASCIIToUTF16("123"); 268 unmask_response.cvc = base::ASCIIToUTF16("123");
224 static_cast<CardUnmaskDelegate*>( 269 static_cast<CardUnmaskDelegate*>(
225 autofill_manager_.GetOrCreateFullCardRequest()) 270 autofill_manager_.GetOrCreateFullCardRequest())
226 ->OnUnmaskResponse(unmask_response); 271 ->OnUnmaskResponse(unmask_response);
227 } 272 }
228 273
229 } // namespace autofill 274 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_assistant.cc ('k') | components/autofill/core/browser/autofill_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698