OLD | NEW |
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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 { FPL("bar.jpg"), false, true, true, "\xFF\xD8\xFF" }, | 58 { FPL("bar.jpg"), false, true, true, "\xFF\xD8\xFF" }, |
59 // Unsupported masquerading file. | 59 // Unsupported masquerading file. |
60 { FPL("sna.jpg"), false, true, false, "abc" }, | 60 { FPL("sna.jpg"), false, true, false, "abc" }, |
61 // Non-media file. | 61 // Non-media file. |
62 { FPL("baz.txt"), false, false, false, "abc" }, | 62 { FPL("baz.txt"), false, false, false, "abc" }, |
63 // Unsupported media file. | 63 // Unsupported media file. |
64 { FPL("foobar.cod"), false, false, false, "abc" }, | 64 { FPL("foobar.cod"), false, false, false, "abc" }, |
65 }; | 65 }; |
66 | 66 |
67 void ExpectEqHelper(const std::string& test_name, | 67 void ExpectEqHelper(const std::string& test_name, |
68 base::PlatformFileError expected, | 68 base::File::Error expected, |
69 base::PlatformFileError actual) { | 69 base::File::Error actual) { |
70 EXPECT_EQ(expected, actual) << test_name; | 70 EXPECT_EQ(expected, actual) << test_name; |
71 } | 71 } |
72 | 72 |
73 void ExpectMetadataEqHelper(const std::string& test_name, | 73 void ExpectMetadataEqHelper(const std::string& test_name, |
74 base::PlatformFileError expected, | 74 base::File::Error expected, |
75 bool expected_is_directory, | 75 bool expected_is_directory, |
76 base::PlatformFileError actual, | 76 base::File::Error actual, |
77 const base::PlatformFileInfo& file_info) { | 77 const base::File::Info& file_info) { |
78 EXPECT_EQ(expected, actual) << test_name; | 78 EXPECT_EQ(expected, actual) << test_name; |
79 if (actual == base::PLATFORM_FILE_OK) | 79 if (actual == base::File::FILE_OK) |
80 EXPECT_EQ(expected_is_directory, file_info.is_directory) << test_name; | 80 EXPECT_EQ(expected_is_directory, file_info.is_directory) << test_name; |
81 } | 81 } |
82 | 82 |
83 void DidReadDirectory(std::set<base::FilePath::StringType>* content, | 83 void DidReadDirectory(std::set<base::FilePath::StringType>* content, |
84 bool* completed, | 84 bool* completed, |
85 base::PlatformFileError error, | 85 base::File::Error error, |
86 const FileEntryList& file_list, | 86 const FileEntryList& file_list, |
87 bool has_more) { | 87 bool has_more) { |
88 EXPECT_TRUE(!*completed); | 88 EXPECT_TRUE(!*completed); |
89 *completed = !has_more; | 89 *completed = !has_more; |
90 for (FileEntryList::const_iterator itr = file_list.begin(); | 90 for (FileEntryList::const_iterator itr = file_list.begin(); |
91 itr != file_list.end(); ++itr) | 91 itr != file_list.end(); ++itr) |
92 EXPECT_TRUE(content->insert(itr->name).second); | 92 EXPECT_TRUE(content->insert(itr->name).second); |
93 } | 93 } |
94 | 94 |
95 void PopulateDirectoryWithTestCases(const base::FilePath& dir, | 95 void PopulateDirectoryWithTestCases(const base::FilePath& dir, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 }; | 199 }; |
200 | 200 |
201 TEST_F(NativeMediaFileUtilTest, DirectoryExistsAndFileExistsFiltering) { | 201 TEST_F(NativeMediaFileUtilTest, DirectoryExistsAndFileExistsFiltering) { |
202 PopulateDirectoryWithTestCases(root_path(), | 202 PopulateDirectoryWithTestCases(root_path(), |
203 kFilteringTestCases, | 203 kFilteringTestCases, |
204 arraysize(kFilteringTestCases)); | 204 arraysize(kFilteringTestCases)); |
205 | 205 |
206 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 206 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
207 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | 207 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
208 | 208 |
209 base::PlatformFileError expectation = | 209 base::File::Error expectation = |
210 kFilteringTestCases[i].visible ? | 210 kFilteringTestCases[i].visible ? |
211 base::PLATFORM_FILE_OK : | 211 base::File::FILE_OK : |
212 base::PLATFORM_FILE_ERROR_NOT_FOUND; | 212 base::File::FILE_ERROR_NOT_FOUND; |
213 | 213 |
214 std::string test_name = | 214 std::string test_name = |
215 base::StringPrintf("DirectoryExistsAndFileExistsFiltering %" PRIuS, i); | 215 base::StringPrintf("DirectoryExistsAndFileExistsFiltering %" PRIuS, i); |
216 if (kFilteringTestCases[i].is_directory) { | 216 if (kFilteringTestCases[i].is_directory) { |
217 operation_runner()->DirectoryExists( | 217 operation_runner()->DirectoryExists( |
218 url, base::Bind(&ExpectEqHelper, test_name, expectation)); | 218 url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
219 } else { | 219 } else { |
220 operation_runner()->FileExists( | 220 operation_runner()->FileExists( |
221 url, base::Bind(&ExpectEqHelper, test_name, expectation)); | 221 url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
222 } | 222 } |
(...skipping 29 matching lines...) Expand all Loading... |
252 // pre-existing. Though the result should be the same. | 252 // pre-existing. Though the result should be the same. |
253 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 253 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
254 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 254 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
255 if (kFilteringTestCases[i].is_directory) { | 255 if (kFilteringTestCases[i].is_directory) { |
256 FileSystemURL root_url = CreateURL(FPL("")); | 256 FileSystemURL root_url = CreateURL(FPL("")); |
257 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | 257 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
258 | 258 |
259 std::string test_name = base::StringPrintf( | 259 std::string test_name = base::StringPrintf( |
260 "CreateFileAndCreateDirectoryFiltering run %d, test %" PRIuS, | 260 "CreateFileAndCreateDirectoryFiltering run %d, test %" PRIuS, |
261 loop_count, i); | 261 loop_count, i); |
262 base::PlatformFileError expectation = | 262 base::File::Error expectation = |
263 kFilteringTestCases[i].visible ? | 263 kFilteringTestCases[i].visible ? |
264 base::PLATFORM_FILE_OK : | 264 base::File::FILE_OK : |
265 base::PLATFORM_FILE_ERROR_SECURITY; | 265 base::File::FILE_ERROR_SECURITY; |
266 operation_runner()->CreateDirectory( | 266 operation_runner()->CreateDirectory( |
267 url, false, false, | 267 url, false, false, |
268 base::Bind(&ExpectEqHelper, test_name, expectation)); | 268 base::Bind(&ExpectEqHelper, test_name, expectation)); |
269 } | 269 } |
270 base::MessageLoop::current()->RunUntilIdle(); | 270 base::MessageLoop::current()->RunUntilIdle(); |
271 } | 271 } |
272 } | 272 } |
273 } | 273 } |
274 | 274 |
275 TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) { | 275 TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) { |
(...skipping 11 matching lines...) Expand all Loading... |
287 // Always start with an empty destination directory. | 287 // Always start with an empty destination directory. |
288 // Copying to a non-empty destination directory is an invalid operation. | 288 // Copying to a non-empty destination directory is an invalid operation. |
289 ASSERT_TRUE(base::DeleteFile(dest_path, true)); | 289 ASSERT_TRUE(base::DeleteFile(dest_path, true)); |
290 ASSERT_TRUE(base::CreateDirectory(dest_path)); | 290 ASSERT_TRUE(base::CreateDirectory(dest_path)); |
291 | 291 |
292 FileSystemURL root_url = CreateURL(FPL("")); | 292 FileSystemURL root_url = CreateURL(FPL("")); |
293 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | 293 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
294 | 294 |
295 std::string test_name = base::StringPrintf( | 295 std::string test_name = base::StringPrintf( |
296 "CopySourceFiltering run %d test %" PRIuS, loop_count, i); | 296 "CopySourceFiltering run %d test %" PRIuS, loop_count, i); |
297 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 297 base::File::Error expectation = base::File::FILE_OK; |
298 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 298 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
299 // If the source does not exist or is not visible. | 299 // If the source does not exist or is not visible. |
300 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 300 expectation = base::File::FILE_ERROR_NOT_FOUND; |
301 } else if (!kFilteringTestCases[i].is_directory) { | 301 } else if (!kFilteringTestCases[i].is_directory) { |
302 // Cannot copy a visible file to a directory. | 302 // Cannot copy a visible file to a directory. |
303 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 303 expectation = base::File::FILE_ERROR_INVALID_OPERATION; |
304 } | 304 } |
305 operation_runner()->Copy( | 305 operation_runner()->Copy( |
306 url, dest_url, | 306 url, dest_url, |
307 fileapi::FileSystemOperation::OPTION_NONE, | 307 fileapi::FileSystemOperation::OPTION_NONE, |
308 fileapi::FileSystemOperationRunner::CopyProgressCallback(), | 308 fileapi::FileSystemOperationRunner::CopyProgressCallback(), |
309 base::Bind(&ExpectEqHelper, test_name, expectation)); | 309 base::Bind(&ExpectEqHelper, test_name, expectation)); |
310 base::MessageLoop::current()->RunUntilIdle(); | 310 base::MessageLoop::current()->RunUntilIdle(); |
311 } | 311 } |
312 } | 312 } |
313 } | 313 } |
(...skipping 22 matching lines...) Expand all Loading... |
336 if (loop_count == 0 && kFilteringTestCases[i].is_directory) { | 336 if (loop_count == 0 && kFilteringTestCases[i].is_directory) { |
337 // These directories do not exist in this case, so Copy() will not | 337 // These directories do not exist in this case, so Copy() will not |
338 // treat them as directories. Thus invalidating these test cases. | 338 // treat them as directories. Thus invalidating these test cases. |
339 continue; | 339 continue; |
340 } | 340 } |
341 FileSystemURL root_url = CreateURL(FPL("")); | 341 FileSystemURL root_url = CreateURL(FPL("")); |
342 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | 342 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
343 | 343 |
344 std::string test_name = base::StringPrintf( | 344 std::string test_name = base::StringPrintf( |
345 "CopyDestFiltering run %d test %" PRIuS, loop_count, i); | 345 "CopyDestFiltering run %d test %" PRIuS, loop_count, i); |
346 base::PlatformFileError expectation; | 346 base::File::Error expectation; |
347 if (loop_count == 0) { | 347 if (loop_count == 0) { |
348 // The destination path is a file here. The directory case has been | 348 // The destination path is a file here. The directory case has been |
349 // handled above. | 349 // handled above. |
350 // If the destination path does not exist and is not visible, then | 350 // If the destination path does not exist and is not visible, then |
351 // creating it would be a security violation. | 351 // creating it would be a security violation. |
352 expectation = | 352 expectation = |
353 kFilteringTestCases[i].visible ? | 353 kFilteringTestCases[i].visible ? |
354 base::PLATFORM_FILE_OK : | 354 base::File::FILE_OK : |
355 base::PLATFORM_FILE_ERROR_SECURITY; | 355 base::File::FILE_ERROR_SECURITY; |
356 } else { | 356 } else { |
357 if (!kFilteringTestCases[i].visible) { | 357 if (!kFilteringTestCases[i].visible) { |
358 // If the destination path exist and is not visible, then to the copy | 358 // If the destination path exist and is not visible, then to the copy |
359 // operation, it looks like the file needs to be created, which is a | 359 // operation, it looks like the file needs to be created, which is a |
360 // security violation. | 360 // security violation. |
361 expectation = base::PLATFORM_FILE_ERROR_SECURITY; | 361 expectation = base::File::FILE_ERROR_SECURITY; |
362 } else if (kFilteringTestCases[i].is_directory) { | 362 } else if (kFilteringTestCases[i].is_directory) { |
363 // Cannot copy a file to a directory. | 363 // Cannot copy a file to a directory. |
364 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 364 expectation = base::File::FILE_ERROR_INVALID_OPERATION; |
365 } else { | 365 } else { |
366 // Copying from a file to a visible file that exists is ok. | 366 // Copying from a file to a visible file that exists is ok. |
367 expectation = base::PLATFORM_FILE_OK; | 367 expectation = base::File::FILE_OK; |
368 } | 368 } |
369 } | 369 } |
370 operation_runner()->Copy( | 370 operation_runner()->Copy( |
371 src_url, url, | 371 src_url, url, |
372 fileapi::FileSystemOperation::OPTION_NONE, | 372 fileapi::FileSystemOperation::OPTION_NONE, |
373 fileapi::FileSystemOperationRunner::CopyProgressCallback(), | 373 fileapi::FileSystemOperationRunner::CopyProgressCallback(), |
374 base::Bind(&ExpectEqHelper, test_name, expectation)); | 374 base::Bind(&ExpectEqHelper, test_name, expectation)); |
375 base::MessageLoop::current()->RunUntilIdle(); | 375 base::MessageLoop::current()->RunUntilIdle(); |
376 } | 376 } |
377 } | 377 } |
(...skipping 14 matching lines...) Expand all Loading... |
392 // Always start with an empty destination directory. | 392 // Always start with an empty destination directory. |
393 // Moving to a non-empty destination directory is an invalid operation. | 393 // Moving to a non-empty destination directory is an invalid operation. |
394 ASSERT_TRUE(base::DeleteFile(dest_path, true)); | 394 ASSERT_TRUE(base::DeleteFile(dest_path, true)); |
395 ASSERT_TRUE(base::CreateDirectory(dest_path)); | 395 ASSERT_TRUE(base::CreateDirectory(dest_path)); |
396 | 396 |
397 FileSystemURL root_url = CreateURL(FPL("")); | 397 FileSystemURL root_url = CreateURL(FPL("")); |
398 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | 398 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
399 | 399 |
400 std::string test_name = base::StringPrintf( | 400 std::string test_name = base::StringPrintf( |
401 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i); | 401 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i); |
402 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 402 base::File::Error expectation = base::File::FILE_OK; |
403 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 403 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
404 // If the source does not exist or is not visible. | 404 // If the source does not exist or is not visible. |
405 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 405 expectation = base::File::FILE_ERROR_NOT_FOUND; |
406 } else if (!kFilteringTestCases[i].is_directory) { | 406 } else if (!kFilteringTestCases[i].is_directory) { |
407 // Cannot move a visible file to a directory. | 407 // Cannot move a visible file to a directory. |
408 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 408 expectation = base::File::FILE_ERROR_INVALID_OPERATION; |
409 } | 409 } |
410 operation_runner()->Move( | 410 operation_runner()->Move( |
411 url, dest_url, fileapi::FileSystemOperation::OPTION_NONE, | 411 url, dest_url, fileapi::FileSystemOperation::OPTION_NONE, |
412 base::Bind(&ExpectEqHelper, test_name, expectation)); | 412 base::Bind(&ExpectEqHelper, test_name, expectation)); |
413 base::MessageLoop::current()->RunUntilIdle(); | 413 base::MessageLoop::current()->RunUntilIdle(); |
414 } | 414 } |
415 } | 415 } |
416 } | 416 } |
417 | 417 |
418 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) { | 418 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) { |
(...skipping 22 matching lines...) Expand all Loading... |
441 FileSystemURL src_url = CreateURL(FPL("foo.jpg")); | 441 FileSystemURL src_url = CreateURL(FPL("foo.jpg")); |
442 static const char kDummyData[] = "dummy"; | 442 static const char kDummyData[] = "dummy"; |
443 ASSERT_TRUE( | 443 ASSERT_TRUE( |
444 file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); | 444 file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); |
445 | 445 |
446 FileSystemURL root_url = CreateURL(FPL("")); | 446 FileSystemURL root_url = CreateURL(FPL("")); |
447 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | 447 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
448 | 448 |
449 std::string test_name = base::StringPrintf( | 449 std::string test_name = base::StringPrintf( |
450 "MoveDestFiltering run %d test %" PRIuS, loop_count, i); | 450 "MoveDestFiltering run %d test %" PRIuS, loop_count, i); |
451 base::PlatformFileError expectation; | 451 base::File::Error expectation; |
452 if (loop_count == 0) { | 452 if (loop_count == 0) { |
453 // The destination path is a file here. The directory case has been | 453 // The destination path is a file here. The directory case has been |
454 // handled above. | 454 // handled above. |
455 // If the destination path does not exist and is not visible, then | 455 // If the destination path does not exist and is not visible, then |
456 // creating it would be a security violation. | 456 // creating it would be a security violation. |
457 expectation = | 457 expectation = |
458 kFilteringTestCases[i].visible ? | 458 kFilteringTestCases[i].visible ? |
459 base::PLATFORM_FILE_OK : | 459 base::File::FILE_OK : |
460 base::PLATFORM_FILE_ERROR_SECURITY; | 460 base::File::FILE_ERROR_SECURITY; |
461 } else { | 461 } else { |
462 if (!kFilteringTestCases[i].visible) { | 462 if (!kFilteringTestCases[i].visible) { |
463 // If the destination path exist and is not visible, then to the move | 463 // If the destination path exist and is not visible, then to the move |
464 // operation, it looks like the file needs to be created, which is a | 464 // operation, it looks like the file needs to be created, which is a |
465 // security violation. | 465 // security violation. |
466 expectation = base::PLATFORM_FILE_ERROR_SECURITY; | 466 expectation = base::File::FILE_ERROR_SECURITY; |
467 } else if (kFilteringTestCases[i].is_directory) { | 467 } else if (kFilteringTestCases[i].is_directory) { |
468 // Cannot move a file to a directory. | 468 // Cannot move a file to a directory. |
469 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 469 expectation = base::File::FILE_ERROR_INVALID_OPERATION; |
470 } else { | 470 } else { |
471 // Moving from a file to a visible file that exists is ok. | 471 // Moving from a file to a visible file that exists is ok. |
472 expectation = base::PLATFORM_FILE_OK; | 472 expectation = base::File::FILE_OK; |
473 } | 473 } |
474 } | 474 } |
475 operation_runner()->Move( | 475 operation_runner()->Move( |
476 src_url, url, fileapi::FileSystemOperation::OPTION_NONE, | 476 src_url, url, fileapi::FileSystemOperation::OPTION_NONE, |
477 base::Bind(&ExpectEqHelper, test_name, expectation)); | 477 base::Bind(&ExpectEqHelper, test_name, expectation)); |
478 base::MessageLoop::current()->RunUntilIdle(); | 478 base::MessageLoop::current()->RunUntilIdle(); |
479 } | 479 } |
480 } | 480 } |
481 } | 481 } |
482 | 482 |
483 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { | 483 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { |
484 // Run the loop twice. The first run has no files. The second run does. | 484 // Run the loop twice. The first run has no files. The second run does. |
485 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 485 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
486 if (loop_count == 1) { | 486 if (loop_count == 1) { |
487 PopulateDirectoryWithTestCases(root_path(), | 487 PopulateDirectoryWithTestCases(root_path(), |
488 kFilteringTestCases, | 488 kFilteringTestCases, |
489 arraysize(kFilteringTestCases)); | 489 arraysize(kFilteringTestCases)); |
490 } | 490 } |
491 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 491 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
492 FileSystemURL root_url = CreateURL(FPL("")); | 492 FileSystemURL root_url = CreateURL(FPL("")); |
493 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | 493 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
494 | 494 |
495 std::string test_name = base::StringPrintf( | 495 std::string test_name = base::StringPrintf( |
496 "GetMetadataFiltering run %d test %" PRIuS, loop_count, i); | 496 "GetMetadataFiltering run %d test %" PRIuS, loop_count, i); |
497 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 497 base::File::Error expectation = base::File::FILE_OK; |
498 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 498 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
499 // Cannot get metadata from files that do not exist or are not visible. | 499 // Cannot get metadata from files that do not exist or are not visible. |
500 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 500 expectation = base::File::FILE_ERROR_NOT_FOUND; |
501 } | 501 } |
502 operation_runner()->GetMetadata( | 502 operation_runner()->GetMetadata( |
503 url, | 503 url, |
504 base::Bind(&ExpectMetadataEqHelper, | 504 base::Bind(&ExpectMetadataEqHelper, |
505 test_name, | 505 test_name, |
506 expectation, | 506 expectation, |
507 kFilteringTestCases[i].is_directory)); | 507 kFilteringTestCases[i].is_directory)); |
508 base::MessageLoop::current()->RunUntilIdle(); | 508 base::MessageLoop::current()->RunUntilIdle(); |
509 } | 509 } |
510 } | 510 } |
511 } | 511 } |
512 | 512 |
513 TEST_F(NativeMediaFileUtilTest, RemoveFileFiltering) { | 513 TEST_F(NativeMediaFileUtilTest, RemoveFileFiltering) { |
514 // Run the loop twice. The first run has no files. The second run does. | 514 // Run the loop twice. The first run has no files. The second run does. |
515 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 515 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
516 if (loop_count == 1) { | 516 if (loop_count == 1) { |
517 PopulateDirectoryWithTestCases(root_path(), | 517 PopulateDirectoryWithTestCases(root_path(), |
518 kFilteringTestCases, | 518 kFilteringTestCases, |
519 arraysize(kFilteringTestCases)); | 519 arraysize(kFilteringTestCases)); |
520 } | 520 } |
521 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 521 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
522 FileSystemURL root_url = CreateURL(FPL("")); | 522 FileSystemURL root_url = CreateURL(FPL("")); |
523 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | 523 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
524 | 524 |
525 std::string test_name = base::StringPrintf( | 525 std::string test_name = base::StringPrintf( |
526 "RemoveFiltering run %d test %" PRIuS, loop_count, i); | 526 "RemoveFiltering run %d test %" PRIuS, loop_count, i); |
527 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 527 base::File::Error expectation = base::File::FILE_OK; |
528 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 528 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
529 // Cannot remove files that do not exist or are not visible. | 529 // Cannot remove files that do not exist or are not visible. |
530 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 530 expectation = base::File::FILE_ERROR_NOT_FOUND; |
531 } else if (kFilteringTestCases[i].is_directory) { | 531 } else if (kFilteringTestCases[i].is_directory) { |
532 expectation = base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 532 expectation = base::File::FILE_ERROR_NOT_A_FILE; |
533 } | 533 } |
534 operation_runner()->RemoveFile( | 534 operation_runner()->RemoveFile( |
535 url, base::Bind(&ExpectEqHelper, test_name, expectation)); | 535 url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
536 base::MessageLoop::current()->RunUntilIdle(); | 536 base::MessageLoop::current()->RunUntilIdle(); |
537 } | 537 } |
538 } | 538 } |
539 } | 539 } |
540 | 540 |
541 void CreateSnapshotCallback(base::PlatformFileError* error, | 541 void CreateSnapshotCallback( |
542 base::PlatformFileError result, const base::PlatformFileInfo&, | 542 base::File::Error* error, |
| 543 base::File::Error result, |
| 544 const base::File::Info&, |
543 const base::FilePath&, | 545 const base::FilePath&, |
544 const scoped_refptr<webkit_blob::ShareableFileReference>&) { | 546 const scoped_refptr<webkit_blob::ShareableFileReference>&) { |
545 *error = result; | 547 *error = result; |
546 } | 548 } |
547 | 549 |
548 TEST_F(NativeMediaFileUtilTest, CreateSnapshot) { | 550 TEST_F(NativeMediaFileUtilTest, CreateSnapshot) { |
549 PopulateDirectoryWithTestCases(root_path(), | 551 PopulateDirectoryWithTestCases(root_path(), |
550 kFilteringTestCases, | 552 kFilteringTestCases, |
551 arraysize(kFilteringTestCases)); | 553 arraysize(kFilteringTestCases)); |
552 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 554 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
553 if (kFilteringTestCases[i].is_directory || | 555 if (kFilteringTestCases[i].is_directory || |
554 !kFilteringTestCases[i].visible) { | 556 !kFilteringTestCases[i].visible) { |
555 continue; | 557 continue; |
556 } | 558 } |
557 FileSystemURL root_url = CreateURL(FPL("")); | 559 FileSystemURL root_url = CreateURL(FPL("")); |
558 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | 560 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
559 base::PlatformFileError expected_error, error; | 561 base::File::Error expected_error, error; |
560 if (kFilteringTestCases[i].media_file) | 562 if (kFilteringTestCases[i].media_file) |
561 expected_error = base::PLATFORM_FILE_OK; | 563 expected_error = base::File::FILE_OK; |
562 else | 564 else |
563 expected_error = base::PLATFORM_FILE_ERROR_SECURITY; | 565 expected_error = base::File::FILE_ERROR_SECURITY; |
564 error = base::PLATFORM_FILE_ERROR_FAILED; | 566 error = base::File::FILE_ERROR_FAILED; |
565 operation_runner()->CreateSnapshotFile(url, | 567 operation_runner()->CreateSnapshotFile(url, |
566 base::Bind(CreateSnapshotCallback, &error)); | 568 base::Bind(CreateSnapshotCallback, &error)); |
567 base::MessageLoop::current()->RunUntilIdle(); | 569 base::MessageLoop::current()->RunUntilIdle(); |
568 ASSERT_EQ(expected_error, error); | 570 ASSERT_EQ(expected_error, error); |
569 } | 571 } |
570 } | 572 } |
OLD | NEW |