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

Side by Side Diff: extensions/common/features/simple_feature_unittest.cc

Issue 2037703004: Remove ListValue::Append(new {Fundamental,String}Value(...)) pattern in //extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « extensions/common/extension_set_unittest.cc ('k') | extensions/common/file_util_unittest.cc » ('j') | 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 "extensions/common/features/simple_feature.h" 5 #include "extensions/common/features/simple_feature.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 EXPECT_TRUE(feature->contexts()->empty()); 502 EXPECT_TRUE(feature->contexts()->empty());
503 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location()); 503 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location());
504 EXPECT_TRUE(feature->platforms()->empty()); 504 EXPECT_TRUE(feature->platforms()->empty());
505 EXPECT_EQ(0, feature->min_manifest_version()); 505 EXPECT_EQ(0, feature->min_manifest_version());
506 EXPECT_EQ(0, feature->max_manifest_version()); 506 EXPECT_EQ(0, feature->max_manifest_version());
507 } 507 }
508 508
509 TEST_F(SimpleFeatureTest, ParseWhitelist) { 509 TEST_F(SimpleFeatureTest, ParseWhitelist) {
510 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 510 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
511 base::ListValue* whitelist = new base::ListValue(); 511 base::ListValue* whitelist = new base::ListValue();
512 whitelist->Append(new base::StringValue("foo")); 512 whitelist->AppendString("foo");
513 whitelist->Append(new base::StringValue("bar")); 513 whitelist->AppendString("bar");
514 value->Set("whitelist", whitelist); 514 value->Set("whitelist", whitelist);
515 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); 515 std::unique_ptr<SimpleFeature> feature(new SimpleFeature());
516 feature->Parse(value.get()); 516 feature->Parse(value.get());
517 EXPECT_EQ(2u, feature->whitelist()->size()); 517 EXPECT_EQ(2u, feature->whitelist()->size());
518 EXPECT_TRUE(STLCount(*(feature->whitelist()), "foo")); 518 EXPECT_TRUE(STLCount(*(feature->whitelist()), "foo"));
519 EXPECT_TRUE(STLCount(*(feature->whitelist()), "bar")); 519 EXPECT_TRUE(STLCount(*(feature->whitelist()), "bar"));
520 } 520 }
521 521
522 TEST_F(SimpleFeatureTest, ParsePackageTypes) { 522 TEST_F(SimpleFeatureTest, ParsePackageTypes) {
523 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 523 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
524 base::ListValue* extension_types = new base::ListValue(); 524 base::ListValue* extension_types = new base::ListValue();
525 extension_types->Append(new base::StringValue("extension")); 525 extension_types->AppendString("extension");
526 extension_types->Append(new base::StringValue("theme")); 526 extension_types->AppendString("theme");
527 extension_types->Append(new base::StringValue("legacy_packaged_app")); 527 extension_types->AppendString("legacy_packaged_app");
528 extension_types->Append(new base::StringValue("hosted_app")); 528 extension_types->AppendString("hosted_app");
529 extension_types->Append(new base::StringValue("platform_app")); 529 extension_types->AppendString("platform_app");
530 extension_types->Append(new base::StringValue("shared_module")); 530 extension_types->AppendString("shared_module");
531 value->Set("extension_types", extension_types); 531 value->Set("extension_types", extension_types);
532 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); 532 std::unique_ptr<SimpleFeature> feature(new SimpleFeature());
533 feature->Parse(value.get()); 533 feature->Parse(value.get());
534 EXPECT_EQ(6u, feature->extension_types()->size()); 534 EXPECT_EQ(6u, feature->extension_types()->size());
535 EXPECT_TRUE( 535 EXPECT_TRUE(
536 STLCount(*(feature->extension_types()), Manifest::TYPE_EXTENSION)); 536 STLCount(*(feature->extension_types()), Manifest::TYPE_EXTENSION));
537 EXPECT_TRUE( 537 EXPECT_TRUE(
538 STLCount(*(feature->extension_types()), Manifest::TYPE_THEME)); 538 STLCount(*(feature->extension_types()), Manifest::TYPE_THEME));
539 EXPECT_TRUE( 539 EXPECT_TRUE(
540 STLCount( 540 STLCount(
541 *(feature->extension_types()), Manifest::TYPE_LEGACY_PACKAGED_APP)); 541 *(feature->extension_types()), Manifest::TYPE_LEGACY_PACKAGED_APP));
542 EXPECT_TRUE( 542 EXPECT_TRUE(
543 STLCount(*(feature->extension_types()), Manifest::TYPE_HOSTED_APP)); 543 STLCount(*(feature->extension_types()), Manifest::TYPE_HOSTED_APP));
544 EXPECT_TRUE( 544 EXPECT_TRUE(
545 STLCount(*(feature->extension_types()), Manifest::TYPE_PLATFORM_APP)); 545 STLCount(*(feature->extension_types()), Manifest::TYPE_PLATFORM_APP));
546 EXPECT_TRUE( 546 EXPECT_TRUE(
547 STLCount(*(feature->extension_types()), Manifest::TYPE_SHARED_MODULE)); 547 STLCount(*(feature->extension_types()), Manifest::TYPE_SHARED_MODULE));
548 548
549 value->SetString("extension_types", "all"); 549 value->SetString("extension_types", "all");
550 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); 550 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature());
551 feature2->Parse(value.get()); 551 feature2->Parse(value.get());
552 EXPECT_EQ(*(feature->extension_types()), *(feature2->extension_types())); 552 EXPECT_EQ(*(feature->extension_types()), *(feature2->extension_types()));
553 } 553 }
554 554
555 TEST_F(SimpleFeatureTest, ParseContexts) { 555 TEST_F(SimpleFeatureTest, ParseContexts) {
556 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 556 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
557 base::ListValue* contexts = new base::ListValue(); 557 base::ListValue* contexts = new base::ListValue();
558 contexts->Append(new base::StringValue("blessed_extension")); 558 contexts->AppendString("blessed_extension");
559 contexts->Append(new base::StringValue("unblessed_extension")); 559 contexts->AppendString("unblessed_extension");
560 contexts->Append(new base::StringValue("content_script")); 560 contexts->AppendString("content_script");
561 contexts->Append(new base::StringValue("web_page")); 561 contexts->AppendString("web_page");
562 contexts->Append(new base::StringValue("blessed_web_page")); 562 contexts->AppendString("blessed_web_page");
563 contexts->Append(new base::StringValue("webui")); 563 contexts->AppendString("webui");
564 contexts->Append(new base::StringValue("extension_service_worker")); 564 contexts->AppendString("extension_service_worker");
565 value->Set("contexts", contexts); 565 value->Set("contexts", contexts);
566 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); 566 std::unique_ptr<SimpleFeature> feature(new SimpleFeature());
567 feature->Parse(value.get()); 567 feature->Parse(value.get());
568 EXPECT_EQ(7u, feature->contexts()->size()); 568 EXPECT_EQ(7u, feature->contexts()->size());
569 EXPECT_TRUE( 569 EXPECT_TRUE(
570 STLCount(*(feature->contexts()), Feature::BLESSED_EXTENSION_CONTEXT)); 570 STLCount(*(feature->contexts()), Feature::BLESSED_EXTENSION_CONTEXT));
571 EXPECT_TRUE( 571 EXPECT_TRUE(
572 STLCount(*(feature->contexts()), Feature::UNBLESSED_EXTENSION_CONTEXT)); 572 STLCount(*(feature->contexts()), Feature::UNBLESSED_EXTENSION_CONTEXT));
573 EXPECT_TRUE( 573 EXPECT_TRUE(
574 STLCount(*(feature->contexts()), Feature::CONTENT_SCRIPT_CONTEXT)); 574 STLCount(*(feature->contexts()), Feature::CONTENT_SCRIPT_CONTEXT));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 EXPECT_EQ(1, STLCount(*(feature.whitelist()), "foo")); 652 EXPECT_EQ(1, STLCount(*(feature.whitelist()), "foo"));
653 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature.location()); 653 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature.location());
654 EXPECT_EQ(1u, feature.platforms()->size()); 654 EXPECT_EQ(1u, feature.platforms()->size());
655 EXPECT_EQ(1, STLCount(*(feature.platforms()), Feature::CHROMEOS_PLATFORM)); 655 EXPECT_EQ(1, STLCount(*(feature.platforms()), Feature::CHROMEOS_PLATFORM));
656 EXPECT_EQ(1, feature.min_manifest_version()); 656 EXPECT_EQ(1, feature.min_manifest_version());
657 EXPECT_EQ(2, feature.max_manifest_version()); 657 EXPECT_EQ(2, feature.max_manifest_version());
658 658
659 base::ListValue* whitelist = new base::ListValue(); 659 base::ListValue* whitelist = new base::ListValue();
660 base::ListValue* extension_types = new base::ListValue(); 660 base::ListValue* extension_types = new base::ListValue();
661 base::ListValue* contexts = new base::ListValue(); 661 base::ListValue* contexts = new base::ListValue();
662 whitelist->Append(new base::StringValue("bar")); 662 whitelist->AppendString("bar");
663 extension_types->Append(new base::StringValue("extension")); 663 extension_types->AppendString("extension");
664 contexts->Append(new base::StringValue("unblessed_extension")); 664 contexts->AppendString("unblessed_extension");
665 definition.Set("whitelist", whitelist); 665 definition.Set("whitelist", whitelist);
666 definition.Set("extension_types", extension_types); 666 definition.Set("extension_types", extension_types);
667 definition.Set("contexts", contexts); 667 definition.Set("contexts", contexts);
668 // Can't test location or platform because we only have one value so far. 668 // Can't test location or platform because we only have one value so far.
669 definition.Set("min_manifest_version", new base::FundamentalValue(2)); 669 definition.Set("min_manifest_version", new base::FundamentalValue(2));
670 definition.Set("max_manifest_version", new base::FundamentalValue(3)); 670 definition.Set("max_manifest_version", new base::FundamentalValue(3));
671 671
672 feature.Parse(&definition); 672 feature.Parse(&definition);
673 EXPECT_EQ(1u, feature.whitelist()->size()); 673 EXPECT_EQ(1u, feature.whitelist()->size());
674 EXPECT_EQ(1u, feature.extension_types()->size()); 674 EXPECT_EQ(1u, feature.extension_types()->size());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 EXPECT_FALSE(SimpleFeature::IsIdInArray("", kIdArray, arraysize(kIdArray))); 737 EXPECT_FALSE(SimpleFeature::IsIdInArray("", kIdArray, arraysize(kIdArray)));
738 EXPECT_FALSE(SimpleFeature::IsIdInArray( 738 EXPECT_FALSE(SimpleFeature::IsIdInArray(
739 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", kIdArray, arraysize(kIdArray))); 739 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", kIdArray, arraysize(kIdArray)));
740 EXPECT_TRUE(SimpleFeature::IsIdInArray( 740 EXPECT_TRUE(SimpleFeature::IsIdInArray(
741 "bbbbccccdddddddddeeeeeeffffgghhh", kIdArray, arraysize(kIdArray))); 741 "bbbbccccdddddddddeeeeeeffffgghhh", kIdArray, arraysize(kIdArray)));
742 EXPECT_TRUE(SimpleFeature::IsIdInArray( 742 EXPECT_TRUE(SimpleFeature::IsIdInArray(
743 "aaaabbbbccccddddeeeeffffgggghhhh", kIdArray, arraysize(kIdArray))); 743 "aaaabbbbccccddddeeeeffffgggghhhh", kIdArray, arraysize(kIdArray)));
744 } 744 }
745 745
746 } // namespace extensions 746 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/extension_set_unittest.cc ('k') | extensions/common/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698