| 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 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "google_apis/gaia/fake_oauth2_token_service.h" | 11 #include "google_apis/gaia/fake_oauth2_token_service.h" |
| 12 #include "google_apis/gaia/google_service_auth_error.h" | 12 #include "google_apis/gaia/google_service_auth_error.h" |
| 13 #include "google_apis/gaia/oauth2_token_service.h" | 13 #include "google_apis/gaia/oauth2_token_service.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const char kAccessToken[] = "access_token"; | 18 const char kAccessToken[] = "access_token"; |
| 19 const char kAccountId[] = "test_user@gmail.com"; | 19 const char kAccountId[] = "test_user@gmail.com"; |
| 20 const char kScope[] = "SCOPE"; | 20 const char kScope[] = "SCOPE"; |
| 21 | 21 |
| 22 class TestingOAuth2TokenServiceConsumer : public OAuth2TokenService::Consumer { | 22 class TestingOAuth2TokenServiceConsumer : public OAuth2TokenService::Consumer { |
| 23 public: | 23 public: |
| 24 TestingOAuth2TokenServiceConsumer(); | 24 TestingOAuth2TokenServiceConsumer(); |
| 25 virtual ~TestingOAuth2TokenServiceConsumer(); | 25 virtual ~TestingOAuth2TokenServiceConsumer(); |
| 26 | 26 |
| 27 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 27 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 28 const std::string& access_token, | 28 const std::string& access_token, |
| 29 const base::Time& expiration_time) OVERRIDE; | 29 const base::Time& expiration_time) override; |
| 30 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 30 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 31 const GoogleServiceAuthError& error) OVERRIDE; | 31 const GoogleServiceAuthError& error) override; |
| 32 | 32 |
| 33 int num_get_token_success_; | 33 int num_get_token_success_; |
| 34 int num_get_token_failure_; | 34 int num_get_token_failure_; |
| 35 std::string last_token_; | 35 std::string last_token_; |
| 36 GoogleServiceAuthError last_error_; | 36 GoogleServiceAuthError last_error_; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 TestingOAuth2TokenServiceConsumer::TestingOAuth2TokenServiceConsumer() | 39 TestingOAuth2TokenServiceConsumer::TestingOAuth2TokenServiceConsumer() |
| 40 : OAuth2TokenService::Consumer("test"), | 40 : OAuth2TokenService::Consumer("test"), |
| 41 num_get_token_success_(0), | 41 num_get_token_success_(0), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 const std::string& last_token_invalidated() const { | 78 const std::string& last_token_invalidated() const { |
| 79 return last_token_invalidated_; | 79 return last_token_invalidated_; |
| 80 } | 80 } |
| 81 | 81 |
| 82 protected: | 82 protected: |
| 83 virtual void FetchOAuth2Token(RequestImpl* request, | 83 virtual void FetchOAuth2Token(RequestImpl* request, |
| 84 const std::string& account_id, | 84 const std::string& account_id, |
| 85 net::URLRequestContextGetter* getter, | 85 net::URLRequestContextGetter* getter, |
| 86 const std::string& client_id, | 86 const std::string& client_id, |
| 87 const std::string& client_secret, | 87 const std::string& client_secret, |
| 88 const ScopeSet& scopes) OVERRIDE; | 88 const ScopeSet& scopes) override; |
| 89 | 89 |
| 90 virtual void InvalidateOAuth2Token(const std::string& account_id, | 90 virtual void InvalidateOAuth2Token(const std::string& account_id, |
| 91 const std::string& client_id, | 91 const std::string& client_id, |
| 92 const ScopeSet& scopes, | 92 const ScopeSet& scopes, |
| 93 const std::string& access_token) OVERRIDE; | 93 const std::string& access_token) override; |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 GoogleServiceAuthError response_error_; | 96 GoogleServiceAuthError response_error_; |
| 97 std::string response_access_token_; | 97 std::string response_access_token_; |
| 98 base::Time response_expiration_; | 98 base::Time response_expiration_; |
| 99 int num_invalidate_token_; | 99 int num_invalidate_token_; |
| 100 std::string last_token_invalidated_; | 100 std::string last_token_invalidated_; |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 MockOAuth2TokenService::MockOAuth2TokenService() | 103 MockOAuth2TokenService::MockOAuth2TokenService() |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 const std::string& account_id, | 138 const std::string& account_id, |
| 139 const std::string& client_id, | 139 const std::string& client_id, |
| 140 const ScopeSet& scopes, | 140 const ScopeSet& scopes, |
| 141 const std::string& access_token) { | 141 const std::string& access_token) { |
| 142 ++num_invalidate_token_; | 142 ++num_invalidate_token_; |
| 143 last_token_invalidated_ = access_token; | 143 last_token_invalidated_ = access_token; |
| 144 } | 144 } |
| 145 | 145 |
| 146 class OAuth2TokenServiceRequestTest : public testing::Test { | 146 class OAuth2TokenServiceRequestTest : public testing::Test { |
| 147 public: | 147 public: |
| 148 virtual void SetUp() OVERRIDE; | 148 virtual void SetUp() override; |
| 149 virtual void TearDown() OVERRIDE; | 149 virtual void TearDown() override; |
| 150 | 150 |
| 151 protected: | 151 protected: |
| 152 class Provider : public OAuth2TokenServiceRequest::TokenServiceProvider { | 152 class Provider : public OAuth2TokenServiceRequest::TokenServiceProvider { |
| 153 public: | 153 public: |
| 154 Provider(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 154 Provider(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 155 OAuth2TokenService* token_service); | 155 OAuth2TokenService* token_service); |
| 156 | 156 |
| 157 virtual scoped_refptr<base::SingleThreadTaskRunner> | 157 virtual scoped_refptr<base::SingleThreadTaskRunner> |
| 158 GetTokenServiceTaskRunner() OVERRIDE; | 158 GetTokenServiceTaskRunner() override; |
| 159 virtual OAuth2TokenService* GetTokenService() OVERRIDE; | 159 virtual OAuth2TokenService* GetTokenService() override; |
| 160 | 160 |
| 161 private: | 161 private: |
| 162 virtual ~Provider(); | 162 virtual ~Provider(); |
| 163 | 163 |
| 164 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 164 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 165 OAuth2TokenService* token_service_; | 165 OAuth2TokenService* token_service_; |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 base::MessageLoop ui_loop_; | 168 base::MessageLoop ui_loop_; |
| 169 OAuth2TokenService::ScopeSet scopes_; | 169 OAuth2TokenService::ScopeSet scopes_; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 OAuth2TokenServiceRequest::InvalidateToken( | 259 OAuth2TokenServiceRequest::InvalidateToken( |
| 260 provider_.get(), kAccountId, scopes_, kAccessToken); | 260 provider_.get(), kAccountId, scopes_, kAccessToken); |
| 261 ui_loop_.RunUntilIdle(); | 261 ui_loop_.RunUntilIdle(); |
| 262 EXPECT_EQ(0, consumer_.num_get_token_success_); | 262 EXPECT_EQ(0, consumer_.num_get_token_success_); |
| 263 EXPECT_EQ(0, consumer_.num_get_token_failure_); | 263 EXPECT_EQ(0, consumer_.num_get_token_failure_); |
| 264 EXPECT_EQ(kAccessToken, oauth2_service_->last_token_invalidated()); | 264 EXPECT_EQ(kAccessToken, oauth2_service_->last_token_invalidated()); |
| 265 EXPECT_EQ(1, oauth2_service_->num_invalidate_token()); | 265 EXPECT_EQ(1, oauth2_service_->num_invalidate_token()); |
| 266 } | 266 } |
| 267 | 267 |
| 268 } // namespace | 268 } // namespace |
| OLD | NEW |