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

Side by Side Diff: base/files/file_util_unittest.cc

Issue 603683005: base::CopyFile can copy *from* Android's content scheme. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: base::internal::CopyFileUnsafe -> base::CopyFile Created 6 years, 1 month 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
« no previous file with comments | « base/files/file_util_posix.cc ('k') | base/files/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 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 FilePath file_name_from = 1464 FilePath file_name_from =
1465 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); 1465 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt"));
1466 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); 1466 const std::wstring file_contents(L"Gooooooooooooooooooooogle");
1467 CreateTextFile(file_name_from, file_contents); 1467 CreateTextFile(file_name_from, file_contents);
1468 ASSERT_TRUE(PathExists(file_name_from)); 1468 ASSERT_TRUE(PathExists(file_name_from));
1469 1469
1470 // Copy the file. 1470 // Copy the file.
1471 FilePath dest_file = dir_name_from.Append(FILE_PATH_LITERAL("DestFile.txt")); 1471 FilePath dest_file = dir_name_from.Append(FILE_PATH_LITERAL("DestFile.txt"));
1472 ASSERT_TRUE(CopyFile(file_name_from, dest_file)); 1472 ASSERT_TRUE(CopyFile(file_name_from, dest_file));
1473 1473
1474 // Copy the file to another location using '..' in the path. 1474 // Try to copy the file to another location using '..' in the path.
1475 FilePath dest_file2(dir_name_from); 1475 FilePath dest_file2(dir_name_from);
1476 dest_file2 = dest_file2.AppendASCII(".."); 1476 dest_file2 = dest_file2.AppendASCII("..");
1477 dest_file2 = dest_file2.AppendASCII("DestFile.txt"); 1477 dest_file2 = dest_file2.AppendASCII("DestFile.txt");
1478 ASSERT_FALSE(CopyFile(file_name_from, dest_file2)); 1478 ASSERT_FALSE(CopyFile(file_name_from, dest_file2));
1479 ASSERT_TRUE(internal::CopyFileUnsafe(file_name_from, dest_file2));
1480 1479
1481 FilePath dest_file2_test(dir_name_from); 1480 FilePath dest_file2_test(dir_name_from);
1482 dest_file2_test = dest_file2_test.DirName(); 1481 dest_file2_test = dest_file2_test.DirName();
1483 dest_file2_test = dest_file2_test.AppendASCII("DestFile.txt"); 1482 dest_file2_test = dest_file2_test.AppendASCII("DestFile.txt");
1484 1483
1485 // Check everything has been copied. 1484 // Check expected copy results.
1486 EXPECT_TRUE(PathExists(file_name_from)); 1485 EXPECT_TRUE(PathExists(file_name_from));
1487 EXPECT_TRUE(PathExists(dest_file)); 1486 EXPECT_TRUE(PathExists(dest_file));
1488 const std::wstring read_contents = ReadTextFile(dest_file); 1487 const std::wstring read_contents = ReadTextFile(dest_file);
1489 EXPECT_EQ(file_contents, read_contents); 1488 EXPECT_EQ(file_contents, read_contents);
1490 EXPECT_TRUE(PathExists(dest_file2_test)); 1489 EXPECT_FALSE(PathExists(dest_file2_test));
1491 EXPECT_TRUE(PathExists(dest_file2)); 1490 EXPECT_FALSE(PathExists(dest_file2));
1492 } 1491 }
1493 1492
1494 TEST_F(FileUtilTest, CopyFileACL) { 1493 TEST_F(FileUtilTest, CopyFileACL) {
1495 // While FileUtilTest.CopyFile asserts the content is correctly copied over, 1494 // While FileUtilTest.CopyFile asserts the content is correctly copied over,
1496 // this test case asserts the access control bits are meeting expectations in 1495 // this test case asserts the access control bits are meeting expectations in
1497 // CopyFileUnsafe(). 1496 // CopyFile().
1498 FilePath src = temp_dir_.path().Append(FILE_PATH_LITERAL("src.txt")); 1497 FilePath src = temp_dir_.path().Append(FILE_PATH_LITERAL("src.txt"));
1499 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); 1498 const std::wstring file_contents(L"Gooooooooooooooooooooogle");
1500 CreateTextFile(src, file_contents); 1499 CreateTextFile(src, file_contents);
1501 1500
1502 // Set the source file to read-only. 1501 // Set the source file to read-only.
1503 ASSERT_FALSE(IsReadOnly(src)); 1502 ASSERT_FALSE(IsReadOnly(src));
1504 SetReadOnly(src, true); 1503 SetReadOnly(src, true);
1505 ASSERT_TRUE(IsReadOnly(src)); 1504 ASSERT_TRUE(IsReadOnly(src));
1506 1505
1507 // Copy the file. 1506 // Copy the file.
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
2607 // Trying to close it should crash. This is important for security. 2606 // Trying to close it should crash. This is important for security.
2608 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); 2607 EXPECT_DEATH(CloseWithScopedFD(fds[1]), "");
2609 #endif 2608 #endif
2610 } 2609 }
2611 2610
2612 #endif // defined(OS_POSIX) 2611 #endif // defined(OS_POSIX)
2613 2612
2614 } // namespace 2613 } // namespace
2615 2614
2616 } // namespace base 2615 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_util_posix.cc ('k') | base/files/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698