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 "chrome/browser/chromeos/drive/drive_file_system.h" | 5 #include "chrome/browser/chromeos/drive/drive_file_system.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 results->at(i).is_directory); | 77 results->at(i).is_directory); |
78 } | 78 } |
79 | 79 |
80 EXPECT_EQ(expected_next_feed, next_feed); | 80 EXPECT_EQ(expected_next_feed, next_feed); |
81 | 81 |
82 message_loop->Quit(); | 82 message_loop->Quit(); |
83 } | 83 } |
84 | 84 |
85 // Action used to set mock expectations for | 85 // Action used to set mock expectations for |
86 // DriveServiceInterface::GetResourceEntry(). | 86 // DriveServiceInterface::GetResourceEntry(). |
87 ACTION_P2(MockGetResourceEntry, status, value) { | 87 ACTION_P2(MockGetResourceEntry, status, entry) { |
88 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 88 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
89 base::Bind(arg1, status, base::Passed(value))); | 89 base::Bind(arg1, status, entry)); |
90 } | 90 } |
91 | 91 |
92 // Action used to set mock expectations for | 92 // Action used to set mock expectations for |
93 // DriveFileSystem::CopyHostedDocument(). | 93 // DriveFileSystem::CopyHostedDocument(). |
94 ACTION_P2(MockCopyHostedDocument, status, value) { | 94 ACTION_P2(MockCopyHostedDocument, status, value) { |
95 base::MessageLoopProxy::current()->PostTask( | 95 base::MessageLoopProxy::current()->PostTask( |
96 FROM_HERE, | 96 FROM_HERE, |
97 base::Bind(arg2, status, base::Passed(value))); | 97 base::Bind(arg2, status, base::Passed(value))); |
98 } | 98 } |
99 | 99 |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 FilePath target_path; | 612 FilePath target_path; |
613 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path)); | 613 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path)); |
614 EXPECT_TRUE(target_path.value() != kSymLinkToDevNull); | 614 EXPECT_TRUE(target_path.value() != kSymLinkToDevNull); |
615 if (test_util::ToCacheEntry(expected_cache_state_).is_present()) | 615 if (test_util::ToCacheEntry(expected_cache_state_).is_present()) |
616 EXPECT_EQ(dest_path, target_path); | 616 EXPECT_EQ(dest_path, target_path); |
617 } else { | 617 } else { |
618 EXPECT_FALSE(exists); | 618 EXPECT_FALSE(exists); |
619 } | 619 } |
620 } | 620 } |
621 | 621 |
622 void SetExpectationsForGetResourceEntry(scoped_ptr<base::Value>* document, | 622 void SetExpectationsForGetResourceEntry(const base::Value& value, |
623 const std::string& resource_id) { | 623 const std::string& resource_id) { |
| 624 scoped_ptr<google_apis::ResourceEntry> entry = |
| 625 google_apis::ResourceEntry::ExtractAndParse(value); |
624 EXPECT_CALL(*mock_drive_service_, GetResourceEntry(resource_id, _)) | 626 EXPECT_CALL(*mock_drive_service_, GetResourceEntry(resource_id, _)) |
625 .WillOnce(MockGetResourceEntry(google_apis::HTTP_SUCCESS, document)); | 627 .WillOnce(MockGetResourceEntry(google_apis::HTTP_SUCCESS, |
| 628 base::Passed(&entry))); |
626 } | 629 } |
627 | 630 |
628 // Loads serialized proto file from GCache, and makes sure the root | 631 // Loads serialized proto file from GCache, and makes sure the root |
629 // filesystem has a root at 'drive' | 632 // filesystem has a root at 'drive' |
630 bool TestLoadMetadataFromCache() { | 633 bool TestLoadMetadataFromCache() { |
631 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 634 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
632 file_system_->LoadRootFeedFromCacheForTesting( | 635 file_system_->LoadRootFeedFromCacheForTesting( |
633 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); | 636 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); |
634 google_apis::test_util::RunBlockingPoolTask(); | 637 google_apis::test_util::RunBlockingPoolTask(); |
635 return error == DRIVE_FILE_OK; | 638 return error == DRIVE_FILE_OK; |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1395 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 1398 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
1396 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); | 1399 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); |
1397 | 1400 |
1398 const std::string remote_src_file_data = "Test file data"; | 1401 const std::string remote_src_file_data = "Test file data"; |
1399 mock_drive_service_->set_file_data(new std::string(remote_src_file_data)); | 1402 mock_drive_service_->set_file_data(new std::string(remote_src_file_data)); |
1400 | 1403 |
1401 // Before Download starts metadata from server will be fetched. | 1404 // Before Download starts metadata from server will be fetched. |
1402 // We will read content url from the result. | 1405 // We will read content url from the result. |
1403 scoped_ptr<base::Value> document = | 1406 scoped_ptr<base::Value> document = |
1404 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); | 1407 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); |
1405 SetExpectationsForGetResourceEntry(&document, "file:2_file_resource_id"); | 1408 SetExpectationsForGetResourceEntry(*document, "file:2_file_resource_id"); |
1406 | 1409 |
1407 // The file is obtained with the mock DriveService. | 1410 // The file is obtained with the mock DriveService. |
1408 EXPECT_CALL(*mock_drive_service_, | 1411 EXPECT_CALL(*mock_drive_service_, |
1409 DownloadFile(remote_src_file_path, | 1412 DownloadFile(remote_src_file_path, |
1410 cache_file, | 1413 cache_file, |
1411 GURL("https://file_content_url_changed/"), | 1414 GURL("https://file_content_url_changed/"), |
1412 _, _)) | 1415 _, _)) |
1413 .Times(1); | 1416 .Times(1); |
1414 | 1417 |
1415 file_system_->TransferFileFromRemoteToLocal( | 1418 file_system_->TransferFileFromRemoteToLocal( |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2011 const int64 file_size = entry_proto->file_info().size(); | 2014 const int64 file_size = entry_proto->file_info().size(); |
2012 | 2015 |
2013 // Pretend we have enough space. | 2016 // Pretend we have enough space. |
2014 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2017 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
2015 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); | 2018 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); |
2016 | 2019 |
2017 // Before Download starts metadata from server will be fetched. | 2020 // Before Download starts metadata from server will be fetched. |
2018 // We will read content url from the result. | 2021 // We will read content url from the result. |
2019 scoped_ptr<base::Value> document = | 2022 scoped_ptr<base::Value> document = |
2020 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); | 2023 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2021 SetExpectationsForGetResourceEntry(&document, "file:2_file_resource_id"); | 2024 SetExpectationsForGetResourceEntry(*document, "file:2_file_resource_id"); |
2022 | 2025 |
2023 // The file is obtained with the mock DriveService. | 2026 // The file is obtained with the mock DriveService. |
2024 EXPECT_CALL(*mock_drive_service_, | 2027 EXPECT_CALL(*mock_drive_service_, |
2025 DownloadFile(file_in_root, | 2028 DownloadFile(file_in_root, |
2026 downloaded_file, | 2029 downloaded_file, |
2027 GURL("https://file_content_url_changed/"), | 2030 GURL("https://file_content_url_changed/"), |
2028 _, _)) | 2031 _, _)) |
2029 .Times(1); | 2032 .Times(1); |
2030 | 2033 |
2031 file_system_->GetFileByPath(file_in_root, callback, | 2034 file_system_->GetFileByPath(file_in_root, callback, |
(...skipping 20 matching lines...) Expand all Loading... |
2052 entry_proto->file_specific_info().file_md5()); | 2055 entry_proto->file_specific_info().file_md5()); |
2053 | 2056 |
2054 // Pretend we have no space at all. | 2057 // Pretend we have no space at all. |
2055 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2058 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
2056 .Times(2).WillRepeatedly(Return(0)); | 2059 .Times(2).WillRepeatedly(Return(0)); |
2057 | 2060 |
2058 // Before Download starts metadata from server will be fetched. | 2061 // Before Download starts metadata from server will be fetched. |
2059 // We will read content url from the result. | 2062 // We will read content url from the result. |
2060 scoped_ptr<base::Value> document = | 2063 scoped_ptr<base::Value> document = |
2061 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); | 2064 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2062 SetExpectationsForGetResourceEntry(&document, "file:2_file_resource_id"); | 2065 SetExpectationsForGetResourceEntry(*document, "file:2_file_resource_id"); |
2063 | 2066 |
2064 // The file is not obtained with the mock DriveService, because of no space. | 2067 // The file is not obtained with the mock DriveService, because of no space. |
2065 EXPECT_CALL(*mock_drive_service_, | 2068 EXPECT_CALL(*mock_drive_service_, |
2066 DownloadFile(file_in_root, | 2069 DownloadFile(file_in_root, |
2067 downloaded_file, | 2070 downloaded_file, |
2068 GURL("https://file_content_url_changed/"), | 2071 GURL("https://file_content_url_changed/"), |
2069 _, _)) | 2072 _, _)) |
2070 .Times(0); | 2073 .Times(0); |
2071 | 2074 |
2072 file_system_->GetFileByPath(file_in_root, callback, | 2075 file_system_->GetFileByPath(file_in_root, callback, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 DRIVE_FILE_OK, | 2111 DRIVE_FILE_OK, |
2109 test_util::TEST_CACHE_STATE_PRESENT, | 2112 test_util::TEST_CACHE_STATE_PRESENT, |
2110 DriveCache::CACHE_TYPE_TMP); | 2113 DriveCache::CACHE_TYPE_TMP); |
2111 ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>")); | 2114 ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>")); |
2112 ASSERT_TRUE(CacheFileExists("<resource_id>", "<md5>")); | 2115 ASSERT_TRUE(CacheFileExists("<resource_id>", "<md5>")); |
2113 | 2116 |
2114 // Before Download starts metadata from server will be fetched. | 2117 // Before Download starts metadata from server will be fetched. |
2115 // We will read content url from the result. | 2118 // We will read content url from the result. |
2116 scoped_ptr<base::Value> document = | 2119 scoped_ptr<base::Value> document = |
2117 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); | 2120 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2118 SetExpectationsForGetResourceEntry(&document, "file:2_file_resource_id"); | 2121 SetExpectationsForGetResourceEntry(*document, "file:2_file_resource_id"); |
2119 | 2122 |
2120 // The file is obtained with the mock DriveService, because of we freed up the | 2123 // The file is obtained with the mock DriveService, because of we freed up the |
2121 // space. | 2124 // space. |
2122 EXPECT_CALL(*mock_drive_service_, | 2125 EXPECT_CALL(*mock_drive_service_, |
2123 DownloadFile(file_in_root, | 2126 DownloadFile(file_in_root, |
2124 downloaded_file, | 2127 downloaded_file, |
2125 GURL("https://file_content_url_changed/"), | 2128 GURL("https://file_content_url_changed/"), |
2126 _, _)) | 2129 _, _)) |
2127 .Times(1); | 2130 .Times(1); |
2128 | 2131 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2161 // (ex. the actual file was larger than the expected size). | 2164 // (ex. the actual file was larger than the expected size). |
2162 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2165 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
2163 .WillOnce(Return(file_size + kMinFreeSpace)) | 2166 .WillOnce(Return(file_size + kMinFreeSpace)) |
2164 .WillOnce(Return(kMinFreeSpace - 1)) | 2167 .WillOnce(Return(kMinFreeSpace - 1)) |
2165 .WillOnce(Return(kMinFreeSpace - 1)); | 2168 .WillOnce(Return(kMinFreeSpace - 1)); |
2166 | 2169 |
2167 // Before Download starts metadata from server will be fetched. | 2170 // Before Download starts metadata from server will be fetched. |
2168 // We will read content url from the result. | 2171 // We will read content url from the result. |
2169 scoped_ptr<base::Value> document = | 2172 scoped_ptr<base::Value> document = |
2170 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); | 2173 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2171 SetExpectationsForGetResourceEntry(&document, "file:2_file_resource_id"); | 2174 SetExpectationsForGetResourceEntry(*document, "file:2_file_resource_id"); |
2172 | 2175 |
2173 // The file is obtained with the mock DriveService. | 2176 // The file is obtained with the mock DriveService. |
2174 EXPECT_CALL(*mock_drive_service_, | 2177 EXPECT_CALL(*mock_drive_service_, |
2175 DownloadFile(file_in_root, | 2178 DownloadFile(file_in_root, |
2176 downloaded_file, | 2179 downloaded_file, |
2177 GURL("https://file_content_url_changed/"), | 2180 GURL("https://file_content_url_changed/"), |
2178 _, _)) | 2181 _, _)) |
2179 .Times(1); | 2182 .Times(1); |
2180 | 2183 |
2181 file_system_->GetFileByPath(file_in_root, callback, | 2184 file_system_->GetFileByPath(file_in_root, callback, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2268 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 2271 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
2269 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 2272 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
2270 FilePath downloaded_file = GetCachePathForFile( | 2273 FilePath downloaded_file = GetCachePathForFile( |
2271 entry_proto->resource_id(), | 2274 entry_proto->resource_id(), |
2272 entry_proto->file_specific_info().file_md5()); | 2275 entry_proto->file_specific_info().file_md5()); |
2273 | 2276 |
2274 // Before Download starts metadata from server will be fetched. | 2277 // Before Download starts metadata from server will be fetched. |
2275 // We will read content url from the result. | 2278 // We will read content url from the result. |
2276 scoped_ptr<base::Value> document = | 2279 scoped_ptr<base::Value> document = |
2277 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); | 2280 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2278 SetExpectationsForGetResourceEntry(&document, "file:2_file_resource_id"); | 2281 SetExpectationsForGetResourceEntry(*document, "file:2_file_resource_id"); |
2279 | 2282 |
2280 // The file is obtained with the mock DriveService, because it's not stored in | 2283 // The file is obtained with the mock DriveService, because it's not stored in |
2281 // the cache. | 2284 // the cache. |
2282 EXPECT_CALL(*mock_drive_service_, | 2285 EXPECT_CALL(*mock_drive_service_, |
2283 DownloadFile(file_in_root, | 2286 DownloadFile(file_in_root, |
2284 downloaded_file, | 2287 downloaded_file, |
2285 GURL("https://file_content_url_changed/"), | 2288 GURL("https://file_content_url_changed/"), |
2286 _, _)) | 2289 _, _)) |
2287 .Times(1); | 2290 .Times(1); |
2288 | 2291 |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2615 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2618 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
2616 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); | 2619 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); |
2617 | 2620 |
2618 const std::string kExpectedFileData = "test file data"; | 2621 const std::string kExpectedFileData = "test file data"; |
2619 mock_drive_service_->set_file_data(new std::string(kExpectedFileData)); | 2622 mock_drive_service_->set_file_data(new std::string(kExpectedFileData)); |
2620 | 2623 |
2621 // Before Download starts metadata from server will be fetched. | 2624 // Before Download starts metadata from server will be fetched. |
2622 // We will read content url from the result. | 2625 // We will read content url from the result. |
2623 scoped_ptr<base::Value> document = | 2626 scoped_ptr<base::Value> document = |
2624 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); | 2627 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2625 SetExpectationsForGetResourceEntry(&document, "file:2_file_resource_id"); | 2628 SetExpectationsForGetResourceEntry(*document, "file:2_file_resource_id"); |
2626 | 2629 |
2627 // The file is obtained with the mock DriveService. | 2630 // The file is obtained with the mock DriveService. |
2628 EXPECT_CALL(*mock_drive_service_, | 2631 EXPECT_CALL(*mock_drive_service_, |
2629 DownloadFile(kFileInRoot, | 2632 DownloadFile(kFileInRoot, |
2630 downloaded_file, | 2633 downloaded_file, |
2631 GURL("https://file_content_url_changed/"), | 2634 GURL("https://file_content_url_changed/"), |
2632 _, _)) | 2635 _, _)) |
2633 .Times(1); | 2636 .Times(1); |
2634 | 2637 |
2635 // Open kFileInRoot ("drive/File 1.txt"). | 2638 // Open kFileInRoot ("drive/File 1.txt"). |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2672 | 2675 |
2673 // Try to close the same file twice. | 2676 // Try to close the same file twice. |
2674 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2677 file_system_->CloseFile(kFileInRoot, close_file_callback); |
2675 message_loop_.Run(); | 2678 message_loop_.Run(); |
2676 | 2679 |
2677 // It must fail. | 2680 // It must fail. |
2678 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2681 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
2679 } | 2682 } |
2680 | 2683 |
2681 } // namespace drive | 2684 } // namespace drive |
OLD | NEW |