OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 GOOGLE_APIS_DRIVE_TEST_UTIL_H_ | 5 #ifndef GOOGLE_APIS_DRIVE_TEST_UTIL_H_ |
6 #define GOOGLE_APIS_DRIVE_TEST_UTIL_H_ | 6 #define GOOGLE_APIS_DRIVE_TEST_UTIL_H_ |
7 | 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
8 #include <string> | 11 #include <string> |
9 #include <utility> | 12 #include <utility> |
10 #include <vector> | 13 #include <vector> |
11 | 14 |
12 #include "base/bind.h" | 15 #include "base/bind.h" |
13 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
16 #include "base/template_util.h" | 20 #include "base/template_util.h" |
17 #include "google_apis/drive/base_requests.h" | 21 #include "google_apis/drive/base_requests.h" |
18 #include "google_apis/drive/drive_api_error_codes.h" | 22 #include "google_apis/drive/drive_api_error_codes.h" |
19 #include "google_apis/drive/task_util.h" | 23 #include "google_apis/drive/task_util.h" |
20 | 24 |
21 class GURL; | 25 class GURL; |
22 | 26 |
23 namespace base { | 27 namespace base { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // |base_url| must be set to the server's base url. | 94 // |base_url| must be set to the server's base url. |
91 scoped_ptr<net::test_server::HttpResponse> HandleDownloadFileRequest( | 95 scoped_ptr<net::test_server::HttpResponse> HandleDownloadFileRequest( |
92 const GURL& base_url, | 96 const GURL& base_url, |
93 net::test_server::HttpRequest* out_request, | 97 net::test_server::HttpRequest* out_request, |
94 const net::test_server::HttpRequest& request); | 98 const net::test_server::HttpRequest& request); |
95 | 99 |
96 // Parses a value of Content-Range header, which looks like | 100 // Parses a value of Content-Range header, which looks like |
97 // "bytes <start_position>-<end_position>/<length>". | 101 // "bytes <start_position>-<end_position>/<length>". |
98 // Returns true on success. | 102 // Returns true on success. |
99 bool ParseContentRangeHeader(const std::string& value, | 103 bool ParseContentRangeHeader(const std::string& value, |
100 int64* start_position, | 104 int64_t* start_position, |
101 int64* end_position, | 105 int64_t* end_position, |
102 int64* length); | 106 int64_t* length); |
103 | 107 |
104 // Google API related code and Drive File System code work on asynchronous | 108 // Google API related code and Drive File System code work on asynchronous |
105 // architecture and return the results via callbacks. | 109 // architecture and return the results via callbacks. |
106 // Following code implements a callback to copy such results. | 110 // Following code implements a callback to copy such results. |
107 // Here is how to use: | 111 // Here is how to use: |
108 // | 112 // |
109 // // Prepare result storage. | 113 // // Prepare result storage. |
110 // ResultType1 result1; | 114 // ResultType1 result1; |
111 // ResultType2 result2; | 115 // ResultType2 result2; |
112 // : | 116 // : |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 base::Callback<void(typename internal::CopyResultCallbackHelper<T1>::InType, | 262 base::Callback<void(typename internal::CopyResultCallbackHelper<T1>::InType, |
259 typename internal::CopyResultCallbackHelper<T2>::InType, | 263 typename internal::CopyResultCallbackHelper<T2>::InType, |
260 typename internal::CopyResultCallbackHelper<T3>::InType, | 264 typename internal::CopyResultCallbackHelper<T3>::InType, |
261 typename internal::CopyResultCallbackHelper<T4>::InType)> | 265 typename internal::CopyResultCallbackHelper<T4>::InType)> |
262 CreateCopyResultCallback(T1* out1, T2* out2, T3* out3, T4* out4) { | 266 CreateCopyResultCallback(T1* out1, T2* out2, T3* out3, T4* out4) { |
263 return base::Bind( | 267 return base::Bind( |
264 &internal::CopyResultCallback<T1, T2, T3, T4>, | 268 &internal::CopyResultCallback<T1, T2, T3, T4>, |
265 internal::OutputParams<T1, T2, T3, T4>(out1, out2, out3, out4)); | 269 internal::OutputParams<T1, T2, T3, T4>(out1, out2, out3, out4)); |
266 } | 270 } |
267 | 271 |
268 typedef std::pair<int64, int64> ProgressInfo; | 272 typedef std::pair<int64_t, int64_t> ProgressInfo; |
269 | 273 |
270 // Helper utility for recording the results via ProgressCallback. | 274 // Helper utility for recording the results via ProgressCallback. |
271 void AppendProgressCallbackResult(std::vector<ProgressInfo>* progress_values, | 275 void AppendProgressCallbackResult(std::vector<ProgressInfo>* progress_values, |
272 int64 progress, | 276 int64_t progress, |
273 int64 total); | 277 int64_t total); |
274 | 278 |
275 // Helper utility for recording the content via GetContentCallback. | 279 // Helper utility for recording the content via GetContentCallback. |
276 class TestGetContentCallback { | 280 class TestGetContentCallback { |
277 public: | 281 public: |
278 TestGetContentCallback(); | 282 TestGetContentCallback(); |
279 ~TestGetContentCallback(); | 283 ~TestGetContentCallback(); |
280 | 284 |
281 const GetContentCallback& callback() const { return callback_; } | 285 const GetContentCallback& callback() const { return callback_; } |
282 const ScopedVector<std::string>& data() const { return data_; } | 286 const ScopedVector<std::string>& data() const { return data_; } |
283 ScopedVector<std::string>* mutable_data() { return &data_; } | 287 ScopedVector<std::string>* mutable_data() { return &data_; } |
284 std::string GetConcatenatedData() const; | 288 std::string GetConcatenatedData() const; |
285 | 289 |
286 private: | 290 private: |
287 void OnGetContent(google_apis::DriveApiErrorCode error, | 291 void OnGetContent(google_apis::DriveApiErrorCode error, |
288 scoped_ptr<std::string> data); | 292 scoped_ptr<std::string> data); |
289 | 293 |
290 const GetContentCallback callback_; | 294 const GetContentCallback callback_; |
291 ScopedVector<std::string> data_; | 295 ScopedVector<std::string> data_; |
292 | 296 |
293 DISALLOW_COPY_AND_ASSIGN(TestGetContentCallback); | 297 DISALLOW_COPY_AND_ASSIGN(TestGetContentCallback); |
294 }; | 298 }; |
295 | 299 |
296 } // namespace test_util | 300 } // namespace test_util |
297 } // namespace google_apis | 301 } // namespace google_apis |
298 | 302 |
299 #endif // GOOGLE_APIS_DRIVE_TEST_UTIL_H_ | 303 #endif // GOOGLE_APIS_DRIVE_TEST_UTIL_H_ |
OLD | NEW |