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

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

Issue 12313142: Revert 184837 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 10 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
« no previous file with comments | « chrome/common/extensions/api/extension_api.cc ('k') | chrome/common/extensions/api/test.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 { 227 {
228 std::set<std::string> permissions; 228 std::set<std::string> permissions;
229 permissions.insert("storage"); 229 permissions.insert("storage");
230 permissions.insert("history"); 230 permissions.insert("history");
231 extension = CreateExtensionWithPermissions(permissions); 231 extension = CreateExtensionWithPermissions(permissions);
232 } 232 }
233 233
234 scoped_ptr<ExtensionAPI> extension_api( 234 scoped_ptr<ExtensionAPI> extension_api(
235 ExtensionAPI::CreateWithDefaultConfiguration()); 235 ExtensionAPI::CreateWithDefaultConfiguration());
236 236
237 std::set<std::string> privileged_apis = extension_api->GetAPIsForContext( 237 scoped_ptr<std::set<std::string> > privileged_apis =
238 Feature::BLESSED_EXTENSION_CONTEXT, extension.get(), GURL()); 238 extension_api->GetAPIsForContext(
239 Feature::BLESSED_EXTENSION_CONTEXT, extension.get(), GURL());
239 240
240 std::set<std::string> unprivileged_apis = extension_api->GetAPIsForContext( 241 scoped_ptr<std::set<std::string> > unprivileged_apis =
241 Feature::UNBLESSED_EXTENSION_CONTEXT, extension.get(), GURL()); 242 extension_api->GetAPIsForContext(
243 Feature::UNBLESSED_EXTENSION_CONTEXT, extension.get(), GURL());
242 244
243 std::set<std::string> content_script_apis = extension_api->GetAPIsForContext( 245 scoped_ptr<std::set<std::string> > content_script_apis =
244 Feature::CONTENT_SCRIPT_CONTEXT, extension.get(), GURL()); 246 extension_api->GetAPIsForContext(
247 Feature::CONTENT_SCRIPT_CONTEXT, extension.get(), GURL());
245 248
246 // "storage" is completely unprivileged. 249 // "storage" is completely unprivileged.
247 EXPECT_EQ(1u, privileged_apis.count("storage")); 250 EXPECT_EQ(1u, privileged_apis->count("storage"));
248 EXPECT_EQ(1u, unprivileged_apis.count("storage")); 251 EXPECT_EQ(1u, unprivileged_apis->count("storage"));
249 EXPECT_EQ(1u, content_script_apis.count("storage")); 252 EXPECT_EQ(1u, content_script_apis->count("storage"));
250 253
251 // "extension" is partially unprivileged. 254 // "extension" is partially unprivileged.
252 EXPECT_EQ(1u, privileged_apis.count("extension")); 255 EXPECT_EQ(1u, privileged_apis->count("extension"));
253 EXPECT_EQ(1u, unprivileged_apis.count("extension")); 256 EXPECT_EQ(1u, unprivileged_apis->count("extension"));
254 EXPECT_EQ(1u, content_script_apis.count("extension")); 257 EXPECT_EQ(1u, content_script_apis->count("extension"));
255 258
256 // "history" is entirely privileged. 259 // "history" is entirely privileged.
257 EXPECT_EQ(1u, privileged_apis.count("history")); 260 EXPECT_EQ(1u, privileged_apis->count("history"));
258 EXPECT_EQ(0u, unprivileged_apis.count("history")); 261 EXPECT_EQ(0u, unprivileged_apis->count("history"));
259 EXPECT_EQ(0u, content_script_apis.count("history")); 262 EXPECT_EQ(0u, content_script_apis->count("history"));
260 } 263 }
261 264
262 TEST(ExtensionAPI, ExtensionWithDependencies) { 265 TEST(ExtensionAPI, ExtensionWithDependencies) {
263 // Extension with the "ttsEngine" permission but not the "tts" permission; it 266 // Extension with the "ttsEngine" permission but not the "tts" permission; it
264 // must load TTS. 267 // must load TTS.
265 { 268 {
266 scoped_refptr<Extension> extension = 269 scoped_refptr<Extension> extension =
267 CreateExtensionWithPermission("ttsEngine"); 270 CreateExtensionWithPermission("ttsEngine");
268 scoped_ptr<ExtensionAPI> api( 271 scoped_ptr<ExtensionAPI> api(
269 ExtensionAPI::CreateWithDefaultConfiguration()); 272 ExtensionAPI::CreateWithDefaultConfiguration());
270 std::set<std::string> apis = api->GetAPIsForContext( 273 scoped_ptr<std::set<std::string> > apis = api->GetAPIsForContext(
271 Feature::BLESSED_EXTENSION_CONTEXT, extension.get(), GURL()); 274 Feature::BLESSED_EXTENSION_CONTEXT, extension.get(), GURL());
272 EXPECT_EQ(1u, apis.count("ttsEngine")); 275 EXPECT_EQ(1u, apis->count("ttsEngine"));
273 EXPECT_EQ(1u, apis.count("tts")); 276 EXPECT_EQ(1u, apis->count("tts"));
274 } 277 }
275 278
276 // Conversely, extension with the "tts" permission but not the "ttsEngine" 279 // Conversely, extension with the "tts" permission but not the "ttsEngine"
277 // permission shouldn't get the "ttsEngine" permission. 280 // permission shouldn't get the "ttsEngine" permission.
278 { 281 {
279 scoped_refptr<Extension> extension = 282 scoped_refptr<Extension> extension =
280 CreateExtensionWithPermission("tts"); 283 CreateExtensionWithPermission("tts");
281 scoped_ptr<ExtensionAPI> api( 284 scoped_ptr<ExtensionAPI> api(
282 ExtensionAPI::CreateWithDefaultConfiguration()); 285 ExtensionAPI::CreateWithDefaultConfiguration());
283 std::set<std::string> apis = api->GetAPIsForContext( 286 scoped_ptr<std::set<std::string> > apis = api->GetAPIsForContext(
284 Feature::BLESSED_EXTENSION_CONTEXT, extension.get(), GURL()); 287 Feature::BLESSED_EXTENSION_CONTEXT, extension.get(), GURL());
285 EXPECT_EQ(0u, apis.count("ttsEngine")); 288 EXPECT_EQ(0u, apis->count("ttsEngine"));
286 EXPECT_EQ(1u, apis.count("tts")); 289 EXPECT_EQ(1u, apis->count("tts"));
287 } 290 }
288 } 291 }
289 292
290 bool MatchesURL( 293 bool MatchesURL(
291 ExtensionAPI* api, const std::string& api_name, const std::string& url) { 294 ExtensionAPI* api, const std::string& api_name, const std::string& url) {
292 std::set<std::string> apis = 295 scoped_ptr<std::set<std::string> > apis =
293 api->GetAPIsForContext(Feature::WEB_PAGE_CONTEXT, NULL, GURL(url)); 296 api->GetAPIsForContext(Feature::WEB_PAGE_CONTEXT, NULL, GURL(url));
294 return apis.count(api_name); 297 return apis->count(api_name);
295 } 298 }
296 299
297 TEST(ExtensionAPI, URLMatching) { 300 TEST(ExtensionAPI, URLMatching) {
298 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); 301 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration());
299 302
300 // "app" API is available to all URLs that content scripts can be injected. 303 // "app" API is available to all URLs that content scripts can be injected.
301 EXPECT_TRUE(MatchesURL(api.get(), "app", "http://example.com/example.html")); 304 EXPECT_TRUE(MatchesURL(api.get(), "app", "http://example.com/example.html"));
302 EXPECT_TRUE(MatchesURL(api.get(), "app", "https://blah.net")); 305 EXPECT_TRUE(MatchesURL(api.get(), "app", "https://blah.net"));
303 EXPECT_TRUE(MatchesURL(api.get(), "app", "file://somefile.html")); 306 EXPECT_TRUE(MatchesURL(api.get(), "app", "file://somefile.html"));
304 307
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); 483 GetDictionaryFromList(dict, "parameters", 0, &sub_dict);
481 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); 484 EXPECT_TRUE(sub_dict->GetString("$ref", &type));
482 EXPECT_EQ("test.foo.TestType", type); 485 EXPECT_EQ("test.foo.TestType", type);
483 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); 486 GetDictionaryFromList(dict, "parameters", 1, &sub_dict);
484 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); 487 EXPECT_TRUE(sub_dict->GetString("$ref", &type));
485 EXPECT_EQ("fully.qualified.Type", type); 488 EXPECT_EQ("fully.qualified.Type", type);
486 } 489 }
487 490
488 } // namespace 491 } // namespace
489 } // namespace extensions 492 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/extension_api.cc ('k') | chrome/common/extensions/api/test.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698