# Copyright 2014 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("//build/config/features.gni")
import("//extensions/buildflags/buildflags.gni")
import("//testing/test.gni")

declare_args() {
  # You can set the variable 'use_official_google_api_keys' to true
  # to use the Google-internal file containing official API keys
  # for Google Chrome even in a developer build.  Setting this
  # variable explicitly to true will cause your build to fail if the
  # internal file is missing.
  #
  # The variable is documented here, but not handled in this file;
  # see //google_apis/determine_use_official_keys.gypi for the
  # implementation.
  #
  # Set the variable to false to not use the internal file, even when
  # it exists in your checkout.
  #
  # Leave it unset or set to "" to have the variable
  # implicitly set to true if you have
  # src/google_apis/internal/google_chrome_api_keys.h in your
  # checkout, and implicitly set to false if not.
  #
  # Note that official builds always behave as if the variable
  # was explicitly set to true, i.e. they always use official keys,
  # and will fail to build if the internal file is missing.
  use_official_google_api_keys = ""

  # Set these to bake the specified API keys and OAuth client
  # IDs/secrets into your build.
  #
  # If you create a build without values baked in, you can instead
  # set environment variables to provide the keys at runtime (see
  # src/google_apis/google_api_keys.h for details).  Features that
  # require server-side APIs may fail to work if no keys are
  # provided.
  #
  # Note that if you are building an official build or if
  # use_official_google_api_keys has been set to trie (explicitly or
  # implicitly), these values will be ignored and the official
  # keys will be used instead.
  google_api_key = ""

  # See google_api_key.
  google_default_client_id = ""

  # See google_api_key.
  google_default_client_secret = ""
}

if (use_official_google_api_keys == "") {
  # Default behavior, check if the key file exists.
  check_internal_result =
      exec_script("build/check_internal.py",
                  [ rebase_path("internal/google_chrome_api_keys.h",
                                root_build_dir) ],
                  "value")
  use_official_google_api_keys = check_internal_result == 1
}

config("key_defines") {
  defines = []
  if (use_official_google_api_keys) {
    defines += [ "USE_OFFICIAL_GOOGLE_API_KEYS=1" ]
  }
  if (google_api_key != "") {
    defines += [ "GOOGLE_API_KEY=\"$google_api_key\"" ]
  }
  if (google_default_client_id != "") {
    defines += [ "GOOGLE_DEFAULT_CLIENT_ID=\"$google_default_client_id\"" ]
  }
  if (google_default_client_secret != "") {
    defines +=
        [ "GOOGLE_DEFAULT_CLIENT_SECRET=\"$google_default_client_secret\"" ]
  }
}

# Variables:
#   deps: Extra dependencies
template("google_apis_tmpl") {
  source_set(target_name) {
    sources = [
      "gaia/gaia_auth_consumer.cc",
      "gaia/gaia_auth_consumer.h",
      "gaia/gaia_auth_fetcher.cc",
      "gaia/gaia_auth_fetcher.h",
      "gaia/gaia_auth_util.cc",
      "gaia/gaia_auth_util.h",
      "gaia/gaia_constants.cc",
      "gaia/gaia_constants.h",
      "gaia/gaia_oauth_client.cc",
      "gaia/gaia_oauth_client.h",
      "gaia/gaia_switches.cc",
      "gaia/gaia_switches.h",
      "gaia/gaia_urls.cc",
      "gaia/gaia_urls.h",
      "gaia/google_service_auth_error.cc",
      "gaia/google_service_auth_error.h",
      "gaia/oauth2_access_token_consumer.cc",
      "gaia/oauth2_access_token_consumer.h",
      "gaia/oauth2_access_token_fetcher.cc",
      "gaia/oauth2_access_token_fetcher.h",
      "gaia/oauth2_access_token_fetcher_immediate_error.cc",
      "gaia/oauth2_access_token_fetcher_immediate_error.h",
      "gaia/oauth2_access_token_fetcher_impl.cc",
      "gaia/oauth2_access_token_fetcher_impl.h",
      "gaia/oauth2_api_call_flow.cc",
      "gaia/oauth2_api_call_flow.h",
      "gaia/oauth2_id_token_decoder.cc",
      "gaia/oauth2_id_token_decoder.h",
      "gaia/oauth2_mint_token_flow.cc",
      "gaia/oauth2_mint_token_flow.h",
      "gaia/oauth2_token_service.cc",
      "gaia/oauth2_token_service.h",
      "gaia/oauth2_token_service_delegate.cc",
      "gaia/oauth2_token_service_delegate.h",
      "gaia/oauth2_token_service_request.cc",
      "gaia/oauth2_token_service_request.h",
      "gaia/oauth_multilogin_result.cc",
      "gaia/oauth_multilogin_result.h",
      "gaia/oauth_request_signer.cc",
      "gaia/oauth_request_signer.h",
      "google_api_keys.cc",
      "google_api_keys.h",
    ]

    configs += [
      ":key_defines",
      "//build/config/compiler:no_size_t_to_int_warning",
    ]

    deps = [
      "//base",
      "//base/third_party/dynamic_annotations",
      "//crypto",
      "//mojo/public/cpp/bindings:struct_traits",
      "//services/network/public/cpp",
    ]

    if (use_official_google_api_keys) {
      deps += [ "internal:generate_metrics_key_header" ]
    }

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

    if (is_mac || is_ios) {
      set_sources_assignment_filter([])
      sources += [
        "google_api_keys_mac.h",
        "google_api_keys_mac.mm",
      ]
      set_sources_assignment_filter(sources_assignment_filter)

      libs = [ "Foundation.framework" ]
    }
  }
}

google_apis_tmpl("google_apis") {
  deps = [
    "//net",
    "//services/network/public/cpp",
  ]
}

static_library("test_support") {
  testonly = true
  sources = [
    "gaia/fake_gaia.cc",
    "gaia/fake_gaia.h",
    "gaia/fake_oauth2_token_service.cc",
    "gaia/fake_oauth2_token_service.h",
    "gaia/fake_oauth2_token_service_delegate.cc",
    "gaia/fake_oauth2_token_service_delegate.h",
    "gaia/mock_url_fetcher_factory.h",
    "gaia/oauth2_token_service_test_util.cc",
    "gaia/oauth2_token_service_test_util.h",
  ]

  public_deps = [
    ":google_apis",
    "//base",
    "//base/test:test_support",
    "//net:test_support",
    "//services/network:network_service",
    "//services/network:test_support",
    "//services/network/public/cpp",
  ]
}

source_set("run_all_unittests") {
  testonly = true
  sources = [
    "run_all_unittests.cc",
  ]

  deps = [
    "//base/test:test_support",
    "//mojo/core/embedder",
  ]
}

test("google_apis_unittests") {
  sources = [
    "gaia/gaia_auth_fetcher_unittest.cc",
    "gaia/gaia_auth_util_unittest.cc",
    "gaia/gaia_oauth_client_unittest.cc",
    "gaia/google_service_auth_error_unittest.cc",
    "gaia/oauth2_access_token_fetcher_impl_unittest.cc",
    "gaia/oauth2_api_call_flow_unittest.cc",
    "gaia/oauth2_id_token_decoder_unittest.cc",
    "gaia/oauth2_mint_token_flow_unittest.cc",
    "gaia/oauth2_token_service_delegate_unittest.cc",
    "gaia/oauth2_token_service_request_unittest.cc",
    "gaia/oauth2_token_service_unittest.cc",
    "gaia/oauth_multilogin_result_unittest.cc",
    "gaia/oauth_request_signer_unittest.cc",
    "google_api_keys_unittest.cc",
    "google_api_keys_unittest.h",
  ]

  data = [
    "test/",
  ]

  configs += [ ":key_defines" ]

  deps = [
    ":google_apis",
    ":run_all_unittests",
    ":test_support",
    "//base",
    "//base/test:test_support",
    "//testing/gmock",
    "//testing/gtest",
  ]

  if (enable_extensions) {
    deps += [ "//google_apis/drive:drive_unittests" ]
  }

  if (is_mac || is_ios) {
    set_sources_assignment_filter([])
    sources += [ "google_api_keys_mac_unittest.mm" ]
    set_sources_assignment_filter(sources_assignment_filter)

    deps += [ "//third_party/ocmock" ]
  }
}
