Index: components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider_unittest.cc |
diff --git a/components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider_unittest.cc b/components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..423c8b6ab39a46dd318073462a2259829be66fe8 |
--- /dev/null |
+++ b/components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider_unittest.cc |
@@ -0,0 +1,78 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider.h" |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "components/ntp_snippets/category.h" |
+#include "components/ntp_snippets/category_factory.h" |
+#include "components/ntp_snippets/content_suggestions_provider.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace ntp_snippets { |
+ |
+namespace { |
+ |
+UrlInfo CreateUrlInfo(const std::string& site_url) { |
+ UrlInfo url_info; |
+ url_info.site_url = GURL(site_url); |
+ return url_info; |
+} |
+ |
+std::vector<UrlInfo> CreateUrlInfos(const std::vector<std::string>& site_urls) { |
+ std::vector<UrlInfo> url_infos; |
+ for (const std::string& site_url : site_urls) { |
+ url_infos.emplace_back(CreateUrlInfo(site_url)); |
+ } |
+ return url_infos; |
+} |
+ |
+class MockProviderObserver : public ContentSuggestionsProvider::Observer { |
tschumann
2016/08/10 17:37:57
Marc, do we already have such an observer for othe
vitaliii
2016/08/11 12:15:25
Done.
|
+ public: |
+ void OnNewSuggestions(ContentSuggestionsProvider* provider, Category category, |
+ std::vector<ContentSuggestion> suggestions) override { |
+ std::vector<std::string> urls; |
+ for (const auto& suggestion : suggestions) { |
+ urls.push_back(suggestion.url().spec()); |
+ } |
+ OnNewSuggestionsUrls(urls); |
Marc Treib
2016/08/10 16:22:03
You could make the mock method take a "const std::
tschumann
2016/08/10 17:37:57
This seems odd -- you're adding a mock function (O
Marc Treib
2016/08/11 12:15:24
This is a workaround for gMock's lack of support f
vitaliii
2016/08/11 12:15:25
Since ContentSuggestion cannot be copied and assig
tschumann
2016/08/11 12:52:24
yuck... I start wondering if it's really worth hav
Marc Treib
2016/08/11 13:09:14
No, that's not the only reason. This way, the Cont
tschumann
2016/08/11 13:14:05
yes, we need to somehow allow the compiler to dist
Marc Treib
2016/08/11 13:17:53
Alright, makes sense. No objections :)
vitaliii
2016/08/11 14:29:58
Acknowledged.
|
+ } |
+ |
+ MOCK_METHOD1(OnNewSuggestionsUrls, void(std::vector<std::string> urls)); |
+ MOCK_METHOD3(OnCategoryStatusChanged, |
+ void(ContentSuggestionsProvider* provider, Category category, |
+ CategoryStatus new_status)); |
+}; |
+ |
+class PhysicalWebPageSuggestionsProviderTest : public testing::Test { |
+ public: |
+ PhysicalWebPageSuggestionsProviderTest() {} |
+ |
+ void SetUp() override {} |
+ |
+ void TearDown() override {} |
Marc Treib
2016/08/10 16:22:03
No need to implement SetUp and TearDown if they do
vitaliii
2016/08/11 12:15:25
Done.
|
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(PhysicalWebPageSuggestionsProviderTest); |
+}; |
+ |
+TEST_F(PhysicalWebPageSuggestionsProviderTest, ShouldCreateSuggestions) { |
tschumann
2016/08/10 17:37:57
If you don't use anything of the test fixture (==t
vitaliii
2016/08/11 12:15:25
Done.
|
+ MockProviderObserver observer; |
+ CategoryFactory category_factory; |
+ ContentSuggestionsProvider::Observer* ob = &observer; |
+ PhysicalWebPageSuggestionsProvider provider(ob, &category_factory); |
Marc Treib
2016/08/10 16:22:03
Just do &observer here and get rid of the ob varia
vitaliii
2016/08/11 12:15:25
Done.
|
+ const std::vector<std::string> urls( |
+ {"http://test1.com/", "http://test2.com/"}); |
+ const std::vector<UrlInfo> url_infos = CreateUrlInfos(urls); |
+ |
+ EXPECT_CALL(observer, OnNewSuggestionsUrls(urls)); |
+ provider.OnDisplayableUrlsChanged(url_infos); |
+} |
+ |
+} // namespace |
Marc Treib
2016/08/10 16:22:03
Only the global functions should be in the anonymo
tschumann
2016/08/10 17:37:57
actually, i think there's a tendency to have all t
Marc Treib
2016/08/11 12:15:24
This is not a common tendency in Chrome I think, b
vitaliii
2016/08/11 12:15:25
Other files in the folder (e.g. https://cs.chromiu
tschumann
2016/08/11 12:52:24
Consistency trumps; so let's remove it. [however,
Marc Treib
2016/08/11 13:09:14
They're somewhat common in unit tests. Personally,
vitaliii
2016/08/11 14:29:58
Acknowledged.
|
+ |
+} // namespace ntp_snippets |