OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extension_api.h" | 5 #include "extensions/common/extension_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 EXPECT_TRUE(feature->whitelist()->empty()); | 669 EXPECT_TRUE(feature->whitelist()->empty()); |
670 EXPECT_TRUE(feature->extension_types()->empty()); | 670 EXPECT_TRUE(feature->extension_types()->empty()); |
671 | 671 |
672 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location()); | 672 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location()); |
673 EXPECT_TRUE(feature->platforms()->empty()); | 673 EXPECT_TRUE(feature->platforms()->empty()); |
674 EXPECT_EQ(0, feature->min_manifest_version()); | 674 EXPECT_EQ(0, feature->min_manifest_version()); |
675 EXPECT_EQ(0, feature->max_manifest_version()); | 675 EXPECT_EQ(0, feature->max_manifest_version()); |
676 } | 676 } |
677 } | 677 } |
678 | 678 |
679 TEST(ExtensionAPITest, FeaturesRequireContexts) { | 679 TEST(ExtensionAPITest, JSONFeatureProviderDoesNotStoreInvalidFeatures) { |
680 // TODO(cduvall): Make this check API featues. | 680 base::DictionaryValue features; |
681 std::unique_ptr<base::DictionaryValue> api_features1( | 681 std::unique_ptr<base::DictionaryValue> feature_value( |
682 new base::DictionaryValue()); | 682 new base::DictionaryValue()); |
683 std::unique_ptr<base::DictionaryValue> api_features2( | 683 // This feature is invalid (it needs an extension context), so the |
684 new base::DictionaryValue()); | 684 // JSONFeatureProvider should not store it. |
685 base::DictionaryValue* test1 = new base::DictionaryValue(); | 685 feature_value->SetString("channel", "stable"); |
686 base::DictionaryValue* test2 = new base::DictionaryValue(); | 686 features.Set("test", std::move(feature_value)); |
687 base::ListValue* contexts = new base::ListValue(); | 687 JSONFeatureProvider api_feature_provider(features, CreateAPIFeature); |
688 contexts->AppendString("content_script"); | 688 EXPECT_FALSE(api_feature_provider.GetFeature("test")); |
689 test1->Set("contexts", contexts); | |
690 test1->SetString("channel", "stable"); | |
691 test2->SetString("channel", "stable"); | |
692 api_features1->Set("test", test1); | |
693 api_features2->Set("test", test2); | |
694 | |
695 struct { | |
696 base::DictionaryValue* api_features; | |
697 bool expect_success; | |
698 } test_data[] = { | |
699 { api_features1.get(), true }, | |
700 { api_features2.get(), false } | |
701 }; | |
702 | |
703 for (size_t i = 0; i < arraysize(test_data); ++i) { | |
704 JSONFeatureProvider api_feature_provider(*test_data[i].api_features, | |
705 CreateAPIFeature); | |
706 Feature* feature = api_feature_provider.GetFeature("test"); | |
707 EXPECT_EQ(test_data[i].expect_success, feature != NULL) << i; | |
708 } | |
709 } | 689 } |
710 | 690 |
711 static void GetDictionaryFromList(const base::DictionaryValue* schema, | 691 static void GetDictionaryFromList(const base::DictionaryValue* schema, |
712 const std::string& list_name, | 692 const std::string& list_name, |
713 const int list_index, | 693 const int list_index, |
714 const base::DictionaryValue** out) { | 694 const base::DictionaryValue** out) { |
715 const base::ListValue* list; | 695 const base::ListValue* list; |
716 EXPECT_TRUE(schema->GetList(list_name, &list)); | 696 EXPECT_TRUE(schema->GetList(list_name, &list)); |
717 EXPECT_TRUE(list->GetDictionary(list_index, out)); | 697 EXPECT_TRUE(list->GetDictionary(list_index, out)); |
718 } | 698 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 extension.get(), | 835 extension.get(), |
856 Feature::BLESSED_EXTENSION_CONTEXT, | 836 Feature::BLESSED_EXTENSION_CONTEXT, |
857 GURL()).is_available()); | 837 GURL()).is_available()); |
858 EXPECT_FALSE(extension_api->IsAvailable("pageAction", | 838 EXPECT_FALSE(extension_api->IsAvailable("pageAction", |
859 extension.get(), | 839 extension.get(), |
860 Feature::BLESSED_EXTENSION_CONTEXT, | 840 Feature::BLESSED_EXTENSION_CONTEXT, |
861 GURL()).is_available()); | 841 GURL()).is_available()); |
862 } | 842 } |
863 | 843 |
864 } // namespace extensions | 844 } // namespace extensions |
OLD | NEW |