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/util/product_unittest.h" | 5 #include "chrome/installer/util/product_unittest.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/test/test_reg_util_win.h" |
8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
9 #include "chrome/installer/util/chrome_frame_distribution.h" | 10 #include "chrome/installer/util/chrome_frame_distribution.h" |
10 #include "chrome/installer/util/google_update_constants.h" | 11 #include "chrome/installer/util/google_update_constants.h" |
11 #include "chrome/installer/util/installation_state.h" | 12 #include "chrome/installer/util/installation_state.h" |
12 #include "chrome/installer/util/installer_state.h" | 13 #include "chrome/installer/util/installer_state.h" |
13 #include "chrome/installer/util/master_preferences.h" | 14 #include "chrome/installer/util/master_preferences.h" |
14 #include "chrome/installer/util/product.h" | 15 #include "chrome/installer/util/product.h" |
15 | 16 |
16 using base::win::RegKey; | 17 using base::win::RegKey; |
17 using installer::Product; | 18 using installer::Product; |
18 using installer::MasterPreferences; | 19 using installer::MasterPreferences; |
| 20 using registry_util::RegistryOverrideManager; |
19 | 21 |
20 void TestWithTempDir::SetUp() { | 22 void TestWithTempDir::SetUp() { |
21 // Name a subdirectory of the user temp directory. | 23 // Name a subdirectory of the user temp directory. |
22 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 24 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
23 } | 25 } |
24 | 26 |
25 void TestWithTempDir::TearDown() { | 27 void TestWithTempDir::TearDown() { |
26 logging::CloseLogFile(); | 28 logging::CloseLogFile(); |
27 ASSERT_TRUE(test_dir_.Delete()); | 29 ASSERT_TRUE(test_dir_.Delete()); |
28 } | 30 } |
29 | 31 |
30 //////////////////////////////////////////////////////////////////////////////// | 32 //////////////////////////////////////////////////////////////////////////////// |
31 | 33 |
32 void TestWithTempDirAndDeleteTempOverrideKeys::SetUp() { | 34 void TestWithTempDirAndDeleteTempOverrideKeys::SetUp() { |
33 TempRegKeyOverride::DeleteAllTempKeys(); | |
34 TestWithTempDir::SetUp(); | 35 TestWithTempDir::SetUp(); |
35 } | 36 } |
36 | 37 |
37 void TestWithTempDirAndDeleteTempOverrideKeys::TearDown() { | 38 void TestWithTempDirAndDeleteTempOverrideKeys::TearDown() { |
38 TestWithTempDir::TearDown(); | 39 TestWithTempDir::TearDown(); |
39 TempRegKeyOverride::DeleteAllTempKeys(); | |
40 } | |
41 | |
42 //////////////////////////////////////////////////////////////////////////////// | |
43 const wchar_t TempRegKeyOverride::kTempTestKeyPath[] = | |
44 L"Software\\Chromium\\TempTestKeys"; | |
45 | |
46 TempRegKeyOverride::TempRegKeyOverride(HKEY override, const wchar_t* temp_name) | |
47 : override_(override), temp_name_(temp_name) { | |
48 DCHECK(temp_name && lstrlenW(temp_name)); | |
49 std::wstring key_path(kTempTestKeyPath); | |
50 key_path += L"\\" + temp_name_; | |
51 EXPECT_EQ(ERROR_SUCCESS, | |
52 temp_key_.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_ALL_ACCESS)); | |
53 EXPECT_EQ(ERROR_SUCCESS, | |
54 ::RegOverridePredefKey(override_, temp_key_.Handle())); | |
55 } | |
56 | |
57 TempRegKeyOverride::~TempRegKeyOverride() { | |
58 ::RegOverridePredefKey(override_, NULL); | |
59 // The temp key will be deleted via a call to DeleteAllTempKeys(). | |
60 } | |
61 | |
62 // static | |
63 void TempRegKeyOverride::DeleteAllTempKeys() { | |
64 RegKey key; | |
65 if (key.Open(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS) == ERROR_SUCCESS) { | |
66 key.DeleteKey(kTempTestKeyPath); | |
67 } | |
68 } | 40 } |
69 | 41 |
70 //////////////////////////////////////////////////////////////////////////////// | 42 //////////////////////////////////////////////////////////////////////////////// |
71 | 43 |
72 class ProductTest : public TestWithTempDirAndDeleteTempOverrideKeys { | 44 class ProductTest : public TestWithTempDirAndDeleteTempOverrideKeys { |
73 protected: | 45 protected: |
74 }; | 46 }; |
75 | 47 |
76 TEST_F(ProductTest, ProductInstallBasic) { | 48 TEST_F(ProductTest, ProductInstallBasic) { |
77 // TODO(tommi): We should mock this and use our mocked distribution. | 49 // TODO(tommi): We should mock this and use our mocked distribution. |
(...skipping 25 matching lines...) Expand all Loading... |
103 EXPECT_EQ(std::wstring::npos, | 75 EXPECT_EQ(std::wstring::npos, |
104 user_data.value().find(program_files.value())); | 76 user_data.value().find(program_files.value())); |
105 | 77 |
106 // There should be no installed version in the registry. | 78 // There should be no installed version in the registry. |
107 machine_state.Initialize(); | 79 machine_state.Initialize(); |
108 EXPECT_TRUE(machine_state.GetProductState( | 80 EXPECT_TRUE(machine_state.GetProductState( |
109 system_level, distribution->GetType()) == NULL); | 81 system_level, distribution->GetType()) == NULL); |
110 | 82 |
111 HKEY root = installer_state.root_key(); | 83 HKEY root = installer_state.root_key(); |
112 { | 84 { |
113 TempRegKeyOverride override(root, L"root_pit"); | 85 RegistryOverrideManager override_manager; |
| 86 override_manager.OverrideRegistry(root, L"root_pit"); |
114 | 87 |
115 // Let's pretend chrome is installed. | 88 // Let's pretend chrome is installed. |
116 RegKey version_key(root, distribution->GetVersionKey().c_str(), | 89 RegKey version_key(root, distribution->GetVersionKey().c_str(), |
117 KEY_ALL_ACCESS); | 90 KEY_ALL_ACCESS); |
118 ASSERT_TRUE(version_key.Valid()); | 91 ASSERT_TRUE(version_key.Valid()); |
119 | 92 |
120 const char kCurrentVersion[] = "1.2.3.4"; | 93 const char kCurrentVersion[] = "1.2.3.4"; |
121 scoped_ptr<Version> current_version( | 94 scoped_ptr<Version> current_version( |
122 Version::GetVersionFromString(kCurrentVersion)); | 95 Version::GetVersionFromString(kCurrentVersion)); |
123 version_key.WriteValue(google_update::kRegVersionField, | 96 version_key.WriteValue(google_update::kRegVersionField, |
(...skipping 24 matching lines...) Expand all Loading... |
148 if (chrome_state != NULL) | 121 if (chrome_state != NULL) |
149 EXPECT_TRUE(chrome_state->is_msi()); | 122 EXPECT_TRUE(chrome_state->is_msi()); |
150 } | 123 } |
151 } | 124 } |
152 | 125 |
153 TEST_F(ProductTest, LaunchChrome) { | 126 TEST_F(ProductTest, LaunchChrome) { |
154 // TODO(tommi): Test Product::LaunchChrome and | 127 // TODO(tommi): Test Product::LaunchChrome and |
155 // Product::LaunchChromeAndWait. | 128 // Product::LaunchChromeAndWait. |
156 LOG(ERROR) << "Test not implemented."; | 129 LOG(ERROR) << "Test not implemented."; |
157 } | 130 } |
OLD | NEW |