| 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 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 // Based on |form|, fills |pickle| with data conforming to | 1100 // Based on |form|, fills |pickle| with data conforming to |
| 1101 // |effective_version|, but marking the pickle version as |stored_version|. In | 1101 // |effective_version|, but marking the pickle version as |stored_version|. In |
| 1102 // most cases the two versions should be the same. | 1102 // most cases the two versions should be the same. |
| 1103 void CreateVersion1PlusPickle(const PasswordForm& form, | 1103 void CreateVersion1PlusPickle(const PasswordForm& form, |
| 1104 base::Pickle* pickle, | 1104 base::Pickle* pickle, |
| 1105 int stored_version, | 1105 int stored_version, |
| 1106 int effective_version); | 1106 int effective_version); |
| 1107 void CreateVersion0Pickle(bool size_32, | 1107 void CreateVersion0Pickle(bool size_32, |
| 1108 const PasswordForm& form, | 1108 const PasswordForm& form, |
| 1109 base::Pickle* pickle); | 1109 base::Pickle* pickle); |
| 1110 void CheckVersion7Pickle(); |
| 1110 // As explained in http://crbug.com/494229#c11, version 6 added a new optional | 1111 // As explained in http://crbug.com/494229#c11, version 6 added a new optional |
| 1111 // field to version 5. This field became required in version 7. Depending on | 1112 // field to version 5. This field became required in version 7. Depending on |
| 1112 // |with_optional_field|, this method checks deserialization with or without | 1113 // |with_optional_field|, this method checks deserialization with or without |
| 1113 // the optional field. | 1114 // the optional field. |
| 1114 void CheckVersion6Pickle(bool with_optional_field); | 1115 void CheckVersion6Pickle(bool with_optional_field); |
| 1115 void CheckVersion5Pickle(); | 1116 void CheckVersion5Pickle(); |
| 1116 void CheckVersion3Pickle(); | 1117 void CheckVersion3Pickle(); |
| 1117 void CheckVersion2Pickle(); | 1118 void CheckVersion2Pickle(); |
| 1118 void CheckVersion1Pickle(); | 1119 void CheckVersion1Pickle(); |
| 1119 void CheckVersion0Pickle(bool size_32, PasswordForm::Scheme scheme); | 1120 void CheckVersion0Pickle(bool size_32, PasswordForm::Scheme scheme); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 pickle->WriteString16(form.submit_element); | 1182 pickle->WriteString16(form.submit_element); |
| 1182 pickle->WriteBool(form.ssl_valid); | 1183 pickle->WriteBool(form.ssl_valid); |
| 1183 pickle->WriteBool(form.preferred); | 1184 pickle->WriteBool(form.preferred); |
| 1184 pickle->WriteBool(form.blacklisted_by_user); | 1185 pickle->WriteBool(form.blacklisted_by_user); |
| 1185 if (date_created_internal) | 1186 if (date_created_internal) |
| 1186 pickle->WriteInt64(form.date_created.ToInternalValue()); | 1187 pickle->WriteInt64(form.date_created.ToInternalValue()); |
| 1187 else | 1188 else |
| 1188 pickle->WriteInt64(form.date_created.ToTimeT()); | 1189 pickle->WriteInt64(form.date_created.ToTimeT()); |
| 1189 } | 1190 } |
| 1190 | 1191 |
| 1192 void NativeBackendKWalletPickleTest::CheckVersion7Pickle() { |
| 1193 base::Pickle pickle; |
| 1194 PasswordForm default_values; |
| 1195 PasswordForm form = form_google_; |
| 1196 |
| 1197 // Version 7 pickles always deserialize with 'skip_zero_click' of 'true'. |
| 1198 form.skip_zero_click = false; |
| 1199 CreateVersion1PlusPickle(form, &pickle, 7, 7); |
| 1200 ScopedVector<PasswordForm> form_list = |
| 1201 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle); |
| 1202 EXPECT_EQ(1u, form_list.size()); |
| 1203 form.skip_zero_click = true; |
| 1204 if (form_list.size() > 0) |
| 1205 CheckPasswordForm(form, *form_list[0], true); |
| 1206 |
| 1207 // Version 8 pickles deserialize with their own 'skip_zero_click' value. |
| 1208 form.skip_zero_click = false; |
| 1209 CreateVersion1PlusPickle(form, &pickle, 8, 8); |
| 1210 form_list = |
| 1211 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle); |
| 1212 EXPECT_EQ(1u, form_list.size()); |
| 1213 if (form_list.size() > 0) |
| 1214 CheckPasswordForm(form, *form_list[0], true); |
| 1215 } |
| 1216 |
| 1191 void NativeBackendKWalletPickleTest::CheckVersion6Pickle( | 1217 void NativeBackendKWalletPickleTest::CheckVersion6Pickle( |
| 1192 bool with_optional_field) { | 1218 bool with_optional_field) { |
| 1193 base::Pickle pickle; | 1219 base::Pickle pickle; |
| 1194 PasswordForm form = form_google_; | 1220 PasswordForm form = form_google_; |
| 1195 if (!with_optional_field) { | 1221 if (!with_optional_field) { |
| 1196 PasswordForm default_values; | 1222 PasswordForm default_values; |
| 1197 form.generation_upload_status = default_values.generation_upload_status; | 1223 form.generation_upload_status = default_values.generation_upload_status; |
| 1198 } | 1224 } |
| 1199 CreateVersion1PlusPickle(form, &pickle, 6, with_optional_field ? 7 : 5); | 1225 CreateVersion1PlusPickle(form, &pickle, 6, with_optional_field ? 7 : 5); |
| 1200 | 1226 |
| 1201 ScopedVector<PasswordForm> form_list = | 1227 ScopedVector<PasswordForm> form_list = |
| 1202 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle); | 1228 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle); |
| 1203 | 1229 |
| 1204 EXPECT_EQ(1u, form_list.size()); | 1230 EXPECT_EQ(1u, form_list.size()); |
| 1205 if (form_list.size() > 0) | 1231 if (form_list.size() > 0) |
| 1206 CheckPasswordForm(form, *form_list[0], true); | 1232 CheckPasswordForm(form, *form_list[0], true); |
| 1207 } | 1233 } |
| 1208 | 1234 |
| 1209 void NativeBackendKWalletPickleTest::CheckVersion5Pickle() { | 1235 void NativeBackendKWalletPickleTest::CheckVersion5Pickle() { |
| 1210 base::Pickle pickle; | 1236 base::Pickle pickle; |
| 1211 PasswordForm default_values; | 1237 PasswordForm default_values; |
| 1212 PasswordForm form = form_google_; | 1238 PasswordForm form = form_google_; |
| 1213 // Remove the field which was not present in version #5. | 1239 // Remove the field which was not present in version #5. |
| 1214 form.generation_upload_status = default_values.generation_upload_status; | 1240 form.generation_upload_status = default_values.generation_upload_status; |
| 1215 CreateVersion1PlusPickle(form, &pickle, 5, 5); | 1241 CreateVersion1PlusPickle(form, &pickle, 6, 6); |
| 1216 | 1242 |
| 1217 ScopedVector<PasswordForm> form_list = | 1243 ScopedVector<PasswordForm> form_list = |
| 1218 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle); | 1244 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle); |
| 1219 | 1245 |
| 1220 EXPECT_EQ(1u, form_list.size()); | 1246 EXPECT_EQ(1u, form_list.size()); |
| 1221 if (form_list.size() > 0) | 1247 if (form_list.size() > 0) |
| 1222 CheckPasswordForm(form, *form_list[0], true); | 1248 CheckPasswordForm(form, *form_list[0], true); |
| 1223 } | 1249 } |
| 1224 | 1250 |
| 1225 void NativeBackendKWalletPickleTest::CheckVersion3Pickle() { | 1251 void NativeBackendKWalletPickleTest::CheckVersion3Pickle() { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 } | 1350 } |
| 1325 | 1351 |
| 1326 TEST_F(NativeBackendKWalletPickleTest, CheckVersion5Pickle) { | 1352 TEST_F(NativeBackendKWalletPickleTest, CheckVersion5Pickle) { |
| 1327 CheckVersion5Pickle(); | 1353 CheckVersion5Pickle(); |
| 1328 } | 1354 } |
| 1329 | 1355 |
| 1330 TEST_F(NativeBackendKWalletPickleTest, CheckVersion6Pickle) { | 1356 TEST_F(NativeBackendKWalletPickleTest, CheckVersion6Pickle) { |
| 1331 CheckVersion6Pickle(false); | 1357 CheckVersion6Pickle(false); |
| 1332 CheckVersion6Pickle(true); | 1358 CheckVersion6Pickle(true); |
| 1333 } | 1359 } |
| OLD | NEW |