# Copyright 2015 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("//components/nacl/features.gni")
import("//media/media_options.gni")
import("//remoting/build/config/remoting_build.gni")

group("remoting_all") {
  testonly = true

  deps = [
    ":remoting_unittests",
    "//remoting/test:chromoting_test_driver",
    "//remoting/webapp:browser_test_resources",
    "//remoting/webapp:unit_tests",
  ]

  if ((is_linux && !is_chromeos) || is_win || is_mac) {
    deps += [ "//remoting/webapp" ]
  }

  if (is_win) {
    deps += [
      "//remoting:remoting_breakpad_tester",
      "//remoting/host/win:all",
    ]

    if (is_chrome_branded) {
      deps += [ "//remoting/host:remoting_host_installation" ]
    }
  }

  if (is_android) {
    deps += [
      "//remoting/android:remoting_apk",
      "//remoting/android:remoting_test_apk",
    ]
  }

  if (is_ios) {
    deps += [
      "//remoting/ios:all",
      "//remoting/ios:ios_remoting_unittests",
    ]
  }

  if (enable_remoting_host) {
    deps += [
      "//remoting:remoting_perftests",
      "//remoting/host",
    ]

    if (!is_chromeos && !is_android) {
      deps += [
        "//remoting/host:remoting_native_messaging_manifests",
        "//remoting/host:remoting_start_host",
        "//remoting/host/it2me:remote_assistance_host",
      ]

      if (is_win) {
        deps += [ "//remoting/host/it2me:remote_assistance_host_uiaccess" ]
      }
    }

    if (is_win || (!is_chromeos && !is_android && !is_ios)) {
      deps += [ "//remoting/host:remoting_native_messaging_host" ]
    }

    if (is_linux && !is_chromeos) {
      deps += [
        "//remoting/host/linux:remoting_dev_me2me_host",
        "//remoting/host/linux:remoting_user_session",
      ]
    }
  }

  if (enable_me2me_host) {
    deps += [ "//remoting/host:remoting_me2me_host" ]
    if (is_chrome_branded) {
      deps += [ "//remoting/host:remoting_me2me_host_archive" ]
    }
  }

  if (enable_nacl) {
    deps += [ "//remoting/tools/javascript_key_tester" ]
  }
}

if (is_win) {
  executable("remoting_breakpad_tester") {
    deps = [
      "//base",
      "//build/win:default_exe_manifest",
      "//remoting/host",
    ]

    libs = []

    configs += [ "//build/config/compiler:wexit_time_destructors" ]

    sources = [
      "tools/breakpad_tester_win.cc",
    ]

    if (is_win) {
      libs += [
        "rpcrt4.lib",
        "wtsapi32.lib",
      ]
    }
  }
}

group("test_support") {
  testonly = true

  deps = [
    "//base",
    "//net",
    "//remoting/base:test_support",
    "//remoting/client",
    "//remoting/codec:decoder",
    "//remoting/codec:encoder",
    "//remoting/protocol:test_support",
    "//remoting/resources",
    "//remoting/signaling:test_support",
    "//remoting/test:test_support",
    "//testing/gmock",
    "//testing/gtest",
  ]

  if (!is_ios) {
    deps += [ "//components/policy/core/browser:test_support" ]
  }

  if (enable_remoting_host) {
    deps += [ "//remoting/host:test_support" ]
  }
}

test("remoting_unittests") {
  defines = []
  libs = []

  configs += [
    "//remoting/build/config:version",

    # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
    "//build/config/compiler:no_size_t_to_int_warning",
  ]

  deps = [
    ":test_support",
    "//base",
    "//base/test:test_support",
    "//google_apis",
    "//remoting/base:unit_tests",
    "//remoting/client:unit_tests",
    "//remoting/client/audio:unit_tests",
    "//remoting/client/display:unit_tests",
    "//remoting/client/input:unit_tests",
    "//remoting/client/ui:unit_tests",
    "//remoting/protocol:unit_tests",
    "//remoting/signaling:unit_tests",
    "//remoting/test:unit_tests",
    "//testing/gmock",
    "//testing/gtest",
  ]

  if (enable_remoting_host) {
    deps += [
      "//remoting/codec:unit_tests",
      "//remoting/host:unit_tests",
      "//ui/gfx",
    ]
  }

  if (enable_webrtc) {
    deps += [ "//third_party/webrtc_overrides:init_webrtc" ]
  }

  if (is_android) {
    deps += [ "//net/android:net_java" ]

    libs += [ "android" ]
  }

  if (is_win) {
    defines += [ "_ALT_NO_EXCEPTIONS" ]

    libs += [
      "comctl32.lib",
      "rpcrt4.lib",
      "wtsapi32.lib",
    ]
  }
}

if (enable_remoting_host) {
  test("remoting_perftests") {
    defines = []
    libs = []

    sources = [
      "test/codec_perftest.cc",
      "test/protocol_perftest.cc",
    ]

    configs += [ "//remoting/build/config:version" ]

    deps = [
      ":test_support",
      "//base",
      "//base/test:run_all_unittests",
      "//base/test:test_support",
      "//net:test_support",
      "//remoting/base",
      "//testing/gtest",
    ]

    if (enable_webrtc) {
      deps += [
        "//third_party/webrtc/modules/desktop_capture",
        "//third_party/webrtc_overrides",
        "//third_party/webrtc_overrides:init_webrtc"
      ]
    }

    if (is_win) {
      defines += [ "_ALT_NO_EXCEPTIONS" ]

      libs += [
        "rpcrt4.lib",
        "wtsapi32.lib",
      ]
    }
  }
}
