| 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 feature_value->SetString("channel", "stable"); |
| 684 new base::DictionaryValue()); | 684 features.Set("test", std::move(feature_value)); |
| 685 base::DictionaryValue* test1 = new base::DictionaryValue(); | 685 JSONFeatureProvider api_feature_provider(features, CreateAPIFeature); |
| 686 base::DictionaryValue* test2 = new base::DictionaryValue(); | 686 EXPECT_FALSE(api_feature_provider.GetFeature("test")); |
| 687 base::ListValue* contexts = new base::ListValue(); | |
| 688 contexts->AppendString("content_script"); | |
| 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 } | 687 } |
| 710 | 688 |
| 711 static void GetDictionaryFromList(const base::DictionaryValue* schema, | 689 static void GetDictionaryFromList(const base::DictionaryValue* schema, |
| 712 const std::string& list_name, | 690 const std::string& list_name, |
| 713 const int list_index, | 691 const int list_index, |
| 714 const base::DictionaryValue** out) { | 692 const base::DictionaryValue** out) { |
| 715 const base::ListValue* list; | 693 const base::ListValue* list; |
| 716 EXPECT_TRUE(schema->GetList(list_name, &list)); | 694 EXPECT_TRUE(schema->GetList(list_name, &list)); |
| 717 EXPECT_TRUE(list->GetDictionary(list_index, out)); | 695 EXPECT_TRUE(list->GetDictionary(list_index, out)); |
| 718 } | 696 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 extension.get(), | 833 extension.get(), |
| 856 Feature::BLESSED_EXTENSION_CONTEXT, | 834 Feature::BLESSED_EXTENSION_CONTEXT, |
| 857 GURL()).is_available()); | 835 GURL()).is_available()); |
| 858 EXPECT_FALSE(extension_api->IsAvailable("pageAction", | 836 EXPECT_FALSE(extension_api->IsAvailable("pageAction", |
| 859 extension.get(), | 837 extension.get(), |
| 860 Feature::BLESSED_EXTENSION_CONTEXT, | 838 Feature::BLESSED_EXTENSION_CONTEXT, |
| 861 GURL()).is_available()); | 839 GURL()).is_available()); |
| 862 } | 840 } |
| 863 | 841 |
| 864 } // namespace extensions | 842 } // namespace extensions |
| OLD | NEW |