OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/registry.h" | 10 #include "base/registry.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 FilePath test_dir_; | 49 FilePath test_dir_; |
50 }; | 50 }; |
51 }; | 51 }; |
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 std::wstring top_dir_to_create(test_dir_.ToWStringHack()); | 58 FilePath top_dir_to_create(test_dir_); |
59 file_util::AppendToPath(&top_dir_to_create, L"a"); | 59 top_dir_to_create = top_dir_to_create.AppendASCII("a"); |
60 std::wstring dir_to_create(top_dir_to_create); | 60 FilePath dir_to_create(top_dir_to_create); |
61 file_util::AppendToPath(&dir_to_create, L"b"); | 61 dir_to_create = dir_to_create.AppendASCII("b"); |
62 ASSERT_FALSE(file_util::PathExists(dir_to_create)); | 62 ASSERT_FALSE(file_util::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.ToWStringHack()))); |
66 EXPECT_TRUE(work_item_list->AddWorkItem(work_item.release())); | 66 EXPECT_TRUE(work_item_list->AddWorkItem(work_item.release())); |
67 | 67 |
68 std::wstring key_to_create(test_root); | 68 std::wstring key_to_create(test_root); |
69 file_util::AppendToPath(&key_to_create, L"ExecutionSuccess"); | 69 file_util::AppendToPath(&key_to_create, L"ExecutionSuccess"); |
70 | 70 |
71 work_item.reset(reinterpret_cast<WorkItem*>( | 71 work_item.reset(reinterpret_cast<WorkItem*>( |
72 WorkItem::CreateCreateRegKeyWorkItem(HKEY_CURRENT_USER, key_to_create))); | 72 WorkItem::CreateCreateRegKeyWorkItem(HKEY_CURRENT_USER, key_to_create))); |
73 EXPECT_TRUE(work_item_list->AddWorkItem(work_item.release())); | 73 EXPECT_TRUE(work_item_list->AddWorkItem(work_item.release())); |
74 | 74 |
75 std::wstring name(L"name"); | 75 std::wstring name(L"name"); |
(...skipping 21 matching lines...) Expand all Loading... |
97 // can not be deleted. | 97 // can not be deleted. |
98 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); | 98 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); |
99 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); | 99 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); |
100 } | 100 } |
101 | 101 |
102 // Execute a WorkItem list. Fail in the middle. Rollback what has been done. | 102 // Execute a WorkItem list. Fail in the middle. Rollback what has been done. |
103 TEST_F(WorkItemListTest, ExecutionFailAndRollback) { | 103 TEST_F(WorkItemListTest, ExecutionFailAndRollback) { |
104 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); | 104 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); |
105 scoped_ptr<WorkItem> work_item; | 105 scoped_ptr<WorkItem> work_item; |
106 | 106 |
107 std::wstring top_dir_to_create(test_dir_.ToWStringHack()); | 107 FilePath top_dir_to_create(test_dir_); |
108 file_util::AppendToPath(&top_dir_to_create, L"a"); | 108 top_dir_to_create = top_dir_to_create.AppendASCII("a"); |
109 std::wstring dir_to_create(top_dir_to_create); | 109 FilePath dir_to_create(top_dir_to_create); |
110 file_util::AppendToPath(&dir_to_create, L"b"); | 110 dir_to_create = dir_to_create.AppendASCII("b"); |
111 ASSERT_FALSE(file_util::PathExists(dir_to_create)); | 111 ASSERT_FALSE(file_util::PathExists(dir_to_create)); |
112 | 112 |
113 work_item.reset(reinterpret_cast<WorkItem*>( | 113 work_item.reset(reinterpret_cast<WorkItem*>( |
114 WorkItem::CreateCreateDirWorkItem(dir_to_create))); | 114 WorkItem::CreateCreateDirWorkItem(dir_to_create.ToWStringHack()))); |
115 EXPECT_TRUE(work_item_list->AddWorkItem(work_item.release())); | 115 EXPECT_TRUE(work_item_list->AddWorkItem(work_item.release())); |
116 | 116 |
117 std::wstring key_to_create(test_root); | 117 std::wstring key_to_create(test_root); |
118 file_util::AppendToPath(&key_to_create, L"ExecutionFail"); | 118 file_util::AppendToPath(&key_to_create, L"ExecutionFail"); |
119 | 119 |
120 work_item.reset(reinterpret_cast<WorkItem*>( | 120 work_item.reset(reinterpret_cast<WorkItem*>( |
121 WorkItem::CreateCreateRegKeyWorkItem(HKEY_CURRENT_USER, key_to_create))); | 121 WorkItem::CreateCreateRegKeyWorkItem(HKEY_CURRENT_USER, key_to_create))); |
122 EXPECT_TRUE(work_item_list->AddWorkItem(work_item.release())); | 122 EXPECT_TRUE(work_item_list->AddWorkItem(work_item.release())); |
123 | 123 |
124 std::wstring not_created_key(test_root); | 124 std::wstring not_created_key(test_root); |
(...skipping 21 matching lines...) Expand all Loading... |
146 // The last one should not be there. | 146 // The last one should not be there. |
147 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, not_created_key.c_str(), | 147 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, not_created_key.c_str(), |
148 KEY_READ)); | 148 KEY_READ)); |
149 | 149 |
150 work_item_list->Rollback(); | 150 work_item_list->Rollback(); |
151 | 151 |
152 // Verify everything is rolled back. | 152 // Verify everything is rolled back. |
153 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); | 153 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); |
154 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); | 154 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); |
155 } | 155 } |
OLD | NEW |