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

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

Issue 591073002: Add support for Manifest.icons.sizes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manifest_icons
Patch Set: rebase Created 6 years, 2 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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 } 485 }
486 486
487 // Negative values are invalid. 487 // Negative values are invalid.
488 { 488 {
489 Manifest manifest = 489 Manifest manifest =
490 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": -2.5 } ] }"); 490 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": -2.5 } ] }");
491 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); 491 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity);
492 } 492 }
493 } 493 }
494 494
495 TEST_F(ManifestParserTest, IconSizesParseRules) {
496 // Smoke test.
497 {
498 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
499 "\"sizes\": \"42x42\" } ] }");
500 EXPECT_EQ(manifest.icons[0].sizes.size(), 1u);
501 }
502
503 // Trim whitespaces.
504 {
505 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
506 "\"sizes\": \" 42x42 \" } ] }");
507 EXPECT_EQ(manifest.icons[0].sizes.size(), 1u);
508 }
509
510 // Don't parse if name isn't a string.
511 {
512 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
513 "\"sizes\": {} } ] }");
514 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u);
515 }
516
517 // Don't parse if name isn't a string.
518 {
519 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
520 "\"sizes\": 42 } ] }");
521 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u);
522 }
523
524 // Smoke test: value correctly parsed.
525 {
526 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
527 "\"sizes\": \"42x42 48x48\" } ] }");
528 EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42));
529 EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(48, 48));
530 }
531
532 // <WIDTH>'x'<HEIGHT> and <WIDTH>'X'<HEIGHT> are equivalent.
533 {
534 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
535 "\"sizes\": \"42X42 48X48\" } ] }");
536 EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42));
537 EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(48, 48));
538 }
539
540 // Twice the same value is parsed twice.
541 {
542 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
543 "\"sizes\": \"42X42 42x42\" } ] }");
544 EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42));
545 EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(42, 42));
546 }
547
548 // Width or height can't start with 0.
549 {
550 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
551 "\"sizes\": \"004X007 042x00\" } ] }");
552 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u);
553 }
554
555 // Width and height MUST contain digits.
556 {
557 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
558 "\"sizes\": \"e4X1.0 55ax1e10\" } ] }");
559 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u);
560 }
561
562 // 'any' is correctly parsed and transformed to gfx::Size(0,0).
563 {
564 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
565 "\"sizes\": \"any AnY ANY aNy\" } ] }");
566 gfx::Size any = gfx::Size(0, 0);
567 EXPECT_EQ(manifest.icons[0].sizes.size(), 4u);
568 EXPECT_EQ(manifest.icons[0].sizes[0], any);
569 EXPECT_EQ(manifest.icons[0].sizes[1], any);
570 EXPECT_EQ(manifest.icons[0].sizes[2], any);
571 EXPECT_EQ(manifest.icons[0].sizes[3], any);
572 }
573
574 // Some invalid width/height combinations.
575 {
576 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
577 "\"sizes\": \"x 40xx 1x2x3 x42 42xx42\" } ] }");
578 gfx::Size any = gfx::Size(0, 0);
579 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u);
580 }
581 }
582
495 } // namespace content 583 } // 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