Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(593)

Side by Side Diff: chrome/browser/bookmarks/bookmark_model_unittest.cc

Issue 1912: Renames BoomarkBarModel to BookmarkModel. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/string_util.h" 5 #include "base/string_util.h"
6 #include "chrome/browser/bookmarks/bookmark_bar_model.h" 6 #include "chrome/browser/bookmarks/bookmark_model.h"
7 #include "chrome/browser/bookmarks/bookmark_codec.h" 7 #include "chrome/browser/bookmarks/bookmark_codec.h"
8 #include "chrome/common/chrome_constants.h" 8 #include "chrome/common/chrome_constants.h"
9 #include "chrome/common/chrome_paths.h" 9 #include "chrome/common/chrome_paths.h"
10 #include "chrome/test/testing_profile.h" 10 #include "chrome/test/testing_profile.h"
11 #include "chrome/views/tree_node_model.h" 11 #include "chrome/views/tree_node_model.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 class BookmarkBarModelTest : public testing::Test, 14 class BookmarkModelTest : public testing::Test, public BookmarkModelObserver {
15 public BookmarkBarModelObserver {
16 public: 15 public:
17 struct ObserverDetails { 16 struct ObserverDetails {
18 ObserverDetails() { 17 ObserverDetails() {
19 Set(NULL, NULL, -1, -1); 18 Set(NULL, NULL, -1, -1);
20 } 19 }
21 20
22 void Set(BookmarkBarNode* node1, 21 void Set(BookmarkNode* node1,
23 BookmarkBarNode* node2, 22 BookmarkNode* node2,
24 int index1, 23 int index1,
25 int index2) { 24 int index2) {
26 this->node1 = node1; 25 this->node1 = node1;
27 this->node2 = node2; 26 this->node2 = node2;
28 this->index1 = index1; 27 this->index1 = index1;
29 this->index2 = index2; 28 this->index2 = index2;
30 } 29 }
31 30
32 void AssertEquals(BookmarkBarNode* node1, 31 void AssertEquals(BookmarkNode* node1,
33 BookmarkBarNode* node2, 32 BookmarkNode* node2,
34 int index1, 33 int index1,
35 int index2) { 34 int index2) {
36 ASSERT_TRUE(this->node1 == node1); 35 ASSERT_TRUE(this->node1 == node1);
37 ASSERT_TRUE(this->node2 == node2); 36 ASSERT_TRUE(this->node2 == node2);
38 ASSERT_EQ(index1, this->index1); 37 ASSERT_EQ(index1, this->index1);
39 ASSERT_EQ(index2, this->index2); 38 ASSERT_EQ(index2, this->index2);
40 } 39 }
41 40
42 BookmarkBarNode* node1; 41 BookmarkNode* node1;
43 BookmarkBarNode* node2; 42 BookmarkNode* node2;
44 int index1; 43 int index1;
45 int index2; 44 int index2;
46 }; 45 };
47 46
48 BookmarkBarModelTest() : model(NULL) { 47 BookmarkModelTest() : model(NULL) {
49 model.AddObserver(this); 48 model.AddObserver(this);
50 ClearCounts(); 49 ClearCounts();
51 } 50 }
52 51
53 52
54 void Loaded(BookmarkBarModel* model) { 53 void Loaded(BookmarkModel* model) {
55 // We never load from the db, so that this should never get invoked. 54 // We never load from the db, so that this should never get invoked.
56 NOTREACHED(); 55 NOTREACHED();
57 } 56 }
58 57
59 virtual void BookmarkNodeMoved(BookmarkBarModel* model, 58 virtual void BookmarkNodeMoved(BookmarkModel* model,
60 BookmarkBarNode* old_parent, 59 BookmarkNode* old_parent,
61 int old_index, 60 int old_index,
62 BookmarkBarNode* new_parent, 61 BookmarkNode* new_parent,
63 int new_index) { 62 int new_index) {
64 moved_count++; 63 moved_count++;
65 observer_details.Set(old_parent, new_parent, old_index, new_index); 64 observer_details.Set(old_parent, new_parent, old_index, new_index);
66 } 65 }
67 66
68 virtual void BookmarkNodeAdded(BookmarkBarModel* model, 67 virtual void BookmarkNodeAdded(BookmarkModel* model,
69 BookmarkBarNode* parent, 68 BookmarkNode* parent,
70 int index) { 69 int index) {
71 added_count++; 70 added_count++;
72 observer_details.Set(parent, NULL, index, -1); 71 observer_details.Set(parent, NULL, index, -1);
73 } 72 }
74 73
75 virtual void BookmarkNodeRemoved(BookmarkBarModel* model, 74 virtual void BookmarkNodeRemoved(BookmarkModel* model,
76 BookmarkBarNode* parent, 75 BookmarkNode* parent,
77 int index) { 76 int index) {
78 removed_count++; 77 removed_count++;
79 observer_details.Set(parent, NULL, index, -1); 78 observer_details.Set(parent, NULL, index, -1);
80 } 79 }
81 80
82 virtual void BookmarkNodeChanged(BookmarkBarModel* model, 81 virtual void BookmarkNodeChanged(BookmarkModel* model,
83 BookmarkBarNode* node) { 82 BookmarkNode* node) {
84 changed_count++; 83 changed_count++;
85 observer_details.Set(node, NULL, -1, -1); 84 observer_details.Set(node, NULL, -1, -1);
86 } 85 }
87 86
88 virtual void BookmarkNodeFavIconLoaded(BookmarkBarModel* model, 87 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
89 BookmarkBarNode* node) { 88 BookmarkNode* node) {
90 // We never attempt to load favicons, so that this method never 89 // We never attempt to load favicons, so that this method never
91 // gets invoked. 90 // gets invoked.
92 } 91 }
93 92
94 void ClearCounts() { 93 void ClearCounts() {
95 moved_count = added_count = removed_count = changed_count = 0; 94 moved_count = added_count = removed_count = changed_count = 0;
96 } 95 }
97 96
98 void AssertObserverCount(int added_count, 97 void AssertObserverCount(int added_count,
99 int moved_count, 98 int moved_count,
100 int removed_count, 99 int removed_count,
101 int changed_count) { 100 int changed_count) {
102 ASSERT_EQ(added_count, this->added_count); 101 ASSERT_EQ(added_count, this->added_count);
103 ASSERT_EQ(moved_count, this->moved_count); 102 ASSERT_EQ(moved_count, this->moved_count);
104 ASSERT_EQ(removed_count, this->removed_count); 103 ASSERT_EQ(removed_count, this->removed_count);
105 ASSERT_EQ(changed_count, this->changed_count); 104 ASSERT_EQ(changed_count, this->changed_count);
106 } 105 }
107 106
108 void AssertNodesEqual(BookmarkBarNode* expected, BookmarkBarNode* actual) { 107 void AssertNodesEqual(BookmarkNode* expected, BookmarkNode* actual) {
109 ASSERT_TRUE(expected); 108 ASSERT_TRUE(expected);
110 ASSERT_TRUE(actual); 109 ASSERT_TRUE(actual);
111 EXPECT_EQ(expected->GetTitle(), actual->GetTitle()); 110 EXPECT_EQ(expected->GetTitle(), actual->GetTitle());
112 EXPECT_EQ(expected->GetType(), actual->GetType()); 111 EXPECT_EQ(expected->GetType(), actual->GetType());
113 EXPECT_TRUE(expected->date_added() == actual->date_added()); 112 EXPECT_TRUE(expected->date_added() == actual->date_added());
114 if (expected->GetType() == history::StarredEntry::URL) { 113 if (expected->GetType() == history::StarredEntry::URL) {
115 EXPECT_EQ(expected->GetURL(), actual->GetURL()); 114 EXPECT_EQ(expected->GetURL(), actual->GetURL());
116 } else { 115 } else {
117 EXPECT_TRUE(expected->date_group_modified() == 116 EXPECT_TRUE(expected->date_group_modified() ==
118 actual->date_group_modified()); 117 actual->date_group_modified());
119 ASSERT_EQ(expected->GetChildCount(), actual->GetChildCount()); 118 ASSERT_EQ(expected->GetChildCount(), actual->GetChildCount());
120 for (int i = 0; i < expected->GetChildCount(); ++i) 119 for (int i = 0; i < expected->GetChildCount(); ++i)
121 AssertNodesEqual(expected->GetChild(i), actual->GetChild(i)); 120 AssertNodesEqual(expected->GetChild(i), actual->GetChild(i));
122 } 121 }
123 } 122 }
124 123
125 void AssertModelsEqual(BookmarkBarModel* expected, 124 void AssertModelsEqual(BookmarkModel* expected,
126 BookmarkBarModel* actual) { 125 BookmarkModel* actual) {
127 AssertNodesEqual(expected->GetBookmarkBarNode(), 126 AssertNodesEqual(expected->GetBookmarkBarNode(),
128 actual->GetBookmarkBarNode()); 127 actual->GetBookmarkBarNode());
129 AssertNodesEqual(expected->other_node(), 128 AssertNodesEqual(expected->other_node(),
130 actual->other_node()); 129 actual->other_node());
131 } 130 }
132 131
133 BookmarkBarModel model; 132 BookmarkModel model;
134 133
135 int moved_count; 134 int moved_count;
136 135
137 int added_count; 136 int added_count;
138 137
139 int removed_count; 138 int removed_count;
140 139
141 int changed_count; 140 int changed_count;
142 141
143 ObserverDetails observer_details; 142 ObserverDetails observer_details;
144 }; 143 };
145 144
146 TEST_F(BookmarkBarModelTest, InitialState) { 145 TEST_F(BookmarkModelTest, InitialState) {
147 BookmarkBarNode* bb_node = model.GetBookmarkBarNode(); 146 BookmarkNode* bb_node = model.GetBookmarkBarNode();
148 ASSERT_TRUE(bb_node != NULL); 147 ASSERT_TRUE(bb_node != NULL);
149 EXPECT_EQ(0, bb_node->GetChildCount()); 148 EXPECT_EQ(0, bb_node->GetChildCount());
150 EXPECT_EQ(history::StarredEntry::BOOKMARK_BAR, bb_node->GetType()); 149 EXPECT_EQ(history::StarredEntry::BOOKMARK_BAR, bb_node->GetType());
151 150
152 BookmarkBarNode* other_node = model.other_node(); 151 BookmarkNode* other_node = model.other_node();
153 ASSERT_TRUE(other_node != NULL); 152 ASSERT_TRUE(other_node != NULL);
154 EXPECT_EQ(0, other_node->GetChildCount()); 153 EXPECT_EQ(0, other_node->GetChildCount());
155 EXPECT_EQ(history::StarredEntry::OTHER, other_node->GetType()); 154 EXPECT_EQ(history::StarredEntry::OTHER, other_node->GetType());
156 155
157 EXPECT_TRUE(bb_node->id() != other_node->id()); 156 EXPECT_TRUE(bb_node->id() != other_node->id());
158 } 157 }
159 158
160 TEST_F(BookmarkBarModelTest, AddURL) { 159 TEST_F(BookmarkModelTest, AddURL) {
161 BookmarkBarNode* root = model.GetBookmarkBarNode(); 160 BookmarkNode* root = model.GetBookmarkBarNode();
162 const std::wstring title(L"foo"); 161 const std::wstring title(L"foo");
163 const GURL url("http://foo.com"); 162 const GURL url("http://foo.com");
164 163
165 BookmarkBarNode* new_node = model.AddURL(root, 0, title, url); 164 BookmarkNode* new_node = model.AddURL(root, 0, title, url);
166 AssertObserverCount(1, 0, 0, 0); 165 AssertObserverCount(1, 0, 0, 0);
167 observer_details.AssertEquals(root, NULL, 0, -1); 166 observer_details.AssertEquals(root, NULL, 0, -1);
168 167
169 ASSERT_EQ(1, root->GetChildCount()); 168 ASSERT_EQ(1, root->GetChildCount());
170 ASSERT_EQ(title, new_node->GetTitle()); 169 ASSERT_EQ(title, new_node->GetTitle());
171 ASSERT_TRUE(url == new_node->GetURL()); 170 ASSERT_TRUE(url == new_node->GetURL());
172 ASSERT_EQ(history::StarredEntry::URL, new_node->GetType()); 171 ASSERT_EQ(history::StarredEntry::URL, new_node->GetType());
173 ASSERT_TRUE(new_node == model.GetNodeByURL(url)); 172 ASSERT_TRUE(new_node == model.GetNodeByURL(url));
174 173
175 EXPECT_TRUE(new_node->id() != root->id() && 174 EXPECT_TRUE(new_node->id() != root->id() &&
176 new_node->id() != model.other_node()->id()); 175 new_node->id() != model.other_node()->id());
177 } 176 }
178 177
179 TEST_F(BookmarkBarModelTest, AddGroup) { 178 TEST_F(BookmarkModelTest, AddGroup) {
180 BookmarkBarNode* root = model.GetBookmarkBarNode(); 179 BookmarkNode* root = model.GetBookmarkBarNode();
181 const std::wstring title(L"foo"); 180 const std::wstring title(L"foo");
182 181
183 BookmarkBarNode* new_node = model.AddGroup(root, 0, title); 182 BookmarkNode* new_node = model.AddGroup(root, 0, title);
184 AssertObserverCount(1, 0, 0, 0); 183 AssertObserverCount(1, 0, 0, 0);
185 observer_details.AssertEquals(root, NULL, 0, -1); 184 observer_details.AssertEquals(root, NULL, 0, -1);
186 185
187 ASSERT_EQ(1, root->GetChildCount()); 186 ASSERT_EQ(1, root->GetChildCount());
188 ASSERT_EQ(title, new_node->GetTitle()); 187 ASSERT_EQ(title, new_node->GetTitle());
189 ASSERT_EQ(history::StarredEntry::USER_GROUP, new_node->GetType()); 188 ASSERT_EQ(history::StarredEntry::USER_GROUP, new_node->GetType());
190 189
191 EXPECT_TRUE(new_node->id() != root->id() && 190 EXPECT_TRUE(new_node->id() != root->id() &&
192 new_node->id() != model.other_node()->id()); 191 new_node->id() != model.other_node()->id());
193 192
194 // Add another group, just to make sure group_ids are incremented correctly. 193 // Add another group, just to make sure group_ids are incremented correctly.
195 ClearCounts(); 194 ClearCounts();
196 BookmarkBarNode* new_node2 = model.AddGroup(root, 0, title); 195 BookmarkNode* new_node2 = model.AddGroup(root, 0, title);
197 AssertObserverCount(1, 0, 0, 0); 196 AssertObserverCount(1, 0, 0, 0);
198 observer_details.AssertEquals(root, NULL, 0, -1); 197 observer_details.AssertEquals(root, NULL, 0, -1);
199 } 198 }
200 199
201 TEST_F(BookmarkBarModelTest, RemoveURL) { 200 TEST_F(BookmarkModelTest, RemoveURL) {
202 BookmarkBarNode* root = model.GetBookmarkBarNode(); 201 BookmarkNode* root = model.GetBookmarkBarNode();
203 const std::wstring title(L"foo"); 202 const std::wstring title(L"foo");
204 const GURL url("http://foo.com"); 203 const GURL url("http://foo.com");
205 BookmarkBarNode* new_node = model.AddURL(root, 0, title, url); 204 BookmarkNode* new_node = model.AddURL(root, 0, title, url);
206 ClearCounts(); 205 ClearCounts();
207 206
208 model.Remove(root, 0); 207 model.Remove(root, 0);
209 ASSERT_EQ(0, root->GetChildCount()); 208 ASSERT_EQ(0, root->GetChildCount());
210 AssertObserverCount(0, 0, 1, 0); 209 AssertObserverCount(0, 0, 1, 0);
211 observer_details.AssertEquals(root, NULL, 0, -1); 210 observer_details.AssertEquals(root, NULL, 0, -1);
212 211
213 // Make sure there is no mapping for the URL. 212 // Make sure there is no mapping for the URL.
214 ASSERT_TRUE(model.GetNodeByURL(url) == NULL); 213 ASSERT_TRUE(model.GetNodeByURL(url) == NULL);
215 } 214 }
216 215
217 TEST_F(BookmarkBarModelTest, RemoveGroup) { 216 TEST_F(BookmarkModelTest, RemoveGroup) {
218 BookmarkBarNode* root = model.GetBookmarkBarNode(); 217 BookmarkNode* root = model.GetBookmarkBarNode();
219 BookmarkBarNode* group = model.AddGroup(root, 0, L"foo"); 218 BookmarkNode* group = model.AddGroup(root, 0, L"foo");
220 219
221 ClearCounts(); 220 ClearCounts();
222 221
223 // Add a URL as a child. 222 // Add a URL as a child.
224 const std::wstring title(L"foo"); 223 const std::wstring title(L"foo");
225 const GURL url("http://foo.com"); 224 const GURL url("http://foo.com");
226 BookmarkBarNode* new_node = model.AddURL(group, 0, title, url); 225 BookmarkNode* new_node = model.AddURL(group, 0, title, url);
227 226
228 ClearCounts(); 227 ClearCounts();
229 228
230 // Now remove the group. 229 // Now remove the group.
231 model.Remove(root, 0); 230 model.Remove(root, 0);
232 ASSERT_EQ(0, root->GetChildCount()); 231 ASSERT_EQ(0, root->GetChildCount());
233 AssertObserverCount(0, 0, 1, 0); 232 AssertObserverCount(0, 0, 1, 0);
234 observer_details.AssertEquals(root, NULL, 0, -1); 233 observer_details.AssertEquals(root, NULL, 0, -1);
235 234
236 // Make sure there is no mapping for the URL. 235 // Make sure there is no mapping for the URL.
237 ASSERT_TRUE(model.GetNodeByURL(url) == NULL); 236 ASSERT_TRUE(model.GetNodeByURL(url) == NULL);
238 } 237 }
239 238
240 TEST_F(BookmarkBarModelTest, SetTitle) { 239 TEST_F(BookmarkModelTest, SetTitle) {
241 BookmarkBarNode* root = model.GetBookmarkBarNode(); 240 BookmarkNode* root = model.GetBookmarkBarNode();
242 std::wstring title(L"foo"); 241 std::wstring title(L"foo");
243 const GURL url("http://foo.com"); 242 const GURL url("http://foo.com");
244 BookmarkBarNode* node = model.AddURL(root, 0, title, url); 243 BookmarkNode* node = model.AddURL(root, 0, title, url);
245 244
246 ClearCounts(); 245 ClearCounts();
247 246
248 title = L"foo2"; 247 title = L"foo2";
249 model.SetTitle(node, title); 248 model.SetTitle(node, title);
250 AssertObserverCount(0, 0, 0, 1); 249 AssertObserverCount(0, 0, 0, 1);
251 observer_details.AssertEquals(node, NULL, -1, -1); 250 observer_details.AssertEquals(node, NULL, -1, -1);
252 EXPECT_EQ(title, node->GetTitle()); 251 EXPECT_EQ(title, node->GetTitle());
253 } 252 }
254 253
255 TEST_F(BookmarkBarModelTest, Move) { 254 TEST_F(BookmarkModelTest, Move) {
256 BookmarkBarNode* root = model.GetBookmarkBarNode(); 255 BookmarkNode* root = model.GetBookmarkBarNode();
257 std::wstring title(L"foo"); 256 std::wstring title(L"foo");
258 const GURL url("http://foo.com"); 257 const GURL url("http://foo.com");
259 BookmarkBarNode* node = model.AddURL(root, 0, title, url); 258 BookmarkNode* node = model.AddURL(root, 0, title, url);
260 BookmarkBarNode* group1 = model.AddGroup(root, 0, L"foo"); 259 BookmarkNode* group1 = model.AddGroup(root, 0, L"foo");
261 ClearCounts(); 260 ClearCounts();
262 261
263 model.Move(node, group1, 0); 262 model.Move(node, group1, 0);
264 263
265 AssertObserverCount(0, 1, 0, 0); 264 AssertObserverCount(0, 1, 0, 0);
266 observer_details.AssertEquals(root, group1, 1, 0); 265 observer_details.AssertEquals(root, group1, 1, 0);
267 EXPECT_TRUE(group1 == node->GetParent()); 266 EXPECT_TRUE(group1 == node->GetParent());
268 EXPECT_EQ(1, root->GetChildCount()); 267 EXPECT_EQ(1, root->GetChildCount());
269 EXPECT_EQ(group1, root->GetChild(0)); 268 EXPECT_EQ(group1, root->GetChild(0));
270 EXPECT_EQ(1, group1->GetChildCount()); 269 EXPECT_EQ(1, group1->GetChildCount());
271 EXPECT_EQ(node, group1->GetChild(0)); 270 EXPECT_EQ(node, group1->GetChild(0));
272 271
273 // And remove the group. 272 // And remove the group.
274 ClearCounts(); 273 ClearCounts();
275 model.Remove(root, 0); 274 model.Remove(root, 0);
276 AssertObserverCount(0, 0, 1, 0); 275 AssertObserverCount(0, 0, 1, 0);
277 observer_details.AssertEquals(root, NULL, 0, -1); 276 observer_details.AssertEquals(root, NULL, 0, -1);
278 EXPECT_TRUE(model.GetNodeByURL(url) == NULL); 277 EXPECT_TRUE(model.GetNodeByURL(url) == NULL);
279 EXPECT_EQ(0, root->GetChildCount()); 278 EXPECT_EQ(0, root->GetChildCount());
280 } 279 }
281 280
282 // Tests that adding a URL to a folder updates the last modified time. 281 // Tests that adding a URL to a folder updates the last modified time.
283 TEST_F(BookmarkBarModelTest, ParentForNewNodes) { 282 TEST_F(BookmarkModelTest, ParentForNewNodes) {
284 ASSERT_EQ(model.GetBookmarkBarNode(), model.GetParentForNewNodes()); 283 ASSERT_EQ(model.GetBookmarkBarNode(), model.GetParentForNewNodes());
285 284
286 const std::wstring title(L"foo"); 285 const std::wstring title(L"foo");
287 const GURL url("http://foo.com"); 286 const GURL url("http://foo.com");
288 287
289 BookmarkBarNode* new_node = 288 BookmarkNode* new_node = model.AddURL(model.other_node(), 0, title, url);
290 model.AddURL(model.other_node(), 0, title, url);
291 289
292 ASSERT_EQ(model.other_node(), model.GetParentForNewNodes()); 290 ASSERT_EQ(model.other_node(), model.GetParentForNewNodes());
293 } 291 }
294 292
295 // Make sure recently modified stays in sync when adding a URL. 293 // Make sure recently modified stays in sync when adding a URL.
296 TEST_F(BookmarkBarModelTest, MostRecentlyModifiedGroups) { 294 TEST_F(BookmarkModelTest, MostRecentlyModifiedGroups) {
297 // Add a group. 295 // Add a group.
298 BookmarkBarNode* group = model.AddGroup(model.other_node(), 0, L"foo"); 296 BookmarkNode* group = model.AddGroup(model.other_node(), 0, L"foo");
299 // Add a URL to it. 297 // Add a URL to it.
300 model.AddURL(group, 0, L"blah", GURL("http://foo.com")); 298 model.AddURL(group, 0, L"blah", GURL("http://foo.com"));
301 299
302 // Make sure group is in the most recently modified. 300 // Make sure group is in the most recently modified.
303 std::vector<BookmarkBarNode*> most_recent_groups = 301 std::vector<BookmarkNode*> most_recent_groups =
304 model.GetMostRecentlyModifiedGroups(1); 302 model.GetMostRecentlyModifiedGroups(1);
305 ASSERT_EQ(1, most_recent_groups.size()); 303 ASSERT_EQ(1, most_recent_groups.size());
306 ASSERT_EQ(group, most_recent_groups[0]); 304 ASSERT_EQ(group, most_recent_groups[0]);
307 305
308 // Nuke the group and do another fetch, making sure group isn't in the 306 // Nuke the group and do another fetch, making sure group isn't in the
309 // returned list. 307 // returned list.
310 model.Remove(group->GetParent(), 0); 308 model.Remove(group->GetParent(), 0);
311 most_recent_groups = model.GetMostRecentlyModifiedGroups(1); 309 most_recent_groups = model.GetMostRecentlyModifiedGroups(1);
312 ASSERT_EQ(1, most_recent_groups.size()); 310 ASSERT_EQ(1, most_recent_groups.size());
313 ASSERT_TRUE(most_recent_groups[0] != group); 311 ASSERT_TRUE(most_recent_groups[0] != group);
314 } 312 }
315 313
316 // Make sure MostRecentlyAddedEntries stays in sync. 314 // Make sure MostRecentlyAddedEntries stays in sync.
317 TEST_F(BookmarkBarModelTest, MostRecentlyAddedEntries) { 315 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) {
318 // Add a couple of nodes such that the following holds for the time of the 316 // Add a couple of nodes such that the following holds for the time of the
319 // nodes: n1 > n2 > n3 > n4. 317 // nodes: n1 > n2 > n3 > n4.
320 Time base_time = Time::Now(); 318 Time base_time = Time::Now();
321 BookmarkBarNode* n1 = model.AddURL( 319 BookmarkNode* n1 = model.AddURL(
322 model.GetBookmarkBarNode(), 0, L"blah", GURL("http://foo.com/0")); 320 model.GetBookmarkBarNode(), 0, L"blah", GURL("http://foo.com/0"));
323 BookmarkBarNode* n2 = model.AddURL( 321 BookmarkNode* n2 = model.AddURL(
324 model.GetBookmarkBarNode(), 1, L"blah", GURL("http://foo.com/1")); 322 model.GetBookmarkBarNode(), 1, L"blah", GURL("http://foo.com/1"));
325 BookmarkBarNode* n3 = model.AddURL( 323 BookmarkNode* n3 = model.AddURL(
326 model.GetBookmarkBarNode(), 2, L"blah", GURL("http://foo.com/2")); 324 model.GetBookmarkBarNode(), 2, L"blah", GURL("http://foo.com/2"));
327 BookmarkBarNode* n4 = model.AddURL( 325 BookmarkNode* n4 = model.AddURL(
328 model.GetBookmarkBarNode(), 3, L"blah", GURL("http://foo.com/3")); 326 model.GetBookmarkBarNode(), 3, L"blah", GURL("http://foo.com/3"));
329 n1->date_added_ = base_time + TimeDelta::FromDays(4); 327 n1->date_added_ = base_time + TimeDelta::FromDays(4);
330 n2->date_added_ = base_time + TimeDelta::FromDays(3); 328 n2->date_added_ = base_time + TimeDelta::FromDays(3);
331 n3->date_added_ = base_time + TimeDelta::FromDays(2); 329 n3->date_added_ = base_time + TimeDelta::FromDays(2);
332 n4->date_added_ = base_time + TimeDelta::FromDays(1); 330 n4->date_added_ = base_time + TimeDelta::FromDays(1);
333 331
334 // Make sure order is honored. 332 // Make sure order is honored.
335 std::vector<BookmarkBarNode*> recently_added; 333 std::vector<BookmarkNode*> recently_added;
336 model.GetMostRecentlyAddedEntries(2, &recently_added); 334 model.GetMostRecentlyAddedEntries(2, &recently_added);
337 ASSERT_EQ(2, recently_added.size()); 335 ASSERT_EQ(2, recently_added.size());
338 ASSERT_TRUE(n1 == recently_added[0]); 336 ASSERT_TRUE(n1 == recently_added[0]);
339 ASSERT_TRUE(n2 == recently_added[1]); 337 ASSERT_TRUE(n2 == recently_added[1]);
340 338
341 // swap 1 and 2, then check again. 339 // swap 1 and 2, then check again.
342 recently_added.clear(); 340 recently_added.clear();
343 std::swap(n1->date_added_, n2->date_added_); 341 std::swap(n1->date_added_, n2->date_added_);
344 model.GetMostRecentlyAddedEntries(4, &recently_added); 342 model.GetMostRecentlyAddedEntries(4, &recently_added);
345 ASSERT_EQ(4, recently_added.size()); 343 ASSERT_EQ(4, recently_added.size());
346 ASSERT_TRUE(n2 == recently_added[0]); 344 ASSERT_TRUE(n2 == recently_added[0]);
347 ASSERT_TRUE(n1 == recently_added[1]); 345 ASSERT_TRUE(n1 == recently_added[1]);
348 ASSERT_TRUE(n3 == recently_added[2]); 346 ASSERT_TRUE(n3 == recently_added[2]);
349 ASSERT_TRUE(n4 == recently_added[3]); 347 ASSERT_TRUE(n4 == recently_added[3]);
350 } 348 }
351 349
352 // Makes sure GetBookmarksMatchingText works. 350 // Makes sure GetBookmarksMatchingText works.
353 TEST_F(BookmarkBarModelTest, GetBookmarksMatchingText) { 351 TEST_F(BookmarkModelTest, GetBookmarksMatchingText) {
354 // Add two urls with titles 'blah' and 'x' and one folder with the title 352 // Add two urls with titles 'blah' and 'x' and one folder with the title
355 // 'blah'. 353 // 'blah'.
356 BookmarkBarNode* n1 = model.AddURL( 354 BookmarkNode* n1 = model.AddURL(
357 model.GetBookmarkBarNode(), 0, L"blah", GURL("http://foo.com/0")); 355 model.GetBookmarkBarNode(), 0, L"blah", GURL("http://foo.com/0"));
358 BookmarkBarNode* n2 = model.AddURL( 356 BookmarkNode* n2 = model.AddURL(
359 model.GetBookmarkBarNode(), 1, L"x", GURL("http://foo.com/1")); 357 model.GetBookmarkBarNode(), 1, L"x", GURL("http://foo.com/1"));
360 model.AddGroup(model.GetBookmarkBarNode(), 2, L"blah"); 358 model.AddGroup(model.GetBookmarkBarNode(), 2, L"blah");
361 359
362 // Make sure we don't get back the folder. 360 // Make sure we don't get back the folder.
363 std::vector<BookmarkBarModel::TitleMatch> results; 361 std::vector<BookmarkModel::TitleMatch> results;
364 model.GetBookmarksMatchingText(L"blah", 2, &results); 362 model.GetBookmarksMatchingText(L"blah", 2, &results);
365 ASSERT_EQ(1U, results.size()); 363 ASSERT_EQ(1U, results.size());
366 EXPECT_EQ(n1, results[0].node); 364 EXPECT_EQ(n1, results[0].node);
367 results.clear(); 365 results.clear();
368 366
369 model.GetBookmarksMatchingText(L"x", 2, &results); 367 model.GetBookmarksMatchingText(L"x", 2, &results);
370 ASSERT_EQ(1U, results.size()); 368 ASSERT_EQ(1U, results.size());
371 EXPECT_EQ(n2, results[0].node); 369 EXPECT_EQ(n2, results[0].node);
372 } 370 }
373 371
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // NOTE: each name must be unique, and groups are assigned a unique title by way 427 // NOTE: each name must be unique, and groups are assigned a unique title by way
430 // of an increasing integer. 428 // of an increasing integer.
431 static void PopulateNodeFromString(const std::wstring& description, 429 static void PopulateNodeFromString(const std::wstring& description,
432 TestNode* parent) { 430 TestNode* parent) {
433 std::vector<std::wstring> elements; 431 std::vector<std::wstring> elements;
434 size_t index = 0; 432 size_t index = 0;
435 SplitStringAlongWhitespace(description, &elements); 433 SplitStringAlongWhitespace(description, &elements);
436 PopulateNodeImpl(elements, &index, parent); 434 PopulateNodeImpl(elements, &index, parent);
437 } 435 }
438 436
439 // Populates the BookmarkBarNode with the children of parent. 437 // Populates the BookmarkNode with the children of parent.
440 static void PopulateBookmarkBarNode(TestNode* parent, 438 static void PopulateBookmarkNode(TestNode* parent,
441 BookmarkBarModel* model, 439 BookmarkModel* model,
442 BookmarkBarNode* bb_node) { 440 BookmarkNode* bb_node) {
443 for (int i = 0; i < parent->GetChildCount(); ++i) { 441 for (int i = 0; i < parent->GetChildCount(); ++i) {
444 TestNode* child = parent->GetChild(i); 442 TestNode* child = parent->GetChild(i);
445 if (child->value == history::StarredEntry::USER_GROUP) { 443 if (child->value == history::StarredEntry::USER_GROUP) {
446 BookmarkBarNode* new_bb_node = 444 BookmarkNode* new_bb_node =
447 model->AddGroup(bb_node, i, child->GetTitle()); 445 model->AddGroup(bb_node, i, child->GetTitle());
448 PopulateBookmarkBarNode(child, model, new_bb_node); 446 PopulateBookmarkNode(child, model, new_bb_node);
449 } else { 447 } else {
450 model->AddURL(bb_node, i, child->GetTitle(), 448 model->AddURL(bb_node, i, child->GetTitle(),
451 GURL("http://" + WideToASCII(child->GetTitle()))); 449 GURL("http://" + WideToASCII(child->GetTitle())));
452 } 450 }
453 } 451 }
454 } 452 }
455 453
456 } // namespace 454 } // namespace
457 455
458 // Test class that creates a BookmarkBarModel with a real history backend. 456 // Test class that creates a BookmarkModel with a real history backend.
459 class BookmarkBarModelTestWithProfile : public testing::Test, 457 class BookmarkModelTestWithProfile : public testing::Test,
460 public BookmarkBarModelObserver { 458 public BookmarkModelObserver {
461 public: 459 public:
462 virtual void SetUp() { 460 virtual void SetUp() {
463 } 461 }
464 462
465 virtual void TearDown() { 463 virtual void TearDown() {
466 profile_.reset(NULL); 464 profile_.reset(NULL);
467 } 465 }
468 466
469 // The profile. 467 // The profile.
470 scoped_ptr<TestingProfile> profile_; 468 scoped_ptr<TestingProfile> profile_;
471 469
472 protected: 470 protected:
473 // Verifies the contents of the bookmark bar node match the contents of the 471 // Verifies the contents of the bookmark bar node match the contents of the
474 // TestNode. 472 // TestNode.
475 void VerifyModelMatchesNode(TestNode* expected, BookmarkBarNode* actual) { 473 void VerifyModelMatchesNode(TestNode* expected, BookmarkNode* actual) {
476 ASSERT_EQ(expected->GetChildCount(), actual->GetChildCount()); 474 ASSERT_EQ(expected->GetChildCount(), actual->GetChildCount());
477 for (int i = 0; i < expected->GetChildCount(); ++i) { 475 for (int i = 0; i < expected->GetChildCount(); ++i) {
478 TestNode* expected_child = expected->GetChild(i); 476 TestNode* expected_child = expected->GetChild(i);
479 BookmarkBarNode* actual_child = actual->GetChild(i); 477 BookmarkNode* actual_child = actual->GetChild(i);
480 ASSERT_EQ(expected_child->GetTitle(), actual_child->GetTitle()); 478 ASSERT_EQ(expected_child->GetTitle(), actual_child->GetTitle());
481 if (expected_child->value == history::StarredEntry::USER_GROUP) { 479 if (expected_child->value == history::StarredEntry::USER_GROUP) {
482 ASSERT_TRUE(actual_child->GetType() == 480 ASSERT_TRUE(actual_child->GetType() ==
483 history::StarredEntry::USER_GROUP); 481 history::StarredEntry::USER_GROUP);
484 // Recurse throught children. 482 // Recurse throught children.
485 VerifyModelMatchesNode(expected_child, actual_child); 483 VerifyModelMatchesNode(expected_child, actual_child);
486 if (HasFatalFailure()) 484 if (HasFatalFailure())
487 return; 485 return;
488 } else { 486 } else {
489 // No need to check the URL, just the title is enough. 487 // No need to check the URL, just the title is enough.
490 ASSERT_TRUE(actual_child->GetType() == 488 ASSERT_TRUE(actual_child->GetType() ==
491 history::StarredEntry::URL); 489 history::StarredEntry::URL);
492 } 490 }
493 } 491 }
494 } 492 }
495 493
496 void BlockTillBookmarkModelLoaded() { 494 void BlockTillBookmarkModelLoaded() {
497 bb_model_ = profile_->GetBookmarkBarModel(); 495 bb_model_ = profile_->GetBookmarkModel();
498 if (!bb_model_->IsLoaded()) 496 if (!bb_model_->IsLoaded())
499 BlockTillLoaded(bb_model_); 497 BlockTillLoaded(bb_model_);
500 else 498 else
501 bb_model_->AddObserver(this); 499 bb_model_->AddObserver(this);
502 } 500 }
503 501
504 // Destroys the current profile, creates a new one and creates the history 502 // Destroys the current profile, creates a new one and creates the history
505 // service. 503 // service.
506 void RecreateProfile() { 504 void RecreateProfile() {
507 // Need to shutdown the old one before creating a new one. 505 // Need to shutdown the old one before creating a new one.
508 profile_.reset(NULL); 506 profile_.reset(NULL);
509 profile_.reset(new TestingProfile()); 507 profile_.reset(new TestingProfile());
510 profile_->CreateHistoryService(true); 508 profile_->CreateHistoryService(true);
511 } 509 }
512 510
513 BookmarkBarModel* bb_model_; 511 BookmarkModel* bb_model_;
514 512
515 private: 513 private:
516 // Blocks until the BookmarkBarModel has finished loading. 514 // Blocks until the BookmarkModel has finished loading.
517 void BlockTillLoaded(BookmarkBarModel* model) { 515 void BlockTillLoaded(BookmarkModel* model) {
518 model->AddObserver(this); 516 model->AddObserver(this);
519 MessageLoop::current()->Run(); 517 MessageLoop::current()->Run();
520 } 518 }
521 519
522 // BookmarkBarModelObserver methods. 520 // BookmarkModelObserver methods.
523 virtual void Loaded(BookmarkBarModel* model) { 521 virtual void Loaded(BookmarkModel* model) {
524 // Balances the call in BlockTillLoaded. 522 // Balances the call in BlockTillLoaded.
525 MessageLoop::current()->Quit(); 523 MessageLoop::current()->Quit();
526 } 524 }
527 virtual void BookmarkNodeMoved(BookmarkBarModel* model, 525 virtual void BookmarkNodeMoved(BookmarkModel* model,
528 BookmarkBarNode* old_parent, 526 BookmarkNode* old_parent,
529 int old_index, 527 int old_index,
530 BookmarkBarNode* new_parent, 528 BookmarkNode* new_parent,
531 int new_index) {} 529 int new_index) {}
532 virtual void BookmarkNodeAdded(BookmarkBarModel* model, 530 virtual void BookmarkNodeAdded(BookmarkModel* model,
533 BookmarkBarNode* parent, 531 BookmarkNode* parent,
534 int index) {} 532 int index) {}
535 virtual void BookmarkNodeRemoved(BookmarkBarModel* model, 533 virtual void BookmarkNodeRemoved(BookmarkModel* model,
536 BookmarkBarNode* parent, 534 BookmarkNode* parent,
537 int index) {} 535 int index) {}
538 virtual void BookmarkNodeChanged(BookmarkBarModel* model, 536 virtual void BookmarkNodeChanged(BookmarkModel* model,
539 BookmarkBarNode* node) {} 537 BookmarkNode* node) {}
540 virtual void BookmarkNodeFavIconLoaded(BookmarkBarModel* model, 538 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
541 BookmarkBarNode* node) {} 539 BookmarkNode* node) {}
542 540
543 MessageLoopForUI message_loop_; 541 MessageLoopForUI message_loop_;
544 }; 542 };
545 543
546 // Creates a set of nodes in the bookmark bar model, then recreates the 544 // Creates a set of nodes in the bookmark bar model, then recreates the
547 // bookmark bar model which triggers loading from the db and checks the loaded 545 // bookmark bar model which triggers loading from the db and checks the loaded
548 // structure to make sure it is what we first created. 546 // structure to make sure it is what we first created.
549 TEST_F(BookmarkBarModelTestWithProfile, CreateAndRestore) { 547 TEST_F(BookmarkModelTestWithProfile, CreateAndRestore) {
550 struct TestData { 548 struct TestData {
551 // Structure of the children of the bookmark bar model node. 549 // Structure of the children of the bookmark bar model node.
552 const std::wstring bbn_contents; 550 const std::wstring bbn_contents;
553 // Structure of the children of the other node. 551 // Structure of the children of the other node.
554 const std::wstring other_contents; 552 const std::wstring other_contents;
555 } data[] = { 553 } data[] = {
556 // See PopulateNodeFromString for a description of these strings. 554 // See PopulateNodeFromString for a description of these strings.
557 { L"", L"" }, 555 { L"", L"" },
558 { L"a", L"b" }, 556 { L"a", L"b" },
559 { L"a [ b ]", L"" }, 557 { L"a [ b ]", L"" },
560 { L"", L"[ b ] a [ c [ d e [ f ] ] ]" }, 558 { L"", L"[ b ] a [ c [ d e [ f ] ] ]" },
561 { L"a [ b ]", L"" }, 559 { L"a [ b ]", L"" },
562 { L"a b c [ d e [ f ] ]", L"g h i [ j k [ l ] ]"}, 560 { L"a b c [ d e [ f ] ]", L"g h i [ j k [ l ] ]"},
563 }; 561 };
564 for (int i = 0; i < arraysize(data); ++i) { 562 for (int i = 0; i < arraysize(data); ++i) {
565 // Recreate the profile. We need to reset with NULL first so that the last 563 // Recreate the profile. We need to reset with NULL first so that the last
566 // HistoryService releases the locks on the files it creates and we can 564 // HistoryService releases the locks on the files it creates and we can
567 // delete them. 565 // delete them.
568 profile_.reset(NULL); 566 profile_.reset(NULL);
569 profile_.reset(new TestingProfile()); 567 profile_.reset(new TestingProfile());
570 profile_->CreateBookmarkBarModel(true); 568 profile_->CreateBookmarkModel(true);
571 profile_->CreateHistoryService(true); 569 profile_->CreateHistoryService(true);
572 BlockTillBookmarkModelLoaded(); 570 BlockTillBookmarkModelLoaded();
573 571
574 TestNode bbn; 572 TestNode bbn;
575 PopulateNodeFromString(data[i].bbn_contents, &bbn); 573 PopulateNodeFromString(data[i].bbn_contents, &bbn);
576 PopulateBookmarkBarNode(&bbn, bb_model_, bb_model_->GetBookmarkBarNode()); 574 PopulateBookmarkNode(&bbn, bb_model_, bb_model_->GetBookmarkBarNode());
577 575
578 TestNode other; 576 TestNode other;
579 PopulateNodeFromString(data[i].other_contents, &other); 577 PopulateNodeFromString(data[i].other_contents, &other);
580 PopulateBookmarkBarNode(&other, bb_model_, bb_model_->other_node()); 578 PopulateBookmarkNode(&other, bb_model_, bb_model_->other_node());
581 579
582 profile_->CreateBookmarkBarModel(false); 580 profile_->CreateBookmarkModel(false);
583 BlockTillBookmarkModelLoaded(); 581 BlockTillBookmarkModelLoaded();
584 582
585 VerifyModelMatchesNode(&bbn, bb_model_->GetBookmarkBarNode()); 583 VerifyModelMatchesNode(&bbn, bb_model_->GetBookmarkBarNode());
586 VerifyModelMatchesNode(&other, bb_model_->other_node()); 584 VerifyModelMatchesNode(&other, bb_model_->other_node());
587 } 585 }
588 } 586 }
589 587
590 // Test class that creates a BookmarkBarModel with a real history backend. 588 // Test class that creates a BookmarkModel with a real history backend.
591 class BookmarkBarModelTestWithProfile2 : 589 class BookmarkModelTestWithProfile2 : public BookmarkModelTestWithProfile {
592 public BookmarkBarModelTestWithProfile {
593 public: 590 public:
594 virtual void SetUp() { 591 virtual void SetUp() {
595 profile_.reset(new TestingProfile()); 592 profile_.reset(new TestingProfile());
596 } 593 }
597 594
598 protected: 595 protected:
599 // Verifies the state of the model matches that of the state in the saved 596 // Verifies the state of the model matches that of the state in the saved
600 // history file. 597 // history file.
601 void VerifyExpectedState() { 598 void VerifyExpectedState() {
602 // Here's the structure we expect: 599 // Here's the structure we expect:
603 // bbn 600 // bbn
604 // www.google.com - Google 601 // www.google.com - Google
605 // F1 602 // F1
606 // http://www.google.com/intl/en/ads/ - Google Advertising 603 // http://www.google.com/intl/en/ads/ - Google Advertising
607 // F11 604 // F11
608 // http://www.google.com/services/ - Google Business Solutions 605 // http://www.google.com/services/ - Google Business Solutions
609 // other 606 // other
610 // OF1 607 // OF1
611 // http://www.google.com/intl/en/about.html - About Google 608 // http://www.google.com/intl/en/about.html - About Google
612 BookmarkBarNode* bbn = bb_model_->GetBookmarkBarNode(); 609 BookmarkNode* bbn = bb_model_->GetBookmarkBarNode();
613 ASSERT_EQ(2, bbn->GetChildCount()); 610 ASSERT_EQ(2, bbn->GetChildCount());
614 611
615 BookmarkBarNode* child = bbn->GetChild(0); 612 BookmarkNode* child = bbn->GetChild(0);
616 ASSERT_EQ(history::StarredEntry::URL, child->GetType()); 613 ASSERT_EQ(history::StarredEntry::URL, child->GetType());
617 ASSERT_EQ(L"Google", child->GetTitle()); 614 ASSERT_EQ(L"Google", child->GetTitle());
618 ASSERT_TRUE(child->GetURL() == GURL("http://www.google.com")); 615 ASSERT_TRUE(child->GetURL() == GURL("http://www.google.com"));
619 616
620 child = bbn->GetChild(1); 617 child = bbn->GetChild(1);
621 ASSERT_TRUE(child->is_folder()); 618 ASSERT_TRUE(child->is_folder());
622 ASSERT_EQ(L"F1", child->GetTitle()); 619 ASSERT_EQ(L"F1", child->GetTitle());
623 ASSERT_EQ(2, child->GetChildCount()); 620 ASSERT_EQ(2, child->GetChildCount());
624 621
625 BookmarkBarNode* parent = child; 622 BookmarkNode* parent = child;
626 child = parent->GetChild(0); 623 child = parent->GetChild(0);
627 ASSERT_EQ(history::StarredEntry::URL, child->GetType()); 624 ASSERT_EQ(history::StarredEntry::URL, child->GetType());
628 ASSERT_EQ(L"Google Advertising", child->GetTitle()); 625 ASSERT_EQ(L"Google Advertising", child->GetTitle());
629 ASSERT_TRUE(child->GetURL() == GURL("http://www.google.com/intl/en/ads/")); 626 ASSERT_TRUE(child->GetURL() == GURL("http://www.google.com/intl/en/ads/"));
630 627
631 child = parent->GetChild(1); 628 child = parent->GetChild(1);
632 ASSERT_TRUE(child->is_folder()); 629 ASSERT_TRUE(child->is_folder());
633 ASSERT_EQ(L"F11", child->GetTitle()); 630 ASSERT_EQ(L"F11", child->GetTitle());
634 ASSERT_EQ(1, child->GetChildCount()); 631 ASSERT_EQ(1, child->GetChildCount());
635 632
(...skipping 17 matching lines...) Expand all
653 ASSERT_TRUE(child->GetURL() == 650 ASSERT_TRUE(child->GetURL() ==
654 GURL("http://www.google.com/intl/en/about.html")); 651 GURL("http://www.google.com/intl/en/about.html"));
655 652
656 ASSERT_TRUE(bb_model_->GetNodeByURL(GURL("http://www.google.com")) != NULL); 653 ASSERT_TRUE(bb_model_->GetNodeByURL(GURL("http://www.google.com")) != NULL);
657 } 654 }
658 }; 655 };
659 656
660 // Tests migrating bookmarks from db into file. This copies an old history db 657 // Tests migrating bookmarks from db into file. This copies an old history db
661 // file containing bookmarks and make sure they are loaded correctly and 658 // file containing bookmarks and make sure they are loaded correctly and
662 // persisted correctly. 659 // persisted correctly.
663 TEST_F(BookmarkBarModelTestWithProfile2, MigrateFromDBToFileTest) { 660 TEST_F(BookmarkModelTestWithProfile2, MigrateFromDBToFileTest) {
664 // Copy db file over that contains starred table. 661 // Copy db file over that contains starred table.
665 std::wstring old_history_path; 662 std::wstring old_history_path;
666 PathService::Get(chrome::DIR_TEST_DATA, &old_history_path); 663 PathService::Get(chrome::DIR_TEST_DATA, &old_history_path);
667 file_util::AppendToPath(&old_history_path, L"bookmarks"); 664 file_util::AppendToPath(&old_history_path, L"bookmarks");
668 file_util::AppendToPath(&old_history_path, L"History_with_starred"); 665 file_util::AppendToPath(&old_history_path, L"History_with_starred");
669 std::wstring new_history_path = profile_->GetPath(); 666 std::wstring new_history_path = profile_->GetPath();
670 file_util::Delete(new_history_path, true); 667 file_util::Delete(new_history_path, true);
671 file_util::CreateDirectory(new_history_path); 668 file_util::CreateDirectory(new_history_path);
672 file_util::AppendToPath(&new_history_path, chrome::kHistoryFilename); 669 file_util::AppendToPath(&new_history_path, chrome::kHistoryFilename);
673 file_util::CopyFile(old_history_path, new_history_path); 670 file_util::CopyFile(old_history_path, new_history_path);
674 671
675 // Create the history service making sure it doesn't blow away the file we 672 // Create the history service making sure it doesn't blow away the file we
676 // just copied. 673 // just copied.
677 profile_->CreateHistoryService(false); 674 profile_->CreateHistoryService(false);
678 profile_->CreateBookmarkBarModel(true); 675 profile_->CreateBookmarkModel(true);
679 BlockTillBookmarkModelLoaded(); 676 BlockTillBookmarkModelLoaded();
680 677
681 // Make sure we loaded OK. 678 // Make sure we loaded OK.
682 VerifyExpectedState(); 679 VerifyExpectedState();
683 if (HasFatalFailure()) 680 if (HasFatalFailure())
684 return; 681 return;
685 682
686 // Create again. This time we shouldn't load from history at all. 683 // Create again. This time we shouldn't load from history at all.
687 profile_->CreateBookmarkBarModel(false); 684 profile_->CreateBookmarkModel(false);
688 BlockTillBookmarkModelLoaded(); 685 BlockTillBookmarkModelLoaded();
689 686
690 // Make sure we loaded OK. 687 // Make sure we loaded OK.
691 VerifyExpectedState(); 688 VerifyExpectedState();
692 if (HasFatalFailure()) 689 if (HasFatalFailure())
693 return; 690 return;
694 691
695 // Recreate the history service (with a clean db). Do this just to make sure 692 // Recreate the history service (with a clean db). Do this just to make sure
696 // we're loading correctly from the bookmarks file. 693 // we're loading correctly from the bookmarks file.
697 profile_->CreateHistoryService(true); 694 profile_->CreateHistoryService(true);
698 profile_->CreateBookmarkBarModel(false); 695 profile_->CreateBookmarkModel(false);
699 BlockTillBookmarkModelLoaded(); 696 BlockTillBookmarkModelLoaded();
700 VerifyExpectedState(); 697 VerifyExpectedState();
701 } 698 }
702 699
703 // Simple test that removes a bookmark. This test exercises the code paths in 700 // Simple test that removes a bookmark. This test exercises the code paths in
704 // History that block till bookmark bar model is loaded. 701 // History that block till bookmark bar model is loaded.
705 TEST_F(BookmarkBarModelTestWithProfile2, RemoveNotification) { 702 TEST_F(BookmarkModelTestWithProfile2, RemoveNotification) {
706 profile_->CreateHistoryService(false); 703 profile_->CreateHistoryService(false);
707 profile_->CreateBookmarkBarModel(true); 704 profile_->CreateBookmarkModel(true);
708 BlockTillBookmarkModelLoaded(); 705 BlockTillBookmarkModelLoaded();
709 706
710 // Add a URL. 707 // Add a URL.
711 GURL url("http://www.google.com"); 708 GURL url("http://www.google.com");
712 bb_model_->SetURLStarred(url, std::wstring(), true); 709 bb_model_->SetURLStarred(url, std::wstring(), true);
713 710
714 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)->AddPage( 711 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)->AddPage(
715 url, NULL, 1, GURL(), PageTransition::TYPED, 712 url, NULL, 1, GURL(), PageTransition::TYPED,
716 HistoryService::RedirectList()); 713 HistoryService::RedirectList());
717 714
718 // This won't actually delete the URL, rather it'll empty out the visits. 715 // This won't actually delete the URL, rather it'll empty out the visits.
719 // This triggers blocking on the BookmarkBarModel. 716 // This triggers blocking on the BookmarkModel.
720 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)->DeleteURL(url); 717 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)->DeleteURL(url);
721 } 718 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698