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;
26 class FakeDriveService;
27 class FakeFreeDiskSpaceGetter;
31 class ChangeListLoader;
33 class ResourceMetadata;
34 class ResourceMetadataStorage;
35 } // namespace internal
37 namespace file_system {
39 // Base fixture class for testing Drive file system operations. It sets up the
40 // basic set of Drive internal classes (ResourceMetadata, Cache, etc) on top of
41 // FakeDriveService for testing.
42 class OperationTestBase : public testing::Test {
44 // OperationObserver that records all the events.
45 class LoggingObserver : public OperationObserver {
50 // OperationObserver overrides.
51 virtual void OnDirectoryChangedByOperation(
52 const base::FilePath& path) OVERRIDE;
53 virtual void OnEntryUpdatedByOperation(
54 const std::string& local_id) OVERRIDE;
55 virtual void OnDriveSyncError(DriveSyncErrorType type,
56 const std::string& local_id) OVERRIDE;
58 // Gets the set of changed paths.
59 const std::set<base::FilePath>& get_changed_paths() {
60 return changed_paths_;
63 // Gets the set of updated local IDs.
64 const std::set<std::string>& updated_local_ids() const {
65 return updated_local_ids_;
68 // Gets the list of drive sync errors.
69 const std::vector<DriveSyncErrorType>& drive_sync_errors() const {
70 return drive_sync_errors_;
74 std::set<base::FilePath> changed_paths_;
75 std::set<std::string> updated_local_ids_;
76 std::vector<DriveSyncErrorType> drive_sync_errors_;
80 explicit OperationTestBase(int test_thread_bundle_options);
81 virtual ~OperationTestBase();
83 // testing::Test overrides.
84 virtual void SetUp() OVERRIDE;
86 // Returns the path of the temporary directory for putting test files.
87 base::FilePath temp_dir() const { return temp_dir_.path(); }
89 // Synchronously gets the resource entry corresponding to the path from local
91 FileError GetLocalResourceEntry(const base::FilePath& path,
92 ResourceEntry* entry);
94 // Synchronously gets the resource entry corresponding to the ID from local
96 FileError GetLocalResourceEntryById(const std::string& local_id,
97 ResourceEntry* entry);
99 // Gets the local ID of the entry specified by the path.
100 std::string GetLocalId(const base::FilePath& path);
102 // Synchronously updates |metadata_| by fetching the change feed from the
104 FileError CheckForUpdates();
106 // Accessors for the components.
107 FakeDriveService* fake_service() {
108 return fake_drive_service_.get();
110 LoggingObserver* observer() { return &observer_; }
111 JobScheduler* scheduler() { return scheduler_.get(); }
112 base::SequencedTaskRunner* blocking_task_runner() {
113 return blocking_task_runner_.get();
115 internal::ResourceMetadata* metadata() { return metadata_.get(); }
116 FakeFreeDiskSpaceGetter* fake_free_disk_space_getter() {
117 return fake_free_disk_space_getter_.get();
119 internal::FileCache* cache() { return cache_.get(); }
122 content::TestBrowserThreadBundle thread_bundle_;
123 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
124 scoped_ptr<TestingPrefServiceSimple> pref_service_;
125 base::ScopedTempDir temp_dir_;
127 LoggingObserver observer_;
128 scoped_ptr<FakeDriveService> fake_drive_service_;
129 scoped_ptr<JobScheduler> scheduler_;
130 scoped_ptr<internal::ResourceMetadataStorage,
131 test_util::DestroyHelperForTests> metadata_storage_;
132 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests>
134 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
135 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_;
136 scoped_ptr<internal::ChangeListLoader> change_list_loader_;
139 } // namespace file_system
142 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_