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.
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_
10 #include "base/files/scoped_temp_dir.h"
11 #include "chrome/browser/chromeos/drive/drive.pb.h"
12 #include "chrome/browser/chromeos/drive/file_errors.h"
13 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h"
14 #include "chrome/browser/chromeos/drive/test_util.h"
15 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 class TestingPrefServiceSimple;
21 class SequencedTaskRunner;
27 class FakeDriveService;
28 class FakeFreeDiskSpaceGetter;
32 class AboutResourceLoader;
33 class ChangeListLoader;
35 class LoaderController;
36 class ResourceMetadata;
37 class ResourceMetadataStorage;
38 } // namespace internal
40 namespace file_system {
42 // Base fixture class for testing Drive file system operations. It sets up the
43 // basic set of Drive internal classes (ResourceMetadata, Cache, etc) on top of
44 // FakeDriveService for testing.
45 class OperationTestBase : public testing::Test {
47 // OperationObserver that records all the events.
48 class LoggingObserver : public OperationObserver {
53 // OperationObserver overrides.
54 virtual void OnDirectoryChangedByOperation(
55 const base::FilePath& path) OVERRIDE;
56 virtual void OnEntryUpdatedByOperation(
57 const std::string& local_id) OVERRIDE;
58 virtual void OnDriveSyncError(DriveSyncErrorType type,
59 const std::string& local_id) OVERRIDE;
61 // Gets the set of changed paths.
62 const std::set<base::FilePath>& get_changed_paths() {
63 return changed_paths_;
66 // Gets the set of updated local IDs.
67 const std::set<std::string>& updated_local_ids() const {
68 return updated_local_ids_;
71 // Gets the list of drive sync errors.
72 const std::vector<DriveSyncErrorType>& drive_sync_errors() const {
73 return drive_sync_errors_;
77 std::set<base::FilePath> changed_paths_;
78 std::set<std::string> updated_local_ids_;
79 std::vector<DriveSyncErrorType> drive_sync_errors_;
83 explicit OperationTestBase(int test_thread_bundle_options);
84 virtual ~OperationTestBase();
86 // testing::Test overrides.
87 virtual void SetUp() OVERRIDE;
89 // Returns the path of the temporary directory for putting test files.
90 base::FilePath temp_dir() const { return temp_dir_.path(); }
92 // Synchronously gets the resource entry corresponding to the path from local
94 FileError GetLocalResourceEntry(const base::FilePath& path,
95 ResourceEntry* entry);
97 // Synchronously gets the resource entry corresponding to the ID from local
99 FileError GetLocalResourceEntryById(const std::string& local_id,
100 ResourceEntry* entry);
102 // Gets the local ID of the entry specified by the path.
103 std::string GetLocalId(const base::FilePath& path);
105 // Synchronously updates |metadata_| by fetching the change feed from the
107 FileError CheckForUpdates();
109 // Accessors for the components.
110 FakeDriveService* fake_service() {
111 return fake_drive_service_.get();
113 EventLogger* logger() { return logger_.get(); }
114 LoggingObserver* observer() { return &observer_; }
115 JobScheduler* scheduler() { return scheduler_.get(); }
116 base::SequencedTaskRunner* blocking_task_runner() {
117 return blocking_task_runner_.get();
119 internal::ResourceMetadata* metadata() { return metadata_.get(); }
120 FakeFreeDiskSpaceGetter* fake_free_disk_space_getter() {
121 return fake_free_disk_space_getter_.get();
123 internal::FileCache* cache() { return cache_.get(); }
124 internal::LoaderController* loader_controller() {
125 return loader_controller_.get();
127 internal::ChangeListLoader* change_list_loader() {
128 return change_list_loader_.get();
132 content::TestBrowserThreadBundle thread_bundle_;
133 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
134 scoped_ptr<TestingPrefServiceSimple> pref_service_;
135 base::ScopedTempDir temp_dir_;
137 LoggingObserver observer_;
138 scoped_ptr<EventLogger> logger_;
139 scoped_ptr<FakeDriveService> fake_drive_service_;
140 scoped_ptr<JobScheduler> scheduler_;
141 scoped_ptr<internal::ResourceMetadataStorage,
142 test_util::DestroyHelperForTests> metadata_storage_;
143 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests>
145 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
146 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_;
147 scoped_ptr<internal::AboutResourceLoader> about_resource_loader_;
148 scoped_ptr<internal::LoaderController> loader_controller_;
149 scoped_ptr<internal::ChangeListLoader> change_list_loader_;
152 } // namespace file_system
155 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_