Chromium Code Reviews| Index: chrome/common/extensions/api/extension_api_unittest.cc |
| diff --git a/chrome/common/extensions/api/extension_api_unittest.cc b/chrome/common/extensions/api/extension_api_unittest.cc |
| index 70982f790cb1e7bc9db9560a16bf95935405b48c..c1080c9cc2a906818e4fa9817a3cad2e180b7841 100644 |
| --- a/chrome/common/extensions/api/extension_api_unittest.cc |
| +++ b/chrome/common/extensions/api/extension_api_unittest.cc |
| @@ -13,8 +13,22 @@ |
| #include "chrome/common/extensions/extension.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +namespace { |
| + |
| using extensions::ExtensionAPI; |
| +bool GetSchemasForURLContains( |
| + const std::string& api_name, const std::string& url) { |
| + ExtensionAPI::SchemaMap schemas; |
| + ExtensionAPI::GetInstance()->GetSchemasForURL(GURL(url), &schemas); |
| + return schemas.find(api_name) != schemas.end(); |
| +} |
| + |
| +bool MatchesURL( |
| + const std::string& api_name, const std::string& url) { |
| + return ExtensionAPI::GetInstance()->MatchesURL(api_name, GURL(url)); |
| +} |
| + |
| TEST(ExtensionAPI, IsPrivileged) { |
| ExtensionAPI* extension_api = ExtensionAPI::GetInstance(); |
| EXPECT_FALSE(extension_api->IsPrivileged("extension.connect")); |
| @@ -33,6 +47,8 @@ TEST(ExtensionAPI, IsPrivileged) { |
| EXPECT_TRUE(extension_api->IsPrivileged("history.search")); |
| // Whole APIs that are unprivileged. |
| + EXPECT_FALSE(extension_api->IsPrivileged("app.getDetails")); |
| + EXPECT_FALSE(extension_api->IsPrivileged("app.isInstalled")); |
| EXPECT_FALSE(extension_api->IsPrivileged("storage.local")); |
| EXPECT_FALSE(extension_api->IsPrivileged("storage.local.onChanged")); |
| EXPECT_FALSE(extension_api->IsPrivileged("storage.local.set")); |
| @@ -81,3 +97,51 @@ TEST(ExtensionAPI, Depends) { |
| *extension, ExtensionAPI::ALL, &schemas); |
| EXPECT_EQ(1u, schemas.count("tts")); |
| } |
| + |
| +TEST(ExtensionAPI, GetSchemasForURL) { |
| + // "app" API is available to all URLs that content scripts can be injected. |
| + EXPECT_TRUE(GetSchemasForURLContains("app", |
| + "http://example.com/example.html")); |
| + EXPECT_TRUE(GetSchemasForURLContains("app", "https://blah.net")); |
| + EXPECT_TRUE(GetSchemasForURLContains("app", "file://somefile.html")); |
| + |
| + // But not internal URLs (for chrome-extension:// the app API is injected by |
| + // GetSchemasForExtension). |
| + EXPECT_FALSE(GetSchemasForURLContains("app", "about:flags")); |
| + EXPECT_FALSE(GetSchemasForURLContains("app", "chrome://flags")); |
| + EXPECT_FALSE(GetSchemasForURLContains("app", |
| + "chrome-extension://fakeextension")); |
| + |
| + // "storage" API (for example) isn't available to any URLs. |
| + EXPECT_FALSE(GetSchemasForURLContains("storage", |
| + "http://example.com/example.html")); |
| + EXPECT_FALSE(GetSchemasForURLContains("storage", "https://blah.net")); |
| + EXPECT_FALSE(GetSchemasForURLContains("storage", "file://somefile.html")); |
| + EXPECT_FALSE(GetSchemasForURLContains("storage", "about:flags")); |
| + EXPECT_FALSE(GetSchemasForURLContains("storage", "chrome://flags")); |
| + EXPECT_FALSE(GetSchemasForURLContains("storage", |
| + "chrome-extension://fakeextension")); |
|
koz (OOO until 15th September)
2012/02/27 03:04:11
nit: This seems redundant to have the same data pa
not at google - send to devlin
2012/02/27 04:44:24
Yeah, it's ok, you didn't need to soften that with
|
| +} |
| + |
| +TEST(ExtensionAPI, MatchesURL) { |
| + // "app" API is available to all URLs that content scripts can be injected. |
| + EXPECT_TRUE(MatchesURL("app", "http://example.com/example.html")); |
| + EXPECT_TRUE(MatchesURL("app", "https://blah.net")); |
| + EXPECT_TRUE(MatchesURL("app", "file://somefile.html")); |
| + |
| + // But not internal URLs (for chrome-extension:// the app API is injected by |
| + // GetSchemasForExtension). |
| + EXPECT_FALSE(MatchesURL("app", "about:flags")); |
| + EXPECT_FALSE(MatchesURL("app", "chrome://flags")); |
| + EXPECT_FALSE(MatchesURL("app", "chrome-extension://fakeextension")); |
| + |
| + // "storage" API (for example) isn't available to any URLs. |
| + EXPECT_FALSE(MatchesURL("storage", "http://example.com/example.html")); |
| + EXPECT_FALSE(MatchesURL("storage", "https://blah.net")); |
| + EXPECT_FALSE(MatchesURL("storage", "file://somefile.html")); |
| + EXPECT_FALSE(MatchesURL("storage", "about:flags")); |
| + EXPECT_FALSE(MatchesURL("storage", "chrome://flags")); |
| + EXPECT_FALSE(MatchesURL("storage", "chrome-extension://fakeextension")); |
| +} |
| + |
| +} // namespace |