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

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

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