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

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

Issue 2771813002: RemoteSuggestionsFetcher: Remove ChromeReader integration (Closed)
Patch Set: Created 3 years, 9 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 }; 105 };
106 106
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"))
116 .SetAuthentication("0BFUSGAIA", "headerstuff") 115 .SetAuthentication("0BFUSGAIA", "headerstuff")
117 .SetUserClassForTesting("ACTIVE_NTP_USER") 116 .SetUserClassForTesting("ACTIVE_NTP_USER")
118 .SetFetchAPI(FetchAPI::CHROME_READER_API)
119 .Build(); 117 .Build();
120 118
121 EXPECT_THAT(builder.PreviewRequestHeadersForTesting(), 119 EXPECT_THAT(builder.PreviewRequestHeadersForTesting(),
122 StrEq("Content-Type: application/json; charset=UTF-8\r\n" 120 StrEq("Content-Type: application/json; charset=UTF-8\r\n"
123 "Authorization: headerstuff\r\n" 121 "Authorization: headerstuff\r\n"
124 "\r\n")); 122 "\r\n"));
125 EXPECT_THAT(builder.PreviewRequestBodyForTesting(), 123 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
126 EqualsJSON("{" 124 EqualsJSON("{"
127 " \"response_detail_level\": \"STANDARD\","
128 " \"obfuscated_gaia_id\": \"0BFUSGAIA\","
129 " \"advanced_options\": {"
130 " \"local_scoring_params\": {"
131 " \"content_restricts\": ["
132 " {"
133 " \"type\": \"METADATA\","
134 " \"value\": \"TITLE\""
135 " },"
136 " {"
137 " \"type\": \"METADATA\","
138 " \"value\": \"SNIPPET\""
139 " },"
140 " {"
141 " \"type\": \"METADATA\","
142 " \"value\": \"THUMBNAIL\""
143 " }"
144 " ]"
145 " },"
146 " \"global_scoring_params\": {"
147 " \"num_to_return\": 25,"
148 " \"sort_type\": 1"
149 " }"
150 " }"
151 "}"));
152
153 builder.SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API);
154
155 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
156 EqualsJSON("{"
157 " \"priority\": \"BACKGROUND_PREFETCH\"," 125 " \"priority\": \"BACKGROUND_PREFETCH\","
158 " \"excludedSuggestionIds\": [" 126 " \"excludedSuggestionIds\": ["
159 " \"1234567890\"" 127 " \"1234567890\""
160 " ]," 128 " ],"
161 " \"userActivenessClass\": \"ACTIVE_NTP_USER\"" 129 " \"userActivenessClass\": \"ACTIVE_NTP_USER\""
162 "}")); 130 "}"));
163 } 131 }
164 132
165 TEST_F(JsonRequestTest, BuildRequestUnauthenticated) { 133 TEST_F(JsonRequestTest, BuildRequestUnauthenticated) {
166 JsonRequest::Builder builder; 134 JsonRequest::Builder builder;
167 RequestParams params; 135 RequestParams params;
168 params.interactive_request = true; 136 params.interactive_request = true;
169 params.count_to_fetch = 10; 137 params.count_to_fetch = 10;
170 builder.SetParams(params) 138 builder.SetParams(params).SetUserClassForTesting("ACTIVE_NTP_USER");
171 .SetUserClassForTesting("ACTIVE_NTP_USER")
172 .SetFetchAPI(FetchAPI::CHROME_READER_API);
173 139
174 EXPECT_THAT(builder.PreviewRequestHeadersForTesting(), 140 EXPECT_THAT(builder.PreviewRequestHeadersForTesting(),
175 StrEq("Content-Type: application/json; charset=UTF-8\r\n" 141 StrEq("Content-Type: application/json; charset=UTF-8\r\n"
176 "\r\n")); 142 "\r\n"));
177 EXPECT_THAT(builder.PreviewRequestBodyForTesting(), 143 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
178 EqualsJSON("{" 144 EqualsJSON("{"
179 " \"response_detail_level\": \"STANDARD\","
180 " \"advanced_options\": {"
181 " \"local_scoring_params\": {"
182 " \"content_restricts\": ["
183 " {"
184 " \"type\": \"METADATA\","
185 " \"value\": \"TITLE\""
186 " },"
187 " {"
188 " \"type\": \"METADATA\","
189 " \"value\": \"SNIPPET\""
190 " },"
191 " {"
192 " \"type\": \"METADATA\","
193 " \"value\": \"THUMBNAIL\""
194 " }"
195 " ]"
196 " },"
197 " \"global_scoring_params\": {"
198 " \"num_to_return\": 10,"
199 " \"sort_type\": 1"
200 " }"
201 " }"
202 "}"));
203
204 builder.SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API);
205 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
206 EqualsJSON("{"
207 " \"priority\": \"USER_ACTION\"," 145 " \"priority\": \"USER_ACTION\","
208 " \"excludedSuggestionIds\": []," 146 " \"excludedSuggestionIds\": [],"
209 " \"userActivenessClass\": \"ACTIVE_NTP_USER\"" 147 " \"userActivenessClass\": \"ACTIVE_NTP_USER\""
210 "}")); 148 "}"));
211 } 149 }
212 150
213 TEST_F(JsonRequestTest, BuildRequestExcludedIds) { 151 TEST_F(JsonRequestTest, BuildRequestExcludedIds) {
214 JsonRequest::Builder builder; 152 JsonRequest::Builder builder;
215 RequestParams params; 153 RequestParams params;
216 params.interactive_request = false; 154 params.interactive_request = false;
217 for (int i = 0; i < 200; ++i) { 155 for (int i = 0; i < 200; ++i) {
218 params.excluded_ids.insert(base::StringPrintf("%03d", i)); 156 params.excluded_ids.insert(base::StringPrintf("%03d", i));
219 } 157 }
220 builder.SetParams(params) 158 builder.SetParams(params).SetUserClassForTesting("ACTIVE_NTP_USER");
221 .SetUserClassForTesting("ACTIVE_NTP_USER")
222 .SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API);
223 159
224 EXPECT_THAT(builder.PreviewRequestBodyForTesting(), 160 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
225 EqualsJSON("{" 161 EqualsJSON("{"
226 " \"priority\": \"BACKGROUND_PREFETCH\"," 162 " \"priority\": \"BACKGROUND_PREFETCH\","
227 " \"excludedSuggestionIds\": [" 163 " \"excludedSuggestionIds\": ["
228 " \"000\", \"001\", \"002\", \"003\", \"004\"," 164 " \"000\", \"001\", \"002\", \"003\", \"004\","
229 " \"005\", \"006\", \"007\", \"008\", \"009\"," 165 " \"005\", \"006\", \"007\", \"008\", \"009\","
230 " \"010\", \"011\", \"012\", \"013\", \"014\"," 166 " \"010\", \"011\", \"012\", \"013\", \"014\","
231 " \"015\", \"016\", \"017\", \"018\", \"019\"," 167 " \"015\", \"016\", \"017\", \"018\", \"019\","
232 " \"020\", \"021\", \"022\", \"023\", \"024\"," 168 " \"020\", \"021\", \"022\", \"023\", \"024\","
(...skipping 16 matching lines...) Expand all
249 // be those lexically first. 185 // be those lexically first.
250 " ]," 186 " ],"
251 " \"userActivenessClass\": \"ACTIVE_NTP_USER\"" 187 " \"userActivenessClass\": \"ACTIVE_NTP_USER\""
252 "}")); 188 "}"));
253 } 189 }
254 190
255 TEST_F(JsonRequestTest, BuildRequestNoUserClass) { 191 TEST_F(JsonRequestTest, BuildRequestNoUserClass) {
256 JsonRequest::Builder builder; 192 JsonRequest::Builder builder;
257 RequestParams params; 193 RequestParams params;
258 params.interactive_request = false; 194 params.interactive_request = false;
259 builder.SetParams(params) 195 builder.SetParams(params);
260 .SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API);
261 196
262 EXPECT_THAT(builder.PreviewRequestBodyForTesting(), 197 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
263 EqualsJSON("{" 198 EqualsJSON("{"
264 " \"priority\": \"BACKGROUND_PREFETCH\"," 199 " \"priority\": \"BACKGROUND_PREFETCH\","
265 " \"excludedSuggestionIds\": []" 200 " \"excludedSuggestionIds\": []"
266 "}")); 201 "}"));
267 } 202 }
268 203
269 TEST_F(JsonRequestTest, BuildRequestWithTwoLanguages) { 204 TEST_F(JsonRequestTest, BuildRequestWithTwoLanguages) {
270 JsonRequest::Builder builder; 205 JsonRequest::Builder builder;
271 std::unique_ptr<translate::LanguageModel> language_model = 206 std::unique_ptr<translate::LanguageModel> language_model =
272 MakeLanguageModel({"de", "en"}); 207 MakeLanguageModel({"de", "en"});
273 RequestParams params; 208 RequestParams params;
274 params.interactive_request = true; 209 params.interactive_request = true;
275 params.language_code = "en"; 210 params.language_code = "en";
276 builder.SetParams(params) 211 builder.SetParams(params).SetLanguageModel(language_model.get());
277 .SetLanguageModel(language_model.get())
278 .SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API);
279 212
280 EXPECT_THAT(builder.PreviewRequestBodyForTesting(), 213 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
281 EqualsJSON("{" 214 EqualsJSON("{"
282 " \"priority\": \"USER_ACTION\"," 215 " \"priority\": \"USER_ACTION\","
283 " \"uiLanguage\": \"en\"," 216 " \"uiLanguage\": \"en\","
284 " \"excludedSuggestionIds\": []," 217 " \"excludedSuggestionIds\": [],"
285 " \"topLanguages\": [" 218 " \"topLanguages\": ["
286 " {" 219 " {"
287 " \"language\" : \"en\"," 220 " \"language\" : \"en\","
288 " \"frequency\" : 0.5" 221 " \"frequency\" : 0.5"
289 " }," 222 " },"
290 " {" 223 " {"
291 " \"language\" : \"de\"," 224 " \"language\" : \"de\","
292 " \"frequency\" : 0.5" 225 " \"frequency\" : 0.5"
293 " }" 226 " }"
294 " ]" 227 " ]"
295 "}")); 228 "}"));
296 } 229 }
297 230
298 TEST_F(JsonRequestTest, BuildRequestWithUILanguageOnly) { 231 TEST_F(JsonRequestTest, BuildRequestWithUILanguageOnly) {
299 JsonRequest::Builder builder; 232 JsonRequest::Builder builder;
300 std::unique_ptr<translate::LanguageModel> language_model = 233 std::unique_ptr<translate::LanguageModel> language_model =
301 MakeLanguageModel({"en"}); 234 MakeLanguageModel({"en"});
302 RequestParams params; 235 RequestParams params;
303 params.interactive_request = true; 236 params.interactive_request = true;
304 params.language_code = "en"; 237 params.language_code = "en";
305 builder.SetParams(params) 238 builder.SetParams(params).SetLanguageModel(language_model.get());
306 .SetLanguageModel(language_model.get())
307 .SetFetchAPI(FetchAPI::CHROME_CONTENT_SUGGESTIONS_API);
308 239
309 EXPECT_THAT(builder.PreviewRequestBodyForTesting(), 240 EXPECT_THAT(builder.PreviewRequestBodyForTesting(),
310 EqualsJSON("{" 241 EqualsJSON("{"
311 " \"priority\": \"USER_ACTION\"," 242 " \"priority\": \"USER_ACTION\","
312 " \"uiLanguage\": \"en\"," 243 " \"uiLanguage\": \"en\","
313 " \"excludedSuggestionIds\": []," 244 " \"excludedSuggestionIds\": [],"
314 " \"topLanguages\": [{" 245 " \"topLanguages\": [{"
315 " \"language\" : \"en\"," 246 " \"language\" : \"en\","
316 " \"frequency\" : 1.0" 247 " \"frequency\" : 1.0"
317 " }]" 248 " }]"
318 "}")); 249 "}"));
319 } 250 }
320 251
321 } // namespace internal 252 } // namespace internal
322 253
323 } // namespace ntp_snippets 254 } // 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