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

Unified Diff: base/path_service_unittest.cc

Issue 1371463003: Move PathService to the base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 | « base/path_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/path_service_unittest.cc
diff --git a/base/path_service_unittest.cc b/base/path_service_unittest.cc
index 7551d6764165753fdac3115a8d6c355f895dfeed..569c0f482e706584d9590ca0703f19fe4c3a2741 100644
--- a/base/path_service_unittest.cc
+++ b/base/path_service_unittest.cc
@@ -18,12 +18,14 @@
#include "base/win/windows_version.h"
#endif
+namespace base {
+
namespace {
// Returns true if PathService::Get returns true and sets the path parameter
// to non-empty for the given PathService::DirType enumeration value.
bool ReturnsValidPath(int dir_type) {
- base::FilePath path;
+ FilePath path;
bool result = PathService::Get(dir_type, &path);
// Some paths might not exist on some platforms in which case confirming
@@ -32,25 +34,25 @@ bool ReturnsValidPath(int dir_type) {
#if defined(OS_POSIX)
// If chromium has never been started on this account, the cache path may not
// exist.
- if (dir_type == base::DIR_CACHE)
+ if (dir_type == DIR_CACHE)
check_path_exists = false;
#endif
#if defined(OS_LINUX)
// On the linux try-bots: a path is returned (e.g. /home/chrome-bot/Desktop),
// but it doesn't exist.
- if (dir_type == base::DIR_USER_DESKTOP)
+ if (dir_type == DIR_USER_DESKTOP)
check_path_exists = false;
#endif
#if defined(OS_WIN)
- if (dir_type == base::DIR_TASKBAR_PINS) {
+ if (dir_type == DIR_TASKBAR_PINS) {
// There is no pinned-to-taskbar shortcuts prior to Win7.
if (base::win::GetVersion() < base::win::VERSION_WIN7)
check_path_exists = false;
}
#endif
#if defined(OS_MACOSX)
- if (dir_type != base::DIR_EXE && dir_type != base::DIR_MODULE &&
- dir_type != base::FILE_EXE && dir_type != base::FILE_MODULE) {
+ if (dir_type != DIR_EXE && dir_type != DIR_MODULE &&
+ dir_type != FILE_EXE && dir_type != FILE_MODULE) {
if (path.ReferencesParent())
return false;
}
@@ -58,8 +60,7 @@ bool ReturnsValidPath(int dir_type) {
if (path.ReferencesParent())
return false;
#endif
- return result && !path.empty() && (!check_path_exists ||
- base::PathExists(path));
+ return result && !path.empty() && (!check_path_exists || PathExists(path));
}
#if defined(OS_WIN)
@@ -67,7 +68,7 @@ bool ReturnsValidPath(int dir_type) {
// of Windows. Checks that the function fails and that the returned path is
// empty.
bool ReturnsInvalidPath(int dir_type) {
- base::FilePath path;
+ FilePath path;
bool result = PathService::Get(dir_type, &path);
return !result && path.empty();
}
@@ -84,21 +85,21 @@ typedef PlatformTest PathServiceTest;
// later changes to Get broke the semantics of the function and yielded the
// correct value while returning false.)
TEST_F(PathServiceTest, Get) {
- for (int key = base::PATH_START + 1; key < base::PATH_END; ++key) {
+ for (int key = PATH_START + 1; key < PATH_END; ++key) {
#if defined(OS_ANDROID)
- if (key == base::FILE_MODULE || key == base::DIR_USER_DESKTOP ||
- key == base::DIR_HOME)
+ if (key == FILE_MODULE || key == DIR_USER_DESKTOP ||
+ key == DIR_HOME)
continue; // Android doesn't implement these.
#elif defined(OS_IOS)
- if (key == base::DIR_USER_DESKTOP)
+ if (key == DIR_USER_DESKTOP)
continue; // iOS doesn't implement DIR_USER_DESKTOP;
#endif
EXPECT_PRED1(ReturnsValidPath, key);
}
#if defined(OS_WIN)
- for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) {
+ for (int key = PATH_WIN_START + 1; key < PATH_WIN_END; ++key) {
bool valid = true;
- if (key == base::DIR_APP_SHORTCUTS)
+ if (key == DIR_APP_SHORTCUTS)
valid = base::win::GetVersion() >= base::win::VERSION_WIN8;
if (valid)
@@ -107,16 +108,16 @@ TEST_F(PathServiceTest, Get) {
EXPECT_TRUE(ReturnsInvalidPath(key)) << key;
}
#elif defined(OS_MACOSX)
- for (int key = base::PATH_MAC_START + 1; key < base::PATH_MAC_END; ++key) {
+ for (int key = PATH_MAC_START + 1; key < PATH_MAC_END; ++key) {
EXPECT_PRED1(ReturnsValidPath, key);
}
#elif defined(OS_ANDROID)
- for (int key = base::PATH_ANDROID_START + 1; key < base::PATH_ANDROID_END;
+ for (int key = PATH_ANDROID_START + 1; key < PATH_ANDROID_END;
++key) {
EXPECT_PRED1(ReturnsValidPath, key);
}
#elif defined(OS_POSIX)
- for (int key = base::PATH_POSIX_START + 1; key < base::PATH_POSIX_END;
+ for (int key = PATH_POSIX_START + 1; key < PATH_POSIX_END;
++key) {
EXPECT_PRED1(ReturnsValidPath, key);
}
@@ -127,32 +128,32 @@ TEST_F(PathServiceTest, Get) {
// are supposed to do.
TEST_F(PathServiceTest, Override) {
int my_special_key = 666;
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath fake_cache_dir(temp_dir.path().AppendASCII("cache"));
+ FilePath fake_cache_dir(temp_dir.path().AppendASCII("cache"));
// PathService::Override should always create the path provided if it doesn't
// exist.
EXPECT_TRUE(PathService::Override(my_special_key, fake_cache_dir));
- EXPECT_TRUE(base::PathExists(fake_cache_dir));
+ EXPECT_TRUE(PathExists(fake_cache_dir));
- base::FilePath fake_cache_dir2(temp_dir.path().AppendASCII("cache2"));
+ FilePath fake_cache_dir2(temp_dir.path().AppendASCII("cache2"));
// 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_FALSE(PathExists(fake_cache_dir2));
EXPECT_TRUE(PathService::OverrideAndCreateIfNeeded(my_special_key,
fake_cache_dir2,
false,
true));
- EXPECT_TRUE(base::PathExists(fake_cache_dir2));
+ EXPECT_TRUE(PathExists(fake_cache_dir2));
#if defined(OS_POSIX)
- base::FilePath non_existent(
- base::MakeAbsoluteFilePath(temp_dir.path()).AppendASCII("non_existent"));
+ FilePath non_existent(
+ MakeAbsoluteFilePath(temp_dir.path()).AppendASCII("non_existent"));
EXPECT_TRUE(non_existent.IsAbsolute());
- EXPECT_FALSE(base::PathExists(non_existent));
+ EXPECT_FALSE(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
@@ -169,8 +170,8 @@ TEST_F(PathServiceTest, Override) {
true,
false));
// Check that the path has been overridden and no directory was created.
- EXPECT_FALSE(base::PathExists(non_existent));
- base::FilePath path;
+ EXPECT_FALSE(PathExists(non_existent));
+ FilePath path;
EXPECT_TRUE(PathService::Get(my_special_key, &path));
EXPECT_EQ(non_existent, path);
#endif
@@ -179,62 +180,62 @@ TEST_F(PathServiceTest, Override) {
// Check if multiple overrides can co-exist.
TEST_F(PathServiceTest, OverrideMultiple) {
int my_special_key = 666;
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath fake_cache_dir1(temp_dir.path().AppendASCII("1"));
+ 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, base::WriteFile(fake_cache_dir1.AppendASCII("t1"), ".", 1));
+ EXPECT_TRUE(PathExists(fake_cache_dir1));
+ ASSERT_EQ(1, WriteFile(fake_cache_dir1.AppendASCII("t1"), ".", 1));
- base::FilePath fake_cache_dir2(temp_dir.path().AppendASCII("2"));
+ 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, base::WriteFile(fake_cache_dir2.AppendASCII("t2"), ".", 1));
+ EXPECT_TRUE(PathExists(fake_cache_dir2));
+ ASSERT_EQ(1, WriteFile(fake_cache_dir2.AppendASCII("t2"), ".", 1));
- base::FilePath result;
+ FilePath result;
EXPECT_TRUE(PathService::Get(my_special_key, &result));
// Override might have changed the path representation but our test file
// should be still there.
- EXPECT_TRUE(base::PathExists(result.AppendASCII("t1")));
+ EXPECT_TRUE(PathExists(result.AppendASCII("t1")));
EXPECT_TRUE(PathService::Get(my_special_key + 1, &result));
- EXPECT_TRUE(base::PathExists(result.AppendASCII("t2")));
+ EXPECT_TRUE(PathExists(result.AppendASCII("t2")));
}
TEST_F(PathServiceTest, RemoveOverride) {
// Before we start the test we have to call RemoveOverride at least once to
// clear any overrides that might have been left from other tests.
- PathService::RemoveOverride(base::DIR_TEMP);
+ PathService::RemoveOverride(DIR_TEMP);
- base::FilePath original_user_data_dir;
- EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &original_user_data_dir));
- EXPECT_FALSE(PathService::RemoveOverride(base::DIR_TEMP));
+ FilePath original_user_data_dir;
+ EXPECT_TRUE(PathService::Get(DIR_TEMP, &original_user_data_dir));
+ EXPECT_FALSE(PathService::RemoveOverride(DIR_TEMP));
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path()));
- base::FilePath new_user_data_dir;
- EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
+ EXPECT_TRUE(PathService::Override(DIR_TEMP, temp_dir.path()));
+ FilePath new_user_data_dir;
+ EXPECT_TRUE(PathService::Get(DIR_TEMP, &new_user_data_dir));
EXPECT_NE(original_user_data_dir, new_user_data_dir);
- EXPECT_TRUE(PathService::RemoveOverride(base::DIR_TEMP));
- EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
+ EXPECT_TRUE(PathService::RemoveOverride(DIR_TEMP));
+ EXPECT_TRUE(PathService::Get(DIR_TEMP, &new_user_data_dir));
EXPECT_EQ(original_user_data_dir, new_user_data_dir);
}
#if defined(OS_WIN)
TEST_F(PathServiceTest, GetProgramFiles) {
- base::FilePath programfiles_dir;
+ FilePath programfiles_dir;
#if defined(_WIN64)
// 64-bit on 64-bit.
- EXPECT_TRUE(PathService::Get(base::DIR_PROGRAM_FILES,
+ EXPECT_TRUE(PathService::Get(DIR_PROGRAM_FILES,
&programfiles_dir));
EXPECT_EQ(programfiles_dir.value(),
FILE_PATH_LITERAL("C:\\Program Files"));
- EXPECT_TRUE(PathService::Get(base::DIR_PROGRAM_FILESX86,
+ EXPECT_TRUE(PathService::Get(DIR_PROGRAM_FILESX86,
&programfiles_dir));
EXPECT_EQ(programfiles_dir.value(),
FILE_PATH_LITERAL("C:\\Program Files (x86)"));
- EXPECT_TRUE(PathService::Get(base::DIR_PROGRAM_FILES6432,
+ EXPECT_TRUE(PathService::Get(DIR_PROGRAM_FILES6432,
&programfiles_dir));
EXPECT_EQ(programfiles_dir.value(),
FILE_PATH_LITERAL("C:\\Program Files"));
@@ -242,29 +243,29 @@ TEST_F(PathServiceTest, GetProgramFiles) {
if (base::win::OSInfo::GetInstance()->wow64_status() ==
base::win::OSInfo::WOW64_ENABLED) {
// 32-bit on 64-bit.
- EXPECT_TRUE(PathService::Get(base::DIR_PROGRAM_FILES,
+ EXPECT_TRUE(PathService::Get(DIR_PROGRAM_FILES,
&programfiles_dir));
EXPECT_EQ(programfiles_dir.value(),
FILE_PATH_LITERAL("C:\\Program Files (x86)"));
- EXPECT_TRUE(PathService::Get(base::DIR_PROGRAM_FILESX86,
+ EXPECT_TRUE(PathService::Get(DIR_PROGRAM_FILESX86,
&programfiles_dir));
EXPECT_EQ(programfiles_dir.value(),
FILE_PATH_LITERAL("C:\\Program Files (x86)"));
- EXPECT_TRUE(PathService::Get(base::DIR_PROGRAM_FILES6432,
+ EXPECT_TRUE(PathService::Get(DIR_PROGRAM_FILES6432,
&programfiles_dir));
EXPECT_EQ(programfiles_dir.value(),
FILE_PATH_LITERAL("C:\\Program Files"));
} else {
// 32-bit on 32-bit.
- EXPECT_TRUE(PathService::Get(base::DIR_PROGRAM_FILES,
+ EXPECT_TRUE(PathService::Get(DIR_PROGRAM_FILES,
&programfiles_dir));
EXPECT_EQ(programfiles_dir.value(),
FILE_PATH_LITERAL("C:\\Program Files"));
- EXPECT_TRUE(PathService::Get(base::DIR_PROGRAM_FILESX86,
+ EXPECT_TRUE(PathService::Get(DIR_PROGRAM_FILESX86,
&programfiles_dir));
EXPECT_EQ(programfiles_dir.value(),
FILE_PATH_LITERAL("C:\\Program Files"));
- EXPECT_TRUE(PathService::Get(base::DIR_PROGRAM_FILES6432,
+ EXPECT_TRUE(PathService::Get(DIR_PROGRAM_FILES6432,
&programfiles_dir));
EXPECT_EQ(programfiles_dir.value(),
FILE_PATH_LITERAL("C:\\Program Files"));
@@ -272,3 +273,5 @@ TEST_F(PathServiceTest, GetProgramFiles) {
#endif
}
#endif
+
+} // namespace base
« no previous file with comments | « base/path_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698