chromium/ios/chrome/test/earl_grey2/chrome_ios_eg2_test.gni

# Copyright 2018 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/apple/compile_entitlements.gni")
import("//build/apple/tweak_info_plist.gni")
import("//build/config/ios/ios_sdk.gni")
import("//build/config/ios/rules.gni")
import("//build/ios/extension_bundle_data.gni")
import("//ios/build/chrome_build.gni")
import("//ios/chrome/app/chrome_app.gni")
import("//ios/public/provider/chrome/browser/build_config.gni")
import("//ios/third_party/earl_grey2/ios_eg2_test.gni")

template("chrome_ios_eg2_test_app_host") {
  if (!defined(entitlements_path) && !defined(entitlements_target)) {
    _target_name = target_name
    _tweak_entitlements = target_name + "_tweak_entitlements"
    compile_entitlements(_tweak_entitlements) {
      substitutions = [ "IOS_BUNDLE_ID_PREFIX=$ios_app_bundle_id_prefix" ]
      output_name = "$target_gen_dir/$_target_name.entitlements"
      entitlements_templates =
          [ "//ios/chrome/test/earl_grey/resources/Chrome.entitlements" ]
      if (ios_egtests_entitlements_additions != []) {
        entitlements_templates += ios_egtests_entitlements_additions
      }
    }
  }

  if (!defined(info_plist) && !defined(info_plist_target)) {
    _tweak_info_plist = target_name + "_tweak_info_plist"
    tweak_info_plist(_tweak_info_plist) {
      info_plists = [
        "//ios/chrome/app/resources/Info.plist",
        "//ios/chrome/app/resources/EarlGreyAddition+Info.plist",
      ]
      if (ios_chrome_info_plist_additions != []) {
        info_plists += ios_chrome_info_plist_additions
      }
      if (ios_chrome_info_plist_addition_targets != []) {
        if (!defined(deps)) {
          deps = []
        }
        deps += ios_chrome_info_plist_addition_targets
      }
      if (defined(invoker.extra_info_plists)) {
        info_plists += invoker.extra_info_plists
      }
      args = [
        "--branding=$chromium_short_name",
        "--version-overrides=MINOR=9999",
      ]
    }
  }

  _deps_group_name = target_name + "_deps_group"
  group(_deps_group_name) {
    testonly = true

    public_deps = []
    if (defined(invoker.deps)) {
      public_deps += invoker.deps
    }

    if (defined(invoker.public_deps)) {
      public_deps += invoker.public_deps
    }
  }

  if (defined(invoker.eg_extension_target)) {
    assert(defined(invoker.eg_extension_name),
           "eg_extension_name must be defined too")
    _eg_extension_bundle_data_target = target_name + "_appex_bundle_data"
    extension_bundle_data(_eg_extension_bundle_data_target) {
      extension_name = invoker.eg_extension_name
      extension_target = invoker.eg_extension_target
    }
  }

  ios_eg2_test_app_host(target_name) {
    forward_variables_from(invoker,
                           [
                             "bundle_deps",
                             "entitlements_path",
                             "entitlements_target",
                             "eg_main_application_delegate",
                             "info_plist",
                             "info_plist_target",
                             "output_name",
                           ])

    testonly = true
    target_type = "chrome_app"

    bundle_identifier = shared_bundle_id_for_test_apps

    if (defined(_tweak_entitlements)) {
      entitlements_target = ":$_tweak_entitlements"
    }

    if (defined(_tweak_info_plist)) {
      info_plist_target = ":$_tweak_info_plist"
    }

    _eg_main_application_delegate = "MainApplicationDelegate"
    if (defined(eg_main_application_delegate)) {
      _eg_main_application_delegate = eg_main_application_delegate
    }

    deps = [
      ":$_deps_group_name",
      "//ios/chrome/app:main",
      "//ios/chrome/test/earl_grey:eg_app_support+eg2",
      "//ios/chrome/test/earl_grey:hooks",
      "//ios/testing:http_server_bundle_data",
      "//ios/third_party/earl_grey2:app_framework+link",

      # Use the same provider API as Chromium.app.
      ios_provider_target,
    ]

    if (defined(invoker.eg_extension_target)) {
      deps += [ ":$_eg_extension_bundle_data_target" ]
    }

    if (!defined(bundle_deps)) {
      bundle_deps = []
    }
    bundle_deps += [
      "//ios/chrome/app/resources",
      "//ios/third_party/earl_grey2:app_framework+bundle",
      "//ios/third_party/gtx:gtx+bundle",
      ios_application_icons_target,
    ]

    extra_substitutions = [
      "CHROMIUM_BUNDLE_ID=$bundle_identifier",
      "CHROMIUM_HANDOFF_ID=$chromium_handoff_id",
      "CHROMIUM_SHORT_NAME=$target_name",
      "CHROMIUM_URL_CHANNEL_SCHEME=${url_channel_scheme}-eg",
      "CHROMIUM_URL_SCHEME_1=$url_unsecure_scheme",
      "CHROMIUM_URL_SCHEME_2=$url_secure_scheme",
      "CHROMIUM_URL_SCHEME_3=$url_x_callback_scheme",
      "CONTENT_WIDGET_EXTENSION_BUNDLE_ID=$bundle_identifier.ContentTodayExtension",
      "EG_MAIN_APPLICATION_DELEGATE=$_eg_main_application_delegate",
      "IOS_MOVE_TAB_ACTIVITY_TYPE=$ios_move_tab_activity_type",
      "SSOAUTH_URL_SCHEME=$url_ssoauth_scheme",
    ]
  }
}

set_defaults("chrome_ios_eg_v2_test_app_host") {
  configs = default_executable_configs
}

template("chrome_ios_eg2_test") {
  _deps_group_name = target_name + "_deps_group"
  group(_deps_group_name) {
    testonly = true

    public_deps = []
    if (defined(invoker.deps)) {
      public_deps += invoker.deps
    }

    if (defined(invoker.public_deps)) {
      public_deps += invoker.public_deps
    }
  }

  assert(defined(invoker.xcode_test_application_name),
         "xcode_test_application_name must be defined for $target_name")
  assert(
      defined(invoker.deps),
      "deps must be defined for $target_name to include at least one earl grey test file.")

  ios_eg2_test(target_name) {
    forward_variables_from(invoker,
                           [
                             "clones",
                             "bundle_deps",
                             "data",
                             "deps",
                             "data_deps",
                             "executable_args",
                             "retries",
                             "xcode_test_application_name",
                           ])

    xctest_bundle_principal_class = "ChromeEGTestBundleMain"

    if (!defined(deps)) {
      deps = []
    }
    deps += [ "//ios/chrome/test/earl_grey:eg_test_support+eg2" ]

    if (!defined(bundle_deps)) {
      bundle_deps = []
    }
    bundle_deps += [
      "//ios/chrome/app/resources",
      "//ios/third_party/gtx:gtx+bundle",
      "//third_party/icu:icudata",
    ]
  }
}

set_defaults("chrome_ios_eg2_test") {
  configs = default_shared_library_configs
}