chromium/components/openscreen_platform/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("//testing/test.gni")

visibility = [ ":*" ]

# Network service-based implementation of Open Screen platform.
# Incompatible with ":openscreen_platform_using_net_sockets".
source_set("openscreen_platform") {
  visibility += [ "*" ]
  public = [ "network_context.h" ]

  sources = [
    "network_context.cc",
    "network_context.h",
    "tls_client_connection.cc",
    "tls_client_connection.h",
    "tls_connection_factory.cc",
    "tls_connection_factory.h",
    "udp_socket.cc",
    "udp_socket.h",
  ]

  public_deps = [
    ":openscreen_platform_without_sockets",
    "//base",
    "//services/network/public/cpp",
    "//services/network/public/mojom",
  ]

  deps = [
    "//mojo/public/cpp/bindings",
    "//mojo/public/cpp/system",
    "//net",
    "//services/network:network_service",
    "//third_party/openscreen/src/platform:api",
  ]

  friend = [ ":unittests" ]
}

# //net-based implementation of UdpSocket for use by targets that cannot use the
# Network service.
# Incompatible with `:openscreen_platform`.
source_set("openscreen_platform_using_net_sockets") {
  testonly = true
  visibility += [
    "//components/cast_streaming/test:test_sender_using_net_sockets",
    "//media/cast:media_vpx_quantizer_parser_fuzzer",
  ]
  if (is_android || is_ios) {
    # Allow broader visibility for platforms with unique generated targets.
    visibility += [ "//components/cast_streaming/browser:*" ]
  }

  assert_no_deps = [ "//services/network:network_service" ]

  public = []

  sources = [
    "net_udp_socket.cc",
    "net_udp_socket.h",
  ]

  public_deps = [ ":openscreen_platform_without_sockets" ]

  deps = [
    "//base",
    "//net",
    "//third_party/openscreen/src/platform:api",
  ]
}

# Implementation of //third_party/openscreen/src/platform:api with the exception
# of network sockets, which are provided by one of the other targets.
source_set("openscreen_platform_without_sockets") {
  # The private target below must directly depend on this target for reasons
  # described at its definition.
  visibility +=
      [ "//components/cast_streaming/test:test_sender_without_socket_deps" ]

  public = [
    "event_trace_logging_platform.h",
    "network_util.h",
    "task_runner.h",
  ]

  sources = [
    "event_trace_logging_platform.cc",
    "logging.cc",
    "network_util.cc",
    "task_runner.cc",
    "time.cc",
    "trace_logging_platform.cc",
  ]

  public_deps = [
    "//base",
    "//net",
    "//third_party/openscreen/src/platform:api",
  ]
}

if (!is_win && !is_ios) {
  source_set("message_port_tls_connection") {
    testonly = true

    public = []

    sources = [
      "message_port_tls_connection.cc",
      "message_port_tls_connection.h",
    ]

    deps = [
      "//base",
      "//components/cast/message_port",
      "//third_party/openscreen/src/platform:api",
    ]

    friend = [ ":unittests" ]
  }
}

source_set("unittests") {
  testonly = true
  visibility += [ "//components:components_unittests${exec_target_suffix}" ]
  if (is_android || is_ios) {
    # Allow broader visibility for platforms with unique generated targets.
    visibility += [ "//components:*" ]
  }

  public = []

  sources = [
    "tls_client_connection_unittest.cc",
    "tls_connection_factory_unittest.cc",
  ]

  deps = [
    ":openscreen_platform",
    "//base",
    "//base/test:test_support",
    "//net",
    "//services/network:test_support",
    "//services/network/public/mojom",
    "//testing/gmock",
    "//testing/gtest",
  ]

  if (!is_win && !is_ios) {
    sources += [ "message_port_tls_connection_unittest.cc" ]
    deps += [
      ":message_port_tls_connection",
      "//components/cast/message_port",
      "//third_party/openscreen/src/platform:api",
    ]
  }
}