class EntryUpdatePerformerTest : public file_system::OperationTestBase {
protected:
virtual void SetUp() OVERRIDE {
- OperationTestBase::SetUp();
- performer_.reset(new EntryUpdatePerformer(blocking_task_runner(),
- observer(),
- scheduler(),
- metadata(),
- cache()));
+ OperationTestBase::SetUp();
+ performer_.reset(new EntryUpdatePerformer(blocking_task_runner(),
+ observer(),
+ scheduler(),
+ metadata(),
+ cache(),
+ loader_controller()));
}
// Stores |content| to the cache and mark it as dirty.
FROM_HERE,
base::Bind(&FileCache::Store,
base::Unretained(cache()),
- local_id, base::MD5String(content), path,
+ local_id, std::string(), path,
FileCache::FILE_OPERATION_COPY),
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
- if (error != FILE_ERROR_OK)
- return error;
-
- // Add the dirty bit.
- error = FILE_ERROR_FAILED;
- scoped_ptr<base::ScopedClosureRunner> file_closer;
- base::PostTaskAndReplyWithResult(
- blocking_task_runner(),
- FROM_HERE,
- base::Bind(&FileCache::OpenForWrite,
- base::Unretained(cache()),
- local_id,
- &file_closer),
- google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
return error;
}
EXPECT_FALSE(cache_entry.is_dirty());
}
+TEST_F(EntryUpdatePerformerTest, UpdateEntry_UploadNewFile) {
+ // Create a new file locally.
+ const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/New File.txt"));
+
+ ResourceEntry parent;
+ EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath.DirName(), &parent));
+
+ ResourceEntry entry;
+ entry.set_parent_local_id(parent.local_id());
+ entry.set_title(kFilePath.BaseName().AsUTF8Unsafe());
+ entry.mutable_file_specific_info()->set_content_mime_type("text/plain");
+ entry.set_metadata_edit_state(ResourceEntry::DIRTY);
+
+ FileError error = FILE_ERROR_FAILED;
+ std::string local_id;
+ base::PostTaskAndReplyWithResult(
+ blocking_task_runner(),
+ FROM_HERE,
+ base::Bind(&internal::ResourceMetadata::AddEntry,
+ base::Unretained(metadata()),
+ entry,
+ &local_id),
+ google_apis::test_util::CreateCopyResultCallback(&error));
+ test_util::RunBlockingPoolTask();
+ EXPECT_EQ(FILE_ERROR_OK, error);
+
+ // Update. This should result in creating a new file on the server.
+ error = FILE_ERROR_FAILED;
+ performer_->UpdateEntry(
+ local_id,
+ ClientContext(USER_INITIATED),
+ google_apis::test_util::CreateCopyResultCallback(&error));
+ test_util::RunBlockingPoolTask();
+ EXPECT_EQ(FILE_ERROR_OK, error);
+
+ // The entry got a resource ID.
+ EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry));
+ EXPECT_FALSE(entry.resource_id().empty());
+ EXPECT_EQ(ResourceEntry::CLEAN, entry.metadata_edit_state());
+
+ // Make sure that the cache is no longer dirty.
+ bool success = false;
+ FileCacheEntry cache_entry;
+ base::PostTaskAndReplyWithResult(
+ blocking_task_runner(),
+ FROM_HERE,
+ base::Bind(&FileCache::GetCacheEntry,
+ base::Unretained(cache()),
+ local_id,
+ &cache_entry),
+ google_apis::test_util::CreateCopyResultCallback(&success));
+ test_util::RunBlockingPoolTask();
+ EXPECT_TRUE(success);
+ EXPECT_FALSE(cache_entry.is_dirty());
+
+ // Make sure that we really created a file.
+ google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
+ scoped_ptr<google_apis::ResourceEntry> resource_entry;
+ fake_service()->GetResourceEntry(
+ entry.resource_id(),
+ google_apis::test_util::CreateCopyResultCallback(&status,
+ &resource_entry));
+ test_util::RunBlockingPoolTask();
+ EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
+ ASSERT_TRUE(resource_entry);
+ EXPECT_FALSE(resource_entry->is_folder());
+}
+
+TEST_F(EntryUpdatePerformerTest, UpdateEntry_CreateDirectory) {
+ // Create a new directory locally.
+ const base::FilePath kPath(FILE_PATH_LITERAL("drive/root/New Directory"));
+
+ ResourceEntry parent;
+ EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPath.DirName(), &parent));
+
+ ResourceEntry entry;
+ entry.set_parent_local_id(parent.local_id());
+ entry.set_title(kPath.BaseName().AsUTF8Unsafe());
+ entry.mutable_file_info()->set_is_directory(true);
+ entry.set_metadata_edit_state(ResourceEntry::DIRTY);
+
+ FileError error = FILE_ERROR_FAILED;
+ std::string local_id;
+ base::PostTaskAndReplyWithResult(
+ blocking_task_runner(),
+ FROM_HERE,
+ base::Bind(&internal::ResourceMetadata::AddEntry,
+ base::Unretained(metadata()),
+ entry,
+ &local_id),
+ google_apis::test_util::CreateCopyResultCallback(&error));
+ test_util::RunBlockingPoolTask();
+ EXPECT_EQ(FILE_ERROR_OK, error);
+
+ // Update. This should result in creating a new directory on the server.
+ error = FILE_ERROR_FAILED;
+ performer_->UpdateEntry(
+ local_id,
+ ClientContext(USER_INITIATED),
+ google_apis::test_util::CreateCopyResultCallback(&error));
+ test_util::RunBlockingPoolTask();
+ EXPECT_EQ(FILE_ERROR_OK, error);
+
+ // The entry got a resource ID.
+ EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPath, &entry));
+ EXPECT_FALSE(entry.resource_id().empty());
+ EXPECT_EQ(ResourceEntry::CLEAN, entry.metadata_edit_state());
+
+ // Make sure that we really created a directory.
+ google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
+ scoped_ptr<google_apis::ResourceEntry> resource_entry;
+ fake_service()->GetResourceEntry(
+ entry.resource_id(),
+ google_apis::test_util::CreateCopyResultCallback(&status,
+ &resource_entry));
+ test_util::RunBlockingPoolTask();
+ EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
+ ASSERT_TRUE(resource_entry);
+ EXPECT_TRUE(resource_entry->is_folder());
+}
+
} // namespace internal
} // namespace drive