Commit 2efd0190 authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Reland "Capture test_api.js javascript dependencies in 2 places (rather than ~13)."

This is a reland of f8dd1ecf

Reverted inadvertently in r714447. Different root cause (https://crbug.com/1023525).

Original change's description:
> Capture test_api.js javascript dependencies in 2 places (rather than ~13).
>
> test_api.js depends on a bunch of JS libraries that appear in many lists.
>
> This CL consolidates those dependencies to two places:
>  - js2gtest.gni, and
>  - A JsTestApiConfig class declared in chrome/test/base/js_test_api.h
>
> Note not all lists captured the axs_testing.js dependency, but this change
> uses the same dependency list in all locations for consistency.
>
> TBR=aboxhall@chromium.org (mechanical change)
>
> Bug: 1000989
> Change-Id: If6e0716c03e42783a2d3529baa70475a9d305045
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1900512
> Commit-Queue: Trent Apted <tapted@chromium.org>
> Reviewed-by: Dan Beam <dbeam@chromium.org>
> Reviewed-by: Colin Blundell <blundell@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#714421}

TBR=tapted@chromium.org,dbeam@chromium.org,aboxhall@chromium.org,blundell@chromium.org,nuskos@chromium.org

Bug: 1000989, 1023795
Change-Id: I8488e9668614bae07b40d65ab2d80f6b01b85ef4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1913221Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Commit-Queue: Trent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714774}
parent f98632d7
......@@ -93,12 +93,9 @@ source_set("browser_tests") {
# The test uses data from the original location, not the copied one.
"//chrome/browser/resources/chromeos/chromevox/",
"//chrome/browser/resources/chromeos/autoclick/",
"//chrome/test/data/webui/test_api.js",
"//chrome/third_party/mock4js/",
"//third_party/accessibility-audit/axs_testing.js",
"//third_party/chaijs/chai.js",
"//ui/webui/resources/js/cr.js",
]
data += js2gtest_js_libraries
}
js2gtest("autoclick_extjs_tests") {
......
......@@ -415,12 +415,9 @@ if (is_chromeos) {
# Surprisingly, the test uses data from the original location, not the
# copied one.
"//chrome/browser/resources/chromeos/chromevox/",
"//chrome/test/data/webui/test_api.js",
"//third_party/chromevox/",
"//chrome/third_party/mock4js/",
"//third_party/accessibility-audit/axs_testing.js",
"//third_party/chaijs/chai.js",
]
data += js2gtest_js_libraries
}
}
......
......@@ -119,12 +119,9 @@ source_set("browser_tests") {
# The test uses data from the original location, not the copied one.
"//chrome/browser/resources/chromeos/chromevox/",
"//chrome/browser/resources/chromeos/select_to_speak/",
"//chrome/test/data/webui/test_api.js",
"//chrome/third_party/mock4js/",
"//third_party/accessibility-audit/axs_testing.js",
"//third_party/chaijs/chai.js",
"//ui/webui/resources/js/cr.js",
]
data += js2gtest_js_libraries
}
js2gtest("select_to_speak_extjs_tests") {
......
......@@ -101,11 +101,9 @@ source_set("browser_tests") {
data = [
"//chrome/browser/resources/chromeos/chromevox/",
"//chrome/browser/resources/chromeos/switch_access/",
"//chrome/third_party/mock4js/",
"//third_party/accessibility-audit/axs_testing.js",
"//third_party/chaijs/chai.js",
"//ui/webui/resources/js/cr.js",
]
data += js2gtest_js_libraries
}
js2gtest("switch_access_extjs_tests") {
......
......@@ -13,6 +13,7 @@ import("//build/toolchain/toolchain.gni")
import("//build/util/version.gni")
import("//chrome/chrome_repack_locales.gni")
import("//chrome/common/features.gni")
import("//chrome/test/base/js2gtest.gni")
import("//components/feature_engagement/features.gni")
import("//components/feed/features.gni")
import("//components/gwp_asan/buildflags/buildflags.gni")
......@@ -110,6 +111,8 @@ static_library("test_support") {
"base/chrome_unit_test_suite.h",
"base/find_result_waiter.cc",
"base/find_result_waiter.h",
"base/js_test_api.cc",
"base/js_test_api.h",
"base/launchservices_utils_mac.h",
"base/launchservices_utils_mac.mm",
"base/process_inspector_win.cc",
......@@ -778,7 +781,6 @@ if (!is_android) {
data = [
"data/",
"//chrome/common/extensions/docs/examples/apps/calculator/",
"//chrome/third_party/mock4js/",
"//components/test/data/arc/",
"//components/test/data/autofill/",
"//components/test/data/payments/",
......@@ -792,8 +794,6 @@ if (!is_android) {
"//ppapi/tests/test_page.css",
"//ppapi/tests/test_page.css.mock-http-headers",
"//testing/test_env.py",
"//third_party/accessibility-audit/axs_testing.js",
"//third_party/chaijs/chai.js",
"//third_party/mocha/mocha.js",
"//third_party/polymer/v1_0/components-chromium/iron-test-helpers/mock-interactions.js",
"//third_party/pywebsocket/src/mod_pywebsocket/",
......@@ -802,6 +802,7 @@ if (!is_android) {
"//ui/webui/resources/",
"$root_out_dir/browser_tests.pak",
]
data += js2gtest_js_libraries
sources = [
"../../apps/app_restore_service_browsertest.cc",
......@@ -3441,18 +3442,16 @@ test("unit_tests") {
"../browser/flag-never-expire-list.json",
"data/",
"//base/test/data/",
"//chrome/third_party/mock4js/",
"//components/test/data/",
"//extensions/test/data/",
"//google_apis/test/data/",
"//net/tools/testserver/",
"//third_party/accessibility-audit/axs_testing.js",
"//third_party/chaijs/chai.js",
"//third_party/pywebsocket/src/mod_pywebsocket/",
"//third_party/tlslite/",
"//third_party/zlib/google/test/data/",
"//tools/metrics/histograms/enums.xml",
]
data += js2gtest_js_libraries
if (is_android) {
data += [
"$root_gen_dir/chrome/android/chrome_apk_paks/chrome_100_percent.pak",
......@@ -5486,15 +5485,12 @@ if (!is_android) {
data = [
"data/",
"//chrome/third_party/mock4js/",
"//content/test/data/",
"//net/tools/testserver/",
"//ppapi/tests/test_case.html",
"//ppapi/tests/test_case.html.mock-http-headers",
"//ppapi/tests/test_page.css",
"//ppapi/tests/test_page.css.mock-http-headers",
"//third_party/accessibility-audit/axs_testing.js",
"//third_party/chaijs/chai.js",
"//third_party/mocha/mocha.js",
"//third_party/polymer/v1_0/components-chromium/iron-test-helpers/mock-interactions.js",
"//third_party/pywebsocket/src/mod_pywebsocket/",
......@@ -5508,6 +5504,7 @@ if (!is_android) {
"$root_out_dir/test_page.css.mock-http-headers",
"$root_out_dir/ui_test.pak",
]
data += js2gtest_js_libraries
if (is_linux || is_win) {
data += [
"$root_out_dir/chrome_100_percent.pak",
......
......@@ -8,31 +8,11 @@
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/js_test_api.h"
#include "components/nacl/common/buildflags.h"
#include "content/public/browser/web_ui.h"
#include "net/base/filename_util.h"
// static
const base::FilePath::CharType
JavaScriptBrowserTest::kA11yAuditLibraryJSPath[] =
FILE_PATH_LITERAL("third_party/accessibility-audit/axs_testing.js");
// static
const base::FilePath::CharType JavaScriptBrowserTest::kChaiJSPath[] =
FILE_PATH_LITERAL("third_party/chaijs/chai.js");
// static
const base::FilePath::CharType JavaScriptBrowserTest::kMockJSPath[] =
FILE_PATH_LITERAL("chrome/third_party/mock4js/mock4js.js");
// static
const base::FilePath::CharType JavaScriptBrowserTest::kWebUILibraryJS[] =
FILE_PATH_LITERAL("test_api.js");
// static
const base::FilePath::CharType JavaScriptBrowserTest::kWebUITestFolder[] =
FILE_PATH_LITERAL("webui");
void JavaScriptBrowserTest::AddLibrary(const base::FilePath& library_path) {
user_libraries_.push_back(library_path);
}
......@@ -44,11 +24,10 @@ JavaScriptBrowserTest::~JavaScriptBrowserTest() {
}
void JavaScriptBrowserTest::SetUpOnMainThread() {
base::FilePath test_data_directory;
ASSERT_TRUE(
base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory));
test_data_directory = test_data_directory.Append(kWebUITestFolder);
library_search_paths_.push_back(test_data_directory);
JsTestApiConfig config;
library_search_paths_.push_back(config.search_path);
DCHECK(user_libraries_.empty());
user_libraries_ = config.default_libraries;
// When the sanitizers (ASAN/MSAN/TSAN) are enabled, the WebUI tests
// which use this generated directory are disabled in the build.
......@@ -69,10 +48,6 @@ void JavaScriptBrowserTest::SetUpOnMainThread() {
ASSERT_TRUE(
base::PathService::Get(base::DIR_SOURCE_ROOT, &source_root_directory));
library_search_paths_.push_back(source_root_directory);
AddLibrary(base::FilePath(kMockJSPath));
AddLibrary(base::FilePath(kChaiJSPath));
AddLibrary(base::FilePath(kWebUILibraryJS));
}
// TODO(dtseng): Make this return bool (success/failure) and remove ASSERt_TRUE
......
......@@ -15,12 +15,6 @@
// A base class providing construction of javascript testing assets.
class JavaScriptBrowserTest : public InProcessBrowserTest {
public:
static const base::FilePath::CharType kA11yAuditLibraryJSPath[];
static const base::FilePath::CharType kChaiJSPath[];
static const base::FilePath::CharType kMockJSPath[];
static const base::FilePath::CharType kWebUILibraryJS[];
static const base::FilePath::CharType kWebUITestFolder[];
// Add a custom helper JS library for your test.
// If a relative path is specified, it'll be read
// as relative to the test data dir.
......
......@@ -5,6 +5,24 @@
import("//v8/gni/snapshot_toolchain.gni")
import("//v8/gni/v8.gni")
# Libraries required to generate the custom test library built with js2gtest.
# Changing the size or the order of files in this array also requires changing
# src/tools/gypv8sh.py.
js2gtest_js_input_libraries = [
"//chrome/third_party/mock4js/mock4js.js",
"//chrome/test/data/webui/test_api.js",
"//chrome/test/base/js2gtest.js",
]
# Additional libraries loaded at test runtime.
js2gtest_runtime_js_libraries = [
"//third_party/chaijs/chai.js",
"//third_party/accessibility-audit/axs_testing.js",
]
js2gtest_js_libraries =
js2gtest_js_input_libraries + js2gtest_runtime_js_libraries
# Variables:
# test_type: One of 'webui', 'unit' or 'extension' indicating what
# environment the test runs under.
......@@ -50,12 +68,7 @@ template("js2gtest") {
v8_shell_path += ".exe"
}
input_js = [
"//chrome/third_party/mock4js/mock4js.js",
"//chrome/test/data/webui/test_api.js",
"//chrome/test/base/js2gtest.js",
]
inputs = [ v8_shell_path ] + input_js
inputs = [ v8_shell_path ] + js2gtest_js_input_libraries
if (defined(invoker.deps_js)) {
inputs += [ invoker.deps_js ]
}
......@@ -83,7 +96,8 @@ template("js2gtest") {
# Need "./" for script to find binary (cur dir is not on path).
"./" + rebase_path(v8_shell_path, root_build_dir),
]
args += rebase_path(input_js, root_build_dir) + [ invoker.test_type ]
args += rebase_path(js2gtest_js_input_libraries, root_build_dir) +
[ invoker.test_type ]
if (v8_use_external_startup_data) {
args += [ "--external=y" ]
} else {
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/base/js_test_api.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "chrome/common/chrome_paths.h"
JsTestApiConfig::JsTestApiConfig() {
constexpr const base::FilePath::CharType* kLibraries[] = {
FILE_PATH_LITERAL("chrome/third_party/mock4js/mock4js.js"),
FILE_PATH_LITERAL("third_party/chaijs/chai.js"),
FILE_PATH_LITERAL("third_party/accessibility-audit/axs_testing.js"),
};
constexpr base::FilePath::CharType kWebUITestFolder[] =
FILE_PATH_LITERAL("webui");
base::FilePath test_data_directory;
CHECK(base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory));
search_path = test_data_directory.Append(kWebUITestFolder);
for (const auto* path : kLibraries)
default_libraries.emplace_back(path);
default_libraries.push_back(search_path.AppendASCII("test_api.js"));
}
JsTestApiConfig::~JsTestApiConfig() = default;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_TEST_BASE_JS_TEST_API_H_
#define CHROME_TEST_BASE_JS_TEST_API_H_
#include <vector>
#include "base/files/file_path.h"
// Shared configuration for test harnesses using test_api.js.
struct JsTestApiConfig {
JsTestApiConfig();
~JsTestApiConfig();
// The search path for client-provided libraries (i.e. DIR_TEST_DATA/webui).
base::FilePath search_path;
// The set of libraries required for test_api.js.
std::vector<base::FilePath> default_libraries;
};
#endif // CHROME_TEST_BASE_JS_TEST_API_H_
......@@ -10,6 +10,7 @@
#include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/js_test_api.h"
#include "third_party/blink/public/web/blink.h"
namespace {
......@@ -177,30 +178,14 @@ bool V8UnitTest::RunJavascriptTestF(const std::string& test_fixture,
}
void V8UnitTest::InitPathsAndLibraries() {
base::FilePath test_data;
ASSERT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &test_data));
g_test_data_directory = test_data.AppendASCII("webui");
JsTestApiConfig config;
g_test_data_directory = config.search_path;
user_libraries_ = config.default_libraries;
ASSERT_TRUE(base::PathService::Get(chrome::DIR_GEN_TEST_DATA,
&g_gen_test_data_directory));
ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &g_src_root));
AddLibrary(g_src_root.AppendASCII("chrome")
.AppendASCII("third_party")
.AppendASCII("mock4js")
.AppendASCII("mock4js.js"));
AddLibrary(g_src_root.AppendASCII("third_party")
.AppendASCII("chaijs")
.AppendASCII("chai.js"));
AddLibrary(g_src_root.AppendASCII("third_party")
.AppendASCII("accessibility-audit")
.AppendASCII("axs_testing.js"));
AddLibrary(g_test_data_directory.AppendASCII("test_api.js"));
}
void V8UnitTest::SetUp() {
......
......@@ -28,6 +28,7 @@
#include "chrome/browser/ui/webui/web_ui_test_handler.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/js_test_api.h"
#include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/url_data_source.h"
......@@ -442,8 +443,6 @@ void BaseWebUIBrowserTest::SetUpOnMainThread() {
logging::SetLogMessageHandler(&LogHandler);
AddLibrary(base::FilePath(kA11yAuditLibraryJSPath));
content::WebUIControllerFactory::UnregisterFactoryForTesting(
ChromeWebUIControllerFactory::GetInstance());
......@@ -545,9 +544,7 @@ bool BaseWebUIBrowserTest::RunJavascriptUsingHandler(
GURL BaseWebUIBrowserTest::WebUITestDataPathToURL(
const base::FilePath::StringType& path) {
base::ScopedAllowBlockingForTesting allow_blocking;
base::FilePath dir_test_data;
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data));
base::FilePath test_path(dir_test_data.Append(kWebUITestFolder).Append(path));
base::FilePath test_path(JsTestApiConfig().search_path);
EXPECT_TRUE(base::PathExists(test_path));
return net::FilePathToFileURL(test_path);
}
......
......@@ -582,12 +582,9 @@ test("chromevox_tests") {
# Surprisingly, the test uses data from the original location, not the
# copied one.
"//ui/accessibility/extensions/chromevoxclassic",
"//chrome/test/data/webui/test_api.js",
"//third_party/chromevox/",
"//chrome/third_party/mock4js/",
"//third_party/accessibility-audit/axs_testing.js",
"//third_party/chaijs/chai.js",
]
data += js2gtest_js_libraries
}
js2gtest("chromevox_unitjs_tests") {
......
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