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