4707f2ba0aa1efb93b688ee5904a4a6ef202f49f
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / drive / file_system / operation_test_base.h
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_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"
17
18 class TestingPrefServiceSimple;
19
20 namespace base {
21 class SequencedTaskRunner;
22 }  // namespace base
23
24 namespace drive {
25
26 class FakeDriveService;
27 class FakeFreeDiskSpaceGetter;
28 class JobScheduler;
29
30 namespace internal {
31 class ChangeListLoader;
32 class FileCache;
33 class ResourceMetadata;
34 class ResourceMetadataStorage;
35 }  // namespace internal
36
37 namespace file_system {
38
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();
49
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;
57
58     // Gets the set of changed paths.
59     const std::set<base::FilePath>& get_changed_paths() {
60       return changed_paths_;
61     }
62
63     // Gets the set of updated local IDs.
64     const std::set<std::string>& updated_local_ids() const {
65       return updated_local_ids_;
66     }
67
68     // Gets the list of drive sync errors.
69     const std::vector<DriveSyncErrorType>& drive_sync_errors() const {
70       return drive_sync_errors_;
71     }
72
73    private:
74     std::set<base::FilePath> changed_paths_;
75     std::set<std::string> updated_local_ids_;
76     std::vector<DriveSyncErrorType> drive_sync_errors_;
77   };
78
79   OperationTestBase();
80   explicit OperationTestBase(int test_thread_bundle_options);
81   virtual ~OperationTestBase();
82
83   // testing::Test overrides.
84   virtual void SetUp() OVERRIDE;
85
86   // Returns the path of the temporary directory for putting test files.
87   base::FilePath temp_dir() const { return temp_dir_.path(); }
88
89   // Synchronously gets the resource entry corresponding to the path from local
90   // ResourceMetadta.
91   FileError GetLocalResourceEntry(const base::FilePath& path,
92                                   ResourceEntry* entry);
93
94   // Synchronously gets the resource entry corresponding to the ID from local
95   // ResourceMetadta.
96   FileError GetLocalResourceEntryById(const std::string& local_id,
97                                       ResourceEntry* entry);
98
99   // Gets the local ID of the entry specified by the path.
100   std::string GetLocalId(const base::FilePath& path);
101
102   // Synchronously updates |metadata_| by fetching the change feed from the
103   // |fake_service_|.
104   FileError CheckForUpdates();
105
106   // Accessors for the components.
107   FakeDriveService* fake_service() {
108     return fake_drive_service_.get();
109   }
110   LoggingObserver* observer() { return &observer_; }
111   JobScheduler* scheduler() { return scheduler_.get(); }
112   base::SequencedTaskRunner* blocking_task_runner() {
113     return blocking_task_runner_.get();
114   }
115   internal::ResourceMetadata* metadata() { return metadata_.get(); }
116   FakeFreeDiskSpaceGetter* fake_free_disk_space_getter() {
117     return fake_free_disk_space_getter_.get();
118   }
119   internal::FileCache* cache() { return cache_.get(); }
120
121  private:
122   content::TestBrowserThreadBundle thread_bundle_;
123   scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
124   scoped_ptr<TestingPrefServiceSimple> pref_service_;
125   base::ScopedTempDir temp_dir_;
126
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>
133       metadata_;
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_;
137 };
138
139 }  // namespace file_system
140 }  // namespace drive
141
142 #endif  // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_