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/work_item_list.h" |
| 6 |
5 #include <windows.h> | 7 #include <windows.h> |
6 | 8 |
| 9 #include <memory> |
| 10 |
7 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
8 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
12 #include "base/test/test_reg_util_win.h" | 15 #include "base/test/test_reg_util_win.h" |
13 #include "base/win/registry.h" | 16 #include "base/win/registry.h" |
14 #include "chrome/installer/util/conditional_work_item_list.h" | 17 #include "chrome/installer/util/conditional_work_item_list.h" |
15 #include "chrome/installer/util/work_item.h" | 18 #include "chrome/installer/util/work_item.h" |
16 #include "chrome/installer/util/work_item_list.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
18 | 20 |
19 using base::win::RegKey; | 21 using base::win::RegKey; |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 const wchar_t kTestRoot[] = L"ListList"; | 25 const wchar_t kTestRoot[] = L"ListList"; |
24 const wchar_t kDataStr[] = L"data_111"; | 26 const wchar_t kDataStr[] = L"data_111"; |
25 const wchar_t kName[] = L"name"; | 27 const wchar_t kName[] = L"name"; |
26 | 28 |
27 class WorkItemListTest : public testing::Test { | 29 class WorkItemListTest : public testing::Test { |
28 protected: | 30 protected: |
29 void SetUp() override { | 31 void SetUp() override { |
30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 32 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
31 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); | 33 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); |
32 } | 34 } |
33 | 35 |
34 void TearDown() override { logging::CloseLogFile(); } | 36 void TearDown() override { logging::CloseLogFile(); } |
35 | 37 |
36 base::ScopedTempDir temp_dir_; | 38 base::ScopedTempDir temp_dir_; |
37 registry_util::RegistryOverrideManager registry_override_manager_; | 39 registry_util::RegistryOverrideManager registry_override_manager_; |
38 }; | 40 }; |
39 | 41 |
40 } // namespace | 42 } // namespace |
41 | 43 |
42 // Execute a WorkItem list successfully and then rollback. | 44 // Execute a WorkItem list successfully and then rollback. |
43 TEST_F(WorkItemListTest, ExecutionSuccess) { | 45 TEST_F(WorkItemListTest, ExecutionSuccess) { |
44 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); | 46 std::unique_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); |
45 scoped_ptr<WorkItem> work_item; | 47 std::unique_ptr<WorkItem> work_item; |
46 | 48 |
47 base::FilePath top_dir_to_create(temp_dir_.path()); | 49 base::FilePath top_dir_to_create(temp_dir_.path()); |
48 top_dir_to_create = top_dir_to_create.AppendASCII("a"); | 50 top_dir_to_create = top_dir_to_create.AppendASCII("a"); |
49 base::FilePath dir_to_create(top_dir_to_create); | 51 base::FilePath dir_to_create(top_dir_to_create); |
50 dir_to_create = dir_to_create.AppendASCII("b"); | 52 dir_to_create = dir_to_create.AppendASCII("b"); |
51 ASSERT_FALSE(base::PathExists(dir_to_create)); | 53 ASSERT_FALSE(base::PathExists(dir_to_create)); |
52 | 54 |
53 work_item.reset(reinterpret_cast<WorkItem*>( | 55 work_item.reset(reinterpret_cast<WorkItem*>( |
54 WorkItem::CreateCreateDirWorkItem(dir_to_create))); | 56 WorkItem::CreateCreateDirWorkItem(dir_to_create))); |
55 work_item_list->AddWorkItem(work_item.release()); | 57 work_item_list->AddWorkItem(work_item.release()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // Verify everything is rolled back. | 93 // Verify everything is rolled back. |
92 // The value must have been deleted first in roll back otherwise the key | 94 // The value must have been deleted first in roll back otherwise the key |
93 // can not be deleted. | 95 // can not be deleted. |
94 EXPECT_NE(ERROR_SUCCESS, | 96 EXPECT_NE(ERROR_SUCCESS, |
95 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); | 97 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); |
96 EXPECT_FALSE(base::PathExists(top_dir_to_create)); | 98 EXPECT_FALSE(base::PathExists(top_dir_to_create)); |
97 } | 99 } |
98 | 100 |
99 // Execute a WorkItem list. Fail in the middle. Rollback what has been done. | 101 // Execute a WorkItem list. Fail in the middle. Rollback what has been done. |
100 TEST_F(WorkItemListTest, ExecutionFailAndRollback) { | 102 TEST_F(WorkItemListTest, ExecutionFailAndRollback) { |
101 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); | 103 std::unique_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); |
102 scoped_ptr<WorkItem> work_item; | 104 std::unique_ptr<WorkItem> work_item; |
103 | 105 |
104 base::FilePath top_dir_to_create(temp_dir_.path()); | 106 base::FilePath top_dir_to_create(temp_dir_.path()); |
105 top_dir_to_create = top_dir_to_create.AppendASCII("a"); | 107 top_dir_to_create = top_dir_to_create.AppendASCII("a"); |
106 base::FilePath dir_to_create(top_dir_to_create); | 108 base::FilePath dir_to_create(top_dir_to_create); |
107 dir_to_create = dir_to_create.AppendASCII("b"); | 109 dir_to_create = dir_to_create.AppendASCII("b"); |
108 ASSERT_FALSE(base::PathExists(dir_to_create)); | 110 ASSERT_FALSE(base::PathExists(dir_to_create)); |
109 | 111 |
110 work_item.reset(reinterpret_cast<WorkItem*>( | 112 work_item.reset(reinterpret_cast<WorkItem*>( |
111 WorkItem::CreateCreateDirWorkItem(dir_to_create))); | 113 WorkItem::CreateCreateDirWorkItem(dir_to_create))); |
112 work_item_list->AddWorkItem(work_item.release()); | 114 work_item_list->AddWorkItem(work_item.release()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 156 |
155 work_item_list->Rollback(); | 157 work_item_list->Rollback(); |
156 | 158 |
157 // Verify everything is rolled back. | 159 // Verify everything is rolled back. |
158 EXPECT_NE(ERROR_SUCCESS, | 160 EXPECT_NE(ERROR_SUCCESS, |
159 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); | 161 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); |
160 EXPECT_FALSE(base::PathExists(top_dir_to_create)); | 162 EXPECT_FALSE(base::PathExists(top_dir_to_create)); |
161 } | 163 } |
162 | 164 |
163 TEST_F(WorkItemListTest, ConditionalExecutionSuccess) { | 165 TEST_F(WorkItemListTest, ConditionalExecutionSuccess) { |
164 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); | 166 std::unique_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); |
165 scoped_ptr<WorkItem> work_item; | 167 std::unique_ptr<WorkItem> work_item; |
166 | 168 |
167 base::FilePath top_dir_to_create(temp_dir_.path()); | 169 base::FilePath top_dir_to_create(temp_dir_.path()); |
168 top_dir_to_create = top_dir_to_create.AppendASCII("a"); | 170 top_dir_to_create = top_dir_to_create.AppendASCII("a"); |
169 base::FilePath dir_to_create(top_dir_to_create); | 171 base::FilePath dir_to_create(top_dir_to_create); |
170 dir_to_create = dir_to_create.AppendASCII("b"); | 172 dir_to_create = dir_to_create.AppendASCII("b"); |
171 ASSERT_FALSE(base::PathExists(dir_to_create)); | 173 ASSERT_FALSE(base::PathExists(dir_to_create)); |
172 | 174 |
173 work_item.reset(reinterpret_cast<WorkItem*>( | 175 work_item.reset(reinterpret_cast<WorkItem*>( |
174 WorkItem::CreateCreateDirWorkItem(dir_to_create))); | 176 WorkItem::CreateCreateDirWorkItem(dir_to_create))); |
175 work_item_list->AddWorkItem(work_item.release()); | 177 work_item_list->AddWorkItem(work_item.release()); |
176 | 178 |
177 scoped_ptr<WorkItemList> conditional_work_item_list( | 179 std::unique_ptr<WorkItemList> conditional_work_item_list( |
178 WorkItem::CreateConditionalWorkItemList( | 180 WorkItem::CreateConditionalWorkItemList( |
179 new ConditionRunIfFileExists(dir_to_create))); | 181 new ConditionRunIfFileExists(dir_to_create))); |
180 | 182 |
181 std::wstring key_to_create(kTestRoot); | 183 std::wstring key_to_create(kTestRoot); |
182 key_to_create.push_back(base::FilePath::kSeparators[0]); | 184 key_to_create.push_back(base::FilePath::kSeparators[0]); |
183 key_to_create.append(L"ExecutionSuccess"); | 185 key_to_create.append(L"ExecutionSuccess"); |
184 work_item.reset( | 186 work_item.reset( |
185 reinterpret_cast<WorkItem*>(WorkItem::CreateCreateRegKeyWorkItem( | 187 reinterpret_cast<WorkItem*>(WorkItem::CreateCreateRegKeyWorkItem( |
186 HKEY_CURRENT_USER, key_to_create, WorkItem::kWow64Default))); | 188 HKEY_CURRENT_USER, key_to_create, WorkItem::kWow64Default))); |
187 conditional_work_item_list->AddWorkItem(work_item.release()); | 189 conditional_work_item_list->AddWorkItem(work_item.release()); |
(...skipping 27 matching lines...) Expand all Loading... |
215 | 217 |
216 // Verify everything is rolled back. | 218 // Verify everything is rolled back. |
217 // The value must have been deleted first in roll back otherwise the key | 219 // The value must have been deleted first in roll back otherwise the key |
218 // can not be deleted. | 220 // can not be deleted. |
219 EXPECT_NE(ERROR_SUCCESS, | 221 EXPECT_NE(ERROR_SUCCESS, |
220 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); | 222 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); |
221 EXPECT_FALSE(base::PathExists(top_dir_to_create)); | 223 EXPECT_FALSE(base::PathExists(top_dir_to_create)); |
222 } | 224 } |
223 | 225 |
224 TEST_F(WorkItemListTest, ConditionalExecutionConditionFailure) { | 226 TEST_F(WorkItemListTest, ConditionalExecutionConditionFailure) { |
225 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); | 227 std::unique_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); |
226 scoped_ptr<WorkItem> work_item; | 228 std::unique_ptr<WorkItem> work_item; |
227 | 229 |
228 base::FilePath top_dir_to_create(temp_dir_.path()); | 230 base::FilePath top_dir_to_create(temp_dir_.path()); |
229 top_dir_to_create = top_dir_to_create.AppendASCII("a"); | 231 top_dir_to_create = top_dir_to_create.AppendASCII("a"); |
230 base::FilePath dir_to_create(top_dir_to_create); | 232 base::FilePath dir_to_create(top_dir_to_create); |
231 dir_to_create = dir_to_create.AppendASCII("b"); | 233 dir_to_create = dir_to_create.AppendASCII("b"); |
232 ASSERT_FALSE(base::PathExists(dir_to_create)); | 234 ASSERT_FALSE(base::PathExists(dir_to_create)); |
233 | 235 |
234 work_item.reset(reinterpret_cast<WorkItem*>( | 236 work_item.reset(reinterpret_cast<WorkItem*>( |
235 WorkItem::CreateCreateDirWorkItem(dir_to_create))); | 237 WorkItem::CreateCreateDirWorkItem(dir_to_create))); |
236 work_item_list->AddWorkItem(work_item.release()); | 238 work_item_list->AddWorkItem(work_item.release()); |
237 | 239 |
238 scoped_ptr<WorkItemList> conditional_work_item_list( | 240 std::unique_ptr<WorkItemList> conditional_work_item_list( |
239 WorkItem::CreateConditionalWorkItemList( | 241 WorkItem::CreateConditionalWorkItemList( |
240 new ConditionRunIfFileExists(dir_to_create.AppendASCII("c")))); | 242 new ConditionRunIfFileExists(dir_to_create.AppendASCII("c")))); |
241 | 243 |
242 std::wstring key_to_create(kTestRoot); | 244 std::wstring key_to_create(kTestRoot); |
243 key_to_create.push_back(base::FilePath::kSeparators[0]); | 245 key_to_create.push_back(base::FilePath::kSeparators[0]); |
244 key_to_create.append(L"ExecutionSuccess"); | 246 key_to_create.append(L"ExecutionSuccess"); |
245 work_item.reset( | 247 work_item.reset( |
246 reinterpret_cast<WorkItem*>(WorkItem::CreateCreateRegKeyWorkItem( | 248 reinterpret_cast<WorkItem*>(WorkItem::CreateCreateRegKeyWorkItem( |
247 HKEY_CURRENT_USER, key_to_create, WorkItem::kWow64Default))); | 249 HKEY_CURRENT_USER, key_to_create, WorkItem::kWow64Default))); |
248 conditional_work_item_list->AddWorkItem(work_item.release()); | 250 conditional_work_item_list->AddWorkItem(work_item.release()); |
(...skipping 27 matching lines...) Expand all Loading... |
276 | 278 |
277 work_item_list->Rollback(); | 279 work_item_list->Rollback(); |
278 | 280 |
279 // Verify everything is rolled back. | 281 // Verify everything is rolled back. |
280 // The value must have been deleted first in roll back otherwise the key | 282 // The value must have been deleted first in roll back otherwise the key |
281 // can not be deleted. | 283 // can not be deleted. |
282 EXPECT_NE(ERROR_SUCCESS, | 284 EXPECT_NE(ERROR_SUCCESS, |
283 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); | 285 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); |
284 EXPECT_FALSE(base::PathExists(top_dir_to_create)); | 286 EXPECT_FALSE(base::PathExists(top_dir_to_create)); |
285 } | 287 } |
OLD | NEW |