summaryrefslogtreecommitdiffstats
path: root/google_apis/google_api_keys_unittest.cc
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/google_api_keys_unittest.cc
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/google_api_keys_unittest.cc')
-rw-r--r--google_apis/google_api_keys_unittest.cc56
1 files changed, 56 insertions, 0 deletions
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