Chromium Code Reviews| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_EmptyAction) { | |
| 195 EnableAutofillCreditCardAssist(); | |
| 196 | |
| 197 // Can be shown if the context is secure and the form action is empty. | |
| 198 FormData form = CreateValidCreditCardFormData(); | |
| 199 form.action = GURL(); | |
| 200 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); | |
| 201 form_structure->DetermineHeuristicTypes(); | |
| 202 | |
| 203 std::vector<std::unique_ptr<FormStructure>> form_structures; | |
| 204 form_structures.push_back(std::move(form_structure)); | |
| 205 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | |
| 176 } | 206 } |
|
sebsg
2016/10/21 19:10:55
Can you add one more test where the js function is
Mathieu
2016/10/21 20:53:59
Done.
| |
| 177 | 207 |
| 178 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_CancelCvc) { | 208 TEST_F(AutofillAssistantTest, ShowAssistForCreditCard_ValidCard_CancelCvc) { |
| 179 EnableAutofillCreditCardAssist(); | 209 EnableAutofillCreditCardAssist(); |
| 180 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); | 210 std::unique_ptr<FormStructure> form_structure = CreateValidCreditCardForm(); |
| 181 | 211 |
| 182 // Will extract the credit card form data. | 212 // Will extract the credit card form data. |
| 183 std::vector<std::unique_ptr<FormStructure>> form_structures; | 213 std::vector<std::unique_ptr<FormStructure>> form_structures; |
| 184 form_structures.push_back(std::move(form_structure)); | 214 form_structures.push_back(std::move(form_structure)); |
| 185 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); | 215 EXPECT_TRUE(autofill_assistant_.CanShowCreditCardAssist(form_structures)); |
| 186 | 216 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 autofill_assistant_.ShowAssistForCreditCard(card); | 250 autofill_assistant_.ShowAssistForCreditCard(card); |
| 221 | 251 |
| 222 CardUnmaskDelegate::UnmaskResponse unmask_response; | 252 CardUnmaskDelegate::UnmaskResponse unmask_response; |
| 223 unmask_response.cvc = base::ASCIIToUTF16("123"); | 253 unmask_response.cvc = base::ASCIIToUTF16("123"); |
| 224 static_cast<CardUnmaskDelegate*>( | 254 static_cast<CardUnmaskDelegate*>( |
| 225 autofill_manager_.GetOrCreateFullCardRequest()) | 255 autofill_manager_.GetOrCreateFullCardRequest()) |
| 226 ->OnUnmaskResponse(unmask_response); | 256 ->OnUnmaskResponse(unmask_response); |
| 227 } | 257 } |
| 228 | 258 |
| 229 } // namespace autofill | 259 } // namespace autofill |
| OLD | NEW |