Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / installer / mini_installer / configuration_test.cc
blobf2c8e3dcbf24acc7fbba4d25b22e8f63b6abe3ce
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"
7 #include <stdlib.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 {
16 public:
17 explicit TestConfiguration(const wchar_t* command_line)
18 : Configuration(),
19 open_registry_key_result_(false),
20 read_registry_value_result_(0),
21 read_registry_value_(L"") {
22 Initialize(command_line);
24 explicit TestConfiguration(const wchar_t* command_line,
25 LONG ret, const wchar_t* value)
26 : Configuration(),
27 open_registry_key_result_(true),
28 read_registry_value_result_(ret),
29 read_registry_value_(value) {
30 Initialize(command_line);
32 void SetRegistryResults(bool openkey, LONG ret, const wchar_t* value) {
34 private:
35 bool open_registry_key_result_;
36 LONG read_registry_value_result_;
37 const wchar_t* read_registry_value_ = L"";
39 void Initialize(const wchar_t* command_line) {
40 Clear();
41 ASSERT_TRUE(ParseCommandLine(command_line));
43 bool ReadClientStateRegistryValue(
44 const HKEY root_key, const wchar_t* app_guid,
45 LONG* retval, ValueString& value) override {
46 *retval = read_registry_value_result_;
47 value.assign(read_registry_value_);
48 return open_registry_key_result_;
52 // Test that the operation type is CLEANUP iff --cleanup is on the cmdline.
53 TEST(MiniInstallerConfigurationTest, Operation) {
54 EXPECT_EQ(Configuration::INSTALL_PRODUCT,
55 TestConfiguration(L"spam.exe").operation());
56 EXPECT_EQ(Configuration::INSTALL_PRODUCT,
57 TestConfiguration(L"spam.exe --clean").operation());
58 EXPECT_EQ(Configuration::INSTALL_PRODUCT,
59 TestConfiguration(L"spam.exe --cleanupthis").operation());
61 EXPECT_EQ(Configuration::CLEANUP,
62 TestConfiguration(L"spam.exe --cleanup").operation());
63 EXPECT_EQ(Configuration::CLEANUP,
64 TestConfiguration(L"spam.exe --cleanup now").operation());
67 TEST(MiniInstallerConfigurationTest, Program) {
68 EXPECT_TRUE(NULL == mini_installer::Configuration().program());
69 EXPECT_TRUE(std::wstring(L"spam.exe") ==
70 TestConfiguration(L"spam.exe").program());
71 EXPECT_TRUE(std::wstring(L"spam.exe") ==
72 TestConfiguration(L"spam.exe --with args").program());
73 EXPECT_TRUE(std::wstring(L"c:\\blaz\\spam.exe") ==
74 TestConfiguration(L"c:\\blaz\\spam.exe --with args").program());
77 TEST(MiniInstallerConfigurationTest, ArgumentCount) {
78 EXPECT_EQ(1, TestConfiguration(L"spam.exe").argument_count());
79 EXPECT_EQ(2, TestConfiguration(L"spam.exe --foo").argument_count());
80 EXPECT_EQ(3, TestConfiguration(L"spam.exe --foo --bar").argument_count());
83 TEST(MiniInstallerConfigurationTest, CommandLine) {
84 static const wchar_t* const kCommandLines[] = {
85 L"",
86 L"spam.exe",
87 L"spam.exe --foo",
89 for (size_t i = 0; i < _countof(kCommandLines); ++i) {
90 EXPECT_TRUE(std::wstring(kCommandLines[i]) ==
91 TestConfiguration(kCommandLines[i]).command_line());
95 TEST(MiniInstallerConfigurationTest, ChromeAppGuid) {
96 EXPECT_TRUE(std::wstring(google_update::kAppGuid) ==
97 TestConfiguration(L"spam.exe").chrome_app_guid());
98 EXPECT_TRUE(std::wstring(google_update::kAppGuid) ==
99 TestConfiguration(L"spam.exe --chrome").chrome_app_guid());
100 EXPECT_TRUE(std::wstring(google_update::kChromeFrameAppGuid) ==
101 TestConfiguration(L"spam.exe --chrome-frame").chrome_app_guid());
102 EXPECT_TRUE(std::wstring(google_update::kSxSAppGuid) ==
103 TestConfiguration(L"spam.exe --chrome-sxs").chrome_app_guid());
104 EXPECT_TRUE(std::wstring(google_update::kMultiInstallAppGuid) ==
105 TestConfiguration(L"spam.exe --multi-install --chrome")
106 .chrome_app_guid());
107 EXPECT_TRUE(std::wstring(google_update::kMultiInstallAppGuid) ==
108 TestConfiguration(L"spam.exe --multi-install --chrome",
109 ERROR_INVALID_FUNCTION, L"")
110 .chrome_app_guid());
111 EXPECT_TRUE(std::wstring(google_update::kAppGuid) ==
112 TestConfiguration(L"spam.exe --multi-install --chrome",
113 ERROR_FILE_NOT_FOUND, L"")
114 .chrome_app_guid());
115 EXPECT_TRUE(std::wstring(google_update::kAppGuid) ==
116 TestConfiguration(L"spam.exe --multi-install --chrome",
117 ERROR_SUCCESS, L"foo-bar")
118 .chrome_app_guid());
119 EXPECT_TRUE(std::wstring(google_update::kMultiInstallAppGuid) ==
120 TestConfiguration(L"spam.exe --multi-install --chrome",
121 ERROR_SUCCESS, L"foo-multi")
122 .chrome_app_guid());
125 TEST(MiniInstallerConfigurationTest, HasChrome) {
126 EXPECT_TRUE(TestConfiguration(L"spam.exe").has_chrome());
127 EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome").has_chrome());
128 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome")
129 .has_chrome());
130 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome-frame").has_chrome());
131 EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install").has_chrome());
134 TEST(MiniInstallerConfigurationTest, HasChromeFrame) {
135 EXPECT_FALSE(TestConfiguration(L"spam.exe").has_chrome_frame());
136 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").has_chrome_frame());
137 EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install --chrome")
138 .has_chrome_frame());
139 EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome-frame").has_chrome_frame());
140 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome-frame")
141 .has_chrome_frame());
142 EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install")
143 .has_chrome_frame());
146 TEST(MiniInstallerConfigurationTest, IsMultiInstall) {
147 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_multi_install());
148 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").is_multi_install());
149 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome")
150 .is_multi_install());
151 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome-frame")
152 .is_multi_install());
153 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome-frame")
154 .is_multi_install());
155 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install")
156 .is_multi_install());
159 TEST(MiniInstallerConfigurationTest, IsSystemLevel) {
160 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_system_level());
161 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").is_system_level());
162 EXPECT_TRUE(TestConfiguration(L"spam.exe --system-level").is_system_level());