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

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

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
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 <windows.h> 5 #include <windows.h>
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 // Execute a WorkItem list successfully and then rollback. 53 // Execute a WorkItem list successfully and then rollback.
54 TEST_F(WorkItemListTest, ExecutionSuccess) { 54 TEST_F(WorkItemListTest, ExecutionSuccess) {
55 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); 55 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
56 scoped_ptr<WorkItem> work_item; 56 scoped_ptr<WorkItem> work_item;
57 57
58 base::FilePath top_dir_to_create(temp_dir_.path()); 58 base::FilePath top_dir_to_create(temp_dir_.path());
59 top_dir_to_create = top_dir_to_create.AppendASCII("a"); 59 top_dir_to_create = top_dir_to_create.AppendASCII("a");
60 base::FilePath dir_to_create(top_dir_to_create); 60 base::FilePath dir_to_create(top_dir_to_create);
61 dir_to_create = dir_to_create.AppendASCII("b"); 61 dir_to_create = dir_to_create.AppendASCII("b");
62 ASSERT_FALSE(file_util::PathExists(dir_to_create)); 62 ASSERT_FALSE(base::PathExists(dir_to_create));
63 63
64 work_item.reset(reinterpret_cast<WorkItem*>( 64 work_item.reset(reinterpret_cast<WorkItem*>(
65 WorkItem::CreateCreateDirWorkItem(dir_to_create))); 65 WorkItem::CreateCreateDirWorkItem(dir_to_create)));
66 work_item_list->AddWorkItem(work_item.release()); 66 work_item_list->AddWorkItem(work_item.release());
67 67
68 std::wstring key_to_create(kTestRoot); 68 std::wstring key_to_create(kTestRoot);
69 key_to_create.push_back(base::FilePath::kSeparators[0]); 69 key_to_create.push_back(base::FilePath::kSeparators[0]);
70 key_to_create.append(L"ExecutionSuccess"); 70 key_to_create.append(L"ExecutionSuccess");
71 71
72 work_item.reset(reinterpret_cast<WorkItem*>( 72 work_item.reset(reinterpret_cast<WorkItem*>(
(...skipping 10 matching lines...) Expand all
83 EXPECT_TRUE(work_item_list->Do()); 83 EXPECT_TRUE(work_item_list->Do());
84 84
85 // Verify all WorkItems have been executed. 85 // Verify all WorkItems have been executed.
86 RegKey key; 86 RegKey key;
87 EXPECT_EQ(ERROR_SUCCESS, 87 EXPECT_EQ(ERROR_SUCCESS,
88 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 88 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
89 std::wstring read_out; 89 std::wstring read_out;
90 EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(name.c_str(), &read_out)); 90 EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(name.c_str(), &read_out));
91 EXPECT_EQ(0, read_out.compare(kDataStr)); 91 EXPECT_EQ(0, read_out.compare(kDataStr));
92 key.Close(); 92 key.Close();
93 EXPECT_TRUE(file_util::PathExists(dir_to_create)); 93 EXPECT_TRUE(base::PathExists(dir_to_create));
94 94
95 work_item_list->Rollback(); 95 work_item_list->Rollback();
96 96
97 // Verify everything is rolled back. 97 // Verify everything is rolled back.
98 // The value must have been deleted first in roll back otherwise the key 98 // The value must have been deleted first in roll back otherwise the key
99 // can not be deleted. 99 // can not be deleted.
100 EXPECT_NE(ERROR_SUCCESS, 100 EXPECT_NE(ERROR_SUCCESS,
101 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 101 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
102 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); 102 EXPECT_FALSE(base::PathExists(top_dir_to_create));
103 } 103 }
104 104
105 // Execute a WorkItem list. Fail in the middle. Rollback what has been done. 105 // Execute a WorkItem list. Fail in the middle. Rollback what has been done.
106 TEST_F(WorkItemListTest, ExecutionFailAndRollback) { 106 TEST_F(WorkItemListTest, ExecutionFailAndRollback) {
107 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); 107 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
108 scoped_ptr<WorkItem> work_item; 108 scoped_ptr<WorkItem> work_item;
109 109
110 base::FilePath top_dir_to_create(temp_dir_.path()); 110 base::FilePath top_dir_to_create(temp_dir_.path());
111 top_dir_to_create = top_dir_to_create.AppendASCII("a"); 111 top_dir_to_create = top_dir_to_create.AppendASCII("a");
112 base::FilePath dir_to_create(top_dir_to_create); 112 base::FilePath dir_to_create(top_dir_to_create);
113 dir_to_create = dir_to_create.AppendASCII("b"); 113 dir_to_create = dir_to_create.AppendASCII("b");
114 ASSERT_FALSE(file_util::PathExists(dir_to_create)); 114 ASSERT_FALSE(base::PathExists(dir_to_create));
115 115
116 work_item.reset(reinterpret_cast<WorkItem*>( 116 work_item.reset(reinterpret_cast<WorkItem*>(
117 WorkItem::CreateCreateDirWorkItem(dir_to_create))); 117 WorkItem::CreateCreateDirWorkItem(dir_to_create)));
118 work_item_list->AddWorkItem(work_item.release()); 118 work_item_list->AddWorkItem(work_item.release());
119 119
120 std::wstring key_to_create(kTestRoot); 120 std::wstring key_to_create(kTestRoot);
121 key_to_create.push_back(base::FilePath::kSeparators[0]); 121 key_to_create.push_back(base::FilePath::kSeparators[0]);
122 key_to_create.append(L"ExecutionFail"); 122 key_to_create.append(L"ExecutionFail");
123 123
124 work_item.reset(reinterpret_cast<WorkItem*>( 124 work_item.reset(reinterpret_cast<WorkItem*>(
(...skipping 16 matching lines...) Expand all
141 not_created_key))); 141 not_created_key)));
142 work_item_list->AddWorkItem(work_item.release()); 142 work_item_list->AddWorkItem(work_item.release());
143 143
144 EXPECT_FALSE(work_item_list->Do()); 144 EXPECT_FALSE(work_item_list->Do());
145 145
146 // Verify the first 2 WorkItems have been executed. 146 // Verify the first 2 WorkItems have been executed.
147 RegKey key; 147 RegKey key;
148 EXPECT_EQ(ERROR_SUCCESS, 148 EXPECT_EQ(ERROR_SUCCESS,
149 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 149 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
150 key.Close(); 150 key.Close();
151 EXPECT_TRUE(file_util::PathExists(dir_to_create)); 151 EXPECT_TRUE(base::PathExists(dir_to_create));
152 // The last one should not be there. 152 // The last one should not be there.
153 EXPECT_NE(ERROR_SUCCESS, 153 EXPECT_NE(ERROR_SUCCESS,
154 key.Open(HKEY_CURRENT_USER, not_created_key.c_str(), KEY_READ)); 154 key.Open(HKEY_CURRENT_USER, not_created_key.c_str(), KEY_READ));
155 155
156 work_item_list->Rollback(); 156 work_item_list->Rollback();
157 157
158 // Verify everything is rolled back. 158 // Verify everything is rolled back.
159 EXPECT_NE(ERROR_SUCCESS, 159 EXPECT_NE(ERROR_SUCCESS,
160 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 160 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
161 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); 161 EXPECT_FALSE(base::PathExists(top_dir_to_create));
162 } 162 }
163 163
164 TEST_F(WorkItemListTest, ConditionalExecutionSuccess) { 164 TEST_F(WorkItemListTest, ConditionalExecutionSuccess) {
165 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); 165 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
166 scoped_ptr<WorkItem> work_item; 166 scoped_ptr<WorkItem> work_item;
167 167
168 base::FilePath top_dir_to_create(temp_dir_.path()); 168 base::FilePath top_dir_to_create(temp_dir_.path());
169 top_dir_to_create = top_dir_to_create.AppendASCII("a"); 169 top_dir_to_create = top_dir_to_create.AppendASCII("a");
170 base::FilePath dir_to_create(top_dir_to_create); 170 base::FilePath dir_to_create(top_dir_to_create);
171 dir_to_create = dir_to_create.AppendASCII("b"); 171 dir_to_create = dir_to_create.AppendASCII("b");
172 ASSERT_FALSE(file_util::PathExists(dir_to_create)); 172 ASSERT_FALSE(base::PathExists(dir_to_create));
173 173
174 work_item.reset(reinterpret_cast<WorkItem*>( 174 work_item.reset(reinterpret_cast<WorkItem*>(
175 WorkItem::CreateCreateDirWorkItem(dir_to_create))); 175 WorkItem::CreateCreateDirWorkItem(dir_to_create)));
176 work_item_list->AddWorkItem(work_item.release()); 176 work_item_list->AddWorkItem(work_item.release());
177 177
178 scoped_ptr<WorkItemList> conditional_work_item_list( 178 scoped_ptr<WorkItemList> conditional_work_item_list(
179 WorkItem::CreateConditionalWorkItemList( 179 WorkItem::CreateConditionalWorkItemList(
180 new ConditionRunIfFileExists(dir_to_create))); 180 new ConditionRunIfFileExists(dir_to_create)));
181 181
182 std::wstring key_to_create(kTestRoot); 182 std::wstring key_to_create(kTestRoot);
(...skipping 15 matching lines...) Expand all
198 EXPECT_TRUE(work_item_list->Do()); 198 EXPECT_TRUE(work_item_list->Do());
199 199
200 // Verify all WorkItems have been executed. 200 // Verify all WorkItems have been executed.
201 RegKey key; 201 RegKey key;
202 EXPECT_EQ(ERROR_SUCCESS, 202 EXPECT_EQ(ERROR_SUCCESS,
203 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 203 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
204 std::wstring read_out; 204 std::wstring read_out;
205 EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(name.c_str(), &read_out)); 205 EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(name.c_str(), &read_out));
206 EXPECT_EQ(0, read_out.compare(kDataStr)); 206 EXPECT_EQ(0, read_out.compare(kDataStr));
207 key.Close(); 207 key.Close();
208 EXPECT_TRUE(file_util::PathExists(dir_to_create)); 208 EXPECT_TRUE(base::PathExists(dir_to_create));
209 209
210 work_item_list->Rollback(); 210 work_item_list->Rollback();
211 211
212 // Verify everything is rolled back. 212 // Verify everything is rolled back.
213 // The value must have been deleted first in roll back otherwise the key 213 // The value must have been deleted first in roll back otherwise the key
214 // can not be deleted. 214 // can not be deleted.
215 EXPECT_NE(ERROR_SUCCESS, 215 EXPECT_NE(ERROR_SUCCESS,
216 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 216 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
217 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); 217 EXPECT_FALSE(base::PathExists(top_dir_to_create));
218 } 218 }
219 219
220 TEST_F(WorkItemListTest, ConditionalExecutionConditionFailure) { 220 TEST_F(WorkItemListTest, ConditionalExecutionConditionFailure) {
221 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); 221 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
222 scoped_ptr<WorkItem> work_item; 222 scoped_ptr<WorkItem> work_item;
223 223
224 base::FilePath top_dir_to_create(temp_dir_.path()); 224 base::FilePath top_dir_to_create(temp_dir_.path());
225 top_dir_to_create = top_dir_to_create.AppendASCII("a"); 225 top_dir_to_create = top_dir_to_create.AppendASCII("a");
226 base::FilePath dir_to_create(top_dir_to_create); 226 base::FilePath dir_to_create(top_dir_to_create);
227 dir_to_create = dir_to_create.AppendASCII("b"); 227 dir_to_create = dir_to_create.AppendASCII("b");
228 ASSERT_FALSE(file_util::PathExists(dir_to_create)); 228 ASSERT_FALSE(base::PathExists(dir_to_create));
229 229
230 work_item.reset(reinterpret_cast<WorkItem*>( 230 work_item.reset(reinterpret_cast<WorkItem*>(
231 WorkItem::CreateCreateDirWorkItem(dir_to_create))); 231 WorkItem::CreateCreateDirWorkItem(dir_to_create)));
232 work_item_list->AddWorkItem(work_item.release()); 232 work_item_list->AddWorkItem(work_item.release());
233 233
234 scoped_ptr<WorkItemList> conditional_work_item_list( 234 scoped_ptr<WorkItemList> conditional_work_item_list(
235 WorkItem::CreateConditionalWorkItemList( 235 WorkItem::CreateConditionalWorkItemList(
236 new ConditionRunIfFileExists(dir_to_create.AppendASCII("c")))); 236 new ConditionRunIfFileExists(dir_to_create.AppendASCII("c"))));
237 237
238 std::wstring key_to_create(kTestRoot); 238 std::wstring key_to_create(kTestRoot);
(...skipping 17 matching lines...) Expand all
256 // Verify that the WorkItems added as part of the conditional list have NOT 256 // Verify that the WorkItems added as part of the conditional list have NOT
257 // been executed. 257 // been executed.
258 RegKey key; 258 RegKey key;
259 EXPECT_NE(ERROR_SUCCESS, 259 EXPECT_NE(ERROR_SUCCESS,
260 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 260 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
261 std::wstring read_out; 261 std::wstring read_out;
262 EXPECT_NE(ERROR_SUCCESS, key.ReadValue(name.c_str(), &read_out)); 262 EXPECT_NE(ERROR_SUCCESS, key.ReadValue(name.c_str(), &read_out));
263 key.Close(); 263 key.Close();
264 264
265 // Verify that the other work item was executed. 265 // Verify that the other work item was executed.
266 EXPECT_TRUE(file_util::PathExists(dir_to_create)); 266 EXPECT_TRUE(base::PathExists(dir_to_create));
267 267
268 work_item_list->Rollback(); 268 work_item_list->Rollback();
269 269
270 // Verify everything is rolled back. 270 // Verify everything is rolled back.
271 // The value must have been deleted first in roll back otherwise the key 271 // The value must have been deleted first in roll back otherwise the key
272 // can not be deleted. 272 // can not be deleted.
273 EXPECT_NE(ERROR_SUCCESS, 273 EXPECT_NE(ERROR_SUCCESS,
274 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 274 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
275 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); 275 EXPECT_FALSE(base::PathExists(top_dir_to_create));
276 } 276 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util_unittest.cc ('k') | chrome/renderer/chrome_render_process_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698