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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "components/bookmarks/browser/bookmark_model.h" | 15 #include "components/bookmarks/browser/bookmark_model.h" |
16 #include "components/bookmarks/browser/bookmark_node.h" | 16 #include "components/bookmarks/browser/bookmark_node.h" |
17 #include "components/bookmarks/test/test_bookmark_client.h" | 17 #include "components/bookmarks/test/test_bookmark_client.h" |
18 #include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h" | 18 #include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h" |
19 #include "components/ntp_snippets/category.h" | 19 #include "components/ntp_snippets/category.h" |
20 #include "components/ntp_snippets/mock_content_suggestions_provider_observer.h" | 20 #include "components/ntp_snippets/mock_content_suggestions_provider_observer.h" |
21 #include "components/prefs/testing_pref_service.h" | |
22 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "url/gurl.h" | 23 #include "url/gurl.h" |
25 | 24 |
26 namespace ntp_snippets { | 25 namespace ntp_snippets { |
27 | 26 |
28 namespace { | 27 namespace { |
29 | 28 |
30 using ::testing::StrictMock; | 29 using ::testing::StrictMock; |
31 using ::testing::_; | 30 using ::testing::_; |
(...skipping 14 matching lines...) Expand all Loading... |
46 EXPECT_CALL(observer_, | 45 EXPECT_CALL(observer_, |
47 OnCategoryStatusChanged( | 46 OnCategoryStatusChanged( |
48 _, Category::FromKnownCategory(KnownCategories::BOOKMARKS), | 47 _, Category::FromKnownCategory(KnownCategories::BOOKMARKS), |
49 CategoryStatus::AVAILABLE_LOADING)) | 48 CategoryStatus::AVAILABLE_LOADING)) |
50 .RetiresOnSaturation(); | 49 .RetiresOnSaturation(); |
51 EXPECT_CALL(observer_, | 50 EXPECT_CALL(observer_, |
52 OnCategoryStatusChanged( | 51 OnCategoryStatusChanged( |
53 _, Category::FromKnownCategory(KnownCategories::BOOKMARKS), | 52 _, Category::FromKnownCategory(KnownCategories::BOOKMARKS), |
54 CategoryStatus::AVAILABLE)) | 53 CategoryStatus::AVAILABLE)) |
55 .RetiresOnSaturation(); | 54 .RetiresOnSaturation(); |
56 BookmarkSuggestionsProvider::RegisterProfilePrefs(test_prefs_.registry()); | 55 provider_ = |
57 provider_ = base::MakeUnique<BookmarkSuggestionsProvider>( | 56 base::MakeUnique<BookmarkSuggestionsProvider>(&observer_, model_.get()); |
58 &observer_, model_.get(), &test_prefs_); | |
59 } | 57 } |
60 | 58 |
61 protected: | 59 protected: |
62 std::unique_ptr<bookmarks::BookmarkModel> model_; | 60 std::unique_ptr<bookmarks::BookmarkModel> model_; |
63 StrictMock<MockContentSuggestionsProviderObserver> observer_; | 61 StrictMock<MockContentSuggestionsProviderObserver> observer_; |
64 TestingPrefServiceSimple test_prefs_; | |
65 std::unique_ptr<BookmarkSuggestionsProvider> provider_; | 62 std::unique_ptr<BookmarkSuggestionsProvider> provider_; |
66 }; | 63 }; |
67 | 64 |
68 TEST_F(BookmarkSuggestionsProviderTest, ShouldProvideBookmarkSuggestions) { | 65 TEST_F(BookmarkSuggestionsProviderTest, ShouldProvideBookmarkSuggestions) { |
69 GURL url("http://my-new-bookmarked.url"); | 66 GURL url("http://my-new-bookmarked.url"); |
70 // Note, this update to the model does not trigger OnNewSuggestions() on the | 67 // Note, this update to the model does not trigger OnNewSuggestions() on the |
71 // observer as the provider realizes no new nodes were added. | 68 // observer as the provider realizes no new nodes were added. |
72 // don't have new data. | 69 // don't have new data. |
73 model_->AddURL(model_->bookmark_bar_node(), 0, | 70 model_->AddURL(model_->bookmark_bar_node(), 0, |
74 base::ASCIIToUTF16("cool page's title"), url); | 71 base::ASCIIToUTF16("cool page's title"), url); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 EXPECT_THAT(IsDismissedFromNTPForBookmark(*dismissed_node), Eq(false)); | 134 EXPECT_THAT(IsDismissedFromNTPForBookmark(*dismissed_node), Eq(false)); |
138 } | 135 } |
139 | 136 |
140 // TODO(tschumann): There are plenty of test cases missing. Most importantly: | 137 // TODO(tschumann): There are plenty of test cases missing. Most importantly: |
141 // -- Remove a bookmark from the model | 138 // -- Remove a bookmark from the model |
142 // -- verifying handling of threshold time | 139 // -- verifying handling of threshold time |
143 // -- dealing with fetches before the model is loaded. | 140 // -- dealing with fetches before the model is loaded. |
144 | 141 |
145 } // namespace | 142 } // namespace |
146 } // namespace ntp_snippets | 143 } // namespace ntp_snippets |
OLD | NEW |