summaryrefslogtreecommitdiffstats
path: root/chromium/base/path_service_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/base/path_service_unittest.cc')
-rw-r--r--chromium/base/path_service_unittest.cc40
1 files changed, 35 insertions, 5 deletions
diff --git a/chromium/base/path_service_unittest.cc b/chromium/base/path_service_unittest.cc
index fbb2d766deb..7a70a89c41a 100644
--- a/chromium/base/path_service_unittest.cc
+++ b/chromium/base/path_service_unittest.cc
@@ -100,8 +100,9 @@ typedef PlatformTest PathServiceTest;
TEST_F(PathServiceTest, Get) {
for (int key = base::PATH_START + 1; key < base::PATH_END; ++key) {
#if defined(OS_ANDROID)
- if (key == base::FILE_MODULE || key == base::DIR_USER_DESKTOP)
- continue; // Android doesn't implement FILE_MODULE and DIR_USER_DESKTOP;
+ if (key == base::FILE_MODULE || key == base::DIR_USER_DESKTOP ||
+ key == base::DIR_HOME)
+ continue; // Android doesn't implement these.
#elif defined(OS_IOS)
if (key == base::DIR_USER_DESKTOP)
continue; // iOS doesn't implement DIR_USER_DESKTOP;
@@ -146,7 +147,7 @@ TEST_F(PathServiceTest, Get) {
#endif
}
-// test that all versions of the Override function of PathService do what they
+// Test that all versions of the Override function of PathService do what they
// are supposed to do.
TEST_F(PathServiceTest, Override) {
int my_special_key = 666;
@@ -162,12 +163,41 @@ TEST_F(PathServiceTest, Override) {
// PathService::OverrideAndCreateIfNeeded should obey the |create| parameter.
PathService::OverrideAndCreateIfNeeded(my_special_key,
fake_cache_dir2,
+ false,
false);
EXPECT_FALSE(base::PathExists(fake_cache_dir2));
EXPECT_TRUE(PathService::OverrideAndCreateIfNeeded(my_special_key,
fake_cache_dir2,
+ false,
true));
EXPECT_TRUE(base::PathExists(fake_cache_dir2));
+
+#if defined(OS_POSIX)
+ base::FilePath non_existent(
+ base::MakeAbsoluteFilePath(temp_dir.path()).AppendASCII("non_existent"));
+ EXPECT_TRUE(non_existent.IsAbsolute());
+ EXPECT_FALSE(base::PathExists(non_existent));
+#if !defined(OS_ANDROID)
+ // This fails because MakeAbsoluteFilePath fails for non-existent files.
+ // Earlier versions of Bionic libc don't fail for non-existent files, so
+ // skip this check on Android.
+ EXPECT_FALSE(PathService::OverrideAndCreateIfNeeded(my_special_key,
+ non_existent,
+ false,
+ false));
+#endif
+ // This works because indicating that |non_existent| is absolute skips the
+ // internal MakeAbsoluteFilePath call.
+ EXPECT_TRUE(PathService::OverrideAndCreateIfNeeded(my_special_key,
+ non_existent,
+ true,
+ false));
+ // Check that the path has been overridden and no directory was created.
+ EXPECT_FALSE(base::PathExists(non_existent));
+ base::FilePath path;
+ EXPECT_TRUE(PathService::Get(my_special_key, &path));
+ EXPECT_EQ(non_existent, path);
+#endif
}
// Check if multiple overrides can co-exist.
@@ -178,12 +208,12 @@ TEST_F(PathServiceTest, OverrideMultiple) {
base::FilePath fake_cache_dir1(temp_dir.path().AppendASCII("1"));
EXPECT_TRUE(PathService::Override(my_special_key, fake_cache_dir1));
EXPECT_TRUE(base::PathExists(fake_cache_dir1));
- ASSERT_EQ(1, file_util::WriteFile(fake_cache_dir1.AppendASCII("t1"), ".", 1));
+ ASSERT_EQ(1, base::WriteFile(fake_cache_dir1.AppendASCII("t1"), ".", 1));
base::FilePath fake_cache_dir2(temp_dir.path().AppendASCII("2"));
EXPECT_TRUE(PathService::Override(my_special_key + 1, fake_cache_dir2));
EXPECT_TRUE(base::PathExists(fake_cache_dir2));
- ASSERT_EQ(1, file_util::WriteFile(fake_cache_dir2.AppendASCII("t2"), ".", 1));
+ ASSERT_EQ(1, base::WriteFile(fake_cache_dir2.AppendASCII("t2"), ".", 1));
base::FilePath result;
EXPECT_TRUE(PathService::Get(my_special_key, &result));