Commit d1a65132 authored by A Olsen's avatar A Olsen Committed by Commit Bot

Fix V8UnitTest to also check the src root for src files.

The js2gtest rule with test_type = "unit" relies on this behavior
when gen_include_files are used - but until now it didn't work.

Bug: 947036
Change-Id: Ieed195c9be9d3c0873e66592d99ace64ccdf8b10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1543529Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Commit-Queue: A Olsen <olsen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#646099}
parent bf95613a
...@@ -38,12 +38,41 @@ bool g_had_errors = false; ...@@ -38,12 +38,41 @@ bool g_had_errors = false;
// testDone results. // testDone results.
bool g_test_result_ok = false; bool g_test_result_ok = false;
// Location of src root.
base::FilePath g_src_root;
// Location of test data (currently test/data/webui). // Location of test data (currently test/data/webui).
base::FilePath g_test_data_directory; base::FilePath g_test_data_directory;
// Location of generated test data (<(PROGRAM_DIR)/test_data). // Location of generated test data (<(PROGRAM_DIR)/test_data).
base::FilePath g_gen_test_data_directory; base::FilePath g_gen_test_data_directory;
// Finds the file that is indicated by |library_path|, updates |library_path|
// to be an absolute path to that file, and returns true.
// If no file is found, returns false.
bool FindLibraryFile(base::FilePath* library_path) {
if (library_path->IsAbsolute()) {
// Absolute file. Only one place to look.
return base::PathExists(*library_path);
}
// Look for relative file.
base::FilePath possible_path = g_src_root.Append(*library_path);
if (!base::PathExists(possible_path)) {
possible_path = g_gen_test_data_directory.Append(*library_path);
if (!base::PathExists(possible_path)) {
possible_path = g_test_data_directory.Append(*library_path);
if (!base::PathExists(possible_path)) {
return false; // Couldn't find relative file anywhere.
}
}
}
*library_path = base::MakeAbsoluteFilePath(possible_path);
return true;
}
} // namespace } // namespace
V8UnitTest::V8UnitTest() : handle_scope_(blink::MainThreadIsolate()) { V8UnitTest::V8UnitTest() : handle_scope_(blink::MainThreadIsolate()) {
...@@ -64,14 +93,14 @@ bool V8UnitTest::ExecuteJavascriptLibraries() { ...@@ -64,14 +93,14 @@ bool V8UnitTest::ExecuteJavascriptLibraries() {
++user_libraries_iterator) { ++user_libraries_iterator) {
std::string library_content; std::string library_content;
base::FilePath library_file(*user_libraries_iterator); base::FilePath library_file(*user_libraries_iterator);
if (!user_libraries_iterator->IsAbsolute()) {
base::FilePath gen_file = g_gen_test_data_directory.Append(library_file); if (!FindLibraryFile(&library_file)) {
library_file = base::PathExists(gen_file) ? ADD_FAILURE() << "Couldn't find " << library_file.value();
gen_file : g_test_data_directory.Append(*user_libraries_iterator); return false;
} }
library_file = base::MakeAbsoluteFilePath(library_file);
if (!base::ReadFileToString(library_file, &library_content)) { if (!base::ReadFileToString(library_file, &library_content)) {
ADD_FAILURE() << library_file.value(); ADD_FAILURE() << "Error reading " << library_file.value();
return false; return false;
} }
ExecuteScriptInContext(library_content, library_file.MaybeAsASCII()); ExecuteScriptInContext(library_content, library_file.MaybeAsASCII());
...@@ -156,21 +185,20 @@ void V8UnitTest::InitPathsAndLibraries() { ...@@ -156,21 +185,20 @@ void V8UnitTest::InitPathsAndLibraries() {
ASSERT_TRUE(base::PathService::Get(chrome::DIR_GEN_TEST_DATA, ASSERT_TRUE(base::PathService::Get(chrome::DIR_GEN_TEST_DATA,
&g_gen_test_data_directory)); &g_gen_test_data_directory));
base::FilePath src_root; ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &g_src_root));
ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &src_root));
AddLibrary(src_root.AppendASCII("chrome") AddLibrary(g_src_root.AppendASCII("chrome")
.AppendASCII("third_party") .AppendASCII("third_party")
.AppendASCII("mock4js") .AppendASCII("mock4js")
.AppendASCII("mock4js.js")); .AppendASCII("mock4js.js"));
AddLibrary(src_root.AppendASCII("third_party") AddLibrary(g_src_root.AppendASCII("third_party")
.AppendASCII("chaijs") .AppendASCII("chaijs")
.AppendASCII("chai.js")); .AppendASCII("chai.js"));
AddLibrary(src_root.AppendASCII("third_party") AddLibrary(g_src_root.AppendASCII("third_party")
.AppendASCII("accessibility-audit") .AppendASCII("accessibility-audit")
.AppendASCII("axs_testing.js")); .AppendASCII("axs_testing.js"));
AddLibrary(g_test_data_directory.AppendASCII("test_api.js")); AddLibrary(g_test_data_directory.AppendASCII("test_api.js"));
} }
......
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