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> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
17 #include "base/json/json_writer.h" | 17 #include "base/json/json_writer.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
24 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
25 #include "extensions/common/extension_builder.h" | 25 #include "extensions/common/extension_builder.h" |
26 #include "extensions/common/features/api_feature.h" | 26 #include "extensions/common/features/api_feature.h" |
27 #include "extensions/common/features/base_feature_provider.h" | 27 #include "extensions/common/features/json_feature_provider.h" |
28 #include "extensions/common/features/simple_feature.h" | 28 #include "extensions/common/features/simple_feature.h" |
29 #include "extensions/common/manifest.h" | 29 #include "extensions/common/manifest.h" |
30 #include "extensions/common/manifest_constants.h" | 30 #include "extensions/common/manifest_constants.h" |
31 #include "extensions/common/test_util.h" | 31 #include "extensions/common/test_util.h" |
32 #include "extensions/common/value_builder.h" | 32 #include "extensions/common/value_builder.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
34 | 34 |
35 namespace extensions { | 35 namespace extensions { |
36 | 36 |
37 using test_util::BuildExtension; | 37 using test_util::BuildExtension; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 .AppendASCII("extension_api_unittest") | 170 .AppendASCII("extension_api_unittest") |
171 .AppendASCII("api_features.json"); | 171 .AppendASCII("api_features.json"); |
172 | 172 |
173 std::string api_features_str; | 173 std::string api_features_str; |
174 ASSERT_TRUE(base::ReadFileToString( | 174 ASSERT_TRUE(base::ReadFileToString( |
175 api_features_path, &api_features_str)) << "api_features.json"; | 175 api_features_path, &api_features_str)) << "api_features.json"; |
176 | 176 |
177 std::unique_ptr<base::DictionaryValue> value( | 177 std::unique_ptr<base::DictionaryValue> value( |
178 static_cast<base::DictionaryValue*>( | 178 static_cast<base::DictionaryValue*>( |
179 base::JSONReader::Read(api_features_str).release())); | 179 base::JSONReader::Read(api_features_str).release())); |
180 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature); | 180 JSONFeatureProvider api_feature_provider(*value, CreateAPIFeature); |
181 | 181 |
182 for (size_t i = 0; i < arraysize(test_data); ++i) { | 182 for (size_t i = 0; i < arraysize(test_data); ++i) { |
183 ExtensionAPI api; | 183 ExtensionAPI api; |
184 api.RegisterDependencyProvider("api", &api_feature_provider); | 184 api.RegisterDependencyProvider("api", &api_feature_provider); |
185 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd(); | 185 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd(); |
186 iter.Advance()) { | 186 iter.Advance()) { |
187 if (iter.key().find(".") == std::string::npos) | 187 if (iter.key().find(".") == std::string::npos) |
188 api.RegisterSchemaResource(iter.key(), 0); | 188 api.RegisterSchemaResource(iter.key(), 0); |
189 } | 189 } |
190 | 190 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 .AppendASCII("extension_api_unittest") | 264 .AppendASCII("extension_api_unittest") |
265 .AppendASCII("api_features.json"); | 265 .AppendASCII("api_features.json"); |
266 | 266 |
267 std::string api_features_str; | 267 std::string api_features_str; |
268 ASSERT_TRUE(base::ReadFileToString( | 268 ASSERT_TRUE(base::ReadFileToString( |
269 api_features_path, &api_features_str)) << "api_features.json"; | 269 api_features_path, &api_features_str)) << "api_features.json"; |
270 | 270 |
271 std::unique_ptr<base::DictionaryValue> value( | 271 std::unique_ptr<base::DictionaryValue> value( |
272 static_cast<base::DictionaryValue*>( | 272 static_cast<base::DictionaryValue*>( |
273 base::JSONReader::Read(api_features_str).release())); | 273 base::JSONReader::Read(api_features_str).release())); |
274 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature); | 274 JSONFeatureProvider api_feature_provider(*value, CreateAPIFeature); |
275 | 275 |
276 for (size_t i = 0; i < arraysize(test_data); ++i) { | 276 for (size_t i = 0; i < arraysize(test_data); ++i) { |
277 ExtensionAPI api; | 277 ExtensionAPI api; |
278 api.RegisterDependencyProvider("api", &api_feature_provider); | 278 api.RegisterDependencyProvider("api", &api_feature_provider); |
279 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd(); | 279 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd(); |
280 iter.Advance()) { | 280 iter.Advance()) { |
281 if (iter.key().find(".") == std::string::npos) | 281 if (iter.key().find(".") == std::string::npos) |
282 api.RegisterSchemaResource(iter.key(), 0); | 282 api.RegisterSchemaResource(iter.key(), 0); |
283 } | 283 } |
284 | 284 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 | 694 |
695 struct { | 695 struct { |
696 base::DictionaryValue* api_features; | 696 base::DictionaryValue* api_features; |
697 bool expect_success; | 697 bool expect_success; |
698 } test_data[] = { | 698 } test_data[] = { |
699 { api_features1.get(), true }, | 699 { api_features1.get(), true }, |
700 { api_features2.get(), false } | 700 { api_features2.get(), false } |
701 }; | 701 }; |
702 | 702 |
703 for (size_t i = 0; i < arraysize(test_data); ++i) { | 703 for (size_t i = 0; i < arraysize(test_data); ++i) { |
704 BaseFeatureProvider api_feature_provider(*test_data[i].api_features, | 704 JSONFeatureProvider api_feature_provider(*test_data[i].api_features, |
705 CreateAPIFeature); | 705 CreateAPIFeature); |
706 Feature* feature = api_feature_provider.GetFeature("test"); | 706 Feature* feature = api_feature_provider.GetFeature("test"); |
707 EXPECT_EQ(test_data[i].expect_success, feature != NULL) << i; | 707 EXPECT_EQ(test_data[i].expect_success, feature != NULL) << i; |
708 } | 708 } |
709 } | 709 } |
710 | 710 |
711 static void GetDictionaryFromList(const base::DictionaryValue* schema, | 711 static void GetDictionaryFromList(const base::DictionaryValue* schema, |
712 const std::string& list_name, | 712 const std::string& list_name, |
713 const int list_index, | 713 const int list_index, |
714 const base::DictionaryValue** out) { | 714 const base::DictionaryValue** out) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 extension.get(), | 855 extension.get(), |
856 Feature::BLESSED_EXTENSION_CONTEXT, | 856 Feature::BLESSED_EXTENSION_CONTEXT, |
857 GURL()).is_available()); | 857 GURL()).is_available()); |
858 EXPECT_FALSE(extension_api->IsAvailable("pageAction", | 858 EXPECT_FALSE(extension_api->IsAvailable("pageAction", |
859 extension.get(), | 859 extension.get(), |
860 Feature::BLESSED_EXTENSION_CONTEXT, | 860 Feature::BLESSED_EXTENSION_CONTEXT, |
861 GURL()).is_available()); | 861 GURL()).is_available()); |
862 } | 862 } |
863 | 863 |
864 } // namespace extensions | 864 } // namespace extensions |
OLD | NEW |