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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 scoped_ptr<base::Value> model_value2(encoder2.Encode(decoded_model.get())); | 348 scoped_ptr<base::Value> model_value2(encoder2.Encode(decoded_model.get())); |
349 | 349 |
350 scoped_ptr<BookmarkModel> decoded_model2(client_.CreateModel()); | 350 scoped_ptr<BookmarkModel> decoded_model2(client_.CreateModel()); |
351 BookmarkCodec decoder2; | 351 BookmarkCodec decoder2; |
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_data_directory; | |
359 base::FilePath test_file = | 358 base::FilePath test_file = |
360 GetTestDataDir().AppendASCII("bookmarks/model_without_sync.json"); | 359 GetTestDataDir().AppendASCII("bookmarks/model_without_sync.json"); |
361 ASSERT_TRUE(base::PathExists(test_file)); | 360 ASSERT_TRUE(base::PathExists(test_file)); |
362 | 361 |
363 JSONFileValueSerializer serializer(test_file); | 362 JSONFileValueSerializer serializer(test_file); |
364 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); | 363 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); |
365 | 364 |
366 scoped_ptr<BookmarkModel> decoded_model(client_.CreateModel()); | 365 scoped_ptr<BookmarkModel> decoded_model(client_.CreateModel()); |
367 BookmarkCodec decoder; | 366 BookmarkCodec decoder; |
368 ASSERT_TRUE(Decode(&decoder, decoded_model.get(), *root.get())); | 367 ASSERT_TRUE(Decode(&decoder, decoded_model.get(), *root.get())); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 EXPECT_EQ(1, model->root_node()->sync_transaction_version()); | 434 EXPECT_EQ(1, model->root_node()->sync_transaction_version()); |
436 bbn = model->bookmark_bar_node(); | 435 bbn = model->bookmark_bar_node(); |
437 EXPECT_EQ(42, bbn->GetChild(1)->sync_transaction_version()); | 436 EXPECT_EQ(42, bbn->GetChild(1)->sync_transaction_version()); |
438 EXPECT_EQ(BookmarkNode::kInvalidSyncTransactionVersion, | 437 EXPECT_EQ(BookmarkNode::kInvalidSyncTransactionVersion, |
439 bbn->GetChild(0)->sync_transaction_version()); | 438 bbn->GetChild(0)->sync_transaction_version()); |
440 } | 439 } |
441 | 440 |
442 // 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 |
443 // way meta info is stored. | 442 // way meta info is stored. |
444 TEST_F(BookmarkCodecTest, CanDecodeMetaInfoAsString) { | 443 TEST_F(BookmarkCodecTest, CanDecodeMetaInfoAsString) { |
445 base::FilePath test_data_directory; | |
446 base::FilePath test_file = | 444 base::FilePath test_file = |
447 GetTestDataDir().AppendASCII("bookmarks/meta_info_as_string.json"); | 445 GetTestDataDir().AppendASCII("bookmarks/meta_info_as_string.json"); |
448 ASSERT_TRUE(base::PathExists(test_file)); | 446 ASSERT_TRUE(base::PathExists(test_file)); |
449 | 447 |
450 JSONFileValueSerializer serializer(test_file); | 448 JSONFileValueSerializer serializer(test_file); |
451 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); | 449 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); |
452 | 450 |
453 scoped_ptr<BookmarkModel> model(client_.CreateModel()); | 451 scoped_ptr<BookmarkModel> model(client_.CreateModel()); |
454 BookmarkCodec decoder; | 452 BookmarkCodec decoder; |
455 ASSERT_TRUE(Decode(&decoder, model.get(), *root.get())); | 453 ASSERT_TRUE(Decode(&decoder, model.get(), *root.get())); |
(...skipping 14 matching lines...) Expand all Loading... |
470 bbn->GetChild(1)->GetMetaInfo(kSyncTransactionVersionKey, &meta_value)); | 468 bbn->GetChild(1)->GetMetaInfo(kSyncTransactionVersionKey, &meta_value)); |
471 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNormalKey, &meta_value)); | 469 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNormalKey, &meta_value)); |
472 EXPECT_EQ("value", meta_value); | 470 EXPECT_EQ("value", meta_value); |
473 EXPECT_TRUE(bbn->GetChild(1)->GetMetaInfo(kNormalKey, &meta_value)); | 471 EXPECT_TRUE(bbn->GetChild(1)->GetMetaInfo(kNormalKey, &meta_value)); |
474 EXPECT_EQ("value2", meta_value); | 472 EXPECT_EQ("value2", meta_value); |
475 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNestedKey, &meta_value)); | 473 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNestedKey, &meta_value)); |
476 EXPECT_EQ("value3", meta_value); | 474 EXPECT_EQ("value3", meta_value); |
477 } | 475 } |
478 | 476 |
479 } // namespace bookmarks | 477 } // namespace bookmarks |
OLD | NEW |