OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 const PasswordForm& actual, | 239 const PasswordForm& actual, |
240 bool check_date_created) { | 240 bool check_date_created) { |
241 EXPECT_EQ(expected.origin, actual.origin); | 241 EXPECT_EQ(expected.origin, actual.origin); |
242 EXPECT_EQ(expected.password_value, actual.password_value); | 242 EXPECT_EQ(expected.password_value, actual.password_value); |
243 EXPECT_EQ(expected.action, actual.action); | 243 EXPECT_EQ(expected.action, actual.action); |
244 EXPECT_EQ(expected.username_element, actual.username_element); | 244 EXPECT_EQ(expected.username_element, actual.username_element); |
245 EXPECT_EQ(expected.username_value, actual.username_value); | 245 EXPECT_EQ(expected.username_value, actual.username_value); |
246 EXPECT_EQ(expected.password_element, actual.password_element); | 246 EXPECT_EQ(expected.password_element, actual.password_element); |
247 EXPECT_EQ(expected.submit_element, actual.submit_element); | 247 EXPECT_EQ(expected.submit_element, actual.submit_element); |
248 EXPECT_EQ(expected.signon_realm, actual.signon_realm); | 248 EXPECT_EQ(expected.signon_realm, actual.signon_realm); |
249 EXPECT_EQ(expected.ssl_valid, actual.ssl_valid); | |
250 EXPECT_EQ(expected.preferred, actual.preferred); | 249 EXPECT_EQ(expected.preferred, actual.preferred); |
251 if (check_date_created) { | 250 if (check_date_created) { |
252 EXPECT_EQ(expected.date_created, actual.date_created); | 251 EXPECT_EQ(expected.date_created, actual.date_created); |
253 } | 252 } |
254 EXPECT_EQ(expected.blacklisted_by_user, actual.blacklisted_by_user); | 253 EXPECT_EQ(expected.blacklisted_by_user, actual.blacklisted_by_user); |
255 EXPECT_EQ(expected.type, actual.type); | 254 EXPECT_EQ(expected.type, actual.type); |
256 EXPECT_EQ(expected.times_used, actual.times_used); | 255 EXPECT_EQ(expected.times_used, actual.times_used); |
257 EXPECT_EQ(expected.scheme, actual.scheme); | 256 EXPECT_EQ(expected.scheme, actual.scheme); |
258 EXPECT_EQ(expected.date_synced, actual.date_synced); | 257 EXPECT_EQ(expected.date_synced, actual.date_synced); |
259 EXPECT_EQ(expected.display_name, actual.display_name); | 258 EXPECT_EQ(expected.display_name, actual.display_name); |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 // most cases the two versions should be the same. | 1164 // most cases the two versions should be the same. |
1166 void CreateVersion1PlusPickle(const PasswordForm& form, | 1165 void CreateVersion1PlusPickle(const PasswordForm& form, |
1167 base::Pickle* pickle, | 1166 base::Pickle* pickle, |
1168 int stored_version, | 1167 int stored_version, |
1169 int effective_version); | 1168 int effective_version); |
1170 // If |size_32| is true, stores the number of forms in the pickle as a 32bit | 1169 // If |size_32| is true, stores the number of forms in the pickle as a 32bit |
1171 // uint, otherwise as 64 bit size_t. | 1170 // uint, otherwise as 64 bit size_t. |
1172 void CreateVersion0Pickle(bool size_32, | 1171 void CreateVersion0Pickle(bool size_32, |
1173 const PasswordForm& form, | 1172 const PasswordForm& form, |
1174 base::Pickle* pickle); | 1173 base::Pickle* pickle); |
| 1174 void CheckVersion9Pickle(); |
1175 void CheckVersion8Pickle(); | 1175 void CheckVersion8Pickle(); |
1176 void CheckVersion7Pickle(); | 1176 void CheckVersion7Pickle(); |
1177 // As explained in http://crbug.com/494229#c11, version 6 added a new optional | 1177 // As explained in http://crbug.com/494229#c11, version 6 added a new optional |
1178 // field to version 5. This field became required in version 7. Depending on | 1178 // field to version 5. This field became required in version 7. Depending on |
1179 // |with_optional_field|, this method checks deserialization with or without | 1179 // |with_optional_field|, this method checks deserialization with or without |
1180 // the optional field. | 1180 // the optional field. |
1181 void CheckVersion6Pickle(bool with_optional_field); | 1181 void CheckVersion6Pickle(bool with_optional_field); |
1182 void CheckVersion5Pickle(); | 1182 void CheckVersion5Pickle(); |
1183 void CheckVersion3Pickle(); | 1183 void CheckVersion3Pickle(); |
1184 void CheckVersion2Pickle(); | 1184 void CheckVersion2Pickle(); |
1185 void CheckVersion1Pickle(); | 1185 void CheckVersion1Pickle(); |
1186 void CheckVersion0Pickle(bool size_32, PasswordForm::Scheme scheme); | 1186 void CheckVersion0Pickle(bool size_32, PasswordForm::Scheme scheme); |
1187 }; | 1187 }; |
1188 | 1188 |
1189 void NativeBackendKWalletPickleTest::CreateVersion1PlusPickle( | 1189 void NativeBackendKWalletPickleTest::CreateVersion1PlusPickle( |
1190 const PasswordForm& form, | 1190 const PasswordForm& form, |
1191 base::Pickle* pickle, | 1191 base::Pickle* pickle, |
1192 int stored_version, | 1192 int stored_version, |
1193 int effective_version) { | 1193 int effective_version) { |
1194 pickle->WriteInt(stored_version); | 1194 pickle->WriteInt(stored_version); |
1195 pickle->WriteUInt64(1); // Number of forms in the pickle. | 1195 pickle->WriteUInt64(1); // Number of forms in the pickle. |
1196 WriteHTMLAttributes(form, pickle); | 1196 WriteHTMLAttributes(form, pickle); |
1197 pickle->WriteBool(form.ssl_valid); | 1197 if (effective_version < 9) |
| 1198 pickle->WriteBool(true); // Unused flag. |
1198 WritePreferenceMetadata(form, pickle); | 1199 WritePreferenceMetadata(form, pickle); |
1199 pickle->WriteInt64(form.date_created.ToInternalValue()); | 1200 pickle->WriteInt64(form.date_created.ToInternalValue()); |
1200 if (effective_version < 2) | 1201 if (effective_version < 2) |
1201 return; | 1202 return; |
1202 pickle->WriteInt(form.type); | 1203 pickle->WriteInt(form.type); |
1203 pickle->WriteInt(form.times_used); | 1204 pickle->WriteInt(form.times_used); |
1204 autofill::SerializeFormData(form.form_data, pickle); | 1205 autofill::SerializeFormData(form.form_data, pickle); |
1205 if (effective_version < 3) | 1206 if (effective_version < 3) |
1206 return; | 1207 return; |
1207 pickle->WriteInt64(form.date_synced.ToInternalValue()); | 1208 pickle->WriteInt64(form.date_synced.ToInternalValue()); |
(...skipping 12 matching lines...) Expand all Loading... |
1220 bool size_32, | 1221 bool size_32, |
1221 const PasswordForm& form, | 1222 const PasswordForm& form, |
1222 base::Pickle* pickle) { | 1223 base::Pickle* pickle) { |
1223 pickle->WriteInt(0); | 1224 pickle->WriteInt(0); |
1224 // Write the number of forms in the pickle in the appopriate bit size. | 1225 // Write the number of forms in the pickle in the appopriate bit size. |
1225 if (size_32) | 1226 if (size_32) |
1226 pickle->WriteUInt32(1); | 1227 pickle->WriteUInt32(1); |
1227 else | 1228 else |
1228 pickle->WriteUInt64(1); | 1229 pickle->WriteUInt64(1); |
1229 WriteHTMLAttributes(form, pickle); | 1230 WriteHTMLAttributes(form, pickle); |
1230 pickle->WriteBool(form.ssl_valid); | 1231 pickle->WriteBool(true); // Unused flag. |
1231 WritePreferenceMetadata(form, pickle); | 1232 WritePreferenceMetadata(form, pickle); |
1232 // Old way to store the date. | 1233 // Old way to store the date. |
1233 pickle->WriteInt64(form.date_created.ToTimeT()); | 1234 pickle->WriteInt64(form.date_created.ToTimeT()); |
1234 } | 1235 } |
1235 | 1236 |
| 1237 void NativeBackendKWalletPickleTest::CheckVersion9Pickle() { |
| 1238 // Pickle 9+ dropped an old flag in the middle of PasswordForm. This test |
| 1239 // makes sure that the attributes after the dropped flag are deserialised |
| 1240 // correctly. |
| 1241 base::Pickle pickle; |
| 1242 PasswordForm default_values; |
| 1243 PasswordForm form = form_google_; |
| 1244 |
| 1245 CreateVersion1PlusPickle(form, &pickle, 9, 9); |
| 1246 ScopedVector<PasswordForm> form_list = |
| 1247 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle); |
| 1248 EXPECT_EQ(1u, form_list.size()); |
| 1249 if (form_list.size() > 0) |
| 1250 CheckPasswordForm(form, *form_list[0], true); |
| 1251 } |
| 1252 |
1236 void NativeBackendKWalletPickleTest::CheckVersion8Pickle() { | 1253 void NativeBackendKWalletPickleTest::CheckVersion8Pickle() { |
1237 base::Pickle pickle; | 1254 base::Pickle pickle; |
1238 PasswordForm default_values; | 1255 PasswordForm default_values; |
1239 PasswordForm form = form_google_; | 1256 PasswordForm form = form_google_; |
1240 | 1257 |
1241 // Version 8 pickles deserialize with their own 'skip_zero_click' value. | 1258 // Version 8 pickles deserialize with their own 'skip_zero_click' value. |
1242 form.skip_zero_click = false; | 1259 form.skip_zero_click = false; |
1243 CreateVersion1PlusPickle(form, &pickle, 8, 8); | 1260 CreateVersion1PlusPickle(form, &pickle, 8, 8); |
1244 ScopedVector<PasswordForm> form_list = | 1261 ScopedVector<PasswordForm> form_list = |
1245 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle); | 1262 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 CheckVersion6Pickle(true); | 1425 CheckVersion6Pickle(true); |
1409 } | 1426 } |
1410 | 1427 |
1411 TEST_F(NativeBackendKWalletPickleTest, CheckVersion7Pickle) { | 1428 TEST_F(NativeBackendKWalletPickleTest, CheckVersion7Pickle) { |
1412 CheckVersion7Pickle(); | 1429 CheckVersion7Pickle(); |
1413 } | 1430 } |
1414 | 1431 |
1415 TEST_F(NativeBackendKWalletPickleTest, CheckVersion8Pickle) { | 1432 TEST_F(NativeBackendKWalletPickleTest, CheckVersion8Pickle) { |
1416 CheckVersion8Pickle(); | 1433 CheckVersion8Pickle(); |
1417 } | 1434 } |
| 1435 |
| 1436 TEST_F(NativeBackendKWalletPickleTest, CheckVersion9Pickle) { |
| 1437 CheckVersion9Pickle(); |
| 1438 } |
OLD | NEW |