| 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 <windows.h> | 5 #include <windows.h> |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/win/registry.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; | 15 using base::win::RegKey; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 wchar_t test_root[] = L"TmpTmp"; | 19 wchar_t test_root[] = L"TmpTmp"; |
| 20 | 20 |
| 21 class CreateRegKeyWorkItemTest : public testing::Test { | 21 class CreateRegKeyWorkItemTest : public testing::Test { |
| 22 protected: | 22 protected: |
| 23 virtual void SetUp() { | 23 void SetUp() override { |
| 24 // Create a temporary key for testing | 24 // Create a temporary key for testing |
| 25 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); | 25 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); |
| 26 key.DeleteKey(test_root); | 26 key.DeleteKey(test_root); |
| 27 ASSERT_NE(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); | 27 ASSERT_NE(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); |
| 28 ASSERT_EQ(ERROR_SUCCESS, key.Create(HKEY_CURRENT_USER, test_root, | 28 ASSERT_EQ(ERROR_SUCCESS, key.Create(HKEY_CURRENT_USER, test_root, |
| 29 KEY_READ)); | 29 KEY_READ)); |
| 30 } | 30 } |
| 31 virtual void TearDown() { | 31 void TearDown() override { |
| 32 logging::CloseLogFile(); | 32 logging::CloseLogFile(); |
| 33 // Clean up the temporary key | 33 // Clean up the temporary key |
| 34 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); | 34 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); |
| 35 ASSERT_EQ(ERROR_SUCCESS, key.DeleteKey(test_root)); | 35 ASSERT_EQ(ERROR_SUCCESS, key.DeleteKey(test_root)); |
| 36 } | 36 } |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 TEST_F(CreateRegKeyWorkItemTest, CreateKey) { | 41 TEST_F(CreateRegKeyWorkItemTest, CreateKey) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 key_to_create.value().c_str(), KEY_READ | KEY_SET_VALUE)); | 187 key_to_create.value().c_str(), KEY_READ | KEY_SET_VALUE)); |
| 188 EXPECT_EQ(ERROR_SUCCESS, key.WriteValue(L"name", L"value")); | 188 EXPECT_EQ(ERROR_SUCCESS, key.WriteValue(L"name", L"value")); |
| 189 key.Close(); | 189 key.Close(); |
| 190 | 190 |
| 191 work_item->Rollback(); | 191 work_item->Rollback(); |
| 192 | 192 |
| 193 // Rollback should not remove the key. | 193 // Rollback should not remove the key. |
| 194 EXPECT_EQ(ERROR_SUCCESS, | 194 EXPECT_EQ(ERROR_SUCCESS, |
| 195 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ)); | 195 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ)); |
| 196 } | 196 } |
| OLD | NEW |