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

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

Issue 412983002: Migrate WorkItemListTest to use RegistryOverrideManager instead of rolling its own attempt at temp … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, reenable tests. Created 6 years, 5 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 | « no previous file | no next file » | 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) 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 <windows.h> 5 #include <windows.h>
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/test/test_reg_util_win.h"
13 #include "base/win/registry.h" 14 #include "base/win/registry.h"
14 #include "chrome/installer/util/conditional_work_item_list.h" 15 #include "chrome/installer/util/conditional_work_item_list.h"
15 #include "chrome/installer/util/work_item.h" 16 #include "chrome/installer/util/work_item.h"
16 #include "chrome/installer/util/work_item_list.h" 17 #include "chrome/installer/util/work_item_list.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 using base::win::RegKey; 20 using base::win::RegKey;
20 21
21 namespace { 22 namespace {
22 23
23 const wchar_t kTestRoot[] = L"ListList"; 24 const wchar_t kTestRoot[] = L"ListList";
24 const wchar_t kDataStr[] = L"data_111"; 25 const wchar_t kDataStr[] = L"data_111";
25 const wchar_t kName[] = L"name"; 26 const wchar_t kName[] = L"name";
26 27
27 class WorkItemListTest : public testing::Test { 28 class WorkItemListTest : public testing::Test {
28 protected: 29 protected:
29 virtual void SetUp() { 30 virtual void SetUp() {
30 // Create a temporary key for testing
31 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS);
32 key.DeleteKey(kTestRoot);
33 ASSERT_NE(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, kTestRoot, KEY_READ));
34 ASSERT_EQ(ERROR_SUCCESS,
35 key.Create(HKEY_CURRENT_USER, kTestRoot, KEY_READ));
36
37 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
32 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER, L"root_pit");
grt (UTC plus 2) 2014/07/23 22:03:59 this is so much better. thank you for doing the ri
38 } 33 }
39 34
40 virtual void TearDown() { 35 virtual void TearDown() {
41 logging::CloseLogFile(); 36 logging::CloseLogFile();
42
43 // Clean up the temporary key
44 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS);
45 ASSERT_EQ(ERROR_SUCCESS, key.DeleteKey(kTestRoot));
46 } 37 }
47 38
48 base::ScopedTempDir temp_dir_; 39 base::ScopedTempDir temp_dir_;
40 registry_util::RegistryOverrideManager registry_override_manager_;
49 }; 41 };
50 42
51 } // namespace 43 } // namespace
52 44
53 // Execute a WorkItem list successfully and then rollback. 45 // Execute a WorkItem list successfully and then rollback.
54 // http://crbug.com/396405 46 TEST_F(WorkItemListTest, ExecutionSuccess) {
55 TEST_F(WorkItemListTest, DISABLED_ExecutionSuccess) {
56 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); 47 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
57 scoped_ptr<WorkItem> work_item; 48 scoped_ptr<WorkItem> work_item;
58 49
59 base::FilePath top_dir_to_create(temp_dir_.path()); 50 base::FilePath top_dir_to_create(temp_dir_.path());
60 top_dir_to_create = top_dir_to_create.AppendASCII("a"); 51 top_dir_to_create = top_dir_to_create.AppendASCII("a");
61 base::FilePath dir_to_create(top_dir_to_create); 52 base::FilePath dir_to_create(top_dir_to_create);
62 dir_to_create = dir_to_create.AppendASCII("b"); 53 dir_to_create = dir_to_create.AppendASCII("b");
63 ASSERT_FALSE(base::PathExists(dir_to_create)); 54 ASSERT_FALSE(base::PathExists(dir_to_create));
64 55
65 work_item.reset(reinterpret_cast<WorkItem*>( 56 work_item.reset(reinterpret_cast<WorkItem*>(
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 work_item_list->Rollback(); 217 work_item_list->Rollback();
227 218
228 // Verify everything is rolled back. 219 // Verify everything is rolled back.
229 // The value must have been deleted first in roll back otherwise the key 220 // The value must have been deleted first in roll back otherwise the key
230 // can not be deleted. 221 // can not be deleted.
231 EXPECT_NE(ERROR_SUCCESS, 222 EXPECT_NE(ERROR_SUCCESS,
232 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 223 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
233 EXPECT_FALSE(base::PathExists(top_dir_to_create)); 224 EXPECT_FALSE(base::PathExists(top_dir_to_create));
234 } 225 }
235 226
236 // http://crbug.com/396405 227 TEST_F(WorkItemListTest, ConditionalExecutionConditionFailure) {
237 TEST_F(WorkItemListTest, DISABLED_ConditionalExecutionConditionFailure) {
238 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); 228 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
239 scoped_ptr<WorkItem> work_item; 229 scoped_ptr<WorkItem> work_item;
240 230
241 base::FilePath top_dir_to_create(temp_dir_.path()); 231 base::FilePath top_dir_to_create(temp_dir_.path());
242 top_dir_to_create = top_dir_to_create.AppendASCII("a"); 232 top_dir_to_create = top_dir_to_create.AppendASCII("a");
243 base::FilePath dir_to_create(top_dir_to_create); 233 base::FilePath dir_to_create(top_dir_to_create);
244 dir_to_create = dir_to_create.AppendASCII("b"); 234 dir_to_create = dir_to_create.AppendASCII("b");
245 ASSERT_FALSE(base::PathExists(dir_to_create)); 235 ASSERT_FALSE(base::PathExists(dir_to_create));
246 236
247 work_item.reset(reinterpret_cast<WorkItem*>( 237 work_item.reset(reinterpret_cast<WorkItem*>(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 279
290 work_item_list->Rollback(); 280 work_item_list->Rollback();
291 281
292 // Verify everything is rolled back. 282 // Verify everything is rolled back.
293 // The value must have been deleted first in roll back otherwise the key 283 // The value must have been deleted first in roll back otherwise the key
294 // can not be deleted. 284 // can not be deleted.
295 EXPECT_NE(ERROR_SUCCESS, 285 EXPECT_NE(ERROR_SUCCESS,
296 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 286 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
297 EXPECT_FALSE(base::PathExists(top_dir_to_create)); 287 EXPECT_FALSE(base::PathExists(top_dir_to_create));
298 } 288 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698