# Copyright 2014 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.

import("../../../tools/bindings/mojom.gni")

group("test_data_deps") {
  testonly = true
  data_deps = [
    ":test_interfaces_js_data_deps",
    ":test_associated_interfaces_js_data_deps",
    ":validation_test_data",
    ":validation_test_data_list",
  ]
}

copy("validation_test_data") {
  testonly = true
  sources = [
    "data/validation",
  ]
  outputs = [
    "$root_gen_dir/layout_test_data/{{source_root_relative_dir}}/{{source_file_part}}",
  ]
}

action_foreach("validation_test_data_list") {
  testonly = true
  script = "//mojo/public/tools/bindings/gen_data_files_list.py"
  inputs = mojom_generator_sources
  sources = [
    "data/validation",
  ]
  outputs = [
    "$root_gen_dir/layout_test_data/{{source_root_relative_dir}}/{{source_file_part}}_index.txt",
  ]
  args = [
    "-d",
    rebase_path(sources[0], root_build_dir),
    "-o",
    rebase_path(outputs[0], root_build_dir),
  ]
}

mojom("test_interfaces") {
  testonly = true
  sources = [
    "math_calculator.mojom",
    "no_module.mojom",
    "ping_service.mojom",
    "rect.mojom",
    "regression_tests.mojom",
    "sample_factory.mojom",
    "sample_interfaces.mojom",
    "sample_service.mojom",
    "scoping.mojom",
    "serialization_test_structs.mojom",
    "test_bad_messages.mojom",
    "test_constants.mojom",
    "test_data_view.mojom",
    "test_name_generator.mojom",
    "test_native_types.mojom",
    "test_structs.mojom",
    "test_sync_methods.mojom",
    "test_unions.mojom",
    "validation_test_interfaces.mojom",
  ]
  public_deps = [
    ":echo",
    ":test_mojom_import",
    ":test_mojom_import2",
  ]

  # TODO(crbug.com/714018): Convert the implementation to use OnceCallback.
  use_once_callback = false

  support_lazy_serialization = true

  # Validation tests require precise message content matching, so we avoid
  # scrambling message IDs for test interfaces.
  scramble_message_ids = false
}

component("test_export_component") {
  testonly = true
  deps = [
    ":test_export",
  ]
}

if (!is_ios) {
  component("test_export_blink_component") {
    testonly = true
    deps = [
      ":test_export_blink",
    ]
  }
}

mojom("test_export") {
  testonly = true
  sources = [
    "test_export.mojom",
  ]
  export_class_attribute = "MOJO_TEST_EXPORT"
  export_define = "MOJO_TEST_IMPLEMENTATION=1"
  export_header = "mojo/public/cpp/bindings/tests/mojo_test_export.h"
  if (!is_ios) {
    export_class_attribute_blink = "MOJO_TEST_BLINK_EXPORT"
    export_define_blink = "MOJO_TEST_BLINK_IMPLEMENTATION=1"
    export_header_blink =
        "mojo/public/cpp/bindings/tests/mojo_test_blink_export.h"
  }
  visibility = [ ":test_export_component" ]
  if (!is_ios) {
    visibility_blink = [ ":test_export_blink_component" ]
  }
}

mojom("test_exported_import") {
  testonly = true
  sources = [
    "test_import.mojom",
  ]
  public_deps = [
    ":test_export",
  ]

  overridden_deps = [ ":test_export" ]
  component_deps = [ ":test_export_component" ]
  if (!is_ios) {
    overridden_deps_blink = [ ":test_export" ]
    component_deps_blink = [ ":test_export_blink_component" ]
  }
}

# Used to test that it is okay to call mojom::Foo::Serialize()/Deserialize()
# even if the mojom target is linked into another component.
#
# We don't use |test_export_component| for this test because
# //mojo/public/cpp/bindings/tests depends on both |test_export_component| and
# |test_exported_import| and therefore actually get the shared cpp sources of
# test_export.mojom from |test_exported_import|.
component("test_export_component2") {
  testonly = true
  public_deps = [
    ":test_export2",
  ]
}

mojom("test_export2") {
  testonly = true
  sources = [
    "test_export2.mojom",
  ]
  export_class_attribute = "MOJO_TEST_EXPORT"
  export_define = "MOJO_TEST_IMPLEMENTATION=1"
  export_header = "mojo/public/cpp/bindings/tests/mojo_test_export.h"
  visibility = [ ":test_export_component2" ]
}

mojom("test_mojom_import") {
  testonly = true
  sources = [
    "sample_import.mojom",
  ]
}

mojom("test_mojom_import_wrapper") {
  testonly = true
  public_deps = [
    ":test_mojom_import",
  ]
}

mojom("test_mojom_import_wrapper_wrapper") {
  testonly = true
  public_deps = [
    ":test_mojom_import_wrapper",
  ]
}

mojom("test_mojom_import2") {
  testonly = true
  sources = [
    "sample_import2.mojom",
  ]
  public_deps = [
    ":test_mojom_import",
    ":test_mojom_import_wrapper_wrapper",
  ]
}

mojom("test_struct_traits_interfaces") {
  testonly = true
  sources = [
    "struct_with_traits.mojom",
  ]

  # TODO(crbug.com/714018): Convert the implementation to use OnceCallback.
  use_once_callback = false

  support_lazy_serialization = true
}

mojom("test_associated_interfaces") {
  # These files are not included in the test_interfaces target because
  # associated interfaces are not supported by all bindings languages yet.
  testonly = true
  sources = [
    "test_associated_interfaces.mojom",
    "validation_test_associated_interfaces.mojom",
  ]

  public_deps = [
    ":test_interfaces",
  ]

  # TODO(crbug.com/714018): Convert the implementation to use OnceCallback.
  use_once_callback = false

  # Validation tests require precise message content matching, so we avoid
  # scrambling message IDs for test interfaces.
  scramble_message_ids = false
}

mojom("versioning_test_service_interfaces") {
  testonly = true
  sources = [
    "versioning_test_service.mojom",
  ]
}

mojom("versioning_test_client_interfaces") {
  testonly = true
  sources = [
    "versioning_test_client.mojom",
  ]
}

mojom("test_wtf_types") {
  testonly = true

  sources = [
    "test_wtf_types.mojom",
  ]

  # TODO(crbug.com/714018): Convert the implementation to use OnceCallback.
  use_once_callback = false
}

mojom("test_no_sources") {
  testonly = true

  public_deps = [
    ":test_interfaces",
  ]
}

mojom("echo") {
  testonly = true
  sources = [
    "echo.mojom",
    "echo_import/echo_import.mojom",
  ]
}
