oauth2_access_token_manager_test_util.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2013 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. #include "google_apis/gaia/oauth2_access_token_manager_test_util.h"
  5. #include "base/strings/stringprintf.h"
  6. namespace {
  7. const char kValidTokenResponse[] =
  8. "{"
  9. " \"access_token\": \"%s\","
  10. " \"expires_in\": %d,"
  11. " \"token_type\": \"Bearer\""
  12. "}";
  13. }
  14. std::string GetValidTokenResponse(const std::string& token, int expiration) {
  15. return base::StringPrintf(kValidTokenResponse, token.c_str(), expiration);
  16. }
  17. TestingOAuth2AccessTokenManagerConsumer::
  18. TestingOAuth2AccessTokenManagerConsumer()
  19. : OAuth2AccessTokenManager::Consumer("test"),
  20. number_of_successful_tokens_(0),
  21. last_error_(GoogleServiceAuthError::AuthErrorNone()),
  22. number_of_errors_(0) {}
  23. TestingOAuth2AccessTokenManagerConsumer::
  24. ~TestingOAuth2AccessTokenManagerConsumer() {}
  25. void TestingOAuth2AccessTokenManagerConsumer::OnGetTokenSuccess(
  26. const OAuth2AccessTokenManager::Request* request,
  27. const OAuth2AccessTokenConsumer::TokenResponse& token_response) {
  28. last_token_ = token_response.access_token;
  29. ++number_of_successful_tokens_;
  30. }
  31. void TestingOAuth2AccessTokenManagerConsumer::OnGetTokenFailure(
  32. const OAuth2AccessTokenManager::Request* request,
  33. const GoogleServiceAuthError& error) {
  34. last_error_ = error;
  35. ++number_of_errors_;
  36. }