OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bookmarks/browser/bookmark_codec.h" | 5 #include "components/bookmarks/browser/bookmark_codec.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
9 #include "base/json/json_file_value_serializer.h" | 12 #include "base/json/json_file_value_serializer.h" |
10 #include "base/json/json_string_value_serializer.h" | 13 #include "base/json/json_string_value_serializer.h" |
11 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
12 #include "base/path_service.h" | 15 #include "base/path_service.h" |
13 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 18 #include "base/values.h" |
16 #include "components/bookmarks/browser/bookmark_model.h" | 19 #include "components/bookmarks/browser/bookmark_model.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 EXPECT_FALSE(stored_checksum.empty()); | 159 EXPECT_FALSE(stored_checksum.empty()); |
157 EXPECT_EQ(computed_checksum, stored_checksum); | 160 EXPECT_EQ(computed_checksum, stored_checksum); |
158 | 161 |
159 *checksum = computed_checksum; | 162 *checksum = computed_checksum; |
160 return value.release(); | 163 return value.release(); |
161 } | 164 } |
162 | 165 |
163 bool Decode(BookmarkCodec* codec, | 166 bool Decode(BookmarkCodec* codec, |
164 BookmarkModel* model, | 167 BookmarkModel* model, |
165 const base::Value& value) { | 168 const base::Value& value) { |
166 int64 max_id; | 169 int64_t max_id; |
167 bool result = codec->Decode(AsMutable(model->bookmark_bar_node()), | 170 bool result = codec->Decode(AsMutable(model->bookmark_bar_node()), |
168 AsMutable(model->other_node()), | 171 AsMutable(model->other_node()), |
169 AsMutable(model->mobile_node()), | 172 AsMutable(model->mobile_node()), |
170 &max_id, | 173 &max_id, |
171 value); | 174 value); |
172 model->set_next_node_id(max_id); | 175 model->set_next_node_id(max_id); |
173 AsMutable(model->root_node())->SetMetaInfoMap(codec->model_meta_info_map()); | 176 AsMutable(model->root_node())->SetMetaInfoMap(codec->model_meta_info_map()); |
174 AsMutable(model->root_node()) | 177 AsMutable(model->root_node()) |
175 ->set_sync_transaction_version(codec->model_sync_transaction_version()); | 178 ->set_sync_transaction_version(codec->model_sync_transaction_version()); |
176 | 179 |
(...skipping 25 matching lines...) Expand all Loading... |
202 // The two checksums should be equal if expected_changes is true; otherwise | 205 // The two checksums should be equal if expected_changes is true; otherwise |
203 // they should be different. | 206 // they should be different. |
204 if (expected_changes) | 207 if (expected_changes) |
205 EXPECT_NE(*computed_checksum, stored_checksum); | 208 EXPECT_NE(*computed_checksum, stored_checksum); |
206 else | 209 else |
207 EXPECT_EQ(*computed_checksum, stored_checksum); | 210 EXPECT_EQ(*computed_checksum, stored_checksum); |
208 | 211 |
209 return model.release(); | 212 return model.release(); |
210 } | 213 } |
211 | 214 |
212 void CheckIDs(const BookmarkNode* node, std::set<int64>* assigned_ids) { | 215 void CheckIDs(const BookmarkNode* node, std::set<int64_t>* assigned_ids) { |
213 DCHECK(node); | 216 DCHECK(node); |
214 int64 node_id = node->id(); | 217 int64_t node_id = node->id(); |
215 EXPECT_TRUE(assigned_ids->find(node_id) == assigned_ids->end()); | 218 EXPECT_TRUE(assigned_ids->find(node_id) == assigned_ids->end()); |
216 assigned_ids->insert(node_id); | 219 assigned_ids->insert(node_id); |
217 for (int i = 0; i < node->child_count(); ++i) | 220 for (int i = 0; i < node->child_count(); ++i) |
218 CheckIDs(node->GetChild(i), assigned_ids); | 221 CheckIDs(node->GetChild(i), assigned_ids); |
219 } | 222 } |
220 | 223 |
221 void ExpectIDsUnique(BookmarkModel* model) { | 224 void ExpectIDsUnique(BookmarkModel* model) { |
222 std::set<int64> assigned_ids; | 225 std::set<int64_t> assigned_ids; |
223 CheckIDs(model->bookmark_bar_node(), &assigned_ids); | 226 CheckIDs(model->bookmark_bar_node(), &assigned_ids); |
224 CheckIDs(model->other_node(), &assigned_ids); | 227 CheckIDs(model->other_node(), &assigned_ids); |
225 CheckIDs(model->mobile_node(), &assigned_ids); | 228 CheckIDs(model->mobile_node(), &assigned_ids); |
226 } | 229 } |
227 | 230 |
228 TestBookmarkClient client_; | 231 TestBookmarkClient client_; |
229 }; | 232 }; |
230 | 233 |
231 TEST_F(BookmarkCodecTest, ChecksumEncodeDecodeTest) { | 234 TEST_F(BookmarkCodecTest, ChecksumEncodeDecodeTest) { |
232 scoped_ptr<BookmarkModel> model_to_encode(CreateTestModel1()); | 235 scoped_ptr<BookmarkModel> model_to_encode(CreateTestModel1()); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 bbn->GetChild(1)->GetMetaInfo(kSyncTransactionVersionKey, &meta_value)); | 471 bbn->GetChild(1)->GetMetaInfo(kSyncTransactionVersionKey, &meta_value)); |
469 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNormalKey, &meta_value)); | 472 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNormalKey, &meta_value)); |
470 EXPECT_EQ("value", meta_value); | 473 EXPECT_EQ("value", meta_value); |
471 EXPECT_TRUE(bbn->GetChild(1)->GetMetaInfo(kNormalKey, &meta_value)); | 474 EXPECT_TRUE(bbn->GetChild(1)->GetMetaInfo(kNormalKey, &meta_value)); |
472 EXPECT_EQ("value2", meta_value); | 475 EXPECT_EQ("value2", meta_value); |
473 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNestedKey, &meta_value)); | 476 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNestedKey, &meta_value)); |
474 EXPECT_EQ("value3", meta_value); | 477 EXPECT_EQ("value3", meta_value); |
475 } | 478 } |
476 | 479 |
477 } // namespace bookmarks | 480 } // namespace bookmarks |
OLD | NEW |