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/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/json/json_value_serializer.h" | 7 #include "base/json/json_value_serializer.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 EXPECT_EQ(computed_checksum, stored_checksum); | 109 EXPECT_EQ(computed_checksum, stored_checksum); |
110 | 110 |
111 *checksum = computed_checksum; | 111 *checksum = computed_checksum; |
112 return value.release(); | 112 return value.release(); |
113 } | 113 } |
114 | 114 |
115 bool Decode(BookmarkCodec* codec, BookmarkModel* model, const Value& value) { | 115 bool Decode(BookmarkCodec* codec, BookmarkModel* model, const Value& value) { |
116 int64 max_id; | 116 int64 max_id; |
117 bool result = codec->Decode(AsMutable(model->bookmark_bar_node()), | 117 bool result = codec->Decode(AsMutable(model->bookmark_bar_node()), |
118 AsMutable(model->other_node()), | 118 AsMutable(model->other_node()), |
119 AsMutable(model->synced_node()), | 119 AsMutable(model->mobile_node()), |
120 &max_id, value); | 120 &max_id, value); |
121 model->set_next_node_id(max_id); | 121 model->set_next_node_id(max_id); |
122 return result; | 122 return result; |
123 } | 123 } |
124 | 124 |
125 BookmarkModel* DecodeHelper(const Value& value, | 125 BookmarkModel* DecodeHelper(const Value& value, |
126 const std::string& expected_stored_checksum, | 126 const std::string& expected_stored_checksum, |
127 std::string* computed_checksum, | 127 std::string* computed_checksum, |
128 bool expected_changes) { | 128 bool expected_changes) { |
129 BookmarkCodec decoder; | 129 BookmarkCodec decoder; |
(...skipping 30 matching lines...) Expand all Loading... |
160 EXPECT_TRUE(assigned_ids->find(node_id) == assigned_ids->end()); | 160 EXPECT_TRUE(assigned_ids->find(node_id) == assigned_ids->end()); |
161 assigned_ids->insert(node_id); | 161 assigned_ids->insert(node_id); |
162 for (int i = 0; i < node->child_count(); ++i) | 162 for (int i = 0; i < node->child_count(); ++i) |
163 CheckIDs(node->GetChild(i), assigned_ids); | 163 CheckIDs(node->GetChild(i), assigned_ids); |
164 } | 164 } |
165 | 165 |
166 void ExpectIDsUnique(BookmarkModel* model) { | 166 void ExpectIDsUnique(BookmarkModel* model) { |
167 std::set<int64> assigned_ids; | 167 std::set<int64> assigned_ids; |
168 CheckIDs(model->bookmark_bar_node(), &assigned_ids); | 168 CheckIDs(model->bookmark_bar_node(), &assigned_ids); |
169 CheckIDs(model->other_node(), &assigned_ids); | 169 CheckIDs(model->other_node(), &assigned_ids); |
170 CheckIDs(model->synced_node(), &assigned_ids); | 170 CheckIDs(model->mobile_node(), &assigned_ids); |
171 } | 171 } |
172 }; | 172 }; |
173 | 173 |
174 TEST_F(BookmarkCodecTest, ChecksumEncodeDecodeTest) { | 174 TEST_F(BookmarkCodecTest, ChecksumEncodeDecodeTest) { |
175 scoped_ptr<BookmarkModel> model_to_encode(CreateTestModel1()); | 175 scoped_ptr<BookmarkModel> model_to_encode(CreateTestModel1()); |
176 std::string enc_checksum; | 176 std::string enc_checksum; |
177 scoped_ptr<Value> value(EncodeHelper(model_to_encode.get(), &enc_checksum)); | 177 scoped_ptr<Value> value(EncodeHelper(model_to_encode.get(), &enc_checksum)); |
178 | 178 |
179 EXPECT_TRUE(value.get() != NULL); | 179 EXPECT_TRUE(value.get() != NULL); |
180 | 180 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 scoped_ptr<Value> model_value2(encoder2.Encode(&decoded_model)); | 288 scoped_ptr<Value> model_value2(encoder2.Encode(&decoded_model)); |
289 | 289 |
290 BookmarkModel decoded_model2(NULL); | 290 BookmarkModel decoded_model2(NULL); |
291 BookmarkCodec decoder2; | 291 BookmarkCodec decoder2; |
292 ASSERT_TRUE(Decode(&decoder2, &decoded_model2, *model_value2.get())); | 292 ASSERT_TRUE(Decode(&decoder2, &decoded_model2, *model_value2.get())); |
293 BookmarkModelTestUtils::AssertModelsEqual(&decoded_model, | 293 BookmarkModelTestUtils::AssertModelsEqual(&decoded_model, |
294 &decoded_model2, | 294 &decoded_model2, |
295 true); | 295 true); |
296 } | 296 } |
297 | 297 |
298 TEST_F(BookmarkCodecTest, CanDecodeModelWithoutSyncedBookmarks) { | 298 TEST_F(BookmarkCodecTest, CanDecodeModelWithoutMobileBookmarks) { |
299 FilePath test_data_directory; | 299 FilePath test_data_directory; |
300 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory)); | 300 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory)); |
301 FilePath test_file = test_data_directory.AppendASCII( | 301 FilePath test_file = test_data_directory.AppendASCII( |
302 "bookmarks/model_without_sync.json"); | 302 "bookmarks/model_without_sync.json"); |
303 ASSERT_TRUE(file_util::PathExists(test_file)); | 303 ASSERT_TRUE(file_util::PathExists(test_file)); |
304 | 304 |
305 JSONFileValueSerializer serializer(test_file); | 305 JSONFileValueSerializer serializer(test_file); |
306 scoped_ptr<Value> root(serializer.Deserialize(NULL, NULL)); | 306 scoped_ptr<Value> root(serializer.Deserialize(NULL, NULL)); |
307 | 307 |
308 BookmarkModel decoded_model(NULL); | 308 BookmarkModel decoded_model(NULL); |
(...skipping 18 matching lines...) Expand all Loading... |
327 | 327 |
328 child = other->GetChild(0); | 328 child = other->GetChild(0); |
329 EXPECT_EQ(BookmarkNode::FOLDER, child->type()); | 329 EXPECT_EQ(BookmarkNode::FOLDER, child->type()); |
330 EXPECT_EQ(ASCIIToUTF16("Folder B"), child->GetTitle()); | 330 EXPECT_EQ(ASCIIToUTF16("Folder B"), child->GetTitle()); |
331 ASSERT_EQ(1, child->child_count()); | 331 ASSERT_EQ(1, child->child_count()); |
332 | 332 |
333 child = child->GetChild(0); | 333 child = child->GetChild(0); |
334 EXPECT_EQ(BookmarkNode::URL, child->type()); | 334 EXPECT_EQ(BookmarkNode::URL, child->type()); |
335 EXPECT_EQ(ASCIIToUTF16("Get started with Google Chrome"), child->GetTitle()); | 335 EXPECT_EQ(ASCIIToUTF16("Get started with Google Chrome"), child->GetTitle()); |
336 | 336 |
337 ASSERT_TRUE(decoded_model.synced_node() != NULL); | 337 ASSERT_TRUE(decoded_model.mobile_node() != NULL); |
338 } | 338 } |
OLD | NEW |