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

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

Issue 2395123002: Connecting UserClassifier to NtpSnippetsFetcher (Closed)
Patch Set: Unit-test fix 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"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/test/histogram_tester.h" 13 #include "base/test/histogram_tester.h"
14 #include "base/test/test_mock_time_task_runner.h" 14 #include "base/test/test_mock_time_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "components/ntp_snippets/category_factory.h" 18 #include "components/ntp_snippets/category_factory.h"
19 #include "components/ntp_snippets/ntp_snippets_constants.h" 19 #include "components/ntp_snippets/ntp_snippets_constants.h"
20 #include "components/ntp_snippets/remote/ntp_snippet.h" 20 #include "components/ntp_snippets/remote/ntp_snippet.h"
21 #include "components/ntp_snippets/user_classifier.h"
21 #include "components/prefs/testing_pref_service.h" 22 #include "components/prefs/testing_pref_service.h"
22 #include "components/signin/core/browser/account_tracker_service.h" 23 #include "components/signin/core/browser/account_tracker_service.h"
23 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" 24 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
24 #include "components/signin/core/browser/fake_signin_manager.h" 25 #include "components/signin/core/browser/fake_signin_manager.h"
25 #include "components/signin/core/browser/test_signin_client.h" 26 #include "components/signin/core/browser/test_signin_client.h"
26 #include "components/variations/entropy_provider.h" 27 #include "components/variations/entropy_provider.h"
27 #include "components/variations/variations_associated_data.h" 28 #include "components/variations/variations_associated_data.h"
28 #include "net/url_request/test_url_fetcher_factory.h" 29 #include "net/url_request/test_url_fetcher_factory.h"
29 #include "net/url_request/url_request_test_util.h" 30 #include "net/url_request/url_request_test_util.h"
30 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 mock_task_runner_handle_(mock_task_runner_), 157 mock_task_runner_handle_(mock_task_runner_),
157 signin_client_(new TestSigninClient(nullptr)), 158 signin_client_(new TestSigninClient(nullptr)),
158 account_tracker_(new AccountTrackerService()), 159 account_tracker_(new AccountTrackerService()),
159 fake_signin_manager_(new FakeSigninManagerBase(signin_client_.get(), 160 fake_signin_manager_(new FakeSigninManagerBase(signin_client_.get(),
160 account_tracker_.get())), 161 account_tracker_.get())),
161 fake_token_service_(new FakeProfileOAuth2TokenService()), 162 fake_token_service_(new FakeProfileOAuth2TokenService()),
162 pref_service_(new TestingPrefServiceSimple()), 163 pref_service_(new TestingPrefServiceSimple()),
163 test_lang_("en-US"), 164 test_lang_("en-US"),
164 test_url_(gurl) { 165 test_url_(gurl) {
165 RequestThrottler::RegisterProfilePrefs(pref_service_->registry()); 166 RequestThrottler::RegisterProfilePrefs(pref_service_->registry());
167 UserClassifier::RegisterProfilePrefs(pref_service_->registry());
168 user_classifier_ = base::MakeUnique<UserClassifier>(pref_service_.get());
166 169
167 snippets_fetcher_ = base::MakeUnique<NTPSnippetsFetcher>( 170 snippets_fetcher_ = base::MakeUnique<NTPSnippetsFetcher>(
168 fake_signin_manager_.get(), fake_token_service_.get(), 171 fake_signin_manager_.get(), fake_token_service_.get(),
169 scoped_refptr<net::TestURLRequestContextGetter>( 172 scoped_refptr<net::TestURLRequestContextGetter>(
170 new net::TestURLRequestContextGetter(mock_task_runner_.get())), 173 new net::TestURLRequestContextGetter(mock_task_runner_.get())),
171 pref_service_.get(), &category_factory_, nullptr, 174 pref_service_.get(), &category_factory_, nullptr,
172 base::Bind(&ParseJsonDelayed), kAPIKey); 175 base::Bind(&ParseJsonDelayed), kAPIKey, user_classifier_.get());
173 176
174 snippets_fetcher_->SetCallback( 177 snippets_fetcher_->SetCallback(
175 base::Bind(&MockSnippetsAvailableCallback::WrappedRun, 178 base::Bind(&MockSnippetsAvailableCallback::WrappedRun,
176 base::Unretained(&mock_callback_))); 179 base::Unretained(&mock_callback_)));
177 snippets_fetcher_->SetTickClockForTesting( 180 snippets_fetcher_->SetTickClockForTesting(
178 mock_task_runner_->GetMockTickClock()); 181 mock_task_runner_->GetMockTickClock());
179 test_excluded_.insert("1234567890"); 182 test_excluded_.insert("1234567890");
180 // Increase initial time such that ticks are non-zero. 183 // Increase initial time such that ticks are non-zero.
181 mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234)); 184 mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234));
182 } 185 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 base::ThreadTaskRunnerHandle mock_task_runner_handle_; 218 base::ThreadTaskRunnerHandle mock_task_runner_handle_;
216 FailingFakeURLFetcherFactory failing_url_fetcher_factory_; 219 FailingFakeURLFetcherFactory failing_url_fetcher_factory_;
217 // Initialized lazily in SetFakeResponse(). 220 // Initialized lazily in SetFakeResponse().
218 std::unique_ptr<net::FakeURLFetcherFactory> fake_url_fetcher_factory_; 221 std::unique_ptr<net::FakeURLFetcherFactory> fake_url_fetcher_factory_;
219 std::unique_ptr<TestSigninClient> signin_client_; 222 std::unique_ptr<TestSigninClient> signin_client_;
220 std::unique_ptr<AccountTrackerService> account_tracker_; 223 std::unique_ptr<AccountTrackerService> account_tracker_;
221 std::unique_ptr<SigninManagerBase> fake_signin_manager_; 224 std::unique_ptr<SigninManagerBase> fake_signin_manager_;
222 std::unique_ptr<OAuth2TokenService> fake_token_service_; 225 std::unique_ptr<OAuth2TokenService> fake_token_service_;
223 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_; 226 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_;
224 std::unique_ptr<TestingPrefServiceSimple> pref_service_; 227 std::unique_ptr<TestingPrefServiceSimple> pref_service_;
228 std::unique_ptr<UserClassifier> user_classifier_;
225 CategoryFactory category_factory_; 229 CategoryFactory category_factory_;
226 MockSnippetsAvailableCallback mock_callback_; 230 MockSnippetsAvailableCallback mock_callback_;
227 const std::string test_lang_; 231 const std::string test_lang_;
228 const GURL test_url_; 232 const GURL test_url_;
229 std::set<std::string> test_hosts_; 233 std::set<std::string> test_hosts_;
230 std::set<std::string> test_excluded_; 234 std::set<std::string> test_excluded_;
231 base::HistogramTester histogram_tester_; 235 base::HistogramTester histogram_tester_;
232 236
233 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcherTest); 237 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcherTest);
234 }; 238 };
235 239
236 class NTPSnippetsContentSuggestionsFetcherTest : public NTPSnippetsFetcherTest { 240 class NTPSnippetsContentSuggestionsFetcherTest : public NTPSnippetsFetcherTest {
237 public: 241 public:
238 NTPSnippetsContentSuggestionsFetcherTest() 242 NTPSnippetsContentSuggestionsFetcherTest()
239 : NTPSnippetsFetcherTest( 243 : NTPSnippetsFetcherTest(
240 GURL(kTestChromeContentSuggestionsUrl), 244 GURL(kTestChromeContentSuggestionsUrl),
241 {{"content_suggestions_backend", kContentSuggestionsServer}}) {} 245 {{"content_suggestions_backend", kContentSuggestionsServer}}) {}
242 }; 246 };
243 247
244 TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) { 248 TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) {
245 NTPSnippetsFetcher::RequestParams params; 249 NTPSnippetsFetcher::RequestParams params;
246 params.obfuscated_gaia_id = "0BFUSGAIA"; 250 params.obfuscated_gaia_id = "0BFUSGAIA";
247 params.only_return_personalized_results = true; 251 params.only_return_personalized_results = true;
248 params.user_locale = "en"; 252 params.user_locale = "en";
249 params.host_restricts = {"chromium.org"}; 253 params.host_restricts = {"chromium.org"};
250 params.excluded_ids = {"1234567890"}; 254 params.excluded_ids = {"1234567890"};
251 params.count_to_fetch = 25; 255 params.count_to_fetch = 25;
252 params.interactive_request = false; 256 params.interactive_request = false;
257 params.user_class = "ACTIVE_NTP_USER";
253 params.ui_language.frequency = 0.0f; 258 params.ui_language.frequency = 0.0f;
254 params.other_top_language.frequency = 0.0f; 259 params.other_top_language.frequency = 0.0f;
255 260
256 261
257 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API; 262 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API;
258 EXPECT_THAT(params.BuildRequest(), 263 EXPECT_THAT(params.BuildRequest(),
259 EqualsJSON("{" 264 EqualsJSON("{"
260 " \"response_detail_level\": \"STANDARD\"," 265 " \"response_detail_level\": \"STANDARD\","
261 " \"obfuscated_gaia_id\": \"0BFUSGAIA\"," 266 " \"obfuscated_gaia_id\": \"0BFUSGAIA\","
262 " \"user_locale\": \"en\"," 267 " \"user_locale\": \"en\","
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 301 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
297 EXPECT_THAT(params.BuildRequest(), 302 EXPECT_THAT(params.BuildRequest(),
298 EqualsJSON("{" 303 EqualsJSON("{"
299 " \"uiLanguage\": \"en\"," 304 " \"uiLanguage\": \"en\","
300 " \"priority\": \"BACKGROUND_PREFETCH\"," 305 " \"priority\": \"BACKGROUND_PREFETCH\","
301 " \"regularlyVisitedHostNames\": [" 306 " \"regularlyVisitedHostNames\": ["
302 " \"chromium.org\"" 307 " \"chromium.org\""
303 " ]," 308 " ],"
304 " \"excludedSuggestionIds\": [" 309 " \"excludedSuggestionIds\": ["
305 " \"1234567890\"" 310 " \"1234567890\""
306 " ]" 311 " ],"
312 " \"userActivenessClass\": \"ACTIVE_NTP_USER\""
307 "}")); 313 "}"));
308 } 314 }
309 315
310 TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) { 316 TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) {
311 NTPSnippetsFetcher::RequestParams params; 317 NTPSnippetsFetcher::RequestParams params;
312 params.only_return_personalized_results = false; 318 params.only_return_personalized_results = false;
313 params.host_restricts = {}; 319 params.host_restricts = {};
314 params.count_to_fetch = 10; 320 params.count_to_fetch = 10;
315 params.excluded_ids = {}; 321 params.excluded_ids = {};
316 params.interactive_request = true; 322 params.interactive_request = true;
323 params.user_class = "ACTIVE_NTP_USER";
317 params.ui_language.frequency = 0.0f; 324 params.ui_language.frequency = 0.0f;
318 params.other_top_language.frequency = 0.0f; 325 params.other_top_language.frequency = 0.0f;
319 326
320 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API; 327 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API;
321 EXPECT_THAT(params.BuildRequest(), 328 EXPECT_THAT(params.BuildRequest(),
322 EqualsJSON("{" 329 EqualsJSON("{"
323 " \"response_detail_level\": \"STANDARD\"," 330 " \"response_detail_level\": \"STANDARD\","
324 " \"advanced_options\": {" 331 " \"advanced_options\": {"
325 " \"local_scoring_params\": {" 332 " \"local_scoring_params\": {"
326 " \"content_params\": {" 333 " \"content_params\": {"
(...skipping 20 matching lines...) Expand all
347 " \"sort_type\": 1" 354 " \"sort_type\": 1"
348 " }" 355 " }"
349 " }" 356 " }"
350 "}")); 357 "}"));
351 358
352 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 359 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
353 EXPECT_THAT(params.BuildRequest(), 360 EXPECT_THAT(params.BuildRequest(),
354 EqualsJSON("{" 361 EqualsJSON("{"
355 " \"regularlyVisitedHostNames\": []," 362 " \"regularlyVisitedHostNames\": [],"
356 " \"priority\": \"USER_ACTION\"," 363 " \"priority\": \"USER_ACTION\","
357 " \"excludedSuggestionIds\": []" 364 " \"excludedSuggestionIds\": [],"
365 " \"userActivenessClass\": \"ACTIVE_NTP_USER\""
358 "}")); 366 "}"));
359 } 367 }
360 368
361 TEST_F(NTPSnippetsFetcherTest, BuildRequestExcludedIds) { 369 TEST_F(NTPSnippetsFetcherTest, BuildRequestExcludedIds) {
362 NTPSnippetsFetcher::RequestParams params; 370 NTPSnippetsFetcher::RequestParams params;
363 params.only_return_personalized_results = false; 371 params.only_return_personalized_results = false;
364 params.host_restricts = {}; 372 params.host_restricts = {};
365 params.count_to_fetch = 10; 373 params.count_to_fetch = 10;
366 params.interactive_request = false; 374 params.interactive_request = false;
367 for (int i = 0; i < 200; ++i) { 375 for (int i = 0; i < 200; ++i) {
368 params.excluded_ids.insert(base::StringPrintf("%03d", i)); 376 params.excluded_ids.insert(base::StringPrintf("%03d", i));
369 } 377 }
378 params.user_class = "ACTIVE_NTP_USER";
370 params.ui_language.frequency = 0.0f; 379 params.ui_language.frequency = 0.0f;
371 params.other_top_language.frequency = 0.0f; 380 params.other_top_language.frequency = 0.0f;
372 381
373 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 382 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
374 EXPECT_THAT(params.BuildRequest(), 383 EXPECT_THAT(params.BuildRequest(),
375 EqualsJSON("{" 384 EqualsJSON("{"
376 " \"regularlyVisitedHostNames\": []," 385 " \"regularlyVisitedHostNames\": [],"
377 " \"priority\": \"BACKGROUND_PREFETCH\"," 386 " \"priority\": \"BACKGROUND_PREFETCH\","
378 " \"excludedSuggestionIds\": [" 387 " \"excludedSuggestionIds\": ["
379 " \"000\", \"001\", \"002\", \"003\", \"004\"," 388 " \"000\", \"001\", \"002\", \"003\", \"004\","
(...skipping 11 matching lines...) Expand all
391 " \"060\", \"061\", \"062\", \"063\", \"064\"," 400 " \"060\", \"061\", \"062\", \"063\", \"064\","
392 " \"065\", \"066\", \"067\", \"068\", \"069\"," 401 " \"065\", \"066\", \"067\", \"068\", \"069\","
393 " \"070\", \"071\", \"072\", \"073\", \"074\"," 402 " \"070\", \"071\", \"072\", \"073\", \"074\","
394 " \"075\", \"076\", \"077\", \"078\", \"079\"," 403 " \"075\", \"076\", \"077\", \"078\", \"079\","
395 " \"080\", \"081\", \"082\", \"083\", \"084\"," 404 " \"080\", \"081\", \"082\", \"083\", \"084\","
396 " \"085\", \"086\", \"087\", \"088\", \"089\"," 405 " \"085\", \"086\", \"087\", \"088\", \"089\","
397 " \"090\", \"091\", \"092\", \"093\", \"094\"," 406 " \"090\", \"091\", \"092\", \"093\", \"094\","
398 " \"095\", \"096\", \"097\", \"098\", \"099\"" 407 " \"095\", \"096\", \"097\", \"098\", \"099\""
399 // Truncated to 100 entries. Currently, they happen to 408 // Truncated to 100 entries. Currently, they happen to
400 // be those lexically first. 409 // be those lexically first.
401 " ]" 410 " ],"
411 " \"userActivenessClass\": \"ACTIVE_NTP_USER\""
402 "}")); 412 "}"));
403 } 413 }
404 414
415 TEST_F(NTPSnippetsFetcherTest, BuildRequestNoUserClass) {
416 NTPSnippetsFetcher::RequestParams params;
417 params.only_return_personalized_results = false;
418 params.host_restricts = {};
419 params.count_to_fetch = 10;
420 params.interactive_request = false;
421 params.ui_language.frequency = 0.0f;
422 params.other_top_language.frequency = 0.0f;
423
424 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
425 EXPECT_THAT(params.BuildRequest(),
426 EqualsJSON("{"
427 " \"regularlyVisitedHostNames\": [],"
428 " \"priority\": \"BACKGROUND_PREFETCH\","
429 " \"excludedSuggestionIds\": []"
430 "}"));
431 }
432
405 TEST_F(NTPSnippetsFetcherTest, BuildRequestWithTwoLanguages) { 433 TEST_F(NTPSnippetsFetcherTest, BuildRequestWithTwoLanguages) {
406 NTPSnippetsFetcher::RequestParams params; 434 NTPSnippetsFetcher::RequestParams params;
407 params.only_return_personalized_results = false; 435 params.only_return_personalized_results = false;
408 params.host_restricts = {}; 436 params.host_restricts = {};
409 params.count_to_fetch = 10; 437 params.count_to_fetch = 10;
410 params.interactive_request = true; 438 params.interactive_request = true;
411 params.ui_language.language_code = "en"; 439 params.ui_language.language_code = "en";
412 params.ui_language.frequency = 0.5f; 440 params.ui_language.frequency = 0.5f;
413 params.other_top_language.language_code = "de"; 441 params.other_top_language.language_code = "de";
414 params.other_top_language.frequency = 0.5f; 442 params.other_top_language.frequency = 0.5f;
415 443
416 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 444 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
417 EXPECT_THAT(params.BuildRequest(), 445 EXPECT_THAT(params.BuildRequest(),
418 EqualsJSON("{" 446 EqualsJSON("{"
419 " \"regularlyVisitedHostNames\": []," 447 " \"regularlyVisitedHostNames\": [],"
420 " \"priority\": \"USER_ACTION\"," 448 " \"priority\": \"USER_ACTION\","
421 " \"excludedSuggestionIds\": []," 449 " \"excludedSuggestionIds\": [],"
422 " \"top_languages\": [" 450 " \"topLanguages\": ["
423 " {" 451 " {"
424 " \"language\" : \"en\"," 452 " \"language\" : \"en\","
425 " \"frequency\" : 0.5" 453 " \"frequency\" : 0.5"
426 " }," 454 " },"
427 " {" 455 " {"
428 " \"language\" : \"de\"," 456 " \"language\" : \"de\","
429 " \"frequency\" : 0.5" 457 " \"frequency\" : 0.5"
430 " }" 458 " }"
431 " ]" 459 " ]"
432 "}")); 460 "}"));
433 } 461 }
434 462
435 TEST_F(NTPSnippetsFetcherTest, BuildRequestWithUILanguageOnly) { 463 TEST_F(NTPSnippetsFetcherTest, BuildRequestWithUILanguageOnly) {
436 NTPSnippetsFetcher::RequestParams params; 464 NTPSnippetsFetcher::RequestParams params;
437 params.only_return_personalized_results = false; 465 params.only_return_personalized_results = false;
438 params.host_restricts = {}; 466 params.host_restricts = {};
439 params.count_to_fetch = 10; 467 params.count_to_fetch = 10;
440 params.interactive_request = true; 468 params.interactive_request = true;
441 params.ui_language.language_code = "en"; 469 params.ui_language.language_code = "en";
442 params.ui_language.frequency = 0.5f; 470 params.ui_language.frequency = 0.5f;
443 params.other_top_language.frequency = 0.0f; 471 params.other_top_language.frequency = 0.0f;
444 472
445 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 473 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
446 EXPECT_THAT(params.BuildRequest(), 474 EXPECT_THAT(params.BuildRequest(),
447 EqualsJSON("{" 475 EqualsJSON("{"
448 " \"regularlyVisitedHostNames\": []," 476 " \"regularlyVisitedHostNames\": [],"
449 " \"priority\": \"USER_ACTION\"," 477 " \"priority\": \"USER_ACTION\","
450 " \"excludedSuggestionIds\": []," 478 " \"excludedSuggestionIds\": [],"
451 " \"top_languages\": [{" 479 " \"topLanguages\": [{"
452 " \"language\" : \"en\"," 480 " \"language\" : \"en\","
453 " \"frequency\" : 0.5" 481 " \"frequency\" : 0.5"
454 " }]" 482 " }]"
455 "}")); 483 "}"));
456 } 484 }
457 485
458 TEST_F(NTPSnippetsFetcherTest, BuildRequestWithOtherLanguageOnly) { 486 TEST_F(NTPSnippetsFetcherTest, BuildRequestWithOtherLanguageOnly) {
459 NTPSnippetsFetcher::RequestParams params; 487 NTPSnippetsFetcher::RequestParams params;
460 params.only_return_personalized_results = false; 488 params.only_return_personalized_results = false;
461 params.host_restricts = {}; 489 params.host_restricts = {};
462 params.count_to_fetch = 10; 490 params.count_to_fetch = 10;
463 params.interactive_request = true; 491 params.interactive_request = true;
464 params.ui_language.frequency = 0.0f; 492 params.ui_language.frequency = 0.0f;
465 params.other_top_language.language_code = "de"; 493 params.other_top_language.language_code = "de";
466 params.other_top_language.frequency = 0.5f; 494 params.other_top_language.frequency = 0.5f;
467 495
468 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 496 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
469 EXPECT_THAT(params.BuildRequest(), 497 EXPECT_THAT(params.BuildRequest(),
470 EqualsJSON("{" 498 EqualsJSON("{"
471 " \"regularlyVisitedHostNames\": []," 499 " \"regularlyVisitedHostNames\": [],"
472 " \"priority\": \"USER_ACTION\"," 500 " \"priority\": \"USER_ACTION\","
473 " \"excludedSuggestionIds\": []," 501 " \"excludedSuggestionIds\": [],"
474 " \"top_languages\": [{" 502 " \"topLanguages\": [{"
475 " \"language\" : \"de\"," 503 " \"language\" : \"de\","
476 " \"frequency\" : 0.5" 504 " \"frequency\" : 0.5"
477 " }]" 505 " }]"
478 "}")); 506 "}"));
479 } 507 }
480 508
481 TEST_F(NTPSnippetsFetcherTest, ShouldNotFetchOnCreation) { 509 TEST_F(NTPSnippetsFetcherTest, ShouldNotFetchOnCreation) {
482 // The lack of registered baked in responses would cause any fetch to fail. 510 // The lack of registered baked in responses would cause any fetch to fail.
483 FastForwardUntilNoTasksRemain(); 511 FastForwardUntilNoTasksRemain();
484 EXPECT_THAT(histogram_tester().GetAllSamples( 512 EXPECT_THAT(histogram_tester().GetAllSamples(
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 const NTPSnippetsFetcher::OptionalFetchedCategories& fetched_categories) { 882 const NTPSnippetsFetcher::OptionalFetchedCategories& fetched_categories) {
855 if (fetched_categories) { 883 if (fetched_categories) {
856 // Matchers above aren't any more precise than this, so this is sufficient 884 // Matchers above aren't any more precise than this, so this is sufficient
857 // for test-failure diagnostics. 885 // for test-failure diagnostics.
858 return os << "list with " << fetched_categories->size() << " elements"; 886 return os << "list with " << fetched_categories->size() << " elements";
859 } 887 }
860 return os << "null"; 888 return os << "null";
861 } 889 }
862 890
863 } // namespace ntp_snippets 891 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698