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

# Copyright 2017 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)

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

switch_access_dir =
    "$root_out_dir/resources/chromeos/accessibility/switch_access"

# 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 = [
  "action_manager.ts",
  "auto_scan_manager.ts",
  "cache.ts",
  "commands.ts",
  "focus_ring_manager.ts",
  "history.ts",
  "item_scan_manager.ts",
  "menu_manager.ts",
  "metrics.ts",
  "navigator.ts",
  "navigator_interfaces.ts",
  "nodes/back_button_node.ts",
  "nodes/basic_node.ts",
  "nodes/combo_box_node.ts",
  "nodes/desktop_node.ts",
  "nodes/group_node.ts",
  "nodes/keyboard_node.ts",
  "nodes/switch_access_node.ts",
  "nodes/window_node.ts",
  "point_scan_manager.ts",
  "settings_manager.ts",
  "switch_access.ts",
  "switch_access_constants.ts",
  "switch_access_loader.ts",
  "switch_access_predicate.ts",
  "text_navigation_manager.ts",
]

# JS files needed to compile TS.
js_modules = [
  "nodes/editable_text_node.js",
  "nodes/modal_dialog_node.js",
  "nodes/slider_node.js",
  "nodes/tab_node.js",
]

# Root dir must be the parent directory so it can reach common.
ts_library("ts_build") {
  root_dir = "$ts_build_staging_dir"
  out_dir = tsc_out_dir

  composite = true

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

  extra_deps = [ ":stage_ts_build" ]

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

  definitions = [
    "../definitions/accessibility_private_mv2.d.ts",
    "../definitions/automation.d.ts",
    "../definitions/clipboard_mv2.d.ts",
    "../definitions/command_line_private.d.ts",
    "../definitions/extension_types.d.ts",
    "../definitions/extensions.d.ts",
    "../definitions/runtime.d.ts",
    "../definitions/settings_private_mv2.d.ts",
    "../definitions/tabs.d.ts",
    "../definitions/windows.d.ts",
    "//tools/typescript/definitions/chrome_event.d.ts",
    "//tools/typescript/definitions/metrics_private.d.ts",
  ]

  in_files = ts_modules + js_modules

  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"
  dest_dir = switch_access_dir
  clear_dest_dirs = [ "." ]
  deps = [
    ":ts_build",
    "../common:copied_files",
  ]
  sources = [
    "background.html",
    "icons/back.svg",
    "icons/copy.svg",
    "icons/cut.svg",
    "icons/decrement.svg",
    "icons/dictation.svg",
    "icons/increment.svg",
    "icons/jumpToBeginningOfText.svg",
    "icons/jumpToEndOfText.svg",
    "icons/keyboard.svg",
    "icons/moveBackwardOneCharOfText.svg",
    "icons/moveBackwardOneWordOfText.svg",
    "icons/moveCursor.svg",
    "icons/moveDownOneLineOfText.svg",
    "icons/moveForwardOneCharOfText.svg",
    "icons/moveForwardOneWordOfText.svg",
    "icons/moveUpOneLineOfText.svg",
    "icons/paste.svg",
    "icons/scrollDownOrForward.svg",
    "icons/scrollLeft.svg",
    "icons/scrollRight.svg",
    "icons/scrollUpOrBackward.svg",
    "icons/select.svg",
    "icons/settings.svg",
    "icons/showContextMenu.svg",
    "icons/textSelectionEnd.svg",
    "icons/textSelectionStart.svg",
  ]
  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 + js_modules
  outputs = [ "$ts_build_staging_dir/{{source_target_relative}}" ]
}

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

  deps = [
    ":switch_access_extjs_tests",
    ":switch_access_mv3_extjs_tests",
  ]

  data = [
    "//chrome/browser/resources/chromeos/accessibility/common/",
    "//chrome/browser/resources/chromeos/accessibility/switch_access/",
  ]
  data += js2gtest_js_libraries
}

test_includes = [
  "../common/testing/accessibility_test_base.js",
  "../common/testing/assert_additions.js",
  "../common/testing/callback_helper.js",
  "../common/testing/e2e_test_base.js",
  "switch_access_e2e_test_base.js",
  "test_utility.js",
]

# The test base classes generate C++ code with these deps.
test_deps = [
  "//ash",
  "//ash/keyboard/ui",
  "//base",
  "//chrome/browser/ash/accessibility",
  "//chrome/browser/ash/crosapi",
  "//chrome/browser/ash/system_web_apps",
  "//chrome/common",
  "//chromeos",
]

js2gtest("switch_access_mv3_extjs_tests") {
  test_type = "extension"
  parameterized = "true"
  sources = [
    "focus_ring_manager_test.js",
    "item_scan_manager_test.js",
    "nodes/basic_node_test.js",
    "nodes/desktop_node_test.js",
    "nodes/group_node_test.js",
    "nodes/tab_node_test.js",
    "point_scan_manager_test.js",
    "switch_access_predicate_test.js",
    "switch_access_test.js",
    "text_navigation_manager_test.js",
  ]
  gen_include_files = test_includes
  deps = test_deps
  defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
}

js2gtest("switch_access_extjs_tests") {
  test_type = "extension"
  sources = [ "auto_scan_manager_test.js" ]
  gen_include_files = test_includes
  deps = test_deps
  defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
}