Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: google_apis/google_api_keys_unittest.cc

Issue 1873663002: Convert //google_apis from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 // close to unmodified as possible. 11 // close to unmodified as possible.
12 12
13 #include "google_apis/google_api_keys.h" 13 #include "google_apis/google_api_keys.h"
14 14
15 #include <memory>
16
15 #include "base/macros.h" 17 #include "base/macros.h"
16 #include "build/build_config.h" 18 #include "build/build_config.h"
17 #include "google_apis/gaia/gaia_switches.h" 19 #include "google_apis/gaia/gaia_switches.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 21
20 // The Win builders fail (with a linker crash) when trying to link 22 // The Win builders fail (with a linker crash) when trying to link
21 // unit_tests, and the Android builders complain about multiply 23 // unit_tests, and the Android builders complain about multiply
22 // defined symbols (likely they don't do name decoration as well as 24 // defined symbols (likely they don't do name decoration as well as
23 // the Mac and Linux linkers). Therefore these tests are only built 25 // the Mac and Linux linkers). Therefore these tests are only built
24 // and run on Mac and Linux, which should provide plenty of coverage 26 // and run on Mac and Linux, which should provide plenty of coverage
25 // since there are no platform-specific bits in this code. 27 // since there are no platform-specific bits in this code.
26 #if defined(OS_LINUX) || defined(OS_MACOSX) 28 #if defined(OS_LINUX) || defined(OS_MACOSX)
27 29
28 // We need to include everything included by google_api_keys.cc once 30 // We need to include everything included by google_api_keys.cc once
29 // at global scope so that things like STL and classes from base don't 31 // at global scope so that things like STL and classes from base don't
30 // get defined when we re-include the google_api_keys.cc file 32 // get defined when we re-include the google_api_keys.cc file
31 // below. We used to include that file in its entirety here, but that 33 // below. We used to include that file in its entirety here, but that
32 // can cause problems if the linker decides the version of symbols 34 // can cause problems if the linker decides the version of symbols
33 // from that file included here is the "right" version. 35 // from that file included here is the "right" version.
34 36
35 #include <stddef.h> 37 #include <stddef.h>
36 38
37 #include <string> 39 #include <string>
38 #include "base/command_line.h" 40 #include "base/command_line.h"
39 #include "base/environment.h" 41 #include "base/environment.h"
40 #include "base/lazy_instance.h" 42 #include "base/lazy_instance.h"
41 #include "base/logging.h" 43 #include "base/logging.h"
42 #include "base/memory/scoped_ptr.h"
43 #include "base/strings/stringize_macros.h" 44 #include "base/strings/stringize_macros.h"
44 45
45 // This is the default baked-in value for OAuth IDs and secrets. 46 // This is the default baked-in value for OAuth IDs and secrets.
46 static const char kDummyToken[] = "dummytoken"; 47 static const char kDummyToken[] = "dummytoken";
47 48
48 struct EnvironmentCache { 49 struct EnvironmentCache {
49 public: 50 public:
50 EnvironmentCache() : variable_name(NULL), was_set(false) {} 51 EnvironmentCache() : variable_name(NULL), was_set(false) {}
51 52
52 const char* variable_name; 53 const char* variable_name;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // Restore environment. 89 // Restore environment.
89 for (size_t i = 0; i < arraysize(env_cache_); ++i) { 90 for (size_t i = 0; i < arraysize(env_cache_); ++i) {
90 EnvironmentCache& cache = env_cache_[i]; 91 EnvironmentCache& cache = env_cache_[i];
91 if (cache.was_set) { 92 if (cache.was_set) {
92 env_->SetVar(cache.variable_name, cache.value); 93 env_->SetVar(cache.variable_name, cache.value);
93 } 94 }
94 } 95 }
95 } 96 }
96 97
97 private: 98 private:
98 scoped_ptr<base::Environment> env_; 99 std::unique_ptr<base::Environment> env_;
99 100
100 // Why 3? It is for GOOGLE_API_KEY, GOOGLE_DEFAULT_CLIENT_ID and 101 // Why 3? It is for GOOGLE_API_KEY, GOOGLE_DEFAULT_CLIENT_ID and
101 // GOOGLE_DEFAULT_CLIENT_SECRET. 102 // GOOGLE_DEFAULT_CLIENT_SECRET.
102 // 103 //
103 // Why 2 times CLIENT_NUM_ITEMS? This is the number of different 104 // Why 2 times CLIENT_NUM_ITEMS? This is the number of different
104 // clients in the OAuth2Client enumeration, and for each of these we 105 // clients in the OAuth2Client enumeration, and for each of these we
105 // have both an ID and a secret. 106 // have both an ID and a secret.
106 EnvironmentCache env_cache_[3 + 2 * google_apis::CLIENT_NUM_ITEMS]; 107 EnvironmentCache env_cache_[3 + 2 * google_apis::CLIENT_NUM_ITEMS];
107 }; 108 };
108 109
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 // Undef include guard so things get defined again, within this namespace. 445 // Undef include guard so things get defined again, within this namespace.
445 #undef GOOGLE_APIS_GOOGLE_API_KEYS_H_ 446 #undef GOOGLE_APIS_GOOGLE_API_KEYS_H_
446 #undef GOOGLE_APIS_INTERNAL_GOOGLE_CHROME_API_KEYS_ 447 #undef GOOGLE_APIS_INTERNAL_GOOGLE_CHROME_API_KEYS_
447 #include "google_apis/google_api_keys.cc" 448 #include "google_apis/google_api_keys.cc"
448 449
449 } // namespace override_all_keys_env 450 } // namespace override_all_keys_env
450 451
451 TEST_F(GoogleAPIKeysTest, OverrideAllKeysUsingEnvironment) { 452 TEST_F(GoogleAPIKeysTest, OverrideAllKeysUsingEnvironment) {
452 namespace testcase = override_all_keys_env::google_apis; 453 namespace testcase = override_all_keys_env::google_apis;
453 454
454 scoped_ptr<base::Environment> env(base::Environment::Create()); 455 std::unique_ptr<base::Environment> env(base::Environment::Create());
455 env->SetVar("GOOGLE_API_KEY", "env-API_KEY"); 456 env->SetVar("GOOGLE_API_KEY", "env-API_KEY");
456 env->SetVar("GOOGLE_CLIENT_ID_MAIN", "env-ID_MAIN"); 457 env->SetVar("GOOGLE_CLIENT_ID_MAIN", "env-ID_MAIN");
457 env->SetVar("GOOGLE_CLIENT_ID_CLOUD_PRINT", "env-ID_CLOUD_PRINT"); 458 env->SetVar("GOOGLE_CLIENT_ID_CLOUD_PRINT", "env-ID_CLOUD_PRINT");
458 env->SetVar("GOOGLE_CLIENT_ID_REMOTING", "env-ID_REMOTING"); 459 env->SetVar("GOOGLE_CLIENT_ID_REMOTING", "env-ID_REMOTING");
459 env->SetVar("GOOGLE_CLIENT_ID_REMOTING_HOST", "env-ID_REMOTING_HOST"); 460 env->SetVar("GOOGLE_CLIENT_ID_REMOTING_HOST", "env-ID_REMOTING_HOST");
460 env->SetVar("GOOGLE_CLIENT_SECRET_MAIN", "env-SECRET_MAIN"); 461 env->SetVar("GOOGLE_CLIENT_SECRET_MAIN", "env-SECRET_MAIN");
461 env->SetVar("GOOGLE_CLIENT_SECRET_CLOUD_PRINT", "env-SECRET_CLOUD_PRINT"); 462 env->SetVar("GOOGLE_CLIENT_SECRET_CLOUD_PRINT", "env-SECRET_CLOUD_PRINT");
462 env->SetVar("GOOGLE_CLIENT_SECRET_REMOTING", "env-SECRET_REMOTING"); 463 env->SetVar("GOOGLE_CLIENT_SECRET_REMOTING", "env-SECRET_REMOTING");
463 env->SetVar("GOOGLE_CLIENT_SECRET_REMOTING_HOST", "env-SECRET_REMOTING_HOST"); 464 env->SetVar("GOOGLE_CLIENT_SECRET_REMOTING_HOST", "env-SECRET_REMOTING_HOST");
464 465
(...skipping 28 matching lines...) Expand all
493 EXPECT_EQ("env-SECRET_MAIN", secret_main); 494 EXPECT_EQ("env-SECRET_MAIN", secret_main);
494 EXPECT_EQ("env-ID_CLOUD_PRINT", id_cloud_print); 495 EXPECT_EQ("env-ID_CLOUD_PRINT", id_cloud_print);
495 EXPECT_EQ("env-SECRET_CLOUD_PRINT", secret_cloud_print); 496 EXPECT_EQ("env-SECRET_CLOUD_PRINT", secret_cloud_print);
496 EXPECT_EQ("env-ID_REMOTING", id_remoting); 497 EXPECT_EQ("env-ID_REMOTING", id_remoting);
497 EXPECT_EQ("env-SECRET_REMOTING", secret_remoting); 498 EXPECT_EQ("env-SECRET_REMOTING", secret_remoting);
498 EXPECT_EQ("env-ID_REMOTING_HOST", id_remoting_host); 499 EXPECT_EQ("env-ID_REMOTING_HOST", id_remoting_host);
499 EXPECT_EQ("env-SECRET_REMOTING_HOST", secret_remoting_host); 500 EXPECT_EQ("env-SECRET_REMOTING_HOST", secret_remoting_host);
500 } 501 }
501 502
502 #endif // defined(OS_LINUX) || defined(OS_MACOSX) 503 #endif // defined(OS_LINUX) || defined(OS_MACOSX)
OLDNEW
« google_apis/drive/base_requests.cc ('K') | « google_apis/google_api_keys.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698