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

Side by Side Diff: chrome/installer/util/shell_util_unittest.cc

Issue 6793008: Replacing base::DIR_TEMP with ScopedTempDir when appropriate. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Needed to rebase; patch didn't apply cleanly to save_package_unittest. Created 9 years, 8 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <windows.h> 5 #include <windows.h>
6 #include <shellapi.h> 6 #include <shellapi.h>
7 #include <shlobj.h> 7 #include <shlobj.h>
8 8
9 #include <fstream> 9 #include <fstream>
10 10
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/scoped_comptr_win.h" 13 #include "base/scoped_comptr_win.h"
14 #include "base/memory/scoped_temp_dir.h"
14 #include "chrome/installer/util/browser_distribution.h" 15 #include "chrome/installer/util/browser_distribution.h"
15 #include "chrome/installer/util/master_preferences.h" 16 #include "chrome/installer/util/master_preferences.h"
16 #include "chrome/installer/util/shell_util.h" 17 #include "chrome/installer/util/shell_util.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace { 20 namespace {
20 bool VerifyChromeShortcut(const std::wstring& exe_path, 21 bool VerifyChromeShortcut(const std::wstring& exe_path,
21 const std::wstring& shortcut, 22 const std::wstring& shortcut,
22 const std::wstring& description, 23 const std::wstring& description,
23 int icon_index) { 24 int icon_index) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 EXPECT_FALSE(failed); 80 EXPECT_FALSE(failed);
80 if (failed) 81 if (failed)
81 return false; 82 return false;
82 83
83 return true; 84 return true;
84 } 85 }
85 86
86 class ShellUtilTest : public testing::Test { 87 class ShellUtilTest : public testing::Test {
87 protected: 88 protected:
88 virtual void SetUp() { 89 virtual void SetUp() {
89 // Name a subdirectory of the user temp directory. 90 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
90 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
91 test_dir_ = test_dir_.AppendASCII("ShellUtilTest");
92
93 // Create a fresh, empty copy of this test directory.
94 file_util::Delete(test_dir_, true);
95 file_util::CreateDirectoryW(test_dir_);
96 ASSERT_TRUE(file_util::PathExists(test_dir_));
97 } 91 }
98 92
99 virtual void TearDown() { 93 ScopedTempDir temp_dir_;
100 // Clean up test directory
101 ASSERT_TRUE(file_util::Delete(test_dir_, true));
102 ASSERT_FALSE(file_util::PathExists(test_dir_));
103 }
104
105 // The path to temporary directory used to contain the test operations.
106 FilePath test_dir_;
107 }; 94 };
108 }; 95 };
109 96
110 // Test that we can open archives successfully. 97 // Test that we can open archives successfully.
111 TEST_F(ShellUtilTest, UpdateChromeShortcutTest) { 98 TEST_F(ShellUtilTest, UpdateChromeShortcutTest) {
112 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 99 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
113 ASSERT_TRUE(dist != NULL); 100 ASSERT_TRUE(dist != NULL);
114 // Create an executable in test path by copying ourself to it. 101 // Create an executable in test path by copying ourself to it.
115 wchar_t exe_full_path_str[MAX_PATH]; 102 wchar_t exe_full_path_str[MAX_PATH];
116 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); 103 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0);
117 FilePath exe_full_path(exe_full_path_str); 104 FilePath exe_full_path(exe_full_path_str);
118 105
119 FilePath exe_path = test_dir_.AppendASCII("setup.exe"); 106 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe");
120 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); 107 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path));
121 108
122 FilePath shortcut_path = test_dir_.AppendASCII("shortcut.lnk"); 109 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk");
123 const std::wstring description(L"dummy description"); 110 const std::wstring description(L"dummy description");
124 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(), 111 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(),
125 shortcut_path.value(), 112 shortcut_path.value(),
126 description, true)); 113 description, true));
127 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 114 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
128 shortcut_path.value(), 115 shortcut_path.value(),
129 description, 0)); 116 description, 0));
130 117
131 // Now specify an icon index in master prefs and make sure it works. 118 // Now specify an icon index in master prefs and make sure it works.
132 FilePath prefs_path = test_dir_.AppendASCII( 119 FilePath prefs_path = temp_dir_.path().AppendASCII(
133 installer::kDefaultMasterPrefs); 120 installer::kDefaultMasterPrefs);
134 std::ofstream file; 121 std::ofstream file;
135 file.open(prefs_path.value().c_str()); 122 file.open(prefs_path.value().c_str());
136 ASSERT_TRUE(file.is_open()); 123 ASSERT_TRUE(file.is_open());
137 file << 124 file <<
138 "{" 125 "{"
139 " \"distribution\":{" 126 " \"distribution\":{"
140 " \"chrome_shortcut_icon_index\" : 1" 127 " \"chrome_shortcut_icon_index\" : 1"
141 " }" 128 " }"
142 "}"; 129 "}";
143 file.close(); 130 file.close();
144 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); 131 ASSERT_TRUE(file_util::Delete(shortcut_path, false));
145 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(), 132 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(),
146 shortcut_path.value(), 133 shortcut_path.value(),
147 description, true)); 134 description, true));
148 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 135 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
149 shortcut_path.value(), 136 shortcut_path.value(),
150 description, 1)); 137 description, 1));
151 138
152 // Now change only description to update shortcut and make sure icon index 139 // Now change only description to update shortcut and make sure icon index
153 // doesn't change. 140 // doesn't change.
154 const std::wstring description2(L"dummy description 2"); 141 const std::wstring description2(L"dummy description 2");
155 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(), 142 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(),
156 shortcut_path.value(), 143 shortcut_path.value(),
157 description2, false)); 144 description2, false));
158 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 145 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
159 shortcut_path.value(), 146 shortcut_path.value(),
160 description2, 1)); 147 description2, 1));
161 } 148 }
OLDNEW
« no previous file with comments | « chrome/installer/util/move_tree_work_item_unittest.cc ('k') | chrome/installer/util/work_item_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698