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

Side by Side Diff: chrome/browser/media_galleries/mac/mtp_device_delegate_impl_mac_unittest.mm

Issue 12255023: [Media Galleries] Switch Mac MTP delegate to async interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Constants &c Created 7 years, 8 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 #import <Foundation/Foundation.h> 5 #import <Foundation/Foundation.h>
6 #import <ImageCaptureCore/ImageCaptureCore.h> 6 #import <ImageCaptureCore/ImageCaptureCore.h>
7 7
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/scoped_temp_dir.h"
9 #include "base/mac/cocoa_protocols.h" 10 #include "base/mac/cocoa_protocols.h"
10 #include "base/mac/foundation_util.h" 11 #include "base/mac/foundation_util.h"
11 #include "base/memory/scoped_nsobject.h" 12 #include "base/memory/scoped_nsobject.h"
12 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/run_loop.h"
13 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
14 #include "base/strings/sys_string_conversions.h" 16 #include "base/strings/sys_string_conversions.h"
15 #include "base/test/sequenced_worker_pool_owner.h" 17 #include "base/test/sequenced_worker_pool_owner.h"
16 #include "base/threading/sequenced_worker_pool.h" 18 #include "base/threading/sequenced_worker_pool.h"
17 #include "chrome/browser/media_galleries/mac/mtp_device_delegate_impl_mac.h" 19 #include "chrome/browser/media_galleries/mac/mtp_device_delegate_impl_mac.h"
18 #include "chrome/browser/storage_monitor/image_capture_device_manager.h" 20 #include "chrome/browser/storage_monitor/image_capture_device_manager.h"
19 #include "chrome/browser/storage_monitor/test_storage_monitor.h" 21 #include "chrome/browser/storage_monitor/test_storage_monitor.h"
20 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
21 #include "content/public/test/test_browser_thread.h" 23 #include "content/public/test/test_browser_thread.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
23 #include "webkit/fileapi/file_system_file_util.h" 25 #include "webkit/fileapi/file_system_file_util.h"
24 26
25 #if !defined(MAC_OS_X_VERSION_10_7) || \ 27 #if !defined(MAC_OS_X_VERSION_10_7) || \
26 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 28 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
27 29
28 @interface NSObject (ICCameraDeviceDelegateLionAPI) 30 @interface NSObject (ICCameraDeviceDelegateLionAPI)
29 - (void)deviceDidBecomeReadyWithCompleteContentCatalog:(ICDevice*)device; 31 - (void)deviceDidBecomeReadyWithCompleteContentCatalog:(ICDevice*)device;
30 - (void)didDownloadFile:(ICCameraFile*)file 32 - (void)didDownloadFile:(ICCameraFile*)file
31 error:(NSError*)error 33 error:(NSError*)error
32 options:(NSDictionary*)options 34 options:(NSDictionary*)options
33 contextInfo:(void*)contextInfo; 35 contextInfo:(void*)contextInfo;
34 @end 36 @end
35 37
36 #endif // 10.6 38 #endif // 10.6
37 39
38 namespace { 40 namespace {
39 41
40 const char kDeviceId[] = "id"; 42 const char kDeviceId[] = "id";
43 const char kDevicePath[] = "/ic:id";
41 const char kTestFileContents[] = "test"; 44 const char kTestFileContents[] = "test";
42 45
43 } // namespace 46 } // namespace
44 47
45 @interface MockMTPICCameraDevice : ICCameraDevice { 48 @interface MockMTPICCameraDevice : ICCameraDevice {
46 @private 49 @private
47 scoped_nsobject<NSMutableArray> allMediaFiles_; 50 scoped_nsobject<NSMutableArray> allMediaFiles_;
48 } 51 }
49 52
50 - (void)addMediaFile:(ICCameraFile*)file; 53 - (void)addMediaFile:(ICCameraFile*)file;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 event->Signal(); 171 event->Signal();
169 } 172 }
170 173
171 class MTPDeviceDelegateImplMacTest : public testing::Test { 174 class MTPDeviceDelegateImplMacTest : public testing::Test {
172 public: 175 public:
173 MTPDeviceDelegateImplMacTest() : camera_(NULL), delegate_(NULL) {} 176 MTPDeviceDelegateImplMacTest() : camera_(NULL), delegate_(NULL) {}
174 177
175 virtual void SetUp() OVERRIDE { 178 virtual void SetUp() OVERRIDE {
176 ui_thread_.reset(new content::TestBrowserThread( 179 ui_thread_.reset(new content::TestBrowserThread(
177 content::BrowserThread::UI, &message_loop_)); 180 content::BrowserThread::UI, &message_loop_));
181 file_thread_.reset(new content::TestBrowserThread(
182 content::BrowserThread::FILE, &message_loop_));
kinuko 2013/04/05 07:51:21 nit: indent
Greg Billock 2013/04/05 16:23:14 Done.
183 io_thread_.reset(new content::TestBrowserThread(
184 content::BrowserThread::IO));
185 ASSERT_TRUE(io_thread_->Start());
178 186
179 manager_.SetNotifications(monitor_.receiver()); 187 manager_.SetNotifications(monitor_.receiver());
180 188
181 camera_ = [MockMTPICCameraDevice alloc]; 189 camera_ = [MockMTPICCameraDevice alloc];
182 id<ICDeviceBrowserDelegate> delegate = manager_.device_browser(); 190 id<ICDeviceBrowserDelegate> delegate = manager_.device_browser();
183 [delegate deviceBrowser:nil didAddDevice:camera_ moreComing:NO]; 191 [delegate deviceBrowser:nil didAddDevice:camera_ moreComing:NO];
184 192
185 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); 193 delegate_ = new chrome::MTPDeviceDelegateImplMac(kDeviceId, kDevicePath);
186 task_runner_ = pool->GetSequencedTaskRunner( 194 }
187 pool->GetNamedSequenceToken("token-name")); 195
188 delegate_ = new chrome::MTPDeviceDelegateImplMac( 196 void OnError(base::WaitableEvent* event, base::PlatformFileError error) {
189 "id", "/ic:id", task_runner_.get()); 197 error_ = error;
198 event->Signal();
199 }
200
201 void OverlappedOnError(base::WaitableEvent* event,
202 base::PlatformFileError error) {
203 overlapped_error_ = error;
204 event->Signal();
205 }
206
207 void OnFileInfo(base::WaitableEvent* event,
208 const base::PlatformFileInfo& info) {
209 error_ = base::PLATFORM_FILE_OK;
210 info_ = info;
211 event->Signal();
212 }
213
214 void OnReadDir(base::WaitableEvent* event,
215 const fileapi::AsyncFileUtil::EntryList& files,
216 bool has_more) {
217 error_ = base::PLATFORM_FILE_OK;
218 ASSERT_FALSE(has_more);
219 file_list_ = files;
220 event->Signal();
221 }
222
223 void OverlappedOnReadDir(base::WaitableEvent* event,
224 const fileapi::AsyncFileUtil::EntryList& files,
225 bool has_more) {
226 overlapped_error_ = base::PLATFORM_FILE_OK;
227 ASSERT_FALSE(has_more);
228 overlapped_file_list_ = files;
229 event->Signal();
230 }
231
232 void OnDownload(base::WaitableEvent* event,
233 const base::PlatformFileInfo& file_info,
234 const base::FilePath& local_path) {
235 error_ = base::PLATFORM_FILE_OK;
236 event->Signal();
237 }
238
239 base::PlatformFileError GetFileInfo(const base::FilePath& path,
240 base::PlatformFileInfo* info) {
241 base::WaitableEvent wait(true, false);
242 delegate_->GetFileInfo(
243 path,
244 base::Bind(&MTPDeviceDelegateImplMacTest::OnFileInfo,
245 base::Unretained(this),
246 &wait),
247 base::Bind(&MTPDeviceDelegateImplMacTest::OnError,
248 base::Unretained(this),
249 &wait));
250 base::RunLoop loop;
251 loop.RunUntilIdle();
252 EXPECT_TRUE(wait.IsSignaled());
253 *info = info_;
254 return error_;
255 }
256
257 base::PlatformFileError ReadDir(const base::FilePath& path) {
258 base::WaitableEvent wait(true, false);
259 delegate_->ReadDirectory(
260 path,
261 base::Bind(&MTPDeviceDelegateImplMacTest::OnReadDir,
262 base::Unretained(this),
263 &wait),
264 base::Bind(&MTPDeviceDelegateImplMacTest::OnError,
265 base::Unretained(this),
266 &wait));
267 base::RunLoop loop;
268 loop.RunUntilIdle();
269 wait.Wait();
270 return error_;
271 }
272
273 base::PlatformFileError DownloadFile(
274 const base::FilePath& path,
275 const base::FilePath& local_path) {
276 base::WaitableEvent wait(true, false);
277 delegate_->CreateSnapshotFile(
278 path, local_path,
279 base::Bind(&MTPDeviceDelegateImplMacTest::OnDownload,
280 base::Unretained(this),
281 &wait),
282 base::Bind(&MTPDeviceDelegateImplMacTest::OnError,
283 base::Unretained(this),
284 &wait));
285 base::RunLoop loop;
286 loop.RunUntilIdle();
287 wait.Wait();
288 return error_;
190 } 289 }
191 290
192 virtual void TearDown() OVERRIDE { 291 virtual void TearDown() OVERRIDE {
193 id<ICDeviceBrowserDelegate> delegate = manager_.device_browser(); 292 id<ICDeviceBrowserDelegate> delegate = manager_.device_browser();
194 [delegate deviceBrowser:nil didRemoveDevice:camera_ moreGoing:NO]; 293 [delegate deviceBrowser:nil didRemoveDevice:camera_ moreGoing:NO];
195 294
196 task_runner_->PostTask(FROM_HERE, 295 delegate_->CancelPendingTasksAndDeleteDelegate();
197 base::Bind(&chrome::MTPDeviceDelegateImplMac:: 296
198 CancelPendingTasksAndDeleteDelegate, 297 io_thread_->Stop();
199 base::Unretained(delegate_)));
200 } 298 }
201 299
202 protected: 300 protected:
203 MessageLoopForUI message_loop_; 301 MessageLoopForUI message_loop_;
302 // Note: threads must be made in this order: UI > FILE > IO
204 scoped_ptr<content::TestBrowserThread> ui_thread_; 303 scoped_ptr<content::TestBrowserThread> ui_thread_;
304 scoped_ptr<content::TestBrowserThread> file_thread_;
305 scoped_ptr<content::TestBrowserThread> io_thread_;
306 base::ScopedTempDir temp_dir_;
205 chrome::test::TestStorageMonitor monitor_; 307 chrome::test::TestStorageMonitor monitor_;
206 chrome::ImageCaptureDeviceManager manager_; 308 chrome::ImageCaptureDeviceManager manager_;
207 ICCameraDevice* camera_; 309 MockMTPICCameraDevice* camera_;
208 scoped_refptr<base::SequencedTaskRunner> task_runner_;
209 310
210 // This object needs special deletion inside the above |task_runner_|. 311 // This object needs special deletion inside the above |task_runner_|.
211 chrome::MTPDeviceDelegateImplMac* delegate_; 312 chrome::MTPDeviceDelegateImplMac* delegate_;
212 313
314 base::PlatformFileError error_;
315 base::PlatformFileInfo info_;
316 fileapi::AsyncFileUtil::EntryList file_list_;
317
318 base::PlatformFileError overlapped_error_;
319 fileapi::AsyncFileUtil::EntryList overlapped_file_list_;
320
213 private: 321 private:
214 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplMacTest); 322 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplMacTest);
215 }; 323 };
216 324
217 TEST_F(MTPDeviceDelegateImplMacTest, TestGetRootFileInfo) { 325 TEST_F(MTPDeviceDelegateImplMacTest, TestGetRootFileInfo) {
218 base::PlatformFileInfo info; 326 base::PlatformFileInfo info;
219 // Making a fresh delegate should have a single file entry for the synthetic 327 // Making a fresh delegate should have a single file entry for the synthetic
220 // root directory, with the name equal to the device id string. 328 // root directory, with the name equal to the device id string.
221 EXPECT_EQ(base::PLATFORM_FILE_OK, 329 EXPECT_EQ(base::PLATFORM_FILE_OK,
222 delegate_->GetFileInfo(base::FilePath("/ic:id"), &info)); 330 GetFileInfo(base::FilePath(kDevicePath), &info));
223 EXPECT_TRUE(info.is_directory); 331 EXPECT_TRUE(info.is_directory);
224 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 332 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
225 delegate_->GetFileInfo(base::FilePath("/nonexistent"), &info)); 333 GetFileInfo(base::FilePath("/nonexistent"), &info));
226 334
227 // Signal the delegate that no files are coming. 335 // Signal the delegate that no files are coming.
228 delegate_->NoMoreItems(); 336 delegate_->NoMoreItems();
229 337
230 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> enumerator = 338 EXPECT_EQ(base::PLATFORM_FILE_OK, ReadDir(base::FilePath(kDevicePath)));
231 delegate_->CreateFileEnumerator(base::FilePath("/ic:id"), true); 339 EXPECT_EQ(0U, file_list_.size());
232 EXPECT_TRUE(enumerator->Next().empty()); 340 }
341
342 TEST_F(MTPDeviceDelegateImplMacTest, TestOverlappedReadDir) {
343 base::Time time1 = base::Time::Now();
344 base::PlatformFileInfo info1;
345 info1.size = 1;
346 info1.is_directory = false;
347 info1.is_symbolic_link = false;
348 info1.last_modified = time1;
349 info1.last_accessed = time1;
350 info1.creation_time = time1;
351 delegate_->ItemAdded("name1", info1);
352
353 base::WaitableEvent wait(true, false);
354
355 delegate_->ReadDirectory(
356 base::FilePath(kDevicePath),
357 base::Bind(&MTPDeviceDelegateImplMacTest::OnReadDir,
358 base::Unretained(this),
359 &wait),
360 base::Bind(&MTPDeviceDelegateImplMacTest::OnError,
361 base::Unretained(this),
362 &wait));
363
364 delegate_->ReadDirectory(
365 base::FilePath(kDevicePath),
366 base::Bind(&MTPDeviceDelegateImplMacTest::OverlappedOnReadDir,
367 base::Unretained(this),
368 &wait),
369 base::Bind(&MTPDeviceDelegateImplMacTest::OverlappedOnError,
370 base::Unretained(this),
371 &wait));
372
373
374 // Signal the delegate that no files are coming.
375 delegate_->NoMoreItems();
376
377 base::RunLoop loop;
378 loop.RunUntilIdle();
379 wait.Wait();
380
381 EXPECT_EQ(base::PLATFORM_FILE_OK, error_);
382 EXPECT_EQ(1U, file_list_.size());
383 EXPECT_EQ(base::PLATFORM_FILE_OK, overlapped_error_);
384 EXPECT_EQ(1U, overlapped_file_list_.size());
233 } 385 }
234 386
235 TEST_F(MTPDeviceDelegateImplMacTest, TestGetFileInfo) { 387 TEST_F(MTPDeviceDelegateImplMacTest, TestGetFileInfo) {
236 base::Time time1 = base::Time::Now(); 388 base::Time time1 = base::Time::Now();
237 base::PlatformFileInfo info1; 389 base::PlatformFileInfo info1;
238 info1.size = 1; 390 info1.size = 1;
239 info1.is_directory = false; 391 info1.is_directory = false;
240 info1.is_symbolic_link = false; 392 info1.is_symbolic_link = false;
241 info1.last_modified = time1; 393 info1.last_modified = time1;
242 info1.last_accessed = time1; 394 info1.last_accessed = time1;
243 info1.creation_time = time1; 395 info1.creation_time = time1;
244 delegate_->ItemAdded("name1", info1); 396 delegate_->ItemAdded("name1", info1);
245 397
246 base::PlatformFileInfo info; 398 base::PlatformFileInfo info;
247 EXPECT_EQ(base::PLATFORM_FILE_OK, 399 EXPECT_EQ(base::PLATFORM_FILE_OK,
248 delegate_->GetFileInfo(base::FilePath("/ic:id/name1"), &info)); 400 GetFileInfo(base::FilePath("/ic:id/name1"), &info));
249 EXPECT_EQ(info1.size, info.size); 401 EXPECT_EQ(info1.size, info.size);
250 EXPECT_EQ(info1.is_directory, info.is_directory); 402 EXPECT_EQ(info1.is_directory, info.is_directory);
251 EXPECT_EQ(info1.last_modified, info.last_modified); 403 EXPECT_EQ(info1.last_modified, info.last_modified);
252 EXPECT_EQ(info1.last_accessed, info.last_accessed); 404 EXPECT_EQ(info1.last_accessed, info.last_accessed);
253 EXPECT_EQ(info1.creation_time, info.creation_time); 405 EXPECT_EQ(info1.creation_time, info.creation_time);
254 406
255 info1.size = 2; 407 info1.size = 2;
256 delegate_->ItemAdded("name2", info1); 408 delegate_->ItemAdded("name2", info1);
257 delegate_->NoMoreItems(); 409 delegate_->NoMoreItems();
258 410
259 EXPECT_EQ(base::PLATFORM_FILE_OK, 411 EXPECT_EQ(base::PLATFORM_FILE_OK,
260 delegate_->GetFileInfo(base::FilePath("/ic:id/name2"), &info)); 412 GetFileInfo(base::FilePath("/ic:id/name2"), &info));
261 EXPECT_EQ(info1.size, info.size); 413 EXPECT_EQ(info1.size, info.size);
262 414
263 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> enumerator = 415 EXPECT_EQ(base::PLATFORM_FILE_OK, ReadDir(base::FilePath(kDevicePath)));
264 delegate_->CreateFileEnumerator(base::FilePath("/ic:id"), true);
265 base::FilePath next = enumerator->Next();
266 ASSERT_FALSE(next.empty());
267 EXPECT_EQ(1, enumerator->Size());
268 EXPECT_EQ(time1, enumerator->LastModifiedTime());
269 EXPECT_FALSE(enumerator->IsDirectory());
270 EXPECT_EQ("/ic:id/name1", next.value());
271 416
272 next = enumerator->Next(); 417 ASSERT_EQ(2U, file_list_.size());
273 ASSERT_FALSE(next.empty()); 418 EXPECT_EQ(time1, file_list_[0].last_modified_time);
274 EXPECT_EQ(2, enumerator->Size()); 419 EXPECT_FALSE(file_list_[0].is_directory);
275 EXPECT_EQ(time1, enumerator->LastModifiedTime()); 420 EXPECT_EQ("/ic:id/name1", file_list_[0].name);
276 EXPECT_FALSE(enumerator->IsDirectory());
277 EXPECT_EQ("/ic:id/name2", next.value());
278 421
279 next = enumerator->Next(); 422 EXPECT_EQ(time1, file_list_[1].last_modified_time);
280 EXPECT_TRUE(next.empty()); 423 EXPECT_FALSE(file_list_[1].is_directory);
424 EXPECT_EQ("/ic:id/name2", file_list_[1].name);
281 } 425 }
282 426
283 TEST_F(MTPDeviceDelegateImplMacTest, TestIgnoreDirectories) { 427 TEST_F(MTPDeviceDelegateImplMacTest, TestIgnoreDirectories) {
284 base::Time time1 = base::Time::Now(); 428 base::Time time1 = base::Time::Now();
285 base::PlatformFileInfo info1; 429 base::PlatformFileInfo info1;
286 info1.size = 1; 430 info1.size = 1;
287 info1.is_directory = false; 431 info1.is_directory = false;
288 info1.is_symbolic_link = false; 432 info1.is_symbolic_link = false;
289 info1.last_modified = time1; 433 info1.last_modified = time1;
290 info1.last_accessed = time1; 434 info1.last_accessed = time1;
291 info1.creation_time = time1; 435 info1.creation_time = time1;
292 delegate_->ItemAdded("name1", info1); 436 delegate_->ItemAdded("name1", info1);
293 437
294 info1.is_directory = true; 438 info1.is_directory = true;
295 delegate_->ItemAdded("dir1", info1); 439 delegate_->ItemAdded("dir1", info1);
296 delegate_->ItemAdded("dir2", info1); 440 delegate_->ItemAdded("dir2", info1);
297 441
298 info1.is_directory = false; 442 info1.is_directory = false;
299 delegate_->ItemAdded("name2", info1); 443 delegate_->ItemAdded("name2", info1);
300 delegate_->NoMoreItems(); 444 delegate_->NoMoreItems();
301 445
302 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> enumerator = 446 EXPECT_EQ(base::PLATFORM_FILE_OK, ReadDir(base::FilePath(kDevicePath)));
303 delegate_->CreateFileEnumerator(base::FilePath("/ic:id"), true);
304 base::FilePath next = enumerator->Next();
305 ASSERT_FALSE(next.empty());
306 EXPECT_EQ("/ic:id/name1", next.value());
307 447
308 next = enumerator->Next(); 448 ASSERT_EQ(2U, file_list_.size());
309 ASSERT_FALSE(next.empty()); 449 EXPECT_EQ(time1, file_list_[0].last_modified_time);
310 EXPECT_EQ("/ic:id/name2", next.value()); 450 EXPECT_FALSE(file_list_[0].is_directory);
451 EXPECT_EQ("/ic:id/name1", file_list_[0].name);
311 452
312 next = enumerator->Next(); 453 EXPECT_EQ(time1, file_list_[1].last_modified_time);
313 EXPECT_TRUE(next.empty()); 454 EXPECT_FALSE(file_list_[1].is_directory);
455 EXPECT_EQ("/ic:id/name2", file_list_[1].name);
314 } 456 }
315 457
316 TEST_F(MTPDeviceDelegateImplMacTest, EnumeratorWaitsForEntries) { 458 TEST_F(MTPDeviceDelegateImplMacTest, TestDownload) {
317 base::Time time1 = base::Time::Now(); 459 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
318 base::PlatformFileInfo info1; 460 base::Time t1 = base::Time::Now();
319 info1.size = 1; 461 base::PlatformFileInfo info;
320 info1.is_directory = false; 462 info.size = 4;
321 info1.is_symbolic_link = false; 463 info.is_directory = false;
322 info1.last_modified = time1; 464 info.is_symbolic_link = false;
323 info1.last_accessed = time1; 465 info.last_modified = t1;
324 info1.creation_time = time1; 466 info.last_accessed = t1;
325 delegate_->ItemAdded("name1", info1); 467 info.creation_time = t1;
468 std::string kTestFileName("filename");
469 scoped_nsobject<MockMTPICCameraFile> picture1(
470 [[MockMTPICCameraFile alloc]
471 init:base::SysUTF8ToNSString(kTestFileName)]);
472 [camera_ addMediaFile:picture1];
473 delegate_->ItemAdded(kTestFileName, info);
474 delegate_->NoMoreItems();
326 475
327 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> enumerator = 476 EXPECT_EQ(base::PLATFORM_FILE_OK, ReadDir(base::FilePath(kDevicePath)));
328 delegate_->CreateFileEnumerator(base::FilePath("/ic:id"), true); 477 ASSERT_EQ(1U, file_list_.size());
329 // Event is manually reset, initially unsignaled 478 ASSERT_EQ("/ic:id/filename", file_list_[0].name);
330 base::WaitableEvent event(true, false);
331 base::FilePath next;
332 task_runner_->PostTask(FROM_HERE,
333 base::Bind(&EnumerateAndSignal,
334 enumerator.get(), &event, &next));
335 message_loop_.RunUntilIdle();
336 ASSERT_TRUE(event.IsSignaled());
337 EXPECT_EQ("/ic:id/name1", next.value());
338 479
339 event.Reset(); 480 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
481 DownloadFile(base::FilePath("/ic:id/nonexist"),
kinuko 2013/04/05 07:51:21 nit: indent
Greg Billock 2013/04/05 16:23:14 Done.
482 temp_dir_.path().Append("target")));
340 483
341 // This method will block until it is sure there are no more items. 484 EXPECT_EQ(base::PLATFORM_FILE_OK,
342 task_runner_->PostTask(FROM_HERE, 485 DownloadFile(base::FilePath("/ic:id/filename"),
343 base::Bind(&EnumerateAndSignal, 486 temp_dir_.path().Append("target")));
344 enumerator.get(), &event, &next)); 487 std::string contents;
345 message_loop_.RunUntilIdle(); 488 EXPECT_TRUE(file_util::ReadFileToString(temp_dir_.path().Append("target"),
346 ASSERT_FALSE(event.IsSignaled()); 489 &contents));
347 delegate_->NoMoreItems(); 490 EXPECT_EQ(kTestFileContents, contents);
348 event.Wait();
349 ASSERT_TRUE(event.IsSignaled());
350 EXPECT_TRUE(next.empty());
351 message_loop_.RunUntilIdle();
352 } 491 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698