# 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 (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" ]
  }
}
