Commit fb4ec2b8 authored by Artur Khachatryan's avatar Artur Khachatryan Committed by Commit Bot

[ChromeDriver] Add Chrome binaries search in system PATH

Adding searching for Chrome binaries in the system PATH as well.


bug: chromedriver:2550
Change-Id: I42c3ad1618e324c964e9b420b2399ce5c8039dab
Reviewed-on: https://chromium-review.googlesource.com/1211744
Commit-Queue: Artur Khachatryan <khachatryan@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589445}
parent b196f14f
......@@ -12,10 +12,13 @@
#include "base/base_paths.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/macros.h"
#include "base/path_service.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#if defined(OS_WIN)
......@@ -64,6 +67,40 @@ void GetApplicationDirs(std::vector<base::FilePath>* locations) {
}
#endif
void GetPathsFromEnvironment(std::vector<base::FilePath>* paths) {
base::FilePath::StringType delimiter;
base::FilePath::StringType commonPath;
std::string path;
std::unique_ptr<base::Environment> env(base::Environment::Create());
if (!env->GetVar("PATH", &path)) {
return;
}
#if defined(OS_WIN)
commonPath = base::UTF8ToWide(path);
delimiter = L";";
#else
commonPath = path;
delimiter = ":";
#endif
std::vector<base::FilePath::StringType> path_entries = base::SplitString(
commonPath, delimiter, base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
for (auto& path_entry : path_entries) {
#if defined(OS_WIN)
size_t size = path_entry.size();
if (size >= 2 && path_entry[0] == '"' && path_entry[size - 1] == '"') {
path_entry.erase(0, 1);
path_entry.erase(size - 2, 1);
}
#endif
if (path_entry.size() > 0)
paths->emplace_back(path_entry);
}
}
} // namespace
namespace internal {
......@@ -124,6 +161,7 @@ bool FindChrome(base::FilePath* browser_exe) {
std::vector<base::FilePath> locations;
GetApplicationDirs(&locations);
GetPathsFromEnvironment(&locations);
return internal::FindExe(
base::Bind(&base::PathExists),
browser_exes,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment