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

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

Issue 3836005: Move pe_image and registry from base to base/win and use the namespace. It re... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/path_service.h" 9 #include "base/path_service.h"
10 #include "base/registry.h"
11 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
12 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/win/registry.h"
13 #include "chrome/installer/util/work_item.h" 13 #include "chrome/installer/util/work_item.h"
14 #include "chrome/installer/util/work_item_list.h" 14 #include "chrome/installer/util/work_item_list.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using base::win::RegKey;
18
17 namespace { 19 namespace {
18 wchar_t test_root[] = L"ListList";
19 wchar_t data_str[] = L"data_111";
20 20
21 class WorkItemListTest : public testing::Test { 21 wchar_t test_root[] = L"ListList";
22 protected: 22 wchar_t data_str[] = L"data_111";
23 virtual void SetUp() {
24 // Create a temporary key for testing
25 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS);
26 key.DeleteKey(test_root);
27 ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ));
28 ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ));
29 23
30 // Create a temp directory for test. 24 class WorkItemListTest : public testing::Test {
31 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); 25 protected:
32 test_dir_ = test_dir_.AppendASCII("WorkItemListTest"); 26 virtual void SetUp() {
33 file_util::Delete(test_dir_, true); 27 // Create a temporary key for testing
34 ASSERT_FALSE(file_util::PathExists(test_dir_)); 28 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS);
35 file_util::CreateDirectoryW(test_dir_); 29 key.DeleteKey(test_root);
36 ASSERT_TRUE(file_util::PathExists(test_dir_)); 30 ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ));
37 } 31 ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ));
38 32
39 virtual void TearDown() { 33 // Create a temp directory for test.
40 logging::CloseLogFile(); 34 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
41 // Clean up test directory 35 test_dir_ = test_dir_.AppendASCII("WorkItemListTest");
42 ASSERT_TRUE(file_util::Delete(test_dir_, true)); 36 file_util::Delete(test_dir_, true);
43 ASSERT_FALSE(file_util::PathExists(test_dir_)); 37 ASSERT_FALSE(file_util::PathExists(test_dir_));
44 // Clean up the temporary key 38 file_util::CreateDirectoryW(test_dir_);
45 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); 39 ASSERT_TRUE(file_util::PathExists(test_dir_));
46 ASSERT_TRUE(key.DeleteKey(test_root)); 40 }
47 }
48 41
49 FilePath test_dir_; 42 virtual void TearDown() {
50 }; 43 logging::CloseLogFile();
44 // Clean up test directory
45 ASSERT_TRUE(file_util::Delete(test_dir_, true));
46 ASSERT_FALSE(file_util::PathExists(test_dir_));
47 // Clean up the temporary key
48 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS);
49 ASSERT_TRUE(key.DeleteKey(test_root));
50 }
51
52 FilePath test_dir_;
51 }; 53 };
52 54
55 } // namespace
56
53 // Execute a WorkItem list successfully and then rollback. 57 // Execute a WorkItem list successfully and then rollback.
54 TEST_F(WorkItemListTest, ExecutionSuccess) { 58 TEST_F(WorkItemListTest, ExecutionSuccess) {
55 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); 59 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
56 scoped_ptr<WorkItem> work_item; 60 scoped_ptr<WorkItem> work_item;
57 61
58 FilePath top_dir_to_create(test_dir_); 62 FilePath top_dir_to_create(test_dir_);
59 top_dir_to_create = top_dir_to_create.AppendASCII("a"); 63 top_dir_to_create = top_dir_to_create.AppendASCII("a");
60 FilePath dir_to_create(top_dir_to_create); 64 FilePath dir_to_create(top_dir_to_create);
61 dir_to_create = dir_to_create.AppendASCII("b"); 65 dir_to_create = dir_to_create.AppendASCII("b");
62 ASSERT_FALSE(file_util::PathExists(dir_to_create)); 66 ASSERT_FALSE(file_util::PathExists(dir_to_create));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // The last one should not be there. 150 // The last one should not be there.
147 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, not_created_key.c_str(), 151 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, not_created_key.c_str(),
148 KEY_READ)); 152 KEY_READ));
149 153
150 work_item_list->Rollback(); 154 work_item_list->Rollback();
151 155
152 // Verify everything is rolled back. 156 // Verify everything is rolled back.
153 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 157 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
154 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); 158 EXPECT_FALSE(file_util::PathExists(top_dir_to_create));
155 } 159 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | chrome/test/mini_installer_test/chrome_mini_installer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698