Home | History | Annotate | Download | only in google_apis
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Unit tests for implementation of google_api_keys namespace.
      6 //
      7 // Because the file deals with a lot of preprocessor defines and
      8 // optionally includes an internal header, the way we test is by
      9 // including the .cc file multiple times with different defines set.
     10 // This is a little unorthodox, but it lets us test the behavior as
     11 // close to unmodified as possible.
     12 
     13 #include "google_apis/google_api_keys.h"
     14 
     15 #include "build/build_config.h"
     16 #include "testing/gtest/include/gtest/gtest.h"
     17 
     18 // The Win builders fail (with a linker crash) when trying to link
     19 // unit_tests, and the Android builders complain about multiply
     20 // defined symbols (likely they don't do name decoration as well as
     21 // the Mac and Linux linkers).  Therefore these tests are only built
     22 // and run on Mac and Linux, which should provide plenty of coverage
     23 // since there are no platform-specific bits in this code.
     24 #if defined(OS_LINUX) || defined(OS_MACOSX)
     25 
     26 // We need to include everything included by google_api_keys.cc once
     27 // at global scope so that things like STL and classes from base don't
     28 // get defined when we re-include the google_api_keys.cc file
     29 // below. We used to include that file in its entirety here, but that
     30 // can cause problems if the linker decides the version of symbols
     31 // from that file included here is the "right" version.
     32 #include <string>
     33 #include "base/command_line.h"
     34 #include "base/environment.h"
     35 #include "base/lazy_instance.h"
     36 #include "base/logging.h"
     37 #include "base/memory/scoped_ptr.h"
     38 #include "base/strings/stringize_macros.h"
     39 
     40 // This is the default baked-in value for OAuth IDs and secrets.
     41 static const char kDummyToken[] = "dummytoken";
     42 
     43 struct EnvironmentCache {
     44  public:
     45   EnvironmentCache() : variable_name(NULL), was_set(false) {}
     46 
     47   const char* variable_name;
     48   bool was_set;
     49   std::string value;
     50 };
     51 
     52 class GoogleAPIKeysTest : public testing::Test {
     53  public:
     54   GoogleAPIKeysTest() : env_(base::Environment::Create()) {
     55     env_cache_[0].variable_name = "GOOGLE_API_KEY";
     56     env_cache_[1].variable_name = "GOOGLE_CLIENT_ID_MAIN";
     57     env_cache_[2].variable_name = "GOOGLE_CLIENT_SECRET_MAIN";
     58     env_cache_[3].variable_name = "GOOGLE_CLIENT_ID_CLOUD_PRINT";
     59     env_cache_[4].variable_name = "GOOGLE_CLIENT_SECRET_CLOUD_PRINT";
     60     env_cache_[5].variable_name = "GOOGLE_CLIENT_ID_REMOTING";
     61     env_cache_[6].variable_name = "GOOGLE_CLIENT_SECRET_REMOTING";
     62     env_cache_[7].variable_name = "GOOGLE_CLIENT_ID_REMOTING_HOST";
     63     env_cache_[8].variable_name = "GOOGLE_CLIENT_SECRET_REMOTING_HOST";
     64     env_cache_[9].variable_name = "GOOGLE_DEFAULT_CLIENT_ID";
     65     env_cache_[10].variable_name = "GOOGLE_DEFAULT_CLIENT_SECRET";
     66   }
     67 
     68   virtual void SetUp() {
     69     // Unset all environment variables that can affect these tests,
     70     // for the duration of the tests.
     71     for (size_t i = 0; i < arraysize(env_cache_); ++i) {
     72       EnvironmentCache& cache = env_cache_[i];
     73       cache.was_set = env_->HasVar(cache.variable_name);
     74       cache.value.clear();
     75       if (cache.was_set) {
     76         env_->GetVar(cache.variable_name, &cache.value);
     77         env_->UnSetVar(cache.variable_name);
     78       }
     79     }
     80   }
     81 
     82   virtual void TearDown() {
     83     // Restore environment.
     84     for (size_t i = 0; i < arraysize(env_cache_); ++i) {
     85       EnvironmentCache& cache = env_cache_[i];
     86       if (cache.was_set) {
     87         env_->SetVar(cache.variable_name, cache.value);
     88       }
     89     }
     90   }
     91 
     92  private:
     93   scoped_ptr<base::Environment> env_;
     94 
     95   // Why 3?  It is for GOOGLE_API_KEY, GOOGLE_DEFAULT_CLIENT_ID and
     96   // GOOGLE_DEFAULT_CLIENT_SECRET.
     97   //
     98   // Why 2 times CLIENT_NUM_ITEMS?  This is the number of different
     99   // clients in the OAuth2Client enumeration, and for each of these we
    100   // have both an ID and a secret.
    101   EnvironmentCache env_cache_[3 + 2 * google_apis::CLIENT_NUM_ITEMS];
    102 };
    103 
    104 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS)
    105 // Test official build behavior, since we are in a checkout where this
    106 // is possible.
    107 namespace official_build {
    108 
    109 // We start every test by creating a clean environment for the
    110 // preprocessor defines used in google_api_keys.cc
    111 #undef DUMMY_API_TOKEN
    112 #undef GOOGLE_API_KEY
    113 #undef GOOGLE_CLIENT_ID_MAIN
    114 #undef GOOGLE_CLIENT_SECRET_MAIN
    115 #undef GOOGLE_CLIENT_ID_CLOUD_PRINT
    116 #undef GOOGLE_CLIENT_SECRET_CLOUD_PRINT
    117 #undef GOOGLE_CLIENT_ID_REMOTING
    118 #undef GOOGLE_CLIENT_SECRET_REMOTING
    119 #undef GOOGLE_CLIENT_ID_REMOTING_HOST
    120 #undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
    121 #undef GOOGLE_DEFAULT_CLIENT_ID
    122 #undef GOOGLE_DEFAULT_CLIENT_SECRET
    123 
    124 // Try setting some keys, these should be ignored since it's a build
    125 // with official keys.
    126 #define GOOGLE_API_KEY "bogus api_key"
    127 #define GOOGLE_CLIENT_ID_MAIN "bogus client_id_main"
    128 
    129 // Undef include guard so things get defined again, within this namespace.
    130 #undef GOOGLE_APIS_GOOGLE_API_KEYS_H_
    131 #undef GOOGLE_APIS_INTERNAL_GOOGLE_CHROME_API_KEYS_
    132 #include "google_apis/google_api_keys.cc"
    133 
    134 }  // namespace official_build
    135 
    136 TEST_F(GoogleAPIKeysTest, OfficialKeys) {
    137   namespace testcase = official_build::google_apis;
    138 
    139   EXPECT_TRUE(testcase::HasKeysConfigured());
    140 
    141   std::string api_key = testcase::g_api_key_cache.Get().api_key();
    142   std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
    143       testcase::CLIENT_MAIN);
    144   std::string secret_main = testcase::g_api_key_cache.Get().GetClientSecret(
    145       testcase::CLIENT_MAIN);
    146   std::string id_cloud_print =
    147       testcase::g_api_key_cache.Get().GetClientID(
    148           testcase::CLIENT_CLOUD_PRINT);
    149   std::string secret_cloud_print =
    150       testcase::g_api_key_cache.Get().GetClientSecret(
    151           testcase::CLIENT_CLOUD_PRINT);
    152   std::string id_remoting = testcase::g_api_key_cache.Get().GetClientID(
    153       testcase::CLIENT_REMOTING);
    154   std::string secret_remoting =
    155       testcase::g_api_key_cache.Get().GetClientSecret(
    156           testcase::CLIENT_REMOTING);
    157   std::string id_remoting_host = testcase::g_api_key_cache.Get().GetClientID(
    158       testcase::CLIENT_REMOTING_HOST);
    159   std::string secret_remoting_host =
    160       testcase::g_api_key_cache.Get().GetClientSecret(
    161           testcase::CLIENT_REMOTING_HOST);
    162 
    163   EXPECT_NE(0u, api_key.size());
    164   EXPECT_NE(DUMMY_API_TOKEN, api_key);
    165   EXPECT_NE("bogus api_key", api_key);
    166   EXPECT_NE(kDummyToken, api_key);
    167 
    168   EXPECT_NE(0u, id_main.size());
    169   EXPECT_NE(DUMMY_API_TOKEN, id_main);
    170   EXPECT_NE("bogus client_id_main", id_main);
    171   EXPECT_NE(kDummyToken, id_main);
    172 
    173   EXPECT_NE(0u, secret_main.size());
    174   EXPECT_NE(DUMMY_API_TOKEN, secret_main);
    175   EXPECT_NE(kDummyToken, secret_main);
    176 
    177   EXPECT_NE(0u, id_cloud_print.size());
    178   EXPECT_NE(DUMMY_API_TOKEN, id_cloud_print);
    179   EXPECT_NE(kDummyToken, id_cloud_print);
    180 
    181   EXPECT_NE(0u, secret_cloud_print.size());
    182   EXPECT_NE(DUMMY_API_TOKEN, secret_cloud_print);
    183   EXPECT_NE(kDummyToken, secret_cloud_print);
    184 
    185   EXPECT_NE(0u, id_remoting.size());
    186   EXPECT_NE(DUMMY_API_TOKEN, id_remoting);
    187   EXPECT_NE(kDummyToken, id_remoting);
    188 
    189   EXPECT_NE(0u, secret_remoting.size());
    190   EXPECT_NE(DUMMY_API_TOKEN, secret_remoting);
    191   EXPECT_NE(kDummyToken, secret_remoting);
    192 
    193   EXPECT_NE(0u, id_remoting_host.size());
    194   EXPECT_NE(DUMMY_API_TOKEN, id_remoting_host);
    195   EXPECT_NE(kDummyToken, id_remoting_host);
    196 
    197   EXPECT_NE(0u, secret_remoting_host.size());
    198   EXPECT_NE(DUMMY_API_TOKEN, secret_remoting_host);
    199   EXPECT_NE(kDummyToken, secret_remoting_host);
    200 }
    201 #endif  // defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS)
    202 
    203 // After this test, for the remainder of this compilation unit, we
    204 // need official keys to not be used.
    205 #undef GOOGLE_CHROME_BUILD
    206 #undef USE_OFFICIAL_GOOGLE_API_KEYS
    207 
    208 // Test the set of keys temporarily baked into Chromium by default.
    209 namespace default_keys {
    210 
    211 // We start every test by creating a clean environment for the
    212 // preprocessor defines used in google_api_keys.cc
    213 #undef DUMMY_API_TOKEN
    214 #undef GOOGLE_API_KEY
    215 #undef GOOGLE_CLIENT_ID_MAIN
    216 #undef GOOGLE_CLIENT_SECRET_MAIN
    217 #undef GOOGLE_CLIENT_ID_CLOUD_PRINT
    218 #undef GOOGLE_CLIENT_SECRET_CLOUD_PRINT
    219 #undef GOOGLE_CLIENT_ID_REMOTING
    220 #undef GOOGLE_CLIENT_SECRET_REMOTING
    221 #undef GOOGLE_CLIENT_ID_REMOTING_HOST
    222 #undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
    223 #undef GOOGLE_DEFAULT_CLIENT_ID
    224 #undef GOOGLE_DEFAULT_CLIENT_SECRET
    225 
    226 // Undef include guard so things get defined again, within this namespace.
    227 #undef GOOGLE_APIS_GOOGLE_API_KEYS_H_
    228 #undef GOOGLE_APIS_INTERNAL_GOOGLE_CHROME_API_KEYS_
    229 #include "google_apis/google_api_keys.cc"
    230 
    231 }  // namespace default_keys
    232 
    233 TEST_F(GoogleAPIKeysTest, DefaultKeys) {
    234   namespace testcase = default_keys::google_apis;
    235 
    236   EXPECT_FALSE(testcase::HasKeysConfigured());
    237 
    238   std::string api_key = testcase::g_api_key_cache.Get().api_key();
    239   std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
    240       testcase::CLIENT_MAIN);
    241   std::string secret_main = testcase::g_api_key_cache.Get().GetClientSecret(
    242       testcase::CLIENT_MAIN);
    243   std::string id_cloud_print =
    244       testcase::g_api_key_cache.Get().GetClientID(
    245           testcase::CLIENT_CLOUD_PRINT);
    246   std::string secret_cloud_print =
    247       testcase::g_api_key_cache.Get().GetClientSecret(
    248           testcase::CLIENT_CLOUD_PRINT);
    249   std::string id_remoting = testcase::g_api_key_cache.Get().GetClientID(
    250       testcase::CLIENT_REMOTING);
    251   std::string secret_remoting =
    252       testcase::g_api_key_cache.Get().GetClientSecret(
    253           testcase::CLIENT_REMOTING);
    254   std::string id_remoting_host = testcase::g_api_key_cache.Get().GetClientID(
    255       testcase::CLIENT_REMOTING_HOST);
    256   std::string secret_remoting_host =
    257       testcase::g_api_key_cache.Get().GetClientSecret(
    258           testcase::CLIENT_REMOTING_HOST);
    259 
    260   EXPECT_EQ(kDummyToken, api_key);
    261   EXPECT_EQ(kDummyToken, id_main);
    262   EXPECT_EQ(kDummyToken, secret_main);
    263   EXPECT_EQ(kDummyToken, id_cloud_print);
    264   EXPECT_EQ(kDummyToken, secret_cloud_print);
    265   EXPECT_EQ(kDummyToken, id_remoting);
    266   EXPECT_EQ(kDummyToken, secret_remoting);
    267   EXPECT_EQ(kDummyToken, id_remoting_host);
    268   EXPECT_EQ(kDummyToken, secret_remoting_host);
    269 }
    270 
    271 // Override a couple of keys, leave the rest default.
    272 namespace override_some_keys {
    273 
    274 // We start every test by creating a clean environment for the
    275 // preprocessor defines used in google_api_keys.cc
    276 #undef DUMMY_API_TOKEN
    277 #undef GOOGLE_API_KEY
    278 #undef GOOGLE_CLIENT_ID_MAIN
    279 #undef GOOGLE_CLIENT_SECRET_MAIN
    280 #undef GOOGLE_CLIENT_ID_CLOUD_PRINT
    281 #undef GOOGLE_CLIENT_SECRET_CLOUD_PRINT
    282 #undef GOOGLE_CLIENT_ID_REMOTING
    283 #undef GOOGLE_CLIENT_SECRET_REMOTING
    284 #undef GOOGLE_CLIENT_ID_REMOTING_HOST
    285 #undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
    286 #undef GOOGLE_DEFAULT_CLIENT_ID
    287 #undef GOOGLE_DEFAULT_CLIENT_SECRET
    288 
    289 #define GOOGLE_API_KEY "API_KEY override"
    290 #define GOOGLE_CLIENT_ID_REMOTING "CLIENT_ID_REMOTING override"
    291 
    292 // Undef include guard so things get defined again, within this namespace.
    293 #undef GOOGLE_APIS_GOOGLE_API_KEYS_H_
    294 #undef GOOGLE_APIS_INTERNAL_GOOGLE_CHROME_API_KEYS_
    295 #include "google_apis/google_api_keys.cc"
    296 
    297 }  // namespace override_some_keys
    298 
    299 TEST_F(GoogleAPIKeysTest, OverrideSomeKeys) {
    300   namespace testcase = override_some_keys::google_apis;
    301 
    302   EXPECT_FALSE(testcase::HasKeysConfigured());
    303 
    304   std::string api_key = testcase::g_api_key_cache.Get().api_key();
    305   std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
    306       testcase::CLIENT_MAIN);
    307   std::string secret_main = testcase::g_api_key_cache.Get().GetClientSecret(
    308       testcase::CLIENT_MAIN);
    309   std::string id_cloud_print =
    310       testcase::g_api_key_cache.Get().GetClientID(
    311           testcase::CLIENT_CLOUD_PRINT);
    312   std::string secret_cloud_print =
    313       testcase::g_api_key_cache.Get().GetClientSecret(
    314           testcase::CLIENT_CLOUD_PRINT);
    315   std::string id_remoting = testcase::g_api_key_cache.Get().GetClientID(
    316       testcase::CLIENT_REMOTING);
    317   std::string secret_remoting =
    318       testcase::g_api_key_cache.Get().GetClientSecret(
    319           testcase::CLIENT_REMOTING);
    320   std::string id_remoting_host = testcase::g_api_key_cache.Get().GetClientID(
    321       testcase::CLIENT_REMOTING_HOST);
    322   std::string secret_remoting_host =
    323       testcase::g_api_key_cache.Get().GetClientSecret(
    324           testcase::CLIENT_REMOTING_HOST);
    325 
    326   EXPECT_EQ("API_KEY override", api_key);
    327   EXPECT_EQ(kDummyToken, id_main);
    328   EXPECT_EQ(kDummyToken, secret_main);
    329   EXPECT_EQ(kDummyToken, id_cloud_print);
    330   EXPECT_EQ(kDummyToken, secret_cloud_print);
    331   EXPECT_EQ("CLIENT_ID_REMOTING override", id_remoting);
    332   EXPECT_EQ(kDummyToken, secret_remoting);
    333   EXPECT_EQ(kDummyToken, id_remoting_host);
    334   EXPECT_EQ(kDummyToken, secret_remoting_host);
    335 }
    336 
    337 // Override all keys.
    338 namespace override_all_keys {
    339 
    340 // We start every test by creating a clean environment for the
    341 // preprocessor defines used in google_api_keys.cc
    342 #undef DUMMY_API_TOKEN
    343 #undef GOOGLE_API_KEY
    344 #undef GOOGLE_CLIENT_ID_MAIN
    345 #undef GOOGLE_CLIENT_SECRET_MAIN
    346 #undef GOOGLE_CLIENT_ID_CLOUD_PRINT
    347 #undef GOOGLE_CLIENT_SECRET_CLOUD_PRINT
    348 #undef GOOGLE_CLIENT_ID_REMOTING
    349 #undef GOOGLE_CLIENT_SECRET_REMOTING
    350 #undef GOOGLE_CLIENT_ID_REMOTING_HOST
    351 #undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
    352 #undef GOOGLE_DEFAULT_CLIENT_ID
    353 #undef GOOGLE_DEFAULT_CLIENT_SECRET
    354 
    355 #define GOOGLE_API_KEY "API_KEY"
    356 #define GOOGLE_CLIENT_ID_MAIN "ID_MAIN"
    357 #define GOOGLE_CLIENT_SECRET_MAIN "SECRET_MAIN"
    358 #define GOOGLE_CLIENT_ID_CLOUD_PRINT "ID_CLOUD_PRINT"
    359 #define GOOGLE_CLIENT_SECRET_CLOUD_PRINT "SECRET_CLOUD_PRINT"
    360 #define GOOGLE_CLIENT_ID_REMOTING "ID_REMOTING"
    361 #define GOOGLE_CLIENT_SECRET_REMOTING "SECRET_REMOTING"
    362 #define GOOGLE_CLIENT_ID_REMOTING_HOST "ID_REMOTING_HOST"
    363 #define GOOGLE_CLIENT_SECRET_REMOTING_HOST "SECRET_REMOTING_HOST"
    364 
    365 // Undef include guard so things get defined again, within this namespace.
    366 #undef GOOGLE_APIS_GOOGLE_API_KEYS_H_
    367 #undef GOOGLE_APIS_INTERNAL_GOOGLE_CHROME_API_KEYS_
    368 #include "google_apis/google_api_keys.cc"
    369 
    370 }  // namespace override_all_keys
    371 
    372 TEST_F(GoogleAPIKeysTest, OverrideAllKeys) {
    373   namespace testcase = override_all_keys::google_apis;
    374 
    375   EXPECT_TRUE(testcase::HasKeysConfigured());
    376 
    377   std::string api_key = testcase::g_api_key_cache.Get().api_key();
    378   std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
    379       testcase::CLIENT_MAIN);
    380   std::string secret_main = testcase::g_api_key_cache.Get().GetClientSecret(
    381       testcase::CLIENT_MAIN);
    382   std::string id_cloud_print =
    383       testcase::g_api_key_cache.Get().GetClientID(
    384           testcase::CLIENT_CLOUD_PRINT);
    385   std::string secret_cloud_print =
    386       testcase::g_api_key_cache.Get().GetClientSecret(
    387           testcase::CLIENT_CLOUD_PRINT);
    388   std::string id_remoting = testcase::g_api_key_cache.Get().GetClientID(
    389       testcase::CLIENT_REMOTING);
    390   std::string secret_remoting =
    391       testcase::g_api_key_cache.Get().GetClientSecret(
    392           testcase::CLIENT_REMOTING);
    393   std::string id_remoting_host = testcase::g_api_key_cache.Get().GetClientID(
    394       testcase::CLIENT_REMOTING_HOST);
    395   std::string secret_remoting_host =
    396       testcase::g_api_key_cache.Get().GetClientSecret(
    397           testcase::CLIENT_REMOTING_HOST);
    398 
    399   EXPECT_EQ("API_KEY", api_key);
    400   EXPECT_EQ("ID_MAIN", id_main);
    401   EXPECT_EQ("SECRET_MAIN", secret_main);
    402   EXPECT_EQ("ID_CLOUD_PRINT", id_cloud_print);
    403   EXPECT_EQ("SECRET_CLOUD_PRINT", secret_cloud_print);
    404   EXPECT_EQ("ID_REMOTING", id_remoting);
    405   EXPECT_EQ("SECRET_REMOTING", secret_remoting);
    406   EXPECT_EQ("ID_REMOTING_HOST", id_remoting_host);
    407   EXPECT_EQ("SECRET_REMOTING_HOST", secret_remoting_host);
    408 }
    409 
    410 // Override all keys using both preprocessor defines and environment
    411 // variables.  The environment variables should win.
    412 namespace override_all_keys_env {
    413 
    414 // We start every test by creating a clean environment for the
    415 // preprocessor defines used in google_api_keys.cc
    416 #undef DUMMY_API_TOKEN
    417 #undef GOOGLE_API_KEY
    418 #undef GOOGLE_CLIENT_ID_MAIN
    419 #undef GOOGLE_CLIENT_SECRET_MAIN
    420 #undef GOOGLE_CLIENT_ID_CLOUD_PRINT
    421 #undef GOOGLE_CLIENT_SECRET_CLOUD_PRINT
    422 #undef GOOGLE_CLIENT_ID_REMOTING
    423 #undef GOOGLE_CLIENT_SECRET_REMOTING
    424 #undef GOOGLE_CLIENT_ID_REMOTING_HOST
    425 #undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
    426 #undef GOOGLE_DEFAULT_CLIENT_ID
    427 #undef GOOGLE_DEFAULT_CLIENT_SECRET
    428 
    429 #define GOOGLE_API_KEY "API_KEY"
    430 #define GOOGLE_CLIENT_ID_MAIN "ID_MAIN"
    431 #define GOOGLE_CLIENT_SECRET_MAIN "SECRET_MAIN"
    432 #define GOOGLE_CLIENT_ID_CLOUD_PRINT "ID_CLOUD_PRINT"
    433 #define GOOGLE_CLIENT_SECRET_CLOUD_PRINT "SECRET_CLOUD_PRINT"
    434 #define GOOGLE_CLIENT_ID_REMOTING "ID_REMOTING"
    435 #define GOOGLE_CLIENT_SECRET_REMOTING "SECRET_REMOTING"
    436 #define GOOGLE_CLIENT_ID_REMOTING_HOST "ID_REMOTING_HOST"
    437 #define GOOGLE_CLIENT_SECRET_REMOTING_HOST "SECRET_REMOTING_HOST"
    438 
    439 // Undef include guard so things get defined again, within this namespace.
    440 #undef GOOGLE_APIS_GOOGLE_API_KEYS_H_
    441 #undef GOOGLE_APIS_INTERNAL_GOOGLE_CHROME_API_KEYS_
    442 #include "google_apis/google_api_keys.cc"
    443 
    444 }  // namespace override_all_keys_env
    445 
    446 TEST_F(GoogleAPIKeysTest, OverrideAllKeysUsingEnvironment) {
    447   namespace testcase = override_all_keys_env::google_apis;
    448 
    449   scoped_ptr<base::Environment> env(base::Environment::Create());
    450   env->SetVar("GOOGLE_API_KEY", "env-API_KEY");
    451   env->SetVar("GOOGLE_CLIENT_ID_MAIN", "env-ID_MAIN");
    452   env->SetVar("GOOGLE_CLIENT_ID_CLOUD_PRINT", "env-ID_CLOUD_PRINT");
    453   env->SetVar("GOOGLE_CLIENT_ID_REMOTING", "env-ID_REMOTING");
    454   env->SetVar("GOOGLE_CLIENT_ID_REMOTING_HOST", "env-ID_REMOTING_HOST");
    455   env->SetVar("GOOGLE_CLIENT_SECRET_MAIN", "env-SECRET_MAIN");
    456   env->SetVar("GOOGLE_CLIENT_SECRET_CLOUD_PRINT", "env-SECRET_CLOUD_PRINT");
    457   env->SetVar("GOOGLE_CLIENT_SECRET_REMOTING", "env-SECRET_REMOTING");
    458   env->SetVar("GOOGLE_CLIENT_SECRET_REMOTING_HOST", "env-SECRET_REMOTING_HOST");
    459 
    460   EXPECT_TRUE(testcase::HasKeysConfigured());
    461 
    462   // It's important that the first call to Get() only happen after the
    463   // environment variables have been set.
    464   std::string api_key = testcase::g_api_key_cache.Get().api_key();
    465   std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
    466       testcase::CLIENT_MAIN);
    467   std::string secret_main = testcase::g_api_key_cache.Get().GetClientSecret(
    468       testcase::CLIENT_MAIN);
    469   std::string id_cloud_print =
    470       testcase::g_api_key_cache.Get().GetClientID(
    471           testcase::CLIENT_CLOUD_PRINT);
    472   std::string secret_cloud_print =
    473       testcase::g_api_key_cache.Get().GetClientSecret(
    474           testcase::CLIENT_CLOUD_PRINT);
    475   std::string id_remoting = testcase::g_api_key_cache.Get().GetClientID(
    476       testcase::CLIENT_REMOTING);
    477   std::string secret_remoting =
    478       testcase::g_api_key_cache.Get().GetClientSecret(
    479           testcase::CLIENT_REMOTING);
    480   std::string id_remoting_host = testcase::g_api_key_cache.Get().GetClientID(
    481       testcase::CLIENT_REMOTING_HOST);
    482   std::string secret_remoting_host =
    483       testcase::g_api_key_cache.Get().GetClientSecret(
    484           testcase::CLIENT_REMOTING_HOST);
    485 
    486   EXPECT_EQ("env-API_KEY", api_key);
    487   EXPECT_EQ("env-ID_MAIN", id_main);
    488   EXPECT_EQ("env-SECRET_MAIN", secret_main);
    489   EXPECT_EQ("env-ID_CLOUD_PRINT", id_cloud_print);
    490   EXPECT_EQ("env-SECRET_CLOUD_PRINT", secret_cloud_print);
    491   EXPECT_EQ("env-ID_REMOTING", id_remoting);
    492   EXPECT_EQ("env-SECRET_REMOTING", secret_remoting);
    493   EXPECT_EQ("env-ID_REMOTING_HOST", id_remoting_host);
    494   EXPECT_EQ("env-SECRET_REMOTING_HOST", secret_remoting_host);
    495 }
    496 
    497 #endif  // defined(OS_LINUX) || defined(OS_MACOSX)
    498