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) : Configuration() { |
18 Initialize(command_line); | 18 Initialize(command_line); |
19 } | 19 } |
| 20 explicit TestConfiguration(const wchar_t* command_line, |
| 21 LONG ret, const wchar_t* value) |
| 22 : Configuration(), |
| 23 open_registry_key_result_(true), |
| 24 read_registry_value_result_(ret), |
| 25 read_registry_value_(value) { |
| 26 Initialize(command_line); |
| 27 } |
| 28 void SetRegistryResults(bool openkey, LONG ret, const wchar_t* value) { |
| 29 } |
20 private: | 30 private: |
| 31 bool open_registry_key_result_; |
| 32 LONG read_registry_value_result_; |
| 33 const wchar_t* read_registry_value_ = L""; |
| 34 |
21 void Initialize(const wchar_t* command_line) { | 35 void Initialize(const wchar_t* command_line) { |
22 Clear(); | 36 Clear(); |
23 ASSERT_TRUE(ParseCommandLine(command_line)); | 37 ASSERT_TRUE(ParseCommandLine(command_line)); |
24 } | 38 } |
| 39 bool ReadClientStateRegistryValue( |
| 40 const HKEY root_key, const wchar_t* app_guid, |
| 41 LONG* retval, ValueString& value) override { |
| 42 *retval = read_registry_value_result_; |
| 43 value.assign(read_registry_value_); |
| 44 return open_registry_key_result_; |
| 45 } |
25 }; | 46 }; |
26 | 47 |
27 // Test that the operation type is CLEANUP iff --cleanup is on the cmdline. | 48 // Test that the operation type is CLEANUP iff --cleanup is on the cmdline. |
28 TEST(MiniInstallerConfigurationTest, Operation) { | 49 TEST(MiniInstallerConfigurationTest, Operation) { |
29 EXPECT_EQ(Configuration::INSTALL_PRODUCT, | 50 EXPECT_EQ(Configuration::INSTALL_PRODUCT, |
30 TestConfiguration(L"spam.exe").operation()); | 51 TestConfiguration(L"spam.exe").operation()); |
31 EXPECT_EQ(Configuration::INSTALL_PRODUCT, | 52 EXPECT_EQ(Configuration::INSTALL_PRODUCT, |
32 TestConfiguration(L"spam.exe --clean").operation()); | 53 TestConfiguration(L"spam.exe --clean").operation()); |
33 EXPECT_EQ(Configuration::INSTALL_PRODUCT, | 54 EXPECT_EQ(Configuration::INSTALL_PRODUCT, |
34 TestConfiguration(L"spam.exe --cleanupthis").operation()); | 55 TestConfiguration(L"spam.exe --cleanupthis").operation()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 TestConfiguration(kCommandLines[i]).command_line()); | 87 TestConfiguration(kCommandLines[i]).command_line()); |
67 } | 88 } |
68 } | 89 } |
69 | 90 |
70 TEST(MiniInstallerConfigurationTest, ChromeAppGuid) { | 91 TEST(MiniInstallerConfigurationTest, ChromeAppGuid) { |
71 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == | 92 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == |
72 TestConfiguration(L"spam.exe").chrome_app_guid()); | 93 TestConfiguration(L"spam.exe").chrome_app_guid()); |
73 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == | 94 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == |
74 TestConfiguration(L"spam.exe --chrome").chrome_app_guid()); | 95 TestConfiguration(L"spam.exe --chrome").chrome_app_guid()); |
75 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == | 96 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == |
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()); | 97 TestConfiguration(L"spam.exe --chrome-frame").chrome_app_guid()); |
80 EXPECT_TRUE(std::wstring(google_update::kSxSAppGuid) == | 98 EXPECT_TRUE(std::wstring(google_update::kSxSAppGuid) == |
81 TestConfiguration(L"spam.exe --chrome-sxs").chrome_app_guid()); | 99 TestConfiguration(L"spam.exe --chrome-sxs").chrome_app_guid()); |
| 100 EXPECT_TRUE(std::wstring(google_update::kMultiInstallAppGuid) == |
| 101 TestConfiguration(L"spam.exe --multi-install --chrome") |
| 102 .chrome_app_guid()); |
| 103 EXPECT_TRUE(std::wstring(google_update::kMultiInstallAppGuid) == |
| 104 TestConfiguration(L"spam.exe --multi-install --chrome", |
| 105 ERROR_INVALID_FUNCTION, L"") |
| 106 .chrome_app_guid()); |
| 107 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == |
| 108 TestConfiguration(L"spam.exe --multi-install --chrome", |
| 109 ERROR_FILE_NOT_FOUND, L"") |
| 110 .chrome_app_guid()); |
| 111 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == |
| 112 TestConfiguration(L"spam.exe --multi-install --chrome", |
| 113 ERROR_SUCCESS, L"foo-bar") |
| 114 .chrome_app_guid()); |
| 115 EXPECT_TRUE(std::wstring(google_update::kMultiInstallAppGuid) == |
| 116 TestConfiguration(L"spam.exe --multi-install --chrome", |
| 117 ERROR_SUCCESS, L"foo-multi") |
| 118 .chrome_app_guid()); |
82 } | 119 } |
83 | 120 |
84 TEST(MiniInstallerConfigurationTest, HasChrome) { | 121 TEST(MiniInstallerConfigurationTest, HasChrome) { |
85 EXPECT_TRUE(TestConfiguration(L"spam.exe").has_chrome()); | 122 EXPECT_TRUE(TestConfiguration(L"spam.exe").has_chrome()); |
86 EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome").has_chrome()); | 123 EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome").has_chrome()); |
87 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome") | 124 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome") |
88 .has_chrome()); | 125 .has_chrome()); |
89 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome-frame").has_chrome()); | 126 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome-frame").has_chrome()); |
90 EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install").has_chrome()); | 127 EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install").has_chrome()); |
91 } | 128 } |
(...skipping 21 matching lines...) Expand all Loading... |
113 .is_multi_install()); | 150 .is_multi_install()); |
114 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install") | 151 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install") |
115 .is_multi_install()); | 152 .is_multi_install()); |
116 } | 153 } |
117 | 154 |
118 TEST(MiniInstallerConfigurationTest, IsSystemLevel) { | 155 TEST(MiniInstallerConfigurationTest, IsSystemLevel) { |
119 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_system_level()); | 156 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_system_level()); |
120 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").is_system_level()); | 157 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").is_system_level()); |
121 EXPECT_TRUE(TestConfiguration(L"spam.exe --system-level").is_system_level()); | 158 EXPECT_TRUE(TestConfiguration(L"spam.exe --system-level").is_system_level()); |
122 } | 159 } |
OLD | NEW |