diff options
author | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-12 07:14:55 +0000 |
---|---|---|
committer | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-12 07:14:55 +0000 |
commit | f1024e222989f0ad1895d46bf407bac95c110b6c (patch) | |
tree | a8154c03b7ac6e04a5e2239698e5d8629f5d725a /base/file_util_unittest.cc | |
parent | 69ebc68fc96a84197c8c93d2adb65e680cb2c988 (diff) | |
download | chromium_src-f1024e222989f0ad1895d46bf407bac95c110b6c.zip chromium_src-f1024e222989f0ad1895d46bf407bac95c110b6c.tar.gz chromium_src-f1024e222989f0ad1895d46bf407bac95c110b6c.tar.bz2 |
Fix and re-commit http://codereview.chromium.org/10914109/ (after revert in http://crrev.com/155918) -- Refactoring and tests for the highly undertested file_util::CreateOrUpdateShortcutLink() method.
Simplify file_util::CreateOrUpdateShortcutLink()'s interface (use a struct to set parameters passed which allows callers to specify exactly what they want without having to pass in a bunch of NULLs for the unused parameters).
The same concept will be used for ShellUtil's shortcut functions in an upcoming CL.
Moved ShellUtil::VerifyChromeShortcut() to file_util::VerifyShortcut() and augmented it for every shortcut properties. This will also allow other shortcut creators (web apps, profiles, etc.) to have a broader test coverage on the shortcut they create (i.e. more testable properties available).
I will leave it up to the owners of these various projects to augment their tests, this CL keeps the previously tested behavior, not more, not less.
This is the 1st CL of a massive refactoring effort for shortcuts (http://goo.gl/Az889) in which ShellUtil's shortcut methods have to be refactored (http://codereview.chromium.org/10836247/ : soon to incorporate interface changes from this CL) which led me even lower to first refactor file_util's shortcut methods.
TBR=robertshield@chromium.org, sky@chromium.org, agl@chromium.org, dgrogan@chromium.org
BUG=132825, 148539
TEST=base_unittests --gtest_filter=FileUtilShortcutTest*
installer_util_unitests --gtest_filter=ShellUtilTestWithDirAndDist*
unit_tests --gtest_filter=ProfileShortcutManagerTest*
(run tests on XP as well)
Review URL: https://chromiumcodereview.appspot.com/10909171
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156250 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_unittest.cc')
-rw-r--r-- | base/file_util_unittest.cc | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index 5a99983..04de367 100644 --- a/base/file_util_unittest.cc +++ b/base/file_util_unittest.cc @@ -1592,75 +1592,6 @@ TEST_F(ReadOnlyFileUtilTest, TextContentsEqual) { // We don't need equivalent functionality outside of Windows. #if defined(OS_WIN) -TEST_F(FileUtilTest, ResolveShortcutTest) { - FilePath target_file = temp_dir_.path().Append(L"Target.txt"); - CreateTextFile(target_file, L"This is the target."); - - FilePath link_file = temp_dir_.path().Append(L"Link.lnk"); - - HRESULT result; - IShellLink* shell = NULL; - IPersistFile* persist = NULL; - - CoInitialize(NULL); - // Temporarily create a shortcut for test - result = CoCreateInstance(CLSID_ShellLink, NULL, - CLSCTX_INPROC_SERVER, IID_IShellLink, - reinterpret_cast<LPVOID*>(&shell)); - EXPECT_TRUE(SUCCEEDED(result)); - result = shell->QueryInterface(IID_IPersistFile, - reinterpret_cast<LPVOID*>(&persist)); - EXPECT_TRUE(SUCCEEDED(result)); - result = shell->SetPath(target_file.value().c_str()); - EXPECT_TRUE(SUCCEEDED(result)); - result = shell->SetDescription(L"ResolveShortcutTest"); - EXPECT_TRUE(SUCCEEDED(result)); - result = shell->SetArguments(L"--args"); - EXPECT_TRUE(SUCCEEDED(result)); - result = persist->Save(link_file.value().c_str(), TRUE); - EXPECT_TRUE(SUCCEEDED(result)); - if (persist) - persist->Release(); - if (shell) - shell->Release(); - - bool is_solved; - std::wstring args; - is_solved = file_util::ResolveShortcut(link_file, &link_file, &args); - EXPECT_TRUE(is_solved); - EXPECT_EQ(L"--args", args); - std::wstring contents; - contents = ReadTextFile(link_file); - EXPECT_EQ(L"This is the target.", contents); - - // Cleaning - DeleteFile(target_file.value().c_str()); - DeleteFile(link_file.value().c_str()); - CoUninitialize(); -} - -TEST_F(FileUtilTest, CreateShortcutTest) { - const wchar_t* file_contents = L"This is another target."; - FilePath target_file = temp_dir_.path().Append(L"Target1.txt"); - CreateTextFile(target_file, file_contents); - - FilePath link_file = temp_dir_.path().Append(L"Link1.lnk"); - - CoInitialize(NULL); - EXPECT_TRUE(file_util::CreateOrUpdateShortcutLink( - target_file.value().c_str(), link_file.value().c_str(), NULL, - NULL, NULL, NULL, 0, NULL, - file_util::SHORTCUT_CREATE_ALWAYS)); - FilePath resolved_name; - EXPECT_TRUE(file_util::ResolveShortcut(link_file, &resolved_name, NULL)); - std::wstring read_contents = ReadTextFile(resolved_name); - EXPECT_EQ(file_contents, read_contents); - - DeleteFile(target_file.value().c_str()); - DeleteFile(link_file.value().c_str()); - CoUninitialize(); -} - TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { // Create a directory FilePath dir_name_from = |