chromium/components/autofill/ios/form_util/BUILD.gn

# Copyright 2018 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/features.gni")
import("//ios/web/public/js_messaging/optimize_js.gni")
import("//ios/web/public/js_messaging/optimize_ts.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")

source_set("form_util") {
  sources = [
    "form_activity_observer.h",
    "form_activity_observer_bridge.h",
    "form_activity_observer_bridge.mm",
    "form_activity_params.h",
    "form_activity_params.mm",
    "form_activity_tab_helper.h",
    "form_activity_tab_helper.mm",
  ]
  deps = [
    ":form_util_feature",
    "//base",
    "//components/autofill/core/common",
    "//components/autofill/ios/browser:util",
    "//ios/web/public",
    "//ios/web/public/js_messaging",
  ]
  configs += [ "//build/config/compiler:wexit_time_destructors" ]
}

source_set("form_util_feature") {
  sources = [
    "form_util_java_script_feature.h",
    "form_util_java_script_feature.mm",
  ]
  deps = [
    ":autofill_form_features",
    ":fill_js",
    ":form_js",
    "//base",
    "//components/autofill/ios/common:common",
    "//ios/web/public/js_messaging",
  ]
  configs += [ "//build/config/compiler:wexit_time_destructors" ]
}

source_set("form_handler_feature") {
  sources = [
    "form_handlers_java_script_feature.h",
    "form_handlers_java_script_feature.mm",
  ]
  deps = [
    ":child_frame_registrar",
    ":form_handlers_js",
    ":form_util",
    ":form_util_feature",
    "//base",
    "//components/autofill/core/common:features",
    "//components/autofill/ios/common",
    "//components/password_manager/ios:password_manager_feature_header",
    "//ios/web/public/js_messaging",
  ]
  configs += [ "//build/config/compiler:wexit_time_destructors" ]
}

# For inclusion by other TS/JS files, so they can check feature state
compile_ts("autofill_form_features_ts") {
  sources = [ "resources/autofill_form_features.ts" ]
  deps = [ "//ios/web/public/js_messaging:gcrweb" ]
}

# For bundling with form_util_feature, which enables/disables features
optimize_js("autofill_form_features") {
  deps = [
    ":autofill_form_features_ts",
    "//ios/web/public/js_messaging:gcrweb",
  ]

  _script = filter_include(get_target_outputs(":autofill_form_features_ts"),
                           [ "*autofill_form_features.js" ])
  primary_script = _script[0]
  sources = _script
}

compile_ts("child_frame_registration_ts_lib") {
  sources = [ "resources/child_frame_registration_lib.ts" ]
  deps = [
    ":autofill_form_features_ts",
    "//ios/web/public/js_messaging:frame_id",
    "//ios/web/public/js_messaging:gcrweb",
    "//ios/web/public/js_messaging:util_scripts",
  ]
}

optimize_ts("child_frame_registration_test_ts") {
  sources = [ "resources/child_frame_registration_test.ts" ]
  deps = [
    ":autofill_form_features_ts",
    ":child_frame_registration_ts_lib",
    "//ios/web/public/js_messaging:frame_id",
    "//ios/web/public/js_messaging:gcrweb",
    "//ios/web/public/js_messaging:util_scripts",
  ]
}

compile_ts("fill_js_dependencies") {
  sources = [
    "resources/create_fill_namespace.ts",
    "resources/fill_constants.ts",
    "resources/fill_element_inference.ts",
    "resources/fill_element_inference_util.ts",
    "resources/fill_util.ts",
  ]

  deps = [
    ":autofill_form_features_ts",
    "//ios/web/public/js_messaging:gcrweb",
    "//ios/web/public/js_messaging:util_scripts",
  ]
}

optimize_ts("fill_js") {
  sources = [ "resources/fill.ts" ]

  deps = [
    ":child_frame_registration_ts_lib",
    ":fill_js_dependencies",
    "//ios/web/public/js_messaging:frame_id",
    "//ios/web/public/js_messaging:gcrweb",
    "//ios/web/public/js_messaging:util_scripts",
  ]
}

optimize_ts("form_js") {
  sources = [ "resources/form.ts" ]

  deps = [
    "//components/autofill/ios/form_util:fill_js_dependencies",
    "//ios/web/public/js_messaging:gcrweb",
    "//ios/web/public/js_messaging:util_scripts",
  ]
}

optimize_ts("form_handlers_js") {
  sources = [ "resources/form_handlers.ts" ]
  deps = [
    ":autofill_form_features_ts",
    ":child_frame_registration_ts_lib",
    "//ios/web/public/js_messaging:frame_id",
    "//ios/web/public/js_messaging:gcrweb",
    "//ios/web/public/js_messaging:util_scripts",
  ]
}

source_set("test_support") {
  testonly = true
  sources = [
    "autofill_test_with_web_state.h",
    "autofill_test_with_web_state.mm",
    "test_form_activity_observer.h",
    "test_form_activity_observer.mm",
    "test_form_activity_tab_helper.h",
    "test_form_activity_tab_helper.mm",
  ]
  deps = [
    ":form_handler_feature",
    ":form_util",
    ":form_util_feature",
    "//base",
    "//base/test:test_support",
    "//ios/web/public",
    "//ios/web/public/js_messaging",
    "//ios/web/public/test",
    "//ios/web/public/test:test_fixture",
    "//testing/gtest",
  ]
}

source_set("child_frame_registrar") {
  sources = [
    "child_frame_registrar.h",
    "child_frame_registrar.mm",
  ]
  deps = [
    "//base",
    "//components/autofill/core/common",
    "//components/autofill/ios/browser:util",
    "//ios/web/public",
    "//ios/web/public/js_messaging",
  ]
}

source_set("unit_tests") {
  testonly = true
  sources = [
    "child_frame_registrar_unittest.mm",
    "fill_js_unittest.mm",
    "form_activity_observer_bridge_unittest.mm",
    "form_activity_tab_helper_unittest.mm",
    "form_unittest.mm",
  ]
  deps = [
    ":child_frame_registrar",
    ":fill_js",
    ":form_handler_feature",
    ":form_js",
    ":form_util",
    ":form_util_feature",
    ":test_support",
    "//base",
    "//base/test:test_support",
    "//components/autofill/ios/browser",
    "//components/autofill/ios/browser:util",
    "//ios/web/public/js_messaging",
    "//ios/web/public/test:javascript_test",
    "//ios/web/public/test:test_fixture",
    "//ios/web/public/test:util",
    "//ios/web/public/test/fakes",
    "//testing/gtest",
  ]
}
if (is_ios) {
  fuzzer_test("form_activity_tab_helper_fuzzer") {
    additional_configs = [ "//testing/libfuzzer:build_for_ios_clusterfuzz_job" ]
    sources = [ "form_activity_tab_helper_fuzzer.mm" ]
    deps = [
      ":form_util",
      "//base/test:test_support",
      "//ios/web/public",
      "//ios/web/public/js_messaging",
      "//ios/web/public/js_messaging/fuzzer_support",
      "//ios/web/public/js_messaging/fuzzer_support:js_message_proto",
      "//ios/web/public/test",
      "//ios/web/public/test:fuzzer_support",
      "//ios/web/public/test:test_fixture",
      "//third_party/libprotobuf-mutator",
    ]
  }
}