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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/autofill_assistant_unittest.cc
diff --git a/components/autofill/core/browser/autofill_assistant_unittest.cc b/components/autofill/core/browser/autofill_assistant_unittest.cc
index 4e972773b1628d119ffc05f133105a0a4cf4a4d1..3364c6f92fd2eeefe8476afe40710f1872f917e0 100644
--- a/components/autofill/core/browser/autofill_assistant_unittest.cc
+++ b/components/autofill/core/browser/autofill_assistant_unittest.cc
@@ -145,34 +145,79 @@ TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn) {
}
// Tests that with the feature enabled and proper input,
-// CanShowCreditCardAssist() behaves as expected for secure vs insecure
-// contexts.
+// CanShowCreditCardAssist() behaves as expected for secure contexts.
+TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_Secure) {
+ EnableAutofillCreditCardAssist();
+
+ // Can be shown if the context is secure.
+ FormData form = CreateValidCreditCardFormData();
+ std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
+ form_structure->DetermineHeuristicTypes();
+
+ std::vector<std::unique_ptr<FormStructure>> form_structures;
+ form_structures.push_back(std::move(form_structure));
+ EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
+}
+
+// Tests that with the feature enabled and proper input,
+// CanShowCreditCardAssist() behaves as expected for insecure contexts.
TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_NotSecure) {
EnableAutofillCreditCardAssist();
- {
- // Cannot be shown if the context is not secure.
- FormData form = CreateValidCreditCardFormData();
- form.action = GURL("http://myform.com");
- form.action = GURL("http://myform.com/submit");
- std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
- form_structure->DetermineHeuristicTypes();
+ // Cannot be shown if the context is not secure.
+ FormData form = CreateValidCreditCardFormData();
+ form.origin = GURL("http://myform.com");
+ form.action = GURL("http://myform.com/submit");
+ std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
+ form_structure->DetermineHeuristicTypes();
- std::vector<std::unique_ptr<FormStructure>> form_structures;
- form_structures.push_back(std::move(form_structure));
- EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
- }
+ std::vector<std::unique_ptr<FormStructure>> form_structures;
+ form_structures.push_back(std::move(form_structure));
+ EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
+}
- {
- // Can be shown if the context is secure.
- FormData form = CreateValidCreditCardFormData();
- std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
- form_structure->DetermineHeuristicTypes();
+TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_Javascript) {
+ EnableAutofillCreditCardAssist();
- std::vector<std::unique_ptr<FormStructure>> form_structures;
- form_structures.push_back(std::move(form_structure));
- EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
- }
+ // Can be shown if the context is secure and the form action is a javascript
+ // function (which is a valid url).
+ FormData form = CreateValidCreditCardFormData();
+ form.action = GURL("javascript:alert('hello');");
+ std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
+ form_structure->DetermineHeuristicTypes();
+
+ std::vector<std::unique_ptr<FormStructure>> form_structures;
+ form_structures.push_back(std::move(form_structure));
+ EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
+}
+
+TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_WeirdJs) {
+ EnableAutofillCreditCardAssist();
+
+ // Can be shown if the context is secure and the form action is a javascript
+ // function that may or may not be valid.
+ FormData form = CreateValidCreditCardFormData();
+ form.action = GURL("javascript:myFunc");
+ std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
+ form_structure->DetermineHeuristicTypes();
+
+ std::vector<std::unique_ptr<FormStructure>> form_structures;
+ form_structures.push_back(std::move(form_structure));
+ EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
+}
+
+TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_EmptyAction) {
+ EnableAutofillCreditCardAssist();
+
+ // Can be shown if the context is secure and the form action is empty.
+ FormData form = CreateValidCreditCardFormData();
+ form.action = GURL();
+ std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
+ form_structure->DetermineHeuristicTypes();
+
+ std::vector<std::unique_ptr<FormStructure>> form_structures;
+ form_structures.push_back(std::move(form_structure));
+ EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
}
TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_CancelCvc) {
« 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