OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/bookmarks/bookmark_utils.h" | 5 #include "chrome/browser/bookmarks/bookmark_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 int grouped_changes_beginning_count_; | 63 int grouped_changes_beginning_count_; |
64 int grouped_changes_ended_count_; | 64 int grouped_changes_ended_count_; |
65 | 65 |
66 // Clipboard requires a message loop. | 66 // Clipboard requires a message loop. |
67 base::MessageLoopForUI loop_; | 67 base::MessageLoopForUI loop_; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(BookmarkUtilsTest); | 69 DISALLOW_COPY_AND_ASSIGN(BookmarkUtilsTest); |
70 }; | 70 }; |
71 | 71 |
72 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesWordPhraseQuery) { | 72 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesWordPhraseQuery) { |
73 BookmarkModel model(NULL); | 73 BookmarkModel model(NULL, false); |
74 const BookmarkNode* node1 = model.AddURL(model.other_node(), | 74 const BookmarkNode* node1 = model.AddURL(model.other_node(), |
75 0, | 75 0, |
76 ASCIIToUTF16("foo bar"), | 76 ASCIIToUTF16("foo bar"), |
77 GURL("http://www.google.com")); | 77 GURL("http://www.google.com")); |
78 const BookmarkNode* node2 = model.AddURL(model.other_node(), | 78 const BookmarkNode* node2 = model.AddURL(model.other_node(), |
79 0, | 79 0, |
80 ASCIIToUTF16("baz buz"), | 80 ASCIIToUTF16("baz buz"), |
81 GURL("http://www.cnn.com")); | 81 GURL("http://www.cnn.com")); |
82 const BookmarkNode* folder1 = model.AddFolder(model.other_node(), | 82 const BookmarkNode* folder1 = model.AddFolder(model.other_node(), |
83 0, | 83 0, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 // Bookmark Bar and Other Bookmarks are not returned in search results. | 122 // Bookmark Bar and Other Bookmarks are not returned in search results. |
123 *query.word_phrase_query = ASCIIToUTF16("Bookmark"); | 123 *query.word_phrase_query = ASCIIToUTF16("Bookmark"); |
124 GetBookmarksMatchingProperties(&model, query, 100, string(), &nodes); | 124 GetBookmarksMatchingProperties(&model, query, 100, string(), &nodes); |
125 ASSERT_EQ(0U, nodes.size()); | 125 ASSERT_EQ(0U, nodes.size()); |
126 nodes.clear(); | 126 nodes.clear(); |
127 } | 127 } |
128 | 128 |
129 // Check exact matching against a URL query. | 129 // Check exact matching against a URL query. |
130 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesUrl) { | 130 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesUrl) { |
131 BookmarkModel model(NULL); | 131 BookmarkModel model(NULL, false); |
132 const BookmarkNode* node1 = model.AddURL(model.other_node(), | 132 const BookmarkNode* node1 = model.AddURL(model.other_node(), |
133 0, | 133 0, |
134 ASCIIToUTF16("Google"), | 134 ASCIIToUTF16("Google"), |
135 GURL("https://www.google.com/")); | 135 GURL("https://www.google.com/")); |
136 model.AddURL(model.other_node(), | 136 model.AddURL(model.other_node(), |
137 0, | 137 0, |
138 ASCIIToUTF16("Google Calendar"), | 138 ASCIIToUTF16("Google Calendar"), |
139 GURL("https://www.google.com/calendar")); | 139 GURL("https://www.google.com/calendar")); |
140 | 140 |
141 model.AddFolder(model.other_node(), 0, ASCIIToUTF16("Folder")); | 141 model.AddFolder(model.other_node(), 0, ASCIIToUTF16("Folder")); |
(...skipping 14 matching lines...) Expand all Loading... |
156 | 156 |
157 // Empty URL should not match folders. | 157 // Empty URL should not match folders. |
158 *query.url = ASCIIToUTF16(""); | 158 *query.url = ASCIIToUTF16(""); |
159 GetBookmarksMatchingProperties(&model, query, 100, string(), &nodes); | 159 GetBookmarksMatchingProperties(&model, query, 100, string(), &nodes); |
160 ASSERT_EQ(0U, nodes.size()); | 160 ASSERT_EQ(0U, nodes.size()); |
161 nodes.clear(); | 161 nodes.clear(); |
162 } | 162 } |
163 | 163 |
164 // Check exact matching against a title query. | 164 // Check exact matching against a title query. |
165 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesTitle) { | 165 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesTitle) { |
166 BookmarkModel model(NULL); | 166 BookmarkModel model(NULL, false); |
167 const BookmarkNode* node1 = model.AddURL(model.other_node(), | 167 const BookmarkNode* node1 = model.AddURL(model.other_node(), |
168 0, | 168 0, |
169 ASCIIToUTF16("Google"), | 169 ASCIIToUTF16("Google"), |
170 GURL("https://www.google.com/")); | 170 GURL("https://www.google.com/")); |
171 model.AddURL(model.other_node(), | 171 model.AddURL(model.other_node(), |
172 0, | 172 0, |
173 ASCIIToUTF16("Google Calendar"), | 173 ASCIIToUTF16("Google Calendar"), |
174 GURL("https://www.google.com/calendar")); | 174 GURL("https://www.google.com/calendar")); |
175 | 175 |
176 const BookmarkNode* folder1 = | 176 const BookmarkNode* folder1 = |
(...skipping 16 matching lines...) Expand all Loading... |
193 // Title should match folders. | 193 // Title should match folders. |
194 *query.title = ASCIIToUTF16("Folder"); | 194 *query.title = ASCIIToUTF16("Folder"); |
195 GetBookmarksMatchingProperties(&model, query, 100, string(), &nodes); | 195 GetBookmarksMatchingProperties(&model, query, 100, string(), &nodes); |
196 ASSERT_EQ(1U, nodes.size()); | 196 ASSERT_EQ(1U, nodes.size()); |
197 EXPECT_TRUE(nodes[0] == folder1); | 197 EXPECT_TRUE(nodes[0] == folder1); |
198 nodes.clear(); | 198 nodes.clear(); |
199 } | 199 } |
200 | 200 |
201 // Check matching against a query with multiple predicates. | 201 // Check matching against a query with multiple predicates. |
202 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesConjunction) { | 202 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesConjunction) { |
203 BookmarkModel model(NULL); | 203 BookmarkModel model(NULL, false); |
204 const BookmarkNode* node1 = model.AddURL(model.other_node(), | 204 const BookmarkNode* node1 = model.AddURL(model.other_node(), |
205 0, | 205 0, |
206 ASCIIToUTF16("Google"), | 206 ASCIIToUTF16("Google"), |
207 GURL("https://www.google.com/")); | 207 GURL("https://www.google.com/")); |
208 model.AddURL(model.other_node(), | 208 model.AddURL(model.other_node(), |
209 0, | 209 0, |
210 ASCIIToUTF16("Google Calendar"), | 210 ASCIIToUTF16("Google Calendar"), |
211 GURL("https://www.google.com/calendar")); | 211 GURL("https://www.google.com/calendar")); |
212 | 212 |
213 model.AddFolder(model.other_node(), 0, ASCIIToUTF16("Folder")); | 213 model.AddFolder(model.other_node(), 0, ASCIIToUTF16("Folder")); |
(...skipping 28 matching lines...) Expand all Loading... |
242 scoped_ptr<base::string16> original_value(fields[i]->release()); | 242 scoped_ptr<base::string16> original_value(fields[i]->release()); |
243 fields[i]->reset(new base::string16(ASCIIToUTF16("fjdkslafjkldsa"))); | 243 fields[i]->reset(new base::string16(ASCIIToUTF16("fjdkslafjkldsa"))); |
244 GetBookmarksMatchingProperties(&model, query, 100, string(), &nodes); | 244 GetBookmarksMatchingProperties(&model, query, 100, string(), &nodes); |
245 ASSERT_EQ(0U, nodes.size()); | 245 ASSERT_EQ(0U, nodes.size()); |
246 nodes.clear(); | 246 nodes.clear(); |
247 fields[i]->reset(original_value.release()); | 247 fields[i]->reset(original_value.release()); |
248 } | 248 } |
249 } | 249 } |
250 | 250 |
251 TEST_F(BookmarkUtilsTest, CopyPaste) { | 251 TEST_F(BookmarkUtilsTest, CopyPaste) { |
252 BookmarkModel model(NULL); | 252 BookmarkModel model(NULL, false); |
253 const BookmarkNode* node = model.AddURL(model.other_node(), | 253 const BookmarkNode* node = model.AddURL(model.other_node(), |
254 0, | 254 0, |
255 ASCIIToUTF16("foo bar"), | 255 ASCIIToUTF16("foo bar"), |
256 GURL("http://www.google.com")); | 256 GURL("http://www.google.com")); |
257 | 257 |
258 // Copy a node to the clipboard. | 258 // Copy a node to the clipboard. |
259 std::vector<const BookmarkNode*> nodes; | 259 std::vector<const BookmarkNode*> nodes; |
260 nodes.push_back(node); | 260 nodes.push_back(node); |
261 CopyToClipboard(&model, nodes, false); | 261 CopyToClipboard(&model, nodes, false); |
262 | 262 |
263 // And make sure we can paste a bookmark from the clipboard. | 263 // And make sure we can paste a bookmark from the clipboard. |
264 EXPECT_TRUE(CanPasteFromClipboard(model.bookmark_bar_node())); | 264 EXPECT_TRUE(CanPasteFromClipboard(model.bookmark_bar_node())); |
265 | 265 |
266 // Write some text to the clipboard. | 266 // Write some text to the clipboard. |
267 { | 267 { |
268 ui::ScopedClipboardWriter clipboard_writer( | 268 ui::ScopedClipboardWriter clipboard_writer( |
269 ui::Clipboard::GetForCurrentThread(), | 269 ui::Clipboard::GetForCurrentThread(), |
270 ui::CLIPBOARD_TYPE_COPY_PASTE); | 270 ui::CLIPBOARD_TYPE_COPY_PASTE); |
271 clipboard_writer.WriteText(ASCIIToUTF16("foo")); | 271 clipboard_writer.WriteText(ASCIIToUTF16("foo")); |
272 } | 272 } |
273 | 273 |
274 // Now we shouldn't be able to paste from the clipboard. | 274 // Now we shouldn't be able to paste from the clipboard. |
275 EXPECT_FALSE(CanPasteFromClipboard(model.bookmark_bar_node())); | 275 EXPECT_FALSE(CanPasteFromClipboard(model.bookmark_bar_node())); |
276 } | 276 } |
277 | 277 |
278 TEST_F(BookmarkUtilsTest, CutToClipboard) { | 278 TEST_F(BookmarkUtilsTest, CutToClipboard) { |
279 BookmarkModel model(NULL); | 279 BookmarkModel model(NULL, false); |
280 model.AddObserver(this); | 280 model.AddObserver(this); |
281 | 281 |
282 base::string16 title(ASCIIToUTF16("foo")); | 282 base::string16 title(ASCIIToUTF16("foo")); |
283 GURL url("http://foo.com"); | 283 GURL url("http://foo.com"); |
284 const BookmarkNode* n1 = model.AddURL(model.other_node(), 0, title, url); | 284 const BookmarkNode* n1 = model.AddURL(model.other_node(), 0, title, url); |
285 const BookmarkNode* n2 = model.AddURL(model.other_node(), 1, title, url); | 285 const BookmarkNode* n2 = model.AddURL(model.other_node(), 1, title, url); |
286 | 286 |
287 // Cut the nodes to the clipboard. | 287 // Cut the nodes to the clipboard. |
288 std::vector<const BookmarkNode*> nodes; | 288 std::vector<const BookmarkNode*> nodes; |
289 nodes.push_back(n1); | 289 nodes.push_back(n1); |
290 nodes.push_back(n2); | 290 nodes.push_back(n2); |
291 CopyToClipboard(&model, nodes, true); | 291 CopyToClipboard(&model, nodes, true); |
292 | 292 |
293 // Make sure the nodes were removed. | 293 // Make sure the nodes were removed. |
294 EXPECT_EQ(0, model.other_node()->child_count()); | 294 EXPECT_EQ(0, model.other_node()->child_count()); |
295 | 295 |
296 // Make sure observers were notified the set of changes should be grouped. | 296 // Make sure observers were notified the set of changes should be grouped. |
297 ExpectGroupedChangeCount(1, 1); | 297 ExpectGroupedChangeCount(1, 1); |
298 | 298 |
299 // And make sure we can paste from the clipboard. | 299 // And make sure we can paste from the clipboard. |
300 EXPECT_TRUE(CanPasteFromClipboard(model.other_node())); | 300 EXPECT_TRUE(CanPasteFromClipboard(model.other_node())); |
301 } | 301 } |
302 | 302 |
303 TEST_F(BookmarkUtilsTest, GetParentForNewNodes) { | 303 TEST_F(BookmarkUtilsTest, GetParentForNewNodes) { |
304 BookmarkModel model(NULL); | 304 BookmarkModel model(NULL, false); |
305 // This tests the case where selection contains one item and that item is a | 305 // This tests the case where selection contains one item and that item is a |
306 // folder. | 306 // folder. |
307 std::vector<const BookmarkNode*> nodes; | 307 std::vector<const BookmarkNode*> nodes; |
308 nodes.push_back(model.bookmark_bar_node()); | 308 nodes.push_back(model.bookmark_bar_node()); |
309 int index = -1; | 309 int index = -1; |
310 const BookmarkNode* real_parent = GetParentForNewNodes( | 310 const BookmarkNode* real_parent = GetParentForNewNodes( |
311 model.bookmark_bar_node(), nodes, &index); | 311 model.bookmark_bar_node(), nodes, &index); |
312 EXPECT_EQ(real_parent, model.bookmark_bar_node()); | 312 EXPECT_EQ(real_parent, model.bookmark_bar_node()); |
313 EXPECT_EQ(0, index); | 313 EXPECT_EQ(0, index); |
314 | 314 |
(...skipping 20 matching lines...) Expand all Loading... |
335 | 335 |
336 // This tests the case where selection doesn't contain any items. | 336 // This tests the case where selection doesn't contain any items. |
337 nodes.clear(); | 337 nodes.clear(); |
338 real_parent = GetParentForNewNodes(model.bookmark_bar_node(), nodes, &index); | 338 real_parent = GetParentForNewNodes(model.bookmark_bar_node(), nodes, &index); |
339 EXPECT_EQ(real_parent, model.bookmark_bar_node()); | 339 EXPECT_EQ(real_parent, model.bookmark_bar_node()); |
340 EXPECT_EQ(2, index); | 340 EXPECT_EQ(2, index); |
341 } | 341 } |
342 | 342 |
343 // Verifies that meta info is copied when nodes are cloned. | 343 // Verifies that meta info is copied when nodes are cloned. |
344 TEST_F(BookmarkUtilsTest, CloneMetaInfo) { | 344 TEST_F(BookmarkUtilsTest, CloneMetaInfo) { |
345 BookmarkModel model(NULL); | 345 BookmarkModel model(NULL, false); |
346 // Add a node containing meta info. | 346 // Add a node containing meta info. |
347 const BookmarkNode* node = model.AddURL(model.other_node(), | 347 const BookmarkNode* node = model.AddURL(model.other_node(), |
348 0, | 348 0, |
349 ASCIIToUTF16("foo bar"), | 349 ASCIIToUTF16("foo bar"), |
350 GURL("http://www.google.com")); | 350 GURL("http://www.google.com")); |
351 model.SetNodeMetaInfo(node, "somekey", "somevalue"); | 351 model.SetNodeMetaInfo(node, "somekey", "somevalue"); |
352 model.SetNodeMetaInfo(node, "someotherkey", "someothervalue"); | 352 model.SetNodeMetaInfo(node, "someotherkey", "someothervalue"); |
353 | 353 |
354 // Clone node to a different folder. | 354 // Clone node to a different folder. |
355 const BookmarkNode* folder = model.AddFolder(model.bookmark_bar_node(), 0, | 355 const BookmarkNode* folder = model.AddFolder(model.bookmark_bar_node(), 0, |
(...skipping 11 matching lines...) Expand all Loading... |
367 EXPECT_EQ(2u, clone->GetMetaInfoMap()->size()); | 367 EXPECT_EQ(2u, clone->GetMetaInfoMap()->size()); |
368 std::string value; | 368 std::string value; |
369 EXPECT_TRUE(clone->GetMetaInfo("somekey", &value)); | 369 EXPECT_TRUE(clone->GetMetaInfo("somekey", &value)); |
370 EXPECT_EQ("somevalue", value); | 370 EXPECT_EQ("somevalue", value); |
371 EXPECT_TRUE(clone->GetMetaInfo("someotherkey", &value)); | 371 EXPECT_TRUE(clone->GetMetaInfo("someotherkey", &value)); |
372 EXPECT_EQ("someothervalue", value); | 372 EXPECT_EQ("someothervalue", value); |
373 } | 373 } |
374 | 374 |
375 } // namespace | 375 } // namespace |
376 } // namespace bookmark_utils | 376 } // namespace bookmark_utils |
OLD | NEW |