| OLD | NEW |
| 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 | 541 |
| 542 TEST_F(SimpleFeatureTest, ParseWhitelist) { | 542 TEST_F(SimpleFeatureTest, ParseWhitelist) { |
| 543 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 543 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 544 base::ListValue* whitelist = new base::ListValue(); | 544 base::ListValue* whitelist = new base::ListValue(); |
| 545 whitelist->AppendString("foo"); | 545 whitelist->AppendString("foo"); |
| 546 whitelist->AppendString("bar"); | 546 whitelist->AppendString("bar"); |
| 547 value->Set("whitelist", whitelist); | 547 value->Set("whitelist", whitelist); |
| 548 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); | 548 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 549 feature->Parse(value.get()); | 549 feature->Parse(value.get()); |
| 550 EXPECT_EQ(2u, feature->whitelist().size()); | 550 EXPECT_EQ(2u, feature->whitelist().size()); |
| 551 EXPECT_TRUE(STLCount(feature->whitelist(), "foo")); | 551 EXPECT_TRUE(base::STLCount(feature->whitelist(), "foo")); |
| 552 EXPECT_TRUE(STLCount(feature->whitelist(), "bar")); | 552 EXPECT_TRUE(base::STLCount(feature->whitelist(), "bar")); |
| 553 } | 553 } |
| 554 | 554 |
| 555 TEST_F(SimpleFeatureTest, ParsePackageTypes) { | 555 TEST_F(SimpleFeatureTest, ParsePackageTypes) { |
| 556 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 556 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 557 base::ListValue* extension_types = new base::ListValue(); | 557 base::ListValue* extension_types = new base::ListValue(); |
| 558 extension_types->AppendString("extension"); | 558 extension_types->AppendString("extension"); |
| 559 extension_types->AppendString("theme"); | 559 extension_types->AppendString("theme"); |
| 560 extension_types->AppendString("legacy_packaged_app"); | 560 extension_types->AppendString("legacy_packaged_app"); |
| 561 extension_types->AppendString("hosted_app"); | 561 extension_types->AppendString("hosted_app"); |
| 562 extension_types->AppendString("platform_app"); | 562 extension_types->AppendString("platform_app"); |
| 563 extension_types->AppendString("shared_module"); | 563 extension_types->AppendString("shared_module"); |
| 564 value->Set("extension_types", extension_types); | 564 value->Set("extension_types", extension_types); |
| 565 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); | 565 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 566 feature->Parse(value.get()); | 566 feature->Parse(value.get()); |
| 567 EXPECT_EQ(6u, feature->extension_types().size()); | 567 EXPECT_EQ(6u, feature->extension_types().size()); |
| 568 EXPECT_TRUE(STLCount(feature->extension_types(), Manifest::TYPE_EXTENSION)); | |
| 569 EXPECT_TRUE(STLCount(feature->extension_types(), Manifest::TYPE_THEME)); | |
| 570 EXPECT_TRUE( | 568 EXPECT_TRUE( |
| 571 STLCount(feature->extension_types(), Manifest::TYPE_LEGACY_PACKAGED_APP)); | 569 base::STLCount(feature->extension_types(), Manifest::TYPE_EXTENSION)); |
| 572 EXPECT_TRUE(STLCount(feature->extension_types(), Manifest::TYPE_HOSTED_APP)); | 570 EXPECT_TRUE(base::STLCount(feature->extension_types(), Manifest::TYPE_THEME)); |
| 571 EXPECT_TRUE(base::STLCount(feature->extension_types(), |
| 572 Manifest::TYPE_LEGACY_PACKAGED_APP)); |
| 573 EXPECT_TRUE( | 573 EXPECT_TRUE( |
| 574 STLCount(feature->extension_types(), Manifest::TYPE_PLATFORM_APP)); | 574 base::STLCount(feature->extension_types(), Manifest::TYPE_HOSTED_APP)); |
| 575 EXPECT_TRUE( | 575 EXPECT_TRUE( |
| 576 STLCount(feature->extension_types(), Manifest::TYPE_SHARED_MODULE)); | 576 base::STLCount(feature->extension_types(), Manifest::TYPE_PLATFORM_APP)); |
| 577 EXPECT_TRUE( |
| 578 base::STLCount(feature->extension_types(), Manifest::TYPE_SHARED_MODULE)); |
| 577 | 579 |
| 578 value->SetString("extension_types", "all"); | 580 value->SetString("extension_types", "all"); |
| 579 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); | 581 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); |
| 580 feature2->Parse(value.get()); | 582 feature2->Parse(value.get()); |
| 581 EXPECT_EQ(feature->extension_types(), feature2->extension_types()); | 583 EXPECT_EQ(feature->extension_types(), feature2->extension_types()); |
| 582 } | 584 } |
| 583 | 585 |
| 584 TEST_F(SimpleFeatureTest, ParseContexts) { | 586 TEST_F(SimpleFeatureTest, ParseContexts) { |
| 585 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 587 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 586 base::ListValue* contexts = new base::ListValue(); | 588 base::ListValue* contexts = new base::ListValue(); |
| 587 contexts->AppendString("blessed_extension"); | 589 contexts->AppendString("blessed_extension"); |
| 588 contexts->AppendString("unblessed_extension"); | 590 contexts->AppendString("unblessed_extension"); |
| 589 contexts->AppendString("content_script"); | 591 contexts->AppendString("content_script"); |
| 590 contexts->AppendString("web_page"); | 592 contexts->AppendString("web_page"); |
| 591 contexts->AppendString("blessed_web_page"); | 593 contexts->AppendString("blessed_web_page"); |
| 592 contexts->AppendString("webui"); | 594 contexts->AppendString("webui"); |
| 593 contexts->AppendString("extension_service_worker"); | 595 contexts->AppendString("extension_service_worker"); |
| 594 value->Set("contexts", contexts); | 596 value->Set("contexts", contexts); |
| 595 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); | 597 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 596 feature->Parse(value.get()); | 598 feature->Parse(value.get()); |
| 597 EXPECT_EQ(7u, feature->contexts().size()); | 599 EXPECT_EQ(7u, feature->contexts().size()); |
| 598 EXPECT_TRUE( | 600 EXPECT_TRUE( |
| 599 STLCount(feature->contexts(), Feature::BLESSED_EXTENSION_CONTEXT)); | 601 base::STLCount(feature->contexts(), Feature::BLESSED_EXTENSION_CONTEXT)); |
| 602 EXPECT_TRUE(base::STLCount(feature->contexts(), |
| 603 Feature::UNBLESSED_EXTENSION_CONTEXT)); |
| 600 EXPECT_TRUE( | 604 EXPECT_TRUE( |
| 601 STLCount(feature->contexts(), Feature::UNBLESSED_EXTENSION_CONTEXT)); | 605 base::STLCount(feature->contexts(), Feature::CONTENT_SCRIPT_CONTEXT)); |
| 602 EXPECT_TRUE(STLCount(feature->contexts(), Feature::CONTENT_SCRIPT_CONTEXT)); | 606 EXPECT_TRUE(base::STLCount(feature->contexts(), Feature::WEB_PAGE_CONTEXT)); |
| 603 EXPECT_TRUE(STLCount(feature->contexts(), Feature::WEB_PAGE_CONTEXT)); | 607 EXPECT_TRUE( |
| 604 EXPECT_TRUE(STLCount(feature->contexts(), Feature::BLESSED_WEB_PAGE_CONTEXT)); | 608 base::STLCount(feature->contexts(), Feature::BLESSED_WEB_PAGE_CONTEXT)); |
| 605 | 609 |
| 606 value->SetString("contexts", "all"); | 610 value->SetString("contexts", "all"); |
| 607 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); | 611 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); |
| 608 feature2->Parse(value.get()); | 612 feature2->Parse(value.get()); |
| 609 EXPECT_EQ(feature->contexts(), feature2->contexts()); | 613 EXPECT_EQ(feature->contexts(), feature2->contexts()); |
| 610 } | 614 } |
| 611 | 615 |
| 612 TEST_F(SimpleFeatureTest, ParseLocation) { | 616 TEST_F(SimpleFeatureTest, ParseLocation) { |
| 613 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 617 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 614 value->SetString("location", "component"); | 618 value->SetString("location", "component"); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 feature.set_min_manifest_version(1); | 672 feature.set_min_manifest_version(1); |
| 669 feature.set_max_manifest_version(2); | 673 feature.set_max_manifest_version(2); |
| 670 | 674 |
| 671 // Test additive parsing. Parsing an empty dictionary should result in no | 675 // Test additive parsing. Parsing an empty dictionary should result in no |
| 672 // changes to a SimpleFeature. | 676 // changes to a SimpleFeature. |
| 673 base::DictionaryValue definition; | 677 base::DictionaryValue definition; |
| 674 feature.Parse(&definition); | 678 feature.Parse(&definition); |
| 675 EXPECT_EQ(1u, feature.whitelist().size()); | 679 EXPECT_EQ(1u, feature.whitelist().size()); |
| 676 EXPECT_EQ(1u, feature.extension_types().size()); | 680 EXPECT_EQ(1u, feature.extension_types().size()); |
| 677 EXPECT_EQ(1u, feature.contexts().size()); | 681 EXPECT_EQ(1u, feature.contexts().size()); |
| 678 EXPECT_EQ(1, STLCount(feature.whitelist(), "foo")); | 682 EXPECT_EQ(1, base::STLCount(feature.whitelist(), "foo")); |
| 679 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature.location()); | 683 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature.location()); |
| 680 EXPECT_EQ(1u, feature.platforms().size()); | 684 EXPECT_EQ(1u, feature.platforms().size()); |
| 681 EXPECT_EQ(1, STLCount(feature.platforms(), Feature::CHROMEOS_PLATFORM)); | 685 EXPECT_EQ(1, base::STLCount(feature.platforms(), Feature::CHROMEOS_PLATFORM)); |
| 682 EXPECT_EQ(1, feature.min_manifest_version()); | 686 EXPECT_EQ(1, feature.min_manifest_version()); |
| 683 EXPECT_EQ(2, feature.max_manifest_version()); | 687 EXPECT_EQ(2, feature.max_manifest_version()); |
| 684 | 688 |
| 685 base::ListValue* whitelist = new base::ListValue(); | 689 base::ListValue* whitelist = new base::ListValue(); |
| 686 base::ListValue* extension_types = new base::ListValue(); | 690 base::ListValue* extension_types = new base::ListValue(); |
| 687 base::ListValue* contexts = new base::ListValue(); | 691 base::ListValue* contexts = new base::ListValue(); |
| 688 whitelist->AppendString("bar"); | 692 whitelist->AppendString("bar"); |
| 689 extension_types->AppendString("extension"); | 693 extension_types->AppendString("extension"); |
| 690 contexts->AppendString("unblessed_extension"); | 694 contexts->AppendString("unblessed_extension"); |
| 691 definition.Set("whitelist", whitelist); | 695 definition.Set("whitelist", whitelist); |
| 692 definition.Set("extension_types", extension_types); | 696 definition.Set("extension_types", extension_types); |
| 693 definition.Set("contexts", contexts); | 697 definition.Set("contexts", contexts); |
| 694 // Can't test location or platform because we only have one value so far. | 698 // Can't test location or platform because we only have one value so far. |
| 695 definition.Set("min_manifest_version", new base::FundamentalValue(2)); | 699 definition.Set("min_manifest_version", new base::FundamentalValue(2)); |
| 696 definition.Set("max_manifest_version", new base::FundamentalValue(3)); | 700 definition.Set("max_manifest_version", new base::FundamentalValue(3)); |
| 697 | 701 |
| 698 feature.Parse(&definition); | 702 feature.Parse(&definition); |
| 699 EXPECT_EQ(1u, feature.whitelist().size()); | 703 EXPECT_EQ(1u, feature.whitelist().size()); |
| 700 EXPECT_EQ(1u, feature.extension_types().size()); | 704 EXPECT_EQ(1u, feature.extension_types().size()); |
| 701 EXPECT_EQ(1u, feature.contexts().size()); | 705 EXPECT_EQ(1u, feature.contexts().size()); |
| 702 EXPECT_EQ(1, STLCount(feature.whitelist(), "bar")); | 706 EXPECT_EQ(1, base::STLCount(feature.whitelist(), "bar")); |
| 703 EXPECT_EQ(1, STLCount(feature.extension_types(), Manifest::TYPE_EXTENSION)); | 707 EXPECT_EQ( |
| 704 EXPECT_EQ(1, | 708 1, base::STLCount(feature.extension_types(), Manifest::TYPE_EXTENSION)); |
| 705 STLCount(feature.contexts(), Feature::UNBLESSED_EXTENSION_CONTEXT)); | 709 EXPECT_EQ(1, base::STLCount(feature.contexts(), |
| 710 Feature::UNBLESSED_EXTENSION_CONTEXT)); |
| 706 EXPECT_EQ(2, feature.min_manifest_version()); | 711 EXPECT_EQ(2, feature.min_manifest_version()); |
| 707 EXPECT_EQ(3, feature.max_manifest_version()); | 712 EXPECT_EQ(3, feature.max_manifest_version()); |
| 708 } | 713 } |
| 709 | 714 |
| 710 TEST_F(SimpleFeatureTest, CommandLineSwitch) { | 715 TEST_F(SimpleFeatureTest, CommandLineSwitch) { |
| 711 SimpleFeature feature; | 716 SimpleFeature feature; |
| 712 feature.set_command_line_switch("laser-beams"); | 717 feature.set_command_line_switch("laser-beams"); |
| 713 { | 718 { |
| 714 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, | 719 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, |
| 715 feature.IsAvailableToEnvironment().result()); | 720 feature.IsAvailableToEnvironment().result()); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 EXPECT_NE(Feature::IS_AVAILABLE, | 970 EXPECT_NE(Feature::IS_AVAILABLE, |
| 966 feature | 971 feature |
| 967 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, | 972 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, |
| 968 Manifest::INVALID_LOCATION, | 973 Manifest::INVALID_LOCATION, |
| 969 Feature::UNSPECIFIED_PLATFORM) | 974 Feature::UNSPECIFIED_PLATFORM) |
| 970 .result()); | 975 .result()); |
| 971 } | 976 } |
| 972 } | 977 } |
| 973 | 978 |
| 974 } // namespace extensions | 979 } // namespace extensions |
| OLD | NEW |