OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/bookmarks/bookmark_codec.h" | 9 #include "chrome/browser/bookmarks/bookmark_codec.h" |
10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 EXPECT_EQ(computed_checksum, stored_checksum); | 104 EXPECT_EQ(computed_checksum, stored_checksum); |
105 | 105 |
106 *checksum = computed_checksum; | 106 *checksum = computed_checksum; |
107 return value.release(); | 107 return value.release(); |
108 } | 108 } |
109 | 109 |
110 bool Decode(BookmarkCodec* codec, BookmarkModel* model, const Value& value) { | 110 bool Decode(BookmarkCodec* codec, BookmarkModel* model, const Value& value) { |
111 int64 max_id; | 111 int64 max_id; |
112 bool result = codec->Decode(AsMutable(model->GetBookmarkBarNode()), | 112 bool result = codec->Decode(AsMutable(model->GetBookmarkBarNode()), |
113 AsMutable(model->other_node()), | 113 AsMutable(model->other_node()), |
| 114 AsMutable(model->synced_node()), |
114 &max_id, value); | 115 &max_id, value); |
115 model->set_next_node_id(max_id); | 116 model->set_next_node_id(max_id); |
116 return result; | 117 return result; |
117 } | 118 } |
118 | 119 |
119 BookmarkModel* DecodeHelper(const Value& value, | 120 BookmarkModel* DecodeHelper(const Value& value, |
120 const std::string& expected_stored_checksum, | 121 const std::string& expected_stored_checksum, |
121 std::string* computed_checksum, | 122 std::string* computed_checksum, |
122 bool expected_changes) { | 123 bool expected_changes) { |
123 BookmarkCodec decoder; | 124 BookmarkCodec decoder; |
(...skipping 30 matching lines...) Expand all Loading... |
154 EXPECT_TRUE(assigned_ids->find(node_id) == assigned_ids->end()); | 155 EXPECT_TRUE(assigned_ids->find(node_id) == assigned_ids->end()); |
155 assigned_ids->insert(node_id); | 156 assigned_ids->insert(node_id); |
156 for (int i = 0; i < node->child_count(); ++i) | 157 for (int i = 0; i < node->child_count(); ++i) |
157 CheckIDs(node->GetChild(i), assigned_ids); | 158 CheckIDs(node->GetChild(i), assigned_ids); |
158 } | 159 } |
159 | 160 |
160 void ExpectIDsUnique(BookmarkModel* model) { | 161 void ExpectIDsUnique(BookmarkModel* model) { |
161 std::set<int64> assigned_ids; | 162 std::set<int64> assigned_ids; |
162 CheckIDs(model->GetBookmarkBarNode(), &assigned_ids); | 163 CheckIDs(model->GetBookmarkBarNode(), &assigned_ids); |
163 CheckIDs(model->other_node(), &assigned_ids); | 164 CheckIDs(model->other_node(), &assigned_ids); |
| 165 CheckIDs(model->synced_node(), &assigned_ids); |
164 } | 166 } |
165 }; | 167 }; |
166 | 168 |
167 TEST_F(BookmarkCodecTest, ChecksumEncodeDecodeTest) { | 169 TEST_F(BookmarkCodecTest, ChecksumEncodeDecodeTest) { |
168 scoped_ptr<BookmarkModel> model_to_encode(CreateTestModel1()); | 170 scoped_ptr<BookmarkModel> model_to_encode(CreateTestModel1()); |
169 std::string enc_checksum; | 171 std::string enc_checksum; |
170 scoped_ptr<Value> value(EncodeHelper(model_to_encode.get(), &enc_checksum)); | 172 scoped_ptr<Value> value(EncodeHelper(model_to_encode.get(), &enc_checksum)); |
171 | 173 |
172 EXPECT_TRUE(value.get() != NULL); | 174 EXPECT_TRUE(value.get() != NULL); |
173 | 175 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 BookmarkCodec encoder2; | 282 BookmarkCodec encoder2; |
281 scoped_ptr<Value> model_value2(encoder2.Encode(&decoded_model)); | 283 scoped_ptr<Value> model_value2(encoder2.Encode(&decoded_model)); |
282 | 284 |
283 BookmarkModel decoded_model2(NULL); | 285 BookmarkModel decoded_model2(NULL); |
284 BookmarkCodec decoder2; | 286 BookmarkCodec decoder2; |
285 ASSERT_TRUE(Decode(&decoder2, &decoded_model2, *model_value2.get())); | 287 ASSERT_TRUE(Decode(&decoder2, &decoded_model2, *model_value2.get())); |
286 BookmarkModelTestUtils::AssertModelsEqual(&decoded_model, | 288 BookmarkModelTestUtils::AssertModelsEqual(&decoded_model, |
287 &decoded_model2, | 289 &decoded_model2, |
288 true); | 290 true); |
289 } | 291 } |
OLD | NEW |