OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "google_apis/gaia/oauth2_token_service_test_util.h" | 5 #include "google_apis/gaia/oauth2_token_service_test_util.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 const char kValidTokenResponse[] = | 10 const char kValidTokenResponse[] = |
11 "{" | 11 "{" |
12 " \"access_token\": \"%s\"," | 12 " \"access_token\": \"%s\"," |
13 " \"expires_in\": %d," | 13 " \"expires_in\": %d," |
14 " \"token_type\": \"Bearer\"" | 14 " \"token_type\": \"Bearer\"" |
15 "}"; | 15 "}"; |
16 } | 16 } |
17 | 17 |
18 std::string GetValidTokenResponse(std::string token, int expiration) { | 18 std::string GetValidTokenResponse(const std::string& token, int expiration) { |
19 return base::StringPrintf(kValidTokenResponse, token.c_str(), expiration); | 19 return base::StringPrintf(kValidTokenResponse, token.c_str(), expiration); |
20 } | 20 } |
21 | 21 |
22 TestingOAuth2TokenServiceConsumer::TestingOAuth2TokenServiceConsumer() | 22 TestingOAuth2TokenServiceConsumer::TestingOAuth2TokenServiceConsumer() |
23 : OAuth2TokenService::Consumer("test"), | 23 : OAuth2TokenService::Consumer("test"), |
24 number_of_successful_tokens_(0), | 24 number_of_successful_tokens_(0), |
25 last_error_(GoogleServiceAuthError::AuthErrorNone()), | 25 last_error_(GoogleServiceAuthError::AuthErrorNone()), |
26 number_of_errors_(0) { | 26 number_of_errors_(0) { |
27 } | 27 } |
28 | 28 |
29 TestingOAuth2TokenServiceConsumer::~TestingOAuth2TokenServiceConsumer() { | 29 TestingOAuth2TokenServiceConsumer::~TestingOAuth2TokenServiceConsumer() { |
30 } | 30 } |
31 | 31 |
32 void TestingOAuth2TokenServiceConsumer::OnGetTokenSuccess( | 32 void TestingOAuth2TokenServiceConsumer::OnGetTokenSuccess( |
33 const OAuth2TokenService::Request* request, | 33 const OAuth2TokenService::Request* request, |
34 const std::string& token, | 34 const std::string& token, |
35 const base::Time& expiration_date) { | 35 const base::Time& expiration_date) { |
36 last_token_ = token; | 36 last_token_ = token; |
37 ++number_of_successful_tokens_; | 37 ++number_of_successful_tokens_; |
38 } | 38 } |
39 | 39 |
40 void TestingOAuth2TokenServiceConsumer::OnGetTokenFailure( | 40 void TestingOAuth2TokenServiceConsumer::OnGetTokenFailure( |
41 const OAuth2TokenService::Request* request, | 41 const OAuth2TokenService::Request* request, |
42 const GoogleServiceAuthError& error) { | 42 const GoogleServiceAuthError& error) { |
43 last_error_ = error; | 43 last_error_ = error; |
44 ++number_of_errors_; | 44 ++number_of_errors_; |
45 } | 45 } |
OLD | NEW |