| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/win/registry.h" | 9 #include "base/win/registry.h" |
| 10 #include "chrome/installer/util/registry_key_backup.h" | 10 #include "chrome/installer/util/registry_key_backup.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 | 27 |
| 28 RegistryTestData test_data_; | 28 RegistryTestData test_data_; |
| 29 std::wstring destination_path_; | 29 std::wstring destination_path_; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 // Test that writing an uninitialized backup does nothing. | 32 // Test that writing an uninitialized backup does nothing. |
| 33 TEST_F(RegistryKeyBackupTest, Uninitialized) { | 33 TEST_F(RegistryKeyBackupTest, Uninitialized) { |
| 34 RegistryKeyBackup backup; | 34 RegistryKeyBackup backup; |
| 35 | 35 |
| 36 EXPECT_TRUE(backup.WriteTo(test_data_.root_key(), destination_path_.c_str())); | 36 EXPECT_TRUE(backup.WriteTo(test_data_.root_key(), |
| 37 destination_path_.c_str(), |
| 38 WorkItem::kWow64Default)); |
| 37 EXPECT_FALSE(RegKey(test_data_.root_key(), destination_path_.c_str(), | 39 EXPECT_FALSE(RegKey(test_data_.root_key(), destination_path_.c_str(), |
| 38 KEY_READ).Valid()); | 40 KEY_READ).Valid()); |
| 39 } | 41 } |
| 40 | 42 |
| 41 // Test that initializing a backup with a non-existent key works, and that | 43 // Test that initializing a backup with a non-existent key works, and that |
| 42 // writing it back out does nothing. | 44 // writing it back out does nothing. |
| 43 TEST_F(RegistryKeyBackupTest, MissingKey) { | 45 TEST_F(RegistryKeyBackupTest, MissingKey) { |
| 44 std::wstring non_existent_key_path(test_data_.base_path() + L"\\NoKeyHere"); | 46 std::wstring non_existent_key_path(test_data_.base_path() + L"\\NoKeyHere"); |
| 45 RegistryKeyBackup backup; | 47 RegistryKeyBackup backup; |
| 46 | 48 |
| 47 EXPECT_TRUE(backup.Initialize(test_data_.root_key(), | 49 EXPECT_TRUE(backup.Initialize(test_data_.root_key(), |
| 48 non_existent_key_path.c_str())); | 50 non_existent_key_path.c_str(), |
| 49 EXPECT_TRUE(backup.WriteTo(test_data_.root_key(), destination_path_.c_str())); | 51 WorkItem::kWow64Default)); |
| 52 EXPECT_TRUE(backup.WriteTo(test_data_.root_key(), |
| 53 destination_path_.c_str(), |
| 54 WorkItem::kWow64Default)); |
| 50 EXPECT_FALSE(RegKey(test_data_.root_key(), destination_path_.c_str(), | 55 EXPECT_FALSE(RegKey(test_data_.root_key(), destination_path_.c_str(), |
| 51 KEY_READ).Valid()); | 56 KEY_READ).Valid()); |
| 52 } | 57 } |
| 53 | 58 |
| 54 // Test that reading some data then writing it out does the right thing. | 59 // Test that reading some data then writing it out does the right thing. |
| 55 TEST_F(RegistryKeyBackupTest, ReadWrite) { | 60 TEST_F(RegistryKeyBackupTest, ReadWrite) { |
| 56 RegistryKeyBackup backup; | 61 RegistryKeyBackup backup; |
| 57 | 62 |
| 58 EXPECT_TRUE(backup.Initialize(test_data_.root_key(), | 63 EXPECT_TRUE(backup.Initialize(test_data_.root_key(), |
| 59 test_data_.non_empty_key_path().c_str())); | 64 test_data_.non_empty_key_path().c_str(), |
| 60 EXPECT_TRUE(backup.WriteTo(test_data_.root_key(), destination_path_.c_str())); | 65 WorkItem::kWow64Default)); |
| 66 EXPECT_TRUE(backup.WriteTo(test_data_.root_key(), |
| 67 destination_path_.c_str(), |
| 68 WorkItem::kWow64Default)); |
| 61 test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(), | 69 test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(), |
| 62 destination_path_.c_str()); | 70 destination_path_.c_str()); |
| 63 } | 71 } |
| 64 | 72 |
| 65 // Test that reading some data, swapping, then writing it out does the right | 73 // Test that reading some data, swapping, then writing it out does the right |
| 66 // thing. | 74 // thing. |
| 67 TEST_F(RegistryKeyBackupTest, Swap) { | 75 TEST_F(RegistryKeyBackupTest, Swap) { |
| 68 RegistryKeyBackup backup; | 76 RegistryKeyBackup backup; |
| 69 RegistryKeyBackup other_backup; | 77 RegistryKeyBackup other_backup; |
| 70 | 78 |
| 71 EXPECT_TRUE(backup.Initialize(test_data_.root_key(), | 79 EXPECT_TRUE(backup.Initialize(test_data_.root_key(), |
| 72 test_data_.non_empty_key_path().c_str())); | 80 test_data_.non_empty_key_path().c_str(), |
| 81 WorkItem::kWow64Default)); |
| 73 backup.swap(other_backup); | 82 backup.swap(other_backup); |
| 74 EXPECT_TRUE(other_backup.WriteTo(test_data_.root_key(), | 83 EXPECT_TRUE(other_backup.WriteTo(test_data_.root_key(), |
| 75 destination_path_.c_str())); | 84 destination_path_.c_str(), |
| 85 WorkItem::kWow64Default)); |
| 76 | 86 |
| 77 // Now make sure the one we started with is truly empty. | 87 // Now make sure the one we started with is truly empty. |
| 78 EXPECT_EQ(ERROR_SUCCESS, | 88 EXPECT_EQ(ERROR_SUCCESS, |
| 79 RegKey(test_data_.root_key(), L"", KEY_QUERY_VALUE) | 89 RegKey(test_data_.root_key(), L"", KEY_QUERY_VALUE) |
| 80 .DeleteKey(destination_path_.c_str())); | 90 .DeleteKey(destination_path_.c_str())); |
| 81 EXPECT_TRUE(backup.WriteTo(test_data_.root_key(), | 91 EXPECT_TRUE(backup.WriteTo(test_data_.root_key(), |
| 82 destination_path_.c_str())); | 92 destination_path_.c_str(), |
| 93 WorkItem::kWow64Default)); |
| 83 EXPECT_FALSE(RegKey(test_data_.root_key(), destination_path_.c_str(), | 94 EXPECT_FALSE(RegKey(test_data_.root_key(), destination_path_.c_str(), |
| 84 KEY_READ).Valid()); | 95 KEY_READ).Valid()); |
| 85 } | 96 } |
| OLD | NEW |