Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 6 #define CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 | 13 |
| 14 #if defined(OS_ANDROID) | 14 #if defined(OS_ANDROID) |
| 15 #include "chrome/browser/signin/android_profile_oauth2_token_service.h" | 15 #include "chrome/browser/signin/android_profile_oauth2_token_service.h" |
| 16 #elif defined(OS_IOS) | |
| 17 #include "components/signin/ios/browser/profile_oauth2_token_service_ios.h" | |
| 16 #else | 18 #else |
| 17 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 19 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 18 #endif | 20 #endif |
| 19 | 21 |
| 20 // Helper class to simplify writing unittests that depend on an instance of | 22 // Helper class to simplify writing unittests that depend on an instance of |
| 21 // ProfileOAuth2TokenService. | 23 // ProfileOAuth2TokenService. |
| 22 // | 24 // |
| 23 // Tests would typically do something like the following: | 25 // Tests would typically do something like the following: |
| 24 // | 26 // |
| 25 // FakeProfileOAuth2TokenService service; | 27 // FakeProfileOAuth2TokenService service; |
| 26 // ... | 28 // ... |
| 27 // service.IssueRefreshToken("token"); // Issue refresh token/notify observers | 29 // service.IssueRefreshToken("token"); // Issue refresh token/notify observers |
| 28 // ... | 30 // ... |
| 29 // // Confirm that there is at least one active request. | 31 // // Confirm that there is at least one active request. |
| 30 // EXPECT_GT(0U, service.GetPendingRequests().size()); | 32 // EXPECT_GT(0U, service.GetPendingRequests().size()); |
| 31 // ... | 33 // ... |
| 32 // // Make any pending token fetches for a given scope succeed. | 34 // // Make any pending token fetches for a given scope succeed. |
| 33 // ScopeSet scopes; | 35 // ScopeSet scopes; |
| 34 // scopes.insert(GaiaConstants::kYourServiceScope); | 36 // scopes.insert(GaiaConstants::kYourServiceScope); |
| 35 // IssueTokenForScope(scopes, "access_token", base::Time()::Max()); | 37 // IssueTokenForScope(scopes, "access_token", base::Time()::Max()); |
| 36 // ... | 38 // ... |
| 37 // // ...or make them fail... | 39 // // ...or make them fail... |
| 38 // IssueErrorForScope(scopes, GoogleServiceAuthError(INVALID_GAIA_CREDENTIALS)); | 40 // IssueErrorForScope(scopes, GoogleServiceAuthError(INVALID_GAIA_CREDENTIALS)); |
| 39 // | 41 // |
| 40 class FakeProfileOAuth2TokenService | 42 class FakeProfileOAuth2TokenService |
| 41 #if defined(OS_ANDROID) | 43 #if defined(OS_ANDROID) |
| 42 : public AndroidProfileOAuth2TokenService { | 44 : public AndroidProfileOAuth2TokenService { |
| 45 #elif defined(OS_IOS) | |
| 46 : public ProfileOAuth2TokenServiceIOS { | |
| 43 #else | 47 #else |
| 44 : public ProfileOAuth2TokenService { | 48 : public ProfileOAuth2TokenService { |
| 45 #endif | 49 #endif |
| 46 public: | 50 public: |
| 47 struct PendingRequest { | 51 struct PendingRequest { |
| 48 PendingRequest(); | 52 PendingRequest(); |
| 49 ~PendingRequest(); | 53 ~PendingRequest(); |
| 50 | 54 |
| 51 std::string account_id; | 55 std::string account_id; |
| 52 std::string client_id; | 56 std::string client_id; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 net::URLRequestContextGetter* getter, | 132 net::URLRequestContextGetter* getter, |
| 129 OAuth2AccessTokenConsumer* consumer) OVERRIDE; | 133 OAuth2AccessTokenConsumer* consumer) OVERRIDE; |
| 130 | 134 |
| 131 virtual void InvalidateOAuth2Token(const std::string& account_id, | 135 virtual void InvalidateOAuth2Token(const std::string& account_id, |
| 132 const std::string& client_id, | 136 const std::string& client_id, |
| 133 const ScopeSet& scopes, | 137 const ScopeSet& scopes, |
| 134 const std::string& access_token) OVERRIDE; | 138 const std::string& access_token) OVERRIDE; |
| 135 | 139 |
| 136 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; | 140 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; |
| 137 | 141 |
| 142 #if defined(OS_IOS) | |
| 143 virtual void AddOrUpdateAccount(const std::string& account_id) OVERRIDE; | |
| 144 virtual void RemoveAccount(const std::string& account_id) OVERRIDE; | |
| 145 #endif | |
|
Roger Tawa OOO till Jul 10th
2014/08/20 15:43:57
Don't you need to define these functions in the cc
| |
| 146 | |
| 138 private: | 147 private: |
| 139 // Helper function to complete pending requests - if |all_scopes| is true, | 148 // Helper function to complete pending requests - if |all_scopes| is true, |
| 140 // then all pending requests are completed, otherwise, only those requests | 149 // then all pending requests are completed, otherwise, only those requests |
| 141 // matching |scopes| are completed. If |account_id| is empty, then pending | 150 // matching |scopes| are completed. If |account_id| is empty, then pending |
| 142 // requests for all accounts are completed, otherwise only requests for the | 151 // requests for all accounts are completed, otherwise only requests for the |
| 143 // given account. | 152 // given account. |
| 144 void CompleteRequests(const std::string& account_id, | 153 void CompleteRequests(const std::string& account_id, |
| 145 bool all_scopes, | 154 bool all_scopes, |
| 146 const ScopeSet& scopes, | 155 const ScopeSet& scopes, |
| 147 const GoogleServiceAuthError& error, | 156 const GoogleServiceAuthError& error, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 159 // |FetchOAuth2Token| on the current run loop. There is no need to call | 168 // |FetchOAuth2Token| on the current run loop. There is no need to call |
| 160 // |IssueTokenForScope| in this case. | 169 // |IssueTokenForScope| in this case. |
| 161 bool auto_post_fetch_response_on_message_loop_; | 170 bool auto_post_fetch_response_on_message_loop_; |
| 162 | 171 |
| 163 base::WeakPtrFactory<FakeProfileOAuth2TokenService> weak_ptr_factory_; | 172 base::WeakPtrFactory<FakeProfileOAuth2TokenService> weak_ptr_factory_; |
| 164 | 173 |
| 165 DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenService); | 174 DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenService); |
| 166 }; | 175 }; |
| 167 | 176 |
| 168 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 177 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
| OLD | NEW |