blob: e323416ddc06c296d109c08f1f704755168ff44b [file] [log] [blame]
[email protected]b68a8172012-02-17 00:25:181// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93027af2009-10-07 23:27:015#include <set>
[email protected]f20d7332011-03-08 21:11:536#include <string>
[email protected]93027af2009-10-07 23:27:017
[email protected]dbbad7a2010-08-13 18:18:368#include "base/base_paths.h"
[email protected]c38831a12011-10-28 12:44:499#include "base/basictypes.h"
[email protected]6892e2e2011-05-26 22:07:1710#include "base/command_line.h"
[email protected]c38831a12011-10-28 12:44:4911#include "base/compiler_specific.h"
[email protected]dbbad7a2010-08-13 18:18:3612#include "base/file_util.h"
[email protected]999f3802009-05-22 19:28:0013#include "base/hash_tables.h"
[email protected]dbbad7a2010-08-13 18:18:3614#include "base/path_service.h"
[email protected]6524385ef2010-08-18 06:34:1315#include "base/string16.h"
[email protected]e83326f2010-07-31 17:29:2516#include "base/string_number_conversions.h"
[email protected]b87c4a72010-11-15 22:03:4217#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2918#include "base/string_util.h"
[email protected]853e01b2012-09-21 20:14:1119#include "base/time.h"
[email protected]81415222010-08-18 16:17:2020#include "base/utf_string_conversions.h"
[email protected]814a2d32009-04-30 23:09:0121#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]ddabf57e2012-08-02 00:53:4722#include "chrome/browser/bookmarks/bookmark_model_factory.h"
[email protected]125b234182011-07-08 19:54:4123#include "chrome/browser/bookmarks/bookmark_model_observer.h"
[email protected]9333f182008-12-09 17:34:1724#include "chrome/browser/bookmarks/bookmark_utils.h"
[email protected]9c92d192009-12-02 08:03:1625#include "chrome/browser/history/history_notifications.h"
[email protected]9aac66862012-06-19 19:44:3126#include "chrome/browser/history/history_service_factory.h"
[email protected]f25387b2008-08-21 15:20:3327#include "chrome/common/chrome_constants.h"
[email protected]432115822011-07-10 15:52:2728#include "chrome/common/chrome_notification_types.h"
[email protected]f25387b2008-08-21 15:20:3329#include "chrome/common/chrome_paths.h"
[email protected]6892e2e2011-05-26 22:07:1730#include "chrome/common/chrome_switches.h"
[email protected]7bc60682011-07-29 20:55:5931#include "chrome/test/base/model_test_utils.h"
[email protected]a4ff9eae2011-08-01 19:58:1632#include "chrome/test/base/testing_profile.h"
[email protected]6c2381d2011-10-19 02:52:5333#include "content/public/browser/notification_details.h"
34#include "content/public/browser/notification_registrar.h"
35#include "content/public/browser/notification_source.h"
[email protected]e97882f2012-06-04 02:23:1736#include "content/public/test/test_browser_thread.h"
initial.commit09911bf2008-07-26 23:55:2937#include "testing/gtest/include/gtest/gtest.h"
[email protected]44cbd9e2011-01-14 15:49:4038#include "ui/base/models/tree_node_iterator.h"
[email protected]f20d7332011-03-08 21:11:5339#include "ui/base/models/tree_node_model.h"
initial.commit09911bf2008-07-26 23:55:2940
[email protected]e1acf6f2008-10-27 20:43:3341using base::Time;
42using base::TimeDelta;
[email protected]631bb742011-11-02 11:29:3943using content::BrowserThread;
[email protected]e1acf6f2008-10-27 20:43:3344
[email protected]b3c33d462009-06-26 22:29:2045namespace {
46
[email protected]aee236542011-12-01 04:34:0347// Test cases used to test the removal of extra whitespace when adding
48// a new folder/bookmark or updating a title of a folder/bookmark.
49static struct {
50 const std::string input_title;
51 const std::string expected_title;
52} whitespace_test_cases[] = {
53 {"foobar", "foobar"},
54 // Newlines.
55 {"foo\nbar", "foo bar"},
56 {"foo\n\nbar", "foo bar"},
57 {"foo\n\n\nbar", "foo bar"},
58 {"foo\r\nbar", "foo bar"},
59 {"foo\r\n\r\nbar", "foo bar"},
60 {"\nfoo\nbar\n", "foo bar"},
61 // Spaces.
62 {"foo bar", "foo bar"},
63 {" foo bar ", "foo bar"},
64 {" foo bar ", "foo bar"},
65 // Tabs.
66 {"\tfoo\tbar\t", "foo bar"},
67 {"\tfoo bar\t", "foo bar"},
68 // Mixed cases.
69 {"\tfoo\nbar\t", "foo bar"},
70 {"\tfoo\r\nbar\t", "foo bar"},
71 {" foo\tbar\n", "foo bar"},
72 {"\t foo \t bar \t", "foo bar"},
73 {"\n foo\r\n\tbar\n \t", "foo bar"},
74};
75
[email protected]b3c33d462009-06-26 22:29:2076// Helper to get a mutable bookmark node.
[email protected]ff6592a2011-07-14 21:41:1477BookmarkNode* AsMutable(const BookmarkNode* node) {
[email protected]b3c33d462009-06-26 22:29:2078 return const_cast<BookmarkNode*>(node);
79}
80
81void SwapDateAdded(BookmarkNode* n1, BookmarkNode* n2) {
82 Time tmp = n1->date_added();
83 n1->set_date_added(n2->date_added());
84 n2->set_date_added(tmp);
85}
86
[email protected]583844c2011-08-27 00:38:3587class BookmarkModelTest : public testing::Test,
[email protected]bcd98a52011-02-25 07:50:1988 public BookmarkModelObserver {
initial.commit09911bf2008-07-26 23:55:2989 public:
90 struct ObserverDetails {
91 ObserverDetails() {
92 Set(NULL, NULL, -1, -1);
93 }
94
[email protected]b3c33d462009-06-26 22:29:2095 void Set(const BookmarkNode* node1,
96 const BookmarkNode* node2,
initial.commit09911bf2008-07-26 23:55:2997 int index1,
98 int index2) {
[email protected]ff6592a2011-07-14 21:41:1499 node1_ = node1;
100 node2_ = node2;
101 index1_ = index1;
102 index2_ = index2;
initial.commit09911bf2008-07-26 23:55:29103 }
104
[email protected]ff6592a2011-07-14 21:41:14105 void ExpectEquals(const BookmarkNode* node1,
[email protected]b3c33d462009-06-26 22:29:20106 const BookmarkNode* node2,
initial.commit09911bf2008-07-26 23:55:29107 int index1,
108 int index2) {
[email protected]ff6592a2011-07-14 21:41:14109 EXPECT_EQ(node1_, node1);
110 EXPECT_EQ(node2_, node2);
111 EXPECT_EQ(index1_, index1);
112 EXPECT_EQ(index2_, index2);
initial.commit09911bf2008-07-26 23:55:29113 }
114
[email protected]ff6592a2011-07-14 21:41:14115 private:
116 const BookmarkNode* node1_;
117 const BookmarkNode* node2_;
118 int index1_;
119 int index2_;
initial.commit09911bf2008-07-26 23:55:29120 };
121
[email protected]c58c5ea2011-07-13 21:43:16122 BookmarkModelTest()
[email protected]972ecf62011-11-22 00:44:38123 : model_(NULL) {
[email protected]c58c5ea2011-07-13 21:43:16124 model_.AddObserver(this);
125 ClearCounts();
initial.commit09911bf2008-07-26 23:55:29126 }
127
[email protected]c58c5ea2011-07-13 21:43:16128 void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE {
initial.commit09911bf2008-07-26 23:55:29129 // We never load from the db, so that this should never get invoked.
130 NOTREACHED();
131 }
132
[email protected]d8e41ed2008-09-11 15:22:32133 virtual void BookmarkNodeMoved(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20134 const BookmarkNode* old_parent,
initial.commit09911bf2008-07-26 23:55:29135 int old_index,
[email protected]b3c33d462009-06-26 22:29:20136 const BookmarkNode* new_parent,
[email protected]f12de8302011-05-23 16:12:30137 int new_index) OVERRIDE {
[email protected]ff6592a2011-07-14 21:41:14138 ++moved_count_;
139 observer_details_.Set(old_parent, new_parent, old_index, new_index);
initial.commit09911bf2008-07-26 23:55:29140 }
141
[email protected]d8e41ed2008-09-11 15:22:32142 virtual void BookmarkNodeAdded(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20143 const BookmarkNode* parent,
[email protected]f12de8302011-05-23 16:12:30144 int index) OVERRIDE {
[email protected]ff6592a2011-07-14 21:41:14145 ++added_count_;
146 observer_details_.Set(parent, NULL, index, -1);
initial.commit09911bf2008-07-26 23:55:29147 }
148
[email protected]d8e41ed2008-09-11 15:22:32149 virtual void BookmarkNodeRemoved(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20150 const BookmarkNode* parent,
[email protected]66965022009-07-15 17:20:01151 int old_index,
[email protected]f12de8302011-05-23 16:12:30152 const BookmarkNode* node) OVERRIDE {
[email protected]ff6592a2011-07-14 21:41:14153 ++removed_count_;
154 observer_details_.Set(parent, NULL, old_index, -1);
initial.commit09911bf2008-07-26 23:55:29155 }
156
[email protected]d8e41ed2008-09-11 15:22:32157 virtual void BookmarkNodeChanged(BookmarkModel* model,
[email protected]f12de8302011-05-23 16:12:30158 const BookmarkNode* node) OVERRIDE {
[email protected]ff6592a2011-07-14 21:41:14159 ++changed_count_;
160 observer_details_.Set(node, NULL, -1, -1);
initial.commit09911bf2008-07-26 23:55:29161 }
162
[email protected]f12de8302011-05-23 16:12:30163 virtual void BookmarkNodeChildrenReordered(
164 BookmarkModel* model,
165 const BookmarkNode* node) OVERRIDE {
[email protected]ff6592a2011-07-14 21:41:14166 ++reordered_count_;
[email protected]e2f86d92009-02-25 00:22:01167 }
168
[email protected]f12de8302011-05-23 16:12:30169 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model,
170 const BookmarkNode* node) OVERRIDE {
initial.commit09911bf2008-07-26 23:55:29171 // We never attempt to load favicons, so that this method never
172 // gets invoked.
173 }
174
[email protected]b68a8172012-02-17 00:25:18175 virtual void ExtensiveBookmarkChangesBeginning(
176 BookmarkModel* model) OVERRIDE {
177 ++extensive_changes_beginning_count_;
178 }
179
180 virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) OVERRIDE {
181 ++extensive_changes_ended_count_;
182 }
183
initial.commit09911bf2008-07-26 23:55:29184 void ClearCounts() {
[email protected]ff6592a2011-07-14 21:41:14185 added_count_ = moved_count_ = removed_count_ = changed_count_ =
[email protected]b68a8172012-02-17 00:25:18186 reordered_count_ = extensive_changes_beginning_count_ =
187 extensive_changes_ended_count_ = 0;
initial.commit09911bf2008-07-26 23:55:29188 }
189
190 void AssertObserverCount(int added_count,
191 int moved_count,
192 int removed_count,
[email protected]e2f86d92009-02-25 00:22:01193 int changed_count,
194 int reordered_count) {
[email protected]ff6592a2011-07-14 21:41:14195 EXPECT_EQ(added_count_, added_count);
196 EXPECT_EQ(moved_count_, moved_count);
197 EXPECT_EQ(removed_count_, removed_count);
198 EXPECT_EQ(changed_count_, changed_count);
199 EXPECT_EQ(reordered_count_, reordered_count);
initial.commit09911bf2008-07-26 23:55:29200 }
201
[email protected]b68a8172012-02-17 00:25:18202 void AssertExtensiveChangesObserverCount(
203 int extensive_changes_beginning_count,
204 int extensive_changes_ended_count) {
205 EXPECT_EQ(extensive_changes_beginning_count_,
206 extensive_changes_beginning_count);
207 EXPECT_EQ(extensive_changes_ended_count_, extensive_changes_ended_count);
208 }
209
[email protected]ff6592a2011-07-14 21:41:14210 protected:
[email protected]6892e2e2011-05-26 22:07:17211 BookmarkModel model_;
[email protected]ff6592a2011-07-14 21:41:14212 ObserverDetails observer_details_;
[email protected]6892e2e2011-05-26 22:07:17213
[email protected]ff6592a2011-07-14 21:41:14214 private:
[email protected]ff6592a2011-07-14 21:41:14215 int added_count_;
216 int moved_count_;
217 int removed_count_;
218 int changed_count_;
[email protected]e2f86d92009-02-25 00:22:01219 int reordered_count_;
[email protected]b68a8172012-02-17 00:25:18220 int extensive_changes_beginning_count_;
221 int extensive_changes_ended_count_;
[email protected]e2f86d92009-02-25 00:22:01222
[email protected]ff6592a2011-07-14 21:41:14223 DISALLOW_COPY_AND_ASSIGN(BookmarkModelTest);
initial.commit09911bf2008-07-26 23:55:29224};
225
[email protected]d8e41ed2008-09-11 15:22:32226TEST_F(BookmarkModelTest, InitialState) {
[email protected]72bdcfe2011-07-22 17:21:58227 const BookmarkNode* bb_node = model_.bookmark_bar_node();
[email protected]f25387b2008-08-21 15:20:33228 ASSERT_TRUE(bb_node != NULL);
[email protected]9c1a75a2011-03-10 02:38:12229 EXPECT_EQ(0, bb_node->child_count());
[email protected]037db002009-10-19 20:06:08230 EXPECT_EQ(BookmarkNode::BOOKMARK_BAR, bb_node->type());
[email protected]f25387b2008-08-21 15:20:33231
[email protected]6892e2e2011-05-26 22:07:17232 const BookmarkNode* other_node = model_.other_node();
[email protected]f25387b2008-08-21 15:20:33233 ASSERT_TRUE(other_node != NULL);
[email protected]9c1a75a2011-03-10 02:38:12234 EXPECT_EQ(0, other_node->child_count());
[email protected]037db002009-10-19 20:06:08235 EXPECT_EQ(BookmarkNode::OTHER_NODE, other_node->type());
[email protected]f25387b2008-08-21 15:20:33236
[email protected]37bc9132011-12-01 22:29:29237 const BookmarkNode* mobile_node = model_.mobile_node();
238 ASSERT_TRUE(mobile_node != NULL);
239 EXPECT_EQ(0, mobile_node->child_count());
240 EXPECT_EQ(BookmarkNode::MOBILE, mobile_node->type());
[email protected]6892e2e2011-05-26 22:07:17241
[email protected]f25387b2008-08-21 15:20:33242 EXPECT_TRUE(bb_node->id() != other_node->id());
[email protected]37bc9132011-12-01 22:29:29243 EXPECT_TRUE(bb_node->id() != mobile_node->id());
244 EXPECT_TRUE(other_node->id() != mobile_node->id());
initial.commit09911bf2008-07-26 23:55:29245}
246
[email protected]d8e41ed2008-09-11 15:22:32247TEST_F(BookmarkModelTest, AddURL) {
[email protected]72bdcfe2011-07-22 17:21:58248 const BookmarkNode* root = model_.bookmark_bar_node();
[email protected]4fe6eb52010-08-12 00:47:09249 const string16 title(ASCIIToUTF16("foo"));
initial.commit09911bf2008-07-26 23:55:29250 const GURL url("http://foo.com");
251
[email protected]6892e2e2011-05-26 22:07:17252 const BookmarkNode* new_node = model_.AddURL(root, 0, title, url);
[email protected]e2f86d92009-02-25 00:22:01253 AssertObserverCount(1, 0, 0, 0, 0);
[email protected]ff6592a2011-07-14 21:41:14254 observer_details_.ExpectEquals(root, NULL, 0, -1);
initial.commit09911bf2008-07-26 23:55:29255
[email protected]9c1a75a2011-03-10 02:38:12256 ASSERT_EQ(1, root->child_count());
[email protected]440b37b22010-08-30 05:31:40257 ASSERT_EQ(title, new_node->GetTitle());
[email protected]5d4077542011-07-21 20:24:07258 ASSERT_TRUE(url == new_node->url());
[email protected]037db002009-10-19 20:06:08259 ASSERT_EQ(BookmarkNode::URL, new_node->type());
[email protected]6892e2e2011-05-26 22:07:17260 ASSERT_TRUE(new_node == model_.GetMostRecentlyAddedNodeForURL(url));
[email protected]f25387b2008-08-21 15:20:33261
262 EXPECT_TRUE(new_node->id() != root->id() &&
[email protected]6892e2e2011-05-26 22:07:17263 new_node->id() != model_.other_node()->id() &&
[email protected]37bc9132011-12-01 22:29:29264 new_node->id() != model_.mobile_node()->id());
[email protected]6892e2e2011-05-26 22:07:17265}
266
[email protected]2fcb5c22012-08-23 16:28:39267TEST_F(BookmarkModelTest, AddURLWithUnicodeTitle) {
268 const BookmarkNode* root = model_.bookmark_bar_node();
269 const string16 title(WideToUTF16(
270 L"\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053"));
271 const GURL url("https://www.baidu.com/");
272
273 const BookmarkNode* new_node = model_.AddURL(root, 0, title, url);
274 AssertObserverCount(1, 0, 0, 0, 0);
275 observer_details_.ExpectEquals(root, NULL, 0, -1);
276
277 ASSERT_EQ(1, root->child_count());
278 ASSERT_EQ(title, new_node->GetTitle());
279 ASSERT_TRUE(url == new_node->url());
280 ASSERT_EQ(BookmarkNode::URL, new_node->type());
281 ASSERT_TRUE(new_node == model_.GetMostRecentlyAddedNodeForURL(url));
282
283 EXPECT_TRUE(new_node->id() != root->id() &&
284 new_node->id() != model_.other_node()->id() &&
285 new_node->id() != model_.mobile_node()->id());
286}
287
[email protected]aee236542011-12-01 04:34:03288TEST_F(BookmarkModelTest, AddURLWithWhitespaceTitle) {
289 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(whitespace_test_cases); ++i) {
290 const BookmarkNode* root = model_.bookmark_bar_node();
291 const string16 title(ASCIIToUTF16(whitespace_test_cases[i].input_title));
292 const GURL url("http://foo.com");
293
294 const BookmarkNode* new_node = model_.AddURL(root, i, title, url);
295
296 int size = i + 1;
297 EXPECT_EQ(size, root->child_count());
298 EXPECT_EQ(ASCIIToUTF16(whitespace_test_cases[i].expected_title),
299 new_node->GetTitle());
300 EXPECT_EQ(BookmarkNode::URL, new_node->type());
301 }
302}
303
[email protected]37bc9132011-12-01 22:29:29304TEST_F(BookmarkModelTest, AddURLToMobileBookmarks) {
305 const BookmarkNode* root = model_.mobile_node();
[email protected]6892e2e2011-05-26 22:07:17306 const string16 title(ASCIIToUTF16("foo"));
307 const GURL url("http://foo.com");
308
309 const BookmarkNode* new_node = model_.AddURL(root, 0, title, url);
310 AssertObserverCount(1, 0, 0, 0, 0);
[email protected]ff6592a2011-07-14 21:41:14311 observer_details_.ExpectEquals(root, NULL, 0, -1);
[email protected]6892e2e2011-05-26 22:07:17312
313 ASSERT_EQ(1, root->child_count());
314 ASSERT_EQ(title, new_node->GetTitle());
[email protected]5d4077542011-07-21 20:24:07315 ASSERT_TRUE(url == new_node->url());
[email protected]6892e2e2011-05-26 22:07:17316 ASSERT_EQ(BookmarkNode::URL, new_node->type());
317 ASSERT_TRUE(new_node == model_.GetMostRecentlyAddedNodeForURL(url));
318
319 EXPECT_TRUE(new_node->id() != root->id() &&
320 new_node->id() != model_.other_node()->id() &&
[email protected]37bc9132011-12-01 22:29:29321 new_node->id() != model_.mobile_node()->id());
initial.commit09911bf2008-07-26 23:55:29322}
323
[email protected]39703292011-03-18 17:03:40324TEST_F(BookmarkModelTest, AddFolder) {
[email protected]72bdcfe2011-07-22 17:21:58325 const BookmarkNode* root = model_.bookmark_bar_node();
[email protected]4fe6eb52010-08-12 00:47:09326 const string16 title(ASCIIToUTF16("foo"));
initial.commit09911bf2008-07-26 23:55:29327
[email protected]6892e2e2011-05-26 22:07:17328 const BookmarkNode* new_node = model_.AddFolder(root, 0, title);
[email protected]e2f86d92009-02-25 00:22:01329 AssertObserverCount(1, 0, 0, 0, 0);
[email protected]ff6592a2011-07-14 21:41:14330 observer_details_.ExpectEquals(root, NULL, 0, -1);
initial.commit09911bf2008-07-26 23:55:29331
[email protected]9c1a75a2011-03-10 02:38:12332 ASSERT_EQ(1, root->child_count());
[email protected]440b37b22010-08-30 05:31:40333 ASSERT_EQ(title, new_node->GetTitle());
[email protected]037db002009-10-19 20:06:08334 ASSERT_EQ(BookmarkNode::FOLDER, new_node->type());
[email protected]f25387b2008-08-21 15:20:33335
336 EXPECT_TRUE(new_node->id() != root->id() &&
[email protected]6892e2e2011-05-26 22:07:17337 new_node->id() != model_.other_node()->id() &&
[email protected]37bc9132011-12-01 22:29:29338 new_node->id() != model_.mobile_node()->id());
initial.commit09911bf2008-07-26 23:55:29339
[email protected]39703292011-03-18 17:03:40340 // Add another folder, just to make sure folder_ids are incremented correctly.
initial.commit09911bf2008-07-26 23:55:29341 ClearCounts();
[email protected]6892e2e2011-05-26 22:07:17342 model_.AddFolder(root, 0, title);
[email protected]e2f86d92009-02-25 00:22:01343 AssertObserverCount(1, 0, 0, 0, 0);
[email protected]ff6592a2011-07-14 21:41:14344 observer_details_.ExpectEquals(root, NULL, 0, -1);
initial.commit09911bf2008-07-26 23:55:29345}
346
[email protected]aee236542011-12-01 04:34:03347TEST_F(BookmarkModelTest, AddFolderWithWhitespaceTitle) {
348 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(whitespace_test_cases); ++i) {
349 const BookmarkNode* root = model_.bookmark_bar_node();
350 const string16 title(ASCIIToUTF16(whitespace_test_cases[i].input_title));
351
352 const BookmarkNode* new_node = model_.AddFolder(root, i, title);
353
354 int size = i + 1;
355 EXPECT_EQ(size, root->child_count());
356 EXPECT_EQ(ASCIIToUTF16(whitespace_test_cases[i].expected_title),
357 new_node->GetTitle());
358 EXPECT_EQ(BookmarkNode::FOLDER, new_node->type());
359 }
360}
361
[email protected]d8e41ed2008-09-11 15:22:32362TEST_F(BookmarkModelTest, RemoveURL) {
[email protected]72bdcfe2011-07-22 17:21:58363 const BookmarkNode* root = model_.bookmark_bar_node();
[email protected]81415222010-08-18 16:17:20364 const string16 title(ASCIIToUTF16("foo"));
initial.commit09911bf2008-07-26 23:55:29365 const GURL url("http://foo.com");
[email protected]6892e2e2011-05-26 22:07:17366 model_.AddURL(root, 0, title, url);
initial.commit09911bf2008-07-26 23:55:29367 ClearCounts();
368
[email protected]6892e2e2011-05-26 22:07:17369 model_.Remove(root, 0);
[email protected]9c1a75a2011-03-10 02:38:12370 ASSERT_EQ(0, root->child_count());
[email protected]e2f86d92009-02-25 00:22:01371 AssertObserverCount(0, 0, 1, 0, 0);
[email protected]ff6592a2011-07-14 21:41:14372 observer_details_.ExpectEquals(root, NULL, 0, -1);
initial.commit09911bf2008-07-26 23:55:29373
374 // Make sure there is no mapping for the URL.
[email protected]6892e2e2011-05-26 22:07:17375 ASSERT_TRUE(model_.GetMostRecentlyAddedNodeForURL(url) == NULL);
initial.commit09911bf2008-07-26 23:55:29376}
377
[email protected]9fcaee72011-03-21 21:53:44378TEST_F(BookmarkModelTest, RemoveFolder) {
[email protected]72bdcfe2011-07-22 17:21:58379 const BookmarkNode* root = model_.bookmark_bar_node();
[email protected]6892e2e2011-05-26 22:07:17380 const BookmarkNode* folder = model_.AddFolder(root, 0, ASCIIToUTF16("foo"));
initial.commit09911bf2008-07-26 23:55:29381
382 ClearCounts();
383
384 // Add a URL as a child.
[email protected]81415222010-08-18 16:17:20385 const string16 title(ASCIIToUTF16("foo"));
initial.commit09911bf2008-07-26 23:55:29386 const GURL url("http://foo.com");
[email protected]6892e2e2011-05-26 22:07:17387 model_.AddURL(folder, 0, title, url);
initial.commit09911bf2008-07-26 23:55:29388
389 ClearCounts();
390
[email protected]39703292011-03-18 17:03:40391 // Now remove the folder.
[email protected]6892e2e2011-05-26 22:07:17392 model_.Remove(root, 0);
[email protected]9c1a75a2011-03-10 02:38:12393 ASSERT_EQ(0, root->child_count());
[email protected]e2f86d92009-02-25 00:22:01394 AssertObserverCount(0, 0, 1, 0, 0);
[email protected]ff6592a2011-07-14 21:41:14395 observer_details_.ExpectEquals(root, NULL, 0, -1);
initial.commit09911bf2008-07-26 23:55:29396
397 // Make sure there is no mapping for the URL.
[email protected]6892e2e2011-05-26 22:07:17398 ASSERT_TRUE(model_.GetMostRecentlyAddedNodeForURL(url) == NULL);
initial.commit09911bf2008-07-26 23:55:29399}
400
[email protected]d8e41ed2008-09-11 15:22:32401TEST_F(BookmarkModelTest, SetTitle) {
[email protected]72bdcfe2011-07-22 17:21:58402 const BookmarkNode* root = model_.bookmark_bar_node();
[email protected]4fe6eb52010-08-12 00:47:09403 string16 title(ASCIIToUTF16("foo"));
initial.commit09911bf2008-07-26 23:55:29404 const GURL url("http://foo.com");
[email protected]6892e2e2011-05-26 22:07:17405 const BookmarkNode* node = model_.AddURL(root, 0, title, url);
initial.commit09911bf2008-07-26 23:55:29406
407 ClearCounts();
408
[email protected]4fe6eb52010-08-12 00:47:09409 title = ASCIIToUTF16("foo2");
[email protected]6892e2e2011-05-26 22:07:17410 model_.SetTitle(node, title);
[email protected]e2f86d92009-02-25 00:22:01411 AssertObserverCount(0, 0, 0, 1, 0);
[email protected]ff6592a2011-07-14 21:41:14412 observer_details_.ExpectEquals(node, NULL, -1, -1);
[email protected]440b37b22010-08-30 05:31:40413 EXPECT_EQ(title, node->GetTitle());
initial.commit09911bf2008-07-26 23:55:29414}
415
[email protected]aee236542011-12-01 04:34:03416TEST_F(BookmarkModelTest, SetTitleWithWhitespace) {
417 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(whitespace_test_cases); ++i) {
418 const BookmarkNode* root = model_.bookmark_bar_node();
419 string16 title(ASCIIToUTF16("dummy"));
420 const GURL url("http://foo.com");
421 const BookmarkNode* node = model_.AddURL(root, 0, title, url);
422
423 title = ASCIIToUTF16(whitespace_test_cases[i].input_title);
424 model_.SetTitle(node, title);
425 EXPECT_EQ(ASCIIToUTF16(whitespace_test_cases[i].expected_title),
426 node->GetTitle());
427 }
428}
429
[email protected]e5486602010-02-09 21:27:55430TEST_F(BookmarkModelTest, SetURL) {
[email protected]72bdcfe2011-07-22 17:21:58431 const BookmarkNode* root = model_.bookmark_bar_node();
[email protected]81415222010-08-18 16:17:20432 const string16 title(ASCIIToUTF16("foo"));
[email protected]e5486602010-02-09 21:27:55433 GURL url("http://foo.com");
[email protected]6892e2e2011-05-26 22:07:17434 const BookmarkNode* node = model_.AddURL(root, 0, title, url);
[email protected]e5486602010-02-09 21:27:55435
436 ClearCounts();
437
438 url = GURL("http://foo2.com");
[email protected]6892e2e2011-05-26 22:07:17439 model_.SetURL(node, url);
[email protected]e5486602010-02-09 21:27:55440 AssertObserverCount(0, 0, 0, 1, 0);
[email protected]ff6592a2011-07-14 21:41:14441 observer_details_.ExpectEquals(node, NULL, -1, -1);
[email protected]5d4077542011-07-21 20:24:07442 EXPECT_EQ(url, node->url());
[email protected]e5486602010-02-09 21:27:55443}
444
[email protected]d8e41ed2008-09-11 15:22:32445TEST_F(BookmarkModelTest, Move) {
[email protected]72bdcfe2011-07-22 17:21:58446 const BookmarkNode* root = model_.bookmark_bar_node();
[email protected]81415222010-08-18 16:17:20447 const string16 title(ASCIIToUTF16("foo"));
initial.commit09911bf2008-07-26 23:55:29448 const GURL url("http://foo.com");
[email protected]6892e2e2011-05-26 22:07:17449 const BookmarkNode* node = model_.AddURL(root, 0, title, url);
450 const BookmarkNode* folder1 = model_.AddFolder(root, 0, ASCIIToUTF16("foo"));
initial.commit09911bf2008-07-26 23:55:29451 ClearCounts();
452
[email protected]6892e2e2011-05-26 22:07:17453 model_.Move(node, folder1, 0);
initial.commit09911bf2008-07-26 23:55:29454
[email protected]e2f86d92009-02-25 00:22:01455 AssertObserverCount(0, 1, 0, 0, 0);
[email protected]ff6592a2011-07-14 21:41:14456 observer_details_.ExpectEquals(root, folder1, 1, 0);
[email protected]39703292011-03-18 17:03:40457 EXPECT_TRUE(folder1 == node->parent());
[email protected]9c1a75a2011-03-10 02:38:12458 EXPECT_EQ(1, root->child_count());
[email protected]39703292011-03-18 17:03:40459 EXPECT_EQ(folder1, root->GetChild(0));
460 EXPECT_EQ(1, folder1->child_count());
461 EXPECT_EQ(node, folder1->GetChild(0));
initial.commit09911bf2008-07-26 23:55:29462
[email protected]39703292011-03-18 17:03:40463 // And remove the folder.
initial.commit09911bf2008-07-26 23:55:29464 ClearCounts();
[email protected]6892e2e2011-05-26 22:07:17465 model_.Remove(root, 0);
[email protected]e2f86d92009-02-25 00:22:01466 AssertObserverCount(0, 0, 1, 0, 0);
[email protected]ff6592a2011-07-14 21:41:14467 observer_details_.ExpectEquals(root, NULL, 0, -1);
[email protected]6892e2e2011-05-26 22:07:17468 EXPECT_TRUE(model_.GetMostRecentlyAddedNodeForURL(url) == NULL);
[email protected]9c1a75a2011-03-10 02:38:12469 EXPECT_EQ(0, root->child_count());
initial.commit09911bf2008-07-26 23:55:29470}
471
[email protected]4e187ef652010-03-11 05:21:35472TEST_F(BookmarkModelTest, Copy) {
[email protected]72bdcfe2011-07-22 17:21:58473 const BookmarkNode* root = model_.bookmark_bar_node();
[email protected]0b0a7d72010-08-25 04:54:09474 static const std::string model_string("a 1:[ b c ] d 2:[ e f g ] h ");
[email protected]6892e2e2011-05-26 22:07:17475 model_test_utils::AddNodesFromModelString(model_, root, model_string);
[email protected]4e187ef652010-03-11 05:21:35476
477 // Validate initial model.
[email protected]0b0a7d72010-08-25 04:54:09478 std::string actualModelString = model_test_utils::ModelStringFromNode(root);
[email protected]94d2135c2010-04-29 18:24:32479 EXPECT_EQ(model_string, actualModelString);
[email protected]4e187ef652010-03-11 05:21:35480
481 // Copy 'd' to be after '1:b': URL item from bar to folder.
482 const BookmarkNode* nodeToCopy = root->GetChild(2);
483 const BookmarkNode* destination = root->GetChild(1);
[email protected]6892e2e2011-05-26 22:07:17484 model_.Copy(nodeToCopy, destination, 1);
[email protected]94d2135c2010-04-29 18:24:32485 actualModelString = model_test_utils::ModelStringFromNode(root);
[email protected]0b0a7d72010-08-25 04:54:09486 EXPECT_EQ("a 1:[ b d c ] d 2:[ e f g ] h ", actualModelString);
[email protected]4e187ef652010-03-11 05:21:35487
488 // Copy '1:d' to be after 'a': URL item from folder to bar.
[email protected]39703292011-03-18 17:03:40489 const BookmarkNode* folder = root->GetChild(1);
490 nodeToCopy = folder->GetChild(1);
[email protected]6892e2e2011-05-26 22:07:17491 model_.Copy(nodeToCopy, root, 1);
[email protected]94d2135c2010-04-29 18:24:32492 actualModelString = model_test_utils::ModelStringFromNode(root);
[email protected]0b0a7d72010-08-25 04:54:09493 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e f g ] h ", actualModelString);
[email protected]4e187ef652010-03-11 05:21:35494
495 // Copy '1' to be after '2:e': Folder from bar to folder.
496 nodeToCopy = root->GetChild(2);
497 destination = root->GetChild(4);
[email protected]6892e2e2011-05-26 22:07:17498 model_.Copy(nodeToCopy, destination, 1);
[email protected]94d2135c2010-04-29 18:24:32499 actualModelString = model_test_utils::ModelStringFromNode(root);
[email protected]0b0a7d72010-08-25 04:54:09500 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f g ] h ", actualModelString);
[email protected]4e187ef652010-03-11 05:21:35501
502 // Copy '2:1' to be after '2:f': Folder within same folder.
[email protected]39703292011-03-18 17:03:40503 folder = root->GetChild(4);
504 nodeToCopy = folder->GetChild(1);
[email protected]6892e2e2011-05-26 22:07:17505 model_.Copy(nodeToCopy, folder, 3);
[email protected]94d2135c2010-04-29 18:24:32506 actualModelString = model_test_utils::ModelStringFromNode(root);
[email protected]0b0a7d72010-08-25 04:54:09507 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h ",
[email protected]4e187ef652010-03-11 05:21:35508 actualModelString);
509
510 // Copy first 'd' to be after 'h': URL item within the bar.
511 nodeToCopy = root->GetChild(1);
[email protected]6892e2e2011-05-26 22:07:17512 model_.Copy(nodeToCopy, root, 6);
[email protected]94d2135c2010-04-29 18:24:32513 actualModelString = model_test_utils::ModelStringFromNode(root);
[email protected]0b0a7d72010-08-25 04:54:09514 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h d ",
[email protected]4e187ef652010-03-11 05:21:35515 actualModelString);
516
517 // Copy '2' to be after 'a': Folder within the bar.
518 nodeToCopy = root->GetChild(4);
[email protected]6892e2e2011-05-26 22:07:17519 model_.Copy(nodeToCopy, root, 1);
[email protected]94d2135c2010-04-29 18:24:32520 actualModelString = model_test_utils::ModelStringFromNode(root);
[email protected]0b0a7d72010-08-25 04:54:09521 EXPECT_EQ("a 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] d 1:[ b d c ] "
522 "d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h d ",
[email protected]4e187ef652010-03-11 05:21:35523 actualModelString);
524}
525
initial.commit09911bf2008-07-26 23:55:29526// Tests that adding a URL to a folder updates the last modified time.
[email protected]d8e41ed2008-09-11 15:22:32527TEST_F(BookmarkModelTest, ParentForNewNodes) {
[email protected]72bdcfe2011-07-22 17:21:58528 ASSERT_EQ(model_.bookmark_bar_node(), model_.GetParentForNewNodes());
initial.commit09911bf2008-07-26 23:55:29529
[email protected]81415222010-08-18 16:17:20530 const string16 title(ASCIIToUTF16("foo"));
initial.commit09911bf2008-07-26 23:55:29531 const GURL url("http://foo.com");
532
[email protected]6892e2e2011-05-26 22:07:17533 model_.AddURL(model_.other_node(), 0, title, url);
534 ASSERT_EQ(model_.other_node(), model_.GetParentForNewNodes());
535}
536
537// Tests that adding a URL to a folder updates the last modified time.
[email protected]37bc9132011-12-01 22:29:29538TEST_F(BookmarkModelTest, ParentForNewMobileNodes) {
[email protected]72bdcfe2011-07-22 17:21:58539 ASSERT_EQ(model_.bookmark_bar_node(), model_.GetParentForNewNodes());
[email protected]6892e2e2011-05-26 22:07:17540
541 const string16 title(ASCIIToUTF16("foo"));
542 const GURL url("http://foo.com");
543
[email protected]37bc9132011-12-01 22:29:29544 model_.AddURL(model_.mobile_node(), 0, title, url);
545 ASSERT_EQ(model_.mobile_node(), model_.GetParentForNewNodes());
initial.commit09911bf2008-07-26 23:55:29546}
547
548// Make sure recently modified stays in sync when adding a URL.
[email protected]9fcaee72011-03-21 21:53:44549TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) {
[email protected]39703292011-03-18 17:03:40550 // Add a folder.
[email protected]6892e2e2011-05-26 22:07:17551 const BookmarkNode* folder = model_.AddFolder(model_.other_node(), 0,
552 ASCIIToUTF16("foo"));
initial.commit09911bf2008-07-26 23:55:29553 // Add a URL to it.
[email protected]6892e2e2011-05-26 22:07:17554 model_.AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com"));
initial.commit09911bf2008-07-26 23:55:29555
[email protected]39703292011-03-18 17:03:40556 // Make sure folder is in the most recently modified.
557 std::vector<const BookmarkNode*> most_recent_folders =
[email protected]6892e2e2011-05-26 22:07:17558 bookmark_utils::GetMostRecentlyModifiedFolders(&model_, 1);
[email protected]39703292011-03-18 17:03:40559 ASSERT_EQ(1U, most_recent_folders.size());
560 ASSERT_EQ(folder, most_recent_folders[0]);
initial.commit09911bf2008-07-26 23:55:29561
[email protected]39703292011-03-18 17:03:40562 // Nuke the folder and do another fetch, making sure folder isn't in the
initial.commit09911bf2008-07-26 23:55:29563 // returned list.
[email protected]6892e2e2011-05-26 22:07:17564 model_.Remove(folder->parent(), 0);
[email protected]39703292011-03-18 17:03:40565 most_recent_folders =
[email protected]6892e2e2011-05-26 22:07:17566 bookmark_utils::GetMostRecentlyModifiedFolders(&model_, 1);
[email protected]39703292011-03-18 17:03:40567 ASSERT_EQ(1U, most_recent_folders.size());
568 ASSERT_TRUE(most_recent_folders[0] != folder);
initial.commit09911bf2008-07-26 23:55:29569}
570
[email protected]f25387b2008-08-21 15:20:33571// Make sure MostRecentlyAddedEntries stays in sync.
[email protected]d8e41ed2008-09-11 15:22:32572TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) {
[email protected]f25387b2008-08-21 15:20:33573 // Add a couple of nodes such that the following holds for the time of the
574 // nodes: n1 > n2 > n3 > n4.
575 Time base_time = Time::Now();
[email protected]72bdcfe2011-07-22 17:21:58576 BookmarkNode* n1 = AsMutable(model_.AddURL(model_.bookmark_bar_node(),
577 0,
578 ASCIIToUTF16("blah"),
579 GURL("http://foo.com/0")));
580 BookmarkNode* n2 = AsMutable(model_.AddURL(model_.bookmark_bar_node(),
581 1,
582 ASCIIToUTF16("blah"),
583 GURL("http://foo.com/1")));
584 BookmarkNode* n3 = AsMutable(model_.AddURL(model_.bookmark_bar_node(),
585 2,
586 ASCIIToUTF16("blah"),
587 GURL("http://foo.com/2")));
588 BookmarkNode* n4 = AsMutable(model_.AddURL(model_.bookmark_bar_node(),
589 3,
590 ASCIIToUTF16("blah"),
591 GURL("http://foo.com/3")));
[email protected]b3c33d462009-06-26 22:29:20592 n1->set_date_added(base_time + TimeDelta::FromDays(4));
593 n2->set_date_added(base_time + TimeDelta::FromDays(3));
594 n3->set_date_added(base_time + TimeDelta::FromDays(2));
595 n4->set_date_added(base_time + TimeDelta::FromDays(1));
[email protected]f25387b2008-08-21 15:20:33596
597 // Make sure order is honored.
[email protected]b3c33d462009-06-26 22:29:20598 std::vector<const BookmarkNode*> recently_added;
[email protected]6892e2e2011-05-26 22:07:17599 bookmark_utils::GetMostRecentlyAddedEntries(&model_, 2, &recently_added);
[email protected]67e4a1e92009-03-03 19:29:45600 ASSERT_EQ(2U, recently_added.size());
[email protected]f25387b2008-08-21 15:20:33601 ASSERT_TRUE(n1 == recently_added[0]);
602 ASSERT_TRUE(n2 == recently_added[1]);
603
604 // swap 1 and 2, then check again.
605 recently_added.clear();
[email protected]b3c33d462009-06-26 22:29:20606 SwapDateAdded(n1, n2);
[email protected]6892e2e2011-05-26 22:07:17607 bookmark_utils::GetMostRecentlyAddedEntries(&model_, 4, &recently_added);
[email protected]67e4a1e92009-03-03 19:29:45608 ASSERT_EQ(4U, recently_added.size());
[email protected]f25387b2008-08-21 15:20:33609 ASSERT_TRUE(n2 == recently_added[0]);
610 ASSERT_TRUE(n1 == recently_added[1]);
611 ASSERT_TRUE(n3 == recently_added[2]);
612 ASSERT_TRUE(n4 == recently_added[3]);
613}
614
[email protected]848cd05e2008-09-19 18:33:48615// Makes sure GetMostRecentlyAddedNodeForURL stays in sync.
616TEST_F(BookmarkModelTest, GetMostRecentlyAddedNodeForURL) {
617 // Add a couple of nodes such that the following holds for the time of the
618 // nodes: n1 > n2
619 Time base_time = Time::Now();
620 const GURL url("http://foo.com/0");
[email protected]6892e2e2011-05-26 22:07:17621 BookmarkNode* n1 = AsMutable(model_.AddURL(
[email protected]72bdcfe2011-07-22 17:21:58622 model_.bookmark_bar_node(), 0, ASCIIToUTF16("blah"), url));
[email protected]6892e2e2011-05-26 22:07:17623 BookmarkNode* n2 = AsMutable(model_.AddURL(
[email protected]72bdcfe2011-07-22 17:21:58624 model_.bookmark_bar_node(), 1, ASCIIToUTF16("blah"), url));
[email protected]b3c33d462009-06-26 22:29:20625 n1->set_date_added(base_time + TimeDelta::FromDays(4));
626 n2->set_date_added(base_time + TimeDelta::FromDays(3));
[email protected]848cd05e2008-09-19 18:33:48627
628 // Make sure order is honored.
[email protected]6892e2e2011-05-26 22:07:17629 ASSERT_EQ(n1, model_.GetMostRecentlyAddedNodeForURL(url));
[email protected]848cd05e2008-09-19 18:33:48630
631 // swap 1 and 2, then check again.
[email protected]b3c33d462009-06-26 22:29:20632 SwapDateAdded(n1, n2);
[email protected]6892e2e2011-05-26 22:07:17633 ASSERT_EQ(n2, model_.GetMostRecentlyAddedNodeForURL(url));
[email protected]848cd05e2008-09-19 18:33:48634}
635
636// Makes sure GetBookmarks removes duplicates.
637TEST_F(BookmarkModelTest, GetBookmarksWithDups) {
638 const GURL url("http://foo.com/0");
[email protected]0f7bee52012-08-06 20:04:17639 const string16 title(ASCIIToUTF16("blah"));
640 model_.AddURL(model_.bookmark_bar_node(), 0, title, url);
641 model_.AddURL(model_.bookmark_bar_node(), 1, title, url);
[email protected]848cd05e2008-09-19 18:33:48642
[email protected]0f7bee52012-08-06 20:04:17643 std::vector<BookmarkService::URLAndTitle> bookmarks;
644 model_.GetBookmarks(&bookmarks);
645 ASSERT_EQ(1U, bookmarks.size());
646 EXPECT_EQ(url, bookmarks[0].url);
647 EXPECT_EQ(title, bookmarks[0].title);
648
649 model_.AddURL(model_.bookmark_bar_node(), 2, ASCIIToUTF16("Title2"), url);
650 // Only one returned, even titles are different.
651 bookmarks.clear();
652 model_.GetBookmarks(&bookmarks);
653 EXPECT_EQ(1U, bookmarks.size());
[email protected]848cd05e2008-09-19 18:33:48654}
655
[email protected]4478c652010-08-27 00:08:21656TEST_F(BookmarkModelTest, HasBookmarks) {
657 const GURL url("http://foo.com/");
[email protected]72bdcfe2011-07-22 17:21:58658 model_.AddURL(model_.bookmark_bar_node(), 0, ASCIIToUTF16("bar"), url);
[email protected]4478c652010-08-27 00:08:21659
[email protected]6892e2e2011-05-26 22:07:17660 EXPECT_TRUE(model_.HasBookmarks());
[email protected]4478c652010-08-27 00:08:21661}
662
[email protected]6c2381d2011-10-19 02:52:53663// content::NotificationObserver implementation used in verifying we've received
664// the NOTIFY_URLS_STARRED method correctly.
665class StarredListener : public content::NotificationObserver {
[email protected]848cd05e2008-09-19 18:33:48666 public:
667 StarredListener() : notification_count_(0), details_(false) {
[email protected]432115822011-07-10 15:52:27668 registrar_.Add(this, chrome::NOTIFICATION_URLS_STARRED,
[email protected]6c2381d2011-10-19 02:52:53669 content::Source<Profile>(NULL));
[email protected]848cd05e2008-09-19 18:33:48670 }
671
[email protected]ff6592a2011-07-14 21:41:14672 // NotificationObserver:
[email protected]432115822011-07-10 15:52:27673 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53674 const content::NotificationSource& source,
675 const content::NotificationDetails& details) OVERRIDE {
[email protected]432115822011-07-10 15:52:27676 if (type == chrome::NOTIFICATION_URLS_STARRED) {
[email protected]848cd05e2008-09-19 18:33:48677 notification_count_++;
[email protected]6c2381d2011-10-19 02:52:53678 details_ =
679 *(content::Details<history::URLsStarredDetails>(details).ptr());
[email protected]848cd05e2008-09-19 18:33:48680 }
681 }
682
683 // Number of times NOTIFY_URLS_STARRED has been observed.
684 int notification_count_;
685
686 // Details from the last NOTIFY_URLS_STARRED.
687 history::URLsStarredDetails details_;
688
689 private:
[email protected]6c2381d2011-10-19 02:52:53690 content::NotificationRegistrar registrar_;
[email protected]848cd05e2008-09-19 18:33:48691
692 DISALLOW_COPY_AND_ASSIGN(StarredListener);
693};
694
[email protected]848cd05e2008-09-19 18:33:48695// Makes sure NOTIFY_URLS_STARRED is sent correctly.
696TEST_F(BookmarkModelTest, NotifyURLsStarred) {
697 StarredListener listener;
698 const GURL url("http://foo.com/0");
[email protected]6892e2e2011-05-26 22:07:17699 const BookmarkNode* n1 = model_.AddURL(
[email protected]72bdcfe2011-07-22 17:21:58700 model_.bookmark_bar_node(), 0, ASCIIToUTF16("blah"), url);
[email protected]848cd05e2008-09-19 18:33:48701
702 // Starred notification should be sent.
703 EXPECT_EQ(1, listener.notification_count_);
704 ASSERT_TRUE(listener.details_.starred);
[email protected]67e4a1e92009-03-03 19:29:45705 ASSERT_EQ(1U, listener.details_.changed_urls.size());
[email protected]848cd05e2008-09-19 18:33:48706 EXPECT_TRUE(url == *(listener.details_.changed_urls.begin()));
707 listener.notification_count_ = 0;
708 listener.details_.changed_urls.clear();
709
710 // Add another bookmark for the same URL. This should not send any
711 // notification.
[email protected]6892e2e2011-05-26 22:07:17712 const BookmarkNode* n2 = model_.AddURL(
[email protected]72bdcfe2011-07-22 17:21:58713 model_.bookmark_bar_node(), 1, ASCIIToUTF16("blah"), url);
[email protected]848cd05e2008-09-19 18:33:48714
715 EXPECT_EQ(0, listener.notification_count_);
716
717 // Remove n2.
[email protected]6892e2e2011-05-26 22:07:17718 model_.Remove(n2->parent(), 1);
[email protected]848cd05e2008-09-19 18:33:48719 n2 = NULL;
720
721 // Shouldn't have received any notification as n1 still exists with the same
722 // URL.
723 EXPECT_EQ(0, listener.notification_count_);
724
[email protected]6892e2e2011-05-26 22:07:17725 EXPECT_TRUE(model_.GetMostRecentlyAddedNodeForURL(url) == n1);
[email protected]848cd05e2008-09-19 18:33:48726
727 // Remove n1.
[email protected]6892e2e2011-05-26 22:07:17728 model_.Remove(n1->parent(), 0);
[email protected]848cd05e2008-09-19 18:33:48729
730 // Now we should get the notification.
731 EXPECT_EQ(1, listener.notification_count_);
732 ASSERT_FALSE(listener.details_.starred);
[email protected]67e4a1e92009-03-03 19:29:45733 ASSERT_EQ(1U, listener.details_.changed_urls.size());
[email protected]848cd05e2008-09-19 18:33:48734 EXPECT_TRUE(url == *(listener.details_.changed_urls.begin()));
735}
736
initial.commit09911bf2008-07-26 23:55:29737// See comment in PopulateNodeFromString.
[email protected]44cbd9e2011-01-14 15:49:40738typedef ui::TreeNodeWithValue<BookmarkNode::Type> TestNode;
initial.commit09911bf2008-07-26 23:55:29739
740// Does the work of PopulateNodeFromString. index gives the index of the current
741// element in description to process.
[email protected]ff6592a2011-07-14 21:41:14742void PopulateNodeImpl(const std::vector<std::string>& description,
743 size_t* index,
744 TestNode* parent) {
initial.commit09911bf2008-07-26 23:55:29745 while (*index < description.size()) {
[email protected]0b0a7d72010-08-25 04:54:09746 const std::string& element = description[*index];
initial.commit09911bf2008-07-26 23:55:29747 (*index)++;
[email protected]0b0a7d72010-08-25 04:54:09748 if (element == "[") {
[email protected]39703292011-03-18 17:03:40749 // Create a new folder and recurse to add all the children.
[email protected]9fcaee72011-03-21 21:53:44750 // Folders are given a unique named by way of an ever increasing integer
[email protected]39703292011-03-18 17:03:40751 // value. The folders need not have a name, but one is assigned to help
initial.commit09911bf2008-07-26 23:55:29752 // in debugging.
[email protected]39703292011-03-18 17:03:40753 static int next_folder_id = 1;
initial.commit09911bf2008-07-26 23:55:29754 TestNode* new_node =
[email protected]39703292011-03-18 17:03:40755 new TestNode(base::IntToString16(next_folder_id++),
[email protected]bd1b96702009-07-08 21:54:14756 BookmarkNode::FOLDER);
[email protected]a0dd6a32011-03-18 17:31:37757 parent->Add(new_node, parent->child_count());
initial.commit09911bf2008-07-26 23:55:29758 PopulateNodeImpl(description, index, new_node);
[email protected]0b0a7d72010-08-25 04:54:09759 } else if (element == "]") {
[email protected]39703292011-03-18 17:03:40760 // End the current folder.
initial.commit09911bf2008-07-26 23:55:29761 return;
762 } else {
763 // Add a new URL.
764
765 // All tokens must be space separated. If there is a [ or ] in the name it
766 // likely means a space was forgotten.
767 DCHECK(element.find('[') == std::string::npos);
768 DCHECK(element.find(']') == std::string::npos);
[email protected]a0dd6a32011-03-18 17:31:37769 parent->Add(new TestNode(UTF8ToUTF16(element), BookmarkNode::URL),
770 parent->child_count());
initial.commit09911bf2008-07-26 23:55:29771 }
772 }
773}
774
775// Creates and adds nodes to parent based on description. description consists
776// of the following tokens (all space separated):
[email protected]9fcaee72011-03-21 21:53:44777// [ : creates a new USER_FOLDER node. All elements following the [ until the
initial.commit09911bf2008-07-26 23:55:29778// next balanced ] is encountered are added as children to the node.
[email protected]39703292011-03-18 17:03:40779// ] : closes the last folder created by [ so that any further nodes are added
780// to the current folders parent.
initial.commit09911bf2008-07-26 23:55:29781// text: creates a new URL node.
782// For example, "a [b] c" creates the following nodes:
783// a 1 c
784// |
785// b
[email protected]39703292011-03-18 17:03:40786// In words: a node of type URL with the title a, followed by a folder node with
initial.commit09911bf2008-07-26 23:55:29787// the title 1 having the single child of type url with name b, followed by
788// the url node with the title c.
789//
[email protected]39703292011-03-18 17:03:40790// NOTE: each name must be unique, and folders are assigned a unique title by
791// way of an increasing integer.
[email protected]ff6592a2011-07-14 21:41:14792void PopulateNodeFromString(const std::string& description, TestNode* parent) {
[email protected]0b0a7d72010-08-25 04:54:09793 std::vector<std::string> elements;
[email protected]b87c4a72010-11-15 22:03:42794 base::SplitStringAlongWhitespace(description, &elements);
[email protected]ff6592a2011-07-14 21:41:14795 size_t index = 0;
initial.commit09911bf2008-07-26 23:55:29796 PopulateNodeImpl(elements, &index, parent);
797}
798
[email protected]d8e41ed2008-09-11 15:22:32799// Populates the BookmarkNode with the children of parent.
[email protected]ff6592a2011-07-14 21:41:14800void PopulateBookmarkNode(TestNode* parent,
801 BookmarkModel* model,
802 const BookmarkNode* bb_node) {
[email protected]9c1a75a2011-03-10 02:38:12803 for (int i = 0; i < parent->child_count(); ++i) {
initial.commit09911bf2008-07-26 23:55:29804 TestNode* child = parent->GetChild(i);
[email protected]bd1b96702009-07-08 21:54:14805 if (child->value == BookmarkNode::FOLDER) {
[email protected]b3c33d462009-06-26 22:29:20806 const BookmarkNode* new_bb_node =
[email protected]39703292011-03-18 17:03:40807 model->AddFolder(bb_node, i, child->GetTitle());
[email protected]d8e41ed2008-09-11 15:22:32808 PopulateBookmarkNode(child, model, new_bb_node);
initial.commit09911bf2008-07-26 23:55:29809 } else {
[email protected]440b37b22010-08-30 05:31:40810 model->AddURL(bb_node, i, child->GetTitle(),
811 GURL("http://" + UTF16ToASCII(child->GetTitle())));
initial.commit09911bf2008-07-26 23:55:29812 }
813 }
814}
815
[email protected]d8e41ed2008-09-11 15:22:32816// Test class that creates a BookmarkModel with a real history backend.
[email protected]583844c2011-08-27 00:38:35817class BookmarkModelTestWithProfile : public testing::Test {
initial.commit09911bf2008-07-26 23:55:29818 public:
[email protected]6fad2632009-11-02 05:59:37819 BookmarkModelTestWithProfile()
[email protected]fe232e02012-08-07 15:09:38820 : bb_model_(NULL),
821 ui_thread_(BrowserThread::UI, &message_loop_),
[email protected]faec6312010-10-05 03:35:34822 file_thread_(BrowserThread::FILE, &message_loop_) {}
[email protected]6fad2632009-11-02 05:59:37823
[email protected]583844c2011-08-27 00:38:35824 // testing::Test:
[email protected]ff6592a2011-07-14 21:41:14825 virtual void TearDown() OVERRIDE {
initial.commit09911bf2008-07-26 23:55:29826 profile_.reset(NULL);
827 }
828
initial.commit09911bf2008-07-26 23:55:29829 protected:
830 // Verifies the contents of the bookmark bar node match the contents of the
831 // TestNode.
[email protected]b3c33d462009-06-26 22:29:20832 void VerifyModelMatchesNode(TestNode* expected, const BookmarkNode* actual) {
[email protected]9c1a75a2011-03-10 02:38:12833 ASSERT_EQ(expected->child_count(), actual->child_count());
834 for (int i = 0; i < expected->child_count(); ++i) {
initial.commit09911bf2008-07-26 23:55:29835 TestNode* expected_child = expected->GetChild(i);
[email protected]b3c33d462009-06-26 22:29:20836 const BookmarkNode* actual_child = actual->GetChild(i);
[email protected]440b37b22010-08-30 05:31:40837 ASSERT_EQ(expected_child->GetTitle(), actual_child->GetTitle());
[email protected]bd1b96702009-07-08 21:54:14838 if (expected_child->value == BookmarkNode::FOLDER) {
[email protected]037db002009-10-19 20:06:08839 ASSERT_TRUE(actual_child->type() == BookmarkNode::FOLDER);
initial.commit09911bf2008-07-26 23:55:29840 // Recurse throught children.
841 VerifyModelMatchesNode(expected_child, actual_child);
[email protected]f25387b2008-08-21 15:20:33842 if (HasFatalFailure())
843 return;
initial.commit09911bf2008-07-26 23:55:29844 } else {
845 // No need to check the URL, just the title is enough.
[email protected]0890e60e2011-06-27 14:55:21846 ASSERT_TRUE(actual_child->is_url());
initial.commit09911bf2008-07-26 23:55:29847 }
848 }
849 }
850
[email protected]999f3802009-05-22 19:28:00851 void VerifyNoDuplicateIDs(BookmarkModel* model) {
[email protected]44cbd9e2011-01-14 15:49:40852 ui::TreeNodeIterator<const BookmarkNode> it(model->root_node());
[email protected]367d7072009-07-13 23:27:13853 base::hash_set<int64> ids;
[email protected]999f3802009-05-22 19:28:00854 while (it.has_next())
855 ASSERT_TRUE(ids.insert(it.Next()->id()).second);
856 }
857
[email protected]90ef13132008-08-27 03:27:46858 void BlockTillBookmarkModelLoaded() {
[email protected]ddabf57e2012-08-02 00:53:47859 bb_model_ = BookmarkModelFactory::GetForProfile(profile_.get());
[email protected]c58c5ea2011-07-13 21:43:16860 profile_->BlockUntilBookmarkModelLoaded();
initial.commit09911bf2008-07-26 23:55:29861 }
862
[email protected]90ef13132008-08-27 03:27:46863 // Destroys the current profile, creates a new one and creates the history
864 // service.
initial.commit09911bf2008-07-26 23:55:29865 void RecreateProfile() {
initial.commit09911bf2008-07-26 23:55:29866 // Need to shutdown the old one before creating a new one.
867 profile_.reset(NULL);
868 profile_.reset(new TestingProfile());
[email protected]d486a0852009-11-02 21:40:00869 profile_->CreateHistoryService(true, false);
initial.commit09911bf2008-07-26 23:55:29870 }
871
[email protected]ff6592a2011-07-14 21:41:14872 // The profile.
873 scoped_ptr<TestingProfile> profile_;
[email protected]d8e41ed2008-09-11 15:22:32874 BookmarkModel* bb_model_;
initial.commit09911bf2008-07-26 23:55:29875
876 private:
[email protected]ab820df2008-08-26 05:55:10877 MessageLoopForUI message_loop_;
[email protected]c38831a12011-10-28 12:44:49878 content::TestBrowserThread ui_thread_;
879 content::TestBrowserThread file_thread_;
initial.commit09911bf2008-07-26 23:55:29880};
881
882// Creates a set of nodes in the bookmark bar model, then recreates the
883// bookmark bar model which triggers loading from the db and checks the loaded
884// structure to make sure it is what we first created.
[email protected]d8e41ed2008-09-11 15:22:32885TEST_F(BookmarkModelTestWithProfile, CreateAndRestore) {
initial.commit09911bf2008-07-26 23:55:29886 struct TestData {
887 // Structure of the children of the bookmark bar model node.
[email protected]0b0a7d72010-08-25 04:54:09888 const std::string bbn_contents;
initial.commit09911bf2008-07-26 23:55:29889 // Structure of the children of the other node.
[email protected]0b0a7d72010-08-25 04:54:09890 const std::string other_contents;
[email protected]6892e2e2011-05-26 22:07:17891 // Structure of the children of the synced node.
[email protected]37bc9132011-12-01 22:29:29892 const std::string mobile_contents;
initial.commit09911bf2008-07-26 23:55:29893 } data[] = {
894 // See PopulateNodeFromString for a description of these strings.
[email protected]0b0a7d72010-08-25 04:54:09895 { "", "" },
896 { "a", "b" },
897 { "a [ b ]", "" },
898 { "", "[ b ] a [ c [ d e [ f ] ] ]" },
899 { "a [ b ]", "" },
900 { "a b c [ d e [ f ] ]", "g h i [ j k [ l ] ]"},
initial.commit09911bf2008-07-26 23:55:29901 };
[email protected]67e4a1e92009-03-03 19:29:45902 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
[email protected]90ef13132008-08-27 03:27:46903 // Recreate the profile. We need to reset with NULL first so that the last
904 // HistoryService releases the locks on the files it creates and we can
905 // delete them.
906 profile_.reset(NULL);
907 profile_.reset(new TestingProfile());
[email protected]d8e41ed2008-09-11 15:22:32908 profile_->CreateBookmarkModel(true);
[email protected]d486a0852009-11-02 21:40:00909 profile_->CreateHistoryService(true, false);
[email protected]90ef13132008-08-27 03:27:46910 BlockTillBookmarkModelLoaded();
initial.commit09911bf2008-07-26 23:55:29911
912 TestNode bbn;
913 PopulateNodeFromString(data[i].bbn_contents, &bbn);
[email protected]72bdcfe2011-07-22 17:21:58914 PopulateBookmarkNode(&bbn, bb_model_, bb_model_->bookmark_bar_node());
initial.commit09911bf2008-07-26 23:55:29915
916 TestNode other;
917 PopulateNodeFromString(data[i].other_contents, &other);
[email protected]d8e41ed2008-09-11 15:22:32918 PopulateBookmarkNode(&other, bb_model_, bb_model_->other_node());
initial.commit09911bf2008-07-26 23:55:29919
[email protected]37bc9132011-12-01 22:29:29920 TestNode mobile;
921 PopulateNodeFromString(data[i].mobile_contents, &mobile);
922 PopulateBookmarkNode(&mobile, bb_model_, bb_model_->mobile_node());
[email protected]6892e2e2011-05-26 22:07:17923
[email protected]d8e41ed2008-09-11 15:22:32924 profile_->CreateBookmarkModel(false);
[email protected]90ef13132008-08-27 03:27:46925 BlockTillBookmarkModelLoaded();
initial.commit09911bf2008-07-26 23:55:29926
[email protected]72bdcfe2011-07-22 17:21:58927 VerifyModelMatchesNode(&bbn, bb_model_->bookmark_bar_node());
initial.commit09911bf2008-07-26 23:55:29928 VerifyModelMatchesNode(&other, bb_model_->other_node());
[email protected]37bc9132011-12-01 22:29:29929 VerifyModelMatchesNode(&mobile, bb_model_->mobile_node());
[email protected]999f3802009-05-22 19:28:00930 VerifyNoDuplicateIDs(bb_model_);
initial.commit09911bf2008-07-26 23:55:29931 }
932}
[email protected]1fcb8b02008-08-01 17:36:48933
[email protected]90ef13132008-08-27 03:27:46934// Simple test that removes a bookmark. This test exercises the code paths in
935// History that block till bookmark bar model is loaded.
[email protected]fa0e5c082012-08-30 03:21:53936TEST_F(BookmarkModelTestWithProfile, RemoveNotification) {
937 profile_.reset(new TestingProfile());
938
[email protected]d486a0852009-11-02 21:40:00939 profile_->CreateHistoryService(false, false);
[email protected]d8e41ed2008-09-11 15:22:32940 profile_->CreateBookmarkModel(true);
[email protected]90ef13132008-08-27 03:27:46941 BlockTillBookmarkModelLoaded();
942
943 // Add a URL.
944 GURL url("http://www.google.com");
[email protected]4394f2b2011-09-03 03:07:56945 bookmark_utils::AddIfNotBookmarked(bb_model_, url, string16());
[email protected]90ef13132008-08-27 03:27:46946
[email protected]9aac66862012-06-19 19:44:31947 HistoryServiceFactory::GetForProfile(
948 profile_.get(), Profile::EXPLICIT_ACCESS)->AddPage(
[email protected]853e01b2012-09-21 20:14:11949 url, base::Time::Now(), NULL, 1, GURL(), history::RedirectList(),
950 content::PAGE_TRANSITION_TYPED, history::SOURCE_BROWSED, false);
[email protected]90ef13132008-08-27 03:27:46951
952 // This won't actually delete the URL, rather it'll empty out the visits.
[email protected]d8e41ed2008-09-11 15:22:32953 // This triggers blocking on the BookmarkModel.
[email protected]ca881b82012-07-26 21:55:26954 HistoryServiceFactory::GetForProfile(
955 profile_.get(), Profile::EXPLICIT_ACCESS)->DeleteURL(url);
[email protected]90ef13132008-08-27 03:27:46956}
[email protected]e2f86d92009-02-25 00:22:01957
958TEST_F(BookmarkModelTest, Sort) {
959 // Populate the bookmark bar node with nodes for 'B', 'a', 'd' and 'C'.
[email protected]ef762642009-03-05 16:30:25960 // 'C' and 'a' are folders.
[email protected]e2f86d92009-02-25 00:22:01961 TestNode bbn;
[email protected]0b0a7d72010-08-25 04:54:09962 PopulateNodeFromString("B [ a ] d [ a ]", &bbn);
[email protected]72bdcfe2011-07-22 17:21:58963 const BookmarkNode* parent = model_.bookmark_bar_node();
[email protected]6892e2e2011-05-26 22:07:17964 PopulateBookmarkNode(&bbn, &model_, parent);
[email protected]e2f86d92009-02-25 00:22:01965
[email protected]b3c33d462009-06-26 22:29:20966 BookmarkNode* child1 = AsMutable(parent->GetChild(1));
[email protected]0491ff72011-12-30 00:45:59967 child1->SetTitle(ASCIIToUTF16("a"));
[email protected]18cc5ff2011-03-22 01:05:23968 delete child1->Remove(child1->GetChild(0));
[email protected]b3c33d462009-06-26 22:29:20969 BookmarkNode* child3 = AsMutable(parent->GetChild(3));
[email protected]0491ff72011-12-30 00:45:59970 child3->SetTitle(ASCIIToUTF16("C"));
[email protected]18cc5ff2011-03-22 01:05:23971 delete child3->Remove(child3->GetChild(0));
[email protected]ef762642009-03-05 16:30:25972
[email protected]e2f86d92009-02-25 00:22:01973 ClearCounts();
974
975 // Sort the children of the bookmark bar node.
[email protected]6892e2e2011-05-26 22:07:17976 model_.SortChildren(parent);
[email protected]e2f86d92009-02-25 00:22:01977
978 // Make sure we were notified.
979 AssertObserverCount(0, 0, 0, 0, 1);
980
[email protected]ef762642009-03-05 16:30:25981 // Make sure the order matches (remember, 'a' and 'C' are folders and
982 // come first).
[email protected]440b37b22010-08-30 05:31:40983 EXPECT_EQ(parent->GetChild(0)->GetTitle(), ASCIIToUTF16("a"));
984 EXPECT_EQ(parent->GetChild(1)->GetTitle(), ASCIIToUTF16("C"));
985 EXPECT_EQ(parent->GetChild(2)->GetTitle(), ASCIIToUTF16("B"));
986 EXPECT_EQ(parent->GetChild(3)->GetTitle(), ASCIIToUTF16("d"));
[email protected]e2f86d92009-02-25 00:22:01987}
[email protected]6892e2e2011-05-26 22:07:17988
[email protected]97fdd162011-12-03 20:50:12989TEST_F(BookmarkModelTest, NodeVisibility) {
990 EXPECT_TRUE(model_.bookmark_bar_node()->IsVisible());
991 EXPECT_TRUE(model_.other_node()->IsVisible());
992 // Mobile node invisible by default
993 EXPECT_FALSE(model_.mobile_node()->IsVisible());
994
[email protected]bc770a032011-12-12 17:35:30995 // Change visibility of permanent nodes.
996 model_.SetPermanentNodeVisible(BookmarkNode::BOOKMARK_BAR, false);
997 EXPECT_FALSE(model_.bookmark_bar_node()->IsVisible());
998 model_.SetPermanentNodeVisible(BookmarkNode::OTHER_NODE, false);
999 EXPECT_FALSE(model_.other_node()->IsVisible());
1000 model_.SetPermanentNodeVisible(BookmarkNode::MOBILE, true);
1001 EXPECT_TRUE(model_.mobile_node()->IsVisible());
1002
[email protected]97fdd162011-12-03 20:50:121003 // Arbitrary node should be visible
1004 TestNode bbn;
1005 PopulateNodeFromString("B", &bbn);
1006 const BookmarkNode* parent = model_.bookmark_bar_node();
1007 PopulateBookmarkNode(&bbn, &model_, parent);
1008 EXPECT_TRUE(parent->GetChild(0)->IsVisible());
[email protected]bc770a032011-12-12 17:35:301009
1010 // Bookmark bar should be visible now that it has a child.
1011 EXPECT_TRUE(model_.bookmark_bar_node()->IsVisible());
[email protected]97fdd162011-12-03 20:50:121012}
1013
1014TEST_F(BookmarkModelTest, MobileNodeVisibileWithChildren) {
1015 const BookmarkNode* root = model_.mobile_node();
1016 const string16 title(ASCIIToUTF16("foo"));
1017 const GURL url("http://foo.com");
1018
1019 model_.AddURL(root, 0, title, url);
1020 EXPECT_TRUE(model_.mobile_node()->IsVisible());
1021}
1022
[email protected]b68a8172012-02-17 00:25:181023TEST_F(BookmarkModelTest, ExtensiveChangesObserver) {
1024 AssertExtensiveChangesObserverCount(0, 0);
1025 EXPECT_FALSE(model_.IsDoingExtensiveChanges());
1026 model_.BeginExtensiveChanges();
1027 EXPECT_TRUE(model_.IsDoingExtensiveChanges());
1028 AssertExtensiveChangesObserverCount(1, 0);
1029 model_.EndExtensiveChanges();
1030 EXPECT_FALSE(model_.IsDoingExtensiveChanges());
1031 AssertExtensiveChangesObserverCount(1, 1);
1032}
1033
1034TEST_F(BookmarkModelTest, MultipleExtensiveChangesObserver) {
1035 AssertExtensiveChangesObserverCount(0, 0);
1036 EXPECT_FALSE(model_.IsDoingExtensiveChanges());
1037 model_.BeginExtensiveChanges();
1038 EXPECT_TRUE(model_.IsDoingExtensiveChanges());
1039 AssertExtensiveChangesObserverCount(1, 0);
1040 model_.BeginExtensiveChanges();
1041 EXPECT_TRUE(model_.IsDoingExtensiveChanges());
1042 AssertExtensiveChangesObserverCount(1, 0);
1043 model_.EndExtensiveChanges();
1044 EXPECT_TRUE(model_.IsDoingExtensiveChanges());
1045 AssertExtensiveChangesObserverCount(1, 0);
1046 model_.EndExtensiveChanges();
1047 EXPECT_FALSE(model_.IsDoingExtensiveChanges());
1048 AssertExtensiveChangesObserverCount(1, 1);
1049}
1050
[email protected]ff6592a2011-07-14 21:41:141051} // namespace