Chromium Code Reviews| 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 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1391 | 1391 |
| 1392 // Check everything has been copied. | 1392 // Check everything has been copied. |
| 1393 EXPECT_TRUE(PathExists(file_name_from)); | 1393 EXPECT_TRUE(PathExists(file_name_from)); |
| 1394 EXPECT_TRUE(PathExists(dest_file)); | 1394 EXPECT_TRUE(PathExists(dest_file)); |
| 1395 const std::wstring read_contents = ReadTextFile(dest_file); | 1395 const std::wstring read_contents = ReadTextFile(dest_file); |
| 1396 EXPECT_EQ(file_contents, read_contents); | 1396 EXPECT_EQ(file_contents, read_contents); |
| 1397 EXPECT_TRUE(PathExists(dest_file2_test)); | 1397 EXPECT_TRUE(PathExists(dest_file2_test)); |
| 1398 EXPECT_TRUE(PathExists(dest_file2)); | 1398 EXPECT_TRUE(PathExists(dest_file2)); |
| 1399 } | 1399 } |
| 1400 | 1400 |
| 1401 #if defined(OS_WIN) || defined(OS_POSIX) | |
| 1402 TEST_F(FileUtilTest, CopyFileACL) { | |
| 1403 // While FileUtilTest.CopyFile asserts the content is correctly copied over, | |
| 1404 // this test case asserts the access control bits are meeting expectations in | |
| 1405 // CopyFileUnsafe(). | |
| 1406 FilePath src = temp_dir_.path().Append(FILE_PATH_LITERAL("src.txt")); | |
| 1407 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); | |
| 1408 CreateTextFile(src, file_contents); | |
| 1409 | |
| 1410 // Set the source file to read-only. | |
| 1411 #if defined(OS_WIN) | |
| 1412 // On Windows, it involves setting a bit. | |
| 1413 DWORD attrs = GetFileAttributes(src.value().c_str()); | |
| 1414 ASSERT_NE(INVALID_FILE_ATTRIBUTES, attrs); | |
| 1415 ASSERT_TRUE(SetFileAttributes( | |
| 1416 src.value().c_str(), attrs | FILE_ATTRIBUTE_READONLY)); | |
| 1417 attrs = GetFileAttributes(src.value().c_str()); | |
| 1418 // Files in the temporary directory should not be indexed ever. If this | |
| 1419 // assumption change, fix this unit test accordingly. | |
| 1420 DWORD expected = (FILE_ATTRIBUTE_NOT_CONTENT_INDEXED | | |
| 1421 FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY); | |
| 1422 ASSERT_EQ(expected, attrs); | |
| 1423 #else | |
| 1424 // On all other platforms, it involves removing the write bit. | |
| 1425 EXPECT_TRUE(SetPosixFilePermissions(src, 0400)); | |
| 1426 #endif | |
| 1427 | |
| 1428 // Copy the file. | |
| 1429 FilePath dst = temp_dir_.path().Append(FILE_PATH_LITERAL("dst.txt")); | |
| 1430 ASSERT_TRUE(CopyFile(src, dst)); | |
| 1431 EXPECT_EQ(file_contents, ReadTextFile(dst)); | |
| 1432 | |
| 1433 #if defined(OS_WIN) | |
| 1434 // While the source file had RO bit set, the copied file doesn't. Other file | |
| 1435 // modes are copied. | |
| 1436 attrs = GetFileAttributes(src.value().c_str()); | |
| 1437 ASSERT_EQ(expected, attrs); | |
| 1438 expected = FILE_ATTRIBUTE_NOT_CONTENT_INDEXED | FILE_ATTRIBUTE_ARCHIVE; | |
| 1439 attrs = GetFileAttributes(dst.value().c_str()); | |
| 1440 ASSERT_EQ(expected, attrs); | |
| 1441 #elif defined(OS_MACOSX) | |
| 1442 // On OSX, file mode is copied. | |
|
M-A Ruel
2014/01/14 14:59:39
Note that I am not changing this behavior, only do
| |
| 1443 int mode = 0; | |
| 1444 EXPECT_TRUE(GetPosixFilePermissions(dst, &mode)); | |
| 1445 EXPECT_EQ(0400, mode & 0600); | |
| 1446 #else | |
| 1447 // On other POSIX, file mode is not copied. | |
| 1448 int mode = 0; | |
| 1449 EXPECT_TRUE(GetPosixFilePermissions(dst, &mode)); | |
| 1450 EXPECT_EQ(0600, mode & 0600); | |
| 1451 #endif | |
| 1452 } | |
| 1453 #endif // defined(OS_WIN) || defined(OS_POSIX) | |
| 1454 | |
| 1401 // file_util winds up using autoreleased objects on the Mac, so this needs | 1455 // file_util winds up using autoreleased objects on the Mac, so this needs |
| 1402 // to be a PlatformTest. | 1456 // to be a PlatformTest. |
| 1403 typedef PlatformTest ReadOnlyFileUtilTest; | 1457 typedef PlatformTest ReadOnlyFileUtilTest; |
| 1404 | 1458 |
| 1405 TEST_F(ReadOnlyFileUtilTest, ContentsEqual) { | 1459 TEST_F(ReadOnlyFileUtilTest, ContentsEqual) { |
| 1406 FilePath data_dir; | 1460 FilePath data_dir; |
| 1407 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir)); | 1461 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir)); |
| 1408 data_dir = data_dir.AppendASCII("file_util"); | 1462 data_dir = data_dir.AppendASCII("file_util"); |
| 1409 ASSERT_TRUE(PathExists(data_dir)); | 1463 ASSERT_TRUE(PathExists(data_dir)); |
| 1410 | 1464 |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2328 int fd = OpenContentUriForRead(path); | 2382 int fd = OpenContentUriForRead(path); |
| 2329 EXPECT_EQ(-1, fd); | 2383 EXPECT_EQ(-1, fd); |
| 2330 } | 2384 } |
| 2331 #endif | 2385 #endif |
| 2332 | 2386 |
| 2333 #endif // defined(OS_POSIX) | 2387 #endif // defined(OS_POSIX) |
| 2334 | 2388 |
| 2335 } // namespace | 2389 } // namespace |
| 2336 | 2390 |
| 2337 } // namespace base | 2391 } // namespace base |
| OLD | NEW |