OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/file_system/download_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/task_runner_util.h" | 8 #include "base/task_runner_util.h" |
9 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" | 9 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" |
10 #include "chrome/browser/chromeos/drive/file_cache.h" | 10 #include "chrome/browser/chromeos/drive/file_cache.h" |
11 #include "chrome/browser/chromeos/drive/file_change.h" | 11 #include "chrome/browser/chromeos/drive/file_change.h" |
12 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 12 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
13 #include "chrome/browser/chromeos/drive/file_system_util.h" | 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
14 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 14 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
15 #include "chrome/browser/drive/fake_drive_service.h" | 15 #include "chrome/browser/drive/fake_drive_service.h" |
| 16 #include "content/public/test/test_utils.h" |
16 #include "google_apis/drive/test_util.h" | 17 #include "google_apis/drive/test_util.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "third_party/cros_system_api/constants/cryptohome.h" | 19 #include "third_party/cros_system_api/constants/cryptohome.h" |
19 | 20 |
20 namespace drive { | 21 namespace drive { |
21 namespace file_system { | 22 namespace file_system { |
22 | 23 |
23 class DownloadOperationTest : public OperationTestBase { | 24 class DownloadOperationTest : public OperationTestBase { |
24 protected: | 25 protected: |
25 virtual void SetUp() OVERRIDE { | 26 virtual void SetUp() OVERRIDE { |
(...skipping 21 matching lines...) Expand all Loading... |
47 FileError error = FILE_ERROR_FAILED; | 48 FileError error = FILE_ERROR_FAILED; |
48 base::FilePath file_path; | 49 base::FilePath file_path; |
49 scoped_ptr<ResourceEntry> entry; | 50 scoped_ptr<ResourceEntry> entry; |
50 operation_->EnsureFileDownloadedByPath( | 51 operation_->EnsureFileDownloadedByPath( |
51 file_in_root, | 52 file_in_root, |
52 ClientContext(USER_INITIATED), | 53 ClientContext(USER_INITIATED), |
53 GetFileContentInitializedCallback(), | 54 GetFileContentInitializedCallback(), |
54 google_apis::GetContentCallback(), | 55 google_apis::GetContentCallback(), |
55 google_apis::test_util::CreateCopyResultCallback( | 56 google_apis::test_util::CreateCopyResultCallback( |
56 &error, &file_path, &entry)); | 57 &error, &file_path, &entry)); |
57 test_util::RunBlockingPoolTask(); | 58 content::RunAllBlockingPoolTasksUntilIdle(); |
58 | 59 |
59 EXPECT_EQ(FILE_ERROR_OK, error); | 60 EXPECT_EQ(FILE_ERROR_OK, error); |
60 ASSERT_TRUE(entry); | 61 ASSERT_TRUE(entry); |
61 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 62 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
62 | 63 |
63 // The transfered file is cached and the change of "offline available" | 64 // The transfered file is cached and the change of "offline available" |
64 // attribute is notified. | 65 // attribute is notified. |
65 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 66 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
66 EXPECT_EQ(1U, observer()->get_changed_files().count(file_in_root)); | 67 EXPECT_EQ(1U, observer()->get_changed_files().count(file_in_root)); |
67 } | 68 } |
68 | 69 |
69 TEST_F(DownloadOperationTest, | 70 TEST_F(DownloadOperationTest, |
70 EnsureFileDownloadedByPath_FromServer_NoSpaceAtAll) { | 71 EnsureFileDownloadedByPath_FromServer_NoSpaceAtAll) { |
71 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 72 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
72 | 73 |
73 // Pretend we have no space at all. | 74 // Pretend we have no space at all. |
74 fake_free_disk_space_getter()->set_default_value(0); | 75 fake_free_disk_space_getter()->set_default_value(0); |
75 | 76 |
76 FileError error = FILE_ERROR_OK; | 77 FileError error = FILE_ERROR_OK; |
77 base::FilePath file_path; | 78 base::FilePath file_path; |
78 scoped_ptr<ResourceEntry> entry; | 79 scoped_ptr<ResourceEntry> entry; |
79 operation_->EnsureFileDownloadedByPath( | 80 operation_->EnsureFileDownloadedByPath( |
80 file_in_root, | 81 file_in_root, |
81 ClientContext(USER_INITIATED), | 82 ClientContext(USER_INITIATED), |
82 GetFileContentInitializedCallback(), | 83 GetFileContentInitializedCallback(), |
83 google_apis::GetContentCallback(), | 84 google_apis::GetContentCallback(), |
84 google_apis::test_util::CreateCopyResultCallback( | 85 google_apis::test_util::CreateCopyResultCallback( |
85 &error, &file_path, &entry)); | 86 &error, &file_path, &entry)); |
86 test_util::RunBlockingPoolTask(); | 87 content::RunAllBlockingPoolTasksUntilIdle(); |
87 | 88 |
88 EXPECT_EQ(FILE_ERROR_NO_LOCAL_SPACE, error); | 89 EXPECT_EQ(FILE_ERROR_NO_LOCAL_SPACE, error); |
89 } | 90 } |
90 | 91 |
91 TEST_F(DownloadOperationTest, | 92 TEST_F(DownloadOperationTest, |
92 EnsureFileDownloadedByPath_FromServer_NoEnoughSpaceButCanFreeUp) { | 93 EnsureFileDownloadedByPath_FromServer_NoEnoughSpaceButCanFreeUp) { |
93 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 94 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
94 ResourceEntry src_entry; | 95 ResourceEntry src_entry; |
95 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 96 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
96 const int64 file_size = src_entry.file_info().size(); | 97 const int64 file_size = src_entry.file_info().size(); |
97 | 98 |
98 // Make another file cached. | 99 // Make another file cached. |
99 // This file's cache file will be removed to free up the disk space. | 100 // This file's cache file will be removed to free up the disk space. |
100 base::FilePath cached_file( | 101 base::FilePath cached_file( |
101 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt")); | 102 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt")); |
102 FileError error = FILE_ERROR_FAILED; | 103 FileError error = FILE_ERROR_FAILED; |
103 base::FilePath file_path; | 104 base::FilePath file_path; |
104 scoped_ptr<ResourceEntry> entry; | 105 scoped_ptr<ResourceEntry> entry; |
105 operation_->EnsureFileDownloadedByPath( | 106 operation_->EnsureFileDownloadedByPath( |
106 cached_file, | 107 cached_file, |
107 ClientContext(USER_INITIATED), | 108 ClientContext(USER_INITIATED), |
108 GetFileContentInitializedCallback(), | 109 GetFileContentInitializedCallback(), |
109 google_apis::GetContentCallback(), | 110 google_apis::GetContentCallback(), |
110 google_apis::test_util::CreateCopyResultCallback( | 111 google_apis::test_util::CreateCopyResultCallback( |
111 &error, &file_path, &entry)); | 112 &error, &file_path, &entry)); |
112 test_util::RunBlockingPoolTask(); | 113 content::RunAllBlockingPoolTasksUntilIdle(); |
113 EXPECT_EQ(FILE_ERROR_OK, error); | 114 EXPECT_EQ(FILE_ERROR_OK, error); |
114 ASSERT_TRUE(entry); | 115 ASSERT_TRUE(entry); |
115 EXPECT_TRUE(entry->file_specific_info().cache_state().is_present()); | 116 EXPECT_TRUE(entry->file_specific_info().cache_state().is_present()); |
116 | 117 |
117 // Pretend we have no space first (checked before downloading a file), | 118 // Pretend we have no space first (checked before downloading a file), |
118 // but then start reporting we have space. This is to emulate that | 119 // but then start reporting we have space. This is to emulate that |
119 // the disk space was freed up by removing temporary files. | 120 // the disk space was freed up by removing temporary files. |
120 fake_free_disk_space_getter()->set_default_value( | 121 fake_free_disk_space_getter()->set_default_value( |
121 file_size + cryptohome::kMinFreeSpaceInBytes); | 122 file_size + cryptohome::kMinFreeSpaceInBytes); |
122 fake_free_disk_space_getter()->PushFakeValue(0); | 123 fake_free_disk_space_getter()->PushFakeValue(0); |
123 | 124 |
124 operation_->EnsureFileDownloadedByPath( | 125 operation_->EnsureFileDownloadedByPath( |
125 file_in_root, | 126 file_in_root, |
126 ClientContext(USER_INITIATED), | 127 ClientContext(USER_INITIATED), |
127 GetFileContentInitializedCallback(), | 128 GetFileContentInitializedCallback(), |
128 google_apis::GetContentCallback(), | 129 google_apis::GetContentCallback(), |
129 google_apis::test_util::CreateCopyResultCallback( | 130 google_apis::test_util::CreateCopyResultCallback( |
130 &error, &file_path, &entry)); | 131 &error, &file_path, &entry)); |
131 test_util::RunBlockingPoolTask(); | 132 content::RunAllBlockingPoolTasksUntilIdle(); |
132 | 133 |
133 EXPECT_EQ(FILE_ERROR_OK, error); | 134 EXPECT_EQ(FILE_ERROR_OK, error); |
134 ASSERT_TRUE(entry); | 135 ASSERT_TRUE(entry); |
135 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 136 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
136 | 137 |
137 // The transfered file is cached and the change of "offline available" | 138 // The transfered file is cached and the change of "offline available" |
138 // attribute is notified. | 139 // attribute is notified. |
139 EXPECT_EQ(2U, observer()->get_changed_files().size()); | 140 EXPECT_EQ(2U, observer()->get_changed_files().size()); |
140 EXPECT_TRUE(observer()->get_changed_files().count(file_in_root)); | 141 EXPECT_TRUE(observer()->get_changed_files().count(file_in_root)); |
141 EXPECT_TRUE(observer()->get_changed_files().count(cached_file)); | 142 EXPECT_TRUE(observer()->get_changed_files().count(cached_file)); |
(...skipping 25 matching lines...) Expand all Loading... |
167 FileError error = FILE_ERROR_OK; | 168 FileError error = FILE_ERROR_OK; |
168 base::FilePath file_path; | 169 base::FilePath file_path; |
169 scoped_ptr<ResourceEntry> entry; | 170 scoped_ptr<ResourceEntry> entry; |
170 operation_->EnsureFileDownloadedByPath( | 171 operation_->EnsureFileDownloadedByPath( |
171 file_in_root, | 172 file_in_root, |
172 ClientContext(USER_INITIATED), | 173 ClientContext(USER_INITIATED), |
173 GetFileContentInitializedCallback(), | 174 GetFileContentInitializedCallback(), |
174 google_apis::GetContentCallback(), | 175 google_apis::GetContentCallback(), |
175 google_apis::test_util::CreateCopyResultCallback( | 176 google_apis::test_util::CreateCopyResultCallback( |
176 &error, &file_path, &entry)); | 177 &error, &file_path, &entry)); |
177 test_util::RunBlockingPoolTask(); | 178 content::RunAllBlockingPoolTasksUntilIdle(); |
178 | 179 |
179 EXPECT_EQ(FILE_ERROR_NO_LOCAL_SPACE, error); | 180 EXPECT_EQ(FILE_ERROR_NO_LOCAL_SPACE, error); |
180 } | 181 } |
181 | 182 |
182 TEST_F(DownloadOperationTest, EnsureFileDownloadedByPath_FromCache) { | 183 TEST_F(DownloadOperationTest, EnsureFileDownloadedByPath_FromCache) { |
183 base::FilePath temp_file; | 184 base::FilePath temp_file; |
184 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir(), &temp_file)); | 185 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir(), &temp_file)); |
185 | 186 |
186 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 187 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
187 ResourceEntry src_entry; | 188 ResourceEntry src_entry; |
188 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 189 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
189 | 190 |
190 // Store something as cached version of this file. | 191 // Store something as cached version of this file. |
191 FileError error = FILE_ERROR_OK; | 192 FileError error = FILE_ERROR_OK; |
192 base::PostTaskAndReplyWithResult( | 193 base::PostTaskAndReplyWithResult( |
193 blocking_task_runner(), | 194 blocking_task_runner(), |
194 FROM_HERE, | 195 FROM_HERE, |
195 base::Bind(&internal::FileCache::Store, | 196 base::Bind(&internal::FileCache::Store, |
196 base::Unretained(cache()), | 197 base::Unretained(cache()), |
197 GetLocalId(file_in_root), | 198 GetLocalId(file_in_root), |
198 src_entry.file_specific_info().md5(), | 199 src_entry.file_specific_info().md5(), |
199 temp_file, | 200 temp_file, |
200 internal::FileCache::FILE_OPERATION_COPY), | 201 internal::FileCache::FILE_OPERATION_COPY), |
201 google_apis::test_util::CreateCopyResultCallback(&error)); | 202 google_apis::test_util::CreateCopyResultCallback(&error)); |
202 test_util::RunBlockingPoolTask(); | 203 content::RunAllBlockingPoolTasksUntilIdle(); |
203 EXPECT_EQ(FILE_ERROR_OK, error); | 204 EXPECT_EQ(FILE_ERROR_OK, error); |
204 | 205 |
205 base::FilePath file_path; | 206 base::FilePath file_path; |
206 scoped_ptr<ResourceEntry> entry; | 207 scoped_ptr<ResourceEntry> entry; |
207 operation_->EnsureFileDownloadedByPath( | 208 operation_->EnsureFileDownloadedByPath( |
208 file_in_root, | 209 file_in_root, |
209 ClientContext(USER_INITIATED), | 210 ClientContext(USER_INITIATED), |
210 GetFileContentInitializedCallback(), | 211 GetFileContentInitializedCallback(), |
211 google_apis::GetContentCallback(), | 212 google_apis::GetContentCallback(), |
212 google_apis::test_util::CreateCopyResultCallback( | 213 google_apis::test_util::CreateCopyResultCallback( |
213 &error, &file_path, &entry)); | 214 &error, &file_path, &entry)); |
214 test_util::RunBlockingPoolTask(); | 215 content::RunAllBlockingPoolTasksUntilIdle(); |
215 | 216 |
216 EXPECT_EQ(FILE_ERROR_OK, error); | 217 EXPECT_EQ(FILE_ERROR_OK, error); |
217 ASSERT_TRUE(entry); | 218 ASSERT_TRUE(entry); |
218 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 219 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
219 } | 220 } |
220 | 221 |
221 TEST_F(DownloadOperationTest, EnsureFileDownloadedByPath_HostedDocument) { | 222 TEST_F(DownloadOperationTest, EnsureFileDownloadedByPath_HostedDocument) { |
222 base::FilePath file_in_root(FILE_PATH_LITERAL( | 223 base::FilePath file_in_root(FILE_PATH_LITERAL( |
223 "drive/root/Document 1 excludeDir-test.gdoc")); | 224 "drive/root/Document 1 excludeDir-test.gdoc")); |
224 | 225 |
225 FileError error = FILE_ERROR_FAILED; | 226 FileError error = FILE_ERROR_FAILED; |
226 base::FilePath file_path; | 227 base::FilePath file_path; |
227 scoped_ptr<ResourceEntry> entry; | 228 scoped_ptr<ResourceEntry> entry; |
228 operation_->EnsureFileDownloadedByPath( | 229 operation_->EnsureFileDownloadedByPath( |
229 file_in_root, | 230 file_in_root, |
230 ClientContext(USER_INITIATED), | 231 ClientContext(USER_INITIATED), |
231 GetFileContentInitializedCallback(), | 232 GetFileContentInitializedCallback(), |
232 google_apis::GetContentCallback(), | 233 google_apis::GetContentCallback(), |
233 google_apis::test_util::CreateCopyResultCallback( | 234 google_apis::test_util::CreateCopyResultCallback( |
234 &error, &file_path, &entry)); | 235 &error, &file_path, &entry)); |
235 test_util::RunBlockingPoolTask(); | 236 content::RunAllBlockingPoolTasksUntilIdle(); |
236 | 237 |
237 EXPECT_EQ(FILE_ERROR_OK, error); | 238 EXPECT_EQ(FILE_ERROR_OK, error); |
238 ASSERT_TRUE(entry); | 239 ASSERT_TRUE(entry); |
239 EXPECT_TRUE(entry->file_specific_info().is_hosted_document()); | 240 EXPECT_TRUE(entry->file_specific_info().is_hosted_document()); |
240 EXPECT_FALSE(file_path.empty()); | 241 EXPECT_FALSE(file_path.empty()); |
241 | 242 |
242 EXPECT_EQ(GURL(entry->file_specific_info().alternate_url()), | 243 EXPECT_EQ(GURL(entry->file_specific_info().alternate_url()), |
243 util::ReadUrlFromGDocFile(file_path)); | 244 util::ReadUrlFromGDocFile(file_path)); |
244 EXPECT_EQ(entry->resource_id(), util::ReadResourceIdFromGDocFile(file_path)); | 245 EXPECT_EQ(entry->resource_id(), util::ReadResourceIdFromGDocFile(file_path)); |
245 EXPECT_EQ(FILE_PATH_LITERAL(".gdoc"), file_path.Extension()); | 246 EXPECT_EQ(FILE_PATH_LITERAL(".gdoc"), file_path.Extension()); |
246 } | 247 } |
247 | 248 |
248 TEST_F(DownloadOperationTest, EnsureFileDownloadedByLocalId) { | 249 TEST_F(DownloadOperationTest, EnsureFileDownloadedByLocalId) { |
249 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 250 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
250 ResourceEntry src_entry; | 251 ResourceEntry src_entry; |
251 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 252 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
252 | 253 |
253 FileError error = FILE_ERROR_OK; | 254 FileError error = FILE_ERROR_OK; |
254 base::FilePath file_path; | 255 base::FilePath file_path; |
255 scoped_ptr<ResourceEntry> entry; | 256 scoped_ptr<ResourceEntry> entry; |
256 operation_->EnsureFileDownloadedByLocalId( | 257 operation_->EnsureFileDownloadedByLocalId( |
257 GetLocalId(file_in_root), | 258 GetLocalId(file_in_root), |
258 ClientContext(USER_INITIATED), | 259 ClientContext(USER_INITIATED), |
259 GetFileContentInitializedCallback(), | 260 GetFileContentInitializedCallback(), |
260 google_apis::GetContentCallback(), | 261 google_apis::GetContentCallback(), |
261 google_apis::test_util::CreateCopyResultCallback( | 262 google_apis::test_util::CreateCopyResultCallback( |
262 &error, &file_path, &entry)); | 263 &error, &file_path, &entry)); |
263 test_util::RunBlockingPoolTask(); | 264 content::RunAllBlockingPoolTasksUntilIdle(); |
264 | 265 |
265 EXPECT_EQ(FILE_ERROR_OK, error); | 266 EXPECT_EQ(FILE_ERROR_OK, error); |
266 ASSERT_TRUE(entry); | 267 ASSERT_TRUE(entry); |
267 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 268 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
268 | 269 |
269 // The transfered file is cached and the change of "offline available" | 270 // The transfered file is cached and the change of "offline available" |
270 // attribute is notified. | 271 // attribute is notified. |
271 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 272 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
272 EXPECT_EQ(1U, observer()->get_changed_files().count(file_in_root)); | 273 EXPECT_EQ(1U, observer()->get_changed_files().count(file_in_root)); |
273 } | 274 } |
274 | 275 |
275 TEST_F(DownloadOperationTest, | 276 TEST_F(DownloadOperationTest, |
276 EnsureFileDownloadedByPath_WithGetContentCallback) { | 277 EnsureFileDownloadedByPath_WithGetContentCallback) { |
277 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 278 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
278 | 279 |
279 { | 280 { |
280 FileError initialized_error = FILE_ERROR_FAILED; | 281 FileError initialized_error = FILE_ERROR_FAILED; |
281 scoped_ptr<ResourceEntry> entry, entry_dontcare; | 282 scoped_ptr<ResourceEntry> entry, entry_dontcare; |
282 base::FilePath local_path, local_path_dontcare; | 283 base::FilePath local_path, local_path_dontcare; |
283 google_apis::test_util::TestGetContentCallback get_content_callback; | 284 google_apis::test_util::TestGetContentCallback get_content_callback; |
284 FileError completion_error = FILE_ERROR_FAILED; | 285 FileError completion_error = FILE_ERROR_FAILED; |
285 base::Closure cancel_download = operation_->EnsureFileDownloadedByPath( | 286 base::Closure cancel_download = operation_->EnsureFileDownloadedByPath( |
286 file_in_root, | 287 file_in_root, |
287 ClientContext(USER_INITIATED), | 288 ClientContext(USER_INITIATED), |
288 google_apis::test_util::CreateCopyResultCallback( | 289 google_apis::test_util::CreateCopyResultCallback( |
289 &initialized_error, &local_path, &entry), | 290 &initialized_error, &local_path, &entry), |
290 get_content_callback.callback(), | 291 get_content_callback.callback(), |
291 google_apis::test_util::CreateCopyResultCallback( | 292 google_apis::test_util::CreateCopyResultCallback( |
292 &completion_error, &local_path_dontcare, &entry_dontcare)); | 293 &completion_error, &local_path_dontcare, &entry_dontcare)); |
293 test_util::RunBlockingPoolTask(); | 294 content::RunAllBlockingPoolTasksUntilIdle(); |
294 | 295 |
295 // For the first time, file is downloaded from the remote server. | 296 // For the first time, file is downloaded from the remote server. |
296 // In this case, |local_path| is empty. | 297 // In this case, |local_path| is empty. |
297 EXPECT_EQ(FILE_ERROR_OK, initialized_error); | 298 EXPECT_EQ(FILE_ERROR_OK, initialized_error); |
298 ASSERT_TRUE(entry); | 299 ASSERT_TRUE(entry); |
299 ASSERT_TRUE(local_path.empty()); | 300 ASSERT_TRUE(local_path.empty()); |
300 EXPECT_FALSE(cancel_download.is_null()); | 301 EXPECT_FALSE(cancel_download.is_null()); |
301 // Content is available through the second callback argument. | 302 // Content is available through the second callback argument. |
302 EXPECT_EQ(static_cast<size_t>(entry->file_info().size()), | 303 EXPECT_EQ(static_cast<size_t>(entry->file_info().size()), |
303 get_content_callback.GetConcatenatedData().size()); | 304 get_content_callback.GetConcatenatedData().size()); |
(...skipping 12 matching lines...) Expand all Loading... |
316 google_apis::test_util::TestGetContentCallback get_content_callback; | 317 google_apis::test_util::TestGetContentCallback get_content_callback; |
317 FileError completion_error = FILE_ERROR_FAILED; | 318 FileError completion_error = FILE_ERROR_FAILED; |
318 base::Closure cancel_download = operation_->EnsureFileDownloadedByPath( | 319 base::Closure cancel_download = operation_->EnsureFileDownloadedByPath( |
319 file_in_root, | 320 file_in_root, |
320 ClientContext(USER_INITIATED), | 321 ClientContext(USER_INITIATED), |
321 google_apis::test_util::CreateCopyResultCallback( | 322 google_apis::test_util::CreateCopyResultCallback( |
322 &initialized_error, &local_path, &entry), | 323 &initialized_error, &local_path, &entry), |
323 get_content_callback.callback(), | 324 get_content_callback.callback(), |
324 google_apis::test_util::CreateCopyResultCallback( | 325 google_apis::test_util::CreateCopyResultCallback( |
325 &completion_error, &local_path_dontcare, &entry_dontcare)); | 326 &completion_error, &local_path_dontcare, &entry_dontcare)); |
326 test_util::RunBlockingPoolTask(); | 327 content::RunAllBlockingPoolTasksUntilIdle(); |
327 | 328 |
328 // Try second download. In this case, the file should be cached, so | 329 // Try second download. In this case, the file should be cached, so |
329 // |local_path| should not be empty. | 330 // |local_path| should not be empty. |
330 EXPECT_EQ(FILE_ERROR_OK, initialized_error); | 331 EXPECT_EQ(FILE_ERROR_OK, initialized_error); |
331 ASSERT_TRUE(entry); | 332 ASSERT_TRUE(entry); |
332 ASSERT_TRUE(!local_path.empty()); | 333 ASSERT_TRUE(!local_path.empty()); |
333 EXPECT_FALSE(cancel_download.is_null()); | 334 EXPECT_FALSE(cancel_download.is_null()); |
334 // The content is available from the cache file. | 335 // The content is available from the cache file. |
335 EXPECT_TRUE(get_content_callback.data().empty()); | 336 EXPECT_TRUE(get_content_callback.data().empty()); |
336 int64 local_file_size = 0; | 337 int64 local_file_size = 0; |
(...skipping 16 matching lines...) Expand all Loading... |
353 base::PostTaskAndReplyWithResult( | 354 base::PostTaskAndReplyWithResult( |
354 blocking_task_runner(), | 355 blocking_task_runner(), |
355 FROM_HERE, | 356 FROM_HERE, |
356 base::Bind(&internal::FileCache::Store, | 357 base::Bind(&internal::FileCache::Store, |
357 base::Unretained(cache()), | 358 base::Unretained(cache()), |
358 GetLocalId(file_in_root), | 359 GetLocalId(file_in_root), |
359 src_entry.file_specific_info().md5(), | 360 src_entry.file_specific_info().md5(), |
360 temp_file, | 361 temp_file, |
361 internal::FileCache::FILE_OPERATION_COPY), | 362 internal::FileCache::FILE_OPERATION_COPY), |
362 google_apis::test_util::CreateCopyResultCallback(&error)); | 363 google_apis::test_util::CreateCopyResultCallback(&error)); |
363 test_util::RunBlockingPoolTask(); | 364 content::RunAllBlockingPoolTasksUntilIdle(); |
364 EXPECT_EQ(FILE_ERROR_OK, error); | 365 EXPECT_EQ(FILE_ERROR_OK, error); |
365 | 366 |
366 // The file is obtained from the cache. | 367 // The file is obtained from the cache. |
367 // Hence the downloading should work even if the drive service is offline. | 368 // Hence the downloading should work even if the drive service is offline. |
368 fake_service()->set_offline(true); | 369 fake_service()->set_offline(true); |
369 | 370 |
370 base::FilePath file_path; | 371 base::FilePath file_path; |
371 scoped_ptr<ResourceEntry> entry; | 372 scoped_ptr<ResourceEntry> entry; |
372 operation_->EnsureFileDownloadedByLocalId( | 373 operation_->EnsureFileDownloadedByLocalId( |
373 GetLocalId(file_in_root), | 374 GetLocalId(file_in_root), |
374 ClientContext(USER_INITIATED), | 375 ClientContext(USER_INITIATED), |
375 GetFileContentInitializedCallback(), | 376 GetFileContentInitializedCallback(), |
376 google_apis::GetContentCallback(), | 377 google_apis::GetContentCallback(), |
377 google_apis::test_util::CreateCopyResultCallback( | 378 google_apis::test_util::CreateCopyResultCallback( |
378 &error, &file_path, &entry)); | 379 &error, &file_path, &entry)); |
379 test_util::RunBlockingPoolTask(); | 380 content::RunAllBlockingPoolTasksUntilIdle(); |
380 | 381 |
381 EXPECT_EQ(FILE_ERROR_OK, error); | 382 EXPECT_EQ(FILE_ERROR_OK, error); |
382 ASSERT_TRUE(entry); | 383 ASSERT_TRUE(entry); |
383 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 384 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
384 } | 385 } |
385 | 386 |
386 TEST_F(DownloadOperationTest, EnsureFileDownloadedByPath_DirtyCache) { | 387 TEST_F(DownloadOperationTest, EnsureFileDownloadedByPath_DirtyCache) { |
387 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 388 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
388 ResourceEntry src_entry; | 389 ResourceEntry src_entry; |
389 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 390 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
(...skipping 10 matching lines...) Expand all Loading... |
400 base::PostTaskAndReplyWithResult( | 401 base::PostTaskAndReplyWithResult( |
401 blocking_task_runner(), | 402 blocking_task_runner(), |
402 FROM_HERE, | 403 FROM_HERE, |
403 base::Bind(&internal::FileCache::Store, | 404 base::Bind(&internal::FileCache::Store, |
404 base::Unretained(cache()), | 405 base::Unretained(cache()), |
405 GetLocalId(file_in_root), | 406 GetLocalId(file_in_root), |
406 std::string(), | 407 std::string(), |
407 dirty_file, | 408 dirty_file, |
408 internal::FileCache::FILE_OPERATION_COPY), | 409 internal::FileCache::FILE_OPERATION_COPY), |
409 google_apis::test_util::CreateCopyResultCallback(&error)); | 410 google_apis::test_util::CreateCopyResultCallback(&error)); |
410 test_util::RunBlockingPoolTask(); | 411 content::RunAllBlockingPoolTasksUntilIdle(); |
411 EXPECT_EQ(FILE_ERROR_OK, error); | 412 EXPECT_EQ(FILE_ERROR_OK, error); |
412 | 413 |
413 // Record values passed to GetFileContentInitializedCallback(). | 414 // Record values passed to GetFileContentInitializedCallback(). |
414 FileError init_error; | 415 FileError init_error; |
415 base::FilePath init_path; | 416 base::FilePath init_path; |
416 scoped_ptr<ResourceEntry> init_entry; | 417 scoped_ptr<ResourceEntry> init_entry; |
417 base::FilePath file_path; | 418 base::FilePath file_path; |
418 scoped_ptr<ResourceEntry> entry; | 419 scoped_ptr<ResourceEntry> entry; |
419 base::Closure cancel_callback = operation_->EnsureFileDownloadedByPath( | 420 base::Closure cancel_callback = operation_->EnsureFileDownloadedByPath( |
420 file_in_root, | 421 file_in_root, |
421 ClientContext(USER_INITIATED), | 422 ClientContext(USER_INITIATED), |
422 google_apis::test_util::CreateCopyResultCallback( | 423 google_apis::test_util::CreateCopyResultCallback( |
423 &init_error, &init_path, &init_entry), | 424 &init_error, &init_path, &init_entry), |
424 google_apis::GetContentCallback(), | 425 google_apis::GetContentCallback(), |
425 google_apis::test_util::CreateCopyResultCallback( | 426 google_apis::test_util::CreateCopyResultCallback( |
426 &error, &file_path, &entry)); | 427 &error, &file_path, &entry)); |
427 test_util::RunBlockingPoolTask(); | 428 content::RunAllBlockingPoolTasksUntilIdle(); |
428 | 429 |
429 EXPECT_EQ(FILE_ERROR_OK, error); | 430 EXPECT_EQ(FILE_ERROR_OK, error); |
430 // Check that the result of local modification is propagated. | 431 // Check that the result of local modification is propagated. |
431 EXPECT_EQ(static_cast<int64>(dirty_size), init_entry->file_info().size()); | 432 EXPECT_EQ(static_cast<int64>(dirty_size), init_entry->file_info().size()); |
432 EXPECT_EQ(static_cast<int64>(dirty_size), entry->file_info().size()); | 433 EXPECT_EQ(static_cast<int64>(dirty_size), entry->file_info().size()); |
433 } | 434 } |
434 | 435 |
435 TEST_F(DownloadOperationTest, EnsureFileDownloadedByPath_LocallyCreatedFile) { | 436 TEST_F(DownloadOperationTest, EnsureFileDownloadedByPath_LocallyCreatedFile) { |
436 // Add a new file with an empty resource ID. | 437 // Add a new file with an empty resource ID. |
437 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/New File.txt")); | 438 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/New File.txt")); |
438 ResourceEntry parent; | 439 ResourceEntry parent; |
439 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_path.DirName(), &parent)); | 440 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_path.DirName(), &parent)); |
440 | 441 |
441 ResourceEntry new_file; | 442 ResourceEntry new_file; |
442 new_file.set_title("New File.txt"); | 443 new_file.set_title("New File.txt"); |
443 new_file.set_parent_local_id(parent.local_id()); | 444 new_file.set_parent_local_id(parent.local_id()); |
444 | 445 |
445 FileError error = FILE_ERROR_FAILED; | 446 FileError error = FILE_ERROR_FAILED; |
446 std::string local_id; | 447 std::string local_id; |
447 base::PostTaskAndReplyWithResult( | 448 base::PostTaskAndReplyWithResult( |
448 blocking_task_runner(), | 449 blocking_task_runner(), |
449 FROM_HERE, | 450 FROM_HERE, |
450 base::Bind(&internal::ResourceMetadata::AddEntry, | 451 base::Bind(&internal::ResourceMetadata::AddEntry, |
451 base::Unretained(metadata()), | 452 base::Unretained(metadata()), |
452 new_file, | 453 new_file, |
453 &local_id), | 454 &local_id), |
454 google_apis::test_util::CreateCopyResultCallback(&error)); | 455 google_apis::test_util::CreateCopyResultCallback(&error)); |
455 test_util::RunBlockingPoolTask(); | 456 content::RunAllBlockingPoolTasksUntilIdle(); |
456 EXPECT_EQ(FILE_ERROR_OK, error); | 457 EXPECT_EQ(FILE_ERROR_OK, error); |
457 | 458 |
458 // Empty cache file should be returned. | 459 // Empty cache file should be returned. |
459 base::FilePath cache_file_path; | 460 base::FilePath cache_file_path; |
460 scoped_ptr<ResourceEntry> entry; | 461 scoped_ptr<ResourceEntry> entry; |
461 operation_->EnsureFileDownloadedByPath( | 462 operation_->EnsureFileDownloadedByPath( |
462 file_path, | 463 file_path, |
463 ClientContext(USER_INITIATED), | 464 ClientContext(USER_INITIATED), |
464 GetFileContentInitializedCallback(), | 465 GetFileContentInitializedCallback(), |
465 google_apis::GetContentCallback(), | 466 google_apis::GetContentCallback(), |
466 google_apis::test_util::CreateCopyResultCallback( | 467 google_apis::test_util::CreateCopyResultCallback( |
467 &error, &cache_file_path, &entry)); | 468 &error, &cache_file_path, &entry)); |
468 test_util::RunBlockingPoolTask(); | 469 content::RunAllBlockingPoolTasksUntilIdle(); |
469 EXPECT_EQ(FILE_ERROR_OK, error); | 470 EXPECT_EQ(FILE_ERROR_OK, error); |
470 | 471 |
471 int64 cache_file_size = 0; | 472 int64 cache_file_size = 0; |
472 EXPECT_TRUE(base::GetFileSize(cache_file_path, &cache_file_size)); | 473 EXPECT_TRUE(base::GetFileSize(cache_file_path, &cache_file_size)); |
473 EXPECT_EQ(static_cast<int64>(0), cache_file_size); | 474 EXPECT_EQ(static_cast<int64>(0), cache_file_size); |
474 ASSERT_TRUE(entry); | 475 ASSERT_TRUE(entry); |
475 EXPECT_EQ(cache_file_size, entry->file_info().size()); | 476 EXPECT_EQ(cache_file_size, entry->file_info().size()); |
476 } | 477 } |
477 | 478 |
478 TEST_F(DownloadOperationTest, CancelBeforeDownloadStarts) { | 479 TEST_F(DownloadOperationTest, CancelBeforeDownloadStarts) { |
479 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 480 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
480 ResourceEntry src_entry; | 481 ResourceEntry src_entry; |
481 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 482 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
482 | 483 |
483 // Start operation. | 484 // Start operation. |
484 FileError error = FILE_ERROR_OK; | 485 FileError error = FILE_ERROR_OK; |
485 base::FilePath file_path; | 486 base::FilePath file_path; |
486 scoped_ptr<ResourceEntry> entry; | 487 scoped_ptr<ResourceEntry> entry; |
487 base::Closure cancel_closure = operation_->EnsureFileDownloadedByLocalId( | 488 base::Closure cancel_closure = operation_->EnsureFileDownloadedByLocalId( |
488 GetLocalId(file_in_root), | 489 GetLocalId(file_in_root), |
489 ClientContext(USER_INITIATED), | 490 ClientContext(USER_INITIATED), |
490 GetFileContentInitializedCallback(), | 491 GetFileContentInitializedCallback(), |
491 google_apis::GetContentCallback(), | 492 google_apis::GetContentCallback(), |
492 google_apis::test_util::CreateCopyResultCallback( | 493 google_apis::test_util::CreateCopyResultCallback( |
493 &error, &file_path, &entry)); | 494 &error, &file_path, &entry)); |
494 | 495 |
495 // Cancel immediately. | 496 // Cancel immediately. |
496 ASSERT_FALSE(cancel_closure.is_null()); | 497 ASSERT_FALSE(cancel_closure.is_null()); |
497 cancel_closure.Run(); | 498 cancel_closure.Run(); |
498 test_util::RunBlockingPoolTask(); | 499 content::RunAllBlockingPoolTasksUntilIdle(); |
499 | 500 |
500 EXPECT_EQ(FILE_ERROR_ABORT, error); | 501 EXPECT_EQ(FILE_ERROR_ABORT, error); |
501 } | 502 } |
502 | 503 |
503 } // namespace file_system | 504 } // namespace file_system |
504 } // namespace drive | 505 } // namespace drive |
OLD | NEW |