| 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/enhanced_bookmarks/enhanced_bookmark_model.h" | 5 #include "components/enhanced_bookmarks/enhanced_bookmark_model.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 672 |
| 673 TEST_F(EnhancedBookmarkModelTest, NodeRemovedWhileResetDuplicationScheduled) { | 673 TEST_F(EnhancedBookmarkModelTest, NodeRemovedWhileResetDuplicationScheduled) { |
| 674 const BookmarkNode* node1 = AddBookmark(); | 674 const BookmarkNode* node1 = AddBookmark(); |
| 675 const BookmarkNode* node2 = AddBookmark(); | 675 const BookmarkNode* node2 = AddBookmark(); |
| 676 bookmark_model_->SetNodeMetaInfo(node1, "stars.id", "c_1"); | 676 bookmark_model_->SetNodeMetaInfo(node1, "stars.id", "c_1"); |
| 677 bookmark_model_->SetNodeMetaInfo(node2, "stars.id", "c_1"); | 677 bookmark_model_->SetNodeMetaInfo(node2, "stars.id", "c_1"); |
| 678 bookmark_model_->Remove(node1->parent(), node1->parent()->GetIndexOf(node1)); | 678 bookmark_model_->Remove(node1->parent(), node1->parent()->GetIndexOf(node1)); |
| 679 base::RunLoop().RunUntilIdle(); | 679 base::RunLoop().RunUntilIdle(); |
| 680 } | 680 } |
| 681 | 681 |
| 682 // Verifies that the NEEDS_OFFLINE_PROCESSING flag is set for nodes added | |
| 683 // with no remote id. | |
| 684 TEST_F(EnhancedBookmarkModelTest, BookmarkAddedSetsOfflineProcessingFlag) { | |
| 685 const BookmarkNode* node = | |
| 686 bookmark_model_->AddURL(bookmark_model_->other_node(), | |
| 687 0, | |
| 688 base::ASCIIToUTF16("Some title"), | |
| 689 GURL(BOOKMARK_URL)); | |
| 690 std::string flags_str; | |
| 691 EXPECT_FALSE(node->GetMetaInfo("stars.flags", &flags_str)); | |
| 692 base::RunLoop().RunUntilIdle(); | |
| 693 ASSERT_TRUE(node->GetMetaInfo("stars.flags", &flags_str)); | |
| 694 int flags; | |
| 695 ASSERT_TRUE(base::StringToInt(flags_str, &flags)); | |
| 696 EXPECT_EQ(1, (flags & 1)); | |
| 697 } | |
| 698 | |
| 699 // Verifies that the NEEDS_OFFLINE_PROCESSING_FLAG is not set for added folders. | |
| 700 TEST_F(EnhancedBookmarkModelTest, FolderAddedDoesNotSetOfflineProcessingFlag) { | |
| 701 const BookmarkNode* node = AddFolder(); | |
| 702 base::RunLoop().RunUntilIdle(); | |
| 703 | |
| 704 std::string flags_str; | |
| 705 if (node->GetMetaInfo("stars.flags", &flags_str)) { | |
| 706 int flags; | |
| 707 ASSERT_TRUE(base::StringToInt(flags_str, &flags)); | |
| 708 EXPECT_EQ(0, (flags & 1)); | |
| 709 } | |
| 710 } | |
| 711 | |
| 712 // Verifies that when a bookmark is added that has a remote id, the status of | |
| 713 // the NEEDS_OFFLINE_PROCESSING flag doesn't change. | |
| 714 TEST_F(EnhancedBookmarkModelTest, | |
| 715 BookmarkAddedWithIdKeepsOfflineProcessingFlag) { | |
| 716 BookmarkNode::MetaInfoMap meta_info; | |
| 717 meta_info["stars.id"] = "some_id"; | |
| 718 meta_info["stars.flags"] = "1"; | |
| 719 | |
| 720 const BookmarkNode* node1 = | |
| 721 bookmark_model_->AddURLWithCreationTimeAndMetaInfo( | |
| 722 bookmark_model_->other_node(), | |
| 723 0, | |
| 724 base::ASCIIToUTF16("Some title"), | |
| 725 GURL(BOOKMARK_URL), | |
| 726 base::Time::Now(), | |
| 727 &meta_info); | |
| 728 base::RunLoop().RunUntilIdle(); | |
| 729 std::string flags_str; | |
| 730 ASSERT_TRUE(node1->GetMetaInfo("stars.flags", &flags_str)); | |
| 731 int flags; | |
| 732 ASSERT_TRUE(base::StringToInt(flags_str, &flags)); | |
| 733 EXPECT_EQ(1, (flags & 1)); | |
| 734 | |
| 735 meta_info["stars.flags"] = "0"; | |
| 736 const BookmarkNode* node2 = | |
| 737 bookmark_model_->AddURLWithCreationTimeAndMetaInfo( | |
| 738 bookmark_model_->other_node(), | |
| 739 0, | |
| 740 base::ASCIIToUTF16("Some title"), | |
| 741 GURL(BOOKMARK_URL), | |
| 742 base::Time::Now(), | |
| 743 &meta_info); | |
| 744 base::RunLoop().RunUntilIdle(); | |
| 745 ASSERT_TRUE(node2->GetMetaInfo("stars.flags", &flags_str)); | |
| 746 ASSERT_TRUE(base::StringToInt(flags_str, &flags)); | |
| 747 EXPECT_EQ(0, (flags & 1)); | |
| 748 } | |
| 749 | |
| 750 TEST_F(EnhancedBookmarkModelTest, | |
| 751 NodeRemovedWhileSetNeedsOfflineProcessingIsScheduled) { | |
| 752 const BookmarkNode* node = | |
| 753 bookmark_model_->AddURL(bookmark_model_->other_node(), | |
| 754 0, | |
| 755 base::ASCIIToUTF16("Some title"), | |
| 756 GURL(BOOKMARK_URL)); | |
| 757 bookmark_model_->Remove(node->parent(), node->parent()->GetIndexOf(node)); | |
| 758 base::RunLoop().RunUntilIdle(); | |
| 759 } | |
| 760 | |
| 761 TEST_F(EnhancedBookmarkModelTest, | 682 TEST_F(EnhancedBookmarkModelTest, |
| 762 RemoveParentShouldRemoveChildrenFromMaps) { | 683 RemoveParentShouldRemoveChildrenFromMaps) { |
| 763 const BookmarkNode* parent = AddFolder(); | 684 const BookmarkNode* parent = AddFolder(); |
| 764 const BookmarkNode* node = AddBookmark("Title", parent); | 685 const BookmarkNode* node = AddBookmark("Title", parent); |
| 765 std::string remote_id = GetId(node); | 686 std::string remote_id = GetId(node); |
| 766 EXPECT_EQ(node, model_->BookmarkForRemoteId(remote_id)); | 687 EXPECT_EQ(node, model_->BookmarkForRemoteId(remote_id)); |
| 767 | 688 |
| 768 const BookmarkNode* gp = parent->parent(); | 689 const BookmarkNode* gp = parent->parent(); |
| 769 bookmark_model_->Remove(gp, gp->GetIndexOf(parent)); | 690 bookmark_model_->Remove(gp, gp->GetIndexOf(parent)); |
| 770 EXPECT_FALSE(model_->BookmarkForRemoteId(remote_id)); | 691 EXPECT_FALSE(model_->BookmarkForRemoteId(remote_id)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 789 EXPECT_FALSE(model_->GetOriginalImage(node, &url, &width, &height)); | 710 EXPECT_FALSE(model_->GetOriginalImage(node, &url, &width, &height)); |
| 790 EXPECT_FALSE(model_->GetThumbnailImage(node, &url, &width, &height)); | 711 EXPECT_FALSE(model_->GetThumbnailImage(node, &url, &width, &height)); |
| 791 | 712 |
| 792 std::string meta_info = GetMetaInfoField(node, "stars.imageData"); | 713 std::string meta_info = GetMetaInfoField(node, "stars.imageData"); |
| 793 std::string decoded; | 714 std::string decoded; |
| 794 ASSERT_TRUE(base::Base64Decode(meta_info, &decoded)); | 715 ASSERT_TRUE(base::Base64Decode(meta_info, &decoded)); |
| 795 image::collections::ImageData data; | 716 image::collections::ImageData data; |
| 796 ASSERT_TRUE(data.ParseFromString(decoded)); | 717 ASSERT_TRUE(data.ParseFromString(decoded)); |
| 797 EXPECT_TRUE(data.user_removed_image()); | 718 EXPECT_TRUE(data.user_removed_image()); |
| 798 } | 719 } |
| OLD | NEW |