Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(960)

Side by Side Diff: google_apis/gaia/oauth2_token_service_request_unittest.cc

Issue 649283003: Standardize usage of virtual/override/final in google_apis/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 ~TestingOAuth2TokenServiceConsumer() override;
26 26
27 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, 27 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 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 18 matching lines...) Expand all
60 last_error_ = error; 60 last_error_ = error;
61 ++num_get_token_failure_; 61 ++num_get_token_failure_;
62 } 62 }
63 63
64 // A mock implementation of an OAuth2TokenService. 64 // A mock implementation of an OAuth2TokenService.
65 // 65 //
66 // Use SetResponse to vary the response to token requests. 66 // Use SetResponse to vary the response to token requests.
67 class MockOAuth2TokenService : public FakeOAuth2TokenService { 67 class MockOAuth2TokenService : public FakeOAuth2TokenService {
68 public: 68 public:
69 MockOAuth2TokenService(); 69 MockOAuth2TokenService();
70 virtual ~MockOAuth2TokenService(); 70 ~MockOAuth2TokenService() override;
71 71
72 void SetResponse(const GoogleServiceAuthError& error, 72 void SetResponse(const GoogleServiceAuthError& error,
73 const std::string& access_token, 73 const std::string& access_token,
74 const base::Time& expiration); 74 const base::Time& expiration);
75 75
76 int num_invalidate_token() const { return num_invalidate_token_; } 76 int num_invalidate_token() const { return num_invalidate_token_; }
77 77
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 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 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 scoped_refptr<base::SingleThreadTaskRunner> GetTokenServiceTaskRunner()
158 GetTokenServiceTaskRunner() override; 158 override;
159 virtual OAuth2TokenService* GetTokenService() override; 159 OAuth2TokenService* GetTokenService() override;
160 160
161 private: 161 private:
162 virtual ~Provider(); 162 ~Provider() override;
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_;
170 scoped_ptr<MockOAuth2TokenService> oauth2_service_; 170 scoped_ptr<MockOAuth2TokenService> oauth2_service_;
171 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> provider_; 171 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> provider_;
172 TestingOAuth2TokenServiceConsumer consumer_; 172 TestingOAuth2TokenServiceConsumer consumer_;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « google_apis/gaia/oauth2_token_service_request.cc ('k') | google_apis/gaia/oauth2_token_service_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698