summaryrefslogtreecommitdiffstats
path: root/google_apis/google_api_keys_unittest.cc
blob: 0438ec21a75698dbb90addda3a3bf4d392ab469b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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