summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-13 13:10:10 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-13 13:10:10 +0000
commitd647e280bba804d4589e952015122ff4bd8d3463 (patch)
treee4f6f9e60f452070ae546d0ee088636a2e3e4c37 /google_apis
parentdeaf719cac8855de0bafe3a1db2a9c3ca6791b3d (diff)
downloadchromium_src-d647e280bba804d4589e952015122ff4bd8d3463.zip
chromium_src-d647e280bba804d4589e952015122ff4bd8d3463.tar.gz
chromium_src-d647e280bba804d4589e952015122ff4bd8d3463.tar.bz2
include.gypi variables to specify API keys or use internal header for keys.
BUG=145584 Review URL: https://codereview.chromium.org/10918196 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156538 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/google_api_keys.cc22
-rw-r--r--google_apis/google_api_keys_unittest.cc56
-rw-r--r--google_apis/google_apis.gyp31
3 files changed, 100 insertions, 9 deletions
diff --git a/google_apis/google_api_keys.cc b/google_apis/google_api_keys.cc
index 6108186..98cb95f 100644
--- a/google_apis/google_api_keys.cc
+++ b/google_apis/google_api_keys.cc
@@ -11,43 +11,47 @@
#include "base/memory/scoped_ptr.h"
#include "base/stringize_macros.h"
-#if defined(GOOGLE_CHROME_BUILD)
+#if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS)
#include "google_apis/internal/google_chrome_api_keys.h"
#endif
+// Used to indicate an unset key/id/secret. This works better with
+// various unit tests than leaving the token empty.
+#define DUMMY_API_TOKEN "dummytoken"
+
#if !defined(GOOGLE_API_KEY)
-// TODO(joi): Make this blank once it is set via include.gypi.
-#define GOOGLE_API_KEY "abcNOTREALKEYxyz"
+#define GOOGLE_API_KEY DUMMY_API_TOKEN
#endif
#if !defined(GOOGLE_CLIENT_ID_MAIN)
-// TODO(joi): Make this blank once it is set via include.gypi.
+// TODO(joi): Use DUMMY_API_TOKEN here once folks on chromium-dev have
+// had a couple of days to update their include.gypi.
#define GOOGLE_CLIENT_ID_MAIN "77185425430.apps.googleusercontent.com"
#endif
#if !defined(GOOGLE_CLIENT_SECRET_MAIN)
-// TODO(joi): Make this blank once it is set via include.gypi.
+// TODO(joi): As above.
#define GOOGLE_CLIENT_SECRET_MAIN "OTJgUOQcT7lO7GsGZq2G4IlT"
#endif
#if !defined(GOOGLE_CLIENT_ID_CLOUD_PRINT)
-// TODO(joi): Make this blank once it is set via include.gypi.
+// TODO(joi): As above.
#define GOOGLE_CLIENT_ID_CLOUD_PRINT "551556820943.apps.googleusercontent.com"
#endif
#if !defined(GOOGLE_CLIENT_SECRET_CLOUD_PRINT)
-// TODO(joi): Make this blank once it is set via include.gypi.
+// TODO(joi): As above.
#define GOOGLE_CLIENT_SECRET_CLOUD_PRINT "u3/mp8CgLFxh4uiX1855/MHe"
#endif
#if !defined(GOOGLE_CLIENT_ID_REMOTING)
-// TODO(joi): Make this blank once it is set via include.gypi.
+// TODO(joi): As above.
#define GOOGLE_CLIENT_ID_REMOTING \
"440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com"
#endif
#if !defined(GOOGLE_CLIENT_SECRET_REMOTING)
-// TODO(joi): Make this blank once it is set via include.gypi.
+// TODO(joi): As above.
#define GOOGLE_CLIENT_SECRET_REMOTING "Bgur6DFiOMM1h8x-AQpuTQlK"
#endif
diff --git a/google_apis/google_api_keys_unittest.cc b/google_apis/google_api_keys_unittest.cc
new file mode 100644
index 0000000..0438ec2
--- /dev/null
+++ b/google_apis/google_api_keys_unittest.cc
@@ -0,0 +1,56 @@
+// Copyright (c) 2012 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.
+
+// Unit tests for implementation of google_api_keys namespace.
+//
+// Because the file deals with a lot of preprocessor defines and
+// optionally includes an internal header, the way we test is by
+// including the .cc file multiple times with different defines set.
+// This is a little unorthodox, but it lets us test the behavior as
+// close to unmodified as possible.
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+#if defined(GOOGLE_CHROME_BUILD) or defined(USE_OFFICIAL_GOOGLE_API_KEYS)
+// Test official build behavior, since we are in a checkout where this
+// is possible.
+namespace official_build {
+
+#undef GOOGLE_API_KEY
+#undef GOOGLE_CLIENT_ID_MAIN
+#undef GOOGLE_CLIENT_SECRET_MAIN
+#undef GOOGLE_CLIENT_ID_CLOUD_PRINT
+#undef GOOGLE_CLIENT_SECRET_CLOUD_PRINT
+#undef GOOGLE_CLIENT_ID_REMOTING
+#undef GOOGLE_CLIENT_SECRET_REMOTING
+
+// Try setting some keys, these should be ignored since it's a build
+// with official keys.
+#define GOOGLE_API_KEY "bogus api key"
+#define GOOGLE_CLIENT_ID_MAIN "bogus client_id_main"
+
+#include "google_apis/google_api_keys.cc"
+
+TEST(GoogleAPIKeys, OfficialKeys) {
+ std::string api_key = g_api_key_cache.Get().api_key();
+ std::string id_main = g_api_key_cache.Get().GetClientID(CLIENT_MAIN);
+ std::string secret_main = g_api_key_cache.Get().GetClientSecret(CLIENT_MAIN);
+ std::string id_cloud_print =
+ g_api_key_cache.Get().GetClientID(CLIENT_CLOUD_PRINT);
+ std::string secret_cloud_print =
+ g_api_key_cache.Get().GetClientSecret(CLIENT_CLOUD_PRINT);
+ std::string id_remoting = g_api_key_cache.Get().GetClientID(CLIENT_REMOTING);
+ std::string secret_remoting =
+ g_api_key_cache.Get().GetClientSecret(CLIENT_REMOTING);
+
+ ASSERT_TRUE(api_key.size() == 0);
+}
+
+} // namespace official_build
+#endif // defined(GOOGLE_CHROME_BUILD) or defined(USE_OFFICIAL_GOOGLE_API_KEYS)
+
+
+} // namespace
diff --git a/google_apis/google_apis.gyp b/google_apis/google_apis.gyp
index b0b81e4..aa09f4a 100644
--- a/google_apis/google_apis.gyp
+++ b/google_apis/google_apis.gyp
@@ -18,6 +18,37 @@
'../crypto/crypto.gyp:crypto',
'../net/net.gyp:net',
],
+ 'conditions': [
+ ['google_api_key!=""', {
+ 'defines': ['GOOGLE_API_KEY="<(google_api_key)"'],
+ }],
+ # Once the default definitions for the various keys in
+ # google_apis/google_api_keys.cc are all made empty, the next
+ # two conditionals can set just GOOGLE_DEFAULT_CLIENT_ID/SECRET.
+ # Until then, we have different semantics on the gyp variables
+ # google_default_client_id/secret and setting the environment
+ # variables of the (upper-case) same name (the latter are used
+ # as the default for unset client IDs/secrets, whereas the
+ # former overrides all client IDs/secrets).
+ # TODO(joi): Fix the above semantic mismatch once possible.
+ ['google_default_client_id!=""', {
+ 'defines': [
+ 'GOOGLE_CLIENT_ID_MAIN="<(google_default_client_id)"',
+ 'GOOGLE_CLIENT_ID_CLOUD_PRINT="<(google_default_client_id)"',
+ 'GOOGLE_CLIENT_ID_REMOTING="<(google_default_client_id)"',
+ ]
+ }],
+ ['google_default_client_secret!=""', {
+ 'defines': [
+ 'GOOGLE_CLIENT_SECRET_MAIN="<(google_default_client_secret)"',
+ 'GOOGLE_CLIENT_SECRET_CLOUD_PRINT="<(google_default_client_secret)"',
+ 'GOOGLE_CLIENT_SECRET_REMOTING="<(google_default_client_secret)"',
+ ]
+ }],
+ ['use_official_google_api_keys==1', {
+ 'defines': ['USE_OFFICIAL_GOOGLE_API_KEYS=1'],
+ }],
+ ],
'sources': [
'gaia/gaia_auth_consumer.cc',
'gaia/gaia_auth_consumer.h',