| OLD | NEW |
| 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 #import <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
| 6 #import <ImageCaptureCore/ImageCaptureCore.h> | 6 #import <ImageCaptureCore/ImageCaptureCore.h> |
| 7 | 7 |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 [device addMediaFile:picture1]; | 351 [device addMediaFile:picture1]; |
| 352 [camera cameraDevice:device didAddItem:picture1]; | 352 [camera cameraDevice:device didAddItem:picture1]; |
| 353 | 353 |
| 354 base::ScopedTempDir temp_dir; | 354 base::ScopedTempDir temp_dir; |
| 355 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 355 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 356 | 356 |
| 357 EXPECT_EQ(0U, listener_.downloads().size()); | 357 EXPECT_EQ(0U, listener_.downloads().size()); |
| 358 | 358 |
| 359 // Test that a nonexistent file we ask to be downloaded will | 359 // Test that a nonexistent file we ask to be downloaded will |
| 360 // return us a not-found error. | 360 // return us a not-found error. |
| 361 base::FilePath temp_file = temp_dir.path().Append("tempfile"); | 361 base::FilePath temp_file = temp_dir.GetPath().Append("tempfile"); |
| 362 [camera downloadFile:std::string("nonexistent") localPath:temp_file]; | 362 [camera downloadFile:std::string("nonexistent") localPath:temp_file]; |
| 363 base::RunLoop().RunUntilIdle(); | 363 base::RunLoop().RunUntilIdle(); |
| 364 ASSERT_EQ(1U, listener_.downloads().size()); | 364 ASSERT_EQ(1U, listener_.downloads().size()); |
| 365 EXPECT_EQ("nonexistent", listener_.downloads()[0]); | 365 EXPECT_EQ("nonexistent", listener_.downloads()[0]); |
| 366 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, listener_.last_error()); | 366 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, listener_.last_error()); |
| 367 | 367 |
| 368 // Test that an existing file we ask to be downloaded will end up in | 368 // Test that an existing file we ask to be downloaded will end up in |
| 369 // the location we specify. The mock system will copy testing file | 369 // the location we specify. The mock system will copy testing file |
| 370 // contents to a separate filename, mimicking the ImageCaptureCore | 370 // contents to a separate filename, mimicking the ImageCaptureCore |
| 371 // library behavior. Our code then renames the file onto the requested | 371 // library behavior. Our code then renames the file onto the requested |
| (...skipping 26 matching lines...) Expand all Loading... |
| 398 | 398 |
| 399 std::string kTestFileName("pic1"); | 399 std::string kTestFileName("pic1"); |
| 400 base::scoped_nsobject<MockICCameraFile> picture1( | 400 base::scoped_nsobject<MockICCameraFile> picture1( |
| 401 [[MockICCameraFile alloc] init:base::SysUTF8ToNSString(kTestFileName)]); | 401 [[MockICCameraFile alloc] init:base::SysUTF8ToNSString(kTestFileName)]); |
| 402 [picture1 setParent:base::SysUTF8ToNSString("dir")]; | 402 [picture1 setParent:base::SysUTF8ToNSString("dir")]; |
| 403 [device addMediaFile:picture1]; | 403 [device addMediaFile:picture1]; |
| 404 [camera cameraDevice:device didAddItem:picture1]; | 404 [camera cameraDevice:device didAddItem:picture1]; |
| 405 | 405 |
| 406 base::ScopedTempDir temp_dir; | 406 base::ScopedTempDir temp_dir; |
| 407 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 407 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 408 base::FilePath temp_file = temp_dir.path().Append("tempfile"); | 408 base::FilePath temp_file = temp_dir.GetPath().Append("tempfile"); |
| 409 | 409 |
| 410 [camera downloadFile:("dir/" + kTestFileName) localPath:temp_file]; | 410 [camera downloadFile:("dir/" + kTestFileName) localPath:temp_file]; |
| 411 base::RunLoop().RunUntilIdle(); | 411 base::RunLoop().RunUntilIdle(); |
| 412 | 412 |
| 413 char file_contents[5]; | 413 char file_contents[5]; |
| 414 ASSERT_EQ(4, base::ReadFile(temp_file, file_contents, | 414 ASSERT_EQ(4, base::ReadFile(temp_file, file_contents, |
| 415 strlen(kTestFileContents))); | 415 strlen(kTestFileContents))); |
| 416 EXPECT_EQ(kTestFileContents, | 416 EXPECT_EQ(kTestFileContents, |
| 417 std::string(file_contents, strlen(kTestFileContents))); | 417 std::string(file_contents, strlen(kTestFileContents))); |
| 418 | 418 |
| 419 [camera didRemoveDevice:device]; | 419 [camera didRemoveDevice:device]; |
| 420 } | 420 } |
| 421 | 421 |
| 422 } // namespace storage_monitor | 422 } // namespace storage_monitor |
| OLD | NEW |