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

Unified Diff: components/autofill/core/browser/autofill_field_unittest.cc

Issue 1473733008: [Autofill] Respect the autocomplete=off attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years 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_field_unittest.cc
diff --git a/components/autofill/core/browser/autofill_field_unittest.cc b/components/autofill/core/browser/autofill_field_unittest.cc
index c65daaa811105800646e3a308bb148d27436580f..46009a20ae947a7912012edf3dc7c7110c647bfe 100644
--- a/components/autofill/core/browser/autofill_field_unittest.cc
+++ b/components/autofill/core/browser/autofill_field_unittest.cc
@@ -9,6 +9,7 @@
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/field_types.h"
+#include "components/autofill/core/common/autofill_util.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::ASCIIToUTF16;
@@ -129,11 +130,45 @@ TEST(AutofillFieldTest, IsFieldFillable) {
field.set_server_type(NAME_LAST);
EXPECT_TRUE(field.IsFieldFillable());
- // Field has autocomplete="off" set. Chrome ignores the attribute.
+ // Field has autocomplete="off" set. Since autofill was able to make a
+ // prediction, it is still considered a fillable field.
field.should_autocomplete = false;
EXPECT_TRUE(field.IsFieldFillable());
}
+// Verify that non credit card related fields with the autocomplete attribute
+// set to off don't get filled on desktop.
+TEST(AutofillFieldTest, FillFormField_AutocompleteOff_AddressField) {
+ AutofillField field;
+ field.should_autocomplete = false;
+
+ // Non credit card related field.
+ AutofillField::FillFormField(field, ASCIIToUTF16("Test"), "en-US", "en-US",
+ &field);
+
+ // Verifiy that the field is filled on mobile but not on desktop.
+ if (IsDesktopPlatform()) {
+ EXPECT_EQ(base::string16(), field.value);
+ } else {
+ EXPECT_EQ(ASCIIToUTF16("Test"), field.value);
+ }
+}
+
+// Verify that credit card related fields with the autocomplete attribute
+// set to off get filled.
+TEST(AutofillFieldTest, FillFormField_AutocompleteOff_CreditCardField) {
+ AutofillField field;
+ field.should_autocomplete = false;
+
+ // Credit card related field.
+ field.set_heuristic_type(CREDIT_CARD_NUMBER);
+ AutofillField::FillFormField(field, ASCIIToUTF16("4111111111111111"), "en-US",
+ "en-US", &field);
+
+ // Verify that the field is filled.
+ EXPECT_EQ(ASCIIToUTF16("4111111111111111"), field.value);
+}
+
TEST(AutofillFieldTest, FillPhoneNumber) {
AutofillField field;
field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode());
« no previous file with comments | « components/autofill/core/browser/autofill_field.cc ('k') | components/autofill/core/browser/autofill_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698