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

Unified Diff: components/ntp_snippets/breaking_news/subscription_manager_unittest.cc

Issue 2922543002: [NTP::Push] Add Content Suggestions GCM App Handler (Closed)
Patch Set: Add missing dependency. Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/ntp_snippets/breaking_news/subscription_manager.cc ('k') | components/ntp_snippets/pref_names.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/breaking_news/subscription_manager_unittest.cc
diff --git a/components/ntp_snippets/breaking_news/subscription_manager_unittest.cc b/components/ntp_snippets/breaking_news/subscription_manager_unittest.cc
index 1cddf00af7bb04649b2fcf188bdd01e0e437f06f..1cf4f4199b05ca1f1c92c68a480cd5888fcfe557 100644
--- a/components/ntp_snippets/breaking_news/subscription_manager_unittest.cc
+++ b/components/ntp_snippets/breaking_news/subscription_manager_unittest.cc
@@ -54,6 +54,8 @@ class SubscriptionManagerTest : public testing::Test {
url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
}
+ const std::string url{"http://valid-url.test"};
+
private:
base::MessageLoop message_loop_;
scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
@@ -63,10 +65,11 @@ class SubscriptionManagerTest : public testing::Test {
TEST_F(SubscriptionManagerTest, SubscribeSuccessfully) {
std::string token = "1234567890";
- SubscriptionManager manager(GetRequestContext(), GetPrefService(),
- GURL("http://valid-url.test"));
+ SubscriptionManager manager(GetRequestContext(), GetPrefService(), GURL(url),
+ GURL(url));
manager.Subscribe(token);
RespondWithData("");
+ EXPECT_TRUE(manager.IsSubscribed());
EXPECT_EQ(GetPrefService()->GetString(
ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken),
token);
@@ -74,12 +77,40 @@ TEST_F(SubscriptionManagerTest, SubscribeSuccessfully) {
TEST_F(SubscriptionManagerTest, SubscribeWithErrors) {
std::string token = "1234567890";
- SubscriptionManager manager(GetRequestContext(), GetPrefService(),
- GURL("http://valid-url.test"));
+ SubscriptionManager manager(GetRequestContext(), GetPrefService(), GURL(url),
+ GURL(url));
manager.Subscribe(token);
RespondWithError(net::ERR_TIMED_OUT);
+ EXPECT_FALSE(manager.IsSubscribed());
+ EXPECT_FALSE(GetPrefService()->HasPrefPath(
+ ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken));
+}
+
+TEST_F(SubscriptionManagerTest, UnsubscribeSuccessfully) {
+ std::string token = "1234567890";
+ GetPrefService()->SetString(
+ ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken, token);
+ SubscriptionManager manager(GetRequestContext(), GetPrefService(), GURL(url),
+ GURL(url));
+ manager.Unsubscribe(token);
+ RespondWithData("");
+ EXPECT_FALSE(manager.IsSubscribed());
EXPECT_FALSE(GetPrefService()->HasPrefPath(
ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken));
}
+TEST_F(SubscriptionManagerTest, UnsubscribeWithErrors) {
+ std::string token = "1234567890";
+ GetPrefService()->SetString(
+ ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken, token);
+ SubscriptionManager manager(GetRequestContext(), GetPrefService(), GURL(url),
+ GURL(url));
+ manager.Unsubscribe(token);
+ RespondWithError(net::ERR_TIMED_OUT);
+ EXPECT_TRUE(manager.IsSubscribed());
+ EXPECT_EQ(GetPrefService()->GetString(
+ ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken),
+ token);
+}
+
} // namespace ntp_snippets
« no previous file with comments | « components/ntp_snippets/breaking_news/subscription_manager.cc ('k') | components/ntp_snippets/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698