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