| Index: chrome/browser/chromeos/drive/file_system_unittest.cc
|
| diff --git a/chrome/browser/chromeos/drive/file_system_unittest.cc b/chrome/browser/chromeos/drive/file_system_unittest.cc
|
| index 000a5f3a2db44b642b95b3da905cf52fce47a1ee..943819a9f4a5d681f6ddda8c277330dbc32c2968 100644
|
| --- a/chrome/browser/chromeos/drive/file_system_unittest.cc
|
| +++ b/chrome/browser/chromeos/drive/file_system_unittest.cc
|
| @@ -217,13 +217,6 @@ class FileSystemTest : public testing::Test {
|
| return result;
|
| }
|
|
|
| - // Returns true if the cache entry exists for the given resource ID and MD5.
|
| - bool CacheEntryExists(const std::string& resource_id,
|
| - const std::string& md5) {
|
| - FileCacheEntry cache_entry;
|
| - return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
|
| - }
|
| -
|
| // Flag for specifying the timestamp of the test filesystem cache.
|
| enum SetUpTestFileSystemParam {
|
| USE_OLD_TIMESTAMP,
|
| @@ -348,25 +341,6 @@ class FileSystemTest : public testing::Test {
|
| return true;
|
| }
|
|
|
| - // Verifies that |file_path| is a valid JSON file for the hosted document
|
| - // associated with |entry| (i.e. |url| and |resource_id| match).
|
| - void VerifyHostedDocumentJSONFile(const ResourceEntry& entry,
|
| - const base::FilePath& file_path) {
|
| - std::string error;
|
| - JSONFileValueSerializer serializer(file_path);
|
| - scoped_ptr<Value> value(serializer.Deserialize(NULL, &error));
|
| - ASSERT_TRUE(value) << "Parse error " << file_path.value() << ": " << error;
|
| - DictionaryValue* dict_value = NULL;
|
| - ASSERT_TRUE(value->GetAsDictionary(&dict_value));
|
| -
|
| - std::string alternate_url, resource_id;
|
| - EXPECT_TRUE(dict_value->GetString("url", &alternate_url));
|
| - EXPECT_TRUE(dict_value->GetString("resource_id", &resource_id));
|
| -
|
| - EXPECT_EQ(entry.file_specific_info().alternate_url(), alternate_url);
|
| - EXPECT_EQ(entry.resource_id(), resource_id);
|
| - }
|
| -
|
| base::MessageLoopForUI message_loop_;
|
| content::TestBrowserThread ui_thread_;
|
| scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
|
| @@ -1028,7 +1002,10 @@ TEST_F(FileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) {
|
| scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(
|
| remote_src_file_path);
|
| ASSERT_TRUE(entry);
|
| - VerifyHostedDocumentJSONFile(*entry, local_dest_file_path);
|
| + EXPECT_EQ(GURL(entry->file_specific_info().alternate_url()),
|
| + util::ReadUrlFromGDocFile(local_dest_file_path));
|
| + EXPECT_EQ(entry->resource_id(),
|
| + util::ReadResourceIdFromGDocFile(local_dest_file_path));
|
| }
|
|
|
| TEST_F(FileSystemTest, CopyNotExistingFile) {
|
| @@ -1165,345 +1142,6 @@ TEST_F(FileSystemTest, PinAndUnpin) {
|
| EXPECT_EQ(FILE_ERROR_OK, error);
|
| }
|
|
|
| -TEST_F(FileSystemTest, GetFileByPath_FromGData_EnoughSpace) {
|
| - ASSERT_TRUE(LoadRootFeedDocument());
|
| -
|
| - // The transfered file is cached and the change of "offline available"
|
| - // attribute is notified.
|
| - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
|
| - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
|
| -
|
| - base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
|
| - scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
|
| - const int64 file_size = entry->file_info().size();
|
| -
|
| - // Pretend we have enough space.
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(
|
| - file_size + internal::kMinFreeSpace);
|
| -
|
| - FileError error = FILE_ERROR_FAILED;
|
| - base::FilePath file_path;
|
| - entry.reset();
|
| - file_system_->GetFileByPath(file_in_root,
|
| - google_apis::test_util::CreateCopyResultCallback(
|
| - &error, &file_path, &entry));
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| -
|
| - EXPECT_EQ(FILE_ERROR_OK, error);
|
| - ASSERT_TRUE(entry);
|
| - EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
|
| -
|
| - // Verify that readable permission is set.
|
| - int permission = 0;
|
| - EXPECT_TRUE(file_util::GetPosixFilePermissions(file_path, &permission));
|
| - EXPECT_EQ(file_util::FILE_PERMISSION_READ_BY_USER |
|
| - file_util::FILE_PERMISSION_WRITE_BY_USER |
|
| - file_util::FILE_PERMISSION_READ_BY_GROUP |
|
| - file_util::FILE_PERMISSION_READ_BY_OTHERS, permission);
|
| -}
|
| -
|
| -TEST_F(FileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) {
|
| - ASSERT_TRUE(LoadRootFeedDocument());
|
| -
|
| - base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
|
| -
|
| - // Pretend we have no space at all.
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(0);
|
| -
|
| - FileError error = FILE_ERROR_OK;
|
| - base::FilePath file_path;
|
| - scoped_ptr<ResourceEntry> entry;
|
| - file_system_->GetFileByPath(file_in_root,
|
| - google_apis::test_util::CreateCopyResultCallback(
|
| - &error, &file_path, &entry));
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| -
|
| - EXPECT_EQ(FILE_ERROR_NO_SPACE, error);
|
| -}
|
| -
|
| -TEST_F(FileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) {
|
| - ASSERT_TRUE(LoadRootFeedDocument());
|
| -
|
| - // The transfered file is cached and the change of "offline available"
|
| - // attribute is notified.
|
| - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
|
| - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
|
| -
|
| - base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
|
| - scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
|
| - const int64 file_size = entry->file_info().size();
|
| -
|
| - // Pretend we have no space first (checked before downloading a file),
|
| - // but then start reporting we have space. This is to emulate that
|
| - // the disk space was freed up by removing temporary files.
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(
|
| - file_size + internal::kMinFreeSpace);
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(0);
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(
|
| - file_size + internal::kMinFreeSpace);
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(
|
| - file_size + internal::kMinFreeSpace);
|
| -
|
| - // Store something of the file size in the temporary cache directory.
|
| - const std::string content(file_size, 'x');
|
| - base::ScopedTempDir temp_dir;
|
| - ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| - const base::FilePath tmp_file =
|
| - temp_dir.path().AppendASCII("something.txt");
|
| - ASSERT_TRUE(google_apis::test_util::WriteStringToFile(tmp_file, content));
|
| -
|
| - FileError error = FILE_ERROR_FAILED;
|
| - cache_->StoreOnUIThread(
|
| - "<resource_id>", "<md5>", tmp_file,
|
| - internal::FileCache::FILE_OPERATION_COPY,
|
| - google_apis::test_util::CreateCopyResultCallback(&error));
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| - EXPECT_EQ(FILE_ERROR_OK, error);
|
| - ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>"));
|
| -
|
| - base::FilePath file_path;
|
| - entry.reset();
|
| - file_system_->GetFileByPath(file_in_root,
|
| - google_apis::test_util::CreateCopyResultCallback(
|
| - &error, &file_path, &entry));
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| -
|
| - EXPECT_EQ(FILE_ERROR_OK, error);
|
| - ASSERT_TRUE(entry);
|
| - EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
|
| -
|
| - // The cache entry should be removed in order to free up space.
|
| - ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>"));
|
| -}
|
| -
|
| -TEST_F(FileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) {
|
| - ASSERT_TRUE(LoadRootFeedDocument());
|
| -
|
| - base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
|
| - scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
|
| - const int64 file_size = entry->file_info().size();
|
| -
|
| - // Pretend we have enough space first (checked before downloading a file),
|
| - // but then start reporting we have not enough space. This is to emulate that
|
| - // the disk space becomes full after the file is downloaded for some reason
|
| - // (ex. the actual file was larger than the expected size).
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(
|
| - file_size + internal::kMinFreeSpace);
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(
|
| - internal::kMinFreeSpace - 1);
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(
|
| - internal::kMinFreeSpace - 1);
|
| -
|
| - FileError error = FILE_ERROR_OK;
|
| - base::FilePath file_path;
|
| - entry.reset();
|
| - file_system_->GetFileByPath(file_in_root,
|
| - google_apis::test_util::CreateCopyResultCallback(
|
| - &error, &file_path, &entry));
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| -
|
| - EXPECT_EQ(FILE_ERROR_NO_SPACE, error);
|
| -}
|
| -
|
| -TEST_F(FileSystemTest, GetFileByPath_FromCache) {
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
|
| -
|
| - ASSERT_TRUE(LoadRootFeedDocument());
|
| -
|
| - base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
|
| - scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
|
| -
|
| - // Store something as cached version of this file.
|
| - FileError error = FILE_ERROR_OK;
|
| - cache_->StoreOnUIThread(
|
| - entry->resource_id(),
|
| - entry->file_specific_info().file_md5(),
|
| - google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
|
| - internal::FileCache::FILE_OPERATION_COPY,
|
| - google_apis::test_util::CreateCopyResultCallback(&error));
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| - EXPECT_EQ(FILE_ERROR_OK, error);
|
| -
|
| - base::FilePath file_path;
|
| - entry.reset();
|
| - file_system_->GetFileByPath(file_in_root,
|
| - google_apis::test_util::CreateCopyResultCallback(
|
| - &error, &file_path, &entry));
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| -
|
| - EXPECT_EQ(FILE_ERROR_OK, error);
|
| - ASSERT_TRUE(entry);
|
| - EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
|
| -}
|
| -
|
| -TEST_F(FileSystemTest, GetFileByPath_HostedDocument) {
|
| - ASSERT_TRUE(LoadRootFeedDocument());
|
| -
|
| - base::FilePath file_in_root(FILE_PATH_LITERAL(
|
| - "drive/root/Document 1 excludeDir-test.gdoc"));
|
| - scoped_ptr<ResourceEntry> src_entry =
|
| - GetResourceEntryByPathSync(file_in_root);
|
| - ASSERT_TRUE(src_entry);
|
| -
|
| - FileError error = FILE_ERROR_FAILED;
|
| - base::FilePath file_path;
|
| - scoped_ptr<ResourceEntry> entry;
|
| - file_system_->GetFileByPath(file_in_root,
|
| - google_apis::test_util::CreateCopyResultCallback(
|
| - &error, &file_path, &entry));
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| -
|
| - EXPECT_EQ(FILE_ERROR_OK, error);
|
| - ASSERT_TRUE(entry);
|
| - EXPECT_TRUE(entry->file_specific_info().is_hosted_document());
|
| - EXPECT_FALSE(file_path.empty());
|
| -
|
| - ASSERT_TRUE(src_entry);
|
| - VerifyHostedDocumentJSONFile(*src_entry, file_path);
|
| -}
|
| -
|
| -TEST_F(FileSystemTest, GetFileByResourceId) {
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
|
| -
|
| - // The transfered file is cached and the change of "offline available"
|
| - // attribute is notified.
|
| - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
|
| - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
|
| -
|
| - ASSERT_TRUE(LoadRootFeedDocument());
|
| -
|
| - base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
|
| - scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
|
| - std::string resource_id = entry->resource_id();
|
| -
|
| - FileError error = FILE_ERROR_OK;
|
| - base::FilePath file_path;
|
| - entry.reset();
|
| - file_system_->GetFileByResourceId(
|
| - resource_id,
|
| - ClientContext(USER_INITIATED),
|
| - google_apis::test_util::CreateCopyResultCallback(
|
| - &error, &file_path, &entry),
|
| - google_apis::GetContentCallback());
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| -
|
| - EXPECT_EQ(FILE_ERROR_OK, error);
|
| - ASSERT_TRUE(entry);
|
| - EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
|
| -}
|
| -
|
| -TEST_F(FileSystemTest, GetFileContentByPath) {
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
|
| -
|
| - // The transfered file is cached and the change of "offline available"
|
| - // attribute is notified.
|
| - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
|
| - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
|
| -
|
| - ASSERT_TRUE(LoadRootFeedDocument());
|
| -
|
| - base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
|
| -
|
| - {
|
| - FileError initialized_error = FILE_ERROR_FAILED;
|
| - scoped_ptr<ResourceEntry> entry;
|
| - base::FilePath local_path;
|
| - base::Closure cancel_download;
|
| - google_apis::test_util::TestGetContentCallback get_content_callback;
|
| -
|
| - FileError completion_error = FILE_ERROR_FAILED;
|
| -
|
| - file_system_->GetFileContentByPath(
|
| - file_in_root,
|
| - google_apis::test_util::CreateCopyResultCallback(
|
| - &initialized_error, &entry, &local_path, &cancel_download),
|
| - get_content_callback.callback(),
|
| - google_apis::test_util::CreateCopyResultCallback(&completion_error));
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| -
|
| - // For the first time, file is downloaded from the remote server.
|
| - // In this case, |local_path| is empty while |cancel_download| is not.
|
| - EXPECT_EQ(FILE_ERROR_OK, initialized_error);
|
| - ASSERT_TRUE(entry);
|
| - ASSERT_TRUE(local_path.empty());
|
| - EXPECT_TRUE(!cancel_download.is_null());
|
| - // Content is available through the second callback argument.
|
| - EXPECT_EQ(static_cast<size_t>(entry->file_info().size()),
|
| - get_content_callback.GetConcatenatedData().size());
|
| - EXPECT_EQ(FILE_ERROR_OK, completion_error);
|
| - }
|
| -
|
| - {
|
| - FileError initialized_error = FILE_ERROR_FAILED;
|
| - scoped_ptr<ResourceEntry> entry;
|
| - base::FilePath local_path;
|
| - base::Closure cancel_download;
|
| - google_apis::test_util::TestGetContentCallback get_content_callback;
|
| -
|
| - FileError completion_error = FILE_ERROR_FAILED;
|
| -
|
| - file_system_->GetFileContentByPath(
|
| - file_in_root,
|
| - google_apis::test_util::CreateCopyResultCallback(
|
| - &initialized_error, &entry, &local_path, &cancel_download),
|
| - get_content_callback.callback(),
|
| - google_apis::test_util::CreateCopyResultCallback(&completion_error));
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| -
|
| - // Try second download. In this case, the file should be cached, so
|
| - // |local_path| should not be empty while |cancel_download| is empty.
|
| - EXPECT_EQ(FILE_ERROR_OK, initialized_error);
|
| - ASSERT_TRUE(entry);
|
| - ASSERT_TRUE(!local_path.empty());
|
| - EXPECT_TRUE(cancel_download.is_null());
|
| - // The content is available from the cache file.
|
| - EXPECT_TRUE(get_content_callback.data().empty());
|
| - int64 local_file_size = 0;
|
| - file_util::GetFileSize(local_path, &local_file_size);
|
| - EXPECT_EQ(entry->file_info().size(), local_file_size);
|
| - EXPECT_EQ(FILE_ERROR_OK, completion_error);
|
| - }
|
| -}
|
| -
|
| -TEST_F(FileSystemTest, GetFileByResourceId_FromCache) {
|
| - fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
|
| -
|
| - ASSERT_TRUE(LoadRootFeedDocument());
|
| -
|
| - base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
|
| - scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
|
| -
|
| - // Store something as cached version of this file.
|
| - FileError error = FILE_ERROR_FAILED;
|
| - cache_->StoreOnUIThread(
|
| - entry->resource_id(),
|
| - entry->file_specific_info().file_md5(),
|
| - google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
|
| - internal::FileCache::FILE_OPERATION_COPY,
|
| - google_apis::test_util::CreateCopyResultCallback(&error));
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| - EXPECT_EQ(FILE_ERROR_OK, error);
|
| -
|
| - // The file is obtained from the cache.
|
| - // Hence the downloading should work even if the drive service is offline.
|
| - fake_drive_service_->set_offline(true);
|
| -
|
| - std::string resource_id = entry->resource_id();
|
| - base::FilePath file_path;
|
| - entry.reset();
|
| - file_system_->GetFileByResourceId(
|
| - resource_id,
|
| - ClientContext(USER_INITIATED),
|
| - google_apis::test_util::CreateCopyResultCallback(
|
| - &error, &file_path, &entry),
|
| - google_apis::GetContentCallback());
|
| - google_apis::test_util::RunBlockingPoolTask();
|
| -
|
| - EXPECT_EQ(FILE_ERROR_OK, error);
|
| - ASSERT_TRUE(entry);
|
| - EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
|
| -}
|
| -
|
| TEST_F(FileSystemTest, GetAvailableSpace) {
|
| FileError error = FILE_ERROR_OK;
|
| int64 bytes_total;
|
|
|