| Index: components/bookmarks/browser/bookmark_model_unittest.cc
|
| diff --git a/components/bookmarks/browser/bookmark_model_unittest.cc b/components/bookmarks/browser/bookmark_model_unittest.cc
|
| index bf4f9176d0cf05e42ceb73f730e10d40e8b5141b..fd4236b5638ec49d13aec7bdc01aef8c87fa1814 100644
|
| --- a/components/bookmarks/browser/bookmark_model_unittest.cc
|
| +++ b/components/bookmarks/browser/bookmark_model_unittest.cc
|
| @@ -18,13 +18,17 @@
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/time/time.h"
|
| +#include "components/bookmarks/browser/bookmark_match.h"
|
| #include "components/bookmarks/browser/bookmark_model_observer.h"
|
| #include "components/bookmarks/browser/bookmark_utils.h"
|
| #include "components/bookmarks/test/bookmark_test_helpers.h"
|
| #include "components/bookmarks/test/test_bookmark_client.h"
|
| +#include "components/favicon_base/favicon_callback.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "third_party/skia/include/core/SkBitmap.h"
|
| #include "ui/base/models/tree_node_iterator.h"
|
| #include "ui/base/models/tree_node_model.h"
|
| +#include "ui/gfx/image/image.h"
|
| #include "url/gurl.h"
|
|
|
| using base::ASCIIToUTF16;
|
| @@ -207,6 +211,8 @@ void VerifyNoDuplicateIDs(BookmarkModel* model) {
|
| ASSERT_TRUE(ids.insert(it.Next()->id()).second);
|
| }
|
|
|
| +} // namespace
|
| +
|
| class BookmarkModelTest : public testing::Test,
|
| public BookmarkModelObserver {
|
| public:
|
| @@ -247,6 +253,22 @@ class BookmarkModelTest : public testing::Test,
|
| ClearCounts();
|
| }
|
|
|
| + // Emulates the favicon getting asynchronously loaded. In production, the
|
| + // favicon is asynchronously loaded when BookmarkModel::GetFavicon() is
|
| + // called.
|
| + void OnFaviconLoaded(BookmarkNode* node, const GURL& icon_url) {
|
| + SkBitmap bitmap;
|
| + bitmap.allocN32Pixels(16, 16);
|
| + bitmap.eraseColor(SK_ColorBLUE);
|
| + gfx::Image image = gfx::Image::CreateFrom1xBitmap(bitmap);
|
| +
|
| + favicon_base::FaviconImageResult image_result;
|
| + image_result.image = image;
|
| + image_result.icon_url = icon_url;
|
| + model_->OnFaviconDataAvailable(node, favicon_base::IconType::FAVICON,
|
| + image_result);
|
| + }
|
| +
|
| void BookmarkModelLoaded(BookmarkModel* model, bool ids_reassigned) override {
|
| // We never load from the db, so that this should never get invoked.
|
| NOTREACHED();
|
| @@ -307,8 +329,6 @@ class BookmarkModelTest : public testing::Test,
|
|
|
| void BookmarkNodeFaviconChanged(BookmarkModel* model,
|
| const BookmarkNode* node) override {
|
| - // We never attempt to load favicons, so that this method never
|
| - // gets invoked.
|
| }
|
|
|
| void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) override {
|
| @@ -605,9 +625,51 @@ TEST_F(BookmarkModelTest, RemoveFolder) {
|
| ASSERT_EQ(0, root->child_count());
|
| AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0);
|
| observer_details_.ExpectEquals(root, NULL, 0, -1);
|
| +}
|
|
|
| - // Make sure there is no mapping for the URL.
|
| - ASSERT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL);
|
| +// Test that removing a BookmarkNode from the BookmarkModel clears any data that
|
| +// the BookmarkModel has cached about that BookmarkNode.
|
| +TEST_F(BookmarkModelTest, RemoveURLClearsCachedData) {
|
| + const BookmarkNode* root = model_->bookmark_bar_node();
|
| + base::string16 kTitle(ASCIIToUTF16("foo"));
|
| + GURL kPageURL("http://www.google.com");
|
| + GURL kFaviconURL("http://www.google.com/favicon.ico");
|
| +
|
| + const BookmarkNode* node = model_->AddURL(root, 0, kTitle, kPageURL);
|
| +
|
| + // Emulate the favicon getting asynchronously loaded.
|
| + OnFaviconLoaded(AsMutable(node), kFaviconURL);
|
| +
|
| + // Test initial state.
|
| + std::vector<const BookmarkNode*> nodes;
|
| + model_->GetNodesByURL(kPageURL, &nodes);
|
| + ASSERT_EQ(1u, nodes.size());
|
| + ASSERT_EQ(node, nodes[0]);
|
| +
|
| + nodes.clear();
|
| + model_->GetNodesByIconURL(kFaviconURL, &nodes);
|
| + ASSERT_EQ(1u, nodes.size());
|
| + ASSERT_EQ(node, nodes[0]);
|
| +
|
| + std::vector<BookmarkMatch> matches;
|
| + model_->GetBookmarksMatching(kTitle, 1u, &matches);
|
| + ASSERT_EQ(1u, nodes.size());
|
| + ASSERT_EQ(node, nodes[0]);
|
| +
|
| + // Remove |node| from the BookmarkModel.
|
| + model_->Remove(nodes[0]);
|
| +
|
| + // Test that the BookmarkModel has forgotten about |node|.
|
| + nodes.clear();
|
| + model_->GetNodesByURL(kPageURL, &nodes);
|
| + EXPECT_TRUE(nodes.empty());
|
| +
|
| + model_->GetNodesByIconURL(kFaviconURL, &nodes);
|
| + EXPECT_TRUE(nodes.empty());
|
| +
|
| + matches.clear();
|
| + model_->GetBookmarksMatching(kTitle, 1u, &matches);
|
| + EXPECT_TRUE(matches.empty());
|
| }
|
|
|
| TEST_F(BookmarkModelTest, RemoveAllUserBookmarks) {
|
| @@ -681,6 +743,39 @@ TEST_F(BookmarkModelTest, SetURL) {
|
| EXPECT_EQ(url, node->url());
|
| }
|
|
|
| +// Test that changing a BookmarkNode's page URL clears the BookmarkModel's
|
| +// cached favicon data and the BookmarkNode's favicon data.
|
| +TEST_F(BookmarkModelTest, SetURLClearsFaviconData) {
|
| + const BookmarkNode* root = model_->bookmark_bar_node();
|
| + base::string16 kTitle(ASCIIToUTF16("foo"));
|
| + GURL kPageURL1("http://www.google.com");
|
| + GURL kFaviconURL1("http://www.google.com/favicon.ico");
|
| + GURL kPageURL2("http://www.wikipedia.org");
|
| +
|
| + const BookmarkNode* node = model_->AddURL(root, 0, kTitle, kPageURL1);
|
| +
|
| + // Emulate the favicon getting asynchronously loaded.
|
| + OnFaviconLoaded(AsMutable(node), kFaviconURL1);
|
| +
|
| + // Test initial state.
|
| + std::vector<const BookmarkNode*> nodes;
|
| + model_->GetNodesByIconURL(kFaviconURL1, &nodes);
|
| + ASSERT_EQ(1u, nodes.size());
|
| + ASSERT_EQ(node, nodes[0]);
|
| + ASSERT_EQ(kFaviconURL1, node->icon_url());
|
| +
|
| + // Change |node|'s page URL
|
| + model_->SetURL(node, kPageURL2);
|
| +
|
| + // BookmarkModel should have forgotten about |kFaviconURL1|.
|
| + nodes.clear();
|
| + model_->GetNodesByIconURL(kFaviconURL1, &nodes);
|
| + EXPECT_TRUE(nodes.empty());
|
| +
|
| + // |node|'s favicon data should have been cleared.
|
| + EXPECT_EQ(GURL(), node->icon_url());
|
| +}
|
| +
|
| TEST_F(BookmarkModelTest, SetDateAdded) {
|
| const BookmarkNode* root = model_->bookmark_bar_node();
|
| const base::string16 title(ASCIIToUTF16("foo"));
|
| @@ -1181,5 +1276,4 @@ TEST(BookmarkModelTest2, CreateAndRestore) {
|
| }
|
| }
|
|
|
| -} // namespace
|
| } // namespace bookmarks
|
|
|