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_model.h" | 5 #include "components/bookmarks/browser/bookmark_model.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
898 const BookmarkNode* new_bb_node = | 898 const BookmarkNode* new_bb_node = |
899 model->AddFolder(bb_node, i, child->GetTitle()); | 899 model->AddFolder(bb_node, i, child->GetTitle()); |
900 PopulateBookmarkNode(child, model, new_bb_node); | 900 PopulateBookmarkNode(child, model, new_bb_node); |
901 } else { | 901 } else { |
902 model->AddURL(bb_node, i, child->GetTitle(), | 902 model->AddURL(bb_node, i, child->GetTitle(), |
903 GURL("http://" + base::UTF16ToASCII(child->GetTitle()))); | 903 GURL("http://" + base::UTF16ToASCII(child->GetTitle()))); |
904 } | 904 } |
905 } | 905 } |
906 } | 906 } |
907 | 907 |
908 // Test class that creates a BookmarkModel with a real history backend. | 908 class BookmarkModelTestClient : public testing::Test { |
tfarina
2015/05/14 00:58:53
Scott, any suggestion for a better name?
sky
2015/05/14 15:13:56
I find your new name worse. The two functions in t
tfarina
2015/05/14 23:41:18
Ah, that way is much better! I moved the member fu
| |
909 class BookmarkModelTestWithProfile : public testing::Test { | |
910 public: | 909 public: |
911 BookmarkModelTestWithProfile() {} | 910 BookmarkModelTestClient() {} |
912 | 911 |
913 protected: | 912 protected: |
914 // Verifies the contents of the bookmark bar node match the contents of the | 913 // Verifies the contents of the bookmark bar node match the contents of the |
915 // TestNode. | 914 // TestNode. |
916 void VerifyModelMatchesNode(TestNode* expected, const BookmarkNode* actual) { | 915 void VerifyModelMatchesNode(TestNode* expected, const BookmarkNode* actual) { |
917 ASSERT_EQ(expected->child_count(), actual->child_count()); | 916 ASSERT_EQ(expected->child_count(), actual->child_count()); |
918 for (int i = 0; i < expected->child_count(); ++i) { | 917 for (int i = 0; i < expected->child_count(); ++i) { |
919 TestNode* expected_child = expected->GetChild(i); | 918 TestNode* expected_child = expected->GetChild(i); |
920 const BookmarkNode* actual_child = actual->GetChild(i); | 919 const BookmarkNode* actual_child = actual->GetChild(i); |
921 ASSERT_EQ(expected_child->GetTitle(), actual_child->GetTitle()); | 920 ASSERT_EQ(expected_child->GetTitle(), actual_child->GetTitle()); |
(...skipping 14 matching lines...) Expand all Loading... | |
936 ui::TreeNodeIterator<const BookmarkNode> it(model->root_node()); | 935 ui::TreeNodeIterator<const BookmarkNode> it(model->root_node()); |
937 base::hash_set<int64> ids; | 936 base::hash_set<int64> ids; |
938 while (it.has_next()) | 937 while (it.has_next()) |
939 ASSERT_TRUE(ids.insert(it.Next()->id()).second); | 938 ASSERT_TRUE(ids.insert(it.Next()->id()).second); |
940 } | 939 } |
941 | 940 |
942 TestBookmarkClient client_; | 941 TestBookmarkClient client_; |
943 scoped_ptr<BookmarkModel> model_; | 942 scoped_ptr<BookmarkModel> model_; |
944 }; | 943 }; |
945 | 944 |
946 // Creates a set of nodes in the bookmark bar model, then recreates the | 945 // Creates a set of nodes in the bookmark model, and checks that the loaded |
947 // bookmark bar model which triggers loading from the db and checks the loaded | 946 // structure is what we first created. |
948 // structure to make sure it is what we first created. | 947 TEST_F(BookmarkModelTestClient, CreateAndRestore) { |
949 TEST_F(BookmarkModelTestWithProfile, CreateAndRestore) { | |
950 struct TestData { | 948 struct TestData { |
951 // Structure of the children of the bookmark bar model node. | 949 // Structure of the children of the bookmark model node. |
952 const std::string bbn_contents; | 950 const std::string bbn_contents; |
953 // Structure of the children of the other node. | 951 // Structure of the children of the other node. |
954 const std::string other_contents; | 952 const std::string other_contents; |
955 // Structure of the children of the synced node. | 953 // Structure of the children of the synced node. |
956 const std::string mobile_contents; | 954 const std::string mobile_contents; |
957 } data[] = { | 955 } data[] = { |
958 // See PopulateNodeFromString for a description of these strings. | 956 // See PopulateNodeFromString for a description of these strings. |
959 { "", "" }, | 957 { "", "" }, |
960 { "a", "b" }, | 958 { "a", "b" }, |
961 { "a [ b ]", "" }, | 959 { "a [ b ]", "" }, |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1188 EXPECT_FALSE(node.DeleteMetaInfo("key3")); | 1186 EXPECT_FALSE(node.DeleteMetaInfo("key3")); |
1189 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); | 1187 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); |
1190 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); | 1188 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); |
1191 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); | 1189 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); |
1192 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); | 1190 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); |
1193 EXPECT_FALSE(node.GetMetaInfoMap()); | 1191 EXPECT_FALSE(node.GetMetaInfoMap()); |
1194 } | 1192 } |
1195 | 1193 |
1196 } // namespace | 1194 } // namespace |
1197 } // namespace bookmarks | 1195 } // namespace bookmarks |
OLD | NEW |