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

Side by Side Diff: webkit/fileapi/media/native_media_file_util_unittest.cc

Issue 11960003: Cleanup: Move more recursive operation logic from FileUtilHelper to FileUtil (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months 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/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
11 #include "base/location.h"
11 #include "base/message_loop.h" 12 #include "base/message_loop.h"
12 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webkit/fileapi/file_system_context.h" 16 #include "webkit/fileapi/file_system_context.h"
16 #include "webkit/fileapi/file_system_operation.h" 17 #include "webkit/fileapi/file_system_operation.h"
17 #include "webkit/fileapi/file_system_task_runners.h" 18 #include "webkit/fileapi/file_system_task_runners.h"
18 #include "webkit/fileapi/isolated_context.h" 19 #include "webkit/fileapi/isolated_context.h"
19 #include "webkit/fileapi/media/native_media_file_util.h" 20 #include "webkit/fileapi/media/native_media_file_util.h"
20 #include "webkit/fileapi/mock_file_system_options.h" 21 #include "webkit/fileapi/mock_file_system_options.h"
(...skipping 21 matching lines...) Expand all
42 { FPL("piyo.txt"), true, true }, 43 { FPL("piyo.txt"), true, true },
43 { FPL("moga.cod"), true, true }, 44 { FPL("moga.cod"), true, true },
44 45
45 // File should be visible if it's a supported media file. 46 // File should be visible if it's a supported media file.
46 { FPL("foo"), false, false }, // File without extension. 47 { FPL("foo"), false, false }, // File without extension.
47 { FPL("bar.jpg"), false, true }, // Supported media file. 48 { FPL("bar.jpg"), false, true }, // Supported media file.
48 { FPL("baz.txt"), false, false }, // Non-media file. 49 { FPL("baz.txt"), false, false }, // Non-media file.
49 { FPL("foobar.cod"), false, false }, // Unsupported media file. 50 { FPL("foobar.cod"), false, false }, // Unsupported media file.
50 }; 51 };
51 52
52 void ExpectEqHelper(const std::string& test_name, 53 void ExpectEqHelper(const tracked_objects::Location& location,
54 const std::string& test_name,
53 base::PlatformFileError expected, 55 base::PlatformFileError expected,
54 base::PlatformFileError actual) { 56 base::PlatformFileError actual) {
55 EXPECT_EQ(expected, actual) << test_name; 57 EXPECT_EQ(expected, actual) << location.ToString() << ": " << test_name;
56 } 58 }
57 59
58 void ExpectMetadataEqHelper(const std::string& test_name, 60 void ExpectMetadataEqHelper(const std::string& test_name,
59 base::PlatformFileError expected, 61 base::PlatformFileError expected,
60 bool expected_is_directory, 62 bool expected_is_directory,
61 base::PlatformFileError actual, 63 base::PlatformFileError actual,
62 const base::PlatformFileInfo& file_info, 64 const base::PlatformFileInfo& file_info,
63 const FilePath& /*platform_path*/) { 65 const FilePath& /*platform_path*/) {
64 EXPECT_EQ(expected, actual) << test_name; 66 EXPECT_EQ(expected, actual) << test_name;
65 if (actual == base::PLATFORM_FILE_OK) 67 if (actual == base::PLATFORM_FILE_OK)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 185
184 base::PlatformFileError expectation = 186 base::PlatformFileError expectation =
185 kFilteringTestCases[i].visible ? 187 kFilteringTestCases[i].visible ?
186 base::PLATFORM_FILE_OK : 188 base::PLATFORM_FILE_OK :
187 base::PLATFORM_FILE_ERROR_NOT_FOUND; 189 base::PLATFORM_FILE_ERROR_NOT_FOUND;
188 190
189 std::string test_name = 191 std::string test_name =
190 base::StringPrintf("DirectoryExistsAndFileExistsFiltering %" PRIuS, i); 192 base::StringPrintf("DirectoryExistsAndFileExistsFiltering %" PRIuS, i);
191 if (kFilteringTestCases[i].is_directory) { 193 if (kFilteringTestCases[i].is_directory) {
192 operation->DirectoryExists( 194 operation->DirectoryExists(
193 url, base::Bind(&ExpectEqHelper, test_name, expectation)); 195 url, base::Bind(&ExpectEqHelper, FROM_HERE, test_name, expectation));
194 } else { 196 } else {
195 operation->FileExists( 197 operation->FileExists(
196 url, base::Bind(&ExpectEqHelper, test_name, expectation)); 198 url, base::Bind(&ExpectEqHelper, FROM_HERE, test_name, expectation));
197 } 199 }
198 MessageLoop::current()->RunUntilIdle(); 200 MessageLoop::current()->RunUntilIdle();
199 } 201 }
200 } 202 }
201 203
202 TEST_F(NativeMediaFileUtilTest, ReadDirectoryFiltering) { 204 TEST_F(NativeMediaFileUtilTest, ReadDirectoryFiltering) {
203 PopulateDirectoryWithTestCases(root_path(), 205 PopulateDirectoryWithTestCases(root_path(),
204 kFilteringTestCases, 206 kFilteringTestCases,
205 arraysize(kFilteringTestCases)); 207 arraysize(kFilteringTestCases));
206 208
(...skipping 28 matching lines...) Expand all
235 std::string test_name = base::StringPrintf( 237 std::string test_name = base::StringPrintf(
236 "CreateFileAndCreateDirectoryFiltering run %d, test %" PRIuS, 238 "CreateFileAndCreateDirectoryFiltering run %d, test %" PRIuS,
237 loop_count, i); 239 loop_count, i);
238 base::PlatformFileError expectation = 240 base::PlatformFileError expectation =
239 kFilteringTestCases[i].visible ? 241 kFilteringTestCases[i].visible ?
240 base::PLATFORM_FILE_OK : 242 base::PLATFORM_FILE_OK :
241 base::PLATFORM_FILE_ERROR_SECURITY; 243 base::PLATFORM_FILE_ERROR_SECURITY;
242 if (kFilteringTestCases[i].is_directory) { 244 if (kFilteringTestCases[i].is_directory) {
243 operation->CreateDirectory( 245 operation->CreateDirectory(
244 url, false, false, 246 url, false, false,
245 base::Bind(&ExpectEqHelper, test_name, expectation)); 247 base::Bind(&ExpectEqHelper, FROM_HERE, test_name, expectation));
246 } else { 248 } else {
247 operation->CreateFile( 249 operation->CreateFile(
248 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); 250 url, false, base::Bind(&ExpectEqHelper, FROM_HERE,
251 test_name, expectation));
249 } 252 }
250 MessageLoop::current()->RunUntilIdle(); 253 MessageLoop::current()->RunUntilIdle();
251 } 254 }
252 } 255 }
253 } 256 }
254 257
255 TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) { 258 TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) {
256 FilePath dest_path = root_path().AppendASCII("dest"); 259 FilePath dest_path = root_path().AppendASCII("dest");
257 FileSystemURL dest_url(origin(), type(), dest_path); 260 FileSystemURL dest_url(origin(), type(), dest_path);
258 261
(...skipping 20 matching lines...) Expand all
279 "CopySourceFiltering run %d test %" PRIuS, loop_count, i); 282 "CopySourceFiltering run %d test %" PRIuS, loop_count, i);
280 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; 283 base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
281 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 284 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
282 // If the source does not exist or is not visible. 285 // If the source does not exist or is not visible.
283 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; 286 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND;
284 } else if (!kFilteringTestCases[i].is_directory) { 287 } else if (!kFilteringTestCases[i].is_directory) {
285 // Cannot copy a visible file to a directory. 288 // Cannot copy a visible file to a directory.
286 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 289 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
287 } 290 }
288 operation->Copy( 291 operation->Copy(
289 url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); 292 url, dest_url, base::Bind(&ExpectEqHelper, FROM_HERE,
293 test_name, expectation));
290 MessageLoop::current()->RunUntilIdle(); 294 MessageLoop::current()->RunUntilIdle();
291 } 295 }
292 } 296 }
293 } 297 }
294 298
295 TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) { 299 TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) {
296 // Run the loop twice. The first run has no destination files. 300 // Run the loop twice. The first run has no destination files.
297 // The second run does. 301 // The second run does.
298 for (int loop_count = 0; loop_count < 2; ++loop_count) { 302 for (int loop_count = 0; loop_count < 2; ++loop_count) {
299 if (loop_count == 1) { 303 if (loop_count == 1) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 expectation = base::PLATFORM_FILE_ERROR_SECURITY; 345 expectation = base::PLATFORM_FILE_ERROR_SECURITY;
342 } else if (kFilteringTestCases[i].is_directory) { 346 } else if (kFilteringTestCases[i].is_directory) {
343 // Cannot copy a file to a directory. 347 // Cannot copy a file to a directory.
344 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 348 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
345 } else { 349 } else {
346 // Copying from a file to a visible file that exists is ok. 350 // Copying from a file to a visible file that exists is ok.
347 expectation = base::PLATFORM_FILE_OK; 351 expectation = base::PLATFORM_FILE_OK;
348 } 352 }
349 } 353 }
350 operation->Copy( 354 operation->Copy(
351 src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); 355 src_url, url, base::Bind(&ExpectEqHelper, FROM_HERE,
356 test_name, expectation));
352 MessageLoop::current()->RunUntilIdle(); 357 MessageLoop::current()->RunUntilIdle();
353 } 358 }
354 } 359 }
355 } 360 }
356 361
357 TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) { 362 TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) {
358 FilePath dest_path = root_path().AppendASCII("dest"); 363 FilePath dest_path = root_path().AppendASCII("dest");
359 FileSystemURL dest_url(origin(), type(), dest_path); 364 FileSystemURL dest_url(origin(), type(), dest_path);
360 365
361 // Run the loop twice. The first run has no source files. The second run does. 366 // Run the loop twice. The first run has no source files. The second run does.
(...skipping 19 matching lines...) Expand all
381 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i); 386 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i);
382 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; 387 base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
383 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 388 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
384 // If the source does not exist or is not visible. 389 // If the source does not exist or is not visible.
385 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; 390 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND;
386 } else if (!kFilteringTestCases[i].is_directory) { 391 } else if (!kFilteringTestCases[i].is_directory) {
387 // Cannot move a visible file to a directory. 392 // Cannot move a visible file to a directory.
388 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 393 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
389 } 394 }
390 operation->Move( 395 operation->Move(
391 url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); 396 url, dest_url, base::Bind(&ExpectEqHelper, FROM_HERE,
397 test_name, expectation));
392 MessageLoop::current()->RunUntilIdle(); 398 MessageLoop::current()->RunUntilIdle();
393 } 399 }
394 } 400 }
395 } 401 }
396 402
397 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) { 403 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) {
398 // Run the loop twice. The first run has no destination files. 404 // Run the loop twice. The first run has no destination files.
399 // The second run does. 405 // The second run does.
400 for (int loop_count = 0; loop_count < 2; ++loop_count) { 406 for (int loop_count = 0; loop_count < 2; ++loop_count) {
401 if (loop_count == 1) { 407 if (loop_count == 1) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 expectation = base::PLATFORM_FILE_ERROR_SECURITY; 450 expectation = base::PLATFORM_FILE_ERROR_SECURITY;
445 } else if (kFilteringTestCases[i].is_directory) { 451 } else if (kFilteringTestCases[i].is_directory) {
446 // Cannot move a file to a directory. 452 // Cannot move a file to a directory.
447 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 453 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
448 } else { 454 } else {
449 // Moving from a file to a visible file that exists is ok. 455 // Moving from a file to a visible file that exists is ok.
450 expectation = base::PLATFORM_FILE_OK; 456 expectation = base::PLATFORM_FILE_OK;
451 } 457 }
452 } 458 }
453 operation->Move( 459 operation->Move(
454 src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); 460 src_url, url, base::Bind(&ExpectEqHelper, FROM_HERE,
461 test_name, expectation));
455 MessageLoop::current()->RunUntilIdle(); 462 MessageLoop::current()->RunUntilIdle();
456 } 463 }
457 } 464 }
458 } 465 }
459 466
460 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { 467 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) {
461 // Run the loop twice. The first run has no files. The second run does. 468 // Run the loop twice. The first run has no files. The second run does.
462 for (int loop_count = 0; loop_count < 2; ++loop_count) { 469 for (int loop_count = 0; loop_count < 2; ++loop_count) {
463 if (loop_count == 1) { 470 if (loop_count == 1) {
464 PopulateDirectoryWithTestCases(root_path(), 471 PopulateDirectoryWithTestCases(root_path(),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 FileSystemURL url(origin(), type(), path); 512 FileSystemURL url(origin(), type(), path);
506 513
507 std::string test_name = base::StringPrintf( 514 std::string test_name = base::StringPrintf(
508 "RemoveFiltering run %d test %" PRIuS, loop_count, i); 515 "RemoveFiltering run %d test %" PRIuS, loop_count, i);
509 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; 516 base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
510 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 517 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
511 // Cannot remove files that do not exist or are not visible. 518 // Cannot remove files that do not exist or are not visible.
512 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; 519 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND;
513 } 520 }
514 operation->Remove( 521 operation->Remove(
515 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); 522 url, false, base::Bind(&ExpectEqHelper, FROM_HERE,
523 test_name, expectation));
516 MessageLoop::current()->RunUntilIdle(); 524 MessageLoop::current()->RunUntilIdle();
517 } 525 }
518 } 526 }
519 } 527 }
520 528
521 TEST_F(NativeMediaFileUtilTest, TruncateFiltering) { 529 TEST_F(NativeMediaFileUtilTest, TruncateFiltering) {
522 // Run the loop twice. The first run has no files. The second run does. 530 // Run the loop twice. The first run has no files. The second run does.
523 for (int loop_count = 0; loop_count < 2; ++loop_count) { 531 for (int loop_count = 0; loop_count < 2; ++loop_count) {
524 if (loop_count == 1) { 532 if (loop_count == 1) {
525 PopulateDirectoryWithTestCases(root_path(), 533 PopulateDirectoryWithTestCases(root_path(),
(...skipping 11 matching lines...) Expand all
537 "TruncateFiltering run %d test %" PRIuS, loop_count, i); 545 "TruncateFiltering run %d test %" PRIuS, loop_count, i);
538 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; 546 base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
539 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 547 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
540 // Cannot truncate files that do not exist or are not visible. 548 // Cannot truncate files that do not exist or are not visible.
541 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; 549 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND;
542 } else if (kFilteringTestCases[i].is_directory) { 550 } else if (kFilteringTestCases[i].is_directory) {
543 // Cannot truncate directories. 551 // Cannot truncate directories.
544 expectation = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; 552 expectation = base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
545 } 553 }
546 operation->Truncate( 554 operation->Truncate(
547 url, 0, base::Bind(&ExpectEqHelper, test_name, expectation)); 555 url, 0, base::Bind(&ExpectEqHelper, FROM_HERE,
556 test_name, expectation));
548 MessageLoop::current()->RunUntilIdle(); 557 MessageLoop::current()->RunUntilIdle();
549 } 558 }
550 } 559 }
551 } 560 }
552 561
553 TEST_F(NativeMediaFileUtilTest, TouchFileFiltering) { 562 TEST_F(NativeMediaFileUtilTest, TouchFileFiltering) {
554 base::Time time = base::Time::Now(); 563 base::Time time = base::Time::Now();
555 564
556 // Run the loop twice. The first run has no files. The second run does. 565 // Run the loop twice. The first run has no files. The second run does.
557 for (int loop_count = 0; loop_count < 2; ++loop_count) { 566 for (int loop_count = 0; loop_count < 2; ++loop_count) {
(...skipping 10 matching lines...) Expand all
568 FileSystemURL url(origin(), type(), path); 577 FileSystemURL url(origin(), type(), path);
569 578
570 std::string test_name = base::StringPrintf( 579 std::string test_name = base::StringPrintf(
571 "TouchFileFiltering run %d test %" PRIuS, loop_count, i); 580 "TouchFileFiltering run %d test %" PRIuS, loop_count, i);
572 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; 581 base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
573 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 582 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
574 // Files do not exists. Touch fails. 583 // Files do not exists. Touch fails.
575 expectation = base::PLATFORM_FILE_ERROR_FAILED; 584 expectation = base::PLATFORM_FILE_ERROR_FAILED;
576 } 585 }
577 operation->TouchFile( 586 operation->TouchFile(
578 url, time, time, base::Bind(&ExpectEqHelper, test_name, expectation)); 587 url, time, time, base::Bind(&ExpectEqHelper, FROM_HERE,
588 test_name, expectation));
579 MessageLoop::current()->RunUntilIdle(); 589 MessageLoop::current()->RunUntilIdle();
580 } 590 }
581 } 591 }
582 } 592 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698