| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/command_line.h" | |
| 6 #include "base/file_util.h" | |
| 7 #include "base/process/process_iterator.h" | |
| 8 #include "base/test/test_suite.h" | |
| 9 #include "base/win/windows_version.h" | |
| 10 #include "chrome/common/chrome_switches.h" | |
| 11 #include "chrome/installer/util/util_constants.h" | |
| 12 #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" | |
| 13 #include "chrome/test/mini_installer_test/installer_test_util.h" | |
| 14 | |
| 15 | |
| 16 void BackUpProfile(bool chrome_frame) { | |
| 17 if (base::GetProcessCount(L"chrome.exe", NULL) > 0) { | |
| 18 printf("Chrome is currently running and cannot backup the profile." | |
| 19 "Please close Chrome and run the tests again.\n"); | |
| 20 exit(1); | |
| 21 } | |
| 22 base::FilePath path; | |
| 23 installer_test::GetChromeInstallDirectory(false /* system_level */, &path); | |
| 24 path = path.Append(mini_installer_constants::kChromeAppDir).DirName(); | |
| 25 base::FilePath backup_path = path; | |
| 26 // Will hold User Data path that needs to be backed-up. | |
| 27 path = path.Append(mini_installer_constants::kChromeUserDataDir); | |
| 28 // Will hold new backup path to save the profile. | |
| 29 backup_path = backup_path.Append( | |
| 30 mini_installer_constants::kChromeUserDataBackupDir); | |
| 31 // Will check if User Data profile is available. | |
| 32 if (base::PathExists(path)) { | |
| 33 // Will check if User Data is already backed up. | |
| 34 // If yes, will delete and create new one. | |
| 35 if (base::PathExists(backup_path)) | |
| 36 base::DeleteFile(backup_path, true); | |
| 37 base::CopyDirectory(path, backup_path, true); | |
| 38 } else { | |
| 39 printf("Chrome is not installed. Will not take any backup\n"); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 int main(int argc, char** argv) { | |
| 44 // Check command line to decide if the tests should continue | |
| 45 // with cleaning the system or make a backup before continuing. | |
| 46 CommandLine::Init(argc, argv); | |
| 47 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 48 base::TestSuite test_suite(argc, argv); | |
| 49 | |
| 50 if (command_line.HasSwitch(switches::kInstallerHelp)) { | |
| 51 printf("This test needs command line arguments.\n"); | |
| 52 printf("Usage: %ls [-backup] [-build <version>] [-force] \n", | |
| 53 command_line.GetProgram().value().c_str()); | |
| 54 printf("-backup arg will make a copy of User Data before uninstalling" | |
| 55 " your chrome at all levels. The copy will be named as" | |
| 56 " User Data Copy.\n" | |
| 57 "-build specifies the build to be tested, e.g., 3.0.195.24." | |
| 58 " Specifying 'dev' or 'stable' will use the latest build from that" | |
| 59 " channel. 'latest', the default, will use the latest build.\n" | |
| 60 "-force allows these tests to be run on the current platform," | |
| 61 " regardless of whether it is supported.\n"); | |
| 62 return 1; | |
| 63 } | |
| 64 | |
| 65 if (command_line.HasSwitch(switches::kInstallerTestBackup)) { | |
| 66 BackUpProfile(command_line.HasSwitch( | |
| 67 installer::switches::kChromeFrame)); | |
| 68 } | |
| 69 | |
| 70 if (base::win::GetVersion() < base::win::VERSION_VISTA || | |
| 71 command_line.HasSwitch(switches::kInstallerTestForce)) { | |
| 72 return test_suite.Run(); | |
| 73 } | |
| 74 printf("These tests don't run on this platform.\n"); | |
| 75 return 0; | |
| 76 } | |
| OLD | NEW |