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

Unified Diff: chrome/common/extensions/api/extension_api_unittest.cc

Issue 9460002: Convert app_bindings.js to the schema_generated_bindings.js infrastructure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: koz comments Created 8 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 side-by-side diff with in-line comments
Download patch
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..825461410564ae1fb9694e37b5144ebf0bfbc652 100644
--- a/chrome/common/extensions/api/extension_api_unittest.cc
+++ b/chrome/common/extensions/api/extension_api_unittest.cc
@@ -13,8 +13,32 @@
#include "chrome/common/extensions/extension.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
using extensions::ExtensionAPI;
+enum MatchesURLResult {
+ NO_MATCH,
+ MATCH,
+ UNKNOWN
+};
+
+MatchesURLResult MatchesURL(
+ const std::string& api_name, const std::string& url) {
+ bool matches_url =
+ ExtensionAPI::GetInstance()->MatchesURL(api_name, GURL(url));
+
+ ExtensionAPI::SchemaMap schemas;
+ ExtensionAPI::GetInstance()->GetSchemasForURL(GURL(url), &schemas);
+ bool get_schemas_for_url_contains = schemas.find(api_name) != schemas.end();
+
+ if (matches_url && get_schemas_for_url_contains)
+ return MATCH;
+ if (!matches_url && !get_schemas_for_url_contains)
+ return NO_MATCH;
+ return UNKNOWN;
+}
+
TEST(ExtensionAPI, IsPrivileged) {
ExtensionAPI* extension_api = ExtensionAPI::GetInstance();
EXPECT_FALSE(extension_api->IsPrivileged("extension.connect"));
@@ -33,6 +57,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 +107,27 @@ TEST(ExtensionAPI, Depends) {
*extension, ExtensionAPI::ALL, &schemas);
EXPECT_EQ(1u, schemas.count("tts"));
}
+
+TEST(ExtensionAPI, MatchesURL) {
+ // "app" API is available to all URLs that content scripts can be injected.
+ EXPECT_EQ(MATCH, MatchesURL("app", "http://example.com/example.html"));
+ EXPECT_EQ(MATCH, MatchesURL("app", "https://blah.net"));
+ EXPECT_EQ(MATCH, MatchesURL("app", "file://somefile.html"));
+
+ // But not internal URLs (for chrome-extension:// the app API is injected by
+ // GetSchemasForExtension).
+ EXPECT_EQ(NO_MATCH, MatchesURL("app", "about:flags"));
+ EXPECT_EQ(NO_MATCH, MatchesURL("app", "chrome://flags"));
+ EXPECT_EQ(NO_MATCH, MatchesURL("app", "chrome-extension://fakeextension"));
+
+ // "storage" API (for example) isn't available to any URLs.
+ EXPECT_EQ(NO_MATCH, MatchesURL("storage", "http://example.com/example.html"));
+ EXPECT_EQ(NO_MATCH, MatchesURL("storage", "https://blah.net"));
+ EXPECT_EQ(NO_MATCH, MatchesURL("storage", "file://somefile.html"));
+ EXPECT_EQ(NO_MATCH, MatchesURL("storage", "about:flags"));
+ EXPECT_EQ(NO_MATCH, MatchesURL("storage", "chrome://flags"));
+ EXPECT_EQ(NO_MATCH, MatchesURL("storage",
+ "chrome-extension://fakeextension"));
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698