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 "google_apis/drive/request_sender.h" | 5 #include "google_apis/drive/request_sender.h" |
6 | 6 |
7 #include "base/sequenced_task_runner.h" | 7 #include "base/sequenced_task_runner.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "google_apis/drive/base_requests.h" | 9 #include "google_apis/drive/base_requests.h" |
10 #include "google_apis/drive/dummy_auth_service.h" | 10 #include "google_apis/drive/dummy_auth_service.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 AUTH_FAILURE, | 25 AUTH_FAILURE, |
26 }; | 26 }; |
27 | 27 |
28 // AuthService for testing purpose. It accepts kTestRefreshToken and returns | 28 // AuthService for testing purpose. It accepts kTestRefreshToken and returns |
29 // kTestAccessToken + {"1", "2", "3", ...}. | 29 // kTestAccessToken + {"1", "2", "3", ...}. |
30 class TestAuthService : public DummyAuthService { | 30 class TestAuthService : public DummyAuthService { |
31 public: | 31 public: |
32 TestAuthService() : auth_try_count_(0) {} | 32 TestAuthService() : auth_try_count_(0) {} |
33 | 33 |
34 virtual void StartAuthentication( | 34 virtual void StartAuthentication( |
35 const AuthStatusCallback& callback) OVERRIDE { | 35 const AuthStatusCallback& callback) override { |
36 // RequestSender should clear the rejected access token before starting | 36 // RequestSender should clear the rejected access token before starting |
37 // to request another one. | 37 // to request another one. |
38 EXPECT_FALSE(HasAccessToken()); | 38 EXPECT_FALSE(HasAccessToken()); |
39 | 39 |
40 ++auth_try_count_; | 40 ++auth_try_count_; |
41 | 41 |
42 if (refresh_token() == kTestRefreshToken) { | 42 if (refresh_token() == kTestRefreshToken) { |
43 const std::string token = | 43 const std::string token = |
44 kTestAccessToken + base::IntToString(auth_try_count_); | 44 kTestAccessToken + base::IntToString(auth_try_count_); |
45 set_access_token(token); | 45 set_access_token(token); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 const std::string& passed_access_token() const { | 90 const std::string& passed_access_token() const { |
91 return passed_access_token_; | 91 return passed_access_token_; |
92 } | 92 } |
93 | 93 |
94 const ReAuthenticateCallback& passed_reauth_callback() const { | 94 const ReAuthenticateCallback& passed_reauth_callback() const { |
95 return passed_reauth_callback_; | 95 return passed_reauth_callback_; |
96 } | 96 } |
97 | 97 |
98 virtual void Start(const std::string& access_token, | 98 virtual void Start(const std::string& access_token, |
99 const std::string& custom_user_agent, | 99 const std::string& custom_user_agent, |
100 const ReAuthenticateCallback& callback) OVERRIDE { | 100 const ReAuthenticateCallback& callback) override { |
101 *start_called_ = true; | 101 *start_called_ = true; |
102 passed_access_token_ = access_token; | 102 passed_access_token_ = access_token; |
103 passed_reauth_callback_ = callback; | 103 passed_reauth_callback_ = callback; |
104 | 104 |
105 // This request class itself does not return any response at this point. | 105 // This request class itself does not return any response at this point. |
106 // Each test case should respond properly by using the above methods. | 106 // Each test case should respond properly by using the above methods. |
107 } | 107 } |
108 | 108 |
109 virtual void Cancel() OVERRIDE { | 109 virtual void Cancel() override { |
110 EXPECT_TRUE(*start_called_); | 110 EXPECT_TRUE(*start_called_); |
111 *finish_reason_ = CANCEL; | 111 *finish_reason_ = CANCEL; |
112 sender_->RequestFinished(this); | 112 sender_->RequestFinished(this); |
113 } | 113 } |
114 | 114 |
115 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE { | 115 virtual void OnAuthFailed(GDataErrorCode code) override { |
116 *finish_reason_ = AUTH_FAILURE; | 116 *finish_reason_ = AUTH_FAILURE; |
117 sender_->RequestFinished(this); | 117 sender_->RequestFinished(this); |
118 } | 118 } |
119 | 119 |
120 virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() OVERRIDE { | 120 virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() override { |
121 return weak_ptr_factory_.GetWeakPtr(); | 121 return weak_ptr_factory_.GetWeakPtr(); |
122 } | 122 } |
123 | 123 |
124 private: | 124 private: |
125 RequestSender* sender_; | 125 RequestSender* sender_; |
126 bool* start_called_; | 126 bool* start_called_; |
127 FinishReason* finish_reason_; | 127 FinishReason* finish_reason_; |
128 std::string passed_access_token_; | 128 std::string passed_access_token_; |
129 ReAuthenticateCallback passed_reauth_callback_; | 129 ReAuthenticateCallback passed_reauth_callback_; |
130 base::WeakPtrFactory<TestRequest> weak_ptr_factory_; | 130 base::WeakPtrFactory<TestRequest> weak_ptr_factory_; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // by the RequestSender. So with this TestRequest, RequestSender retries | 242 // by the RequestSender. So with this TestRequest, RequestSender retries |
243 // infinitely. Let it succeed/ | 243 // infinitely. Let it succeed/ |
244 EXPECT_EQ(kTestAccessToken + std::string("3"), | 244 EXPECT_EQ(kTestAccessToken + std::string("3"), |
245 request->passed_access_token()); | 245 request->passed_access_token()); |
246 request->FinishRequestWithSuccess(); | 246 request->FinishRequestWithSuccess(); |
247 EXPECT_EQ(SUCCESS, finish_reason); | 247 EXPECT_EQ(SUCCESS, finish_reason); |
248 EXPECT_FALSE(weak_ptr); | 248 EXPECT_FALSE(weak_ptr); |
249 } | 249 } |
250 | 250 |
251 } // namespace google_apis | 251 } // namespace google_apis |
OLD | NEW |