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

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

Issue 1878313003: Convert //chrome/installer from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert decompress.cc in mini_installer. Created 4 years, 8 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 "chrome/installer/util/create_reg_key_work_item.h"
6
5 #include <windows.h> 7 #include <windows.h>
6 8
9 #include <memory>
10
7 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
10 #include "base/win/registry.h" 13 #include "base/win/registry.h"
11 #include "chrome/installer/util/create_reg_key_work_item.h"
12 #include "chrome/installer/util/work_item.h" 14 #include "chrome/installer/util/work_item.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 using base::win::RegKey; 17 using base::win::RegKey;
16 18
17 namespace { 19 namespace {
18 20
19 wchar_t test_root[] = L"TmpTmp"; 21 wchar_t test_root[] = L"TmpTmp";
20 22
21 class CreateRegKeyWorkItemTest : public testing::Test { 23 class CreateRegKeyWorkItemTest : public testing::Test {
(...skipping 24 matching lines...) Expand all
46 ASSERT_EQ(ERROR_SUCCESS, 48 ASSERT_EQ(ERROR_SUCCESS,
47 key.Create(HKEY_CURRENT_USER, parent_key.value().c_str(), KEY_READ)); 49 key.Create(HKEY_CURRENT_USER, parent_key.value().c_str(), KEY_READ));
48 50
49 base::FilePath top_key_to_create(parent_key); 51 base::FilePath top_key_to_create(parent_key);
50 top_key_to_create = top_key_to_create.AppendASCII("b"); 52 top_key_to_create = top_key_to_create.AppendASCII("b");
51 53
52 base::FilePath key_to_create(top_key_to_create); 54 base::FilePath key_to_create(top_key_to_create);
53 key_to_create = key_to_create.AppendASCII("c"); 55 key_to_create = key_to_create.AppendASCII("c");
54 key_to_create = key_to_create.AppendASCII("d"); 56 key_to_create = key_to_create.AppendASCII("d");
55 57
56 scoped_ptr<CreateRegKeyWorkItem> work_item( 58 std::unique_ptr<CreateRegKeyWorkItem> work_item(
57 WorkItem::CreateCreateRegKeyWorkItem( 59 WorkItem::CreateCreateRegKeyWorkItem(
58 HKEY_CURRENT_USER, key_to_create.value(), WorkItem::kWow64Default)); 60 HKEY_CURRENT_USER, key_to_create.value(), WorkItem::kWow64Default));
59 61
60 EXPECT_TRUE(work_item->Do()); 62 EXPECT_TRUE(work_item->Do());
61 63
62 EXPECT_EQ(ERROR_SUCCESS, 64 EXPECT_EQ(ERROR_SUCCESS,
63 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ)); 65 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ));
64 66
65 work_item->Rollback(); 67 work_item->Rollback();
66 68
67 // Rollback should delete all the keys up to top_key_to_create. 69 // Rollback should delete all the keys up to top_key_to_create.
68 EXPECT_NE(ERROR_SUCCESS, 70 EXPECT_NE(ERROR_SUCCESS,
69 key.Open(HKEY_CURRENT_USER, top_key_to_create.value().c_str(), KEY_READ)); 71 key.Open(HKEY_CURRENT_USER, top_key_to_create.value().c_str(), KEY_READ));
70 EXPECT_EQ(ERROR_SUCCESS, 72 EXPECT_EQ(ERROR_SUCCESS,
71 key.Open(HKEY_CURRENT_USER, parent_key.value().c_str(), KEY_READ)); 73 key.Open(HKEY_CURRENT_USER, parent_key.value().c_str(), KEY_READ));
72 } 74 }
73 75
74 TEST_F(CreateRegKeyWorkItemTest, CreateExistingKey) { 76 TEST_F(CreateRegKeyWorkItemTest, CreateExistingKey) {
75 RegKey key; 77 RegKey key;
76 78
77 base::FilePath key_to_create(test_root); 79 base::FilePath key_to_create(test_root);
78 key_to_create = key_to_create.AppendASCII("aa"); 80 key_to_create = key_to_create.AppendASCII("aa");
79 ASSERT_EQ(ERROR_SUCCESS, 81 ASSERT_EQ(ERROR_SUCCESS,
80 key.Create(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ)); 82 key.Create(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ));
81 83
82 scoped_ptr<CreateRegKeyWorkItem> work_item( 84 std::unique_ptr<CreateRegKeyWorkItem> work_item(
83 WorkItem::CreateCreateRegKeyWorkItem( 85 WorkItem::CreateCreateRegKeyWorkItem(
84 HKEY_CURRENT_USER, key_to_create.value(), WorkItem::kWow64Default)); 86 HKEY_CURRENT_USER, key_to_create.value(), WorkItem::kWow64Default));
85 87
86 EXPECT_TRUE(work_item->Do()); 88 EXPECT_TRUE(work_item->Do());
87 89
88 EXPECT_EQ(ERROR_SUCCESS, 90 EXPECT_EQ(ERROR_SUCCESS,
89 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ)); 91 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ));
90 92
91 work_item->Rollback(); 93 work_item->Rollback();
92 94
93 // Rollback should not remove the key since it exists before 95 // Rollback should not remove the key since it exists before
94 // the CreateRegKeyWorkItem is called. 96 // the CreateRegKeyWorkItem is called.
95 EXPECT_EQ(ERROR_SUCCESS, 97 EXPECT_EQ(ERROR_SUCCESS,
96 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ)); 98 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ));
97 } 99 }
98 100
99 TEST_F(CreateRegKeyWorkItemTest, CreateSharedKey) { 101 TEST_F(CreateRegKeyWorkItemTest, CreateSharedKey) {
100 RegKey key; 102 RegKey key;
101 base::FilePath key_to_create_1(test_root); 103 base::FilePath key_to_create_1(test_root);
102 key_to_create_1 = key_to_create_1.AppendASCII("aaa"); 104 key_to_create_1 = key_to_create_1.AppendASCII("aaa");
103 105
104 base::FilePath key_to_create_2(key_to_create_1); 106 base::FilePath key_to_create_2(key_to_create_1);
105 key_to_create_2 = key_to_create_2.AppendASCII("bbb"); 107 key_to_create_2 = key_to_create_2.AppendASCII("bbb");
106 108
107 base::FilePath key_to_create_3(key_to_create_2); 109 base::FilePath key_to_create_3(key_to_create_2);
108 key_to_create_3 = key_to_create_3.AppendASCII("ccc"); 110 key_to_create_3 = key_to_create_3.AppendASCII("ccc");
109 111
110 scoped_ptr<CreateRegKeyWorkItem> work_item( 112 std::unique_ptr<CreateRegKeyWorkItem> work_item(
111 WorkItem::CreateCreateRegKeyWorkItem( 113 WorkItem::CreateCreateRegKeyWorkItem(
112 HKEY_CURRENT_USER, key_to_create_3.value(), WorkItem::kWow64Default)); 114 HKEY_CURRENT_USER, key_to_create_3.value(), WorkItem::kWow64Default));
113 115
114 EXPECT_TRUE(work_item->Do()); 116 EXPECT_TRUE(work_item->Do());
115 117
116 EXPECT_EQ(ERROR_SUCCESS, 118 EXPECT_EQ(ERROR_SUCCESS,
117 key.Open(HKEY_CURRENT_USER, key_to_create_3.value().c_str(), KEY_READ)); 119 key.Open(HKEY_CURRENT_USER, key_to_create_3.value().c_str(), KEY_READ));
118 120
119 // Create another key under key_to_create_2 121 // Create another key under key_to_create_2
120 base::FilePath key_to_create_4(key_to_create_2); 122 base::FilePath key_to_create_4(key_to_create_2);
(...skipping 18 matching lines...) Expand all
139 RegKey key; 141 RegKey key;
140 base::FilePath key_to_create_1(test_root); 142 base::FilePath key_to_create_1(test_root);
141 key_to_create_1 = key_to_create_1.AppendASCII("aaaa"); 143 key_to_create_1 = key_to_create_1.AppendASCII("aaaa");
142 144
143 base::FilePath key_to_create_2(key_to_create_1); 145 base::FilePath key_to_create_2(key_to_create_1);
144 key_to_create_2 = key_to_create_2.AppendASCII("bbbb"); 146 key_to_create_2 = key_to_create_2.AppendASCII("bbbb");
145 147
146 base::FilePath key_to_create_3(key_to_create_2); 148 base::FilePath key_to_create_3(key_to_create_2);
147 key_to_create_3 = key_to_create_3.AppendASCII("cccc"); 149 key_to_create_3 = key_to_create_3.AppendASCII("cccc");
148 150
149 scoped_ptr<CreateRegKeyWorkItem> work_item( 151 std::unique_ptr<CreateRegKeyWorkItem> work_item(
150 WorkItem::CreateCreateRegKeyWorkItem( 152 WorkItem::CreateCreateRegKeyWorkItem(
151 HKEY_CURRENT_USER, key_to_create_3.value(), WorkItem::kWow64Default)); 153 HKEY_CURRENT_USER, key_to_create_3.value(), WorkItem::kWow64Default));
152 154
153 EXPECT_TRUE(work_item->Do()); 155 EXPECT_TRUE(work_item->Do());
154 156
155 EXPECT_EQ(ERROR_SUCCESS, 157 EXPECT_EQ(ERROR_SUCCESS,
156 key.Open(HKEY_CURRENT_USER, key_to_create_3.value().c_str(), KEY_READ)); 158 key.Open(HKEY_CURRENT_USER, key_to_create_3.value().c_str(), KEY_READ));
157 key.Close(); 159 key.Close();
158 160
159 // now delete key_to_create_3 161 // now delete key_to_create_3
160 ASSERT_EQ(ERROR_SUCCESS, 162 ASSERT_EQ(ERROR_SUCCESS,
161 RegDeleteKey(HKEY_CURRENT_USER, key_to_create_3.value().c_str())); 163 RegDeleteKey(HKEY_CURRENT_USER, key_to_create_3.value().c_str()));
162 ASSERT_NE(ERROR_SUCCESS, 164 ASSERT_NE(ERROR_SUCCESS,
163 key.Open(HKEY_CURRENT_USER, key_to_create_3.value().c_str(), KEY_READ)); 165 key.Open(HKEY_CURRENT_USER, key_to_create_3.value().c_str(), KEY_READ));
164 166
165 work_item->Rollback(); 167 work_item->Rollback();
166 168
167 // key_to_create_3 has already been deleted, Rollback should delete 169 // key_to_create_3 has already been deleted, Rollback should delete
168 // the rest. 170 // the rest.
169 ASSERT_NE(ERROR_SUCCESS, 171 ASSERT_NE(ERROR_SUCCESS,
170 key.Open(HKEY_CURRENT_USER, key_to_create_1.value().c_str(), KEY_READ)); 172 key.Open(HKEY_CURRENT_USER, key_to_create_1.value().c_str(), KEY_READ));
171 } 173 }
172 174
173 TEST_F(CreateRegKeyWorkItemTest, RollbackWithSetValue) { 175 TEST_F(CreateRegKeyWorkItemTest, RollbackWithSetValue) {
174 RegKey key; 176 RegKey key;
175 177
176 base::FilePath key_to_create(test_root); 178 base::FilePath key_to_create(test_root);
177 key_to_create = key_to_create.AppendASCII("aaaaa"); 179 key_to_create = key_to_create.AppendASCII("aaaaa");
178 180
179 scoped_ptr<CreateRegKeyWorkItem> work_item( 181 std::unique_ptr<CreateRegKeyWorkItem> work_item(
180 WorkItem::CreateCreateRegKeyWorkItem( 182 WorkItem::CreateCreateRegKeyWorkItem(
181 HKEY_CURRENT_USER, key_to_create.value(), WorkItem::kWow64Default)); 183 HKEY_CURRENT_USER, key_to_create.value(), WorkItem::kWow64Default));
182 184
183 EXPECT_TRUE(work_item->Do()); 185 EXPECT_TRUE(work_item->Do());
184 186
185 // Write a value under the key we just created. 187 // Write a value under the key we just created.
186 EXPECT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, 188 EXPECT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER,
187 key_to_create.value().c_str(), KEY_READ | KEY_SET_VALUE)); 189 key_to_create.value().c_str(), KEY_READ | KEY_SET_VALUE));
188 EXPECT_EQ(ERROR_SUCCESS, key.WriteValue(L"name", L"value")); 190 EXPECT_EQ(ERROR_SUCCESS, key.WriteValue(L"name", L"value"));
189 key.Close(); 191 key.Close();
190 192
191 work_item->Rollback(); 193 work_item->Rollback();
192 194
193 // Rollback should not remove the key. 195 // Rollback should not remove the key.
194 EXPECT_EQ(ERROR_SUCCESS, 196 EXPECT_EQ(ERROR_SUCCESS,
195 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ)); 197 key.Open(HKEY_CURRENT_USER, key_to_create.value().c_str(), KEY_READ));
196 } 198 }
OLDNEW
« no previous file with comments | « chrome/installer/util/create_dir_work_item_unittest.cc ('k') | chrome/installer/util/delete_after_reboot_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698