1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_ 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_ 7 8 #include <set> 9 10 #include "base/files/scoped_temp_dir.h" 11 #include "chrome/browser/chromeos/drive/drive.pb.h" 12 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" 13 #include "chrome/browser/chromeos/drive/test_util.h" 14 #include "content/public/test/test_browser_thread_bundle.h" 15 #include "testing/gtest/include/gtest/gtest.h" 16 17 class TestingPrefServiceSimple; 18 19 namespace base { 20 class SequencedTaskRunner; 21 } // namespace base 22 23 namespace drive { 24 25 class FakeDriveService; 26 class FakeFreeDiskSpaceGetter; 27 class JobScheduler; 28 29 namespace internal { 30 class FileCache; 31 class ResourceMetadata; 32 class ResourceMetadataStorage; 33 } // namespace internal 34 35 namespace file_system { 36 37 // Base fixture class for testing Drive file system operations. It sets up the 38 // basic set of Drive internal classes (ResourceMetadata, Cache, etc) on top of 39 // FakeDriveService for testing. 40 class OperationTestBase : public testing::Test { 41 protected: 42 // OperationObserver that records all the events. 43 class LoggingObserver : public OperationObserver { 44 public: 45 LoggingObserver(); 46 ~LoggingObserver(); 47 48 // OperationObserver overrides. 49 virtual void OnDirectoryChangedByOperation( 50 const base::FilePath& path) OVERRIDE; 51 virtual void OnCacheFileUploadNeededByOperation( 52 const std::string& resource_id) OVERRIDE; 53 54 // Gets the set of changed paths. 55 const std::set<base::FilePath>& get_changed_paths() { 56 return changed_paths_; 57 } 58 59 // Gets the set of upload needed resource IDs. 60 const std::set<std::string>& upload_needed_resource_ids() const { 61 return upload_needed_resource_ids_; 62 } 63 64 private: 65 std::set<base::FilePath> changed_paths_; 66 std::set<std::string> upload_needed_resource_ids_; 67 }; 68 69 OperationTestBase(); 70 explicit OperationTestBase(int test_thread_bundle_options); 71 virtual ~OperationTestBase(); 72 73 // testing::Test overrides. 74 virtual void SetUp() OVERRIDE; 75 76 // Returns the path of the temporary directory for putting test files. 77 base::FilePath temp_dir() const { return temp_dir_.path(); } 78 79 // Synchronously gets the resource entry corresponding to the path from local 80 // ResourceMetadta. 81 FileError GetLocalResourceEntry(const base::FilePath& path, 82 ResourceEntry* entry); 83 84 // Accessors for the components. 85 FakeDriveService* fake_service() { 86 return fake_drive_service_.get(); 87 } 88 LoggingObserver* observer() { return &observer_; } 89 JobScheduler* scheduler() { return scheduler_.get(); } 90 base::SequencedTaskRunner* blocking_task_runner() { 91 return blocking_task_runner_.get(); 92 } 93 internal::ResourceMetadata* metadata() { return metadata_.get(); } 94 FakeFreeDiskSpaceGetter* fake_free_disk_space_getter() { 95 return fake_free_disk_space_getter_.get(); 96 } 97 internal::FileCache* cache() { return cache_.get(); } 98 99 private: 100 content::TestBrowserThreadBundle thread_bundle_; 101 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 102 scoped_ptr<TestingPrefServiceSimple> pref_service_; 103 base::ScopedTempDir temp_dir_; 104 105 LoggingObserver observer_; 106 scoped_ptr<FakeDriveService> fake_drive_service_; 107 scoped_ptr<JobScheduler> scheduler_; 108 scoped_ptr<internal::ResourceMetadataStorage, 109 test_util::DestroyHelperForTests> metadata_storage_; 110 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> 111 metadata_; 112 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; 113 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_; 114 }; 115 116 } // namespace file_system 117 } // namespace drive 118 119 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_ 120