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

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

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 // If there are files on the file system, a unique reservation should uniquify 275 // If there are files on the file system, a unique reservation should uniquify
276 // around it. 276 // around it.
277 TEST_F(DownloadPathReservationTrackerTest, ConflictingFiles) { 277 TEST_F(DownloadPathReservationTrackerTest, ConflictingFiles) {
278 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1)); 278 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1));
279 base::FilePath path( 279 base::FilePath path(
280 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo.txt"))); 280 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo.txt")));
281 base::FilePath path1( 281 base::FilePath path1(
282 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo (1).txt"))); 282 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo (1).txt")));
283 // Create a file at |path|, and a .crdownload file at |path1|. 283 // Create a file at |path|, and a .crdownload file at |path1|.
284 ASSERT_EQ(0, file_util::WriteFile(path, "", 0)); 284 ASSERT_EQ(0, base::WriteFile(path, "", 0));
285 ASSERT_EQ(0, 285 ASSERT_EQ(0,
286 file_util::WriteFile( 286 base::WriteFile(
287 DownloadTargetDeterminer::GetCrDownloadPath(path1), "", 0)); 287 DownloadTargetDeterminer::GetCrDownloadPath(path1), "", 0));
288 ASSERT_TRUE(IsPathInUse(path)); 288 ASSERT_TRUE(IsPathInUse(path));
289 289
290 base::FilePath reserved_path; 290 base::FilePath reserved_path;
291 bool verified = false; 291 bool verified = false;
292 bool create_directory = false; 292 bool create_directory = false;
293 DownloadPathReservationTracker::FilenameConflictAction conflict_action = 293 DownloadPathReservationTracker::FilenameConflictAction conflict_action =
294 DownloadPathReservationTracker::UNIQUIFY; 294 DownloadPathReservationTracker::UNIQUIFY;
295 CallGetReservedPath( 295 CallGetReservedPath(
296 item.get(), 296 item.get(),
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
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")));
644 base::FilePath path2(GetLongNamePathInDownloadsDirectory( 644 base::FilePath path2(GetLongNamePathInDownloadsDirectory(
645 max_length - 8, FILE_PATH_LITERAL(" (2).txt"))); 645 max_length - 8, FILE_PATH_LITERAL(" (2).txt")));
646 ASSERT_FALSE(IsPathInUse(path)); 646 ASSERT_FALSE(IsPathInUse(path));
647 // "aaa...aaaaaaa.txt" (truncated path) and 647 // "aaa...aaaaaaa.txt" (truncated path) and
648 // "aaa...aaa (1).txt" (truncated and first uniquification try) exists. 648 // "aaa...aaa (1).txt" (truncated and first uniquification try) exists.
649 // "aaa...aaa (2).txt" should be used. 649 // "aaa...aaa (2).txt" should be used.
650 ASSERT_EQ(0, file_util::WriteFile(path0, "", 0)); 650 ASSERT_EQ(0, base::WriteFile(path0, "", 0));
651 ASSERT_EQ(0, file_util::WriteFile(path1, "", 0)); 651 ASSERT_EQ(0, base::WriteFile(path1, "", 0));
652 652
653 base::FilePath reserved_path; 653 base::FilePath reserved_path;
654 bool verified = false; 654 bool verified = false;
655 DownloadPathReservationTracker::FilenameConflictAction conflict_action = 655 DownloadPathReservationTracker::FilenameConflictAction conflict_action =
656 DownloadPathReservationTracker::UNIQUIFY; 656 DownloadPathReservationTracker::UNIQUIFY;
657 bool create_directory = false; 657 bool create_directory = false;
658 CallGetReservedPath( 658 CallGetReservedPath(
659 item.get(), 659 item.get(),
660 path, 660 path,
661 create_directory, 661 create_directory,
(...skipping 29 matching lines...) Expand all
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

Powered by Google App Engine
This is Rietveld 408576698