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

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

Issue 6793008: Replacing base::DIR_TEMP with ScopedTempDir when appropriate. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Needed to rebase; patch didn't apply cleanly to save_package_unittest. Created 9 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 | Annotate | Revision Log
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 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/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_temp_dir.h"
10 #include "base/path_service.h" 11 #include "base/path_service.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "chrome/installer/util/work_item.h" 13 #include "chrome/installer/util/work_item.h"
13 #include "chrome/installer/util/create_dir_work_item.h" 14 #include "chrome/installer/util/create_dir_work_item.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace { 17 namespace {
17 class CreateDirWorkItemTest : public testing::Test { 18 class CreateDirWorkItemTest : public testing::Test {
18 protected: 19 protected:
19 virtual void SetUp() { 20 virtual void SetUp() {
20 // Name a subdirectory of the temp directory. 21 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
21 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
22 test_dir_ = test_dir_.AppendASCII("CreateDirWorkItemTest");
23
24 // Create a fresh, empty copy of this directory.
25 file_util::Delete(test_dir_, true);
26 file_util::CreateDirectoryW(test_dir_);
27 }
28 virtual void TearDown() {
29 // Clean up test directory
30 ASSERT_TRUE(file_util::Delete(test_dir_, true));
31 ASSERT_FALSE(file_util::PathExists(test_dir_));
32 } 22 }
33 23
34 // the path to temporary directory used to contain the test operations 24 ScopedTempDir temp_dir_;
35 FilePath test_dir_;
36 }; 25 };
37 }; 26 };
38 27
39 TEST_F(CreateDirWorkItemTest, CreatePath) { 28 TEST_F(CreateDirWorkItemTest, CreatePath) {
40 FilePath parent_dir(test_dir_); 29 FilePath parent_dir(temp_dir_.path());
41 parent_dir = parent_dir.AppendASCII("a"); 30 parent_dir = parent_dir.AppendASCII("a");
42 file_util::CreateDirectory(parent_dir); 31 file_util::CreateDirectory(parent_dir);
43 ASSERT_TRUE(file_util::PathExists(parent_dir)); 32 ASSERT_TRUE(file_util::PathExists(parent_dir));
44 33
45 FilePath top_dir_to_create(parent_dir); 34 FilePath top_dir_to_create(parent_dir);
46 top_dir_to_create = top_dir_to_create.AppendASCII("b"); 35 top_dir_to_create = top_dir_to_create.AppendASCII("b");
47 36
48 FilePath dir_to_create(top_dir_to_create); 37 FilePath dir_to_create(top_dir_to_create);
49 dir_to_create = dir_to_create.AppendASCII("c"); 38 dir_to_create = dir_to_create.AppendASCII("c");
50 dir_to_create = dir_to_create.AppendASCII("d"); 39 dir_to_create = dir_to_create.AppendASCII("d");
51 40
52 scoped_ptr<CreateDirWorkItem> work_item( 41 scoped_ptr<CreateDirWorkItem> work_item(
53 WorkItem::CreateCreateDirWorkItem(dir_to_create)); 42 WorkItem::CreateCreateDirWorkItem(dir_to_create));
54 43
55 EXPECT_TRUE(work_item->Do()); 44 EXPECT_TRUE(work_item->Do());
56 45
57 EXPECT_TRUE(file_util::PathExists(dir_to_create)); 46 EXPECT_TRUE(file_util::PathExists(dir_to_create));
58 47
59 work_item->Rollback(); 48 work_item->Rollback();
60 49
61 // Rollback should delete all the paths up to top_dir_to_create. 50 // Rollback should delete all the paths up to top_dir_to_create.
62 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); 51 EXPECT_FALSE(file_util::PathExists(top_dir_to_create));
63 EXPECT_TRUE(file_util::PathExists(parent_dir)); 52 EXPECT_TRUE(file_util::PathExists(parent_dir));
64 } 53 }
65 54
66 TEST_F(CreateDirWorkItemTest, CreateExistingPath) { 55 TEST_F(CreateDirWorkItemTest, CreateExistingPath) {
67 FilePath dir_to_create(test_dir_); 56 FilePath dir_to_create(temp_dir_.path());
68 dir_to_create = dir_to_create.AppendASCII("aa"); 57 dir_to_create = dir_to_create.AppendASCII("aa");
69 file_util::CreateDirectory(dir_to_create); 58 file_util::CreateDirectory(dir_to_create);
70 ASSERT_TRUE(file_util::PathExists(dir_to_create)); 59 ASSERT_TRUE(file_util::PathExists(dir_to_create));
71 60
72 scoped_ptr<CreateDirWorkItem> work_item( 61 scoped_ptr<CreateDirWorkItem> work_item(
73 WorkItem::CreateCreateDirWorkItem(dir_to_create)); 62 WorkItem::CreateCreateDirWorkItem(dir_to_create));
74 63
75 EXPECT_TRUE(work_item->Do()); 64 EXPECT_TRUE(work_item->Do());
76 65
77 EXPECT_TRUE(file_util::PathExists(dir_to_create)); 66 EXPECT_TRUE(file_util::PathExists(dir_to_create));
78 67
79 work_item->Rollback(); 68 work_item->Rollback();
80 69
81 // Rollback should not remove the path since it exists before 70 // Rollback should not remove the path since it exists before
82 // the CreateDirWorkItem is called. 71 // the CreateDirWorkItem is called.
83 EXPECT_TRUE(file_util::PathExists(dir_to_create)); 72 EXPECT_TRUE(file_util::PathExists(dir_to_create));
84 } 73 }
85 74
86 TEST_F(CreateDirWorkItemTest, CreateSharedPath) { 75 TEST_F(CreateDirWorkItemTest, CreateSharedPath) {
87 FilePath dir_to_create_1(test_dir_); 76 FilePath dir_to_create_1(temp_dir_.path());
88 dir_to_create_1 = dir_to_create_1.AppendASCII("aaa"); 77 dir_to_create_1 = dir_to_create_1.AppendASCII("aaa");
89 78
90 FilePath dir_to_create_2(dir_to_create_1); 79 FilePath dir_to_create_2(dir_to_create_1);
91 dir_to_create_2 = dir_to_create_2.AppendASCII("bbb"); 80 dir_to_create_2 = dir_to_create_2.AppendASCII("bbb");
92 81
93 FilePath dir_to_create_3(dir_to_create_2); 82 FilePath dir_to_create_3(dir_to_create_2);
94 dir_to_create_3 = dir_to_create_3.AppendASCII("ccc"); 83 dir_to_create_3 = dir_to_create_3.AppendASCII("ccc");
95 84
96 scoped_ptr<CreateDirWorkItem> work_item( 85 scoped_ptr<CreateDirWorkItem> work_item(
97 WorkItem::CreateCreateDirWorkItem(dir_to_create_3)); 86 WorkItem::CreateCreateDirWorkItem(dir_to_create_3));
(...skipping 12 matching lines...) Expand all
110 99
111 // Rollback should delete dir_to_create_3. 100 // Rollback should delete dir_to_create_3.
112 EXPECT_FALSE(file_util::PathExists(dir_to_create_3)); 101 EXPECT_FALSE(file_util::PathExists(dir_to_create_3));
113 102
114 // Rollback should not delete dir_to_create_2 as it is shared. 103 // Rollback should not delete dir_to_create_2 as it is shared.
115 EXPECT_TRUE(file_util::PathExists(dir_to_create_2)); 104 EXPECT_TRUE(file_util::PathExists(dir_to_create_2));
116 EXPECT_TRUE(file_util::PathExists(dir_to_create_4)); 105 EXPECT_TRUE(file_util::PathExists(dir_to_create_4));
117 } 106 }
118 107
119 TEST_F(CreateDirWorkItemTest, RollbackWithMissingDir) { 108 TEST_F(CreateDirWorkItemTest, RollbackWithMissingDir) {
120 FilePath dir_to_create_1(test_dir_); 109 FilePath dir_to_create_1(temp_dir_.path());
121 dir_to_create_1 = dir_to_create_1.AppendASCII("aaaa"); 110 dir_to_create_1 = dir_to_create_1.AppendASCII("aaaa");
122 111
123 FilePath dir_to_create_2(dir_to_create_1); 112 FilePath dir_to_create_2(dir_to_create_1);
124 dir_to_create_2 = dir_to_create_2.AppendASCII("bbbb"); 113 dir_to_create_2 = dir_to_create_2.AppendASCII("bbbb");
125 114
126 FilePath dir_to_create_3(dir_to_create_2); 115 FilePath dir_to_create_3(dir_to_create_2);
127 dir_to_create_3 = dir_to_create_3.AppendASCII("cccc"); 116 dir_to_create_3 = dir_to_create_3.AppendASCII("cccc");
128 117
129 scoped_ptr<CreateDirWorkItem> work_item( 118 scoped_ptr<CreateDirWorkItem> work_item(
130 WorkItem::CreateCreateDirWorkItem(dir_to_create_3)); 119 WorkItem::CreateCreateDirWorkItem(dir_to_create_3));
131 120
132 EXPECT_TRUE(work_item->Do()); 121 EXPECT_TRUE(work_item->Do());
133 122
134 EXPECT_TRUE(file_util::PathExists(dir_to_create_3)); 123 EXPECT_TRUE(file_util::PathExists(dir_to_create_3));
135 124
136 RemoveDirectory(dir_to_create_3.value().c_str()); 125 RemoveDirectory(dir_to_create_3.value().c_str());
137 ASSERT_FALSE(file_util::PathExists(dir_to_create_3)); 126 ASSERT_FALSE(file_util::PathExists(dir_to_create_3));
138 127
139 work_item->Rollback(); 128 work_item->Rollback();
140 129
141 // dir_to_create_3 has already been deleted, Rollback should delete 130 // dir_to_create_3 has already been deleted, Rollback should delete
142 // the rest. 131 // the rest.
143 EXPECT_FALSE(file_util::PathExists(dir_to_create_1)); 132 EXPECT_FALSE(file_util::PathExists(dir_to_create_1));
144 } 133 }
OLDNEW
« no previous file with comments | « chrome/installer/util/copy_tree_work_item_unittest.cc ('k') | chrome/installer/util/delete_tree_work_item_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698