OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/registry.h" | |
9 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
10 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/win/registry.h" |
11 #include "chrome/installer/util/create_reg_key_work_item.h" | 11 #include "chrome/installer/util/create_reg_key_work_item.h" |
12 #include "chrome/installer/util/work_item.h" | 12 #include "chrome/installer/util/work_item.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
| 15 using base::win::RegKey; |
| 16 |
15 namespace { | 17 namespace { |
16 wchar_t test_root[] = L"TmpTmp"; | 18 |
17 class CreateRegKeyWorkItemTest : public testing::Test { | 19 wchar_t test_root[] = L"TmpTmp"; |
18 protected: | 20 |
19 virtual void SetUp() { | 21 class CreateRegKeyWorkItemTest : public testing::Test { |
20 // Create a temporary key for testing | 22 protected: |
21 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); | 23 virtual void SetUp() { |
22 key.DeleteKey(test_root); | 24 // Create a temporary key for testing |
23 ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); | 25 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); |
24 ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ)); | 26 key.DeleteKey(test_root); |
25 } | 27 ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); |
26 virtual void TearDown() { | 28 ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ)); |
27 logging::CloseLogFile(); | 29 } |
28 // Clean up the temporary key | 30 virtual void TearDown() { |
29 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); | 31 logging::CloseLogFile(); |
30 ASSERT_TRUE(key.DeleteKey(test_root)); | 32 // Clean up the temporary key |
31 } | 33 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); |
32 }; | 34 ASSERT_TRUE(key.DeleteKey(test_root)); |
| 35 } |
33 }; | 36 }; |
34 | 37 |
| 38 } // namespace |
| 39 |
35 TEST_F(CreateRegKeyWorkItemTest, CreateKey) { | 40 TEST_F(CreateRegKeyWorkItemTest, CreateKey) { |
36 RegKey key; | 41 RegKey key; |
37 | 42 |
38 FilePath parent_key(test_root); | 43 FilePath parent_key(test_root); |
39 parent_key = parent_key.AppendASCII("a"); | 44 parent_key = parent_key.AppendASCII("a"); |
40 ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, parent_key.value().c_str(), | 45 ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, parent_key.value().c_str(), |
41 KEY_READ)); | 46 KEY_READ)); |
42 | 47 |
43 FilePath top_key_to_create(parent_key); | 48 FilePath top_key_to_create(parent_key); |
44 top_key_to_create = top_key_to_create.AppendASCII("b"); | 49 top_key_to_create = top_key_to_create.AppendASCII("b"); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 KEY_READ | KEY_SET_VALUE)); | 186 KEY_READ | KEY_SET_VALUE)); |
182 EXPECT_TRUE(key.WriteValue(L"name", L"value")); | 187 EXPECT_TRUE(key.WriteValue(L"name", L"value")); |
183 key.Close(); | 188 key.Close(); |
184 | 189 |
185 work_item->Rollback(); | 190 work_item->Rollback(); |
186 | 191 |
187 // Rollback should not remove the key. | 192 // Rollback should not remove the key. |
188 EXPECT_TRUE(key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), | 193 EXPECT_TRUE(key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), |
189 KEY_READ)); | 194 KEY_READ)); |
190 } | 195 } |
OLD | NEW |