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

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

Issue 2400133002: Sending LanguageModel info to suggestions server (Closed)
Patch Set: Small fixes Created 4 years, 2 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/ntp_snippets_fetcher.h" 5 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 fake_token_service_(new FakeProfileOAuth2TokenService()), 157 fake_token_service_(new FakeProfileOAuth2TokenService()),
158 pref_service_(new TestingPrefServiceSimple()), 158 pref_service_(new TestingPrefServiceSimple()),
159 test_lang_("en-US"), 159 test_lang_("en-US"),
160 test_url_(gurl) { 160 test_url_(gurl) {
161 RequestThrottler::RegisterProfilePrefs(pref_service_->registry()); 161 RequestThrottler::RegisterProfilePrefs(pref_service_->registry());
162 162
163 snippets_fetcher_ = base::MakeUnique<NTPSnippetsFetcher>( 163 snippets_fetcher_ = base::MakeUnique<NTPSnippetsFetcher>(
164 fake_signin_manager_.get(), fake_token_service_.get(), 164 fake_signin_manager_.get(), fake_token_service_.get(),
165 scoped_refptr<net::TestURLRequestContextGetter>( 165 scoped_refptr<net::TestURLRequestContextGetter>(
166 new net::TestURLRequestContextGetter(mock_task_runner_.get())), 166 new net::TestURLRequestContextGetter(mock_task_runner_.get())),
167 pref_service_.get(), &category_factory_, base::Bind(&ParseJsonDelayed), 167 pref_service_.get(), &category_factory_, nullptr,
168 kAPIKey); 168 base::Bind(&ParseJsonDelayed), kAPIKey);
169 169
170 snippets_fetcher_->SetCallback( 170 snippets_fetcher_->SetCallback(
171 base::Bind(&MockSnippetsAvailableCallback::WrappedRun, 171 base::Bind(&MockSnippetsAvailableCallback::WrappedRun,
172 base::Unretained(&mock_callback_))); 172 base::Unretained(&mock_callback_)));
173 snippets_fetcher_->SetTickClockForTesting( 173 snippets_fetcher_->SetTickClockForTesting(
174 mock_task_runner_->GetMockTickClock()); 174 mock_task_runner_->GetMockTickClock());
175 test_excluded_.insert("1234567890"); 175 test_excluded_.insert("1234567890");
176 // Increase initial time such that ticks are non-zero. 176 // Increase initial time such that ticks are non-zero.
177 mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234)); 177 mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234));
178 } 178 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 } 301 }
302 302
303 TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) { 303 TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) {
304 NTPSnippetsFetcher::RequestParams params; 304 NTPSnippetsFetcher::RequestParams params;
305 params.only_return_personalized_results = false; 305 params.only_return_personalized_results = false;
306 params.host_restricts = {}; 306 params.host_restricts = {};
307 params.count_to_fetch = 10; 307 params.count_to_fetch = 10;
308 params.excluded_ids = {}; 308 params.excluded_ids = {};
309 params.interactive_request = true; 309 params.interactive_request = true;
310 310
311
312 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API; 311 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API;
313 EXPECT_THAT(params.BuildRequest(), 312 EXPECT_THAT(params.BuildRequest(),
314 EqualsJSON("{" 313 EqualsJSON("{"
315 " \"response_detail_level\": \"STANDARD\"," 314 " \"response_detail_level\": \"STANDARD\","
316 " \"advanced_options\": {" 315 " \"advanced_options\": {"
317 " \"local_scoring_params\": {" 316 " \"local_scoring_params\": {"
318 " \"content_params\": {" 317 " \"content_params\": {"
319 " \"only_return_personalized_results\": false" 318 " \"only_return_personalized_results\": false"
320 " }," 319 " },"
321 " \"content_restricts\": [" 320 " \"content_restricts\": ["
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 " \"080\", \"081\", \"082\", \"083\", \"084\"," 384 " \"080\", \"081\", \"082\", \"083\", \"084\","
386 " \"085\", \"086\", \"087\", \"088\", \"089\"," 385 " \"085\", \"086\", \"087\", \"088\", \"089\","
387 " \"090\", \"091\", \"092\", \"093\", \"094\"," 386 " \"090\", \"091\", \"092\", \"093\", \"094\","
388 " \"095\", \"096\", \"097\", \"098\", \"099\"" 387 " \"095\", \"096\", \"097\", \"098\", \"099\""
389 // Truncated to 100 entries. Currently, they happen to 388 // Truncated to 100 entries. Currently, they happen to
390 // be those lexically first. 389 // be those lexically first.
391 " ]" 390 " ]"
392 "}")); 391 "}"));
393 } 392 }
394 393
394 TEST_F(NTPSnippetsFetcherTest, BuildRequestWithTwoLanguages) {
395 NTPSnippetsFetcher::RequestParams params;
396 params.only_return_personalized_results = false;
397 params.host_restricts = {};
398 params.count_to_fetch = 10;
399 params.interactive_request = true;
400 params.ui_language.language_code = "en";
401 params.ui_language.frequency = 0.5f;
402 params.other_top_language.language_code = "de";
403 params.other_top_language.frequency = 0.5f;
404
405 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
406 EXPECT_THAT(params.BuildRequest(),
407 EqualsJSON("{"
408 " \"regularlyVisitedHostNames\": [],"
409 " \"priority\": \"USER_ACTION\","
410 " \"excludedSuggestionIds\": [],"
411 " \"top_languages\": ["
412 " {"
413 " \"language\" : \"en\","
414 " \"frequency\" : 0.5"
415 " },"
416 " {"
417 " \"language\" : \"de\","
418 " \"frequency\" : 0.5"
419 " }"
420 " ]"
421 "}"));
422 }
423
424 TEST_F(NTPSnippetsFetcherTest, BuildRequestWithUILanguageOnly) {
425 NTPSnippetsFetcher::RequestParams params;
426 params.only_return_personalized_results = false;
427 params.host_restricts = {};
428 params.count_to_fetch = 10;
429 params.interactive_request = true;
430 params.ui_language.language_code = "en";
431 params.ui_language.frequency = 0.5f;
432
433 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
434 EXPECT_THAT(params.BuildRequest(),
435 EqualsJSON("{"
436 " \"regularlyVisitedHostNames\": [],"
437 " \"priority\": \"USER_ACTION\","
438 " \"excludedSuggestionIds\": [],"
439 " \"top_languages\": [{"
440 " \"language\" : \"en\","
441 " \"frequency\" : 0.5"
442 " }]"
443 "}"));
444 }
445
446 TEST_F(NTPSnippetsFetcherTest, BuildRequestWithOtherLanguageOnly) {
447 NTPSnippetsFetcher::RequestParams params;
448 params.only_return_personalized_results = false;
449 params.host_restricts = {};
450 params.count_to_fetch = 10;
451 params.interactive_request = true;
452 params.other_top_language.language_code = "de";
453 params.other_top_language.frequency = 0.5f;
454
455 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
456 EXPECT_THAT(params.BuildRequest(),
457 EqualsJSON("{"
458 " \"regularlyVisitedHostNames\": [],"
459 " \"priority\": \"USER_ACTION\","
460 " \"excludedSuggestionIds\": [],"
461 " \"top_languages\": [{"
462 " \"language\" : \"de\","
463 " \"frequency\" : 0.5"
464 " }]"
465 "}"));
466 }
467
395 TEST_F(NTPSnippetsFetcherTest, ShouldNotFetchOnCreation) { 468 TEST_F(NTPSnippetsFetcherTest, ShouldNotFetchOnCreation) {
396 // The lack of registered baked in responses would cause any fetch to fail. 469 // The lack of registered baked in responses would cause any fetch to fail.
397 FastForwardUntilNoTasksRemain(); 470 FastForwardUntilNoTasksRemain();
398 EXPECT_THAT(histogram_tester().GetAllSamples( 471 EXPECT_THAT(histogram_tester().GetAllSamples(
399 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 472 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
400 IsEmpty()); 473 IsEmpty());
401 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), 474 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
402 IsEmpty()); 475 IsEmpty());
403 EXPECT_THAT(snippets_fetcher().last_status(), IsEmpty()); 476 EXPECT_THAT(snippets_fetcher().last_status(), IsEmpty());
404 } 477 }
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 const NTPSnippetsFetcher::OptionalSnippets& snippets) { 841 const NTPSnippetsFetcher::OptionalSnippets& snippets) {
769 if (snippets) { 842 if (snippets) {
770 // Matchers above aren't any more precise than this, so this is sufficient 843 // Matchers above aren't any more precise than this, so this is sufficient
771 // for test-failure diagnostics. 844 // for test-failure diagnostics.
772 return os << "list with " << snippets->size() << " elements"; 845 return os << "list with " << snippets->size() << " elements";
773 } 846 }
774 return os << "null"; 847 return os << "null";
775 } 848 }
776 849
777 } // namespace ntp_snippets 850 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698