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

Side by Side Diff: components/ntp_snippets/remote/json_request_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/json_request.h" 5 #include "components/ntp_snippets/remote/json_request.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 TEST_F(JsonRequestTest, BuildRequestAuthenticated) { 107 TEST_F(JsonRequestTest, BuildRequestAuthenticated) {
108 JsonRequest::Builder builder = CreateMinimalBuilder(); 108 JsonRequest::Builder builder = CreateMinimalBuilder();
109 RequestParams params; 109 RequestParams params;
110 params.excluded_ids = {"1234567890"}; 110 params.excluded_ids = {"1234567890"};
111 params.count_to_fetch = 25; 111 params.count_to_fetch = 25;
112 params.interactive_request = false; 112 params.interactive_request = false;
113 builder.SetParams(params) 113 builder.SetParams(params)
114 .SetUrl(GURL("http://valid-url.test")) 114 .SetUrl(GURL("http://valid-url.test"))
115 .SetUrl(GURL("http://valid-url.test")) 115 .SetUrl(GURL("http://valid-url.test"))
116 .SetAuthentication("0BFUSGAIA", "headerstuff") 116 .SetAuthentication("0BFUSGAIA", "headerstuff")
117 .SetPersonalization(Personalization::kPersonal)
118 .SetUserClassForTesting("ACTIVE_NTP_USER") 117 .SetUserClassForTesting("ACTIVE_NTP_USER")
119 .SetFetchAPI(FetchAPI::CHROME_READER_API) 118 .SetFetchAPI(FetchAPI::CHROME_READER_API)
120 .Build(); 119 .Build();
121 120
122 EXPECT_THAT(builder.PreviewRequestHeadersForTesting(), 121 EXPECT_THAT(builder.PreviewRequestHeadersForTesting(),
123 StrEq("Content-Type: application/json; charset=UTF-8\r\n" 122 StrEq("Content-Type: application/json; charset=UTF-8\r\n"
124 "Authorization: headerstuff\r\n" 123 "Authorization: headerstuff\r\n"
125 "\r\n")); 124 "\r\n"));
126 EXPECT_THAT(builder.PreviewRequestBodyForTesting(), 125 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
127 EqualsJSON("{" 126 EqualsJSON("{"
128 " \"response_detail_level\": \"STANDARD\"," 127 " \"response_detail_level\": \"STANDARD\","
129 " \"obfuscated_gaia_id\": \"0BFUSGAIA\"," 128 " \"obfuscated_gaia_id\": \"0BFUSGAIA\","
130 " \"advanced_options\": {" 129 " \"advanced_options\": {"
131 " \"local_scoring_params\": {" 130 " \"local_scoring_params\": {"
132 " \"content_params\": {"
133 " \"only_return_personalized_results\": true"
134 " },"
135 " \"content_restricts\": [" 131 " \"content_restricts\": ["
136 " {" 132 " {"
137 " \"type\": \"METADATA\"," 133 " \"type\": \"METADATA\","
138 " \"value\": \"TITLE\"" 134 " \"value\": \"TITLE\""
139 " }," 135 " },"
140 " {" 136 " {"
141 " \"type\": \"METADATA\"," 137 " \"type\": \"METADATA\","
142 " \"value\": \"SNIPPET\"" 138 " \"value\": \"SNIPPET\""
143 " }," 139 " },"
144 " {" 140 " {"
(...skipping 21 matching lines...) Expand all
166 "}")); 162 "}"));
167 } 163 }
168 164
169 TEST_F(JsonRequestTest, BuildRequestUnauthenticated) { 165 TEST_F(JsonRequestTest, BuildRequestUnauthenticated) {
170 JsonRequest::Builder builder; 166 JsonRequest::Builder builder;
171 RequestParams params; 167 RequestParams params;
172 params.interactive_request = true; 168 params.interactive_request = true;
173 params.count_to_fetch = 10; 169 params.count_to_fetch = 10;
174 builder.SetParams(params) 170 builder.SetParams(params)
175 .SetUserClassForTesting("ACTIVE_NTP_USER") 171 .SetUserClassForTesting("ACTIVE_NTP_USER")
176 .SetPersonalization(Personalization::kNonPersonal)
177 .SetFetchAPI(FetchAPI::CHROME_READER_API); 172 .SetFetchAPI(FetchAPI::CHROME_READER_API);
178 173
179 EXPECT_THAT(builder.PreviewRequestHeadersForTesting(), 174 EXPECT_THAT(builder.PreviewRequestHeadersForTesting(),
180 StrEq("Content-Type: application/json; charset=UTF-8\r\n" 175 StrEq("Content-Type: application/json; charset=UTF-8\r\n"
181 "\r\n")); 176 "\r\n"));
182 EXPECT_THAT(builder.PreviewRequestBodyForTesting(), 177 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
183 EqualsJSON("{" 178 EqualsJSON("{"
184 " \"response_detail_level\": \"STANDARD\"," 179 " \"response_detail_level\": \"STANDARD\","
185 " \"advanced_options\": {" 180 " \"advanced_options\": {"
186 " \"local_scoring_params\": {" 181 " \"local_scoring_params\": {"
187 " \"content_params\": {"
188 " \"only_return_personalized_results\": false"
189 " },"
190 " \"content_restricts\": [" 182 " \"content_restricts\": ["
191 " {" 183 " {"
192 " \"type\": \"METADATA\"," 184 " \"type\": \"METADATA\","
193 " \"value\": \"TITLE\"" 185 " \"value\": \"TITLE\""
194 " }," 186 " },"
195 " {" 187 " {"
196 " \"type\": \"METADATA\"," 188 " \"type\": \"METADATA\","
197 " \"value\": \"SNIPPET\"" 189 " \"value\": \"SNIPPET\""
198 " }," 190 " },"
199 " {" 191 " {"
(...skipping 20 matching lines...) Expand all
220 212
221 TEST_F(JsonRequestTest, BuildRequestExcludedIds) { 213 TEST_F(JsonRequestTest, BuildRequestExcludedIds) {
222 JsonRequest::Builder builder; 214 JsonRequest::Builder builder;
223 RequestParams params; 215 RequestParams params;
224 params.interactive_request = false; 216 params.interactive_request = false;
225 for (int i = 0; i < 200; ++i) { 217 for (int i = 0; i < 200; ++i) {
226 params.excluded_ids.insert(base::StringPrintf("%03d", i)); 218 params.excluded_ids.insert(base::StringPrintf("%03d", i));
227 } 219 }
228 builder.SetParams(params) 220 builder.SetParams(params)
229 .SetUserClassForTesting("ACTIVE_NTP_USER") 221 .SetUserClassForTesting("ACTIVE_NTP_USER")
230 .SetPersonalization(Personalization::kNonPersonal)
231 .SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API); 222 .SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API);
232 223
233 EXPECT_THAT(builder.PreviewRequestBodyForTesting(), 224 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
234 EqualsJSON("{" 225 EqualsJSON("{"
235 " \"priority\": \"BACKGROUND_PREFETCH\"," 226 " \"priority\": \"BACKGROUND_PREFETCH\","
236 " \"excludedSuggestionIds\": [" 227 " \"excludedSuggestionIds\": ["
237 " \"000\", \"001\", \"002\", \"003\", \"004\"," 228 " \"000\", \"001\", \"002\", \"003\", \"004\","
238 " \"005\", \"006\", \"007\", \"008\", \"009\"," 229 " \"005\", \"006\", \"007\", \"008\", \"009\","
239 " \"010\", \"011\", \"012\", \"013\", \"014\"," 230 " \"010\", \"011\", \"012\", \"013\", \"014\","
240 " \"015\", \"016\", \"017\", \"018\", \"019\"," 231 " \"015\", \"016\", \"017\", \"018\", \"019\","
(...skipping 17 matching lines...) Expand all
258 // be those lexically first. 249 // be those lexically first.
259 " ]," 250 " ],"
260 " \"userActivenessClass\": \"ACTIVE_NTP_USER\"" 251 " \"userActivenessClass\": \"ACTIVE_NTP_USER\""
261 "}")); 252 "}"));
262 } 253 }
263 254
264 TEST_F(JsonRequestTest, BuildRequestNoUserClass) { 255 TEST_F(JsonRequestTest, BuildRequestNoUserClass) {
265 JsonRequest::Builder builder; 256 JsonRequest::Builder builder;
266 RequestParams params; 257 RequestParams params;
267 params.interactive_request = false; 258 params.interactive_request = false;
268 builder.SetPersonalization(Personalization::kNonPersonal) 259 builder.SetParams(params)
269 .SetParams(params)
270 .SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API); 260 .SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API);
271 261
272 EXPECT_THAT(builder.PreviewRequestBodyForTesting(), 262 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
273 EqualsJSON("{" 263 EqualsJSON("{"
274 " \"priority\": \"BACKGROUND_PREFETCH\"," 264 " \"priority\": \"BACKGROUND_PREFETCH\","
275 " \"excludedSuggestionIds\": []" 265 " \"excludedSuggestionIds\": []"
276 "}")); 266 "}"));
277 } 267 }
278 268
279 TEST_F(JsonRequestTest, BuildRequestWithTwoLanguages) { 269 TEST_F(JsonRequestTest, BuildRequestWithTwoLanguages) {
280 JsonRequest::Builder builder; 270 JsonRequest::Builder builder;
281 std::unique_ptr<translate::LanguageModel> language_model = 271 std::unique_ptr<translate::LanguageModel> language_model =
282 MakeLanguageModel({"de", "en"}); 272 MakeLanguageModel({"de", "en"});
283 RequestParams params; 273 RequestParams params;
284 params.interactive_request = true; 274 params.interactive_request = true;
285 params.language_code = "en"; 275 params.language_code = "en";
286 builder.SetParams(params) 276 builder.SetParams(params)
287 .SetLanguageModel(language_model.get()) 277 .SetLanguageModel(language_model.get())
288 .SetPersonalization(Personalization::kNonPersonal)
289 .SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API); 278 .SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API);
290 279
291 EXPECT_THAT(builder.PreviewRequestBodyForTesting(), 280 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
292 EqualsJSON("{" 281 EqualsJSON("{"
293 " \"priority\": \"USER_ACTION\"," 282 " \"priority\": \"USER_ACTION\","
294 " \"uiLanguage\": \"en\"," 283 " \"uiLanguage\": \"en\","
295 " \"excludedSuggestionIds\": []," 284 " \"excludedSuggestionIds\": [],"
296 " \"topLanguages\": [" 285 " \"topLanguages\": ["
297 " {" 286 " {"
298 " \"language\" : \"en\"," 287 " \"language\" : \"en\","
299 " \"frequency\" : 0.5" 288 " \"frequency\" : 0.5"
300 " }," 289 " },"
301 " {" 290 " {"
302 " \"language\" : \"de\"," 291 " \"language\" : \"de\","
303 " \"frequency\" : 0.5" 292 " \"frequency\" : 0.5"
304 " }" 293 " }"
305 " ]" 294 " ]"
306 "}")); 295 "}"));
307 } 296 }
308 297
309 TEST_F(JsonRequestTest, BuildRequestWithUILanguageOnly) { 298 TEST_F(JsonRequestTest, BuildRequestWithUILanguageOnly) {
310 JsonRequest::Builder builder; 299 JsonRequest::Builder builder;
311 std::unique_ptr<translate::LanguageModel> language_model = 300 std::unique_ptr<translate::LanguageModel> language_model =
312 MakeLanguageModel({"en"}); 301 MakeLanguageModel({"en"});
313 RequestParams params; 302 RequestParams params;
314 params.interactive_request = true; 303 params.interactive_request = true;
315 params.language_code = "en"; 304 params.language_code = "en";
316 builder.SetParams(params) 305 builder.SetParams(params)
317 .SetLanguageModel(language_model.get()) 306 .SetLanguageModel(language_model.get())
318 .SetPersonalization(Personalization::kNonPersonal)
319 .SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API); 307 .SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API);
320 308
321 EXPECT_THAT(builder.PreviewRequestBodyForTesting(), 309 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
322 EqualsJSON("{" 310 EqualsJSON("{"
323 " \"priority\": \"USER_ACTION\"," 311 " \"priority\": \"USER_ACTION\","
324 " \"uiLanguage\": \"en\"," 312 " \"uiLanguage\": \"en\","
325 " \"excludedSuggestionIds\": []," 313 " \"excludedSuggestionIds\": [],"
326 " \"topLanguages\": [{" 314 " \"topLanguages\": [{"
327 " \"language\" : \"en\"," 315 " \"language\" : \"en\","
328 " \"frequency\" : 1.0" 316 " \"frequency\" : 1.0"
329 " }]" 317 " }]"
330 "}")); 318 "}"));
331 } 319 }
332 320
333 } // namespace internal 321 } // namespace internal
334 322
335 } // namespace ntp_snippets 323 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/remote/json_request.cc ('k') | components/ntp_snippets/remote/remote_suggestions_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698