Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Unit tests for implementation of google_api_keys namespace. | 5 // Unit tests for implementation of google_api_keys namespace. |
| 6 // | 6 // |
| 7 // Because the file deals with a lot of preprocessor defines and | 7 // Because the file deals with a lot of preprocessor defines and |
| 8 // optionally includes an internal header, the way we test is by | 8 // optionally includes an internal header, the way we test is by |
| 9 // including the .cc file multiple times with different defines set. | 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 | 10 // This is a little unorthodox, but it lets us test the behavior as |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 // from that file included here is the "right" version. | 35 // from that file included here is the "right" version. |
| 36 | 36 |
| 37 #include <stddef.h> | 37 #include <stddef.h> |
| 38 | 38 |
| 39 #include <string> | 39 #include <string> |
| 40 #include "base/command_line.h" | 40 #include "base/command_line.h" |
| 41 #include "base/environment.h" | 41 #include "base/environment.h" |
| 42 #include "base/lazy_instance.h" | 42 #include "base/lazy_instance.h" |
| 43 #include "base/logging.h" | 43 #include "base/logging.h" |
| 44 #include "base/strings/stringize_macros.h" | 44 #include "base/strings/stringize_macros.h" |
| 45 #include "google_apis/google_api_keys_mac.h" | |
|
Roger Tawa OOO till Jul 10th
2016/08/08 18:03:05
Should this be in an #ifdef?
bzanotti
2016/08/10 13:23:40
Yes, this unit test is ran on Linux as well where
| |
| 45 | 46 |
| 46 // This is the default baked-in value for OAuth IDs and secrets. | 47 // This is the default baked-in value for OAuth IDs and secrets. |
| 47 static const char kDummyToken[] = "dummytoken"; | 48 static const char kDummyToken[] = "dummytoken"; |
| 48 | 49 |
| 49 struct EnvironmentCache { | 50 struct EnvironmentCache { |
| 50 public: | 51 public: |
| 51 EnvironmentCache() : variable_name(NULL), was_set(false) {} | 52 EnvironmentCache() : variable_name(NULL), was_set(false) {} |
| 52 | 53 |
| 53 const char* variable_name; | 54 const char* variable_name; |
| 54 bool was_set; | 55 bool was_set; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 private: | 99 private: |
| 99 std::unique_ptr<base::Environment> env_; | 100 std::unique_ptr<base::Environment> env_; |
| 100 | 101 |
| 101 // Why 3? It is for GOOGLE_API_KEY, GOOGLE_DEFAULT_CLIENT_ID and | 102 // Why 3? It is for GOOGLE_API_KEY, GOOGLE_DEFAULT_CLIENT_ID and |
| 102 // GOOGLE_DEFAULT_CLIENT_SECRET. | 103 // GOOGLE_DEFAULT_CLIENT_SECRET. |
| 103 // | 104 // |
| 104 // Why 2 times CLIENT_NUM_ITEMS? This is the number of different | 105 // Why 2 times CLIENT_NUM_ITEMS? This is the number of different |
| 105 // clients in the OAuth2Client enumeration, and for each of these we | 106 // clients in the OAuth2Client enumeration, and for each of these we |
| 106 // have both an ID and a secret. | 107 // have both an ID and a secret. |
| 107 EnvironmentCache env_cache_[3 + 2 * google_apis::CLIENT_NUM_ITEMS]; | 108 EnvironmentCache env_cache_[3 + 2 * google_apis::CLIENT_NUM_ITEMS]; |
| 108 }; | 109 }; |
|
Roger Tawa OOO till Jul 10th
2016/08/08 18:03:05
There seems to be lots of duplicate code here with
bzanotti
2016/08/10 13:23:40
Done.
| |
| 109 | 110 |
| 110 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) | 111 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) |
| 111 // Test official build behavior, since we are in a checkout where this | 112 // Test official build behavior, since we are in a checkout where this |
| 112 // is possible. | 113 // is possible. |
| 113 namespace official_build { | 114 namespace official_build { |
| 114 | 115 |
| 115 // We start every test by creating a clean environment for the | 116 // We start every test by creating a clean environment for the |
| 116 // preprocessor defines used in google_api_keys.cc | 117 // preprocessor defines used in google_api_keys.cc |
| 117 #undef DUMMY_API_TOKEN | 118 #undef DUMMY_API_TOKEN |
| 118 #undef GOOGLE_API_KEY | 119 #undef GOOGLE_API_KEY |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 EXPECT_EQ("env-SECRET_MAIN", secret_main); | 495 EXPECT_EQ("env-SECRET_MAIN", secret_main); |
| 495 EXPECT_EQ("env-ID_CLOUD_PRINT", id_cloud_print); | 496 EXPECT_EQ("env-ID_CLOUD_PRINT", id_cloud_print); |
| 496 EXPECT_EQ("env-SECRET_CLOUD_PRINT", secret_cloud_print); | 497 EXPECT_EQ("env-SECRET_CLOUD_PRINT", secret_cloud_print); |
| 497 EXPECT_EQ("env-ID_REMOTING", id_remoting); | 498 EXPECT_EQ("env-ID_REMOTING", id_remoting); |
| 498 EXPECT_EQ("env-SECRET_REMOTING", secret_remoting); | 499 EXPECT_EQ("env-SECRET_REMOTING", secret_remoting); |
| 499 EXPECT_EQ("env-ID_REMOTING_HOST", id_remoting_host); | 500 EXPECT_EQ("env-ID_REMOTING_HOST", id_remoting_host); |
| 500 EXPECT_EQ("env-SECRET_REMOTING_HOST", secret_remoting_host); | 501 EXPECT_EQ("env-SECRET_REMOTING_HOST", secret_remoting_host); |
| 501 } | 502 } |
| 502 | 503 |
| 503 #endif // defined(OS_LINUX) || defined(OS_MACOSX) | 504 #endif // defined(OS_LINUX) || defined(OS_MACOSX) |
| OLD | NEW |