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 "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 ASSERT_TRUE(Decode(&decoder2, decoded_model2.get(), *model_value2.get())); | 352 ASSERT_TRUE(Decode(&decoder2, decoded_model2.get(), *model_value2.get())); |
353 ASSERT_NO_FATAL_FAILURE( | 353 ASSERT_NO_FATAL_FAILURE( |
354 AssertModelsEqual(decoded_model.get(), decoded_model2.get())); | 354 AssertModelsEqual(decoded_model.get(), decoded_model2.get())); |
355 } | 355 } |
356 | 356 |
357 TEST_F(BookmarkCodecTest, CanDecodeModelWithoutMobileBookmarks) { | 357 TEST_F(BookmarkCodecTest, CanDecodeModelWithoutMobileBookmarks) { |
358 base::FilePath test_file = | 358 base::FilePath test_file = |
359 GetTestDataDir().AppendASCII("bookmarks/model_without_sync.json"); | 359 GetTestDataDir().AppendASCII("bookmarks/model_without_sync.json"); |
360 ASSERT_TRUE(base::PathExists(test_file)); | 360 ASSERT_TRUE(base::PathExists(test_file)); |
361 | 361 |
362 JSONFileValueSerializer serializer(test_file); | 362 JSONFileValueDeserializer deserializer(test_file); |
363 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); | 363 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, NULL)); |
364 | 364 |
365 scoped_ptr<BookmarkModel> decoded_model(client_.CreateModel()); | 365 scoped_ptr<BookmarkModel> decoded_model(client_.CreateModel()); |
366 BookmarkCodec decoder; | 366 BookmarkCodec decoder; |
367 ASSERT_TRUE(Decode(&decoder, decoded_model.get(), *root.get())); | 367 ASSERT_TRUE(Decode(&decoder, decoded_model.get(), *root.get())); |
368 ExpectIDsUnique(decoded_model.get()); | 368 ExpectIDsUnique(decoded_model.get()); |
369 | 369 |
370 const BookmarkNode* bbn = decoded_model->bookmark_bar_node(); | 370 const BookmarkNode* bbn = decoded_model->bookmark_bar_node(); |
371 ASSERT_EQ(1, bbn->child_count()); | 371 ASSERT_EQ(1, bbn->child_count()); |
372 | 372 |
373 const BookmarkNode* child = bbn->GetChild(0); | 373 const BookmarkNode* child = bbn->GetChild(0); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 bbn->GetChild(0)->sync_transaction_version()); | 438 bbn->GetChild(0)->sync_transaction_version()); |
439 } | 439 } |
440 | 440 |
441 // Verifies that we can still decode the old codec format after changing the | 441 // Verifies that we can still decode the old codec format after changing the |
442 // way meta info is stored. | 442 // way meta info is stored. |
443 TEST_F(BookmarkCodecTest, CanDecodeMetaInfoAsString) { | 443 TEST_F(BookmarkCodecTest, CanDecodeMetaInfoAsString) { |
444 base::FilePath test_file = | 444 base::FilePath test_file = |
445 GetTestDataDir().AppendASCII("bookmarks/meta_info_as_string.json"); | 445 GetTestDataDir().AppendASCII("bookmarks/meta_info_as_string.json"); |
446 ASSERT_TRUE(base::PathExists(test_file)); | 446 ASSERT_TRUE(base::PathExists(test_file)); |
447 | 447 |
448 JSONFileValueSerializer serializer(test_file); | 448 JSONFileValueDeserializer deserializer(test_file); |
449 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); | 449 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, NULL)); |
450 | 450 |
451 scoped_ptr<BookmarkModel> model(client_.CreateModel()); | 451 scoped_ptr<BookmarkModel> model(client_.CreateModel()); |
452 BookmarkCodec decoder; | 452 BookmarkCodec decoder; |
453 ASSERT_TRUE(Decode(&decoder, model.get(), *root.get())); | 453 ASSERT_TRUE(Decode(&decoder, model.get(), *root.get())); |
454 | 454 |
455 EXPECT_EQ(1, model->root_node()->sync_transaction_version()); | 455 EXPECT_EQ(1, model->root_node()->sync_transaction_version()); |
456 const BookmarkNode* bbn = model->bookmark_bar_node(); | 456 const BookmarkNode* bbn = model->bookmark_bar_node(); |
457 EXPECT_EQ(BookmarkNode::kInvalidSyncTransactionVersion, | 457 EXPECT_EQ(BookmarkNode::kInvalidSyncTransactionVersion, |
458 bbn->GetChild(0)->sync_transaction_version()); | 458 bbn->GetChild(0)->sync_transaction_version()); |
459 EXPECT_EQ(42, bbn->GetChild(1)->sync_transaction_version()); | 459 EXPECT_EQ(42, bbn->GetChild(1)->sync_transaction_version()); |
460 | 460 |
461 const char kSyncTransactionVersionKey[] = "sync.transaction_version"; | 461 const char kSyncTransactionVersionKey[] = "sync.transaction_version"; |
462 const char kNormalKey[] = "key"; | 462 const char kNormalKey[] = "key"; |
463 const char kNestedKey[] = "nested.key"; | 463 const char kNestedKey[] = "nested.key"; |
464 std::string meta_value; | 464 std::string meta_value; |
465 EXPECT_FALSE( | 465 EXPECT_FALSE( |
466 model->root_node()->GetMetaInfo(kSyncTransactionVersionKey, &meta_value)); | 466 model->root_node()->GetMetaInfo(kSyncTransactionVersionKey, &meta_value)); |
467 EXPECT_FALSE( | 467 EXPECT_FALSE( |
468 bbn->GetChild(1)->GetMetaInfo(kSyncTransactionVersionKey, &meta_value)); | 468 bbn->GetChild(1)->GetMetaInfo(kSyncTransactionVersionKey, &meta_value)); |
469 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNormalKey, &meta_value)); | 469 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNormalKey, &meta_value)); |
470 EXPECT_EQ("value", meta_value); | 470 EXPECT_EQ("value", meta_value); |
471 EXPECT_TRUE(bbn->GetChild(1)->GetMetaInfo(kNormalKey, &meta_value)); | 471 EXPECT_TRUE(bbn->GetChild(1)->GetMetaInfo(kNormalKey, &meta_value)); |
472 EXPECT_EQ("value2", meta_value); | 472 EXPECT_EQ("value2", meta_value); |
473 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNestedKey, &meta_value)); | 473 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNestedKey, &meta_value)); |
474 EXPECT_EQ("value3", meta_value); | 474 EXPECT_EQ("value3", meta_value); |
475 } | 475 } |
476 | 476 |
477 } // namespace bookmarks | 477 } // namespace bookmarks |
OLD | NEW |