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 28 matching lines...) Expand all Loading... |
39 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
40 | 40 |
41 using ::testing::AnyNumber; | 41 using ::testing::AnyNumber; |
42 using ::testing::AtLeast; | 42 using ::testing::AtLeast; |
43 using ::testing::Eq; | 43 using ::testing::Eq; |
44 using ::testing::NotNull; | 44 using ::testing::NotNull; |
45 using ::testing::Return; | 45 using ::testing::Return; |
46 using ::testing::StrictMock; | 46 using ::testing::StrictMock; |
47 using ::testing::_; | 47 using ::testing::_; |
48 | 48 |
49 namespace gdata { | 49 namespace drive { |
50 namespace { | 50 namespace { |
51 | 51 |
52 const char kSymLinkToDevNull[] = "/dev/null"; | 52 const char kSymLinkToDevNull[] = "/dev/null"; |
53 | 53 |
54 const int64 kLotsOfSpace = kMinFreeSpace * 10; | 54 const int64 kLotsOfSpace = kMinFreeSpace * 10; |
55 | 55 |
56 struct SearchResultPair { | 56 struct SearchResultPair { |
57 const char* path; | 57 const char* path; |
58 const bool is_directory; | 58 const bool is_directory; |
59 }; | 59 }; |
(...skipping 24 matching lines...) Expand all Loading... |
84 // DriveServiceInterface::GetDocumentEntry(). | 84 // DriveServiceInterface::GetDocumentEntry(). |
85 ACTION_P2(MockGetDocumentEntry, status, value) { | 85 ACTION_P2(MockGetDocumentEntry, status, value) { |
86 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 86 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
87 base::Bind(arg1, status, base::Passed(value))); | 87 base::Bind(arg1, status, base::Passed(value))); |
88 } | 88 } |
89 | 89 |
90 // Action used to set mock expectations for | 90 // Action used to set mock expectations for |
91 // DriveUploaderInterface::UploadExistingFile(). | 91 // DriveUploaderInterface::UploadExistingFile(). |
92 ACTION_P4(MockUploadExistingFile, | 92 ACTION_P4(MockUploadExistingFile, |
93 error, drive_path, local_file_path, document_entry) { | 93 error, drive_path, local_file_path, document_entry) { |
94 scoped_ptr<DocumentEntry> scoped_document_entry(document_entry); | 94 scoped_ptr<gdata::DocumentEntry> scoped_document_entry(document_entry); |
95 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 95 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
96 base::Bind(arg5, | 96 base::Bind(arg5, |
97 error, | 97 error, |
98 drive_path, | 98 drive_path, |
99 local_file_path, | 99 local_file_path, |
100 base::Passed(&scoped_document_entry))); | 100 base::Passed(&scoped_document_entry))); |
101 | 101 |
102 const int kUploadId = 123; | 102 const int kUploadId = 123; |
103 return kUploadId; | 103 return kUploadId; |
104 } | 104 } |
105 | 105 |
106 // Action used to set mock expectations for | 106 // Action used to set mock expectations for |
107 // DriveUploaderInterface::UploadNewFile(). | 107 // DriveUploaderInterface::UploadNewFile(). |
108 ACTION(MockUploadNewFile) { | 108 ACTION(MockUploadNewFile) { |
109 scoped_ptr<base::Value> value = | 109 scoped_ptr<base::Value> value = |
110 test_util::LoadJSONFile("gdata/uploaded_file.json"); | 110 gdata::test_util::LoadJSONFile("gdata/uploaded_file.json"); |
111 scoped_ptr<DocumentEntry> document_entry( | 111 scoped_ptr<gdata::DocumentEntry> document_entry( |
112 DocumentEntry::ExtractAndParse(*value)); | 112 gdata::DocumentEntry::ExtractAndParse(*value)); |
113 | 113 |
114 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 114 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
115 base::Bind(arg7, | 115 base::Bind(arg7, |
116 DRIVE_FILE_OK, | 116 DRIVE_FILE_OK, |
117 arg1, | 117 arg1, |
118 arg2, | 118 arg2, |
119 base::Passed(&document_entry))); | 119 base::Passed(&document_entry))); |
120 | 120 |
121 const int kUploadId = 123; | 121 const int kUploadId = 123; |
122 return kUploadId; | 122 return kUploadId; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 blocking_task_runner_); | 197 blocking_task_runner_); |
198 | 198 |
199 mock_cache_observer_.reset(new StrictMock<MockDriveCacheObserver>); | 199 mock_cache_observer_.reset(new StrictMock<MockDriveCacheObserver>); |
200 cache_->AddObserver(mock_cache_observer_.get()); | 200 cache_->AddObserver(mock_cache_observer_.get()); |
201 | 201 |
202 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); | 202 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); |
203 file_system_->AddObserver(mock_directory_observer_.get()); | 203 file_system_->AddObserver(mock_directory_observer_.get()); |
204 | 204 |
205 file_system_->Initialize(); | 205 file_system_->Initialize(); |
206 cache_->RequestInitializeOnUIThreadForTesting(); | 206 cache_->RequestInitializeOnUIThreadForTesting(); |
207 test_util::RunBlockingPoolTask(); | 207 gdata::test_util::RunBlockingPoolTask(); |
208 } | 208 } |
209 | 209 |
210 virtual void TearDown() OVERRIDE { | 210 virtual void TearDown() OVERRIDE { |
211 ASSERT_TRUE(file_system_); | 211 ASSERT_TRUE(file_system_); |
212 EXPECT_CALL(*mock_drive_service_, CancelAll()).Times(1); | 212 EXPECT_CALL(*mock_drive_service_, CancelAll()).Times(1); |
213 delete file_system_; | 213 delete file_system_; |
214 file_system_ = NULL; | 214 file_system_ = NULL; |
215 delete mock_drive_service_; | 215 delete mock_drive_service_; |
216 mock_drive_service_ = NULL; | 216 mock_drive_service_ = NULL; |
217 SetFreeDiskSpaceGetterForTesting(NULL); | 217 SetFreeDiskSpaceGetterForTesting(NULL); |
218 cache_->DestroyOnUIThread(); | 218 cache_->DestroyOnUIThread(); |
219 // The cache destruction requires to post a task to the blocking pool. | 219 // The cache destruction requires to post a task to the blocking pool. |
220 test_util::RunBlockingPoolTask(); | 220 gdata::test_util::RunBlockingPoolTask(); |
221 | 221 |
222 profile_.reset(NULL); | 222 profile_.reset(NULL); |
223 } | 223 } |
224 | 224 |
225 // Loads test json file as root ("/drive") element. | 225 // Loads test json file as root ("/drive") element. |
226 void LoadRootFeedDocument(const std::string& filename) { | 226 void LoadRootFeedDocument(const std::string& filename) { |
227 LoadChangeFeed(filename, 0); | 227 LoadChangeFeed(filename, 0); |
228 } | 228 } |
229 | 229 |
230 void LoadChangeFeed(const std::string& filename, | 230 void LoadChangeFeed(const std::string& filename, |
231 int largest_changestamp) { | 231 int largest_changestamp) { |
232 test_util::LoadChangeFeed(filename, | 232 test_util::LoadChangeFeed(filename, |
233 file_system_, | 233 file_system_, |
234 largest_changestamp, | 234 largest_changestamp, |
235 root_feed_changestamp_); | 235 root_feed_changestamp_); |
236 root_feed_changestamp_++; | 236 root_feed_changestamp_++; |
237 } | 237 } |
238 | 238 |
239 void AddDirectoryFromFile(const FilePath& directory_path, | 239 void AddDirectoryFromFile(const FilePath& directory_path, |
240 const std::string& filename) { | 240 const std::string& filename) { |
241 scoped_ptr<Value> atom = test_util::LoadJSONFile(filename); | 241 scoped_ptr<Value> atom = gdata::test_util::LoadJSONFile(filename); |
242 ASSERT_TRUE(atom.get()); | 242 ASSERT_TRUE(atom.get()); |
243 ASSERT_TRUE(atom->GetType() == Value::TYPE_DICTIONARY); | 243 ASSERT_TRUE(atom->GetType() == Value::TYPE_DICTIONARY); |
244 | 244 |
245 DictionaryValue* dict_value = NULL; | 245 DictionaryValue* dict_value = NULL; |
246 Value* entry_value = NULL; | 246 Value* entry_value = NULL; |
247 ASSERT_TRUE(atom->GetAsDictionary(&dict_value)); | 247 ASSERT_TRUE(atom->GetAsDictionary(&dict_value)); |
248 ASSERT_TRUE(dict_value->Get("entry", &entry_value)); | 248 ASSERT_TRUE(dict_value->Get("entry", &entry_value)); |
249 | 249 |
250 DictionaryValue* entry_dict = NULL; | 250 DictionaryValue* entry_dict = NULL; |
251 ASSERT_TRUE(entry_value->GetAsDictionary(&entry_dict)); | 251 ASSERT_TRUE(entry_value->GetAsDictionary(&entry_dict)); |
252 | 252 |
253 // Tweak entry title to match the last segment of the directory path | 253 // Tweak entry title to match the last segment of the directory path |
254 // (new directory name). | 254 // (new directory name). |
255 std::vector<FilePath::StringType> dir_parts; | 255 std::vector<FilePath::StringType> dir_parts; |
256 directory_path.GetComponents(&dir_parts); | 256 directory_path.GetComponents(&dir_parts); |
257 entry_dict->SetString("title.$t", dir_parts[dir_parts.size() - 1]); | 257 entry_dict->SetString("title.$t", dir_parts[dir_parts.size() - 1]); |
258 | 258 |
259 DriveFileError error; | 259 DriveFileError error; |
260 DriveFileSystem::CreateDirectoryParams params(directory_path, | 260 DriveFileSystem::CreateDirectoryParams params(directory_path, |
261 directory_path, | 261 directory_path, |
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, HTTP_SUCCESS, atom.Pass()); | 265 file_system_->AddNewDirectory(params, gdata::HTTP_SUCCESS, atom.Pass()); |
266 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_, DeleteDocument(_, _)).Times(AnyNumber()); |
273 file_system_->remove_operation_->Remove( | 273 file_system_->remove_operation_->Remove( |
274 file_path, false, | 274 file_path, false, |
275 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); | 275 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); |
276 | 276 |
277 test_util::RunBlockingPoolTask(); | 277 gdata::test_util::RunBlockingPoolTask(); |
278 return error == DRIVE_FILE_OK; | 278 return error == DRIVE_FILE_OK; |
279 } | 279 } |
280 | 280 |
281 FilePath GetCachePathForFile(const std::string& resource_id, | 281 FilePath GetCachePathForFile(const std::string& resource_id, |
282 const std::string& md5) { | 282 const std::string& md5) { |
283 return cache_->GetCacheFilePath(resource_id, | 283 return cache_->GetCacheFilePath(resource_id, |
284 md5, | 284 md5, |
285 DriveCache::CACHE_TYPE_TMP, | 285 DriveCache::CACHE_TYPE_TMP, |
286 DriveCache::CACHED_FILE_FROM_SERVER); | 286 DriveCache::CACHED_FILE_FROM_SERVER); |
287 } | 287 } |
288 | 288 |
289 // Gets entry info by path synchronously. | 289 // Gets entry info by path synchronously. |
290 scoped_ptr<DriveEntryProto> GetEntryInfoByPathSync( | 290 scoped_ptr<DriveEntryProto> GetEntryInfoByPathSync( |
291 const FilePath& file_path) { | 291 const FilePath& file_path) { |
292 file_system_->GetEntryInfoByPath( | 292 file_system_->GetEntryInfoByPath( |
293 file_path, | 293 file_path, |
294 base::Bind(&CallbackHelper::GetEntryInfoCallback, | 294 base::Bind(&CallbackHelper::GetEntryInfoCallback, |
295 callback_helper_.get())); | 295 callback_helper_.get())); |
296 test_util::RunBlockingPoolTask(); | 296 gdata::test_util::RunBlockingPoolTask(); |
297 | 297 |
298 return callback_helper_->entry_proto_.Pass(); | 298 return callback_helper_->entry_proto_.Pass(); |
299 } | 299 } |
300 | 300 |
301 // Gets directory info by path synchronously. | 301 // Gets directory info by path synchronously. |
302 scoped_ptr<DriveEntryProtoVector> ReadDirectoryByPathSync( | 302 scoped_ptr<DriveEntryProtoVector> ReadDirectoryByPathSync( |
303 const FilePath& file_path) { | 303 const FilePath& file_path) { |
304 file_system_->ReadDirectoryByPath( | 304 file_system_->ReadDirectoryByPath( |
305 file_path, | 305 file_path, |
306 base::Bind(&CallbackHelper::ReadDirectoryCallback, | 306 base::Bind(&CallbackHelper::ReadDirectoryCallback, |
307 callback_helper_.get())); | 307 callback_helper_.get())); |
308 test_util::RunBlockingPoolTask(); | 308 gdata::test_util::RunBlockingPoolTask(); |
309 | 309 |
310 return callback_helper_->directory_entries_.Pass(); | 310 return callback_helper_->directory_entries_.Pass(); |
311 } | 311 } |
312 | 312 |
313 // Returns true if an entry exists at |file_path|. | 313 // Returns true if an entry exists at |file_path|. |
314 bool EntryExists(const FilePath& file_path) { | 314 bool EntryExists(const FilePath& file_path) { |
315 return GetEntryInfoByPathSync(file_path).get(); | 315 return GetEntryInfoByPathSync(file_path).get(); |
316 } | 316 } |
317 | 317 |
318 | 318 |
(...skipping 13 matching lines...) Expand all Loading... |
332 DriveCacheEntry* cache_entry) { | 332 DriveCacheEntry* cache_entry) { |
333 bool result = false; | 333 bool result = false; |
334 blocking_task_runner_->PostTask( | 334 blocking_task_runner_->PostTask( |
335 FROM_HERE, | 335 FROM_HERE, |
336 base::Bind(&DriveFileSystemTest::GetCacheEntryFromOriginThreadInternal, | 336 base::Bind(&DriveFileSystemTest::GetCacheEntryFromOriginThreadInternal, |
337 base::Unretained(this), | 337 base::Unretained(this), |
338 resource_id, | 338 resource_id, |
339 md5, | 339 md5, |
340 cache_entry, | 340 cache_entry, |
341 &result)); | 341 &result)); |
342 test_util::RunBlockingPoolTask(); | 342 gdata::test_util::RunBlockingPoolTask(); |
343 return result; | 343 return result; |
344 } | 344 } |
345 | 345 |
346 // Used to implement GetCacheEntry. | 346 // Used to implement GetCacheEntry. |
347 void GetCacheEntryFromOriginThreadInternal( | 347 void GetCacheEntryFromOriginThreadInternal( |
348 const std::string& resource_id, | 348 const std::string& resource_id, |
349 const std::string& md5, | 349 const std::string& md5, |
350 DriveCacheEntry* cache_entry, | 350 DriveCacheEntry* cache_entry, |
351 bool* result) { | 351 bool* result) { |
352 *result = cache_->GetCacheEntry(resource_id, md5, cache_entry); | 352 *result = cache_->GetCacheEntry(resource_id, md5, cache_entry); |
(...skipping 27 matching lines...) Expand all Loading... |
380 expected_error_ = expected_error; | 380 expected_error_ = expected_error; |
381 expected_cache_state_ = expected_cache_state; | 381 expected_cache_state_ = expected_cache_state; |
382 expected_sub_dir_type_ = expected_sub_dir_type; | 382 expected_sub_dir_type_ = expected_sub_dir_type; |
383 | 383 |
384 cache_->StoreOnUIThread( | 384 cache_->StoreOnUIThread( |
385 resource_id, md5, source_path, | 385 resource_id, md5, source_path, |
386 DriveCache::FILE_OPERATION_COPY, | 386 DriveCache::FILE_OPERATION_COPY, |
387 base::Bind(&DriveFileSystemTest::VerifyCacheFileState, | 387 base::Bind(&DriveFileSystemTest::VerifyCacheFileState, |
388 base::Unretained(this))); | 388 base::Unretained(this))); |
389 | 389 |
390 test_util::RunBlockingPoolTask(); | 390 gdata::test_util::RunBlockingPoolTask(); |
391 } | 391 } |
392 | 392 |
393 void TestPin( | 393 void TestPin( |
394 const std::string& resource_id, | 394 const std::string& resource_id, |
395 const std::string& md5, | 395 const std::string& md5, |
396 DriveFileError expected_error, | 396 DriveFileError expected_error, |
397 int expected_cache_state, | 397 int expected_cache_state, |
398 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { | 398 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { |
399 expected_error_ = expected_error; | 399 expected_error_ = expected_error; |
400 expected_cache_state_ = expected_cache_state; | 400 expected_cache_state_ = expected_cache_state; |
401 expected_sub_dir_type_ = expected_sub_dir_type; | 401 expected_sub_dir_type_ = expected_sub_dir_type; |
402 | 402 |
403 cache_->PinOnUIThread( | 403 cache_->PinOnUIThread( |
404 resource_id, md5, | 404 resource_id, md5, |
405 base::Bind(&DriveFileSystemTest::VerifyCacheFileState, | 405 base::Bind(&DriveFileSystemTest::VerifyCacheFileState, |
406 base::Unretained(this))); | 406 base::Unretained(this))); |
407 | 407 |
408 test_util::RunBlockingPoolTask(); | 408 gdata::test_util::RunBlockingPoolTask(); |
409 } | 409 } |
410 | 410 |
411 void TestMarkDirty( | 411 void TestMarkDirty( |
412 const std::string& resource_id, | 412 const std::string& resource_id, |
413 const std::string& md5, | 413 const std::string& md5, |
414 DriveFileError expected_error, | 414 DriveFileError expected_error, |
415 int expected_cache_state, | 415 int expected_cache_state, |
416 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { | 416 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { |
417 expected_error_ = expected_error; | 417 expected_error_ = expected_error; |
418 expected_cache_state_ = expected_cache_state; | 418 expected_cache_state_ = expected_cache_state; |
419 expected_sub_dir_type_ = expected_sub_dir_type; | 419 expected_sub_dir_type_ = expected_sub_dir_type; |
420 expect_outgoing_symlink_ = false; | 420 expect_outgoing_symlink_ = false; |
421 | 421 |
422 cache_->MarkDirtyOnUIThread( | 422 cache_->MarkDirtyOnUIThread( |
423 resource_id, | 423 resource_id, |
424 md5, | 424 md5, |
425 base::Bind(&DriveFileSystemTest::VerifyMarkDirty, | 425 base::Bind(&DriveFileSystemTest::VerifyMarkDirty, |
426 base::Unretained(this), | 426 base::Unretained(this), |
427 resource_id, | 427 resource_id, |
428 md5)); | 428 md5)); |
429 | 429 |
430 test_util::RunBlockingPoolTask(); | 430 gdata::test_util::RunBlockingPoolTask(); |
431 } | 431 } |
432 | 432 |
433 void VerifyMarkDirty(const std::string& resource_id, | 433 void VerifyMarkDirty(const std::string& resource_id, |
434 const std::string& md5, | 434 const std::string& md5, |
435 DriveFileError error, | 435 DriveFileError error, |
436 const FilePath& cache_file_path) { | 436 const FilePath& cache_file_path) { |
437 VerifyCacheFileState(error, resource_id, md5); | 437 VerifyCacheFileState(error, resource_id, md5); |
438 | 438 |
439 // Verify filename of |cache_file_path|. | 439 // Verify filename of |cache_file_path|. |
440 if (error == DRIVE_FILE_OK) { | 440 if (error == DRIVE_FILE_OK) { |
(...skipping 16 matching lines...) Expand all Loading... |
457 expected_error_ = expected_error; | 457 expected_error_ = expected_error; |
458 expected_cache_state_ = expected_cache_state; | 458 expected_cache_state_ = expected_cache_state; |
459 expected_sub_dir_type_ = expected_sub_dir_type; | 459 expected_sub_dir_type_ = expected_sub_dir_type; |
460 expect_outgoing_symlink_ = true; | 460 expect_outgoing_symlink_ = true; |
461 | 461 |
462 cache_->CommitDirtyOnUIThread( | 462 cache_->CommitDirtyOnUIThread( |
463 resource_id, md5, | 463 resource_id, md5, |
464 base::Bind(&DriveFileSystemTest::VerifyCacheFileState, | 464 base::Bind(&DriveFileSystemTest::VerifyCacheFileState, |
465 base::Unretained(this))); | 465 base::Unretained(this))); |
466 | 466 |
467 test_util::RunBlockingPoolTask(); | 467 gdata::test_util::RunBlockingPoolTask(); |
468 } | 468 } |
469 | 469 |
470 // Verify the file identified by |resource_id| and |md5| is in the expected | 470 // Verify the file identified by |resource_id| and |md5| is in the expected |
471 // cache state after |OpenFile|, that is, marked dirty and has no outgoing | 471 // cache state after |OpenFile|, that is, marked dirty and has no outgoing |
472 // symlink, etc. | 472 // symlink, etc. |
473 void VerifyCacheStateAfterOpenFile(DriveFileError error, | 473 void VerifyCacheStateAfterOpenFile(DriveFileError error, |
474 const std::string& resource_id, | 474 const std::string& resource_id, |
475 const std::string& md5, | 475 const std::string& md5, |
476 const FilePath& cache_file_path) { | 476 const FilePath& cache_file_path) { |
477 expected_error_ = DRIVE_FILE_OK; | 477 expected_error_ = DRIVE_FILE_OK; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 void SetExpectationsForGetDocumentEntry(scoped_ptr<base::Value>* document, | 582 void SetExpectationsForGetDocumentEntry(scoped_ptr<base::Value>* document, |
583 const std::string& resource_id) { | 583 const std::string& resource_id) { |
584 EXPECT_CALL(*mock_drive_service_, GetDocumentEntry(resource_id, _)) | 584 EXPECT_CALL(*mock_drive_service_, GetDocumentEntry(resource_id, _)) |
585 .WillOnce(MockGetDocumentEntry(gdata::HTTP_SUCCESS, document)); | 585 .WillOnce(MockGetDocumentEntry(gdata::HTTP_SUCCESS, document)); |
586 } | 586 } |
587 | 587 |
588 // Loads serialized proto file from GCache, and makes sure the root | 588 // Loads serialized proto file from GCache, and makes sure the root |
589 // filesystem has a root at 'drive' | 589 // filesystem has a root at 'drive' |
590 void TestLoadMetadataFromCache() { | 590 void TestLoadMetadataFromCache() { |
591 file_system_->LoadRootFeedFromCacheForTesting(); | 591 file_system_->LoadRootFeedFromCacheForTesting(); |
592 test_util::RunBlockingPoolTask(); | 592 gdata::test_util::RunBlockingPoolTask(); |
593 } | 593 } |
594 | 594 |
595 // Creates a proto file representing a filesystem with directories: | 595 // Creates a proto file representing a filesystem with directories: |
596 // drive, drive/Dir1, drive/Dir1/SubDir2 | 596 // drive, drive/Dir1, drive/Dir1/SubDir2 |
597 // and files | 597 // and files |
598 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3. | 598 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3. |
599 // Sets the changestamp to 654321, equal to that of "account_metadata.json" | 599 // Sets the changestamp to 654321, equal to that of "account_metadata.json" |
600 // test data, indicating the cache is holding the latest file system info. | 600 // test data, indicating the cache is holding the latest file system info. |
601 void SaveTestFileSystem() { | 601 void SaveTestFileSystem() { |
602 DriveRootDirectoryProto root; | 602 DriveRootDirectoryProto root; |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 EXPECT_TRUE(EntryExists( | 1168 EXPECT_TRUE(EntryExists( |
1169 FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2/File3")))); | 1169 FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2/File3")))); |
1170 } | 1170 } |
1171 | 1171 |
1172 TEST_F(DriveFileSystemTest, CachedFeadLoadingThenServerFeedLoading) { | 1172 TEST_F(DriveFileSystemTest, CachedFeadLoadingThenServerFeedLoading) { |
1173 SaveTestFileSystem(); | 1173 SaveTestFileSystem(); |
1174 | 1174 |
1175 // SaveTestFileSystem and "account_metadata.json" have the same changestamp, | 1175 // SaveTestFileSystem and "account_metadata.json" have the same changestamp, |
1176 // so no request for new feeds (i.e., call to GetDocuments) should happen. | 1176 // so no request for new feeds (i.e., call to GetDocuments) should happen. |
1177 mock_drive_service_->set_account_metadata( | 1177 mock_drive_service_->set_account_metadata( |
1178 test_util::LoadJSONFile("gdata/account_metadata.json").release()); | 1178 gdata::test_util::LoadJSONFile("gdata/account_metadata.json").release()); |
1179 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); | 1179 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); |
1180 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); | 1180 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); |
1181 EXPECT_CALL(*mock_drive_service_, GetDocuments(_, _, _, _, _)).Times(0); | 1181 EXPECT_CALL(*mock_drive_service_, GetDocuments(_, _, _, _, _)).Times(0); |
1182 | 1182 |
1183 // Kicks loading of cached file system and query for server update. | 1183 // Kicks loading of cached file system and query for server update. |
1184 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1")))); | 1184 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1")))); |
1185 | 1185 |
1186 // Since the file system has verified that it holds the latest snapshot, | 1186 // Since the file system has verified that it holds the latest snapshot, |
1187 // it should change its state to FROM_SERVER, which admits periodic refresh. | 1187 // it should change its state to FROM_SERVER, which admits periodic refresh. |
1188 // To test it, call CheckForUpdates and verify it does try to check updates. | 1188 // To test it, call CheckForUpdates and verify it does try to check updates. |
1189 mock_drive_service_->set_account_metadata( | 1189 mock_drive_service_->set_account_metadata( |
1190 test_util::LoadJSONFile("gdata/account_metadata.json").release()); | 1190 gdata::test_util::LoadJSONFile("gdata/account_metadata.json").release()); |
1191 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); | 1191 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); |
1192 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); | 1192 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); |
1193 | 1193 |
1194 file_system_->CheckForUpdates(); | 1194 file_system_->CheckForUpdates(); |
1195 test_util::RunBlockingPoolTask(); | 1195 gdata::test_util::RunBlockingPoolTask(); |
1196 } | 1196 } |
1197 | 1197 |
1198 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { | 1198 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { |
1199 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 1199 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
1200 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); | 1200 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); |
1201 | 1201 |
1202 LoadRootFeedDocument("gdata/root_feed.json"); | 1202 LoadRootFeedDocument("gdata/root_feed.json"); |
1203 | 1203 |
1204 // We'll add a file to the Drive root directory. | 1204 // We'll add a file to the Drive root directory. |
1205 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1205 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1206 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1206 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
1207 | 1207 |
1208 FileOperationCallback callback = | 1208 FileOperationCallback callback = |
1209 base::Bind(&CallbackHelper::FileOperationCallback, | 1209 base::Bind(&CallbackHelper::FileOperationCallback, |
1210 callback_helper_.get()); | 1210 callback_helper_.get()); |
1211 | 1211 |
1212 // Prepare a local file. | 1212 // Prepare a local file. |
1213 ScopedTempDir temp_dir; | 1213 ScopedTempDir temp_dir; |
1214 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1214 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1215 const FilePath local_src_file_path = temp_dir.path().Append("local.txt"); | 1215 const FilePath local_src_file_path = temp_dir.path().Append("local.txt"); |
1216 const std::string kContent = "hello"; | 1216 const std::string kContent = "hello"; |
1217 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); | 1217 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); |
1218 | 1218 |
1219 // Confirm that the remote file does not exist. | 1219 // Confirm that the remote file does not exist. |
1220 const FilePath remote_dest_file_path(FILE_PATH_LITERAL("drive/remote.txt")); | 1220 const FilePath remote_dest_file_path(FILE_PATH_LITERAL("drive/remote.txt")); |
1221 EXPECT_FALSE(EntryExists(remote_dest_file_path)); | 1221 EXPECT_FALSE(EntryExists(remote_dest_file_path)); |
1222 | 1222 |
1223 scoped_ptr<base::Value> value = | 1223 scoped_ptr<base::Value> value = |
1224 test_util::LoadJSONFile("gdata/document_to_download.json"); | 1224 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
1225 scoped_ptr<DocumentEntry> document_entry( | 1225 scoped_ptr<gdata::DocumentEntry> document_entry( |
1226 DocumentEntry::ExtractAndParse(*value)); | 1226 gdata::DocumentEntry::ExtractAndParse(*value)); |
1227 | 1227 |
1228 EXPECT_CALL(*mock_uploader_, UploadNewFile(_, _, _, _, _, _, _, _, _)) | 1228 EXPECT_CALL(*mock_uploader_, UploadNewFile(_, _, _, _, _, _, _, _, _)) |
1229 .WillOnce(MockUploadNewFile()); | 1229 .WillOnce(MockUploadNewFile()); |
1230 | 1230 |
1231 // Transfer the local file to Drive. | 1231 // Transfer the local file to Drive. |
1232 file_system_->TransferFileFromLocalToRemote( | 1232 file_system_->TransferFileFromLocalToRemote( |
1233 local_src_file_path, remote_dest_file_path, callback); | 1233 local_src_file_path, remote_dest_file_path, callback); |
1234 test_util::RunBlockingPoolTask(); | 1234 gdata::test_util::RunBlockingPoolTask(); |
1235 | 1235 |
1236 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 1236 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
1237 | 1237 |
1238 // Now the remote file should exist. | 1238 // Now the remote file should exist. |
1239 EXPECT_TRUE(EntryExists(remote_dest_file_path)); | 1239 EXPECT_TRUE(EntryExists(remote_dest_file_path)); |
1240 } | 1240 } |
1241 | 1241 |
1242 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_HostedDocument) { | 1242 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_HostedDocument) { |
1243 LoadRootFeedDocument("gdata/root_feed.json"); | 1243 LoadRootFeedDocument("gdata/root_feed.json"); |
1244 | 1244 |
(...skipping 15 matching lines...) Expand all Loading... |
1260 FILE_PATH_LITERAL("drive/Directory 1/Document 1.gdoc")); | 1260 FILE_PATH_LITERAL("drive/Directory 1/Document 1.gdoc")); |
1261 EXPECT_FALSE(EntryExists(remote_dest_file_path)); | 1261 EXPECT_FALSE(EntryExists(remote_dest_file_path)); |
1262 | 1262 |
1263 // We'll add a file to "Directory 1" directory on Drive. | 1263 // We'll add a file to "Directory 1" directory on Drive. |
1264 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1264 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1265 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1265 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
1266 | 1266 |
1267 // We'll copy a hosted document using CopyDocument. | 1267 // We'll copy a hosted document using CopyDocument. |
1268 // ".gdoc" suffix should be stripped when copying. | 1268 // ".gdoc" suffix should be stripped when copying. |
1269 scoped_ptr<base::Value> document = | 1269 scoped_ptr<base::Value> document = |
1270 test_util::LoadJSONFile("gdata/uploaded_document.json"); | 1270 gdata::test_util::LoadJSONFile("gdata/uploaded_document.json"); |
1271 EXPECT_CALL(*mock_drive_service_, | 1271 EXPECT_CALL(*mock_drive_service_, |
1272 CopyDocument(kResourceId, | 1272 CopyDocument(kResourceId, |
1273 FILE_PATH_LITERAL("Document 1"), | 1273 FILE_PATH_LITERAL("Document 1"), |
1274 _)) | 1274 _)) |
1275 .WillOnce(MockCopyDocument(gdata::HTTP_SUCCESS, &document)); | 1275 .WillOnce(MockCopyDocument(gdata::HTTP_SUCCESS, &document)); |
1276 // We'll then add the hosted document to the destination directory. | 1276 // We'll then add the hosted document to the destination directory. |
1277 EXPECT_CALL(*mock_drive_service_, | 1277 EXPECT_CALL(*mock_drive_service_, |
1278 AddResourceToDirectory(_, _, _)).Times(1); | 1278 AddResourceToDirectory(_, _, _)).Times(1); |
1279 | 1279 |
1280 FileOperationCallback callback = | 1280 FileOperationCallback callback = |
1281 base::Bind(&CallbackHelper::FileOperationCallback, | 1281 base::Bind(&CallbackHelper::FileOperationCallback, |
1282 callback_helper_.get()); | 1282 callback_helper_.get()); |
1283 | 1283 |
1284 // Transfer the local file to Drive. | 1284 // Transfer the local file to Drive. |
1285 file_system_->TransferFileFromLocalToRemote( | 1285 file_system_->TransferFileFromLocalToRemote( |
1286 local_src_file_path, remote_dest_file_path, callback); | 1286 local_src_file_path, remote_dest_file_path, callback); |
1287 test_util::RunBlockingPoolTask(); | 1287 gdata::test_util::RunBlockingPoolTask(); |
1288 | 1288 |
1289 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 1289 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
1290 | 1290 |
1291 // Now the remote file should exist. | 1291 // Now the remote file should exist. |
1292 EXPECT_TRUE(EntryExists(remote_dest_file_path)); | 1292 EXPECT_TRUE(EntryExists(remote_dest_file_path)); |
1293 } | 1293 } |
1294 | 1294 |
1295 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { | 1295 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { |
1296 LoadRootFeedDocument("gdata/root_feed.json"); | 1296 LoadRootFeedDocument("gdata/root_feed.json"); |
1297 | 1297 |
(...skipping 16 matching lines...) Expand all Loading... |
1314 // Pretend we have enough space. | 1314 // Pretend we have enough space. |
1315 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 1315 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
1316 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); | 1316 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); |
1317 | 1317 |
1318 const std::string remote_src_file_data = "Test file data"; | 1318 const std::string remote_src_file_data = "Test file data"; |
1319 mock_drive_service_->set_file_data(new std::string(remote_src_file_data)); | 1319 mock_drive_service_->set_file_data(new std::string(remote_src_file_data)); |
1320 | 1320 |
1321 // Before Download starts metadata from server will be fetched. | 1321 // Before Download starts metadata from server will be fetched. |
1322 // We will read content url from the result. | 1322 // We will read content url from the result. |
1323 scoped_ptr<base::Value> document = | 1323 scoped_ptr<base::Value> document = |
1324 test_util::LoadJSONFile("gdata/document_to_download.json"); | 1324 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
1325 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 1325 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
1326 | 1326 |
1327 // The file is obtained with the mock DriveService. | 1327 // The file is obtained with the mock DriveService. |
1328 EXPECT_CALL(*mock_drive_service_, | 1328 EXPECT_CALL(*mock_drive_service_, |
1329 DownloadFile(remote_src_file_path, | 1329 DownloadFile(remote_src_file_path, |
1330 cache_file, | 1330 cache_file, |
1331 GURL("https://file_content_url_changed/"), | 1331 GURL("https://file_content_url_changed/"), |
1332 _, _)) | 1332 _, _)) |
1333 .Times(1); | 1333 .Times(1); |
1334 | 1334 |
1335 file_system_->TransferFileFromRemoteToLocal( | 1335 file_system_->TransferFileFromRemoteToLocal( |
1336 remote_src_file_path, local_dest_file_path, callback); | 1336 remote_src_file_path, local_dest_file_path, callback); |
1337 test_util::RunBlockingPoolTask(); | 1337 gdata::test_util::RunBlockingPoolTask(); |
1338 | 1338 |
1339 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 1339 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
1340 | 1340 |
1341 std::string cache_file_data; | 1341 std::string cache_file_data; |
1342 EXPECT_TRUE(file_util::ReadFileToString(cache_file, &cache_file_data)); | 1342 EXPECT_TRUE(file_util::ReadFileToString(cache_file, &cache_file_data)); |
1343 EXPECT_EQ(remote_src_file_data, cache_file_data); | 1343 EXPECT_EQ(remote_src_file_data, cache_file_data); |
1344 | 1344 |
1345 std::string local_dest_file_data; | 1345 std::string local_dest_file_data; |
1346 EXPECT_TRUE(file_util::ReadFileToString(local_dest_file_path, | 1346 EXPECT_TRUE(file_util::ReadFileToString(local_dest_file_path, |
1347 &local_dest_file_data)); | 1347 &local_dest_file_data)); |
1348 EXPECT_EQ(remote_src_file_data, local_dest_file_data); | 1348 EXPECT_EQ(remote_src_file_data, local_dest_file_data); |
1349 } | 1349 } |
1350 | 1350 |
1351 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { | 1351 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { |
1352 LoadRootFeedDocument("gdata/root_feed.json"); | 1352 LoadRootFeedDocument("gdata/root_feed.json"); |
1353 | 1353 |
1354 FileOperationCallback callback = | 1354 FileOperationCallback callback = |
1355 base::Bind(&CallbackHelper::FileOperationCallback, | 1355 base::Bind(&CallbackHelper::FileOperationCallback, |
1356 callback_helper_.get()); | 1356 callback_helper_.get()); |
1357 | 1357 |
1358 ScopedTempDir temp_dir; | 1358 ScopedTempDir temp_dir; |
1359 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1359 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1360 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt"); | 1360 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt"); |
1361 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc")); | 1361 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc")); |
1362 file_system_->TransferFileFromRemoteToLocal( | 1362 file_system_->TransferFileFromRemoteToLocal( |
1363 remote_src_file_path, local_dest_file_path, callback); | 1363 remote_src_file_path, local_dest_file_path, callback); |
1364 test_util::RunBlockingPoolTask(); | 1364 gdata::test_util::RunBlockingPoolTask(); |
1365 | 1365 |
1366 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 1366 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
1367 | 1367 |
1368 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync( | 1368 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync( |
1369 remote_src_file_path); | 1369 remote_src_file_path); |
1370 ASSERT_TRUE(entry_proto.get()); | 1370 ASSERT_TRUE(entry_proto.get()); |
1371 VerifyHostedDocumentJSONFile(*entry_proto, local_dest_file_path); | 1371 VerifyHostedDocumentJSONFile(*entry_proto, local_dest_file_path); |
1372 } | 1372 } |
1373 | 1373 |
1374 TEST_F(DriveFileSystemTest, CopyNotExistingFile) { | 1374 TEST_F(DriveFileSystemTest, CopyNotExistingFile) { |
1375 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); | 1375 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); |
1376 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); | 1376 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); |
1377 | 1377 |
1378 LoadRootFeedDocument("gdata/root_feed.json"); | 1378 LoadRootFeedDocument("gdata/root_feed.json"); |
1379 | 1379 |
1380 EXPECT_FALSE(EntryExists(src_file_path)); | 1380 EXPECT_FALSE(EntryExists(src_file_path)); |
1381 | 1381 |
1382 FileOperationCallback callback = | 1382 FileOperationCallback callback = |
1383 base::Bind(&CallbackHelper::FileOperationCallback, | 1383 base::Bind(&CallbackHelper::FileOperationCallback, |
1384 callback_helper_.get()); | 1384 callback_helper_.get()); |
1385 | 1385 |
1386 file_system_->Copy(src_file_path, dest_file_path, callback); | 1386 file_system_->Copy(src_file_path, dest_file_path, callback); |
1387 test_util::RunBlockingPoolTask(); | 1387 gdata::test_util::RunBlockingPoolTask(); |
1388 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 1388 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
1389 | 1389 |
1390 EXPECT_FALSE(EntryExists(src_file_path)); | 1390 EXPECT_FALSE(EntryExists(src_file_path)); |
1391 EXPECT_FALSE(EntryExists(dest_file_path)); | 1391 EXPECT_FALSE(EntryExists(dest_file_path)); |
1392 } | 1392 } |
1393 | 1393 |
1394 TEST_F(DriveFileSystemTest, CopyFileToNonExistingDirectory) { | 1394 TEST_F(DriveFileSystemTest, CopyFileToNonExistingDirectory) { |
1395 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1395 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); |
1396 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); | 1396 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); |
1397 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); | 1397 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); |
1398 | 1398 |
1399 LoadRootFeedDocument("gdata/root_feed.json"); | 1399 LoadRootFeedDocument("gdata/root_feed.json"); |
1400 | 1400 |
1401 ASSERT_TRUE(EntryExists(src_file_path)); | 1401 ASSERT_TRUE(EntryExists(src_file_path)); |
1402 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1402 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
1403 src_file_path); | 1403 src_file_path); |
1404 ASSERT_TRUE(src_entry_proto.get()); | 1404 ASSERT_TRUE(src_entry_proto.get()); |
1405 std::string src_file_path_resource_id = | 1405 std::string src_file_path_resource_id = |
1406 src_entry_proto->resource_id(); | 1406 src_entry_proto->resource_id(); |
1407 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1407 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
1408 | 1408 |
1409 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1409 EXPECT_FALSE(EntryExists(dest_parent_path)); |
1410 | 1410 |
1411 FileOperationCallback callback = | 1411 FileOperationCallback callback = |
1412 base::Bind(&CallbackHelper::FileOperationCallback, | 1412 base::Bind(&CallbackHelper::FileOperationCallback, |
1413 callback_helper_.get()); | 1413 callback_helper_.get()); |
1414 | 1414 |
1415 file_system_->Move(src_file_path, dest_file_path, callback); | 1415 file_system_->Move(src_file_path, dest_file_path, callback); |
1416 test_util::RunBlockingPoolTask(); | 1416 gdata::test_util::RunBlockingPoolTask(); |
1417 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 1417 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
1418 | 1418 |
1419 EXPECT_TRUE(EntryExists(src_file_path)); | 1419 EXPECT_TRUE(EntryExists(src_file_path)); |
1420 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1420 EXPECT_FALSE(EntryExists(dest_parent_path)); |
1421 EXPECT_FALSE(EntryExists(dest_file_path)); | 1421 EXPECT_FALSE(EntryExists(dest_file_path)); |
1422 } | 1422 } |
1423 | 1423 |
1424 // Test the case where the parent of |dest_file_path| is an existing file, | 1424 // Test the case where the parent of |dest_file_path| is an existing file, |
1425 // not a directory. | 1425 // not a directory. |
1426 TEST_F(DriveFileSystemTest, CopyFileToInvalidPath) { | 1426 TEST_F(DriveFileSystemTest, CopyFileToInvalidPath) { |
(...skipping 15 matching lines...) Expand all Loading... |
1442 ASSERT_TRUE(EntryExists(dest_parent_path)); | 1442 ASSERT_TRUE(EntryExists(dest_parent_path)); |
1443 scoped_ptr<DriveEntryProto> dest_entry_proto = GetEntryInfoByPathSync( | 1443 scoped_ptr<DriveEntryProto> dest_entry_proto = GetEntryInfoByPathSync( |
1444 dest_parent_path); | 1444 dest_parent_path); |
1445 ASSERT_TRUE(dest_entry_proto.get()); | 1445 ASSERT_TRUE(dest_entry_proto.get()); |
1446 | 1446 |
1447 FileOperationCallback callback = | 1447 FileOperationCallback callback = |
1448 base::Bind(&CallbackHelper::FileOperationCallback, | 1448 base::Bind(&CallbackHelper::FileOperationCallback, |
1449 callback_helper_.get()); | 1449 callback_helper_.get()); |
1450 | 1450 |
1451 file_system_->Copy(src_file_path, dest_file_path, callback); | 1451 file_system_->Copy(src_file_path, dest_file_path, callback); |
1452 test_util::RunBlockingPoolTask(); | 1452 gdata::test_util::RunBlockingPoolTask(); |
1453 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, | 1453 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, |
1454 callback_helper_->last_error_); | 1454 callback_helper_->last_error_); |
1455 | 1455 |
1456 EXPECT_TRUE(EntryExists(src_file_path)); | 1456 EXPECT_TRUE(EntryExists(src_file_path)); |
1457 EXPECT_TRUE(EntryExists(src_file_path)); | 1457 EXPECT_TRUE(EntryExists(src_file_path)); |
1458 EXPECT_TRUE(EntryExists(dest_parent_path)); | 1458 EXPECT_TRUE(EntryExists(dest_parent_path)); |
1459 | 1459 |
1460 EXPECT_FALSE(EntryExists(dest_file_path)); | 1460 EXPECT_FALSE(EntryExists(dest_file_path)); |
1461 } | 1461 } |
1462 | 1462 |
(...skipping 18 matching lines...) Expand all Loading... |
1481 FILE_PATH_LITERAL("Test.log"), _)); | 1481 FILE_PATH_LITERAL("Test.log"), _)); |
1482 | 1482 |
1483 FileOperationCallback callback = | 1483 FileOperationCallback callback = |
1484 base::Bind(&CallbackHelper::FileOperationCallback, | 1484 base::Bind(&CallbackHelper::FileOperationCallback, |
1485 callback_helper_.get()); | 1485 callback_helper_.get()); |
1486 | 1486 |
1487 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1487 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1488 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1488 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
1489 | 1489 |
1490 file_system_->Move(src_file_path, dest_file_path, callback); | 1490 file_system_->Move(src_file_path, dest_file_path, callback); |
1491 test_util::RunBlockingPoolTask(); | 1491 gdata::test_util::RunBlockingPoolTask(); |
1492 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 1492 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
1493 | 1493 |
1494 EXPECT_FALSE(EntryExists(src_file_path)); | 1494 EXPECT_FALSE(EntryExists(src_file_path)); |
1495 EXPECT_TRUE(EntryExists(dest_file_path)); | 1495 EXPECT_TRUE(EntryExists(dest_file_path)); |
1496 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1496 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
1497 } | 1497 } |
1498 | 1498 |
1499 TEST_F(DriveFileSystemTest, MoveFileFromRootToSubDirectory) { | 1499 TEST_F(DriveFileSystemTest, MoveFileFromRootToSubDirectory) { |
1500 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1500 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); |
1501 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1501 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); |
(...skipping 28 matching lines...) Expand all Loading... |
1530 base::Bind(&CallbackHelper::FileOperationCallback, | 1530 base::Bind(&CallbackHelper::FileOperationCallback, |
1531 callback_helper_.get()); | 1531 callback_helper_.get()); |
1532 | 1532 |
1533 // Expect notification for both source and destination directories. | 1533 // Expect notification for both source and destination directories. |
1534 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1534 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1535 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1535 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
1536 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1536 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1537 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1537 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
1538 | 1538 |
1539 file_system_->Move(src_file_path, dest_file_path, callback); | 1539 file_system_->Move(src_file_path, dest_file_path, callback); |
1540 test_util::RunBlockingPoolTask(); | 1540 gdata::test_util::RunBlockingPoolTask(); |
1541 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 1541 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
1542 | 1542 |
1543 EXPECT_FALSE(EntryExists(src_file_path)); | 1543 EXPECT_FALSE(EntryExists(src_file_path)); |
1544 EXPECT_TRUE(EntryExists(dest_file_path)); | 1544 EXPECT_TRUE(EntryExists(dest_file_path)); |
1545 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1545 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
1546 } | 1546 } |
1547 | 1547 |
1548 TEST_F(DriveFileSystemTest, MoveFileFromSubDirectoryToRoot) { | 1548 TEST_F(DriveFileSystemTest, MoveFileFromSubDirectoryToRoot) { |
1549 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1549 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); |
1550 FilePath src_file_path( | 1550 FilePath src_file_path( |
(...skipping 30 matching lines...) Expand all Loading... |
1581 base::Bind(&CallbackHelper::FileOperationCallback, | 1581 base::Bind(&CallbackHelper::FileOperationCallback, |
1582 callback_helper_.get()); | 1582 callback_helper_.get()); |
1583 | 1583 |
1584 // Expect notification for both source and destination directories. | 1584 // Expect notification for both source and destination directories. |
1585 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1585 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1586 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1586 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
1587 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1587 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1588 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1588 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
1589 | 1589 |
1590 file_system_->Move(src_file_path, dest_file_path, callback); | 1590 file_system_->Move(src_file_path, dest_file_path, callback); |
1591 test_util::RunBlockingPoolTask(); | 1591 gdata::test_util::RunBlockingPoolTask(); |
1592 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 1592 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
1593 | 1593 |
1594 EXPECT_FALSE(EntryExists(src_file_path)); | 1594 EXPECT_FALSE(EntryExists(src_file_path)); |
1595 ASSERT_TRUE(EntryExists(dest_file_path)); | 1595 ASSERT_TRUE(EntryExists(dest_file_path)); |
1596 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1596 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
1597 } | 1597 } |
1598 | 1598 |
1599 TEST_F(DriveFileSystemTest, MoveFileBetweenSubDirectories) { | 1599 TEST_F(DriveFileSystemTest, MoveFileBetweenSubDirectories) { |
1600 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1600 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); |
1601 FilePath src_file_path( | 1601 FilePath src_file_path( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1656 // Expect notification for both source and destination directories plus | 1656 // Expect notification for both source and destination directories plus |
1657 // interim file path. | 1657 // interim file path. |
1658 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1658 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1659 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1659 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
1660 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1660 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1661 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1661 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
1662 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1662 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1663 Eq(FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); | 1663 Eq(FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); |
1664 | 1664 |
1665 file_system_->Move(src_file_path, dest_file_path, callback); | 1665 file_system_->Move(src_file_path, dest_file_path, callback); |
1666 test_util::RunBlockingPoolTask(); | 1666 gdata::test_util::RunBlockingPoolTask(); |
1667 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 1667 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
1668 | 1668 |
1669 EXPECT_FALSE(EntryExists(src_file_path)); | 1669 EXPECT_FALSE(EntryExists(src_file_path)); |
1670 EXPECT_FALSE(EntryExists(interim_file_path)); | 1670 EXPECT_FALSE(EntryExists(interim_file_path)); |
1671 | 1671 |
1672 EXPECT_FALSE(EntryExists(src_file_path)); | 1672 EXPECT_FALSE(EntryExists(src_file_path)); |
1673 EXPECT_TRUE(EntryExists(dest_file_path)); | 1673 EXPECT_TRUE(EntryExists(dest_file_path)); |
1674 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1674 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
1675 } | 1675 } |
1676 | 1676 |
1677 TEST_F(DriveFileSystemTest, MoveNotExistingFile) { | 1677 TEST_F(DriveFileSystemTest, MoveNotExistingFile) { |
1678 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); | 1678 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); |
1679 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); | 1679 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); |
1680 | 1680 |
1681 LoadRootFeedDocument("gdata/root_feed.json"); | 1681 LoadRootFeedDocument("gdata/root_feed.json"); |
1682 | 1682 |
1683 EXPECT_FALSE(EntryExists(src_file_path)); | 1683 EXPECT_FALSE(EntryExists(src_file_path)); |
1684 | 1684 |
1685 FileOperationCallback callback = | 1685 FileOperationCallback callback = |
1686 base::Bind(&CallbackHelper::FileOperationCallback, | 1686 base::Bind(&CallbackHelper::FileOperationCallback, |
1687 callback_helper_.get()); | 1687 callback_helper_.get()); |
1688 | 1688 |
1689 file_system_->Move(src_file_path, dest_file_path, callback); | 1689 file_system_->Move(src_file_path, dest_file_path, callback); |
1690 test_util::RunBlockingPoolTask(); | 1690 gdata::test_util::RunBlockingPoolTask(); |
1691 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 1691 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
1692 | 1692 |
1693 EXPECT_FALSE(EntryExists(src_file_path)); | 1693 EXPECT_FALSE(EntryExists(src_file_path)); |
1694 EXPECT_FALSE(EntryExists(dest_file_path)); | 1694 EXPECT_FALSE(EntryExists(dest_file_path)); |
1695 } | 1695 } |
1696 | 1696 |
1697 TEST_F(DriveFileSystemTest, MoveFileToNonExistingDirectory) { | 1697 TEST_F(DriveFileSystemTest, MoveFileToNonExistingDirectory) { |
1698 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1698 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); |
1699 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); | 1699 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); |
1700 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); | 1700 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); |
1701 | 1701 |
1702 LoadRootFeedDocument("gdata/root_feed.json"); | 1702 LoadRootFeedDocument("gdata/root_feed.json"); |
1703 | 1703 |
1704 ASSERT_TRUE(EntryExists(src_file_path)); | 1704 ASSERT_TRUE(EntryExists(src_file_path)); |
1705 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1705 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
1706 src_file_path); | 1706 src_file_path); |
1707 ASSERT_TRUE(src_entry_proto.get()); | 1707 ASSERT_TRUE(src_entry_proto.get()); |
1708 std::string src_file_resource_id = | 1708 std::string src_file_resource_id = |
1709 src_entry_proto->resource_id(); | 1709 src_entry_proto->resource_id(); |
1710 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1710 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
1711 | 1711 |
1712 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1712 EXPECT_FALSE(EntryExists(dest_parent_path)); |
1713 | 1713 |
1714 FileOperationCallback callback = | 1714 FileOperationCallback callback = |
1715 base::Bind(&CallbackHelper::FileOperationCallback, | 1715 base::Bind(&CallbackHelper::FileOperationCallback, |
1716 callback_helper_.get()); | 1716 callback_helper_.get()); |
1717 | 1717 |
1718 file_system_->Move(src_file_path, dest_file_path, callback); | 1718 file_system_->Move(src_file_path, dest_file_path, callback); |
1719 test_util::RunBlockingPoolTask(); | 1719 gdata::test_util::RunBlockingPoolTask(); |
1720 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 1720 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
1721 | 1721 |
1722 | 1722 |
1723 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1723 EXPECT_FALSE(EntryExists(dest_parent_path)); |
1724 EXPECT_FALSE(EntryExists(dest_file_path)); | 1724 EXPECT_FALSE(EntryExists(dest_file_path)); |
1725 } | 1725 } |
1726 | 1726 |
1727 // Test the case where the parent of |dest_file_path| is a existing file, | 1727 // Test the case where the parent of |dest_file_path| is a existing file, |
1728 // not a directory. | 1728 // not a directory. |
1729 TEST_F(DriveFileSystemTest, MoveFileToInvalidPath) { | 1729 TEST_F(DriveFileSystemTest, MoveFileToInvalidPath) { |
(...skipping 15 matching lines...) Expand all Loading... |
1745 ASSERT_TRUE(EntryExists(dest_parent_path)); | 1745 ASSERT_TRUE(EntryExists(dest_parent_path)); |
1746 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( | 1746 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( |
1747 dest_parent_path); | 1747 dest_parent_path); |
1748 ASSERT_TRUE(dest_parent_proto.get()); | 1748 ASSERT_TRUE(dest_parent_proto.get()); |
1749 | 1749 |
1750 FileOperationCallback callback = | 1750 FileOperationCallback callback = |
1751 base::Bind(&CallbackHelper::FileOperationCallback, | 1751 base::Bind(&CallbackHelper::FileOperationCallback, |
1752 callback_helper_.get()); | 1752 callback_helper_.get()); |
1753 | 1753 |
1754 file_system_->Move(src_file_path, dest_file_path, callback); | 1754 file_system_->Move(src_file_path, dest_file_path, callback); |
1755 test_util::RunBlockingPoolTask(); | 1755 gdata::test_util::RunBlockingPoolTask(); |
1756 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, | 1756 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, |
1757 callback_helper_->last_error_); | 1757 callback_helper_->last_error_); |
1758 | 1758 |
1759 EXPECT_TRUE(EntryExists(src_file_path)); | 1759 EXPECT_TRUE(EntryExists(src_file_path)); |
1760 EXPECT_TRUE(EntryExists(dest_parent_path)); | 1760 EXPECT_TRUE(EntryExists(dest_parent_path)); |
1761 EXPECT_FALSE(EntryExists(dest_file_path)); | 1761 EXPECT_FALSE(EntryExists(dest_file_path)); |
1762 } | 1762 } |
1763 | 1763 |
1764 TEST_F(DriveFileSystemTest, RemoveEntries) { | 1764 TEST_F(DriveFileSystemTest, RemoveEntries) { |
1765 LoadRootFeedDocument("gdata/root_feed.json"); | 1765 LoadRootFeedDocument("gdata/root_feed.json"); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 // Try removing file in already removed subdirectory. | 1805 // Try removing file in already removed subdirectory. |
1806 EXPECT_FALSE(RemoveEntry(file_in_subdir)); | 1806 EXPECT_FALSE(RemoveEntry(file_in_subdir)); |
1807 | 1807 |
1808 // Try removing non-existing file. | 1808 // Try removing non-existing file. |
1809 EXPECT_FALSE(RemoveEntry(nonexisting_file)); | 1809 EXPECT_FALSE(RemoveEntry(nonexisting_file)); |
1810 | 1810 |
1811 // Try removing root file element. | 1811 // Try removing root file element. |
1812 EXPECT_FALSE(RemoveEntry(FilePath(FILE_PATH_LITERAL("drive")))); | 1812 EXPECT_FALSE(RemoveEntry(FilePath(FILE_PATH_LITERAL("drive")))); |
1813 | 1813 |
1814 // Need this to ensure OnDirectoryChanged() is run. | 1814 // Need this to ensure OnDirectoryChanged() is run. |
1815 test_util::RunBlockingPoolTask(); | 1815 gdata::test_util::RunBlockingPoolTask(); |
1816 } | 1816 } |
1817 | 1817 |
1818 TEST_F(DriveFileSystemTest, CreateDirectory) { | 1818 TEST_F(DriveFileSystemTest, CreateDirectory) { |
1819 LoadRootFeedDocument("gdata/root_feed.json"); | 1819 LoadRootFeedDocument("gdata/root_feed.json"); |
1820 | 1820 |
1821 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1821 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1822 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1822 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
1823 | 1823 |
1824 // Create directory in root. | 1824 // Create directory in root. |
1825 FilePath dir_path(FILE_PATH_LITERAL("drive/New Folder 1")); | 1825 FilePath dir_path(FILE_PATH_LITERAL("drive/New Folder 1")); |
(...skipping 15 matching lines...) Expand all Loading... |
1841 LoadRootFeedDocument("gdata/root_feed.json"); | 1841 LoadRootFeedDocument("gdata/root_feed.json"); |
1842 | 1842 |
1843 DriveFileSystem::FindFirstMissingParentDirectoryResult result; | 1843 DriveFileSystem::FindFirstMissingParentDirectoryResult result; |
1844 | 1844 |
1845 // Create directory in root. | 1845 // Create directory in root. |
1846 FilePath dir_path(FILE_PATH_LITERAL("drive/New Folder 1")); | 1846 FilePath dir_path(FILE_PATH_LITERAL("drive/New Folder 1")); |
1847 file_system_->FindFirstMissingParentDirectory( | 1847 file_system_->FindFirstMissingParentDirectory( |
1848 dir_path, | 1848 dir_path, |
1849 base::Bind(&CopyResultFromFindFirstMissingParentDirectory, | 1849 base::Bind(&CopyResultFromFindFirstMissingParentDirectory, |
1850 &result)); | 1850 &result)); |
1851 test_util::RunBlockingPoolTask(); | 1851 gdata::test_util::RunBlockingPoolTask(); |
1852 EXPECT_EQ(DriveFileSystem::FIND_FIRST_FOUND_MISSING, result.error); | 1852 EXPECT_EQ(DriveFileSystem::FIND_FIRST_FOUND_MISSING, result.error); |
1853 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("drive/New Folder 1")), | 1853 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("drive/New Folder 1")), |
1854 result.first_missing_parent_path); | 1854 result.first_missing_parent_path); |
1855 EXPECT_TRUE(result.last_dir_content_url.is_empty()); // root directory. | 1855 EXPECT_TRUE(result.last_dir_content_url.is_empty()); // root directory. |
1856 | 1856 |
1857 // Missing folders in subdir of an existing folder. | 1857 // Missing folders in subdir of an existing folder. |
1858 FilePath dir_path2(FILE_PATH_LITERAL("drive/Directory 1/New Folder 2")); | 1858 FilePath dir_path2(FILE_PATH_LITERAL("drive/Directory 1/New Folder 2")); |
1859 file_system_->FindFirstMissingParentDirectory( | 1859 file_system_->FindFirstMissingParentDirectory( |
1860 dir_path2, | 1860 dir_path2, |
1861 base::Bind(&CopyResultFromFindFirstMissingParentDirectory, | 1861 base::Bind(&CopyResultFromFindFirstMissingParentDirectory, |
1862 &result)); | 1862 &result)); |
1863 test_util::RunBlockingPoolTask(); | 1863 gdata::test_util::RunBlockingPoolTask(); |
1864 EXPECT_EQ(DriveFileSystem::FIND_FIRST_FOUND_MISSING, result.error); | 1864 EXPECT_EQ(DriveFileSystem::FIND_FIRST_FOUND_MISSING, result.error); |
1865 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("drive/Directory 1/New Folder 2")), | 1865 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("drive/Directory 1/New Folder 2")), |
1866 result.first_missing_parent_path); | 1866 result.first_missing_parent_path); |
1867 EXPECT_FALSE(result.last_dir_content_url.is_empty()); // non-root dir. | 1867 EXPECT_FALSE(result.last_dir_content_url.is_empty()); // non-root dir. |
1868 | 1868 |
1869 // Missing two folders on the path. | 1869 // Missing two folders on the path. |
1870 FilePath dir_path3 = dir_path2.Append(FILE_PATH_LITERAL("Another Folder")); | 1870 FilePath dir_path3 = dir_path2.Append(FILE_PATH_LITERAL("Another Folder")); |
1871 file_system_->FindFirstMissingParentDirectory( | 1871 file_system_->FindFirstMissingParentDirectory( |
1872 dir_path3, | 1872 dir_path3, |
1873 base::Bind(&CopyResultFromFindFirstMissingParentDirectory, | 1873 base::Bind(&CopyResultFromFindFirstMissingParentDirectory, |
1874 &result)); | 1874 &result)); |
1875 test_util::RunBlockingPoolTask(); | 1875 gdata::test_util::RunBlockingPoolTask(); |
1876 EXPECT_EQ(DriveFileSystem::FIND_FIRST_FOUND_MISSING, result.error); | 1876 EXPECT_EQ(DriveFileSystem::FIND_FIRST_FOUND_MISSING, result.error); |
1877 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("drive/Directory 1/New Folder 2")), | 1877 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("drive/Directory 1/New Folder 2")), |
1878 result.first_missing_parent_path); | 1878 result.first_missing_parent_path); |
1879 EXPECT_FALSE(result.last_dir_content_url.is_empty()); // non-root dir. | 1879 EXPECT_FALSE(result.last_dir_content_url.is_empty()); // non-root dir. |
1880 | 1880 |
1881 // Folders on top of an existing file. | 1881 // Folders on top of an existing file. |
1882 file_system_->FindFirstMissingParentDirectory( | 1882 file_system_->FindFirstMissingParentDirectory( |
1883 FilePath(FILE_PATH_LITERAL("drive/File 1.txt/BadDir")), | 1883 FilePath(FILE_PATH_LITERAL("drive/File 1.txt/BadDir")), |
1884 base::Bind(&CopyResultFromFindFirstMissingParentDirectory, | 1884 base::Bind(&CopyResultFromFindFirstMissingParentDirectory, |
1885 &result)); | 1885 &result)); |
1886 test_util::RunBlockingPoolTask(); | 1886 gdata::test_util::RunBlockingPoolTask(); |
1887 EXPECT_EQ(DriveFileSystem::FIND_FIRST_FOUND_INVALID, result.error); | 1887 EXPECT_EQ(DriveFileSystem::FIND_FIRST_FOUND_INVALID, result.error); |
1888 | 1888 |
1889 // Existing folder. | 1889 // Existing folder. |
1890 file_system_->FindFirstMissingParentDirectory( | 1890 file_system_->FindFirstMissingParentDirectory( |
1891 FilePath(FILE_PATH_LITERAL("drive/Directory 1")), | 1891 FilePath(FILE_PATH_LITERAL("drive/Directory 1")), |
1892 base::Bind(&CopyResultFromFindFirstMissingParentDirectory, | 1892 base::Bind(&CopyResultFromFindFirstMissingParentDirectory, |
1893 &result)); | 1893 &result)); |
1894 test_util::RunBlockingPoolTask(); | 1894 gdata::test_util::RunBlockingPoolTask(); |
1895 EXPECT_EQ(DriveFileSystem::FIND_FIRST_DIRECTORY_ALREADY_PRESENT, | 1895 EXPECT_EQ(DriveFileSystem::FIND_FIRST_DIRECTORY_ALREADY_PRESENT, |
1896 result.error); | 1896 result.error); |
1897 } | 1897 } |
1898 | 1898 |
1899 // Create a directory through the document service | 1899 // Create a directory through the document service |
1900 TEST_F(DriveFileSystemTest, CreateDirectoryWithService) { | 1900 TEST_F(DriveFileSystemTest, CreateDirectoryWithService) { |
1901 LoadRootFeedDocument("gdata/root_feed.json"); | 1901 LoadRootFeedDocument("gdata/root_feed.json"); |
1902 EXPECT_CALL(*mock_drive_service_, | 1902 EXPECT_CALL(*mock_drive_service_, |
1903 CreateDirectory(_, "Sample Directory Title", _)).Times(1); | 1903 CreateDirectory(_, "Sample Directory Title", _)).Times(1); |
1904 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1904 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1905 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1905 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
1906 | 1906 |
1907 // Set last error so it's not a valid error code. | 1907 // Set last error so it's not a valid error code. |
1908 callback_helper_->last_error_ = static_cast<DriveFileError>(1); | 1908 callback_helper_->last_error_ = static_cast<DriveFileError>(1); |
1909 file_system_->CreateDirectory( | 1909 file_system_->CreateDirectory( |
1910 FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")), | 1910 FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")), |
1911 false, // is_exclusive | 1911 false, // is_exclusive |
1912 true, // is_recursive | 1912 true, // is_recursive |
1913 base::Bind(&CallbackHelper::FileOperationCallback, | 1913 base::Bind(&CallbackHelper::FileOperationCallback, |
1914 callback_helper_.get())); | 1914 callback_helper_.get())); |
1915 test_util::RunBlockingPoolTask(); | 1915 gdata::test_util::RunBlockingPoolTask(); |
1916 // TODO(gspencer): Uncomment this when we get a blob that | 1916 // TODO(gspencer): Uncomment this when we get a blob that |
1917 // works that can be returned from the mock. | 1917 // works that can be returned from the mock. |
1918 // EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 1918 // EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
1919 } | 1919 } |
1920 | 1920 |
1921 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { | 1921 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { |
1922 LoadRootFeedDocument("gdata/root_feed.json"); | 1922 LoadRootFeedDocument("gdata/root_feed.json"); |
1923 | 1923 |
1924 GetFileCallback callback = | 1924 GetFileCallback callback = |
1925 base::Bind(&CallbackHelper::GetFileCallback, | 1925 base::Bind(&CallbackHelper::GetFileCallback, |
1926 callback_helper_.get()); | 1926 callback_helper_.get()); |
1927 | 1927 |
1928 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1928 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
1929 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1929 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
1930 FilePath downloaded_file = GetCachePathForFile( | 1930 FilePath downloaded_file = GetCachePathForFile( |
1931 entry_proto->resource_id(), | 1931 entry_proto->resource_id(), |
1932 entry_proto->file_specific_info().file_md5()); | 1932 entry_proto->file_specific_info().file_md5()); |
1933 const int64 file_size = entry_proto->file_info().size(); | 1933 const int64 file_size = entry_proto->file_info().size(); |
1934 | 1934 |
1935 // Pretend we have enough space. | 1935 // Pretend we have enough space. |
1936 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 1936 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
1937 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); | 1937 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); |
1938 | 1938 |
1939 // Before Download starts metadata from server will be fetched. | 1939 // Before Download starts metadata from server will be fetched. |
1940 // We will read content url from the result. | 1940 // We will read content url from the result. |
1941 scoped_ptr<base::Value> document = | 1941 scoped_ptr<base::Value> document = |
1942 test_util::LoadJSONFile("gdata/document_to_download.json"); | 1942 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
1943 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 1943 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
1944 | 1944 |
1945 // The file is obtained with the mock DriveService. | 1945 // The file is obtained with the mock DriveService. |
1946 EXPECT_CALL(*mock_drive_service_, | 1946 EXPECT_CALL(*mock_drive_service_, |
1947 DownloadFile(file_in_root, | 1947 DownloadFile(file_in_root, |
1948 downloaded_file, | 1948 downloaded_file, |
1949 GURL("https://file_content_url_changed/"), | 1949 GURL("https://file_content_url_changed/"), |
1950 _, _)) | 1950 _, _)) |
1951 .Times(1); | 1951 .Times(1); |
1952 | 1952 |
1953 file_system_->GetFileByPath(file_in_root, callback, | 1953 file_system_->GetFileByPath(file_in_root, callback, |
1954 GetContentCallback()); | 1954 gdata::GetContentCallback()); |
1955 test_util::RunBlockingPoolTask(); | 1955 gdata::test_util::RunBlockingPoolTask(); |
1956 | 1956 |
1957 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 1957 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
1958 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 1958 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
1959 EXPECT_EQ(downloaded_file.value(), | 1959 EXPECT_EQ(downloaded_file.value(), |
1960 callback_helper_->download_path_.value()); | 1960 callback_helper_->download_path_.value()); |
1961 } | 1961 } |
1962 | 1962 |
1963 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) { | 1963 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) { |
1964 LoadRootFeedDocument("gdata/root_feed.json"); | 1964 LoadRootFeedDocument("gdata/root_feed.json"); |
1965 | 1965 |
1966 GetFileCallback callback = | 1966 GetFileCallback callback = |
1967 base::Bind(&CallbackHelper::GetFileCallback, | 1967 base::Bind(&CallbackHelper::GetFileCallback, |
1968 callback_helper_.get()); | 1968 callback_helper_.get()); |
1969 | 1969 |
1970 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1970 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
1971 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1971 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
1972 FilePath downloaded_file = GetCachePathForFile( | 1972 FilePath downloaded_file = GetCachePathForFile( |
1973 entry_proto->resource_id(), | 1973 entry_proto->resource_id(), |
1974 entry_proto->file_specific_info().file_md5()); | 1974 entry_proto->file_specific_info().file_md5()); |
1975 | 1975 |
1976 // Pretend we have no space at all. | 1976 // Pretend we have no space at all. |
1977 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 1977 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
1978 .Times(2).WillRepeatedly(Return(0)); | 1978 .Times(2).WillRepeatedly(Return(0)); |
1979 | 1979 |
1980 // Before Download starts metadata from server will be fetched. | 1980 // Before Download starts metadata from server will be fetched. |
1981 // We will read content url from the result. | 1981 // We will read content url from the result. |
1982 scoped_ptr<base::Value> document = | 1982 scoped_ptr<base::Value> document = |
1983 test_util::LoadJSONFile("gdata/document_to_download.json"); | 1983 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
1984 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 1984 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
1985 | 1985 |
1986 // The file is not obtained with the mock DriveService, because of no space. | 1986 // The file is not obtained with the mock DriveService, because of no space. |
1987 EXPECT_CALL(*mock_drive_service_, | 1987 EXPECT_CALL(*mock_drive_service_, |
1988 DownloadFile(file_in_root, | 1988 DownloadFile(file_in_root, |
1989 downloaded_file, | 1989 downloaded_file, |
1990 GURL("https://file_content_url_changed/"), | 1990 GURL("https://file_content_url_changed/"), |
1991 _, _)) | 1991 _, _)) |
1992 .Times(0); | 1992 .Times(0); |
1993 | 1993 |
1994 file_system_->GetFileByPath(file_in_root, callback, | 1994 file_system_->GetFileByPath(file_in_root, callback, |
1995 GetContentCallback()); | 1995 gdata::GetContentCallback()); |
1996 test_util::RunBlockingPoolTask(); | 1996 gdata::test_util::RunBlockingPoolTask(); |
1997 | 1997 |
1998 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, | 1998 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, |
1999 callback_helper_->last_error_); | 1999 callback_helper_->last_error_); |
2000 } | 2000 } |
2001 | 2001 |
2002 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) { | 2002 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) { |
2003 LoadRootFeedDocument("gdata/root_feed.json"); | 2003 LoadRootFeedDocument("gdata/root_feed.json"); |
2004 | 2004 |
2005 GetFileCallback callback = | 2005 GetFileCallback callback = |
2006 base::Bind(&CallbackHelper::GetFileCallback, | 2006 base::Bind(&CallbackHelper::GetFileCallback, |
(...skipping 11 matching lines...) Expand all Loading... |
2018 // the disk space was freed up by removing temporary files. | 2018 // the disk space was freed up by removing temporary files. |
2019 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2019 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
2020 .WillOnce(Return(file_size + kMinFreeSpace)) | 2020 .WillOnce(Return(file_size + kMinFreeSpace)) |
2021 .WillOnce(Return(0)) | 2021 .WillOnce(Return(0)) |
2022 .WillOnce(Return(file_size + kMinFreeSpace)) | 2022 .WillOnce(Return(file_size + kMinFreeSpace)) |
2023 .WillOnce(Return(file_size + kMinFreeSpace)); | 2023 .WillOnce(Return(file_size + kMinFreeSpace)); |
2024 | 2024 |
2025 // Store something in the temporary cache directory. | 2025 // Store something in the temporary cache directory. |
2026 TestStoreToCache("<resource_id>", | 2026 TestStoreToCache("<resource_id>", |
2027 "<md5>", | 2027 "<md5>", |
2028 test_util::GetTestFilePath("gdata/root_feed.json"), | 2028 gdata::test_util::GetTestFilePath("gdata/root_feed.json"), |
2029 DRIVE_FILE_OK, | 2029 DRIVE_FILE_OK, |
2030 test_util::TEST_CACHE_STATE_PRESENT, | 2030 test_util::TEST_CACHE_STATE_PRESENT, |
2031 DriveCache::CACHE_TYPE_TMP); | 2031 DriveCache::CACHE_TYPE_TMP); |
2032 ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>")); | 2032 ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>")); |
2033 ASSERT_TRUE(CacheFileExists("<resource_id>", "<md5>")); | 2033 ASSERT_TRUE(CacheFileExists("<resource_id>", "<md5>")); |
2034 | 2034 |
2035 // Before Download starts metadata from server will be fetched. | 2035 // Before Download starts metadata from server will be fetched. |
2036 // We will read content url from the result. | 2036 // We will read content url from the result. |
2037 scoped_ptr<base::Value> document = | 2037 scoped_ptr<base::Value> document = |
2038 test_util::LoadJSONFile("gdata/document_to_download.json"); | 2038 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2039 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 2039 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
2040 | 2040 |
2041 // The file is obtained with the mock DriveService, because of we freed up the | 2041 // The file is obtained with the mock DriveService, because of we freed up the |
2042 // space. | 2042 // space. |
2043 EXPECT_CALL(*mock_drive_service_, | 2043 EXPECT_CALL(*mock_drive_service_, |
2044 DownloadFile(file_in_root, | 2044 DownloadFile(file_in_root, |
2045 downloaded_file, | 2045 downloaded_file, |
2046 GURL("https://file_content_url_changed/"), | 2046 GURL("https://file_content_url_changed/"), |
2047 _, _)) | 2047 _, _)) |
2048 .Times(1); | 2048 .Times(1); |
2049 | 2049 |
2050 file_system_->GetFileByPath(file_in_root, callback, | 2050 file_system_->GetFileByPath(file_in_root, callback, |
2051 GetContentCallback()); | 2051 gdata::GetContentCallback()); |
2052 test_util::RunBlockingPoolTask(); | 2052 gdata::test_util::RunBlockingPoolTask(); |
2053 | 2053 |
2054 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 2054 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
2055 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 2055 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
2056 EXPECT_EQ(downloaded_file.value(), | 2056 EXPECT_EQ(downloaded_file.value(), |
2057 callback_helper_->download_path_.value()); | 2057 callback_helper_->download_path_.value()); |
2058 | 2058 |
2059 // The file should be removed in order to free up space, and the cache | 2059 // The file should be removed in order to free up space, and the cache |
2060 // entry should also be removed. | 2060 // entry should also be removed. |
2061 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>")); | 2061 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>")); |
2062 ASSERT_FALSE(CacheFileExists("<resource_id>", "<md5>")); | 2062 ASSERT_FALSE(CacheFileExists("<resource_id>", "<md5>")); |
(...skipping 18 matching lines...) Expand all Loading... |
2081 // the disk space becomes full after the file is downloaded for some reason | 2081 // the disk space becomes full after the file is downloaded for some reason |
2082 // (ex. the actual file was larger than the expected size). | 2082 // (ex. the actual file was larger than the expected size). |
2083 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2083 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
2084 .WillOnce(Return(file_size + kMinFreeSpace)) | 2084 .WillOnce(Return(file_size + kMinFreeSpace)) |
2085 .WillOnce(Return(kMinFreeSpace - 1)) | 2085 .WillOnce(Return(kMinFreeSpace - 1)) |
2086 .WillOnce(Return(kMinFreeSpace - 1)); | 2086 .WillOnce(Return(kMinFreeSpace - 1)); |
2087 | 2087 |
2088 // Before Download starts metadata from server will be fetched. | 2088 // Before Download starts metadata from server will be fetched. |
2089 // We will read content url from the result. | 2089 // We will read content url from the result. |
2090 scoped_ptr<base::Value> document = | 2090 scoped_ptr<base::Value> document = |
2091 test_util::LoadJSONFile("gdata/document_to_download.json"); | 2091 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2092 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 2092 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
2093 | 2093 |
2094 // The file is obtained with the mock DriveService. | 2094 // The file is obtained with the mock DriveService. |
2095 EXPECT_CALL(*mock_drive_service_, | 2095 EXPECT_CALL(*mock_drive_service_, |
2096 DownloadFile(file_in_root, | 2096 DownloadFile(file_in_root, |
2097 downloaded_file, | 2097 downloaded_file, |
2098 GURL("https://file_content_url_changed/"), | 2098 GURL("https://file_content_url_changed/"), |
2099 _, _)) | 2099 _, _)) |
2100 .Times(1); | 2100 .Times(1); |
2101 | 2101 |
2102 file_system_->GetFileByPath(file_in_root, callback, | 2102 file_system_->GetFileByPath(file_in_root, callback, |
2103 GetContentCallback()); | 2103 gdata::GetContentCallback()); |
2104 test_util::RunBlockingPoolTask(); | 2104 gdata::test_util::RunBlockingPoolTask(); |
2105 | 2105 |
2106 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, | 2106 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, |
2107 callback_helper_->last_error_); | 2107 callback_helper_->last_error_); |
2108 } | 2108 } |
2109 | 2109 |
2110 TEST_F(DriveFileSystemTest, GetFileByPath_FromCache) { | 2110 TEST_F(DriveFileSystemTest, GetFileByPath_FromCache) { |
2111 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2111 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
2112 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); | 2112 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); |
2113 | 2113 |
2114 LoadRootFeedDocument("gdata/root_feed.json"); | 2114 LoadRootFeedDocument("gdata/root_feed.json"); |
2115 | 2115 |
2116 GetFileCallback callback = | 2116 GetFileCallback callback = |
2117 base::Bind(&CallbackHelper::GetFileCallback, | 2117 base::Bind(&CallbackHelper::GetFileCallback, |
2118 callback_helper_.get()); | 2118 callback_helper_.get()); |
2119 | 2119 |
2120 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 2120 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
2121 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 2121 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
2122 FilePath downloaded_file = GetCachePathForFile( | 2122 FilePath downloaded_file = GetCachePathForFile( |
2123 entry_proto->resource_id(), | 2123 entry_proto->resource_id(), |
2124 entry_proto->file_specific_info().file_md5()); | 2124 entry_proto->file_specific_info().file_md5()); |
2125 | 2125 |
2126 // Store something as cached version of this file. | 2126 // Store something as cached version of this file. |
2127 TestStoreToCache(entry_proto->resource_id(), | 2127 TestStoreToCache(entry_proto->resource_id(), |
2128 entry_proto->file_specific_info().file_md5(), | 2128 entry_proto->file_specific_info().file_md5(), |
2129 test_util::GetTestFilePath("gdata/root_feed.json"), | 2129 gdata::test_util::GetTestFilePath("gdata/root_feed.json"), |
2130 DRIVE_FILE_OK, | 2130 DRIVE_FILE_OK, |
2131 test_util::TEST_CACHE_STATE_PRESENT, | 2131 test_util::TEST_CACHE_STATE_PRESENT, |
2132 DriveCache::CACHE_TYPE_TMP); | 2132 DriveCache::CACHE_TYPE_TMP); |
2133 | 2133 |
2134 // Make sure we don't fetch metadata for downloading file. | 2134 // Make sure we don't fetch metadata for downloading file. |
2135 EXPECT_CALL(*mock_drive_service_, GetDocumentEntry(_, _)).Times(0); | 2135 EXPECT_CALL(*mock_drive_service_, GetDocumentEntry(_, _)).Times(0); |
2136 | 2136 |
2137 // Make sure we don't call downloads at all. | 2137 // Make sure we don't call downloads at all. |
2138 EXPECT_CALL(*mock_drive_service_, | 2138 EXPECT_CALL(*mock_drive_service_, |
2139 DownloadFile(file_in_root, | 2139 DownloadFile(file_in_root, |
2140 downloaded_file, | 2140 downloaded_file, |
2141 GURL("https://file_content_url_changed/"), | 2141 GURL("https://file_content_url_changed/"), |
2142 _, _)) | 2142 _, _)) |
2143 .Times(0); | 2143 .Times(0); |
2144 | 2144 |
2145 file_system_->GetFileByPath(file_in_root, callback, | 2145 file_system_->GetFileByPath(file_in_root, callback, |
2146 GetContentCallback()); | 2146 gdata::GetContentCallback()); |
2147 test_util::RunBlockingPoolTask(); | 2147 gdata::test_util::RunBlockingPoolTask(); |
2148 | 2148 |
2149 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 2149 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
2150 EXPECT_EQ(downloaded_file.value(), | 2150 EXPECT_EQ(downloaded_file.value(), |
2151 callback_helper_->download_path_.value()); | 2151 callback_helper_->download_path_.value()); |
2152 } | 2152 } |
2153 | 2153 |
2154 TEST_F(DriveFileSystemTest, GetFileByPath_HostedDocument) { | 2154 TEST_F(DriveFileSystemTest, GetFileByPath_HostedDocument) { |
2155 LoadRootFeedDocument("gdata/root_feed.json"); | 2155 LoadRootFeedDocument("gdata/root_feed.json"); |
2156 | 2156 |
2157 GetFileCallback callback = | 2157 GetFileCallback callback = |
2158 base::Bind(&CallbackHelper::GetFileCallback, | 2158 base::Bind(&CallbackHelper::GetFileCallback, |
2159 callback_helper_.get()); | 2159 callback_helper_.get()); |
2160 | 2160 |
2161 FilePath file_in_root(FILE_PATH_LITERAL("drive/Document 1.gdoc")); | 2161 FilePath file_in_root(FILE_PATH_LITERAL("drive/Document 1.gdoc")); |
2162 scoped_ptr<DriveEntryProto> src_entry_proto = | 2162 scoped_ptr<DriveEntryProto> src_entry_proto = |
2163 GetEntryInfoByPathSync(file_in_root); | 2163 GetEntryInfoByPathSync(file_in_root); |
2164 ASSERT_TRUE(src_entry_proto.get()); | 2164 ASSERT_TRUE(src_entry_proto.get()); |
2165 | 2165 |
2166 file_system_->GetFileByPath(file_in_root, callback, | 2166 file_system_->GetFileByPath(file_in_root, callback, |
2167 GetContentCallback()); | 2167 gdata::GetContentCallback()); |
2168 test_util::RunBlockingPoolTask(); | 2168 gdata::test_util::RunBlockingPoolTask(); |
2169 | 2169 |
2170 EXPECT_EQ(HOSTED_DOCUMENT, callback_helper_->file_type_); | 2170 EXPECT_EQ(HOSTED_DOCUMENT, callback_helper_->file_type_); |
2171 EXPECT_FALSE(callback_helper_->download_path_.empty()); | 2171 EXPECT_FALSE(callback_helper_->download_path_.empty()); |
2172 | 2172 |
2173 ASSERT_TRUE(src_entry_proto.get()); | 2173 ASSERT_TRUE(src_entry_proto.get()); |
2174 VerifyHostedDocumentJSONFile(*src_entry_proto, | 2174 VerifyHostedDocumentJSONFile(*src_entry_proto, |
2175 callback_helper_->download_path_); | 2175 callback_helper_->download_path_); |
2176 } | 2176 } |
2177 | 2177 |
2178 TEST_F(DriveFileSystemTest, GetFileByResourceId) { | 2178 TEST_F(DriveFileSystemTest, GetFileByResourceId) { |
2179 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2179 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
2180 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); | 2180 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); |
2181 | 2181 |
2182 LoadRootFeedDocument("gdata/root_feed.json"); | 2182 LoadRootFeedDocument("gdata/root_feed.json"); |
2183 | 2183 |
2184 GetFileCallback callback = | 2184 GetFileCallback callback = |
2185 base::Bind(&CallbackHelper::GetFileCallback, | 2185 base::Bind(&CallbackHelper::GetFileCallback, |
2186 callback_helper_.get()); | 2186 callback_helper_.get()); |
2187 | 2187 |
2188 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 2188 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
2189 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 2189 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
2190 FilePath downloaded_file = GetCachePathForFile( | 2190 FilePath downloaded_file = GetCachePathForFile( |
2191 entry_proto->resource_id(), | 2191 entry_proto->resource_id(), |
2192 entry_proto->file_specific_info().file_md5()); | 2192 entry_proto->file_specific_info().file_md5()); |
2193 | 2193 |
2194 // Before Download starts metadata from server will be fetched. | 2194 // Before Download starts metadata from server will be fetched. |
2195 // We will read content url from the result. | 2195 // We will read content url from the result. |
2196 scoped_ptr<base::Value> document = | 2196 scoped_ptr<base::Value> document = |
2197 test_util::LoadJSONFile("gdata/document_to_download.json"); | 2197 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2198 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 2198 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
2199 | 2199 |
2200 // The file is obtained with the mock DriveService, because it's not stored in | 2200 // The file is obtained with the mock DriveService, because it's not stored in |
2201 // the cache. | 2201 // the cache. |
2202 EXPECT_CALL(*mock_drive_service_, | 2202 EXPECT_CALL(*mock_drive_service_, |
2203 DownloadFile(file_in_root, | 2203 DownloadFile(file_in_root, |
2204 downloaded_file, | 2204 downloaded_file, |
2205 GURL("https://file_content_url_changed/"), | 2205 GURL("https://file_content_url_changed/"), |
2206 _, _)) | 2206 _, _)) |
2207 .Times(1); | 2207 .Times(1); |
2208 | 2208 |
2209 file_system_->GetFileByResourceId(entry_proto->resource_id(), | 2209 file_system_->GetFileByResourceId(entry_proto->resource_id(), |
2210 callback, | 2210 callback, |
2211 GetContentCallback()); | 2211 gdata::GetContentCallback()); |
2212 test_util::RunBlockingPoolTask(); | 2212 gdata::test_util::RunBlockingPoolTask(); |
2213 | 2213 |
2214 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 2214 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
2215 EXPECT_EQ(downloaded_file.value(), | 2215 EXPECT_EQ(downloaded_file.value(), |
2216 callback_helper_->download_path_.value()); | 2216 callback_helper_->download_path_.value()); |
2217 } | 2217 } |
2218 | 2218 |
2219 TEST_F(DriveFileSystemTest, GetFileByResourceId_FromCache) { | 2219 TEST_F(DriveFileSystemTest, GetFileByResourceId_FromCache) { |
2220 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2220 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
2221 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); | 2221 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); |
2222 | 2222 |
2223 LoadRootFeedDocument("gdata/root_feed.json"); | 2223 LoadRootFeedDocument("gdata/root_feed.json"); |
2224 | 2224 |
2225 GetFileCallback callback = | 2225 GetFileCallback callback = |
2226 base::Bind(&CallbackHelper::GetFileCallback, | 2226 base::Bind(&CallbackHelper::GetFileCallback, |
2227 callback_helper_.get()); | 2227 callback_helper_.get()); |
2228 | 2228 |
2229 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 2229 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
2230 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 2230 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
2231 FilePath downloaded_file = GetCachePathForFile( | 2231 FilePath downloaded_file = GetCachePathForFile( |
2232 entry_proto->resource_id(), | 2232 entry_proto->resource_id(), |
2233 entry_proto->file_specific_info().file_md5()); | 2233 entry_proto->file_specific_info().file_md5()); |
2234 | 2234 |
2235 // Store something as cached version of this file. | 2235 // Store something as cached version of this file. |
2236 TestStoreToCache(entry_proto->resource_id(), | 2236 TestStoreToCache(entry_proto->resource_id(), |
2237 entry_proto->file_specific_info().file_md5(), | 2237 entry_proto->file_specific_info().file_md5(), |
2238 test_util::GetTestFilePath("gdata/root_feed.json"), | 2238 gdata::test_util::GetTestFilePath("gdata/root_feed.json"), |
2239 DRIVE_FILE_OK, | 2239 DRIVE_FILE_OK, |
2240 test_util::TEST_CACHE_STATE_PRESENT, | 2240 test_util::TEST_CACHE_STATE_PRESENT, |
2241 DriveCache::CACHE_TYPE_TMP); | 2241 DriveCache::CACHE_TYPE_TMP); |
2242 | 2242 |
2243 // The file is obtained from the cache. | 2243 // The file is obtained from the cache. |
2244 // Make sure we don't call downloads at all. | 2244 // Make sure we don't call downloads at all. |
2245 EXPECT_CALL(*mock_drive_service_, DownloadFile(_, _, _, _, _)) | 2245 EXPECT_CALL(*mock_drive_service_, DownloadFile(_, _, _, _, _)) |
2246 .Times(0); | 2246 .Times(0); |
2247 | 2247 |
2248 file_system_->GetFileByResourceId(entry_proto->resource_id(), | 2248 file_system_->GetFileByResourceId(entry_proto->resource_id(), |
2249 callback, | 2249 callback, |
2250 GetContentCallback()); | 2250 gdata::GetContentCallback()); |
2251 test_util::RunBlockingPoolTask(); | 2251 gdata::test_util::RunBlockingPoolTask(); |
2252 | 2252 |
2253 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 2253 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
2254 EXPECT_EQ(downloaded_file.value(), | 2254 EXPECT_EQ(downloaded_file.value(), |
2255 callback_helper_->download_path_.value()); | 2255 callback_helper_->download_path_.value()); |
2256 } | 2256 } |
2257 | 2257 |
2258 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_PersistentFile) { | 2258 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_PersistentFile) { |
2259 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2259 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
2260 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); | 2260 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); |
2261 | 2261 |
(...skipping 14 matching lines...) Expand all Loading... |
2276 | 2276 |
2277 // First store a file to cache. A cache file will be created at: | 2277 // First store a file to cache. A cache file will be created at: |
2278 // GCache/v1/persistent/<kResourceId>.<kMd5> | 2278 // GCache/v1/persistent/<kResourceId>.<kMd5> |
2279 const FilePath original_cache_file_path = | 2279 const FilePath original_cache_file_path = |
2280 DriveCache::GetCacheRootPath(profile_.get()) | 2280 DriveCache::GetCacheRootPath(profile_.get()) |
2281 .AppendASCII("persistent") | 2281 .AppendASCII("persistent") |
2282 .AppendASCII(kResourceId + "." + kMd5); | 2282 .AppendASCII(kResourceId + "." + kMd5); |
2283 TestStoreToCache(kResourceId, | 2283 TestStoreToCache(kResourceId, |
2284 kMd5, | 2284 kMd5, |
2285 // Anything works. | 2285 // Anything works. |
2286 test_util::GetTestFilePath("gdata/root_feed.json"), | 2286 gdata::test_util::GetTestFilePath("gdata/root_feed.json"), |
2287 DRIVE_FILE_OK, | 2287 DRIVE_FILE_OK, |
2288 test_util::TEST_CACHE_STATE_PRESENT | | 2288 test_util::TEST_CACHE_STATE_PRESENT | |
2289 test_util::TEST_CACHE_STATE_PINNED | | 2289 test_util::TEST_CACHE_STATE_PINNED | |
2290 test_util::TEST_CACHE_STATE_PERSISTENT, | 2290 test_util::TEST_CACHE_STATE_PERSISTENT, |
2291 DriveCache::CACHE_TYPE_PERSISTENT); | 2291 DriveCache::CACHE_TYPE_PERSISTENT); |
2292 ASSERT_TRUE(file_util::PathExists(original_cache_file_path)); | 2292 ASSERT_TRUE(file_util::PathExists(original_cache_file_path)); |
2293 | 2293 |
2294 // Add the dirty bit. The cache file will be renamed to | 2294 // Add the dirty bit. The cache file will be renamed to |
2295 // GCache/v1/persistent/<kResourceId>.local | 2295 // GCache/v1/persistent/<kResourceId>.local |
2296 TestMarkDirty(kResourceId, | 2296 TestMarkDirty(kResourceId, |
(...skipping 29 matching lines...) Expand all Loading... |
2326 test_util::TEST_CACHE_STATE_DIRTY | | 2326 test_util::TEST_CACHE_STATE_DIRTY | |
2327 test_util::TEST_CACHE_STATE_PERSISTENT, | 2327 test_util::TEST_CACHE_STATE_PERSISTENT, |
2328 DriveCache::CACHE_TYPE_PERSISTENT); | 2328 DriveCache::CACHE_TYPE_PERSISTENT); |
2329 const FilePath outgoing_symlink_path = | 2329 const FilePath outgoing_symlink_path = |
2330 DriveCache::GetCacheRootPath(profile_.get()) | 2330 DriveCache::GetCacheRootPath(profile_.get()) |
2331 .AppendASCII("outgoing") | 2331 .AppendASCII("outgoing") |
2332 .AppendASCII(kResourceId); | 2332 .AppendASCII(kResourceId); |
2333 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); | 2333 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); |
2334 ASSERT_TRUE(file_util::PathExists(outgoing_symlink_path)); | 2334 ASSERT_TRUE(file_util::PathExists(outgoing_symlink_path)); |
2335 | 2335 |
2336 // Create a DocumentEntry, which is needed to mock | 2336 // Create a gdata::DocumentEntry, which is needed to mock |
2337 // DriveUploaderInterface::UploadExistingFile(). | 2337 // DriveUploaderInterface::UploadExistingFile(). |
2338 // TODO(satorux): This should be cleaned up. crbug.com/134240. | 2338 // TODO(satorux): This should be cleaned up. crbug.com/134240. |
2339 DocumentEntry* document_entry = NULL; | 2339 gdata::DocumentEntry* document_entry = NULL; |
2340 scoped_ptr<base::Value> value = | 2340 scoped_ptr<base::Value> value = |
2341 test_util::LoadJSONFile("gdata/root_feed.json"); | 2341 gdata::test_util::LoadJSONFile("gdata/root_feed.json"); |
2342 ASSERT_TRUE(value.get()); | 2342 ASSERT_TRUE(value.get()); |
2343 base::DictionaryValue* as_dict = NULL; | 2343 base::DictionaryValue* as_dict = NULL; |
2344 base::ListValue* entry_list = NULL; | 2344 base::ListValue* entry_list = NULL; |
2345 if (value->GetAsDictionary(&as_dict) && | 2345 if (value->GetAsDictionary(&as_dict) && |
2346 as_dict->GetList("feed.entry", &entry_list)) { | 2346 as_dict->GetList("feed.entry", &entry_list)) { |
2347 for (size_t i = 0; i < entry_list->GetSize(); ++i) { | 2347 for (size_t i = 0; i < entry_list->GetSize(); ++i) { |
2348 base::DictionaryValue* entry = NULL; | 2348 base::DictionaryValue* entry = NULL; |
2349 std::string resource_id; | 2349 std::string resource_id; |
2350 if (entry_list->GetDictionary(i, &entry) && | 2350 if (entry_list->GetDictionary(i, &entry) && |
2351 entry->GetString("gd$resourceId.$t", &resource_id) && | 2351 entry->GetString("gd$resourceId.$t", &resource_id) && |
2352 resource_id == kResourceId) { | 2352 resource_id == kResourceId) { |
2353 // This will be deleted by UploadExistingFile(). | 2353 // This will be deleted by UploadExistingFile(). |
2354 document_entry = DocumentEntry::CreateFrom(*entry); | 2354 document_entry = gdata::DocumentEntry::CreateFrom(*entry); |
2355 } | 2355 } |
2356 } | 2356 } |
2357 } | 2357 } |
2358 ASSERT_TRUE(document_entry); | 2358 ASSERT_TRUE(document_entry); |
2359 | 2359 |
2360 // The mock uploader will be used to simulate a file upload. | 2360 // The mock uploader will be used to simulate a file upload. |
2361 EXPECT_CALL(*mock_uploader_, UploadExistingFile( | 2361 EXPECT_CALL(*mock_uploader_, UploadExistingFile( |
2362 GURL("https://file_link_resumable_edit_media/"), | 2362 GURL("https://file_link_resumable_edit_media/"), |
2363 kFilePath, | 2363 kFilePath, |
2364 dirty_cache_file_path, | 2364 dirty_cache_file_path, |
(...skipping 18 matching lines...) Expand all Loading... |
2383 callback_helper_.get()); | 2383 callback_helper_.get()); |
2384 | 2384 |
2385 // Check the number of files in the root directory. We'll compare the | 2385 // Check the number of files in the root directory. We'll compare the |
2386 // number after updating a file. | 2386 // number after updating a file. |
2387 scoped_ptr<DriveEntryProtoVector> root_directory_entries( | 2387 scoped_ptr<DriveEntryProtoVector> root_directory_entries( |
2388 ReadDirectoryByPathSync(FilePath::FromUTF8Unsafe("drive"))); | 2388 ReadDirectoryByPathSync(FilePath::FromUTF8Unsafe("drive"))); |
2389 ASSERT_TRUE(root_directory_entries.get()); | 2389 ASSERT_TRUE(root_directory_entries.get()); |
2390 const int num_files_in_root = CountFiles(*root_directory_entries); | 2390 const int num_files_in_root = CountFiles(*root_directory_entries); |
2391 | 2391 |
2392 file_system_->UpdateFileByResourceId(kResourceId, callback); | 2392 file_system_->UpdateFileByResourceId(kResourceId, callback); |
2393 test_util::RunBlockingPoolTask(); | 2393 gdata::test_util::RunBlockingPoolTask(); |
2394 | 2394 |
2395 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); | 2395 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
2396 // Make sure that the number of files did not change (i.e. we updated an | 2396 // Make sure that the number of files did not change (i.e. we updated an |
2397 // existing file, rather than adding a new file. The number of files | 2397 // existing file, rather than adding a new file. The number of files |
2398 // increases if we don't handle the file update right). | 2398 // increases if we don't handle the file update right). |
2399 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); | 2399 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); |
2400 // After the file is updated, the dirty bit is cleared, hence the symlink | 2400 // After the file is updated, the dirty bit is cleared, hence the symlink |
2401 // should be gone. | 2401 // should be gone. |
2402 ASSERT_FALSE(file_util::PathExists(outgoing_symlink_path)); | 2402 ASSERT_FALSE(file_util::PathExists(outgoing_symlink_path)); |
2403 } | 2403 } |
2404 | 2404 |
2405 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_NonexistentFile) { | 2405 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_NonexistentFile) { |
2406 LoadRootFeedDocument("gdata/root_feed.json"); | 2406 LoadRootFeedDocument("gdata/root_feed.json"); |
2407 | 2407 |
2408 // This is nonexistent in root_feed.json. | 2408 // This is nonexistent in root_feed.json. |
2409 const FilePath kFilePath(FILE_PATH_LITERAL("drive/Nonexistent.txt")); | 2409 const FilePath kFilePath(FILE_PATH_LITERAL("drive/Nonexistent.txt")); |
2410 const std::string kResourceId("file:nonexistent_resource_id"); | 2410 const std::string kResourceId("file:nonexistent_resource_id"); |
2411 const std::string kMd5("nonexistent_md5"); | 2411 const std::string kMd5("nonexistent_md5"); |
2412 | 2412 |
2413 // The callback will be called upon completion of | 2413 // The callback will be called upon completion of |
2414 // UpdateFileByResourceId(). | 2414 // UpdateFileByResourceId(). |
2415 FileOperationCallback callback = | 2415 FileOperationCallback callback = |
2416 base::Bind(&CallbackHelper::FileOperationCallback, | 2416 base::Bind(&CallbackHelper::FileOperationCallback, |
2417 callback_helper_.get()); | 2417 callback_helper_.get()); |
2418 | 2418 |
2419 file_system_->UpdateFileByResourceId(kResourceId, callback); | 2419 file_system_->UpdateFileByResourceId(kResourceId, callback); |
2420 test_util::RunBlockingPoolTask(); | 2420 gdata::test_util::RunBlockingPoolTask(); |
2421 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2421 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
2422 } | 2422 } |
2423 | 2423 |
2424 TEST_F(DriveFileSystemTest, ContentSearch) { | 2424 TEST_F(DriveFileSystemTest, ContentSearch) { |
2425 LoadRootFeedDocument("gdata/root_feed.json"); | 2425 LoadRootFeedDocument("gdata/root_feed.json"); |
2426 | 2426 |
2427 mock_drive_service_->set_search_result("gdata/search_result_feed.json"); | 2427 mock_drive_service_->set_search_result("gdata/search_result_feed.json"); |
2428 | 2428 |
2429 EXPECT_CALL(*mock_drive_service_, GetDocuments(Eq(GURL()), _, "foo", _, _)) | 2429 EXPECT_CALL(*mock_drive_service_, GetDocuments(Eq(GURL()), _, "foo", _, _)) |
2430 .Times(1); | 2430 .Times(1); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2492 } | 2492 } |
2493 | 2493 |
2494 TEST_F(DriveFileSystemTest, GetAvailableSpace) { | 2494 TEST_F(DriveFileSystemTest, GetAvailableSpace) { |
2495 GetAvailableSpaceCallback callback = | 2495 GetAvailableSpaceCallback callback = |
2496 base::Bind(&CallbackHelper::GetAvailableSpaceCallback, | 2496 base::Bind(&CallbackHelper::GetAvailableSpaceCallback, |
2497 callback_helper_.get()); | 2497 callback_helper_.get()); |
2498 | 2498 |
2499 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)); | 2499 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)); |
2500 | 2500 |
2501 file_system_->GetAvailableSpace(callback); | 2501 file_system_->GetAvailableSpace(callback); |
2502 test_util::RunBlockingPoolTask(); | 2502 gdata::test_util::RunBlockingPoolTask(); |
2503 EXPECT_EQ(GG_LONGLONG(6789012345), callback_helper_->quota_bytes_used_); | 2503 EXPECT_EQ(GG_LONGLONG(6789012345), callback_helper_->quota_bytes_used_); |
2504 EXPECT_EQ(GG_LONGLONG(9876543210), callback_helper_->quota_bytes_total_); | 2504 EXPECT_EQ(GG_LONGLONG(9876543210), callback_helper_->quota_bytes_total_); |
2505 } | 2505 } |
2506 | 2506 |
2507 TEST_F(DriveFileSystemTest, RequestDirectoryRefresh) { | 2507 TEST_F(DriveFileSystemTest, RequestDirectoryRefresh) { |
2508 LoadRootFeedDocument("gdata/root_feed.json"); | 2508 LoadRootFeedDocument("gdata/root_feed.json"); |
2509 | 2509 |
2510 // We'll fetch documents in the root directory with its resource ID. | 2510 // We'll fetch documents in the root directory with its resource ID. |
2511 EXPECT_CALL(*mock_drive_service_, | 2511 EXPECT_CALL(*mock_drive_service_, |
2512 GetDocuments(Eq(GURL()), _, _, kDriveRootDirectoryResourceId, _)) | 2512 GetDocuments(Eq(GURL()), _, _, kDriveRootDirectoryResourceId, _)) |
2513 .Times(1); | 2513 .Times(1); |
2514 // We'll notify the directory change to the observer. | 2514 // We'll notify the directory change to the observer. |
2515 EXPECT_CALL(*mock_directory_observer_, | 2515 EXPECT_CALL(*mock_directory_observer_, |
2516 OnDirectoryChanged(Eq(FilePath(kDriveRootDirectory)))).Times(1); | 2516 OnDirectoryChanged(Eq(FilePath(kDriveRootDirectory)))).Times(1); |
2517 | 2517 |
2518 file_system_->RequestDirectoryRefresh(FilePath(kDriveRootDirectory)); | 2518 file_system_->RequestDirectoryRefresh(FilePath(kDriveRootDirectory)); |
2519 test_util::RunBlockingPoolTask(); | 2519 gdata::test_util::RunBlockingPoolTask(); |
2520 } | 2520 } |
2521 | 2521 |
2522 TEST_F(DriveFileSystemTest, OpenAndCloseFile) { | 2522 TEST_F(DriveFileSystemTest, OpenAndCloseFile) { |
2523 LoadRootFeedDocument("gdata/root_feed.json"); | 2523 LoadRootFeedDocument("gdata/root_feed.json"); |
2524 | 2524 |
2525 OpenFileCallback callback = | 2525 OpenFileCallback callback = |
2526 base::Bind(&CallbackHelper::OpenFileCallback, | 2526 base::Bind(&CallbackHelper::OpenFileCallback, |
2527 callback_helper_.get()); | 2527 callback_helper_.get()); |
2528 FileOperationCallback close_file_callback = | 2528 FileOperationCallback close_file_callback = |
2529 base::Bind(&CallbackHelper::CloseFileCallback, | 2529 base::Bind(&CallbackHelper::CloseFileCallback, |
(...skipping 16 matching lines...) Expand all Loading... |
2546 // Pretend we have enough space. | 2546 // Pretend we have enough space. |
2547 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2547 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
2548 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); | 2548 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); |
2549 | 2549 |
2550 const std::string kExpectedFileData = "test file data"; | 2550 const std::string kExpectedFileData = "test file data"; |
2551 mock_drive_service_->set_file_data(new std::string(kExpectedFileData)); | 2551 mock_drive_service_->set_file_data(new std::string(kExpectedFileData)); |
2552 | 2552 |
2553 // Before Download starts metadata from server will be fetched. | 2553 // Before Download starts metadata from server will be fetched. |
2554 // We will read content url from the result. | 2554 // We will read content url from the result. |
2555 scoped_ptr<base::Value> document = | 2555 scoped_ptr<base::Value> document = |
2556 test_util::LoadJSONFile("gdata/document_to_download.json"); | 2556 gdata::test_util::LoadJSONFile("gdata/document_to_download.json"); |
2557 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 2557 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
2558 | 2558 |
2559 // The file is obtained with the mock DriveService. | 2559 // The file is obtained with the mock DriveService. |
2560 EXPECT_CALL(*mock_drive_service_, | 2560 EXPECT_CALL(*mock_drive_service_, |
2561 DownloadFile(kFileInRoot, | 2561 DownloadFile(kFileInRoot, |
2562 downloaded_file, | 2562 downloaded_file, |
2563 GURL("https://file_content_url_changed/"), | 2563 GURL("https://file_content_url_changed/"), |
2564 _, _)) | 2564 _, _)) |
2565 .Times(1); | 2565 .Times(1); |
2566 | 2566 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2603 file_md5); | 2603 file_md5); |
2604 | 2604 |
2605 // Try to close the same file twice. | 2605 // Try to close the same file twice. |
2606 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2606 file_system_->CloseFile(kFileInRoot, close_file_callback); |
2607 message_loop_.Run(); | 2607 message_loop_.Run(); |
2608 | 2608 |
2609 // It must fail. | 2609 // It must fail. |
2610 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2610 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
2611 } | 2611 } |
2612 | 2612 |
2613 } // namespace gdata | 2613 } // namespace drive |
OLD | NEW |