diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-09 22:14:27 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-09 22:14:27 +0000 |
commit | ee5c29daf67e999166394e1acb0f89b755b70aaf (patch) | |
tree | db73c6f93b688b554e08eefd805411cef1d8a940 /base/file_util_unittest.cc | |
parent | 2747db2640d2395115de7f3d168786b8ef6e3a81 (diff) | |
download | chromium_src-ee5c29daf67e999166394e1acb0f89b755b70aaf.zip chromium_src-ee5c29daf67e999166394e1acb0f89b755b70aaf.tar.gz chromium_src-ee5c29daf67e999166394e1acb0f89b755b70aaf.tar.bz2 |
Move Contains() method to file_utils, stop relying on in extensions_protocol
Review URL: http://codereview.chromium.org/16805
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7841 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_unittest.cc')
-rw-r--r-- | base/file_util_unittest.cc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index a8855e9..8f5ce19 100644 --- a/base/file_util_unittest.cc +++ b/base/file_util_unittest.cc @@ -978,4 +978,50 @@ TEST_F(FileUtilTest, PathComponentsTest) { } } +TEST_F(FileUtilTest, Contains) { + FilePath data_dir; + ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &data_dir)); + data_dir = data_dir.Append(FILE_PATH_LITERAL("FilePathTest")); + + // Create a fresh, empty copy of this directory. + ASSERT_TRUE(file_util::Delete(data_dir, true)); + ASSERT_TRUE(file_util::CreateDirectory(data_dir)); + + FilePath foo(data_dir.Append(FILE_PATH_LITERAL("foo"))); + FilePath bar(foo.Append(FILE_PATH_LITERAL("bar.txt"))); + FilePath baz(data_dir.Append(FILE_PATH_LITERAL("baz.txt"))); + FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); + + // Annoyingly, the directories must actually exist in order for realpath(), + // which Contains() relies on in posix, to work. + ASSERT_TRUE(file_util::CreateDirectory(foo)); + std::string data("hello"); + ASSERT_TRUE(file_util::WriteFile(bar.ToWStringHack(), data.c_str(), + data.length())); + ASSERT_TRUE(file_util::WriteFile(baz.ToWStringHack(), data.c_str(), + data.length())); + ASSERT_TRUE(file_util::WriteFile(foobar.ToWStringHack(), data.c_str(), + data.length())); + + EXPECT_TRUE(file_util::ContainsPath(foo, bar)); + EXPECT_FALSE(file_util::ContainsPath(foo, baz)); + EXPECT_FALSE(file_util::ContainsPath(foo, foobar)); + EXPECT_FALSE(file_util::ContainsPath(foo, foo)); + +// Platform-specific concerns + FilePath foo_caps(data_dir.Append(FILE_PATH_LITERAL("FOO"))); +#if defined(OS_WIN) + EXPECT_TRUE(file_util::ContainsPath(foo, + foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); + EXPECT_TRUE(file_util::ContainsPath(foo, + FilePath(foo.value() + FILE_PATH_LITERAL("/bar.txt")))); +#elif defined(OS_LINUX) + EXPECT_FALSE(file_util::ContainsPath(foo, + foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); +#else + // We can't really do this test on osx since the case-sensitivity of the + // filesystem is configurable. +#endif +} + } // namespace |