# Copyright 2023 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")
import("//third_party/protobuf/proto_library.gni")

assert(is_chromeos)

proto_library("proto") {
  proto_in_dir = "//"
  sources = [ "app_install.proto" ]

  deps = [ "//chrome/browser/apps/almanac_api_client/proto" ]
}

source_set("app_install") {
  sources = [
    "app_install_service.h",
    "app_install_types.cc",
    "app_install_types.h",
  ]

  deps = [
    "//components/services/app_service",
    "//services/network/public/cpp",
    "//ui/gfx:native_ui_types",
  ]
}

# This target is separated from the :app_install interface target to allow the
# implementation to depend on //chrome/browser/apps/app_service without circular
# deps.
source_set("implementation") {
  sources = [
    "app_install_almanac_endpoint.cc",
    "app_install_almanac_endpoint.h",
    "app_install_discovery_metrics.cc",
    "app_install_discovery_metrics.h",
    "app_install_service.cc",
    "app_install_service_ash.cc",
    "app_install_service_ash.h",
    "arc_app_installer.cc",
    "arc_app_installer.h",
    "web_app_installer.cc",
    "web_app_installer.h",
  ]

  deps = [
    ":app_install",
    ":proto",
    "//ash/constants",
    "//base",
    "//chrome/browser/apps/almanac_api_client",
    "//chrome/browser/apps/app_service",
    "//chrome/browser/ash/borealis",
    "//chrome/browser/profiles:profile",
    "//chrome/browser/ui/webui/ash/app_install:mojo_bindings",
    "//chrome/browser/web_applications",
    "//chromeos/ash/components/browser_context_helper",
    "//chromeos/ash/experiences/arc:arc_app_constants",
    "//chromeos/ash/experiences/arc/mojom",
    "//chromeos/ash/experiences/arc/session",
    "//chromeos/ash/experiences/arc/session:connection_holder",
    "//chromeos/components/mgs",
    "//chromeos/constants",
    "//components/metrics/structured:structured_events",
    "//components/services/app_service",
    "//components/webapps/browser",
    "//components/webapps/common",
    "//services/network/public/cpp",
    "//ui/native_window_tracker",
  ]

  # Outside of //chrome/browser only tests should be depending on this target.
  visibility = [
    ":*",
    "//chrome/browser",
    "//chrome/browser/ash/system_web_apps/apps/help_app:browser_tests",
  ]
}

source_set("navigation_throttle") {
  sources = [
    "app_install_navigation_throttle.cc",
    "app_install_navigation_throttle.h",
  ]

  deps = [
    ":app_install",
    "//base",
    "//chrome/browser/apps/app_service",
    "//chrome/browser/apps/link_capturing",
    "//chrome/browser/profiles:profile",
    "//chromeos/constants",
    "//components/services/app_service",
    "//content/public/browser",
    "//services/network/public/cpp",
  ]
}

source_set("unit_tests") {
  testonly = true

  sources = [
    "app_install_almanac_endpoint_unittest.cc",
    "app_install_navigation_throttle_unittest.cc",
    "app_install_service_ash_unittest.cc",
    "app_install_types_unittest.cc",
    "arc_app_installer_unittest.cc",
  ]

  deps = [
    ":app_install",
    ":implementation",
    ":navigation_throttle",
    ":proto",
    ":test_support",
    "//base",
    "//chrome/browser/apps/almanac_api_client",
    "//chrome/browser/apps/almanac_api_client/proto",
    "//chrome/browser/apps/app_service",
    "//chrome/browser/ash/app_list/arc",
    "//chrome/browser/ash/app_list/arc:test_support",
    "//chrome/browser/web_applications",
    "//chrome/browser/web_applications:web_applications_test_support",
    "//chrome/test:test_support",
    "//chromeos/ash/components/login/session",
    "//chromeos/ash/components/system",
    "//chromeos/ash/experiences/arc:arc_app_constants",
    "//chromeos/ash/experiences/arc:arc_test_support",
    "//components/services/app_service",
    "//content/test:test_support",
    "//services/network:test_support",
    "//testing/gtest",
  ]

  # TODO(crbug.com/40031409): Fix code that adds exit-time destructors and
  # enable the diagnostic by removing this line.
  configs += [ "//build/config/compiler:no_exit_time_destructors" ]
}

source_set("browser_tests") {
  testonly = true
  sources = [
    "app_install_navigation_throttle_browsertest.cc",
    "app_install_service_ash_browsertest.cc",
    "web_app_installer_browsertest.cc",
  ]

  defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]

  deps = [
    ":app_install",
    ":implementation",
    ":navigation_throttle",
    ":proto",
    ":test_support",
    "//base",
    "//chrome/browser/apps/almanac_api_client/proto",
    "//chrome/browser/apps/app_service",
    "//chrome/browser/apps/app_service:app_registry_cache_waiter",
    "//chrome/browser/apps/link_capturing:test_support",
    "//chrome/browser/ui/navigator",
    "//chrome/browser/ui/web_applications",
    "//chrome/browser/ui/webui/ash/app_install",
    "//chrome/browser/ui/webui/ash/app_install:test_support",
    "//chrome/browser/web_applications",
    "//chrome/browser/web_applications:web_applications_test_support",
    "//chrome/test:test_support",
    "//components/services/app_service",
    "//components/webapps/common",
    "//content/test:test_support",
    "//services/network:test_support",
    "//testing/gtest",
  ]
}

test("app_install_fuzztests") {
  sources = [ "app_install_navigation_throttle_fuzztests.cc" ]

  fuzztests = [
    "AppInstallNavigationThrottleFuzzTest.ExtractQueryParamsCanParseAnyString",
  ]

  deps = [
    ":navigation_throttle",
    "//chrome/test:test_support",
    "//third_party/fuzztest:fuzztest_gtest_main",
  ]
}

source_set("test_support") {
  testonly = true

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

  deps = [
    ":proto",
    "//base",
    "//chrome/browser/apps/almanac_api_client",
    "//chrome/browser/web_applications",
    "//components/services/app_service",
    "//components/webapps/common",
    "//net:test_support",
  ]
}
