Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/chromeos/gdata/mock_drive_service.cc

Issue 10828385: Rename DocumentsServiceInterface to DriveServiceInterface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unnecessary includes. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/chromeos/gdata/mock_documents_service.h" 5 #include "chrome/browser/chromeos/gdata/mock_drive_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/json/json_file_value_serializer.h" 11 #include "base/json/json_file_value_serializer.h"
12 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/platform_file.h" 14 #include "base/platform_file.h"
15 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
(...skipping 18 matching lines...) Expand all
34 34
35 JSONFileValueSerializer serializer(path); 35 JSONFileValueSerializer serializer(path);
36 Value* value = serializer.Deserialize(NULL, &error); 36 Value* value = serializer.Deserialize(NULL, &error);
37 EXPECT_TRUE(value) << 37 EXPECT_TRUE(value) <<
38 "Parse error " << path.value() << ": " << error; 38 "Parse error " << path.value() << ": " << error;
39 return value; 39 return value;
40 } 40 }
41 41
42 } // namespace 42 } // namespace
43 43
44 MockDocumentsService::MockDocumentsService() { 44 MockDriveService::MockDriveService() {
45 ON_CALL(*this, Authenticate(_)) 45 ON_CALL(*this, Authenticate(_))
46 .WillByDefault(Invoke(this, &MockDocumentsService::AuthenticateStub)); 46 .WillByDefault(Invoke(this, &MockDriveService::AuthenticateStub));
47 ON_CALL(*this, GetDocuments(_, _, _, _, _)) 47 ON_CALL(*this, GetDocuments(_, _, _, _, _))
48 .WillByDefault(Invoke(this, &MockDocumentsService::GetDocumentsStub)); 48 .WillByDefault(Invoke(this, &MockDriveService::GetDocumentsStub));
49 ON_CALL(*this, GetAccountMetadata(_)) 49 ON_CALL(*this, GetAccountMetadata(_))
50 .WillByDefault(Invoke(this, 50 .WillByDefault(Invoke(this,
51 &MockDocumentsService::GetAccountMetadataStub)); 51 &MockDriveService::GetAccountMetadataStub));
52 ON_CALL(*this, DeleteDocument(_, _)) 52 ON_CALL(*this, DeleteDocument(_, _))
53 .WillByDefault(Invoke(this, &MockDocumentsService::DeleteDocumentStub)); 53 .WillByDefault(Invoke(this, &MockDriveService::DeleteDocumentStub));
54 ON_CALL(*this, DownloadDocument(_, _, _, _, _)) 54 ON_CALL(*this, DownloadDocument(_, _, _, _, _))
55 .WillByDefault(Invoke(this, &MockDocumentsService::DownloadDocumentStub)); 55 .WillByDefault(Invoke(this, &MockDriveService::DownloadDocumentStub));
56 ON_CALL(*this, CopyDocument(_, _, _)) 56 ON_CALL(*this, CopyDocument(_, _, _))
57 .WillByDefault(Invoke(this, &MockDocumentsService::CopyDocumentStub)); 57 .WillByDefault(Invoke(this, &MockDriveService::CopyDocumentStub));
58 ON_CALL(*this, RenameResource(_, _, _)) 58 ON_CALL(*this, RenameResource(_, _, _))
59 .WillByDefault(Invoke(this, &MockDocumentsService::RenameResourceStub)); 59 .WillByDefault(Invoke(this, &MockDriveService::RenameResourceStub));
60 ON_CALL(*this, AddResourceToDirectory(_, _, _)) 60 ON_CALL(*this, AddResourceToDirectory(_, _, _))
61 .WillByDefault( 61 .WillByDefault(
62 Invoke(this, &MockDocumentsService::AddResourceToDirectoryStub)); 62 Invoke(this, &MockDriveService::AddResourceToDirectoryStub));
63 ON_CALL(*this, RemoveResourceFromDirectory(_, _, _, _)) 63 ON_CALL(*this, RemoveResourceFromDirectory(_, _, _, _))
64 .WillByDefault( 64 .WillByDefault(
65 Invoke(this, &MockDocumentsService::RemoveResourceFromDirectoryStub)); 65 Invoke(this, &MockDriveService::RemoveResourceFromDirectoryStub));
66 ON_CALL(*this, CreateDirectory(_, _, _)) 66 ON_CALL(*this, CreateDirectory(_, _, _))
67 .WillByDefault(Invoke(this, &MockDocumentsService::CreateDirectoryStub)); 67 .WillByDefault(Invoke(this, &MockDriveService::CreateDirectoryStub));
68 ON_CALL(*this, DownloadFile(_, _, _, _, _)) 68 ON_CALL(*this, DownloadFile(_, _, _, _, _))
69 .WillByDefault(Invoke(this, &MockDocumentsService::DownloadFileStub)); 69 .WillByDefault(Invoke(this, &MockDriveService::DownloadFileStub));
70 70
71 // Fill in the default values for mock feeds. 71 // Fill in the default values for mock feeds.
72 account_metadata_.reset(LoadJSONFile("account_metadata.json")); 72 account_metadata_.reset(LoadJSONFile("account_metadata.json"));
73 feed_data_.reset(LoadJSONFile("basic_feed.json")); 73 feed_data_.reset(LoadJSONFile("basic_feed.json"));
74 directory_data_.reset(LoadJSONFile("new_folder_entry.json")); 74 directory_data_.reset(LoadJSONFile("new_folder_entry.json"));
75 } 75 }
76 76
77 MockDocumentsService::~MockDocumentsService() {} 77 MockDriveService::~MockDriveService() {}
78 78
79 void MockDocumentsService::set_search_result( 79 void MockDriveService::set_search_result(
80 const std::string& search_result_feed) { 80 const std::string& search_result_feed) {
81 search_result_.reset(LoadJSONFile(search_result_feed)); 81 search_result_.reset(LoadJSONFile(search_result_feed));
82 } 82 }
83 83
84 void MockDocumentsService::AuthenticateStub( 84 void MockDriveService::AuthenticateStub(
85 const AuthStatusCallback& callback) { 85 const AuthStatusCallback& callback) {
86 base::MessageLoopProxy::current()->PostTask( 86 base::MessageLoopProxy::current()->PostTask(
87 FROM_HERE, 87 FROM_HERE,
88 base::Bind(callback, HTTP_SUCCESS, "my_auth_token")); 88 base::Bind(callback, HTTP_SUCCESS, "my_auth_token"));
89 } 89 }
90 90
91 void MockDocumentsService::GetDocumentsStub( 91 void MockDriveService::GetDocumentsStub(
92 const GURL& feed_url, 92 const GURL& feed_url,
93 int64 start_changestamp, 93 int64 start_changestamp,
94 const std::string& search_string, 94 const std::string& search_string,
95 const std::string& directory_resource_id, 95 const std::string& directory_resource_id,
96 const GetDataCallback& callback) { 96 const GetDataCallback& callback) {
97 if (search_string.empty()) { 97 if (search_string.empty()) {
98 base::MessageLoopProxy::current()->PostTask( 98 base::MessageLoopProxy::current()->PostTask(
99 FROM_HERE, 99 FROM_HERE,
100 base::Bind(callback, HTTP_SUCCESS, base::Passed(&feed_data_))); 100 base::Bind(callback, HTTP_SUCCESS, base::Passed(&feed_data_)));
101 } else { 101 } else {
102 base::MessageLoopProxy::current()->PostTask( 102 base::MessageLoopProxy::current()->PostTask(
103 FROM_HERE, 103 FROM_HERE,
104 base::Bind(callback, HTTP_SUCCESS, base::Passed(&search_result_))); 104 base::Bind(callback, HTTP_SUCCESS, base::Passed(&search_result_)));
105 } 105 }
106 } 106 }
107 107
108 void MockDocumentsService::GetAccountMetadataStub( 108 void MockDriveService::GetAccountMetadataStub(
109 const GetDataCallback& callback) { 109 const GetDataCallback& callback) {
110 base::MessageLoopProxy::current()->PostTask( 110 base::MessageLoopProxy::current()->PostTask(
111 FROM_HERE, 111 FROM_HERE,
112 base::Bind(callback, HTTP_SUCCESS, base::Passed(&account_metadata_))); 112 base::Bind(callback, HTTP_SUCCESS, base::Passed(&account_metadata_)));
113 } 113 }
114 114
115 void MockDocumentsService::DeleteDocumentStub( 115 void MockDriveService::DeleteDocumentStub(
116 const GURL& document_url, 116 const GURL& document_url,
117 const EntryActionCallback& callback) { 117 const EntryActionCallback& callback) {
118 base::MessageLoopProxy::current()->PostTask( 118 base::MessageLoopProxy::current()->PostTask(
119 FROM_HERE, 119 FROM_HERE,
120 base::Bind(callback, HTTP_SUCCESS, document_url)); 120 base::Bind(callback, HTTP_SUCCESS, document_url));
121 } 121 }
122 122
123 void MockDocumentsService::DownloadDocumentStub( 123 void MockDriveService::DownloadDocumentStub(
124 const FilePath& virtual_path, 124 const FilePath& virtual_path,
125 const FilePath& local_tmp_path, 125 const FilePath& local_tmp_path,
126 const GURL& content_url, 126 const GURL& content_url,
127 DocumentExportFormat format, 127 DocumentExportFormat format,
128 const DownloadActionCallback& callback) { 128 const DownloadActionCallback& callback) {
129 base::MessageLoopProxy::current()->PostTask( 129 base::MessageLoopProxy::current()->PostTask(
130 FROM_HERE, 130 FROM_HERE,
131 base::Bind(callback, HTTP_SUCCESS, content_url, local_tmp_path)); 131 base::Bind(callback, HTTP_SUCCESS, content_url, local_tmp_path));
132 } 132 }
133 133
134 void MockDocumentsService::CopyDocumentStub( 134 void MockDriveService::CopyDocumentStub(
135 const std::string& resource_id, 135 const std::string& resource_id,
136 const FilePath::StringType& new_name, 136 const FilePath::StringType& new_name,
137 const GetDataCallback& callback) { 137 const GetDataCallback& callback) {
138 base::MessageLoopProxy::current()->PostTask( 138 base::MessageLoopProxy::current()->PostTask(
139 FROM_HERE, 139 FROM_HERE,
140 base::Bind(callback, HTTP_SUCCESS, base::Passed(&document_data_))); 140 base::Bind(callback, HTTP_SUCCESS, base::Passed(&document_data_)));
141 } 141 }
142 142
143 void MockDocumentsService::RenameResourceStub( 143 void MockDriveService::RenameResourceStub(
144 const GURL& resource_url, 144 const GURL& resource_url,
145 const FilePath::StringType& new_name, 145 const FilePath::StringType& new_name,
146 const EntryActionCallback& callback) { 146 const EntryActionCallback& callback) {
147 base::MessageLoopProxy::current()->PostTask( 147 base::MessageLoopProxy::current()->PostTask(
148 FROM_HERE, 148 FROM_HERE,
149 base::Bind(callback, HTTP_SUCCESS, resource_url)); 149 base::Bind(callback, HTTP_SUCCESS, resource_url));
150 } 150 }
151 151
152 void MockDocumentsService::AddResourceToDirectoryStub( 152 void MockDriveService::AddResourceToDirectoryStub(
153 const GURL& parent_content_url, 153 const GURL& parent_content_url,
154 const GURL& resource_url, 154 const GURL& resource_url,
155 const EntryActionCallback& callback) { 155 const EntryActionCallback& callback) {
156 base::MessageLoopProxy::current()->PostTask( 156 base::MessageLoopProxy::current()->PostTask(
157 FROM_HERE, 157 FROM_HERE,
158 base::Bind(callback, HTTP_SUCCESS, resource_url)); 158 base::Bind(callback, HTTP_SUCCESS, resource_url));
159 } 159 }
160 160
161 void MockDocumentsService::RemoveResourceFromDirectoryStub( 161 void MockDriveService::RemoveResourceFromDirectoryStub(
162 const GURL& parent_content_url, 162 const GURL& parent_content_url,
163 const GURL& resource_url, 163 const GURL& resource_url,
164 const std::string& resource_id, 164 const std::string& resource_id,
165 const EntryActionCallback& callback) { 165 const EntryActionCallback& callback) {
166 base::MessageLoopProxy::current()->PostTask( 166 base::MessageLoopProxy::current()->PostTask(
167 FROM_HERE, 167 FROM_HERE,
168 base::Bind(callback, HTTP_SUCCESS, resource_url)); 168 base::Bind(callback, HTTP_SUCCESS, resource_url));
169 } 169 }
170 170
171 void MockDocumentsService::CreateDirectoryStub( 171 void MockDriveService::CreateDirectoryStub(
172 const GURL& parent_content_url, 172 const GURL& parent_content_url,
173 const FilePath::StringType& directory_name, 173 const FilePath::StringType& directory_name,
174 const GetDataCallback& callback) { 174 const GetDataCallback& callback) {
175 base::MessageLoopProxy::current()->PostTask( 175 base::MessageLoopProxy::current()->PostTask(
176 FROM_HERE, 176 FROM_HERE,
177 base::Bind(callback, HTTP_SUCCESS, base::Passed(&directory_data_))); 177 base::Bind(callback, HTTP_SUCCESS, base::Passed(&directory_data_)));
178 } 178 }
179 179
180 void MockDocumentsService::DownloadFileStub( 180 void MockDriveService::DownloadFileStub(
181 const FilePath& virtual_path, 181 const FilePath& virtual_path,
182 const FilePath& local_tmp_path, 182 const FilePath& local_tmp_path,
183 const GURL& content_url, 183 const GURL& content_url,
184 const DownloadActionCallback& download_action_callback, 184 const DownloadActionCallback& download_action_callback,
185 const GetContentCallback& get_content_callback) { 185 const GetContentCallback& get_content_callback) {
186 GDataErrorCode error = HTTP_SUCCESS; 186 GDataErrorCode error = HTTP_SUCCESS;
187 if (file_data_.get()) { 187 if (file_data_.get()) {
188 int file_data_size = static_cast<int>(file_data_->size()); 188 int file_data_size = static_cast<int>(file_data_->size());
189 ASSERT_EQ(file_data_size, 189 ASSERT_EQ(file_data_size,
190 file_util::WriteFile(local_tmp_path, file_data_->data(), 190 file_util::WriteFile(local_tmp_path, file_data_->data(),
191 file_data_size)); 191 file_data_size));
192 } 192 }
193 base::MessageLoopProxy::current()->PostTask( 193 base::MessageLoopProxy::current()->PostTask(
194 FROM_HERE, 194 FROM_HERE,
195 base::Bind(download_action_callback, error, content_url, local_tmp_path)); 195 base::Bind(download_action_callback, error, content_url, local_tmp_path));
196 } 196 }
197 197
198 } // namespace gdata 198 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/mock_drive_service.h ('k') | chrome/browser/chromeos/gdata/operations_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698