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

Side by Side Diff: chrome/browser/download/download_path_reservation_tracker_unittest.cc

Issue 189333004: Move more file_util functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 message_loop_.RunUntilIdle(); 588 message_loop_.RunUntilIdle();
589 EXPECT_FALSE(IsPathInUse(new_target_path)); 589 EXPECT_FALSE(IsPathInUse(new_target_path));
590 } 590 }
591 591
592 // Tests for long name truncation. On other platforms automatic truncation 592 // Tests for long name truncation. On other platforms automatic truncation
593 // is not performed (yet). 593 // is not performed (yet).
594 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 594 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
595 595
596 TEST_F(DownloadPathReservationTrackerTest, BasicTruncation) { 596 TEST_F(DownloadPathReservationTrackerTest, BasicTruncation) {
597 int real_max_length = 597 int real_max_length =
598 file_util::GetMaximumPathComponentLength(default_download_path()); 598 base::GetMaximumPathComponentLength(default_download_path());
599 ASSERT_NE(-1, real_max_length); 599 ASSERT_NE(-1, real_max_length);
600 600
601 // TODO(kinaba): the current implementation leaves spaces for appending 601 // TODO(kinaba): the current implementation leaves spaces for appending
602 // ".crdownload". So take it into account. Should be removed in the future. 602 // ".crdownload". So take it into account. Should be removed in the future.
603 const size_t max_length = real_max_length - 11; 603 const size_t max_length = real_max_length - 11;
604 604
605 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1)); 605 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1));
606 base::FilePath path(GetLongNamePathInDownloadsDirectory( 606 base::FilePath path(GetLongNamePathInDownloadsDirectory(
607 max_length, FILE_PATH_LITERAL(".txt"))); 607 max_length, FILE_PATH_LITERAL(".txt")));
608 ASSERT_FALSE(IsPathInUse(path)); 608 ASSERT_FALSE(IsPathInUse(path));
(...skipping 14 matching lines...) Expand all
623 EXPECT_TRUE(verified); 623 EXPECT_TRUE(verified);
624 // The file name length is truncated to max_length. 624 // The file name length is truncated to max_length.
625 EXPECT_EQ(max_length, reserved_path.BaseName().value().size()); 625 EXPECT_EQ(max_length, reserved_path.BaseName().value().size());
626 // But the extension is kept unchanged. 626 // But the extension is kept unchanged.
627 EXPECT_EQ(path.Extension(), reserved_path.Extension()); 627 EXPECT_EQ(path.Extension(), reserved_path.Extension());
628 item->SetState(DownloadItem::COMPLETE); 628 item->SetState(DownloadItem::COMPLETE);
629 } 629 }
630 630
631 TEST_F(DownloadPathReservationTrackerTest, TruncationConflict) { 631 TEST_F(DownloadPathReservationTrackerTest, TruncationConflict) {
632 int real_max_length = 632 int real_max_length =
633 file_util::GetMaximumPathComponentLength(default_download_path()); 633 base::GetMaximumPathComponentLength(default_download_path());
634 ASSERT_NE(-1, real_max_length); 634 ASSERT_NE(-1, real_max_length);
635 const size_t max_length = real_max_length - 11; 635 const size_t max_length = real_max_length - 11;
636 636
637 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1)); 637 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1));
638 base::FilePath path(GetLongNamePathInDownloadsDirectory( 638 base::FilePath path(GetLongNamePathInDownloadsDirectory(
639 max_length, FILE_PATH_LITERAL(".txt"))); 639 max_length, FILE_PATH_LITERAL(".txt")));
640 base::FilePath path0(GetLongNamePathInDownloadsDirectory( 640 base::FilePath path0(GetLongNamePathInDownloadsDirectory(
641 max_length - 4, FILE_PATH_LITERAL(".txt"))); 641 max_length - 4, FILE_PATH_LITERAL(".txt")));
642 base::FilePath path1(GetLongNamePathInDownloadsDirectory( 642 base::FilePath path1(GetLongNamePathInDownloadsDirectory(
643 max_length - 8, FILE_PATH_LITERAL(" (1).txt"))); 643 max_length - 8, FILE_PATH_LITERAL(" (1).txt")));
(...skipping 19 matching lines...) Expand all
663 &reserved_path, 663 &reserved_path,
664 &verified); 664 &verified);
665 EXPECT_TRUE(IsPathInUse(reserved_path)); 665 EXPECT_TRUE(IsPathInUse(reserved_path));
666 EXPECT_TRUE(verified); 666 EXPECT_TRUE(verified);
667 EXPECT_EQ(path2, reserved_path); 667 EXPECT_EQ(path2, reserved_path);
668 item->SetState(DownloadItem::COMPLETE); 668 item->SetState(DownloadItem::COMPLETE);
669 } 669 }
670 670
671 TEST_F(DownloadPathReservationTrackerTest, TruncationFail) { 671 TEST_F(DownloadPathReservationTrackerTest, TruncationFail) {
672 int real_max_length = 672 int real_max_length =
673 file_util::GetMaximumPathComponentLength(default_download_path()); 673 base::GetMaximumPathComponentLength(default_download_path());
674 ASSERT_NE(-1, real_max_length); 674 ASSERT_NE(-1, real_max_length);
675 const size_t max_length = real_max_length - 11; 675 const size_t max_length = real_max_length - 11;
676 676
677 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1)); 677 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1));
678 base::FilePath path(GetPathInDownloadsDirectory( 678 base::FilePath path(GetPathInDownloadsDirectory(
679 (FILE_PATH_LITERAL("a.") + 679 (FILE_PATH_LITERAL("a.") +
680 base::FilePath::StringType(max_length, 'b')).c_str())); 680 base::FilePath::StringType(max_length, 'b')).c_str()));
681 ASSERT_FALSE(IsPathInUse(path)); 681 ASSERT_FALSE(IsPathInUse(path));
682 682
683 base::FilePath reserved_path; 683 base::FilePath reserved_path;
684 bool verified = false; 684 bool verified = false;
685 DownloadPathReservationTracker::FilenameConflictAction conflict_action = 685 DownloadPathReservationTracker::FilenameConflictAction conflict_action =
686 DownloadPathReservationTracker::OVERWRITE; 686 DownloadPathReservationTracker::OVERWRITE;
687 bool create_directory = false; 687 bool create_directory = false;
688 CallGetReservedPath( 688 CallGetReservedPath(
689 item.get(), 689 item.get(),
690 path, 690 path,
691 create_directory, 691 create_directory,
692 conflict_action, 692 conflict_action,
693 &reserved_path, 693 &reserved_path,
694 &verified); 694 &verified);
695 // We cannot truncate a path with very long extension. 695 // We cannot truncate a path with very long extension.
696 EXPECT_FALSE(verified); 696 EXPECT_FALSE(verified);
697 item->SetState(DownloadItem::COMPLETE); 697 item->SetState(DownloadItem::COMPLETE);
698 } 698 }
699 699
700 #endif 700 #endif
OLDNEW
« no previous file with comments | « chrome/browser/download/download_path_reservation_tracker.cc ('k') | chrome/browser/extensions/external_pref_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698