OLD | NEW |
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 "base/pickle.h" | 7 #include "base/pickle.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "components/autofill/core/common/form_field_data.h" | 9 #include "components/autofill/core/common/form_field_data.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 // This function serializes the form data into the pickle in version one format. | 14 // This function serializes the form data into the pickle in version one format. |
15 // It should always be possible to deserialize it using DeserializeFormData(), | 15 // It should always be possible to deserialize it using DeserializeFormData(), |
16 // even when version changes. See kPickleVersion in form_data.cc. | 16 // even when version changes. See kPickleVersion in form_data.cc. |
17 void SerializeInVersion1Format(const autofill::FormData& form_data, | 17 void SerializeInVersion1Format(const autofill::FormData& form_data, |
18 Pickle* pickle) { | 18 Pickle* pickle) { |
19 pickle->WriteInt(1); | 19 pickle->WriteInt(1); |
20 pickle->WriteString16(form_data.name); | 20 pickle->WriteString16(form_data.name); |
21 base::string16 method(base::ASCIIToUTF16("POST")); | 21 base::string16 method(base::ASCIIToUTF16("POST")); |
22 pickle->WriteString16(method); | 22 pickle->WriteString16(method); |
23 pickle->WriteString(form_data.origin.spec()); | 23 pickle->WriteString(form_data.origin.spec()); |
24 pickle->WriteString(form_data.action.spec()); | 24 pickle->WriteString(form_data.action.spec()); |
25 pickle->WriteBool(form_data.user_submitted); | 25 pickle->WriteBool(form_data.user_submitted); |
| 26 SerializeFormFieldData(form_data.username, pickle); |
| 27 SerializeFormFieldData(form_data.password, pickle); |
26 pickle->WriteInt(static_cast<int>(form_data.fields.size())); | 28 pickle->WriteInt(static_cast<int>(form_data.fields.size())); |
27 for (size_t i = 0; i < form_data.fields.size(); ++i) { | 29 for (size_t i = 0; i < form_data.fields.size(); ++i) { |
28 SerializeFormFieldData(form_data.fields[i], pickle); | 30 SerializeFormFieldData(form_data.fields[i], pickle); |
29 } | 31 } |
30 } | 32 } |
31 | 33 |
32 // This function serializes the form data into the pickle in incorrect format | 34 // This function serializes the form data into the pickle in incorrect format |
33 // (no version number). | 35 // (no version number). |
34 void SerializeIncorrectFormat(const autofill::FormData& form_data, | 36 void SerializeIncorrectFormat(const autofill::FormData& form_data, |
35 Pickle* pickle) { | 37 Pickle* pickle) { |
36 pickle->WriteString16(form_data.name); | 38 pickle->WriteString16(form_data.name); |
37 pickle->WriteString(form_data.origin.spec()); | 39 pickle->WriteString(form_data.origin.spec()); |
38 pickle->WriteString(form_data.action.spec()); | 40 pickle->WriteString(form_data.action.spec()); |
39 pickle->WriteBool(form_data.user_submitted); | 41 pickle->WriteBool(form_data.user_submitted); |
| 42 SerializeFormFieldData(form_data.username, pickle); |
| 43 SerializeFormFieldData(form_data.password, pickle); |
40 pickle->WriteInt(static_cast<int>(form_data.fields.size())); | 44 pickle->WriteInt(static_cast<int>(form_data.fields.size())); |
41 for (size_t i = 0; i < form_data.fields.size(); ++i) { | 45 for (size_t i = 0; i < form_data.fields.size(); ++i) { |
42 SerializeFormFieldData(form_data.fields[i], pickle); | 46 SerializeFormFieldData(form_data.fields[i], pickle); |
43 } | 47 } |
44 } | 48 } |
45 | 49 |
46 } | 50 } |
47 | 51 |
48 namespace autofill { | 52 namespace autofill { |
49 | 53 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 172 |
169 Pickle pickle; | 173 Pickle pickle; |
170 SerializeIncorrectFormat(data, &pickle); | 174 SerializeIncorrectFormat(data, &pickle); |
171 | 175 |
172 PickleIterator iter(pickle); | 176 PickleIterator iter(pickle); |
173 FormData actual; | 177 FormData actual; |
174 EXPECT_FALSE(DeserializeFormData(&iter, &actual)); | 178 EXPECT_FALSE(DeserializeFormData(&iter, &actual)); |
175 } | 179 } |
176 | 180 |
177 } // namespace autofill | 181 } // namespace autofill |
OLD | NEW |