| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_request.h" | 5 #include "google_apis/gaia/oauth2_token_service_request.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 83 } |
| 84 | 84 |
| 85 protected: | 85 protected: |
| 86 void FetchOAuth2Token(RequestImpl* request, | 86 void FetchOAuth2Token(RequestImpl* request, |
| 87 const std::string& account_id, | 87 const std::string& account_id, |
| 88 net::URLRequestContextGetter* getter, | 88 net::URLRequestContextGetter* getter, |
| 89 const std::string& client_id, | 89 const std::string& client_id, |
| 90 const std::string& client_secret, | 90 const std::string& client_secret, |
| 91 const ScopeSet& scopes) override; | 91 const ScopeSet& scopes) override; |
| 92 | 92 |
| 93 void InvalidateOAuth2Token(const std::string& account_id, | 93 void InvalidateAccessTokenImpl(const std::string& account_id, |
| 94 const std::string& client_id, | 94 const std::string& client_id, |
| 95 const ScopeSet& scopes, | 95 const ScopeSet& scopes, |
| 96 const std::string& access_token) override; | 96 const std::string& access_token) override; |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 GoogleServiceAuthError response_error_; | 99 GoogleServiceAuthError response_error_; |
| 100 std::string response_access_token_; | 100 std::string response_access_token_; |
| 101 base::Time response_expiration_; | 101 base::Time response_expiration_; |
| 102 int num_invalidate_token_; | 102 int num_invalidate_token_; |
| 103 std::string last_token_invalidated_; | 103 std::string last_token_invalidated_; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 MockOAuth2TokenService::MockOAuth2TokenService() | 106 MockOAuth2TokenService::MockOAuth2TokenService() |
| (...skipping 23 matching lines...) Expand all Loading... |
| 130 const ScopeSet& scopes) { | 130 const ScopeSet& scopes) { |
| 131 base::MessageLoop::current()->PostTask( | 131 base::MessageLoop::current()->PostTask( |
| 132 FROM_HERE, | 132 FROM_HERE, |
| 133 base::Bind(&OAuth2TokenService::RequestImpl::InformConsumer, | 133 base::Bind(&OAuth2TokenService::RequestImpl::InformConsumer, |
| 134 request->AsWeakPtr(), | 134 request->AsWeakPtr(), |
| 135 response_error_, | 135 response_error_, |
| 136 response_access_token_, | 136 response_access_token_, |
| 137 response_expiration_)); | 137 response_expiration_)); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void MockOAuth2TokenService::InvalidateOAuth2Token( | 140 void MockOAuth2TokenService::InvalidateAccessTokenImpl( |
| 141 const std::string& account_id, | 141 const std::string& account_id, |
| 142 const std::string& client_id, | 142 const std::string& client_id, |
| 143 const ScopeSet& scopes, | 143 const ScopeSet& scopes, |
| 144 const std::string& access_token) { | 144 const std::string& access_token) { |
| 145 ++num_invalidate_token_; | 145 ++num_invalidate_token_; |
| 146 last_token_invalidated_ = access_token; | 146 last_token_invalidated_ = access_token; |
| 147 } | 147 } |
| 148 | 148 |
| 149 class OAuth2TokenServiceRequestTest : public testing::Test { | 149 class OAuth2TokenServiceRequestTest : public testing::Test { |
| 150 public: | 150 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 171 base::MessageLoop ui_loop_; | 171 base::MessageLoop ui_loop_; |
| 172 OAuth2TokenService::ScopeSet scopes_; | 172 OAuth2TokenService::ScopeSet scopes_; |
| 173 scoped_ptr<MockOAuth2TokenService> oauth2_service_; | 173 scoped_ptr<MockOAuth2TokenService> oauth2_service_; |
| 174 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> provider_; | 174 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> provider_; |
| 175 TestingOAuth2TokenServiceConsumer consumer_; | 175 TestingOAuth2TokenServiceConsumer consumer_; |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 void OAuth2TokenServiceRequestTest::SetUp() { | 178 void OAuth2TokenServiceRequestTest::SetUp() { |
| 179 scopes_.insert(kScope); | 179 scopes_.insert(kScope); |
| 180 oauth2_service_.reset(new MockOAuth2TokenService); | 180 oauth2_service_.reset(new MockOAuth2TokenService); |
| 181 oauth2_service_->AddAccount(kAccountId); | 181 oauth2_service_->GetDelegate()->UpdateCredentials(kAccountId, |
| 182 "refresh_token"); |
| 182 provider_ = | 183 provider_ = |
| 183 new Provider(base::ThreadTaskRunnerHandle::Get(), oauth2_service_.get()); | 184 new Provider(base::ThreadTaskRunnerHandle::Get(), oauth2_service_.get()); |
| 184 } | 185 } |
| 185 | 186 |
| 186 void OAuth2TokenServiceRequestTest::TearDown() { | 187 void OAuth2TokenServiceRequestTest::TearDown() { |
| 187 // Run the loop to execute any pending tasks that may free resources. | 188 // Run the loop to execute any pending tasks that may free resources. |
| 188 ui_loop_.RunUntilIdle(); | 189 ui_loop_.RunUntilIdle(); |
| 189 } | 190 } |
| 190 | 191 |
| 191 OAuth2TokenServiceRequestTest::Provider::Provider( | 192 OAuth2TokenServiceRequestTest::Provider::Provider( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 OAuth2TokenServiceRequest::InvalidateToken( | 263 OAuth2TokenServiceRequest::InvalidateToken( |
| 263 provider_.get(), kAccountId, scopes_, kAccessToken); | 264 provider_.get(), kAccountId, scopes_, kAccessToken); |
| 264 ui_loop_.RunUntilIdle(); | 265 ui_loop_.RunUntilIdle(); |
| 265 EXPECT_EQ(0, consumer_.num_get_token_success_); | 266 EXPECT_EQ(0, consumer_.num_get_token_success_); |
| 266 EXPECT_EQ(0, consumer_.num_get_token_failure_); | 267 EXPECT_EQ(0, consumer_.num_get_token_failure_); |
| 267 EXPECT_EQ(kAccessToken, oauth2_service_->last_token_invalidated()); | 268 EXPECT_EQ(kAccessToken, oauth2_service_->last_token_invalidated()); |
| 268 EXPECT_EQ(1, oauth2_service_->num_invalidate_token()); | 269 EXPECT_EQ(1, oauth2_service_->num_invalidate_token()); |
| 269 } | 270 } |
| 270 | 271 |
| 271 } // namespace | 272 } // namespace |
| OLD | NEW |