OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/set_reg_value_work_item.h" |
| 6 |
5 #include <windows.h> | 7 #include <windows.h> |
6 | 8 |
| 9 #include <memory> |
7 #include <string> | 10 #include <string> |
8 | 11 |
9 #include "base/bind.h" | 12 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
11 #include "base/macros.h" | 14 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
14 #include "base/test/test_reg_util_win.h" | 16 #include "base/test/test_reg_util_win.h" |
15 #include "base/win/registry.h" | 17 #include "base/win/registry.h" |
16 #include "chrome/installer/util/set_reg_value_work_item.h" | |
17 #include "chrome/installer/util/work_item.h" | 18 #include "chrome/installer/util/work_item.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 const wchar_t kTestKey[] = L"TempTemp"; | 23 const wchar_t kTestKey[] = L"TempTemp"; |
23 const wchar_t kDataStr1[] = L"data_111"; | 24 const wchar_t kDataStr1[] = L"data_111"; |
24 const wchar_t kDataStr2[] = L"data_222"; | 25 const wchar_t kDataStr2[] = L"data_222"; |
25 const wchar_t kNameStr[] = L"name_str"; | 26 const wchar_t kNameStr[] = L"name_str"; |
26 const wchar_t kNameDword[] = L"name_dword"; | 27 const wchar_t kNameDword[] = L"name_dword"; |
(...skipping 20 matching lines...) Expand all Loading... |
47 private: | 48 private: |
48 registry_util::RegistryOverrideManager registry_override_manager_; | 49 registry_util::RegistryOverrideManager registry_override_manager_; |
49 | 50 |
50 DISALLOW_COPY_AND_ASSIGN(SetRegValueWorkItemTest); | 51 DISALLOW_COPY_AND_ASSIGN(SetRegValueWorkItemTest); |
51 }; | 52 }; |
52 | 53 |
53 } // namespace | 54 } // namespace |
54 | 55 |
55 // Write a new value without overwrite flag. The value should be set. | 56 // Write a new value without overwrite flag. The value should be set. |
56 TEST_F(SetRegValueWorkItemTest, WriteNewNonOverwrite) { | 57 TEST_F(SetRegValueWorkItemTest, WriteNewNonOverwrite) { |
57 scoped_ptr<SetRegValueWorkItem> work_item1( | 58 std::unique_ptr<SetRegValueWorkItem> work_item1( |
58 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, | 59 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, kTestKey, |
59 kTestKey, | 60 WorkItem::kWow64Default, kNameStr, |
60 WorkItem::kWow64Default, | 61 kDataStr1, false)); |
61 kNameStr, | |
62 kDataStr1, | |
63 false)); | |
64 | 62 |
65 scoped_ptr<SetRegValueWorkItem> work_item2( | 63 std::unique_ptr<SetRegValueWorkItem> work_item2( |
66 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, | 64 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, kTestKey, |
67 kTestKey, | 65 WorkItem::kWow64Default, kNameDword, |
68 WorkItem::kWow64Default, | 66 kDword1, false)); |
69 kNameDword, | |
70 kDword1, | |
71 false)); | |
72 | 67 |
73 ASSERT_TRUE(work_item1->Do()); | 68 ASSERT_TRUE(work_item1->Do()); |
74 ASSERT_TRUE(work_item2->Do()); | 69 ASSERT_TRUE(work_item2->Do()); |
75 | 70 |
76 std::wstring read_out; | 71 std::wstring read_out; |
77 DWORD read_dword; | 72 DWORD read_dword; |
78 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); | 73 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); |
79 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValueDW(kNameDword, &read_dword)); | 74 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValueDW(kNameDword, &read_dword)); |
80 EXPECT_EQ(read_out, kDataStr1); | 75 EXPECT_EQ(read_out, kDataStr1); |
81 EXPECT_EQ(read_dword, kDword1); | 76 EXPECT_EQ(read_dword, kDword1); |
82 | 77 |
83 work_item1->Rollback(); | 78 work_item1->Rollback(); |
84 work_item2->Rollback(); | 79 work_item2->Rollback(); |
85 | 80 |
86 // Rollback should delete the value. | 81 // Rollback should delete the value. |
87 EXPECT_FALSE(test_key_.HasValue(kNameStr)); | 82 EXPECT_FALSE(test_key_.HasValue(kNameStr)); |
88 EXPECT_FALSE(test_key_.HasValue(kNameDword)); | 83 EXPECT_FALSE(test_key_.HasValue(kNameDword)); |
89 } | 84 } |
90 | 85 |
91 // Write a new value with overwrite flag. The value should be set. | 86 // Write a new value with overwrite flag. The value should be set. |
92 TEST_F(SetRegValueWorkItemTest, WriteNewOverwrite) { | 87 TEST_F(SetRegValueWorkItemTest, WriteNewOverwrite) { |
93 scoped_ptr<SetRegValueWorkItem> work_item1( | 88 std::unique_ptr<SetRegValueWorkItem> work_item1( |
94 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, | 89 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, kTestKey, |
95 kTestKey, | 90 WorkItem::kWow64Default, kNameStr, |
96 WorkItem::kWow64Default, | 91 kDataStr1, true)); |
97 kNameStr, | |
98 kDataStr1, | |
99 true)); | |
100 | 92 |
101 scoped_ptr<SetRegValueWorkItem> work_item2( | 93 std::unique_ptr<SetRegValueWorkItem> work_item2( |
102 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, | 94 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, kTestKey, |
103 kTestKey, | 95 WorkItem::kWow64Default, kNameDword, |
104 WorkItem::kWow64Default, | 96 kDword1, true)); |
105 kNameDword, | |
106 kDword1, | |
107 true)); | |
108 | 97 |
109 ASSERT_TRUE(work_item1->Do()); | 98 ASSERT_TRUE(work_item1->Do()); |
110 ASSERT_TRUE(work_item2->Do()); | 99 ASSERT_TRUE(work_item2->Do()); |
111 | 100 |
112 std::wstring read_out; | 101 std::wstring read_out; |
113 DWORD read_dword; | 102 DWORD read_dword; |
114 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); | 103 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); |
115 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValueDW(kNameDword, &read_dword)); | 104 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValueDW(kNameDword, &read_dword)); |
116 EXPECT_EQ(read_out, kDataStr1); | 105 EXPECT_EQ(read_out, kDataStr1); |
117 EXPECT_EQ(read_dword, kDword1); | 106 EXPECT_EQ(read_dword, kDword1); |
118 | 107 |
119 work_item1->Rollback(); | 108 work_item1->Rollback(); |
120 work_item2->Rollback(); | 109 work_item2->Rollback(); |
121 | 110 |
122 // Rollback should delete the value. | 111 // Rollback should delete the value. |
123 EXPECT_FALSE(test_key_.HasValue(kNameStr)); | 112 EXPECT_FALSE(test_key_.HasValue(kNameStr)); |
124 EXPECT_FALSE(test_key_.HasValue(kNameDword)); | 113 EXPECT_FALSE(test_key_.HasValue(kNameDword)); |
125 } | 114 } |
126 | 115 |
127 // Write to an existing value without overwrite flag. There should be | 116 // Write to an existing value without overwrite flag. There should be |
128 // no change. | 117 // no change. |
129 TEST_F(SetRegValueWorkItemTest, WriteExistingNonOverwrite) { | 118 TEST_F(SetRegValueWorkItemTest, WriteExistingNonOverwrite) { |
130 // First test REG_SZ value. | 119 // First test REG_SZ value. |
131 // Write data to the value we are going to set. | 120 // Write data to the value we are going to set. |
132 ASSERT_EQ(ERROR_SUCCESS, test_key_.WriteValue(kNameStr, kDataStr1)); | 121 ASSERT_EQ(ERROR_SUCCESS, test_key_.WriteValue(kNameStr, kDataStr1)); |
133 | 122 |
134 scoped_ptr<SetRegValueWorkItem> work_item( | 123 std::unique_ptr<SetRegValueWorkItem> work_item( |
135 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, | 124 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, kTestKey, |
136 kTestKey, | 125 WorkItem::kWow64Default, kNameStr, |
137 WorkItem::kWow64Default, | 126 kDataStr2, false)); |
138 kNameStr, | |
139 kDataStr2, | |
140 false)); | |
141 ASSERT_TRUE(work_item->Do()); | 127 ASSERT_TRUE(work_item->Do()); |
142 | 128 |
143 std::wstring read_out; | 129 std::wstring read_out; |
144 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); | 130 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); |
145 EXPECT_EQ(read_out, kDataStr1); | 131 EXPECT_EQ(read_out, kDataStr1); |
146 | 132 |
147 work_item->Rollback(); | 133 work_item->Rollback(); |
148 EXPECT_TRUE(test_key_.HasValue(kNameStr)); | 134 EXPECT_TRUE(test_key_.HasValue(kNameStr)); |
149 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); | 135 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); |
150 EXPECT_EQ(read_out, kDataStr1); | 136 EXPECT_EQ(read_out, kDataStr1); |
(...skipping 23 matching lines...) Expand all Loading... |
174 // overwritten. | 160 // overwritten. |
175 TEST_F(SetRegValueWorkItemTest, WriteExistingOverwrite) { | 161 TEST_F(SetRegValueWorkItemTest, WriteExistingOverwrite) { |
176 // First test REG_SZ value. | 162 // First test REG_SZ value. |
177 // Write data to the value we are going to set. | 163 // Write data to the value we are going to set. |
178 ASSERT_EQ(ERROR_SUCCESS, test_key_.WriteValue(kNameStr, kDataStr1)); | 164 ASSERT_EQ(ERROR_SUCCESS, test_key_.WriteValue(kNameStr, kDataStr1)); |
179 | 165 |
180 const wchar_t kNameEmpty[] = L"name_empty"; | 166 const wchar_t kNameEmpty[] = L"name_empty"; |
181 ASSERT_EQ(ERROR_SUCCESS, RegSetValueEx(test_key_.Handle(), kNameEmpty, NULL, | 167 ASSERT_EQ(ERROR_SUCCESS, RegSetValueEx(test_key_.Handle(), kNameEmpty, NULL, |
182 REG_SZ, NULL, 0)); | 168 REG_SZ, NULL, 0)); |
183 | 169 |
184 scoped_ptr<SetRegValueWorkItem> work_item1( | 170 std::unique_ptr<SetRegValueWorkItem> work_item1( |
185 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, | 171 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, kTestKey, |
186 kTestKey, | 172 WorkItem::kWow64Default, kNameStr, |
187 WorkItem::kWow64Default, | 173 kDataStr2, true)); |
188 kNameStr, | 174 std::unique_ptr<SetRegValueWorkItem> work_item2( |
189 kDataStr2, | 175 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, kTestKey, |
190 true)); | 176 WorkItem::kWow64Default, kNameEmpty, |
191 scoped_ptr<SetRegValueWorkItem> work_item2( | 177 kDataStr2, true)); |
192 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, | |
193 kTestKey, | |
194 WorkItem::kWow64Default, | |
195 kNameEmpty, | |
196 kDataStr2, | |
197 true)); | |
198 | 178 |
199 ASSERT_TRUE(work_item1->Do()); | 179 ASSERT_TRUE(work_item1->Do()); |
200 ASSERT_TRUE(work_item2->Do()); | 180 ASSERT_TRUE(work_item2->Do()); |
201 | 181 |
202 std::wstring read_out; | 182 std::wstring read_out; |
203 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); | 183 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); |
204 EXPECT_EQ(read_out, kDataStr2); | 184 EXPECT_EQ(read_out, kDataStr2); |
205 | 185 |
206 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameEmpty, &read_out)); | 186 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameEmpty, &read_out)); |
207 EXPECT_EQ(read_out, kDataStr2); | 187 EXPECT_EQ(read_out, kDataStr2); |
208 | 188 |
209 work_item1->Rollback(); | 189 work_item1->Rollback(); |
210 work_item2->Rollback(); | 190 work_item2->Rollback(); |
211 | 191 |
212 EXPECT_TRUE(test_key_.HasValue(kNameStr)); | 192 EXPECT_TRUE(test_key_.HasValue(kNameStr)); |
213 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); | 193 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); |
214 EXPECT_EQ(read_out, kDataStr1); | 194 EXPECT_EQ(read_out, kDataStr1); |
215 | 195 |
216 DWORD type = 0; | 196 DWORD type = 0; |
217 DWORD size = 0; | 197 DWORD size = 0; |
218 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameEmpty, NULL, &size, &type)); | 198 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameEmpty, NULL, &size, &type)); |
219 EXPECT_EQ(static_cast<DWORD>(REG_SZ), type); | 199 EXPECT_EQ(static_cast<DWORD>(REG_SZ), type); |
220 EXPECT_EQ(0u, size); | 200 EXPECT_EQ(0u, size); |
221 | 201 |
222 // Now test REG_DWORD value. | 202 // Now test REG_DWORD value. |
223 // Write data to the value we are going to set. | 203 // Write data to the value we are going to set. |
224 ASSERT_EQ(ERROR_SUCCESS, test_key_.WriteValue(kNameDword, kDword1)); | 204 ASSERT_EQ(ERROR_SUCCESS, test_key_.WriteValue(kNameDword, kDword1)); |
225 scoped_ptr<SetRegValueWorkItem> work_item3( | 205 std::unique_ptr<SetRegValueWorkItem> work_item3( |
226 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, | 206 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, kTestKey, |
227 kTestKey, | 207 WorkItem::kWow64Default, kNameDword, |
228 WorkItem::kWow64Default, | 208 kDword2, true)); |
229 kNameDword, | |
230 kDword2, | |
231 true)); | |
232 ASSERT_TRUE(work_item3->Do()); | 209 ASSERT_TRUE(work_item3->Do()); |
233 | 210 |
234 DWORD read_dword; | 211 DWORD read_dword; |
235 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValueDW(kNameDword, &read_dword)); | 212 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValueDW(kNameDword, &read_dword)); |
236 EXPECT_EQ(read_dword, kDword2); | 213 EXPECT_EQ(read_dword, kDword2); |
237 | 214 |
238 work_item3->Rollback(); | 215 work_item3->Rollback(); |
239 EXPECT_TRUE(test_key_.HasValue(kNameDword)); | 216 EXPECT_TRUE(test_key_.HasValue(kNameDword)); |
240 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValueDW(kNameDword, &read_dword)); | 217 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValueDW(kNameDword, &read_dword)); |
241 EXPECT_EQ(read_dword, kDword1); | 218 EXPECT_EQ(read_dword, kDword1); |
242 } | 219 } |
243 | 220 |
244 // Write a value to a non-existing key. This should fail. | 221 // Write a value to a non-existing key. This should fail. |
245 TEST_F(SetRegValueWorkItemTest, WriteNonExistingKey) { | 222 TEST_F(SetRegValueWorkItemTest, WriteNonExistingKey) { |
246 std::wstring non_existing(kTestKey); | 223 std::wstring non_existing(kTestKey); |
247 non_existing.append(&base::FilePath::kSeparators[0], 1); | 224 non_existing.append(&base::FilePath::kSeparators[0], 1); |
248 non_existing.append(L"NonExistingKey"); | 225 non_existing.append(L"NonExistingKey"); |
249 | 226 |
250 scoped_ptr<SetRegValueWorkItem> work_item( | 227 std::unique_ptr<SetRegValueWorkItem> work_item( |
251 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, | 228 WorkItem::CreateSetRegValueWorkItem( |
252 non_existing.c_str(), | 229 HKEY_CURRENT_USER, non_existing.c_str(), WorkItem::kWow64Default, |
253 WorkItem::kWow64Default, | 230 kNameStr, kDataStr1, false)); |
254 kNameStr, | |
255 kDataStr1, | |
256 false)); | |
257 EXPECT_FALSE(work_item->Do()); | 231 EXPECT_FALSE(work_item->Do()); |
258 | 232 |
259 work_item.reset(WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, | 233 work_item.reset(WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, |
260 non_existing.c_str(), | 234 non_existing.c_str(), |
261 WorkItem::kWow64Default, | 235 WorkItem::kWow64Default, |
262 kNameStr, | 236 kNameStr, |
263 kDword1, | 237 kDword1, |
264 false)); | 238 false)); |
265 EXPECT_FALSE(work_item->Do()); | 239 EXPECT_FALSE(work_item->Do()); |
266 } | 240 } |
(...skipping 12 matching lines...) Expand all Loading... |
279 return desired_new_value; | 253 return desired_new_value; |
280 } | 254 } |
281 | 255 |
282 // Modify an existing value with the callback API. | 256 // Modify an existing value with the callback API. |
283 TEST_F(SetRegValueWorkItemTest, ModifyExistingWithCallback) { | 257 TEST_F(SetRegValueWorkItemTest, ModifyExistingWithCallback) { |
284 // Write |kDataStr1| to the value we are going to modify. | 258 // Write |kDataStr1| to the value we are going to modify. |
285 ASSERT_EQ(ERROR_SUCCESS, test_key_.WriteValue(kNameStr, kDataStr1)); | 259 ASSERT_EQ(ERROR_SUCCESS, test_key_.WriteValue(kNameStr, kDataStr1)); |
286 | 260 |
287 int callback_invocation_count = 0; | 261 int callback_invocation_count = 0; |
288 | 262 |
289 scoped_ptr<SetRegValueWorkItem> work_item( | 263 std::unique_ptr<SetRegValueWorkItem> work_item( |
290 WorkItem::CreateSetRegValueWorkItem( | 264 WorkItem::CreateSetRegValueWorkItem( |
291 HKEY_CURRENT_USER, | 265 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameStr, |
292 kTestKey, | |
293 WorkItem::kWow64Default, | |
294 kNameStr, | |
295 base::Bind(&VerifyPreviousValueAndReplace, &callback_invocation_count, | 266 base::Bind(&VerifyPreviousValueAndReplace, &callback_invocation_count, |
296 kDataStr1, kDataStr2))); | 267 kDataStr1, kDataStr2))); |
297 | 268 |
298 // The callback should not be used until the item is executed. | 269 // The callback should not be used until the item is executed. |
299 EXPECT_EQ(0, callback_invocation_count); | 270 EXPECT_EQ(0, callback_invocation_count); |
300 | 271 |
301 ASSERT_TRUE(work_item->Do()); | 272 ASSERT_TRUE(work_item->Do()); |
302 | 273 |
303 std::wstring read_out; | 274 std::wstring read_out; |
304 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); | 275 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); |
305 EXPECT_EQ(read_out, kDataStr2); | 276 EXPECT_EQ(read_out, kDataStr2); |
306 | 277 |
307 // The callback should have been used only once to achieve this result. | 278 // The callback should have been used only once to achieve this result. |
308 EXPECT_EQ(1, callback_invocation_count); | 279 EXPECT_EQ(1, callback_invocation_count); |
309 | 280 |
310 work_item->Rollback(); | 281 work_item->Rollback(); |
311 | 282 |
312 EXPECT_TRUE(test_key_.HasValue(kNameStr)); | 283 EXPECT_TRUE(test_key_.HasValue(kNameStr)); |
313 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); | 284 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); |
314 EXPECT_EQ(read_out, kDataStr1); | 285 EXPECT_EQ(read_out, kDataStr1); |
315 | 286 |
316 // The callback should not have been used again for the rollback. | 287 // The callback should not have been used again for the rollback. |
317 EXPECT_EQ(1, callback_invocation_count); | 288 EXPECT_EQ(1, callback_invocation_count); |
318 } | 289 } |
319 | 290 |
320 // Modify a non-existing value with the callback API. | 291 // Modify a non-existing value with the callback API. |
321 TEST_F(SetRegValueWorkItemTest, ModifyNonExistingWithCallback) { | 292 TEST_F(SetRegValueWorkItemTest, ModifyNonExistingWithCallback) { |
322 int callback_invocation_count = 0; | 293 int callback_invocation_count = 0; |
323 | 294 |
324 scoped_ptr<SetRegValueWorkItem> work_item( | 295 std::unique_ptr<SetRegValueWorkItem> work_item( |
325 WorkItem::CreateSetRegValueWorkItem( | 296 WorkItem::CreateSetRegValueWorkItem( |
326 HKEY_CURRENT_USER, | 297 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameStr, |
327 kTestKey, | |
328 WorkItem::kWow64Default, | |
329 kNameStr, | |
330 base::Bind(&VerifyPreviousValueAndReplace, &callback_invocation_count, | 298 base::Bind(&VerifyPreviousValueAndReplace, &callback_invocation_count, |
331 L"", kDataStr1))); | 299 L"", kDataStr1))); |
332 | 300 |
333 EXPECT_EQ(0, callback_invocation_count); | 301 EXPECT_EQ(0, callback_invocation_count); |
334 | 302 |
335 ASSERT_TRUE(work_item->Do()); | 303 ASSERT_TRUE(work_item->Do()); |
336 | 304 |
337 std::wstring read_out; | 305 std::wstring read_out; |
338 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); | 306 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_out)); |
339 EXPECT_EQ(read_out, kDataStr1); | 307 EXPECT_EQ(read_out, kDataStr1); |
340 | 308 |
341 EXPECT_EQ(1, callback_invocation_count); | 309 EXPECT_EQ(1, callback_invocation_count); |
342 | 310 |
343 work_item->Rollback(); | 311 work_item->Rollback(); |
344 | 312 |
345 EXPECT_FALSE(test_key_.HasValue(kNameStr)); | 313 EXPECT_FALSE(test_key_.HasValue(kNameStr)); |
346 | 314 |
347 EXPECT_EQ(1, callback_invocation_count); | 315 EXPECT_EQ(1, callback_invocation_count); |
348 } | 316 } |
349 | 317 |
350 // Modify an existing value which is not a string (REG_SZ) with the string | 318 // Modify an existing value which is not a string (REG_SZ) with the string |
351 // callback API. | 319 // callback API. |
352 TEST_F(SetRegValueWorkItemTest, ModifyExistingNonStringWithStringCallback) { | 320 TEST_F(SetRegValueWorkItemTest, ModifyExistingNonStringWithStringCallback) { |
353 // Write |kDword1| to the value we are going to modify. | 321 // Write |kDword1| to the value we are going to modify. |
354 ASSERT_EQ(ERROR_SUCCESS, test_key_.WriteValue(kNameStr, kDword1)); | 322 ASSERT_EQ(ERROR_SUCCESS, test_key_.WriteValue(kNameStr, kDword1)); |
355 | 323 |
356 int callback_invocation_count = 0; | 324 int callback_invocation_count = 0; |
357 | 325 |
358 scoped_ptr<SetRegValueWorkItem> work_item( | 326 std::unique_ptr<SetRegValueWorkItem> work_item( |
359 WorkItem::CreateSetRegValueWorkItem( | 327 WorkItem::CreateSetRegValueWorkItem( |
360 HKEY_CURRENT_USER, | 328 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameStr, |
361 kTestKey, | |
362 WorkItem::kWow64Default, | |
363 kNameStr, | |
364 base::Bind(&VerifyPreviousValueAndReplace, &callback_invocation_count, | 329 base::Bind(&VerifyPreviousValueAndReplace, &callback_invocation_count, |
365 L"", kDataStr1))); | 330 L"", kDataStr1))); |
366 | 331 |
367 EXPECT_EQ(0, callback_invocation_count); | 332 EXPECT_EQ(0, callback_invocation_count); |
368 | 333 |
369 ASSERT_TRUE(work_item->Do()); | 334 ASSERT_TRUE(work_item->Do()); |
370 | 335 |
371 std::wstring read_str_out; | 336 std::wstring read_str_out; |
372 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_str_out)); | 337 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValue(kNameStr, &read_str_out)); |
373 EXPECT_EQ(read_str_out, kDataStr1); | 338 EXPECT_EQ(read_str_out, kDataStr1); |
374 | 339 |
375 EXPECT_EQ(1, callback_invocation_count); | 340 EXPECT_EQ(1, callback_invocation_count); |
376 | 341 |
377 work_item->Rollback(); | 342 work_item->Rollback(); |
378 | 343 |
379 DWORD read_dword_out = 0; | 344 DWORD read_dword_out = 0; |
380 EXPECT_TRUE(test_key_.HasValue(kNameStr)); | 345 EXPECT_TRUE(test_key_.HasValue(kNameStr)); |
381 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValueDW(kNameStr, &read_dword_out)); | 346 EXPECT_EQ(ERROR_SUCCESS, test_key_.ReadValueDW(kNameStr, &read_dword_out)); |
382 EXPECT_EQ(read_dword_out, kDword1); | 347 EXPECT_EQ(read_dword_out, kDword1); |
383 | 348 |
384 EXPECT_EQ(1, callback_invocation_count); | 349 EXPECT_EQ(1, callback_invocation_count); |
385 } | 350 } |
OLD | NEW |