chromium/net/android/BUILD.gn

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

import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("//third_party/jni_zero/jni_zero.gni")

android_library("net_java") {
  sources = [
    "java/src/org/chromium/net/AndroidCertVerifyResult.java",
    "java/src/org/chromium/net/AndroidKeyStore.java",
    "java/src/org/chromium/net/AndroidNetworkLibrary.java",
    "java/src/org/chromium/net/AndroidTrafficStats.java",
    "java/src/org/chromium/net/ChromiumNetworkAdapter.java",
    "java/src/org/chromium/net/DnsStatus.java",
    "java/src/org/chromium/net/GURLUtils.java",
    "java/src/org/chromium/net/HttpNegotiateAuthenticator.java",
    "java/src/org/chromium/net/HttpNegotiateConstants.java",
    "java/src/org/chromium/net/HttpUtil.java",
    "java/src/org/chromium/net/MimeTypeFilter.java",
    "java/src/org/chromium/net/NetStringUtil.java",
    "java/src/org/chromium/net/NetworkActiveNotifier.java",
    "java/src/org/chromium/net/NetworkChangeNotifier.java",
    "java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java",
    "java/src/org/chromium/net/NetworkTrafficAnnotationTag.java",
    "java/src/org/chromium/net/ProxyBroadcastReceiver.java",
    "java/src/org/chromium/net/ProxyChangeListener.java",
    "java/src/org/chromium/net/RegistrationPolicyAlwaysRegister.java",
    "java/src/org/chromium/net/RegistrationPolicyApplicationStatus.java",
    "java/src/org/chromium/net/X509Util.java",
  ]
  deps = [
    ":net_thread_stats_uid_java",
    "//base:base_java",
    "//build/android:build_java",
    "//third_party/android_deps:com_google_code_findbugs_jsr305_java",
    "//third_party/androidx:androidx_annotation_annotation_java",
    "//third_party/jni_zero:jni_zero_java",
  ]
  srcjar_deps = [
    ":net_android_java_enums_srcjar",
    ":net_errors_java",
    "//net:net_jni_headers",
  ]
  resources_package = "org.chromium.native_test"
}

android_library("net_thread_stats_uid_java") {
  sources = [ "java/src/org/chromium/net/ThreadStatsUid.java" ]
}

android_aidl("embedded_test_server_aidl") {
  interface_file = "../test/android/javatests/src/org/chromium/net/test/IEmbeddedTestServerInterface.aidl"
  sources = [
    "../test/android/javatests/src/org/chromium/net/test/IConnectionListener.aidl",
    "../test/android/javatests/src/org/chromium/net/test/IEmbeddedTestServerImpl.aidl",
  ]
}

android_library("embedded_test_server_aidl_java") {
  testonly = true
  deps = []
  srcjar_deps = [ ":embedded_test_server_aidl" ]
}

generate_jni("net_test_support_jni") {
  testonly = true
  sources = [ "../test/android/javatests/src/org/chromium/net/AndroidNetworkLibraryTestUtil.java" ]
}

android_library("net_java_test_support") {
  testonly = true
  sources = [
    "../test/android/javatests/src/org/chromium/net/AndroidNetworkLibraryTestUtil.java",
    "../test/android/javatests/src/org/chromium/net/test/EmbeddedTestServer.java",
    "../test/android/javatests/src/org/chromium/net/test/EmbeddedTestServerRule.java",
    "../test/android/javatests/src/org/chromium/net/test/util/CertTestUtil.java",
    "../test/android/javatests/src/org/chromium/net/test/util/NetworkChangeNotifierTestUtil.java",
    "../test/android/javatests/src/org/chromium/net/test/util/TestWebServer.java",
    "../test/android/javatests/src/org/chromium/net/test/util/WebServer.java",
  ]
  deps = [
    ":embedded_test_server_aidl_java",
    ":net_java",
    "//base:base_java",
    "//base:base_java_test_support",
    "//base:base_java_url_utils_for_test",
    "//third_party/androidx:androidx_annotation_annotation_java",
    "//third_party/androidx:androidx_test_monitor_java",
    "//third_party/androidx:androidx_test_uiautomator_uiautomator_java",
    "//third_party/jni_zero:jni_zero_java",
    "//third_party/junit",
  ]
  srcjar_deps = [
    ":net_java_test_support_enums_srcjar",
    ":net_test_support_jni",
  ]
  mergeable_android_manifests =
      [ "../test/android/javatests/AndroidManifest_client.xml" ]
}

generate_jni("net_test_support_provider_jni") {
  testonly = true
  sources = [ "../test/android/javatests/src/org/chromium/net/test/EmbeddedTestServerImpl.java" ]
}

generate_jni("dummy_spnego_authenticator_jni") {
  testonly = true
  sources = [ "../test/android/javatests/src/org/chromium/net/test/DummySpnegoAuthenticator.java" ]
}

android_library("net_test_support_provider_java") {
  testonly = true
  sources = [
    "../test/android/javatests/src/org/chromium/net/test/EmbeddedTestServerImpl.java",
    "../test/android/javatests/src/org/chromium/net/test/EmbeddedTestServerService.java",
  ]
  srcjar_deps = [ ":net_test_support_provider_jni" ]

  deps = [
    ":embedded_test_server_aidl_java",
    ":net_java",
    "//base:base_java",
    "//base:base_java_url_utils_for_test",
    "//third_party/jni_zero:jni_zero_java",
  ]

  data_deps = [ "//net:test_support" ]
}

android_library("dummy_spnego_authenticator_java") {
  testonly = true
  sources = [
    "../test/android/javatests/src/org/chromium/net/test/DummySpnegoAuthenticator.java",
    "../test/android/javatests/src/org/chromium/net/test/DummySpnegoAuthenticatorService.java",
  ]
  srcjar_deps = [ ":dummy_spnego_authenticator_jni" ]

  deps = [
    ":net_java",
    "//base:base_java",
    "//base:base_java_url_utils_for_test",
    "//third_party/jni_zero:jni_zero_java",
  ]

  data_deps = [ "//net:test_support" ]
}

source_set("java_test_native_support") {
  testonly = true
  sources = [
    "../test/android/net_test_entry_point.cc",
    "../test/android/net_test_jni_onload.cc",
    "../test/android/net_test_jni_onload.h",
    "../test/embedded_test_server/android/embedded_test_server_android.cc",
    "../test/embedded_test_server/android/embedded_test_server_android.h",
  ]

  deps = [ "//net:test_support" ]
  public_deps = [ ":net_test_support_provider_jni" ]
}

shared_library_with_jni("net_java_test_native_support") {
  testonly = true
  deps = [
    ":java_test_native_support",
    "//net:test_support",
  ]

  configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
  configs += [ "//build/config/android:hide_all_but_jni" ]
  java_targets = [ ":net_test_support_apk" ]
}

android_apk("net_test_support_apk") {
  testonly = true

  # Used as an additional_apk in test scripts.
  never_incremental = true

  # Required on Android Q+ to read from /sdcard when installing certs.
  target_sdk_version = 28

  deps = [
    ":net_java_test_support",
    ":net_test_support_provider_java",
  ]
  android_manifest = "../test/android/javatests/AndroidManifest.xml"
  apk_name = "ChromiumNetTestSupport"
  shared_libraries = [ ":net_java_test_native_support" ]
  srcjar_deps = [ ":net_java_test_native_support__jni_registration" ]
}

android_resources("net_unittests_apk_resources") {
  sources = [
    "unittest_support/res/mipmap-hdpi/app_icon.png",
    "unittest_support/res/mipmap-mdpi/app_icon.png",
    "unittest_support/res/mipmap-xhdpi/app_icon.png",
    "unittest_support/res/mipmap-xxhdpi/app_icon.png",
    "unittest_support/res/mipmap-xxxhdpi/app_icon.png",
    "unittest_support/res/xml/dummy_spnego_account_preferences.xml",
    "unittest_support/res/xml/dummy_spnego_authenticator.xml",
  ]
}

generate_jni("net_tests_jni") {
  testonly = true
  sources = [
    "javatests/src/org/chromium/net/AndroidKeyStoreTestUtil.java",
    "javatests/src/org/chromium/net/AndroidProxyConfigServiceTestUtil.java",
  ]
}

android_library("net_tests_java") {
  testonly = true
  sources = [
    "javatests/src/org/chromium/net/AndroidKeyStoreTestUtil.java",
    "javatests/src/org/chromium/net/AndroidNetworkLibraryTest.java",
    "javatests/src/org/chromium/net/AndroidProxyConfigServiceTestUtil.java",
    "javatests/src/org/chromium/net/AndroidProxySelectorTest.java",
    "javatests/src/org/chromium/net/HttpUtilTest.java",
    "javatests/src/org/chromium/net/MimeTypeFilterTest.java",
    "javatests/src/org/chromium/net/NetErrorsTest.java",
    "javatests/src/org/chromium/net/NetworkChangeNotifierNoNativeTest.java",
    "javatests/src/org/chromium/net/NetworkChangeNotifierTest.java",
    "javatests/src/org/chromium/net/ProxyChangeListenerTest.java",
    "javatests/src/org/chromium/net/X509UtilTest.java",
  ]
  srcjar_deps = [ ":net_tests_jni" ]
  deps = [
    ":net_java",
    ":net_java_test_support",
    "//base:base_java",
    "//base:base_java_test_support",
    "//third_party/android_sdk:android_test_mock_java",
    "//third_party/androidx:androidx_test_monitor_java",
    "//third_party/androidx:androidx_test_rules_java",
    "//third_party/androidx:androidx_test_runner_java",
    "//third_party/jni_zero:jni_zero_java",
    "//third_party/junit",
    "//third_party/mockito:mockito_java",
  ]
}

java_cpp_template("net_errors_java") {
  sources = [ "java/NetError.template" ]
  inputs = [ "../base/net_error_list.h" ]
}

java_cpp_enum("net_java_test_support_enums_srcjar") {
  sources = [
    "../test/embedded_test_server/embedded_test_server.h",
    "../test/url_request/url_request_failed_job.h",
  ]
}

java_cpp_enum("net_android_java_enums_srcjar") {
  sources = [
    "../base/network_change_notifier.h",
    "../socket/socket_tag.cc",
    "cert_verify_result_android.h",
    "keystore.h",
    "network_change_notifier_android.cc",
    "traffic_stats.cc",
  ]
}

robolectric_binary("net_junit_tests") {
  sources = [
    "junit/src/org/chromium/net/HttpNegotiateAuthenticatorTest.java",
    "junit/src/org/chromium/net/NetworkTrafficAnnotationTagTest.java",
  ]
  deps = [
    ":net_java",
    "//base:base_java",
    "//base:base_java_test_support",
    "//base:base_junit_test_support",
    "//third_party/hamcrest:hamcrest_java",
    "//third_party/jni_zero:jni_zero_java",
  ]
}