diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-12 19:25:06 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-12 19:25:06 +0000 |
commit | f8621b0f6d9652721f012fe68595be02f644ac00 (patch) | |
tree | 55190d4c919e3fe9d62f6c91a41810fd5351cad8 | |
parent | f61d80e7d69770c31f89216a626b51583a2fb205 (diff) | |
download | chromium_src-f8621b0f6d9652721f012fe68595be02f644ac00.zip chromium_src-f8621b0f6d9652721f012fe68595be02f644ac00.tar.gz chromium_src-f8621b0f6d9652721f012fe68595be02f644ac00.tar.bz2 |
google_apis: Return "xxx.." instead of the content URL from FakeDriveService
Returning the content URL as the download content was a bad idea. The content
length should match the file size specified in the entry.
BUG=162350
TEST=none; test changes
Review URL: https://chromiumcodereview.appspot.com/11859007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176574 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 52 insertions, 30 deletions
diff --git a/chrome/browser/chromeos/drive/drive_file_system_unittest.cc b/chrome/browser/chromeos/drive/drive_file_system_unittest.cc index e514b4a..31e6b70 100644 --- a/chrome/browser/chromeos/drive/drive_file_system_unittest.cc +++ b/chrome/browser/chromeos/drive/drive_file_system_unittest.cc @@ -1297,14 +1297,16 @@ TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { EXPECT_EQ(DRIVE_FILE_OK, error); + // The content is "x"s of the file size. + const std::string kExpectedContent = "xxxxxxxxxx"; std::string cache_file_data; EXPECT_TRUE(file_util::ReadFileToString(cache_file, &cache_file_data)); - EXPECT_EQ("https://file_content_url/", cache_file_data); + EXPECT_EQ(kExpectedContent, cache_file_data); std::string local_dest_file_data; EXPECT_TRUE(file_util::ReadFileToString(local_dest_file_path, &local_dest_file_data)); - EXPECT_EQ("https://file_content_url/", local_dest_file_data); + EXPECT_EQ(kExpectedContent, local_dest_file_data); } TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { @@ -1909,11 +1911,18 @@ TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) { fake_free_disk_space_getter_->set_fake_free_disk_space( file_size + kMinFreeSpace); - // Store something in the temporary cache directory. + // 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 FilePath tmp_file = + temp_dir.path().AppendASCII("something.txt"); + ASSERT_EQ(file_size, + file_util::WriteFile(tmp_file, content.data(), content.size())); + TestStoreToCache("<resource_id>", "<md5>", - google_apis::test_util::GetTestFilePath( - "gdata/root_feed.json"), + tmp_file, DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, DriveCache::CACHE_TYPE_TMP); @@ -2359,10 +2368,11 @@ TEST_F(DriveFileSystemTest, OpenAndCloseFile) { EXPECT_EQ(DRIVE_FILE_ERROR_IN_USE, callback_helper_->last_error_); // Verify that the file contents match the expected contents. - // The file should contain the content URL of the entry. + // The content is "x"s of the file size. + const std::string kExpectedContent = "xxxxxxxxxx"; std::string cache_file_data; EXPECT_TRUE(file_util::ReadFileToString(opened_file_path, &cache_file_data)); - EXPECT_EQ("https://file_content_url/", cache_file_data); + EXPECT_EQ(kExpectedContent, cache_file_data); // Verify that the cache state was changed as expected. VerifyCacheStateAfterOpenFile(DRIVE_FILE_OK, diff --git a/chrome/browser/google_apis/fake_drive_service.cc b/chrome/browser/google_apis/fake_drive_service.cc index e91b3d8..423b0c8 100644 --- a/chrome/browser/google_apis/fake_drive_service.cc +++ b/chrome/browser/google_apis/fake_drive_service.cc @@ -371,20 +371,31 @@ void FakeDriveService::DownloadFile( return; } - // Write the content URL as the content of the file. - if (static_cast<int>(content_url.spec().size()) != - file_util::WriteFile(local_cache_path, - content_url.spec().data(), - content_url.spec().size())) { - base::MessageLoopProxy::current()->PostTask( - FROM_HERE, - base::Bind(download_action_callback, GDATA_FILE_ERROR, FilePath())); - return; + // Write "x"s of the file size specified in the entry. + std::string file_size_string; + entry->GetString("docs$size.$t", &file_size_string); + int64 file_size = 0; + if (base::StringToInt64(file_size_string, &file_size)) { + std::string content(file_size, 'x'); + DCHECK_EQ(static_cast<size_t>(file_size), content.size()); + + if (static_cast<int>(content.size()) == + file_util::WriteFile(local_cache_path, + content.data(), + content.size())) { + base::MessageLoopProxy::current()->PostTask( + FROM_HERE, + base::Bind(download_action_callback, + HTTP_SUCCESS, + local_cache_path)); + return; + } } + // Failed to write the content. base::MessageLoopProxy::current()->PostTask( FROM_HERE, - base::Bind(download_action_callback, HTTP_SUCCESS, local_cache_path)); + base::Bind(download_action_callback, GDATA_FILE_ERROR, FilePath())); } void FakeDriveService::CopyHostedDocument( diff --git a/chrome/browser/google_apis/fake_drive_service_unittest.cc b/chrome/browser/google_apis/fake_drive_service_unittest.cc index c1744e3..4fb748d7 100644 --- a/chrome/browser/google_apis/fake_drive_service_unittest.cc +++ b/chrome/browser/google_apis/fake_drive_service_unittest.cc @@ -409,7 +409,8 @@ TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) { EXPECT_EQ(output_file_path, kOutputFilePath); std::string content; ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content)); - EXPECT_EQ(kContentUrl.spec(), content); + // The content is "x"s of the file size specified in root_feed.json. + EXPECT_EQ("xxxxxxxxxx", content); } TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) { diff --git a/chrome/test/data/chromeos/gdata/root_feed.json b/chrome/test/data/chromeos/gdata/root_feed.json index 14d5663..d5b21c2 100644 --- a/chrome/test/data/chromeos/gdata/root_feed.json +++ b/chrome/test/data/chromeos/gdata/root_feed.json @@ -211,7 +211,7 @@ "$t": "3b4382ebefec6e743578c76bbd0575ce" }, "docs$size": { - "$t": "892721" + "$t": "10" }, "docs$suggestedFilename": { "$t": "SubDirectory File 1.txt" @@ -233,7 +233,7 @@ } }, "gd$quotaBytesUsed": { - "$t": "892721" + "$t": "10" }, "gd$resourceId": { "$t": "file:subdirectory_file_1_id" @@ -464,7 +464,7 @@ "$t": "3b4382ebefec6e743578c76bbd0575ce" }, "docs$size": { - "$t": "892721" + "$t": "10" }, "docs$suggestedFilename": { "$t": "File 1.txt" @@ -486,7 +486,7 @@ } }, "gd$quotaBytesUsed": { - "$t": "892721" + "$t": "10" }, "gd$resourceId": { "$t": "file:2_file_resource_id" @@ -553,7 +553,7 @@ "$t": "3b4382ebefec6e743578c76bbd0575ce" }, "docs$size": { - "$t": "892721" + "$t": "10" }, "docs$suggestedFilename": { "$t": "Slash / in file 1.txt" @@ -575,7 +575,7 @@ } }, "gd$quotaBytesUsed": { - "$t": "892721" + "$t": "10" }, "gd$resourceId": { "$t": "file:slash_file_resource_id" @@ -642,7 +642,7 @@ "$t": "3b4382ebefec6e743578c76bbd0575ce" }, "docs$size": { - "$t": "892721" + "$t": "10" }, "docs$suggestedFilename": { "$t": "Duplicate Name.txt" @@ -664,7 +664,7 @@ } }, "gd$quotaBytesUsed": { - "$t": "892721" + "$t": "10" }, "gd$resourceId": { "$t": "file:3_file_resource_id" @@ -731,7 +731,7 @@ "$t": "3b4382ebefec6e743578c76bbd0575ce" }, "docs$size": { - "$t": "892721" + "$t": "10" }, "docs$suggestedFilename": { "$t": "Duplicate Name.txt" @@ -753,7 +753,7 @@ } }, "gd$quotaBytesUsed": { - "$t": "892721" + "$t": "10" }, "gd$resourceId": { "$t": "file:4_file_resource_id" @@ -984,7 +984,7 @@ "$t": "3b4382ebefec6e743578c76bbd0575ce" }, "docs$size": { - "$t": "892721" + "$t": "10" }, "docs$suggestedFilename": { "$t": "Slash SubDir File.txt" @@ -1006,7 +1006,7 @@ } }, "gd$quotaBytesUsed": { - "$t": "892721" + "$t": "10" }, "gd$resourceId": { "$t": "file:slash_subdir_file" |