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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/open_file_unittest.cc

Issue 335753004: [fsp] Cleanup handling errors for operation requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 false /* create */, 171 false /* create */,
172 base::Bind(&CallbackLogger::OnOpenFile, callback_logger.GetWeakPtr())); 172 base::Bind(&CallbackLogger::OnOpenFile, callback_logger.GetWeakPtr()));
173 open_file.SetDispatchEventImplForTesting( 173 open_file.SetDispatchEventImplForTesting(
174 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, 174 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl,
175 base::Unretained(&dispatcher))); 175 base::Unretained(&dispatcher)));
176 176
177 EXPECT_FALSE(open_file.Execute(kRequestId)); 177 EXPECT_FALSE(open_file.Execute(kRequestId));
178 } 178 }
179 179
180 TEST_F(FileSystemProviderOperationsOpenFileTest, OnSuccess) { 180 TEST_F(FileSystemProviderOperationsOpenFileTest, OnSuccess) {
181 using extensions::api::file_system_provider_internal::
182 OpenFileRequestedSuccess::Params;
183
184 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 181 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
185 CallbackLogger callback_logger; 182 CallbackLogger callback_logger;
186 183
187 OpenFile open_file( 184 OpenFile open_file(
188 NULL, 185 NULL,
189 file_system_info_, 186 file_system_info_,
190 base::FilePath::FromUTF8Unsafe(kFilePath), 187 base::FilePath::FromUTF8Unsafe(kFilePath),
191 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, 188 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ,
192 false /* create */, 189 false /* create */,
193 base::Bind(&CallbackLogger::OnOpenFile, callback_logger.GetWeakPtr())); 190 base::Bind(&CallbackLogger::OnOpenFile, callback_logger.GetWeakPtr()));
194 open_file.SetDispatchEventImplForTesting( 191 open_file.SetDispatchEventImplForTesting(
195 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, 192 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl,
196 base::Unretained(&dispatcher))); 193 base::Unretained(&dispatcher)));
197 194
198 EXPECT_TRUE(open_file.Execute(kRequestId)); 195 EXPECT_TRUE(open_file.Execute(kRequestId));
199 196
200 open_file.OnSuccess(kRequestId, 197 open_file.OnSuccess(kRequestId,
201 scoped_ptr<RequestValue>(new RequestValue()), 198 scoped_ptr<RequestValue>(new RequestValue()),
202 false /* has_more */); 199 false /* has_more */);
203 ASSERT_EQ(1u, callback_logger.events().size()); 200 ASSERT_EQ(1u, callback_logger.events().size());
204 CallbackLogger::Event* event = callback_logger.events()[0]; 201 CallbackLogger::Event* event = callback_logger.events()[0];
205 EXPECT_EQ(base::File::FILE_OK, event->result()); 202 EXPECT_EQ(base::File::FILE_OK, event->result());
206 EXPECT_LT(0, event->file_handle()); 203 EXPECT_LT(0, event->file_handle());
207 } 204 }
208 205
209 TEST_F(FileSystemProviderOperationsOpenFileTest, OnError) { 206 TEST_F(FileSystemProviderOperationsOpenFileTest, OnError) {
210 using extensions::api::file_system_provider_internal::OpenFileRequestedError::
211 Params;
212
213 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 207 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
214 CallbackLogger callback_logger; 208 CallbackLogger callback_logger;
215 209
216 OpenFile open_file( 210 OpenFile open_file(
217 NULL, 211 NULL,
218 file_system_info_, 212 file_system_info_,
219 base::FilePath::FromUTF8Unsafe(kFilePath), 213 base::FilePath::FromUTF8Unsafe(kFilePath),
220 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, 214 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ,
221 false /* create */, 215 false /* create */,
222 base::Bind(&CallbackLogger::OnOpenFile, callback_logger.GetWeakPtr())); 216 base::Bind(&CallbackLogger::OnOpenFile, callback_logger.GetWeakPtr()));
223 open_file.SetDispatchEventImplForTesting( 217 open_file.SetDispatchEventImplForTesting(
224 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, 218 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl,
225 base::Unretained(&dispatcher))); 219 base::Unretained(&dispatcher)));
226 220
227 EXPECT_TRUE(open_file.Execute(kRequestId)); 221 EXPECT_TRUE(open_file.Execute(kRequestId));
228 222
229 open_file.OnError(kRequestId, base::File::FILE_ERROR_TOO_MANY_OPENED); 223 open_file.OnError(kRequestId,
224 scoped_ptr<RequestValue>(new RequestValue()),
225 base::File::FILE_ERROR_TOO_MANY_OPENED);
230 ASSERT_EQ(1u, callback_logger.events().size()); 226 ASSERT_EQ(1u, callback_logger.events().size());
231 CallbackLogger::Event* event = callback_logger.events()[0]; 227 CallbackLogger::Event* event = callback_logger.events()[0];
232 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); 228 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result());
233 ASSERT_EQ(0, event->file_handle()); 229 ASSERT_EQ(0, event->file_handle());
234 } 230 }
235 231
236 } // namespace operations 232 } // namespace operations
237 } // namespace file_system_provider 233 } // namespace file_system_provider
238 } // namespace chromeos 234 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698