| OLD | NEW |
| 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" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_unittest.h" | |
| 22 #include "chrome/common/extensions/features/api_feature.h" | 21 #include "chrome/common/extensions/features/api_feature.h" |
| 23 #include "chrome/common/extensions/features/base_feature_provider.h" | 22 #include "chrome/common/extensions/features/base_feature_provider.h" |
| 24 #include "chrome/common/extensions/features/simple_feature.h" | 23 #include "chrome/common/extensions/features/simple_feature.h" |
| 25 #include "chrome/common/extensions/manifest.h" | 24 #include "chrome/common/extensions/manifest.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 26 |
| 28 namespace extensions { | 27 namespace extensions { |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 SimpleFeature* CreateAPIFeature() { | 30 SimpleFeature* CreateAPIFeature() { |
| 32 return new APIFeature(); | 31 return new APIFeature(); |
| 33 } | 32 } |
| 34 | 33 |
| 35 class ExtensionAPITest : public ExtensionTest { | 34 TEST(ExtensionAPITest, Creation) { |
| 36 }; | |
| 37 | |
| 38 TEST_F(ExtensionAPITest, Creation) { | |
| 39 ExtensionAPI* shared_instance = ExtensionAPI::GetSharedInstance(); | 35 ExtensionAPI* shared_instance = ExtensionAPI::GetSharedInstance(); |
| 40 EXPECT_EQ(shared_instance, ExtensionAPI::GetSharedInstance()); | 36 EXPECT_EQ(shared_instance, ExtensionAPI::GetSharedInstance()); |
| 41 | 37 |
| 42 scoped_ptr<ExtensionAPI> new_instance( | 38 scoped_ptr<ExtensionAPI> new_instance( |
| 43 ExtensionAPI::CreateWithDefaultConfiguration()); | 39 ExtensionAPI::CreateWithDefaultConfiguration()); |
| 44 EXPECT_NE(new_instance.get(), | 40 EXPECT_NE(new_instance.get(), |
| 45 scoped_ptr<ExtensionAPI>( | 41 scoped_ptr<ExtensionAPI>( |
| 46 ExtensionAPI::CreateWithDefaultConfiguration()).get()); | 42 ExtensionAPI::CreateWithDefaultConfiguration()).get()); |
| 47 | 43 |
| 48 ExtensionAPI empty_instance; | 44 ExtensionAPI empty_instance; |
| 49 | 45 |
| 50 struct { | 46 struct { |
| 51 ExtensionAPI* api; | 47 ExtensionAPI* api; |
| 52 bool expect_populated; | 48 bool expect_populated; |
| 53 } test_data[] = { | 49 } test_data[] = { |
| 54 { shared_instance, true }, | 50 { shared_instance, true }, |
| 55 { new_instance.get(), true }, | 51 { new_instance.get(), true }, |
| 56 { &empty_instance, false } | 52 { &empty_instance, false } |
| 57 }; | 53 }; |
| 58 | 54 |
| 59 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 55 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 60 EXPECT_EQ(test_data[i].expect_populated, | 56 EXPECT_EQ(test_data[i].expect_populated, |
| 61 test_data[i].api->GetSchema("bookmarks.create") != NULL); | 57 test_data[i].api->GetSchema("bookmarks.create") != NULL); |
| 62 } | 58 } |
| 63 } | 59 } |
| 64 | 60 |
| 65 TEST_F(ExtensionAPITest, SplitDependencyName) { | 61 TEST(ExtensionAPITest, SplitDependencyName) { |
| 66 struct { | 62 struct { |
| 67 std::string input; | 63 std::string input; |
| 68 std::string expected_feature_type; | 64 std::string expected_feature_type; |
| 69 std::string expected_feature_name; | 65 std::string expected_feature_name; |
| 70 } test_data[] = { | 66 } test_data[] = { |
| 71 { "", "api", "" }, // assumes "api" when no type is present | 67 { "", "api", "" }, // assumes "api" when no type is present |
| 72 { "foo", "api", "foo" }, | 68 { "foo", "api", "foo" }, |
| 73 { "foo:", "foo", "" }, | 69 { "foo:", "foo", "" }, |
| 74 { ":foo", "", "foo" }, | 70 { ":foo", "", "foo" }, |
| 75 { "foo:bar", "foo", "bar" }, | 71 { "foo:bar", "foo", "bar" }, |
| 76 { "foo:bar.baz", "foo", "bar.baz" } | 72 { "foo:bar.baz", "foo", "bar.baz" } |
| 77 }; | 73 }; |
| 78 | 74 |
| 79 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 75 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 80 std::string feature_type; | 76 std::string feature_type; |
| 81 std::string feature_name; | 77 std::string feature_name; |
| 82 ExtensionAPI::SplitDependencyName(test_data[i].input, &feature_type, | 78 ExtensionAPI::SplitDependencyName(test_data[i].input, &feature_type, |
| 83 &feature_name); | 79 &feature_name); |
| 84 EXPECT_EQ(test_data[i].expected_feature_type, feature_type) << i; | 80 EXPECT_EQ(test_data[i].expected_feature_type, feature_type) << i; |
| 85 EXPECT_EQ(test_data[i].expected_feature_name, feature_name) << i; | 81 EXPECT_EQ(test_data[i].expected_feature_name, feature_name) << i; |
| 86 } | 82 } |
| 87 } | 83 } |
| 88 | 84 |
| 89 TEST_F(ExtensionAPITest, IsPrivileged) { | 85 TEST(ExtensionAPITest, IsPrivileged) { |
| 90 scoped_ptr<ExtensionAPI> extension_api( | 86 scoped_ptr<ExtensionAPI> extension_api( |
| 91 ExtensionAPI::CreateWithDefaultConfiguration()); | 87 ExtensionAPI::CreateWithDefaultConfiguration()); |
| 92 | 88 |
| 93 EXPECT_FALSE(extension_api->IsPrivileged("runtime.connect")); | 89 EXPECT_FALSE(extension_api->IsPrivileged("runtime.connect")); |
| 94 EXPECT_FALSE(extension_api->IsPrivileged("runtime.onConnect")); | 90 EXPECT_FALSE(extension_api->IsPrivileged("runtime.onConnect")); |
| 95 | 91 |
| 96 // Properties are not supported yet. | 92 // Properties are not supported yet. |
| 97 EXPECT_TRUE(extension_api->IsPrivileged("runtime.lastError")); | 93 EXPECT_TRUE(extension_api->IsPrivileged("runtime.lastError")); |
| 98 | 94 |
| 99 // Default unknown names to privileged for paranoia's sake. | 95 // Default unknown names to privileged for paranoia's sake. |
| 100 EXPECT_TRUE(extension_api->IsPrivileged(std::string())); | 96 EXPECT_TRUE(extension_api->IsPrivileged(std::string())); |
| 101 EXPECT_TRUE(extension_api->IsPrivileged("<unknown-namespace>")); | 97 EXPECT_TRUE(extension_api->IsPrivileged("<unknown-namespace>")); |
| 102 EXPECT_TRUE(extension_api->IsPrivileged("extension.<unknown-member>")); | 98 EXPECT_TRUE(extension_api->IsPrivileged("extension.<unknown-member>")); |
| 103 | 99 |
| 104 // Exists, but privileged. | 100 // Exists, but privileged. |
| 105 EXPECT_TRUE(extension_api->IsPrivileged("extension.getViews")); | 101 EXPECT_TRUE(extension_api->IsPrivileged("extension.getViews")); |
| 106 EXPECT_TRUE(extension_api->IsPrivileged("history.search")); | 102 EXPECT_TRUE(extension_api->IsPrivileged("history.search")); |
| 107 | 103 |
| 108 // Whole APIs that are unprivileged. | 104 // Whole APIs that are unprivileged. |
| 109 EXPECT_FALSE(extension_api->IsPrivileged("app.getDetails")); | 105 EXPECT_FALSE(extension_api->IsPrivileged("app.getDetails")); |
| 110 EXPECT_FALSE(extension_api->IsPrivileged("app.isInstalled")); | 106 EXPECT_FALSE(extension_api->IsPrivileged("app.isInstalled")); |
| 111 EXPECT_FALSE(extension_api->IsPrivileged("storage.local")); | 107 EXPECT_FALSE(extension_api->IsPrivileged("storage.local")); |
| 112 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.onChanged")); | 108 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.onChanged")); |
| 113 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.set")); | 109 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.set")); |
| 114 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.MAX_ITEMS")); | 110 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.MAX_ITEMS")); |
| 115 EXPECT_FALSE(extension_api->IsPrivileged("storage.set")); | 111 EXPECT_FALSE(extension_api->IsPrivileged("storage.set")); |
| 116 } | 112 } |
| 117 | 113 |
| 118 TEST_F(ExtensionAPITest, IsPrivilegedFeatures) { | 114 TEST(ExtensionAPITest, IsPrivilegedFeatures) { |
| 119 struct { | 115 struct { |
| 120 std::string api_full_name; | 116 std::string api_full_name; |
| 121 bool expect_is_privilged; | 117 bool expect_is_privilged; |
| 122 } test_data[] = { | 118 } test_data[] = { |
| 123 { "test1", false }, | 119 { "test1", false }, |
| 124 { "test1.foo", true }, | 120 { "test1.foo", true }, |
| 125 { "test2", true }, | 121 { "test2", true }, |
| 126 { "test2.foo", false }, | 122 { "test2.foo", false }, |
| 127 { "test2.bar", false }, | 123 { "test2.bar", false }, |
| 128 { "test2.baz", true }, | 124 { "test2.baz", true }, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 214 } |
| 219 | 215 |
| 220 EXPECT_EQ(test_data[i].expect_is_available, | 216 EXPECT_EQ(test_data[i].expect_is_available, |
| 221 api.IsAvailable(test_data[i].api_full_name, | 217 api.IsAvailable(test_data[i].api_full_name, |
| 222 NULL, | 218 NULL, |
| 223 test_data[i].context, | 219 test_data[i].context, |
| 224 test_data[i].url).is_available()) << i; | 220 test_data[i].url).is_available()) << i; |
| 225 } | 221 } |
| 226 } | 222 } |
| 227 | 223 |
| 228 TEST_F(ExtensionAPITest, LazyGetSchema) { | 224 TEST(ExtensionAPITest, LazyGetSchema) { |
| 229 scoped_ptr<ExtensionAPI> apis(ExtensionAPI::CreateWithDefaultConfiguration()); | 225 scoped_ptr<ExtensionAPI> apis(ExtensionAPI::CreateWithDefaultConfiguration()); |
| 230 | 226 |
| 231 EXPECT_EQ(NULL, apis->GetSchema(std::string())); | 227 EXPECT_EQ(NULL, apis->GetSchema(std::string())); |
| 232 EXPECT_EQ(NULL, apis->GetSchema(std::string())); | 228 EXPECT_EQ(NULL, apis->GetSchema(std::string())); |
| 233 EXPECT_EQ(NULL, apis->GetSchema("experimental")); | 229 EXPECT_EQ(NULL, apis->GetSchema("experimental")); |
| 234 EXPECT_EQ(NULL, apis->GetSchema("experimental")); | 230 EXPECT_EQ(NULL, apis->GetSchema("experimental")); |
| 235 EXPECT_EQ(NULL, apis->GetSchema("foo")); | 231 EXPECT_EQ(NULL, apis->GetSchema("foo")); |
| 236 EXPECT_EQ(NULL, apis->GetSchema("foo")); | 232 EXPECT_EQ(NULL, apis->GetSchema("foo")); |
| 237 | 233 |
| 238 EXPECT_TRUE(apis->GetSchema("experimental.dns")); | 234 EXPECT_TRUE(apis->GetSchema("experimental.dns")); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 return extension; | 268 return extension; |
| 273 } | 269 } |
| 274 | 270 |
| 275 scoped_refptr<Extension> CreateExtensionWithPermission( | 271 scoped_refptr<Extension> CreateExtensionWithPermission( |
| 276 const std::string& permission) { | 272 const std::string& permission) { |
| 277 std::set<std::string> permissions; | 273 std::set<std::string> permissions; |
| 278 permissions.insert(permission); | 274 permissions.insert(permission); |
| 279 return CreateExtensionWithPermissions(permissions); | 275 return CreateExtensionWithPermissions(permissions); |
| 280 } | 276 } |
| 281 | 277 |
| 282 TEST_F(ExtensionAPITest, ExtensionWithUnprivilegedAPIs) { | 278 TEST(ExtensionAPITest, ExtensionWithUnprivilegedAPIs) { |
| 283 scoped_refptr<Extension> extension; | 279 scoped_refptr<Extension> extension; |
| 284 { | 280 { |
| 285 std::set<std::string> permissions; | 281 std::set<std::string> permissions; |
| 286 permissions.insert("storage"); | 282 permissions.insert("storage"); |
| 287 permissions.insert("history"); | 283 permissions.insert("history"); |
| 288 extension = CreateExtensionWithPermissions(permissions); | 284 extension = CreateExtensionWithPermissions(permissions); |
| 289 } | 285 } |
| 290 | 286 |
| 291 scoped_ptr<ExtensionAPI> extension_api( | 287 scoped_ptr<ExtensionAPI> extension_api( |
| 292 ExtensionAPI::CreateWithDefaultConfiguration()); | 288 ExtensionAPI::CreateWithDefaultConfiguration()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 EXPECT_FALSE(extension_api->IsAvailable("history", | 323 EXPECT_FALSE(extension_api->IsAvailable("history", |
| 328 extension.get(), | 324 extension.get(), |
| 329 Feature::UNBLESSED_EXTENSION_CONTEXT, | 325 Feature::UNBLESSED_EXTENSION_CONTEXT, |
| 330 GURL()).is_available()); | 326 GURL()).is_available()); |
| 331 EXPECT_FALSE(extension_api->IsAvailable("history", | 327 EXPECT_FALSE(extension_api->IsAvailable("history", |
| 332 extension.get(), | 328 extension.get(), |
| 333 Feature::CONTENT_SCRIPT_CONTEXT, | 329 Feature::CONTENT_SCRIPT_CONTEXT, |
| 334 GURL()).is_available()); | 330 GURL()).is_available()); |
| 335 } | 331 } |
| 336 | 332 |
| 337 TEST_F(ExtensionAPITest, ExtensionWithDependencies) { | 333 TEST(ExtensionAPITest, ExtensionWithDependencies) { |
| 338 // Extension with the "ttsEngine" permission but not the "tts" permission; it | 334 // Extension with the "ttsEngine" permission but not the "tts" permission; it |
| 339 // should not automatically get "tts" permission. | 335 // should not automatically get "tts" permission. |
| 340 { | 336 { |
| 341 scoped_refptr<Extension> extension = | 337 scoped_refptr<Extension> extension = |
| 342 CreateExtensionWithPermission("ttsEngine"); | 338 CreateExtensionWithPermission("ttsEngine"); |
| 343 scoped_ptr<ExtensionAPI> api( | 339 scoped_ptr<ExtensionAPI> api( |
| 344 ExtensionAPI::CreateWithDefaultConfiguration()); | 340 ExtensionAPI::CreateWithDefaultConfiguration()); |
| 345 EXPECT_TRUE(api->IsAvailable("ttsEngine", | 341 EXPECT_TRUE(api->IsAvailable("ttsEngine", |
| 346 extension.get(), | 342 extension.get(), |
| 347 Feature::BLESSED_EXTENSION_CONTEXT, | 343 Feature::BLESSED_EXTENSION_CONTEXT, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 369 GURL()).is_available()); | 365 GURL()).is_available()); |
| 370 } | 366 } |
| 371 } | 367 } |
| 372 | 368 |
| 373 bool MatchesURL( | 369 bool MatchesURL( |
| 374 ExtensionAPI* api, const std::string& api_name, const std::string& url) { | 370 ExtensionAPI* api, const std::string& api_name, const std::string& url) { |
| 375 return api->IsAvailable( | 371 return api->IsAvailable( |
| 376 api_name, NULL, Feature::WEB_PAGE_CONTEXT, GURL(url)).is_available(); | 372 api_name, NULL, Feature::WEB_PAGE_CONTEXT, GURL(url)).is_available(); |
| 377 } | 373 } |
| 378 | 374 |
| 379 TEST_F(ExtensionAPITest, URLMatching) { | 375 TEST(ExtensionAPITest, URLMatching) { |
| 380 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); | 376 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); |
| 381 | 377 |
| 382 // "app" API is available to all URLs that content scripts can be injected. | 378 // "app" API is available to all URLs that content scripts can be injected. |
| 383 EXPECT_TRUE(MatchesURL(api.get(), "app", "http://example.com/example.html")); | 379 EXPECT_TRUE(MatchesURL(api.get(), "app", "http://example.com/example.html")); |
| 384 EXPECT_TRUE(MatchesURL(api.get(), "app", "https://blah.net")); | 380 EXPECT_TRUE(MatchesURL(api.get(), "app", "https://blah.net")); |
| 385 EXPECT_TRUE(MatchesURL(api.get(), "app", "file://somefile.html")); | 381 EXPECT_TRUE(MatchesURL(api.get(), "app", "file://somefile.html")); |
| 386 | 382 |
| 387 // But not internal URLs. | 383 // But not internal URLs. |
| 388 EXPECT_FALSE(MatchesURL(api.get(), "app", "about:flags")); | 384 EXPECT_FALSE(MatchesURL(api.get(), "app", "about:flags")); |
| 389 EXPECT_FALSE(MatchesURL(api.get(), "app", "chrome://flags")); | 385 EXPECT_FALSE(MatchesURL(api.get(), "app", "chrome://flags")); |
| 390 | 386 |
| 391 // "app" should be available to chrome-extension URLs. | 387 // "app" should be available to chrome-extension URLs. |
| 392 EXPECT_TRUE(MatchesURL(api.get(), "app", | 388 EXPECT_TRUE(MatchesURL(api.get(), "app", |
| 393 "chrome-extension://fakeextension")); | 389 "chrome-extension://fakeextension")); |
| 394 | 390 |
| 395 // "storage" API (for example) isn't available to any URLs. | 391 // "storage" API (for example) isn't available to any URLs. |
| 396 EXPECT_FALSE(MatchesURL(api.get(), "storage", | 392 EXPECT_FALSE(MatchesURL(api.get(), "storage", |
| 397 "http://example.com/example.html")); | 393 "http://example.com/example.html")); |
| 398 EXPECT_FALSE(MatchesURL(api.get(), "storage", "https://blah.net")); | 394 EXPECT_FALSE(MatchesURL(api.get(), "storage", "https://blah.net")); |
| 399 EXPECT_FALSE(MatchesURL(api.get(), "storage", "file://somefile.html")); | 395 EXPECT_FALSE(MatchesURL(api.get(), "storage", "file://somefile.html")); |
| 400 EXPECT_FALSE(MatchesURL(api.get(), "storage", "about:flags")); | 396 EXPECT_FALSE(MatchesURL(api.get(), "storage", "about:flags")); |
| 401 EXPECT_FALSE(MatchesURL(api.get(), "storage", "chrome://flags")); | 397 EXPECT_FALSE(MatchesURL(api.get(), "storage", "chrome://flags")); |
| 402 EXPECT_FALSE(MatchesURL(api.get(), "storage", | 398 EXPECT_FALSE(MatchesURL(api.get(), "storage", |
| 403 "chrome-extension://fakeextension")); | 399 "chrome-extension://fakeextension")); |
| 404 } | 400 } |
| 405 | 401 |
| 406 TEST_F(ExtensionAPITest, GetAPINameFromFullName) { | 402 TEST(ExtensionAPITest, GetAPINameFromFullName) { |
| 407 struct { | 403 struct { |
| 408 std::string input; | 404 std::string input; |
| 409 std::string api_name; | 405 std::string api_name; |
| 410 std::string child_name; | 406 std::string child_name; |
| 411 } test_data[] = { | 407 } test_data[] = { |
| 412 { "", "", "" }, | 408 { "", "", "" }, |
| 413 { "unknown", "", "" }, | 409 { "unknown", "", "" }, |
| 414 { "bookmarks", "bookmarks", "" }, | 410 { "bookmarks", "bookmarks", "" }, |
| 415 { "bookmarks.", "bookmarks", "" }, | 411 { "bookmarks.", "bookmarks", "" }, |
| 416 { ".bookmarks", "", "" }, | 412 { ".bookmarks", "", "" }, |
| 417 { "bookmarks.create", "bookmarks", "create" }, | 413 { "bookmarks.create", "bookmarks", "create" }, |
| 418 { "bookmarks.create.", "bookmarks", "create." }, | 414 { "bookmarks.create.", "bookmarks", "create." }, |
| 419 { "bookmarks.create.monkey", "bookmarks", "create.monkey" }, | 415 { "bookmarks.create.monkey", "bookmarks", "create.monkey" }, |
| 420 { "bookmarkManagerPrivate", "bookmarkManagerPrivate", "" }, | 416 { "bookmarkManagerPrivate", "bookmarkManagerPrivate", "" }, |
| 421 { "bookmarkManagerPrivate.copy", "bookmarkManagerPrivate", "copy" } | 417 { "bookmarkManagerPrivate.copy", "bookmarkManagerPrivate", "copy" } |
| 422 }; | 418 }; |
| 423 | 419 |
| 424 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); | 420 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); |
| 425 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 421 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 426 std::string child_name; | 422 std::string child_name; |
| 427 std::string api_name = api->GetAPINameFromFullName(test_data[i].input, | 423 std::string api_name = api->GetAPINameFromFullName(test_data[i].input, |
| 428 &child_name); | 424 &child_name); |
| 429 EXPECT_EQ(test_data[i].api_name, api_name) << test_data[i].input; | 425 EXPECT_EQ(test_data[i].api_name, api_name) << test_data[i].input; |
| 430 EXPECT_EQ(test_data[i].child_name, child_name) << test_data[i].input; | 426 EXPECT_EQ(test_data[i].child_name, child_name) << test_data[i].input; |
| 431 } | 427 } |
| 432 } | 428 } |
| 433 | 429 |
| 434 TEST_F(ExtensionAPITest, DefaultConfigurationFeatures) { | 430 TEST(ExtensionAPITest, DefaultConfigurationFeatures) { |
| 435 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); | 431 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); |
| 436 | 432 |
| 437 SimpleFeature* bookmarks = static_cast<SimpleFeature*>( | 433 SimpleFeature* bookmarks = static_cast<SimpleFeature*>( |
| 438 api->GetFeatureDependency("api:bookmarks")); | 434 api->GetFeatureDependency("api:bookmarks")); |
| 439 SimpleFeature* bookmarks_create = static_cast<SimpleFeature*>( | 435 SimpleFeature* bookmarks_create = static_cast<SimpleFeature*>( |
| 440 api->GetFeatureDependency("api:bookmarks.create")); | 436 api->GetFeatureDependency("api:bookmarks.create")); |
| 441 | 437 |
| 442 struct { | 438 struct { |
| 443 SimpleFeature* feature; | 439 SimpleFeature* feature; |
| 444 // TODO(aa): More stuff to test over time. | 440 // TODO(aa): More stuff to test over time. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 458 EXPECT_TRUE(feature->GetContexts()->count( | 454 EXPECT_TRUE(feature->GetContexts()->count( |
| 459 Feature::BLESSED_EXTENSION_CONTEXT)); | 455 Feature::BLESSED_EXTENSION_CONTEXT)); |
| 460 | 456 |
| 461 EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location()); | 457 EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location()); |
| 462 EXPECT_EQ(Feature::UNSPECIFIED_PLATFORM, feature->platform()); | 458 EXPECT_EQ(Feature::UNSPECIFIED_PLATFORM, feature->platform()); |
| 463 EXPECT_EQ(0, feature->min_manifest_version()); | 459 EXPECT_EQ(0, feature->min_manifest_version()); |
| 464 EXPECT_EQ(0, feature->max_manifest_version()); | 460 EXPECT_EQ(0, feature->max_manifest_version()); |
| 465 } | 461 } |
| 466 } | 462 } |
| 467 | 463 |
| 468 TEST_F(ExtensionAPITest, FeaturesRequireContexts) { | 464 TEST(ExtensionAPITest, FeaturesRequireContexts) { |
| 469 // TODO(cduvall): Make this check API featues. | 465 // TODO(cduvall): Make this check API featues. |
| 470 scoped_ptr<base::DictionaryValue> api_features1(new base::DictionaryValue()); | 466 scoped_ptr<base::DictionaryValue> api_features1(new base::DictionaryValue()); |
| 471 scoped_ptr<base::DictionaryValue> api_features2(new base::DictionaryValue()); | 467 scoped_ptr<base::DictionaryValue> api_features2(new base::DictionaryValue()); |
| 472 base::DictionaryValue* test1 = new base::DictionaryValue(); | 468 base::DictionaryValue* test1 = new base::DictionaryValue(); |
| 473 base::DictionaryValue* test2 = new base::DictionaryValue(); | 469 base::DictionaryValue* test2 = new base::DictionaryValue(); |
| 474 base::ListValue* contexts = new base::ListValue(); | 470 base::ListValue* contexts = new base::ListValue(); |
| 475 contexts->Append(new base::StringValue("content_script")); | 471 contexts->Append(new base::StringValue("content_script")); |
| 476 test1->Set("contexts", contexts); | 472 test1->Set("contexts", contexts); |
| 477 api_features1->Set("test", test1); | 473 api_features1->Set("test", test1); |
| 478 api_features2->Set("test", test2); | 474 api_features2->Set("test", test2); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 496 | 492 |
| 497 static void GetDictionaryFromList(const base::DictionaryValue* schema, | 493 static void GetDictionaryFromList(const base::DictionaryValue* schema, |
| 498 const std::string& list_name, | 494 const std::string& list_name, |
| 499 const int list_index, | 495 const int list_index, |
| 500 const base::DictionaryValue** out) { | 496 const base::DictionaryValue** out) { |
| 501 const base::ListValue* list; | 497 const base::ListValue* list; |
| 502 EXPECT_TRUE(schema->GetList(list_name, &list)); | 498 EXPECT_TRUE(schema->GetList(list_name, &list)); |
| 503 EXPECT_TRUE(list->GetDictionary(list_index, out)); | 499 EXPECT_TRUE(list->GetDictionary(list_index, out)); |
| 504 } | 500 } |
| 505 | 501 |
| 506 TEST_F(ExtensionAPITest, TypesHaveNamespace) { | 502 TEST(ExtensionAPITest, TypesHaveNamespace) { |
| 507 base::FilePath manifest_path; | 503 base::FilePath manifest_path; |
| 508 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path); | 504 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path); |
| 509 manifest_path = manifest_path.AppendASCII("extensions") | 505 manifest_path = manifest_path.AppendASCII("extensions") |
| 510 .AppendASCII("extension_api_unittest") | 506 .AppendASCII("extension_api_unittest") |
| 511 .AppendASCII("types_have_namespace.json"); | 507 .AppendASCII("types_have_namespace.json"); |
| 512 | 508 |
| 513 std::string manifest_str; | 509 std::string manifest_str; |
| 514 ASSERT_TRUE(file_util::ReadFileToString(manifest_path, &manifest_str)) | 510 ASSERT_TRUE(file_util::ReadFileToString(manifest_path, &manifest_str)) |
| 515 << "Failed to load: " << manifest_path.value(); | 511 << "Failed to load: " << manifest_path.value(); |
| 516 | 512 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); | 553 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); |
| 558 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | 554 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); |
| 559 EXPECT_EQ("test.foo.TestType", type); | 555 EXPECT_EQ("test.foo.TestType", type); |
| 560 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); | 556 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); |
| 561 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | 557 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); |
| 562 EXPECT_EQ("fully.qualified.Type", type); | 558 EXPECT_EQ("fully.qualified.Type", type); |
| 563 } | 559 } |
| 564 | 560 |
| 565 } // namespace | 561 } // namespace |
| 566 } // namespace extensions | 562 } // namespace extensions |
| OLD | NEW |