| 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 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1585 different_last_file)); | 1585 different_last_file)); |
| 1586 EXPECT_FALSE(file_util::TextContentsEqual(first1_file, first2_file)); | 1586 EXPECT_FALSE(file_util::TextContentsEqual(first1_file, first2_file)); |
| 1587 EXPECT_TRUE(file_util::TextContentsEqual(empty1_file, empty2_file)); | 1587 EXPECT_TRUE(file_util::TextContentsEqual(empty1_file, empty2_file)); |
| 1588 EXPECT_FALSE(file_util::TextContentsEqual(original_file, empty1_file)); | 1588 EXPECT_FALSE(file_util::TextContentsEqual(original_file, empty1_file)); |
| 1589 EXPECT_TRUE(file_util::TextContentsEqual(blank_line_file, | 1589 EXPECT_TRUE(file_util::TextContentsEqual(blank_line_file, |
| 1590 blank_line_crlf_file)); | 1590 blank_line_crlf_file)); |
| 1591 } | 1591 } |
| 1592 | 1592 |
| 1593 // We don't need equivalent functionality outside of Windows. | 1593 // We don't need equivalent functionality outside of Windows. |
| 1594 #if defined(OS_WIN) | 1594 #if defined(OS_WIN) |
| 1595 TEST_F(FileUtilTest, ResolveShortcutTest) { | |
| 1596 FilePath target_file = temp_dir_.path().Append(L"Target.txt"); | |
| 1597 CreateTextFile(target_file, L"This is the target."); | |
| 1598 | |
| 1599 FilePath link_file = temp_dir_.path().Append(L"Link.lnk"); | |
| 1600 | |
| 1601 HRESULT result; | |
| 1602 IShellLink* shell = NULL; | |
| 1603 IPersistFile* persist = NULL; | |
| 1604 | |
| 1605 CoInitialize(NULL); | |
| 1606 // Temporarily create a shortcut for test | |
| 1607 result = CoCreateInstance(CLSID_ShellLink, NULL, | |
| 1608 CLSCTX_INPROC_SERVER, IID_IShellLink, | |
| 1609 reinterpret_cast<LPVOID*>(&shell)); | |
| 1610 EXPECT_TRUE(SUCCEEDED(result)); | |
| 1611 result = shell->QueryInterface(IID_IPersistFile, | |
| 1612 reinterpret_cast<LPVOID*>(&persist)); | |
| 1613 EXPECT_TRUE(SUCCEEDED(result)); | |
| 1614 result = shell->SetPath(target_file.value().c_str()); | |
| 1615 EXPECT_TRUE(SUCCEEDED(result)); | |
| 1616 result = shell->SetDescription(L"ResolveShortcutTest"); | |
| 1617 EXPECT_TRUE(SUCCEEDED(result)); | |
| 1618 result = shell->SetArguments(L"--args"); | |
| 1619 EXPECT_TRUE(SUCCEEDED(result)); | |
| 1620 result = persist->Save(link_file.value().c_str(), TRUE); | |
| 1621 EXPECT_TRUE(SUCCEEDED(result)); | |
| 1622 if (persist) | |
| 1623 persist->Release(); | |
| 1624 if (shell) | |
| 1625 shell->Release(); | |
| 1626 | |
| 1627 bool is_solved; | |
| 1628 std::wstring args; | |
| 1629 is_solved = file_util::ResolveShortcut(link_file, &link_file, &args); | |
| 1630 EXPECT_TRUE(is_solved); | |
| 1631 EXPECT_EQ(L"--args", args); | |
| 1632 std::wstring contents; | |
| 1633 contents = ReadTextFile(link_file); | |
| 1634 EXPECT_EQ(L"This is the target.", contents); | |
| 1635 | |
| 1636 // Cleaning | |
| 1637 DeleteFile(target_file.value().c_str()); | |
| 1638 DeleteFile(link_file.value().c_str()); | |
| 1639 CoUninitialize(); | |
| 1640 } | |
| 1641 | |
| 1642 TEST_F(FileUtilTest, CreateShortcutTest) { | |
| 1643 const wchar_t* file_contents = L"This is another target."; | |
| 1644 FilePath target_file = temp_dir_.path().Append(L"Target1.txt"); | |
| 1645 CreateTextFile(target_file, file_contents); | |
| 1646 | |
| 1647 FilePath link_file = temp_dir_.path().Append(L"Link1.lnk"); | |
| 1648 | |
| 1649 CoInitialize(NULL); | |
| 1650 EXPECT_TRUE(file_util::CreateOrUpdateShortcutLink( | |
| 1651 target_file.value().c_str(), link_file.value().c_str(), NULL, | |
| 1652 NULL, NULL, NULL, 0, NULL, | |
| 1653 file_util::SHORTCUT_CREATE_ALWAYS)); | |
| 1654 FilePath resolved_name; | |
| 1655 EXPECT_TRUE(file_util::ResolveShortcut(link_file, &resolved_name, NULL)); | |
| 1656 std::wstring read_contents = ReadTextFile(resolved_name); | |
| 1657 EXPECT_EQ(file_contents, read_contents); | |
| 1658 | |
| 1659 DeleteFile(target_file.value().c_str()); | |
| 1660 DeleteFile(link_file.value().c_str()); | |
| 1661 CoUninitialize(); | |
| 1662 } | |
| 1663 | |
| 1664 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { | 1595 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { |
| 1665 // Create a directory | 1596 // Create a directory |
| 1666 FilePath dir_name_from = | 1597 FilePath dir_name_from = |
| 1667 temp_dir_.path().Append(FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); | 1598 temp_dir_.path().Append(FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); |
| 1668 file_util::CreateDirectory(dir_name_from); | 1599 file_util::CreateDirectory(dir_name_from); |
| 1669 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 1600 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 1670 | 1601 |
| 1671 // Create a file under the directory | 1602 // Create a file under the directory |
| 1672 FilePath file_name_from = | 1603 FilePath file_name_from = |
| 1673 dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); | 1604 dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2458 file_util::VerifyPathControlledByUser( | 2389 file_util::VerifyPathControlledByUser( |
| 2459 base_dir_, text_file_, uid_, ok_gids_)); | 2390 base_dir_, text_file_, uid_, ok_gids_)); |
| 2460 EXPECT_TRUE( | 2391 EXPECT_TRUE( |
| 2461 file_util::VerifyPathControlledByUser( | 2392 file_util::VerifyPathControlledByUser( |
| 2462 sub_dir_, text_file_, uid_, ok_gids_)); | 2393 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2463 } | 2394 } |
| 2464 | 2395 |
| 2465 #endif // defined(OS_POSIX) | 2396 #endif // defined(OS_POSIX) |
| 2466 | 2397 |
| 2467 } // namespace | 2398 } // namespace |
| OLD | NEW |