Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / file_system / operation_test_base.h
blobf899d33203106b09d11eca40674d2b64e34e6dd1
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_
8 #include <set>
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;
20 namespace base {
21 class SequencedTaskRunner;
22 } // namespace base
24 namespace drive {
26 class FakeDriveService;
27 class FakeFreeDiskSpaceGetter;
28 class JobScheduler;
30 namespace internal {
31 class ChangeListLoader;
32 class FileCache;
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 {
43 protected:
44 // OperationObserver that records all the events.
45 class LoggingObserver : public OperationObserver {
46 public:
47 LoggingObserver();
48 ~LoggingObserver();
50 // OperationObserver overrides.
51 virtual void OnDirectoryChangedByOperation(
52 const base::FilePath& path) OVERRIDE;
53 virtual void OnCacheFileUploadNeededByOperation(
54 const std::string& local_id) OVERRIDE;
55 virtual void OnEntryUpdatedByOperation(
56 const std::string& local_id) OVERRIDE;
57 virtual void OnDriveSyncError(DriveSyncErrorType type,
58 const std::string& local_id) OVERRIDE;
60 // Gets the set of changed paths.
61 const std::set<base::FilePath>& get_changed_paths() {
62 return changed_paths_;
65 // Gets the set of upload needed local IDs.
66 const std::set<std::string>& upload_needed_local_ids() const {
67 return upload_needed_local_ids_;
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 private:
81 std::set<base::FilePath> changed_paths_;
82 std::set<std::string> upload_needed_local_ids_;
83 std::set<std::string> updated_local_ids_;
84 std::vector<DriveSyncErrorType> drive_sync_errors_;
87 OperationTestBase();
88 explicit OperationTestBase(int test_thread_bundle_options);
89 virtual ~OperationTestBase();
91 // testing::Test overrides.
92 virtual void SetUp() OVERRIDE;
94 // Returns the path of the temporary directory for putting test files.
95 base::FilePath temp_dir() const { return temp_dir_.path(); }
97 // Synchronously gets the resource entry corresponding to the path from local
98 // ResourceMetadta.
99 FileError GetLocalResourceEntry(const base::FilePath& path,
100 ResourceEntry* entry);
102 // Synchronously gets the resource entry corresponding to the ID from local
103 // ResourceMetadta.
104 FileError GetLocalResourceEntryById(const std::string& local_id,
105 ResourceEntry* entry);
107 // Gets the local ID of the entry specified by the path.
108 std::string GetLocalId(const base::FilePath& path);
110 // Synchronously updates |metadata_| by fetching the change feed from the
111 // |fake_service_|.
112 FileError CheckForUpdates();
114 // Accessors for the components.
115 FakeDriveService* fake_service() {
116 return fake_drive_service_.get();
118 LoggingObserver* observer() { return &observer_; }
119 JobScheduler* scheduler() { return scheduler_.get(); }
120 base::SequencedTaskRunner* blocking_task_runner() {
121 return blocking_task_runner_.get();
123 internal::ResourceMetadata* metadata() { return metadata_.get(); }
124 FakeFreeDiskSpaceGetter* fake_free_disk_space_getter() {
125 return fake_free_disk_space_getter_.get();
127 internal::FileCache* cache() { return cache_.get(); }
129 private:
130 content::TestBrowserThreadBundle thread_bundle_;
131 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
132 scoped_ptr<TestingPrefServiceSimple> pref_service_;
133 base::ScopedTempDir temp_dir_;
135 LoggingObserver observer_;
136 scoped_ptr<FakeDriveService> fake_drive_service_;
137 scoped_ptr<JobScheduler> scheduler_;
138 scoped_ptr<internal::ResourceMetadataStorage,
139 test_util::DestroyHelperForTests> metadata_storage_;
140 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests>
141 metadata_;
142 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
143 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_;
144 scoped_ptr<internal::ChangeListLoader> change_list_loader_;
147 } // namespace file_system
148 } // namespace drive
150 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_