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

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

Issue 3080025: Get rid of FromWStringHack in chrome_mini_installer.cc. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: Created 10 years, 4 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
« no previous file with comments | « chrome/test/mini_installer_test/chrome_mini_installer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/chrome_mini_installer.h" 5 #include "chrome/test/mini_installer_test/chrome_mini_installer.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"
11 #include "base/registry.h" 11 #include "base/registry.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "chrome/installer/util/browser_distribution.h" 14 #include "chrome/installer/util/browser_distribution.h"
15 #include "chrome/installer/util/google_update_constants.h" 15 #include "chrome/installer/util/google_update_constants.h"
16 #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" 16 #include "chrome/test/mini_installer_test/mini_installer_test_constants.h"
17 #include "chrome/test/mini_installer_test/mini_installer_test_util.h" 17 #include "chrome/test/mini_installer_test/mini_installer_test_util.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 // Constructor.
21 ChromeMiniInstaller::ChromeMiniInstaller(const std::wstring& install_type, 20 ChromeMiniInstaller::ChromeMiniInstaller(const std::wstring& install_type,
22 bool is_chrome_frame) : is_chrome_frame_(is_chrome_frame), 21 bool is_chrome_frame)
23 install_type_(install_type) { 22 : is_chrome_frame_(is_chrome_frame),
23 install_type_(install_type),
24 has_diff_installer_(false),
25 has_full_installer_(false),
26 has_prev_installer_(false) {
24 installer_name_ = StringPrintf(L"%ls (%ls)", 27 installer_name_ = StringPrintf(L"%ls (%ls)",
25 mini_installer_constants::kChromeBuildType, install_type_.c_str()); 28 mini_installer_constants::kChromeBuildType, install_type_.c_str());
26
27 has_diff_installer_ = false;
28 has_full_installer_ = false;
29 has_prev_installer_ = false;
30 } 29 }
31 30
32 void ChromeMiniInstaller::SetBuildUnderTest(const std::wstring& build) { 31 void ChromeMiniInstaller::SetBuildUnderTest(const std::wstring& build) {
33 // Locate the full, diff, and previous installers. 32 // Locate the full, diff, and previous installers.
34 const wchar_t * build_prefix; 33 const wchar_t * build_prefix;
35 if (LowerCaseEqualsASCII(build, "dev")) 34 if (LowerCaseEqualsASCII(build, "dev"))
36 build_prefix = mini_installer_constants::kDevChannelBuild; 35 build_prefix = mini_installer_constants::kDevChannelBuild;
37 else if (LowerCaseEqualsASCII(build, "stable")) 36 else if (LowerCaseEqualsASCII(build, "stable"))
38 build_prefix = mini_installer_constants::kStableChannelBuild; 37 build_prefix = mini_installer_constants::kStableChannelBuild;
39 else if (LowerCaseEqualsASCII(build, "latest")) 38 else if (LowerCaseEqualsASCII(build, "latest"))
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 InstallMiniInstaller(over_install, full_installer_); 130 InstallMiniInstaller(over_install, full_installer_);
132 } 131 }
133 132
134 // Installs the Chrome mini-installer, checks the registry and shortcuts. 133 // Installs the Chrome mini-installer, checks the registry and shortcuts.
135 void ChromeMiniInstaller::InstallMiniInstaller(bool over_install, 134 void ChromeMiniInstaller::InstallMiniInstaller(bool over_install,
136 const std::wstring& path) { 135 const std::wstring& path) {
137 std::wstring exe_name = file_util::GetFilenameFromPath(path); 136 std::wstring exe_name = file_util::GetFilenameFromPath(path);
138 printf("\nChrome will be installed at %ls level\n", install_type_.c_str()); 137 printf("\nChrome will be installed at %ls level\n", install_type_.c_str());
139 printf("\nWill proceed with the test only if this path exists: %ls\n\n", 138 printf("\nWill proceed with the test only if this path exists: %ls\n\n",
140 path.c_str()); 139 path.c_str());
141 ASSERT_TRUE(file_util::PathExists(FilePath::FromWStringHack(path))); 140 ASSERT_TRUE(file_util::PathExists(FilePath(path)));
142 LaunchInstaller(path, exe_name.c_str()); 141 LaunchInstaller(path, exe_name.c_str());
143 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 142 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
144 ASSERT_TRUE(CheckRegistryKey(dist->GetVersionKey())); 143 ASSERT_TRUE(CheckRegistryKey(dist->GetVersionKey()));
145 VerifyInstall(over_install); 144 VerifyInstall(over_install);
146 } 145 }
147 146
148 // This method tests the standalone installer by verifying the steps listed at: 147 // This method tests the standalone installer by verifying the steps listed at:
149 // https://sites.google.com/a/google.com/chrome-pmo/ 148 // https://sites.google.com/a/google.com/chrome-pmo/
150 // standalone-installers/testing-standalone-installers 149 // standalone-installers/testing-standalone-installers
151 // This method applies appropriate tags to standalone installer and deletes 150 // This method applies appropriate tags to standalone installer and deletes
152 // old installer before running the new tagged installer. It also verifies 151 // old installer before running the new tagged installer. It also verifies
153 // that the installed version is correct. 152 // that the installed version is correct.
154 void ChromeMiniInstaller::InstallStandaloneInstaller() { 153 void ChromeMiniInstaller::InstallStandaloneInstaller() {
155 standalone_installer = true;
156 file_util::Delete(mini_installer_constants::kStandaloneInstaller, true); 154 file_util::Delete(mini_installer_constants::kStandaloneInstaller, true);
157 std::wstring tag_installer_command; 155 std::wstring tag_installer_command;
158 ASSERT_TRUE(MiniInstallerTestUtil::GetCommandForTagging( 156 ASSERT_TRUE(MiniInstallerTestUtil::GetCommandForTagging(
159 &tag_installer_command)); 157 &tag_installer_command));
160 base::LaunchApp(tag_installer_command, true, false, NULL); 158 base::LaunchApp(tag_installer_command, true, false, NULL);
161 std::wstring installer_path = MiniInstallerTestUtil::GetFilePath( 159 std::wstring installer_path = MiniInstallerTestUtil::GetFilePath(
162 mini_installer_constants::kStandaloneInstaller); 160 mini_installer_constants::kStandaloneInstaller);
163 InstallMiniInstaller(false, installer_path); 161 InstallMiniInstaller(false, installer_path);
164 ASSERT_TRUE(VerifyStandaloneInstall()); 162 ASSERT_TRUE(VerifyStandaloneInstall());
165 file_util::Delete(mini_installer_constants::kStandaloneInstaller, true); 163 file_util::Delete(mini_installer_constants::kStandaloneInstaller, true);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 MiniInstallerTestUtil::CloseProcesses(L"IEXPLORE.EXE"); 249 MiniInstallerTestUtil::CloseProcesses(L"IEXPLORE.EXE");
252 MiniInstallerTestUtil::CloseProcesses(installer_util::kChromeExe); 250 MiniInstallerTestUtil::CloseProcesses(installer_util::kChromeExe);
253 MiniInstallerTestUtil::CloseProcesses(installer_util::kNaClExe); 251 MiniInstallerTestUtil::CloseProcesses(installer_util::kNaClExe);
254 std::wstring uninstall_path = GetUninstallPath(); 252 std::wstring uninstall_path = GetUninstallPath();
255 if (uninstall_path == L"") { 253 if (uninstall_path == L"") {
256 printf("\n %ls install is in a weird state. Cleaning the machine...\n", 254 printf("\n %ls install is in a weird state. Cleaning the machine...\n",
257 product_name.c_str()); 255 product_name.c_str());
258 CleanChromeInstall(); 256 CleanChromeInstall();
259 return; 257 return;
260 } 258 }
261 ASSERT_TRUE(file_util::PathExists(FilePath::FromWStringHack(uninstall_path))); 259 ASSERT_TRUE(file_util::PathExists(FilePath(uninstall_path)));
262 std::wstring uninstall_args(L"\""); 260 std::wstring uninstall_args(L"\"");
263 uninstall_args.append(uninstall_path); 261 uninstall_args.append(uninstall_path);
264 uninstall_args.append(L"\" --uninstall --force-uninstall"); 262 uninstall_args.append(L"\" --uninstall --force-uninstall");
265 if (is_chrome_frame_) 263 if (is_chrome_frame_)
266 uninstall_args.append(L" --chrome-frame"); 264 uninstall_args.append(L" --chrome-frame");
267 if (install_type_ == mini_installer_constants::kSystemInstall) 265 if (install_type_ == mini_installer_constants::kSystemInstall)
268 uninstall_args = uninstall_args + L" --system-level"; 266 uninstall_args = uninstall_args + L" --system-level";
269 base::LaunchApp(uninstall_args, false, false, NULL); 267 base::LaunchApp(uninstall_args, false, false, NULL);
270 if (is_chrome_frame_) 268 if (is_chrome_frame_)
271 ASSERT_TRUE(CloseUninstallWindow()); 269 ASSERT_TRUE(CloseUninstallWindow());
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 pv_key.append(dist->GetAppGuid()); 428 pv_key.append(dist->GetAppGuid());
431 429
432 RegKey key; 430 RegKey key;
433 if (key.Open(GetRootRegistryKey(), pv_key.c_str(), KEY_ALL_ACCESS)) 431 if (key.Open(GetRootRegistryKey(), pv_key.c_str(), KEY_ALL_ACCESS))
434 ASSERT_TRUE(key.DeleteValue(L"pv")); 432 ASSERT_TRUE(key.DeleteValue(L"pv"));
435 printf("Deleted %ls key\n", pv_key.c_str()); 433 printf("Deleted %ls key\n", pv_key.c_str());
436 } 434 }
437 435
438 // Verifies if Chrome shortcut exists. 436 // Verifies if Chrome shortcut exists.
439 void ChromeMiniInstaller::FindChromeShortcut() { 437 void ChromeMiniInstaller::FindChromeShortcut() {
440 std::wstring username, path, append_path, uninstall_lnk, shortcut_path;
441 bool return_val = false; 438 bool return_val = false;
442 path = GetStartMenuShortcutPath(); 439 FilePath uninstall_lnk;
443 file_util::AppendToPath(&path, mini_installer_constants::kChromeBuildType); 440 FilePath path = GetStartMenuShortcutPath();
441 path = path.Append(mini_installer_constants::kChromeBuildType);
444 // Verify if path exists. 442 // Verify if path exists.
445 if (file_util::PathExists(FilePath::FromWStringHack(path))) { 443 if (file_util::PathExists(path)) {
446 return_val = true; 444 return_val = true;
447 uninstall_lnk = path; 445 uninstall_lnk = path;
448 file_util::AppendToPath(&path, 446 path = path.Append(mini_installer_constants::kChromeLaunchShortcut);
449 mini_installer_constants::kChromeLaunchShortcut); 447 uninstall_lnk = uninstall_lnk.Append(
450 file_util::AppendToPath(&uninstall_lnk, 448 mini_installer_constants::kChromeUninstallShortcut);
451 mini_installer_constants::kChromeUninstallShortcut); 449 ASSERT_TRUE(file_util::PathExists(path));
452 ASSERT_TRUE(file_util::PathExists(FilePath::FromWStringHack(path))); 450 ASSERT_TRUE(file_util::PathExists(uninstall_lnk));
453 ASSERT_TRUE(file_util::PathExists(
454 FilePath::FromWStringHack(uninstall_lnk)));
455 } 451 }
456 if (return_val) 452 if (return_val) {
457 printf("Chrome shortcuts found are:\n%ls\n%ls\n\n", 453 printf("Chrome shortcuts found are:\n%ls\n%ls\n\n",
458 path.c_str(), uninstall_lnk.c_str()); 454 path.value().c_str(), uninstall_lnk.value().c_str());
459 else 455 } else {
460 printf("Chrome shortcuts not found\n\n"); 456 printf("Chrome shortcuts not found\n\n");
457 }
461 } 458 }
462 459
463 // This method returns path to either program files 460 // This method returns path to either program files
464 // or documents and setting based on the install type. 461 // or documents and setting based on the install type.
465 std::wstring ChromeMiniInstaller::GetChromeInstallDirectoryLocation() { 462 std::wstring ChromeMiniInstaller::GetChromeInstallDirectoryLocation() {
466 FilePath path; 463 FilePath path;
467 if (install_type_ == mini_installer_constants::kSystemInstall) 464 if (install_type_ == mini_installer_constants::kSystemInstall)
468 PathService::Get(base::DIR_PROGRAM_FILES, &path); 465 PathService::Get(base::DIR_PROGRAM_FILES, &path);
469 else 466 else
470 PathService::Get(base::DIR_LOCAL_APP_DATA, &path); 467 PathService::Get(base::DIR_LOCAL_APP_DATA, &path);
471 return path.ToWStringHack(); 468 return path.ToWStringHack();
472 } 469 }
473 470
474 // This method gets the shortcut path from startmenu based on install type 471 FilePath ChromeMiniInstaller::GetStartMenuShortcutPath() {
475 std::wstring ChromeMiniInstaller::GetStartMenuShortcutPath() {
476 FilePath path_name; 472 FilePath path_name;
477 if (install_type_ == mini_installer_constants::kSystemInstall) 473 if (install_type_ == mini_installer_constants::kSystemInstall)
478 PathService::Get(base::DIR_COMMON_START_MENU, &path_name); 474 PathService::Get(base::DIR_COMMON_START_MENU, &path_name);
479 else 475 else
480 PathService::Get(base::DIR_START_MENU, &path_name); 476 PathService::Get(base::DIR_START_MENU, &path_name);
481 return path_name.ToWStringHack(); 477 return path_name;
482 } 478 }
483 479
484 // Gets the path for uninstall. 480 // Gets the path for uninstall.
485 std::wstring ChromeMiniInstaller::GetUninstallPath() { 481 std::wstring ChromeMiniInstaller::GetUninstallPath() {
486 std::wstring username, append_path, path, reg_key_value; 482 std::wstring path, reg_key_value;
487 if (!GetChromeVersionFromRegistry(&reg_key_value)) 483 if (!GetChromeVersionFromRegistry(&reg_key_value))
488 return L""; 484 return std::wstring();
489 path = GetChromeInstallDirectoryLocation(); 485 path = GetChromeInstallDirectoryLocation();
490 if (is_chrome_frame_) 486 if (is_chrome_frame_) {
491 file_util::AppendToPath(&path, 487 file_util::AppendToPath(&path,
492 mini_installer_constants::kChromeFrameAppDir); 488 mini_installer_constants::kChromeFrameAppDir);
493 else 489 } else {
494 file_util::AppendToPath(&path, mini_installer_constants::kChromeAppDir); 490 file_util::AppendToPath(&path, mini_installer_constants::kChromeAppDir);
491 }
495 file_util::AppendToPath(&path, reg_key_value); 492 file_util::AppendToPath(&path, reg_key_value);
496 file_util::AppendToPath(&path, installer_util::kInstallerDir); 493 file_util::AppendToPath(&path, installer_util::kInstallerDir);
497 file_util::AppendToPath(&path, 494 file_util::AppendToPath(&path,
498 mini_installer_constants::kChromeSetupExecutable); 495 mini_installer_constants::kChromeSetupExecutable);
499 if (!file_util::PathExists(FilePath::FromWStringHack(path))) { 496 if (!file_util::PathExists(FilePath(path))) {
500 printf("This uninstall path is not correct %ls. Will not proceed further", 497 printf("This uninstall path is not correct %ls. Will not proceed further",
501 path.c_str()); 498 path.c_str());
502 return L""; 499 return L"";
503 } 500 }
504 printf("uninstall path is %ls\n", path.c_str()); 501 printf("uninstall path is %ls\n", path.c_str());
505 return path; 502 return path;
506 } 503 }
507 504
508 // Returns Chrome pv registry key value 505 // Returns Chrome pv registry key value
509 bool ChromeMiniInstaller::GetChromeVersionFromRegistry( 506 bool ChromeMiniInstaller::GetChromeVersionFromRegistry(
(...skipping 12 matching lines...) Expand all
522 HKEY ChromeMiniInstaller::GetRootRegistryKey() { 519 HKEY ChromeMiniInstaller::GetRootRegistryKey() {
523 HKEY type = HKEY_CURRENT_USER; 520 HKEY type = HKEY_CURRENT_USER;
524 if (install_type_ == mini_installer_constants::kSystemInstall) 521 if (install_type_ == mini_installer_constants::kSystemInstall)
525 type = HKEY_LOCAL_MACHINE; 522 type = HKEY_LOCAL_MACHINE;
526 return type; 523 return type;
527 } 524 }
528 525
529 // Launches the chrome installer and waits for it to end. 526 // Launches the chrome installer and waits for it to end.
530 void ChromeMiniInstaller::LaunchInstaller(const std::wstring& path, 527 void ChromeMiniInstaller::LaunchInstaller(const std::wstring& path,
531 const wchar_t* process_name) { 528 const wchar_t* process_name) {
532 ASSERT_TRUE(file_util::PathExists(FilePath::FromWStringHack(path))); 529 ASSERT_TRUE(file_util::PathExists(FilePath(path)));
533 if (install_type_ == mini_installer_constants::kSystemInstall) { 530 if (install_type_ == mini_installer_constants::kSystemInstall) {
534 std::wstring launch_args; 531 std::wstring launch_args;
535 if (is_chrome_frame_) { 532 if (is_chrome_frame_) {
536 launch_args.append(L" --do-not-create-shortcuts"); 533 launch_args.append(L" --do-not-create-shortcuts");
537 launch_args.append(L" --do-not-register-for-update-launch"); 534 launch_args.append(L" --do-not-register-for-update-launch");
538 launch_args.append(L" --chrome-frame"); 535 launch_args.append(L" --chrome-frame");
539 } 536 }
540 launch_args.append(L" --system-level"); 537 launch_args.append(L" --system-level");
541 base::LaunchApp(L"\"" + path + L"\"" + launch_args, false, false, NULL); 538 base::LaunchApp(L"\"" + path + L"\"" + launch_args, false, false, NULL);
542 } else { 539 } else {
543 base::LaunchApp(L"\"" + path + L"\"", false, false, NULL); 540 base::LaunchApp(L"\"" + path + L"\"", false, false, NULL);
544 } 541 }
545 printf("Waiting while this process is running %ls ....\n", process_name); 542 printf("Waiting while this process is running %ls ....\n", process_name);
546 MiniInstallerTestUtil::VerifyProcessLaunch(process_name, true); 543 MiniInstallerTestUtil::VerifyProcessLaunch(process_name, true);
547 ASSERT_TRUE(MiniInstallerTestUtil::VerifyProcessClose(process_name)); 544 ASSERT_TRUE(MiniInstallerTestUtil::VerifyProcessClose(process_name));
548 } 545 }
549 546
550 // Gets the path to launch Chrome. 547 // Gets the path to launch Chrome.
551 bool ChromeMiniInstaller::GetChromeLaunchPath(std::wstring* launch_path) { 548 bool ChromeMiniInstaller::GetChromeLaunchPath(std::wstring* launch_path) {
552 std::wstring path; 549 std::wstring path;
553 path = GetChromeInstallDirectoryLocation(); 550 path = GetChromeInstallDirectoryLocation();
554 file_util::AppendToPath(&path, mini_installer_constants::kChromeAppDir); 551 file_util::AppendToPath(&path, mini_installer_constants::kChromeAppDir);
555 file_util::AppendToPath(&path, installer_util::kChromeExe); 552 file_util::AppendToPath(&path, installer_util::kChromeExe);
556 launch_path->assign(path); 553 launch_path->assign(path);
557 return(file_util::PathExists(FilePath::FromWStringHack(path))); 554 return file_util::PathExists(FilePath(path));
558 } 555 }
559 556
560 // Launch Chrome to see if it works after overinstall. Then close it. 557 // Launch Chrome to see if it works after overinstall. Then close it.
561 void ChromeMiniInstaller::LaunchAndCloseChrome(bool over_install) { 558 void ChromeMiniInstaller::LaunchAndCloseChrome(bool over_install) {
562 VerifyChromeLaunch(true); 559 VerifyChromeLaunch(true);
563 if ((install_type_ == mini_installer_constants::kSystemInstall) && 560 if ((install_type_ == mini_installer_constants::kSystemInstall) &&
564 (!over_install)) { 561 (!over_install)) {
565 MiniInstallerTestUtil::VerifyProcessLaunch( 562 MiniInstallerTestUtil::VerifyProcessLaunch(
566 installer_util::kChromeExe, true); 563 installer_util::kChromeExe, true);
567 } 564 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 // This method will verify if the installed build is correct. 653 // This method will verify if the installed build is correct.
657 bool ChromeMiniInstaller::VerifyStandaloneInstall() { 654 bool ChromeMiniInstaller::VerifyStandaloneInstall() {
658 std::wstring reg_key_value_returned, standalone_installer_version; 655 std::wstring reg_key_value_returned, standalone_installer_version;
659 MiniInstallerTestUtil::GetStandaloneVersion(&standalone_installer_version); 656 MiniInstallerTestUtil::GetStandaloneVersion(&standalone_installer_version);
660 GetChromeVersionFromRegistry(&reg_key_value_returned); 657 GetChromeVersionFromRegistry(&reg_key_value_returned);
661 if (standalone_installer_version.compare(reg_key_value_returned) == 0) 658 if (standalone_installer_version.compare(reg_key_value_returned) == 0)
662 return true; 659 return true;
663 else 660 else
664 return false; 661 return false;
665 } 662 }
OLDNEW
« no previous file with comments | « chrome/test/mini_installer_test/chrome_mini_installer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698