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 "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
12 namespace { | |
13 | |
14 void SerializeFormData_v1(const autofill::FormData& form_data, Pickle* pickle) { | |
Ilya Sherman
2014/08/18 21:05:45
nit: Please name this something more like "Seriali
Ilya Sherman
2014/08/18 21:05:46
nit: Please document this function.
| |
15 pickle->WriteInt(1); | |
16 pickle->WriteString16(form_data.name); | |
17 base::string16 method(base::ASCIIToUTF16("POST")); | |
18 pickle->WriteString16(method); | |
19 pickle->WriteString(form_data.origin.spec()); | |
20 pickle->WriteString(form_data.action.spec()); | |
21 pickle->WriteBool(form_data.user_submitted); | |
22 pickle->WriteInt(static_cast<int>(form_data.fields.size())); | |
23 for (size_t i = 0; i < form_data.fields.size(); ++i) { | |
24 SerializeFormFieldData(form_data.fields[i], pickle); | |
25 } | |
26 } | |
Ilya Sherman
2014/08/18 21:05:46
nit: Please leave a blank line after this one.
| |
27 } | |
28 | |
11 namespace autofill { | 29 namespace autofill { |
12 | 30 |
13 TEST(FormDataTest, SerializeAndDeserialize) { | 31 TEST(FormDataTest, SerializeAndDeserialize) { |
14 FormData data; | 32 FormData data; |
15 data.name = base::ASCIIToUTF16("name"); | 33 data.name = base::ASCIIToUTF16("name"); |
16 data.origin = GURL("origin"); | 34 data.origin = GURL("origin"); |
17 data.action = GURL("action"); | 35 data.action = GURL("action"); |
18 data.user_submitted = true; | 36 data.user_submitted = true; |
19 | 37 |
20 FormFieldData field_data; | 38 FormFieldData field_data; |
(...skipping 25 matching lines...) Expand all Loading... | |
46 Pickle pickle; | 64 Pickle pickle; |
47 SerializeFormData(data, &pickle); | 65 SerializeFormData(data, &pickle); |
48 | 66 |
49 PickleIterator iter(pickle); | 67 PickleIterator iter(pickle); |
50 FormData actual; | 68 FormData actual; |
51 EXPECT_TRUE(DeserializeFormData(&iter, &actual)); | 69 EXPECT_TRUE(DeserializeFormData(&iter, &actual)); |
52 | 70 |
53 EXPECT_EQ(actual, data); | 71 EXPECT_EQ(actual, data); |
54 } | 72 } |
55 | 73 |
74 TEST(FormDataTest, Serialize_v1_Deserialize_vCurrent) { | |
75 FormData data; | |
76 data.name = base::ASCIIToUTF16("name"); | |
77 data.origin = GURL("origin"); | |
78 data.action = GURL("action"); | |
79 data.user_submitted = true; | |
80 | |
81 FormFieldData field_data; | |
82 field_data.label = base::ASCIIToUTF16("label"); | |
83 field_data.name = base::ASCIIToUTF16("name"); | |
84 field_data.value = base::ASCIIToUTF16("value"); | |
85 field_data.form_control_type = "password"; | |
86 field_data.autocomplete_attribute = "off"; | |
87 field_data.max_length = 200; | |
88 field_data.is_autofilled = true; | |
89 field_data.is_checked = true; | |
90 field_data.is_checkable = true; | |
91 field_data.is_focusable = true; | |
92 field_data.should_autocomplete = false; | |
93 field_data.text_direction = base::i18n::RIGHT_TO_LEFT; | |
94 field_data.option_values.push_back(base::ASCIIToUTF16("First")); | |
95 field_data.option_values.push_back(base::ASCIIToUTF16("Second")); | |
96 field_data.option_contents.push_back(base::ASCIIToUTF16("First")); | |
97 field_data.option_contents.push_back(base::ASCIIToUTF16("Second")); | |
98 | |
99 data.fields.push_back(field_data); | |
100 | |
101 // Change a few fields. | |
102 field_data.max_length = 150; | |
103 field_data.option_values.push_back(base::ASCIIToUTF16("Third")); | |
104 field_data.option_contents.push_back(base::ASCIIToUTF16("Third")); | |
105 data.fields.push_back(field_data); | |
106 | |
107 Pickle pickle; | |
108 SerializeFormData_v1(data, &pickle); | |
109 | |
110 PickleIterator iter(pickle); | |
111 FormData actual; | |
112 EXPECT_TRUE(DeserializeFormData(&iter, &actual)); | |
113 | |
114 EXPECT_EQ(actual, data); | |
115 } | |
56 } // namespace autofill | 116 } // namespace autofill |
OLD | NEW |