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

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

Issue 19052005: Move PathIsWritable, DirectoryExists, ContentsEqual, and TextContentsEqual to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | « chrome/installer/util/self_cleaning_temp_dir.cc ('k') | chrome/installer/util/shell_util.cc » ('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 <wincrypt.h> 6 #include <wincrypt.h>
7 7
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/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 TEST_F(SelfCleaningTempDirTest, RemoveUnusedOnDelete) { 67 TEST_F(SelfCleaningTempDirTest, RemoveUnusedOnDelete) {
68 // Make a directory in which we'll work. 68 // Make a directory in which we'll work.
69 base::ScopedTempDir work_dir; 69 base::ScopedTempDir work_dir;
70 EXPECT_TRUE(work_dir.CreateUniqueTempDir()); 70 EXPECT_TRUE(work_dir.CreateUniqueTempDir());
71 71
72 // Make up some path under the temp dir. 72 // Make up some path under the temp dir.
73 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two")); 73 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two"));
74 SelfCleaningTempDir temp_dir; 74 SelfCleaningTempDir temp_dir;
75 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three")); 75 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three"));
76 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path()); 76 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path());
77 EXPECT_TRUE(file_util::DirectoryExists(temp_dir.path())); 77 EXPECT_TRUE(base::DirectoryExists(temp_dir.path()));
78 EXPECT_TRUE(temp_dir.Delete()); 78 EXPECT_TRUE(temp_dir.Delete());
79 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir.Append(L"Three"))); 79 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.Append(L"Three")));
80 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir)); 80 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir));
81 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir.DirName())); 81 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName()));
82 EXPECT_TRUE(file_util::DirectoryExists(parent_temp_dir.DirName().DirName())); 82 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir.DirName().DirName()));
83 EXPECT_TRUE(work_dir.Delete()); 83 EXPECT_TRUE(work_dir.Delete());
84 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir.DirName().DirName())); 84 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName().DirName()));
85 } 85 }
86 86
87 // Test that two clients can work in the same area. 87 // Test that two clients can work in the same area.
88 TEST_F(SelfCleaningTempDirTest, TwoClients) { 88 TEST_F(SelfCleaningTempDirTest, TwoClients) {
89 // Make a directory in which we'll work. 89 // Make a directory in which we'll work.
90 base::ScopedTempDir work_dir; 90 base::ScopedTempDir work_dir;
91 EXPECT_TRUE(work_dir.CreateUniqueTempDir()); 91 EXPECT_TRUE(work_dir.CreateUniqueTempDir());
92 92
93 // Make up some path under the temp dir. 93 // Make up some path under the temp dir.
94 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two")); 94 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two"));
95 SelfCleaningTempDir temp_dir1; 95 SelfCleaningTempDir temp_dir1;
96 SelfCleaningTempDir temp_dir2; 96 SelfCleaningTempDir temp_dir2;
97 // First client is created. 97 // First client is created.
98 EXPECT_TRUE(temp_dir1.Initialize(parent_temp_dir, L"Three")); 98 EXPECT_TRUE(temp_dir1.Initialize(parent_temp_dir, L"Three"));
99 // Second client is created in the same space. 99 // Second client is created in the same space.
100 EXPECT_TRUE(temp_dir2.Initialize(parent_temp_dir, L"Three")); 100 EXPECT_TRUE(temp_dir2.Initialize(parent_temp_dir, L"Three"));
101 // Both clients are where they are expected. 101 // Both clients are where they are expected.
102 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir1.path()); 102 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir1.path());
103 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir2.path()); 103 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir2.path());
104 EXPECT_TRUE(file_util::DirectoryExists(temp_dir1.path())); 104 EXPECT_TRUE(base::DirectoryExists(temp_dir1.path()));
105 EXPECT_TRUE(file_util::DirectoryExists(temp_dir2.path())); 105 EXPECT_TRUE(base::DirectoryExists(temp_dir2.path()));
106 // Second client goes away. 106 // Second client goes away.
107 EXPECT_TRUE(temp_dir2.Delete()); 107 EXPECT_TRUE(temp_dir2.Delete());
108 // The first is now useless. 108 // The first is now useless.
109 EXPECT_FALSE(file_util::DirectoryExists(temp_dir1.path())); 109 EXPECT_FALSE(base::DirectoryExists(temp_dir1.path()));
110 // But the intermediate dirs are still present 110 // But the intermediate dirs are still present
111 EXPECT_TRUE(file_util::DirectoryExists(parent_temp_dir)); 111 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir));
112 // Now the first goes away. 112 // Now the first goes away.
113 EXPECT_TRUE(temp_dir1.Delete()); 113 EXPECT_TRUE(temp_dir1.Delete());
114 // And cleans up after itself. 114 // And cleans up after itself.
115 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir.Append(L"Three"))); 115 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.Append(L"Three")));
116 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir)); 116 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir));
117 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir.DirName())); 117 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName()));
118 EXPECT_TRUE(file_util::DirectoryExists(parent_temp_dir.DirName().DirName())); 118 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir.DirName().DirName()));
119 EXPECT_TRUE(work_dir.Delete()); 119 EXPECT_TRUE(work_dir.Delete());
120 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir.DirName().DirName())); 120 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName().DirName()));
121 } 121 }
122 122
123 // Test that all intermediate dirs are cleaned up if they're empty when the 123 // Test that all intermediate dirs are cleaned up if they're empty when the
124 // destructor is called. 124 // destructor is called.
125 TEST_F(SelfCleaningTempDirTest, RemoveUnusedOnDestroy) { 125 TEST_F(SelfCleaningTempDirTest, RemoveUnusedOnDestroy) {
126 // Make a directory in which we'll work. 126 // Make a directory in which we'll work.
127 base::ScopedTempDir work_dir; 127 base::ScopedTempDir work_dir;
128 EXPECT_TRUE(work_dir.CreateUniqueTempDir()); 128 EXPECT_TRUE(work_dir.CreateUniqueTempDir());
129 129
130 // Make up some path under the temp dir. 130 // Make up some path under the temp dir.
131 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two")); 131 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two"));
132 { 132 {
133 SelfCleaningTempDir temp_dir; 133 SelfCleaningTempDir temp_dir;
134 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three")); 134 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three"));
135 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path()); 135 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path());
136 EXPECT_TRUE(file_util::DirectoryExists(temp_dir.path())); 136 EXPECT_TRUE(base::DirectoryExists(temp_dir.path()));
137 } 137 }
138 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir.Append(L"Three"))); 138 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.Append(L"Three")));
139 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir)); 139 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir));
140 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir.DirName())); 140 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName()));
141 EXPECT_TRUE(file_util::DirectoryExists(parent_temp_dir.DirName().DirName())); 141 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir.DirName().DirName()));
142 EXPECT_TRUE(work_dir.Delete()); 142 EXPECT_TRUE(work_dir.Delete());
143 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir.DirName().DirName())); 143 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName().DirName()));
144 } 144 }
145 145
146 // Test that intermediate dirs are left behind if they're not empty when the 146 // Test that intermediate dirs are left behind if they're not empty when the
147 // destructor is called. 147 // destructor is called.
148 TEST_F(SelfCleaningTempDirTest, LeaveUsedOnDestroy) { 148 TEST_F(SelfCleaningTempDirTest, LeaveUsedOnDestroy) {
149 static const char kHiHon[] = "hi, hon"; 149 static const char kHiHon[] = "hi, hon";
150 150
151 // Make a directory in which we'll work. 151 // Make a directory in which we'll work.
152 base::ScopedTempDir work_dir; 152 base::ScopedTempDir work_dir;
153 EXPECT_TRUE(work_dir.CreateUniqueTempDir()); 153 EXPECT_TRUE(work_dir.CreateUniqueTempDir());
154 154
155 // Make up some path under the temp dir. 155 // Make up some path under the temp dir.
156 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two")); 156 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two"));
157 { 157 {
158 SelfCleaningTempDir temp_dir; 158 SelfCleaningTempDir temp_dir;
159 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three")); 159 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three"));
160 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path()); 160 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path());
161 EXPECT_TRUE(file_util::DirectoryExists(temp_dir.path())); 161 EXPECT_TRUE(base::DirectoryExists(temp_dir.path()));
162 // Drop a file somewhere. 162 // Drop a file somewhere.
163 EXPECT_EQ(arraysize(kHiHon) - 1, 163 EXPECT_EQ(arraysize(kHiHon) - 1,
164 file_util::WriteFile(parent_temp_dir.Append(GetRandomFilename()), 164 file_util::WriteFile(parent_temp_dir.Append(GetRandomFilename()),
165 kHiHon, arraysize(kHiHon) - 1)); 165 kHiHon, arraysize(kHiHon) - 1));
166 } 166 }
167 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir.Append(L"Three"))); 167 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.Append(L"Three")));
168 EXPECT_TRUE(file_util::DirectoryExists(parent_temp_dir)); 168 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir));
169 EXPECT_TRUE(work_dir.Delete()); 169 EXPECT_TRUE(work_dir.Delete());
170 EXPECT_FALSE(file_util::DirectoryExists(parent_temp_dir.DirName().DirName())); 170 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName().DirName()));
171 } 171 }
172 172
173 } // namespace installer 173 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/util/self_cleaning_temp_dir.cc ('k') | chrome/installer/util/shell_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698