forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth2_access_token_manager_test_util.cc
44 lines (36 loc) · 1.41 KB
/
oauth2_access_token_manager_test_util.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "google_apis/gaia/oauth2_access_token_manager_test_util.h"
#include "base/strings/stringprintf.h"
namespace {
const char kValidTokenResponse[] =
"{"
" \"access_token\": \"%s\","
" \"expires_in\": %d,"
" \"token_type\": \"Bearer\""
"}";
}
std::string GetValidTokenResponse(const std::string& token, int expiration) {
return base::StringPrintf(kValidTokenResponse, token.c_str(), expiration);
}
TestingOAuth2AccessTokenManagerConsumer::
TestingOAuth2AccessTokenManagerConsumer()
: OAuth2AccessTokenManager::Consumer("test"),
number_of_successful_tokens_(0),
last_error_(GoogleServiceAuthError::AuthErrorNone()),
number_of_errors_(0) {}
TestingOAuth2AccessTokenManagerConsumer::
~TestingOAuth2AccessTokenManagerConsumer() {}
void TestingOAuth2AccessTokenManagerConsumer::OnGetTokenSuccess(
const OAuth2AccessTokenManager::Request* request,
const OAuth2AccessTokenConsumer::TokenResponse& token_response) {
last_token_ = token_response.access_token;
++number_of_successful_tokens_;
}
void TestingOAuth2AccessTokenManagerConsumer::OnGetTokenFailure(
const OAuth2AccessTokenManager::Request* request,
const GoogleServiceAuthError& error) {
last_error_ = error;
++number_of_errors_;
}