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

Side by Side Diff: components/autofill/core/common/form_data_unittest.cc

Issue 1671753004: [Autofill] Fill fields that have an autocomplete attributes even if not in a form. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added IPC Trait for new attribute Created 4 years, 10 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/common/form_data.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/common/form_data.h" 5 #include "components/autofill/core/common/form_data.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/pickle.h" 9 #include "base/pickle.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 pickle->WriteString16(form_data.name); 66 pickle->WriteString16(form_data.name);
67 pickle->WriteString(form_data.origin.spec()); 67 pickle->WriteString(form_data.origin.spec());
68 pickle->WriteString(form_data.action.spec()); 68 pickle->WriteString(form_data.action.spec());
69 pickle->WriteInt(static_cast<int>(form_data.fields.size())); 69 pickle->WriteInt(static_cast<int>(form_data.fields.size()));
70 for (size_t i = 0; i < form_data.fields.size(); ++i) { 70 for (size_t i = 0; i < form_data.fields.size(); ++i) {
71 SerializeFormFieldData(form_data.fields[i], pickle); 71 SerializeFormFieldData(form_data.fields[i], pickle);
72 } 72 }
73 pickle->WriteBool(form_data.is_form_tag); 73 pickle->WriteBool(form_data.is_form_tag);
74 } 74 }
75 75
76 void SerializeInVersion5Format(const FormData& form_data,
77 base::Pickle* pickle) {
78 pickle->WriteInt(5);
79 pickle->WriteString16(form_data.name);
80 pickle->WriteString(form_data.origin.spec());
81 pickle->WriteString(form_data.action.spec());
82 pickle->WriteInt(static_cast<int>(form_data.fields.size()));
83 for (size_t i = 0; i < form_data.fields.size(); ++i) {
84 SerializeFormFieldData(form_data.fields[i], pickle);
85 }
86 pickle->WriteBool(form_data.is_form_tag);
87 pickle->WriteBool(form_data.is_formless_checkout);
88 }
89
76 // This function serializes the form data into the pickle in incorrect format 90 // This function serializes the form data into the pickle in incorrect format
77 // (no version number). 91 // (no version number).
78 void SerializeIncorrectFormat(const FormData& form_data, base::Pickle* pickle) { 92 void SerializeIncorrectFormat(const FormData& form_data, base::Pickle* pickle) {
79 pickle->WriteString16(form_data.name); 93 pickle->WriteString16(form_data.name);
80 pickle->WriteString(form_data.origin.spec()); 94 pickle->WriteString(form_data.origin.spec());
81 pickle->WriteString(form_data.action.spec()); 95 pickle->WriteString(form_data.action.spec());
82 pickle->WriteBool(true); // Used to be |user_submitted|, which was removed. 96 pickle->WriteBool(true); // Used to be |user_submitted|, which was removed.
83 pickle->WriteInt(static_cast<int>(form_data.fields.size())); 97 pickle->WriteInt(static_cast<int>(form_data.fields.size()));
84 for (size_t i = 0; i < form_data.fields.size(); ++i) { 98 for (size_t i = 0; i < form_data.fields.size(); ++i) {
85 SerializeFormFieldData(form_data.fields[i], pickle); 99 SerializeFormFieldData(form_data.fields[i], pickle);
86 } 100 }
87 } 101 }
88 102
89 void FillInDummyFormData(FormData* data) { 103 void FillInDummyFormData(FormData* data) {
90 data->name = base::ASCIIToUTF16("name"); 104 data->name = base::ASCIIToUTF16("name");
91 data->origin = GURL("origin"); 105 data->origin = GURL("origin");
92 data->action = GURL("action"); 106 data->action = GURL("action");
93 data->is_form_tag = true; // Default value. 107 data->is_form_tag = true; // Default value.
108 data->is_formless_checkout = false; // Default value.
94 109
95 FormFieldData field_data; 110 FormFieldData field_data;
96 field_data.label = base::ASCIIToUTF16("label"); 111 field_data.label = base::ASCIIToUTF16("label");
97 field_data.name = base::ASCIIToUTF16("name"); 112 field_data.name = base::ASCIIToUTF16("name");
98 field_data.value = base::ASCIIToUTF16("value"); 113 field_data.value = base::ASCIIToUTF16("value");
99 field_data.form_control_type = "password"; 114 field_data.form_control_type = "password";
100 field_data.autocomplete_attribute = "off"; 115 field_data.autocomplete_attribute = "off";
101 field_data.max_length = 200; 116 field_data.max_length = 200;
102 field_data.is_autofilled = true; 117 field_data.is_autofilled = true;
103 field_data.is_checked = true; 118 field_data.is_checked = true;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 base::Pickle pickle; 228 base::Pickle pickle;
214 SerializeInVersion4Format(data, &pickle); 229 SerializeInVersion4Format(data, &pickle);
215 230
216 base::PickleIterator iter(pickle); 231 base::PickleIterator iter(pickle);
217 FormData actual; 232 FormData actual;
218 EXPECT_TRUE(DeserializeFormData(&iter, &actual)); 233 EXPECT_TRUE(DeserializeFormData(&iter, &actual));
219 234
220 EXPECT_TRUE(actual.SameFormAs(data)); 235 EXPECT_TRUE(actual.SameFormAs(data));
221 } 236 }
222 237
238 TEST(FormDataTest, Serialize_v5_Deserialize_vCurrent) {
239 FormData data;
240 FillInDummyFormData(&data);
241 data.is_formless_checkout = true;
242
243 base::Pickle pickle;
244 SerializeInVersion5Format(data, &pickle);
245
246 base::PickleIterator iter(pickle);
247 FormData actual;
248 EXPECT_TRUE(DeserializeFormData(&iter, &actual));
249
250 EXPECT_TRUE(actual.SameFormAs(data));
251 }
252
223 TEST(FormDataTest, SerializeIncorrectFormatAndDeserialize) { 253 TEST(FormDataTest, SerializeIncorrectFormatAndDeserialize) {
224 FormData data; 254 FormData data;
225 FillInDummyFormData(&data); 255 FillInDummyFormData(&data);
226 256
227 base::Pickle pickle; 257 base::Pickle pickle;
228 SerializeIncorrectFormat(data, &pickle); 258 SerializeIncorrectFormat(data, &pickle);
229 259
230 base::PickleIterator iter(pickle); 260 base::PickleIterator iter(pickle);
231 FormData actual; 261 FormData actual;
232 EXPECT_FALSE(DeserializeFormData(&iter, &actual)); 262 EXPECT_FALSE(DeserializeFormData(&iter, &actual));
233 263
234 FormData empty; 264 FormData empty;
235 EXPECT_TRUE(actual.SameFormAs(empty)); 265 EXPECT_TRUE(actual.SameFormAs(empty));
236 } 266 }
237 267
238 } // namespace autofill 268 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/common/form_data.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698