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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc

Issue 372713004: Wait for parent directory sync before performing server-side copy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add operation_observer.cc Created 6 years, 5 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
OLDNEW
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 "chrome/browser/chromeos/drive/file_system/copy_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/task_runner_util.h" 8 #include "base/task_runner_util.h"
9 #include "chrome/browser/chromeos/drive/file_cache.h" 9 #include "chrome/browser/chromeos/drive/file_cache.h"
10 #include "chrome/browser/chromeos/drive/file_change.h" 10 #include "chrome/browser/chromeos/drive/file_change.h"
11 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" 11 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
12 #include "chrome/browser/chromeos/drive/file_system_util.h" 12 #include "chrome/browser/chromeos/drive/file_system_util.h"
13 #include "chrome/browser/chromeos/drive/resource_metadata.h"
13 #include "chrome/browser/drive/drive_api_util.h" 14 #include "chrome/browser/drive/drive_api_util.h"
14 #include "chrome/browser/drive/fake_drive_service.h" 15 #include "chrome/browser/drive/fake_drive_service.h"
15 #include "content/public/test/test_utils.h" 16 #include "content/public/test/test_utils.h"
16 #include "google_apis/drive/drive_api_parser.h" 17 #include "google_apis/drive/drive_api_parser.h"
17 #include "google_apis/drive/test_util.h" 18 #include "google_apis/drive/test_util.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 namespace drive { 21 namespace drive {
21 namespace file_system { 22 namespace file_system {
22 23
24 namespace {
25
26 // Used to handle WaitForSyncComplete() calls.
27 bool CopyWaitForSyncCompleteArguments(std::string* out_local_id,
28 FileOperationCallback* out_callback,
29 const std::string& local_id,
30 const FileOperationCallback& callback) {
31 *out_local_id = local_id;
32 *out_callback = callback;
33 return true;
34 }
35
36 } // namespace
37
23 class CopyOperationTest : public OperationTestBase { 38 class CopyOperationTest : public OperationTestBase {
24 protected: 39 protected:
25 virtual void SetUp() OVERRIDE { 40 virtual void SetUp() OVERRIDE {
26 OperationTestBase::SetUp(); 41 OperationTestBase::SetUp();
27 operation_.reset(new CopyOperation( 42 operation_.reset(new CopyOperation(
28 blocking_task_runner(), 43 blocking_task_runner(),
29 observer(), 44 observer(),
30 scheduler(), 45 scheduler(),
31 metadata(), 46 metadata(),
32 cache(), 47 cache(),
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 content::RunAllBlockingPoolTasksUntilIdle(); 434 content::RunAllBlockingPoolTasksUntilIdle();
420 EXPECT_EQ(FILE_ERROR_OK, error); 435 EXPECT_EQ(FILE_ERROR_OK, error);
421 436
422 ResourceEntry entry2; 437 ResourceEntry entry2;
423 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); 438 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry));
424 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &entry2)); 439 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &entry2));
425 EXPECT_EQ(entry.file_info().last_modified(), 440 EXPECT_EQ(entry.file_info().last_modified(),
426 entry2.file_info().last_modified()); 441 entry2.file_info().last_modified());
427 } 442 }
428 443
444 TEST_F(CopyOperationTest, WaitForSyncComplete) {
445 // Create a directory locally.
446 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
447 base::FilePath directory_path(FILE_PATH_LITERAL("drive/root/New Directory"));
448 base::FilePath dest_path = directory_path.AppendASCII("File 1.txt");
449
450 ResourceEntry directory_parent;
451 EXPECT_EQ(FILE_ERROR_OK,
452 GetLocalResourceEntry(directory_path.DirName(), &directory_parent));
453
454 ResourceEntry directory;
455 directory.set_parent_local_id(directory_parent.local_id());
456 directory.set_title(directory_path.BaseName().AsUTF8Unsafe());
457 directory.mutable_file_info()->set_is_directory(true);
458 directory.set_metadata_edit_state(ResourceEntry::DIRTY);
459
460 std::string directory_local_id;
461 FileError error = FILE_ERROR_FAILED;
462 base::PostTaskAndReplyWithResult(
463 blocking_task_runner(),
464 FROM_HERE,
465 base::Bind(&internal::ResourceMetadata::AddEntry,
466 base::Unretained(metadata()), directory, &directory_local_id),
467 google_apis::test_util::CreateCopyResultCallback(&error));
468 content::RunAllBlockingPoolTasksUntilIdle();
469 EXPECT_EQ(FILE_ERROR_OK, error);
470
471 // Try to copy a file to the new directory which lacks resource ID.
472 // This should result in waiting for the directory to sync.
473 std::string waited_local_id;
474 FileOperationCallback pending_callback;
475 observer()->set_wait_for_sync_complete_handler(
476 base::Bind(&CopyWaitForSyncCompleteArguments,
477 &waited_local_id, &pending_callback));
478
479 FileError copy_error = FILE_ERROR_FAILED;
480 operation_->Copy(src_path,
481 dest_path,
482 true, // Preserve last modified.
483 google_apis::test_util::CreateCopyResultCallback(
484 &copy_error));
485 content::RunAllBlockingPoolTasksUntilIdle();
486 EXPECT_EQ(directory_local_id, waited_local_id);
487 ASSERT_FALSE(pending_callback.is_null());
488
489 // Add a new directory to the server and store the resource ID locally.
490 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
491 scoped_ptr<google_apis::FileResource> file_resource;
492 fake_service()->AddNewDirectory(
493 directory_parent.resource_id(),
494 directory.title(),
495 DriveServiceInterface::AddNewDirectoryOptions(),
496 google_apis::test_util::CreateCopyResultCallback(
497 &status, &file_resource));
498 content::RunAllBlockingPoolTasksUntilIdle();
499 EXPECT_EQ(google_apis::HTTP_CREATED, status);
500 ASSERT_TRUE(file_resource);
501
502 directory.set_local_id(directory_local_id);
503 directory.set_resource_id(file_resource->file_id());
504 base::PostTaskAndReplyWithResult(
505 blocking_task_runner(),
506 FROM_HERE,
507 base::Bind(&internal::ResourceMetadata::RefreshEntry,
508 base::Unretained(metadata()), directory),
509 google_apis::test_util::CreateCopyResultCallback(&error));
510 content::RunAllBlockingPoolTasksUntilIdle();
511 EXPECT_EQ(FILE_ERROR_OK, error);
512
513 // Resume the copy operation.
514 pending_callback.Run(FILE_ERROR_OK);
515 content::RunAllBlockingPoolTasksUntilIdle();
516
517 EXPECT_EQ(FILE_ERROR_OK, copy_error);
518 ResourceEntry entry;
519 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &entry));
520 }
521
429 } // namespace file_system 522 } // namespace file_system
430 } // namespace drive 523 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698