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

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

Issue 21790002: drive: Discard upload location when there is no uploaded contents (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/drive/drive_uploader.cc ('k') | no next file » | 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 const UploadRangeCallback& callback, 279 const UploadRangeCallback& callback,
280 const ProgressCallback& progress_callback) OVERRIDE { 280 const ProgressCallback& progress_callback) OVERRIDE {
281 base::MessageLoop::current()->PostTask(FROM_HERE, 281 base::MessageLoop::current()->PostTask(FROM_HERE,
282 base::Bind(callback, 282 base::Bind(callback,
283 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1), 283 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1),
284 base::Passed(scoped_ptr<ResourceEntry>()))); 284 base::Passed(scoped_ptr<ResourceEntry>())));
285 return CancelCallback(); 285 return CancelCallback();
286 } 286 }
287 }; 287 };
288 288
289 // Mock DriveService that returns a failure at GetUploadStatus().
290 class MockDriveServiceNoConnectionAtGetUploadStatus : public DummyDriveService {
291 // Returns error.
292 virtual CancelCallback GetUploadStatus(
293 const GURL& upload_url,
294 int64 content_length,
295 const UploadRangeCallback& callback) OVERRIDE {
296 base::MessageLoop::current()->PostTask(FROM_HERE,
297 base::Bind(callback,
298 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1),
299 base::Passed(scoped_ptr<ResourceEntry>())));
300 return CancelCallback();
301 }
302 };
303
289 class DriveUploaderTest : public testing::Test { 304 class DriveUploaderTest : public testing::Test {
290 public: 305 public:
291 virtual void SetUp() OVERRIDE { 306 virtual void SetUp() OVERRIDE {
292 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 307 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
293 } 308 }
294 309
295 protected: 310 protected:
296 content::TestBrowserThreadBundle thread_bundle_; 311 content::TestBrowserThreadBundle thread_bundle_;
297 base::ScopedTempDir temp_dir_; 312 base::ScopedTempDir temp_dir_;
298 }; 313 };
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 std::string(), // etag 485 std::string(), // etag
471 test_util::CreateCopyResultCallback( 486 test_util::CreateCopyResultCallback(
472 &error, &upload_location, &resource_entry), 487 &error, &upload_location, &resource_entry),
473 google_apis::ProgressCallback()); 488 google_apis::ProgressCallback());
474 base::RunLoop().RunUntilIdle(); 489 base::RunLoop().RunUntilIdle();
475 490
476 EXPECT_EQ(GDATA_NO_CONNECTION, error); 491 EXPECT_EQ(GDATA_NO_CONNECTION, error);
477 EXPECT_EQ(GURL(kTestUploadExistingFileURL), upload_location); 492 EXPECT_EQ(GURL(kTestUploadExistingFileURL), upload_location);
478 } 493 }
479 494
495 TEST_F(DriveUploaderTest, GetUploadStatusFail) {
496 base::FilePath local_path;
497 std::string data;
498 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
499 temp_dir_.path(), 512 * 1024, &local_path, &data));
500
501 GDataErrorCode error = HTTP_SUCCESS;
502 GURL upload_location;
503 scoped_ptr<ResourceEntry> resource_entry;
504
505 MockDriveServiceNoConnectionAtGetUploadStatus mock_service;
506 DriveUploader uploader(&mock_service,
507 base::MessageLoopProxy::current().get());
508 uploader.ResumeUploadFile(GURL(kTestUploadExistingFileURL),
509 local_path,
510 kTestMimeType,
511 test_util::CreateCopyResultCallback(
512 &error, &upload_location, &resource_entry),
513 google_apis::ProgressCallback());
514 base::RunLoop().RunUntilIdle();
515
516 EXPECT_EQ(GDATA_NO_CONNECTION, error);
517 EXPECT_TRUE(upload_location.is_empty());
518 }
519
480 TEST_F(DriveUploaderTest, NonExistingSourceFile) { 520 TEST_F(DriveUploaderTest, NonExistingSourceFile) {
481 GDataErrorCode error = GDATA_OTHER_ERROR; 521 GDataErrorCode error = GDATA_OTHER_ERROR;
482 GURL upload_location; 522 GURL upload_location;
483 scoped_ptr<ResourceEntry> resource_entry; 523 scoped_ptr<ResourceEntry> resource_entry;
484 524
485 DriveUploader uploader(NULL, // NULL, the service won't be used. 525 DriveUploader uploader(NULL, // NULL, the service won't be used.
486 base::MessageLoopProxy::current().get()); 526 base::MessageLoopProxy::current().get());
487 uploader.UploadExistingFile( 527 uploader.UploadExistingFile(
488 kTestInitiateUploadResourceId, 528 kTestInitiateUploadResourceId,
489 temp_dir_.path().AppendASCII("_this_path_should_not_exist_"), 529 temp_dir_.path().AppendASCII("_this_path_should_not_exist_"),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 EXPECT_EQ(HTTP_SUCCESS, error); 572 EXPECT_EQ(HTTP_SUCCESS, error);
533 EXPECT_TRUE(upload_location.is_empty()); 573 EXPECT_TRUE(upload_location.is_empty());
534 ASSERT_TRUE(resource_entry); 574 ASSERT_TRUE(resource_entry);
535 EXPECT_EQ(kTestDummyId, resource_entry->id()); 575 EXPECT_EQ(kTestDummyId, resource_entry->id());
536 ASSERT_EQ(1U, upload_progress_values.size()); 576 ASSERT_EQ(1U, upload_progress_values.size());
537 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024), 577 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024),
538 upload_progress_values[0]); 578 upload_progress_values[0]);
539 } 579 }
540 580
541 } // namespace drive 581 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/drive/drive_uploader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698