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

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

Issue 10025007: Convert tabs, windows, and extension APIs to feature system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blah Created 8 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_path.h" 10 #include "base/file_path.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 } 93 }
94 94
95 TEST(ExtensionAPI, IsPrivileged) { 95 TEST(ExtensionAPI, IsPrivileged) {
96 scoped_ptr<ExtensionAPI> extension_api( 96 scoped_ptr<ExtensionAPI> extension_api(
97 ExtensionAPI::CreateWithDefaultConfiguration()); 97 ExtensionAPI::CreateWithDefaultConfiguration());
98 98
99 EXPECT_FALSE(extension_api->IsPrivileged("extension.connect")); 99 EXPECT_FALSE(extension_api->IsPrivileged("extension.connect"));
100 EXPECT_FALSE(extension_api->IsPrivileged("extension.onConnect")); 100 EXPECT_FALSE(extension_api->IsPrivileged("extension.onConnect"));
101 101
102 // Properties are not supported yet. 102 // Properties are not supported yet, but the default for this module is
103 EXPECT_TRUE(extension_api->IsPrivileged("extension.lastError")); 103 // unprivileged, so that's what we see.
104 EXPECT_FALSE(extension_api->IsPrivileged("extension.lastError"));
104 105
105 // Default unknown names to privileged for paranoia's sake. 106 // Default unknown modules to privileged for paranoia's sake.
106 EXPECT_TRUE(extension_api->IsPrivileged("")); 107 EXPECT_TRUE(extension_api->IsPrivileged(""));
107 EXPECT_TRUE(extension_api->IsPrivileged("<unknown-namespace>")); 108 EXPECT_TRUE(extension_api->IsPrivileged("<unknown-namespace>"));
108 EXPECT_TRUE(extension_api->IsPrivileged("extension.<unknown-member>")); 109
110 // Default unknown names within a module to the parent's value.
111 EXPECT_FALSE(extension_api->IsPrivileged("extension.<unknown-member>"));
109 112
110 // Exists, but privileged. 113 // Exists, but privileged.
111 EXPECT_TRUE(extension_api->IsPrivileged("extension.getViews")); 114 EXPECT_TRUE(extension_api->IsPrivileged("extension.getViews"));
112 EXPECT_TRUE(extension_api->IsPrivileged("history.search")); 115 EXPECT_TRUE(extension_api->IsPrivileged("history.search"));
113 116
114 // Whole APIs that are unprivileged. 117 // Whole APIs that are unprivileged.
115 EXPECT_FALSE(extension_api->IsPrivileged("app.getDetails")); 118 EXPECT_FALSE(extension_api->IsPrivileged("app.getDetails"));
116 EXPECT_FALSE(extension_api->IsPrivileged("app.isInstalled")); 119 EXPECT_FALSE(extension_api->IsPrivileged("app.isInstalled"));
117 EXPECT_FALSE(extension_api->IsPrivileged("storage.local")); 120 EXPECT_FALSE(extension_api->IsPrivileged("storage.local"));
118 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.onChanged")); 121 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.onChanged"));
119 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.set")); 122 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.set"));
120 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.MAX_ITEMS")); 123 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.MAX_ITEMS"));
121 EXPECT_FALSE(extension_api->IsPrivileged("storage.set")); 124 EXPECT_FALSE(extension_api->IsPrivileged("storage.set"));
122 } 125 }
123 126
124 TEST(ExtensionAPI, IsPrivilegedFeatures) { 127 TEST(ExtensionAPI, IsPrivilegedFeatures) {
125 struct { 128 struct {
126 std::string filename; 129 std::string filename;
127 std::string api_full_name; 130 std::string api_full_name;
128 bool expect_is_privilged; 131 bool expect_is_privilged;
129 Feature::Context test2_contexts; 132 Feature::Context test2_contexts;
130 } test_data[] = { 133 } test_data[] = {
131 { "is_privileged_features_1.json", "test", false, 134 { "is_privileged_features_1.json", "test", false,
132 Feature::UNSPECIFIED_CONTEXT }, 135 Feature::UNSPECIFIED_CONTEXT },
133 { "is_privileged_features_2.json", "test", true, 136 { "is_privileged_features_2.json", "test", true,
134 Feature::UNSPECIFIED_CONTEXT }, 137 Feature::UNSPECIFIED_CONTEXT },
135 { "is_privileged_features_3.json", "test", false, 138 { "is_privileged_features_3.json", "test", false,
136 Feature::UNSPECIFIED_CONTEXT }, 139 Feature::UNSPECIFIED_CONTEXT },
137 { "is_privileged_features_4.json", "test.bar", false, 140 { "is_privileged_features_5.json", "test.bar", true,
141 Feature::BLESSED_EXTENSION_CONTEXT },
142 // These are privileged because a child always depends on its parent. So
143 // even if the child is more permissive than its parent, it still ends up
144 // having the same requirements.
145 { "is_privileged_features_4.json", "test.bar", true,
138 Feature::UNSPECIFIED_CONTEXT }, 146 Feature::UNSPECIFIED_CONTEXT },
139 { "is_privileged_features_5.json", "test.bar", true, 147 { "is_privileged_features_5.json", "test.bar", true,
140 Feature::BLESSED_EXTENSION_CONTEXT },
141 { "is_privileged_features_5.json", "test.bar", false,
142 Feature::UNBLESSED_EXTENSION_CONTEXT } 148 Feature::UNBLESSED_EXTENSION_CONTEXT }
143 }; 149 };
144 150
145 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 151 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
146 FilePath manifest_path; 152 FilePath manifest_path;
147 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path); 153 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path);
148 manifest_path = manifest_path.AppendASCII("extensions") 154 manifest_path = manifest_path.AppendASCII("extensions")
149 .AppendASCII("extension_api_unittest") 155 .AppendASCII("extension_api_unittest")
150 .AppendASCII(test_data[i].filename); 156 .AppendASCII(test_data[i].filename);
151 157
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); 349 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration());
344 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 350 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
345 std::string child_name; 351 std::string child_name;
346 std::string api_name = api->GetAPINameFromFullName(test_data[i].input, 352 std::string api_name = api->GetAPINameFromFullName(test_data[i].input,
347 &child_name); 353 &child_name);
348 EXPECT_EQ(test_data[i].api_name, api_name) << test_data[i].input; 354 EXPECT_EQ(test_data[i].api_name, api_name) << test_data[i].input;
349 EXPECT_EQ(test_data[i].child_name, child_name) << test_data[i].input; 355 EXPECT_EQ(test_data[i].child_name, child_name) << test_data[i].input;
350 } 356 }
351 } 357 }
352 358
353 TEST(ExtensionAPI, DefaultConfigurationFeatures) {
354 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration());
355
356 Feature* bookmarks = api->GetFeature("bookmarks");
357 Feature* bookmarks_create = api->GetFeature("bookmarks.create");
358
359 struct {
360 Feature* feature;
361 // TODO(aa): More stuff to test over time.
362 } test_data[] = {
363 { bookmarks },
364 { bookmarks_create }
365 };
366
367 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
368 Feature* feature = test_data[i].feature;
369 ASSERT_TRUE(feature) << i;
370
371 EXPECT_TRUE(feature->whitelist()->empty());
372 EXPECT_TRUE(feature->extension_types()->empty());
373
374 EXPECT_EQ(1u, feature->contexts()->size());
375 EXPECT_TRUE(feature->contexts()->count(
376 Feature::BLESSED_EXTENSION_CONTEXT));
377
378 EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location());
379 EXPECT_EQ(Feature::UNSPECIFIED_PLATFORM, feature->platform());
380 EXPECT_EQ(0, feature->min_manifest_version());
381 EXPECT_EQ(0, feature->max_manifest_version());
382 }
383 }
384
385 TEST(ExtensionAPI, FeaturesRequireContexts) {
386 scoped_ptr<ListValue> schema1(new ListValue());
387 DictionaryValue* feature_definition = new DictionaryValue();
388 schema1->Append(feature_definition);
389 feature_definition->SetString("namespace", "test");
390 feature_definition->SetBoolean("uses_feature_system", true);
391
392 scoped_ptr<ListValue> schema2(schema1->DeepCopy());
393
394 ListValue* contexts = new ListValue();
395 contexts->Append(Value::CreateStringValue("content_script"));
396 feature_definition->Set("contexts", contexts);
397
398 struct {
399 ListValue* schema;
400 bool expect_success;
401 } test_data[] = {
402 { schema1.get(), true },
403 { schema2.get(), false }
404 };
405
406 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
407 std::string schema_source;
408 base::JSONWriter::Write(test_data[i].schema, &schema_source);
409
410 ExtensionAPI api;
411 api.RegisterSchema("test", base::StringPiece(schema_source));
412 api.LoadAllSchemas();
413
414 Feature* feature = api.GetFeature("test");
415 EXPECT_EQ(test_data[i].expect_success, feature != NULL) << i;
416 }
417 }
418
419 } // namespace 359 } // namespace
420 } // namespace extensions 360 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/extension_api_feature_unittest.cc ('k') | chrome/common/extensions/api/tabs.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698