| 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 "chrome/common/extensions/api/extension_api.h" | 5 #include "chrome/common/extensions/api/extension_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 { "test4", false } | 125 { "test4", false } |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 base::FilePath api_features_path; | 128 base::FilePath api_features_path; |
| 129 PathService::Get(chrome::DIR_TEST_DATA, &api_features_path); | 129 PathService::Get(chrome::DIR_TEST_DATA, &api_features_path); |
| 130 api_features_path = api_features_path.AppendASCII("extensions") | 130 api_features_path = api_features_path.AppendASCII("extensions") |
| 131 .AppendASCII("extension_api_unittest") | 131 .AppendASCII("extension_api_unittest") |
| 132 .AppendASCII("privileged_api_features.json"); | 132 .AppendASCII("privileged_api_features.json"); |
| 133 | 133 |
| 134 std::string api_features_str; | 134 std::string api_features_str; |
| 135 ASSERT_TRUE(file_util::ReadFileToString( | 135 ASSERT_TRUE(base::ReadFileToString( |
| 136 api_features_path, &api_features_str)) << "privileged_api_features.json"; | 136 api_features_path, &api_features_str)) << "privileged_api_features.json"; |
| 137 | 137 |
| 138 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>( | 138 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>( |
| 139 base::JSONReader::Read(api_features_str))); | 139 base::JSONReader::Read(api_features_str))); |
| 140 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature); | 140 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature); |
| 141 | 141 |
| 142 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 142 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 143 ExtensionAPI api; | 143 ExtensionAPI api; |
| 144 api.RegisterDependencyProvider("api", &api_feature_provider); | 144 api.RegisterDependencyProvider("api", &api_feature_provider); |
| 145 EXPECT_EQ(test_data[i].expect_is_privilged, | 145 EXPECT_EQ(test_data[i].expect_is_privilged, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 GURL() } | 221 GURL() } |
| 222 }; | 222 }; |
| 223 | 223 |
| 224 base::FilePath api_features_path; | 224 base::FilePath api_features_path; |
| 225 PathService::Get(chrome::DIR_TEST_DATA, &api_features_path); | 225 PathService::Get(chrome::DIR_TEST_DATA, &api_features_path); |
| 226 api_features_path = api_features_path.AppendASCII("extensions") | 226 api_features_path = api_features_path.AppendASCII("extensions") |
| 227 .AppendASCII("extension_api_unittest") | 227 .AppendASCII("extension_api_unittest") |
| 228 .AppendASCII("api_features.json"); | 228 .AppendASCII("api_features.json"); |
| 229 | 229 |
| 230 std::string api_features_str; | 230 std::string api_features_str; |
| 231 ASSERT_TRUE(file_util::ReadFileToString( | 231 ASSERT_TRUE(base::ReadFileToString( |
| 232 api_features_path, &api_features_str)) << "api_features.json"; | 232 api_features_path, &api_features_str)) << "api_features.json"; |
| 233 | 233 |
| 234 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>( | 234 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>( |
| 235 base::JSONReader::Read(api_features_str))); | 235 base::JSONReader::Read(api_features_str))); |
| 236 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature); | 236 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature); |
| 237 | 237 |
| 238 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 238 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 239 ExtensionAPI api; | 239 ExtensionAPI api; |
| 240 api.RegisterDependencyProvider("api", &api_feature_provider); | 240 api.RegisterDependencyProvider("api", &api_feature_provider); |
| 241 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd(); | 241 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 { "test7", false, Feature::WEB_PAGE_CONTEXT, NULL, GURL("http://bar.com") } | 293 { "test7", false, Feature::WEB_PAGE_CONTEXT, NULL, GURL("http://bar.com") } |
| 294 }; | 294 }; |
| 295 | 295 |
| 296 base::FilePath api_features_path; | 296 base::FilePath api_features_path; |
| 297 PathService::Get(chrome::DIR_TEST_DATA, &api_features_path); | 297 PathService::Get(chrome::DIR_TEST_DATA, &api_features_path); |
| 298 api_features_path = api_features_path.AppendASCII("extensions") | 298 api_features_path = api_features_path.AppendASCII("extensions") |
| 299 .AppendASCII("extension_api_unittest") | 299 .AppendASCII("extension_api_unittest") |
| 300 .AppendASCII("api_features.json"); | 300 .AppendASCII("api_features.json"); |
| 301 | 301 |
| 302 std::string api_features_str; | 302 std::string api_features_str; |
| 303 ASSERT_TRUE(file_util::ReadFileToString( | 303 ASSERT_TRUE(base::ReadFileToString( |
| 304 api_features_path, &api_features_str)) << "api_features.json"; | 304 api_features_path, &api_features_str)) << "api_features.json"; |
| 305 | 305 |
| 306 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>( | 306 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>( |
| 307 base::JSONReader::Read(api_features_str))); | 307 base::JSONReader::Read(api_features_str))); |
| 308 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature); | 308 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature); |
| 309 | 309 |
| 310 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 310 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 311 ExtensionAPI api; | 311 ExtensionAPI api; |
| 312 api.RegisterDependencyProvider("api", &api_feature_provider); | 312 api.RegisterDependencyProvider("api", &api_feature_provider); |
| 313 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd(); | 313 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd(); |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 } | 767 } |
| 768 | 768 |
| 769 TEST(ExtensionAPITest, TypesHaveNamespace) { | 769 TEST(ExtensionAPITest, TypesHaveNamespace) { |
| 770 base::FilePath manifest_path; | 770 base::FilePath manifest_path; |
| 771 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path); | 771 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path); |
| 772 manifest_path = manifest_path.AppendASCII("extensions") | 772 manifest_path = manifest_path.AppendASCII("extensions") |
| 773 .AppendASCII("extension_api_unittest") | 773 .AppendASCII("extension_api_unittest") |
| 774 .AppendASCII("types_have_namespace.json"); | 774 .AppendASCII("types_have_namespace.json"); |
| 775 | 775 |
| 776 std::string manifest_str; | 776 std::string manifest_str; |
| 777 ASSERT_TRUE(file_util::ReadFileToString(manifest_path, &manifest_str)) | 777 ASSERT_TRUE(base::ReadFileToString(manifest_path, &manifest_str)) |
| 778 << "Failed to load: " << manifest_path.value(); | 778 << "Failed to load: " << manifest_path.value(); |
| 779 | 779 |
| 780 ExtensionAPI api; | 780 ExtensionAPI api; |
| 781 api.RegisterSchemaResource("test.foo", 0); | 781 api.RegisterSchemaResource("test.foo", 0); |
| 782 api.LoadSchema("test.foo", manifest_str); | 782 api.LoadSchema("test.foo", manifest_str); |
| 783 | 783 |
| 784 const base::DictionaryValue* schema = api.GetSchema("test.foo"); | 784 const base::DictionaryValue* schema = api.GetSchema("test.foo"); |
| 785 | 785 |
| 786 const base::DictionaryValue* dict; | 786 const base::DictionaryValue* dict; |
| 787 const base::DictionaryValue* sub_dict; | 787 const base::DictionaryValue* sub_dict; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 extension.get(), | 903 extension.get(), |
| 904 Feature::BLESSED_EXTENSION_CONTEXT, | 904 Feature::BLESSED_EXTENSION_CONTEXT, |
| 905 GURL()).is_available()); | 905 GURL()).is_available()); |
| 906 EXPECT_FALSE(extension_api->IsAvailable("pageAction", | 906 EXPECT_FALSE(extension_api->IsAvailable("pageAction", |
| 907 extension.get(), | 907 extension.get(), |
| 908 Feature::BLESSED_EXTENSION_CONTEXT, | 908 Feature::BLESSED_EXTENSION_CONTEXT, |
| 909 GURL()).is_available()); | 909 GURL()).is_available()); |
| 910 } | 910 } |
| 911 | 911 |
| 912 } // namespace extensions | 912 } // namespace extensions |
| OLD | NEW |