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

Side by Side Diff: content/renderer/manifest/manifest_parser_unittest.cc

Issue 590563002: Add support for icons.{src,type,density} in Manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: EXPORT Manifest::Icon Created 6 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 | « content/renderer/manifest/manifest_parser.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/renderer/manifest/manifest_parser.h" 5 #include "content/renderer/manifest/manifest_parser.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "content/public/common/manifest.h" 8 #include "content/public/common/manifest.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 blink::WebScreenOrientationLockPortraitSecondary); 318 blink::WebScreenOrientationLockPortraitSecondary);
319 } 319 }
320 320
321 // Case insensitive. 321 // Case insensitive.
322 { 322 {
323 Manifest manifest = ParseManifest("{ \"orientation\": \"LANDSCAPE\" }"); 323 Manifest manifest = ParseManifest("{ \"orientation\": \"LANDSCAPE\" }");
324 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockLandscape); 324 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockLandscape);
325 } 325 }
326 } 326 }
327 327
328 TEST_F(ManifestParserTest, IconsParseRules) {
329 // Smoke test: if no icon, empty list.
330 {
331 Manifest manifest = ParseManifest("{ \"icons\": [] }");
332 EXPECT_EQ(manifest.icons.size(), 0u);
333 EXPECT_TRUE(manifest.IsEmpty());
334 }
335
336 // Smoke test: if empty icon, empty list.
337 {
338 Manifest manifest = ParseManifest("{ \"icons\": [ {} ] }");
339 EXPECT_EQ(manifest.icons.size(), 0u);
340 EXPECT_TRUE(manifest.IsEmpty());
341 }
342
343 // Smoke test: icon with invalid src, empty list.
344 {
345 Manifest manifest = ParseManifest("{ \"icons\": [ { \"icons\": [] } ] }");
346 EXPECT_EQ(manifest.icons.size(), 0u);
347 EXPECT_TRUE(manifest.IsEmpty());
348 }
349
350 // Smoke test: if icon with empty src, it will be present in the list.
351 {
352 Manifest manifest = ParseManifest("{ \"icons\": [ { \"src\": \"\" } ] }");
353 EXPECT_EQ(manifest.icons.size(), 1u);
354 EXPECT_EQ(manifest.icons[0].src.spec(), "http://foo.com/index.html");
355 EXPECT_FALSE(manifest.IsEmpty());
356 }
357
358 // Smoke test: if one icons with valid src, it will be present in the list.
359 {
360 Manifest manifest =
361 ParseManifest("{ \"icons\": [{ \"src\": \"foo.jpg\" }] }");
362 EXPECT_EQ(manifest.icons.size(), 1u);
363 EXPECT_EQ(manifest.icons[0].src.spec(), "http://foo.com/foo.jpg");
364 EXPECT_FALSE(manifest.IsEmpty());
365 }
366 }
367
368 TEST_F(ManifestParserTest, IconSrcParseRules) {
369 // Smoke test.
370 {
371 Manifest manifest =
372 ParseManifest("{ \"icons\": [ {\"src\": \"foo.png\" } ] }");
373 EXPECT_EQ(manifest.icons[0].src.spec(),
374 default_document_url.Resolve("foo.png").spec());
375 }
376
377 // Whitespaces.
378 {
379 Manifest manifest =
380 ParseManifest("{ \"icons\": [ {\"src\": \" foo.png \" } ] }");
381 EXPECT_EQ(manifest.icons[0].src.spec(),
382 default_document_url.Resolve("foo.png").spec());
383 }
384
385 // Don't parse if property isn't a string.
386 {
387 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": {} } ] }");
388 EXPECT_TRUE(manifest.icons.empty());
389 }
390
391 // Don't parse if property isn't a string.
392 {
393 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": 42 } ] }");
394 EXPECT_TRUE(manifest.icons.empty());
395 }
396
397 // Resolving has to happen based on the document_url.
398 {
399 Manifest manifest =
400 ParseManifest("{ \"icons\": [ {\"src\": \"icons/foo.png\" } ] }",
401 GURL("http://foo.com/landing/index.html"));
402 EXPECT_EQ(manifest.icons[0].src.spec(),
403 "http://foo.com/landing/icons/foo.png");
404 }
405 }
406
407 TEST_F(ManifestParserTest, IconTypeParseRules) {
408 // Smoke test.
409 {
410 Manifest manifest =
411 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": \"foo\" } ] }");
412 EXPECT_TRUE(EqualsASCII(manifest.icons[0].type.string(), "foo"));
413 }
414
415 // Trim whitespaces.
416 {
417 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
418 " \"type\": \" foo \" } ] }");
419 EXPECT_TRUE(EqualsASCII(manifest.icons[0].type.string(), "foo"));
420 }
421
422 // Don't parse if property isn't a string.
423 {
424 Manifest manifest =
425 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": {} } ] }");
426 EXPECT_TRUE(manifest.icons[0].type.is_null());
427 }
428
429 // Don't parse if property isn't a string.
430 {
431 Manifest manifest =
432 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": 42 } ] }");
433 EXPECT_TRUE(manifest.icons[0].type.is_null());
434 }
435 }
436
437 TEST_F(ManifestParserTest, IconDensityParseRules) {
438 // Smoke test.
439 {
440 Manifest manifest =
441 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 42 } ] }");
442 EXPECT_EQ(manifest.icons[0].density, 42);
443 }
444
445 // Decimal value.
446 {
447 Manifest manifest =
448 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 2.5 } ] }");
449 EXPECT_EQ(manifest.icons[0].density, 2.5);
450 }
451
452 // Parse fail if it isn't a float.
453 {
454 Manifest manifest =
455 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": {} } ] }");
456 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity);
457 }
458
459 // Parse fail if it isn't a float.
460 {
461 Manifest manifest =
462 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\":\"2\" } ] }");
463 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity);
464 }
465
466 // Edge case: 1.0.
467 {
468 Manifest manifest =
469 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 1.00 } ] }");
470 EXPECT_EQ(manifest.icons[0].density, 1);
471 }
472
473 // Edge case: values between 0.0 and 1.0 are allowed.
474 {
475 Manifest manifest =
476 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 0.42 } ] }");
477 EXPECT_EQ(manifest.icons[0].density, 0.42);
478 }
479
480 // 0 is an invalid value.
481 {
482 Manifest manifest =
483 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 0.0 } ] }");
484 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity);
485 }
486
487 // Negative values are invalid.
488 {
489 Manifest manifest =
490 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": -2.5 } ] }");
491 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity);
492 }
493 }
494
328 } // namespace content 495 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/manifest/manifest_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698