OLD | NEW |
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 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1140 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
1141 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1141 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
1142 | 1142 |
1143 // Test path traversal. | 1143 // Test path traversal. |
1144 file_name_from = dir_name_to.Append(txt_file_name); | 1144 file_name_from = dir_name_to.Append(txt_file_name); |
1145 file_name_to = dir_name_to.Append(FILE_PATH_LITERAL("..")); | 1145 file_name_to = dir_name_to.Append(FILE_PATH_LITERAL("..")); |
1146 file_name_to = file_name_to.Append(txt_file_name); | 1146 file_name_to = file_name_to.Append(txt_file_name); |
1147 EXPECT_FALSE(base::Move(file_name_from, file_name_to)); | 1147 EXPECT_FALSE(base::Move(file_name_from, file_name_to)); |
1148 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1148 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
1149 EXPECT_FALSE(file_util::PathExists(file_name_to)); | 1149 EXPECT_FALSE(file_util::PathExists(file_name_to)); |
1150 EXPECT_TRUE(base::MoveUnsafe(file_name_from, file_name_to)); | 1150 EXPECT_TRUE(base::internal::MoveUnsafe(file_name_from, file_name_to)); |
1151 EXPECT_FALSE(file_util::PathExists(file_name_from)); | 1151 EXPECT_FALSE(file_util::PathExists(file_name_from)); |
1152 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1152 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
1153 } | 1153 } |
1154 | 1154 |
1155 TEST_F(FileUtilTest, MoveExist) { | 1155 TEST_F(FileUtilTest, MoveExist) { |
1156 // Create a directory | 1156 // Create a directory |
1157 FilePath dir_name_from = | 1157 FilePath dir_name_from = |
1158 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 1158 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
1159 file_util::CreateDirectory(dir_name_from); | 1159 file_util::CreateDirectory(dir_name_from); |
1160 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 1160 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1217 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
1218 FilePath file_name_to = | 1218 FilePath file_name_to = |
1219 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1219 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1220 FilePath subdir_name_to = | 1220 FilePath subdir_name_to = |
1221 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1221 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
1222 FilePath file_name2_to = | 1222 FilePath file_name2_to = |
1223 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1223 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1224 | 1224 |
1225 ASSERT_FALSE(file_util::PathExists(dir_name_to)); | 1225 ASSERT_FALSE(file_util::PathExists(dir_name_to)); |
1226 | 1226 |
1227 EXPECT_TRUE(file_util::CopyDirectory(dir_name_from, dir_name_to, true)); | 1227 EXPECT_TRUE(base::CopyDirectory(dir_name_from, dir_name_to, true)); |
1228 | 1228 |
1229 // Check everything has been copied. | 1229 // Check everything has been copied. |
1230 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 1230 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
1231 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1231 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
1232 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 1232 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
1233 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 1233 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
1234 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1234 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
1235 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1235 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
1236 EXPECT_TRUE(file_util::PathExists(subdir_name_to)); | 1236 EXPECT_TRUE(file_util::PathExists(subdir_name_to)); |
1237 EXPECT_TRUE(file_util::PathExists(file_name2_to)); | 1237 EXPECT_TRUE(file_util::PathExists(file_name2_to)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1272 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1273 FilePath subdir_name_to = | 1273 FilePath subdir_name_to = |
1274 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1274 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
1275 FilePath file_name2_to = | 1275 FilePath file_name2_to = |
1276 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1276 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1277 | 1277 |
1278 // Create the destination directory. | 1278 // Create the destination directory. |
1279 file_util::CreateDirectory(dir_name_exists); | 1279 file_util::CreateDirectory(dir_name_exists); |
1280 ASSERT_TRUE(file_util::PathExists(dir_name_exists)); | 1280 ASSERT_TRUE(file_util::PathExists(dir_name_exists)); |
1281 | 1281 |
1282 EXPECT_TRUE(file_util::CopyDirectory(dir_name_from, dir_name_exists, true)); | 1282 EXPECT_TRUE(base::CopyDirectory(dir_name_from, dir_name_exists, true)); |
1283 | 1283 |
1284 // Check everything has been copied. | 1284 // Check everything has been copied. |
1285 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 1285 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
1286 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1286 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
1287 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 1287 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
1288 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 1288 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
1289 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1289 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
1290 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1290 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
1291 EXPECT_TRUE(file_util::PathExists(subdir_name_to)); | 1291 EXPECT_TRUE(file_util::PathExists(subdir_name_to)); |
1292 EXPECT_TRUE(file_util::PathExists(file_name2_to)); | 1292 EXPECT_TRUE(file_util::PathExists(file_name2_to)); |
(...skipping 27 matching lines...) Expand all Loading... |
1320 // Copy the directory not recursively. | 1320 // Copy the directory not recursively. |
1321 FilePath dir_name_to = | 1321 FilePath dir_name_to = |
1322 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1322 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
1323 FilePath file_name_to = | 1323 FilePath file_name_to = |
1324 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1324 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1325 FilePath subdir_name_to = | 1325 FilePath subdir_name_to = |
1326 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1326 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
1327 | 1327 |
1328 ASSERT_FALSE(file_util::PathExists(dir_name_to)); | 1328 ASSERT_FALSE(file_util::PathExists(dir_name_to)); |
1329 | 1329 |
1330 EXPECT_TRUE(file_util::CopyDirectory(dir_name_from, dir_name_to, false)); | 1330 EXPECT_TRUE(base::CopyDirectory(dir_name_from, dir_name_to, false)); |
1331 | 1331 |
1332 // Check everything has been copied. | 1332 // Check everything has been copied. |
1333 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 1333 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
1334 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1334 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
1335 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 1335 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
1336 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 1336 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
1337 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1337 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
1338 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1338 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
1339 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); | 1339 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); |
1340 } | 1340 } |
(...skipping 28 matching lines...) Expand all Loading... |
1369 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1369 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
1370 FilePath file_name_to = | 1370 FilePath file_name_to = |
1371 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1371 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1372 FilePath subdir_name_to = | 1372 FilePath subdir_name_to = |
1373 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1373 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
1374 | 1374 |
1375 // Create the destination directory. | 1375 // Create the destination directory. |
1376 file_util::CreateDirectory(dir_name_to); | 1376 file_util::CreateDirectory(dir_name_to); |
1377 ASSERT_TRUE(file_util::PathExists(dir_name_to)); | 1377 ASSERT_TRUE(file_util::PathExists(dir_name_to)); |
1378 | 1378 |
1379 EXPECT_TRUE(file_util::CopyDirectory(dir_name_from, dir_name_to, false)); | 1379 EXPECT_TRUE(base::CopyDirectory(dir_name_from, dir_name_to, false)); |
1380 | 1380 |
1381 // Check everything has been copied. | 1381 // Check everything has been copied. |
1382 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 1382 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
1383 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1383 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
1384 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 1384 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
1385 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 1385 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
1386 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1386 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
1387 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1387 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
1388 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); | 1388 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); |
1389 } | 1389 } |
1390 | 1390 |
1391 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToNew) { | 1391 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToNew) { |
1392 // Create a file | 1392 // Create a file |
1393 FilePath file_name_from = | 1393 FilePath file_name_from = |
1394 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1394 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1395 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1395 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1396 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1396 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
1397 | 1397 |
1398 // The destination name | 1398 // The destination name |
1399 FilePath file_name_to = temp_dir_.path().Append( | 1399 FilePath file_name_to = temp_dir_.path().Append( |
1400 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); | 1400 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); |
1401 ASSERT_FALSE(file_util::PathExists(file_name_to)); | 1401 ASSERT_FALSE(file_util::PathExists(file_name_to)); |
1402 | 1402 |
1403 EXPECT_TRUE(file_util::CopyDirectory(file_name_from, file_name_to, true)); | 1403 EXPECT_TRUE(base::CopyDirectory(file_name_from, file_name_to, true)); |
1404 | 1404 |
1405 // Check the has been copied | 1405 // Check the has been copied |
1406 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1406 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
1407 } | 1407 } |
1408 | 1408 |
1409 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExisting) { | 1409 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExisting) { |
1410 // Create a file | 1410 // Create a file |
1411 FilePath file_name_from = | 1411 FilePath file_name_from = |
1412 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1412 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1413 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1413 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1414 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1414 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
1415 | 1415 |
1416 // The destination name | 1416 // The destination name |
1417 FilePath file_name_to = temp_dir_.path().Append( | 1417 FilePath file_name_to = temp_dir_.path().Append( |
1418 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); | 1418 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); |
1419 CreateTextFile(file_name_to, L"Old file content"); | 1419 CreateTextFile(file_name_to, L"Old file content"); |
1420 ASSERT_TRUE(file_util::PathExists(file_name_to)); | 1420 ASSERT_TRUE(file_util::PathExists(file_name_to)); |
1421 | 1421 |
1422 EXPECT_TRUE(file_util::CopyDirectory(file_name_from, file_name_to, true)); | 1422 EXPECT_TRUE(base::CopyDirectory(file_name_from, file_name_to, true)); |
1423 | 1423 |
1424 // Check the has been copied | 1424 // Check the has been copied |
1425 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1425 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
1426 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); | 1426 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); |
1427 } | 1427 } |
1428 | 1428 |
1429 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { | 1429 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { |
1430 // Create a file | 1430 // Create a file |
1431 FilePath file_name_from = | 1431 FilePath file_name_from = |
1432 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1432 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1433 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1433 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1434 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1434 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
1435 | 1435 |
1436 // The destination | 1436 // The destination |
1437 FilePath dir_name_to = | 1437 FilePath dir_name_to = |
1438 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1438 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
1439 file_util::CreateDirectory(dir_name_to); | 1439 file_util::CreateDirectory(dir_name_to); |
1440 ASSERT_TRUE(file_util::PathExists(dir_name_to)); | 1440 ASSERT_TRUE(file_util::PathExists(dir_name_to)); |
1441 FilePath file_name_to = | 1441 FilePath file_name_to = |
1442 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1442 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1443 | 1443 |
1444 EXPECT_TRUE(file_util::CopyDirectory(file_name_from, dir_name_to, true)); | 1444 EXPECT_TRUE(base::CopyDirectory(file_name_from, dir_name_to, true)); |
1445 | 1445 |
1446 // Check the has been copied | 1446 // Check the has been copied |
1447 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1447 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
1448 } | 1448 } |
1449 | 1449 |
1450 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { | 1450 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { |
1451 // Create a directory. | 1451 // Create a directory. |
1452 FilePath dir_name_from = | 1452 FilePath dir_name_from = |
1453 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1453 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1454 file_util::CreateDirectory(dir_name_from); | 1454 file_util::CreateDirectory(dir_name_from); |
(...skipping 13 matching lines...) Expand all Loading... |
1468 | 1468 |
1469 // Create from path with trailing separators. | 1469 // Create from path with trailing separators. |
1470 #if defined(OS_WIN) | 1470 #if defined(OS_WIN) |
1471 FilePath from_path = | 1471 FilePath from_path = |
1472 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\")); | 1472 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\")); |
1473 #elif defined (OS_POSIX) | 1473 #elif defined (OS_POSIX) |
1474 FilePath from_path = | 1474 FilePath from_path = |
1475 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir///")); | 1475 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir///")); |
1476 #endif | 1476 #endif |
1477 | 1477 |
1478 EXPECT_TRUE(file_util::CopyDirectory(from_path, dir_name_to, true)); | 1478 EXPECT_TRUE(base::CopyDirectory(from_path, dir_name_to, true)); |
1479 | 1479 |
1480 // Check everything has been copied. | 1480 // Check everything has been copied. |
1481 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 1481 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
1482 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1482 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
1483 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1483 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
1484 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1484 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
1485 } | 1485 } |
1486 | 1486 |
1487 TEST_F(FileUtilTest, CopyFile) { | 1487 TEST_F(FileUtilTest, CopyFile) { |
1488 // Create a directory | 1488 // Create a directory |
1489 FilePath dir_name_from = | 1489 FilePath dir_name_from = |
1490 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1490 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1491 file_util::CreateDirectory(dir_name_from); | 1491 file_util::CreateDirectory(dir_name_from); |
1492 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 1492 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
1493 | 1493 |
1494 // Create a file under the directory | 1494 // Create a file under the directory |
1495 FilePath file_name_from = | 1495 FilePath file_name_from = |
1496 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1496 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1497 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); | 1497 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); |
1498 CreateTextFile(file_name_from, file_contents); | 1498 CreateTextFile(file_name_from, file_contents); |
1499 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1499 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
1500 | 1500 |
1501 // Copy the file. | 1501 // Copy the file. |
1502 FilePath dest_file = dir_name_from.Append(FILE_PATH_LITERAL("DestFile.txt")); | 1502 FilePath dest_file = dir_name_from.Append(FILE_PATH_LITERAL("DestFile.txt")); |
1503 ASSERT_TRUE(file_util::CopyFile(file_name_from, dest_file)); | 1503 ASSERT_TRUE(base::CopyFile(file_name_from, dest_file)); |
1504 | 1504 |
1505 // Copy the file to another location using '..' in the path. | 1505 // Copy the file to another location using '..' in the path. |
1506 FilePath dest_file2(dir_name_from); | 1506 FilePath dest_file2(dir_name_from); |
1507 dest_file2 = dest_file2.AppendASCII(".."); | 1507 dest_file2 = dest_file2.AppendASCII(".."); |
1508 dest_file2 = dest_file2.AppendASCII("DestFile.txt"); | 1508 dest_file2 = dest_file2.AppendASCII("DestFile.txt"); |
1509 ASSERT_FALSE(file_util::CopyFile(file_name_from, dest_file2)); | 1509 ASSERT_FALSE(base::CopyFile(file_name_from, dest_file2)); |
1510 ASSERT_TRUE(file_util::CopyFileUnsafe(file_name_from, dest_file2)); | 1510 ASSERT_TRUE(base::internal::CopyFileUnsafe(file_name_from, dest_file2)); |
1511 | 1511 |
1512 FilePath dest_file2_test(dir_name_from); | 1512 FilePath dest_file2_test(dir_name_from); |
1513 dest_file2_test = dest_file2_test.DirName(); | 1513 dest_file2_test = dest_file2_test.DirName(); |
1514 dest_file2_test = dest_file2_test.AppendASCII("DestFile.txt"); | 1514 dest_file2_test = dest_file2_test.AppendASCII("DestFile.txt"); |
1515 | 1515 |
1516 // Check everything has been copied. | 1516 // Check everything has been copied. |
1517 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1517 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
1518 EXPECT_TRUE(file_util::PathExists(dest_file)); | 1518 EXPECT_TRUE(file_util::PathExists(dest_file)); |
1519 const std::wstring read_contents = ReadTextFile(dest_file); | 1519 const std::wstring read_contents = ReadTextFile(dest_file); |
1520 EXPECT_EQ(file_contents, read_contents); | 1520 EXPECT_EQ(file_contents, read_contents); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1637 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
1638 | 1638 |
1639 // Move the directory by using CopyAndDeleteDirectory | 1639 // Move the directory by using CopyAndDeleteDirectory |
1640 FilePath dir_name_to = temp_dir_.path().Append( | 1640 FilePath dir_name_to = temp_dir_.path().Append( |
1641 FILE_PATH_LITERAL("CopyAndDelete_To_Subdir")); | 1641 FILE_PATH_LITERAL("CopyAndDelete_To_Subdir")); |
1642 FilePath file_name_to = | 1642 FilePath file_name_to = |
1643 dir_name_to.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); | 1643 dir_name_to.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); |
1644 | 1644 |
1645 ASSERT_FALSE(file_util::PathExists(dir_name_to)); | 1645 ASSERT_FALSE(file_util::PathExists(dir_name_to)); |
1646 | 1646 |
1647 EXPECT_TRUE(file_util::CopyAndDeleteDirectory(dir_name_from, dir_name_to)); | 1647 EXPECT_TRUE(base::internal::CopyAndDeleteDirectory(dir_name_from, |
| 1648 dir_name_to)); |
1648 | 1649 |
1649 // Check everything has been moved. | 1650 // Check everything has been moved. |
1650 EXPECT_FALSE(file_util::PathExists(dir_name_from)); | 1651 EXPECT_FALSE(file_util::PathExists(dir_name_from)); |
1651 EXPECT_FALSE(file_util::PathExists(file_name_from)); | 1652 EXPECT_FALSE(file_util::PathExists(file_name_from)); |
1652 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1653 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
1653 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1654 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
1654 } | 1655 } |
1655 | 1656 |
1656 TEST_F(FileUtilTest, GetTempDirTest) { | 1657 TEST_F(FileUtilTest, GetTempDirTest) { |
1657 static const TCHAR* kTmpKey = _T("TMP"); | 1658 static const TCHAR* kTmpKey = _T("TMP"); |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2373 file_util::VerifyPathControlledByUser( | 2374 file_util::VerifyPathControlledByUser( |
2374 base_dir_, text_file_, uid_, ok_gids_)); | 2375 base_dir_, text_file_, uid_, ok_gids_)); |
2375 EXPECT_TRUE( | 2376 EXPECT_TRUE( |
2376 file_util::VerifyPathControlledByUser( | 2377 file_util::VerifyPathControlledByUser( |
2377 sub_dir_, text_file_, uid_, ok_gids_)); | 2378 sub_dir_, text_file_, uid_, ok_gids_)); |
2378 } | 2379 } |
2379 | 2380 |
2380 #endif // defined(OS_POSIX) | 2381 #endif // defined(OS_POSIX) |
2381 | 2382 |
2382 } // namespace | 2383 } // namespace |
OLD | NEW |