| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "google_apis/gaia/gaia_constants.h" | 9 #include "google_apis/gaia/gaia_constants.h" |
| 10 #include "google_apis/gaia/google_service_auth_error.h" | 10 #include "google_apis/gaia/google_service_auth_error.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 : public TestingOAuth2TokenServiceConsumer { | 23 : public TestingOAuth2TokenServiceConsumer { |
| 24 public: | 24 public: |
| 25 RetryingTestingOAuth2TokenServiceConsumer( | 25 RetryingTestingOAuth2TokenServiceConsumer( |
| 26 OAuth2TokenService* oauth2_service, | 26 OAuth2TokenService* oauth2_service, |
| 27 const std::string& account_id) | 27 const std::string& account_id) |
| 28 : oauth2_service_(oauth2_service), | 28 : oauth2_service_(oauth2_service), |
| 29 account_id_(account_id) {} | 29 account_id_(account_id) {} |
| 30 virtual ~RetryingTestingOAuth2TokenServiceConsumer() {} | 30 virtual ~RetryingTestingOAuth2TokenServiceConsumer() {} |
| 31 | 31 |
| 32 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 32 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 33 const GoogleServiceAuthError& error) OVERRIDE { | 33 const GoogleServiceAuthError& error) override { |
| 34 TestingOAuth2TokenServiceConsumer::OnGetTokenFailure(request, error); | 34 TestingOAuth2TokenServiceConsumer::OnGetTokenFailure(request, error); |
| 35 request_.reset(oauth2_service_->StartRequest( | 35 request_.reset(oauth2_service_->StartRequest( |
| 36 account_id_, OAuth2TokenService::ScopeSet(), this).release()); | 36 account_id_, OAuth2TokenService::ScopeSet(), this).release()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 OAuth2TokenService* oauth2_service_; | 39 OAuth2TokenService* oauth2_service_; |
| 40 std::string account_id_; | 40 std::string account_id_; |
| 41 scoped_ptr<OAuth2TokenService::Request> request_; | 41 scoped_ptr<OAuth2TokenService::Request> request_; |
| 42 }; | 42 }; |
| 43 | 43 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 56 // For testing: set the refresh token to be used. | 56 // For testing: set the refresh token to be used. |
| 57 void set_refresh_token(const std::string& account_id, | 57 void set_refresh_token(const std::string& account_id, |
| 58 const std::string& refresh_token) { | 58 const std::string& refresh_token) { |
| 59 if (refresh_token.empty()) | 59 if (refresh_token.empty()) |
| 60 refresh_tokens_.erase(account_id); | 60 refresh_tokens_.erase(account_id); |
| 61 else | 61 else |
| 62 refresh_tokens_[account_id] = refresh_token; | 62 refresh_tokens_[account_id] = refresh_token; |
| 63 } | 63 } |
| 64 | 64 |
| 65 virtual bool RefreshTokenIsAvailable(const std::string& account_id) const | 65 virtual bool RefreshTokenIsAvailable(const std::string& account_id) const |
| 66 OVERRIDE { | 66 override { |
| 67 std::map<std::string, std::string>::const_iterator it = | 67 std::map<std::string, std::string>::const_iterator it = |
| 68 refresh_tokens_.find(account_id); | 68 refresh_tokens_.find(account_id); |
| 69 | 69 |
| 70 return it != refresh_tokens_.end(); | 70 return it != refresh_tokens_.end(); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 // OAuth2TokenService implementation. | 74 // OAuth2TokenService implementation. |
| 75 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE { | 75 virtual net::URLRequestContextGetter* GetRequestContext() override { |
| 76 return request_context_getter_.get(); | 76 return request_context_getter_.get(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( | 79 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
| 80 const std::string& account_id, | 80 const std::string& account_id, |
| 81 net::URLRequestContextGetter* getter, | 81 net::URLRequestContextGetter* getter, |
| 82 OAuth2AccessTokenConsumer* consumer) OVERRIDE { | 82 OAuth2AccessTokenConsumer* consumer) override { |
| 83 std::map<std::string, std::string>::const_iterator it = | 83 std::map<std::string, std::string>::const_iterator it = |
| 84 refresh_tokens_.find(account_id); | 84 refresh_tokens_.find(account_id); |
| 85 DCHECK(it != refresh_tokens_.end()); | 85 DCHECK(it != refresh_tokens_.end()); |
| 86 std::string refresh_token(it->second); | 86 std::string refresh_token(it->second); |
| 87 return new OAuth2AccessTokenFetcherImpl(consumer, getter, refresh_token); | 87 return new OAuth2AccessTokenFetcherImpl(consumer, getter, refresh_token); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 std::map<std::string, std::string> refresh_tokens_; | 90 std::map<std::string, std::string> refresh_tokens_; |
| 91 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 91 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 class OAuth2TokenServiceTest : public testing::Test { | 94 class OAuth2TokenServiceTest : public testing::Test { |
| 95 public: | 95 public: |
| 96 virtual void SetUp() OVERRIDE { | 96 virtual void SetUp() override { |
| 97 oauth2_service_.reset( | 97 oauth2_service_.reset( |
| 98 new TestOAuth2TokenService(new net::TestURLRequestContextGetter( | 98 new TestOAuth2TokenService(new net::TestURLRequestContextGetter( |
| 99 message_loop_.message_loop_proxy()))); | 99 message_loop_.message_loop_proxy()))); |
| 100 account_id_ = "test_user@gmail.com"; | 100 account_id_ = "test_user@gmail.com"; |
| 101 } | 101 } |
| 102 | 102 |
| 103 virtual void TearDown() OVERRIDE { | 103 virtual void TearDown() override { |
| 104 // Makes sure that all the clean up tasks are run. | 104 // Makes sure that all the clean up tasks are run. |
| 105 base::RunLoop().RunUntilIdle(); | 105 base::RunLoop().RunUntilIdle(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 protected: | 108 protected: |
| 109 base::MessageLoopForIO message_loop_; // net:: stuff needs IO message loop. | 109 base::MessageLoopForIO message_loop_; // net:: stuff needs IO message loop. |
| 110 net::TestURLFetcherFactory factory_; | 110 net::TestURLFetcherFactory factory_; |
| 111 scoped_ptr<TestOAuth2TokenService> oauth2_service_; | 111 scoped_ptr<TestOAuth2TokenService> oauth2_service_; |
| 112 std::string account_id_; | 112 std::string account_id_; |
| 113 TestingOAuth2TokenServiceConsumer consumer_; | 113 TestingOAuth2TokenServiceConsumer consumer_; |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 } else if (i < j) { | 642 } else if (i < j) { |
| 643 EXPECT_TRUE(params[i] < params[j]) << " i=" << i << ", j=" << j; | 643 EXPECT_TRUE(params[i] < params[j]) << " i=" << i << ", j=" << j; |
| 644 EXPECT_FALSE(params[j] < params[i]) << " i=" << i << ", j=" << j; | 644 EXPECT_FALSE(params[j] < params[i]) << " i=" << i << ", j=" << j; |
| 645 } else { | 645 } else { |
| 646 EXPECT_TRUE(params[j] < params[i]) << " i=" << i << ", j=" << j; | 646 EXPECT_TRUE(params[j] < params[i]) << " i=" << i << ", j=" << j; |
| 647 EXPECT_FALSE(params[i] < params[j]) << " i=" << i << ", j=" << j; | 647 EXPECT_FALSE(params[i] < params[j]) << " i=" << i << ", j=" << j; |
| 648 } | 648 } |
| 649 } | 649 } |
| 650 } | 650 } |
| 651 } | 651 } |
| OLD | NEW |