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.
5 #include "chrome/installer/mini_installer/configuration.h"
9 #include "base/basictypes.h"
10 #include "chrome/installer/mini_installer/appid.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 using mini_installer::Configuration
;
15 class TestConfiguration
: public Configuration
{
17 explicit TestConfiguration(const wchar_t* command_line
) : Configuration() {
18 Initialize(command_line
);
21 void Initialize(const wchar_t* command_line
) {
22 ASSERT_TRUE(InitializeFromCommandLine(command_line
));
26 // Test that the operation type is CLEANUP iff --cleanup is on the cmdline.
27 TEST(MiniInstallerConfigurationTest
, Operation
) {
28 EXPECT_EQ(Configuration::INSTALL_PRODUCT
,
29 TestConfiguration(L
"spam.exe").operation());
30 EXPECT_EQ(Configuration::INSTALL_PRODUCT
,
31 TestConfiguration(L
"spam.exe --clean").operation());
32 EXPECT_EQ(Configuration::INSTALL_PRODUCT
,
33 TestConfiguration(L
"spam.exe --cleanupthis").operation());
35 EXPECT_EQ(Configuration::CLEANUP
,
36 TestConfiguration(L
"spam.exe --cleanup").operation());
37 EXPECT_EQ(Configuration::CLEANUP
,
38 TestConfiguration(L
"spam.exe --cleanup now").operation());
41 TEST(MiniInstallerConfigurationTest
, Program
) {
42 EXPECT_TRUE(NULL
== mini_installer::Configuration().program());
43 EXPECT_TRUE(std::wstring(L
"spam.exe") ==
44 TestConfiguration(L
"spam.exe").program());
45 EXPECT_TRUE(std::wstring(L
"spam.exe") ==
46 TestConfiguration(L
"spam.exe --with args").program());
47 EXPECT_TRUE(std::wstring(L
"c:\\blaz\\spam.exe") ==
48 TestConfiguration(L
"c:\\blaz\\spam.exe --with args").program());
51 TEST(MiniInstallerConfigurationTest
, ArgumentCount
) {
52 EXPECT_EQ(1, TestConfiguration(L
"spam.exe").argument_count());
53 EXPECT_EQ(2, TestConfiguration(L
"spam.exe --foo").argument_count());
54 EXPECT_EQ(3, TestConfiguration(L
"spam.exe --foo --bar").argument_count());
57 TEST(MiniInstallerConfigurationTest
, CommandLine
) {
58 static const wchar_t* const kCommandLines
[] = {
63 for (size_t i
= 0; i
< _countof(kCommandLines
); ++i
) {
64 EXPECT_TRUE(std::wstring(kCommandLines
[i
]) ==
65 TestConfiguration(kCommandLines
[i
]).command_line());
69 TEST(MiniInstallerConfigurationTest
, ChromeAppGuid
) {
70 EXPECT_TRUE(std::wstring(google_update::kAppGuid
) ==
71 TestConfiguration(L
"spam.exe").chrome_app_guid());
72 EXPECT_TRUE(std::wstring(google_update::kAppGuid
) ==
73 TestConfiguration(L
"spam.exe --chrome").chrome_app_guid());
74 EXPECT_TRUE(std::wstring(google_update::kAppGuid
) ==
75 TestConfiguration(L
"spam.exe --multi-install --chrome")
77 EXPECT_TRUE(std::wstring(google_update::kAppGuid
) ==
78 TestConfiguration(L
"spam.exe --chrome-frame").chrome_app_guid());
79 EXPECT_TRUE(std::wstring(google_update::kSxSAppGuid
) ==
80 TestConfiguration(L
"spam.exe --chrome-sxs").chrome_app_guid());
83 TEST(MiniInstallerConfigurationTest
, HasChrome
) {
84 EXPECT_TRUE(TestConfiguration(L
"spam.exe").has_chrome());
85 EXPECT_TRUE(TestConfiguration(L
"spam.exe --chrome").has_chrome());
86 EXPECT_TRUE(TestConfiguration(L
"spam.exe --multi-install --chrome")
88 EXPECT_FALSE(TestConfiguration(L
"spam.exe --chrome-frame").has_chrome());
89 EXPECT_FALSE(TestConfiguration(L
"spam.exe --multi-install").has_chrome());
92 TEST(MiniInstallerConfigurationTest
, HasChromeFrame
) {
93 EXPECT_FALSE(TestConfiguration(L
"spam.exe").has_chrome_frame());
94 EXPECT_FALSE(TestConfiguration(L
"spam.exe --chrome").has_chrome_frame());
95 EXPECT_FALSE(TestConfiguration(L
"spam.exe --multi-install --chrome")
97 EXPECT_TRUE(TestConfiguration(L
"spam.exe --chrome-frame").has_chrome_frame());
98 EXPECT_TRUE(TestConfiguration(L
"spam.exe --multi-install --chrome-frame")
100 EXPECT_FALSE(TestConfiguration(L
"spam.exe --multi-install")
101 .has_chrome_frame());
104 TEST(MiniInstallerConfigurationTest
, IsMultiInstall
) {
105 EXPECT_FALSE(TestConfiguration(L
"spam.exe").is_multi_install());
106 EXPECT_FALSE(TestConfiguration(L
"spam.exe --chrome").is_multi_install());
107 EXPECT_TRUE(TestConfiguration(L
"spam.exe --multi-install --chrome")
108 .is_multi_install());
109 EXPECT_FALSE(TestConfiguration(L
"spam.exe --chrome-frame")
110 .is_multi_install());
111 EXPECT_TRUE(TestConfiguration(L
"spam.exe --multi-install --chrome-frame")
112 .is_multi_install());
113 EXPECT_TRUE(TestConfiguration(L
"spam.exe --multi-install")
114 .is_multi_install());
117 TEST(MiniInstallerConfigurationTest
, IsSystemLevel
) {
118 EXPECT_FALSE(TestConfiguration(L
"spam.exe").is_system_level());
119 EXPECT_FALSE(TestConfiguration(L
"spam.exe --chrome").is_system_level());
120 EXPECT_TRUE(TestConfiguration(L
"spam.exe --system-level").is_system_level());