Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/breaking_news/subscription_manager.h" | 5 #include "components/ntp_snippets/breaking_news/subscription_manager.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "components/ntp_snippets/pref_names.h" | 8 #include "components/ntp_snippets/pref_names.h" |
| 9 #include "components/prefs/testing_pref_service.h" | 9 #include "components/prefs/testing_pref_service.h" |
| 10 #include "net/url_request/test_url_fetcher_factory.h" | 10 #include "net/url_request/test_url_fetcher_factory.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 private: | 57 private: |
| 58 base::MessageLoop message_loop_; | 58 base::MessageLoop message_loop_; |
| 59 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 59 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
| 60 net::TestURLFetcherFactory url_fetcher_factory_; | 60 net::TestURLFetcherFactory url_fetcher_factory_; |
| 61 std::unique_ptr<TestingPrefServiceSimple> pref_service_; | 61 std::unique_ptr<TestingPrefServiceSimple> pref_service_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 TEST_F(SubscriptionManagerTest, SubscribeSuccessfully) { | 64 TEST_F(SubscriptionManagerTest, SubscribeSuccessfully) { |
| 65 std::string token = "1234567890"; | 65 std::string token = "1234567890"; |
| 66 SubscriptionManager manager(GetRequestContext(), GetPrefService(), | 66 SubscriptionManager manager(GetRequestContext(), GetPrefService(), |
| 67 GURL("http://valid-url.test"), | |
|
Peter Beverloo
2017/06/08 07:02:40
nit: usually we store repeated strings in a consta
mamir
2017/06/08 10:31:38
Done.
| |
| 67 GURL("http://valid-url.test")); | 68 GURL("http://valid-url.test")); |
| 68 manager.Subscribe(token); | 69 manager.Subscribe(token); |
| 69 RespondWithData(""); | 70 RespondWithData(""); |
| 70 EXPECT_EQ(GetPrefService()->GetString( | 71 EXPECT_EQ(GetPrefService()->GetString( |
| 71 ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken), | 72 ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken), |
| 72 token); | 73 token); |
| 73 } | 74 } |
| 74 | 75 |
| 75 TEST_F(SubscriptionManagerTest, SubscribeWithErrors) { | 76 TEST_F(SubscriptionManagerTest, SubscribeWithErrors) { |
| 76 std::string token = "1234567890"; | 77 std::string token = "1234567890"; |
| 77 SubscriptionManager manager(GetRequestContext(), GetPrefService(), | 78 SubscriptionManager manager(GetRequestContext(), GetPrefService(), |
| 79 GURL("http://valid-url.test"), | |
| 78 GURL("http://valid-url.test")); | 80 GURL("http://valid-url.test")); |
| 79 manager.Subscribe(token); | 81 manager.Subscribe(token); |
| 80 RespondWithError(net::ERR_TIMED_OUT); | 82 RespondWithError(net::ERR_TIMED_OUT); |
| 81 EXPECT_FALSE(GetPrefService()->HasPrefPath( | 83 EXPECT_FALSE(GetPrefService()->HasPrefPath( |
| 82 ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken)); | 84 ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken)); |
| 83 } | 85 } |
| 84 | 86 |
| 87 TEST_F(SubscriptionManagerTest, UnsubscribeSuccessfully) { | |
| 88 std::string token = "1234567890"; | |
| 89 GetPrefService()->SetString( | |
| 90 ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken, token); | |
| 91 SubscriptionManager manager(GetRequestContext(), GetPrefService(), | |
| 92 GURL("http://valid-url.test"), | |
| 93 GURL("http://valid-url.test")); | |
| 94 manager.Unsubscribe(token); | |
| 95 RespondWithData(""); | |
| 96 EXPECT_FALSE(GetPrefService()->HasPrefPath( | |
| 97 ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken)); | |
| 98 } | |
| 99 | |
| 100 TEST_F(SubscriptionManagerTest, UnsubscribeWithErrors) { | |
| 101 std::string token = "1234567890"; | |
| 102 GetPrefService()->SetString( | |
| 103 ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken, token); | |
| 104 SubscriptionManager manager(GetRequestContext(), GetPrefService(), | |
| 105 GURL("http://valid-url.test"), | |
| 106 GURL("http://valid-url.test")); | |
| 107 manager.Unsubscribe(token); | |
| 108 RespondWithError(net::ERR_TIMED_OUT); | |
| 109 EXPECT_EQ(GetPrefService()->GetString( | |
| 110 ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken), | |
| 111 token); | |
| 112 } | |
| 113 | |
| 85 } // namespace ntp_snippets | 114 } // namespace ntp_snippets |
| OLD | NEW |