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

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

Issue 2271283002: Add request type to FetchSuggestionsRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 3 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
« no previous file with comments | « components/ntp_snippets/ntp_snippets_fetcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ntp_snippets_fetcher.h" 5 #include "components/ntp_snippets/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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 GURL GetFetcherUrl(const char* url_format) { 141 GURL GetFetcherUrl(const char* url_format) {
142 return GURL(base::StringPrintf(url_format, google_apis::GetAPIKey().c_str())); 142 return GURL(base::StringPrintf(url_format, google_apis::GetAPIKey().c_str()));
143 } 143 }
144 144
145 } // namespace 145 } // namespace
146 146
147 class NTPSnippetsFetcherTest : public testing::Test { 147 class NTPSnippetsFetcherTest : public testing::Test {
148 public: 148 public:
149 NTPSnippetsFetcherTest() 149 NTPSnippetsFetcherTest()
150 : NTPSnippetsFetcherTest( 150 : NTPSnippetsFetcherTest(GetFetcherUrl(kTestChromeReaderUrlFormat),
151 GetFetcherUrl(kTestChromeReaderUrlFormat), 151 std::map<std::string, std::string>()) {}
152 std::map<std::string, std::string>()) {}
153 152
154 NTPSnippetsFetcherTest(const GURL& gurl, 153 NTPSnippetsFetcherTest(const GURL& gurl,
155 const std::map<std::string, std::string>& params) 154 const std::map<std::string, std::string>& params)
156 : params_manager_(ntp_snippets::kStudyName, params), 155 : params_manager_(ntp_snippets::kStudyName, params),
157 mock_task_runner_(new base::TestMockTimeTaskRunner()), 156 mock_task_runner_(new base::TestMockTimeTaskRunner()),
158 mock_task_runner_handle_(mock_task_runner_), 157 mock_task_runner_handle_(mock_task_runner_),
159 signin_client_(new TestSigninClient(nullptr)), 158 signin_client_(new TestSigninClient(nullptr)),
160 account_tracker_(new AccountTrackerService()), 159 account_tracker_(new AccountTrackerService()),
161 fake_signin_manager_(new FakeSigninManagerBase(signin_client_.get(), 160 fake_signin_manager_(new FakeSigninManagerBase(signin_client_.get(),
162 account_tracker_.get())), 161 account_tracker_.get())),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 public: 239 public:
241 NTPSnippetsContentSuggestionsFetcherTest() 240 NTPSnippetsContentSuggestionsFetcherTest()
242 : NTPSnippetsFetcherTest( 241 : NTPSnippetsFetcherTest(
243 GetFetcherUrl(kTestChromeContentSuggestionsUrlFormat), 242 GetFetcherUrl(kTestChromeContentSuggestionsUrlFormat),
244 {{"content_suggestions_backend", kContentSuggestionsServer}}) {} 243 {{"content_suggestions_backend", kContentSuggestionsServer}}) {}
245 }; 244 };
246 245
247 class NTPSnippetsFetcherHostRestrictedTest : public NTPSnippetsFetcherTest { 246 class NTPSnippetsFetcherHostRestrictedTest : public NTPSnippetsFetcherTest {
248 public: 247 public:
249 NTPSnippetsFetcherHostRestrictedTest() 248 NTPSnippetsFetcherHostRestrictedTest()
250 : NTPSnippetsFetcherTest( 249 : NTPSnippetsFetcherTest(GetFetcherUrl(kTestChromeReaderUrlFormat),
251 GetFetcherUrl(kTestChromeReaderUrlFormat), 250 {{"fetching_host_restrict", "on"}}) {}
252 {{"fetching_host_restrict", "on"}}) {}
253 }; 251 };
254 252
255 TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) { 253 TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) {
256 NTPSnippetsFetcher::RequestParams params; 254 NTPSnippetsFetcher::RequestParams params;
257 params.obfuscated_gaia_id = "0BFUSGAIA"; 255 params.obfuscated_gaia_id = "0BFUSGAIA";
258 params.only_return_personalized_results = true; 256 params.only_return_personalized_results = true;
259 params.user_locale = "en"; 257 params.user_locale = "en";
260 params.host_restricts = {"chromium.org"}; 258 params.host_restricts = {"chromium.org"};
261 params.excluded_ids = {"1234567890"}; 259 params.excluded_ids = {"1234567890"};
262 params.count_to_fetch = 25; 260 params.count_to_fetch = 25;
261 params.interactive_request = false;
263 262
264 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API; 263 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API;
265 EXPECT_THAT(params.BuildRequest(), 264 EXPECT_THAT(params.BuildRequest(),
266 EqualsJSON("{" 265 EqualsJSON("{"
267 " \"response_detail_level\": \"STANDARD\"," 266 " \"response_detail_level\": \"STANDARD\","
268 " \"obfuscated_gaia_id\": \"0BFUSGAIA\"," 267 " \"obfuscated_gaia_id\": \"0BFUSGAIA\","
269 " \"user_locale\": \"en\"," 268 " \"user_locale\": \"en\","
270 " \"advanced_options\": {" 269 " \"advanced_options\": {"
271 " \"local_scoring_params\": {" 270 " \"local_scoring_params\": {"
272 " \"content_params\": {" 271 " \"content_params\": {"
(...skipping 24 matching lines...) Expand all
297 " \"num_to_return\": 25," 296 " \"num_to_return\": 25,"
298 " \"sort_type\": 1" 297 " \"sort_type\": 1"
299 " }" 298 " }"
300 " }" 299 " }"
301 "}")); 300 "}"));
302 301
303 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 302 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
304 EXPECT_THAT(params.BuildRequest(), 303 EXPECT_THAT(params.BuildRequest(),
305 EqualsJSON("{" 304 EqualsJSON("{"
306 " \"uiLanguage\": \"en\"," 305 " \"uiLanguage\": \"en\","
306 " \"priority\": \"BACKGROUND_PREFETCH\","
307 " \"regularlyVisitedHostNames\": [" 307 " \"regularlyVisitedHostNames\": ["
308 " \"chromium.org\"" 308 " \"chromium.org\""
309 " ]," 309 " ],"
310 " \"excludedSuggestionIds\": [" 310 " \"excludedSuggestionIds\": ["
311 " \"1234567890\"" 311 " \"1234567890\""
312 " ]" 312 " ]"
313 "}")); 313 "}"));
314 } 314 }
315 315
316 TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) { 316 TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) {
317 NTPSnippetsFetcher::RequestParams params; 317 NTPSnippetsFetcher::RequestParams params;
318 params.only_return_personalized_results = false; 318 params.only_return_personalized_results = false;
319 params.host_restricts = {}; 319 params.host_restricts = {};
320 params.count_to_fetch = 10; 320 params.count_to_fetch = 10;
321 params.excluded_ids = {}; 321 params.excluded_ids = {};
322 params.interactive_request = true;
323
322 324
323 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API; 325 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API;
324 EXPECT_THAT(params.BuildRequest(), 326 EXPECT_THAT(params.BuildRequest(),
325 EqualsJSON("{" 327 EqualsJSON("{"
326 " \"response_detail_level\": \"STANDARD\"," 328 " \"response_detail_level\": \"STANDARD\","
327 " \"advanced_options\": {" 329 " \"advanced_options\": {"
328 " \"local_scoring_params\": {" 330 " \"local_scoring_params\": {"
329 " \"content_params\": {" 331 " \"content_params\": {"
330 " \"only_return_personalized_results\": false" 332 " \"only_return_personalized_results\": false"
331 " }," 333 " },"
(...skipping 17 matching lines...) Expand all
349 " \"num_to_return\": 10," 351 " \"num_to_return\": 10,"
350 " \"sort_type\": 1" 352 " \"sort_type\": 1"
351 " }" 353 " }"
352 " }" 354 " }"
353 "}")); 355 "}"));
354 356
355 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 357 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
356 EXPECT_THAT(params.BuildRequest(), 358 EXPECT_THAT(params.BuildRequest(),
357 EqualsJSON("{" 359 EqualsJSON("{"
358 " \"regularlyVisitedHostNames\": []," 360 " \"regularlyVisitedHostNames\": [],"
361 " \"priority\": \"USER_ACTION\","
359 " \"excludedSuggestionIds\": []" 362 " \"excludedSuggestionIds\": []"
360 "}")); 363 "}"));
361 } 364 }
362 365
363 TEST_F(NTPSnippetsFetcherTest, BuildRequestExcludedIds) { 366 TEST_F(NTPSnippetsFetcherTest, BuildRequestExcludedIds) {
364 NTPSnippetsFetcher::RequestParams params; 367 NTPSnippetsFetcher::RequestParams params;
365 params.only_return_personalized_results = false; 368 params.only_return_personalized_results = false;
366 params.host_restricts = {}; 369 params.host_restricts = {};
367 params.count_to_fetch = 10; 370 params.count_to_fetch = 10;
371 params.interactive_request = false;
368 for (int i = 0; i < 200; ++i) { 372 for (int i = 0; i < 200; ++i) {
369 params.excluded_ids.insert(base::StringPrintf("%03d", i)); 373 params.excluded_ids.insert(base::StringPrintf("%03d", i));
370 } 374 }
371 375
372 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 376 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
373 EXPECT_THAT(params.BuildRequest(), 377 EXPECT_THAT(params.BuildRequest(),
374 EqualsJSON("{" 378 EqualsJSON("{"
375 " \"regularlyVisitedHostNames\": []," 379 " \"regularlyVisitedHostNames\": [],"
380 " \"priority\": \"BACKGROUND_PREFETCH\","
376 " \"excludedSuggestionIds\": [" 381 " \"excludedSuggestionIds\": ["
377 " \"000\", \"001\", \"002\", \"003\", \"004\"," 382 " \"000\", \"001\", \"002\", \"003\", \"004\","
378 " \"005\", \"006\", \"007\", \"008\", \"009\"," 383 " \"005\", \"006\", \"007\", \"008\", \"009\","
379 " \"010\", \"011\", \"012\", \"013\", \"014\"," 384 " \"010\", \"011\", \"012\", \"013\", \"014\","
380 " \"015\", \"016\", \"017\", \"018\", \"019\"," 385 " \"015\", \"016\", \"017\", \"018\", \"019\","
381 " \"020\", \"021\", \"022\", \"023\", \"024\"," 386 " \"020\", \"021\", \"022\", \"023\", \"024\","
382 " \"025\", \"026\", \"027\", \"028\", \"029\"," 387 " \"025\", \"026\", \"027\", \"028\", \"029\","
383 " \"030\", \"031\", \"032\", \"033\", \"034\"," 388 " \"030\", \"031\", \"032\", \"033\", \"034\","
384 " \"035\", \"036\", \"037\", \"038\", \"039\"," 389 " \"035\", \"036\", \"037\", \"038\", \"039\","
385 " \"040\", \"041\", \"042\", \"043\", \"044\"," 390 " \"040\", \"041\", \"042\", \"043\", \"044\","
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 if (snippets) { 805 if (snippets) {
801 // Matchers above aren't any more precise than this, so this is sufficient 806 // Matchers above aren't any more precise than this, so this is sufficient
802 // for test-failure diagnostics. 807 // for test-failure diagnostics.
803 return os << "list with " << snippets->size() << " elements"; 808 return os << "list with " << snippets->size() << " elements";
804 } else { 809 } else {
805 return os << "null"; 810 return os << "null";
806 } 811 }
807 } 812 }
808 813
809 } // namespace ntp_snippets 814 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippets_fetcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698