summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-04 20:46:06 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-04 20:46:06 +0000
commitceeb87e90224c8743995b999661eede7c31b6346 (patch)
tree459f0698b022e42ead17cb742be9ff7f9d1b441f
parentf3208bd4c625527d854c3bf49908352199488c48 (diff)
downloadchromium_src-ceeb87e90224c8743995b999661eede7c31b6346.zip
chromium_src-ceeb87e90224c8743995b999661eede7c31b6346.tar.gz
chromium_src-ceeb87e90224c8743995b999661eede7c31b6346.tar.bz2
Get rid of kPathSeparator on windows. Port some wstring function to take FilePaths. Re-enable relevant posix unit tests.
Review URL: http://codereview.chromium.org/12893 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6387 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/file_util.cc66
-rw-r--r--base/file_util.h22
-rw-r--r--base/file_util_unittest.cc120
-rw-r--r--base/file_util_win.cc75
-rw-r--r--chrome/browser/browser_uitest.cc2
-rw-r--r--chrome/browser/download/download_uitest.cc2
-rw-r--r--chrome/browser/download/save_page_uitest.cc2
-rw-r--r--chrome/browser/history/starred_url_database_unittest.cc15
-rw-r--r--chrome/browser/history/url_database_unittest.cc2
-rw-r--r--chrome/browser/history/visit_database_unittest.cc2
-rw-r--r--chrome/browser/importer/ie_importer.cc2
-rw-r--r--chrome/browser/safe_browsing/database_perftest.cc4
-rw-r--r--chrome/browser/session_history_uitest.cc8
-rw-r--r--chrome/browser/session_restore_uitest.cc17
-rw-r--r--chrome/browser/ssl_uitest.cc2
-rw-r--r--chrome/browser/tab_restore_uitest.cc2
-rw-r--r--chrome/browser/url_fetcher_unittest.cc2
-rw-r--r--chrome/browser/visitedlink_perftest.cc24
-rw-r--r--chrome/browser/webdata/web_database_unittest.cc2
-rw-r--r--chrome/test/tab_switching/tab_switching_test.cc4
-rw-r--r--net/base/net_util.cc28
-rw-r--r--net/base/net_util.h2
-rw-r--r--webkit/tools/test_shell/test_shell_win.cc6
23 files changed, 210 insertions, 201 deletions
diff --git a/base/file_util.cc b/base/file_util.cc
index 187e7b0..10e08d5 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -16,6 +16,12 @@
#include "base/string_piece.h"
#include "base/sys_string_conversions.h"
+namespace {
+
+const FilePath::CharType kExtensionSeparator = FILE_PATH_LITERAL('.');
+
+}
+
namespace file_util {
void PathComponents(const FilePath& path,
@@ -73,13 +79,6 @@ void TrimTrailingSeparator(std::wstring* dir) {
dir->resize(dir->length() - 1);
}
-std::wstring GetFilenameFromPath(const std::wstring& path) {
- // TODO(erikkay): fix this - it's not using kPathSeparator, but win unit test
- // are exercising '/' as a path separator as well.
- std::wstring::size_type pos = path.find_last_of(L"\\/");
- return std::wstring(path, pos == std::wstring::npos ? 0 : pos + 1);
-}
-
std::wstring GetFileExtensionFromPath(const std::wstring& path) {
std::wstring file_name = GetFilenameFromPath(path);
std::wstring::size_type last_dot = file_name.rfind(L'.');
@@ -94,6 +93,53 @@ std::wstring GetFilenameWithoutExtensionFromPath(const std::wstring& path) {
return file_name.substr(0, last_dot);
}
+void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix) {
+ FilePath::StringType& value =
+ const_cast<FilePath::StringType&>(path->value());
+
+ const FilePath::StringType::size_type last_dot =
+ value.rfind(kExtensionSeparator);
+ const FilePath::StringType::size_type last_separator =
+ value.find_last_of(FilePath::StringType(FilePath::kSeparators));
+
+ if (last_dot == FilePath::StringType::npos ||
+ (last_separator != std::wstring::npos && last_dot < last_separator)) {
+ // The path looks something like "C:\pics.old\jojo" or "C:\pics\jojo".
+ // We should just append the suffix to the entire path.
+ value.append(suffix);
+ return;
+ }
+
+ value.insert(last_dot, suffix);
+}
+
+void ReplaceExtension(FilePath* path, const FilePath::StringType& extension) {
+ FilePath::StringType clean_extension;
+ // If the new extension is "" or ".", then we will just remove the current
+ // extension.
+ if (!extension.empty() &&
+ extension != FilePath::StringType(&kExtensionSeparator, 1)) {
+ if (extension[0] != kExtensionSeparator)
+ clean_extension.append(&kExtensionSeparator, 1);
+ clean_extension.append(extension);
+ }
+
+ FilePath::StringType& value =
+ const_cast<FilePath::StringType&>(path->value());
+ const FilePath::StringType::size_type last_dot =
+ value.rfind(kExtensionSeparator);
+ const FilePath::StringType::size_type last_separator =
+ value.find_last_of(FilePath::StringType(FilePath::kSeparators));
+
+ // Erase the current extension, if any.
+ if ((last_dot > last_separator ||
+ last_separator == FilePath::StringType::npos) &&
+ last_dot != FilePath::StringType::npos)
+ value.erase(last_dot);
+
+ value.append(clean_extension);
+}
+
void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char) {
DCHECK(file_name);
@@ -295,6 +341,12 @@ bool GetCurrentDirectory(std::wstring* path_str) {
bool GetFileInfo(const std::wstring& file_path, FileInfo* results) {
return GetFileInfo(FilePath::FromWStringHack(file_path), results);
}
+std::wstring GetFilenameFromPath(const std::wstring& path) {
+ if (path.empty() || EndsWithSeparator(path))
+ return std::wstring();
+
+ return FilePath::FromWStringHack(path).BaseName().ToWStringHack();
+}
bool GetFileSize(const std::wstring& file_path, int64* file_size) {
return GetFileSize(FilePath::FromWStringHack(file_path), file_size);
}
diff --git a/base/file_util.h b/base/file_util.h
index eebf3af..41bc70b 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -29,16 +29,6 @@
namespace file_util {
//-----------------------------------------------------------------------------
-// Constants
-
-#if defined(OS_WIN)
-// The use of this constant is deprecated. Instead use file_util or FilePath
-// functions (Append, TrimTrailingSeparator, etc.), or use
-// FilePath::kSeparator[0].
-extern const wchar_t kPathSeparator;
-#endif
-
-//-----------------------------------------------------------------------------
// Functions that operate purely on a path string w/o touching the filesystem:
// Returns a vector of all of the components of the provided path.
@@ -80,6 +70,7 @@ void UpOneDirectoryOrEmpty(std::wstring* dir);
void TrimFilename(std::wstring* path);
// Returns the filename portion of 'path', without any leading \'s or /'s.
+// Deprecated. Use FilePath::BaseName instead.
std::wstring GetFilenameFromPath(const std::wstring& path);
// Returns "jpg" for path "C:\pics\jojo.jpg", or an empty string if
@@ -109,9 +100,6 @@ bool AbsolutePath(FilePath* path);
// Deprecated temporary compatibility function.
bool AbsolutePath(std::wstring* path);
-// TODO(port): create FilePath versions of these functions, and remove this
-// platform define.
-#if defined(OS_WIN)
// Inserts |suffix| after the file name portion of |path| but before the
// extension.
// Examples:
@@ -119,11 +107,17 @@ bool AbsolutePath(std::wstring* path);
// path == "jojo.jpg" suffix == " (1)", returns "jojo (1).jpg"
// path == "C:\pics\jojo" suffix == " (1)", returns "C:\pics\jojo (1)"
// path == "C:\pics.old\jojo" suffix == " (1)", returns "C:\pics.old\jojo (1)"
-void InsertBeforeExtension(std::wstring* path, const std::wstring& suffix);
+void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix);
// Replaces the extension of |file_name| with |extension|. If |file_name|
// does not have an extension, them |extension| is added. If |extension| is
// empty, then the extension is removed from |file_name|.
+void ReplaceExtension(FilePath* file_name,
+ const FilePath::StringType& extension);
+
+#if defined(OS_WIN)
+// Deprecated temporary compatibility functions.
+void InsertBeforeExtension(std::wstring* path, const std::wstring& suffix);
void ReplaceExtension(std::wstring* file_name, const std::wstring& extension);
#endif
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index 3a4962d..4c7743a 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -147,29 +147,27 @@ TEST_F(FileUtilTest, AppendToPath) {
#endif
}
-// TODO(port): enable this test for non-Windows.
-#if defined(OS_WIN)
static const struct InsertBeforeExtensionCase {
std::wstring path;
- std::wstring suffix;
+ FilePath::StringType suffix;
std::wstring result;
} kInsertBeforeExtension[] = {
- {L"", L"", L""},
- {L"", L"txt", L"txt"},
- {L".", L"txt", L"txt."},
- {L".", L"", L"."},
- {L"foo.dll", L"txt", L"footxt.dll"},
- {L"foo.dll", L".txt", L"foo.txt.dll"},
- {L"foo", L"txt", L"footxt"},
- {L"foo", L".txt", L"foo.txt"},
- {L"foo.baz.dll", L"txt", L"foo.baztxt.dll"},
- {L"foo.baz.dll", L".txt", L"foo.baz.txt.dll"},
- {L"foo.dll", L"", L"foo.dll"},
- {L"foo.dll", L".", L"foo..dll"},
- {L"foo", L"", L"foo"},
- {L"foo", L".", L"foo."},
- {L"foo.baz.dll", L"", L"foo.baz.dll"},
- {L"foo.baz.dll", L".", L"foo.baz..dll"},
+ {L"", FILE_PATH_LITERAL(""), L""},
+ {L"", FILE_PATH_LITERAL("txt"), L"txt"},
+ {L".", FILE_PATH_LITERAL("txt"), L"txt."},
+ {L".", FILE_PATH_LITERAL(""), L"."},
+ {L"foo.dll", FILE_PATH_LITERAL("txt"), L"footxt.dll"},
+ {L"foo.dll", FILE_PATH_LITERAL(".txt"), L"foo.txt.dll"},
+ {L"foo", FILE_PATH_LITERAL("txt"), L"footxt"},
+ {L"foo", FILE_PATH_LITERAL(".txt"), L"foo.txt"},
+ {L"foo.baz.dll", FILE_PATH_LITERAL("txt"), L"foo.baztxt.dll"},
+ {L"foo.baz.dll", FILE_PATH_LITERAL(".txt"), L"foo.baz.txt.dll"},
+ {L"foo.dll", FILE_PATH_LITERAL(""), L"foo.dll"},
+ {L"foo.dll", FILE_PATH_LITERAL("."), L"foo..dll"},
+ {L"foo", FILE_PATH_LITERAL(""), L"foo"},
+ {L"foo", FILE_PATH_LITERAL("."), L"foo."},
+ {L"foo.baz.dll", FILE_PATH_LITERAL(""), L"foo.baz.dll"},
+ {L"foo.baz.dll", FILE_PATH_LITERAL("."), L"foo.baz..dll"},
#if defined(OS_WIN)
{L"\\", L"", L"\\"},
{L"\\", L"txt", L"\\txt"},
@@ -184,29 +182,28 @@ static const struct InsertBeforeExtensionCase {
{L"C:\\bar.baz\\foo.dll.exe", L"", L"C:\\bar.baz\\foo.dll.exe"},
{L"C:\\bar\\baz\\foo.exe", L" (1)", L"C:\\bar\\baz\\foo (1).exe"},
#elif defined(OS_POSIX)
- {L"/", L"", L"/"},
- {L"/", L"txt", L"/txt"},
- {L"/.", L"txt", L"/txt."},
- {L"/.", L"", L"/."},
- {L"/bar/foo.dll", L"txt", L"/bar/footxt.dll"},
- {L"/bar.baz/foodll", L"txt", L"/bar.baz/foodlltxt"},
- {L"/bar.baz/foo.dll", L"txt", L"/bar.baz/footxt.dll"},
- {L"/bar.baz/foo.dll.exe", L"txt", L"/bar.baz/foo.dlltxt.exe"},
- {L"/bar.baz/foo", L"", L"/bar.baz/foo"},
- {L"/bar.baz/foo.exe", L"", L"/bar.baz/foo.exe"},
- {L"/bar.baz/foo.dll.exe", L"", L"/bar.baz/foo.dll.exe"},
- {L"/bar/baz/foo.exe", L" (1)", L"/bar/baz/foo (1).exe"},
+ {L"/", "", L"/"},
+ {L"/", "txt", L"/txt"},
+ {L"/.", "txt", L"/txt."},
+ {L"/.", "", L"/."},
+ {L"/bar/foo.dll", "txt", L"/bar/footxt.dll"},
+ {L"/bar.baz/foodll", "txt", L"/bar.baz/foodlltxt"},
+ {L"/bar.baz/foo.dll", "txt", L"/bar.baz/footxt.dll"},
+ {L"/bar.baz/foo.dll.exe", "txt", L"/bar.baz/foo.dlltxt.exe"},
+ {L"/bar.baz/foo", "", L"/bar.baz/foo"},
+ {L"/bar.baz/foo.exe", "", L"/bar.baz/foo.exe"},
+ {L"/bar.baz/foo.dll.exe", "", L"/bar.baz/foo.dll.exe"},
+ {L"/bar/baz/foo.exe", " (1)", L"/bar/baz/foo (1).exe"},
#endif
};
TEST_F(FileUtilTest, InsertBeforeExtensionTest) {
for (unsigned int i = 0; i < arraysize(kInsertBeforeExtension); ++i) {
- std::wstring path(kInsertBeforeExtension[i].path);
+ FilePath path = FilePath::FromWStringHack(kInsertBeforeExtension[i].path);
file_util::InsertBeforeExtension(&path, kInsertBeforeExtension[i].suffix);
- EXPECT_EQ(path, kInsertBeforeExtension[i].result);
+ EXPECT_EQ(kInsertBeforeExtension[i].result, path.ToWStringHack());
}
}
-#endif // defined(OS_WIN)
static const struct filename_case {
const wchar_t* path;
@@ -788,51 +785,48 @@ TEST_F(FileUtilTest, ReplaceIllegalCharactersTest) {
}
}
-// TODO(port): enable this test for non-windows.
-#if defined(OS_WIN)
static const struct ReplaceExtensionCase {
std::wstring file_name;
- std::wstring extension;
+ FilePath::StringType extension;
std::wstring result;
} kReplaceExtension[] = {
- {L"", L"", L""},
- {L"", L"txt", L".txt"},
- {L".", L"txt", L".txt"},
- {L".", L"", L""},
- {L"foo.dll", L"txt", L"foo.txt"},
- {L"foo.dll", L".txt", L"foo.txt"},
- {L"foo", L"txt", L"foo.txt"},
- {L"foo", L".txt", L"foo.txt"},
- {L"foo.baz.dll", L"txt", L"foo.baz.txt"},
- {L"foo.baz.dll", L".txt", L"foo.baz.txt"},
- {L"foo.dll", L"", L"foo"},
- {L"foo.dll", L".", L"foo"},
- {L"foo", L"", L"foo"},
- {L"foo", L".", L"foo"},
- {L"foo.baz.dll", L"", L"foo.baz"},
- {L"foo.baz.dll", L".", L"foo.baz"},
+ {L"", FILE_PATH_LITERAL(""), L""},
+ {L"", FILE_PATH_LITERAL("txt"), L".txt"},
+ {L".", FILE_PATH_LITERAL("txt"), L".txt"},
+ {L".", FILE_PATH_LITERAL(""), L""},
+ {L"foo.dll", FILE_PATH_LITERAL("txt"), L"foo.txt"},
+ {L"foo.dll", FILE_PATH_LITERAL(".txt"), L"foo.txt"},
+ {L"foo", FILE_PATH_LITERAL("txt"), L"foo.txt"},
+ {L"foo", FILE_PATH_LITERAL(".txt"), L"foo.txt"},
+ {L"foo.baz.dll", FILE_PATH_LITERAL("txt"), L"foo.baz.txt"},
+ {L"foo.baz.dll", FILE_PATH_LITERAL(".txt"), L"foo.baz.txt"},
+ {L"foo.dll", FILE_PATH_LITERAL(""), L"foo"},
+ {L"foo.dll", FILE_PATH_LITERAL("."), L"foo"},
+ {L"foo", FILE_PATH_LITERAL(""), L"foo"},
+ {L"foo", FILE_PATH_LITERAL("."), L"foo"},
+ {L"foo.baz.dll", FILE_PATH_LITERAL(""), L"foo.baz"},
+ {L"foo.baz.dll", FILE_PATH_LITERAL("."), L"foo.baz"},
};
TEST_F(FileUtilTest, ReplaceExtensionTest) {
for (unsigned int i = 0; i < arraysize(kReplaceExtension); ++i) {
- std::wstring file_name(kReplaceExtension[i].file_name);
- file_util::ReplaceExtension(&file_name, kReplaceExtension[i].extension);
- EXPECT_EQ(file_name, kReplaceExtension[i].result);
+ FilePath path = FilePath::FromWStringHack(kReplaceExtension[i].file_name);
+ file_util::ReplaceExtension(&path, kReplaceExtension[i].extension);
+ EXPECT_EQ(kReplaceExtension[i].result, path.ToWStringHack());
}
}
// Make sure ReplaceExtension doesn't replace an extension that occurs as one of
// the directory names of the path.
TEST_F(FileUtilTest, ReplaceExtensionTestWithPathSeparators) {
- std::wstring path;
- file_util::AppendToPath(&path, L"foo.bar");
- file_util::AppendToPath(&path, L"foo");
+ FilePath path;
+ path = path.Append(FILE_PATH_LITERAL("foo.bar"));
+ path = path.Append(FILE_PATH_LITERAL("foo"));
// '/foo.bar/foo' with extension '.baz'
- std::wstring result_path = path;
- file_util::ReplaceExtension(&result_path, L".baz");
- EXPECT_EQ(path + L".baz", result_path);
+ FilePath result_path = path;
+ file_util::ReplaceExtension(&result_path, FILE_PATH_LITERAL(".baz"));
+ EXPECT_EQ(path.ToWStringHack() + L".baz", result_path.ToWStringHack());
}
-#endif // defined(OS_WIN)
TEST_F(FileUtilTest, FileEnumeratorTest) {
// Test an empty directory.
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index c107711..c32c87d 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -18,14 +18,6 @@
namespace file_util {
-const wchar_t kPathSeparator = L'\\';
-const wchar_t kExtensionSeparator = L'.';
-
-void PathComponents(const std::wstring& path,
- std::vector<std::wstring>* components) {
- PathComponents(FilePath(path), components);
-}
-
std::wstring GetDirectoryFromPath(const std::wstring& path) {
wchar_t path_buffer[MAX_PATH];
wchar_t* file_ptr = NULL;
@@ -47,55 +39,6 @@ bool AbsolutePath(FilePath* path) {
return true;
}
-void InsertBeforeExtension(std::wstring* path, const std::wstring& suffix) {
- DCHECK(path);
-
- const std::wstring::size_type last_dot = path->rfind(kExtensionSeparator);
- const std::wstring::size_type last_sep = path->rfind(kPathSeparator);
-
- if (last_dot == std::wstring::npos ||
- (last_sep != std::wstring::npos && last_dot < last_sep)) {
- // The path looks something like "C:\pics.old\jojo" or "C:\pics\jojo".
- // We should just append the suffix to the entire path.
- path->append(suffix);
- return;
- }
-
- path->insert(last_dot, suffix);
-}
-
-// Appends the extension to file adding a '.' if extension doesn't contain one.
-// This does nothing if extension is empty or '.'. This is used internally by
-// ReplaceExtension.
-static void AppendExtension(const std::wstring& extension,
- std::wstring* file) {
- if (!extension.empty() && extension != L".") {
- if (extension[0] != L'.')
- file->append(L".");
- file->append(extension);
- }
-}
-
-void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) {
- const std::wstring::size_type last_dot = file_name->rfind(L'.');
- if (last_dot == std::wstring::npos) {
- // No extension, just append the supplied extension.
- AppendExtension(extension, file_name);
- return;
- }
- const std::wstring::size_type last_separator =
- file_name->rfind(kPathSeparator);
- if (last_separator != std::wstring::npos && last_dot < last_separator) {
- // File name doesn't have extension, but one of the directories does; don't
- // replace it, just append the supplied extension. For example
- // 'c:\tmp.bar\foo'.
- AppendExtension(extension, file_name);
- return;
- }
- std::wstring result = file_name->substr(0, last_dot);
- AppendExtension(extension, &result);
- file_name->swap(result);
-}
int CountFilesCreatedAfter(const std::wstring& path,
const FILETIME& comparison_time) {
int file_count = 0;
@@ -751,4 +694,22 @@ std::wstring FileEnumerator::Next() {
}
return (file_type_ & FileEnumerator::FILES) ? cur_file : Next();
}
+
+// Deprecated functions ----------------------------------------------------
+
+void InsertBeforeExtension(std::wstring* path_str,
+ const std::wstring& suffix) {
+ FilePath path(*path_str);
+ InsertBeforeExtension(&path, suffix);
+ path_str->assign(path.value());
+}
+void PathComponents(const std::wstring& path,
+ std::vector<std::wstring>* components) {
+ PathComponents(FilePath(path), components);
+}
+void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) {
+ FilePath path(*file_name);
+ ReplaceExtension(&path, extension);
+ file_name->assign(path.value());
+}
} // namespace file_util
diff --git a/chrome/browser/browser_uitest.cc b/chrome/browser/browser_uitest.cc
index 3bbffe1..f3e42e3 100644
--- a/chrome/browser/browser_uitest.cc
+++ b/chrome/browser/browser_uitest.cc
@@ -230,7 +230,7 @@ TEST_F(BrowserTest, JavascriptAlertActivatesTab) {
TEST_F(BrowserTest, DuplicateTab) {
std::wstring path_prefix = test_data_directory_;
file_util::AppendToPath(&path_prefix, L"session_history");
- path_prefix += file_util::kPathSeparator;
+ path_prefix += FilePath::kSeparators[0];
GURL url1 = net::FilePathToFileURL(path_prefix + L"bot1.html");
GURL url2 = net::FilePathToFileURL(path_prefix + L"bot2.html");
GURL url3 = GURL("about:blank");
diff --git a/chrome/browser/download/download_uitest.cc b/chrome/browser/download/download_uitest.cc
index 92e826f..52d67ba 100644
--- a/chrome/browser/download/download_uitest.cc
+++ b/chrome/browser/download/download_uitest.cc
@@ -102,7 +102,7 @@ class DownloadTest : public UITest {
virtual void SetUp() {
UITest::SetUp();
download_prefix_ = GetDownloadDirectory();
- download_prefix_ += file_util::kPathSeparator;
+ download_prefix_ += FilePath::kSeparators[0];
}
protected:
diff --git a/chrome/browser/download/save_page_uitest.cc b/chrome/browser/download/save_page_uitest.cc
index 551c335..0c75c21 100644
--- a/chrome/browser/download/save_page_uitest.cc
+++ b/chrome/browser/download/save_page_uitest.cc
@@ -52,7 +52,7 @@ class SavePageTest : public UITest {
virtual void SetUp() {
UITest::SetUp();
EXPECT_TRUE(file_util::CreateNewTempDirectory(L"", &save_dir_));
- save_dir_ += file_util::kPathSeparator;
+ save_dir_ += FilePath::kSeparators[0];
}
std::wstring save_dir_;
diff --git a/chrome/browser/history/starred_url_database_unittest.cc b/chrome/browser/history/starred_url_database_unittest.cc
index 32e834d..b570358 100644
--- a/chrome/browser/history/starred_url_database_unittest.cc
+++ b/chrome/browser/history/starred_url_database_unittest.cc
@@ -66,18 +66,19 @@ class StarredURLDatabaseTest : public testing::Test,
// Test setup.
void SetUp() {
PathService::Get(base::DIR_TEMP, &db_file_);
- db_file_.push_back(file_util::kPathSeparator);
- db_file_.append(L"VisitTest.db");
+ db_file_ = db_file_.Append(FILE_PATH_LITERAL("VisitTest.db"));
file_util::Delete(db_file_, false);
// Copy db file over that contains starred table.
- std::wstring old_history_path;
+ FilePath old_history_path;
PathService::Get(chrome::DIR_TEST_DATA, &old_history_path);
- file_util::AppendToPath(&old_history_path, L"bookmarks");
- file_util::AppendToPath(&old_history_path, L"History_with_empty_starred");
+ old_history_path = old_history_path.Append(FILE_PATH_LITERAL("bookmarks"));
+ old_history_path = old_history_path.Append(
+ FILE_PATH_LITERAL("History_with_empty_starred"));
file_util::CopyFile(old_history_path, db_file_);
- EXPECT_EQ(SQLITE_OK, sqlite3_open(WideToUTF8(db_file_).c_str(), &db_));
+ EXPECT_EQ(SQLITE_OK,
+ sqlite3_open(WideToUTF8(db_file_.ToWStringHack()).c_str(), &db_));
statement_cache_ = new SqliteStatementCache(db_);
// Initialize the tables for this test.
@@ -99,7 +100,7 @@ class StarredURLDatabaseTest : public testing::Test,
return *statement_cache_;
}
- std::wstring db_file_;
+ FilePath db_file_;
sqlite3* db_;
SqliteStatementCache* statement_cache_;
};
diff --git a/chrome/browser/history/url_database_unittest.cc b/chrome/browser/history/url_database_unittest.cc
index c58029d..2159e45 100644
--- a/chrome/browser/history/url_database_unittest.cc
+++ b/chrome/browser/history/url_database_unittest.cc
@@ -39,7 +39,7 @@ class URLDatabaseTest : public testing::Test,
// Test setup.
void SetUp() {
PathService::Get(base::DIR_TEMP, &db_file_);
- db_file_.push_back(file_util::kPathSeparator);
+ db_file_.push_back(FilePath::kSeparators[0]);
db_file_.append(L"URLTest.db");
EXPECT_EQ(SQLITE_OK, sqlite3_open(WideToUTF8(db_file_).c_str(), &db_));
diff --git a/chrome/browser/history/visit_database_unittest.cc b/chrome/browser/history/visit_database_unittest.cc
index 1992f0b..47846b6 100644
--- a/chrome/browser/history/visit_database_unittest.cc
+++ b/chrome/browser/history/visit_database_unittest.cc
@@ -41,7 +41,7 @@ class VisitDatabaseTest : public testing::Test,
// Test setup.
void SetUp() {
PathService::Get(base::DIR_TEMP, &db_file_);
- db_file_.push_back(file_util::kPathSeparator);
+ db_file_.push_back(FilePath::kSeparators[0]);
db_file_.append(L"VisitTest.db");
file_util::Delete(db_file_, false);
diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc
index 2e5d919..450e5165 100644
--- a/chrome/browser/importer/ie_importer.cc
+++ b/chrome/browser/importer/ie_importer.cc
@@ -495,7 +495,7 @@ void IEImporter::ParseFavoritesFolder(const FavoritesInfo& info,
entry.url = url;
entry.creation_time = GetFileCreationTime(*it);
if (!relative_path.empty())
- SplitString(relative_path, file_util::kPathSeparator, &entry.path);
+ file_util::PathComponents(relative_path, &entry.path);
// Flatten the bookmarks in Link folder onto bookmark toolbar. Otherwise,
// put it into "Other bookmarks".
diff --git a/chrome/browser/safe_browsing/database_perftest.cc b/chrome/browser/safe_browsing/database_perftest.cc
index c39a58d..273bda4 100644
--- a/chrome/browser/safe_browsing/database_perftest.cc
+++ b/chrome/browser/safe_browsing/database_perftest.cc
@@ -45,7 +45,7 @@ class Database {
// get an empty file for the test DB
std::wstring filename;
PathService::Get(base::DIR_TEMP, &filename);
- filename.push_back(file_util::kPathSeparator);
+ filename.push_back(FilePath::kSeparators[0]);
filename.append(ASCIIToWide(name));
if (create) {
@@ -390,7 +390,7 @@ class SafeBrowsingDatabaseTest {
logging::DELETE_OLD_LOG_FILE);
PathService::Get(base::DIR_TEMP, &filename_);
- filename_.push_back(file_util::kPathSeparator);
+ filename_.push_back(FilePath::kSeparators[0]);
filename_.append(name);
}
diff --git a/chrome/browser/session_history_uitest.cc b/chrome/browser/session_history_uitest.cc
index dc72ef1..251a3ba 100644
--- a/chrome/browser/session_history_uitest.cc
+++ b/chrome/browser/session_history_uitest.cc
@@ -22,11 +22,11 @@ const wchar_t kDocRoot[] = L"chrome/test/data";
class SessionHistoryTest : public UITest {
protected:
SessionHistoryTest() : UITest() {
- wstring path_prefix = test_data_directory_;
- file_util::AppendToPath(&path_prefix, L"session_history");
- path_prefix += file_util::kPathSeparator;
+ FilePath path = FilePath::FromWStringHack(test_data_directory_);
+ path = path.Append(FILE_PATH_LITERAL("session_history"))
+ .Append(FilePath::StringType(&FilePath::kSeparators[0], 1));
- url_prefix_ = UTF8ToWide(net::FilePathToFileURL(path_prefix).spec());
+ url_prefix_ = UTF8ToWide(net::FilePathToFileURL(path).spec());
}
virtual void SetUp() {
diff --git a/chrome/browser/session_restore_uitest.cc b/chrome/browser/session_restore_uitest.cc
index dede0fc9a..f93098a 100644
--- a/chrome/browser/session_restore_uitest.cc
+++ b/chrome/browser/session_restore_uitest.cc
@@ -21,13 +21,16 @@ namespace {
class SessionRestoreUITest : public UITest {
protected:
SessionRestoreUITest() : UITest() {
- std::wstring path_prefix = test_data_directory_;
- file_util::AppendToPath(&path_prefix, L"session_history");
- path_prefix += file_util::kPathSeparator;
-
- url1 = net::FilePathToFileURL(path_prefix + L"bot1.html");
- url2 = net::FilePathToFileURL(path_prefix + L"bot2.html");
- url3 = net::FilePathToFileURL(path_prefix + L"bot3.html");
+ FilePath path_prefix = FilePath::FromWStringHack(test_data_directory_);
+ path_prefix = path_prefix.Append(FILE_PATH_LITERAL("session_history"))
+ .Append(FilePath::StringType(&FilePath::kSeparators[0], 1));
+
+ url1 = net::FilePathToFileURL(
+ path_prefix.Append(FILE_PATH_LITERAL("bot1.html")));
+ url2 = net::FilePathToFileURL(
+ path_prefix.Append(FILE_PATH_LITERAL("bot2.html")));
+ url3 = net::FilePathToFileURL(
+ path_prefix.Append(FILE_PATH_LITERAL("bot3.html")));
}
virtual void QuitBrowserAndRestore() {
diff --git a/chrome/browser/ssl_uitest.cc b/chrome/browser/ssl_uitest.cc
index feea5e0..906c28c 100644
--- a/chrome/browser/ssl_uitest.cc
+++ b/chrome/browser/ssl_uitest.cc
@@ -32,7 +32,7 @@ class SSLUITest : public UITest {
PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_);
cert_dir_ += L"/chrome/test/data/ssl/certificates/";
std::replace(cert_dir_.begin(), cert_dir_.end(),
- L'/', file_util::kPathSeparator);
+ L'/', FilePath::kSeparators[0]);
}
TabProxy* GetActiveTabProxy() {
diff --git a/chrome/browser/tab_restore_uitest.cc b/chrome/browser/tab_restore_uitest.cc
index d108d0f..6e813e8 100644
--- a/chrome/browser/tab_restore_uitest.cc
+++ b/chrome/browser/tab_restore_uitest.cc
@@ -21,7 +21,7 @@ class TabRestoreUITest : public UITest {
TabRestoreUITest() : UITest() {
std::wstring path_prefix = test_data_directory_;
file_util::AppendToPath(&path_prefix, L"session_history");
- path_prefix += file_util::kPathSeparator;
+ path_prefix += FilePath::kSeparators[0];
url1_ = net::FilePathToFileURL(path_prefix + L"bot1.html");
url2_ = net::FilePathToFileURL(path_prefix + L"bot2.html");
}
diff --git a/chrome/browser/url_fetcher_unittest.cc b/chrome/browser/url_fetcher_unittest.cc
index 7f737c4..b842b762 100644
--- a/chrome/browser/url_fetcher_unittest.cc
+++ b/chrome/browser/url_fetcher_unittest.cc
@@ -263,7 +263,7 @@ URLFetcherBadHTTPSTest::URLFetcherBadHTTPSTest() {
PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_);
cert_dir_ += L"/chrome/test/data/ssl/certificates/";
std::replace(cert_dir_.begin(), cert_dir_.end(),
- L'/', file_util::kPathSeparator);
+ L'/', FilePath::kSeparators[0]);
}
// The "server certificate expired" error should result in automatic
diff --git a/chrome/browser/visitedlink_perftest.cc b/chrome/browser/visitedlink_perftest.cc
index 328e9fe..d589f92 100644
--- a/chrome/browser/visitedlink_perftest.cc
+++ b/chrome/browser/visitedlink_perftest.cc
@@ -34,14 +34,12 @@ VisitedLinkMaster::PostNewTableEvent DummyBroadcastNewTableEvent;
void DummyBroadcastNewTableEvent(base::SharedMemory *table) {
}
-// Call at the beginning of the test to retrieve the database name and to
-// delete any old databases left by previous unit tests. The input buffer
-// should be MAX_PATH long.
-void InitDBName(wchar_t* db_name) {
- ASSERT_TRUE(GetCurrentDirectory(MAX_PATH, db_name));
- if (db_name[wcslen(db_name) - 1] != file_util::kPathSeparator)
- wcsncat_s(db_name, MAX_PATH, &file_util::kPathSeparator, 1);
- wcscat_s(db_name, MAX_PATH, L"TempVisitedLinks");
+// Call at the beginning of the test to retrieve the database name.
+void InitDBName(std::wstring* db_name) {
+ FilePath db_path;
+ ASSERT_TRUE(file_util::GetCurrentDirectory(&db_path));
+ db_path = db_path.Append(FILE_PATH_LITERAL("TempVisitedLinks"));
+ *db_name = db_path.ToWStringHack();
}
// this checks IsVisited for the URLs starting with the given prefix and
@@ -62,13 +60,13 @@ void FillTable(VisitedLinkMaster& master, const char* prefix,
class VisitedLink : public testing::Test {
protected:
- wchar_t db_name_[MAX_PATH];
+ std::wstring db_name_;
virtual void SetUp() {
- InitDBName(db_name_);
- DeleteFile(db_name_);
+ InitDBName(&db_name_);
+ file_util::Delete(db_name_, false);
}
virtual void TearDown() {
- DeleteFile(db_name_);
+ file_util::Delete(db_name_, false);
}
};
@@ -145,7 +143,7 @@ TEST_F(VisitedLink, TestLoad) {
for (int i = 0; i < load_count; i++)
{
// make sure the file has to be re-loaded
- file_util::EvictFileFromSystemCache(db_name_);
+ file_util::EvictFileFromSystemCache(db_name_.c_str());
// cold load (no OS cache, hopefully)
{
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc
index 785409a..1fe4ce4 100644
--- a/chrome/browser/webdata/web_database_unittest.cc
+++ b/chrome/browser/webdata/web_database_unittest.cc
@@ -28,7 +28,7 @@ class WebDatabaseTest : public testing::Test {
_itow_s(static_cast<int>(GetTickCount()), b, arraysize(b), 10);
PathService::Get(chrome::DIR_TEST_DATA, &file_);
- file_ += file_util::kPathSeparator;
+ file_ += FilePath::kSeparators[0];
file_ += L"TestWebDatabase";
file_ += b;
file_ += L".db";
diff --git a/chrome/test/tab_switching/tab_switching_test.cc b/chrome/test/tab_switching/tab_switching_test.cc
index 14a993a..612181c 100644
--- a/chrome/test/tab_switching/tab_switching_test.cc
+++ b/chrome/test/tab_switching/tab_switching_test.cc
@@ -33,7 +33,7 @@ class TabSwitchingUITest : public UITest {
file_util::UpOneDirectory(&path_prefix_);
file_util::AppendToPath(&path_prefix_, L"data");
file_util::AppendToPath(&path_prefix_, L"tab_switching");
- path_prefix_ += file_util::kPathSeparator;
+ path_prefix_ += FilePath::kSeparators[0];
show_window_ = true;
}
@@ -120,7 +120,7 @@ class TabSwitchingUITest : public UITest {
for (int i = 0; i < arraysize(files); ++i) {
file_name = path_prefix_;
file_name += files[i];
- file_name += file_util::kPathSeparator;
+ file_name += FilePath::kSeparators[0];
file_name += L"index.html";
browser_proxy_->AppendTab(net::FilePathToFileURL(file_name));
number_of_new_tabs_opened++;
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 959ab28..64f4d1d 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -49,7 +49,8 @@ using base::Time;
namespace {
// what we prepend to get a file URL
-static const wchar_t kFileURLPrefix[] = L"file:///";
+static const FilePath::CharType kFileURLPrefix[] =
+ FILE_PATH_LITERAL("file:///");
// The general list of blocked ports. Will be blocked unless a specific
// protocol overrides it. (Ex: ftp can use ports 20 and 21)
@@ -638,12 +639,12 @@ void IDNToUnicodeOneComponent(const char16* comp,
namespace net {
-GURL FilePathToFileURL(const std::wstring& file_path) {
+GURL FilePathToFileURL(const FilePath& path) {
// Produce a URL like "file:///C:/foo" for a regular file, or
// "file://///server/path" for UNC. The URL canonicalizer will fix up the
// latter case to be the canonical UNC form: "file://server/path"
- std::wstring url_str(kFileURLPrefix);
- url_str.append(file_path);
+ FilePath::StringType url_string(kFileURLPrefix);
+ url_string.append(path.value());
// Now do replacement of some characters. Since we assume the input is a
// literal filename, anything the URL parser might consider special should
@@ -651,18 +652,21 @@ GURL FilePathToFileURL(const std::wstring& file_path) {
// must be the first substitution since others will introduce percents as the
// escape character
- ReplaceSubstringsAfterOffset(&url_str, 0, L"%", L"%25");
+ ReplaceSubstringsAfterOffset(&url_string, 0,
+ FILE_PATH_LITERAL("%"), FILE_PATH_LITERAL("%25"));
// semicolon is supposed to be some kind of separator according to RFC 2396
- ReplaceSubstringsAfterOffset(&url_str, 0, L";", L"%3B");
+ ReplaceSubstringsAfterOffset(&url_string, 0,
+ FILE_PATH_LITERAL(";"), FILE_PATH_LITERAL("%3B"));
- ReplaceSubstringsAfterOffset(&url_str, 0, L"#", L"%23");
+ ReplaceSubstringsAfterOffset(&url_string, 0,
+ FILE_PATH_LITERAL("#"), FILE_PATH_LITERAL("%23"));
-#if defined(WCHAR_T_IS_UTF32)
- return GURL(WideToUTF8(url_str));
-#else
- return GURL(url_str);
-#endif
+ return GURL(url_string);
+}
+
+GURL FilePathToFileURL(const std::wstring& path_str) {
+ return FilePathToFileURL(FilePath::FromWStringHack(path_str));
}
std::wstring GetSpecificHeader(const std::wstring& headers,
diff --git a/net/base/net_util.h b/net/base/net_util.h
index fb6841f..ddaa77b 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -28,6 +28,8 @@ namespace net {
// Given the full path to a file name, creates a file: URL. The returned URL
// may not be valid if the input is malformed.
+GURL FilePathToFileURL(const FilePath& path);
+// Deprecated temporary compatibility function.
GURL FilePathToFileURL(const std::wstring& file_path);
// Converts a file: URL back to a filename that can be passed to the OS. The
diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc
index 1b71c2d..787ac1a 100644
--- a/webkit/tools/test_shell/test_shell_win.cc
+++ b/webkit/tools/test_shell/test_shell_win.cc
@@ -92,13 +92,13 @@ bool MinidumpCallback(const wchar_t *dumpPath,
// will be happening on developers' machines where they have debuggers.
StackWString<kPathBufSize * 2> origPath;
origPath->append(dumpPath);
- origPath->push_back(file_util::kPathSeparator);
+ origPath->push_back(FilePath::kSeparators[0]);
origPath->append(minidumpID);
origPath->append(L".dmp");
StackWString<kPathBufSize * 2> newPath;
newPath->append(dumpPath);
- newPath->push_back(file_util::kPathSeparator);
+ newPath->push_back(FilePath::kSeparators[0]);
newPath->append(g_currentTestName);
newPath->append(L"-");
newPath->append(minidumpID);
@@ -329,7 +329,7 @@ std::string TestShell::RewriteLocalUrl(const std::string& url) {
file_util::AppendToPath(&replace_url, L"data");
file_util::AppendToPath(&replace_url, L"layout_tests");
file_util::AppendToPath(&replace_url, L"LayoutTests");
- replace_url.push_back(file_util::kPathSeparator);
+ replace_url.push_back(FilePath::kSeparators[0]);
new_url = std::string("file:///") +
WideToUTF8(replace_url).append(url.substr(kPrefixLen));
}