| 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 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1610 CLSCTX_INPROC_SERVER, IID_IShellLink, | 1610 CLSCTX_INPROC_SERVER, IID_IShellLink, |
| 1611 reinterpret_cast<LPVOID*>(&shell)); | 1611 reinterpret_cast<LPVOID*>(&shell)); |
| 1612 EXPECT_TRUE(SUCCEEDED(result)); | 1612 EXPECT_TRUE(SUCCEEDED(result)); |
| 1613 result = shell->QueryInterface(IID_IPersistFile, | 1613 result = shell->QueryInterface(IID_IPersistFile, |
| 1614 reinterpret_cast<LPVOID*>(&persist)); | 1614 reinterpret_cast<LPVOID*>(&persist)); |
| 1615 EXPECT_TRUE(SUCCEEDED(result)); | 1615 EXPECT_TRUE(SUCCEEDED(result)); |
| 1616 result = shell->SetPath(target_file.value().c_str()); | 1616 result = shell->SetPath(target_file.value().c_str()); |
| 1617 EXPECT_TRUE(SUCCEEDED(result)); | 1617 EXPECT_TRUE(SUCCEEDED(result)); |
| 1618 result = shell->SetDescription(L"ResolveShortcutTest"); | 1618 result = shell->SetDescription(L"ResolveShortcutTest"); |
| 1619 EXPECT_TRUE(SUCCEEDED(result)); | 1619 EXPECT_TRUE(SUCCEEDED(result)); |
| 1620 result = shell->SetArguments(L"--args"); |
| 1621 EXPECT_TRUE(SUCCEEDED(result)); |
| 1620 result = persist->Save(link_file.value().c_str(), TRUE); | 1622 result = persist->Save(link_file.value().c_str(), TRUE); |
| 1621 EXPECT_TRUE(SUCCEEDED(result)); | 1623 EXPECT_TRUE(SUCCEEDED(result)); |
| 1622 if (persist) | 1624 if (persist) |
| 1623 persist->Release(); | 1625 persist->Release(); |
| 1624 if (shell) | 1626 if (shell) |
| 1625 shell->Release(); | 1627 shell->Release(); |
| 1626 | 1628 |
| 1627 bool is_solved; | 1629 bool is_solved; |
| 1628 is_solved = file_util::ResolveShortcut(&link_file); | 1630 std::wstring args; |
| 1631 is_solved = file_util::ResolveShortcut(link_file, &link_file, &args); |
| 1629 EXPECT_TRUE(is_solved); | 1632 EXPECT_TRUE(is_solved); |
| 1633 EXPECT_EQ(L"--args", args); |
| 1630 std::wstring contents; | 1634 std::wstring contents; |
| 1631 contents = ReadTextFile(link_file); | 1635 contents = ReadTextFile(link_file); |
| 1632 EXPECT_EQ(L"This is the target.", contents); | 1636 EXPECT_EQ(L"This is the target.", contents); |
| 1633 | 1637 |
| 1634 // Cleaning | 1638 // Cleaning |
| 1635 DeleteFile(target_file.value().c_str()); | 1639 DeleteFile(target_file.value().c_str()); |
| 1636 DeleteFile(link_file.value().c_str()); | 1640 DeleteFile(link_file.value().c_str()); |
| 1637 CoUninitialize(); | 1641 CoUninitialize(); |
| 1638 } | 1642 } |
| 1639 | 1643 |
| 1640 TEST_F(FileUtilTest, CreateShortcutTest) { | 1644 TEST_F(FileUtilTest, CreateShortcutTest) { |
| 1641 const wchar_t* file_contents = L"This is another target."; | 1645 const wchar_t* file_contents = L"This is another target."; |
| 1642 FilePath target_file = temp_dir_.path().Append(L"Target1.txt"); | 1646 FilePath target_file = temp_dir_.path().Append(L"Target1.txt"); |
| 1643 CreateTextFile(target_file, file_contents); | 1647 CreateTextFile(target_file, file_contents); |
| 1644 | 1648 |
| 1645 FilePath link_file = temp_dir_.path().Append(L"Link1.lnk"); | 1649 FilePath link_file = temp_dir_.path().Append(L"Link1.lnk"); |
| 1646 | 1650 |
| 1647 CoInitialize(NULL); | 1651 CoInitialize(NULL); |
| 1648 EXPECT_TRUE(file_util::CreateOrUpdateShortcutLink( | 1652 EXPECT_TRUE(file_util::CreateOrUpdateShortcutLink( |
| 1649 target_file.value().c_str(), link_file.value().c_str(), NULL, | 1653 target_file.value().c_str(), link_file.value().c_str(), NULL, |
| 1650 NULL, NULL, NULL, 0, NULL, | 1654 NULL, NULL, NULL, 0, NULL, |
| 1651 file_util::SHORTCUT_CREATE_ALWAYS)); | 1655 file_util::SHORTCUT_CREATE_ALWAYS)); |
| 1652 FilePath resolved_name = link_file; | 1656 FilePath resolved_name; |
| 1653 EXPECT_TRUE(file_util::ResolveShortcut(&resolved_name)); | 1657 EXPECT_TRUE(file_util::ResolveShortcut(link_file, &resolved_name, NULL)); |
| 1654 std::wstring read_contents = ReadTextFile(resolved_name); | 1658 std::wstring read_contents = ReadTextFile(resolved_name); |
| 1655 EXPECT_EQ(file_contents, read_contents); | 1659 EXPECT_EQ(file_contents, read_contents); |
| 1656 | 1660 |
| 1657 DeleteFile(target_file.value().c_str()); | 1661 DeleteFile(target_file.value().c_str()); |
| 1658 DeleteFile(link_file.value().c_str()); | 1662 DeleteFile(link_file.value().c_str()); |
| 1659 CoUninitialize(); | 1663 CoUninitialize(); |
| 1660 } | 1664 } |
| 1661 | 1665 |
| 1662 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { | 1666 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { |
| 1663 // Create a directory | 1667 // Create a directory |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2459 file_util::VerifyPathControlledByUser( | 2463 file_util::VerifyPathControlledByUser( |
| 2460 base_dir_, text_file_, uid_, ok_gids_)); | 2464 base_dir_, text_file_, uid_, ok_gids_)); |
| 2461 EXPECT_TRUE( | 2465 EXPECT_TRUE( |
| 2462 file_util::VerifyPathControlledByUser( | 2466 file_util::VerifyPathControlledByUser( |
| 2463 sub_dir_, text_file_, uid_, ok_gids_)); | 2467 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2464 } | 2468 } |
| 2465 | 2469 |
| 2466 #endif // defined(OS_POSIX) | 2470 #endif // defined(OS_POSIX) |
| 2467 | 2471 |
| 2468 } // namespace | 2472 } // namespace |
| OLD | NEW |