| 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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 } | 467 } |
| 468 } | 468 } |
| 469 | 469 |
| 470 TEST_F(BookmarkModelTest, RemoveURL) { | 470 TEST_F(BookmarkModelTest, RemoveURL) { |
| 471 const BookmarkNode* root = model_->bookmark_bar_node(); | 471 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 472 const base::string16 title(ASCIIToUTF16("foo")); | 472 const base::string16 title(ASCIIToUTF16("foo")); |
| 473 const GURL url("http://foo.com"); | 473 const GURL url("http://foo.com"); |
| 474 model_->AddURL(root, 0, title, url); | 474 model_->AddURL(root, 0, title, url); |
| 475 ClearCounts(); | 475 ClearCounts(); |
| 476 | 476 |
| 477 model_->Remove(root, 0); | 477 model_->Remove(root->GetChild(0)); |
| 478 ASSERT_EQ(0, root->child_count()); | 478 ASSERT_EQ(0, root->child_count()); |
| 479 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); | 479 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); |
| 480 observer_details_.ExpectEquals(root, NULL, 0, -1); | 480 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 481 | 481 |
| 482 // Make sure there is no mapping for the URL. | 482 // Make sure there is no mapping for the URL. |
| 483 ASSERT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); | 483 ASSERT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); |
| 484 } | 484 } |
| 485 | 485 |
| 486 TEST_F(BookmarkModelTest, RemoveFolder) { | 486 TEST_F(BookmarkModelTest, RemoveFolder) { |
| 487 const BookmarkNode* root = model_->bookmark_bar_node(); | 487 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 488 const BookmarkNode* folder = model_->AddFolder(root, 0, ASCIIToUTF16("foo")); | 488 const BookmarkNode* folder = model_->AddFolder(root, 0, ASCIIToUTF16("foo")); |
| 489 | 489 |
| 490 ClearCounts(); | 490 ClearCounts(); |
| 491 | 491 |
| 492 // Add a URL as a child. | 492 // Add a URL as a child. |
| 493 const base::string16 title(ASCIIToUTF16("foo")); | 493 const base::string16 title(ASCIIToUTF16("foo")); |
| 494 const GURL url("http://foo.com"); | 494 const GURL url("http://foo.com"); |
| 495 model_->AddURL(folder, 0, title, url); | 495 model_->AddURL(folder, 0, title, url); |
| 496 | 496 |
| 497 ClearCounts(); | 497 ClearCounts(); |
| 498 | 498 |
| 499 // Now remove the folder. | 499 // Now remove the folder. |
| 500 model_->Remove(root, 0); | 500 model_->Remove(root->GetChild(0)); |
| 501 ASSERT_EQ(0, root->child_count()); | 501 ASSERT_EQ(0, root->child_count()); |
| 502 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); | 502 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); |
| 503 observer_details_.ExpectEquals(root, NULL, 0, -1); | 503 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 504 | 504 |
| 505 // Make sure there is no mapping for the URL. | 505 // Make sure there is no mapping for the URL. |
| 506 ASSERT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); | 506 ASSERT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); |
| 507 } | 507 } |
| 508 | 508 |
| 509 TEST_F(BookmarkModelTest, RemoveAllUserBookmarks) { | 509 TEST_F(BookmarkModelTest, RemoveAllUserBookmarks) { |
| 510 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node(); | 510 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 AssertObserverCount(0, 1, 0, 0, 0, 0, 0, 0, 0); | 605 AssertObserverCount(0, 1, 0, 0, 0, 0, 0, 0, 0); |
| 606 observer_details_.ExpectEquals(root, folder1, 1, 0); | 606 observer_details_.ExpectEquals(root, folder1, 1, 0); |
| 607 EXPECT_TRUE(folder1 == node->parent()); | 607 EXPECT_TRUE(folder1 == node->parent()); |
| 608 EXPECT_EQ(1, root->child_count()); | 608 EXPECT_EQ(1, root->child_count()); |
| 609 EXPECT_EQ(folder1, root->GetChild(0)); | 609 EXPECT_EQ(folder1, root->GetChild(0)); |
| 610 EXPECT_EQ(1, folder1->child_count()); | 610 EXPECT_EQ(1, folder1->child_count()); |
| 611 EXPECT_EQ(node, folder1->GetChild(0)); | 611 EXPECT_EQ(node, folder1->GetChild(0)); |
| 612 | 612 |
| 613 // And remove the folder. | 613 // And remove the folder. |
| 614 ClearCounts(); | 614 ClearCounts(); |
| 615 model_->Remove(root, 0); | 615 model_->Remove(root->GetChild(0)); |
| 616 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); | 616 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); |
| 617 observer_details_.ExpectEquals(root, NULL, 0, -1); | 617 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 618 EXPECT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); | 618 EXPECT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); |
| 619 EXPECT_EQ(0, root->child_count()); | 619 EXPECT_EQ(0, root->child_count()); |
| 620 } | 620 } |
| 621 | 621 |
| 622 TEST_F(BookmarkModelTest, NonMovingMoveCall) { | 622 TEST_F(BookmarkModelTest, NonMovingMoveCall) { |
| 623 const BookmarkNode* root = model_->bookmark_bar_node(); | 623 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 624 const base::string16 title(ASCIIToUTF16("foo")); | 624 const base::string16 title(ASCIIToUTF16("foo")); |
| 625 const GURL url("http://foo.com"); | 625 const GURL url("http://foo.com"); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); | 721 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); |
| 722 | 722 |
| 723 // Make sure folder is in the most recently modified. | 723 // Make sure folder is in the most recently modified. |
| 724 std::vector<const BookmarkNode*> most_recent_folders = | 724 std::vector<const BookmarkNode*> most_recent_folders = |
| 725 GetMostRecentlyModifiedUserFolders(model_.get(), 1); | 725 GetMostRecentlyModifiedUserFolders(model_.get(), 1); |
| 726 ASSERT_EQ(1U, most_recent_folders.size()); | 726 ASSERT_EQ(1U, most_recent_folders.size()); |
| 727 ASSERT_EQ(folder, most_recent_folders[0]); | 727 ASSERT_EQ(folder, most_recent_folders[0]); |
| 728 | 728 |
| 729 // Nuke the folder and do another fetch, making sure folder isn't in the | 729 // Nuke the folder and do another fetch, making sure folder isn't in the |
| 730 // returned list. | 730 // returned list. |
| 731 model_->Remove(folder->parent(), 0); | 731 model_->Remove(folder->parent()->GetChild(0)); |
| 732 most_recent_folders = GetMostRecentlyModifiedUserFolders(model_.get(), 1); | 732 most_recent_folders = GetMostRecentlyModifiedUserFolders(model_.get(), 1); |
| 733 ASSERT_EQ(1U, most_recent_folders.size()); | 733 ASSERT_EQ(1U, most_recent_folders.size()); |
| 734 ASSERT_TRUE(most_recent_folders[0] != folder); | 734 ASSERT_TRUE(most_recent_folders[0] != folder); |
| 735 } | 735 } |
| 736 | 736 |
| 737 // Make sure MostRecentlyAddedEntries stays in sync. | 737 // Make sure MostRecentlyAddedEntries stays in sync. |
| 738 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { | 738 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { |
| 739 // Add a couple of nodes such that the following holds for the time of the | 739 // Add a couple of nodes such that the following holds for the time of the |
| 740 // nodes: n1 > n2 > n3 > n4. | 740 // nodes: n1 > n2 > n3 > n4. |
| 741 Time base_time = Time::Now(); | 741 Time base_time = Time::Now(); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 EXPECT_FALSE(node.DeleteMetaInfo("key3")); | 1188 EXPECT_FALSE(node.DeleteMetaInfo("key3")); |
| 1189 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); | 1189 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); |
| 1190 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); | 1190 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); |
| 1191 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); | 1191 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); |
| 1192 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); | 1192 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); |
| 1193 EXPECT_FALSE(node.GetMetaInfoMap()); | 1193 EXPECT_FALSE(node.GetMetaInfoMap()); |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 } // namespace | 1196 } // namespace |
| 1197 } // namespace bookmarks | 1197 } // namespace bookmarks |
| OLD | NEW |