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 "chrome/browser/signin/profile_oauth2_token_service.h" | |
9 | |
10 #include <string> | 8 #include <string> |
11 #include <vector> | 9 #include <vector> |
12 | 10 |
13 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
14 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
15 | 13 |
| 14 #if defined(OS_ANDROID) |
| 15 #include "chrome/browser/signin/android_profile_oauth2_token_service.h" |
| 16 #else |
| 17 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 18 #endif |
| 19 |
16 namespace content { | 20 namespace content { |
17 class BrowserContext; | 21 class BrowserContext; |
18 } | 22 } |
19 | 23 |
20 // Helper class to simplify writing unittests that depend on an instance of | 24 // Helper class to simplify writing unittests that depend on an instance of |
21 // ProfileOAuth2TokenService. | 25 // ProfileOAuth2TokenService. |
22 // | 26 // |
23 // Tests would typically do something like the following: | 27 // Tests would typically do something like the following: |
24 // | 28 // |
25 // FakeProfileOAuth2TokenService service; | 29 // FakeProfileOAuth2TokenService service; |
26 // ... | 30 // ... |
27 // service.IssueRefreshToken("token"); // Issue refresh token/notify observers | 31 // service.IssueRefreshToken("token"); // Issue refresh token/notify observers |
28 // ... | 32 // ... |
29 // // Confirm that there is at least one active request. | 33 // // Confirm that there is at least one active request. |
30 // EXPECT_GT(0U, service.GetPendingRequests().size()); | 34 // EXPECT_GT(0U, service.GetPendingRequests().size()); |
31 // ... | 35 // ... |
32 // // Make any pending token fetches for a given scope succeed. | 36 // // Make any pending token fetches for a given scope succeed. |
33 // ScopeSet scopes; | 37 // ScopeSet scopes; |
34 // scopes.insert(GaiaConstants::kYourServiceScope); | 38 // scopes.insert(GaiaConstants::kYourServiceScope); |
35 // IssueTokenForScope(scopes, "access_token", base::Time()::Max()); | 39 // IssueTokenForScope(scopes, "access_token", base::Time()::Max()); |
36 // ... | 40 // ... |
37 // // ...or make them fail... | 41 // // ...or make them fail... |
38 // IssueErrorForScope(scopes, GoogleServiceAuthError(INVALID_GAIA_CREDENTIALS)); | 42 // IssueErrorForScope(scopes, GoogleServiceAuthError(INVALID_GAIA_CREDENTIALS)); |
39 // | 43 // |
40 class FakeProfileOAuth2TokenService : public ProfileOAuth2TokenService { | 44 class FakeProfileOAuth2TokenService |
| 45 #if defined(OS_ANDROID) |
| 46 : public AndroidProfileOAuth2TokenService { |
| 47 #else |
| 48 : public ProfileOAuth2TokenService { |
| 49 #endif |
41 public: | 50 public: |
42 struct PendingRequest { | 51 struct PendingRequest { |
43 PendingRequest(); | 52 PendingRequest(); |
44 ~PendingRequest(); | 53 ~PendingRequest(); |
45 | 54 |
46 std::string client_id; | 55 std::string client_id; |
47 std::string client_secret; | 56 std::string client_secret; |
48 ScopeSet scopes; | 57 ScopeSet scopes; |
49 base::WeakPtr<RequestImpl> request; | 58 base::WeakPtr<RequestImpl> request; |
50 }; | 59 }; |
(...skipping 16 matching lines...) Expand all Loading... |
67 const base::Time& expiration); | 76 const base::Time& expiration); |
68 | 77 |
69 void IssueErrorForScope(const ScopeSet& scopes, | 78 void IssueErrorForScope(const ScopeSet& scopes, |
70 const GoogleServiceAuthError& error); | 79 const GoogleServiceAuthError& error); |
71 | 80 |
72 void IssueTokenForAllPendingRequests(const std::string& access_token, | 81 void IssueTokenForAllPendingRequests(const std::string& access_token, |
73 const base::Time& expiration); | 82 const base::Time& expiration); |
74 | 83 |
75 void IssueErrorForAllPendingRequests(const GoogleServiceAuthError& error); | 84 void IssueErrorForAllPendingRequests(const GoogleServiceAuthError& error); |
76 | 85 |
77 virtual void Shutdown() OVERRIDE; | |
78 | |
79 // Helper function to be used with | 86 // Helper function to be used with |
80 // BrowserContextKeyedService::SetTestingFactory(). | 87 // BrowserContextKeyedService::SetTestingFactory(). |
81 static BrowserContextKeyedService* Build(content::BrowserContext* profile); | 88 static BrowserContextKeyedService* Build(content::BrowserContext* profile); |
82 | 89 |
83 protected: | 90 protected: |
84 // OAuth2TokenService overrides. | 91 // OAuth2TokenService overrides. |
85 virtual void FetchOAuth2Token(RequestImpl* request, | 92 virtual void FetchOAuth2Token(RequestImpl* request, |
86 net::URLRequestContextGetter* getter, | 93 net::URLRequestContextGetter* getter, |
87 const std::string& client_id, | 94 const std::string& client_id, |
88 const std::string& client_secret, | 95 const std::string& client_secret, |
(...skipping 13 matching lines...) Expand all Loading... |
102 const std::string& access_token, | 109 const std::string& access_token, |
103 const base::Time& expiration); | 110 const base::Time& expiration); |
104 | 111 |
105 std::vector<PendingRequest> pending_requests_; | 112 std::vector<PendingRequest> pending_requests_; |
106 std::string refresh_token_; | 113 std::string refresh_token_; |
107 | 114 |
108 DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenService); | 115 DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenService); |
109 }; | 116 }; |
110 | 117 |
111 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 118 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
OLD | NEW |