Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: chrome/installer/util/create_reg_key_work_item_unittest.cc

Issue 282363003: Add WOW64 support to the installer registry work items (Closed) Base URL: https://chromium.googlesource.com/chromium/src
Patch Set: nits. fix call to DeleteRegistryKey Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 key.Create(HKEY_CURRENT_USER, parent_key.value().c_str(), KEY_READ)); 47 key.Create(HKEY_CURRENT_USER, parent_key.value().c_str(), KEY_READ));
48 48
49 base::FilePath top_key_to_create(parent_key); 49 base::FilePath top_key_to_create(parent_key);
50 top_key_to_create = top_key_to_create.AppendASCII("b"); 50 top_key_to_create = top_key_to_create.AppendASCII("b");
51 51
52 base::FilePath key_to_create(top_key_to_create); 52 base::FilePath key_to_create(top_key_to_create);
53 key_to_create = key_to_create.AppendASCII("c"); 53 key_to_create = key_to_create.AppendASCII("c");
54 key_to_create = key_to_create.AppendASCII("d"); 54 key_to_create = key_to_create.AppendASCII("d");
55 55
56 scoped_ptr<CreateRegKeyWorkItem> work_item( 56 scoped_ptr<CreateRegKeyWorkItem> work_item(
57 WorkItem::CreateCreateRegKeyWorkItem(HKEY_CURRENT_USER, 57 WorkItem::CreateCreateRegKeyWorkItem(
58 key_to_create.value())); 58 HKEY_CURRENT_USER, key_to_create.value(), WorkItem::kWow64Default));
59 59
60 EXPECT_TRUE(work_item->Do()); 60 EXPECT_TRUE(work_item->Do());
61 61
62 EXPECT_EQ(ERROR_SUCCESS, 62 EXPECT_EQ(ERROR_SUCCESS,
63 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ)); 63 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ));
64 64
65 work_item->Rollback(); 65 work_item->Rollback();
66 66
67 // Rollback should delete all the keys up to top_key_to_create. 67 // Rollback should delete all the keys up to top_key_to_create.
68 EXPECT_NE(ERROR_SUCCESS, 68 EXPECT_NE(ERROR_SUCCESS,
69 key.Open(HKEY_CURRENT_USER, top_key_to_create.value().c_str(), KEY_READ)); 69 key.Open(HKEY_CURRENT_USER, top_key_to_create.value().c_str(), KEY_READ));
70 EXPECT_EQ(ERROR_SUCCESS, 70 EXPECT_EQ(ERROR_SUCCESS,
71 key.Open(HKEY_CURRENT_USER, parent_key.value().c_str(), KEY_READ)); 71 key.Open(HKEY_CURRENT_USER, parent_key.value().c_str(), KEY_READ));
72 } 72 }
73 73
74 TEST_F(CreateRegKeyWorkItemTest, CreateExistingKey) { 74 TEST_F(CreateRegKeyWorkItemTest, CreateExistingKey) {
75 RegKey key; 75 RegKey key;
76 76
77 base::FilePath key_to_create(test_root); 77 base::FilePath key_to_create(test_root);
78 key_to_create = key_to_create.AppendASCII("aa"); 78 key_to_create = key_to_create.AppendASCII("aa");
79 ASSERT_EQ(ERROR_SUCCESS, 79 ASSERT_EQ(ERROR_SUCCESS,
80 key.Create(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ)); 80 key.Create(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ));
81 81
82 scoped_ptr<CreateRegKeyWorkItem> work_item( 82 scoped_ptr<CreateRegKeyWorkItem> work_item(
83 WorkItem::CreateCreateRegKeyWorkItem(HKEY_CURRENT_USER, 83 WorkItem::CreateCreateRegKeyWorkItem(
84 key_to_create.value())); 84 HKEY_CURRENT_USER, key_to_create.value(), WorkItem::kWow64Default));
85 85
86 EXPECT_TRUE(work_item->Do()); 86 EXPECT_TRUE(work_item->Do());
87 87
88 EXPECT_EQ(ERROR_SUCCESS, 88 EXPECT_EQ(ERROR_SUCCESS,
89 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ)); 89 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ));
90 90
91 work_item->Rollback(); 91 work_item->Rollback();
92 92
93 // Rollback should not remove the key since it exists before 93 // Rollback should not remove the key since it exists before
94 // the CreateRegKeyWorkItem is called. 94 // the CreateRegKeyWorkItem is called.
95 EXPECT_EQ(ERROR_SUCCESS, 95 EXPECT_EQ(ERROR_SUCCESS,
96 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ)); 96 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ));
97 } 97 }
98 98
99 TEST_F(CreateRegKeyWorkItemTest, CreateSharedKey) { 99 TEST_F(CreateRegKeyWorkItemTest, CreateSharedKey) {
100 RegKey key; 100 RegKey key;
101 base::FilePath key_to_create_1(test_root); 101 base::FilePath key_to_create_1(test_root);
102 key_to_create_1 = key_to_create_1.AppendASCII("aaa"); 102 key_to_create_1 = key_to_create_1.AppendASCII("aaa");
103 103
104 base::FilePath key_to_create_2(key_to_create_1); 104 base::FilePath key_to_create_2(key_to_create_1);
105 key_to_create_2 = key_to_create_2.AppendASCII("bbb"); 105 key_to_create_2 = key_to_create_2.AppendASCII("bbb");
106 106
107 base::FilePath key_to_create_3(key_to_create_2); 107 base::FilePath key_to_create_3(key_to_create_2);
108 key_to_create_3 = key_to_create_3.AppendASCII("ccc"); 108 key_to_create_3 = key_to_create_3.AppendASCII("ccc");
109 109
110 scoped_ptr<CreateRegKeyWorkItem> work_item( 110 scoped_ptr<CreateRegKeyWorkItem> work_item(
111 WorkItem::CreateCreateRegKeyWorkItem(HKEY_CURRENT_USER, 111 WorkItem::CreateCreateRegKeyWorkItem(
112 key_to_create_3.value())); 112 HKEY_CURRENT_USER, key_to_create_3.value(), WorkItem::kWow64Default));
113 113
114 EXPECT_TRUE(work_item->Do()); 114 EXPECT_TRUE(work_item->Do());
115 115
116 EXPECT_EQ(ERROR_SUCCESS, 116 EXPECT_EQ(ERROR_SUCCESS,
117 key.Open(HKEY_CURRENT_USER, key_to_create_3.value().c_str(), KEY_READ)); 117 key.Open(HKEY_CURRENT_USER, key_to_create_3.value().c_str(), KEY_READ));
118 118
119 // Create another key under key_to_create_2 119 // Create another key under key_to_create_2
120 base::FilePath key_to_create_4(key_to_create_2); 120 base::FilePath key_to_create_4(key_to_create_2);
121 key_to_create_4 = key_to_create_4.AppendASCII("ddd"); 121 key_to_create_4 = key_to_create_4.AppendASCII("ddd");
122 ASSERT_EQ(ERROR_SUCCESS, 122 ASSERT_EQ(ERROR_SUCCESS,
(...skipping 17 matching lines...) Expand all
140 base::FilePath key_to_create_1(test_root); 140 base::FilePath key_to_create_1(test_root);
141 key_to_create_1 = key_to_create_1.AppendASCII("aaaa"); 141 key_to_create_1 = key_to_create_1.AppendASCII("aaaa");
142 142
143 base::FilePath key_to_create_2(key_to_create_1); 143 base::FilePath key_to_create_2(key_to_create_1);
144 key_to_create_2 = key_to_create_2.AppendASCII("bbbb"); 144 key_to_create_2 = key_to_create_2.AppendASCII("bbbb");
145 145
146 base::FilePath key_to_create_3(key_to_create_2); 146 base::FilePath key_to_create_3(key_to_create_2);
147 key_to_create_3 = key_to_create_3.AppendASCII("cccc"); 147 key_to_create_3 = key_to_create_3.AppendASCII("cccc");
148 148
149 scoped_ptr<CreateRegKeyWorkItem> work_item( 149 scoped_ptr<CreateRegKeyWorkItem> work_item(
150 WorkItem::CreateCreateRegKeyWorkItem(HKEY_CURRENT_USER, 150 WorkItem::CreateCreateRegKeyWorkItem(
151 key_to_create_3.value())); 151 HKEY_CURRENT_USER, key_to_create_3.value(), WorkItem::kWow64Default));
152 152
153 EXPECT_TRUE(work_item->Do()); 153 EXPECT_TRUE(work_item->Do());
154 154
155 EXPECT_EQ(ERROR_SUCCESS, 155 EXPECT_EQ(ERROR_SUCCESS,
156 key.Open(HKEY_CURRENT_USER, key_to_create_3.value().c_str(), KEY_READ)); 156 key.Open(HKEY_CURRENT_USER, key_to_create_3.value().c_str(), KEY_READ));
157 key.Close(); 157 key.Close();
158 158
159 // now delete key_to_create_3 159 // now delete key_to_create_3
160 ASSERT_EQ(ERROR_SUCCESS, 160 ASSERT_EQ(ERROR_SUCCESS,
161 RegDeleteKey(HKEY_CURRENT_USER, key_to_create_3.value().c_str())); 161 RegDeleteKey(HKEY_CURRENT_USER, key_to_create_3.value().c_str()));
162 ASSERT_NE(ERROR_SUCCESS, 162 ASSERT_NE(ERROR_SUCCESS,
163 key.Open(HKEY_CURRENT_USER, key_to_create_3.value().c_str(), KEY_READ)); 163 key.Open(HKEY_CURRENT_USER, key_to_create_3.value().c_str(), KEY_READ));
164 164
165 work_item->Rollback(); 165 work_item->Rollback();
166 166
167 // key_to_create_3 has already been deleted, Rollback should delete 167 // key_to_create_3 has already been deleted, Rollback should delete
168 // the rest. 168 // the rest.
169 ASSERT_NE(ERROR_SUCCESS, 169 ASSERT_NE(ERROR_SUCCESS,
170 key.Open(HKEY_CURRENT_USER, key_to_create_1.value().c_str(), KEY_READ)); 170 key.Open(HKEY_CURRENT_USER, key_to_create_1.value().c_str(), KEY_READ));
171 } 171 }
172 172
173 TEST_F(CreateRegKeyWorkItemTest, RollbackWithSetValue) { 173 TEST_F(CreateRegKeyWorkItemTest, RollbackWithSetValue) {
174 RegKey key; 174 RegKey key;
175 175
176 base::FilePath key_to_create(test_root); 176 base::FilePath key_to_create(test_root);
177 key_to_create = key_to_create.AppendASCII("aaaaa"); 177 key_to_create = key_to_create.AppendASCII("aaaaa");
178 178
179 scoped_ptr<CreateRegKeyWorkItem> work_item( 179 scoped_ptr<CreateRegKeyWorkItem> work_item(
180 WorkItem::CreateCreateRegKeyWorkItem(HKEY_CURRENT_USER, 180 WorkItem::CreateCreateRegKeyWorkItem(
181 key_to_create.value())); 181 HKEY_CURRENT_USER, key_to_create.value(), WorkItem::kWow64Default));
182 182
183 EXPECT_TRUE(work_item->Do()); 183 EXPECT_TRUE(work_item->Do());
184 184
185 // Write a value under the key we just created. 185 // Write a value under the key we just created.
186 EXPECT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, 186 EXPECT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER,
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 }
OLDNEW
« no previous file with comments | « chrome/installer/util/create_reg_key_work_item.cc ('k') | chrome/installer/util/delete_reg_key_work_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698