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

Unified Diff: chrome/common/extensions/extension_unittest.cc

Issue 6772022: Make <all_urls> and file:///* in permissions trigger "Allow file access" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch for landing Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/url_pattern.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/extension_unittest.cc
diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc
index e3d2d4f984f3b5f78f83f6dd396f3a8917acff83..7248cacac01c3bf608cc876a8a1f9587a2d188a6 100644
--- a/chrome/common/extensions/extension_unittest.cc
+++ b/chrome/common/extensions/extension_unittest.cc
@@ -777,7 +777,8 @@ TEST(ExtensionTest, MimeTypeSniffing) {
}
static scoped_refptr<Extension> LoadManifest(const std::string& dir,
- const std::string& test_file) {
+ const std::string& test_file,
+ int extra_flags) {
FilePath path;
PathService::Get(chrome::DIR_TEST_DATA, &path);
path = path.AppendASCII("extensions")
@@ -795,11 +796,16 @@ static scoped_refptr<Extension> LoadManifest(const std::string& dir,
scoped_refptr<Extension> extension = Extension::Create(
path.DirName(), Extension::INVALID,
*static_cast<DictionaryValue*>(result.get()),
- Extension::STRICT_ERROR_CHECKS, &error);
+ Extension::STRICT_ERROR_CHECKS | extra_flags, &error);
EXPECT_TRUE(extension) << error;
return extension;
}
+static scoped_refptr<Extension> LoadManifest(const std::string& dir,
+ const std::string& test_file) {
+ return LoadManifest(dir, test_file, Extension::NO_FLAGS);
+}
+
TEST(ExtensionTest, EffectiveHostPermissions) {
scoped_refptr<Extension> extension;
ExtensionExtent hosts;
@@ -1165,6 +1171,71 @@ TEST(ExtensionTest, GetHostPermissionMessages_ManyHosts) {
UTF16ToUTF8(warnings[0]));
}
+TEST(ExtensionTest, WantsFileAccess) {
+ scoped_refptr<Extension> extension;
+ GURL file_url("file:///etc/passwd");
+
+ // <all_urls> permission
+ extension = LoadManifest("permissions", "permissions_all_urls.json");
+ EXPECT_TRUE(extension->wants_file_access());
+ EXPECT_FALSE(extension->CanExecuteScriptOnPage(file_url, NULL, NULL));
+ extension = LoadManifest(
+ "permissions", "permissions_all_urls.json", Extension::ALLOW_FILE_ACCESS);
+ EXPECT_TRUE(extension->wants_file_access());
+ EXPECT_TRUE(extension->CanExecuteScriptOnPage(file_url, NULL, NULL));
+
+ // file:///* permission
+ extension = LoadManifest("permissions", "permissions_file_scheme.json");
+ EXPECT_TRUE(extension->wants_file_access());
+ EXPECT_FALSE(extension->CanExecuteScriptOnPage(file_url, NULL, NULL));
+ extension = LoadManifest("permissions", "permissions_file_scheme.json",
+ Extension::ALLOW_FILE_ACCESS);
+ EXPECT_TRUE(extension->wants_file_access());
+ EXPECT_TRUE(extension->CanExecuteScriptOnPage(file_url, NULL, NULL));
+
+ // http://* permission
+ extension = LoadManifest("permissions", "permissions_http_scheme.json");
+ EXPECT_FALSE(extension->wants_file_access());
+ EXPECT_FALSE(extension->CanExecuteScriptOnPage(file_url, NULL, NULL));
+ extension = LoadManifest("permissions", "permissions_http_scheme.json",
+ Extension::ALLOW_FILE_ACCESS);
+ EXPECT_FALSE(extension->wants_file_access());
+ EXPECT_FALSE(extension->CanExecuteScriptOnPage(file_url, NULL, NULL));
+
+ // <all_urls> content script match
+ extension = LoadManifest("permissions", "content_script_all_urls.json");
+ EXPECT_TRUE(extension->wants_file_access());
+ EXPECT_FALSE(extension->CanExecuteScriptOnPage(
+ file_url, &extension->content_scripts()[0], NULL));
+ extension = LoadManifest("permissions", "content_script_all_urls.json",
+ Extension::ALLOW_FILE_ACCESS);
+ EXPECT_TRUE(extension->wants_file_access());
+ EXPECT_TRUE(extension->CanExecuteScriptOnPage(
+ file_url, &extension->content_scripts()[0], NULL));
+
+ // file:///* content script match
+ extension = LoadManifest("permissions", "content_script_file_scheme.json");
+ EXPECT_TRUE(extension->wants_file_access());
+ EXPECT_FALSE(extension->CanExecuteScriptOnPage(
+ file_url, &extension->content_scripts()[0], NULL));
+ extension = LoadManifest("permissions", "content_script_file_scheme.json",
+ Extension::ALLOW_FILE_ACCESS);
+ EXPECT_TRUE(extension->wants_file_access());
+ EXPECT_TRUE(extension->CanExecuteScriptOnPage(
+ file_url, &extension->content_scripts()[0], NULL));
+
+ // http://* content script match
+ extension = LoadManifest("permissions", "content_script_http_scheme.json");
+ EXPECT_FALSE(extension->wants_file_access());
+ EXPECT_FALSE(extension->CanExecuteScriptOnPage(
+ file_url, &extension->content_scripts()[0], NULL));
+ extension = LoadManifest("permissions", "content_script_http_scheme.json",
+ Extension::ALLOW_FILE_ACCESS);
+ EXPECT_FALSE(extension->wants_file_access());
+ EXPECT_FALSE(extension->CanExecuteScriptOnPage(
+ file_url, &extension->content_scripts()[0], NULL));
+}
+
TEST(ExtensionTest, GetDistinctHostsForDisplay) {
std::vector<std::string> expected;
expected.push_back("www.foo.com");
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/url_pattern.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698