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

Side by Side Diff: chrome/installer/util/delete_reg_value_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) 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/delete_reg_value_work_item.h"
6
5 #include <windows.h> 7 #include <windows.h>
6 8
9 #include <memory>
10
7 #include "base/macros.h" 11 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
10 #include "base/test/test_reg_util_win.h" 13 #include "base/test/test_reg_util_win.h"
11 #include "base/win/registry.h" 14 #include "base/win/registry.h"
12 #include "chrome/installer/util/delete_reg_value_work_item.h"
13 #include "chrome/installer/util/work_item.h" 15 #include "chrome/installer/util/work_item.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 using base::win::RegKey; 18 using base::win::RegKey;
17 19
18 namespace { 20 namespace {
19 21
20 const wchar_t kTestKey[] = L"DeleteRegValueWorkItemTest"; 22 const wchar_t kTestKey[] = L"DeleteRegValueWorkItemTest";
21 const wchar_t kNameStr[] = L"name_str"; 23 const wchar_t kNameStr[] = L"name_str";
22 const wchar_t kNameDword[] = L"name_dword"; 24 const wchar_t kNameDword[] = L"name_dword";
(...skipping 22 matching lines...) Expand all
45 key.Create(HKEY_CURRENT_USER, kTestKey, KEY_READ | KEY_WRITE)); 47 key.Create(HKEY_CURRENT_USER, kTestKey, KEY_READ | KEY_WRITE));
46 const base::string16 data_str(L"data_111"); 48 const base::string16 data_str(L"data_111");
47 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kNameStr, data_str.c_str())); 49 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kNameStr, data_str.c_str()));
48 const DWORD data_dword = 100; 50 const DWORD data_dword = 100;
49 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kNameDword, data_dword)); 51 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kNameDword, data_dword));
50 52
51 static const wchar_t kNameEmpty[](L"name_empty"); 53 static const wchar_t kNameEmpty[](L"name_empty");
52 ASSERT_EQ(ERROR_SUCCESS, 54 ASSERT_EQ(ERROR_SUCCESS,
53 RegSetValueEx(key.Handle(), kNameEmpty, NULL, REG_SZ, NULL, 0)); 55 RegSetValueEx(key.Handle(), kNameEmpty, NULL, REG_SZ, NULL, 0));
54 56
55 scoped_ptr<DeleteRegValueWorkItem> work_item1( 57 std::unique_ptr<DeleteRegValueWorkItem> work_item1(
56 WorkItem::CreateDeleteRegValueWorkItem( 58 WorkItem::CreateDeleteRegValueWorkItem(
57 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameStr)); 59 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameStr));
58 scoped_ptr<DeleteRegValueWorkItem> work_item2( 60 std::unique_ptr<DeleteRegValueWorkItem> work_item2(
59 WorkItem::CreateDeleteRegValueWorkItem( 61 WorkItem::CreateDeleteRegValueWorkItem(
60 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameDword)); 62 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameDword));
61 scoped_ptr<DeleteRegValueWorkItem> work_item3( 63 std::unique_ptr<DeleteRegValueWorkItem> work_item3(
62 WorkItem::CreateDeleteRegValueWorkItem( 64 WorkItem::CreateDeleteRegValueWorkItem(
63 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameEmpty)); 65 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameEmpty));
64 66
65 EXPECT_TRUE(key.HasValue(kNameStr)); 67 EXPECT_TRUE(key.HasValue(kNameStr));
66 EXPECT_TRUE(key.HasValue(kNameDword)); 68 EXPECT_TRUE(key.HasValue(kNameDword));
67 EXPECT_TRUE(key.HasValue(kNameEmpty)); 69 EXPECT_TRUE(key.HasValue(kNameEmpty));
68 70
69 EXPECT_TRUE(work_item1->Do()); 71 EXPECT_TRUE(work_item1->Do());
70 EXPECT_TRUE(work_item2->Do()); 72 EXPECT_TRUE(work_item2->Do());
71 EXPECT_TRUE(work_item3->Do()); 73 EXPECT_TRUE(work_item3->Do());
(...skipping 26 matching lines...) Expand all
98 } 100 }
99 101
100 // Try deleting a value that doesn't exist. 102 // Try deleting a value that doesn't exist.
101 TEST_F(DeleteRegValueWorkItemTest, DeleteNonExistentValue) { 103 TEST_F(DeleteRegValueWorkItemTest, DeleteNonExistentValue) {
102 RegKey key; 104 RegKey key;
103 ASSERT_EQ(ERROR_SUCCESS, 105 ASSERT_EQ(ERROR_SUCCESS,
104 key.Create(HKEY_CURRENT_USER, kTestKey, KEY_READ | KEY_WRITE)); 106 key.Create(HKEY_CURRENT_USER, kTestKey, KEY_READ | KEY_WRITE));
105 EXPECT_FALSE(key.HasValue(kNameStr)); 107 EXPECT_FALSE(key.HasValue(kNameStr));
106 EXPECT_FALSE(key.HasValue(kNameDword)); 108 EXPECT_FALSE(key.HasValue(kNameDword));
107 109
108 scoped_ptr<DeleteRegValueWorkItem> work_item1( 110 std::unique_ptr<DeleteRegValueWorkItem> work_item1(
109 WorkItem::CreateDeleteRegValueWorkItem( 111 WorkItem::CreateDeleteRegValueWorkItem(
110 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameStr)); 112 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameStr));
111 scoped_ptr<DeleteRegValueWorkItem> work_item2( 113 std::unique_ptr<DeleteRegValueWorkItem> work_item2(
112 WorkItem::CreateDeleteRegValueWorkItem( 114 WorkItem::CreateDeleteRegValueWorkItem(
113 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameDword)); 115 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameDword));
114 116
115 EXPECT_TRUE(work_item1->Do()); 117 EXPECT_TRUE(work_item1->Do());
116 EXPECT_TRUE(work_item2->Do()); 118 EXPECT_TRUE(work_item2->Do());
117 119
118 EXPECT_FALSE(key.HasValue(kNameStr)); 120 EXPECT_FALSE(key.HasValue(kNameStr));
119 EXPECT_FALSE(key.HasValue(kNameDword)); 121 EXPECT_FALSE(key.HasValue(kNameDword));
120 122
121 work_item1->Rollback(); 123 work_item1->Rollback();
122 work_item2->Rollback(); 124 work_item2->Rollback();
123 125
124 EXPECT_FALSE(key.HasValue(kNameStr)); 126 EXPECT_FALSE(key.HasValue(kNameStr));
125 EXPECT_FALSE(key.HasValue(kNameDword)); 127 EXPECT_FALSE(key.HasValue(kNameDword));
126 } 128 }
127 129
128 // Try deleting a value whose key doesn't even exist. 130 // Try deleting a value whose key doesn't even exist.
129 TEST_F(DeleteRegValueWorkItemTest, DeleteValueInNonExistentKey) { 131 TEST_F(DeleteRegValueWorkItemTest, DeleteValueInNonExistentKey) {
130 RegKey key; 132 RegKey key;
131 // Confirm the key doesn't exist. 133 // Confirm the key doesn't exist.
132 ASSERT_EQ(ERROR_FILE_NOT_FOUND, 134 ASSERT_EQ(ERROR_FILE_NOT_FOUND,
133 key.Open(HKEY_CURRENT_USER, kTestKey, KEY_READ)); 135 key.Open(HKEY_CURRENT_USER, kTestKey, KEY_READ));
134 136
135 scoped_ptr<DeleteRegValueWorkItem> work_item1( 137 std::unique_ptr<DeleteRegValueWorkItem> work_item1(
136 WorkItem::CreateDeleteRegValueWorkItem( 138 WorkItem::CreateDeleteRegValueWorkItem(
137 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameStr)); 139 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameStr));
138 scoped_ptr<DeleteRegValueWorkItem> work_item2( 140 std::unique_ptr<DeleteRegValueWorkItem> work_item2(
139 WorkItem::CreateDeleteRegValueWorkItem( 141 WorkItem::CreateDeleteRegValueWorkItem(
140 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameDword)); 142 HKEY_CURRENT_USER, kTestKey, WorkItem::kWow64Default, kNameDword));
141 143
142 EXPECT_TRUE(work_item1->Do()); 144 EXPECT_TRUE(work_item1->Do());
143 EXPECT_TRUE(work_item2->Do()); 145 EXPECT_TRUE(work_item2->Do());
144 146
145 EXPECT_EQ(ERROR_FILE_NOT_FOUND, 147 EXPECT_EQ(ERROR_FILE_NOT_FOUND,
146 key.Open(HKEY_CURRENT_USER, kTestKey, KEY_READ)); 148 key.Open(HKEY_CURRENT_USER, kTestKey, KEY_READ));
147 149
148 work_item1->Rollback(); 150 work_item1->Rollback();
149 work_item2->Rollback(); 151 work_item2->Rollback();
150 152
151 EXPECT_EQ(ERROR_FILE_NOT_FOUND, 153 EXPECT_EQ(ERROR_FILE_NOT_FOUND,
152 key.Open(HKEY_CURRENT_USER, kTestKey, KEY_READ)); 154 key.Open(HKEY_CURRENT_USER, kTestKey, KEY_READ));
153 } 155 }
OLDNEW
« no previous file with comments | « chrome/installer/util/delete_reg_key_work_item_unittest.cc ('k') | chrome/installer/util/delete_tree_work_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698