Index: chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.cc |
diff --git a/chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.cc b/chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.cc |
index 6c81f188888f6c430dd3895a2156f42e8b9a9f6a..82f794acae2415d1481e1ee1b35583aaabc7e7b8 100644 |
--- a/chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.cc |
+++ b/chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.cc |
@@ -31,6 +31,8 @@ const int kRequestRestartDelay = 3000; |
} // namespace |
+bool PolicyOAuth2TokenFetcher::enable_fake_for_testing_ = false; |
achuithb
2016/03/03 22:45:00
do we use comment //static here? I think we do?
jdufault
2016/03/04 20:42:47
Done.
|
+ |
PolicyOAuth2TokenFetcher::PolicyOAuth2TokenFetcher() { |
} |
@@ -46,6 +48,13 @@ void PolicyOAuth2TokenFetcher::StartWithSigninContext( |
auth_context_getter_ = auth_context_getter; |
system_context_getter_ = system_context_getter; |
callback_ = callback; |
+ |
+ if (enable_fake_for_testing_) { |
achuithb
2016/03/03 22:45:00
Rather than pollute this class, is it possible to
jdufault
2016/03/03 23:11:04
Sure; I will have to make PolicyOAuth2TokenFetcher
achuithb
2016/03/03 23:23:43
I think that would be cleaner?
achuithb
2016/03/04 19:12:37
Or maybe this is too much work for not much gain.
jdufault
2016/03/04 20:42:47
Done. Also moved the impl header file to the cc fi
|
+ OnGetTokenSuccess("authcode", |
+ base::Time::Now() + base::TimeDelta::FromMinutes(5)); |
+ return; |
+ } |
+ |
StartFetchingRefreshToken(); |
} |
@@ -58,6 +67,13 @@ void PolicyOAuth2TokenFetcher::StartWithAuthCode( |
auth_code_ = auth_code; |
system_context_getter_ = system_context_getter; |
callback_ = callback; |
+ |
+ if (enable_fake_for_testing_) { |
+ OnGetTokenSuccess("authcode", |
+ base::Time::Now() + base::TimeDelta::FromMinutes(5)); |
+ return; |
+ } |
+ |
StartFetchingRefreshToken(); |
} |
@@ -70,6 +86,13 @@ void PolicyOAuth2TokenFetcher::StartWithRefreshToken( |
oauth2_refresh_token_ = oauth2_refresh_token; |
system_context_getter_ = system_context_getter; |
callback_ = callback; |
+ |
+ if (enable_fake_for_testing_) { |
+ OnGetTokenSuccess("authcode", |
+ base::Time::Now() + base::TimeDelta::FromMinutes(5)); |
+ return; |
+ } |
+ |
StartFetchingAccessToken(); |
} |
@@ -100,6 +123,10 @@ void PolicyOAuth2TokenFetcher::StartFetchingAccessToken() { |
scopes); |
} |
+void PolicyOAuth2TokenFetcher::EnableFakeForTesting() { |
+ enable_fake_for_testing_ = true; |
+} |
+ |
void PolicyOAuth2TokenFetcher::OnClientOAuthSuccess( |
const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { |
VLOG(1) << "OAuth2 tokens for policy fetching succeeded."; |