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

Side by Side Diff: chrome/browser/drive/drive_uploader_unittest.cc

Issue 671513005: Standardize usage of virtual/override/final in chrome/browser/drive/ (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
« no previous file with comments | « chrome/browser/drive/drive_uploader.h ('k') | chrome/browser/drive/dummy_drive_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/drive/drive_uploader.h" 5 #include "chrome/browser/drive/drive_uploader.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 int64 received_bytes() const { return received_bytes_; } 68 int64 received_bytes() const { return received_bytes_; }
69 void set_received_bytes(int64 received_bytes) { 69 void set_received_bytes(int64 received_bytes) {
70 received_bytes_ = received_bytes; 70 received_bytes_ = received_bytes;
71 } 71 }
72 72
73 int64 resume_upload_call_count() const { return resume_upload_call_count_; } 73 int64 resume_upload_call_count() const { return resume_upload_call_count_; }
74 74
75 private: 75 private:
76 // DriveServiceInterface overrides. 76 // DriveServiceInterface overrides.
77 // Handles a request for obtaining an upload location URL. 77 // Handles a request for obtaining an upload location URL.
78 virtual CancelCallback InitiateUploadNewFile( 78 CancelCallback InitiateUploadNewFile(
79 const std::string& content_type, 79 const std::string& content_type,
80 int64 content_length, 80 int64 content_length,
81 const std::string& parent_resource_id, 81 const std::string& parent_resource_id,
82 const std::string& title, 82 const std::string& title,
83 const InitiateUploadNewFileOptions& options, 83 const InitiateUploadNewFileOptions& options,
84 const InitiateUploadCallback& callback) override { 84 const InitiateUploadCallback& callback) override {
85 EXPECT_EQ(kTestDocumentTitle, title); 85 EXPECT_EQ(kTestDocumentTitle, title);
86 EXPECT_EQ(kTestMimeType, content_type); 86 EXPECT_EQ(kTestMimeType, content_type);
87 EXPECT_EQ(expected_content_length_, content_length); 87 EXPECT_EQ(expected_content_length_, content_length);
88 EXPECT_EQ(kTestInitiateUploadParentResourceId, parent_resource_id); 88 EXPECT_EQ(kTestInitiateUploadParentResourceId, parent_resource_id);
89 89
90 // Calls back the upload URL for subsequent ResumeUpload requests. 90 // Calls back the upload URL for subsequent ResumeUpload requests.
91 // InitiateUpload is an asynchronous function, so don't callback directly. 91 // InitiateUpload is an asynchronous function, so don't callback directly.
92 base::MessageLoop::current()->PostTask(FROM_HERE, 92 base::MessageLoop::current()->PostTask(FROM_HERE,
93 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL))); 93 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL)));
94 return CancelCallback(); 94 return CancelCallback();
95 } 95 }
96 96
97 virtual CancelCallback InitiateUploadExistingFile( 97 CancelCallback InitiateUploadExistingFile(
98 const std::string& content_type, 98 const std::string& content_type,
99 int64 content_length, 99 int64 content_length,
100 const std::string& resource_id, 100 const std::string& resource_id,
101 const InitiateUploadExistingFileOptions& options, 101 const InitiateUploadExistingFileOptions& options,
102 const InitiateUploadCallback& callback) override { 102 const InitiateUploadCallback& callback) override {
103 EXPECT_EQ(kTestMimeType, content_type); 103 EXPECT_EQ(kTestMimeType, content_type);
104 EXPECT_EQ(expected_content_length_, content_length); 104 EXPECT_EQ(expected_content_length_, content_length);
105 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id); 105 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id);
106 106
107 if (!options.etag.empty() && options.etag != kTestETag) { 107 if (!options.etag.empty() && options.etag != kTestETag) {
108 base::MessageLoop::current()->PostTask(FROM_HERE, 108 base::MessageLoop::current()->PostTask(FROM_HERE,
109 base::Bind(callback, HTTP_PRECONDITION, GURL())); 109 base::Bind(callback, HTTP_PRECONDITION, GURL()));
110 return CancelCallback(); 110 return CancelCallback();
111 } 111 }
112 112
113 // Calls back the upload URL for subsequent ResumeUpload requests. 113 // Calls back the upload URL for subsequent ResumeUpload requests.
114 // InitiateUpload is an asynchronous function, so don't callback directly. 114 // InitiateUpload is an asynchronous function, so don't callback directly.
115 base::MessageLoop::current()->PostTask(FROM_HERE, 115 base::MessageLoop::current()->PostTask(FROM_HERE,
116 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL))); 116 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL)));
117 return CancelCallback(); 117 return CancelCallback();
118 } 118 }
119 119
120 // Handles a request for uploading a chunk of bytes. 120 // Handles a request for uploading a chunk of bytes.
121 virtual CancelCallback ResumeUpload( 121 CancelCallback ResumeUpload(
122 const GURL& upload_location, 122 const GURL& upload_location,
123 int64 start_position, 123 int64 start_position,
124 int64 end_position, 124 int64 end_position,
125 int64 content_length, 125 int64 content_length,
126 const std::string& content_type, 126 const std::string& content_type,
127 const base::FilePath& local_file_path, 127 const base::FilePath& local_file_path,
128 const UploadRangeCallback& callback, 128 const UploadRangeCallback& callback,
129 const ProgressCallback& progress_callback) override { 129 const ProgressCallback& progress_callback) override {
130 // The upload range should start from the current first unreceived byte. 130 // The upload range should start from the current first unreceived byte.
131 EXPECT_EQ(received_bytes_, start_position); 131 EXPECT_EQ(received_bytes_, start_position);
(...skipping 23 matching lines...) Expand all
155 int64 chunk_size = end_position - start_position; 155 int64 chunk_size = end_position - start_position;
156 base::MessageLoop::current()->PostTask(FROM_HERE, 156 base::MessageLoop::current()->PostTask(FROM_HERE,
157 base::Bind(progress_callback, chunk_size, chunk_size)); 157 base::Bind(progress_callback, chunk_size, chunk_size));
158 } 158 }
159 159
160 SendUploadRangeResponse(upload_location, callback); 160 SendUploadRangeResponse(upload_location, callback);
161 return CancelCallback(); 161 return CancelCallback();
162 } 162 }
163 163
164 // Handles a request to fetch the current upload status. 164 // Handles a request to fetch the current upload status.
165 virtual CancelCallback GetUploadStatus( 165 CancelCallback GetUploadStatus(const GURL& upload_location,
166 const GURL& upload_location, 166 int64 content_length,
167 int64 content_length, 167 const UploadRangeCallback& callback) override {
168 const UploadRangeCallback& callback) override {
169 EXPECT_EQ(expected_content_length_, content_length); 168 EXPECT_EQ(expected_content_length_, content_length);
170 // The upload URL returned by InitiateUpload() must be used. 169 // The upload URL returned by InitiateUpload() must be used.
171 EXPECT_TRUE(GURL(kTestUploadNewFileURL) == upload_location || 170 EXPECT_TRUE(GURL(kTestUploadNewFileURL) == upload_location ||
172 GURL(kTestUploadExistingFileURL) == upload_location); 171 GURL(kTestUploadExistingFileURL) == upload_location);
173 172
174 SendUploadRangeResponse(upload_location, callback); 173 SendUploadRangeResponse(upload_location, callback);
175 return CancelCallback(); 174 return CancelCallback();
176 } 175 }
177 176
178 // Runs |callback| with the current upload status. 177 // Runs |callback| with the current upload status.
(...skipping 21 matching lines...) Expand all
200 199
201 const base::FilePath expected_upload_file_; 200 const base::FilePath expected_upload_file_;
202 const int64 expected_content_length_; 201 const int64 expected_content_length_;
203 int64 received_bytes_; 202 int64 received_bytes_;
204 int64 resume_upload_call_count_; 203 int64 resume_upload_call_count_;
205 }; 204 };
206 205
207 // Mock DriveService that returns a failure at InitiateUpload(). 206 // Mock DriveService that returns a failure at InitiateUpload().
208 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService { 207 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService {
209 // Returns error. 208 // Returns error.
210 virtual CancelCallback InitiateUploadNewFile( 209 CancelCallback InitiateUploadNewFile(
211 const std::string& content_type, 210 const std::string& content_type,
212 int64 content_length, 211 int64 content_length,
213 const std::string& parent_resource_id, 212 const std::string& parent_resource_id,
214 const std::string& title, 213 const std::string& title,
215 const InitiateUploadNewFileOptions& options, 214 const InitiateUploadNewFileOptions& options,
216 const InitiateUploadCallback& callback) override { 215 const InitiateUploadCallback& callback) override {
217 base::MessageLoop::current()->PostTask(FROM_HERE, 216 base::MessageLoop::current()->PostTask(FROM_HERE,
218 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); 217 base::Bind(callback, GDATA_NO_CONNECTION, GURL()));
219 return CancelCallback(); 218 return CancelCallback();
220 } 219 }
221 220
222 virtual CancelCallback InitiateUploadExistingFile( 221 CancelCallback InitiateUploadExistingFile(
223 const std::string& content_type, 222 const std::string& content_type,
224 int64 content_length, 223 int64 content_length,
225 const std::string& resource_id, 224 const std::string& resource_id,
226 const InitiateUploadExistingFileOptions& options, 225 const InitiateUploadExistingFileOptions& options,
227 const InitiateUploadCallback& callback) override { 226 const InitiateUploadCallback& callback) override {
228 base::MessageLoop::current()->PostTask(FROM_HERE, 227 base::MessageLoop::current()->PostTask(FROM_HERE,
229 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); 228 base::Bind(callback, GDATA_NO_CONNECTION, GURL()));
230 return CancelCallback(); 229 return CancelCallback();
231 } 230 }
232 231
233 // Should not be used. 232 // Should not be used.
234 virtual CancelCallback ResumeUpload( 233 CancelCallback ResumeUpload(
235 const GURL& upload_url, 234 const GURL& upload_url,
236 int64 start_position, 235 int64 start_position,
237 int64 end_position, 236 int64 end_position,
238 int64 content_length, 237 int64 content_length,
239 const std::string& content_type, 238 const std::string& content_type,
240 const base::FilePath& local_file_path, 239 const base::FilePath& local_file_path,
241 const UploadRangeCallback& callback, 240 const UploadRangeCallback& callback,
242 const ProgressCallback& progress_callback) override { 241 const ProgressCallback& progress_callback) override {
243 NOTREACHED(); 242 NOTREACHED();
244 return CancelCallback(); 243 return CancelCallback();
245 } 244 }
246 }; 245 };
247 246
248 // Mock DriveService that returns a failure at ResumeUpload(). 247 // Mock DriveService that returns a failure at ResumeUpload().
249 class MockDriveServiceNoConnectionAtResume : public DummyDriveService { 248 class MockDriveServiceNoConnectionAtResume : public DummyDriveService {
250 // Succeeds and returns an upload location URL. 249 // Succeeds and returns an upload location URL.
251 virtual CancelCallback InitiateUploadNewFile( 250 CancelCallback InitiateUploadNewFile(
252 const std::string& content_type, 251 const std::string& content_type,
253 int64 content_length, 252 int64 content_length,
254 const std::string& parent_resource_id, 253 const std::string& parent_resource_id,
255 const std::string& title, 254 const std::string& title,
256 const InitiateUploadNewFileOptions& options, 255 const InitiateUploadNewFileOptions& options,
257 const InitiateUploadCallback& callback) override { 256 const InitiateUploadCallback& callback) override {
258 base::MessageLoop::current()->PostTask(FROM_HERE, 257 base::MessageLoop::current()->PostTask(FROM_HERE,
259 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL))); 258 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL)));
260 return CancelCallback(); 259 return CancelCallback();
261 } 260 }
262 261
263 virtual CancelCallback InitiateUploadExistingFile( 262 CancelCallback InitiateUploadExistingFile(
264 const std::string& content_type, 263 const std::string& content_type,
265 int64 content_length, 264 int64 content_length,
266 const std::string& resource_id, 265 const std::string& resource_id,
267 const InitiateUploadExistingFileOptions& options, 266 const InitiateUploadExistingFileOptions& options,
268 const InitiateUploadCallback& callback) override { 267 const InitiateUploadCallback& callback) override {
269 base::MessageLoop::current()->PostTask(FROM_HERE, 268 base::MessageLoop::current()->PostTask(FROM_HERE,
270 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL))); 269 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL)));
271 return CancelCallback(); 270 return CancelCallback();
272 } 271 }
273 272
274 // Returns error. 273 // Returns error.
275 virtual CancelCallback ResumeUpload( 274 CancelCallback ResumeUpload(
276 const GURL& upload_url, 275 const GURL& upload_url,
277 int64 start_position, 276 int64 start_position,
278 int64 end_position, 277 int64 end_position,
279 int64 content_length, 278 int64 content_length,
280 const std::string& content_type, 279 const std::string& content_type,
281 const base::FilePath& local_file_path, 280 const base::FilePath& local_file_path,
282 const UploadRangeCallback& callback, 281 const UploadRangeCallback& callback,
283 const ProgressCallback& progress_callback) override { 282 const ProgressCallback& progress_callback) override {
284 base::MessageLoop::current()->PostTask(FROM_HERE, 283 base::MessageLoop::current()->PostTask(FROM_HERE,
285 base::Bind(callback, 284 base::Bind(callback,
286 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1), 285 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1),
287 base::Passed(scoped_ptr<FileResource>()))); 286 base::Passed(scoped_ptr<FileResource>())));
288 return CancelCallback(); 287 return CancelCallback();
289 } 288 }
290 }; 289 };
291 290
292 // Mock DriveService that returns a failure at GetUploadStatus(). 291 // Mock DriveService that returns a failure at GetUploadStatus().
293 class MockDriveServiceNoConnectionAtGetUploadStatus : public DummyDriveService { 292 class MockDriveServiceNoConnectionAtGetUploadStatus : public DummyDriveService {
294 // Returns error. 293 // Returns error.
295 virtual CancelCallback GetUploadStatus( 294 CancelCallback GetUploadStatus(const GURL& upload_url,
296 const GURL& upload_url, 295 int64 content_length,
297 int64 content_length, 296 const UploadRangeCallback& callback) override {
298 const UploadRangeCallback& callback) override {
299 base::MessageLoop::current()->PostTask(FROM_HERE, 297 base::MessageLoop::current()->PostTask(FROM_HERE,
300 base::Bind(callback, 298 base::Bind(callback,
301 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1), 299 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1),
302 base::Passed(scoped_ptr<FileResource>()))); 300 base::Passed(scoped_ptr<FileResource>())));
303 return CancelCallback(); 301 return CancelCallback();
304 } 302 }
305 }; 303 };
306 304
307 class DriveUploaderTest : public testing::Test { 305 class DriveUploaderTest : public testing::Test {
308 public: 306 public:
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 EXPECT_EQ(HTTP_SUCCESS, error); 577 EXPECT_EQ(HTTP_SUCCESS, error);
580 EXPECT_TRUE(upload_location.is_empty()); 578 EXPECT_TRUE(upload_location.is_empty());
581 ASSERT_TRUE(entry); 579 ASSERT_TRUE(entry);
582 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum()); 580 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum());
583 ASSERT_EQ(1U, upload_progress_values.size()); 581 ASSERT_EQ(1U, upload_progress_values.size());
584 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024), 582 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024),
585 upload_progress_values[0]); 583 upload_progress_values[0]);
586 } 584 }
587 585
588 } // namespace drive 586 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/drive/drive_uploader.h ('k') | chrome/browser/drive/dummy_drive_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698