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

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

Issue 282363003: Add WOW64 support to the installer registry work items (Closed) Base URL: https://chromium.googlesource.com/chromium/src
Patch Set: nits. fix call to DeleteRegistryKey Created 6 years, 7 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 <windows.h> 5 #include <windows.h>
6 #include <atlsecurity.h> // NOLINT 6 #include <atlsecurity.h> // NOLINT
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/win/registry.h" 9 #include "base/win/registry.h"
10 #include "chrome/installer/util/delete_reg_key_work_item.h" 10 #include "chrome/installer/util/delete_reg_key_work_item.h"
(...skipping 19 matching lines...) Expand all
30 // Test that deleting a key that doesn't exist succeeds, and that rollback does 30 // Test that deleting a key that doesn't exist succeeds, and that rollback does
31 // nothing. 31 // nothing.
32 TEST_F(DeleteRegKeyWorkItemTest, TestNoKey) { 32 TEST_F(DeleteRegKeyWorkItemTest, TestNoKey) {
33 const std::wstring key_paths[] = { 33 const std::wstring key_paths[] = {
34 std::wstring(test_data_.base_path() + L"\\NoKeyHere"), 34 std::wstring(test_data_.base_path() + L"\\NoKeyHere"),
35 std::wstring(test_data_.base_path() + L"\\NoKeyHere\\OrHere") 35 std::wstring(test_data_.base_path() + L"\\NoKeyHere\\OrHere")
36 }; 36 };
37 RegKey key; 37 RegKey key;
38 for (size_t i = 0; i < arraysize(key_paths); ++i) { 38 for (size_t i = 0; i < arraysize(key_paths); ++i) {
39 const std::wstring& key_path = key_paths[i]; 39 const std::wstring& key_path = key_paths[i];
40 scoped_ptr<DeleteRegKeyWorkItem> item( 40 scoped_ptr<DeleteRegKeyWorkItem> item(WorkItem::CreateDeleteRegKeyWorkItem(
41 WorkItem::CreateDeleteRegKeyWorkItem(test_data_.root_key(), key_path)); 41 test_data_.root_key(), key_path, WorkItem::kWow64Default));
42 EXPECT_TRUE(item->Do()); 42 EXPECT_TRUE(item->Do());
43 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(), 43 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(),
44 KEY_READ)); 44 KEY_READ));
45 item->Rollback(); 45 item->Rollback();
46 item.reset(); 46 item.reset();
47 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(), 47 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(),
48 KEY_READ)); 48 KEY_READ));
49 } 49 }
50 } 50 }
51 51
52 // Test that deleting an empty key succeeds, and that rollback brings it back. 52 // Test that deleting an empty key succeeds, and that rollback brings it back.
53 TEST_F(DeleteRegKeyWorkItemTest, TestEmptyKey) { 53 TEST_F(DeleteRegKeyWorkItemTest, TestEmptyKey) {
54 RegKey key; 54 RegKey key;
55 const std::wstring& key_path = test_data_.empty_key_path(); 55 const std::wstring& key_path = test_data_.empty_key_path();
56 scoped_ptr<DeleteRegKeyWorkItem> item( 56 scoped_ptr<DeleteRegKeyWorkItem> item(WorkItem::CreateDeleteRegKeyWorkItem(
57 WorkItem::CreateDeleteRegKeyWorkItem(test_data_.root_key(), key_path)); 57 test_data_.root_key(), key_path, WorkItem::kWow64Default));
58 EXPECT_TRUE(item->Do()); 58 EXPECT_TRUE(item->Do());
59 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(), 59 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(),
60 KEY_READ)); 60 KEY_READ));
61 item->Rollback(); 61 item->Rollback();
62 item.reset(); 62 item.reset();
63 EXPECT_EQ(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(), 63 EXPECT_EQ(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(),
64 KEY_READ)); 64 KEY_READ));
65 } 65 }
66 66
67 // Test that deleting a key with subkeys and values succeeds, and that rollback 67 // Test that deleting a key with subkeys and values succeeds, and that rollback
68 // brings them all back. 68 // brings them all back.
69 TEST_F(DeleteRegKeyWorkItemTest, TestNonEmptyKey) { 69 TEST_F(DeleteRegKeyWorkItemTest, TestNonEmptyKey) {
70 RegKey key; 70 RegKey key;
71 const std::wstring& key_path = test_data_.non_empty_key_path(); 71 const std::wstring& key_path = test_data_.non_empty_key_path();
72 scoped_ptr<DeleteRegKeyWorkItem> item( 72 scoped_ptr<DeleteRegKeyWorkItem> item(WorkItem::CreateDeleteRegKeyWorkItem(
73 WorkItem::CreateDeleteRegKeyWorkItem(test_data_.root_key(), key_path)); 73 test_data_.root_key(), key_path, WorkItem::kWow64Default));
74 EXPECT_TRUE(item->Do()); 74 EXPECT_TRUE(item->Do());
75 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(), 75 EXPECT_NE(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_path.c_str(),
76 KEY_READ)); 76 KEY_READ));
77 item->Rollback(); 77 item->Rollback();
78 item.reset(); 78 item.reset();
79 test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(), key_path.c_str()); 79 test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(), key_path.c_str());
80 } 80 }
81 81
82 // Test that deleting a key with subkeys we can't delete fails, and that 82 // Test that deleting a key with subkeys we can't delete fails, and that
83 // everything is there after rollback. 83 // everything is there after rollback.
(...skipping 21 matching lines...) Expand all
105 const_cast<SECURITY_DESCRIPTOR*>( 105 const_cast<SECURITY_DESCRIPTOR*>(
106 sec_desc.GetPSECURITY_DESCRIPTOR()))); 106 sec_desc.GetPSECURITY_DESCRIPTOR())));
107 sec_desc.FromString(L"D:PAI(A;OICI;KA;;;BU)"); // builtin users all access 107 sec_desc.FromString(L"D:PAI(A;OICI;KA;;;BU)"); // builtin users all access
108 EXPECT_EQ(ERROR_SUCCESS, 108 EXPECT_EQ(ERROR_SUCCESS,
109 RegSetKeySecurity(subkey2.Handle(), DACL_SECURITY_INFORMATION, 109 RegSetKeySecurity(subkey2.Handle(), DACL_SECURITY_INFORMATION,
110 const_cast<SECURITY_DESCRIPTOR*>( 110 const_cast<SECURITY_DESCRIPTOR*>(
111 sec_desc.GetPSECURITY_DESCRIPTOR()))); 111 sec_desc.GetPSECURITY_DESCRIPTOR())));
112 subkey2.Close(); 112 subkey2.Close();
113 subkey.Close(); 113 subkey.Close();
114 key.Close(); 114 key.Close();
115 scoped_ptr<DeleteRegKeyWorkItem> item( 115 scoped_ptr<DeleteRegKeyWorkItem> item(WorkItem::CreateDeleteRegKeyWorkItem(
116 WorkItem::CreateDeleteRegKeyWorkItem(test_data_.root_key(), key_name)); 116 test_data_.root_key(), key_name, WorkItem::kWow64Default));
117 EXPECT_FALSE(item->Do()); 117 EXPECT_FALSE(item->Do());
118 EXPECT_EQ(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_name.c_str(), 118 EXPECT_EQ(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_name.c_str(),
119 KEY_QUERY_VALUE)); 119 KEY_QUERY_VALUE));
120 item->Rollback(); 120 item->Rollback();
121 item.reset(); 121 item.reset();
122 EXPECT_EQ(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_name.c_str(), 122 EXPECT_EQ(ERROR_SUCCESS, key.Open(test_data_.root_key(), key_name.c_str(),
123 KEY_QUERY_VALUE)); 123 KEY_QUERY_VALUE));
124 std::wstring str_value; 124 std::wstring str_value;
125 EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(NULL, &str_value)); 125 EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(NULL, &str_value));
126 EXPECT_EQ(key_name, str_value); 126 EXPECT_EQ(key_name, str_value);
127 EXPECT_EQ(ERROR_SUCCESS, key.OpenKey(L"Subkey", KEY_READ | WRITE_DAC)); 127 EXPECT_EQ(ERROR_SUCCESS, key.OpenKey(L"Subkey", KEY_READ | WRITE_DAC));
128 dw_value = 0; 128 dw_value = 0;
129 EXPECT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"SomeValue", &dw_value)); 129 EXPECT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"SomeValue", &dw_value));
130 EXPECT_EQ(1U, dw_value); 130 EXPECT_EQ(1U, dw_value);
131 // Give users all access to the subkey so it can be deleted. 131 // Give users all access to the subkey so it can be deleted.
132 EXPECT_EQ(ERROR_SUCCESS, 132 EXPECT_EQ(ERROR_SUCCESS,
133 RegSetKeySecurity(key.Handle(), DACL_SECURITY_INFORMATION, 133 RegSetKeySecurity(key.Handle(), DACL_SECURITY_INFORMATION,
134 const_cast<SECURITY_DESCRIPTOR*>( 134 const_cast<SECURITY_DESCRIPTOR*>(
135 sec_desc.GetPSECURITY_DESCRIPTOR()))); 135 sec_desc.GetPSECURITY_DESCRIPTOR())));
136 EXPECT_EQ(ERROR_SUCCESS, key.OpenKey(L"Subkey2", KEY_QUERY_VALUE)); 136 EXPECT_EQ(ERROR_SUCCESS, key.OpenKey(L"Subkey2", KEY_QUERY_VALUE));
137 EXPECT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"", &dw_value)); 137 EXPECT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"", &dw_value));
138 EXPECT_EQ(2U, dw_value); 138 EXPECT_EQ(2U, dw_value);
139 } 139 }
OLDNEW
« no previous file with comments | « chrome/installer/util/delete_reg_key_work_item.cc ('k') | chrome/installer/util/delete_reg_value_work_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698