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

Side by Side Diff: chrome/browser/media_galleries/fileapi/native_media_file_util_unittest.cc

Issue 100573002: Move directory creation functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 #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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
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(file_util::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, file_util::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_) {
116 } 116 }
117 117
118 virtual void SetUp() { 118 virtual void SetUp() {
119 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 119 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
120 ASSERT_TRUE(file_util::CreateDirectory(root_path())); 120 ASSERT_TRUE(base::CreateDirectory(root_path()));
121 121
122 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = 122 scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
123 new quota::MockSpecialStoragePolicy(); 123 new quota::MockSpecialStoragePolicy();
124 124
125 ScopedVector<fileapi::FileSystemBackend> additional_providers; 125 ScopedVector<fileapi::FileSystemBackend> additional_providers;
126 additional_providers.push_back(new MediaFileSystemBackend( 126 additional_providers.push_back(new MediaFileSystemBackend(
127 data_dir_.path(), base::MessageLoopProxy::current().get())); 127 data_dir_.path(), base::MessageLoopProxy::current().get()));
128 128
129 file_system_context_ = new fileapi::FileSystemContext( 129 file_system_context_ = new fileapi::FileSystemContext(
130 base::MessageLoopProxy::current().get(), 130 base::MessageLoopProxy::current().get(),
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 for (int loop_count = 0; loop_count < 2; ++loop_count) { 280 for (int loop_count = 0; loop_count < 2; ++loop_count) {
281 if (loop_count == 1) { 281 if (loop_count == 1) {
282 PopulateDirectoryWithTestCases(root_path(), 282 PopulateDirectoryWithTestCases(root_path(),
283 kFilteringTestCases, 283 kFilteringTestCases,
284 arraysize(kFilteringTestCases)); 284 arraysize(kFilteringTestCases));
285 } 285 }
286 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { 286 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) {
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(file_util::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::PlatformFileError expectation = base::PLATFORM_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::PLATFORM_FILE_ERROR_NOT_FOUND;
(...skipping 12 matching lines...) Expand all
313 } 313 }
314 314
315 TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) { 315 TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) {
316 // Run the loop twice. The first run has no destination files. 316 // Run the loop twice. The first run has no destination files.
317 // The second run does. 317 // The second run does.
318 for (int loop_count = 0; loop_count < 2; ++loop_count) { 318 for (int loop_count = 0; loop_count < 2; ++loop_count) {
319 if (loop_count == 1) { 319 if (loop_count == 1) {
320 // Reset the test directory between the two loops to remove old 320 // Reset the test directory between the two loops to remove old
321 // directories and create new ones that should pre-exist. 321 // directories and create new ones that should pre-exist.
322 ASSERT_TRUE(base::DeleteFile(root_path(), true)); 322 ASSERT_TRUE(base::DeleteFile(root_path(), true));
323 ASSERT_TRUE(file_util::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(file_util::WriteFile(src_path, kDummyData, strlen(kDummyData)));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 for (int loop_count = 0; loop_count < 2; ++loop_count) { 385 for (int loop_count = 0; loop_count < 2; ++loop_count) {
386 if (loop_count == 1) { 386 if (loop_count == 1) {
387 PopulateDirectoryWithTestCases(root_path(), 387 PopulateDirectoryWithTestCases(root_path(),
388 kFilteringTestCases, 388 kFilteringTestCases,
389 arraysize(kFilteringTestCases)); 389 arraysize(kFilteringTestCases));
390 } 390 }
391 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { 391 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) {
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(file_util::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::PlatformFileError expectation = base::PLATFORM_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::PLATFORM_FILE_ERROR_NOT_FOUND;
(...skipping 10 matching lines...) Expand all
416 } 416 }
417 417
418 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) { 418 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) {
419 // Run the loop twice. The first run has no destination files. 419 // Run the loop twice. The first run has no destination files.
420 // The second run does. 420 // The second run does.
421 for (int loop_count = 0; loop_count < 2; ++loop_count) { 421 for (int loop_count = 0; loop_count < 2; ++loop_count) {
422 if (loop_count == 1) { 422 if (loop_count == 1) {
423 // Reset the test directory between the two loops to remove old 423 // Reset the test directory between the two loops to remove old
424 // directories and create new ones that should pre-exist. 424 // directories and create new ones that should pre-exist.
425 ASSERT_TRUE(base::DeleteFile(root_path(), true)); 425 ASSERT_TRUE(base::DeleteFile(root_path(), true));
426 ASSERT_TRUE(file_util::CreateDirectory(root_path())); 426 ASSERT_TRUE(base::CreateDirectory(root_path()));
427 PopulateDirectoryWithTestCases(root_path(), 427 PopulateDirectoryWithTestCases(root_path(),
428 kFilteringTestCases, 428 kFilteringTestCases,
429 arraysize(kFilteringTestCases)); 429 arraysize(kFilteringTestCases));
430 } 430 }
431 431
432 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { 432 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) {
433 if (loop_count == 0 && kFilteringTestCases[i].is_directory) { 433 if (loop_count == 0 && kFilteringTestCases[i].is_directory) {
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;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 expected_error = base::PLATFORM_FILE_OK; 561 expected_error = base::PLATFORM_FILE_OK;
562 else 562 else
563 expected_error = base::PLATFORM_FILE_ERROR_SECURITY; 563 expected_error = base::PLATFORM_FILE_ERROR_SECURITY;
564 error = base::PLATFORM_FILE_ERROR_FAILED; 564 error = base::PLATFORM_FILE_ERROR_FAILED;
565 operation_runner()->CreateSnapshotFile(url, 565 operation_runner()->CreateSnapshotFile(url,
566 base::Bind(CreateSnapshotCallback, &error)); 566 base::Bind(CreateSnapshotCallback, &error));
567 base::MessageLoop::current()->RunUntilIdle(); 567 base::MessageLoop::current()->RunUntilIdle();
568 ASSERT_EQ(expected_error, error); 568 ASSERT_EQ(expected_error, error);
569 } 569 }
570 } 570 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698