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

Side by Side Diff: components/ntp_snippets/remote/remote_suggestions_fetcher_unittest.cc

Issue 2665743002: [Remote suggestions] Clean up variation params in the fetcher. (Closed)
Patch Set: Add a comment Created 3 years, 10 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
OLDNEW
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/remote/remote_suggestions_fetcher.h" 5 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 const SuccessCallback& success_callback, 260 const SuccessCallback& success_callback,
261 const ErrorCallback& error_callback) { 261 const ErrorCallback& error_callback) {
262 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 262 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
263 FROM_HERE, base::Bind(&ParseJson, json, std::move(success_callback), 263 FROM_HERE, base::Bind(&ParseJson, json, std::move(success_callback),
264 std::move(error_callback)), 264 std::move(error_callback)),
265 base::TimeDelta::FromMilliseconds(kTestJsonParsingLatencyMs)); 265 base::TimeDelta::FromMilliseconds(kTestJsonParsingLatencyMs));
266 } 266 }
267 267
268 } // namespace 268 } // namespace
269 269
270 // TODO(jkrcal): Add unit-tests with signin client being signed in (covering
271 // sign-in / refresh tokens / access token code). crbug.com/688310
270 class RemoteSuggestionsFetcherTestBase : public testing::Test { 272 class RemoteSuggestionsFetcherTestBase : public testing::Test {
271 public: 273 public:
272 explicit RemoteSuggestionsFetcherTestBase(const GURL& gurl) 274 explicit RemoteSuggestionsFetcherTestBase(const GURL& gurl)
273 : default_variation_params_( 275 : default_variation_params_(
274 {{"send_top_languages", "true"}, {"send_user_class", "true"}}), 276 {{"send_top_languages", "true"}, {"send_user_class", "true"}}),
275 params_manager_(ntp_snippets::kStudyName, 277 params_manager_(ntp_snippets::kStudyName,
276 default_variation_params_, 278 default_variation_params_,
277 {ntp_snippets::kArticleSuggestionsFeature.name}), 279 {ntp_snippets::kArticleSuggestionsFeature.name}),
278 mock_task_runner_(new base::TestMockTimeTaskRunner()), 280 mock_task_runner_(new base::TestMockTimeTaskRunner()),
279 mock_task_runner_handle_(mock_task_runner_), 281 mock_task_runner_handle_(mock_task_runner_),
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 677
676 ASSERT_TRUE(fetched_categories); 678 ASSERT_TRUE(fetched_categories);
677 ASSERT_THAT(fetched_categories->size(), Eq(1u)); 679 ASSERT_THAT(fetched_categories->size(), Eq(1u));
678 const auto& category = (*fetched_categories)[0]; 680 const auto& category = (*fetched_categories)[0];
679 EXPECT_THAT(category.category.id(), Eq(Category::FromRemoteCategory(2).id())); 681 EXPECT_THAT(category.category.id(), Eq(Category::FromRemoteCategory(2).id()));
680 ASSERT_THAT(category.suggestions.size(), Eq(1u)); 682 ASSERT_THAT(category.suggestions.size(), Eq(1u));
681 EXPECT_THAT(category.suggestions[0]->url().spec(), 683 EXPECT_THAT(category.suggestions[0]->url().spec(),
682 Eq("http://localhost/foo2")); 684 Eq("http://localhost/foo2"));
683 } 685 }
684 686
685 // TODO(fhorschig): Check for behavioral changes instead of state.
686 TEST_F(ChromeReaderSnippetsFetcherTest, PersonalizesDependingOnVariations) {
687 // Default setting should be both personalization options.
688 EXPECT_THAT(snippets_fetcher().personalization(), Eq(Personalization::kBoth));
689
690 SetVariationParam("fetching_personalization", "personal");
691 ResetSnippetsFetcher();
692 EXPECT_THAT(snippets_fetcher().personalization(),
693 Eq(Personalization::kPersonal));
694
695 SetVariationParam("fetching_personalization", "non_personal");
696 ResetSnippetsFetcher();
697 EXPECT_THAT(snippets_fetcher().personalization(),
698 Eq(Personalization::kNonPersonal));
699
700 SetVariationParam("fetching_personalization", "both");
701 ResetSnippetsFetcher();
702 EXPECT_THAT(snippets_fetcher().personalization(), Eq(Personalization::kBoth));
703 }
704
705 TEST_F(ChromeReaderSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) { 687 TEST_F(ChromeReaderSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) {
706 const std::string kJsonStr = "{\"recos\": []}"; 688 const std::string kJsonStr = "{\"recos\": []}";
707 SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, 689 SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK,
708 net::URLRequestStatus::SUCCESS); 690 net::URLRequestStatus::SUCCESS);
709 EXPECT_CALL(mock_callback(), Run(IsSuccess(), IsEmptyArticleList())); 691 EXPECT_CALL(mock_callback(), Run(IsSuccess(), IsEmptyArticleList()));
710 snippets_fetcher().FetchSnippets( 692 snippets_fetcher().FetchSnippets(
711 test_params(), ToSnippetsAvailableCallback(&mock_callback())); 693 test_params(), ToSnippetsAvailableCallback(&mock_callback()));
712 FastForwardUntilNoTasksRemain(); 694 FastForwardUntilNoTasksRemain();
713 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK")); 695 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK"));
714 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr)); 696 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr));
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 fetched_categories) { 899 fetched_categories) {
918 if (fetched_categories) { 900 if (fetched_categories) {
919 // Matchers above aren't any more precise than this, so this is sufficient 901 // Matchers above aren't any more precise than this, so this is sufficient
920 // for test-failure diagnostics. 902 // for test-failure diagnostics.
921 return os << "list with " << fetched_categories->size() << " elements"; 903 return os << "list with " << fetched_categories->size() << " elements";
922 } 904 }
923 return os << "null"; 905 return os << "null";
924 } 906 }
925 907
926 } // namespace ntp_snippets 908 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698