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

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

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

Powered by Google App Engine
This is Rietveld 408576698