OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains mocks for classes in drive_service_interface.h | 5 // This file contains mocks for classes in drive_service_interface.h |
6 | 6 |
7 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_MOCK_DRIVE_SERVICE_H_ | 7 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_MOCK_DRIVE_SERVICE_H_ |
8 #define CHROME_BROWSER_CHROMEOS_DRIVE_MOCK_DRIVE_SERVICE_H_ | 8 #define CHROME_BROWSER_CHROMEOS_DRIVE_MOCK_DRIVE_SERVICE_H_ |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "chrome/browser/chromeos/drive/drive_service_interface.h" | 13 #include "chrome/browser/chromeos/drive/drive_service_interface.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 | 15 |
16 class FilePath; | 16 class FilePath; |
17 | 17 |
18 namespace gdata { | 18 namespace drive { |
19 | 19 |
20 class MockDriveService : public DriveServiceInterface { | 20 class MockDriveService : public DriveServiceInterface { |
21 public: | 21 public: |
22 // DriveService is usually owned and created by DriveFileSystem. | 22 // DriveService is usually owned and created by DriveFileSystem. |
23 MockDriveService(); | 23 MockDriveService(); |
24 virtual ~MockDriveService(); | 24 virtual ~MockDriveService(); |
25 | 25 |
26 // DriveServiceInterface overrides. | 26 // DriveServiceInterface overrides. |
27 MOCK_METHOD1(Initialize, void(Profile* profile)); | 27 MOCK_METHOD1(Initialize, void(Profile* profile)); |
28 MOCK_METHOD1(AddObserver, void(DriveServiceObserver* observer)); | 28 MOCK_METHOD1(AddObserver, void(DriveServiceObserver* observer)); |
29 MOCK_METHOD1(RemoveObserver, void(DriveServiceObserver* observer)); | 29 MOCK_METHOD1(RemoveObserver, void(DriveServiceObserver* observer)); |
30 MOCK_CONST_METHOD0(CanStartOperation, bool()); | 30 MOCK_CONST_METHOD0(CanStartOperation, bool()); |
31 MOCK_METHOD0(CancelAll, void(void)); | 31 MOCK_METHOD0(CancelAll, void(void)); |
32 MOCK_METHOD1(CancelForFilePath, bool(const FilePath& file_path)); | 32 MOCK_METHOD1(CancelForFilePath, bool(const FilePath& file_path)); |
33 MOCK_CONST_METHOD0(GetProgressStatusList, OperationProgressStatusList()); | 33 MOCK_CONST_METHOD0(GetProgressStatusList, |
34 MOCK_METHOD1(Authenticate, void(const AuthStatusCallback& callback)); | 34 gdata::OperationProgressStatusList()); |
| 35 MOCK_METHOD1(Authenticate, void(const gdata::AuthStatusCallback& callback)); |
35 MOCK_METHOD5(GetDocuments, void(const GURL& feed_url, | 36 MOCK_METHOD5(GetDocuments, void(const GURL& feed_url, |
36 int64 start_changestamp, | 37 int64 start_changestamp, |
37 const std::string& search_string, | 38 const std::string& search_string, |
38 const std::string& directory_resource_id, | 39 const std::string& directory_resource_id, |
39 const GetDataCallback& callback)); | 40 const gdata::GetDataCallback& callback)); |
40 MOCK_METHOD2(GetDocumentEntry, void(const std::string& resource_id, | 41 MOCK_METHOD2(GetDocumentEntry, void(const std::string& resource_id, |
41 const GetDataCallback& callback)); | 42 const gdata::GetDataCallback& callback)); |
42 MOCK_METHOD1(GetAccountMetadata, void(const GetDataCallback& callback)); | 43 MOCK_METHOD1(GetAccountMetadata, |
43 MOCK_METHOD1(GetApplicationInfo, void(const GetDataCallback& callback)); | 44 void(const gdata::GetDataCallback& callback)); |
44 MOCK_METHOD2(DeleteDocument, void(const GURL& document_url, | 45 MOCK_METHOD1(GetApplicationInfo, |
45 const EntryActionCallback& callback)); | 46 void(const gdata::GetDataCallback& callback)); |
46 MOCK_METHOD5(DownloadDocument, void(const FilePath& virtual_path, | 47 MOCK_METHOD2(DeleteDocument, |
47 const FilePath& local_cache_path, | 48 void(const GURL& document_url, |
48 const GURL& content_url, | 49 const gdata::EntryActionCallback& callback)); |
49 DocumentExportFormat format, | 50 MOCK_METHOD5(DownloadDocument, |
50 const DownloadActionCallback& callback)); | 51 void(const FilePath& virtual_path, |
| 52 const FilePath& local_cache_path, |
| 53 const GURL& content_url, |
| 54 DocumentExportFormat format, |
| 55 const gdata::DownloadActionCallback& callback)); |
51 MOCK_METHOD3(CopyDocument, void(const std::string& resource_id, | 56 MOCK_METHOD3(CopyDocument, void(const std::string& resource_id, |
52 const FilePath::StringType& new_name, | 57 const FilePath::StringType& new_name, |
53 const GetDataCallback& callback)); | 58 const gdata::GetDataCallback& callback)); |
54 MOCK_METHOD3(RenameResource, void(const GURL& resource_url, | 59 MOCK_METHOD3(RenameResource, |
55 const FilePath::StringType& new_name, | 60 void(const GURL& resource_url, |
56 const EntryActionCallback& callback)); | 61 const FilePath::StringType& new_name, |
| 62 const gdata::EntryActionCallback& callback)); |
57 MOCK_METHOD3(AddResourceToDirectory, | 63 MOCK_METHOD3(AddResourceToDirectory, |
58 void(const GURL& parent_content_url, | 64 void(const GURL& parent_content_url, |
59 const GURL& resource_url, | 65 const GURL& resource_url, |
60 const EntryActionCallback& callback)); | 66 const gdata::EntryActionCallback& callback)); |
61 MOCK_METHOD4(RemoveResourceFromDirectory, | 67 MOCK_METHOD4(RemoveResourceFromDirectory, |
62 void(const GURL& parent_content_url, | 68 void(const GURL& parent_content_url, |
63 const GURL& resource_url, | 69 const GURL& resource_url, |
64 const std::string& resource_id, | 70 const std::string& resource_id, |
65 const EntryActionCallback& callback)); | 71 const gdata::EntryActionCallback& callback)); |
66 MOCK_METHOD3(CreateDirectory, | 72 MOCK_METHOD3(CreateDirectory, |
67 void(const GURL& parent_content_url, | 73 void(const GURL& parent_content_url, |
68 const FilePath::StringType& directory_name, | 74 const FilePath::StringType& directory_name, |
69 const GetDataCallback& callback)); | 75 const gdata::GetDataCallback& callback)); |
70 MOCK_METHOD5(DownloadFile, | 76 MOCK_METHOD5(DownloadFile, |
71 void(const FilePath& virtual_path, | 77 void(const FilePath& virtual_path, |
72 const FilePath& local_cache_path, | 78 const FilePath& local_cache_path, |
73 const GURL& content_url, | 79 const GURL& content_url, |
74 const DownloadActionCallback& donwload_action_callback, | 80 const gdata::DownloadActionCallback& |
75 const GetContentCallback& get_content_callback)); | 81 donwload_action_callback, |
| 82 const gdata::GetContentCallback& get_content_callback)); |
76 MOCK_METHOD2(InitiateUpload, | 83 MOCK_METHOD2(InitiateUpload, |
77 void(const InitiateUploadParams& upload_file_info, | 84 void(const gdata::InitiateUploadParams& upload_file_info, |
78 const InitiateUploadCallback& callback)); | 85 const gdata::InitiateUploadCallback& callback)); |
79 MOCK_METHOD2(ResumeUpload, void(const ResumeUploadParams& upload_file_info, | 86 MOCK_METHOD2(ResumeUpload, |
80 const ResumeUploadCallback& callback)); | 87 void(const gdata::ResumeUploadParams& upload_file_info, |
| 88 const gdata::ResumeUploadCallback& callback)); |
81 MOCK_METHOD3(AuthorizeApp, void(const GURL& resource_url, | 89 MOCK_METHOD3(AuthorizeApp, void(const GURL& resource_url, |
82 const std::string& app_ids, | 90 const std::string& app_ids, |
83 const GetDataCallback& callback)); | 91 const gdata::GetDataCallback& callback)); |
84 MOCK_CONST_METHOD0(HasAccessToken, bool()); | 92 MOCK_CONST_METHOD0(HasAccessToken, bool()); |
85 MOCK_CONST_METHOD0(HasRefreshToken, bool()); | 93 MOCK_CONST_METHOD0(HasRefreshToken, bool()); |
86 | 94 |
87 void set_account_metadata(base::Value* account_metadata) { | 95 void set_account_metadata(base::Value* account_metadata) { |
88 account_metadata_.reset(account_metadata); | 96 account_metadata_.reset(account_metadata); |
89 } | 97 } |
90 | 98 |
91 void set_feed_data(base::Value* feed_data) { | 99 void set_feed_data(base::Value* feed_data) { |
92 feed_data_.reset(feed_data); | 100 feed_data_.reset(feed_data); |
93 } | 101 } |
94 | 102 |
95 void set_directory_data(base::Value* directory_data) { | 103 void set_directory_data(base::Value* directory_data) { |
96 directory_data_.reset(directory_data); | 104 directory_data_.reset(directory_data); |
97 } | 105 } |
98 | 106 |
99 void set_file_data(std::string* file_data) { | 107 void set_file_data(std::string* file_data) { |
100 file_data_.reset(file_data); | 108 file_data_.reset(file_data); |
101 } | 109 } |
102 | 110 |
103 void set_search_result(const std::string& search_result_feed); | 111 void set_search_result(const std::string& search_result_feed); |
104 | 112 |
105 private: | 113 private: |
106 // Helper stub methods for functions which take callbacks, so that | 114 // Helper stub methods for functions which take callbacks, so that |
107 // the callbacks get called with testable results. | 115 // the callbacks get called with testable results. |
108 | 116 |
109 // Will call |callback| with HTTP_SUCCESS and the token "test_auth_token" | 117 // Will call |callback| with HTTP_SUCCESS and the token "test_auth_token" |
110 // as the token. | 118 // as the token. |
111 void AuthenticateStub(const AuthStatusCallback& callback); | 119 void AuthenticateStub(const gdata::AuthStatusCallback& callback); |
112 | 120 |
113 // Will call |callback| with HTTP_SUCCESS and a StringValue with the current | 121 // Will call |callback| with HTTP_SUCCESS and a StringValue with the current |
114 // value of |feed_data_|. | 122 // value of |feed_data_|. |
115 void GetDocumentsStub(const GURL& feed_url, | 123 void GetDocumentsStub(const GURL& feed_url, |
116 int64 start_changestamp, | 124 int64 start_changestamp, |
117 const std::string& search_string, | 125 const std::string& search_string, |
118 const std::string& directory_resource_id, | 126 const std::string& directory_resource_id, |
119 const GetDataCallback& callback); | 127 const gdata::GetDataCallback& callback); |
120 | 128 |
121 // Will call |callback| with HTTP_SUCCESS and a StringValue with the current | 129 // Will call |callback| with HTTP_SUCCESS and a StringValue with the current |
122 // value of |account_metadata_|. | 130 // value of |account_metadata_|. |
123 void GetAccountMetadataStub(const GetDataCallback& callback); | 131 void GetAccountMetadataStub(const gdata::GetDataCallback& callback); |
124 | 132 |
125 // Will call |callback| with HTTP_SUCCESS and the |document_url|. | 133 // Will call |callback| with HTTP_SUCCESS and the |document_url|. |
126 void DeleteDocumentStub(const GURL& document_url, | 134 void DeleteDocumentStub(const GURL& document_url, |
127 const EntryActionCallback& callback); | 135 const gdata::EntryActionCallback& callback); |
128 | 136 |
129 // Will call |callback| with HTTP_SUCCESS, the given URL, and the host+path | 137 // Will call |callback| with HTTP_SUCCESS, the given URL, and the host+path |
130 // portion of the URL as the temporary file path. | 138 // portion of the URL as the temporary file path. |
131 void DownloadDocumentStub(const FilePath& virtual_path, | 139 void DownloadDocumentStub(const FilePath& virtual_path, |
132 const FilePath& local_tmp_path, | 140 const FilePath& local_tmp_path, |
133 const GURL& content_url, | 141 const GURL& content_url, |
134 DocumentExportFormat format, | 142 DocumentExportFormat format, |
135 const DownloadActionCallback& callback); | 143 const gdata::DownloadActionCallback& callback); |
136 | 144 |
137 // Will call |callback| with HTTP_SUCCESS and the current value of | 145 // Will call |callback| with HTTP_SUCCESS and the current value of |
138 // |document_data_|. | 146 // |document_data_|. |
139 void CopyDocumentStub(const std::string& resource_id, | 147 void CopyDocumentStub(const std::string& resource_id, |
140 const FilePath::StringType& new_name, | 148 const FilePath::StringType& new_name, |
141 const GetDataCallback& callback); | 149 const gdata::GetDataCallback& callback); |
142 | 150 |
143 // Will call |callback| with HTTP_SUCCESS and the |document_url|. | 151 // Will call |callback| with HTTP_SUCCESS and the |document_url|. |
144 void RenameResourceStub(const GURL& document_url, | 152 void RenameResourceStub(const GURL& document_url, |
145 const FilePath::StringType& new_name, | 153 const FilePath::StringType& new_name, |
146 const EntryActionCallback& callback); | 154 const gdata::EntryActionCallback& callback); |
147 | 155 |
148 // Will call |callback| with HTTP_SUCCESS and the |resource_url|. | 156 // Will call |callback| with HTTP_SUCCESS and the |resource_url|. |
149 void AddResourceToDirectoryStub(const GURL& parent_content_url, | 157 void AddResourceToDirectoryStub(const GURL& parent_content_url, |
150 const GURL& resource_url, | 158 const GURL& resource_url, |
151 const EntryActionCallback& callback); | 159 const gdata::EntryActionCallback& callback); |
152 | 160 |
153 // Will call |callback| with HTTP_SUCCESS and the |resource_url|. | 161 // Will call |callback| with HTTP_SUCCESS and the |resource_url|. |
154 void RemoveResourceFromDirectoryStub(const GURL& parent_content_url, | 162 void RemoveResourceFromDirectoryStub( |
155 const GURL& resource_url, | 163 const GURL& parent_content_url, |
156 const std::string& resource_id, | 164 const GURL& resource_url, |
157 const EntryActionCallback& callback); | 165 const std::string& resource_id, |
| 166 const gdata::EntryActionCallback& callback); |
158 | 167 |
159 // Will call |callback| with HTTP_SUCCESS and the current value of | 168 // Will call |callback| with HTTP_SUCCESS and the current value of |
160 // |directory_data_|. | 169 // |directory_data_|. |
161 void CreateDirectoryStub(const GURL& parent_content_url, | 170 void CreateDirectoryStub(const GURL& parent_content_url, |
162 const FilePath::StringType& directory_name, | 171 const FilePath::StringType& directory_name, |
163 const GetDataCallback& callback); | 172 const gdata::GetDataCallback& callback); |
164 | 173 |
165 // Will call |callback| with HTTP_SUCCESS, the given URL, and the host+path | 174 // Will call |callback| with HTTP_SUCCESS, the given URL, and the host+path |
166 // portion of the URL as the temporary file path. If |file_data_| is not null, | 175 // portion of the URL as the temporary file path. If |file_data_| is not null, |
167 // |file_data_| is written to the temporary file. | 176 // |file_data_| is written to the temporary file. |
168 void DownloadFileStub( | 177 void DownloadFileStub( |
169 const FilePath& virtual_path, | 178 const FilePath& virtual_path, |
170 const FilePath& local_tmp_path, | 179 const FilePath& local_tmp_path, |
171 const GURL& content_url, | 180 const GURL& content_url, |
172 const DownloadActionCallback& download_action_callback, | 181 const gdata::DownloadActionCallback& download_action_callback, |
173 const GetContentCallback& get_content_callback); | 182 const gdata::GetContentCallback& get_content_callback); |
174 | 183 |
175 // Account meta data to be returned from GetAccountMetadata. | 184 // Account meta data to be returned from GetAccountMetadata. |
176 scoped_ptr<base::Value> account_metadata_; | 185 scoped_ptr<base::Value> account_metadata_; |
177 | 186 |
178 // Feed data to be returned from GetDocuments. | 187 // Feed data to be returned from GetDocuments. |
179 scoped_ptr<base::Value> feed_data_; | 188 scoped_ptr<base::Value> feed_data_; |
180 | 189 |
181 // Feed data to be returned from CreateDirectory. | 190 // Feed data to be returned from CreateDirectory. |
182 scoped_ptr<base::Value> directory_data_; | 191 scoped_ptr<base::Value> directory_data_; |
183 | 192 |
184 // Feed data to be returned from CopyDocument. | 193 // Feed data to be returned from CopyDocument. |
185 scoped_ptr<base::Value> document_data_; | 194 scoped_ptr<base::Value> document_data_; |
186 | 195 |
187 // Feed data to be returned from GetDocuments if the search path is specified. | 196 // Feed data to be returned from GetDocuments if the search path is specified. |
188 // The feed contains subset of the root_feed. | 197 // The feed contains subset of the root_feed. |
189 scoped_ptr<base::Value> search_result_; | 198 scoped_ptr<base::Value> search_result_; |
190 | 199 |
191 // File data to be written to the local temporary file when | 200 // File data to be written to the local temporary file when |
192 // DownloadDocumentStub is called. | 201 // DownloadDocumentStub is called. |
193 scoped_ptr<std::string> file_data_; | 202 scoped_ptr<std::string> file_data_; |
194 }; | 203 }; |
195 | 204 |
196 } // namespace gdata | 205 } // namespace drive |
197 | 206 |
198 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_MOCK_DRIVE_SERVICE_H_ | 207 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_MOCK_DRIVE_SERVICE_H_ |
OLD | NEW |