| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 void PopulateDirectoryWithTestCases(const base::FilePath& dir, | 95 void PopulateDirectoryWithTestCases(const base::FilePath& dir, |
| 96 const FilteringTestCase* test_cases, | 96 const FilteringTestCase* test_cases, |
| 97 size_t n) { | 97 size_t n) { |
| 98 for (size_t i = 0; i < n; ++i) { | 98 for (size_t i = 0; i < n; ++i) { |
| 99 base::FilePath path = dir.Append(test_cases[i].path); | 99 base::FilePath path = dir.Append(test_cases[i].path); |
| 100 if (test_cases[i].is_directory) { | 100 if (test_cases[i].is_directory) { |
| 101 ASSERT_TRUE(base::CreateDirectory(path)); | 101 ASSERT_TRUE(base::CreateDirectory(path)); |
| 102 } else { | 102 } else { |
| 103 ASSERT_TRUE(test_cases[i].content != NULL); | 103 ASSERT_TRUE(test_cases[i].content != NULL); |
| 104 int len = strlen(test_cases[i].content); | 104 int len = strlen(test_cases[i].content); |
| 105 ASSERT_EQ(len, file_util::WriteFile(path, test_cases[i].content, len)); | 105 ASSERT_EQ(len, base::WriteFile(path, test_cases[i].content, len)); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace | 110 } // namespace |
| 111 | 111 |
| 112 class NativeMediaFileUtilTest : public testing::Test { | 112 class NativeMediaFileUtilTest : public testing::Test { |
| 113 public: | 113 public: |
| 114 NativeMediaFileUtilTest() | 114 NativeMediaFileUtilTest() |
| 115 : io_thread_(content::BrowserThread::IO, &message_loop_) { | 115 : io_thread_(content::BrowserThread::IO, &message_loop_) { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 ASSERT_TRUE(base::CreateDirectory(root_path())); | 323 ASSERT_TRUE(base::CreateDirectory(root_path())); |
| 324 PopulateDirectoryWithTestCases(root_path(), | 324 PopulateDirectoryWithTestCases(root_path(), |
| 325 kFilteringTestCases, | 325 kFilteringTestCases, |
| 326 arraysize(kFilteringTestCases)); | 326 arraysize(kFilteringTestCases)); |
| 327 } | 327 } |
| 328 | 328 |
| 329 // Always create a dummy source data file. | 329 // Always create a dummy source data file. |
| 330 base::FilePath src_path = root_path().AppendASCII("foo.jpg"); | 330 base::FilePath src_path = root_path().AppendASCII("foo.jpg"); |
| 331 FileSystemURL src_url = CreateURL(FPL("foo.jpg")); | 331 FileSystemURL src_url = CreateURL(FPL("foo.jpg")); |
| 332 static const char kDummyData[] = "dummy"; | 332 static const char kDummyData[] = "dummy"; |
| 333 ASSERT_TRUE(file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); | 333 ASSERT_TRUE(base::WriteFile(src_path, kDummyData, strlen(kDummyData))); |
| 334 | 334 |
| 335 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 335 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
| 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 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 // These directories do not exist in this case, so Copy() will not | 434 // These directories do not exist in this case, so Copy() will not |
| 435 // treat them as directories. Thus invalidating these test cases. | 435 // treat them as directories. Thus invalidating these test cases. |
| 436 continue; | 436 continue; |
| 437 } | 437 } |
| 438 | 438 |
| 439 // Create the source file for every test case because it might get moved. | 439 // Create the source file for every test case because it might get moved. |
| 440 base::FilePath src_path = root_path().AppendASCII("foo.jpg"); | 440 base::FilePath src_path = root_path().AppendASCII("foo.jpg"); |
| 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 base::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::File::Error 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. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 expected_error = base::File::FILE_OK; | 563 expected_error = base::File::FILE_OK; |
| 564 else | 564 else |
| 565 expected_error = base::File::FILE_ERROR_SECURITY; | 565 expected_error = base::File::FILE_ERROR_SECURITY; |
| 566 error = base::File::FILE_ERROR_FAILED; | 566 error = base::File::FILE_ERROR_FAILED; |
| 567 operation_runner()->CreateSnapshotFile(url, | 567 operation_runner()->CreateSnapshotFile(url, |
| 568 base::Bind(CreateSnapshotCallback, &error)); | 568 base::Bind(CreateSnapshotCallback, &error)); |
| 569 base::MessageLoop::current()->RunUntilIdle(); | 569 base::MessageLoop::current()->RunUntilIdle(); |
| 570 ASSERT_EQ(expected_error, error); | 570 ASSERT_EQ(expected_error, error); |
| 571 } | 571 } |
| 572 } | 572 } |
| OLD | NEW |