diff options
author | zhchbin@gmail.com <zhchbin@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-08 07:42:03 +0000 |
---|---|---|
committer | zhchbin@gmail.com <zhchbin@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-08 07:42:03 +0000 |
commit | a07346b59280824c8623115ce2f396cca43e4a69 (patch) | |
tree | 951617057d0208ddb469335393faf7739cefef38 /chrome/browser/extensions | |
parent | 8d25881d44dd6ad0d64499c3873d2800f1c777c7 (diff) | |
download | chromium_src-a07346b59280824c8623115ce2f396cca43e4a69.zip chromium_src-a07346b59280824c8623115ce2f396cca43e4a69.tar.gz chromium_src-a07346b59280824c8623115ce2f396cca43e4a69.tar.bz2 |
Ignore files in the.git, .svn and __MACOSX directory when packing extension.
BUG=314360, 27840
TEST=unit_tests --gtest_filter=ExtensionCreatorFilterTest.*
Review URL: https://codereview.chromium.org/57273003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233814 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extension_creator_filter.cc | 26 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_creator_filter_unittest.cc | 41 |
2 files changed, 63 insertions, 4 deletions
diff --git a/chrome/browser/extensions/extension_creator_filter.cc b/chrome/browser/extensions/extension_creator_filter.cc index a904d31..27c4e22 100644 --- a/chrome/browser/extensions/extension_creator_filter.cc +++ b/chrome/browser/extensions/extension_creator_filter.cc @@ -4,6 +4,9 @@ #include "chrome/browser/extensions/extension_creator_filter.h" +#include <vector> +#include <set> + #include "base/files/file_path.h" #if defined(OS_WIN) @@ -19,6 +22,25 @@ bool ExtensionCreatorFilter::ShouldPackageFile( return false; } + // The file path that contains one of following special components should be + // excluded. See crbug.com/314360 and crbug.com/27840. + const base::FilePath::StringType names_to_exclude[] = { + FILE_PATH_LITERAL(".DS_Store"), + FILE_PATH_LITERAL(".git"), + FILE_PATH_LITERAL(".svn"), + FILE_PATH_LITERAL("__MACOSX"), + FILE_PATH_LITERAL("desktop.ini"), + FILE_PATH_LITERAL("Thumbs.db") + }; + std::set<base::FilePath::StringType> names_to_exclude_set(names_to_exclude, + names_to_exclude + arraysize(names_to_exclude)); + std::vector<base::FilePath::StringType> components; + file_path.GetComponents(&components); + for (size_t i = 0; i < components.size(); i++) { + if (names_to_exclude_set.count(components[i])) + return false; + } + base::FilePath::CharType first_character = base_name.value()[0]; base::FilePath::CharType last_character = base_name.value()[base_name.value().length() - 1]; @@ -35,10 +57,6 @@ bool ExtensionCreatorFilter::ShouldPackageFile( if (first_character == '#' && last_character == '#') { return false; } - // Magic OS X file - if (base_name.value() == FILE_PATH_LITERAL("__MACOSX")) { - return false; - } #if defined(OS_WIN) // It's correct that we use file_path, not base_name, here, because we diff --git a/chrome/browser/extensions/extension_creator_filter_unittest.cc b/chrome/browser/extensions/extension_creator_filter_unittest.cc index 48f5806..61a1f66 100644 --- a/chrome/browser/extensions/extension_creator_filter_unittest.cc +++ b/chrome/browser/extensions/extension_creator_filter_unittest.cc @@ -30,6 +30,18 @@ class ExtensionCreatorFilterTest : public PlatformTest { return test_file; } + base::FilePath CreateEmptyTestFileInDir( + const base::FilePath::StringType& file_name, + const base::FilePath::StringType& dir) { + base::FilePath temp_sub_dir(test_dir_.Append(dir)); + base::FilePath test_file(temp_sub_dir.Append(file_name)); + EXPECT_TRUE(file_util::CreateDirectory(temp_sub_dir)); + base::FilePath temp_file; + EXPECT_TRUE(file_util::CreateTemporaryFileInDir(temp_sub_dir, &temp_file)); + EXPECT_TRUE(base::Move(temp_file, test_file)); + return test_file; + } + scoped_refptr<extensions::ExtensionCreatorFilter> filter_; base::ScopedTempDir temp_dir_; @@ -53,6 +65,9 @@ TEST_F(ExtensionCreatorFilterTest, NormalCases) { { FILE_PATH_LITERAL("#foo#"), false }, { FILE_PATH_LITERAL(".svn"), false }, { FILE_PATH_LITERAL("__MACOSX"), false }, + { FILE_PATH_LITERAL(".DS_Store"), false }, + { FILE_PATH_LITERAL("desktop.ini"), false }, + { FILE_PATH_LITERAL("Thumbs.db"), false }, }; for (size_t i = 0; i < arraysize(cases); ++i) { @@ -65,6 +80,32 @@ TEST_F(ExtensionCreatorFilterTest, NormalCases) { } } +struct StringStringWithBooleanTestData { + const base::FilePath::StringType file_name; + const base::FilePath::StringType dir; + bool expected; +}; + +// Ignore the files in special directories, including ".git", ".svn", +// "__MACOSX". +TEST_F(ExtensionCreatorFilterTest, IgnoreFilesInSpecialDir) { + const struct StringStringWithBooleanTestData cases[] = { + { FILE_PATH_LITERAL("foo"), FILE_PATH_LITERAL(".git"), false }, + { FILE_PATH_LITERAL("goo"), FILE_PATH_LITERAL(".svn"), false }, + { FILE_PATH_LITERAL("foo"), FILE_PATH_LITERAL("__MACOSX"), false }, + { FILE_PATH_LITERAL("foo"), FILE_PATH_LITERAL("foo"), true }, + { FILE_PATH_LITERAL("index.js"), FILE_PATH_LITERAL("scripts"), true }, + }; + + for (size_t i = 0; i < arraysize(cases); ++i) { + base::FilePath test_file(CreateEmptyTestFileInDir(cases[i].file_name, + cases[i].dir)); + bool observed = filter_->ShouldPackageFile(test_file); + EXPECT_EQ(cases[i].expected, observed) << + "i: " << i << ", input: " << test_file.value(); + } +} + #if defined(OS_WIN) struct StringBooleanWithBooleanTestData { const base::FilePath::CharType* input_char; |