chromium/fuchsia_web/shell/BUILD.gn

# Copyright 2022 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

assert(is_fuchsia)

import("//build/config/cast.gni")
import("//build/config/fuchsia/generate_runner_scripts.gni")
import("//third_party/fuchsia-gn-sdk/src/component.gni")
import("//third_party/fuchsia-gn-sdk/src/package.gni")

# Nothing else should depend on these targets except the final component.
visibility = [ ":*" ]

group("shell") {
  testonly = true
  visibility += [
    "//chrome/test:*",
    "//content/test:*",
    "//fuchsia_web:gn_all",
  ]
  deps = [ ":web_engine_shell" ]

  if (enable_cast_receiver) {
    deps += [ ":cast_streaming_shell" ]
  }
}

source_set("remote_debugging_port") {
  sources = [
    "remote_debugging_port.cc",
    "remote_debugging_port.h",
  ]
  deps = [ "//base" ]
}

source_set("present_frame") {
  testonly = true
  sources = [
    "present_frame.cc",
    "present_frame.h",
  ]
  deps = [ "//base" ]
  public_deps = [
    "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.element",
    "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.web",
  ]
}

fuchsia_component("web_engine_shell_component") {
  testonly = true
  manifest = "web_engine_shell.cml"
  data_deps = [ ":web_engine_shell_exec" ]
}

# WebInstanceHost needs to serve capabilities to web_instance. Since the
# primary web_engine_shell component is a test component, it is not able to do
# this directly. Instead, it launches this here component to start instances via
# WebInstanceHost.
fuchsia_component("web_engine_shell_for_web_instance_host_component") {
  testonly = true
  manifest = "web_engine_shell_for_web_instance_host.cml"
  data_deps = [ ":web_engine_shell_exec" ]
}

fuchsia_package("web_engine_shell_pkg") {
  testonly = true

  # TODO(fxbug.dev/100944): Add appropriate visibility when fixed.
  package_name = "web_engine_shell"
  deps = [
    ":web_engine_shell_component",
    ":web_engine_shell_for_web_instance_host_component",
  ]
}

fuchsia_package_installer("web_engine_shell") {
  testonly = true
  package = ":web_engine_shell_pkg"
  package_name = "web_engine_shell"
  package_deps = [
    [
      "//fuchsia_web/webengine:web_engine",
      "web_engine",
    ],
    [
      "//fuchsia_web/webengine:web_engine_with_webui",
      "web_engine_with_webui",
    ],
  ]
}

executable("web_engine_shell_exec") {
  testonly = true
  sources = [ "web_engine_shell.cc" ]

  data = [ "data" ]

  deps = [
    ":present_frame",
    ":remote_debugging_port",
    ":shell_relauncher",
    "//base",
    "//components/fuchsia_component_support:annotations_manager",
    "//fuchsia_web/common",
    "//fuchsia_web/webinstance_host:webinstance_host",
    "//third_party/fuchsia-sdk/sdk/pkg/fdio",
    "//third_party/fuchsia-sdk/sdk/pkg/fidl_cpp",
    "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
    "//third_party/widevine/cdm:buildflags",
    "//url",
  ]
}

source_set("shell_relauncher") {
  testonly = true
  public = [ "shell_relauncher.h" ]
  sources = [ "shell_relauncher.cc" ]
  public_deps = [
    "//base",
    "//third_party/abseil-cpp:absl",
  ]
  deps = [
    "//fuchsia_web/common/test:test_support",
    "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.component:fuchsia.component_hlcpp",
    "//third_party/fuchsia-sdk/sdk/pkg/sys_component_cpp_testing",
  ]
}

if (enable_cast_receiver) {
  fuchsia_component("cast_streaming_shell_component") {
    testonly = true
    manifest = "cast_streaming_shell.cml"
    data_deps = [ ":cast_streaming_shell_exe" ]
  }

  # WebInstanceHost needs to serve capabilities to child components, which is
  # not possible when running inside a test component, such as
  # cast_streaming_shell. The shell therefore uses an intermediate component to
  # actually run the WebInstanceHost, from which the capabilities can be served.
  fuchsia_component("cast_streaming_shell_for_web_instance_host_component") {
    testonly = true
    manifest = "cast_streaming_shell_for_web_instance_host.cml"
    data_deps = [ ":cast_streaming_shell_exe" ]
  }

  fuchsia_package("cast_streaming_shell_pkg") {
    testonly = true
    package_name = "cast_streaming_shell"
    deps = [
      ":cast_streaming_shell_component",
      ":cast_streaming_shell_for_web_instance_host_component",
    ]
  }

  fuchsia_package_installer("cast_streaming_shell") {
    testonly = true
    package = ":cast_streaming_shell_pkg"
    package_name = "cast_streaming_shell"
    package_deps = [ [
          "//fuchsia_web/webengine:web_engine",
          "web_engine",
        ] ]
  }

  executable("cast_streaming_shell_exe") {
    testonly = true
    sources = [ "cast_streaming_shell.cc" ]

    data = [
      "cast_streaming_shell_data",
      rebase_path("//media/test/data/bear-1280x720.ivf"),
    ]

    deps = [
      ":present_frame",
      ":remote_debugging_port",
      ":shell_relauncher",
      "//base",
      "//base/test:test_support",
      "//components/cast/message_port:message_port",
      "//components/cast_streaming/test:test_sender_using_net_sockets",
      "//components/fuchsia_component_support:annotations_manager",
      "//fuchsia_web/cast_streaming",
      "//fuchsia_web/common",
      "//fuchsia_web/common/test:test_support",
      "//fuchsia_web/webengine:switches",
      "//fuchsia_web/webinstance_host:webinstance_host",
      "//media",
      "//media/gpu/test:test_helpers",
      "//third_party/fuchsia-sdk/sdk/pkg/fdio",
      "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
      "//url",
    ]
  }
}