chromium/chrome/browser/resources/chromeos/accessibility/enhanced_network_tts/BUILD.gn

# Copyright 2021 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/chromeos/ui_mode.gni")
import("//build/config/features.gni")
import(
    "//chrome/browser/resources/chromeos/accessibility/tools/run_jsbundler.gni")
import("//chrome/common/features.gni")
import("//chrome/test/base/ash/js2gtest.gni")
import("//tools/typescript/ts_library.gni")

assert(is_chromeos_ash)

group("build") {
  deps = [ ":copied_files" ]
}

enhanced_network_tts_dir =
    "$root_out_dir/resources/chromeos/accessibility/enhanced_network_tts"

# Directory where typescript build will occur.
ts_build_staging_dir = "$target_gen_dir/ts_build_staging"

tsc_out_dir = "$target_gen_dir/tsc"

common_tsc_dir =
    "$root_gen_dir/chrome/browser/resources/chromeos/accessibility/common/tsc"

# TS files to compile.
ts_modules = [
  "background.ts",
  "enhanced_network_tts.ts",
]

# JS files needed by the TS compiler.
js_deps = []

# Root dir must be parent directory to access common/.
ts_library("ts_build") {
  root_dir = "$ts_build_staging_dir"
  out_dir = tsc_out_dir

  deps = [ "../common:ts_build" ]

  extra_deps = [ ":stage_ts_build" ]

  path_mappings =
      [ "/common/*|" + rebase_path("$common_tsc_dir/*", target_gen_dir) ]

  definitions = [
    "mojo_bindings_externs.d.ts",
    "../definitions/extensions.d.ts",
    "../definitions/extension_types.d.ts",
    "../definitions/runtime.d.ts",
    "../definitions/tabs.d.ts",
    "../definitions/tts.d.ts",
    "../definitions/tts_engine.d.ts",
    "../definitions/windows.d.ts",
    "//tools/typescript/definitions/chrome_event.d.ts",
  ]

  in_files = ts_modules + js_deps

  tsconfig_base = "../tsconfig.base.json"
}

# Instead of setting up one copy target for each subdirectory, use a script
# to copy all files.
run_jsbundler("copied_files") {
  mode = "copy"
  deps = [
    ":ts_build",
    "../common:copied_files",
  ]
  dest_dir = enhanced_network_tts_dir
  sources = [ "background.html" ]
  sources += filter_include(get_target_outputs(":ts_build"), [ "*.js" ])

  rewrite_rules = [
    rebase_path("$tsc_out_dir", root_build_dir) + ":",
    rebase_path(".", root_build_dir) + ":",
    rebase_path(closure_library_dir, root_build_dir) + ":closure",
  ]
}

# Copy all JS and TS sources to a staging folder. All generated TS/JS files
# will also be copied into this folder, which will allow us to support a TS
# build that uses both checked-in and generated files.
copy("stage_ts_build") {
  sources = ts_modules
  outputs = [ "$ts_build_staging_dir/{{source_target_relative}}" ]
}

source_set("browser_tests") {
  testonly = true
  assert(enable_extensions)

  deps = [ ":enhanced_network_tts_extjs_tests" ]

  data = [
    "$root_out_dir/resources/chromeos/accessibility/enhanced_network_tts/background.html",
    "$root_out_dir/resources/chromeos/accessibility/enhanced_network_tts/background.js",
    "$root_out_dir/resources/chromeos/accessibility/enhanced_network_tts/enhanced_network_tts.js",
    "//chrome/browser/resources/chromeos/accessibility/common/",
    "//chrome/browser/resources/chromeos/accessibility/enhanced_network_tts/",
  ]
  data += js2gtest_js_libraries
}

js2gtest("enhanced_network_tts_extjs_tests") {
  test_type = "extension"
  sources = [
    "enhanced_network_tts_unittest.js",
    "error_handling_unittest.js",
  ]
  gen_include_files = [
    "../common/testing/accessibility_test_base.js",
    "../common/testing/e2e_test_base.js",
    "enhanced_network_tts_e2e_test_base.js",
    "mock_mojo_private.js",
  ]

  # The test base classes generate C++ code with these deps.
  deps = [
    "//ash",
    "//base",
    "//chrome/browser/ash/accessibility",
    "//chrome/browser/ash/crosapi",
    "//chrome/browser/ash/system_web_apps",
    "//chrome/common",
  ]
  defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
}