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

Side by Side Diff: chrome/test/mini_installer_test/mini_installer_test_util.cc

Issue 329037: Add a command-line option for specifying a particular build to test and for p... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/test/mini_installer_test/mini_installer_test_util.h" 5 #include "chrome/test/mini_installer_test/mini_installer_test_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/platform_thread.h" 9 #include "base/platform_thread.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 28 matching lines...) Expand all
39 timer = timer + 200; 39 timer = timer + 200;
40 } 40 }
41 ASSERT_EQ(0, base::GetProcessCount(executable_name, NULL)); 41 ASSERT_EQ(0, base::GetProcessCount(executable_name, NULL));
42 } 42 }
43 43
44 bool MiniInstallerTestUtil::CloseWindow(const wchar_t* window_name, 44 bool MiniInstallerTestUtil::CloseWindow(const wchar_t* window_name,
45 UINT message) { 45 UINT message) {
46 int timer = 0; 46 int timer = 0;
47 bool return_val = false; 47 bool return_val = false;
48 HWND hndl = FindWindow(NULL, window_name); 48 HWND hndl = FindWindow(NULL, window_name);
49 while (hndl == NULL && (timer < 60000)) { 49 while (hndl == NULL && (timer < 20000)) {
50 hndl = FindWindow(NULL, window_name); 50 hndl = FindWindow(NULL, window_name);
51 PlatformThread::Sleep(200); 51 PlatformThread::Sleep(200);
52 timer = timer + 200; 52 timer = timer + 200;
53 } 53 }
54 if (hndl != NULL) { 54 if (hndl != NULL) {
55 LRESULT _result = SendMessage(hndl, message, 1, 0); 55 LRESULT _result = SendMessage(hndl, message, 1, 0);
56 return_val = true; 56 return_val = true;
57 } 57 }
58 return return_val; 58 return return_val;
59 } 59 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 // This method will first call GetLatestFile to get the list of all 95 // This method will first call GetLatestFile to get the list of all
96 // builds, sorted on creation time. Then goes through each build folder 96 // builds, sorted on creation time. Then goes through each build folder
97 // until it finds the installer file that matches the pattern argument. 97 // until it finds the installer file that matches the pattern argument.
98 bool MiniInstallerTestUtil::GetInstaller(const wchar_t* pattern, 98 bool MiniInstallerTestUtil::GetInstaller(const wchar_t* pattern,
99 std::wstring *path, const wchar_t* channel_type) { 99 std::wstring *path, const wchar_t* channel_type) {
100 FileInfoList builds_list; 100 FileInfoList builds_list;
101 FileInfoList exe_list; 101 FileInfoList exe_list;
102 std::wstring chrome_diff_installer( 102 std::wstring chrome_diff_installer(
103 mini_installer_constants::kChromeDiffInstallerLocation); 103 mini_installer_constants::kChromeDiffInstallerLocation);
104
104 chrome_diff_installer.append(L"*"); 105 chrome_diff_installer.append(L"*");
105 if (!GetLatestFile(chrome_diff_installer.c_str(), 106 if (!GetLatestFile(chrome_diff_installer.c_str(),
106 channel_type, &builds_list)) 107 channel_type, &builds_list))
107 return false; 108 return false;
109
108 FileInfoList::const_reverse_iterator builds_list_size = builds_list.rbegin(); 110 FileInfoList::const_reverse_iterator builds_list_size = builds_list.rbegin();
109 while (builds_list_size != builds_list.rend()) { 111 while (builds_list_size != builds_list.rend()) {
110 path->assign(mini_installer_constants::kChromeDiffInstallerLocation); 112 path->assign(mini_installer_constants::kChromeDiffInstallerLocation);
111 file_util::AppendToPath(path, builds_list_size->name_); 113 file_util::AppendToPath(path, builds_list_size->name_);
112 if (channel_type == mini_installer_constants::kDevChannelBuild) 114 file_util::AppendToPath(path, L"win");
113 file_util::AppendToPath(path, L"win");
114 std::wstring installer_path(path->c_str()); 115 std::wstring installer_path(path->c_str());
115 file_util::AppendToPath(&installer_path, L"*.exe"); 116 file_util::AppendToPath(&installer_path, L"*.exe");
116 if (!GetLatestFile(installer_path.c_str(), pattern, &exe_list)) { 117 if (!GetLatestFile(installer_path.c_str(), pattern, &exe_list)) {
117 ++builds_list_size; 118 ++builds_list_size;
118 } else { 119 } else {
119 file_util::AppendToPath(path, exe_list.at(0).name_.c_str()); 120 file_util::AppendToPath(path, exe_list.at(0).name_.c_str());
120 if (!file_util::PathExists(FilePath::FromWStringHack(*path))) { 121 if (!file_util::PathExists(FilePath::FromWStringHack(*path))) {
121 ++builds_list_size; 122 ++builds_list_size;
122 } else { 123 } else {
123 break; 124 break;
124 } 125 }
125 } 126 }
126 } 127 }
127 return file_util::PathExists(FilePath::FromWStringHack(*path)); 128 return file_util::PathExists(FilePath::FromWStringHack(*path));
128 } 129 }
129 130
130 // This method will get the latest installer filename from the directory. 131 // This method will get the latest installer filename from the directory.
131 bool MiniInstallerTestUtil::GetLatestFile(const wchar_t* file_name, 132 bool MiniInstallerTestUtil::GetLatestFile(const wchar_t* file_name,
132 const wchar_t* pattern, FileInfoList *file_details) { 133 const wchar_t* pattern, FileInfoList *file_details) {
134
133 WIN32_FIND_DATA find_file_data; 135 WIN32_FIND_DATA find_file_data;
134 HANDLE file_handle = FindFirstFile(file_name, &find_file_data); 136 HANDLE file_handle = FindFirstFile(file_name, &find_file_data);
135 if (file_handle == INVALID_HANDLE_VALUE) { 137 if (file_handle == INVALID_HANDLE_VALUE) {
136 LOG(INFO) << "Handle is invalid."; 138 LOG(INFO) << "Handle is invalid.";
137 return false; 139 return false;
138 } 140 }
139 BOOL ret = TRUE; 141 BOOL ret = TRUE;
140 bool return_val = false; 142 bool return_val = false;
141 while (ret) { 143 while (ret) {
142 std::wstring search_path = find_file_data.cFileName; 144 std::wstring search_path = find_file_data.cFileName;
(...skipping 12 matching lines...) Expand all
155 return_val = true; 157 return_val = true;
156 } 158 }
157 } 159 }
158 ret = FindNextFile(file_handle, &find_file_data); 160 ret = FindNextFile(file_handle, &find_file_data);
159 } 161 }
160 std::sort(file_details->rbegin(), file_details->rend(), &IsNewer); 162 std::sort(file_details->rbegin(), file_details->rend(), &IsNewer);
161 FindClose(file_handle); 163 FindClose(file_handle);
162 return return_val; 164 return return_val;
163 } 165 }
164 166
165 void MiniInstallerTestUtil::GetPreviousBuildNumber(const std::wstring& path, 167 // This method retrieves the previous build version for the given diff
166 std::wstring *build_number, const wchar_t* channel_type) { 168 // installer path.
167 std::wstring diff_installer_name = file_util::GetFilenameFromPath(path); 169 bool MiniInstallerTestUtil::GetPreviousBuildNumber(const std::wstring& path,
168 std::wstring::size_type start_position = diff_installer_name.find(L"f"); 170 std::wstring *build_number) {
169 std::wstring::size_type end_position = diff_installer_name.find(L"_c"); 171
170 end_position = end_position - start_position; 172 std::wstring diff_name = file_util::GetFilenameFromPath(path);
171 std::wstring file_name = diff_installer_name.substr(start_position, 173 // We want to remove 'from_', so add its length to found index (which is 5)
172 end_position); 174 std::wstring::size_type start_position = diff_name.find(L"from_") + 5;
173 file_name = file_name.substr(file_name.find(L'_')+1, file_name.size()); 175 std::wstring::size_type end_position = diff_name.find(L"_c");
174 file_name = channel_type + file_name; 176 std::wstring::size_type size = end_position - start_position;
175 build_number->assign(file_name); 177
176 LOG(INFO) << "Previous build number: " << file_name.c_str(); 178 std::wstring build_no = diff_name.substr(start_position, size);
179
180 // Search for a build folder with this build suffix.
181 std::wstring pattern = L"*" + build_no;
182
183 file_util::FileEnumerator files(FilePath(
184 mini_installer_constants::kChromeDiffInstallerLocation),
185 false, file_util::FileEnumerator::DIRECTORIES, pattern);
186 FilePath folder = files.Next();
187 if (folder.empty())
188 return false;
189
190 build_number->assign(folder.BaseName().ToWStringHack());
191 return true;
177 } 192 }
178 193
194
179 // This method will get the previous full installer path 195 // This method will get the previous full installer path
180 // from given diff installer path. It will first get the 196 // from given diff installer path. It will first get the
181 // filename from the diff installer path, gets the previous 197 // filename from the diff installer path, gets the previous
182 // build information from the filename, then computes the 198 // build information from the filename, then computes the
183 // path for previous full installer. 199 // path for previous full installer.
184 bool MiniInstallerTestUtil::GetPreviousFullInstaller( 200 bool MiniInstallerTestUtil::GetPreviousFullInstaller(
185 const std::wstring& diff_file_name, std::wstring *previous, 201 const std::wstring& diff_path, std::wstring *previous) {
186 const wchar_t* channel_type) { 202 std::wstring build_no;
187 std::wstring diff_file = diff_file_name; 203
188 std::wstring build_number; 204 if (!GetPreviousBuildNumber(diff_path, &build_no))
189 GetPreviousBuildNumber(diff_file, &build_number, channel_type);
190 file_util::UpOneDirectory(&diff_file);
191 file_util::UpOneDirectory(&diff_file);
192 if (channel_type == mini_installer_constants::kDevChannelBuild)
193 file_util::UpOneDirectory(&diff_file);
194 file_util::AppendToPath(&diff_file, build_number.c_str());
195 if (channel_type == mini_installer_constants::kDevChannelBuild)
196 file_util::AppendToPath(&diff_file, L"win");
197 previous->assign(diff_file);
198 file_util::AppendToPath(&diff_file, L"*.exe");
199 FileInfoList directory_list;
200 if (!GetLatestFile(diff_file.c_str(),
201 mini_installer_constants::kFullInstallerPattern,
202 &directory_list))
203 return false; 205 return false;
204 file_util::AppendToPath(previous, directory_list.at(0).name_); 206
205 return file_util::PathExists(FilePath::FromWStringHack(*previous)); 207 // Use the fifth and onward characters of the build version string
208 // to compose the full installer name.
209 std::wstring name = build_no.substr(4) +
210 mini_installer_constants::kFullInstallerPattern + L".exe";
211
212 // Create the full installer path.
213 FilePath installer = FilePath(
214 mini_installer_constants::kChromeDiffInstallerLocation);
215 installer = installer.Append(build_no).Append(L"win").Append(name);
216 previous->assign(installer.value());
217
218 return file_util::PathExists(installer);
206 } 219 }
207 220
208 bool MiniInstallerTestUtil::GetStandaloneInstallerFileName( 221 bool MiniInstallerTestUtil::GetStandaloneInstallerFileName(
209 FileInfoList *file_name) { 222 FileInfoList *file_name) {
210 std::wstring standalone_installer( 223 std::wstring standalone_installer(
211 mini_installer_constants::kChromeStandAloneInstallerLocation); 224 mini_installer_constants::kChromeStandAloneInstallerLocation);
212 standalone_installer.append(L"*.exe"); 225 standalone_installer.append(L"*.exe");
213 return GetLatestFile(standalone_installer.c_str(), 226 return GetLatestFile(standalone_installer.c_str(),
214 mini_installer_constants::kUntaggedInstallerPattern, 227 mini_installer_constants::kUntaggedInstallerPattern,
215 file_name); 228 file_name);
216 } 229 }
217 230
218 bool MiniInstallerTestUtil::GetStandaloneVersion( 231 bool MiniInstallerTestUtil::GetStandaloneVersion(
219 std::wstring* return_file_name) { 232 std::wstring* return_file_name) {
220 FileInfoList file_details; 233 FileInfoList file_details;
221 GetStandaloneInstallerFileName(&file_details); 234 GetStandaloneInstallerFileName(&file_details);
222 std::wstring file_name = file_details.at(0).name_; 235 std::wstring file_name = file_details.at(0).name_;
223 // Returned file name will have following convention: 236 // Returned file name will have following convention:
224 // ChromeStandaloneSetup_<build>_<patch>.exe 237 // ChromeStandaloneSetup_<build>_<patch>.exe
225 // Following code will extract build, patch details from the file 238 // Following code will extract build, patch details from the file
226 // and concatenate with 1.0 to form the build version. 239 // and concatenate with 1.0 to form the build version.
227 // Patteren followed: 1.0.<build>.<patch>htt 240 // Patteren followed: 1.0.<build>.<patch>htt
228 file_name = file_name.substr(22, 25); 241 file_name = file_name.substr(22, 25);
229 std::wstring::size_type last_dot = file_name.find(L'.'); 242 std::wstring::size_type last_dot = file_name.find(L'.');
230 file_name = file_name.substr(0, last_dot); 243 file_name = file_name.substr(0, last_dot);
231 std::wstring::size_type pos = file_name.find(L'_'); 244 std::wstring::size_type pos = file_name.find(L'_');
232 file_name.replace(pos, 1, L"."); 245 file_name.replace(pos, 1, L".");
233 file_name = L"2.0." + file_name; 246 file_name = L"3.0." + file_name;
234 return_file_name->assign(file_name.c_str()); 247 return_file_name->assign(file_name.c_str());
235 LOG(INFO) << "Standalone installer version: " << file_name.c_str(); 248 LOG(INFO) << "Standalone installer version: " << file_name.c_str();
236 return true; 249 return true;
237 } 250 }
238 251
239 void MiniInstallerTestUtil::SendEnterKeyToWindow() { 252 void MiniInstallerTestUtil::SendEnterKeyToWindow() {
240 INPUT key; 253 INPUT key;
241 key.type = INPUT_KEYBOARD; 254 key.type = INPUT_KEYBOARD;
242 key.ki.wVk = VK_RETURN; 255 key.ki.wVk = VK_RETURN;
243 key.ki.dwFlags = 0; 256 key.ki.dwFlags = 0;
244 key.ki.time = 0; 257 key.ki.time = 0;
245 key.ki.wScan = 0; 258 key.ki.wScan = 0;
246 key.ki.dwExtraInfo = 0; 259 key.ki.dwExtraInfo = 0;
247 SendInput(1, &key, sizeof(INPUT)); 260 SendInput(1, &key, sizeof(INPUT));
248 key.ki.dwExtraInfo = KEYEVENTF_KEYUP; 261 key.ki.dwExtraInfo = KEYEVENTF_KEYUP;
249 SendInput(1, &key, sizeof(INPUT)); 262 SendInput(1, &key, sizeof(INPUT));
250 } 263 }
251 264
265
252 void MiniInstallerTestUtil::VerifyProcessLaunch( 266 void MiniInstallerTestUtil::VerifyProcessLaunch(
253 const wchar_t* process_name, bool expected_status) { 267 const wchar_t* process_name, bool expected_status) {
254 int timer = 0, wait_time = 60000; 268 int timer = 0, wait_time = 60000;
255 if (!expected_status) 269 if (!expected_status)
256 wait_time = 8000; 270 wait_time = 8000;
271
257 while ((base::GetProcessCount(process_name, NULL) == 0) && 272 while ((base::GetProcessCount(process_name, NULL) == 0) &&
258 (timer < wait_time)) { 273 (timer < wait_time)) {
259 PlatformThread::Sleep(200); 274 PlatformThread::Sleep(200);
260 timer = timer + 200; 275 timer = timer + 200;
261 } 276 }
277
262 if (expected_status) 278 if (expected_status)
263 ASSERT_NE(0, base::GetProcessCount(process_name, NULL)); 279 ASSERT_NE(0, base::GetProcessCount(process_name, NULL));
264 else 280 else
265 ASSERT_EQ(0, base::GetProcessCount(process_name, NULL)); 281 ASSERT_EQ(0, base::GetProcessCount(process_name, NULL));
266 } 282 }
267 283
268 bool MiniInstallerTestUtil::VerifyProcessClose( 284 bool MiniInstallerTestUtil::VerifyProcessClose(
269 const wchar_t* process_name) { 285 const wchar_t* process_name) {
270 int timer = 0; 286 int timer = 0;
271 if (base::GetProcessCount(process_name, NULL) > 0) { 287 if (base::GetProcessCount(process_name, NULL) > 0) {
272 LOG(INFO) << "Waiting for this process to end: " << process_name; 288 LOG(INFO) << "Waiting for this process to end: " << process_name;
273 while ((base::GetProcessCount(process_name, NULL) > 0) && 289 while ((base::GetProcessCount(process_name, NULL) > 0) &&
274 (timer < 60000)) { 290 (timer < 60000)) {
275 PlatformThread::Sleep(200); 291 PlatformThread::Sleep(200);
276 timer = timer + 200; 292 timer = timer + 200;
277 } 293 }
278 } else { 294 } else {
279 if (base::GetProcessCount(process_name, NULL) != 0) 295 if (base::GetProcessCount(process_name, NULL) != 0)
280 return false; 296 return false;
281 } 297 }
282 return true; 298 return true;
283 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698