0

[google-apis] Stop re-including google_api_keys-inc.cc in tests

Instead of including google_api_keys-inc.cc multiple times in the tests,
we can now construct ApiKeyCache instance in a test and re-assign the
global pointer to it.

Bug: 367764868
Change-Id: I7a229aed2357de4e61a318fd7da9a0b63020697c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5878080
Commit-Queue: Alex Ilin <alexilin@chromium.org>
Reviewed-by: Mihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1358788}
This commit is contained in:
Alex Ilin
2024-09-23 14:09:40 +00:00
committed by Chromium LUCI CQ
parent df6c719341
commit c8f909854f
7 changed files with 241 additions and 281 deletions

@ -5,11 +5,10 @@
#ifndef GOOGLE_APIS_GOOGLE_API_KEYS_H_
#define GOOGLE_APIS_GOOGLE_API_KEYS_H_
// If you add more includes to this file, you also need to add them to
// google_api_keys_unittest.cc.
#include <string>
#include "base/component_export.h"
#include "base/functional/callback_helpers.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "google_apis/buildflags.h"
@ -66,6 +65,8 @@ enum class Channel;
namespace google_apis {
class ApiKeyCache;
COMPONENT_EXPORT(GOOGLE_APIS) extern const char kAPIKeysDevelopersHowToURL[];
// Returns true if no dummy API key is set.
@ -168,6 +169,12 @@ void SetOAuth2ClientSecret(OAuth2Client client,
// Google Chrome.
COMPONENT_EXPORT(GOOGLE_APIS) bool IsGoogleChromeAPIKeyUsed();
// Sets a testing global instance of `ApiKeyCache` and returns a scoped object
// that will restore the previous value once destroyed.
COMPONENT_EXPORT(GOOGLE_APIS)
base::ScopedClosureRunner
SetScopedApiKeyCacheForTesting(ApiKeyCache* api_key_cache);
} // namespace google_apis
#endif // GOOGLE_APIS_GOOGLE_API_KEYS_H_