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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 // Run the loop twice. The first run has no source files. The second run does. | 281 // Run the loop twice. The first run has no source files. The second run does. |
282 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 282 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
283 if (loop_count == 1) { | 283 if (loop_count == 1) { |
284 PopulateDirectoryWithTestCases(root_path(), | 284 PopulateDirectoryWithTestCases(root_path(), |
285 kFilteringTestCases, | 285 kFilteringTestCases, |
286 arraysize(kFilteringTestCases)); | 286 arraysize(kFilteringTestCases)); |
287 } | 287 } |
288 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 288 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
289 // Always start with an empty destination directory. | 289 // Always start with an empty destination directory. |
290 // Copying to a non-empty destination directory is an invalid operation. | 290 // Copying to a non-empty destination directory is an invalid operation. |
291 ASSERT_TRUE(file_util::Delete(dest_path, true)); | 291 ASSERT_TRUE(base::Delete(dest_path, true)); |
292 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); | 292 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); |
293 | 293 |
294 FileSystemURL root_url = CreateURL(FPL("")); | 294 FileSystemURL root_url = CreateURL(FPL("")); |
295 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | 295 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
296 | 296 |
297 std::string test_name = base::StringPrintf( | 297 std::string test_name = base::StringPrintf( |
298 "CopySourceFiltering run %d test %" PRIuS, loop_count, i); | 298 "CopySourceFiltering run %d test %" PRIuS, loop_count, i); |
299 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 299 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
300 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 300 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
301 // If the source does not exist or is not visible. | 301 // If the source does not exist or is not visible. |
302 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 302 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
303 } else if (!kFilteringTestCases[i].is_directory) { | 303 } else if (!kFilteringTestCases[i].is_directory) { |
304 // Cannot copy a visible file to a directory. | 304 // Cannot copy a visible file to a directory. |
305 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 305 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
306 } | 306 } |
307 operation_runner()->Copy( | 307 operation_runner()->Copy( |
308 url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); | 308 url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
309 base::MessageLoop::current()->RunUntilIdle(); | 309 base::MessageLoop::current()->RunUntilIdle(); |
310 } | 310 } |
311 } | 311 } |
312 } | 312 } |
313 | 313 |
314 TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) { | 314 TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) { |
315 // Run the loop twice. The first run has no destination files. | 315 // Run the loop twice. The first run has no destination files. |
316 // The second run does. | 316 // The second run does. |
317 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 317 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
318 if (loop_count == 1) { | 318 if (loop_count == 1) { |
319 // Reset the test directory between the two loops to remove old | 319 // Reset the test directory between the two loops to remove old |
320 // directories and create new ones that should pre-exist. | 320 // directories and create new ones that should pre-exist. |
321 ASSERT_TRUE(file_util::Delete(root_path(), true)); | 321 ASSERT_TRUE(base::Delete(root_path(), true)); |
322 ASSERT_TRUE(file_util::CreateDirectory(root_path())); | 322 ASSERT_TRUE(file_util::CreateDirectory(root_path())); |
323 PopulateDirectoryWithTestCases(root_path(), | 323 PopulateDirectoryWithTestCases(root_path(), |
324 kFilteringTestCases, | 324 kFilteringTestCases, |
325 arraysize(kFilteringTestCases)); | 325 arraysize(kFilteringTestCases)); |
326 } | 326 } |
327 | 327 |
328 // Always create a dummy source data file. | 328 // Always create a dummy source data file. |
329 base::FilePath src_path = root_path().AppendASCII("foo.jpg"); | 329 base::FilePath src_path = root_path().AppendASCII("foo.jpg"); |
330 FileSystemURL src_url = CreateURL(FPL("foo.jpg")); | 330 FileSystemURL src_url = CreateURL(FPL("foo.jpg")); |
331 static const char kDummyData[] = "dummy"; | 331 static const char kDummyData[] = "dummy"; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 // Run the loop twice. The first run has no source files. The second run does. | 380 // Run the loop twice. The first run has no source files. The second run does. |
381 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 381 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
382 if (loop_count == 1) { | 382 if (loop_count == 1) { |
383 PopulateDirectoryWithTestCases(root_path(), | 383 PopulateDirectoryWithTestCases(root_path(), |
384 kFilteringTestCases, | 384 kFilteringTestCases, |
385 arraysize(kFilteringTestCases)); | 385 arraysize(kFilteringTestCases)); |
386 } | 386 } |
387 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 387 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
388 // Always start with an empty destination directory. | 388 // Always start with an empty destination directory. |
389 // Moving to a non-empty destination directory is an invalid operation. | 389 // Moving to a non-empty destination directory is an invalid operation. |
390 ASSERT_TRUE(file_util::Delete(dest_path, true)); | 390 ASSERT_TRUE(base::Delete(dest_path, true)); |
391 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); | 391 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); |
392 | 392 |
393 FileSystemURL root_url = CreateURL(FPL("")); | 393 FileSystemURL root_url = CreateURL(FPL("")); |
394 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | 394 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
395 | 395 |
396 std::string test_name = base::StringPrintf( | 396 std::string test_name = base::StringPrintf( |
397 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i); | 397 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i); |
398 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 398 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
399 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 399 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
400 // If the source does not exist or is not visible. | 400 // If the source does not exist or is not visible. |
401 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 401 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
402 } else if (!kFilteringTestCases[i].is_directory) { | 402 } else if (!kFilteringTestCases[i].is_directory) { |
403 // Cannot move a visible file to a directory. | 403 // Cannot move a visible file to a directory. |
404 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 404 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
405 } | 405 } |
406 operation_runner()->Move( | 406 operation_runner()->Move( |
407 url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); | 407 url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
408 base::MessageLoop::current()->RunUntilIdle(); | 408 base::MessageLoop::current()->RunUntilIdle(); |
409 } | 409 } |
410 } | 410 } |
411 } | 411 } |
412 | 412 |
413 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) { | 413 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) { |
414 // Run the loop twice. The first run has no destination files. | 414 // Run the loop twice. The first run has no destination files. |
415 // The second run does. | 415 // The second run does. |
416 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 416 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
417 if (loop_count == 1) { | 417 if (loop_count == 1) { |
418 // Reset the test directory between the two loops to remove old | 418 // Reset the test directory between the two loops to remove old |
419 // directories and create new ones that should pre-exist. | 419 // directories and create new ones that should pre-exist. |
420 ASSERT_TRUE(file_util::Delete(root_path(), true)); | 420 ASSERT_TRUE(base::Delete(root_path(), true)); |
421 ASSERT_TRUE(file_util::CreateDirectory(root_path())); | 421 ASSERT_TRUE(file_util::CreateDirectory(root_path())); |
422 PopulateDirectoryWithTestCases(root_path(), | 422 PopulateDirectoryWithTestCases(root_path(), |
423 kFilteringTestCases, | 423 kFilteringTestCases, |
424 arraysize(kFilteringTestCases)); | 424 arraysize(kFilteringTestCases)); |
425 } | 425 } |
426 | 426 |
427 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 427 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
428 if (loop_count == 0 && kFilteringTestCases[i].is_directory) { | 428 if (loop_count == 0 && kFilteringTestCases[i].is_directory) { |
429 // These directories do not exist in this case, so Copy() will not | 429 // These directories do not exist in this case, so Copy() will not |
430 // treat them as directories. Thus invalidating these test cases. | 430 // treat them as directories. Thus invalidating these test cases. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 expected_error = base::PLATFORM_FILE_ERROR_SECURITY; | 529 expected_error = base::PLATFORM_FILE_ERROR_SECURITY; |
530 error = base::PLATFORM_FILE_ERROR_FAILED; | 530 error = base::PLATFORM_FILE_ERROR_FAILED; |
531 operation_runner()->CreateSnapshotFile(url, | 531 operation_runner()->CreateSnapshotFile(url, |
532 base::Bind(CreateSnapshotCallback, &error)); | 532 base::Bind(CreateSnapshotCallback, &error)); |
533 base::MessageLoop::current()->RunUntilIdle(); | 533 base::MessageLoop::current()->RunUntilIdle(); |
534 ASSERT_EQ(expected_error, error); | 534 ASSERT_EQ(expected_error, error); |
535 } | 535 } |
536 } | 536 } |
537 | 537 |
538 } // namespace chrome | 538 } // namespace chrome |
OLD | NEW |