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

# Copyright 2020 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("//testing/test.gni")
import("//tools/typescript/ts_library.gni")

assert(is_chromeos_ash)

accessibility_common_out_dir =
    "$root_out_dir/resources/chromeos/accessibility/common"
tsc_out_dir = "$target_gen_dir/tsc"

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

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

js_sources = [
  "gdocs_script.js",
  "testing/accessibility_test_base.js",
  "testing/test_node_generator.js",
]

# Add typescript files to compile here.
ts_modules = [
  "action_fulfillment/context_checker.ts",
  "action_fulfillment/input_controller.ts",
  "action_fulfillment/macros/custom_callback_macro.ts",
  "action_fulfillment/macros/delete_prev_sent_macro.ts",
  "action_fulfillment/macros/input_text_view_macro.ts",
  "action_fulfillment/macros/key_press_macro.ts",
  "action_fulfillment/macros/macro.ts",
  "action_fulfillment/macros/mouse_click_macro.ts",
  "action_fulfillment/macros/nav_sent_macro.ts",
  "action_fulfillment/macros/repeat_macro.ts",
  "action_fulfillment/macros/repeatable_key_press_macro.ts",
  "action_fulfillment/macros/smart_delete_phrase_macro.ts",
  "action_fulfillment/macros/smart_insert_before_macro.ts",
  "action_fulfillment/macros/smart_replace_phrase_macro.ts",
  "action_fulfillment/macros/smart_select_between_macro.ts",
  "action_fulfillment/macros/toggle_dictation_macro.ts",
  "array_util.ts",
  "async_util.ts",
  "automation_predicate.ts",
  "automation_util.ts",
  "bridge_callback_manager.ts",
  "bridge_helper.ts",
  "browser_util.ts",
  "chrome_event_handler.ts",
  "constants.ts",
  "cursors/cursor.ts",
  "cursors/range.ts",
  "cursors/recovery_strategy.ts",
  "event_generator.ts",
  "event_handler.ts",
  "flags.ts",
  "instance_checker.ts",
  "key_code.ts",
  "local_storage.ts",
  "node_navigation_utils.ts",
  "node_utils.ts",
  "paragraph_utils.ts",
  "rect_util.ts",
  "repeated_event_handler.ts",
  "repeated_tree_change_handler.ts",
  "sentence_utils.ts",
  "settings.ts",
  "string_util.ts",
  "testing/test_import_manager.ts",
  "tree_walker.ts",
  "word_utils.ts",
]

# The relative path in the staging directory of TS modules that need to be copied from another directory.
copied_ts_modules = [ "action_fulfillment/macros/macro_names.ts" ]

ts_definitions = [
  "../definitions/accessibility_private_mv2.d.ts",
  "../definitions/automation.d.ts",
  "../definitions/command_line_private.d.ts",
  "../definitions/extensions.d.ts",
  "../definitions/extension_types.d.ts",
  "../definitions/i18n.d.ts",
  "../definitions/runtime.d.ts",
  "../definitions/settings_private_mv2.d.ts",
  "../definitions/storage_mv2.d.ts",
  "../definitions/tabs.d.ts",
  "../definitions/tts.d.ts",
  "../definitions/windows.d.ts",
  "//tools/typescript/definitions/chrome_event.d.ts",
]

# 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_sources") {
  sources = js_sources + ts_modules
  outputs = [ "$ts_build_staging_dir/{{source_target_relative}}" ]
}

copy("copy_ash_common_macros") {
  sources = [ "//ash/webui/common/resources/accessibility/macro_names.ts" ]
  outputs = [ "$ts_build_staging_dir/action_fulfillment/macros/macro_names.ts" ]
}

ts_library("ts_build") {
  root_dir = "$ts_build_staging_dir"
  out_dir = tsc_out_dir
  definitions = ts_definitions
  composite = true
  in_files = ts_modules + js_sources + copied_ts_modules

  # Targets that need to run before running the TS build.
  extra_deps = [
    # copied files in staging directory.
    ":copy_ash_common_macros",
    ":stage_ts_sources",
  ]

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

run_jsbundler("copied_files") {
  mode = "copy"
  dest_dir = accessibility_common_out_dir
  deps = [ ":ts_build" ]
  sources =
      js_sources + filter_include(get_target_outputs(":ts_build"), [ "*.js" ])

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

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

  deps = [ ":accessibility_tests" ]

  # TODO(jamescook): Figure out which of these are really necessary.
  data = [
    "$root_out_dir/chrome_100_percent.pak",
    "$root_out_dir/chrome_200_percent.pak",
    "$root_out_dir/locales/en-US.pak",
    "$root_out_dir/locales/fr.pak",
    "$root_out_dir/resources.pak",

    # The test uses data from the original location.
    "//chrome/browser/resources/chromeos/accessibility/common/",
  ]
  data += js2gtest_js_libraries
}

js2gtest("accessibility_tests") {
  test_type = "extension"
  sources = [
    "array_util_test.js",
    "automation_predicate_test.js",
    "automation_util_test.js",
    "cursors/cursors_test.js",
    "cursors/recovery_strategy_test.js",
    "event_generator_test.js",
    "local_storage_test.js",
    "paragraph_utils_overflow_test.js",
    "rect_util_test.js",
    "repeated_event_handler_test.js",
    "repeated_tree_change_handler_test.js",
    "string_util_test.js",
    "tree_walker_test.js",
  ]

  # These are unit tests run under an extension environment to get ES6 module support.
  sources += [
    "node_navigation_utils_unittest.js",
    "node_utils_unittest.js",
    "paragraph_utils_unittest.js",
    "sentence_utils_unittest.js",
    "word_utils_unittest.js",
  ]

  gen_include_files = [
    "testing/accessibility_test_base.js",
    "testing/assert_additions.js",
    "testing/callback_helper.js",
    "testing/common_e2e_test_base.js",
    "testing/doc_utils.js",
    "testing/e2e_test_base.js",
    "testing/mock_storage.js",
    "testing/snippets.js",
  ]

  if (is_chromeos_ash) {
    # 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" ]
}