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

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

Issue 2253343003: Only show the credit card assist feature in secure contexts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove redudant comments Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « components/autofill/core/browser/autofill_assistant.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 protected: 53 protected:
54 AutofillAssistantTest() 54 AutofillAssistantTest()
55 : message_loop_(), 55 : message_loop_(),
56 autofill_client_(), 56 autofill_client_(),
57 autofill_driver_(), 57 autofill_driver_(),
58 autofill_manager_(&autofill_driver_, &autofill_client_), 58 autofill_manager_(&autofill_driver_, &autofill_client_),
59 autofill_assistant_(&autofill_manager_) {} 59 autofill_assistant_(&autofill_manager_) {}
60 60
61 void EnableAutofillCreditCardAssist() { 61 void EnableAutofillCreditCardAssist() {
62 scoped_feature_list_.InitAndEnableFeature(kAutofillCreditCardAssist); 62 scoped_feature_list_.InitAndEnableFeature(kAutofillCreditCardAssist);
63 autofill_client_.set_is_context_secure(true);
63 } 64 }
64 65
65 // Returns an initialized FormStructure with credit card form data. To be 66 // Returns an initialized FormStructure with credit card form data. To be
66 // owned by the caller. 67 // owned by the caller.
67 std::unique_ptr<FormStructure> CreateValidCreditCardForm() { 68 std::unique_ptr<FormStructure> CreateValidCreditCardForm() {
68 std::unique_ptr<FormStructure> form_structure; 69 std::unique_ptr<FormStructure> form_structure;
69 FormData form; 70 FormData form;
70 71
71 FormFieldData field; 72 FormFieldData field;
72 field.form_control_type = "text"; 73 field.form_control_type = "text";
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); 126 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm();
126 127
127 std::vector<FormStructure*> form_structures; 128 std::vector<FormStructure*> form_structures;
128 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); 129 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
129 130
130 // With valid input, the function extracts the credit card form properly. 131 // With valid input, the function extracts the credit card form properly.
131 form_structures.push_back(form_structure.get()); 132 form_structures.push_back(form_structure.get());
132 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); 133 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
133 } 134 }
134 135
136 // Tests that with the feature enabled and proper input,
137 // CanShowCreditCardAssist() behaves as expected for secure vs insecure
138 // contexts.
139 TEST_F(AutofillAssistantTest, CanShowCreditCardAssist_FeatureOn_NotSecure) {
140 EnableAutofillCreditCardAssist();
141 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm();
142 std::vector<FormStructure*> form_structures;
143 form_structures.push_back(form_structure.get());
144
145 // Cannot be shown if the context is not secure.
146 autofill_client_.set_is_context_secure(false);
147 EXPECT_FALSE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
148
149 // Can be shown if the context is secure.
150 autofill_client_.set_is_context_secure(true);
151 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
152 }
153
135 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard) { 154 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard) {
136 EnableAutofillCreditCardAssist(); 155 EnableAutofillCreditCardAssist();
137 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); 156 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm();
138 157
139 // Will extract the credit card form data. 158 // Will extract the credit card form data.
140 std::vector<FormStructure*> form_structures{form_structure.get()}; 159 std::vector<FormStructure*> form_structures{form_structure.get()};
141 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); 160 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures));
142 161
143 // Create a valid card for the assist. 162 // Create a valid card for the assist.
144 CreditCard card; 163 CreditCard card;
145 test::SetCreditCardInfo(&card, "John Doe", "4111111111111111", "05", "2999"); 164 test::SetCreditCardInfo(&card, "John Doe", "4111111111111111", "05", "2999");
146 165
147 // FillCreditCardForm ends up being called after user has accepted the 166 // FillCreditCardForm ends up being called after user has accepted the
148 // prompt. 167 // prompt.
149 EXPECT_CALL( 168 EXPECT_CALL(
150 autofill_manager_, 169 autofill_manager_,
151 FillCreditCardForm(kNoQueryId, _, _, CreditCardMatches(card.guid()), 170 FillCreditCardForm(kNoQueryId, _, _, CreditCardMatches(card.guid()),
152 /* empty cvc */ base::string16())); 171 /* empty cvc */ base::string16()));
153 172
154 autofill_assistant_.ShowAssistForCreditCard(card); 173 autofill_assistant_.ShowAssistForCreditCard(card);
155 } 174 }
156 175
157 } // namespace autofill 176 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_assistant.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698