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> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
| 11 #include <memory> |
11 #include <string> | 12 #include <string> |
12 #include <utility> | 13 #include <utility> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/bind.h" | 16 #include "base/bind.h" |
16 #include "base/callback.h" | 17 #include "base/callback.h" |
17 #include "base/macros.h" | 18 #include "base/macros.h" |
18 #include "base/memory/scoped_ptr.h" | |
19 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
20 #include "google_apis/drive/base_requests.h" | 20 #include "google_apis/drive/base_requests.h" |
21 #include "google_apis/drive/drive_api_error_codes.h" | 21 #include "google_apis/drive/drive_api_error_codes.h" |
22 #include "google_apis/drive/task_util.h" | 22 #include "google_apis/drive/task_util.h" |
23 | 23 |
24 class GURL; | 24 class GURL; |
25 | 25 |
26 namespace base { | 26 namespace base { |
27 class FilePath; | 27 class FilePath; |
28 class RunLoop; | 28 class RunLoop; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // used. | 74 // used. |
75 // Returns true on success with the created file's |path| and |data|, otherwise | 75 // Returns true on success with the created file's |path| and |data|, otherwise |
76 // false. | 76 // false. |
77 bool CreateFileOfSpecifiedSize(const base::FilePath& temp_dir, | 77 bool CreateFileOfSpecifiedSize(const base::FilePath& temp_dir, |
78 size_t size, | 78 size_t size, |
79 base::FilePath* path, | 79 base::FilePath* path, |
80 std::string* data); | 80 std::string* data); |
81 | 81 |
82 // Loads a test JSON file as a base::Value, from a test file stored under | 82 // Loads a test JSON file as a base::Value, from a test file stored under |
83 // chrome/test/data. | 83 // chrome/test/data. |
84 scoped_ptr<base::Value> LoadJSONFile(const std::string& relative_path); | 84 std::unique_ptr<base::Value> LoadJSONFile(const std::string& relative_path); |
85 | 85 |
86 // Returns a HttpResponse created from the given file path. | 86 // Returns a HttpResponse created from the given file path. |
87 scoped_ptr<net::test_server::BasicHttpResponse> CreateHttpResponseFromFile( | 87 std::unique_ptr<net::test_server::BasicHttpResponse> CreateHttpResponseFromFile( |
88 const base::FilePath& file_path); | 88 const base::FilePath& file_path); |
89 | 89 |
90 // Handles a request for downloading a file. Reads a file from the test | 90 // Handles a request for downloading a file. Reads a file from the test |
91 // directory and returns the content. Also, copies the |request| to the memory | 91 // directory and returns the content. Also, copies the |request| to the memory |
92 // pointed by |out_request|. | 92 // pointed by |out_request|. |
93 // |base_url| must be set to the server's base url. | 93 // |base_url| must be set to the server's base url. |
94 scoped_ptr<net::test_server::HttpResponse> HandleDownloadFileRequest( | 94 std::unique_ptr<net::test_server::HttpResponse> HandleDownloadFileRequest( |
95 const GURL& base_url, | 95 const GURL& base_url, |
96 net::test_server::HttpRequest* out_request, | 96 net::test_server::HttpRequest* out_request, |
97 const net::test_server::HttpRequest& request); | 97 const net::test_server::HttpRequest& request); |
98 | 98 |
99 // Parses a value of Content-Range header, which looks like | 99 // Parses a value of Content-Range header, which looks like |
100 // "bytes <start_position>-<end_position>/<length>". | 100 // "bytes <start_position>-<end_position>/<length>". |
101 // Returns true on success. | 101 // Returns true on success. |
102 bool ParseContentRangeHeader(const std::string& value, | 102 bool ParseContentRangeHeader(const std::string& value, |
103 int64_t* start_position, | 103 int64_t* start_position, |
104 int64_t* end_position, | 104 int64_t* end_position, |
(...skipping 25 matching lines...) Expand all Loading... |
130 // Following helper templates are to support Chrome's move semantics. | 130 // Following helper templates are to support Chrome's move semantics. |
131 // Their goal is defining helper methods which are similar to: | 131 // Their goal is defining helper methods which are similar to: |
132 // void CopyResultCallback1(T1* out1, T1&& in1) | 132 // void CopyResultCallback1(T1* out1, T1&& in1) |
133 // void CopyResultCallback2(T1* out1, T2* out2, T1&& in1, T2&& in2) | 133 // void CopyResultCallback2(T1* out1, T2* out2, T1&& in1, T2&& in2) |
134 // : | 134 // : |
135 // in C++11. | 135 // in C++11. |
136 | 136 |
137 // Declare if the type is movable or not. Currently limited to scoped_ptr only. | 137 // Declare if the type is movable or not. Currently limited to scoped_ptr only. |
138 // We can add more types upon the usage. | 138 // We can add more types upon the usage. |
139 template<typename T> struct IsMovable : std::false_type {}; | 139 template<typename T> struct IsMovable : std::false_type {}; |
140 template<typename T, typename D> | 140 template <typename T, typename D> |
141 struct IsMovable<scoped_ptr<T, D> > : std::true_type {}; | 141 struct IsMovable<std::unique_ptr<T, D>> : std::true_type {}; |
142 | 142 |
143 // InType is const T& if |UseConstRef| is true, otherwise |T|. | 143 // InType is const T& if |UseConstRef| is true, otherwise |T|. |
144 template<bool UseConstRef, typename T> struct InTypeHelper { | 144 template<bool UseConstRef, typename T> struct InTypeHelper { |
145 typedef const T& InType; | 145 typedef const T& InType; |
146 }; | 146 }; |
147 template<typename T> struct InTypeHelper<false, T> { | 147 template<typename T> struct InTypeHelper<false, T> { |
148 typedef T InType; | 148 typedef T InType; |
149 }; | 149 }; |
150 | 150 |
151 // Simulates the std::move function in C++11. We use pointer here for argument, | 151 // Simulates the std::move function in C++11. We use pointer here for argument, |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 TestGetContentCallback(); | 281 TestGetContentCallback(); |
282 ~TestGetContentCallback(); | 282 ~TestGetContentCallback(); |
283 | 283 |
284 const GetContentCallback& callback() const { return callback_; } | 284 const GetContentCallback& callback() const { return callback_; } |
285 const ScopedVector<std::string>& data() const { return data_; } | 285 const ScopedVector<std::string>& data() const { return data_; } |
286 ScopedVector<std::string>* mutable_data() { return &data_; } | 286 ScopedVector<std::string>* mutable_data() { return &data_; } |
287 std::string GetConcatenatedData() const; | 287 std::string GetConcatenatedData() const; |
288 | 288 |
289 private: | 289 private: |
290 void OnGetContent(google_apis::DriveApiErrorCode error, | 290 void OnGetContent(google_apis::DriveApiErrorCode error, |
291 scoped_ptr<std::string> data); | 291 std::unique_ptr<std::string> data); |
292 | 292 |
293 const GetContentCallback callback_; | 293 const GetContentCallback callback_; |
294 ScopedVector<std::string> data_; | 294 ScopedVector<std::string> data_; |
295 | 295 |
296 DISALLOW_COPY_AND_ASSIGN(TestGetContentCallback); | 296 DISALLOW_COPY_AND_ASSIGN(TestGetContentCallback); |
297 }; | 297 }; |
298 | 298 |
299 } // namespace test_util | 299 } // namespace test_util |
300 } // namespace google_apis | 300 } // namespace google_apis |
301 | 301 |
302 #endif // GOOGLE_APIS_DRIVE_TEST_UTIL_H_ | 302 #endif // GOOGLE_APIS_DRIVE_TEST_UTIL_H_ |
OLD | NEW |