summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-12 23:57:27 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-12 23:57:27 +0000
commit19eef14a9c8d939a82fa262633927968a33daf6e (patch)
treeb5f5c188f49911cddf39a3edb8f18daaa76d5c88
parent2f7f4d591192cfdebee227b72e3cf57c7c604450 (diff)
downloadchromium_src-19eef14a9c8d939a82fa262633927968a33daf6e.zip
chromium_src-19eef14a9c8d939a82fa262633927968a33daf6e.tar.gz
chromium_src-19eef14a9c8d939a82fa262633927968a33daf6e.tar.bz2
Convert a CopyRecursiveDirNoCache to use FilePaths instead
of wstrings. Also convert template_user_data_ in UITest to be a FilePath. Review URL: http://codereview.chromium.org/273021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28762 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/test/test_file_util.h4
-rw-r--r--base/test/test_file_util_posix.cc33
-rw-r--r--base/test/test_file_util_win.cc18
-rw-r--r--chrome/test/page_cycler/page_cycler_test.cc2
-rw-r--r--chrome/test/startup/feature_startup_test.cc2
-rw-r--r--chrome/test/startup/startup_test.cc6
-rw-r--r--chrome/test/ui/ui_test.cc2
-rw-r--r--chrome/test/ui/ui_test.h6
8 files changed, 34 insertions, 39 deletions
diff --git a/base/test/test_file_util.h b/base/test/test_file_util.h
index 3d2764e..e9e888e 100644
--- a/base/test/test_file_util.h
+++ b/base/test/test_file_util.h
@@ -28,8 +28,8 @@ bool EvictFileFromSystemCache(const FilePath& file);
//
// Returns true on success. False means there was some error copying, so the
// state of the destination is unknown.
-bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
- const std::wstring& dest_dir);
+bool CopyRecursiveDirNoCache(const FilePath& source_dir,
+ const FilePath& dest_dir);
} // namespace file_util
diff --git a/base/test/test_file_util_posix.cc b/base/test/test_file_util_posix.cc
index 096f3c6..8f7d69d 100644
--- a/base/test/test_file_util_posix.cc
+++ b/base/test/test_file_util_posix.cc
@@ -24,19 +24,16 @@ bool DieFileDie(const FilePath& file, bool recurse) {
}
// Mostly a verbatim copy of CopyDirectory
-bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
- const std::wstring& dest_dir) {
- const FilePath from_path(FilePath::FromWStringHack(source_dir));
- const FilePath to_path(FilePath::FromWStringHack(dest_dir));
-
+bool CopyRecursiveDirNoCache(const FilePath& source_dir,
+ const FilePath& dest_dir) {
char top_dir[PATH_MAX];
- if (base::strlcpy(top_dir, from_path.value().c_str(),
+ if (base::strlcpy(top_dir, source_dir.value().c_str(),
arraysize(top_dir)) >= arraysize(top_dir)) {
return false;
}
// This function does not properly handle destinations within the source
- FilePath real_to_path = to_path;
+ FilePath real_to_path = dest_dir;
if (PathExists(real_to_path)) {
if (!AbsolutePath(&real_to_path))
return false;
@@ -45,35 +42,35 @@ bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
if (!AbsolutePath(&real_to_path))
return false;
}
- if (real_to_path.value().compare(0, from_path.value().size(),
- from_path.value()) == 0)
+ if (real_to_path.value().compare(0, source_dir.value().size(),
+ source_dir.value()) == 0)
return false;
bool success = true;
FileEnumerator::FILE_TYPE traverse_type =
static_cast<FileEnumerator::FILE_TYPE>(FileEnumerator::FILES |
FileEnumerator::SHOW_SYM_LINKS | FileEnumerator::DIRECTORIES);
- FileEnumerator traversal(from_path, true, traverse_type);
+ FileEnumerator traversal(source_dir, true, traverse_type);
- // to_path may not exist yet, start the loop with to_path
+ // dest_dir may not exist yet, start the loop with dest_dir
FileEnumerator::FindInfo info;
- FilePath current = from_path;
- if (stat(from_path.value().c_str(), &info.stat) < 0) {
+ FilePath current = source_dir;
+ if (stat(source_dir.value().c_str(), &info.stat) < 0) {
LOG(ERROR) << "CopyRecursiveDirNoCache() couldn't stat source directory: "
- << from_path.value() << " errno = " << errno;
+ << source_dir.value() << " errno = " << errno;
success = false;
}
while (success && !current.empty()) {
- // current is the source path, including from_path, so paste
- // the suffix after from_path onto to_path to create the target_path.
- std::string suffix(&current.value().c_str()[from_path.value().size()]);
+ // |current| is the source path, including source_dir, so paste
+ // the suffix after source_dir onto dest_dir to create the target_path.
+ std::string suffix(&current.value().c_str()[source_dir.value().size()]);
// Strip the leading '/' (if any).
if (!suffix.empty()) {
DCHECK_EQ('/', suffix[0]);
suffix.erase(0, 1);
}
- const FilePath target_path = to_path.Append(suffix);
+ const FilePath target_path = dest_dir.Append(suffix);
if (S_ISDIR(info.stat.st_mode)) {
if (mkdir(target_path.value().c_str(), info.stat.st_mode & 01777) != 0 &&
diff --git a/base/test/test_file_util_win.cc b/base/test/test_file_util_win.cc
index 4ebea54..e7bfce8 100644
--- a/base/test/test_file_util_win.cc
+++ b/base/test/test_file_util_win.cc
@@ -122,8 +122,8 @@ bool EvictFileFromSystemCache(const FilePath& file) {
// Like CopyFileNoCache but recursively copies all files and subdirectories
// in the given input directory to the output directory.
-bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
- const std::wstring& dest_dir) {
+bool CopyRecursiveDirNoCache(const FilePath& source_dir,
+ const FilePath& dest_dir) {
// Try to create the directory if it doesn't already exist.
if (!CreateDirectory(dest_dir)) {
if (GetLastError() != ERROR_ALREADY_EXISTS)
@@ -132,7 +132,7 @@ bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
std::vector<std::wstring> files_copied;
- std::wstring src(source_dir);
+ std::wstring src(source_dir.value());
file_util::AppendToPath(&src, L"*");
WIN32_FIND_DATA fd;
@@ -145,11 +145,8 @@ bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
if (cur_file == L"." || cur_file == L"..")
continue; // Skip these special entries.
- std::wstring cur_source_path(source_dir);
- file_util::AppendToPath(&cur_source_path, cur_file);
-
- std::wstring cur_dest_path(dest_dir);
- file_util::AppendToPath(&cur_dest_path, cur_file);
+ FilePath cur_source_path = source_dir.Append(cur_file);
+ FilePath cur_dest_path = dest_dir.Append(cur_file);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
// Recursively copy a subdirectory. We stripped "." and ".." already.
@@ -159,7 +156,8 @@ bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
}
} else {
// Copy the file.
- if (!::CopyFile(cur_source_path.c_str(), cur_dest_path.c_str(), false)) {
+ if (!::CopyFile(cur_source_path.value().c_str(),
+ cur_dest_path.value().c_str(), false)) {
FindClose(fh);
return false;
}
@@ -168,7 +166,7 @@ bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
// files that are in the repository, and they will have read-only set.
// This will prevent us from evicting from the cache, but these don't
// matter anyway.
- EvictFileFromSystemCache(FilePath::FromWStringHack(cur_dest_path));
+ EvictFileFromSystemCache(cur_dest_path);
}
} while (FindNextFile(fh, &fd));
diff --git a/chrome/test/page_cycler/page_cycler_test.cc b/chrome/test/page_cycler/page_cycler_test.cc
index 033cd09..7c611d5 100644
--- a/chrome/test/page_cycler/page_cycler_test.cc
+++ b/chrome/test/page_cycler/page_cycler_test.cc
@@ -449,7 +449,7 @@ class PageCyclerExtensionTest : public PageCyclerTest {
data_dir = data_dir.AppendASCII("extensions").AppendASCII("profiles").
AppendASCII(extension_profile);
ASSERT_TRUE(file_util::DirectoryExists(data_dir));
- set_template_user_data(data_dir.ToWStringHack());
+ set_template_user_data(data_dir);
// Now run the test.
PageCyclerTest::SetUp();
diff --git a/chrome/test/startup/feature_startup_test.cc b/chrome/test/startup/feature_startup_test.cc
index d112295..31fd81a 100644
--- a/chrome/test/startup/feature_startup_test.cc
+++ b/chrome/test/startup/feature_startup_test.cc
@@ -44,7 +44,7 @@ class NewTabUIStartupTest : public UITest {
// Install the location of the test profile file.
set_template_user_data(UITest::ComputeTypicalUserDataSource(
- profile_type).ToWStringHack());
+ profile_type));
// Disable the first run notification because it has an animation which
// masks any real performance regressions.
diff --git a/chrome/test/startup/startup_test.cc b/chrome/test/startup/startup_test.cc
index ec874f2..385b592 100644
--- a/chrome/test/startup/startup_test.cc
+++ b/chrome/test/startup/startup_test.cc
@@ -46,7 +46,7 @@ class StartupTest : public UITest {
PathService::Get(chrome::DIR_TEST_DATA, &data_dir);
data_dir = data_dir.AppendASCII("extensions").AppendASCII("profiles").
AppendASCII(profile);
- set_template_user_data(data_dir.ToWStringHack());
+ set_template_user_data(data_dir);
}
void RunStartupTest(const char* graph, const char* trace,
@@ -57,7 +57,7 @@ class StartupTest : public UITest {
// the non-default themes test.
if (profile_type != UITest::DEFAULT_THEME) {
set_template_user_data(UITest::ComputeTypicalUserDataSource(
- profile_type).ToWStringHack());
+ profile_type));
}
const int kNumCyclesMax = 20;
@@ -109,7 +109,7 @@ class StartupTest : public UITest {
clear_profile_ = false;
// Clear template_user_data_ so we don't try to copy it over each time
// through.
- set_template_user_data(L"");
+ set_template_user_data(FilePath());
}
}
diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc
index 8ff8f64..cf49227 100644
--- a/chrome/test/ui/ui_test.cc
+++ b/chrome/test/ui/ui_test.cc
@@ -357,7 +357,7 @@ void UITest::LaunchBrowser(const CommandLine& arguments, bool clear_profile) {
// Recursively copy the template directory to the user_data_dir.
ASSERT_TRUE(file_util::CopyRecursiveDirNoCache(
template_user_data_,
- user_data_dir_.ToWStringHack()));
+ user_data_dir_));
// If we're using the complex theme data, we need to write the
// user_data_dir_ to our preferences file.
if (profile_type_ == UITest::COMPLEX_THEME) {
diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h
index c87ffe1..4112549a 100644
--- a/chrome/test/ui/ui_test.h
+++ b/chrome/test/ui/ui_test.h
@@ -383,8 +383,8 @@ class UITest : public testing::Test {
// copied into the user data directory for the test and the files will be
// evicted from the OS cache. To start with a blank profile, supply an empty
// string (the default).
- std::wstring template_user_data() const { return template_user_data_; }
- void set_template_user_data(const std::wstring& template_user_data) {
+ const FilePath& template_user_data() const { return template_user_data_; }
+ void set_template_user_data(const FilePath& template_user_data) {
template_user_data_ = template_user_data;
}
@@ -503,7 +503,7 @@ class UITest : public testing::Test {
base::TimeTicks browser_launch_time_; // Time when the browser was run.
bool dom_automation_enabled_; // This can be set to true to have the
// test run the dom automation case.
- std::wstring template_user_data_; // See set_template_user_data().
+ FilePath template_user_data_; // See set_template_user_data().
base::ProcessHandle process_; // Handle to the first Chrome process.
base::ProcessId process_id_; // PID of |process_| (for debugging).
FilePath user_data_dir_; // User data directory used for the test