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

Side by Side Diff: base/file_util_unittest.cc

Issue 18383003: Move DeleteAfterReboot and Move to base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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
« no previous file with comments | « base/file_util_posix.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 FilePath file_name_from = 1062 FilePath file_name_from =
1063 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); 1063 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt"));
1064 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); 1064 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
1065 ASSERT_TRUE(file_util::PathExists(file_name_from)); 1065 ASSERT_TRUE(file_util::PathExists(file_name_from));
1066 1066
1067 // The destination. 1067 // The destination.
1068 FilePath file_name_to = temp_dir_.path().Append( 1068 FilePath file_name_to = temp_dir_.path().Append(
1069 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); 1069 FILE_PATH_LITERAL("Move_Test_File_Destination.txt"));
1070 ASSERT_FALSE(file_util::PathExists(file_name_to)); 1070 ASSERT_FALSE(file_util::PathExists(file_name_to));
1071 1071
1072 EXPECT_TRUE(file_util::Move(file_name_from, file_name_to)); 1072 EXPECT_TRUE(base::Move(file_name_from, file_name_to));
1073 1073
1074 // Check everything has been moved. 1074 // Check everything has been moved.
1075 EXPECT_FALSE(file_util::PathExists(file_name_from)); 1075 EXPECT_FALSE(file_util::PathExists(file_name_from));
1076 EXPECT_TRUE(file_util::PathExists(file_name_to)); 1076 EXPECT_TRUE(file_util::PathExists(file_name_to));
1077 } 1077 }
1078 1078
1079 TEST_F(FileUtilTest, MoveFileExists) { 1079 TEST_F(FileUtilTest, MoveFileExists) {
1080 // Create a file 1080 // Create a file
1081 FilePath file_name_from = 1081 FilePath file_name_from =
1082 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); 1082 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt"));
1083 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); 1083 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
1084 ASSERT_TRUE(file_util::PathExists(file_name_from)); 1084 ASSERT_TRUE(file_util::PathExists(file_name_from));
1085 1085
1086 // The destination name. 1086 // The destination name.
1087 FilePath file_name_to = temp_dir_.path().Append( 1087 FilePath file_name_to = temp_dir_.path().Append(
1088 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); 1088 FILE_PATH_LITERAL("Move_Test_File_Destination.txt"));
1089 CreateTextFile(file_name_to, L"Old file content"); 1089 CreateTextFile(file_name_to, L"Old file content");
1090 ASSERT_TRUE(file_util::PathExists(file_name_to)); 1090 ASSERT_TRUE(file_util::PathExists(file_name_to));
1091 1091
1092 EXPECT_TRUE(file_util::Move(file_name_from, file_name_to)); 1092 EXPECT_TRUE(base::Move(file_name_from, file_name_to));
1093 1093
1094 // Check everything has been moved. 1094 // Check everything has been moved.
1095 EXPECT_FALSE(file_util::PathExists(file_name_from)); 1095 EXPECT_FALSE(file_util::PathExists(file_name_from));
1096 EXPECT_TRUE(file_util::PathExists(file_name_to)); 1096 EXPECT_TRUE(file_util::PathExists(file_name_to));
1097 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); 1097 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to));
1098 } 1098 }
1099 1099
1100 TEST_F(FileUtilTest, MoveFileDirExists) { 1100 TEST_F(FileUtilTest, MoveFileDirExists) {
1101 // Create a file 1101 // Create a file
1102 FilePath file_name_from = 1102 FilePath file_name_from =
1103 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); 1103 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt"));
1104 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); 1104 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
1105 ASSERT_TRUE(file_util::PathExists(file_name_from)); 1105 ASSERT_TRUE(file_util::PathExists(file_name_from));
1106 1106
1107 // The destination directory 1107 // The destination directory
1108 FilePath dir_name_to = 1108 FilePath dir_name_to =
1109 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); 1109 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination"));
1110 file_util::CreateDirectory(dir_name_to); 1110 file_util::CreateDirectory(dir_name_to);
1111 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 1111 ASSERT_TRUE(file_util::PathExists(dir_name_to));
1112 1112
1113 EXPECT_FALSE(file_util::Move(file_name_from, dir_name_to)); 1113 EXPECT_FALSE(base::Move(file_name_from, dir_name_to));
1114 } 1114 }
1115 1115
1116 1116
1117 TEST_F(FileUtilTest, MoveNew) { 1117 TEST_F(FileUtilTest, MoveNew) {
1118 // Create a directory 1118 // Create a directory
1119 FilePath dir_name_from = 1119 FilePath dir_name_from =
1120 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); 1120 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir"));
1121 file_util::CreateDirectory(dir_name_from); 1121 file_util::CreateDirectory(dir_name_from);
1122 ASSERT_TRUE(file_util::PathExists(dir_name_from)); 1122 ASSERT_TRUE(file_util::PathExists(dir_name_from));
1123 1123
1124 // Create a file under the directory 1124 // Create a file under the directory
1125 FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt")); 1125 FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt"));
1126 FilePath file_name_from = dir_name_from.Append(txt_file_name); 1126 FilePath file_name_from = dir_name_from.Append(txt_file_name);
1127 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); 1127 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
1128 ASSERT_TRUE(file_util::PathExists(file_name_from)); 1128 ASSERT_TRUE(file_util::PathExists(file_name_from));
1129 1129
1130 // Move the directory. 1130 // Move the directory.
1131 FilePath dir_name_to = 1131 FilePath dir_name_to =
1132 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_To_Subdir")); 1132 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_To_Subdir"));
1133 FilePath file_name_to = 1133 FilePath file_name_to =
1134 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); 1134 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt"));
1135 1135
1136 ASSERT_FALSE(file_util::PathExists(dir_name_to)); 1136 ASSERT_FALSE(file_util::PathExists(dir_name_to));
1137 1137
1138 EXPECT_TRUE(file_util::Move(dir_name_from, dir_name_to)); 1138 EXPECT_TRUE(base::Move(dir_name_from, dir_name_to));
1139 1139
1140 // Check everything has been moved. 1140 // Check everything has been moved.
1141 EXPECT_FALSE(file_util::PathExists(dir_name_from)); 1141 EXPECT_FALSE(file_util::PathExists(dir_name_from));
1142 EXPECT_FALSE(file_util::PathExists(file_name_from)); 1142 EXPECT_FALSE(file_util::PathExists(file_name_from));
1143 EXPECT_TRUE(file_util::PathExists(dir_name_to)); 1143 EXPECT_TRUE(file_util::PathExists(dir_name_to));
1144 EXPECT_TRUE(file_util::PathExists(file_name_to)); 1144 EXPECT_TRUE(file_util::PathExists(file_name_to));
1145 1145
1146 // Test path traversal. 1146 // Test path traversal.
1147 file_name_from = dir_name_to.Append(txt_file_name); 1147 file_name_from = dir_name_to.Append(txt_file_name);
1148 file_name_to = dir_name_to.Append(FILE_PATH_LITERAL("..")); 1148 file_name_to = dir_name_to.Append(FILE_PATH_LITERAL(".."));
1149 file_name_to = file_name_to.Append(txt_file_name); 1149 file_name_to = file_name_to.Append(txt_file_name);
1150 EXPECT_FALSE(file_util::Move(file_name_from, file_name_to)); 1150 EXPECT_FALSE(base::Move(file_name_from, file_name_to));
1151 EXPECT_TRUE(file_util::PathExists(file_name_from)); 1151 EXPECT_TRUE(file_util::PathExists(file_name_from));
1152 EXPECT_FALSE(file_util::PathExists(file_name_to)); 1152 EXPECT_FALSE(file_util::PathExists(file_name_to));
1153 EXPECT_TRUE(file_util::MoveUnsafe(file_name_from, file_name_to)); 1153 EXPECT_TRUE(base::MoveUnsafe(file_name_from, file_name_to));
1154 EXPECT_FALSE(file_util::PathExists(file_name_from)); 1154 EXPECT_FALSE(file_util::PathExists(file_name_from));
1155 EXPECT_TRUE(file_util::PathExists(file_name_to)); 1155 EXPECT_TRUE(file_util::PathExists(file_name_to));
1156 } 1156 }
1157 1157
1158 TEST_F(FileUtilTest, MoveExist) { 1158 TEST_F(FileUtilTest, MoveExist) {
1159 // Create a directory 1159 // Create a directory
1160 FilePath dir_name_from = 1160 FilePath dir_name_from =
1161 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); 1161 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir"));
1162 file_util::CreateDirectory(dir_name_from); 1162 file_util::CreateDirectory(dir_name_from);
1163 ASSERT_TRUE(file_util::PathExists(dir_name_from)); 1163 ASSERT_TRUE(file_util::PathExists(dir_name_from));
(...skipping 10 matching lines...) Expand all
1174 1174
1175 FilePath dir_name_to = 1175 FilePath dir_name_to =
1176 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir")); 1176 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir"));
1177 FilePath file_name_to = 1177 FilePath file_name_to =
1178 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); 1178 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt"));
1179 1179
1180 // Create the destination directory. 1180 // Create the destination directory.
1181 file_util::CreateDirectory(dir_name_exists); 1181 file_util::CreateDirectory(dir_name_exists);
1182 ASSERT_TRUE(file_util::PathExists(dir_name_exists)); 1182 ASSERT_TRUE(file_util::PathExists(dir_name_exists));
1183 1183
1184 EXPECT_TRUE(file_util::Move(dir_name_from, dir_name_to)); 1184 EXPECT_TRUE(base::Move(dir_name_from, dir_name_to));
1185 1185
1186 // Check everything has been moved. 1186 // Check everything has been moved.
1187 EXPECT_FALSE(file_util::PathExists(dir_name_from)); 1187 EXPECT_FALSE(file_util::PathExists(dir_name_from));
1188 EXPECT_FALSE(file_util::PathExists(file_name_from)); 1188 EXPECT_FALSE(file_util::PathExists(file_name_from));
1189 EXPECT_TRUE(file_util::PathExists(dir_name_to)); 1189 EXPECT_TRUE(file_util::PathExists(dir_name_to));
1190 EXPECT_TRUE(file_util::PathExists(file_name_to)); 1190 EXPECT_TRUE(file_util::PathExists(file_name_to));
1191 } 1191 }
1192 1192
1193 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { 1193 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) {
1194 // Create a directory. 1194 // Create a directory.
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2376 file_util::VerifyPathControlledByUser( 2376 file_util::VerifyPathControlledByUser(
2377 base_dir_, text_file_, uid_, ok_gids_)); 2377 base_dir_, text_file_, uid_, ok_gids_));
2378 EXPECT_TRUE( 2378 EXPECT_TRUE(
2379 file_util::VerifyPathControlledByUser( 2379 file_util::VerifyPathControlledByUser(
2380 sub_dir_, text_file_, uid_, ok_gids_)); 2380 sub_dir_, text_file_, uid_, ok_gids_));
2381 } 2381 }
2382 2382
2383 #endif // defined(OS_POSIX) 2383 #endif // defined(OS_POSIX)
2384 2384
2385 } // namespace 2385 } // namespace
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698