OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" | 5 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 using ::testing::_; | 31 using ::testing::_; |
32 using ::testing::Eq; | 32 using ::testing::Eq; |
33 using ::testing::IsEmpty; | 33 using ::testing::IsEmpty; |
34 using ::testing::Property; | 34 using ::testing::Property; |
35 using ::testing::UnorderedElementsAre; | 35 using ::testing::UnorderedElementsAre; |
36 | 36 |
37 class BookmarkSuggestionsProviderTest : public ::testing::Test { | 37 class BookmarkSuggestionsProviderTest : public ::testing::Test { |
38 public: | 38 public: |
39 BookmarkSuggestionsProviderTest() | 39 BookmarkSuggestionsProviderTest() |
40 : model_(bookmarks::TestBookmarkClient::CreateModel()) { | 40 : model_(bookmarks::TestBookmarkClient::CreateModel()) { |
41 EXPECT_CALL(observer_, OnNewSuggestions(_, Category::FromKnownCategory( | 41 EXPECT_CALL(observer_, |
42 KnownCategories::BOOKMARKS), | 42 OnNewSuggestions( |
43 IsEmpty())) | 43 _, Category::FromKnownCategory(KnownCategories::BOOKMARKS), |
| 44 IsEmpty())) |
44 .RetiresOnSaturation(); | 45 .RetiresOnSaturation(); |
45 EXPECT_CALL(observer_, | 46 EXPECT_CALL(observer_, |
46 OnCategoryStatusChanged( | 47 OnCategoryStatusChanged( |
47 _, Category::FromKnownCategory(KnownCategories::BOOKMARKS), | 48 _, Category::FromKnownCategory(KnownCategories::BOOKMARKS), |
48 CategoryStatus::AVAILABLE_LOADING)) | 49 CategoryStatus::AVAILABLE_LOADING)) |
49 .RetiresOnSaturation(); | 50 .RetiresOnSaturation(); |
50 EXPECT_CALL(observer_, | 51 EXPECT_CALL(observer_, |
51 OnCategoryStatusChanged( | 52 OnCategoryStatusChanged( |
52 _, Category::FromKnownCategory(KnownCategories::BOOKMARKS), | 53 _, Category::FromKnownCategory(KnownCategories::BOOKMARKS), |
53 CategoryStatus::AVAILABLE)) | 54 CategoryStatus::AVAILABLE)) |
54 .RetiresOnSaturation(); | 55 .RetiresOnSaturation(); |
55 BookmarkSuggestionsProvider::RegisterProfilePrefs(test_prefs_.registry()); | 56 BookmarkSuggestionsProvider::RegisterProfilePrefs(test_prefs_.registry()); |
56 provider_ = base::MakeUnique<BookmarkSuggestionsProvider>( | 57 provider_ = base::MakeUnique<BookmarkSuggestionsProvider>( |
57 &observer_, model_.get(), &test_prefs_); | 58 &observer_, model_.get(), &test_prefs_); |
58 } | 59 } |
59 | 60 |
60 protected: | 61 protected: |
61 std::unique_ptr<bookmarks::BookmarkModel> model_; | 62 std::unique_ptr<bookmarks::BookmarkModel> model_; |
62 StrictMock<MockContentSuggestionsProviderObserver> observer_; | 63 StrictMock<MockContentSuggestionsProviderObserver> observer_; |
63 TestingPrefServiceSimple test_prefs_; | 64 TestingPrefServiceSimple test_prefs_; |
64 std::unique_ptr<BookmarkSuggestionsProvider> provider_; | 65 std::unique_ptr<BookmarkSuggestionsProvider> provider_; |
65 }; | 66 }; |
66 | 67 |
67 TEST_F(BookmarkSuggestionsProviderTest, | 68 TEST_F(BookmarkSuggestionsProviderTest, ShouldProvideBookmarkSuggestions) { |
68 ShouldProvideBookmarkSuggestions) { | |
69 GURL url("http://my-new-bookmarked.url"); | 69 GURL url("http://my-new-bookmarked.url"); |
70 // Note, this update to the model does not trigger OnNewSuggestions() on the | 70 // Note, this update to the model does not trigger OnNewSuggestions() on the |
71 // observer as the provider realizes no new nodes were added. | 71 // observer as the provider realizes no new nodes were added. |
72 // don't have new data. | 72 // don't have new data. |
73 model_->AddURL(model_->bookmark_bar_node(), 0, | 73 model_->AddURL(model_->bookmark_bar_node(), 0, |
74 base::ASCIIToUTF16("cool page's title"), url); | 74 base::ASCIIToUTF16("cool page's title"), url); |
75 | 75 |
76 // Once we provided the last-visited meta information, an update with the | 76 // Once we provided the last-visited meta information, an update with the |
77 // suggestion containing the bookmark should follow. | 77 // suggestion containing the bookmark should follow. |
78 EXPECT_CALL( | 78 EXPECT_CALL( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 /*is_mobile_platform=*/true); | 118 /*is_mobile_platform=*/true); |
119 // According to the ContentSugestionsProvider contract, solely dismissing an | 119 // According to the ContentSugestionsProvider contract, solely dismissing an |
120 // item should not result in another OnNewSuggestions() call. | 120 // item should not result in another OnNewSuggestions() call. |
121 static_cast<ContentSuggestionsProvider*>(provider_.get()) | 121 static_cast<ContentSuggestionsProvider*>(provider_.get()) |
122 ->DismissSuggestion(ContentSuggestion::ID( | 122 ->DismissSuggestion(ContentSuggestion::ID( |
123 Category::FromKnownCategory(KnownCategories::BOOKMARKS), | 123 Category::FromKnownCategory(KnownCategories::BOOKMARKS), |
124 dismissed_bookmark.spec())); | 124 dismissed_bookmark.spec())); |
125 EXPECT_THAT(IsDismissedFromNTPForBookmark(*dismissed_node), Eq(true)); | 125 EXPECT_THAT(IsDismissedFromNTPForBookmark(*dismissed_node), Eq(true)); |
126 | 126 |
127 // Clear history and make sure the suggestions actually get removed. | 127 // Clear history and make sure the suggestions actually get removed. |
128 EXPECT_CALL(observer_, OnNewSuggestions(_, Category::FromKnownCategory( | 128 EXPECT_CALL(observer_, |
129 KnownCategories::BOOKMARKS), | 129 OnNewSuggestions( |
130 IsEmpty())); | 130 _, Category::FromKnownCategory(KnownCategories::BOOKMARKS), |
| 131 IsEmpty())); |
131 static_cast<ContentSuggestionsProvider*>(provider_.get()) | 132 static_cast<ContentSuggestionsProvider*>(provider_.get()) |
132 ->ClearHistory(base::Time(), base::Time::Max(), | 133 ->ClearHistory(base::Time(), base::Time::Max(), |
133 base::Bind([] (const GURL& url) { return true; })); | 134 base::Bind([](const GURL& url) { return true; })); |
134 | 135 |
135 // Verify the dismissed marker is gone. | 136 // Verify the dismissed marker is gone. |
136 EXPECT_THAT(IsDismissedFromNTPForBookmark(*dismissed_node), Eq(false)); | 137 EXPECT_THAT(IsDismissedFromNTPForBookmark(*dismissed_node), Eq(false)); |
137 } | 138 } |
138 | 139 |
139 // TODO(tschumann): There are plenty of test cases missing. Most importantly: | 140 // TODO(tschumann): There are plenty of test cases missing. Most importantly: |
140 // -- Remove a bookmark from the model | 141 // -- Remove a bookmark from the model |
141 // -- verifying handling of threshold time | 142 // -- verifying handling of threshold time |
142 // -- dealing with fetches before the model is loaded. | 143 // -- dealing with fetches before the model is loaded. |
143 | 144 |
144 } // namespace | 145 } // namespace |
145 } // namespace ntp_snippets | 146 } // namespace ntp_snippets |
146 | |
OLD | NEW |