• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_INSTALLER_UTIL_FAKE_INSTALLATION_STATE_H_
6 #define CHROME_INSTALLER_UTIL_FAKE_INSTALLATION_STATE_H_
7 
8 #include "base/files/file_path.h"
9 #include "base/version.h"
10 #include "chrome/installer/util/fake_product_state.h"
11 #include "chrome/installer/util/helper.h"
12 #include "chrome/installer/util/installation_state.h"
13 #include "chrome/installer/util/util_constants.h"
14 
15 namespace installer {
16 
17 // An InstallationState helper for use by unit tests.
18 class FakeInstallationState : public InstallationState {
19  public:
20   // Takes ownership of |version|.
AddChrome(bool system_install,bool multi_install,Version * version)21   void AddChrome(bool system_install, bool multi_install, Version* version) {
22     FakeProductState chrome_state;
23     chrome_state.set_version(version);
24     chrome_state.set_multi_install(multi_install);
25     base::FilePath setup_exe(
26         GetChromeInstallPath(system_install,
27                              BrowserDistribution::GetSpecificDistribution(
28                                  BrowserDistribution::CHROME_BROWSER)));
29     setup_exe = setup_exe
30         .AppendASCII(version->GetString())
31         .Append(kInstallerDir)
32         .Append(kSetupExe);
33     chrome_state.SetUninstallProgram(setup_exe);
34     chrome_state.AddUninstallSwitch(switches::kUninstall);
35     if (multi_install) {
36       chrome_state.AddUninstallSwitch(switches::kMultiInstall);
37       chrome_state.AddUninstallSwitch(switches::kChrome);
38     }
39     SetProductState(system_install, BrowserDistribution::CHROME_BROWSER,
40                     chrome_state);
41   }
42 
SetProductState(bool system_install,BrowserDistribution::Type type,const ProductState & product_state)43   void SetProductState(bool system_install,
44                        BrowserDistribution::Type type,
45                        const ProductState& product_state) {
46     ProductState& target = GetProducts(system_install)[IndexFromDistType(type)];
47     target.CopyFrom(product_state);
48   }
49 
50  protected:
GetProducts(bool system_install)51   ProductState* GetProducts(bool system_install) {
52     return system_install ? system_products_ : user_products_;
53   }
54 };
55 
56 }  // namespace installer
57 
58 #endif  // CHROME_INSTALLER_UTIL_FAKE_INSTALLATION_STATE_H_
59