OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/bookmarks/browser/bookmark_model.h" | 5 #include "components/bookmarks/browser/bookmark_model.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 void AssertExtensiveChangesObserverCount( | 260 void AssertExtensiveChangesObserverCount( |
261 int extensive_changes_beginning_count, | 261 int extensive_changes_beginning_count, |
262 int extensive_changes_ended_count) { | 262 int extensive_changes_ended_count) { |
263 EXPECT_EQ(extensive_changes_beginning_count_, | 263 EXPECT_EQ(extensive_changes_beginning_count_, |
264 extensive_changes_beginning_count); | 264 extensive_changes_beginning_count); |
265 EXPECT_EQ(extensive_changes_ended_count_, extensive_changes_ended_count); | 265 EXPECT_EQ(extensive_changes_ended_count_, extensive_changes_ended_count); |
266 } | 266 } |
267 | 267 |
268 int AllNodesRemovedObserverCount() const { return all_bookmarks_removed_; } | 268 int AllNodesRemovedObserverCount() const { return all_bookmarks_removed_; } |
269 | 269 |
270 BookmarkPermanentNode* ReloadModelWithExtraNode() { | |
271 BookmarkPermanentNode* extra_node = new BookmarkPermanentNode(100); | |
272 bookmarks::BookmarkPermanentNodeList extra_nodes; | |
273 extra_nodes.push_back(extra_node); | |
274 client_.SetExtraNodesToLoad(extra_nodes.Pass()); | |
275 | |
276 model_->RemoveObserver(this); | |
277 model_ = client_.CreateModel(false); | |
278 model_->AddObserver(this); | |
279 ClearCounts(); | |
280 | |
281 if (model_->root_node()->GetIndexOf(extra_node) == -1) | |
282 ADD_FAILURE(); | |
283 | |
284 return extra_node; | |
285 } | |
286 | |
287 protected: | 270 protected: |
288 test::TestBookmarkClient client_; | 271 test::TestBookmarkClient client_; |
289 scoped_ptr<BookmarkModel> model_; | 272 scoped_ptr<BookmarkModel> model_; |
290 ObserverDetails observer_details_; | 273 ObserverDetails observer_details_; |
291 | 274 |
292 private: | 275 private: |
293 int added_count_; | 276 int added_count_; |
294 int moved_count_; | 277 int moved_count_; |
295 int removed_count_; | 278 int removed_count_; |
296 int changed_count_; | 279 int changed_count_; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 const GURL url("http://foo.com"); | 316 const GURL url("http://foo.com"); |
334 | 317 |
335 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); | 318 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); |
336 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 319 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
337 observer_details_.ExpectEquals(root, NULL, 0, -1); | 320 observer_details_.ExpectEquals(root, NULL, 0, -1); |
338 | 321 |
339 ASSERT_EQ(1, root->child_count()); | 322 ASSERT_EQ(1, root->child_count()); |
340 ASSERT_EQ(title, new_node->GetTitle()); | 323 ASSERT_EQ(title, new_node->GetTitle()); |
341 ASSERT_TRUE(url == new_node->url()); | 324 ASSERT_TRUE(url == new_node->url()); |
342 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 325 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
343 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); | 326 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); |
344 | 327 |
345 EXPECT_TRUE(new_node->id() != root->id() && | 328 EXPECT_TRUE(new_node->id() != root->id() && |
346 new_node->id() != model_->other_node()->id() && | 329 new_node->id() != model_->other_node()->id() && |
347 new_node->id() != model_->mobile_node()->id()); | 330 new_node->id() != model_->mobile_node()->id()); |
348 } | 331 } |
349 | 332 |
350 TEST_F(BookmarkModelTest, AddURLWithUnicodeTitle) { | 333 TEST_F(BookmarkModelTest, AddURLWithUnicodeTitle) { |
351 const BookmarkNode* root = model_->bookmark_bar_node(); | 334 const BookmarkNode* root = model_->bookmark_bar_node(); |
352 const base::string16 title(base::WideToUTF16( | 335 const base::string16 title(base::WideToUTF16( |
353 L"\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053")); | 336 L"\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053")); |
354 const GURL url("https://www.baidu.com/"); | 337 const GURL url("https://www.baidu.com/"); |
355 | 338 |
356 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); | 339 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); |
357 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 340 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
358 observer_details_.ExpectEquals(root, NULL, 0, -1); | 341 observer_details_.ExpectEquals(root, NULL, 0, -1); |
359 | 342 |
360 ASSERT_EQ(1, root->child_count()); | 343 ASSERT_EQ(1, root->child_count()); |
361 ASSERT_EQ(title, new_node->GetTitle()); | 344 ASSERT_EQ(title, new_node->GetTitle()); |
362 ASSERT_TRUE(url == new_node->url()); | 345 ASSERT_TRUE(url == new_node->url()); |
363 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 346 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
364 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); | 347 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); |
365 | 348 |
366 EXPECT_TRUE(new_node->id() != root->id() && | 349 EXPECT_TRUE(new_node->id() != root->id() && |
367 new_node->id() != model_->other_node()->id() && | 350 new_node->id() != model_->other_node()->id() && |
368 new_node->id() != model_->mobile_node()->id()); | 351 new_node->id() != model_->mobile_node()->id()); |
369 } | 352 } |
370 | 353 |
371 TEST_F(BookmarkModelTest, AddURLWithWhitespaceTitle) { | 354 TEST_F(BookmarkModelTest, AddURLWithWhitespaceTitle) { |
372 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_whitespace_test_cases); ++i) { | 355 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_whitespace_test_cases); ++i) { |
373 const BookmarkNode* root = model_->bookmark_bar_node(); | 356 const BookmarkNode* root = model_->bookmark_bar_node(); |
374 const base::string16 title( | 357 const base::string16 title( |
(...skipping 23 matching lines...) Expand all Loading... |
398 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 381 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
399 observer_details_.ExpectEquals(root, NULL, 0, -1); | 382 observer_details_.ExpectEquals(root, NULL, 0, -1); |
400 | 383 |
401 ASSERT_EQ(1, root->child_count()); | 384 ASSERT_EQ(1, root->child_count()); |
402 ASSERT_EQ(title, new_node->GetTitle()); | 385 ASSERT_EQ(title, new_node->GetTitle()); |
403 ASSERT_TRUE(url == new_node->url()); | 386 ASSERT_TRUE(url == new_node->url()); |
404 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 387 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
405 ASSERT_EQ(time, new_node->date_added()); | 388 ASSERT_EQ(time, new_node->date_added()); |
406 ASSERT_TRUE(new_node->GetMetaInfoMap()); | 389 ASSERT_TRUE(new_node->GetMetaInfoMap()); |
407 ASSERT_EQ(meta_info, *new_node->GetMetaInfoMap()); | 390 ASSERT_EQ(meta_info, *new_node->GetMetaInfoMap()); |
408 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); | 391 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); |
409 | 392 |
410 EXPECT_TRUE(new_node->id() != root->id() && | 393 EXPECT_TRUE(new_node->id() != root->id() && |
411 new_node->id() != model_->other_node()->id() && | 394 new_node->id() != model_->other_node()->id() && |
412 new_node->id() != model_->mobile_node()->id()); | 395 new_node->id() != model_->mobile_node()->id()); |
413 } | 396 } |
414 | 397 |
415 TEST_F(BookmarkModelTest, AddURLToMobileBookmarks) { | 398 TEST_F(BookmarkModelTest, AddURLToMobileBookmarks) { |
416 const BookmarkNode* root = model_->mobile_node(); | 399 const BookmarkNode* root = model_->mobile_node(); |
417 const base::string16 title(ASCIIToUTF16("foo")); | 400 const base::string16 title(ASCIIToUTF16("foo")); |
418 const GURL url("http://foo.com"); | 401 const GURL url("http://foo.com"); |
419 | 402 |
420 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); | 403 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); |
421 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 404 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
422 observer_details_.ExpectEquals(root, NULL, 0, -1); | 405 observer_details_.ExpectEquals(root, NULL, 0, -1); |
423 | 406 |
424 ASSERT_EQ(1, root->child_count()); | 407 ASSERT_EQ(1, root->child_count()); |
425 ASSERT_EQ(title, new_node->GetTitle()); | 408 ASSERT_EQ(title, new_node->GetTitle()); |
426 ASSERT_TRUE(url == new_node->url()); | 409 ASSERT_TRUE(url == new_node->url()); |
427 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 410 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
428 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); | 411 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); |
429 | 412 |
430 EXPECT_TRUE(new_node->id() != root->id() && | 413 EXPECT_TRUE(new_node->id() != root->id() && |
431 new_node->id() != model_->other_node()->id() && | 414 new_node->id() != model_->other_node()->id() && |
432 new_node->id() != model_->mobile_node()->id()); | 415 new_node->id() != model_->mobile_node()->id()); |
433 } | 416 } |
434 | 417 |
435 TEST_F(BookmarkModelTest, AddFolder) { | 418 TEST_F(BookmarkModelTest, AddFolder) { |
436 const BookmarkNode* root = model_->bookmark_bar_node(); | 419 const BookmarkNode* root = model_->bookmark_bar_node(); |
437 const base::string16 title(ASCIIToUTF16("foo")); | 420 const base::string16 title(ASCIIToUTF16("foo")); |
438 | 421 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 const GURL url("http://foo.com"); | 460 const GURL url("http://foo.com"); |
478 model_->AddURL(root, 0, title, url); | 461 model_->AddURL(root, 0, title, url); |
479 ClearCounts(); | 462 ClearCounts(); |
480 | 463 |
481 model_->Remove(root, 0); | 464 model_->Remove(root, 0); |
482 ASSERT_EQ(0, root->child_count()); | 465 ASSERT_EQ(0, root->child_count()); |
483 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); | 466 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); |
484 observer_details_.ExpectEquals(root, NULL, 0, -1); | 467 observer_details_.ExpectEquals(root, NULL, 0, -1); |
485 | 468 |
486 // Make sure there is no mapping for the URL. | 469 // Make sure there is no mapping for the URL. |
487 ASSERT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); | 470 ASSERT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == NULL); |
488 } | 471 } |
489 | 472 |
490 TEST_F(BookmarkModelTest, RemoveFolder) { | 473 TEST_F(BookmarkModelTest, RemoveFolder) { |
491 const BookmarkNode* root = model_->bookmark_bar_node(); | 474 const BookmarkNode* root = model_->bookmark_bar_node(); |
492 const BookmarkNode* folder = model_->AddFolder(root, 0, ASCIIToUTF16("foo")); | 475 const BookmarkNode* folder = model_->AddFolder(root, 0, ASCIIToUTF16("foo")); |
493 | 476 |
494 ClearCounts(); | 477 ClearCounts(); |
495 | 478 |
496 // Add a URL as a child. | 479 // Add a URL as a child. |
497 const base::string16 title(ASCIIToUTF16("foo")); | 480 const base::string16 title(ASCIIToUTF16("foo")); |
498 const GURL url("http://foo.com"); | 481 const GURL url("http://foo.com"); |
499 model_->AddURL(folder, 0, title, url); | 482 model_->AddURL(folder, 0, title, url); |
500 | 483 |
501 ClearCounts(); | 484 ClearCounts(); |
502 | 485 |
503 // Now remove the folder. | 486 // Now remove the folder. |
504 model_->Remove(root, 0); | 487 model_->Remove(root, 0); |
505 ASSERT_EQ(0, root->child_count()); | 488 ASSERT_EQ(0, root->child_count()); |
506 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); | 489 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); |
507 observer_details_.ExpectEquals(root, NULL, 0, -1); | 490 observer_details_.ExpectEquals(root, NULL, 0, -1); |
508 | 491 |
509 // Make sure there is no mapping for the URL. | 492 // Make sure there is no mapping for the URL. |
510 ASSERT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); | 493 ASSERT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == NULL); |
511 } | 494 } |
512 | 495 |
513 TEST_F(BookmarkModelTest, RemoveAll) { | 496 TEST_F(BookmarkModelTest, RemoveAll) { |
514 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node(); | 497 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node(); |
515 | 498 |
516 ClearCounts(); | 499 ClearCounts(); |
517 | 500 |
518 // Add a url to bookmark bar. | 501 // Add a url to bookmark bar. |
519 base::string16 title(ASCIIToUTF16("foo")); | 502 base::string16 title(ASCIIToUTF16("foo")); |
520 GURL url("http://foo.com"); | 503 GURL url("http://foo.com"); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 EXPECT_EQ(1, root->child_count()); | 595 EXPECT_EQ(1, root->child_count()); |
613 EXPECT_EQ(folder1, root->GetChild(0)); | 596 EXPECT_EQ(folder1, root->GetChild(0)); |
614 EXPECT_EQ(1, folder1->child_count()); | 597 EXPECT_EQ(1, folder1->child_count()); |
615 EXPECT_EQ(node, folder1->GetChild(0)); | 598 EXPECT_EQ(node, folder1->GetChild(0)); |
616 | 599 |
617 // And remove the folder. | 600 // And remove the folder. |
618 ClearCounts(); | 601 ClearCounts(); |
619 model_->Remove(root, 0); | 602 model_->Remove(root, 0); |
620 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); | 603 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); |
621 observer_details_.ExpectEquals(root, NULL, 0, -1); | 604 observer_details_.ExpectEquals(root, NULL, 0, -1); |
622 EXPECT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); | 605 EXPECT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == NULL); |
623 EXPECT_EQ(0, root->child_count()); | 606 EXPECT_EQ(0, root->child_count()); |
624 } | 607 } |
625 | 608 |
626 TEST_F(BookmarkModelTest, NonMovingMoveCall) { | 609 TEST_F(BookmarkModelTest, NonMovingMoveCall) { |
627 const BookmarkNode* root = model_->bookmark_bar_node(); | 610 const BookmarkNode* root = model_->bookmark_bar_node(); |
628 const base::string16 title(ASCIIToUTF16("foo")); | 611 const base::string16 title(ASCIIToUTF16("foo")); |
629 const GURL url("http://foo.com"); | 612 const GURL url("http://foo.com"); |
630 const base::Time old_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 613 const base::Time old_date(base::Time::Now() - base::TimeDelta::FromDays(1)); |
631 | 614 |
632 const BookmarkNode* node = model_->AddURL(root, 0, title, url); | 615 const BookmarkNode* node = model_->AddURL(root, 0, title, url); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 // Make sure recently modified stays in sync when adding a URL. | 702 // Make sure recently modified stays in sync when adding a URL. |
720 TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) { | 703 TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) { |
721 // Add a folder. | 704 // Add a folder. |
722 const BookmarkNode* folder = | 705 const BookmarkNode* folder = |
723 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foo")); | 706 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foo")); |
724 // Add a URL to it. | 707 // Add a URL to it. |
725 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); | 708 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); |
726 | 709 |
727 // Make sure folder is in the most recently modified. | 710 // Make sure folder is in the most recently modified. |
728 std::vector<const BookmarkNode*> most_recent_folders = | 711 std::vector<const BookmarkNode*> most_recent_folders = |
729 bookmark_utils::GetMostRecentlyModifiedUserFolders(model_.get(), 1); | 712 bookmark_utils::GetMostRecentlyModifiedFolders(model_.get(), 1); |
730 ASSERT_EQ(1U, most_recent_folders.size()); | 713 ASSERT_EQ(1U, most_recent_folders.size()); |
731 ASSERT_EQ(folder, most_recent_folders[0]); | 714 ASSERT_EQ(folder, most_recent_folders[0]); |
732 | 715 |
733 // Nuke the folder and do another fetch, making sure folder isn't in the | 716 // Nuke the folder and do another fetch, making sure folder isn't in the |
734 // returned list. | 717 // returned list. |
735 model_->Remove(folder->parent(), 0); | 718 model_->Remove(folder->parent(), 0); |
736 most_recent_folders = | 719 most_recent_folders = |
737 bookmark_utils::GetMostRecentlyModifiedUserFolders(model_.get(), 1); | 720 bookmark_utils::GetMostRecentlyModifiedFolders(model_.get(), 1); |
738 ASSERT_EQ(1U, most_recent_folders.size()); | 721 ASSERT_EQ(1U, most_recent_folders.size()); |
739 ASSERT_TRUE(most_recent_folders[0] != folder); | 722 ASSERT_TRUE(most_recent_folders[0] != folder); |
740 } | 723 } |
741 | 724 |
742 // Make sure MostRecentlyAddedEntries stays in sync. | 725 // Make sure MostRecentlyAddedEntries stays in sync. |
743 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { | 726 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { |
744 // Add a couple of nodes such that the following holds for the time of the | 727 // Add a couple of nodes such that the following holds for the time of the |
745 // nodes: n1 > n2 > n3 > n4. | 728 // nodes: n1 > n2 > n3 > n4. |
746 Time base_time = Time::Now(); | 729 Time base_time = Time::Now(); |
747 BookmarkNode* n1 = AsMutable(model_->AddURL(model_->bookmark_bar_node(), | 730 BookmarkNode* n1 = AsMutable(model_->AddURL(model_->bookmark_bar_node(), |
(...skipping 28 matching lines...) Expand all Loading... |
776 recently_added.clear(); | 759 recently_added.clear(); |
777 SwapDateAdded(n1, n2); | 760 SwapDateAdded(n1, n2); |
778 bookmark_utils::GetMostRecentlyAddedEntries(model_.get(), 4, &recently_added); | 761 bookmark_utils::GetMostRecentlyAddedEntries(model_.get(), 4, &recently_added); |
779 ASSERT_EQ(4U, recently_added.size()); | 762 ASSERT_EQ(4U, recently_added.size()); |
780 ASSERT_TRUE(n2 == recently_added[0]); | 763 ASSERT_TRUE(n2 == recently_added[0]); |
781 ASSERT_TRUE(n1 == recently_added[1]); | 764 ASSERT_TRUE(n1 == recently_added[1]); |
782 ASSERT_TRUE(n3 == recently_added[2]); | 765 ASSERT_TRUE(n3 == recently_added[2]); |
783 ASSERT_TRUE(n4 == recently_added[3]); | 766 ASSERT_TRUE(n4 == recently_added[3]); |
784 } | 767 } |
785 | 768 |
786 // Makes sure GetMostRecentlyAddedUserNodeForURL stays in sync. | 769 // Makes sure GetMostRecentlyAddedNodeForURL stays in sync. |
787 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURL) { | 770 TEST_F(BookmarkModelTest, GetMostRecentlyAddedNodeForURL) { |
788 // Add a couple of nodes such that the following holds for the time of the | 771 // Add a couple of nodes such that the following holds for the time of the |
789 // nodes: n1 > n2 | 772 // nodes: n1 > n2 |
790 Time base_time = Time::Now(); | 773 Time base_time = Time::Now(); |
791 const GURL url("http://foo.com/0"); | 774 const GURL url("http://foo.com/0"); |
792 BookmarkNode* n1 = AsMutable(model_->AddURL( | 775 BookmarkNode* n1 = AsMutable(model_->AddURL( |
793 model_->bookmark_bar_node(), 0, ASCIIToUTF16("blah"), url)); | 776 model_->bookmark_bar_node(), 0, ASCIIToUTF16("blah"), url)); |
794 BookmarkNode* n2 = AsMutable(model_->AddURL( | 777 BookmarkNode* n2 = AsMutable(model_->AddURL( |
795 model_->bookmark_bar_node(), 1, ASCIIToUTF16("blah"), url)); | 778 model_->bookmark_bar_node(), 1, ASCIIToUTF16("blah"), url)); |
796 n1->set_date_added(base_time + TimeDelta::FromDays(4)); | 779 n1->set_date_added(base_time + TimeDelta::FromDays(4)); |
797 n2->set_date_added(base_time + TimeDelta::FromDays(3)); | 780 n2->set_date_added(base_time + TimeDelta::FromDays(3)); |
798 | 781 |
799 // Make sure order is honored. | 782 // Make sure order is honored. |
800 ASSERT_EQ(n1, model_->GetMostRecentlyAddedUserNodeForURL(url)); | 783 ASSERT_EQ(n1, model_->GetMostRecentlyAddedNodeForURL(url)); |
801 | 784 |
802 // swap 1 and 2, then check again. | 785 // swap 1 and 2, then check again. |
803 SwapDateAdded(n1, n2); | 786 SwapDateAdded(n1, n2); |
804 ASSERT_EQ(n2, model_->GetMostRecentlyAddedUserNodeForURL(url)); | 787 ASSERT_EQ(n2, model_->GetMostRecentlyAddedNodeForURL(url)); |
805 } | 788 } |
806 | 789 |
807 // Makes sure GetBookmarks removes duplicates. | 790 // Makes sure GetBookmarks removes duplicates. |
808 TEST_F(BookmarkModelTest, GetBookmarksWithDups) { | 791 TEST_F(BookmarkModelTest, GetBookmarksWithDups) { |
809 const GURL url("http://foo.com/0"); | 792 const GURL url("http://foo.com/0"); |
810 const base::string16 title(ASCIIToUTF16("blah")); | 793 const base::string16 title(ASCIIToUTF16("blah")); |
811 model_->AddURL(model_->bookmark_bar_node(), 0, title, url); | 794 model_->AddURL(model_->bookmark_bar_node(), 0, title, url); |
812 model_->AddURL(model_->bookmark_bar_node(), 1, title, url); | 795 model_->AddURL(model_->bookmark_bar_node(), 1, title, url); |
813 | 796 |
814 std::vector<BookmarkModel::URLAndTitle> bookmarks; | 797 std::vector<BookmarkModel::URLAndTitle> bookmarks; |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 EXPECT_TRUE(model_->IsDoingExtensiveChanges()); | 1090 EXPECT_TRUE(model_->IsDoingExtensiveChanges()); |
1108 AssertExtensiveChangesObserverCount(1, 0); | 1091 AssertExtensiveChangesObserverCount(1, 0); |
1109 model_->EndExtensiveChanges(); | 1092 model_->EndExtensiveChanges(); |
1110 EXPECT_TRUE(model_->IsDoingExtensiveChanges()); | 1093 EXPECT_TRUE(model_->IsDoingExtensiveChanges()); |
1111 AssertExtensiveChangesObserverCount(1, 0); | 1094 AssertExtensiveChangesObserverCount(1, 0); |
1112 model_->EndExtensiveChanges(); | 1095 model_->EndExtensiveChanges(); |
1113 EXPECT_FALSE(model_->IsDoingExtensiveChanges()); | 1096 EXPECT_FALSE(model_->IsDoingExtensiveChanges()); |
1114 AssertExtensiveChangesObserverCount(1, 1); | 1097 AssertExtensiveChangesObserverCount(1, 1); |
1115 } | 1098 } |
1116 | 1099 |
1117 // Verifies that IsBookmarked is true if any bookmark matches the given URL, | |
1118 // and that IsBookmarkedByUser is true only if at least one of the matching | |
1119 // bookmarks can be edited by the user. | |
1120 TEST_F(BookmarkModelTest, IsBookmarked) { | |
1121 // Reload the model with an extra node that is not editable by the user. | |
1122 BookmarkPermanentNode* extra_node = ReloadModelWithExtraNode(); | |
1123 | |
1124 // "google.com" is a "user" bookmark. | |
1125 model_->AddURL(model_->other_node(), 0, base::ASCIIToUTF16("User"), | |
1126 GURL("http://google.com")); | |
1127 // "youtube.com" is not. | |
1128 model_->AddURL(extra_node, 0, base::ASCIIToUTF16("Extra"), | |
1129 GURL("http://youtube.com")); | |
1130 | |
1131 EXPECT_TRUE(model_->IsBookmarked(GURL("http://google.com"))); | |
1132 EXPECT_TRUE(model_->IsBookmarked(GURL("http://youtube.com"))); | |
1133 EXPECT_FALSE(model_->IsBookmarked(GURL("http://reddit.com"))); | |
1134 | |
1135 EXPECT_TRUE(bookmark_utils::IsBookmarkedByUser(model_.get(), | |
1136 GURL("http://google.com"))); | |
1137 EXPECT_FALSE(bookmark_utils::IsBookmarkedByUser(model_.get(), | |
1138 GURL("http://youtube.com"))); | |
1139 EXPECT_FALSE(bookmark_utils::IsBookmarkedByUser(model_.get(), | |
1140 GURL("http://reddit.com"))); | |
1141 } | |
1142 | |
1143 // Verifies that GetMostRecentlyAddedUserNodeForURL skips bookmarks that | |
1144 // are not owned by the user. | |
1145 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURLSkipsManagedNodes) { | |
1146 // Reload the model with an extra node that is not editable by the user. | |
1147 BookmarkPermanentNode* extra_node = ReloadModelWithExtraNode(); | |
1148 | |
1149 const base::string16 title = base::ASCIIToUTF16("Title"); | |
1150 const BookmarkNode* user_parent = model_->other_node(); | |
1151 const BookmarkNode* managed_parent = extra_node; | |
1152 const GURL url("http://google.com"); | |
1153 | |
1154 // |url| is not bookmarked yet. | |
1155 EXPECT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); | |
1156 | |
1157 // Having a managed node doesn't count. | |
1158 model_->AddURL(managed_parent, 0, title, url); | |
1159 EXPECT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); | |
1160 | |
1161 // Now add a user node. | |
1162 const BookmarkNode* user = model_->AddURL(user_parent, 0, title, url); | |
1163 EXPECT_EQ(user, model_->GetMostRecentlyAddedUserNodeForURL(url)); | |
1164 | |
1165 // Having a more recent managed node doesn't count either. | |
1166 const BookmarkNode* managed = model_->AddURL(managed_parent, 0, title, url); | |
1167 EXPECT_GT(managed->date_added(), user->date_added()); | |
1168 EXPECT_EQ(user, model_->GetMostRecentlyAddedUserNodeForURL(url)); | |
1169 } | |
1170 | |
1171 TEST(BookmarkNodeTest, NodeMetaInfo) { | 1100 TEST(BookmarkNodeTest, NodeMetaInfo) { |
1172 GURL url; | 1101 GURL url; |
1173 BookmarkNode node(url); | 1102 BookmarkNode node(url); |
1174 EXPECT_FALSE(node.GetMetaInfoMap()); | 1103 EXPECT_FALSE(node.GetMetaInfoMap()); |
1175 | 1104 |
1176 EXPECT_TRUE(node.SetMetaInfo("key1", "value1")); | 1105 EXPECT_TRUE(node.SetMetaInfo("key1", "value1")); |
1177 std::string out_value; | 1106 std::string out_value; |
1178 EXPECT_TRUE(node.GetMetaInfo("key1", &out_value)); | 1107 EXPECT_TRUE(node.GetMetaInfo("key1", &out_value)); |
1179 EXPECT_EQ("value1", out_value); | 1108 EXPECT_EQ("value1", out_value); |
1180 EXPECT_FALSE(node.SetMetaInfo("key1", "value1")); | 1109 EXPECT_FALSE(node.SetMetaInfo("key1", "value1")); |
(...skipping 13 matching lines...) Expand all Loading... |
1194 EXPECT_TRUE(node.DeleteMetaInfo("key2.subkey2.leaf")); | 1123 EXPECT_TRUE(node.DeleteMetaInfo("key2.subkey2.leaf")); |
1195 EXPECT_FALSE(node.DeleteMetaInfo("key3")); | 1124 EXPECT_FALSE(node.DeleteMetaInfo("key3")); |
1196 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); | 1125 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); |
1197 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); | 1126 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); |
1198 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); | 1127 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); |
1199 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); | 1128 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); |
1200 EXPECT_FALSE(node.GetMetaInfoMap()); | 1129 EXPECT_FALSE(node.GetMetaInfoMap()); |
1201 } | 1130 } |
1202 | 1131 |
1203 } // namespace | 1132 } // namespace |
OLD | NEW |