| 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 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1404 FilePath src_file = src.Append(FILE_PATH_LITERAL("src.txt")); | 1404 FilePath src_file = src.Append(FILE_PATH_LITERAL("src.txt")); |
| 1405 CreateTextFile(src_file, L"Gooooooooooooooooooooogle"); | 1405 CreateTextFile(src_file, L"Gooooooooooooooooooooogle"); |
| 1406 SetReadOnly(src_file); | 1406 SetReadOnly(src_file); |
| 1407 ASSERT_TRUE(IsReadOnly(src_file)); | 1407 ASSERT_TRUE(IsReadOnly(src_file)); |
| 1408 | 1408 |
| 1409 // Copy the directory recursively. | 1409 // Copy the directory recursively. |
| 1410 FilePath dst = temp_dir_.path().Append(FILE_PATH_LITERAL("dst")); | 1410 FilePath dst = temp_dir_.path().Append(FILE_PATH_LITERAL("dst")); |
| 1411 FilePath dst_file = dst.Append(FILE_PATH_LITERAL("src.txt")); | 1411 FilePath dst_file = dst.Append(FILE_PATH_LITERAL("src.txt")); |
| 1412 EXPECT_TRUE(CopyDirectory(src, dst, true)); | 1412 EXPECT_TRUE(CopyDirectory(src, dst, true)); |
| 1413 | 1413 |
| 1414 #if defined(OS_WIN) | |
| 1415 // While the source file had RO bit set, the copied file doesn't. | |
| 1416 ASSERT_FALSE(IsReadOnly(dst_file)); | 1414 ASSERT_FALSE(IsReadOnly(dst_file)); |
| 1417 #elif defined(OS_MACOSX) | |
| 1418 // On OSX, file mode is copied. | |
| 1419 ASSERT_TRUE(IsReadOnly(dst_file)); | |
| 1420 #else | |
| 1421 // On other POSIX, file mode is not copied. | |
| 1422 ASSERT_FALSE(IsReadOnly(dst_file)); | |
| 1423 #endif | |
| 1424 } | 1415 } |
| 1425 | 1416 |
| 1426 TEST_F(FileUtilTest, CopyFile) { | 1417 TEST_F(FileUtilTest, CopyFile) { |
| 1427 // Create a directory | 1418 // Create a directory |
| 1428 FilePath dir_name_from = | 1419 FilePath dir_name_from = |
| 1429 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1420 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1430 CreateDirectory(dir_name_from); | 1421 CreateDirectory(dir_name_from); |
| 1431 ASSERT_TRUE(PathExists(dir_name_from)); | 1422 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1432 | 1423 |
| 1433 // Create a file under the directory | 1424 // Create a file under the directory |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 // Set the source file to read-only. | 1463 // Set the source file to read-only. |
| 1473 ASSERT_FALSE(IsReadOnly(src)); | 1464 ASSERT_FALSE(IsReadOnly(src)); |
| 1474 SetReadOnly(src); | 1465 SetReadOnly(src); |
| 1475 ASSERT_TRUE(IsReadOnly(src)); | 1466 ASSERT_TRUE(IsReadOnly(src)); |
| 1476 | 1467 |
| 1477 // Copy the file. | 1468 // Copy the file. |
| 1478 FilePath dst = temp_dir_.path().Append(FILE_PATH_LITERAL("dst.txt")); | 1469 FilePath dst = temp_dir_.path().Append(FILE_PATH_LITERAL("dst.txt")); |
| 1479 ASSERT_TRUE(CopyFile(src, dst)); | 1470 ASSERT_TRUE(CopyFile(src, dst)); |
| 1480 EXPECT_EQ(file_contents, ReadTextFile(dst)); | 1471 EXPECT_EQ(file_contents, ReadTextFile(dst)); |
| 1481 | 1472 |
| 1482 #if defined(OS_WIN) | |
| 1483 // While the source file had RO bit set, the copied file doesn't. Other file | |
| 1484 // modes are copied. | |
| 1485 ASSERT_FALSE(IsReadOnly(dst)); | 1473 ASSERT_FALSE(IsReadOnly(dst)); |
| 1486 #elif defined(OS_MACOSX) | |
| 1487 // On OSX, file mode is copied. | |
| 1488 ASSERT_TRUE(IsReadOnly(dst)); | |
| 1489 #else | |
| 1490 // On other POSIX, file mode is not copied. | |
| 1491 ASSERT_FALSE(IsReadOnly(dst)); | |
| 1492 #endif | |
| 1493 } | 1474 } |
| 1494 | 1475 |
| 1495 // file_util winds up using autoreleased objects on the Mac, so this needs | 1476 // file_util winds up using autoreleased objects on the Mac, so this needs |
| 1496 // to be a PlatformTest. | 1477 // to be a PlatformTest. |
| 1497 typedef PlatformTest ReadOnlyFileUtilTest; | 1478 typedef PlatformTest ReadOnlyFileUtilTest; |
| 1498 | 1479 |
| 1499 TEST_F(ReadOnlyFileUtilTest, ContentsEqual) { | 1480 TEST_F(ReadOnlyFileUtilTest, ContentsEqual) { |
| 1500 FilePath data_dir; | 1481 FilePath data_dir; |
| 1501 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir)); | 1482 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir)); |
| 1502 data_dir = data_dir.AppendASCII("file_util"); | 1483 data_dir = data_dir.AppendASCII("file_util"); |
| (...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2422 int fd = OpenContentUriForRead(path); | 2403 int fd = OpenContentUriForRead(path); |
| 2423 EXPECT_EQ(-1, fd); | 2404 EXPECT_EQ(-1, fd); |
| 2424 } | 2405 } |
| 2425 #endif | 2406 #endif |
| 2426 | 2407 |
| 2427 #endif // defined(OS_POSIX) | 2408 #endif // defined(OS_POSIX) |
| 2428 | 2409 |
| 2429 } // namespace | 2410 } // namespace |
| 2430 | 2411 |
| 2431 } // namespace base | 2412 } // namespace base |
| OLD | NEW |