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

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

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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/file.h"
9 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
10 #include "base/mac/cocoa_protocols.h" 11 #include "base/mac/cocoa_protocols.h"
11 #include "base/mac/foundation_util.h" 12 #include "base/mac/foundation_util.h"
12 #include "base/mac/scoped_nsobject.h" 13 #include "base/mac/scoped_nsobject.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "base/strings/sys_string_conversions.h" 16 #include "base/strings/sys_string_conversions.h"
16 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
17 #include "base/test/sequenced_worker_pool_owner.h" 18 #include "base/test/sequenced_worker_pool_owner.h"
18 #include "base/threading/sequenced_worker_pool.h" 19 #include "base/threading/sequenced_worker_pool.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 id<ICDeviceBrowserDelegate> delegate = manager_.device_browser(); 188 id<ICDeviceBrowserDelegate> delegate = manager_.device_browser();
188 [delegate deviceBrowser:nil didRemoveDevice:camera_ moreGoing:NO]; 189 [delegate deviceBrowser:nil didRemoveDevice:camera_ moreGoing:NO];
189 190
190 delegate_->CancelPendingTasksAndDeleteDelegate(); 191 delegate_->CancelPendingTasksAndDeleteDelegate();
191 192
192 TestStorageMonitor::RemoveSingleton(); 193 TestStorageMonitor::RemoveSingleton();
193 194
194 io_thread_->Stop(); 195 io_thread_->Stop();
195 } 196 }
196 197
197 void OnError(base::WaitableEvent* event, base::PlatformFileError error) { 198 void OnError(base::WaitableEvent* event, base::File::Error error) {
198 error_ = error; 199 error_ = error;
199 event->Signal(); 200 event->Signal();
200 } 201 }
201 202
202 void OverlappedOnError(base::WaitableEvent* event, 203 void OverlappedOnError(base::WaitableEvent* event,
203 base::PlatformFileError error) { 204 base::File::Error error) {
204 overlapped_error_ = error; 205 overlapped_error_ = error;
205 event->Signal(); 206 event->Signal();
206 } 207 }
207 208
208 void OnFileInfo(base::WaitableEvent* event, 209 void OnFileInfo(base::WaitableEvent* event,
209 const base::PlatformFileInfo& info) { 210 const base::File::Info& info) {
210 error_ = base::PLATFORM_FILE_OK; 211 error_ = base::File::FILE_OK;
211 info_ = info; 212 info_ = info;
212 event->Signal(); 213 event->Signal();
213 } 214 }
214 215
215 void OnReadDir(base::WaitableEvent* event, 216 void OnReadDir(base::WaitableEvent* event,
216 const fileapi::AsyncFileUtil::EntryList& files, 217 const fileapi::AsyncFileUtil::EntryList& files,
217 bool has_more) { 218 bool has_more) {
218 error_ = base::PLATFORM_FILE_OK; 219 error_ = base::File::FILE_OK;
219 ASSERT_FALSE(has_more); 220 ASSERT_FALSE(has_more);
220 file_list_ = files; 221 file_list_ = files;
221 event->Signal(); 222 event->Signal();
222 } 223 }
223 224
224 void OverlappedOnReadDir(base::WaitableEvent* event, 225 void OverlappedOnReadDir(base::WaitableEvent* event,
225 const fileapi::AsyncFileUtil::EntryList& files, 226 const fileapi::AsyncFileUtil::EntryList& files,
226 bool has_more) { 227 bool has_more) {
227 overlapped_error_ = base::PLATFORM_FILE_OK; 228 overlapped_error_ = base::File::FILE_OK;
228 ASSERT_FALSE(has_more); 229 ASSERT_FALSE(has_more);
229 overlapped_file_list_ = files; 230 overlapped_file_list_ = files;
230 event->Signal(); 231 event->Signal();
231 } 232 }
232 233
233 void OnDownload(base::WaitableEvent* event, 234 void OnDownload(base::WaitableEvent* event,
234 const base::PlatformFileInfo& file_info, 235 const base::File::Info& file_info,
235 const base::FilePath& local_path) { 236 const base::FilePath& local_path) {
236 error_ = base::PLATFORM_FILE_OK; 237 error_ = base::File::FILE_OK;
237 event->Signal(); 238 event->Signal();
238 } 239 }
239 240
240 base::PlatformFileError GetFileInfo(const base::FilePath& path, 241 base::File::Error GetFileInfo(const base::FilePath& path,
241 base::PlatformFileInfo* info) { 242 base::File::Info* info) {
242 base::WaitableEvent wait(true, false); 243 base::WaitableEvent wait(true, false);
243 delegate_->GetFileInfo( 244 delegate_->GetFileInfo(
244 path, 245 path,
245 base::Bind(&MTPDeviceDelegateImplMacTest::OnFileInfo, 246 base::Bind(&MTPDeviceDelegateImplMacTest::OnFileInfo,
246 base::Unretained(this), 247 base::Unretained(this),
247 &wait), 248 &wait),
248 base::Bind(&MTPDeviceDelegateImplMacTest::OnError, 249 base::Bind(&MTPDeviceDelegateImplMacTest::OnError,
249 base::Unretained(this), 250 base::Unretained(this),
250 &wait)); 251 &wait));
251 base::RunLoop loop; 252 base::RunLoop loop;
252 loop.RunUntilIdle(); 253 loop.RunUntilIdle();
253 EXPECT_TRUE(wait.IsSignaled()); 254 EXPECT_TRUE(wait.IsSignaled());
254 *info = info_; 255 *info = info_;
255 return error_; 256 return error_;
256 } 257 }
257 258
258 base::PlatformFileError ReadDir(const base::FilePath& path) { 259 base::File::Error ReadDir(const base::FilePath& path) {
259 base::WaitableEvent wait(true, false); 260 base::WaitableEvent wait(true, false);
260 delegate_->ReadDirectory( 261 delegate_->ReadDirectory(
261 path, 262 path,
262 base::Bind(&MTPDeviceDelegateImplMacTest::OnReadDir, 263 base::Bind(&MTPDeviceDelegateImplMacTest::OnReadDir,
263 base::Unretained(this), 264 base::Unretained(this),
264 &wait), 265 &wait),
265 base::Bind(&MTPDeviceDelegateImplMacTest::OnError, 266 base::Bind(&MTPDeviceDelegateImplMacTest::OnError,
266 base::Unretained(this), 267 base::Unretained(this),
267 &wait)); 268 &wait));
268 base::RunLoop loop; 269 base::RunLoop loop;
269 loop.RunUntilIdle(); 270 loop.RunUntilIdle();
270 wait.Wait(); 271 wait.Wait();
271 return error_; 272 return error_;
272 } 273 }
273 274
274 base::PlatformFileError DownloadFile( 275 base::File::Error DownloadFile(
275 const base::FilePath& path, 276 const base::FilePath& path,
276 const base::FilePath& local_path) { 277 const base::FilePath& local_path) {
277 base::WaitableEvent wait(true, false); 278 base::WaitableEvent wait(true, false);
278 delegate_->CreateSnapshotFile( 279 delegate_->CreateSnapshotFile(
279 path, local_path, 280 path, local_path,
280 base::Bind(&MTPDeviceDelegateImplMacTest::OnDownload, 281 base::Bind(&MTPDeviceDelegateImplMacTest::OnDownload,
281 base::Unretained(this), 282 base::Unretained(this),
282 &wait), 283 &wait),
283 base::Bind(&MTPDeviceDelegateImplMacTest::OnError, 284 base::Bind(&MTPDeviceDelegateImplMacTest::OnError,
284 base::Unretained(this), 285 base::Unretained(this),
(...skipping 10 matching lines...) Expand all
295 scoped_ptr<content::TestBrowserThread> ui_thread_; 296 scoped_ptr<content::TestBrowserThread> ui_thread_;
296 scoped_ptr<content::TestBrowserThread> file_thread_; 297 scoped_ptr<content::TestBrowserThread> file_thread_;
297 scoped_ptr<content::TestBrowserThread> io_thread_; 298 scoped_ptr<content::TestBrowserThread> io_thread_;
298 base::ScopedTempDir temp_dir_; 299 base::ScopedTempDir temp_dir_;
299 ImageCaptureDeviceManager manager_; 300 ImageCaptureDeviceManager manager_;
300 MockMTPICCameraDevice* camera_; 301 MockMTPICCameraDevice* camera_;
301 302
302 // This object needs special deletion inside the above |task_runner_|. 303 // This object needs special deletion inside the above |task_runner_|.
303 MTPDeviceDelegateImplMac* delegate_; 304 MTPDeviceDelegateImplMac* delegate_;
304 305
305 base::PlatformFileError error_; 306 base::File::Error error_;
306 base::PlatformFileInfo info_; 307 base::File::Info info_;
307 fileapi::AsyncFileUtil::EntryList file_list_; 308 fileapi::AsyncFileUtil::EntryList file_list_;
308 309
309 base::PlatformFileError overlapped_error_; 310 base::File::Error overlapped_error_;
310 fileapi::AsyncFileUtil::EntryList overlapped_file_list_; 311 fileapi::AsyncFileUtil::EntryList overlapped_file_list_;
311 312
312 private: 313 private:
313 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplMacTest); 314 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplMacTest);
314 }; 315 };
315 316
316 TEST_F(MTPDeviceDelegateImplMacTest, TestGetRootFileInfo) { 317 TEST_F(MTPDeviceDelegateImplMacTest, TestGetRootFileInfo) {
317 base::PlatformFileInfo info; 318 base::File::Info info;
318 // Making a fresh delegate should have a single file entry for the synthetic 319 // Making a fresh delegate should have a single file entry for the synthetic
319 // root directory, with the name equal to the device id string. 320 // root directory, with the name equal to the device id string.
320 EXPECT_EQ(base::PLATFORM_FILE_OK, 321 EXPECT_EQ(base::File::FILE_OK,
321 GetFileInfo(base::FilePath(kDevicePath), &info)); 322 GetFileInfo(base::FilePath(kDevicePath), &info));
322 EXPECT_TRUE(info.is_directory); 323 EXPECT_TRUE(info.is_directory);
323 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 324 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
324 GetFileInfo(base::FilePath("/nonexistent"), &info)); 325 GetFileInfo(base::FilePath("/nonexistent"), &info));
325 326
326 // Signal the delegate that no files are coming. 327 // Signal the delegate that no files are coming.
327 delegate_->NoMoreItems(); 328 delegate_->NoMoreItems();
328 329
329 EXPECT_EQ(base::PLATFORM_FILE_OK, ReadDir(base::FilePath(kDevicePath))); 330 EXPECT_EQ(base::File::FILE_OK, ReadDir(base::FilePath(kDevicePath)));
330 EXPECT_EQ(0U, file_list_.size()); 331 EXPECT_EQ(0U, file_list_.size());
331 } 332 }
332 333
333 TEST_F(MTPDeviceDelegateImplMacTest, TestOverlappedReadDir) { 334 TEST_F(MTPDeviceDelegateImplMacTest, TestOverlappedReadDir) {
334 base::Time time1 = base::Time::Now(); 335 base::Time time1 = base::Time::Now();
335 base::PlatformFileInfo info1; 336 base::File::Info info1;
336 info1.size = 1; 337 info1.size = 1;
337 info1.is_directory = false; 338 info1.is_directory = false;
338 info1.is_symbolic_link = false; 339 info1.is_symbolic_link = false;
339 info1.last_modified = time1; 340 info1.last_modified = time1;
340 info1.last_accessed = time1; 341 info1.last_accessed = time1;
341 info1.creation_time = time1; 342 info1.creation_time = time1;
342 delegate_->ItemAdded("name1", info1); 343 delegate_->ItemAdded("name1", info1);
343 344
344 base::WaitableEvent wait(true, false); 345 base::WaitableEvent wait(true, false);
345 346
(...skipping 16 matching lines...) Expand all
362 &wait)); 363 &wait));
363 364
364 365
365 // Signal the delegate that no files are coming. 366 // Signal the delegate that no files are coming.
366 delegate_->NoMoreItems(); 367 delegate_->NoMoreItems();
367 368
368 base::RunLoop loop; 369 base::RunLoop loop;
369 loop.RunUntilIdle(); 370 loop.RunUntilIdle();
370 wait.Wait(); 371 wait.Wait();
371 372
372 EXPECT_EQ(base::PLATFORM_FILE_OK, error_); 373 EXPECT_EQ(base::File::FILE_OK, error_);
373 EXPECT_EQ(1U, file_list_.size()); 374 EXPECT_EQ(1U, file_list_.size());
374 EXPECT_EQ(base::PLATFORM_FILE_OK, overlapped_error_); 375 EXPECT_EQ(base::File::FILE_OK, overlapped_error_);
375 EXPECT_EQ(1U, overlapped_file_list_.size()); 376 EXPECT_EQ(1U, overlapped_file_list_.size());
376 } 377 }
377 378
378 TEST_F(MTPDeviceDelegateImplMacTest, TestGetFileInfo) { 379 TEST_F(MTPDeviceDelegateImplMacTest, TestGetFileInfo) {
379 base::Time time1 = base::Time::Now(); 380 base::Time time1 = base::Time::Now();
380 base::PlatformFileInfo info1; 381 base::File::Info info1;
381 info1.size = 1; 382 info1.size = 1;
382 info1.is_directory = false; 383 info1.is_directory = false;
383 info1.is_symbolic_link = false; 384 info1.is_symbolic_link = false;
384 info1.last_modified = time1; 385 info1.last_modified = time1;
385 info1.last_accessed = time1; 386 info1.last_accessed = time1;
386 info1.creation_time = time1; 387 info1.creation_time = time1;
387 delegate_->ItemAdded("name1", info1); 388 delegate_->ItemAdded("name1", info1);
388 389
389 base::PlatformFileInfo info; 390 base::File::Info info;
390 EXPECT_EQ(base::PLATFORM_FILE_OK, 391 EXPECT_EQ(base::File::FILE_OK,
391 GetFileInfo(base::FilePath("/ic:id/name1"), &info)); 392 GetFileInfo(base::FilePath("/ic:id/name1"), &info));
392 EXPECT_EQ(info1.size, info.size); 393 EXPECT_EQ(info1.size, info.size);
393 EXPECT_EQ(info1.is_directory, info.is_directory); 394 EXPECT_EQ(info1.is_directory, info.is_directory);
394 EXPECT_EQ(info1.last_modified, info.last_modified); 395 EXPECT_EQ(info1.last_modified, info.last_modified);
395 EXPECT_EQ(info1.last_accessed, info.last_accessed); 396 EXPECT_EQ(info1.last_accessed, info.last_accessed);
396 EXPECT_EQ(info1.creation_time, info.creation_time); 397 EXPECT_EQ(info1.creation_time, info.creation_time);
397 398
398 info1.size = 2; 399 info1.size = 2;
399 delegate_->ItemAdded("name2", info1); 400 delegate_->ItemAdded("name2", info1);
400 delegate_->NoMoreItems(); 401 delegate_->NoMoreItems();
401 402
402 EXPECT_EQ(base::PLATFORM_FILE_OK, 403 EXPECT_EQ(base::File::FILE_OK,
403 GetFileInfo(base::FilePath("/ic:id/name2"), &info)); 404 GetFileInfo(base::FilePath("/ic:id/name2"), &info));
404 EXPECT_EQ(info1.size, info.size); 405 EXPECT_EQ(info1.size, info.size);
405 406
406 EXPECT_EQ(base::PLATFORM_FILE_OK, ReadDir(base::FilePath(kDevicePath))); 407 EXPECT_EQ(base::File::FILE_OK, ReadDir(base::FilePath(kDevicePath)));
407 408
408 ASSERT_EQ(2U, file_list_.size()); 409 ASSERT_EQ(2U, file_list_.size());
409 EXPECT_EQ(time1, file_list_[0].last_modified_time); 410 EXPECT_EQ(time1, file_list_[0].last_modified_time);
410 EXPECT_FALSE(file_list_[0].is_directory); 411 EXPECT_FALSE(file_list_[0].is_directory);
411 EXPECT_EQ("name1", file_list_[0].name); 412 EXPECT_EQ("name1", file_list_[0].name);
412 413
413 EXPECT_EQ(time1, file_list_[1].last_modified_time); 414 EXPECT_EQ(time1, file_list_[1].last_modified_time);
414 EXPECT_FALSE(file_list_[1].is_directory); 415 EXPECT_FALSE(file_list_[1].is_directory);
415 EXPECT_EQ("name2", file_list_[1].name); 416 EXPECT_EQ("name2", file_list_[1].name);
416 } 417 }
417 418
418 TEST_F(MTPDeviceDelegateImplMacTest, TestDirectoriesAndSorting) { 419 TEST_F(MTPDeviceDelegateImplMacTest, TestDirectoriesAndSorting) {
419 base::Time time1 = base::Time::Now(); 420 base::Time time1 = base::Time::Now();
420 base::PlatformFileInfo info1; 421 base::File::Info info1;
421 info1.size = 1; 422 info1.size = 1;
422 info1.is_directory = false; 423 info1.is_directory = false;
423 info1.is_symbolic_link = false; 424 info1.is_symbolic_link = false;
424 info1.last_modified = time1; 425 info1.last_modified = time1;
425 info1.last_accessed = time1; 426 info1.last_accessed = time1;
426 info1.creation_time = time1; 427 info1.creation_time = time1;
427 delegate_->ItemAdded("name2", info1); 428 delegate_->ItemAdded("name2", info1);
428 429
429 info1.is_directory = true; 430 info1.is_directory = true;
430 delegate_->ItemAdded("dir2", info1); 431 delegate_->ItemAdded("dir2", info1);
431 delegate_->ItemAdded("dir1", info1); 432 delegate_->ItemAdded("dir1", info1);
432 433
433 info1.is_directory = false; 434 info1.is_directory = false;
434 delegate_->ItemAdded("name1", info1); 435 delegate_->ItemAdded("name1", info1);
435 delegate_->NoMoreItems(); 436 delegate_->NoMoreItems();
436 437
437 EXPECT_EQ(base::PLATFORM_FILE_OK, ReadDir(base::FilePath(kDevicePath))); 438 EXPECT_EQ(base::File::FILE_OK, ReadDir(base::FilePath(kDevicePath)));
438 439
439 ASSERT_EQ(4U, file_list_.size()); 440 ASSERT_EQ(4U, file_list_.size());
440 EXPECT_EQ("dir1", file_list_[0].name); 441 EXPECT_EQ("dir1", file_list_[0].name);
441 EXPECT_EQ("dir2", file_list_[1].name); 442 EXPECT_EQ("dir2", file_list_[1].name);
442 EXPECT_EQ(time1, file_list_[2].last_modified_time); 443 EXPECT_EQ(time1, file_list_[2].last_modified_time);
443 EXPECT_FALSE(file_list_[2].is_directory); 444 EXPECT_FALSE(file_list_[2].is_directory);
444 EXPECT_EQ("name1", file_list_[2].name); 445 EXPECT_EQ("name1", file_list_[2].name);
445 446
446 EXPECT_EQ(time1, file_list_[3].last_modified_time); 447 EXPECT_EQ(time1, file_list_[3].last_modified_time);
447 EXPECT_FALSE(file_list_[3].is_directory); 448 EXPECT_FALSE(file_list_[3].is_directory);
448 EXPECT_EQ("name2", file_list_[3].name); 449 EXPECT_EQ("name2", file_list_[3].name);
449 } 450 }
450 451
451 TEST_F(MTPDeviceDelegateImplMacTest, SubDirectories) { 452 TEST_F(MTPDeviceDelegateImplMacTest, SubDirectories) {
452 base::Time time1 = base::Time::Now(); 453 base::Time time1 = base::Time::Now();
453 base::PlatformFileInfo info1; 454 base::File::Info info1;
454 info1.size = 0; 455 info1.size = 0;
455 info1.is_directory = true; 456 info1.is_directory = true;
456 info1.is_symbolic_link = false; 457 info1.is_symbolic_link = false;
457 info1.last_modified = time1; 458 info1.last_modified = time1;
458 info1.last_accessed = time1; 459 info1.last_accessed = time1;
459 info1.creation_time = time1; 460 info1.creation_time = time1;
460 delegate_->ItemAdded("dir1", info1); 461 delegate_->ItemAdded("dir1", info1);
461 462
462 info1.size = 1; 463 info1.size = 1;
463 info1.is_directory = false; 464 info1.is_directory = false;
(...skipping 15 matching lines...) Expand all
479 info1.size = 0; 480 info1.size = 0;
480 delegate_->ItemAdded("dir2/subdir", info1); 481 delegate_->ItemAdded("dir2/subdir", info1);
481 482
482 info1.is_directory = false; 483 info1.is_directory = false;
483 info1.size = 1; 484 info1.size = 1;
484 delegate_->ItemAdded("dir2/subdir/name3", info1); 485 delegate_->ItemAdded("dir2/subdir/name3", info1);
485 delegate_->ItemAdded("name4", info1); 486 delegate_->ItemAdded("name4", info1);
486 487
487 delegate_->NoMoreItems(); 488 delegate_->NoMoreItems();
488 489
489 EXPECT_EQ(base::PLATFORM_FILE_OK, ReadDir(base::FilePath(kDevicePath))); 490 EXPECT_EQ(base::File::FILE_OK, ReadDir(base::FilePath(kDevicePath)));
490 ASSERT_EQ(3U, file_list_.size()); 491 ASSERT_EQ(3U, file_list_.size());
491 EXPECT_TRUE(file_list_[0].is_directory); 492 EXPECT_TRUE(file_list_[0].is_directory);
492 EXPECT_EQ("dir1", file_list_[0].name); 493 EXPECT_EQ("dir1", file_list_[0].name);
493 EXPECT_TRUE(file_list_[1].is_directory); 494 EXPECT_TRUE(file_list_[1].is_directory);
494 EXPECT_EQ("dir2", file_list_[1].name); 495 EXPECT_EQ("dir2", file_list_[1].name);
495 EXPECT_FALSE(file_list_[2].is_directory); 496 EXPECT_FALSE(file_list_[2].is_directory);
496 EXPECT_EQ("name4", file_list_[2].name); 497 EXPECT_EQ("name4", file_list_[2].name);
497 498
498 EXPECT_EQ(base::PLATFORM_FILE_OK, 499 EXPECT_EQ(base::File::FILE_OK,
499 ReadDir(base::FilePath(kDevicePath).Append("dir1"))); 500 ReadDir(base::FilePath(kDevicePath).Append("dir1")));
500 ASSERT_EQ(1U, file_list_.size()); 501 ASSERT_EQ(1U, file_list_.size());
501 EXPECT_FALSE(file_list_[0].is_directory); 502 EXPECT_FALSE(file_list_[0].is_directory);
502 EXPECT_EQ("name1", file_list_[0].name); 503 EXPECT_EQ("name1", file_list_[0].name);
503 504
504 EXPECT_EQ(base::PLATFORM_FILE_OK, 505 EXPECT_EQ(base::File::FILE_OK,
505 ReadDir(base::FilePath(kDevicePath).Append("dir2"))); 506 ReadDir(base::FilePath(kDevicePath).Append("dir2")));
506 ASSERT_EQ(2U, file_list_.size()); 507 ASSERT_EQ(2U, file_list_.size());
507 EXPECT_FALSE(file_list_[0].is_directory); 508 EXPECT_FALSE(file_list_[0].is_directory);
508 EXPECT_EQ("name2", file_list_[0].name); 509 EXPECT_EQ("name2", file_list_[0].name);
509 EXPECT_TRUE(file_list_[1].is_directory); 510 EXPECT_TRUE(file_list_[1].is_directory);
510 EXPECT_EQ("subdir", file_list_[1].name); 511 EXPECT_EQ("subdir", file_list_[1].name);
511 512
512 EXPECT_EQ(base::PLATFORM_FILE_OK, 513 EXPECT_EQ(base::File::FILE_OK,
513 ReadDir(base::FilePath(kDevicePath) 514 ReadDir(base::FilePath(kDevicePath)
514 .Append("dir2").Append("subdir"))); 515 .Append("dir2").Append("subdir")));
515 ASSERT_EQ(1U, file_list_.size()); 516 ASSERT_EQ(1U, file_list_.size());
516 EXPECT_FALSE(file_list_[0].is_directory); 517 EXPECT_FALSE(file_list_[0].is_directory);
517 EXPECT_EQ("name3", file_list_[0].name); 518 EXPECT_EQ("name3", file_list_[0].name);
518 519
519 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 520 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
520 ReadDir(base::FilePath(kDevicePath) 521 ReadDir(base::FilePath(kDevicePath)
521 .Append("dir2").Append("subdir").Append("subdir"))); 522 .Append("dir2").Append("subdir").Append("subdir")));
522 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 523 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
523 ReadDir(base::FilePath(kDevicePath) 524 ReadDir(base::FilePath(kDevicePath)
524 .Append("dir3").Append("subdir"))); 525 .Append("dir3").Append("subdir")));
525 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 526 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
526 ReadDir(base::FilePath(kDevicePath).Append("dir3"))); 527 ReadDir(base::FilePath(kDevicePath).Append("dir3")));
527 } 528 }
528 529
529 TEST_F(MTPDeviceDelegateImplMacTest, TestDownload) { 530 TEST_F(MTPDeviceDelegateImplMacTest, TestDownload) {
530 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 531 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
531 base::Time t1 = base::Time::Now(); 532 base::Time t1 = base::Time::Now();
532 base::PlatformFileInfo info; 533 base::File::Info info;
533 info.size = 4; 534 info.size = 4;
534 info.is_directory = false; 535 info.is_directory = false;
535 info.is_symbolic_link = false; 536 info.is_symbolic_link = false;
536 info.last_modified = t1; 537 info.last_modified = t1;
537 info.last_accessed = t1; 538 info.last_accessed = t1;
538 info.creation_time = t1; 539 info.creation_time = t1;
539 std::string kTestFileName("filename"); 540 std::string kTestFileName("filename");
540 base::scoped_nsobject<MockMTPICCameraFile> picture1( 541 base::scoped_nsobject<MockMTPICCameraFile> picture1(
541 [[MockMTPICCameraFile alloc] 542 [[MockMTPICCameraFile alloc]
542 init:base::SysUTF8ToNSString(kTestFileName)]); 543 init:base::SysUTF8ToNSString(kTestFileName)]);
543 [camera_ addMediaFile:picture1]; 544 [camera_ addMediaFile:picture1];
544 delegate_->ItemAdded(kTestFileName, info); 545 delegate_->ItemAdded(kTestFileName, info);
545 delegate_->NoMoreItems(); 546 delegate_->NoMoreItems();
546 547
547 EXPECT_EQ(base::PLATFORM_FILE_OK, ReadDir(base::FilePath(kDevicePath))); 548 EXPECT_EQ(base::File::FILE_OK, ReadDir(base::FilePath(kDevicePath)));
548 ASSERT_EQ(1U, file_list_.size()); 549 ASSERT_EQ(1U, file_list_.size());
549 ASSERT_EQ("filename", file_list_[0].name); 550 ASSERT_EQ("filename", file_list_[0].name);
550 551
551 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 552 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
552 DownloadFile(base::FilePath("/ic:id/nonexist"), 553 DownloadFile(base::FilePath("/ic:id/nonexist"),
553 temp_dir_.path().Append("target"))); 554 temp_dir_.path().Append("target")));
554 555
555 EXPECT_EQ(base::PLATFORM_FILE_OK, 556 EXPECT_EQ(base::File::FILE_OK,
556 DownloadFile(base::FilePath("/ic:id/filename"), 557 DownloadFile(base::FilePath("/ic:id/filename"),
557 temp_dir_.path().Append("target"))); 558 temp_dir_.path().Append("target")));
558 std::string contents; 559 std::string contents;
559 EXPECT_TRUE(base::ReadFileToString(temp_dir_.path().Append("target"), 560 EXPECT_TRUE(base::ReadFileToString(temp_dir_.path().Append("target"),
560 &contents)); 561 &contents));
561 EXPECT_EQ(kTestFileContents, contents); 562 EXPECT_EQ(kTestFileContents, contents);
562 } 563 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698