1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
9 #include "base/files/file_path.h"
10 #include "chrome/test/chromedriver/chrome/chrome_finder.h"
11 #include "testing/gtest/include/gtest/gtest.h"
15 bool PathIn(const std::vector<base::FilePath>& list,
16 const base::FilePath& path) {
17 for (size_t i = 0; i < list.size(); ++i) {
24 void AssertFound(const base::FilePath& found,
25 const std::vector<base::FilePath>& existing_paths,
26 const std::vector<base::FilePath>& rel_paths,
27 const std::vector<base::FilePath>& locations) {
29 ASSERT_TRUE(internal::FindExe(
30 base::Bind(&PathIn, existing_paths),
34 ASSERT_EQ(found, exe);
39 TEST(ChromeFinderTest, FindExeFound) {
40 base::FilePath found =
41 base::FilePath().AppendASCII("exists").AppendASCII("exists");
42 std::vector<base::FilePath> existing_paths;
43 existing_paths.push_back(found);
44 std::vector<base::FilePath> rel_paths;
45 rel_paths.push_back(found.BaseName());
46 std::vector<base::FilePath> locations;
47 locations.push_back(found.DirName());
48 ASSERT_NO_FATAL_FAILURE(
49 AssertFound(found, existing_paths, rel_paths, locations));
52 TEST(ChromeFinderTest, FindExeShouldGoInOrder) {
53 base::FilePath dir(FILE_PATH_LITERAL("dir"));
54 base::FilePath first = dir.AppendASCII("first");
55 base::FilePath second = dir.AppendASCII("second");
56 std::vector<base::FilePath> existing_paths;
57 existing_paths.push_back(first);
58 existing_paths.push_back(second);
59 std::vector<base::FilePath> rel_paths;
60 rel_paths.push_back(first.BaseName());
61 rel_paths.push_back(second.BaseName());
62 std::vector<base::FilePath> locations;
63 locations.push_back(dir);
64 ASSERT_NO_FATAL_FAILURE(
65 AssertFound(first, existing_paths, rel_paths, locations));
68 TEST(ChromeFinderTest, FindExeShouldPreferExeNameOverDir) {
69 base::FilePath dir1(FILE_PATH_LITERAL("dir1"));
70 base::FilePath dir2(FILE_PATH_LITERAL("dir2"));
71 base::FilePath preferred(FILE_PATH_LITERAL("preferred"));
72 base::FilePath nonpreferred(FILE_PATH_LITERAL("nonpreferred"));
73 std::vector<base::FilePath> existing_paths;
74 existing_paths.push_back(dir2.Append(preferred));
75 existing_paths.push_back(dir1.Append(nonpreferred));
76 std::vector<base::FilePath> rel_paths;
77 rel_paths.push_back(preferred);
78 rel_paths.push_back(nonpreferred);
79 std::vector<base::FilePath> locations;
80 locations.push_back(dir1);
81 locations.push_back(dir2);
82 ASSERT_NO_FATAL_FAILURE(AssertFound(
83 dir2.Append(preferred), existing_paths, rel_paths, locations));
86 TEST(ChromeFinderTest, FindExeNotFound) {
87 base::FilePath found =
88 base::FilePath().AppendASCII("exists").AppendASCII("exists");
89 std::vector<base::FilePath> existing_paths;
90 std::vector<base::FilePath> rel_paths;
91 rel_paths.push_back(found.BaseName());
92 std::vector<base::FilePath> locations;
93 locations.push_back(found.DirName());
95 ASSERT_FALSE(internal::FindExe(
96 base::Bind(&PathIn, existing_paths),
102 TEST(ChromeFinderTest, NoCrash) {
103 // It's not worthwhile to check the validity of the path, so just check