Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / drive / file_system / operation_test_base.h
blobbfdece00dcf4a23763653515b0ee70bbb4f83da5
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 COMPONENTS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_
6 #define COMPONENTS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_
8 #include <set>
10 #include "base/files/scoped_temp_dir.h"
11 #include "components/drive/drive.pb.h"
12 #include "components/drive/drive_test_util.h"
13 #include "components/drive/file_change.h"
14 #include "components/drive/file_errors.h"
15 #include "components/drive/file_system/operation_delegate.h"
16 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "testing/gtest/include/gtest/gtest.h"
19 class TestingPrefServiceSimple;
21 namespace base {
22 class SequencedTaskRunner;
23 } // namespace base
25 namespace drive {
26 struct ClientContext;
27 class EventLogger;
28 class FakeDriveService;
29 class FakeFreeDiskSpaceGetter;
30 class JobScheduler;
32 namespace internal {
33 class AboutResourceLoader;
34 class ChangeListLoader;
35 class FileCache;
36 class LoaderController;
37 class ResourceMetadata;
38 class ResourceMetadataStorage;
39 } // namespace internal
41 namespace file_system {
43 // Base fixture class for testing Drive file system operations. It sets up the
44 // basic set of Drive internal classes (ResourceMetadata, Cache, etc) on top of
45 // FakeDriveService for testing.
46 class OperationTestBase : public testing::Test {
47 protected:
48 // OperationDelegate that records all the events.
49 class LoggingDelegate : public OperationDelegate {
50 public:
51 typedef base::Callback<bool(
52 const std::string& local_id,
53 const FileOperationCallback& callback)> WaitForSyncCompleteHandler;
55 LoggingDelegate();
56 ~LoggingDelegate();
58 // OperationDelegate overrides.
59 void OnFileChangedByOperation(const FileChange& changed_files) override;
60 void OnEntryUpdatedByOperation(const ClientContext& context,
61 const std::string& local_id) override;
62 void OnDriveSyncError(DriveSyncErrorType type,
63 const std::string& local_id) override;
64 bool WaitForSyncComplete(const std::string& local_id,
65 const FileOperationCallback& callback) override;
67 // Gets the set of changed paths.
68 const FileChange& get_changed_files() { return changed_files_; }
70 // Gets the set of updated local IDs.
71 const std::set<std::string>& updated_local_ids() const {
72 return updated_local_ids_;
75 // Gets the list of drive sync errors.
76 const std::vector<DriveSyncErrorType>& drive_sync_errors() const {
77 return drive_sync_errors_;
80 // Sets the callback used to handle WaitForSyncComplete() method calls.
81 void set_wait_for_sync_complete_handler(
82 const WaitForSyncCompleteHandler& wait_for_sync_complete_handler) {
83 wait_for_sync_complete_handler_ = wait_for_sync_complete_handler;
86 private:
87 FileChange changed_files_;
88 std::set<std::string> updated_local_ids_;
89 std::vector<DriveSyncErrorType> drive_sync_errors_;
90 WaitForSyncCompleteHandler wait_for_sync_complete_handler_;
93 OperationTestBase();
94 explicit OperationTestBase(int test_thread_bundle_options);
95 ~OperationTestBase() override;
97 // testing::Test overrides.
98 void SetUp() override;
100 // Returns the path of the temporary directory for putting test files.
101 base::FilePath temp_dir() const { return temp_dir_.path(); }
103 // Synchronously gets the resource entry corresponding to the path from local
104 // ResourceMetadta.
105 FileError GetLocalResourceEntry(const base::FilePath& path,
106 ResourceEntry* entry);
108 // Synchronously gets the resource entry corresponding to the ID from local
109 // ResourceMetadta.
110 FileError GetLocalResourceEntryById(const std::string& local_id,
111 ResourceEntry* entry);
113 // Gets the local ID of the entry specified by the path.
114 std::string GetLocalId(const base::FilePath& path);
116 // Synchronously updates |metadata_| by fetching the change feed from the
117 // |fake_service_|.
118 FileError CheckForUpdates();
120 // Accessors for the components.
121 FakeDriveService* fake_service() {
122 return fake_drive_service_.get();
124 EventLogger* logger() { return logger_.get(); }
125 LoggingDelegate* delegate() { return &delegate_; }
126 JobScheduler* scheduler() { return scheduler_.get(); }
127 base::SequencedTaskRunner* blocking_task_runner() {
128 return blocking_task_runner_.get();
130 FakeFreeDiskSpaceGetter* fake_free_disk_space_getter() {
131 return fake_free_disk_space_getter_.get();
133 internal::FileCache* cache() { return cache_.get(); }
134 internal::ResourceMetadata* metadata() { return metadata_.get(); }
135 internal::LoaderController* loader_controller() {
136 return loader_controller_.get();
138 internal::ChangeListLoader* change_list_loader() {
139 return change_list_loader_.get();
142 private:
143 content::TestBrowserThreadBundle thread_bundle_;
144 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
145 scoped_ptr<TestingPrefServiceSimple> pref_service_;
146 base::ScopedTempDir temp_dir_;
148 LoggingDelegate delegate_;
149 scoped_ptr<EventLogger> logger_;
150 scoped_ptr<FakeDriveService> fake_drive_service_;
151 scoped_ptr<JobScheduler> scheduler_;
152 scoped_ptr<internal::ResourceMetadataStorage,
153 test_util::DestroyHelperForTests> metadata_storage_;
154 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
155 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_;
156 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests>
157 metadata_;
158 scoped_ptr<internal::AboutResourceLoader> about_resource_loader_;
159 scoped_ptr<internal::LoaderController> loader_controller_;
160 scoped_ptr<internal::ChangeListLoader> change_list_loader_;
163 } // namespace file_system
164 } // namespace drive
166 #endif // COMPONENTS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_