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

Side by Side Diff: chrome/installer/util/delete_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/delete_reg_key_work_item.h"
6
5 #include <windows.h> 7 #include <windows.h>
6 #include <atlsecurity.h> // NOLINT 8 #include <atlsecurity.h> // NOLINT
7 #include <stddef.h> 9 #include <stddef.h>
8 10
11 #include <memory>
12
9 #include "base/logging.h" 13 #include "base/logging.h"
10 #include "base/macros.h" 14 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/win/registry.h" 15 #include "base/win/registry.h"
13 #include "chrome/installer/util/delete_reg_key_work_item.h"
14 #include "chrome/installer/util/registry_test_data.h" 16 #include "chrome/installer/util/registry_test_data.h"
15 #include "chrome/installer/util/work_item.h" 17 #include "chrome/installer/util/work_item.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 19
18 using base::win::RegKey; 20 using base::win::RegKey;
19 21
20 class DeleteRegKeyWorkItemTest : public testing::Test { 22 class DeleteRegKeyWorkItemTest : public testing::Test {
21 protected: 23 protected:
22 static void TearDownTestCase() { 24 static void TearDownTestCase() {
23 logging::CloseLogFile(); 25 logging::CloseLogFile();
24 } 26 }
25 27
26 void SetUp() override { 28 void SetUp() override {
27 ASSERT_TRUE(test_data_.Initialize(HKEY_CURRENT_USER, L"SOFTWARE\\TmpTmp")); 29 ASSERT_TRUE(test_data_.Initialize(HKEY_CURRENT_USER, L"SOFTWARE\\TmpTmp"));
28 } 30 }
29 31
30 RegistryTestData test_data_; 32 RegistryTestData test_data_;
31 }; 33 };
32 34
33 // Test that deleting a key that doesn't exist succeeds, and that rollback does 35 // Test that deleting a key that doesn't exist succeeds, and that rollback does
34 // nothing. 36 // nothing.
35 TEST_F(DeleteRegKeyWorkItemTest, TestNoKey) { 37 TEST_F(DeleteRegKeyWorkItemTest, TestNoKey) {
36 const std::wstring key_paths[] = { 38 const std::wstring key_paths[] = {
37 std::wstring(test_data_.base_path() + L"\\NoKeyHere"), 39 std::wstring(test_data_.base_path() + L"\\NoKeyHere"),
38 std::wstring(test_data_.base_path() + L"\\NoKeyHere\\OrHere") 40 std::wstring(test_data_.base_path() + L"\\NoKeyHere\\OrHere")
39 }; 41 };
40 RegKey key; 42 RegKey key;
41 for (size_t i = 0; i < arraysize(key_paths); ++i) { 43 for (size_t i = 0; i < arraysize(key_paths); ++i) {
42 const std::wstring& key_path = key_paths[i]; 44 const std::wstring& key_path = key_paths[i];
43 scoped_ptr<DeleteRegKeyWorkItem> item(WorkItem::CreateDeleteRegKeyWorkItem( 45 std::unique_ptr<DeleteRegKeyWorkItem> item(
44 test_data_.root_key(), key_path, WorkItem::kWow64Default)); 46 WorkItem::CreateDeleteRegKeyWorkItem(test_data_.root_key(), key_path,
47 WorkItem::kWow64Default));
45 EXPECT_TRUE(item->Do()); 48 EXPECT_TRUE(item->Do());
46 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(), 49 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(),
47 KEY_READ)); 50 KEY_READ));
48 item->Rollback(); 51 item->Rollback();
49 item.reset(); 52 item.reset();
50 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(), 53 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(),
51 KEY_READ)); 54 KEY_READ));
52 } 55 }
53 } 56 }
54 57
55 // Test that deleting an empty key succeeds, and that rollback brings it back. 58 // Test that deleting an empty key succeeds, and that rollback brings it back.
56 TEST_F(DeleteRegKeyWorkItemTest, TestEmptyKey) { 59 TEST_F(DeleteRegKeyWorkItemTest, TestEmptyKey) {
57 RegKey key; 60 RegKey key;
58 const std::wstring& key_path = test_data_.empty_key_path(); 61 const std::wstring& key_path = test_data_.empty_key_path();
59 scoped_ptr<DeleteRegKeyWorkItem> item(WorkItem::CreateDeleteRegKeyWorkItem( 62 std::unique_ptr<DeleteRegKeyWorkItem> item(
60 test_data_.root_key(), key_path, WorkItem::kWow64Default)); 63 WorkItem::CreateDeleteRegKeyWorkItem(test_data_.root_key(), key_path,
64 WorkItem::kWow64Default));
61 EXPECT_TRUE(item->Do()); 65 EXPECT_TRUE(item->Do());
62 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(), 66 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(),
63 KEY_READ)); 67 KEY_READ));
64 item->Rollback(); 68 item->Rollback();
65 item.reset(); 69 item.reset();
66 EXPECT_EQ(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(), 70 EXPECT_EQ(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(),
67 KEY_READ)); 71 KEY_READ));
68 } 72 }
69 73
70 // Test that deleting a key with subkeys and values succeeds, and that rollback 74 // Test that deleting a key with subkeys and values succeeds, and that rollback
71 // brings them all back. 75 // brings them all back.
72 TEST_F(DeleteRegKeyWorkItemTest, TestNonEmptyKey) { 76 TEST_F(DeleteRegKeyWorkItemTest, TestNonEmptyKey) {
73 RegKey key; 77 RegKey key;
74 const std::wstring& key_path = test_data_.non_empty_key_path(); 78 const std::wstring& key_path = test_data_.non_empty_key_path();
75 scoped_ptr<DeleteRegKeyWorkItem> item(WorkItem::CreateDeleteRegKeyWorkItem( 79 std::unique_ptr<DeleteRegKeyWorkItem> item(
76 test_data_.root_key(), key_path, WorkItem::kWow64Default)); 80 WorkItem::CreateDeleteRegKeyWorkItem(test_data_.root_key(), key_path,
81 WorkItem::kWow64Default));
77 EXPECT_TRUE(item->Do()); 82 EXPECT_TRUE(item->Do());
78 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(), 83 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(),
79 KEY_READ)); 84 KEY_READ));
80 item->Rollback(); 85 item->Rollback();
81 item.reset(); 86 item.reset();
82 test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(), key_path.c_str()); 87 test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(), key_path.c_str());
83 } 88 }
84 89
85 // Test that deleting a key with subkeys we can't delete fails, and that 90 // Test that deleting a key with subkeys we can't delete fails, and that
86 // everything is there after rollback. 91 // everything is there after rollback.
(...skipping 21 matching lines...) Expand all
108 const_cast<SECURITY_DESCRIPTOR*>( 113 const_cast<SECURITY_DESCRIPTOR*>(
109 sec_desc.GetPSECURITY_DESCRIPTOR()))); 114 sec_desc.GetPSECURITY_DESCRIPTOR())));
110 sec_desc.FromString(L"D:PAI(A;OICI;KA;;;BU)"); // builtin users all access 115 sec_desc.FromString(L"D:PAI(A;OICI;KA;;;BU)"); // builtin users all access
111 EXPECT_EQ(ERROR_SUCCESS, 116 EXPECT_EQ(ERROR_SUCCESS,
112 RegSetKeySecurity(subkey2.Handle(), DACL_SECURITY_INFORMATION, 117 RegSetKeySecurity(subkey2.Handle(), DACL_SECURITY_INFORMATION,
113 const_cast<SECURITY_DESCRIPTOR*>( 118 const_cast<SECURITY_DESCRIPTOR*>(
114 sec_desc.GetPSECURITY_DESCRIPTOR()))); 119 sec_desc.GetPSECURITY_DESCRIPTOR())));
115 subkey2.Close(); 120 subkey2.Close();
116 subkey.Close(); 121 subkey.Close();
117 key.Close(); 122 key.Close();
118 scoped_ptr<DeleteRegKeyWorkItem> item(WorkItem::CreateDeleteRegKeyWorkItem( 123 std::unique_ptr<DeleteRegKeyWorkItem> item(
119 test_data_.root_key(), key_name, WorkItem::kWow64Default)); 124 WorkItem::CreateDeleteRegKeyWorkItem(test_data_.root_key(), key_name,
125 WorkItem::kWow64Default));
120 EXPECT_FALSE(item->Do()); 126 EXPECT_FALSE(item->Do());
121 EXPECT_EQ(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_name.c_str(), 127 EXPECT_EQ(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_name.c_str(),
122 KEY_QUERY_VALUE)); 128 KEY_QUERY_VALUE));
123 item->Rollback(); 129 item->Rollback();
124 item.reset(); 130 item.reset();
125 EXPECT_EQ(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_name.c_str(), 131 EXPECT_EQ(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_name.c_str(),
126 KEY_QUERY_VALUE)); 132 KEY_QUERY_VALUE));
127 std::wstring str_value; 133 std::wstring str_value;
128 EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(NULL, &str_value)); 134 EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(NULL, &str_value));
129 EXPECT_EQ(key_name, str_value); 135 EXPECT_EQ(key_name, str_value);
130 EXPECT_EQ(ERROR_SUCCESS, key.OpenKey(L"Subkey", KEY_READ | WRITE_DAC)); 136 EXPECT_EQ(ERROR_SUCCESS, key.OpenKey(L"Subkey", KEY_READ | WRITE_DAC));
131 dw_value = 0; 137 dw_value = 0;
132 EXPECT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"SomeValue", &dw_value)); 138 EXPECT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"SomeValue", &dw_value));
133 EXPECT_EQ(1U, dw_value); 139 EXPECT_EQ(1U, dw_value);
134 // Give users all access to the subkey so it can be deleted. 140 // Give users all access to the subkey so it can be deleted.
135 EXPECT_EQ(ERROR_SUCCESS, 141 EXPECT_EQ(ERROR_SUCCESS,
136 RegSetKeySecurity(key.Handle(), DACL_SECURITY_INFORMATION, 142 RegSetKeySecurity(key.Handle(), DACL_SECURITY_INFORMATION,
137 const_cast<SECURITY_DESCRIPTOR*>( 143 const_cast<SECURITY_DESCRIPTOR*>(
138 sec_desc.GetPSECURITY_DESCRIPTOR()))); 144 sec_desc.GetPSECURITY_DESCRIPTOR())));
139 EXPECT_EQ(ERROR_SUCCESS, key.OpenKey(L"Subkey2", KEY_QUERY_VALUE)); 145 EXPECT_EQ(ERROR_SUCCESS, key.OpenKey(L"Subkey2", KEY_QUERY_VALUE));
140 EXPECT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"", &dw_value)); 146 EXPECT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"", &dw_value));
141 EXPECT_EQ(2U, dw_value); 147 EXPECT_EQ(2U, dw_value);
142 } 148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698