OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/installer/mini_installer/configuration.h" | 5 #include "chrome/installer/mini_installer/configuration.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "chrome/installer/mini_installer/appid.h" | 10 #include "chrome/installer/mini_installer/appid.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 using mini_installer::Configuration; | 13 using mini_installer::Configuration; |
14 | 14 |
15 class TestConfiguration : public Configuration { | 15 class TestConfiguration : public Configuration { |
16 public: | 16 public: |
17 explicit TestConfiguration(const wchar_t* command_line) : Configuration() { | 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"") { |
18 Initialize(command_line); | 22 Initialize(command_line); |
19 } | 23 } |
| 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); |
| 31 } |
| 32 void SetRegistryResults(bool openkey, LONG ret, const wchar_t* value) { |
| 33 } |
20 private: | 34 private: |
| 35 bool open_registry_key_result_; |
| 36 LONG read_registry_value_result_; |
| 37 const wchar_t* read_registry_value_ = L""; |
| 38 |
21 void Initialize(const wchar_t* command_line) { | 39 void Initialize(const wchar_t* command_line) { |
22 Clear(); | 40 Clear(); |
23 ASSERT_TRUE(ParseCommandLine(command_line)); | 41 ASSERT_TRUE(ParseCommandLine(command_line)); |
24 } | 42 } |
| 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_; |
| 49 } |
25 }; | 50 }; |
26 | 51 |
27 // Test that the operation type is CLEANUP iff --cleanup is on the cmdline. | 52 // Test that the operation type is CLEANUP iff --cleanup is on the cmdline. |
28 TEST(MiniInstallerConfigurationTest, Operation) { | 53 TEST(MiniInstallerConfigurationTest, Operation) { |
29 EXPECT_EQ(Configuration::INSTALL_PRODUCT, | 54 EXPECT_EQ(Configuration::INSTALL_PRODUCT, |
30 TestConfiguration(L"spam.exe").operation()); | 55 TestConfiguration(L"spam.exe").operation()); |
31 EXPECT_EQ(Configuration::INSTALL_PRODUCT, | 56 EXPECT_EQ(Configuration::INSTALL_PRODUCT, |
32 TestConfiguration(L"spam.exe --clean").operation()); | 57 TestConfiguration(L"spam.exe --clean").operation()); |
33 EXPECT_EQ(Configuration::INSTALL_PRODUCT, | 58 EXPECT_EQ(Configuration::INSTALL_PRODUCT, |
34 TestConfiguration(L"spam.exe --cleanupthis").operation()); | 59 TestConfiguration(L"spam.exe --cleanupthis").operation()); |
(...skipping 30 matching lines...) Expand all Loading... |
65 EXPECT_TRUE(std::wstring(kCommandLines[i]) == | 90 EXPECT_TRUE(std::wstring(kCommandLines[i]) == |
66 TestConfiguration(kCommandLines[i]).command_line()); | 91 TestConfiguration(kCommandLines[i]).command_line()); |
67 } | 92 } |
68 } | 93 } |
69 | 94 |
70 TEST(MiniInstallerConfigurationTest, ChromeAppGuid) { | 95 TEST(MiniInstallerConfigurationTest, ChromeAppGuid) { |
71 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == | 96 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == |
72 TestConfiguration(L"spam.exe").chrome_app_guid()); | 97 TestConfiguration(L"spam.exe").chrome_app_guid()); |
73 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == | 98 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == |
74 TestConfiguration(L"spam.exe --chrome").chrome_app_guid()); | 99 TestConfiguration(L"spam.exe --chrome").chrome_app_guid()); |
75 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == | 100 EXPECT_TRUE(std::wstring(google_update::kChromeFrameAppGuid) == |
76 TestConfiguration(L"spam.exe --multi-install --chrome") | |
77 .chrome_app_guid()); | |
78 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == | |
79 TestConfiguration(L"spam.exe --chrome-frame").chrome_app_guid()); | 101 TestConfiguration(L"spam.exe --chrome-frame").chrome_app_guid()); |
80 EXPECT_TRUE(std::wstring(google_update::kSxSAppGuid) == | 102 EXPECT_TRUE(std::wstring(google_update::kSxSAppGuid) == |
81 TestConfiguration(L"spam.exe --chrome-sxs").chrome_app_guid()); | 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()); |
82 } | 123 } |
83 | 124 |
84 TEST(MiniInstallerConfigurationTest, HasChrome) { | 125 TEST(MiniInstallerConfigurationTest, HasChrome) { |
85 EXPECT_TRUE(TestConfiguration(L"spam.exe").has_chrome()); | 126 EXPECT_TRUE(TestConfiguration(L"spam.exe").has_chrome()); |
86 EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome").has_chrome()); | 127 EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome").has_chrome()); |
87 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome") | 128 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome") |
88 .has_chrome()); | 129 .has_chrome()); |
89 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome-frame").has_chrome()); | 130 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome-frame").has_chrome()); |
90 EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install").has_chrome()); | 131 EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install").has_chrome()); |
91 } | 132 } |
(...skipping 21 matching lines...) Expand all Loading... |
113 .is_multi_install()); | 154 .is_multi_install()); |
114 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install") | 155 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install") |
115 .is_multi_install()); | 156 .is_multi_install()); |
116 } | 157 } |
117 | 158 |
118 TEST(MiniInstallerConfigurationTest, IsSystemLevel) { | 159 TEST(MiniInstallerConfigurationTest, IsSystemLevel) { |
119 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_system_level()); | 160 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_system_level()); |
120 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").is_system_level()); | 161 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").is_system_level()); |
121 EXPECT_TRUE(TestConfiguration(L"spam.exe --system-level").is_system_level()); | 162 EXPECT_TRUE(TestConfiguration(L"spam.exe --system-level").is_system_level()); |
122 } | 163 } |
OLD | NEW |