Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: chrome/common/extensions/api/extension_api_unittest.cc

Issue 14494013: Allow API functions and events to have entries in _api_features.json (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 } 87 }
88 88
89 TEST_F(ExtensionAPITest, IsPrivileged) { 89 TEST_F(ExtensionAPITest, IsPrivileged) {
90 scoped_ptr<ExtensionAPI> extension_api( 90 scoped_ptr<ExtensionAPI> extension_api(
91 ExtensionAPI::CreateWithDefaultConfiguration()); 91 ExtensionAPI::CreateWithDefaultConfiguration());
92 92
93 EXPECT_FALSE(extension_api->IsPrivileged("runtime.connect")); 93 EXPECT_FALSE(extension_api->IsPrivileged("runtime.connect"));
94 EXPECT_FALSE(extension_api->IsPrivileged("runtime.onConnect")); 94 EXPECT_FALSE(extension_api->IsPrivileged("runtime.onConnect"));
95 95
96 // Properties are not supported yet.
97 EXPECT_TRUE(extension_api->IsPrivileged("runtime.lastError"));
not at google - send to devlin 2013/04/27 01:02:43 change to EXPECT_FALSE?
cduvall 2013/05/01 02:51:47 Done.
98
99 // Default unknown names to privileged for paranoia's sake. 96 // Default unknown names to privileged for paranoia's sake.
100 EXPECT_TRUE(extension_api->IsPrivileged(std::string())); 97 EXPECT_TRUE(extension_api->IsPrivileged(std::string()));
101 EXPECT_TRUE(extension_api->IsPrivileged("<unknown-namespace>")); 98 EXPECT_TRUE(extension_api->IsPrivileged("<unknown-namespace>"));
102 EXPECT_TRUE(extension_api->IsPrivileged("extension.<unknown-member>")); 99 EXPECT_TRUE(extension_api->IsPrivileged("extension.<unknown-member>"));
103 100
104 // Exists, but privileged. 101 // Exists, but privileged.
105 EXPECT_TRUE(extension_api->IsPrivileged("extension.getViews")); 102 EXPECT_TRUE(extension_api->IsPrivileged("extension.getViews"));
106 EXPECT_TRUE(extension_api->IsPrivileged("history.search")); 103 EXPECT_TRUE(extension_api->IsPrivileged("history.search"));
107 104
108 // Whole APIs that are unprivileged. 105 // Whole APIs that are unprivileged.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 215 }
219 216
220 EXPECT_EQ(test_data[i].expect_is_available, 217 EXPECT_EQ(test_data[i].expect_is_available,
221 api.IsAvailable(test_data[i].api_full_name, 218 api.IsAvailable(test_data[i].api_full_name,
222 NULL, 219 NULL,
223 test_data[i].context, 220 test_data[i].context,
224 test_data[i].url).is_available()) << i; 221 test_data[i].url).is_available()) << i;
225 } 222 }
226 } 223 }
227 224
225 TEST(ExtensionAPI, IsPartAvailableToContext) {
226 struct {
227 std::string api_full_name;
228 bool expect_is_available;
229 Feature::Context context;
230 GURL url;
231 } test_data[] = {
232 { "test1", false, Feature::WEB_PAGE_CONTEXT, GURL() },
233 { "test1", true, Feature::UNBLESSED_EXTENSION_CONTEXT, GURL() },
234 { "test2", true, Feature::CONTENT_SCRIPT_CONTEXT, GURL() },
235 { "test2", true, Feature::WEB_PAGE_CONTEXT, GURL("http://google.com") },
236 { "test2.foo", false, Feature::WEB_PAGE_CONTEXT,
237 GURL("http://google.com") },
238 { "test3", true, Feature::CONTENT_SCRIPT_CONTEXT, GURL() },
239 { "test3", true, Feature::WEB_PAGE_CONTEXT, GURL("http://foo.com") },
240 { "test4.foo", true, Feature::CONTENT_SCRIPT_CONTEXT, GURL() },
241 { "test7", false, Feature::WEB_PAGE_CONTEXT, GURL("http://google.com") },
242 { "test7", true, Feature::WEB_PAGE_CONTEXT, GURL("http://foo.com") },
243 { "test7", false, Feature::WEB_PAGE_CONTEXT, GURL("http://bar.com") }
244 };
245
246 base::FilePath api_features_path;
247 PathService::Get(chrome::DIR_TEST_DATA, &api_features_path);
248 api_features_path = api_features_path.AppendASCII("extensions")
249 .AppendASCII("extension_api_unittest")
250 .AppendASCII("api_features.json");
251
252 std::string api_features_str;
253 ASSERT_TRUE(file_util::ReadFileToString(
254 api_features_path, &api_features_str)) << "api_features.json";
255
256 scoped_ptr<base::DictionaryValue> value(static_cast<DictionaryValue*>(
257 base::JSONReader::Read(api_features_str)));
258 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature);
259
260 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
261 ExtensionAPI api;
262 api.RegisterDependencyProvider("api", &api_feature_provider);
263 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd();
264 iter.Advance()) {
265 if (iter.key().find(".") == std::string::npos)
266 api.RegisterSchema(iter.key(), "");
267 }
268
269 EXPECT_EQ(test_data[i].expect_is_available,
270 api.IsPartAvailableToContext(
271 test_data[i].api_full_name,
272 test_data[i].context,
273 test_data[i].url).is_available()) << i;
274 }
275 }
276
228 TEST_F(ExtensionAPITest, LazyGetSchema) { 277 TEST_F(ExtensionAPITest, LazyGetSchema) {
229 scoped_ptr<ExtensionAPI> apis(ExtensionAPI::CreateWithDefaultConfiguration()); 278 scoped_ptr<ExtensionAPI> apis(ExtensionAPI::CreateWithDefaultConfiguration());
230 279
231 EXPECT_EQ(NULL, apis->GetSchema(std::string())); 280 EXPECT_EQ(NULL, apis->GetSchema(std::string()));
232 EXPECT_EQ(NULL, apis->GetSchema(std::string())); 281 EXPECT_EQ(NULL, apis->GetSchema(std::string()));
233 EXPECT_EQ(NULL, apis->GetSchema("experimental")); 282 EXPECT_EQ(NULL, apis->GetSchema("experimental"));
234 EXPECT_EQ(NULL, apis->GetSchema("experimental")); 283 EXPECT_EQ(NULL, apis->GetSchema("experimental"));
235 EXPECT_EQ(NULL, apis->GetSchema("foo")); 284 EXPECT_EQ(NULL, apis->GetSchema("foo"));
236 EXPECT_EQ(NULL, apis->GetSchema("foo")); 285 EXPECT_EQ(NULL, apis->GetSchema("foo"));
237 286
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); 606 GetDictionaryFromList(dict, "parameters", 0, &sub_dict);
558 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); 607 EXPECT_TRUE(sub_dict->GetString("$ref", &type));
559 EXPECT_EQ("test.foo.TestType", type); 608 EXPECT_EQ("test.foo.TestType", type);
560 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); 609 GetDictionaryFromList(dict, "parameters", 1, &sub_dict);
561 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); 610 EXPECT_TRUE(sub_dict->GetString("$ref", &type));
562 EXPECT_EQ("fully.qualified.Type", type); 611 EXPECT_EQ("fully.qualified.Type", type);
563 } 612 }
564 613
565 } // namespace 614 } // namespace
566 } // namespace extensions 615 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698