Chromium Code Reviews| Index: chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc |
| diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc |
| index b35742925979bb1c2ba4cb527c3315b833986b13..d7fa3767cf0460c9649f7e59029d96b4cb4cf441 100644 |
| --- a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc |
| +++ b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc |
| @@ -159,6 +159,13 @@ class GDataFileSystemTest : public testing::Test { |
| base::PLATFORM_FILE_OK; |
| } |
| + FilePath GetCachePathForFile(GDataFile* file) { |
| + return file_system_->GetCacheFilePath(file->resource_id(), |
| + file->file_md5(), |
| + GDataFileSystem::CACHE_TYPE_TMP, |
| + false); |
| + } |
| + |
| GDataFileBase* FindFile(const FilePath& file_path) { |
| ReadOnlyFindFileDelegate search_delegate; |
| file_system_->FindFileByPathSync(file_path, &search_delegate); |
| @@ -1489,20 +1496,64 @@ TEST_F(GDataFileSystemTest, CreateDirectoryWithService) { |
| // EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); |
| } |
| -TEST_F(GDataFileSystemTest, GetFile) { |
| +TEST_F(GDataFileSystemTest, GetFileFromDownloads) { |
| LoadRootFeedDocument("root_feed.json"); |
| GetFileCallback callback = |
| base::Bind(&CallbackHelper::GetFileCallback, |
| callback_helper_.get()); |
| + FilePath file_in_root(FILE_PATH_LITERAL("gdata/File 1.txt")); |
| + GDataFileBase* file_base = FindFile(file_in_root); |
| + GDataFile* file = file_base->AsGDataFile(); |
| + FilePath downloaded_file = GetCachePathForFile(file); |
| + |
| EXPECT_CALL(*mock_doc_service_, |
| - DownloadFile(_, GURL("https://file_content_url/"), _)); |
| + DownloadFile(file_in_root, |
| + downloaded_file, |
| + GURL("https://file_content_url/"), |
| + _)) |
| + .Times(1); |
| + |
| + file_system_->GetFile(file_in_root, callback); |
| + RunAllPendingForCache(); |
| + |
| + message_loop_.RunAllPending(); // Wait to get our result. |
| + EXPECT_STREQ(downloaded_file.value().c_str(), |
| + callback_helper_->download_path_.value().c_str()); |
| +} |
| + |
| +TEST_F(GDataFileSystemTest, GetFileFromCache) { |
| + LoadRootFeedDocument("root_feed.json"); |
| + |
| + GetFileCallback callback = |
| + base::Bind(&CallbackHelper::GetFileCallback, |
| + callback_helper_.get()); |
| FilePath file_in_root(FILE_PATH_LITERAL("gdata/File 1.txt")); |
| + GDataFileBase* file_base = FindFile(file_in_root); |
| + GDataFile* file = file_base->AsGDataFile(); |
| + FilePath downloaded_file = GetCachePathForFile(file); |
| + |
| + // Store something as cached version of this file. |
| + TestStoreToCache(file->resource_id(), |
| + file->file_md5(), |
| + GetTestFilePath("root_feed.json"), |
| + base::PLATFORM_FILE_OK); |
| + |
| + // Make sure we don't call downloads at all. |
| + EXPECT_CALL(*mock_doc_service_, |
| + DownloadFile(file_in_root, |
| + downloaded_file, |
| + GURL("https://file_content_url/"), |
| + _)) |
| + .Times(0); |
| + |
| file_system_->GetFile(file_in_root, callback); |
| + RunAllPendingForCache(); |
| + |
| message_loop_.RunAllPending(); // Wait to get our result. |
|
kuan
2012/03/20 05:22:27
nit: don't need this because RunAllPendingForCache
zel
2012/03/20 05:27:20
Done.
|
| - EXPECT_STREQ("file_content_url/", |
| + EXPECT_STREQ(downloaded_file.value().c_str(), |
| callback_helper_->download_path_.value().c_str()); |
| } |