Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: components/ntp_snippets/content_suggestions_provider_unittest.cc

Issue 2302363002: Revert of Add test of MakeUniqueID() and friends. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/ntp_snippets/content_suggestions_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/ntp_snippets/content_suggestions_provider.h"
6
7 #include "base/callback.h"
8 #include "components/ntp_snippets/category_factory.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 using testing::Eq;
13 using testing::StrictMock;
14
15 namespace ntp_snippets {
16
17 // We do not care about any of these methods. We use mock methods so that we can
18 // declare a StrictMock below and ensure none of them are called.
19 class MockContentSuggestionsProvider : public ContentSuggestionsProvider {
20 public:
21 MockContentSuggestionsProvider(Observer* observer,
22 CategoryFactory* category_factory)
23 : ContentSuggestionsProvider(observer, category_factory) {}
24 virtual ~MockContentSuggestionsProvider() = default;
25
26 MOCK_METHOD1(GetCategoryStatus, CategoryStatus(Category));
27 MOCK_METHOD1(GetCategoryInfo, CategoryInfo(Category));
28 MOCK_METHOD1(DismissSuggestion, void(const std::string&));
29 MOCK_METHOD2(FetchSuggestionImage,
30 void(const std::string&, const ImageFetchedCallback&));
31 MOCK_METHOD3(ClearHistory,
32 void(base::Time,
33 base::Time,
34 const base::Callback<bool(const GURL&)>&));
35 MOCK_METHOD1(ClearCachedSuggestions, void(Category));
36 MOCK_METHOD2(GetDismissedSuggestionsForDebugging,
37 void(Category, const DismissedSuggestionsCallback&));
38 MOCK_METHOD1(ClearDismissedSuggestionsForDebugging, void(Category));
39 };
40
41 class ContentSuggestionsProviderTest : public ::testing::Test {
42 protected:
43 ContentSuggestionsProviderTest() : provider_(nullptr, &factory_) {}
44
45 std::string MakeUniqueID(Category category,
46 const std::string& within_category_id) const {
47 return provider_.MakeUniqueID(category, within_category_id);
48 }
49
50 Category GetCategoryFromUniqueID(const std::string& unique_id) const {
51 return provider_.GetCategoryFromUniqueID(unique_id);
52 }
53
54 std::string GetWithinCategoryIDFromUniqueID(
55 const std::string& unique_id) const {
56 return provider_.GetWithinCategoryIDFromUniqueID(unique_id);
57 }
58
59 CategoryFactory factory_;
60 StrictMock<MockContentSuggestionsProvider> provider_;
61 };
62
63 TEST_F(ContentSuggestionsProviderTest, Articles) {
64 Category kArticles = factory_.FromKnownCategory(KnownCategories::ARTICLES);
65 const std::string kUrl = "https://chromium.org/";
66
67 std::string uid = MakeUniqueID(kArticles, kUrl);
68 EXPECT_THAT(uid, Eq("10001|https://chromium.org/"));
69 EXPECT_THAT(GetCategoryFromUniqueID(uid), Eq(kArticles));
70 EXPECT_THAT(GetWithinCategoryIDFromUniqueID(uid), Eq(kUrl));
71 }
72
73 TEST_F(ContentSuggestionsProviderTest, Remote) {
74 Category kRemoteCategory = factory_.FromRemoteCategory(2);
75 const std::string kUrl = "https://chromium.org/";
76
77 std::string uid = MakeUniqueID(kRemoteCategory, kUrl);
78 EXPECT_THAT(uid, Eq("10002|https://chromium.org/"));
79 EXPECT_THAT(GetCategoryFromUniqueID(uid), Eq(kRemoteCategory));
80 EXPECT_THAT(GetWithinCategoryIDFromUniqueID(uid), Eq(kUrl));
81 }
82
83 TEST_F(ContentSuggestionsProviderTest, FromID) {
84 Category kCategory = factory_.FromIDValue(10003);
85 const std::string kUrl = "https://chromium.org/";
86
87 std::string uid = MakeUniqueID(kCategory, kUrl);
88 EXPECT_THAT(uid, Eq("10003|https://chromium.org/"));
89 EXPECT_THAT(GetCategoryFromUniqueID(uid), Eq(kCategory));
90 EXPECT_THAT(GetWithinCategoryIDFromUniqueID(uid), Eq(kUrl));
91 }
92
93 TEST_F(ContentSuggestionsProviderTest, Death) {
94 const std::string kUrl = "https://chromium.org/";
95 #if DCHECK_IS_ON()
96 EXPECT_DEATH_IF_SUPPORTED(GetCategoryFromUniqueID(kUrl),
97 "Not a valid unique_id");
98 EXPECT_DEATH_IF_SUPPORTED(GetWithinCategoryIDFromUniqueID(kUrl),
99 "Not a valid unique_id");
100
101 EXPECT_DEATH_IF_SUPPORTED(GetCategoryFromUniqueID("one|" + kUrl),
102 "Non-numeric category");
103 EXPECT_THAT(GetWithinCategoryIDFromUniqueID("one|" + kUrl), Eq(kUrl));
104 #else
105 const Category kNoCategory = factory_.FromIDValue(-1);
106
107 EXPECT_THAT(GetCategoryFromUniqueID(kUrl), Eq(kNoCategory));
108 EXPECT_THAT(GetWithinCategoryIDFromUniqueID(kUrl), Eq(kUrl));
109
110 EXPECT_THAT(GetCategoryFromUniqueID("one|" + kUrl), Eq(kNoCategory));
111 EXPECT_THAT(GetWithinCategoryIDFromUniqueID("one|" + kUrl), Eq(kUrl));
112 #endif
113 }
114
115 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/content_suggestions_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698