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

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

Issue 7976045: Fix in-use updates for Chrome Frame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sanity check before dcommit Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/installer/util/copy_reg_key_work_item.cc ('k') | chrome/installer/util/work_item.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <shlwapi.h> // NOLINT 6 #include <shlwapi.h> // NOLINT
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/win/registry.h" 10 #include "base/win/registry.h"
(...skipping 24 matching lines...) Expand all
35 TEST_F(CopyRegKeyWorkItemTest, TestNoKey) { 35 TEST_F(CopyRegKeyWorkItemTest, TestNoKey) {
36 const std::wstring key_paths[] = { 36 const std::wstring key_paths[] = {
37 std::wstring(test_data_.base_path() + L"\\NoKeyHere"), 37 std::wstring(test_data_.base_path() + L"\\NoKeyHere"),
38 std::wstring(test_data_.base_path() + L"\\NoKeyHere\\OrHere") 38 std::wstring(test_data_.base_path() + L"\\NoKeyHere\\OrHere")
39 }; 39 };
40 RegKey key; 40 RegKey key;
41 for (size_t i = 0; i < arraysize(key_paths); ++i) { 41 for (size_t i = 0; i < arraysize(key_paths); ++i) {
42 const std::wstring& key_path = key_paths[i]; 42 const std::wstring& key_path = key_paths[i];
43 scoped_ptr<CopyRegKeyWorkItem> item( 43 scoped_ptr<CopyRegKeyWorkItem> item(
44 WorkItem::CreateCopyRegKeyWorkItem(test_data_.root_key(), key_path, 44 WorkItem::CreateCopyRegKeyWorkItem(test_data_.root_key(), key_path,
45 destination_path_)); 45 destination_path_,
46 WorkItem::ALWAYS));
46 EXPECT_TRUE(item->Do()); 47 EXPECT_TRUE(item->Do());
47 EXPECT_NE(ERROR_SUCCESS, 48 EXPECT_NE(ERROR_SUCCESS,
48 key.Open(test_data_.root_key(), destination_path_.c_str(), 49 key.Open(test_data_.root_key(), destination_path_.c_str(),
49 KEY_READ)); 50 KEY_READ));
50 item->Rollback(); 51 item->Rollback();
51 item.reset(); 52 item.reset();
52 EXPECT_NE(ERROR_SUCCESS, 53 EXPECT_NE(ERROR_SUCCESS,
53 key.Open(test_data_.root_key(), destination_path_.c_str(), 54 key.Open(test_data_.root_key(), destination_path_.c_str(),
54 KEY_READ)); 55 KEY_READ));
55 } 56 }
56 } 57 }
57 58
58 // Test that copying an empty key succeeds, and that rollback removes the copy. 59 // Test that copying an empty key succeeds, and that rollback removes the copy.
59 TEST_F(CopyRegKeyWorkItemTest, TestEmptyKey) { 60 TEST_F(CopyRegKeyWorkItemTest, TestEmptyKey) {
60 RegKey key; 61 RegKey key;
61 scoped_ptr<CopyRegKeyWorkItem> item( 62 scoped_ptr<CopyRegKeyWorkItem> item(
62 WorkItem::CreateCopyRegKeyWorkItem(test_data_.root_key(), 63 WorkItem::CreateCopyRegKeyWorkItem(test_data_.root_key(),
63 test_data_.empty_key_path(), 64 test_data_.empty_key_path(),
64 destination_path_)); 65 destination_path_,
66 WorkItem::ALWAYS));
65 EXPECT_TRUE(item->Do()); 67 EXPECT_TRUE(item->Do());
66 RegistryTestData::ExpectEmptyKey(test_data_.root_key(), 68 RegistryTestData::ExpectEmptyKey(test_data_.root_key(),
67 destination_path_.c_str()); 69 destination_path_.c_str());
68 item->Rollback(); 70 item->Rollback();
69 item.reset(); 71 item.reset();
70 EXPECT_NE(ERROR_SUCCESS, 72 EXPECT_NE(ERROR_SUCCESS,
71 key.Open(test_data_.root_key(), destination_path_.c_str(), 73 key.Open(test_data_.root_key(), destination_path_.c_str(),
72 KEY_READ)); 74 KEY_READ));
73 } 75 }
74 76
75 // Test that copying a key with subkeys and values succeeds, and that rollback 77 // Test that copying a key with subkeys and values succeeds, and that rollback
76 // removes the copy. 78 // removes the copy.
77 TEST_F(CopyRegKeyWorkItemTest, TestNonEmptyKey) { 79 TEST_F(CopyRegKeyWorkItemTest, TestNonEmptyKey) {
78 RegKey key; 80 RegKey key;
79 scoped_ptr<CopyRegKeyWorkItem> item( 81 scoped_ptr<CopyRegKeyWorkItem> item(
80 WorkItem::CreateCopyRegKeyWorkItem(test_data_.root_key(), 82 WorkItem::CreateCopyRegKeyWorkItem(test_data_.root_key(),
81 test_data_.non_empty_key_path(), 83 test_data_.non_empty_key_path(),
82 destination_path_)); 84 destination_path_,
85 WorkItem::ALWAYS));
83 EXPECT_TRUE(item->Do()); 86 EXPECT_TRUE(item->Do());
84 test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(), 87 test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(),
85 destination_path_.c_str()); 88 destination_path_.c_str());
86 item->Rollback(); 89 item->Rollback();
87 item.reset(); 90 item.reset();
88 EXPECT_NE(ERROR_SUCCESS, 91 EXPECT_NE(ERROR_SUCCESS,
89 key.Open(test_data_.root_key(), destination_path_.c_str(), 92 key.Open(test_data_.root_key(), destination_path_.c_str(),
90 KEY_READ)); 93 KEY_READ));
91 } 94 }
92 95
96 // Test that existing data isn't overwritten.
97 TEST_F(CopyRegKeyWorkItemTest, TestNoOverwrite) {
98 RegKey key;
99 // First copy the data into the dest.
100 EXPECT_EQ(ERROR_SUCCESS,
101 key.Create(test_data_.root_key(), destination_path_.c_str(),
102 KEY_WRITE));
103 EXPECT_EQ(ERROR_SUCCESS,
104 SHCopyKey(test_data_.root_key(),
105 test_data_.non_empty_key_path().c_str(), key.Handle(),
106 0));
107 key.Close();
108
109 // Now copy the empty key into the dest, which should do nothing.
110 scoped_ptr<CopyRegKeyWorkItem> item(
111 WorkItem::CreateCopyRegKeyWorkItem(test_data_.root_key(),
112 test_data_.empty_key_path(),
113 destination_path_,
114 WorkItem::IF_NOT_PRESENT));
115 EXPECT_TRUE(item->Do());
116
117 // Make sure it's all there.
118 test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(),
119 destination_path_.c_str());
120
121 // Rollback should do nothing.
122 item->Rollback();
123 item.reset();
124
125 // Make sure it's still all there.
126 test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(),
127 destination_path_.c_str());
128 }
129
93 // Test that copying an empty key over a key with data succeeds, and that 130 // Test that copying an empty key over a key with data succeeds, and that
94 // rollback restores the original data. 131 // rollback restores the original data.
95 TEST_F(CopyRegKeyWorkItemTest, TestOverwriteAndRestore) { 132 TEST_F(CopyRegKeyWorkItemTest, TestOverwriteAndRestore) {
96 RegKey key; 133 RegKey key;
97 // First copy the data into the dest. 134 // First copy the data into the dest.
98 EXPECT_EQ(ERROR_SUCCESS, 135 EXPECT_EQ(ERROR_SUCCESS,
99 key.Create(test_data_.root_key(), destination_path_.c_str(), 136 key.Create(test_data_.root_key(), destination_path_.c_str(),
100 KEY_WRITE)); 137 KEY_WRITE));
101 EXPECT_EQ(ERROR_SUCCESS, 138 EXPECT_EQ(ERROR_SUCCESS,
102 SHCopyKey(test_data_.root_key(), 139 SHCopyKey(test_data_.root_key(),
103 test_data_.non_empty_key_path().c_str(), key.Handle(), 140 test_data_.non_empty_key_path().c_str(), key.Handle(),
104 0)); 141 0));
105 key.Close(); 142 key.Close();
106 143
107 // Now copy the empty key into the dest. 144 // Now copy the empty key into the dest.
108 scoped_ptr<CopyRegKeyWorkItem> item( 145 scoped_ptr<CopyRegKeyWorkItem> item(
109 WorkItem::CreateCopyRegKeyWorkItem(test_data_.root_key(), 146 WorkItem::CreateCopyRegKeyWorkItem(test_data_.root_key(),
110 test_data_.empty_key_path(), 147 test_data_.empty_key_path(),
111 destination_path_)); 148 destination_path_,
149 WorkItem::ALWAYS));
112 EXPECT_TRUE(item->Do()); 150 EXPECT_TRUE(item->Do());
113 151
114 // Make sure the dest is now empty. 152 // Make sure the dest is now empty.
115 RegistryTestData::ExpectEmptyKey(test_data_.root_key(), 153 RegistryTestData::ExpectEmptyKey(test_data_.root_key(),
116 destination_path_.c_str()); 154 destination_path_.c_str());
117 155
118 // Restore the data. 156 // Restore the data.
119 item->Rollback(); 157 item->Rollback();
120 item.reset(); 158 item.reset();
121 159
122 // Make sure it's all there. 160 // Make sure it's all there.
123 test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(), 161 test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(),
124 destination_path_.c_str()); 162 destination_path_.c_str());
125 } 163 }
126 164
127 // Test that Rollback does nothing when the item is configured to ignore 165 // Test that Rollback does nothing when the item is configured to ignore
128 // failures. 166 // failures.
129 TEST_F(CopyRegKeyWorkItemTest, TestIgnoreFailRollback) { 167 TEST_F(CopyRegKeyWorkItemTest, TestIgnoreFailRollback) {
130 // Copy the empty key onto the non-empty key, ignoring failures. 168 // Copy the empty key onto the non-empty key, ignoring failures.
131 scoped_ptr<CopyRegKeyWorkItem> item( 169 scoped_ptr<CopyRegKeyWorkItem> item(
132 WorkItem::CreateCopyRegKeyWorkItem(test_data_.root_key(), 170 WorkItem::CreateCopyRegKeyWorkItem(test_data_.root_key(),
133 test_data_.empty_key_path(), 171 test_data_.empty_key_path(),
134 test_data_.non_empty_key_path())); 172 test_data_.non_empty_key_path(),
173 WorkItem::ALWAYS));
135 item->set_ignore_failure(true); 174 item->set_ignore_failure(true);
136 EXPECT_TRUE(item->Do()); 175 EXPECT_TRUE(item->Do());
137 item->Rollback(); 176 item->Rollback();
138 item.reset(); 177 item.reset();
139 RegistryTestData::ExpectEmptyKey(test_data_.root_key(), 178 RegistryTestData::ExpectEmptyKey(test_data_.root_key(),
140 test_data_.non_empty_key_path().c_str()); 179 test_data_.non_empty_key_path().c_str());
141 } 180 }
OLDNEW
« no previous file with comments | « chrome/installer/util/copy_reg_key_work_item.cc ('k') | chrome/installer/util/work_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698