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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 181
182 fileapi::FileSystemType type() { 182 fileapi::FileSystemType type() {
183 return fileapi::kFileSystemTypeNativeMedia; 183 return fileapi::kFileSystemTypeNativeMedia;
184 } 184 }
185 185
186 FileSystemOperation* NewOperation(const FileSystemURL& url) { 186 FileSystemOperation* NewOperation(const FileSystemURL& url) {
187 return file_system_context_->CreateFileSystemOperation(url, NULL); 187 return file_system_context_->CreateFileSystemOperation(url, NULL);
188 } 188 }
189 189
190 private: 190 private:
191 MessageLoop message_loop_; 191 base::MessageLoop message_loop_;
192 192
193 base::ScopedTempDir data_dir_; 193 base::ScopedTempDir data_dir_;
194 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 194 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
195 195
196 fileapi::FileSystemFileUtil* file_util_; 196 fileapi::FileSystemFileUtil* file_util_;
197 std::string filesystem_id_; 197 std::string filesystem_id_;
198 198
199 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest); 199 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest);
200 }; 200 };
201 201
(...skipping 13 matching lines...) Expand all
215 215
216 std::string test_name = 216 std::string test_name =
217 base::StringPrintf("DirectoryExistsAndFileExistsFiltering %" PRIuS, i); 217 base::StringPrintf("DirectoryExistsAndFileExistsFiltering %" PRIuS, i);
218 if (kFilteringTestCases[i].is_directory) { 218 if (kFilteringTestCases[i].is_directory) {
219 operation->DirectoryExists( 219 operation->DirectoryExists(
220 url, base::Bind(&ExpectEqHelper, test_name, expectation)); 220 url, base::Bind(&ExpectEqHelper, test_name, expectation));
221 } else { 221 } else {
222 operation->FileExists( 222 operation->FileExists(
223 url, base::Bind(&ExpectEqHelper, test_name, expectation)); 223 url, base::Bind(&ExpectEqHelper, test_name, expectation));
224 } 224 }
225 MessageLoop::current()->RunUntilIdle(); 225 base::MessageLoop::current()->RunUntilIdle();
226 } 226 }
227 } 227 }
228 228
229 TEST_F(NativeMediaFileUtilTest, ReadDirectoryFiltering) { 229 TEST_F(NativeMediaFileUtilTest, ReadDirectoryFiltering) {
230 PopulateDirectoryWithTestCases(root_path(), 230 PopulateDirectoryWithTestCases(root_path(),
231 kFilteringTestCases, 231 kFilteringTestCases,
232 arraysize(kFilteringTestCases)); 232 arraysize(kFilteringTestCases));
233 233
234 std::set<base::FilePath::StringType> content; 234 std::set<base::FilePath::StringType> content;
235 FileSystemURL url = CreateURL(FPL("")); 235 FileSystemURL url = CreateURL(FPL(""));
236 bool completed = false; 236 bool completed = false;
237 NewOperation(url)->ReadDirectory( 237 NewOperation(url)->ReadDirectory(
238 url, base::Bind(&DidReadDirectory, &content, &completed)); 238 url, base::Bind(&DidReadDirectory, &content, &completed));
239 MessageLoop::current()->RunUntilIdle(); 239 base::MessageLoop::current()->RunUntilIdle();
240 EXPECT_TRUE(completed); 240 EXPECT_TRUE(completed);
241 EXPECT_EQ(5u, content.size()); 241 EXPECT_EQ(5u, content.size());
242 242
243 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { 243 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) {
244 base::FilePath::StringType name = 244 base::FilePath::StringType name =
245 base::FilePath(kFilteringTestCases[i].path).BaseName().value(); 245 base::FilePath(kFilteringTestCases[i].path).BaseName().value();
246 std::set<base::FilePath::StringType>::const_iterator found = 246 std::set<base::FilePath::StringType>::const_iterator found =
247 content.find(name); 247 content.find(name);
248 EXPECT_EQ(kFilteringTestCases[i].visible, found != content.end()); 248 EXPECT_EQ(kFilteringTestCases[i].visible, found != content.end());
249 } 249 }
(...skipping 17 matching lines...) Expand all
267 base::PLATFORM_FILE_OK : 267 base::PLATFORM_FILE_OK :
268 base::PLATFORM_FILE_ERROR_SECURITY; 268 base::PLATFORM_FILE_ERROR_SECURITY;
269 if (kFilteringTestCases[i].is_directory) { 269 if (kFilteringTestCases[i].is_directory) {
270 operation->CreateDirectory( 270 operation->CreateDirectory(
271 url, false, false, 271 url, false, false,
272 base::Bind(&ExpectEqHelper, test_name, expectation)); 272 base::Bind(&ExpectEqHelper, test_name, expectation));
273 } else { 273 } else {
274 operation->CreateFile( 274 operation->CreateFile(
275 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); 275 url, false, base::Bind(&ExpectEqHelper, test_name, expectation));
276 } 276 }
277 MessageLoop::current()->RunUntilIdle(); 277 base::MessageLoop::current()->RunUntilIdle();
278 } 278 }
279 } 279 }
280 } 280 }
281 281
282 TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) { 282 TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) {
283 base::FilePath dest_path = root_path().AppendASCII("dest"); 283 base::FilePath dest_path = root_path().AppendASCII("dest");
284 FileSystemURL dest_url = CreateURL(FPL("dest")); 284 FileSystemURL dest_url = CreateURL(FPL("dest"));
285 285
286 // Run the loop twice. The first run has no source files. The second run does. 286 // Run the loop twice. The first run has no source files. The second run does.
287 for (int loop_count = 0; loop_count < 2; ++loop_count) { 287 for (int loop_count = 0; loop_count < 2; ++loop_count) {
(...skipping 18 matching lines...) Expand all
306 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; 306 base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
307 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 307 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
308 // If the source does not exist or is not visible. 308 // If the source does not exist or is not visible.
309 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; 309 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND;
310 } else if (!kFilteringTestCases[i].is_directory) { 310 } else if (!kFilteringTestCases[i].is_directory) {
311 // Cannot copy a visible file to a directory. 311 // Cannot copy a visible file to a directory.
312 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 312 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
313 } 313 }
314 operation->Copy( 314 operation->Copy(
315 url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); 315 url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation));
316 MessageLoop::current()->RunUntilIdle(); 316 base::MessageLoop::current()->RunUntilIdle();
317 } 317 }
318 } 318 }
319 } 319 }
320 320
321 TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) { 321 TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) {
322 // Run the loop twice. The first run has no destination files. 322 // Run the loop twice. The first run has no destination files.
323 // The second run does. 323 // The second run does.
324 for (int loop_count = 0; loop_count < 2; ++loop_count) { 324 for (int loop_count = 0; loop_count < 2; ++loop_count) {
325 if (loop_count == 1) { 325 if (loop_count == 1) {
326 // Reset the test directory between the two loops to remove old 326 // Reset the test directory between the two loops to remove old
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } else if (kFilteringTestCases[i].is_directory) { 372 } else if (kFilteringTestCases[i].is_directory) {
373 // Cannot copy a file to a directory. 373 // Cannot copy a file to a directory.
374 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 374 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
375 } else { 375 } else {
376 // Copying from a file to a visible file that exists is ok. 376 // Copying from a file to a visible file that exists is ok.
377 expectation = base::PLATFORM_FILE_OK; 377 expectation = base::PLATFORM_FILE_OK;
378 } 378 }
379 } 379 }
380 operation->Copy( 380 operation->Copy(
381 src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); 381 src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation));
382 MessageLoop::current()->RunUntilIdle(); 382 base::MessageLoop::current()->RunUntilIdle();
383 } 383 }
384 } 384 }
385 } 385 }
386 386
387 TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) { 387 TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) {
388 base::FilePath dest_path = root_path().AppendASCII("dest"); 388 base::FilePath dest_path = root_path().AppendASCII("dest");
389 FileSystemURL dest_url = CreateURL(FPL("dest")); 389 FileSystemURL dest_url = CreateURL(FPL("dest"));
390 390
391 // Run the loop twice. The first run has no source files. The second run does. 391 // Run the loop twice. The first run has no source files. The second run does.
392 for (int loop_count = 0; loop_count < 2; ++loop_count) { 392 for (int loop_count = 0; loop_count < 2; ++loop_count) {
(...skipping 18 matching lines...) Expand all
411 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; 411 base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
412 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 412 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
413 // If the source does not exist or is not visible. 413 // If the source does not exist or is not visible.
414 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; 414 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND;
415 } else if (!kFilteringTestCases[i].is_directory) { 415 } else if (!kFilteringTestCases[i].is_directory) {
416 // Cannot move a visible file to a directory. 416 // Cannot move a visible file to a directory.
417 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 417 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
418 } 418 }
419 operation->Move( 419 operation->Move(
420 url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); 420 url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation));
421 MessageLoop::current()->RunUntilIdle(); 421 base::MessageLoop::current()->RunUntilIdle();
422 } 422 }
423 } 423 }
424 } 424 }
425 425
426 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) { 426 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) {
427 // Run the loop twice. The first run has no destination files. 427 // Run the loop twice. The first run has no destination files.
428 // The second run does. 428 // The second run does.
429 for (int loop_count = 0; loop_count < 2; ++loop_count) { 429 for (int loop_count = 0; loop_count < 2; ++loop_count) {
430 if (loop_count == 1) { 430 if (loop_count == 1) {
431 // Reset the test directory between the two loops to remove old 431 // Reset the test directory between the two loops to remove old
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } else if (kFilteringTestCases[i].is_directory) { 479 } else if (kFilteringTestCases[i].is_directory) {
480 // Cannot move a file to a directory. 480 // Cannot move a file to a directory.
481 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 481 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
482 } else { 482 } else {
483 // Moving from a file to a visible file that exists is ok. 483 // Moving from a file to a visible file that exists is ok.
484 expectation = base::PLATFORM_FILE_OK; 484 expectation = base::PLATFORM_FILE_OK;
485 } 485 }
486 } 486 }
487 operation->Move( 487 operation->Move(
488 src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); 488 src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation));
489 MessageLoop::current()->RunUntilIdle(); 489 base::MessageLoop::current()->RunUntilIdle();
490 } 490 }
491 } 491 }
492 } 492 }
493 493
494 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { 494 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) {
495 // Run the loop twice. The first run has no files. The second run does. 495 // Run the loop twice. The first run has no files. The second run does.
496 for (int loop_count = 0; loop_count < 2; ++loop_count) { 496 for (int loop_count = 0; loop_count < 2; ++loop_count) {
497 if (loop_count == 1) { 497 if (loop_count == 1) {
498 PopulateDirectoryWithTestCases(root_path(), 498 PopulateDirectoryWithTestCases(root_path(),
499 kFilteringTestCases, 499 kFilteringTestCases,
(...skipping 10 matching lines...) Expand all
510 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; 510 base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
511 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 511 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
512 // Cannot get metadata from files that do not exist or are not visible. 512 // Cannot get metadata from files that do not exist or are not visible.
513 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; 513 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND;
514 } 514 }
515 operation->GetMetadata(url, 515 operation->GetMetadata(url,
516 base::Bind(&ExpectMetadataEqHelper, 516 base::Bind(&ExpectMetadataEqHelper,
517 test_name, 517 test_name,
518 expectation, 518 expectation,
519 kFilteringTestCases[i].is_directory)); 519 kFilteringTestCases[i].is_directory));
520 MessageLoop::current()->RunUntilIdle(); 520 base::MessageLoop::current()->RunUntilIdle();
521 } 521 }
522 } 522 }
523 } 523 }
524 524
525 TEST_F(NativeMediaFileUtilTest, RemoveFiltering) { 525 TEST_F(NativeMediaFileUtilTest, RemoveFiltering) {
526 // Run the loop twice. The first run has no files. The second run does. 526 // Run the loop twice. The first run has no files. The second run does.
527 for (int loop_count = 0; loop_count < 2; ++loop_count) { 527 for (int loop_count = 0; loop_count < 2; ++loop_count) {
528 if (loop_count == 1) { 528 if (loop_count == 1) {
529 PopulateDirectoryWithTestCases(root_path(), 529 PopulateDirectoryWithTestCases(root_path(),
530 kFilteringTestCases, 530 kFilteringTestCases,
531 arraysize(kFilteringTestCases)); 531 arraysize(kFilteringTestCases));
532 } 532 }
533 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { 533 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) {
534 FileSystemURL root_url = CreateURL(FPL("")); 534 FileSystemURL root_url = CreateURL(FPL(""));
535 FileSystemOperation* operation = NewOperation(root_url); 535 FileSystemOperation* operation = NewOperation(root_url);
536 536
537 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); 537 FileSystemURL url = CreateURL(kFilteringTestCases[i].path);
538 538
539 std::string test_name = base::StringPrintf( 539 std::string test_name = base::StringPrintf(
540 "RemoveFiltering run %d test %" PRIuS, loop_count, i); 540 "RemoveFiltering run %d test %" PRIuS, loop_count, i);
541 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; 541 base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
542 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 542 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
543 // Cannot remove files that do not exist or are not visible. 543 // Cannot remove files that do not exist or are not visible.
544 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; 544 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND;
545 } 545 }
546 operation->Remove( 546 operation->Remove(
547 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); 547 url, false, base::Bind(&ExpectEqHelper, test_name, expectation));
548 MessageLoop::current()->RunUntilIdle(); 548 base::MessageLoop::current()->RunUntilIdle();
549 } 549 }
550 } 550 }
551 } 551 }
552 552
553 TEST_F(NativeMediaFileUtilTest, TruncateFiltering) { 553 TEST_F(NativeMediaFileUtilTest, TruncateFiltering) {
554 // Run the loop twice. The first run has no files. The second run does. 554 // Run the loop twice. The first run has no files. The second run does.
555 for (int loop_count = 0; loop_count < 2; ++loop_count) { 555 for (int loop_count = 0; loop_count < 2; ++loop_count) {
556 if (loop_count == 1) { 556 if (loop_count == 1) {
557 PopulateDirectoryWithTestCases(root_path(), 557 PopulateDirectoryWithTestCases(root_path(),
558 kFilteringTestCases, 558 kFilteringTestCases,
(...skipping 10 matching lines...) Expand all
569 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; 569 base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
570 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 570 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
571 // Cannot truncate files that do not exist or are not visible. 571 // Cannot truncate files that do not exist or are not visible.
572 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; 572 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND;
573 } else if (kFilteringTestCases[i].is_directory) { 573 } else if (kFilteringTestCases[i].is_directory) {
574 // Cannot truncate directories. 574 // Cannot truncate directories.
575 expectation = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; 575 expectation = base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
576 } 576 }
577 operation->Truncate( 577 operation->Truncate(
578 url, 0, base::Bind(&ExpectEqHelper, test_name, expectation)); 578 url, 0, base::Bind(&ExpectEqHelper, test_name, expectation));
579 MessageLoop::current()->RunUntilIdle(); 579 base::MessageLoop::current()->RunUntilIdle();
580 } 580 }
581 } 581 }
582 } 582 }
583 583
584 TEST_F(NativeMediaFileUtilTest, TouchFileFiltering) { 584 TEST_F(NativeMediaFileUtilTest, TouchFileFiltering) {
585 base::Time time = base::Time::Now(); 585 base::Time time = base::Time::Now();
586 586
587 // Run the loop twice. The first run has no files. The second run does. 587 // Run the loop twice. The first run has no files. The second run does.
588 for (int loop_count = 0; loop_count < 2; ++loop_count) { 588 for (int loop_count = 0; loop_count < 2; ++loop_count) {
589 if (loop_count == 1) { 589 if (loop_count == 1) {
590 PopulateDirectoryWithTestCases(root_path(), 590 PopulateDirectoryWithTestCases(root_path(),
591 kFilteringTestCases, 591 kFilteringTestCases,
592 arraysize(kFilteringTestCases)); 592 arraysize(kFilteringTestCases));
593 } 593 }
594 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { 594 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) {
595 FileSystemURL root_url = CreateURL(FPL("")); 595 FileSystemURL root_url = CreateURL(FPL(""));
596 FileSystemOperation* operation = NewOperation(root_url); 596 FileSystemOperation* operation = NewOperation(root_url);
597 597
598 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); 598 FileSystemURL url = CreateURL(kFilteringTestCases[i].path);
599 599
600 std::string test_name = base::StringPrintf( 600 std::string test_name = base::StringPrintf(
601 "TouchFileFiltering run %d test %" PRIuS, loop_count, i); 601 "TouchFileFiltering run %d test %" PRIuS, loop_count, i);
602 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; 602 base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
603 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 603 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
604 // Files do not exists. Touch fails. 604 // Files do not exists. Touch fails.
605 expectation = base::PLATFORM_FILE_ERROR_FAILED; 605 expectation = base::PLATFORM_FILE_ERROR_FAILED;
606 } 606 }
607 operation->TouchFile( 607 operation->TouchFile(
608 url, time, time, base::Bind(&ExpectEqHelper, test_name, expectation)); 608 url, time, time, base::Bind(&ExpectEqHelper, test_name, expectation));
609 MessageLoop::current()->RunUntilIdle(); 609 base::MessageLoop::current()->RunUntilIdle();
610 } 610 }
611 } 611 }
612 } 612 }
613 613
614 } // namespace chrome 614 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698