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

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

Issue 2321573002: //chrome misc: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Fix Win compilation Created 4 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
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 <stdint.h> 6 #include <stdint.h>
7 #include <wincrypt.h> 7 #include <wincrypt.h>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 65
66 // Test that all intermediate dirs are cleaned up if they're empty when 66 // Test that all intermediate dirs are cleaned up if they're empty when
67 // Delete() is called. 67 // Delete() is called.
68 TEST_F(SelfCleaningTempDirTest, RemoveUnusedOnDelete) { 68 TEST_F(SelfCleaningTempDirTest, RemoveUnusedOnDelete) {
69 // Make a directory in which we'll work. 69 // Make a directory in which we'll work.
70 base::ScopedTempDir work_dir; 70 base::ScopedTempDir work_dir;
71 EXPECT_TRUE(work_dir.CreateUniqueTempDir()); 71 EXPECT_TRUE(work_dir.CreateUniqueTempDir());
72 72
73 // Make up some path under the temp dir. 73 // Make up some path under the temp dir.
74 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two")); 74 base::FilePath parent_temp_dir(
75 work_dir.GetPath().Append(L"One").Append(L"Two"));
75 SelfCleaningTempDir temp_dir; 76 SelfCleaningTempDir temp_dir;
76 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three")); 77 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three"));
77 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path()); 78 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path());
78 EXPECT_TRUE(base::DirectoryExists(temp_dir.path())); 79 EXPECT_TRUE(base::DirectoryExists(temp_dir.path()));
79 EXPECT_TRUE(temp_dir.Delete()); 80 EXPECT_TRUE(temp_dir.Delete());
80 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.Append(L"Three"))); 81 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.Append(L"Three")));
81 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir)); 82 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir));
82 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName())); 83 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName()));
83 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir.DirName().DirName())); 84 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir.DirName().DirName()));
84 EXPECT_TRUE(work_dir.Delete()); 85 EXPECT_TRUE(work_dir.Delete());
85 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName().DirName())); 86 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName().DirName()));
86 } 87 }
87 88
88 // Test that two clients can work in the same area. 89 // Test that two clients can work in the same area.
89 TEST_F(SelfCleaningTempDirTest, TwoClients) { 90 TEST_F(SelfCleaningTempDirTest, TwoClients) {
90 // Make a directory in which we'll work. 91 // Make a directory in which we'll work.
91 base::ScopedTempDir work_dir; 92 base::ScopedTempDir work_dir;
92 EXPECT_TRUE(work_dir.CreateUniqueTempDir()); 93 EXPECT_TRUE(work_dir.CreateUniqueTempDir());
93 94
94 // Make up some path under the temp dir. 95 // Make up some path under the temp dir.
95 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two")); 96 base::FilePath parent_temp_dir(
97 work_dir.GetPath().Append(L"One").Append(L"Two"));
96 SelfCleaningTempDir temp_dir1; 98 SelfCleaningTempDir temp_dir1;
97 SelfCleaningTempDir temp_dir2; 99 SelfCleaningTempDir temp_dir2;
98 // First client is created. 100 // First client is created.
99 EXPECT_TRUE(temp_dir1.Initialize(parent_temp_dir, L"Three")); 101 EXPECT_TRUE(temp_dir1.Initialize(parent_temp_dir, L"Three"));
100 // Second client is created in the same space. 102 // Second client is created in the same space.
101 EXPECT_TRUE(temp_dir2.Initialize(parent_temp_dir, L"Three")); 103 EXPECT_TRUE(temp_dir2.Initialize(parent_temp_dir, L"Three"));
102 // Both clients are where they are expected. 104 // Both clients are where they are expected.
103 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir1.path()); 105 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir1.path());
104 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir2.path()); 106 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir2.path());
105 EXPECT_TRUE(base::DirectoryExists(temp_dir1.path())); 107 EXPECT_TRUE(base::DirectoryExists(temp_dir1.path()));
(...skipping 16 matching lines...) Expand all
122 } 124 }
123 125
124 // Test that all intermediate dirs are cleaned up if they're empty when the 126 // Test that all intermediate dirs are cleaned up if they're empty when the
125 // destructor is called. 127 // destructor is called.
126 TEST_F(SelfCleaningTempDirTest, RemoveUnusedOnDestroy) { 128 TEST_F(SelfCleaningTempDirTest, RemoveUnusedOnDestroy) {
127 // Make a directory in which we'll work. 129 // Make a directory in which we'll work.
128 base::ScopedTempDir work_dir; 130 base::ScopedTempDir work_dir;
129 EXPECT_TRUE(work_dir.CreateUniqueTempDir()); 131 EXPECT_TRUE(work_dir.CreateUniqueTempDir());
130 132
131 // Make up some path under the temp dir. 133 // Make up some path under the temp dir.
132 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two")); 134 base::FilePath parent_temp_dir(
135 work_dir.GetPath().Append(L"One").Append(L"Two"));
133 { 136 {
134 SelfCleaningTempDir temp_dir; 137 SelfCleaningTempDir temp_dir;
135 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three")); 138 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three"));
136 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path()); 139 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path());
137 EXPECT_TRUE(base::DirectoryExists(temp_dir.path())); 140 EXPECT_TRUE(base::DirectoryExists(temp_dir.path()));
138 } 141 }
139 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.Append(L"Three"))); 142 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.Append(L"Three")));
140 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir)); 143 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir));
141 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName())); 144 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName()));
142 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir.DirName().DirName())); 145 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir.DirName().DirName()));
143 EXPECT_TRUE(work_dir.Delete()); 146 EXPECT_TRUE(work_dir.Delete());
144 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName().DirName())); 147 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName().DirName()));
145 } 148 }
146 149
147 // Test that intermediate dirs are left behind if they're not empty when the 150 // Test that intermediate dirs are left behind if they're not empty when the
148 // destructor is called. 151 // destructor is called.
149 TEST_F(SelfCleaningTempDirTest, LeaveUsedOnDestroy) { 152 TEST_F(SelfCleaningTempDirTest, LeaveUsedOnDestroy) {
150 static const char kHiHon[] = "hi, hon"; 153 static const char kHiHon[] = "hi, hon";
151 154
152 // Make a directory in which we'll work. 155 // Make a directory in which we'll work.
153 base::ScopedTempDir work_dir; 156 base::ScopedTempDir work_dir;
154 EXPECT_TRUE(work_dir.CreateUniqueTempDir()); 157 EXPECT_TRUE(work_dir.CreateUniqueTempDir());
155 158
156 // Make up some path under the temp dir. 159 // Make up some path under the temp dir.
157 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two")); 160 base::FilePath parent_temp_dir(
161 work_dir.GetPath().Append(L"One").Append(L"Two"));
158 { 162 {
159 SelfCleaningTempDir temp_dir; 163 SelfCleaningTempDir temp_dir;
160 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three")); 164 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three"));
161 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path()); 165 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path());
162 EXPECT_TRUE(base::DirectoryExists(temp_dir.path())); 166 EXPECT_TRUE(base::DirectoryExists(temp_dir.path()));
163 // Drop a file somewhere. 167 // Drop a file somewhere.
164 EXPECT_EQ(static_cast<int>(arraysize(kHiHon) - 1), 168 EXPECT_EQ(static_cast<int>(arraysize(kHiHon) - 1),
165 base::WriteFile(parent_temp_dir.AppendASCII(GetRandomFilename()), 169 base::WriteFile(parent_temp_dir.AppendASCII(GetRandomFilename()),
166 kHiHon, arraysize(kHiHon) - 1)); 170 kHiHon, arraysize(kHiHon) - 1));
167 } 171 }
168 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.Append(L"Three"))); 172 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.Append(L"Three")));
169 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir)); 173 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir));
170 EXPECT_TRUE(work_dir.Delete()); 174 EXPECT_TRUE(work_dir.Delete());
171 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName().DirName())); 175 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName().DirName()));
172 } 176 }
173 177
174 } // namespace installer 178 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/util/move_tree_work_item_unittest.cc ('k') | chrome/installer/util/shell_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698