| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 const char* path; | 52 const char* path; |
| 53 const bool is_directory; | 53 const bool is_directory; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // Callback to GDataFileSystem::Search used in ContentSearch tests. | 56 // Callback to GDataFileSystem::Search used in ContentSearch tests. |
| 57 // Verifies returned vector of results. | 57 // Verifies returned vector of results. |
| 58 void DriveSearchCallback( | 58 void DriveSearchCallback( |
| 59 MessageLoop* message_loop, | 59 MessageLoop* message_loop, |
| 60 const SearchResultPair* expected_results, | 60 const SearchResultPair* expected_results, |
| 61 size_t expected_results_size, | 61 size_t expected_results_size, |
| 62 GDataFileError error, | 62 DriveFileError error, |
| 63 const GURL& next_feed, | 63 const GURL& next_feed, |
| 64 scoped_ptr<std::vector<SearchResultInfo> > results) { | 64 scoped_ptr<std::vector<SearchResultInfo> > results) { |
| 65 ASSERT_TRUE(results.get()); | 65 ASSERT_TRUE(results.get()); |
| 66 ASSERT_EQ(expected_results_size, results->size()); | 66 ASSERT_EQ(expected_results_size, results->size()); |
| 67 | 67 |
| 68 for (size_t i = 0; i < results->size(); i++) { | 68 for (size_t i = 0; i < results->size(); i++) { |
| 69 EXPECT_EQ(FilePath(expected_results[i].path), | 69 EXPECT_EQ(FilePath(expected_results[i].path), |
| 70 results->at(i).path); | 70 results->at(i).path); |
| 71 EXPECT_EQ(expected_results[i].is_directory, | 71 EXPECT_EQ(expected_results[i].is_directory, |
| 72 results->at(i).is_directory); | 72 results->at(i).is_directory); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // Used for TransferFileFromLocalToRemote_RegularFile test. | 159 // Used for TransferFileFromLocalToRemote_RegularFile test. |
| 160 scoped_ptr<base::Value> value(LoadJSONFile("uploaded_file.json")); | 160 scoped_ptr<base::Value> value(LoadJSONFile("uploaded_file.json")); |
| 161 scoped_ptr<DocumentEntry> document_entry( | 161 scoped_ptr<DocumentEntry> document_entry( |
| 162 DocumentEntry::ExtractAndParse(*value)); | 162 DocumentEntry::ExtractAndParse(*value)); |
| 163 upload_file_info->entry = document_entry.Pass(); | 163 upload_file_info->entry = document_entry.Pass(); |
| 164 | 164 |
| 165 // Run the completion callback. | 165 // Run the completion callback. |
| 166 const UploadFileInfo::UploadCompletionCallback callback = | 166 const UploadFileInfo::UploadCompletionCallback callback = |
| 167 upload_file_info->completion_callback; | 167 upload_file_info->completion_callback; |
| 168 if (!callback.is_null()) | 168 if (!callback.is_null()) |
| 169 callback.Run(GDATA_FILE_OK, upload_file_info.Pass()); | 169 callback.Run(DRIVE_FILE_OK, upload_file_info.Pass()); |
| 170 | 170 |
| 171 const int kUploadId = 123; | 171 const int kUploadId = 123; |
| 172 return kUploadId; | 172 return kUploadId; |
| 173 } | 173 } |
| 174 | 174 |
| 175 // This function is not mockable by gmock. | 175 // This function is not mockable by gmock. |
| 176 virtual int StreamExistingFile( | 176 virtual int StreamExistingFile( |
| 177 scoped_ptr<UploadFileInfo> upload_file_info) OVERRIDE { return 0; } | 177 scoped_ptr<UploadFileInfo> upload_file_info) OVERRIDE { return 0; } |
| 178 | 178 |
| 179 MOCK_METHOD6(UploadExistingFile, | 179 MOCK_METHOD6(UploadExistingFile, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 205 class GDataFileSystemTest : public testing::Test { | 205 class GDataFileSystemTest : public testing::Test { |
| 206 protected: | 206 protected: |
| 207 GDataFileSystemTest() | 207 GDataFileSystemTest() |
| 208 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 208 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 209 io_thread_(content::BrowserThread::IO), | 209 io_thread_(content::BrowserThread::IO), |
| 210 cache_(NULL), | 210 cache_(NULL), |
| 211 file_system_(NULL), | 211 file_system_(NULL), |
| 212 mock_drive_service_(NULL), | 212 mock_drive_service_(NULL), |
| 213 mock_webapps_registry_(NULL), | 213 mock_webapps_registry_(NULL), |
| 214 num_callback_invocations_(0), | 214 num_callback_invocations_(0), |
| 215 expected_error_(GDATA_FILE_OK), | 215 expected_error_(DRIVE_FILE_OK), |
| 216 expected_cache_state_(0), | 216 expected_cache_state_(0), |
| 217 expected_sub_dir_type_(DriveCache::CACHE_TYPE_META), | 217 expected_sub_dir_type_(DriveCache::CACHE_TYPE_META), |
| 218 expected_success_(true), | 218 expected_success_(true), |
| 219 expect_outgoing_symlink_(false), | 219 expect_outgoing_symlink_(false), |
| 220 root_feed_changestamp_(0) { | 220 root_feed_changestamp_(0) { |
| 221 } | 221 } |
| 222 | 222 |
| 223 virtual void SetUp() OVERRIDE { | 223 virtual void SetUp() OVERRIDE { |
| 224 chromeos::CrosLibrary::Initialize(true /* use_stub */); | 224 chromeos::CrosLibrary::Initialize(true /* use_stub */); |
| 225 io_thread_.StartIOThread(); | 225 io_thread_.StartIOThread(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 ASSERT_TRUE(entry_value->GetAsDictionary(&entry_dict)); | 319 ASSERT_TRUE(entry_value->GetAsDictionary(&entry_dict)); |
| 320 | 320 |
| 321 // Tweak entry title to match the last segment of the directory path | 321 // Tweak entry title to match the last segment of the directory path |
| 322 // (new directory name). | 322 // (new directory name). |
| 323 std::vector<FilePath::StringType> dir_parts; | 323 std::vector<FilePath::StringType> dir_parts; |
| 324 directory_path.GetComponents(&dir_parts); | 324 directory_path.GetComponents(&dir_parts); |
| 325 entry_dict->SetString("title.$t", dir_parts[dir_parts.size() - 1]); | 325 entry_dict->SetString("title.$t", dir_parts[dir_parts.size() - 1]); |
| 326 | 326 |
| 327 ASSERT_EQ(file_system_->AddNewDirectory(directory_path.DirName(), | 327 ASSERT_EQ(file_system_->AddNewDirectory(directory_path.DirName(), |
| 328 entry_value), | 328 entry_value), |
| 329 GDATA_FILE_OK) | 329 DRIVE_FILE_OK) |
| 330 << "Failed adding " | 330 << "Failed adding " |
| 331 << directory_path.DirName().value(); | 331 << directory_path.DirName().value(); |
| 332 } | 332 } |
| 333 | 333 |
| 334 // Updates the content of directory under |directory_path| with parsed feed | 334 // Updates the content of directory under |directory_path| with parsed feed |
| 335 // |value|. | 335 // |value|. |
| 336 bool UpdateContent(const std::vector<DocumentFeed*>& list, | 336 bool UpdateContent(const std::vector<DocumentFeed*>& list, |
| 337 int largest_changestamp) { | 337 int largest_changestamp) { |
| 338 GURL unused; | 338 GURL unused; |
| 339 return file_system_->UpdateFromFeedForTesting( | 339 return file_system_->UpdateFromFeedForTesting( |
| 340 list, | 340 list, |
| 341 largest_changestamp, | 341 largest_changestamp, |
| 342 root_feed_changestamp_++) == GDATA_FILE_OK; | 342 root_feed_changestamp_++) == DRIVE_FILE_OK; |
| 343 } | 343 } |
| 344 | 344 |
| 345 bool RemoveEntry(const FilePath& file_path) { | 345 bool RemoveEntry(const FilePath& file_path) { |
| 346 return file_system_->RemoveEntryAndCacheLocally(file_path) == | 346 return file_system_->RemoveEntryAndCacheLocally(file_path) == |
| 347 GDATA_FILE_OK; | 347 DRIVE_FILE_OK; |
| 348 } | 348 } |
| 349 | 349 |
| 350 FilePath GetCachePathForFile(const std::string& resource_id, | 350 FilePath GetCachePathForFile(const std::string& resource_id, |
| 351 const std::string& md5) { | 351 const std::string& md5) { |
| 352 return cache_->GetCacheFilePath(resource_id, | 352 return cache_->GetCacheFilePath(resource_id, |
| 353 md5, | 353 md5, |
| 354 DriveCache::CACHE_TYPE_TMP, | 354 DriveCache::CACHE_TYPE_TMP, |
| 355 DriveCache::CACHED_FILE_FROM_SERVER); | 355 DriveCache::CACHED_FILE_FROM_SERVER); |
| 356 } | 356 } |
| 357 | 357 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 md5, | 436 md5, |
| 437 DriveCache::CACHE_TYPE_TMP, | 437 DriveCache::CACHE_TYPE_TMP, |
| 438 DriveCache::CACHED_FILE_FROM_SERVER); | 438 DriveCache::CACHED_FILE_FROM_SERVER); |
| 439 return file_util::PathExists(file_path); | 439 return file_util::PathExists(file_path); |
| 440 } | 440 } |
| 441 | 441 |
| 442 void TestStoreToCache( | 442 void TestStoreToCache( |
| 443 const std::string& resource_id, | 443 const std::string& resource_id, |
| 444 const std::string& md5, | 444 const std::string& md5, |
| 445 const FilePath& source_path, | 445 const FilePath& source_path, |
| 446 GDataFileError expected_error, | 446 DriveFileError expected_error, |
| 447 int expected_cache_state, | 447 int expected_cache_state, |
| 448 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { | 448 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { |
| 449 expected_error_ = expected_error; | 449 expected_error_ = expected_error; |
| 450 expected_cache_state_ = expected_cache_state; | 450 expected_cache_state_ = expected_cache_state; |
| 451 expected_sub_dir_type_ = expected_sub_dir_type; | 451 expected_sub_dir_type_ = expected_sub_dir_type; |
| 452 | 452 |
| 453 cache_->StoreOnUIThread( | 453 cache_->StoreOnUIThread( |
| 454 resource_id, md5, source_path, | 454 resource_id, md5, source_path, |
| 455 DriveCache::FILE_OPERATION_COPY, | 455 DriveCache::FILE_OPERATION_COPY, |
| 456 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, | 456 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, |
| 457 base::Unretained(this))); | 457 base::Unretained(this))); |
| 458 | 458 |
| 459 test_util::RunBlockingPoolTask(); | 459 test_util::RunBlockingPoolTask(); |
| 460 } | 460 } |
| 461 | 461 |
| 462 void TestPin( | 462 void TestPin( |
| 463 const std::string& resource_id, | 463 const std::string& resource_id, |
| 464 const std::string& md5, | 464 const std::string& md5, |
| 465 GDataFileError expected_error, | 465 DriveFileError expected_error, |
| 466 int expected_cache_state, | 466 int expected_cache_state, |
| 467 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { | 467 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { |
| 468 expected_error_ = expected_error; | 468 expected_error_ = expected_error; |
| 469 expected_cache_state_ = expected_cache_state; | 469 expected_cache_state_ = expected_cache_state; |
| 470 expected_sub_dir_type_ = expected_sub_dir_type; | 470 expected_sub_dir_type_ = expected_sub_dir_type; |
| 471 | 471 |
| 472 cache_->PinOnUIThread( | 472 cache_->PinOnUIThread( |
| 473 resource_id, md5, | 473 resource_id, md5, |
| 474 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, | 474 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, |
| 475 base::Unretained(this))); | 475 base::Unretained(this))); |
| 476 | 476 |
| 477 test_util::RunBlockingPoolTask(); | 477 test_util::RunBlockingPoolTask(); |
| 478 } | 478 } |
| 479 | 479 |
| 480 void TestMarkDirty( | 480 void TestMarkDirty( |
| 481 const std::string& resource_id, | 481 const std::string& resource_id, |
| 482 const std::string& md5, | 482 const std::string& md5, |
| 483 GDataFileError expected_error, | 483 DriveFileError expected_error, |
| 484 int expected_cache_state, | 484 int expected_cache_state, |
| 485 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { | 485 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { |
| 486 expected_error_ = expected_error; | 486 expected_error_ = expected_error; |
| 487 expected_cache_state_ = expected_cache_state; | 487 expected_cache_state_ = expected_cache_state; |
| 488 expected_sub_dir_type_ = expected_sub_dir_type; | 488 expected_sub_dir_type_ = expected_sub_dir_type; |
| 489 expect_outgoing_symlink_ = false; | 489 expect_outgoing_symlink_ = false; |
| 490 | 490 |
| 491 cache_->MarkDirtyOnUIThread( | 491 cache_->MarkDirtyOnUIThread( |
| 492 resource_id, md5, | 492 resource_id, md5, |
| 493 base::Bind(&GDataFileSystemTest::VerifyMarkDirty, | 493 base::Bind(&GDataFileSystemTest::VerifyMarkDirty, |
| 494 base::Unretained(this))); | 494 base::Unretained(this))); |
| 495 | 495 |
| 496 test_util::RunBlockingPoolTask(); | 496 test_util::RunBlockingPoolTask(); |
| 497 } | 497 } |
| 498 | 498 |
| 499 void VerifyMarkDirty(GDataFileError error, | 499 void VerifyMarkDirty(DriveFileError error, |
| 500 const std::string& resource_id, | 500 const std::string& resource_id, |
| 501 const std::string& md5, | 501 const std::string& md5, |
| 502 const FilePath& cache_file_path) { | 502 const FilePath& cache_file_path) { |
| 503 VerifyCacheFileState(error, resource_id, md5); | 503 VerifyCacheFileState(error, resource_id, md5); |
| 504 | 504 |
| 505 // Verify filename of |cache_file_path|. | 505 // Verify filename of |cache_file_path|. |
| 506 if (error == GDATA_FILE_OK) { | 506 if (error == DRIVE_FILE_OK) { |
| 507 FilePath base_name = cache_file_path.BaseName(); | 507 FilePath base_name = cache_file_path.BaseName(); |
| 508 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + | 508 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + |
| 509 FilePath::kExtensionSeparator + | 509 FilePath::kExtensionSeparator + |
| 510 "local", | 510 "local", |
| 511 base_name.value()); | 511 base_name.value()); |
| 512 } else { | 512 } else { |
| 513 EXPECT_TRUE(cache_file_path.empty()); | 513 EXPECT_TRUE(cache_file_path.empty()); |
| 514 } | 514 } |
| 515 } | 515 } |
| 516 | 516 |
| 517 void TestCommitDirty( | 517 void TestCommitDirty( |
| 518 const std::string& resource_id, | 518 const std::string& resource_id, |
| 519 const std::string& md5, | 519 const std::string& md5, |
| 520 GDataFileError expected_error, | 520 DriveFileError expected_error, |
| 521 int expected_cache_state, | 521 int expected_cache_state, |
| 522 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { | 522 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { |
| 523 expected_error_ = expected_error; | 523 expected_error_ = expected_error; |
| 524 expected_cache_state_ = expected_cache_state; | 524 expected_cache_state_ = expected_cache_state; |
| 525 expected_sub_dir_type_ = expected_sub_dir_type; | 525 expected_sub_dir_type_ = expected_sub_dir_type; |
| 526 expect_outgoing_symlink_ = true; | 526 expect_outgoing_symlink_ = true; |
| 527 | 527 |
| 528 cache_->CommitDirtyOnUIThread( | 528 cache_->CommitDirtyOnUIThread( |
| 529 resource_id, md5, | 529 resource_id, md5, |
| 530 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, | 530 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, |
| 531 base::Unretained(this))); | 531 base::Unretained(this))); |
| 532 | 532 |
| 533 test_util::RunBlockingPoolTask(); | 533 test_util::RunBlockingPoolTask(); |
| 534 } | 534 } |
| 535 | 535 |
| 536 // Verify the file identified by |resource_id| and |md5| is in the expected | 536 // Verify the file identified by |resource_id| and |md5| is in the expected |
| 537 // cache state after |OpenFile|, that is, marked dirty and has no outgoing | 537 // cache state after |OpenFile|, that is, marked dirty and has no outgoing |
| 538 // symlink, etc. | 538 // symlink, etc. |
| 539 void VerifyCacheStateAfterOpenFile(GDataFileError error, | 539 void VerifyCacheStateAfterOpenFile(DriveFileError error, |
| 540 const std::string& resource_id, | 540 const std::string& resource_id, |
| 541 const std::string& md5, | 541 const std::string& md5, |
| 542 const FilePath& cache_file_path) { | 542 const FilePath& cache_file_path) { |
| 543 expected_error_ = GDATA_FILE_OK; | 543 expected_error_ = DRIVE_FILE_OK; |
| 544 expected_cache_state_ = (test_util::TEST_CACHE_STATE_PRESENT | | 544 expected_cache_state_ = (test_util::TEST_CACHE_STATE_PRESENT | |
| 545 test_util::TEST_CACHE_STATE_DIRTY | | 545 test_util::TEST_CACHE_STATE_DIRTY | |
| 546 test_util::TEST_CACHE_STATE_PERSISTENT); | 546 test_util::TEST_CACHE_STATE_PERSISTENT); |
| 547 expected_sub_dir_type_ = DriveCache::CACHE_TYPE_PERSISTENT; | 547 expected_sub_dir_type_ = DriveCache::CACHE_TYPE_PERSISTENT; |
| 548 expect_outgoing_symlink_ = false; | 548 expect_outgoing_symlink_ = false; |
| 549 VerifyMarkDirty(error, resource_id, md5, cache_file_path); | 549 VerifyMarkDirty(error, resource_id, md5, cache_file_path); |
| 550 } | 550 } |
| 551 | 551 |
| 552 // Verify the file identified by |resource_id| and |md5| is in the expected | 552 // Verify the file identified by |resource_id| and |md5| is in the expected |
| 553 // cache state after |CloseFile|, that is, marked dirty and has an outgoing | 553 // cache state after |CloseFile|, that is, marked dirty and has an outgoing |
| 554 // symlink, etc. | 554 // symlink, etc. |
| 555 void VerifyCacheStateAfterCloseFile(GDataFileError error, | 555 void VerifyCacheStateAfterCloseFile(DriveFileError error, |
| 556 const std::string& resource_id, | 556 const std::string& resource_id, |
| 557 const std::string& md5) { | 557 const std::string& md5) { |
| 558 expected_error_ = GDATA_FILE_OK; | 558 expected_error_ = DRIVE_FILE_OK; |
| 559 expected_cache_state_ = (test_util::TEST_CACHE_STATE_PRESENT | | 559 expected_cache_state_ = (test_util::TEST_CACHE_STATE_PRESENT | |
| 560 test_util::TEST_CACHE_STATE_DIRTY | | 560 test_util::TEST_CACHE_STATE_DIRTY | |
| 561 test_util::TEST_CACHE_STATE_PERSISTENT); | 561 test_util::TEST_CACHE_STATE_PERSISTENT); |
| 562 expected_sub_dir_type_ = DriveCache::CACHE_TYPE_PERSISTENT; | 562 expected_sub_dir_type_ = DriveCache::CACHE_TYPE_PERSISTENT; |
| 563 expect_outgoing_symlink_ = true; | 563 expect_outgoing_symlink_ = true; |
| 564 VerifyCacheFileState(error, resource_id, md5); | 564 VerifyCacheFileState(error, resource_id, md5); |
| 565 } | 565 } |
| 566 | 566 |
| 567 void VerifyCacheFileState(GDataFileError error, | 567 void VerifyCacheFileState(DriveFileError error, |
| 568 const std::string& resource_id, | 568 const std::string& resource_id, |
| 569 const std::string& md5) { | 569 const std::string& md5) { |
| 570 ++num_callback_invocations_; | 570 ++num_callback_invocations_; |
| 571 | 571 |
| 572 EXPECT_EQ(expected_error_, error); | 572 EXPECT_EQ(expected_error_, error); |
| 573 | 573 |
| 574 // Verify cache map. | 574 // Verify cache map. |
| 575 DriveCacheEntry cache_entry; | 575 DriveCacheEntry cache_entry; |
| 576 const bool cache_entry_found = | 576 const bool cache_entry_found = |
| 577 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); | 577 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 EXPECT_EQ(entry_proto.resource_id(), resource_id); | 758 EXPECT_EQ(entry_proto.resource_id(), resource_id); |
| 759 } | 759 } |
| 760 | 760 |
| 761 // This is used as a helper for registering callbacks that need to be | 761 // This is used as a helper for registering callbacks that need to be |
| 762 // RefCountedThreadSafe, and a place where we can fetch results from various | 762 // RefCountedThreadSafe, and a place where we can fetch results from various |
| 763 // operations. | 763 // operations. |
| 764 class CallbackHelper | 764 class CallbackHelper |
| 765 : public base::RefCountedThreadSafe<CallbackHelper> { | 765 : public base::RefCountedThreadSafe<CallbackHelper> { |
| 766 public: | 766 public: |
| 767 CallbackHelper() | 767 CallbackHelper() |
| 768 : last_error_(GDATA_FILE_OK), | 768 : last_error_(DRIVE_FILE_OK), |
| 769 quota_bytes_total_(0), | 769 quota_bytes_total_(0), |
| 770 quota_bytes_used_(0), | 770 quota_bytes_used_(0), |
| 771 entry_proto_(NULL) {} | 771 entry_proto_(NULL) {} |
| 772 | 772 |
| 773 virtual void GetFileCallback(GDataFileError error, | 773 virtual void GetFileCallback(DriveFileError error, |
| 774 const FilePath& file_path, | 774 const FilePath& file_path, |
| 775 const std::string& mime_type, | 775 const std::string& mime_type, |
| 776 DriveFileType file_type) { | 776 DriveFileType file_type) { |
| 777 last_error_ = error; | 777 last_error_ = error; |
| 778 download_path_ = file_path; | 778 download_path_ = file_path; |
| 779 mime_type_ = mime_type; | 779 mime_type_ = mime_type; |
| 780 file_type_ = file_type; | 780 file_type_ = file_type; |
| 781 } | 781 } |
| 782 | 782 |
| 783 virtual void FileOperationCallback(GDataFileError error) { | 783 virtual void FileOperationCallback(DriveFileError error) { |
| 784 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 784 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 785 | 785 |
| 786 last_error_ = error; | 786 last_error_ = error; |
| 787 } | 787 } |
| 788 | 788 |
| 789 virtual void GetAvailableSpaceCallback(GDataFileError error, | 789 virtual void GetAvailableSpaceCallback(DriveFileError error, |
| 790 int64 bytes_total, | 790 int64 bytes_total, |
| 791 int64 bytes_used) { | 791 int64 bytes_used) { |
| 792 last_error_ = error; | 792 last_error_ = error; |
| 793 quota_bytes_total_ = bytes_total; | 793 quota_bytes_total_ = bytes_total; |
| 794 quota_bytes_used_ = bytes_used; | 794 quota_bytes_used_ = bytes_used; |
| 795 } | 795 } |
| 796 | 796 |
| 797 virtual void OpenFileCallback(GDataFileError error, | 797 virtual void OpenFileCallback(DriveFileError error, |
| 798 const FilePath& file_path) { | 798 const FilePath& file_path) { |
| 799 last_error_ = error; | 799 last_error_ = error; |
| 800 opened_file_path_ = file_path; | 800 opened_file_path_ = file_path; |
| 801 MessageLoop::current()->Quit(); | 801 MessageLoop::current()->Quit(); |
| 802 } | 802 } |
| 803 | 803 |
| 804 virtual void CloseFileCallback(GDataFileError error) { | 804 virtual void CloseFileCallback(DriveFileError error) { |
| 805 last_error_ = error; | 805 last_error_ = error; |
| 806 MessageLoop::current()->Quit(); | 806 MessageLoop::current()->Quit(); |
| 807 } | 807 } |
| 808 | 808 |
| 809 virtual void GetEntryInfoCallback( | 809 virtual void GetEntryInfoCallback( |
| 810 GDataFileError error, | 810 DriveFileError error, |
| 811 scoped_ptr<DriveEntryProto> entry_proto) { | 811 scoped_ptr<DriveEntryProto> entry_proto) { |
| 812 last_error_ = error; | 812 last_error_ = error; |
| 813 entry_proto_ = entry_proto.Pass(); | 813 entry_proto_ = entry_proto.Pass(); |
| 814 } | 814 } |
| 815 | 815 |
| 816 virtual void ReadDirectoryCallback( | 816 virtual void ReadDirectoryCallback( |
| 817 GDataFileError error, | 817 DriveFileError error, |
| 818 bool /* hide_hosted_documents */, | 818 bool /* hide_hosted_documents */, |
| 819 scoped_ptr<DriveEntryProtoVector> entries) { | 819 scoped_ptr<DriveEntryProtoVector> entries) { |
| 820 last_error_ = error; | 820 last_error_ = error; |
| 821 directory_entries_ = entries.Pass(); | 821 directory_entries_ = entries.Pass(); |
| 822 } | 822 } |
| 823 | 823 |
| 824 GDataFileError last_error_; | 824 DriveFileError last_error_; |
| 825 FilePath download_path_; | 825 FilePath download_path_; |
| 826 FilePath opened_file_path_; | 826 FilePath opened_file_path_; |
| 827 std::string mime_type_; | 827 std::string mime_type_; |
| 828 DriveFileType file_type_; | 828 DriveFileType file_type_; |
| 829 int64 quota_bytes_total_; | 829 int64 quota_bytes_total_; |
| 830 int64 quota_bytes_used_; | 830 int64 quota_bytes_used_; |
| 831 scoped_ptr<DriveEntryProto> entry_proto_; | 831 scoped_ptr<DriveEntryProto> entry_proto_; |
| 832 scoped_ptr<DriveEntryProtoVector> directory_entries_; | 832 scoped_ptr<DriveEntryProtoVector> directory_entries_; |
| 833 | 833 |
| 834 protected: | 834 protected: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 849 DriveCache* cache_; | 849 DriveCache* cache_; |
| 850 scoped_ptr<StrictMock<MockGDataUploader> > mock_uploader_; | 850 scoped_ptr<StrictMock<MockGDataUploader> > mock_uploader_; |
| 851 GDataFileSystem* file_system_; | 851 GDataFileSystem* file_system_; |
| 852 StrictMock<MockDriveService>* mock_drive_service_; | 852 StrictMock<MockDriveService>* mock_drive_service_; |
| 853 scoped_ptr<StrictMock<MockDriveWebAppsRegistry> > mock_webapps_registry_; | 853 scoped_ptr<StrictMock<MockDriveWebAppsRegistry> > mock_webapps_registry_; |
| 854 StrictMock<MockFreeDiskSpaceGetter>* mock_free_disk_space_checker_; | 854 StrictMock<MockFreeDiskSpaceGetter>* mock_free_disk_space_checker_; |
| 855 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_; | 855 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_; |
| 856 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; | 856 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; |
| 857 | 857 |
| 858 int num_callback_invocations_; | 858 int num_callback_invocations_; |
| 859 GDataFileError expected_error_; | 859 DriveFileError expected_error_; |
| 860 int expected_cache_state_; | 860 int expected_cache_state_; |
| 861 DriveCache::CacheSubDirectoryType expected_sub_dir_type_; | 861 DriveCache::CacheSubDirectoryType expected_sub_dir_type_; |
| 862 bool expected_success_; | 862 bool expected_success_; |
| 863 bool expect_outgoing_symlink_; | 863 bool expect_outgoing_symlink_; |
| 864 std::string expected_file_extension_; | 864 std::string expected_file_extension_; |
| 865 int root_feed_changestamp_; | 865 int root_feed_changestamp_; |
| 866 static bool cros_initialized_; | 866 static bool cros_initialized_; |
| 867 }; | 867 }; |
| 868 | 868 |
| 869 bool GDataFileSystemTest::cros_initialized_ = false; | 869 bool GDataFileSystemTest::cros_initialized_ = false; |
| 870 | 870 |
| 871 void AsyncInitializationCallback( | 871 void AsyncInitializationCallback( |
| 872 int* counter, | 872 int* counter, |
| 873 int expected_counter, | 873 int expected_counter, |
| 874 const FilePath& expected_file_path, | 874 const FilePath& expected_file_path, |
| 875 MessageLoop* message_loop, | 875 MessageLoop* message_loop, |
| 876 GDataFileError error, | 876 DriveFileError error, |
| 877 scoped_ptr<DriveEntryProto> entry_proto) { | 877 scoped_ptr<DriveEntryProto> entry_proto) { |
| 878 ASSERT_EQ(GDATA_FILE_OK, error); | 878 ASSERT_EQ(DRIVE_FILE_OK, error); |
| 879 ASSERT_TRUE(entry_proto.get()); | 879 ASSERT_TRUE(entry_proto.get()); |
| 880 ASSERT_TRUE(entry_proto->file_info().is_directory()); | 880 ASSERT_TRUE(entry_proto->file_info().is_directory()); |
| 881 EXPECT_EQ(expected_file_path.value(), entry_proto->base_name()); | 881 EXPECT_EQ(expected_file_path.value(), entry_proto->base_name()); |
| 882 | 882 |
| 883 (*counter)++; | 883 (*counter)++; |
| 884 if (*counter >= expected_counter) | 884 if (*counter >= expected_counter) |
| 885 message_loop->Quit(); | 885 message_loop->Quit(); |
| 886 } | 886 } |
| 887 | 887 |
| 888 TEST_F(GDataFileSystemTest, DuplicatedAsyncInitialization) { | 888 TEST_F(GDataFileSystemTest, DuplicatedAsyncInitialization) { |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1276 | 1276 |
| 1277 // Confirm that the remote file does not exist. | 1277 // Confirm that the remote file does not exist. |
| 1278 const FilePath remote_dest_file_path(FILE_PATH_LITERAL("drive/remote.txt")); | 1278 const FilePath remote_dest_file_path(FILE_PATH_LITERAL("drive/remote.txt")); |
| 1279 EXPECT_FALSE(EntryExists(remote_dest_file_path)); | 1279 EXPECT_FALSE(EntryExists(remote_dest_file_path)); |
| 1280 | 1280 |
| 1281 // Transfer the local file to Drive. | 1281 // Transfer the local file to Drive. |
| 1282 file_system_->TransferFileFromLocalToRemote( | 1282 file_system_->TransferFileFromLocalToRemote( |
| 1283 local_src_file_path, remote_dest_file_path, callback); | 1283 local_src_file_path, remote_dest_file_path, callback); |
| 1284 test_util::RunBlockingPoolTask(); | 1284 test_util::RunBlockingPoolTask(); |
| 1285 | 1285 |
| 1286 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1286 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 1287 | 1287 |
| 1288 // Now the remote file should exist. | 1288 // Now the remote file should exist. |
| 1289 EXPECT_TRUE(EntryExists(remote_dest_file_path)); | 1289 EXPECT_TRUE(EntryExists(remote_dest_file_path)); |
| 1290 } | 1290 } |
| 1291 | 1291 |
| 1292 TEST_F(GDataFileSystemTest, TransferFileFromLocalToRemote_HostedDocument) { | 1292 TEST_F(GDataFileSystemTest, TransferFileFromLocalToRemote_HostedDocument) { |
| 1293 LoadRootFeedDocument("root_feed.json"); | 1293 LoadRootFeedDocument("root_feed.json"); |
| 1294 | 1294 |
| 1295 // Prepare a local file, which is a json file of a hosted document, which | 1295 // Prepare a local file, which is a json file of a hosted document, which |
| 1296 // matches "Document 1" in root_feed.json. | 1296 // matches "Document 1" in root_feed.json. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 | 1328 |
| 1329 FileOperationCallback callback = | 1329 FileOperationCallback callback = |
| 1330 base::Bind(&CallbackHelper::FileOperationCallback, | 1330 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1331 callback_helper_.get()); | 1331 callback_helper_.get()); |
| 1332 | 1332 |
| 1333 // Transfer the local file to Drive. | 1333 // Transfer the local file to Drive. |
| 1334 file_system_->TransferFileFromLocalToRemote( | 1334 file_system_->TransferFileFromLocalToRemote( |
| 1335 local_src_file_path, remote_dest_file_path, callback); | 1335 local_src_file_path, remote_dest_file_path, callback); |
| 1336 test_util::RunBlockingPoolTask(); | 1336 test_util::RunBlockingPoolTask(); |
| 1337 | 1337 |
| 1338 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1338 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 1339 | 1339 |
| 1340 // Now the remote file should exist. | 1340 // Now the remote file should exist. |
| 1341 EXPECT_TRUE(EntryExists(remote_dest_file_path)); | 1341 EXPECT_TRUE(EntryExists(remote_dest_file_path)); |
| 1342 } | 1342 } |
| 1343 | 1343 |
| 1344 TEST_F(GDataFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { | 1344 TEST_F(GDataFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { |
| 1345 LoadRootFeedDocument("root_feed.json"); | 1345 LoadRootFeedDocument("root_feed.json"); |
| 1346 | 1346 |
| 1347 FileOperationCallback callback = | 1347 FileOperationCallback callback = |
| 1348 base::Bind(&CallbackHelper::FileOperationCallback, | 1348 base::Bind(&CallbackHelper::FileOperationCallback, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1377 DownloadFile(remote_src_file_path, | 1377 DownloadFile(remote_src_file_path, |
| 1378 cache_file, | 1378 cache_file, |
| 1379 GURL("https://file_content_url_changed/"), | 1379 GURL("https://file_content_url_changed/"), |
| 1380 _, _)) | 1380 _, _)) |
| 1381 .Times(1); | 1381 .Times(1); |
| 1382 | 1382 |
| 1383 file_system_->TransferFileFromRemoteToLocal( | 1383 file_system_->TransferFileFromRemoteToLocal( |
| 1384 remote_src_file_path, local_dest_file_path, callback); | 1384 remote_src_file_path, local_dest_file_path, callback); |
| 1385 test_util::RunBlockingPoolTask(); | 1385 test_util::RunBlockingPoolTask(); |
| 1386 | 1386 |
| 1387 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1387 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 1388 | 1388 |
| 1389 std::string cache_file_data; | 1389 std::string cache_file_data; |
| 1390 EXPECT_TRUE(file_util::ReadFileToString(cache_file, &cache_file_data)); | 1390 EXPECT_TRUE(file_util::ReadFileToString(cache_file, &cache_file_data)); |
| 1391 EXPECT_EQ(remote_src_file_data, cache_file_data); | 1391 EXPECT_EQ(remote_src_file_data, cache_file_data); |
| 1392 | 1392 |
| 1393 std::string local_dest_file_data; | 1393 std::string local_dest_file_data; |
| 1394 EXPECT_TRUE(file_util::ReadFileToString(local_dest_file_path, | 1394 EXPECT_TRUE(file_util::ReadFileToString(local_dest_file_path, |
| 1395 &local_dest_file_data)); | 1395 &local_dest_file_data)); |
| 1396 EXPECT_EQ(remote_src_file_data, local_dest_file_data); | 1396 EXPECT_EQ(remote_src_file_data, local_dest_file_data); |
| 1397 } | 1397 } |
| 1398 | 1398 |
| 1399 TEST_F(GDataFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { | 1399 TEST_F(GDataFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { |
| 1400 LoadRootFeedDocument("root_feed.json"); | 1400 LoadRootFeedDocument("root_feed.json"); |
| 1401 | 1401 |
| 1402 FileOperationCallback callback = | 1402 FileOperationCallback callback = |
| 1403 base::Bind(&CallbackHelper::FileOperationCallback, | 1403 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1404 callback_helper_.get()); | 1404 callback_helper_.get()); |
| 1405 | 1405 |
| 1406 ScopedTempDir temp_dir; | 1406 ScopedTempDir temp_dir; |
| 1407 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1407 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1408 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt"); | 1408 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt"); |
| 1409 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc")); | 1409 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc")); |
| 1410 file_system_->TransferFileFromRemoteToLocal( | 1410 file_system_->TransferFileFromRemoteToLocal( |
| 1411 remote_src_file_path, local_dest_file_path, callback); | 1411 remote_src_file_path, local_dest_file_path, callback); |
| 1412 test_util::RunBlockingPoolTask(); | 1412 test_util::RunBlockingPoolTask(); |
| 1413 | 1413 |
| 1414 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1414 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 1415 | 1415 |
| 1416 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync( | 1416 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync( |
| 1417 remote_src_file_path); | 1417 remote_src_file_path); |
| 1418 ASSERT_TRUE(entry_proto.get()); | 1418 ASSERT_TRUE(entry_proto.get()); |
| 1419 VerifyHostedDocumentJSONFile(*entry_proto, local_dest_file_path); | 1419 VerifyHostedDocumentJSONFile(*entry_proto, local_dest_file_path); |
| 1420 } | 1420 } |
| 1421 | 1421 |
| 1422 TEST_F(GDataFileSystemTest, CopyNotExistingFile) { | 1422 TEST_F(GDataFileSystemTest, CopyNotExistingFile) { |
| 1423 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); | 1423 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); |
| 1424 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); | 1424 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); |
| 1425 | 1425 |
| 1426 LoadRootFeedDocument("root_feed.json"); | 1426 LoadRootFeedDocument("root_feed.json"); |
| 1427 | 1427 |
| 1428 EXPECT_FALSE(EntryExists(src_file_path)); | 1428 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1429 | 1429 |
| 1430 FileOperationCallback callback = | 1430 FileOperationCallback callback = |
| 1431 base::Bind(&CallbackHelper::FileOperationCallback, | 1431 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1432 callback_helper_.get()); | 1432 callback_helper_.get()); |
| 1433 | 1433 |
| 1434 file_system_->Copy(src_file_path, dest_file_path, callback); | 1434 file_system_->Copy(src_file_path, dest_file_path, callback); |
| 1435 test_util::RunBlockingPoolTask(); | 1435 test_util::RunBlockingPoolTask(); |
| 1436 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 1436 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 1437 | 1437 |
| 1438 EXPECT_FALSE(EntryExists(src_file_path)); | 1438 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1439 EXPECT_FALSE(EntryExists(dest_file_path)); | 1439 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1440 } | 1440 } |
| 1441 | 1441 |
| 1442 TEST_F(GDataFileSystemTest, CopyFileToNonExistingDirectory) { | 1442 TEST_F(GDataFileSystemTest, CopyFileToNonExistingDirectory) { |
| 1443 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1443 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 1444 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); | 1444 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); |
| 1445 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); | 1445 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); |
| 1446 | 1446 |
| 1447 LoadRootFeedDocument("root_feed.json"); | 1447 LoadRootFeedDocument("root_feed.json"); |
| 1448 | 1448 |
| 1449 ASSERT_TRUE(EntryExists(src_file_path)); | 1449 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1450 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1450 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1451 src_file_path); | 1451 src_file_path); |
| 1452 ASSERT_TRUE(src_entry_proto.get()); | 1452 ASSERT_TRUE(src_entry_proto.get()); |
| 1453 std::string src_file_path_resource_id = | 1453 std::string src_file_path_resource_id = |
| 1454 src_entry_proto->resource_id(); | 1454 src_entry_proto->resource_id(); |
| 1455 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1455 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1456 | 1456 |
| 1457 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1457 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1458 | 1458 |
| 1459 FileOperationCallback callback = | 1459 FileOperationCallback callback = |
| 1460 base::Bind(&CallbackHelper::FileOperationCallback, | 1460 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1461 callback_helper_.get()); | 1461 callback_helper_.get()); |
| 1462 | 1462 |
| 1463 file_system_->Move(src_file_path, dest_file_path, callback); | 1463 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1464 test_util::RunBlockingPoolTask(); | 1464 test_util::RunBlockingPoolTask(); |
| 1465 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 1465 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 1466 | 1466 |
| 1467 EXPECT_TRUE(EntryExists(src_file_path)); | 1467 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1468 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1468 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1469 EXPECT_FALSE(EntryExists(dest_file_path)); | 1469 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1470 } | 1470 } |
| 1471 | 1471 |
| 1472 // Test the case where the parent of |dest_file_path| is an existing file, | 1472 // Test the case where the parent of |dest_file_path| is an existing file, |
| 1473 // not a directory. | 1473 // not a directory. |
| 1474 TEST_F(GDataFileSystemTest, CopyFileToInvalidPath) { | 1474 TEST_F(GDataFileSystemTest, CopyFileToInvalidPath) { |
| 1475 FilePath src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc")); | 1475 FilePath src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc")); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1491 scoped_ptr<DriveEntryProto> dest_entry_proto = GetEntryInfoByPathSync( | 1491 scoped_ptr<DriveEntryProto> dest_entry_proto = GetEntryInfoByPathSync( |
| 1492 dest_parent_path); | 1492 dest_parent_path); |
| 1493 ASSERT_TRUE(dest_entry_proto.get()); | 1493 ASSERT_TRUE(dest_entry_proto.get()); |
| 1494 | 1494 |
| 1495 FileOperationCallback callback = | 1495 FileOperationCallback callback = |
| 1496 base::Bind(&CallbackHelper::FileOperationCallback, | 1496 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1497 callback_helper_.get()); | 1497 callback_helper_.get()); |
| 1498 | 1498 |
| 1499 file_system_->Copy(src_file_path, dest_file_path, callback); | 1499 file_system_->Copy(src_file_path, dest_file_path, callback); |
| 1500 test_util::RunBlockingPoolTask(); | 1500 test_util::RunBlockingPoolTask(); |
| 1501 EXPECT_EQ(GDATA_FILE_ERROR_NOT_A_DIRECTORY, | 1501 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, |
| 1502 callback_helper_->last_error_); | 1502 callback_helper_->last_error_); |
| 1503 | 1503 |
| 1504 EXPECT_TRUE(EntryExists(src_file_path)); | 1504 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1505 EXPECT_TRUE(EntryExists(src_file_path)); | 1505 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1506 EXPECT_TRUE(EntryExists(dest_parent_path)); | 1506 EXPECT_TRUE(EntryExists(dest_parent_path)); |
| 1507 | 1507 |
| 1508 EXPECT_FALSE(EntryExists(dest_file_path)); | 1508 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1509 } | 1509 } |
| 1510 | 1510 |
| 1511 TEST_F(GDataFileSystemTest, RenameFile) { | 1511 TEST_F(GDataFileSystemTest, RenameFile) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1530 | 1530 |
| 1531 FileOperationCallback callback = | 1531 FileOperationCallback callback = |
| 1532 base::Bind(&CallbackHelper::FileOperationCallback, | 1532 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1533 callback_helper_.get()); | 1533 callback_helper_.get()); |
| 1534 | 1534 |
| 1535 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1535 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1536 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1536 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
| 1537 | 1537 |
| 1538 file_system_->Move(src_file_path, dest_file_path, callback); | 1538 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1539 test_util::RunBlockingPoolTask(); | 1539 test_util::RunBlockingPoolTask(); |
| 1540 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1540 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 1541 | 1541 |
| 1542 EXPECT_FALSE(EntryExists(src_file_path)); | 1542 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1543 EXPECT_TRUE(EntryExists(dest_file_path)); | 1543 EXPECT_TRUE(EntryExists(dest_file_path)); |
| 1544 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1544 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1545 } | 1545 } |
| 1546 | 1546 |
| 1547 TEST_F(GDataFileSystemTest, MoveFileFromRootToSubDirectory) { | 1547 TEST_F(GDataFileSystemTest, MoveFileFromRootToSubDirectory) { |
| 1548 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1548 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 1549 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1549 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); |
| 1550 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Directory 1/Test.log")); | 1550 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Directory 1/Test.log")); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1579 callback_helper_.get()); | 1579 callback_helper_.get()); |
| 1580 | 1580 |
| 1581 // Expect notification for both source and destination directories. | 1581 // Expect notification for both source and destination directories. |
| 1582 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1582 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1583 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1583 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
| 1584 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1584 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1585 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1585 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
| 1586 | 1586 |
| 1587 file_system_->Move(src_file_path, dest_file_path, callback); | 1587 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1588 test_util::RunBlockingPoolTask(); | 1588 test_util::RunBlockingPoolTask(); |
| 1589 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1589 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 1590 | 1590 |
| 1591 EXPECT_FALSE(EntryExists(src_file_path)); | 1591 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1592 EXPECT_TRUE(EntryExists(dest_file_path)); | 1592 EXPECT_TRUE(EntryExists(dest_file_path)); |
| 1593 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1593 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1594 } | 1594 } |
| 1595 | 1595 |
| 1596 TEST_F(GDataFileSystemTest, MoveFileFromSubDirectoryToRoot) { | 1596 TEST_F(GDataFileSystemTest, MoveFileFromSubDirectoryToRoot) { |
| 1597 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1597 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); |
| 1598 FilePath src_file_path( | 1598 FilePath src_file_path( |
| 1599 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); | 1599 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1630 callback_helper_.get()); | 1630 callback_helper_.get()); |
| 1631 | 1631 |
| 1632 // Expect notification for both source and destination directories. | 1632 // Expect notification for both source and destination directories. |
| 1633 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1633 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1634 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1634 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
| 1635 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1635 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1636 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1636 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
| 1637 | 1637 |
| 1638 file_system_->Move(src_file_path, dest_file_path, callback); | 1638 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1639 test_util::RunBlockingPoolTask(); | 1639 test_util::RunBlockingPoolTask(); |
| 1640 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1640 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 1641 | 1641 |
| 1642 EXPECT_FALSE(EntryExists(src_file_path)); | 1642 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1643 ASSERT_TRUE(EntryExists(dest_file_path)); | 1643 ASSERT_TRUE(EntryExists(dest_file_path)); |
| 1644 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1644 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1645 } | 1645 } |
| 1646 | 1646 |
| 1647 TEST_F(GDataFileSystemTest, MoveFileBetweenSubDirectories) { | 1647 TEST_F(GDataFileSystemTest, MoveFileBetweenSubDirectories) { |
| 1648 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1648 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); |
| 1649 FilePath src_file_path( | 1649 FilePath src_file_path( |
| 1650 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); | 1650 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1705 // interim file path. | 1705 // interim file path. |
| 1706 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1706 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1707 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1707 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
| 1708 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1708 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1709 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1709 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
| 1710 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1710 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1711 Eq(FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); | 1711 Eq(FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); |
| 1712 | 1712 |
| 1713 file_system_->Move(src_file_path, dest_file_path, callback); | 1713 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1714 test_util::RunBlockingPoolTask(); | 1714 test_util::RunBlockingPoolTask(); |
| 1715 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1715 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 1716 | 1716 |
| 1717 EXPECT_FALSE(EntryExists(src_file_path)); | 1717 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1718 EXPECT_FALSE(EntryExists(interim_file_path)); | 1718 EXPECT_FALSE(EntryExists(interim_file_path)); |
| 1719 | 1719 |
| 1720 EXPECT_FALSE(EntryExists(src_file_path)); | 1720 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1721 EXPECT_TRUE(EntryExists(dest_file_path)); | 1721 EXPECT_TRUE(EntryExists(dest_file_path)); |
| 1722 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1722 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1723 } | 1723 } |
| 1724 | 1724 |
| 1725 TEST_F(GDataFileSystemTest, MoveNotExistingFile) { | 1725 TEST_F(GDataFileSystemTest, MoveNotExistingFile) { |
| 1726 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); | 1726 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); |
| 1727 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); | 1727 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); |
| 1728 | 1728 |
| 1729 LoadRootFeedDocument("root_feed.json"); | 1729 LoadRootFeedDocument("root_feed.json"); |
| 1730 | 1730 |
| 1731 EXPECT_FALSE(EntryExists(src_file_path)); | 1731 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1732 | 1732 |
| 1733 FileOperationCallback callback = | 1733 FileOperationCallback callback = |
| 1734 base::Bind(&CallbackHelper::FileOperationCallback, | 1734 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1735 callback_helper_.get()); | 1735 callback_helper_.get()); |
| 1736 | 1736 |
| 1737 file_system_->Move(src_file_path, dest_file_path, callback); | 1737 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1738 test_util::RunBlockingPoolTask(); | 1738 test_util::RunBlockingPoolTask(); |
| 1739 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 1739 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 1740 | 1740 |
| 1741 EXPECT_FALSE(EntryExists(src_file_path)); | 1741 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1742 EXPECT_FALSE(EntryExists(dest_file_path)); | 1742 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1743 } | 1743 } |
| 1744 | 1744 |
| 1745 TEST_F(GDataFileSystemTest, MoveFileToNonExistingDirectory) { | 1745 TEST_F(GDataFileSystemTest, MoveFileToNonExistingDirectory) { |
| 1746 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1746 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 1747 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); | 1747 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); |
| 1748 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); | 1748 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); |
| 1749 | 1749 |
| 1750 LoadRootFeedDocument("root_feed.json"); | 1750 LoadRootFeedDocument("root_feed.json"); |
| 1751 | 1751 |
| 1752 ASSERT_TRUE(EntryExists(src_file_path)); | 1752 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1753 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1753 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1754 src_file_path); | 1754 src_file_path); |
| 1755 ASSERT_TRUE(src_entry_proto.get()); | 1755 ASSERT_TRUE(src_entry_proto.get()); |
| 1756 std::string src_file_resource_id = | 1756 std::string src_file_resource_id = |
| 1757 src_entry_proto->resource_id(); | 1757 src_entry_proto->resource_id(); |
| 1758 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1758 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1759 | 1759 |
| 1760 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1760 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1761 | 1761 |
| 1762 FileOperationCallback callback = | 1762 FileOperationCallback callback = |
| 1763 base::Bind(&CallbackHelper::FileOperationCallback, | 1763 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1764 callback_helper_.get()); | 1764 callback_helper_.get()); |
| 1765 | 1765 |
| 1766 file_system_->Move(src_file_path, dest_file_path, callback); | 1766 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1767 test_util::RunBlockingPoolTask(); | 1767 test_util::RunBlockingPoolTask(); |
| 1768 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 1768 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 1769 | 1769 |
| 1770 | 1770 |
| 1771 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1771 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1772 EXPECT_FALSE(EntryExists(dest_file_path)); | 1772 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1773 } | 1773 } |
| 1774 | 1774 |
| 1775 // Test the case where the parent of |dest_file_path| is a existing file, | 1775 // Test the case where the parent of |dest_file_path| is a existing file, |
| 1776 // not a directory. | 1776 // not a directory. |
| 1777 TEST_F(GDataFileSystemTest, MoveFileToInvalidPath) { | 1777 TEST_F(GDataFileSystemTest, MoveFileToInvalidPath) { |
| 1778 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1778 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1794 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( | 1794 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( |
| 1795 dest_parent_path); | 1795 dest_parent_path); |
| 1796 ASSERT_TRUE(dest_parent_proto.get()); | 1796 ASSERT_TRUE(dest_parent_proto.get()); |
| 1797 | 1797 |
| 1798 FileOperationCallback callback = | 1798 FileOperationCallback callback = |
| 1799 base::Bind(&CallbackHelper::FileOperationCallback, | 1799 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1800 callback_helper_.get()); | 1800 callback_helper_.get()); |
| 1801 | 1801 |
| 1802 file_system_->Move(src_file_path, dest_file_path, callback); | 1802 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1803 test_util::RunBlockingPoolTask(); | 1803 test_util::RunBlockingPoolTask(); |
| 1804 EXPECT_EQ(GDATA_FILE_ERROR_NOT_A_DIRECTORY, | 1804 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, |
| 1805 callback_helper_->last_error_); | 1805 callback_helper_->last_error_); |
| 1806 | 1806 |
| 1807 EXPECT_TRUE(EntryExists(src_file_path)); | 1807 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1808 EXPECT_TRUE(EntryExists(dest_parent_path)); | 1808 EXPECT_TRUE(EntryExists(dest_parent_path)); |
| 1809 EXPECT_FALSE(EntryExists(dest_file_path)); | 1809 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1810 } | 1810 } |
| 1811 | 1811 |
| 1812 TEST_F(GDataFileSystemTest, RemoveEntries) { | 1812 TEST_F(GDataFileSystemTest, RemoveEntries) { |
| 1813 LoadRootFeedDocument("root_feed.json"); | 1813 LoadRootFeedDocument("root_feed.json"); |
| 1814 | 1814 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1943 | 1943 |
| 1944 // Create a directory through the document service | 1944 // Create a directory through the document service |
| 1945 TEST_F(GDataFileSystemTest, CreateDirectoryWithService) { | 1945 TEST_F(GDataFileSystemTest, CreateDirectoryWithService) { |
| 1946 LoadRootFeedDocument("root_feed.json"); | 1946 LoadRootFeedDocument("root_feed.json"); |
| 1947 EXPECT_CALL(*mock_drive_service_, | 1947 EXPECT_CALL(*mock_drive_service_, |
| 1948 CreateDirectory(_, "Sample Directory Title", _)).Times(1); | 1948 CreateDirectory(_, "Sample Directory Title", _)).Times(1); |
| 1949 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1949 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1950 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1950 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
| 1951 | 1951 |
| 1952 // Set last error so it's not a valid error code. | 1952 // Set last error so it's not a valid error code. |
| 1953 callback_helper_->last_error_ = static_cast<GDataFileError>(1); | 1953 callback_helper_->last_error_ = static_cast<DriveFileError>(1); |
| 1954 file_system_->CreateDirectory( | 1954 file_system_->CreateDirectory( |
| 1955 FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")), | 1955 FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")), |
| 1956 false, // is_exclusive | 1956 false, // is_exclusive |
| 1957 true, // is_recursive | 1957 true, // is_recursive |
| 1958 base::Bind(&CallbackHelper::FileOperationCallback, | 1958 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1959 callback_helper_.get())); | 1959 callback_helper_.get())); |
| 1960 test_util::RunBlockingPoolTask(); | 1960 test_util::RunBlockingPoolTask(); |
| 1961 // TODO(gspencer): Uncomment this when we get a blob that | 1961 // TODO(gspencer): Uncomment this when we get a blob that |
| 1962 // works that can be returned from the mock. | 1962 // works that can be returned from the mock. |
| 1963 // EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1963 // EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 1964 } | 1964 } |
| 1965 | 1965 |
| 1966 TEST_F(GDataFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { | 1966 TEST_F(GDataFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { |
| 1967 LoadRootFeedDocument("root_feed.json"); | 1967 LoadRootFeedDocument("root_feed.json"); |
| 1968 | 1968 |
| 1969 GetFileCallback callback = | 1969 GetFileCallback callback = |
| 1970 base::Bind(&CallbackHelper::GetFileCallback, | 1970 base::Bind(&CallbackHelper::GetFileCallback, |
| 1971 callback_helper_.get()); | 1971 callback_helper_.get()); |
| 1972 | 1972 |
| 1973 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1973 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1991 DownloadFile(file_in_root, | 1991 DownloadFile(file_in_root, |
| 1992 downloaded_file, | 1992 downloaded_file, |
| 1993 GURL("https://file_content_url_changed/"), | 1993 GURL("https://file_content_url_changed/"), |
| 1994 _, _)) | 1994 _, _)) |
| 1995 .Times(1); | 1995 .Times(1); |
| 1996 | 1996 |
| 1997 file_system_->GetFileByPath(file_in_root, callback, | 1997 file_system_->GetFileByPath(file_in_root, callback, |
| 1998 GetContentCallback()); | 1998 GetContentCallback()); |
| 1999 test_util::RunBlockingPoolTask(); | 1999 test_util::RunBlockingPoolTask(); |
| 2000 | 2000 |
| 2001 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 2001 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 2002 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 2002 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
| 2003 EXPECT_EQ(downloaded_file.value(), | 2003 EXPECT_EQ(downloaded_file.value(), |
| 2004 callback_helper_->download_path_.value()); | 2004 callback_helper_->download_path_.value()); |
| 2005 } | 2005 } |
| 2006 | 2006 |
| 2007 TEST_F(GDataFileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) { | 2007 TEST_F(GDataFileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) { |
| 2008 LoadRootFeedDocument("root_feed.json"); | 2008 LoadRootFeedDocument("root_feed.json"); |
| 2009 | 2009 |
| 2010 GetFileCallback callback = | 2010 GetFileCallback callback = |
| 2011 base::Bind(&CallbackHelper::GetFileCallback, | 2011 base::Bind(&CallbackHelper::GetFileCallback, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2031 DownloadFile(file_in_root, | 2031 DownloadFile(file_in_root, |
| 2032 downloaded_file, | 2032 downloaded_file, |
| 2033 GURL("https://file_content_url_changed/"), | 2033 GURL("https://file_content_url_changed/"), |
| 2034 _, _)) | 2034 _, _)) |
| 2035 .Times(0); | 2035 .Times(0); |
| 2036 | 2036 |
| 2037 file_system_->GetFileByPath(file_in_root, callback, | 2037 file_system_->GetFileByPath(file_in_root, callback, |
| 2038 GetContentCallback()); | 2038 GetContentCallback()); |
| 2039 test_util::RunBlockingPoolTask(); | 2039 test_util::RunBlockingPoolTask(); |
| 2040 | 2040 |
| 2041 EXPECT_EQ(GDATA_FILE_ERROR_NO_SPACE, | 2041 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, |
| 2042 callback_helper_->last_error_); | 2042 callback_helper_->last_error_); |
| 2043 } | 2043 } |
| 2044 | 2044 |
| 2045 TEST_F(GDataFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) { | 2045 TEST_F(GDataFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) { |
| 2046 LoadRootFeedDocument("root_feed.json"); | 2046 LoadRootFeedDocument("root_feed.json"); |
| 2047 | 2047 |
| 2048 GetFileCallback callback = | 2048 GetFileCallback callback = |
| 2049 base::Bind(&CallbackHelper::GetFileCallback, | 2049 base::Bind(&CallbackHelper::GetFileCallback, |
| 2050 callback_helper_.get()); | 2050 callback_helper_.get()); |
| 2051 | 2051 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2062 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2062 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
| 2063 .WillOnce(Return(file_size + kMinFreeSpace)) | 2063 .WillOnce(Return(file_size + kMinFreeSpace)) |
| 2064 .WillOnce(Return(0)) | 2064 .WillOnce(Return(0)) |
| 2065 .WillOnce(Return(file_size + kMinFreeSpace)) | 2065 .WillOnce(Return(file_size + kMinFreeSpace)) |
| 2066 .WillOnce(Return(file_size + kMinFreeSpace)); | 2066 .WillOnce(Return(file_size + kMinFreeSpace)); |
| 2067 | 2067 |
| 2068 // Store something in the temporary cache directory. | 2068 // Store something in the temporary cache directory. |
| 2069 TestStoreToCache("<resource_id>", | 2069 TestStoreToCache("<resource_id>", |
| 2070 "<md5>", | 2070 "<md5>", |
| 2071 GetTestFilePath("root_feed.json"), | 2071 GetTestFilePath("root_feed.json"), |
| 2072 GDATA_FILE_OK, | 2072 DRIVE_FILE_OK, |
| 2073 test_util::TEST_CACHE_STATE_PRESENT, | 2073 test_util::TEST_CACHE_STATE_PRESENT, |
| 2074 DriveCache::CACHE_TYPE_TMP); | 2074 DriveCache::CACHE_TYPE_TMP); |
| 2075 ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>")); | 2075 ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>")); |
| 2076 ASSERT_TRUE(CacheFileExists("<resource_id>", "<md5>")); | 2076 ASSERT_TRUE(CacheFileExists("<resource_id>", "<md5>")); |
| 2077 | 2077 |
| 2078 // Before Download starts metadata from server will be fetched. | 2078 // Before Download starts metadata from server will be fetched. |
| 2079 // We will read content url from the result. | 2079 // We will read content url from the result. |
| 2080 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json")); | 2080 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json")); |
| 2081 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); | 2081 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); |
| 2082 | 2082 |
| 2083 // The file is obtained with the mock DriveService, because of we freed up the | 2083 // The file is obtained with the mock DriveService, because of we freed up the |
| 2084 // space. | 2084 // space. |
| 2085 EXPECT_CALL(*mock_drive_service_, | 2085 EXPECT_CALL(*mock_drive_service_, |
| 2086 DownloadFile(file_in_root, | 2086 DownloadFile(file_in_root, |
| 2087 downloaded_file, | 2087 downloaded_file, |
| 2088 GURL("https://file_content_url_changed/"), | 2088 GURL("https://file_content_url_changed/"), |
| 2089 _, _)) | 2089 _, _)) |
| 2090 .Times(1); | 2090 .Times(1); |
| 2091 | 2091 |
| 2092 file_system_->GetFileByPath(file_in_root, callback, | 2092 file_system_->GetFileByPath(file_in_root, callback, |
| 2093 GetContentCallback()); | 2093 GetContentCallback()); |
| 2094 test_util::RunBlockingPoolTask(); | 2094 test_util::RunBlockingPoolTask(); |
| 2095 | 2095 |
| 2096 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 2096 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 2097 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 2097 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
| 2098 EXPECT_EQ(downloaded_file.value(), | 2098 EXPECT_EQ(downloaded_file.value(), |
| 2099 callback_helper_->download_path_.value()); | 2099 callback_helper_->download_path_.value()); |
| 2100 | 2100 |
| 2101 // The file should be removed in order to free up space, and the cache | 2101 // The file should be removed in order to free up space, and the cache |
| 2102 // entry should also be removed. | 2102 // entry should also be removed. |
| 2103 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>")); | 2103 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>")); |
| 2104 ASSERT_FALSE(CacheFileExists("<resource_id>", "<md5>")); | 2104 ASSERT_FALSE(CacheFileExists("<resource_id>", "<md5>")); |
| 2105 } | 2105 } |
| 2106 | 2106 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2137 DownloadFile(file_in_root, | 2137 DownloadFile(file_in_root, |
| 2138 downloaded_file, | 2138 downloaded_file, |
| 2139 GURL("https://file_content_url_changed/"), | 2139 GURL("https://file_content_url_changed/"), |
| 2140 _, _)) | 2140 _, _)) |
| 2141 .Times(1); | 2141 .Times(1); |
| 2142 | 2142 |
| 2143 file_system_->GetFileByPath(file_in_root, callback, | 2143 file_system_->GetFileByPath(file_in_root, callback, |
| 2144 GetContentCallback()); | 2144 GetContentCallback()); |
| 2145 test_util::RunBlockingPoolTask(); | 2145 test_util::RunBlockingPoolTask(); |
| 2146 | 2146 |
| 2147 EXPECT_EQ(GDATA_FILE_ERROR_NO_SPACE, | 2147 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, |
| 2148 callback_helper_->last_error_); | 2148 callback_helper_->last_error_); |
| 2149 } | 2149 } |
| 2150 | 2150 |
| 2151 TEST_F(GDataFileSystemTest, GetFileByPath_FromCache) { | 2151 TEST_F(GDataFileSystemTest, GetFileByPath_FromCache) { |
| 2152 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 2152 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
| 2153 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); | 2153 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); |
| 2154 | 2154 |
| 2155 LoadRootFeedDocument("root_feed.json"); | 2155 LoadRootFeedDocument("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/File 1.txt")); | 2161 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 2162 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 2162 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 2163 FilePath downloaded_file = GetCachePathForFile( | 2163 FilePath downloaded_file = GetCachePathForFile( |
| 2164 entry_proto->resource_id(), | 2164 entry_proto->resource_id(), |
| 2165 entry_proto->file_specific_info().file_md5()); | 2165 entry_proto->file_specific_info().file_md5()); |
| 2166 | 2166 |
| 2167 // Store something as cached version of this file. | 2167 // Store something as cached version of this file. |
| 2168 TestStoreToCache(entry_proto->resource_id(), | 2168 TestStoreToCache(entry_proto->resource_id(), |
| 2169 entry_proto->file_specific_info().file_md5(), | 2169 entry_proto->file_specific_info().file_md5(), |
| 2170 GetTestFilePath("root_feed.json"), | 2170 GetTestFilePath("root_feed.json"), |
| 2171 GDATA_FILE_OK, | 2171 DRIVE_FILE_OK, |
| 2172 test_util::TEST_CACHE_STATE_PRESENT, | 2172 test_util::TEST_CACHE_STATE_PRESENT, |
| 2173 DriveCache::CACHE_TYPE_TMP); | 2173 DriveCache::CACHE_TYPE_TMP); |
| 2174 | 2174 |
| 2175 // Make sure we don't fetch metadata for downloading file. | 2175 // Make sure we don't fetch metadata for downloading file. |
| 2176 EXPECT_CALL(*mock_drive_service_, GetDocumentEntry(_, _)).Times(0); | 2176 EXPECT_CALL(*mock_drive_service_, GetDocumentEntry(_, _)).Times(0); |
| 2177 | 2177 |
| 2178 // Make sure we don't call downloads at all. | 2178 // Make sure we don't call downloads at all. |
| 2179 EXPECT_CALL(*mock_drive_service_, | 2179 EXPECT_CALL(*mock_drive_service_, |
| 2180 DownloadFile(file_in_root, | 2180 DownloadFile(file_in_root, |
| 2181 downloaded_file, | 2181 downloaded_file, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2269 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 2269 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 2270 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 2270 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 2271 FilePath downloaded_file = GetCachePathForFile( | 2271 FilePath downloaded_file = GetCachePathForFile( |
| 2272 entry_proto->resource_id(), | 2272 entry_proto->resource_id(), |
| 2273 entry_proto->file_specific_info().file_md5()); | 2273 entry_proto->file_specific_info().file_md5()); |
| 2274 | 2274 |
| 2275 // Store something as cached version of this file. | 2275 // Store something as cached version of this file. |
| 2276 TestStoreToCache(entry_proto->resource_id(), | 2276 TestStoreToCache(entry_proto->resource_id(), |
| 2277 entry_proto->file_specific_info().file_md5(), | 2277 entry_proto->file_specific_info().file_md5(), |
| 2278 GetTestFilePath("root_feed.json"), | 2278 GetTestFilePath("root_feed.json"), |
| 2279 GDATA_FILE_OK, | 2279 DRIVE_FILE_OK, |
| 2280 test_util::TEST_CACHE_STATE_PRESENT, | 2280 test_util::TEST_CACHE_STATE_PRESENT, |
| 2281 DriveCache::CACHE_TYPE_TMP); | 2281 DriveCache::CACHE_TYPE_TMP); |
| 2282 | 2282 |
| 2283 // The file is obtained from the cache. | 2283 // The file is obtained from the cache. |
| 2284 // Make sure we don't call downloads at all. | 2284 // Make sure we don't call downloads at all. |
| 2285 EXPECT_CALL(*mock_drive_service_, DownloadFile(_, _, _, _, _)) | 2285 EXPECT_CALL(*mock_drive_service_, DownloadFile(_, _, _, _, _)) |
| 2286 .Times(0); | 2286 .Times(0); |
| 2287 | 2287 |
| 2288 file_system_->GetFileByResourceId(entry_proto->resource_id(), | 2288 file_system_->GetFileByResourceId(entry_proto->resource_id(), |
| 2289 callback, | 2289 callback, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2303 | 2303 |
| 2304 // This is a file defined in root_feed.json. | 2304 // This is a file defined in root_feed.json. |
| 2305 const FilePath kFilePath(FILE_PATH_LITERAL("drive/File 1.txt")); | 2305 const FilePath kFilePath(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 2306 const std::string kResourceId("file:2_file_resource_id"); | 2306 const std::string kResourceId("file:2_file_resource_id"); |
| 2307 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce"); | 2307 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce"); |
| 2308 | 2308 |
| 2309 // Pin the file so it'll be store in "persistent" directory. | 2309 // Pin the file so it'll be store in "persistent" directory. |
| 2310 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(kResourceId, kMd5)).Times(1); | 2310 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(kResourceId, kMd5)).Times(1); |
| 2311 TestPin(kResourceId, | 2311 TestPin(kResourceId, |
| 2312 kMd5, | 2312 kMd5, |
| 2313 GDATA_FILE_OK, | 2313 DRIVE_FILE_OK, |
| 2314 test_util::TEST_CACHE_STATE_PINNED, | 2314 test_util::TEST_CACHE_STATE_PINNED, |
| 2315 DriveCache::CACHE_TYPE_TMP); | 2315 DriveCache::CACHE_TYPE_TMP); |
| 2316 | 2316 |
| 2317 // First store a file to cache. A cache file will be created at: | 2317 // First store a file to cache. A cache file will be created at: |
| 2318 // GCache/v1/persistent/<kResourceId>.<kMd5> | 2318 // GCache/v1/persistent/<kResourceId>.<kMd5> |
| 2319 const FilePath original_cache_file_path = | 2319 const FilePath original_cache_file_path = |
| 2320 DriveCache::GetCacheRootPath(profile_.get()) | 2320 DriveCache::GetCacheRootPath(profile_.get()) |
| 2321 .AppendASCII("persistent") | 2321 .AppendASCII("persistent") |
| 2322 .AppendASCII(kResourceId + "." + kMd5); | 2322 .AppendASCII(kResourceId + "." + kMd5); |
| 2323 TestStoreToCache(kResourceId, | 2323 TestStoreToCache(kResourceId, |
| 2324 kMd5, | 2324 kMd5, |
| 2325 GetTestFilePath("root_feed.json"), // Anything works. | 2325 GetTestFilePath("root_feed.json"), // Anything works. |
| 2326 GDATA_FILE_OK, | 2326 DRIVE_FILE_OK, |
| 2327 test_util::TEST_CACHE_STATE_PRESENT | | 2327 test_util::TEST_CACHE_STATE_PRESENT | |
| 2328 test_util::TEST_CACHE_STATE_PINNED | | 2328 test_util::TEST_CACHE_STATE_PINNED | |
| 2329 test_util::TEST_CACHE_STATE_PERSISTENT, | 2329 test_util::TEST_CACHE_STATE_PERSISTENT, |
| 2330 DriveCache::CACHE_TYPE_PERSISTENT); | 2330 DriveCache::CACHE_TYPE_PERSISTENT); |
| 2331 ASSERT_TRUE(file_util::PathExists(original_cache_file_path)); | 2331 ASSERT_TRUE(file_util::PathExists(original_cache_file_path)); |
| 2332 | 2332 |
| 2333 // Add the dirty bit. The cache file will be renamed to | 2333 // Add the dirty bit. The cache file will be renamed to |
| 2334 // GCache/v1/persistent/<kResourceId>.local | 2334 // GCache/v1/persistent/<kResourceId>.local |
| 2335 TestMarkDirty(kResourceId, | 2335 TestMarkDirty(kResourceId, |
| 2336 kMd5, | 2336 kMd5, |
| 2337 GDATA_FILE_OK, | 2337 DRIVE_FILE_OK, |
| 2338 test_util::TEST_CACHE_STATE_PRESENT | | 2338 test_util::TEST_CACHE_STATE_PRESENT | |
| 2339 test_util::TEST_CACHE_STATE_PINNED | | 2339 test_util::TEST_CACHE_STATE_PINNED | |
| 2340 test_util::TEST_CACHE_STATE_DIRTY | | 2340 test_util::TEST_CACHE_STATE_DIRTY | |
| 2341 test_util::TEST_CACHE_STATE_PERSISTENT, | 2341 test_util::TEST_CACHE_STATE_PERSISTENT, |
| 2342 DriveCache::CACHE_TYPE_PERSISTENT); | 2342 DriveCache::CACHE_TYPE_PERSISTENT); |
| 2343 const FilePath dirty_cache_file_path = | 2343 const FilePath dirty_cache_file_path = |
| 2344 DriveCache::GetCacheRootPath(profile_.get()) | 2344 DriveCache::GetCacheRootPath(profile_.get()) |
| 2345 .AppendASCII("persistent") | 2345 .AppendASCII("persistent") |
| 2346 .AppendASCII(kResourceId + ".local"); | 2346 .AppendASCII(kResourceId + ".local"); |
| 2347 ASSERT_FALSE(file_util::PathExists(original_cache_file_path)); | 2347 ASSERT_FALSE(file_util::PathExists(original_cache_file_path)); |
| 2348 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); | 2348 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); |
| 2349 | 2349 |
| 2350 // Modify the cached file. | 2350 // Modify the cached file. |
| 2351 const std::string kDummyCacheContent("modification to the cache"); | 2351 const std::string kDummyCacheContent("modification to the cache"); |
| 2352 ASSERT_TRUE(file_util::WriteFile(dirty_cache_file_path, | 2352 ASSERT_TRUE(file_util::WriteFile(dirty_cache_file_path, |
| 2353 kDummyCacheContent.c_str(), | 2353 kDummyCacheContent.c_str(), |
| 2354 kDummyCacheContent.size())); | 2354 kDummyCacheContent.size())); |
| 2355 | 2355 |
| 2356 // Commit the dirty bit. The cache file name remains the same | 2356 // Commit the dirty bit. The cache file name remains the same |
| 2357 // but a symlink will be created at: | 2357 // but a symlink will be created at: |
| 2358 // GCache/v1/outgoing/<kResourceId> | 2358 // GCache/v1/outgoing/<kResourceId> |
| 2359 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(kResourceId)).Times(1); | 2359 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(kResourceId)).Times(1); |
| 2360 TestCommitDirty(kResourceId, | 2360 TestCommitDirty(kResourceId, |
| 2361 kMd5, | 2361 kMd5, |
| 2362 GDATA_FILE_OK, | 2362 DRIVE_FILE_OK, |
| 2363 test_util::TEST_CACHE_STATE_PRESENT | | 2363 test_util::TEST_CACHE_STATE_PRESENT | |
| 2364 test_util::TEST_CACHE_STATE_PINNED | | 2364 test_util::TEST_CACHE_STATE_PINNED | |
| 2365 test_util::TEST_CACHE_STATE_DIRTY | | 2365 test_util::TEST_CACHE_STATE_DIRTY | |
| 2366 test_util::TEST_CACHE_STATE_PERSISTENT, | 2366 test_util::TEST_CACHE_STATE_PERSISTENT, |
| 2367 DriveCache::CACHE_TYPE_PERSISTENT); | 2367 DriveCache::CACHE_TYPE_PERSISTENT); |
| 2368 const FilePath outgoing_symlink_path = | 2368 const FilePath outgoing_symlink_path = |
| 2369 DriveCache::GetCacheRootPath(profile_.get()) | 2369 DriveCache::GetCacheRootPath(profile_.get()) |
| 2370 .AppendASCII("outgoing") | 2370 .AppendASCII("outgoing") |
| 2371 .AppendASCII(kResourceId); | 2371 .AppendASCII(kResourceId); |
| 2372 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); | 2372 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2397 | 2397 |
| 2398 // The mock uploader will be used to simulate a file upload. | 2398 // The mock uploader will be used to simulate a file upload. |
| 2399 EXPECT_CALL(*mock_uploader_, UploadExistingFile( | 2399 EXPECT_CALL(*mock_uploader_, UploadExistingFile( |
| 2400 GURL("https://file_link_resumable_edit_media/"), | 2400 GURL("https://file_link_resumable_edit_media/"), |
| 2401 kFilePath, | 2401 kFilePath, |
| 2402 dirty_cache_file_path, | 2402 dirty_cache_file_path, |
| 2403 kDummyCacheContent.size(), // The size after modification must be used. | 2403 kDummyCacheContent.size(), // The size after modification must be used. |
| 2404 "audio/mpeg", | 2404 "audio/mpeg", |
| 2405 _)) // callback | 2405 _)) // callback |
| 2406 .WillOnce(MockUploadExistingFile( | 2406 .WillOnce(MockUploadExistingFile( |
| 2407 GDATA_FILE_OK, | 2407 DRIVE_FILE_OK, |
| 2408 FilePath::FromUTF8Unsafe("drive/File1"), | 2408 FilePath::FromUTF8Unsafe("drive/File1"), |
| 2409 dirty_cache_file_path, | 2409 dirty_cache_file_path, |
| 2410 document_entry)); | 2410 document_entry)); |
| 2411 | 2411 |
| 2412 // We'll notify the directory change to the observer upon completion. | 2412 // We'll notify the directory change to the observer upon completion. |
| 2413 EXPECT_CALL(*mock_directory_observer_, | 2413 EXPECT_CALL(*mock_directory_observer_, |
| 2414 OnDirectoryChanged(Eq(FilePath(kDriveRootDirectory)))).Times(1); | 2414 OnDirectoryChanged(Eq(FilePath(kDriveRootDirectory)))).Times(1); |
| 2415 | 2415 |
| 2416 // The callback will be called upon completion of | 2416 // The callback will be called upon completion of |
| 2417 // UpdateFileByResourceId(). | 2417 // UpdateFileByResourceId(). |
| 2418 FileOperationCallback callback = | 2418 FileOperationCallback callback = |
| 2419 base::Bind(&CallbackHelper::FileOperationCallback, | 2419 base::Bind(&CallbackHelper::FileOperationCallback, |
| 2420 callback_helper_.get()); | 2420 callback_helper_.get()); |
| 2421 | 2421 |
| 2422 // Check the number of files in the root directory. We'll compare the | 2422 // Check the number of files in the root directory. We'll compare the |
| 2423 // number after updating a file. | 2423 // number after updating a file. |
| 2424 scoped_ptr<DriveEntryProtoVector> root_directory_entries( | 2424 scoped_ptr<DriveEntryProtoVector> root_directory_entries( |
| 2425 ReadDirectoryByPathSync(FilePath::FromUTF8Unsafe("drive"))); | 2425 ReadDirectoryByPathSync(FilePath::FromUTF8Unsafe("drive"))); |
| 2426 ASSERT_TRUE(root_directory_entries.get()); | 2426 ASSERT_TRUE(root_directory_entries.get()); |
| 2427 const int num_files_in_root = CountFiles(*root_directory_entries); | 2427 const int num_files_in_root = CountFiles(*root_directory_entries); |
| 2428 | 2428 |
| 2429 file_system_->UpdateFileByResourceId(kResourceId, callback); | 2429 file_system_->UpdateFileByResourceId(kResourceId, callback); |
| 2430 test_util::RunBlockingPoolTask(); | 2430 test_util::RunBlockingPoolTask(); |
| 2431 | 2431 |
| 2432 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 2432 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 2433 // Make sure that the number of files did not change (i.e. we updated an | 2433 // Make sure that the number of files did not change (i.e. we updated an |
| 2434 // existing file, rather than adding a new file. The number of files | 2434 // existing file, rather than adding a new file. The number of files |
| 2435 // increases if we don't handle the file update right). | 2435 // increases if we don't handle the file update right). |
| 2436 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); | 2436 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); |
| 2437 // After the file is updated, the dirty bit is cleared, hence the symlink | 2437 // After the file is updated, the dirty bit is cleared, hence the symlink |
| 2438 // should be gone. | 2438 // should be gone. |
| 2439 ASSERT_FALSE(file_util::PathExists(outgoing_symlink_path)); | 2439 ASSERT_FALSE(file_util::PathExists(outgoing_symlink_path)); |
| 2440 } | 2440 } |
| 2441 | 2441 |
| 2442 TEST_F(GDataFileSystemTest, UpdateFileByResourceId_NonexistentFile) { | 2442 TEST_F(GDataFileSystemTest, UpdateFileByResourceId_NonexistentFile) { |
| 2443 LoadRootFeedDocument("root_feed.json"); | 2443 LoadRootFeedDocument("root_feed.json"); |
| 2444 | 2444 |
| 2445 // This is nonexistent in root_feed.json. | 2445 // This is nonexistent in root_feed.json. |
| 2446 const FilePath kFilePath(FILE_PATH_LITERAL("drive/Nonexistent.txt")); | 2446 const FilePath kFilePath(FILE_PATH_LITERAL("drive/Nonexistent.txt")); |
| 2447 const std::string kResourceId("file:nonexistent_resource_id"); | 2447 const std::string kResourceId("file:nonexistent_resource_id"); |
| 2448 const std::string kMd5("nonexistent_md5"); | 2448 const std::string kMd5("nonexistent_md5"); |
| 2449 | 2449 |
| 2450 // The callback will be called upon completion of | 2450 // The callback will be called upon completion of |
| 2451 // UpdateFileByResourceId(). | 2451 // UpdateFileByResourceId(). |
| 2452 FileOperationCallback callback = | 2452 FileOperationCallback callback = |
| 2453 base::Bind(&CallbackHelper::FileOperationCallback, | 2453 base::Bind(&CallbackHelper::FileOperationCallback, |
| 2454 callback_helper_.get()); | 2454 callback_helper_.get()); |
| 2455 | 2455 |
| 2456 file_system_->UpdateFileByResourceId(kResourceId, callback); | 2456 file_system_->UpdateFileByResourceId(kResourceId, callback); |
| 2457 test_util::RunBlockingPoolTask(); | 2457 test_util::RunBlockingPoolTask(); |
| 2458 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2458 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 2459 } | 2459 } |
| 2460 | 2460 |
| 2461 TEST_F(GDataFileSystemTest, ContentSearch) { | 2461 TEST_F(GDataFileSystemTest, ContentSearch) { |
| 2462 LoadRootFeedDocument("root_feed.json"); | 2462 LoadRootFeedDocument("root_feed.json"); |
| 2463 | 2463 |
| 2464 mock_drive_service_->set_search_result("search_result_feed.json"); | 2464 mock_drive_service_->set_search_result("search_result_feed.json"); |
| 2465 | 2465 |
| 2466 EXPECT_CALL(*mock_drive_service_, GetDocuments(Eq(GURL()), _, "foo", _, _)) | 2466 EXPECT_CALL(*mock_drive_service_, GetDocuments(Eq(GURL()), _, "foo", _, _)) |
| 2467 .Times(1); | 2467 .Times(1); |
| 2468 | 2468 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2599 GURL("https://file_content_url_changed/"), | 2599 GURL("https://file_content_url_changed/"), |
| 2600 _, _)) | 2600 _, _)) |
| 2601 .Times(1); | 2601 .Times(1); |
| 2602 | 2602 |
| 2603 // Open kFileInRoot ("drive/File 1.txt"). | 2603 // Open kFileInRoot ("drive/File 1.txt"). |
| 2604 file_system_->OpenFile(kFileInRoot, callback); | 2604 file_system_->OpenFile(kFileInRoot, callback); |
| 2605 message_loop_.Run(); | 2605 message_loop_.Run(); |
| 2606 const FilePath opened_file_path = callback_helper_->opened_file_path_; | 2606 const FilePath opened_file_path = callback_helper_->opened_file_path_; |
| 2607 | 2607 |
| 2608 // Verify that the file was properly opened. | 2608 // Verify that the file was properly opened. |
| 2609 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 2609 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 2610 | 2610 |
| 2611 // Try to open the already opened file. | 2611 // Try to open the already opened file. |
| 2612 file_system_->OpenFile(kFileInRoot, callback); | 2612 file_system_->OpenFile(kFileInRoot, callback); |
| 2613 message_loop_.Run(); | 2613 message_loop_.Run(); |
| 2614 | 2614 |
| 2615 // It must fail. | 2615 // It must fail. |
| 2616 EXPECT_EQ(GDATA_FILE_ERROR_IN_USE, callback_helper_->last_error_); | 2616 EXPECT_EQ(DRIVE_FILE_ERROR_IN_USE, callback_helper_->last_error_); |
| 2617 | 2617 |
| 2618 // Verify that the file contents match the expected contents. | 2618 // Verify that the file contents match the expected contents. |
| 2619 std::string cache_file_data; | 2619 std::string cache_file_data; |
| 2620 EXPECT_TRUE(file_util::ReadFileToString(opened_file_path, &cache_file_data)); | 2620 EXPECT_TRUE(file_util::ReadFileToString(opened_file_path, &cache_file_data)); |
| 2621 EXPECT_EQ(kExpectedFileData, cache_file_data); | 2621 EXPECT_EQ(kExpectedFileData, cache_file_data); |
| 2622 | 2622 |
| 2623 // Verify that the cache state was changed as expected. | 2623 // Verify that the cache state was changed as expected. |
| 2624 VerifyCacheStateAfterOpenFile(GDATA_FILE_OK, | 2624 VerifyCacheStateAfterOpenFile(DRIVE_FILE_OK, |
| 2625 file_resource_id, | 2625 file_resource_id, |
| 2626 file_md5, | 2626 file_md5, |
| 2627 opened_file_path); | 2627 opened_file_path); |
| 2628 | 2628 |
| 2629 // Close kFileInRoot ("drive/File 1.txt"). | 2629 // Close kFileInRoot ("drive/File 1.txt"). |
| 2630 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2630 file_system_->CloseFile(kFileInRoot, close_file_callback); |
| 2631 message_loop_.Run(); | 2631 message_loop_.Run(); |
| 2632 | 2632 |
| 2633 // Verify that the file was properly closed. | 2633 // Verify that the file was properly closed. |
| 2634 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 2634 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); |
| 2635 | 2635 |
| 2636 // Verify that the cache state was changed as expected. | 2636 // Verify that the cache state was changed as expected. |
| 2637 VerifyCacheStateAfterCloseFile(GDATA_FILE_OK, | 2637 VerifyCacheStateAfterCloseFile(DRIVE_FILE_OK, |
| 2638 file_resource_id, | 2638 file_resource_id, |
| 2639 file_md5); | 2639 file_md5); |
| 2640 | 2640 |
| 2641 // Try to close the same file twice. | 2641 // Try to close the same file twice. |
| 2642 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2642 file_system_->CloseFile(kFileInRoot, close_file_callback); |
| 2643 message_loop_.Run(); | 2643 message_loop_.Run(); |
| 2644 | 2644 |
| 2645 // It must fail. | 2645 // It must fail. |
| 2646 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2646 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 2647 } | 2647 } |
| 2648 | 2648 |
| 2649 } // namespace gdata | 2649 } // namespace gdata |
| OLD | NEW |