OLD | NEW |
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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/test/test_suite.h" | 7 #include "base/test/test_suite.h" |
8 #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" | 8 #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" |
9 #include "chrome_mini_installer.h" | 9 #include "chrome_mini_installer.h" |
10 | 10 |
11 void BackUpProfile() { | 11 void BackUpProfile() { |
12 if (base::GetProcessCount(L"chrome.exe", NULL) > 0) { | 12 if (base::GetProcessCount(L"chrome.exe", NULL) > 0) { |
13 printf("Chrome is currently running and cannot backup the profile." | 13 printf("Chrome is currently running and cannot backup the profile." |
14 "Please close Chrome and run the tests again.\n"); | 14 "Please close Chrome and run the tests again.\n"); |
15 exit(1); | 15 exit(1); |
16 } | 16 } |
17 ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); | 17 ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); |
18 FilePath path = | 18 std::wstring path = installer.GetChromeInstallDirectoryLocation(); |
19 FilePath::FromWStringHack(installer.GetChromeInstallDirectoryLocation()); | 19 file_util::AppendToPath(&path, mini_installer_constants::kChromeAppDir); |
20 path = path.Append(mini_installer_constants::kChromeAppDir).DirName(); | 20 file_util::UpOneDirectory(&path); |
21 FilePath backup_path = path; | 21 std::wstring backup_path = path; |
22 // Will hold User Data path that needs to be backed-up. | 22 // Will hold User Data path that needs to be backed-up. |
23 path = path.Append(mini_installer_constants::kChromeUserDataDir); | 23 file_util::AppendToPath(&path, |
| 24 mini_installer_constants::kChromeUserDataDir); |
24 // Will hold new backup path to save the profile. | 25 // Will hold new backup path to save the profile. |
25 backup_path = path.Append(mini_installer_constants::kChromeUserDataBackupDir); | 26 file_util::AppendToPath(&backup_path, |
| 27 mini_installer_constants::kChromeUserDataBackupDir); |
26 // Will check if User Data profile is available. | 28 // Will check if User Data profile is available. |
27 if (file_util::PathExists(path)) { | 29 if (file_util::PathExists(path)) { |
28 // Will check if User Data is already backed up. | 30 // Will check if User Data is already backed up. |
29 // If yes, will delete and create new one. | 31 // If yes, will delete and create new one. |
30 if (file_util::PathExists(backup_path)) | 32 if (file_util::PathExists(backup_path)) |
31 file_util::Delete(backup_path, true); | 33 file_util::Delete(backup_path.c_str(), true); |
32 file_util::CopyDirectory(path, backup_path, true); | 34 file_util::CopyDirectory(path, backup_path, true); |
33 } else { | 35 } else { |
34 printf("Chrome is not installed. Will not take any backup\n"); | 36 printf("Chrome is not installed. Will not take any backup\n"); |
35 } | 37 } |
36 } | 38 } |
37 | 39 |
38 int main(int argc, char** argv) { | 40 int main(int argc, char** argv) { |
39 // Check command line to decide if the tests should continue | 41 // Check command line to decide if the tests should continue |
40 // with cleaning the system or make a backup before continuing. | 42 // with cleaning the system or make a backup before continuing. |
41 CommandLine::Init(argc, argv); | 43 CommandLine::Init(argc, argv); |
42 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 44 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
43 if (command_line.HasSwitch("clean")) { | 45 if (command_line.HasSwitch("clean")) { |
44 printf("Current version of Chrome will be uninstalled " | 46 printf("Current version of Chrome will be uninstalled " |
45 "from all levels before proceeding with tests.\n"); | 47 "from all levels before proceeding with tests.\n"); |
46 } else if (command_line.HasSwitch("backup")) { | 48 } else if (command_line.HasSwitch("backup")) { |
47 BackUpProfile(); | 49 BackUpProfile(); |
48 } else { | 50 } else { |
49 printf("This test needs command line Arguments.\n"); | 51 printf("This test needs command line Arguments.\n"); |
50 printf("Usage: mini_installer_tests.exe -{clean|backup}\n"); | 52 printf("Usage: mini_installer_tests.exe -{clean|backup}\n"); |
51 printf("Note: -clean arg will uninstall your chrome at all levels" | 53 printf("Note: -clean arg will uninstall your chrome at all levels" |
52 " and also delete profile.\n" | 54 " and also delete profile.\n" |
53 "-backup arg will make a copy of User Data before uninstalling" | 55 "-backup arg will make a copy of User Data before uninstalling" |
54 " your chrome at all levels. The copy will be named as" | 56 " your chrome at all levels. The copy will be named as" |
55 " User Data Copy.\n"); | 57 " User Data Copy.\n"); |
56 exit(1); | 58 exit(1); |
57 } | 59 } |
58 return TestSuite(argc, argv).Run(); | 60 return TestSuite(argc, argv).Run(); |
59 } | 61 } |
OLD | NEW |