Chromium Code Reviews| Index: chrome/test/base/ui_test_utils.cc |
| diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc |
| index faae2365366f561d65f03a70debe1a40628fa820..c5821bba3d8bed947171ce70c069c4db8e56895f 100644 |
| --- a/chrome/test/base/ui_test_utils.cc |
| +++ b/chrome/test/base/ui_test_utils.cc |
| @@ -15,6 +15,7 @@ |
| #include "base/callback.h" |
| #include "base/command_line.h" |
| #include "base/file_path.h" |
| +#include "base/file_util.h" |
| #include "base/json/json_reader.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/message_loop.h" |
| @@ -315,6 +316,48 @@ GURL GetTestUrl(const FilePath& dir, const FilePath& file) { |
| return net::FilePathToFileURL(GetTestFilePath(dir, file)); |
| } |
| +bool GetRelativeBuildDirectory(FilePath* build_dir) { |
| + // This function is used to find the build directory so TestServer can serve |
| + // built files (nexes, etc). TestServer expects a path relative to the source |
| + // root. |
| + FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName(); |
| + FilePath src_dir; |
| + if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) |
| + return false; |
| + |
| + // We must first generate absolute paths to SRC and EXE and from there |
| + // generate a relative path. |
| + if (!exe_dir.IsAbsolute()) |
| + file_util::AbsolutePath(&exe_dir); |
| + if (!src_dir.IsAbsolute()) |
| + file_util::AbsolutePath(&src_dir); |
| + if (!exe_dir.IsAbsolute()) |
| + return false; |
| + if (!src_dir.IsAbsolute()) |
| + return false; |
| + |
| + size_t match, exe_size, src_size; |
|
Mark Seaborn
2012/08/13 22:16:59
Nit: The normal style is one variable decl per lin
|
| + std::vector<FilePath::StringType> src_parts, exe_parts; |
| + |
| + // Determine point at which src and exe diverge. |
| + exe_dir.GetComponents(&exe_parts); |
| + src_dir.GetComponents(&src_parts); |
| + exe_size = exe_parts.size(); |
| + src_size = src_parts.size(); |
| + for (match = 0; match < exe_size && match < src_size; ++match) { |
|
Mark Seaborn
2012/08/13 22:16:59
Why write src_size rather than src_parts.size()?
|
| + if (exe_parts[match] != src_parts[match]) |
| + break; |
| + } |
| + |
| + // Create a relative path. |
| + *build_dir = FilePath(); |
| + for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) |
| + *build_dir = build_dir->Append(FILE_PATH_LITERAL("..")); |
| + for (; match < exe_size; ++match) |
| + *build_dir = build_dir->Append(exe_parts[match]); |
| + return true; |
| +} |
| + |
| AppModalDialog* WaitForAppModalDialog() { |
| content::WindowedNotificationObserver observer( |
| chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, |