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/files/file_path.h"
7#include "base/memory/scoped_ptr.h"
8#include "base/process/kill.h"
9#include "base/strings/string_util.h"
10#include "chrome/common/chrome_result_codes.h"
11#include "chrome/common/chrome_switches.h"
12#include "chrome/installer/util/install_util.h"
13#include "chrome/installer/util/installation_validator.h"
14#include "chrome/installer/util/util_constants.h"
15#include "chrome/test/mini_installer_test/installer_path_provider.h"
16#include "chrome/test/mini_installer_test/installer_test_util.h"
17#include "chrome/test/mini_installer_test/mini_installer_test_constants.h"
18#include "chrome/test/mini_installer_test/switch_builder.h"
19#include "testing/gtest/include/gtest/gtest.h"
20
21using installer::InstallationValidator;
22using installer_test::InstallerPathProvider;
23using installer_test::SwitchBuilder;
24
25namespace {
26
27class MiniInstallTest : public testing::Test {
28 public:
29  virtual void SetUp() {
30    std::vector<installer_test::InstalledProduct> installed;
31    if (installer_test::GetInstalledProducts(&installed)) {
32      ASSERT_TRUE(installer_test::UninstallAll());
33    }
34  }
35
36  virtual void TearDown() {
37    installer_test::UninstallAll();
38  }
39
40 protected:
41  static void SetUpTestCase() {
42    std::string build_under_test;
43    const CommandLine* cmd = CommandLine::ForCurrentProcess();
44    build_under_test = cmd->GetSwitchValueASCII(switches::kInstallerTestBuild);
45    if (build_under_test.empty())
46      provider_ = new InstallerPathProvider();
47    else
48      provider_ = new InstallerPathProvider(build_under_test);
49    ASSERT_FALSE(provider_->GetCurrentBuild().empty());
50    ASSERT_TRUE(provider_->GetFullInstaller(&full_installer_));
51    ASSERT_TRUE(provider_->GetPreviousInstaller(&previous_installer_));
52    ASSERT_TRUE(provider_->GetDiffInstaller(&diff_installer_));
53    ASSERT_TRUE(
54        provider_->GetSignedStandaloneInstaller(&standalone_installer_));
55    ASSERT_TRUE(provider_->GetMiniInstaller(&mini_installer_));
56  }
57
58  static void TearDownTestCase() {
59    delete provider_;
60    provider_ = NULL;
61  }
62
63  static InstallerPathProvider* provider_;
64  static base::FilePath full_installer_;
65  static base::FilePath previous_installer_;
66  static base::FilePath diff_installer_;
67  static base::FilePath standalone_installer_;
68  static base::FilePath mini_installer_;
69};
70
71InstallerPathProvider* MiniInstallTest::provider_;
72base::FilePath MiniInstallTest::full_installer_;
73base::FilePath MiniInstallTest::previous_installer_;
74base::FilePath MiniInstallTest::diff_installer_;
75base::FilePath MiniInstallTest::standalone_installer_;
76base::FilePath MiniInstallTest::mini_installer_;
77
78}  // namespace
79
80#if defined(GOOGLE_CHROME_BUILD)
81// Could use a parameterized gtest to slim down this list of tests, but since
82// these tests will often be run manually, don't want to have obscure test
83// names.
84
85// Install full installer at user level.
86TEST_F(MiniInstallTest, FullInstallerUser) {
87  ASSERT_TRUE(installer_test::Install(
88      full_installer_, SwitchBuilder().AddChrome()));
89  ASSERT_TRUE(installer_test::ValidateInstall(false,
90      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
91}
92
93// Install full installer at system level.
94TEST_F(MiniInstallTest, FullInstallerSys) {
95  ASSERT_TRUE(installer_test::Install(full_installer_,
96      SwitchBuilder().AddChrome().AddSystemInstall()));
97  ASSERT_TRUE(installer_test::ValidateInstall(true,
98      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
99}
100
101// Overinstall full installer.
102TEST_F(MiniInstallTest, FullOverPreviousFullUser) {
103  ASSERT_TRUE(installer_test::Install(
104      previous_installer_, SwitchBuilder().AddChrome()));
105  ASSERT_TRUE(installer_test::ValidateInstall(false,
106      InstallationValidator::CHROME_SINGLE, provider_->GetPreviousBuild()));
107  ASSERT_TRUE(installer_test::Install(
108      full_installer_, SwitchBuilder().AddChrome()));
109  ASSERT_TRUE(installer_test::ValidateInstall(false,
110      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
111}
112
113TEST_F(MiniInstallTest, FullOverPreviousFullSys) {
114  ASSERT_TRUE(installer_test::Install(previous_installer_,
115      SwitchBuilder().AddChrome().AddSystemInstall()));
116  ASSERT_TRUE(installer_test::ValidateInstall(true,
117      InstallationValidator::CHROME_SINGLE, provider_->GetPreviousBuild()));
118  ASSERT_TRUE(installer_test::Install(full_installer_,
119      SwitchBuilder().AddChrome().AddSystemInstall()));
120  ASSERT_TRUE(installer_test::ValidateInstall(true,
121      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
122}
123
124TEST_F(MiniInstallTest, FreshChromeFrameUser) {
125  ASSERT_TRUE(installer_test::Install(
126      full_installer_, SwitchBuilder().AddChromeFrame()));
127  ASSERT_TRUE(installer_test::ValidateInstall(
128      false,
129      InstallationValidator::CHROME_FRAME_SINGLE,
130      provider_->GetCurrentBuild()));
131}
132
133// Overinstall full Chrome Frame installer while IE browser is running.
134TEST_F(MiniInstallTest, FullFrameOverPreviousFullIERunningSys) {
135  installer_test::LaunchIE("http://www.google.com");
136  ASSERT_TRUE(installer_test::Install(previous_installer_,
137      SwitchBuilder().AddChromeFrame().AddSystemInstall()));
138  ASSERT_TRUE(installer_test::ValidateInstall(
139      true,
140      InstallationValidator::CHROME_FRAME_SINGLE,
141      provider_->GetPreviousBuild()));
142  ASSERT_TRUE(installer_test::Install(full_installer_,
143      SwitchBuilder().AddChromeFrame().AddSystemInstall()));
144  ASSERT_TRUE(installer_test::ValidateInstall(
145      true,
146      InstallationValidator::CHROME_FRAME_SINGLE,
147      provider_->GetCurrentBuild()));
148}
149
150// Overinstall diff installer.
151TEST_F(MiniInstallTest, DiffOverPreviousFullUser) {
152  ASSERT_TRUE(installer_test::Install(
153      previous_installer_, SwitchBuilder().AddChrome()));
154  ASSERT_TRUE(installer_test::ValidateInstall(false,
155      InstallationValidator::CHROME_SINGLE, provider_->GetPreviousBuild()));
156  ASSERT_TRUE(installer_test::Install(
157      diff_installer_, SwitchBuilder().AddChrome()));
158  ASSERT_TRUE(installer_test::ValidateInstall(false,
159      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
160}
161
162TEST_F(MiniInstallTest, DiffOverPreviousFullSys) {
163  ASSERT_TRUE(installer_test::Install(previous_installer_,
164      SwitchBuilder().AddChrome().AddSystemInstall()));
165  ASSERT_TRUE(installer_test::ValidateInstall(true,
166      InstallationValidator::CHROME_SINGLE, provider_->GetPreviousBuild()));
167  ASSERT_TRUE(installer_test::Install(diff_installer_,
168      SwitchBuilder().AddChrome().AddSystemInstall()));
169  ASSERT_TRUE(installer_test::ValidateInstall(true,
170      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
171}
172
173// Overinstall diff Chrome Frame installer while IE browser is running.
174TEST_F(MiniInstallTest, DiffFrameOverPreviousFullIERunningSys) {
175  installer_test::LaunchIE("http://www.google.com");
176  ASSERT_TRUE(installer_test::Install(previous_installer_,
177    SwitchBuilder().AddChromeFrame().AddSystemInstall()));
178  ASSERT_TRUE(installer_test::ValidateInstall(
179      true,
180      InstallationValidator::CHROME_FRAME_SINGLE,
181      provider_->GetPreviousBuild()));
182  ASSERT_TRUE(installer_test::Install(diff_installer_,
183      SwitchBuilder().AddChromeFrame().AddSystemInstall()));
184  ASSERT_TRUE(installer_test::ValidateInstall(
185      true,
186      InstallationValidator::CHROME_FRAME_SINGLE,
187      provider_->GetCurrentBuild()));
188}
189
190TEST_F(MiniInstallTest, InstallChromeMultiOverChromeSys) {
191  ASSERT_TRUE(installer_test::Install(full_installer_,
192    SwitchBuilder().AddChrome().AddSystemInstall()));
193  ASSERT_TRUE(installer_test::ValidateInstall(true,
194    InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
195  ASSERT_TRUE(installer_test::Install(full_installer_,
196    SwitchBuilder().AddChrome().AddSystemInstall().AddMultiInstall()));
197  ASSERT_TRUE(installer_test::ValidateInstall(true,
198    InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild()));
199}
200
201// Repair version folder.
202TEST_F(MiniInstallTest, RepairFolderOnFullUser) {
203  ASSERT_TRUE(installer_test::Install(
204      full_installer_, SwitchBuilder().AddChrome()));
205  ASSERT_TRUE(installer_test::ValidateInstall(false,
206      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
207  base::CleanupProcesses(installer::kChromeExe, base::TimeDelta(),
208                         content::RESULT_CODE_HUNG, NULL);
209  ASSERT_TRUE(installer_test::DeleteInstallDirectory(
210      false, // system level
211      InstallationValidator::CHROME_SINGLE));
212  ASSERT_TRUE(installer_test::Install(
213      full_installer_, SwitchBuilder().AddChrome()));
214  ASSERT_TRUE(installer_test::ValidateInstall(false,
215      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
216}
217
218TEST_F(MiniInstallTest, RepairFolderOnFullSys) {
219  ASSERT_TRUE(installer_test::Install(full_installer_,
220      SwitchBuilder().AddChrome().AddSystemInstall()));
221  ASSERT_TRUE(installer_test::ValidateInstall(true,
222      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
223  base::CleanupProcesses(installer::kChromeExe, base::TimeDelta(),
224                         content::RESULT_CODE_HUNG, NULL);
225  ASSERT_TRUE(installer_test::DeleteInstallDirectory(
226      true, // system level
227      InstallationValidator::CHROME_SINGLE));
228  ASSERT_TRUE(installer_test::Install(full_installer_,
229      SwitchBuilder().AddChrome().AddSystemInstall()));
230  ASSERT_TRUE(installer_test::ValidateInstall(true,
231      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
232}
233
234// Repair registry.
235TEST_F(MiniInstallTest, RepairRegistryOnFullUser) {
236  ASSERT_TRUE(installer_test::Install(
237      full_installer_, SwitchBuilder().AddChrome()));
238  ASSERT_TRUE(installer_test::ValidateInstall(false,
239      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
240  base::CleanupProcesses(installer::kChromeExe, base::TimeDelta(),
241                         content::RESULT_CODE_HUNG, NULL);
242  ASSERT_TRUE(installer_test::DeleteRegistryKey(
243      false, // system level
244      InstallationValidator::CHROME_SINGLE));
245  ASSERT_TRUE(
246      installer_test::Install(full_installer_, SwitchBuilder().AddChrome()));
247  ASSERT_TRUE(installer_test::ValidateInstall(false,
248      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
249}
250
251TEST_F(MiniInstallTest, RepairRegistryOnFullSys) {
252  ASSERT_TRUE(installer_test::Install(full_installer_,
253      SwitchBuilder().AddChrome().AddSystemInstall()));
254  ASSERT_TRUE(installer_test::ValidateInstall(true,
255      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
256  ASSERT_TRUE(installer_test::DeleteRegistryKey(
257      true, // system level
258      InstallationValidator::CHROME_SINGLE));
259  ASSERT_TRUE(installer_test::Install(full_installer_,
260      SwitchBuilder().AddChrome().AddSystemInstall()));
261  ASSERT_TRUE(installer_test::ValidateInstall(true,
262      InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild()));
263}
264
265// Run full Chrome Frame install then uninstall it while IE browser is running.
266TEST_F(MiniInstallTest, FullInstallAndUnInstallChromeFrameWithIERunning) {
267  ASSERT_TRUE(installer_test::Install(full_installer_,
268      SwitchBuilder().AddChromeFrame().AddSystemInstall()));
269  ASSERT_TRUE(installer_test::ValidateInstall(
270      true,
271      InstallationValidator::CHROME_FRAME_SINGLE,
272      provider_->GetCurrentBuild()));
273  // Launch IE and let TearDown step perform uninstall.
274  installer_test::LaunchIE("http://www.google.com");
275}
276
277// Install standalone.
278TEST_F(MiniInstallTest, InstallStandaloneUser) {
279  ASSERT_TRUE(installer_test::Install(standalone_installer_));
280  ASSERT_TRUE(installer_test::ValidateInstall(false,
281      InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild()));
282}
283
284// This test doesn't make sense. Disabling for now.
285TEST_F(MiniInstallTest, DISABLED_MiniInstallerOverChromeMetaInstallerTest) {
286}
287
288// Encountering issue 9593. Disabling temporarily.
289TEST_F(MiniInstallTest,
290    DISABLED_InstallLatestStableFullInstallerOverChromeMetaInstaller) {
291}
292
293// Encountering issue 9593. Disabling temporarily.
294TEST_F(MiniInstallTest,
295       DISABLED_InstallLatestDevFullInstallerOverChromeMetaInstallerTest) {
296}
297
298TEST_F(MiniInstallTest,
299    InstallChromeUsingMultiInstallUser) {
300  ASSERT_TRUE(installer_test::Install(full_installer_,
301      SwitchBuilder().AddChrome().AddMultiInstall()));
302  ASSERT_TRUE(installer_test::ValidateInstall(false,
303      InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild()));
304}
305
306TEST_F(MiniInstallTest,
307    InstallChromeUsingMultiInstallSys) {
308  ASSERT_TRUE(installer_test::Install(full_installer_,
309      SwitchBuilder().AddChrome().AddMultiInstall().AddSystemInstall()));
310  ASSERT_TRUE(installer_test::ValidateInstall(true,
311      InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild()));
312}
313
314TEST_F(MiniInstallTest, InstallChromeAndChromeFrameMultiInstallUser) {
315  ASSERT_TRUE(installer_test::Install(full_installer_,
316      SwitchBuilder().AddChrome().AddChromeFrame().AddMultiInstall()));
317  ASSERT_TRUE(installer_test::ValidateInstall(
318      false,
319      InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI,
320      provider_->GetCurrentBuild()));
321}
322
323TEST_F(MiniInstallTest, InstallChromeAndChromeFrameMultiInstallSys) {
324  ASSERT_TRUE(installer_test::Install(
325      full_installer_, SwitchBuilder().AddChrome()
326      .AddChromeFrame().AddMultiInstall().AddSystemInstall()));
327  ASSERT_TRUE(installer_test::ValidateInstall(
328      true,
329      InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI,
330      provider_->GetCurrentBuild()));
331}
332
333TEST_F(MiniInstallTest,
334    InstallChromeAndChromeFrameReadyModeUser) {
335  ASSERT_TRUE(
336      installer_test::Install(full_installer_,SwitchBuilder().AddChrome()
337      .AddChromeFrame().AddMultiInstall().AddReadyMode()));
338  ASSERT_TRUE(installer_test::ValidateInstall(
339      false,
340      InstallationValidator::CHROME_FRAME_READY_MODE_CHROME_MULTI,
341      provider_->GetCurrentBuild()));
342}
343
344TEST_F(MiniInstallTest,
345    InstallChromeAndChromeFrameReadyModeSys) {
346  ASSERT_TRUE(installer_test::Install(full_installer_,
347      SwitchBuilder().AddChrome().AddChromeFrame().AddMultiInstall()
348      .AddReadyMode().AddSystemInstall()));
349  ASSERT_TRUE(installer_test::ValidateInstall(
350      true,
351      InstallationValidator::CHROME_FRAME_READY_MODE_CHROME_MULTI,
352      provider_->GetCurrentBuild()));
353}
354
355TEST_F(MiniInstallTest, InstallChromeFrameUsingMultiInstallUser) {
356  ASSERT_TRUE(installer_test::Install(full_installer_,
357      SwitchBuilder().AddChromeFrame().AddMultiInstall()));
358  ASSERT_TRUE(installer_test::ValidateInstall(
359      false,
360      InstallationValidator::CHROME_FRAME_MULTI,
361      provider_->GetCurrentBuild()));
362}
363
364TEST_F(MiniInstallTest, InstallChromeFrameUsingMultiInstallSys) {
365  ASSERT_TRUE(installer_test::Install(full_installer_,
366      SwitchBuilder().AddChromeFrame().AddMultiInstall().AddSystemInstall()));
367  ASSERT_TRUE(installer_test::ValidateInstall(
368      true,
369      InstallationValidator::CHROME_FRAME_MULTI,
370      provider_->GetCurrentBuild()));
371}
372
373// Chrome Frame is in use while Chrome is install.
374TEST_F(MiniInstallTest, InstallChromeWithExistingChromeFrameMultiInstallUser) {
375  ASSERT_TRUE(installer_test::Install(previous_installer_,
376      SwitchBuilder().AddChromeFrame().AddMultiInstall()));
377  ASSERT_TRUE(installer_test::ValidateInstall(
378      false,
379      InstallationValidator::CHROME_FRAME_MULTI,
380      provider_->GetPreviousBuild()));
381  ASSERT_TRUE(installer_test::Install(full_installer_,
382      SwitchBuilder().AddChrome().AddMultiInstall()));
383  ASSERT_TRUE(installer_test::ValidateInstall(
384      false,
385      InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI,
386      provider_->GetCurrentBuild()));
387}
388
389// Chrome Frame is in use while Chrome is install.
390TEST_F(MiniInstallTest, InstallChromeWithExistingChromeFrameMultiInstallSys) {
391  ASSERT_TRUE(installer_test::Install(previous_installer_,
392      SwitchBuilder().AddChromeFrame().AddMultiInstall().AddSystemInstall()));
393  ASSERT_TRUE(installer_test::ValidateInstall(
394      true,
395      InstallationValidator::CHROME_FRAME_MULTI,
396      provider_->GetPreviousBuild()));
397  ASSERT_TRUE(installer_test::Install(full_installer_,
398      SwitchBuilder().AddChrome().AddMultiInstall()));
399  ASSERT_TRUE(installer_test::ValidateInstall(true,
400      InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild()));
401}
402
403TEST_F(MiniInstallTest, OverInstallChromeWhenInUseUser) {
404  ASSERT_TRUE(installer_test::Install(full_installer_,
405      SwitchBuilder().AddChrome().AddMultiInstall()));
406  ASSERT_TRUE(installer_test::ValidateInstall(false,
407      InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild()));
408  installer_test::LaunchChrome(false, false);
409  ASSERT_TRUE(installer_test::Install(full_installer_,
410      SwitchBuilder().AddChrome().AddMultiInstall()));
411  ASSERT_TRUE(installer_test::ValidateInstall(false,
412      InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild()));
413}
414
415TEST_F(MiniInstallTest, OverInstallChromeWhenInUseSys) {
416  ASSERT_TRUE(installer_test::Install(full_installer_,
417      SwitchBuilder().AddChrome().AddMultiInstall().AddSystemInstall()));
418  ASSERT_TRUE(installer_test::ValidateInstall(true,
419      InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild()));
420  installer_test::LaunchChrome(false, true);
421  ASSERT_TRUE(installer_test::Install(full_installer_,
422      SwitchBuilder().AddChrome().AddMultiInstall().AddSystemInstall()));
423  ASSERT_TRUE(installer_test::ValidateInstall(true,
424      InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild()));
425}
426
427#endif
428
429TEST(GenericInstallTest, MiniInstallTestValidWindowsVersion) {
430  // We run the tests on all supported OSes.
431  // Make sure the code agrees.
432  EXPECT_TRUE(InstallUtil::IsOSSupported());
433}
434
435