Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 GURL unused; | 152 GURL unused; |
| 153 return file_system_->UpdateDirectoryWithDocumentFeed( | 153 return file_system_->UpdateDirectoryWithDocumentFeed( |
| 154 list, FROM_SERVER) == base::PLATFORM_FILE_OK; | 154 list, FROM_SERVER) == base::PLATFORM_FILE_OK; |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool RemoveFile(const FilePath& file_path) { | 157 bool RemoveFile(const FilePath& file_path) { |
| 158 return file_system_->RemoveFileFromFileSystem(file_path) == | 158 return file_system_->RemoveFileFromFileSystem(file_path) == |
| 159 base::PLATFORM_FILE_OK; | 159 base::PLATFORM_FILE_OK; |
| 160 } | 160 } |
| 161 | 161 |
| 162 FilePath GetCachePathForFile(GDataFile* file) { | |
| 163 return file_system_->GetCacheFilePath(file->resource_id(), | |
| 164 file->file_md5(), | |
| 165 GDataFileSystem::CACHE_TYPE_TMP, | |
| 166 false); | |
| 167 } | |
| 168 | |
| 162 GDataFileBase* FindFile(const FilePath& file_path) { | 169 GDataFileBase* FindFile(const FilePath& file_path) { |
| 163 ReadOnlyFindFileDelegate search_delegate; | 170 ReadOnlyFindFileDelegate search_delegate; |
| 164 file_system_->FindFileByPathSync(file_path, &search_delegate); | 171 file_system_->FindFileByPathSync(file_path, &search_delegate); |
| 165 return search_delegate.file(); | 172 return search_delegate.file(); |
| 166 } | 173 } |
| 167 | 174 |
| 168 void FindAndTestFilePath(const FilePath& file_path) { | 175 void FindAndTestFilePath(const FilePath& file_path) { |
| 169 GDataFileBase* file = FindFile(file_path); | 176 GDataFileBase* file = FindFile(file_path); |
| 170 ASSERT_TRUE(file) << "File can't be found " << file_path.value(); | 177 ASSERT_TRUE(file) << "File can't be found " << file_path.value(); |
| 171 EXPECT_EQ(file->GetFilePath(), file_path); | 178 EXPECT_EQ(file->GetFilePath(), file_path); |
| (...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1482 false, // is_exclusive | 1489 false, // is_exclusive |
| 1483 true, // is_recursive | 1490 true, // is_recursive |
| 1484 base::Bind(&CallbackHelper::FileOperationCallback, | 1491 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1485 callback_helper_.get())); | 1492 callback_helper_.get())); |
| 1486 message_loop_.RunAllPending(); // Wait to get our result. | 1493 message_loop_.RunAllPending(); // Wait to get our result. |
| 1487 // TODO(gspencer): Uncomment this when we get a blob that | 1494 // TODO(gspencer): Uncomment this when we get a blob that |
| 1488 // works that can be returned from the mock. | 1495 // works that can be returned from the mock. |
| 1489 // EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); | 1496 // EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); |
| 1490 } | 1497 } |
| 1491 | 1498 |
| 1492 TEST_F(GDataFileSystemTest, GetFile) { | 1499 TEST_F(GDataFileSystemTest, GetFileFromDownloads) { |
| 1493 LoadRootFeedDocument("root_feed.json"); | 1500 LoadRootFeedDocument("root_feed.json"); |
| 1494 | 1501 |
| 1495 GetFileCallback callback = | 1502 GetFileCallback callback = |
| 1496 base::Bind(&CallbackHelper::GetFileCallback, | 1503 base::Bind(&CallbackHelper::GetFileCallback, |
| 1497 callback_helper_.get()); | 1504 callback_helper_.get()); |
| 1498 | 1505 |
| 1506 FilePath file_in_root(FILE_PATH_LITERAL("gdata/File 1.txt")); | |
| 1507 GDataFileBase* file_base = FindFile(file_in_root); | |
| 1508 GDataFile* file = file_base->AsGDataFile(); | |
| 1509 FilePath downloaded_file = GetCachePathForFile(file); | |
| 1510 | |
| 1499 EXPECT_CALL(*mock_doc_service_, | 1511 EXPECT_CALL(*mock_doc_service_, |
| 1500 DownloadFile(_, GURL("https://file_content_url/"), _)); | 1512 DownloadFile(file_in_root, |
| 1513 downloaded_file, | |
| 1514 GURL("https://file_content_url/"), | |
| 1515 _)) | |
| 1516 .Times(1); | |
| 1501 | 1517 |
| 1502 FilePath file_in_root(FILE_PATH_LITERAL("gdata/File 1.txt")); | |
| 1503 file_system_->GetFile(file_in_root, callback); | 1518 file_system_->GetFile(file_in_root, callback); |
| 1519 RunAllPendingForCache(); | |
| 1520 | |
| 1504 message_loop_.RunAllPending(); // Wait to get our result. | 1521 message_loop_.RunAllPending(); // Wait to get our result. |
| 1505 EXPECT_STREQ("file_content_url/", | 1522 EXPECT_STREQ(downloaded_file.value().c_str(), |
| 1506 callback_helper_->download_path_.value().c_str()); | 1523 callback_helper_->download_path_.value().c_str()); |
| 1507 } | 1524 } |
| 1508 | 1525 |
| 1526 TEST_F(GDataFileSystemTest, GetFileFromCache) { | |
| 1527 LoadRootFeedDocument("root_feed.json"); | |
| 1528 | |
| 1529 GetFileCallback callback = | |
| 1530 base::Bind(&CallbackHelper::GetFileCallback, | |
| 1531 callback_helper_.get()); | |
| 1532 | |
| 1533 FilePath file_in_root(FILE_PATH_LITERAL("gdata/File 1.txt")); | |
| 1534 GDataFileBase* file_base = FindFile(file_in_root); | |
| 1535 GDataFile* file = file_base->AsGDataFile(); | |
| 1536 FilePath downloaded_file = GetCachePathForFile(file); | |
| 1537 | |
| 1538 // Store something as cached version of this file. | |
| 1539 TestStoreToCache(file->resource_id(), | |
| 1540 file->file_md5(), | |
| 1541 GetTestFilePath("root_feed.json"), | |
| 1542 base::PLATFORM_FILE_OK); | |
| 1543 | |
| 1544 // Make sure we don't call downloads at all. | |
| 1545 EXPECT_CALL(*mock_doc_service_, | |
| 1546 DownloadFile(file_in_root, | |
| 1547 downloaded_file, | |
| 1548 GURL("https://file_content_url/"), | |
| 1549 _)) | |
| 1550 .Times(0); | |
| 1551 | |
| 1552 file_system_->GetFile(file_in_root, callback); | |
| 1553 RunAllPendingForCache(); | |
| 1554 | |
| 1555 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.
| |
| 1556 EXPECT_STREQ(downloaded_file.value().c_str(), | |
| 1557 callback_helper_->download_path_.value().c_str()); | |
| 1558 } | |
| 1559 | |
| 1509 TEST_F(GDataFileSystemTest, GetAvailableSpace) { | 1560 TEST_F(GDataFileSystemTest, GetAvailableSpace) { |
| 1510 GetAvailableSpaceCallback callback = | 1561 GetAvailableSpaceCallback callback = |
| 1511 base::Bind(&CallbackHelper::GetAvailableSpaceCallback, | 1562 base::Bind(&CallbackHelper::GetAvailableSpaceCallback, |
| 1512 callback_helper_.get()); | 1563 callback_helper_.get()); |
| 1513 | 1564 |
| 1514 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)); | 1565 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)); |
| 1515 | 1566 |
| 1516 file_system_->GetAvailableSpace(callback); | 1567 file_system_->GetAvailableSpace(callback); |
| 1517 message_loop_.RunAllPending(); // Wait to get our result. | 1568 message_loop_.RunAllPending(); // Wait to get our result. |
| 1518 EXPECT_EQ(1234, callback_helper_->quota_bytes_used_); | 1569 EXPECT_EQ(1234, callback_helper_->quota_bytes_used_); |
| 1519 EXPECT_EQ(12345, callback_helper_->quota_bytes_total_); | 1570 EXPECT_EQ(12345, callback_helper_->quota_bytes_total_); |
| 1520 } | 1571 } |
| 1521 | 1572 |
| 1522 } // namespace gdata | 1573 } // namespace gdata |
| OLD | NEW |