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

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: Addressed comments. 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
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 public: 236 public:
238 NTPSnippetsContentSuggestionsFetcherTest() 237 NTPSnippetsContentSuggestionsFetcherTest()
239 : NTPSnippetsFetcherTest( 238 : NTPSnippetsFetcherTest(
240 GetFetcherUrl(kTestChromeContentSuggestionsUrlFormat), 239 GetFetcherUrl(kTestChromeContentSuggestionsUrlFormat),
241 {{"content_suggestions_backend", kContentSuggestionsServer}}) {} 240 {{"content_suggestions_backend", kContentSuggestionsServer}}) {}
242 }; 241 };
243 242
244 class NTPSnippetsFetcherHostRestrictedTest : public NTPSnippetsFetcherTest { 243 class NTPSnippetsFetcherHostRestrictedTest : public NTPSnippetsFetcherTest {
245 public: 244 public:
246 NTPSnippetsFetcherHostRestrictedTest() 245 NTPSnippetsFetcherHostRestrictedTest()
247 : NTPSnippetsFetcherTest( 246 : NTPSnippetsFetcherTest(GetFetcherUrl(kTestChromeReaderUrlFormat),
248 GetFetcherUrl(kTestChromeReaderUrlFormat), 247 {{"fetching_host_restrict", "on"}}) {}
249 {{"fetching_host_restrict", "on"}}) {}
250 }; 248 };
251 249
252 TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) { 250 TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) {
253 NTPSnippetsFetcher::RequestParams params; 251 NTPSnippetsFetcher::RequestParams params;
254 params.obfuscated_gaia_id = "0BFUSGAIA"; 252 params.obfuscated_gaia_id = "0BFUSGAIA";
255 params.only_return_personalized_results = true; 253 params.only_return_personalized_results = true;
256 params.user_locale = "en"; 254 params.user_locale = "en";
257 params.host_restricts = {"chromium.org"}; 255 params.host_restricts = {"chromium.org"};
258 params.count_to_fetch = 25; 256 params.count_to_fetch = 25;
257 params.interactive_request = false;
259 258
260 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API; 259 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API;
261 EXPECT_THAT(params.BuildRequest(), 260 EXPECT_THAT(params.BuildRequest(),
262 EqualsJSON("{" 261 EqualsJSON("{"
263 " \"response_detail_level\": \"STANDARD\"," 262 " \"response_detail_level\": \"STANDARD\","
264 " \"obfuscated_gaia_id\": \"0BFUSGAIA\"," 263 " \"obfuscated_gaia_id\": \"0BFUSGAIA\","
265 " \"user_locale\": \"en\"," 264 " \"user_locale\": \"en\","
266 " \"advanced_options\": {" 265 " \"advanced_options\": {"
267 " \"local_scoring_params\": {" 266 " \"local_scoring_params\": {"
268 " \"content_params\": {" 267 " \"content_params\": {"
(...skipping 24 matching lines...) Expand all
293 " \"num_to_return\": 25," 292 " \"num_to_return\": 25,"
294 " \"sort_type\": 1" 293 " \"sort_type\": 1"
295 " }" 294 " }"
296 " }" 295 " }"
297 "}")); 296 "}"));
298 297
299 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 298 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
300 EXPECT_THAT(params.BuildRequest(), 299 EXPECT_THAT(params.BuildRequest(),
301 EqualsJSON("{" 300 EqualsJSON("{"
302 " \"uiLanguage\": \"en\"," 301 " \"uiLanguage\": \"en\","
302 " \"type\": \"BACKGROUND\","
303 " \"regularlyVisitedHostNames\": [" 303 " \"regularlyVisitedHostNames\": ["
304 " \"chromium.org\"" 304 " \"chromium.org\""
305 " ]" 305 " ]"
306 "}")); 306 "}"));
307 } 307 }
308 308
309 TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) { 309 TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) {
310 NTPSnippetsFetcher::RequestParams params; 310 NTPSnippetsFetcher::RequestParams params;
311 params.only_return_personalized_results = false; 311 params.only_return_personalized_results = false;
312 params.host_restricts = {}; 312 params.host_restricts = {};
313 params.count_to_fetch = 10; 313 params.count_to_fetch = 10;
314 params.interactive_request = true;
314 315
315 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API; 316 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API;
316 EXPECT_THAT(params.BuildRequest(), 317 EXPECT_THAT(params.BuildRequest(),
317 EqualsJSON("{" 318 EqualsJSON("{"
318 " \"response_detail_level\": \"STANDARD\"," 319 " \"response_detail_level\": \"STANDARD\","
319 " \"advanced_options\": {" 320 " \"advanced_options\": {"
320 " \"local_scoring_params\": {" 321 " \"local_scoring_params\": {"
321 " \"content_params\": {" 322 " \"content_params\": {"
322 " \"only_return_personalized_results\": false" 323 " \"only_return_personalized_results\": false"
323 " }," 324 " },"
(...skipping 16 matching lines...) Expand all
340 " \"global_scoring_params\": {" 341 " \"global_scoring_params\": {"
341 " \"num_to_return\": 10," 342 " \"num_to_return\": 10,"
342 " \"sort_type\": 1" 343 " \"sort_type\": 1"
343 " }" 344 " }"
344 " }" 345 " }"
345 "}")); 346 "}"));
346 347
347 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 348 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
348 EXPECT_THAT(params.BuildRequest(), 349 EXPECT_THAT(params.BuildRequest(),
349 EqualsJSON("{" 350 EqualsJSON("{"
350 " \"regularlyVisitedHostNames\": []" 351 " \"regularlyVisitedHostNames\": [],"
352 " \"type\": \"INTERACTIVE\""
351 "}")); 353 "}"));
352 } 354 }
353 355
354 TEST_F(NTPSnippetsFetcherTest, ShouldNotFetchOnCreation) { 356 TEST_F(NTPSnippetsFetcherTest, ShouldNotFetchOnCreation) {
355 // The lack of registered baked in responses would cause any fetch to fail. 357 // The lack of registered baked in responses would cause any fetch to fail.
356 FastForwardUntilNoTasksRemain(); 358 FastForwardUntilNoTasksRemain();
357 EXPECT_THAT(histogram_tester().GetAllSamples( 359 EXPECT_THAT(histogram_tester().GetAllSamples(
358 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 360 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
359 IsEmpty()); 361 IsEmpty());
360 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), 362 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 if (snippets) { 715 if (snippets) {
714 // Matchers above aren't any more precise than this, so this is sufficient 716 // Matchers above aren't any more precise than this, so this is sufficient
715 // for test-failure diagnostics. 717 // for test-failure diagnostics.
716 return os << "list with " << snippets->size() << " elements"; 718 return os << "list with " << snippets->size() << " elements";
717 } else { 719 } else {
718 return os << "null"; 720 return os << "null";
719 } 721 }
720 } 722 }
721 723
722 } // namespace ntp_snippets 724 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698