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

Side by Side Diff: chrome/renderer/searchbox/searchbox_unittest.cc

Issue 1017853002: [Icons NTP] Allow chrome-search:// large-icon and fallback-icon hosts to use <view_id>/<restricted_… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: LargeIconUrlParser not in chrome namespace; add tests. Created 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "chrome/common/instant_types.h" 6 #include "chrome/common/instant_types.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h" 8 #include "url/gurl.h"
9 9
10 namespace internal { 10 namespace internal {
11 11
12 // Defined in searchbox.cc 12 // Defined in searchbox.cc
13 bool GetRestrictedIDFromThumbnailUrl(int render_view_id, 13 bool GetRestrictedIDFromThumbnailUrl(int render_view_id,
14 const GURL& url, 14 const GURL& url,
15 InstantRestrictedID* id); 15 InstantRestrictedID* id);
16 16
17 // Defined in searchbox.cc 17 // Defined in searchbox.cc
18 bool GetRestrictedIDFromFaviconUrl(int render_view_id, 18 bool GetRestrictedIDFromFaviconUrl(int render_view_id,
19 const GURL& url, 19 const GURL& url,
20 std::string* favicon_params, 20 std::string* favicon_params,
21 InstantRestrictedID* rid); 21 InstantRestrictedID* rid);
22 22
23 // Defined in searchbox.cc
24 bool GetRestrictedIDFromLargeIconUrl(int render_view_id,
25 const GURL& url,
26 std::string* favicon_params,
27 InstantRestrictedID* rid);
28
29 // Defined in searchbox.cc
30 bool GetRestrictedIDFromFallbackIconUrl(int render_view_id,
31 const GURL& url,
32 std::string* favicon_params,
33 InstantRestrictedID* rid);
34
23 TEST(SearchBoxUtilTest, GetInstantRestrictedIDFromTransientURL) { 35 TEST(SearchBoxUtilTest, GetInstantRestrictedIDFromTransientURL) {
24 const int kInvalidRenderViewID = 920; 36 const int kInvalidRenderViewID = 920;
25 const int kValidRenderViewID = 1; 37 const int kValidRenderViewID = 1;
26 38
27 const struct { 39 const struct {
28 int render_view_id; 40 int render_view_id;
29 GURL transient_url; 41 GURL transient_url;
30 InstantRestrictedID expected_rid; 42 InstantRestrictedID expected_rid;
31 bool expected_return_val; 43 bool expected_return_val;
32 } test_cases[] = { 44 } test_cases[] = {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 &favicon_params, 235 &favicon_params,
224 &rid); 236 &rid);
225 EXPECT_EQ(test_cases[i].expected_return_val, return_val); 237 EXPECT_EQ(test_cases[i].expected_return_val, return_val);
226 EXPECT_EQ(test_cases[i].expected_favicon_params, favicon_params); 238 EXPECT_EQ(test_cases[i].expected_favicon_params, favicon_params);
227 EXPECT_EQ(test_cases[i].expected_rid, rid); 239 EXPECT_EQ(test_cases[i].expected_rid, rid);
228 favicon_params = ""; 240 favicon_params = "";
229 rid = 0; 241 rid = 0;
230 } 242 }
231 } 243 }
232 244
245 TEST(SearchBoxUtilTest, GetRestrictedIDFromLargeIconUrl) {
246 const int kInvalidRenderViewID = 920;
247 const int kValidRenderViewID = 1;
248
249 const struct {
250 int render_view_id;
251 GURL transient_url;
252 std::string expected_icon_params;
253 InstantRestrictedID expected_rid;
254 bool expected_return_val;
255 } test_cases[] = {
256 // RenderView ID matches the view id specified in the transient url.
257 {
258 kValidRenderViewID,
259 GURL("chrome-search://big-icon/96/1/2"),
260 "96/",
261 2,
262 true
263 },
264
265 // RenderView ID does not match the view id specified in the transient url.
266 {
267 kInvalidRenderViewID,
268 GURL("chrome-search://big-icon/96/1/2"),
269 "96/",
270 0,
271 true
272 },
273
274 // Invalid transient urls.
275 {
276 kValidRenderViewID,
277 GURL("chrome-search://big-icon"),
278 "",
279 0,
280 false
281 },
282 {
283 kValidRenderViewID,
284 GURL("chrome-search://big-icon/"),
285 "",
286 0,
287 false
288 },
289 {
290 kValidRenderViewID,
291 GURL("chrome-search://big-icon/96"),
292 "",
293 0,
294 false
295 },
296 {
297 kValidRenderViewID,
298 GURL("chrome-search://big-icon/96/123"),
299 "96/",
300 0,
301 true
302 },
303 {
304 kValidRenderViewID,
305 GURL("chrome-search://big-icon/96/xyz"),
306 "96/",
307 0,
308 true
309 },
310 {
311 kValidRenderViewID,
312 GURL("chrome-search://big-icon/invalidparameter/96/1/2"),
313 "",
314 0,
315 false // More stringent than chrome-search://favicon.
316 }
317 };
318
319 std::string icon_params = "";
320 InstantRestrictedID rid = 0;
321 for (size_t i = 0; i < arraysize(test_cases); ++i) {
322 bool return_val = GetRestrictedIDFromLargeIconUrl(
323 test_cases[i].render_view_id,
324 test_cases[i].transient_url,
325 &icon_params,
326 &rid);
327 EXPECT_EQ(test_cases[i].expected_return_val, return_val);
328 EXPECT_EQ(test_cases[i].expected_icon_params, icon_params);
329 EXPECT_EQ(test_cases[i].expected_rid, rid);
330 icon_params = "";
331 rid = 0;
332 }
333 }
334
335 TEST(SearchBoxUtilTest, GetRestrictedIDFromFallbackIconUrl) {
336 const int kInvalidRenderViewID = 920;
337 const int kValidRenderViewID = 1;
338
339 const struct {
340 int render_view_id;
341 GURL transient_url;
342 std::string expected_icon_params;
343 InstantRestrictedID expected_rid;
344 bool expected_return_val;
345 } test_cases[] = {
346 // RenderView ID matches the view id specified in the transient url.
347 {
348 kValidRenderViewID,
349 GURL("chrome-search://fallback-icon/,,,,/1/2"),
350 ",,,,/",
351 2,
352 true
353 },
354
355 // RenderView ID does not match the view id specified in the transient url.
356 {
357 kInvalidRenderViewID,
358 GURL("chrome-search://fallback-icon/,,,,/1/2"),
359 ",,,,/",
360 0,
361 true
362 },
363
364 // Invalid transient urls.
365 {
366 kValidRenderViewID,
367 GURL("chrome-search://fallback-icon"),
368 "",
369 0,
370 false
371 },
372 {
373 kValidRenderViewID,
374 GURL("chrome-search://fallback-icon/"),
375 "",
376 0,
377 false
378 },
379 {
380 kValidRenderViewID,
381 GURL("chrome-search://fallback-icon/,,,,"),
382 "",
383 0,
384 false
385 },
386 {
387 kValidRenderViewID,
388 GURL("chrome-search://fallback-icon/,,,,/123"),
389 ",,,,/",
390 0,
391 true
392 },
393 {
394 kValidRenderViewID,
395 GURL("chrome-search://fallback-icon/,,,,/xyz"),
396 ",,,,/",
397 0,
398 true
399 },
400 {
401 kValidRenderViewID,
402 GURL("chrome-search://fallback-icon/invalidparameter/,,,,/1/2"),
403 "",
404 0,
405 false // More stringent than chrome-search://favicon.
406 }
407 };
408
409 std::string icon_params = "";
410 InstantRestrictedID rid = 0;
411 for (size_t i = 0; i < arraysize(test_cases); ++i) {
412 bool return_val = GetRestrictedIDFromFallbackIconUrl(
413 test_cases[i].render_view_id,
414 test_cases[i].transient_url,
415 &icon_params,
416 &rid);
417 EXPECT_EQ(test_cases[i].expected_return_val, return_val);
418 EXPECT_EQ(test_cases[i].expected_icon_params, icon_params);
419 EXPECT_EQ(test_cases[i].expected_rid, rid);
420 icon_params = "";
421 rid = 0;
422 }
423 }
424
233 } // namespace internal 425 } // namespace internal
OLDNEW
« chrome/renderer/searchbox/searchbox.cc ('K') | « chrome/renderer/searchbox/searchbox.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698