Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc

Issue 10836354: Rename GData* to Drive* in gdata.proto (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for comments. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/json/json_file_value_serializer.h" 11 #include "base/json/json_file_value_serializer.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/scoped_temp_dir.h" 15 #include "base/scoped_temp_dir.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/chromeos/cros/cros_library.h" 19 #include "chrome/browser/chromeos/cros/cros_library.h"
20 #include "chrome/browser/chromeos/gdata/drive.pb.h"
20 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" 21 #include "chrome/browser/chromeos/gdata/drive_api_parser.h"
21 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" 22 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
22 #include "chrome/browser/chromeos/gdata/gdata.pb.h"
23 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 23 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
24 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" 24 #include "chrome/browser/chromeos/gdata/gdata_test_util.h"
25 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" 25 #include "chrome/browser/chromeos/gdata/gdata_uploader.h"
26 #include "chrome/browser/chromeos/gdata/gdata_util.h" 26 #include "chrome/browser/chromeos/gdata/gdata_util.h"
27 #include "chrome/browser/chromeos/gdata/mock_directory_change_observer.h" 27 #include "chrome/browser/chromeos/gdata/mock_directory_change_observer.h"
28 #include "chrome/browser/chromeos/gdata/mock_drive_service.h"
28 #include "chrome/browser/chromeos/gdata/mock_gdata_cache_observer.h" 29 #include "chrome/browser/chromeos/gdata/mock_gdata_cache_observer.h"
29 #include "chrome/browser/chromeos/gdata/mock_drive_service.h"
30 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
31 #include "chrome/test/base/testing_profile.h" 31 #include "chrome/test/base/testing_profile.h"
32 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
33 #include "content/public/test/test_browser_thread.h" 33 #include "content/public/test/test_browser_thread.h"
34 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
36 36
37 using ::testing::AtLeast; 37 using ::testing::AtLeast;
38 using ::testing::Eq; 38 using ::testing::Eq;
39 using ::testing::NotNull; 39 using ::testing::NotNull;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 std::string error; 126 std::string error;
127 JSONFileValueSerializer serializer(path); 127 JSONFileValueSerializer serializer(path);
128 base::Value* value = serializer.Deserialize(NULL, &error); 128 base::Value* value = serializer.Deserialize(NULL, &error);
129 EXPECT_TRUE(value) << 129 EXPECT_TRUE(value) <<
130 "Parse error " << path.value() << ": " << error; 130 "Parse error " << path.value() << ": " << error;
131 return value; 131 return value;
132 } 132 }
133 133
134 // Counts the number of files (not directories) in |entries|. 134 // Counts the number of files (not directories) in |entries|.
135 int CountFiles(const GDataEntryProtoVector& entries) { 135 int CountFiles(const DriveEntryProtoVector& entries) {
136 int num_files = 0; 136 int num_files = 0;
137 for (size_t i = 0; i < entries.size(); ++i) { 137 for (size_t i = 0; i < entries.size(); ++i) {
138 if (!entries[i].file_info().is_directory()) 138 if (!entries[i].file_info().is_directory())
139 ++num_files; 139 ++num_files;
140 } 140 }
141 return num_files; 141 return num_files;
142 } 142 }
143 143
144 } // namespace 144 } // namespace
145 145
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 GDataCache::CACHE_TYPE_TMP, 354 GDataCache::CACHE_TYPE_TMP,
355 GDataCache::CACHED_FILE_FROM_SERVER); 355 GDataCache::CACHED_FILE_FROM_SERVER);
356 } 356 }
357 357
358 // Gets entry info by path synchronously. 358 // Gets entry info by path synchronously.
359 scoped_ptr<GDataEntryProto> GetEntryInfoByPathSync( 359 scoped_ptr<DriveEntryProto> GetEntryInfoByPathSync(
360 const FilePath& file_path) { 360 const FilePath& file_path) {
361 file_system_->GetEntryInfoByPath( 361 file_system_->GetEntryInfoByPath(
362 file_path, 362 file_path,
363 base::Bind(&CallbackHelper::GetEntryInfoCallback, 363 base::Bind(&CallbackHelper::GetEntryInfoCallback,
364 callback_helper_.get())); 364 callback_helper_.get()));
365 test_util::RunBlockingPoolTask(); 365 test_util::RunBlockingPoolTask();
366 366
367 return callback_helper_->entry_proto_.Pass(); 367 return callback_helper_->entry_proto_.Pass();
368 } 368 }
369 369
370 // Gets directory info by path synchronously. 370 // Gets directory info by path synchronously.
371 scoped_ptr<GDataEntryProtoVector> ReadDirectoryByPathSync( 371 scoped_ptr<DriveEntryProtoVector> ReadDirectoryByPathSync(
372 const FilePath& file_path) { 372 const FilePath& file_path) {
373 file_system_->ReadDirectoryByPath( 373 file_system_->ReadDirectoryByPath(
374 file_path, 374 file_path,
375 base::Bind(&CallbackHelper::ReadDirectoryCallback, 375 base::Bind(&CallbackHelper::ReadDirectoryCallback,
376 callback_helper_.get())); 376 callback_helper_.get()));
377 test_util::RunBlockingPoolTask(); 377 test_util::RunBlockingPoolTask();
378 378
379 return callback_helper_->directory_entries_.Pass(); 379 return callback_helper_->directory_entries_.Pass();
380 } 380 }
381 381
382 // Returns true if an entry exists at |file_path|. 382 // Returns true if an entry exists at |file_path|.
383 bool EntryExists(const FilePath& file_path) { 383 bool EntryExists(const FilePath& file_path) {
384 return GetEntryInfoByPathSync(file_path).get(); 384 return GetEntryInfoByPathSync(file_path).get();
385 } 385 }
386 386
387 387
388 // Gets the resource ID of |file_path|. Returns an empty string if not found. 388 // Gets the resource ID of |file_path|. Returns an empty string if not found.
389 std::string GetResourceIdByPath(const FilePath& file_path) { 389 std::string GetResourceIdByPath(const FilePath& file_path) {
390 scoped_ptr<GDataEntryProto> entry_proto = 390 scoped_ptr<DriveEntryProto> entry_proto =
391 GetEntryInfoByPathSync(file_path); 391 GetEntryInfoByPathSync(file_path);
392 if (entry_proto.get()) 392 if (entry_proto.get())
393 return entry_proto->resource_id(); 393 return entry_proto->resource_id();
394 else 394 else
395 return ""; 395 return "";
396 } 396 }
397 397
398 // Helper function to call GetCacheEntry from origin thread. 398 // Helper function to call GetCacheEntry from origin thread.
399 bool GetCacheEntryFromOriginThread(const std::string& resource_id, 399 bool GetCacheEntryFromOriginThread(const std::string& resource_id,
400 const std::string& md5, 400 const std::string& md5,
401 GDataCacheEntry* cache_entry) { 401 DriveCacheEntry* cache_entry) {
402 bool result = false; 402 bool result = false;
403 blocking_task_runner_->PostTask( 403 blocking_task_runner_->PostTask(
404 FROM_HERE, 404 FROM_HERE,
405 base::Bind(&GDataFileSystemTest::GetCacheEntryFromOriginThreadInternal, 405 base::Bind(&GDataFileSystemTest::GetCacheEntryFromOriginThreadInternal,
406 base::Unretained(this), 406 base::Unretained(this),
407 resource_id, 407 resource_id,
408 md5, 408 md5,
409 cache_entry, 409 cache_entry,
410 &result)); 410 &result));
411 test_util::RunBlockingPoolTask(); 411 test_util::RunBlockingPoolTask();
412 return result; 412 return result;
413 } 413 }
414 414
415 // Used to implement GetCacheEntry. 415 // Used to implement GetCacheEntry.
416 void GetCacheEntryFromOriginThreadInternal( 416 void GetCacheEntryFromOriginThreadInternal(
417 const std::string& resource_id, 417 const std::string& resource_id,
418 const std::string& md5, 418 const std::string& md5,
419 GDataCacheEntry* cache_entry, 419 DriveCacheEntry* cache_entry,
420 bool* result) { 420 bool* result) {
421 *result = cache_->GetCacheEntry(resource_id, md5, cache_entry); 421 *result = cache_->GetCacheEntry(resource_id, md5, cache_entry);
422 } 422 }
423 423
424 // Returns true if the cache entry exists for the given resource ID and MD5. 424 // Returns true if the cache entry exists for the given resource ID and MD5.
425 bool CacheEntryExists(const std::string& resource_id, 425 bool CacheEntryExists(const std::string& resource_id,
426 const std::string& md5) { 426 const std::string& md5) {
427 GDataCacheEntry cache_entry; 427 DriveCacheEntry cache_entry;
428 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); 428 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
429 } 429 }
430 430
431 // Returns true if the cache file exists for the given resource ID and MD5. 431 // Returns true if the cache file exists for the given resource ID and MD5.
432 bool CacheFileExists(const std::string& resource_id, 432 bool CacheFileExists(const std::string& resource_id,
433 const std::string& md5) { 433 const std::string& md5) {
434 const FilePath file_path = cache_->GetCacheFilePath( 434 const FilePath file_path = cache_->GetCacheFilePath(
435 resource_id, 435 resource_id,
436 md5, 436 md5,
437 GDataCache::CACHE_TYPE_TMP, 437 GDataCache::CACHE_TYPE_TMP,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 } 565 }
566 566
567 void VerifyCacheFileState(GDataFileError error, 567 void VerifyCacheFileState(GDataFileError 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 GDataCacheEntry 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);
578 if (test_util::ToCacheEntry(expected_cache_state_).is_present() || 578 if (test_util::ToCacheEntry(expected_cache_state_).is_present() ||
579 test_util::ToCacheEntry(expected_cache_state_).is_pinned()) { 579 test_util::ToCacheEntry(expected_cache_state_).is_pinned()) {
580 ASSERT_TRUE(cache_entry_found); 580 ASSERT_TRUE(cache_entry_found);
581 EXPECT_TRUE(test_util::CacheStatesEqual( 581 EXPECT_TRUE(test_util::CacheStatesEqual(
582 test_util::ToCacheEntry(expected_cache_state_), 582 test_util::ToCacheEntry(expected_cache_state_),
583 cache_entry)); 583 cache_entry));
584 EXPECT_EQ(expected_sub_dir_type_, 584 EXPECT_EQ(expected_sub_dir_type_,
585 GDataCache::GetSubDirectoryType(cache_entry)); 585 GDataCache::GetSubDirectoryType(cache_entry));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 test_util::RunBlockingPoolTask(); 658 test_util::RunBlockingPoolTask();
659 } 659 }
660 660
661 // Creates a proto file representing a filesystem with directories: 661 // Creates a proto file representing a filesystem with directories:
662 // drive, drive/Dir1, drive/Dir1/SubDir2 662 // drive, drive/Dir1, drive/Dir1/SubDir2
663 // and files 663 // and files
664 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3. 664 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3.
665 // Sets the changestamp to 654321, equal to that of "account_metadata.json" 665 // Sets the changestamp to 654321, equal to that of "account_metadata.json"
666 // test data, indicating the cache is holding the latest file system info. 666 // test data, indicating the cache is holding the latest file system info.
667 void SaveTestFileSystem() { 667 void SaveTestFileSystem() {
668 GDataRootDirectoryProto root; 668 DriveRootDirectoryProto root;
669 root.set_version(kProtoVersion); 669 root.set_version(kProtoVersion);
670 root.set_largest_changestamp(654321); 670 root.set_largest_changestamp(654321);
671 GDataDirectoryProto* root_dir = root.mutable_gdata_directory(); 671 DriveDirectoryProto* root_dir = root.mutable_gdata_directory();
672 GDataEntryProto* dir_base = root_dir->mutable_gdata_entry(); 672 DriveEntryProto* dir_base = root_dir->mutable_gdata_entry();
673 PlatformFileInfoProto* platform_info = dir_base->mutable_file_info(); 673 PlatformFileInfoProto* platform_info = dir_base->mutable_file_info();
674 dir_base->set_title("drive"); 674 dir_base->set_title("drive");
675 dir_base->set_resource_id(kGDataRootDirectoryResourceId); 675 dir_base->set_resource_id(kGDataRootDirectoryResourceId);
676 dir_base->set_upload_url("http://resumable-create-media/1"); 676 dir_base->set_upload_url("http://resumable-create-media/1");
677 platform_info->set_is_directory(true); 677 platform_info->set_is_directory(true);
678 678
679 // drive/File1 679 // drive/File1
680 GDataEntryProto* file = root_dir->add_child_files(); 680 DriveEntryProto* file = root_dir->add_child_files();
681 file->set_title("File1"); 681 file->set_title("File1");
682 file->set_resource_id("resource_id:File1"); 682 file->set_resource_id("resource_id:File1");
683 file->set_upload_url("http://resumable-edit-media/1"); 683 file->set_upload_url("http://resumable-edit-media/1");
684 file->mutable_file_specific_info()->set_file_md5("md5"); 684 file->mutable_file_specific_info()->set_file_md5("md5");
685 platform_info = file->mutable_file_info(); 685 platform_info = file->mutable_file_info();
686 platform_info->set_is_directory(false); 686 platform_info->set_is_directory(false);
687 platform_info->set_size(1048576); 687 platform_info->set_size(1048576);
688 688
689 // drive/Dir1 689 // drive/Dir1
690 GDataDirectoryProto* dir1 = root_dir->add_child_directories(); 690 DriveDirectoryProto* dir1 = root_dir->add_child_directories();
691 dir_base = dir1->mutable_gdata_entry(); 691 dir_base = dir1->mutable_gdata_entry();
692 dir_base->set_title("Dir1"); 692 dir_base->set_title("Dir1");
693 dir_base->set_resource_id("resource_id:Dir1"); 693 dir_base->set_resource_id("resource_id:Dir1");
694 dir_base->set_upload_url("http://resumable-create-media/2"); 694 dir_base->set_upload_url("http://resumable-create-media/2");
695 platform_info = dir_base->mutable_file_info(); 695 platform_info = dir_base->mutable_file_info();
696 platform_info->set_is_directory(true); 696 platform_info->set_is_directory(true);
697 697
698 // drive/Dir1/File2 698 // drive/Dir1/File2
699 file = dir1->add_child_files(); 699 file = dir1->add_child_files();
700 file->set_title("File2"); 700 file->set_title("File2");
701 file->set_resource_id("resource_id:File2"); 701 file->set_resource_id("resource_id:File2");
702 file->set_upload_url("http://resumable-edit-media/2"); 702 file->set_upload_url("http://resumable-edit-media/2");
703 file->mutable_file_specific_info()->set_file_md5("md5"); 703 file->mutable_file_specific_info()->set_file_md5("md5");
704 platform_info = file->mutable_file_info(); 704 platform_info = file->mutable_file_info();
705 platform_info->set_is_directory(false); 705 platform_info->set_is_directory(false);
706 platform_info->set_size(555); 706 platform_info->set_size(555);
707 707
708 // drive/Dir1/SubDir2 708 // drive/Dir1/SubDir2
709 GDataDirectoryProto* dir2 = dir1->add_child_directories(); 709 DriveDirectoryProto* dir2 = dir1->add_child_directories();
710 dir_base = dir2->mutable_gdata_entry(); 710 dir_base = dir2->mutable_gdata_entry();
711 dir_base->set_title("SubDir2"); 711 dir_base->set_title("SubDir2");
712 dir_base->set_resource_id("resource_id:SubDir2"); 712 dir_base->set_resource_id("resource_id:SubDir2");
713 dir_base->set_upload_url("http://resumable-create-media/3"); 713 dir_base->set_upload_url("http://resumable-create-media/3");
714 platform_info = dir_base->mutable_file_info(); 714 platform_info = dir_base->mutable_file_info();
715 platform_info->set_is_directory(true); 715 platform_info->set_is_directory(true);
716 716
717 // drive/Dir1/SubDir2/File3 717 // drive/Dir1/SubDir2/File3
718 file = dir2->add_child_files(); 718 file = dir2->add_child_files();
719 file->set_title("File3"); 719 file->set_title("File3");
(...skipping 12 matching lines...) Expand all
732 FilePath cache_dir_path = profile_->GetPath().Append( 732 FilePath cache_dir_path = profile_->GetPath().Append(
733 FILE_PATH_LITERAL("GCache/v1/meta/")); 733 FILE_PATH_LITERAL("GCache/v1/meta/"));
734 ASSERT_TRUE(file_util::CreateDirectory(cache_dir_path)); 734 ASSERT_TRUE(file_util::CreateDirectory(cache_dir_path));
735 const int file_size = static_cast<int>(serialized_proto.length()); 735 const int file_size = static_cast<int>(serialized_proto.length());
736 ASSERT_EQ(file_util::WriteFile(cache_dir_path.Append("file_system.pb"), 736 ASSERT_EQ(file_util::WriteFile(cache_dir_path.Append("file_system.pb"),
737 serialized_proto.data(), file_size), file_size); 737 serialized_proto.data(), file_size), file_size);
738 } 738 }
739 739
740 // Verifies that |file_path| is a valid JSON file for the hosted document 740 // Verifies that |file_path| is a valid JSON file for the hosted document
741 // associated with |entry| (i.e. |url| and |resource_id| match). 741 // associated with |entry| (i.e. |url| and |resource_id| match).
742 void VerifyHostedDocumentJSONFile(const GDataEntryProto& entry_proto, 742 void VerifyHostedDocumentJSONFile(const DriveEntryProto& entry_proto,
743 const FilePath& file_path) { 743 const FilePath& file_path) {
744 std::string error; 744 std::string error;
745 JSONFileValueSerializer serializer(file_path); 745 JSONFileValueSerializer serializer(file_path);
746 scoped_ptr<Value> value(serializer.Deserialize(NULL, &error)); 746 scoped_ptr<Value> value(serializer.Deserialize(NULL, &error));
747 ASSERT_TRUE(value.get()) << "Parse error " << file_path.value() 747 ASSERT_TRUE(value.get()) << "Parse error " << file_path.value()
748 << ": " << error; 748 << ": " << error;
749 DictionaryValue* dict_value = NULL; 749 DictionaryValue* dict_value = NULL;
750 ASSERT_TRUE(value->GetAsDictionary(&dict_value)); 750 ASSERT_TRUE(value->GetAsDictionary(&dict_value));
751 751
752 std::string edit_url, resource_id; 752 std::string edit_url, resource_id;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 MessageLoop::current()->Quit(); 801 MessageLoop::current()->Quit();
802 } 802 }
803 803
804 virtual void CloseFileCallback(GDataFileError error) { 804 virtual void CloseFileCallback(GDataFileError 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 GDataFileError error,
811 scoped_ptr<GDataEntryProto> 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 GDataFileError error,
818 bool /* hide_hosted_documents */, 818 bool /* hide_hosted_documents */,
819 scoped_ptr<GDataEntryProtoVector> 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 GDataFileError 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 GDataFileType file_type_; 828 GDataFileType 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<GDataEntryProto> entry_proto_; 831 scoped_ptr<DriveEntryProto> entry_proto_;
832 scoped_ptr<GDataEntryProtoVector> directory_entries_; 832 scoped_ptr<DriveEntryProtoVector> directory_entries_;
833 833
834 protected: 834 protected:
835 virtual ~CallbackHelper() {} 835 virtual ~CallbackHelper() {}
836 836
837 private: 837 private:
838 friend class base::RefCountedThreadSafe<CallbackHelper>; 838 friend class base::RefCountedThreadSafe<CallbackHelper>;
839 }; 839 };
840 840
841 MessageLoopForUI message_loop_; 841 MessageLoopForUI message_loop_;
842 // The order of the test threads is important, do not change the order. 842 // The order of the test threads is important, do not change the order.
(...skipping 24 matching lines...) Expand all
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 GDataFileError error,
877 scoped_ptr<GDataEntryProto> entry_proto) { 877 scoped_ptr<DriveEntryProto> entry_proto) {
878 ASSERT_EQ(GDATA_FILE_OK, error); 878 ASSERT_EQ(GDATA_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
(...skipping 17 matching lines...) Expand all
905 file_system_->GetEntryInfoByPath( 905 file_system_->GetEntryInfoByPath(
906 FilePath(FILE_PATH_LITERAL("drive")), callback); 906 FilePath(FILE_PATH_LITERAL("drive")), callback);
907 message_loop_.Run(); // Wait to get our result 907 message_loop_.Run(); // Wait to get our result
908 EXPECT_EQ(2, counter); 908 EXPECT_EQ(2, counter);
909 } 909 }
910 910
911 TEST_F(GDataFileSystemTest, SearchRootDirectory) { 911 TEST_F(GDataFileSystemTest, SearchRootDirectory) {
912 LoadRootFeedDocument("root_feed.json"); 912 LoadRootFeedDocument("root_feed.json");
913 913
914 const FilePath kFilePath = FilePath(FILE_PATH_LITERAL("drive")); 914 const FilePath kFilePath = FilePath(FILE_PATH_LITERAL("drive"));
915 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync( 915 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(
916 FilePath(FILE_PATH_LITERAL(kFilePath))); 916 FilePath(FILE_PATH_LITERAL(kFilePath)));
917 ASSERT_TRUE(entry.get()); 917 ASSERT_TRUE(entry.get());
918 EXPECT_EQ(kGDataRootDirectoryResourceId, entry->resource_id()); 918 EXPECT_EQ(kGDataRootDirectoryResourceId, entry->resource_id());
919 } 919 }
920 920
921 TEST_F(GDataFileSystemTest, SearchExistingFile) { 921 TEST_F(GDataFileSystemTest, SearchExistingFile) {
922 LoadRootFeedDocument("root_feed.json"); 922 LoadRootFeedDocument("root_feed.json");
923 923
924 const FilePath kFilePath = FilePath( 924 const FilePath kFilePath = FilePath(
925 FILE_PATH_LITERAL("drive/File 1.txt")); 925 FILE_PATH_LITERAL("drive/File 1.txt"));
926 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 926 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
927 ASSERT_TRUE(entry.get()); 927 ASSERT_TRUE(entry.get());
928 EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); 928 EXPECT_EQ("file:2_file_resource_id", entry->resource_id());
929 } 929 }
930 930
931 TEST_F(GDataFileSystemTest, SearchExistingDocument) { 931 TEST_F(GDataFileSystemTest, SearchExistingDocument) {
932 LoadRootFeedDocument("root_feed.json"); 932 LoadRootFeedDocument("root_feed.json");
933 933
934 const FilePath kFilePath = FilePath( 934 const FilePath kFilePath = FilePath(
935 FILE_PATH_LITERAL("drive/Document 1.gdoc")); 935 FILE_PATH_LITERAL("drive/Document 1.gdoc"));
936 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 936 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
937 ASSERT_TRUE(entry.get()); 937 ASSERT_TRUE(entry.get());
938 EXPECT_EQ("document:5_document_resource_id", entry->resource_id()); 938 EXPECT_EQ("document:5_document_resource_id", entry->resource_id());
939 } 939 }
940 940
941 TEST_F(GDataFileSystemTest, SearchNonExistingFile) { 941 TEST_F(GDataFileSystemTest, SearchNonExistingFile) {
942 LoadRootFeedDocument("root_feed.json"); 942 LoadRootFeedDocument("root_feed.json");
943 943
944 const FilePath kFilePath = FilePath( 944 const FilePath kFilePath = FilePath(
945 FILE_PATH_LITERAL("drive/nonexisting.file")); 945 FILE_PATH_LITERAL("drive/nonexisting.file"));
946 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 946 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
947 ASSERT_FALSE(entry.get()); 947 ASSERT_FALSE(entry.get());
948 } 948 }
949 949
950 TEST_F(GDataFileSystemTest, SearchEncodedFileNames) { 950 TEST_F(GDataFileSystemTest, SearchEncodedFileNames) {
951 LoadRootFeedDocument("root_feed.json"); 951 LoadRootFeedDocument("root_feed.json");
952 952
953 const FilePath kFilePath1 = FilePath( 953 const FilePath kFilePath1 = FilePath(
954 FILE_PATH_LITERAL("drive/Slash / in file 1.txt")); 954 FILE_PATH_LITERAL("drive/Slash / in file 1.txt"));
955 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(kFilePath1); 955 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1);
956 ASSERT_FALSE(entry.get()); 956 ASSERT_FALSE(entry.get());
957 957
958 const FilePath kFilePath2 = FilePath::FromUTF8Unsafe( 958 const FilePath kFilePath2 = FilePath::FromUTF8Unsafe(
959 "drive/Slash \xE2\x88\x95 in file 1.txt"); 959 "drive/Slash \xE2\x88\x95 in file 1.txt");
960 entry = GetEntryInfoByPathSync(kFilePath2); 960 entry = GetEntryInfoByPathSync(kFilePath2);
961 ASSERT_TRUE(entry.get()); 961 ASSERT_TRUE(entry.get());
962 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id()); 962 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id());
963 963
964 const FilePath kFilePath3 = FilePath::FromUTF8Unsafe( 964 const FilePath kFilePath3 = FilePath::FromUTF8Unsafe(
965 "drive/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt"); 965 "drive/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt");
966 entry = GetEntryInfoByPathSync(kFilePath3); 966 entry = GetEntryInfoByPathSync(kFilePath3);
967 ASSERT_TRUE(entry.get()); 967 ASSERT_TRUE(entry.get());
968 EXPECT_EQ("file:slash_subdir_file", entry->resource_id()); 968 EXPECT_EQ("file:slash_subdir_file", entry->resource_id());
969 } 969 }
970 970
971 TEST_F(GDataFileSystemTest, SearchEncodedFileNamesLoadingRoot) { 971 TEST_F(GDataFileSystemTest, SearchEncodedFileNamesLoadingRoot) {
972 LoadRootFeedDocument("root_feed.json"); 972 LoadRootFeedDocument("root_feed.json");
973 973
974 const FilePath kFilePath1 = FilePath( 974 const FilePath kFilePath1 = FilePath(
975 FILE_PATH_LITERAL("drive/Slash / in file 1.txt")); 975 FILE_PATH_LITERAL("drive/Slash / in file 1.txt"));
976 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(kFilePath1); 976 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1);
977 ASSERT_FALSE(entry.get()); 977 ASSERT_FALSE(entry.get());
978 978
979 const FilePath kFilePath2 = FilePath::FromUTF8Unsafe( 979 const FilePath kFilePath2 = FilePath::FromUTF8Unsafe(
980 "drive/Slash \xE2\x88\x95 in file 1.txt"); 980 "drive/Slash \xE2\x88\x95 in file 1.txt");
981 entry = GetEntryInfoByPathSync(kFilePath2); 981 entry = GetEntryInfoByPathSync(kFilePath2);
982 ASSERT_TRUE(entry.get()); 982 ASSERT_TRUE(entry.get());
983 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id()); 983 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id());
984 984
985 const FilePath kFilePath3 = FilePath::FromUTF8Unsafe( 985 const FilePath kFilePath3 = FilePath::FromUTF8Unsafe(
986 "drive/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt"); 986 "drive/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt");
987 entry = GetEntryInfoByPathSync(kFilePath3); 987 entry = GetEntryInfoByPathSync(kFilePath3);
988 ASSERT_TRUE(entry.get()); 988 ASSERT_TRUE(entry.get());
989 EXPECT_EQ("file:slash_subdir_file", entry->resource_id()); 989 EXPECT_EQ("file:slash_subdir_file", entry->resource_id());
990 } 990 }
991 991
992 TEST_F(GDataFileSystemTest, SearchDuplicateNames) { 992 TEST_F(GDataFileSystemTest, SearchDuplicateNames) {
993 LoadRootFeedDocument("root_feed.json"); 993 LoadRootFeedDocument("root_feed.json");
994 994
995 const FilePath kFilePath1 = FilePath( 995 const FilePath kFilePath1 = FilePath(
996 FILE_PATH_LITERAL("drive/Duplicate Name.txt")); 996 FILE_PATH_LITERAL("drive/Duplicate Name.txt"));
997 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(kFilePath1); 997 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1);
998 ASSERT_TRUE(entry.get()); 998 ASSERT_TRUE(entry.get());
999 EXPECT_EQ("file:3_file_resource_id", entry->resource_id()); 999 EXPECT_EQ("file:3_file_resource_id", entry->resource_id());
1000 1000
1001 const FilePath kFilePath2 = FilePath( 1001 const FilePath kFilePath2 = FilePath(
1002 FILE_PATH_LITERAL("drive/Duplicate Name (2).txt")); 1002 FILE_PATH_LITERAL("drive/Duplicate Name (2).txt"));
1003 entry = GetEntryInfoByPathSync(kFilePath2); 1003 entry = GetEntryInfoByPathSync(kFilePath2);
1004 ASSERT_TRUE(entry.get()); 1004 ASSERT_TRUE(entry.get());
1005 EXPECT_EQ("file:4_file_resource_id", entry->resource_id()); 1005 EXPECT_EQ("file:4_file_resource_id", entry->resource_id());
1006 } 1006 }
1007 1007
1008 TEST_F(GDataFileSystemTest, SearchExistingDirectory) { 1008 TEST_F(GDataFileSystemTest, SearchExistingDirectory) {
1009 LoadRootFeedDocument("root_feed.json"); 1009 LoadRootFeedDocument("root_feed.json");
1010 1010
1011 const FilePath kFilePath = FilePath( 1011 const FilePath kFilePath = FilePath(
1012 FILE_PATH_LITERAL("drive/Directory 1")); 1012 FILE_PATH_LITERAL("drive/Directory 1"));
1013 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 1013 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
1014 ASSERT_TRUE(entry.get()); 1014 ASSERT_TRUE(entry.get());
1015 ASSERT_EQ("folder:1_folder_resource_id", entry->resource_id()); 1015 ASSERT_EQ("folder:1_folder_resource_id", entry->resource_id());
1016 } 1016 }
1017 1017
1018 TEST_F(GDataFileSystemTest, SearchInSubdir) { 1018 TEST_F(GDataFileSystemTest, SearchInSubdir) {
1019 LoadRootFeedDocument("root_feed.json"); 1019 LoadRootFeedDocument("root_feed.json");
1020 1020
1021 const FilePath kFilePath = FilePath( 1021 const FilePath kFilePath = FilePath(
1022 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); 1022 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt"));
1023 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 1023 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
1024 ASSERT_TRUE(entry.get()); 1024 ASSERT_TRUE(entry.get());
1025 ASSERT_EQ("file:subdirectory_file_1_id", entry->resource_id()); 1025 ASSERT_EQ("file:subdirectory_file_1_id", entry->resource_id());
1026 } 1026 }
1027 1027
1028 // Check the reconstruction of the directory structure from only the root feed. 1028 // Check the reconstruction of the directory structure from only the root feed.
1029 TEST_F(GDataFileSystemTest, SearchInSubSubdir) { 1029 TEST_F(GDataFileSystemTest, SearchInSubSubdir) {
1030 LoadRootFeedDocument("root_feed.json"); 1030 LoadRootFeedDocument("root_feed.json");
1031 1031
1032 const FilePath kFilePath = FilePath( 1032 const FilePath kFilePath = FilePath(
1033 FILE_PATH_LITERAL("drive/Directory 1/Sub Directory Folder/" 1033 FILE_PATH_LITERAL("drive/Directory 1/Sub Directory Folder/"
1034 "Sub Sub Directory Folder")); 1034 "Sub Sub Directory Folder"));
1035 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 1035 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
1036 ASSERT_TRUE(entry.get()); 1036 ASSERT_TRUE(entry.get());
1037 ASSERT_EQ("folder:sub_sub_directory_folder_id", entry->resource_id()); 1037 ASSERT_EQ("folder:sub_sub_directory_folder_id", entry->resource_id());
1038 } 1038 }
1039 1039
1040 TEST_F(GDataFileSystemTest, FilePathTests) { 1040 TEST_F(GDataFileSystemTest, FilePathTests) {
1041 LoadRootFeedDocument("root_feed.json"); 1041 LoadRootFeedDocument("root_feed.json");
1042 1042
1043 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File 1.txt")))); 1043 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File 1.txt"))));
1044 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/Directory 1")))); 1044 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))));
1045 EXPECT_TRUE(EntryExists( 1045 EXPECT_TRUE(EntryExists(
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 1346
1347 FileOperationCallback callback = 1347 FileOperationCallback callback =
1348 base::Bind(&CallbackHelper::FileOperationCallback, 1348 base::Bind(&CallbackHelper::FileOperationCallback,
1349 callback_helper_.get()); 1349 callback_helper_.get());
1350 1350
1351 ScopedTempDir temp_dir; 1351 ScopedTempDir temp_dir;
1352 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1352 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1353 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt"); 1353 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt");
1354 1354
1355 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1355 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/File 1.txt"));
1356 scoped_ptr<GDataEntryProto> file = GetEntryInfoByPathSync( 1356 scoped_ptr<DriveEntryProto> file = GetEntryInfoByPathSync(
1357 remote_src_file_path); 1357 remote_src_file_path);
1358 FilePath cache_file = GetCachePathForFile( 1358 FilePath cache_file = GetCachePathForFile(
1359 file->resource_id(), 1359 file->resource_id(),
1360 file->file_specific_info().file_md5()); 1360 file->file_specific_info().file_md5());
1361 const int64 file_size = file->file_info().size(); 1361 const int64 file_size = file->file_info().size();
1362 1362
1363 // Pretend we have enough space. 1363 // Pretend we have enough space.
1364 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1364 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1365 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); 1365 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace));
1366 1366
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(GDATA_FILE_OK, callback_helper_->last_error_);
1415 1415
1416 scoped_ptr<GDataEntryProto> 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");
(...skipping 13 matching lines...) Expand all
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<GDataEntryProto> 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,
(...skipping 12 matching lines...) Expand all
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"));
1476 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Duplicate Name.txt")); 1476 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Duplicate Name.txt"));
1477 FilePath dest_file_path(FILE_PATH_LITERAL( 1477 FilePath dest_file_path(FILE_PATH_LITERAL(
1478 "drive/Duplicate Name.txt/Document 1.gdoc")); 1478 "drive/Duplicate Name.txt/Document 1.gdoc"));
1479 1479
1480 LoadRootFeedDocument("root_feed.json"); 1480 LoadRootFeedDocument("root_feed.json");
1481 1481
1482 ASSERT_TRUE(EntryExists(src_file_path)); 1482 ASSERT_TRUE(EntryExists(src_file_path));
1483 scoped_ptr<GDataEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1483 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1484 src_file_path); 1484 src_file_path);
1485 ASSERT_TRUE(src_entry_proto.get()); 1485 ASSERT_TRUE(src_entry_proto.get());
1486 std::string src_file_resource_id = 1486 std::string src_file_resource_id =
1487 src_entry_proto->resource_id(); 1487 src_entry_proto->resource_id();
1488 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1488 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1489 1489
1490 ASSERT_TRUE(EntryExists(dest_parent_path)); 1490 ASSERT_TRUE(EntryExists(dest_parent_path));
1491 scoped_ptr<GDataEntryProto> 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(GDATA_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) {
1512 const FilePath src_file_path( 1512 const FilePath src_file_path(
1513 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); 1513 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt"));
1514 const FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); 1514 const FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1"));
1515 const FilePath dest_file_path( 1515 const FilePath dest_file_path(
1516 FILE_PATH_LITERAL("drive/Directory 1/Test.log")); 1516 FILE_PATH_LITERAL("drive/Directory 1/Test.log"));
1517 1517
1518 LoadRootFeedDocument("root_feed.json"); 1518 LoadRootFeedDocument("root_feed.json");
1519 1519
1520 ASSERT_TRUE(EntryExists(src_file_path)); 1520 ASSERT_TRUE(EntryExists(src_file_path));
1521 scoped_ptr<GDataEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1521 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1522 src_file_path); 1522 src_file_path);
1523 ASSERT_TRUE(src_entry_proto.get()); 1523 ASSERT_TRUE(src_entry_proto.get());
1524 std::string src_file_resource_id = 1524 std::string src_file_resource_id =
1525 src_entry_proto->resource_id(); 1525 src_entry_proto->resource_id();
1526 1526
1527 EXPECT_CALL(*mock_drive_service_, 1527 EXPECT_CALL(*mock_drive_service_,
1528 RenameResource(GURL(src_entry_proto->edit_url()), 1528 RenameResource(GURL(src_entry_proto->edit_url()),
1529 FILE_PATH_LITERAL("Test.log"), _)); 1529 FILE_PATH_LITERAL("Test.log"), _));
1530 1530
1531 FileOperationCallback callback = 1531 FileOperationCallback callback =
(...skipping 13 matching lines...) Expand all
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"));
1551 1551
1552 LoadRootFeedDocument("root_feed.json"); 1552 LoadRootFeedDocument("root_feed.json");
1553 1553
1554 ASSERT_TRUE(EntryExists(src_file_path)); 1554 ASSERT_TRUE(EntryExists(src_file_path));
1555 scoped_ptr<GDataEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1555 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1556 src_file_path); 1556 src_file_path);
1557 ASSERT_TRUE(src_entry_proto.get()); 1557 ASSERT_TRUE(src_entry_proto.get());
1558 std::string src_file_resource_id = 1558 std::string src_file_resource_id =
1559 src_entry_proto->resource_id(); 1559 src_entry_proto->resource_id();
1560 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1560 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1561 1561
1562 ASSERT_TRUE(EntryExists(dest_parent_path)); 1562 ASSERT_TRUE(EntryExists(dest_parent_path));
1563 scoped_ptr<GDataEntryProto> dest_parent_proto = GetEntryInfoByPathSync( 1563 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync(
1564 dest_parent_path); 1564 dest_parent_path);
1565 ASSERT_TRUE(dest_parent_proto.get()); 1565 ASSERT_TRUE(dest_parent_proto.get());
1566 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); 1566 ASSERT_TRUE(dest_parent_proto->file_info().is_directory());
1567 EXPECT_FALSE(dest_parent_proto->content_url().empty()); 1567 EXPECT_FALSE(dest_parent_proto->content_url().empty());
1568 1568
1569 EXPECT_CALL(*mock_drive_service_, 1569 EXPECT_CALL(*mock_drive_service_,
1570 RenameResource(GURL(src_entry_proto->edit_url()), 1570 RenameResource(GURL(src_entry_proto->edit_url()),
1571 FILE_PATH_LITERAL("Test.log"), _)); 1571 FILE_PATH_LITERAL("Test.log"), _));
1572 EXPECT_CALL(*mock_drive_service_, 1572 EXPECT_CALL(*mock_drive_service_,
1573 AddResourceToDirectory( 1573 AddResourceToDirectory(
(...skipping 21 matching lines...) Expand all
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"));
1600 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); 1600 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log"));
1601 1601
1602 LoadRootFeedDocument("root_feed.json"); 1602 LoadRootFeedDocument("root_feed.json");
1603 1603
1604 ASSERT_TRUE(EntryExists(src_file_path)); 1604 ASSERT_TRUE(EntryExists(src_file_path));
1605 scoped_ptr<GDataEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1605 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1606 src_file_path); 1606 src_file_path);
1607 ASSERT_TRUE(src_entry_proto.get()); 1607 ASSERT_TRUE(src_entry_proto.get());
1608 std::string src_file_resource_id = 1608 std::string src_file_resource_id =
1609 src_entry_proto->resource_id(); 1609 src_entry_proto->resource_id();
1610 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1610 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1611 1611
1612 ASSERT_TRUE(EntryExists(src_parent_path)); 1612 ASSERT_TRUE(EntryExists(src_parent_path));
1613 scoped_ptr<GDataEntryProto> src_parent_proto = GetEntryInfoByPathSync( 1613 scoped_ptr<DriveEntryProto> src_parent_proto = GetEntryInfoByPathSync(
1614 src_parent_path); 1614 src_parent_path);
1615 ASSERT_TRUE(src_parent_proto.get()); 1615 ASSERT_TRUE(src_parent_proto.get());
1616 ASSERT_TRUE(src_parent_proto->file_info().is_directory()); 1616 ASSERT_TRUE(src_parent_proto->file_info().is_directory());
1617 EXPECT_FALSE(src_parent_proto->content_url().empty()); 1617 EXPECT_FALSE(src_parent_proto->content_url().empty());
1618 1618
1619 EXPECT_CALL(*mock_drive_service_, 1619 EXPECT_CALL(*mock_drive_service_,
1620 RenameResource(GURL(src_entry_proto->edit_url()), 1620 RenameResource(GURL(src_entry_proto->edit_url()),
1621 FILE_PATH_LITERAL("Test.log"), _)); 1621 FILE_PATH_LITERAL("Test.log"), _));
1622 EXPECT_CALL(*mock_drive_service_, 1622 EXPECT_CALL(*mock_drive_service_,
1623 RemoveResourceFromDirectory( 1623 RemoveResourceFromDirectory(
(...skipping 29 matching lines...) Expand all
1653 FilePath interim_file_path(FILE_PATH_LITERAL("drive/Test.log")); 1653 FilePath interim_file_path(FILE_PATH_LITERAL("drive/Test.log"));
1654 1654
1655 LoadRootFeedDocument("root_feed.json"); 1655 LoadRootFeedDocument("root_feed.json");
1656 1656
1657 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1657 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1658 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1658 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
1659 1659
1660 AddDirectoryFromFile(dest_parent_path, "directory_entry_atom.json"); 1660 AddDirectoryFromFile(dest_parent_path, "directory_entry_atom.json");
1661 1661
1662 ASSERT_TRUE(EntryExists(src_file_path)); 1662 ASSERT_TRUE(EntryExists(src_file_path));
1663 scoped_ptr<GDataEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1663 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1664 src_file_path); 1664 src_file_path);
1665 ASSERT_TRUE(src_entry_proto.get()); 1665 ASSERT_TRUE(src_entry_proto.get());
1666 std::string src_file_resource_id = 1666 std::string src_file_resource_id =
1667 src_entry_proto->resource_id(); 1667 src_entry_proto->resource_id();
1668 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1668 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1669 1669
1670 ASSERT_TRUE(EntryExists(src_parent_path)); 1670 ASSERT_TRUE(EntryExists(src_parent_path));
1671 scoped_ptr<GDataEntryProto> src_parent_proto = GetEntryInfoByPathSync( 1671 scoped_ptr<DriveEntryProto> src_parent_proto = GetEntryInfoByPathSync(
1672 src_parent_path); 1672 src_parent_path);
1673 ASSERT_TRUE(src_parent_proto.get()); 1673 ASSERT_TRUE(src_parent_proto.get());
1674 ASSERT_TRUE(src_parent_proto->file_info().is_directory()); 1674 ASSERT_TRUE(src_parent_proto->file_info().is_directory());
1675 EXPECT_FALSE(src_parent_proto->content_url().empty()); 1675 EXPECT_FALSE(src_parent_proto->content_url().empty());
1676 1676
1677 ASSERT_TRUE(EntryExists(dest_parent_path)); 1677 ASSERT_TRUE(EntryExists(dest_parent_path));
1678 scoped_ptr<GDataEntryProto> dest_parent_proto = GetEntryInfoByPathSync( 1678 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync(
1679 dest_parent_path); 1679 dest_parent_path);
1680 ASSERT_TRUE(dest_parent_proto.get()); 1680 ASSERT_TRUE(dest_parent_proto.get());
1681 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); 1681 ASSERT_TRUE(dest_parent_proto->file_info().is_directory());
1682 EXPECT_FALSE(dest_parent_proto->content_url().empty()); 1682 EXPECT_FALSE(dest_parent_proto->content_url().empty());
1683 1683
1684 EXPECT_FALSE(EntryExists(interim_file_path)); 1684 EXPECT_FALSE(EntryExists(interim_file_path));
1685 1685
1686 EXPECT_CALL(*mock_drive_service_, 1686 EXPECT_CALL(*mock_drive_service_,
1687 RenameResource(GURL(src_entry_proto->edit_url()), 1687 RenameResource(GURL(src_entry_proto->edit_url()),
1688 FILE_PATH_LITERAL("Test.log"), _)); 1688 FILE_PATH_LITERAL("Test.log"), _));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
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<GDataEntryProto> 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,
(...skipping 12 matching lines...) Expand all
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"));
1779 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Duplicate Name.txt")); 1779 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Duplicate Name.txt"));
1780 FilePath dest_file_path(FILE_PATH_LITERAL( 1780 FilePath dest_file_path(FILE_PATH_LITERAL(
1781 "drive/Duplicate Name.txt/Test.log")); 1781 "drive/Duplicate Name.txt/Test.log"));
1782 1782
1783 LoadRootFeedDocument("root_feed.json"); 1783 LoadRootFeedDocument("root_feed.json");
1784 1784
1785 ASSERT_TRUE(EntryExists(src_file_path)); 1785 ASSERT_TRUE(EntryExists(src_file_path));
1786 scoped_ptr<GDataEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1786 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1787 src_file_path); 1787 src_file_path);
1788 ASSERT_TRUE(src_entry_proto.get()); 1788 ASSERT_TRUE(src_entry_proto.get());
1789 std::string src_file_resource_id = 1789 std::string src_file_resource_id =
1790 src_entry_proto->resource_id(); 1790 src_entry_proto->resource_id();
1791 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1791 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1792 1792
1793 ASSERT_TRUE(EntryExists(dest_parent_path)); 1793 ASSERT_TRUE(EntryExists(dest_parent_path));
1794 scoped_ptr<GDataEntryProto> 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(GDATA_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
1815 FilePath nonexisting_file(FILE_PATH_LITERAL("drive/Dummy file.txt")); 1815 FilePath nonexisting_file(FILE_PATH_LITERAL("drive/Dummy file.txt"));
1816 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 1816 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
1817 FilePath dir_in_root(FILE_PATH_LITERAL("drive/Directory 1")); 1817 FilePath dir_in_root(FILE_PATH_LITERAL("drive/Directory 1"));
1818 FilePath file_in_subdir( 1818 FilePath file_in_subdir(
1819 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); 1819 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt"));
1820 1820
1821 ASSERT_TRUE(EntryExists(file_in_root)); 1821 ASSERT_TRUE(EntryExists(file_in_root));
1822 scoped_ptr<GDataEntryProto> file_in_root_proto = GetEntryInfoByPathSync( 1822 scoped_ptr<DriveEntryProto> file_in_root_proto = GetEntryInfoByPathSync(
1823 file_in_root); 1823 file_in_root);
1824 ASSERT_TRUE(file_in_root_proto.get()); 1824 ASSERT_TRUE(file_in_root_proto.get());
1825 1825
1826 ASSERT_TRUE(EntryExists(dir_in_root)); 1826 ASSERT_TRUE(EntryExists(dir_in_root));
1827 scoped_ptr<GDataEntryProto> dir_in_root_proto = GetEntryInfoByPathSync( 1827 scoped_ptr<DriveEntryProto> dir_in_root_proto = GetEntryInfoByPathSync(
1828 dir_in_root); 1828 dir_in_root);
1829 ASSERT_TRUE(dir_in_root_proto.get()); 1829 ASSERT_TRUE(dir_in_root_proto.get());
1830 ASSERT_TRUE(dir_in_root_proto->file_info().is_directory()); 1830 ASSERT_TRUE(dir_in_root_proto->file_info().is_directory());
1831 1831
1832 ASSERT_TRUE(EntryExists(file_in_subdir)); 1832 ASSERT_TRUE(EntryExists(file_in_subdir));
1833 scoped_ptr<GDataEntryProto> file_in_subdir_proto = GetEntryInfoByPathSync( 1833 scoped_ptr<DriveEntryProto> file_in_subdir_proto = GetEntryInfoByPathSync(
1834 file_in_subdir); 1834 file_in_subdir);
1835 ASSERT_TRUE(file_in_subdir_proto.get()); 1835 ASSERT_TRUE(file_in_subdir_proto.get());
1836 1836
1837 // Once for file in root and once for file... 1837 // Once for file in root and once for file...
1838 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1838 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1839 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(2); 1839 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(2);
1840 1840
1841 // Remove first file in root. 1841 // Remove first file in root.
1842 EXPECT_TRUE(RemoveEntry(file_in_root)); 1842 EXPECT_TRUE(RemoveEntry(file_in_root));
1843 EXPECT_FALSE(EntryExists(file_in_root)); 1843 EXPECT_FALSE(EntryExists(file_in_root));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
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"));
1974 scoped_ptr<GDataEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); 1974 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root));
1975 FilePath downloaded_file = GetCachePathForFile( 1975 FilePath downloaded_file = GetCachePathForFile(
1976 entry_proto->resource_id(), 1976 entry_proto->resource_id(),
1977 entry_proto->file_specific_info().file_md5()); 1977 entry_proto->file_specific_info().file_md5());
1978 const int64 file_size = entry_proto->file_info().size(); 1978 const int64 file_size = entry_proto->file_info().size();
1979 1979
1980 // Pretend we have enough space. 1980 // Pretend we have enough space.
1981 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1981 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1982 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); 1982 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace));
1983 1983
1984 // Before Download starts metadata from server will be fetched. 1984 // Before Download starts metadata from server will be fetched.
(...skipping 20 matching lines...) Expand all
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,
2012 callback_helper_.get()); 2012 callback_helper_.get());
2013 2013
2014 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 2014 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
2015 scoped_ptr<GDataEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); 2015 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root));
2016 FilePath downloaded_file = GetCachePathForFile( 2016 FilePath downloaded_file = GetCachePathForFile(
2017 entry_proto->resource_id(), 2017 entry_proto->resource_id(),
2018 entry_proto->file_specific_info().file_md5()); 2018 entry_proto->file_specific_info().file_md5());
2019 2019
2020 // Pretend we have no space at all. 2020 // Pretend we have no space at all.
2021 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 2021 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
2022 .Times(2).WillRepeatedly(Return(0)); 2022 .Times(2).WillRepeatedly(Return(0));
2023 2023
2024 // Before Download starts metadata from server will be fetched. 2024 // Before Download starts metadata from server will be fetched.
2025 // We will read content url from the result. 2025 // We will read content url from the result.
(...skipping 17 matching lines...) Expand all
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
2052 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 2052 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
2053 scoped_ptr<GDataEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); 2053 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root));
2054 FilePath downloaded_file = GetCachePathForFile( 2054 FilePath downloaded_file = GetCachePathForFile(
2055 entry_proto->resource_id(), 2055 entry_proto->resource_id(),
2056 entry_proto->file_specific_info().file_md5()); 2056 entry_proto->file_specific_info().file_md5());
2057 const int64 file_size = entry_proto->file_info().size(); 2057 const int64 file_size = entry_proto->file_info().size();
2058 2058
2059 // Pretend we have no space first (checked before downloading a file), 2059 // Pretend we have no space first (checked before downloading a file),
2060 // but then start reporting we have space. This is to emulate that 2060 // but then start reporting we have space. This is to emulate that
2061 // the disk space was freed up by removing temporary files. 2061 // the disk space was freed up by removing temporary files.
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))
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 } 2105 }
2106 2106
2107 TEST_F(GDataFileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) { 2107 TEST_F(GDataFileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) {
2108 LoadRootFeedDocument("root_feed.json"); 2108 LoadRootFeedDocument("root_feed.json");
2109 2109
2110 GetFileCallback callback = 2110 GetFileCallback callback =
2111 base::Bind(&CallbackHelper::GetFileCallback, 2111 base::Bind(&CallbackHelper::GetFileCallback,
2112 callback_helper_.get()); 2112 callback_helper_.get());
2113 2113
2114 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 2114 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
2115 scoped_ptr<GDataEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); 2115 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root));
2116 FilePath downloaded_file = GetCachePathForFile( 2116 FilePath downloaded_file = GetCachePathForFile(
2117 entry_proto->resource_id(), 2117 entry_proto->resource_id(),
2118 entry_proto->file_specific_info().file_md5()); 2118 entry_proto->file_specific_info().file_md5());
2119 const int64 file_size = entry_proto->file_info().size(); 2119 const int64 file_size = entry_proto->file_info().size();
2120 2120
2121 // Pretend we have enough space first (checked before downloading a file), 2121 // Pretend we have enough space first (checked before downloading a file),
2122 // but then start reporting we have not enough space. This is to emulate that 2122 // but then start reporting we have not enough space. This is to emulate that
2123 // the disk space becomes full after the file is downloaded for some reason 2123 // the disk space becomes full after the file is downloaded for some reason
2124 // (ex. the actual file was larger than the expected size). 2124 // (ex. the actual file was larger than the expected size).
2125 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 2125 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
(...skipping 26 matching lines...) Expand all
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<GDataEntryProto> 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 GDATA_FILE_OK,
2172 test_util::TEST_CACHE_STATE_PRESENT, 2172 test_util::TEST_CACHE_STATE_PRESENT,
(...skipping 20 matching lines...) Expand all
2193 } 2193 }
2194 2194
2195 TEST_F(GDataFileSystemTest, GetFileByPath_HostedDocument) { 2195 TEST_F(GDataFileSystemTest, GetFileByPath_HostedDocument) {
2196 LoadRootFeedDocument("root_feed.json"); 2196 LoadRootFeedDocument("root_feed.json");
2197 2197
2198 GetFileCallback callback = 2198 GetFileCallback callback =
2199 base::Bind(&CallbackHelper::GetFileCallback, 2199 base::Bind(&CallbackHelper::GetFileCallback,
2200 callback_helper_.get()); 2200 callback_helper_.get());
2201 2201
2202 FilePath file_in_root(FILE_PATH_LITERAL("drive/Document 1.gdoc")); 2202 FilePath file_in_root(FILE_PATH_LITERAL("drive/Document 1.gdoc"));
2203 scoped_ptr<GDataEntryProto> src_entry_proto = 2203 scoped_ptr<DriveEntryProto> src_entry_proto =
2204 GetEntryInfoByPathSync(file_in_root); 2204 GetEntryInfoByPathSync(file_in_root);
2205 ASSERT_TRUE(src_entry_proto.get()); 2205 ASSERT_TRUE(src_entry_proto.get());
2206 2206
2207 file_system_->GetFileByPath(file_in_root, callback, 2207 file_system_->GetFileByPath(file_in_root, callback,
2208 GetContentCallback()); 2208 GetContentCallback());
2209 test_util::RunBlockingPoolTask(); 2209 test_util::RunBlockingPoolTask();
2210 2210
2211 EXPECT_EQ(HOSTED_DOCUMENT, callback_helper_->file_type_); 2211 EXPECT_EQ(HOSTED_DOCUMENT, callback_helper_->file_type_);
2212 EXPECT_FALSE(callback_helper_->download_path_.empty()); 2212 EXPECT_FALSE(callback_helper_->download_path_.empty());
2213 2213
2214 ASSERT_TRUE(src_entry_proto.get()); 2214 ASSERT_TRUE(src_entry_proto.get());
2215 VerifyHostedDocumentJSONFile(*src_entry_proto, 2215 VerifyHostedDocumentJSONFile(*src_entry_proto,
2216 callback_helper_->download_path_); 2216 callback_helper_->download_path_);
2217 } 2217 }
2218 2218
2219 TEST_F(GDataFileSystemTest, GetFileByResourceId) { 2219 TEST_F(GDataFileSystemTest, GetFileByResourceId) {
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("root_feed.json"); 2223 LoadRootFeedDocument("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<GDataEntryProto> 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 // Before Download starts metadata from server will be fetched. 2235 // Before Download starts metadata from server will be fetched.
2236 // We will read content url from the result. 2236 // We will read content url from the result.
2237 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json")); 2237 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json"));
2238 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); 2238 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
2239 2239
2240 // The file is obtained with the mock DriveService, because it's not stored in 2240 // The file is obtained with the mock DriveService, because it's not stored in
(...skipping 19 matching lines...) Expand all
2260 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 2260 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
2261 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 2261 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
2262 2262
2263 LoadRootFeedDocument("root_feed.json"); 2263 LoadRootFeedDocument("root_feed.json");
2264 2264
2265 GetFileCallback callback = 2265 GetFileCallback callback =
2266 base::Bind(&CallbackHelper::GetFileCallback, 2266 base::Bind(&CallbackHelper::GetFileCallback,
2267 callback_helper_.get()); 2267 callback_helper_.get());
2268 2268
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<GDataEntryProto> 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 GDATA_FILE_OK,
2280 test_util::TEST_CACHE_STATE_PRESENT, 2280 test_util::TEST_CACHE_STATE_PRESENT,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2414 OnDirectoryChanged(Eq(FilePath(kGDataRootDirectory)))).Times(1); 2414 OnDirectoryChanged(Eq(FilePath(kGDataRootDirectory)))).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<GDataEntryProtoVector> 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(GDATA_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
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2560 LoadRootFeedDocument("root_feed.json"); 2560 LoadRootFeedDocument("root_feed.json");
2561 2561
2562 OpenFileCallback callback = 2562 OpenFileCallback callback =
2563 base::Bind(&CallbackHelper::OpenFileCallback, 2563 base::Bind(&CallbackHelper::OpenFileCallback,
2564 callback_helper_.get()); 2564 callback_helper_.get());
2565 FileOperationCallback close_file_callback = 2565 FileOperationCallback close_file_callback =
2566 base::Bind(&CallbackHelper::CloseFileCallback, 2566 base::Bind(&CallbackHelper::CloseFileCallback,
2567 callback_helper_.get()); 2567 callback_helper_.get());
2568 2568
2569 const FilePath kFileInRoot(FILE_PATH_LITERAL("drive/File 1.txt")); 2569 const FilePath kFileInRoot(FILE_PATH_LITERAL("drive/File 1.txt"));
2570 scoped_ptr<GDataEntryProto> entry_proto(GetEntryInfoByPathSync(kFileInRoot)); 2570 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(kFileInRoot));
2571 FilePath downloaded_file = GetCachePathForFile( 2571 FilePath downloaded_file = GetCachePathForFile(
2572 entry_proto->resource_id(), 2572 entry_proto->resource_id(),
2573 entry_proto->file_specific_info().file_md5()); 2573 entry_proto->file_specific_info().file_md5());
2574 const int64 file_size = entry_proto->file_info().size(); 2574 const int64 file_size = entry_proto->file_info().size();
2575 const std::string& file_resource_id = 2575 const std::string& file_resource_id =
2576 entry_proto->resource_id(); 2576 entry_proto->resource_id();
2577 const std::string& file_md5 = entry_proto->file_specific_info().file_md5(); 2577 const std::string& file_md5 = entry_proto->file_specific_info().file_md5();
2578 2578
2579 // A dirty file is created on close. 2579 // A dirty file is created on close.
2580 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(file_resource_id)) 2580 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(file_resource_id))
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
2647 } 2647 }
2648 2648
2649 } // namespace gdata 2649 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc ('k') | chrome/browser/chromeos/gdata/gdata_files.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698