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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 false, // is_exclusive | 262 false, // is_exclusive |
263 false, // is_recursive | 263 false, // is_recursive |
264 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); | 264 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); |
265 file_system_->AddNewDirectory(params, gdata::HTTP_SUCCESS, atom.Pass()); | 265 file_system_->AddNewDirectory(params, gdata::HTTP_SUCCESS, atom.Pass()); |
266 gdata::test_util::RunBlockingPoolTask(); | 266 gdata::test_util::RunBlockingPoolTask(); |
267 EXPECT_EQ(DRIVE_FILE_OK, error); | 267 EXPECT_EQ(DRIVE_FILE_OK, error); |
268 } | 268 } |
269 | 269 |
270 bool RemoveEntry(const FilePath& file_path) { | 270 bool RemoveEntry(const FilePath& file_path) { |
271 DriveFileError error; | 271 DriveFileError error; |
272 EXPECT_CALL(*mock_drive_service_, DeleteDocument(_, _)).Times(AnyNumber()); | 272 EXPECT_CALL(*mock_drive_service_, |
| 273 DeleteDocument(_, _, _)).Times(AnyNumber()); |
273 file_system_->Remove( | 274 file_system_->Remove( |
274 file_path, false, | 275 file_path, false, |
275 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); | 276 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); |
276 | 277 |
277 gdata::test_util::RunBlockingPoolTask(); | 278 gdata::test_util::RunBlockingPoolTask(); |
278 return error == DRIVE_FILE_OK; | 279 return error == DRIVE_FILE_OK; |
279 } | 280 } |
280 | 281 |
281 FilePath GetCachePathForFile(const std::string& resource_id, | 282 FilePath GetCachePathForFile(const std::string& resource_id, |
282 const std::string& md5) { | 283 const std::string& md5) { |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 // We will read content url from the result. | 1323 // We will read content url from the result. |
1323 scoped_ptr<base::Value> document = | 1324 scoped_ptr<base::Value> document = |
1324 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); | 1325 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
1325 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 1326 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
1326 | 1327 |
1327 // The file is obtained with the mock DriveService. | 1328 // The file is obtained with the mock DriveService. |
1328 EXPECT_CALL(*mock_drive_service_, | 1329 EXPECT_CALL(*mock_drive_service_, |
1329 DownloadFile(remote_src_file_path, | 1330 DownloadFile(remote_src_file_path, |
1330 cache_file, | 1331 cache_file, |
1331 GURL("https://file_content_url_changed/"), | 1332 GURL("https://file_content_url_changed/"), |
1332 _, _)) | 1333 _, _, _)) |
1333 .Times(1); | 1334 .Times(1); |
1334 | 1335 |
1335 file_system_->TransferFileFromRemoteToLocal( | 1336 file_system_->TransferFileFromRemoteToLocal( |
1336 remote_src_file_path, local_dest_file_path, callback); | 1337 remote_src_file_path, local_dest_file_path, callback); |
1337 gdata::test_util::RunBlockingPoolTask(); | 1338 gdata::test_util::RunBlockingPoolTask(); |
1338 | 1339 |
1339 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 1340 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
1340 | 1341 |
1341 std::string cache_file_data; | 1342 std::string cache_file_data; |
1342 EXPECT_TRUE(file_util::ReadFileToString(cache_file, &cache_file_data)); | 1343 EXPECT_TRUE(file_util::ReadFileToString(cache_file, &cache_file_data)); |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1940 // We will read content url from the result. | 1941 // We will read content url from the result. |
1941 scoped_ptr<base::Value> document = | 1942 scoped_ptr<base::Value> document = |
1942 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); | 1943 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
1943 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 1944 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
1944 | 1945 |
1945 // The file is obtained with the mock DriveService. | 1946 // The file is obtained with the mock DriveService. |
1946 EXPECT_CALL(*mock_drive_service_, | 1947 EXPECT_CALL(*mock_drive_service_, |
1947 DownloadFile(file_in_root, | 1948 DownloadFile(file_in_root, |
1948 downloaded_file, | 1949 downloaded_file, |
1949 GURL("https://file_content_url_changed/"), | 1950 GURL("https://file_content_url_changed/"), |
1950 _, _)) | 1951 _, _, _)) |
1951 .Times(1); | 1952 .Times(1); |
1952 | 1953 |
1953 file_system_->GetFileByPath(file_in_root, callback, | 1954 file_system_->GetFileByPath(file_in_root, callback, |
1954 gdata::GetContentCallback()); | 1955 gdata::GetContentCallback()); |
1955 gdata::test_util::RunBlockingPoolTask(); | 1956 gdata::test_util::RunBlockingPoolTask(); |
1956 | 1957 |
1957 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 1958 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
1958 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 1959 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
1959 EXPECT_EQ(downloaded_file.value(), | 1960 EXPECT_EQ(downloaded_file.value(), |
1960 callback_helper_->download_path_.value()); | 1961 callback_helper_->download_path_.value()); |
(...skipping 20 matching lines...) Expand all Loading... |
1981 // We will read content url from the result. | 1982 // We will read content url from the result. |
1982 scoped_ptr<base::Value> document = | 1983 scoped_ptr<base::Value> document = |
1983 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); | 1984 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
1984 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 1985 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
1985 | 1986 |
1986 // The file is not obtained with the mock DriveService, because of no space. | 1987 // The file is not obtained with the mock DriveService, because of no space. |
1987 EXPECT_CALL(*mock_drive_service_, | 1988 EXPECT_CALL(*mock_drive_service_, |
1988 DownloadFile(file_in_root, | 1989 DownloadFile(file_in_root, |
1989 downloaded_file, | 1990 downloaded_file, |
1990 GURL("https://file_content_url_changed/"), | 1991 GURL("https://file_content_url_changed/"), |
1991 _, _)) | 1992 _, _, _)) |
1992 .Times(0); | 1993 .Times(0); |
1993 | 1994 |
1994 file_system_->GetFileByPath(file_in_root, callback, | 1995 file_system_->GetFileByPath(file_in_root, callback, |
1995 gdata::GetContentCallback()); | 1996 gdata::GetContentCallback()); |
1996 gdata::test_util::RunBlockingPoolTask(); | 1997 gdata::test_util::RunBlockingPoolTask(); |
1997 | 1998 |
1998 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, | 1999 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, |
1999 callback_helper_->last_error_); | 2000 callback_helper_->last_error_); |
2000 } | 2001 } |
2001 | 2002 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 scoped_ptr<base::Value> document = | 2038 scoped_ptr<base::Value> document = |
2038 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); | 2039 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2039 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 2040 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
2040 | 2041 |
2041 // The file is obtained with the mock DriveService, because of we freed up the | 2042 // The file is obtained with the mock DriveService, because of we freed up the |
2042 // space. | 2043 // space. |
2043 EXPECT_CALL(*mock_drive_service_, | 2044 EXPECT_CALL(*mock_drive_service_, |
2044 DownloadFile(file_in_root, | 2045 DownloadFile(file_in_root, |
2045 downloaded_file, | 2046 downloaded_file, |
2046 GURL("https://file_content_url_changed/"), | 2047 GURL("https://file_content_url_changed/"), |
2047 _, _)) | 2048 _, _, _)) |
2048 .Times(1); | 2049 .Times(1); |
2049 | 2050 |
2050 file_system_->GetFileByPath(file_in_root, callback, | 2051 file_system_->GetFileByPath(file_in_root, callback, |
2051 gdata::GetContentCallback()); | 2052 gdata::GetContentCallback()); |
2052 gdata::test_util::RunBlockingPoolTask(); | 2053 gdata::test_util::RunBlockingPoolTask(); |
2053 | 2054 |
2054 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 2055 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
2055 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 2056 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
2056 EXPECT_EQ(downloaded_file.value(), | 2057 EXPECT_EQ(downloaded_file.value(), |
2057 callback_helper_->download_path_.value()); | 2058 callback_helper_->download_path_.value()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2089 // We will read content url from the result. | 2090 // We will read content url from the result. |
2090 scoped_ptr<base::Value> document = | 2091 scoped_ptr<base::Value> document = |
2091 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); | 2092 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2092 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 2093 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
2093 | 2094 |
2094 // The file is obtained with the mock DriveService. | 2095 // The file is obtained with the mock DriveService. |
2095 EXPECT_CALL(*mock_drive_service_, | 2096 EXPECT_CALL(*mock_drive_service_, |
2096 DownloadFile(file_in_root, | 2097 DownloadFile(file_in_root, |
2097 downloaded_file, | 2098 downloaded_file, |
2098 GURL("https://file_content_url_changed/"), | 2099 GURL("https://file_content_url_changed/"), |
2099 _, _)) | 2100 _, _, _)) |
2100 .Times(1); | 2101 .Times(1); |
2101 | 2102 |
2102 file_system_->GetFileByPath(file_in_root, callback, | 2103 file_system_->GetFileByPath(file_in_root, callback, |
2103 gdata::GetContentCallback()); | 2104 gdata::GetContentCallback()); |
2104 gdata::test_util::RunBlockingPoolTask(); | 2105 gdata::test_util::RunBlockingPoolTask(); |
2105 | 2106 |
2106 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, | 2107 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, |
2107 callback_helper_->last_error_); | 2108 callback_helper_->last_error_); |
2108 } | 2109 } |
2109 | 2110 |
(...skipping 22 matching lines...) Expand all Loading... |
2132 DriveCache::CACHE_TYPE_TMP); | 2133 DriveCache::CACHE_TYPE_TMP); |
2133 | 2134 |
2134 // Make sure we don't fetch metadata for downloading file. | 2135 // Make sure we don't fetch metadata for downloading file. |
2135 EXPECT_CALL(*mock_drive_service_, GetDocumentEntry(_, _)).Times(0); | 2136 EXPECT_CALL(*mock_drive_service_, GetDocumentEntry(_, _)).Times(0); |
2136 | 2137 |
2137 // Make sure we don't call downloads at all. | 2138 // Make sure we don't call downloads at all. |
2138 EXPECT_CALL(*mock_drive_service_, | 2139 EXPECT_CALL(*mock_drive_service_, |
2139 DownloadFile(file_in_root, | 2140 DownloadFile(file_in_root, |
2140 downloaded_file, | 2141 downloaded_file, |
2141 GURL("https://file_content_url_changed/"), | 2142 GURL("https://file_content_url_changed/"), |
2142 _, _)) | 2143 _, _, _)) |
2143 .Times(0); | 2144 .Times(0); |
2144 | 2145 |
2145 file_system_->GetFileByPath(file_in_root, callback, | 2146 file_system_->GetFileByPath(file_in_root, callback, |
2146 gdata::GetContentCallback()); | 2147 gdata::GetContentCallback()); |
2147 gdata::test_util::RunBlockingPoolTask(); | 2148 gdata::test_util::RunBlockingPoolTask(); |
2148 | 2149 |
2149 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 2150 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
2150 EXPECT_EQ(downloaded_file.value(), | 2151 EXPECT_EQ(downloaded_file.value(), |
2151 callback_helper_->download_path_.value()); | 2152 callback_helper_->download_path_.value()); |
2152 } | 2153 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2196 scoped_ptr<base::Value> document = | 2197 scoped_ptr<base::Value> document = |
2197 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); | 2198 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2198 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 2199 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
2199 | 2200 |
2200 // The file is obtained with the mock DriveService, because it's not stored in | 2201 // The file is obtained with the mock DriveService, because it's not stored in |
2201 // the cache. | 2202 // the cache. |
2202 EXPECT_CALL(*mock_drive_service_, | 2203 EXPECT_CALL(*mock_drive_service_, |
2203 DownloadFile(file_in_root, | 2204 DownloadFile(file_in_root, |
2204 downloaded_file, | 2205 downloaded_file, |
2205 GURL("https://file_content_url_changed/"), | 2206 GURL("https://file_content_url_changed/"), |
2206 _, _)) | 2207 _, _, _)) |
2207 .Times(1); | 2208 .Times(1); |
2208 | 2209 |
2209 file_system_->GetFileByResourceId(entry_proto->resource_id(), | 2210 file_system_->GetFileByResourceId(entry_proto->resource_id(), |
2210 callback, | 2211 callback, |
2211 gdata::GetContentCallback()); | 2212 gdata::GetContentCallback()); |
2212 gdata::test_util::RunBlockingPoolTask(); | 2213 gdata::test_util::RunBlockingPoolTask(); |
2213 | 2214 |
2214 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 2215 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
2215 EXPECT_EQ(downloaded_file.value(), | 2216 EXPECT_EQ(downloaded_file.value(), |
2216 callback_helper_->download_path_.value()); | 2217 callback_helper_->download_path_.value()); |
(...skipping 18 matching lines...) Expand all Loading... |
2235 // Store something as cached version of this file. | 2236 // Store something as cached version of this file. |
2236 TestStoreToCache(entry_proto->resource_id(), | 2237 TestStoreToCache(entry_proto->resource_id(), |
2237 entry_proto->file_specific_info().file_md5(), | 2238 entry_proto->file_specific_info().file_md5(), |
2238 gdata::test_util::GetTestFilePath("gdata/root_feed.json"), | 2239 gdata::test_util::GetTestFilePath("gdata/root_feed.json"), |
2239 DRIVE_FILE_OK, | 2240 DRIVE_FILE_OK, |
2240 test_util::TEST_CACHE_STATE_PRESENT, | 2241 test_util::TEST_CACHE_STATE_PRESENT, |
2241 DriveCache::CACHE_TYPE_TMP); | 2242 DriveCache::CACHE_TYPE_TMP); |
2242 | 2243 |
2243 // The file is obtained from the cache. | 2244 // The file is obtained from the cache. |
2244 // Make sure we don't call downloads at all. | 2245 // Make sure we don't call downloads at all. |
2245 EXPECT_CALL(*mock_drive_service_, DownloadFile(_, _, _, _, _)) | 2246 EXPECT_CALL(*mock_drive_service_, DownloadFile(_, _, _, _, _, _)) |
2246 .Times(0); | 2247 .Times(0); |
2247 | 2248 |
2248 file_system_->GetFileByResourceId(entry_proto->resource_id(), | 2249 file_system_->GetFileByResourceId(entry_proto->resource_id(), |
2249 callback, | 2250 callback, |
2250 gdata::GetContentCallback()); | 2251 gdata::GetContentCallback()); |
2251 gdata::test_util::RunBlockingPoolTask(); | 2252 gdata::test_util::RunBlockingPoolTask(); |
2252 | 2253 |
2253 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 2254 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
2254 EXPECT_EQ(downloaded_file.value(), | 2255 EXPECT_EQ(downloaded_file.value(), |
2255 callback_helper_->download_path_.value()); | 2256 callback_helper_->download_path_.value()); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2554 // We will read content url from the result. | 2555 // We will read content url from the result. |
2555 scoped_ptr<base::Value> document = | 2556 scoped_ptr<base::Value> document = |
2556 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); | 2557 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2557 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 2558 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
2558 | 2559 |
2559 // The file is obtained with the mock DriveService. | 2560 // The file is obtained with the mock DriveService. |
2560 EXPECT_CALL(*mock_drive_service_, | 2561 EXPECT_CALL(*mock_drive_service_, |
2561 DownloadFile(kFileInRoot, | 2562 DownloadFile(kFileInRoot, |
2562 downloaded_file, | 2563 downloaded_file, |
2563 GURL("https://file_content_url_changed/"), | 2564 GURL("https://file_content_url_changed/"), |
2564 _, _)) | 2565 _, _, _)) |
2565 .Times(1); | 2566 .Times(1); |
2566 | 2567 |
2567 // Open kFileInRoot ("drive/File 1.txt"). | 2568 // Open kFileInRoot ("drive/File 1.txt"). |
2568 file_system_->OpenFile(kFileInRoot, callback); | 2569 file_system_->OpenFile(kFileInRoot, callback); |
2569 message_loop_.Run(); | 2570 message_loop_.Run(); |
2570 const FilePath opened_file_path = callback_helper_->opened_file_path_; | 2571 const FilePath opened_file_path = callback_helper_->opened_file_path_; |
2571 | 2572 |
2572 // Verify that the file was properly opened. | 2573 // Verify that the file was properly opened. |
2573 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 2574 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
2574 | 2575 |
(...skipping 29 matching lines...) Expand all Loading... |
2604 | 2605 |
2605 // Try to close the same file twice. | 2606 // Try to close the same file twice. |
2606 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2607 file_system_->CloseFile(kFileInRoot, close_file_callback); |
2607 message_loop_.Run(); | 2608 message_loop_.Run(); |
2608 | 2609 |
2609 // It must fail. | 2610 // It must fail. |
2610 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2611 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
2611 } | 2612 } |
2612 | 2613 |
2613 } // namespace drive | 2614 } // namespace drive |
OLD | NEW |