OLD | NEW |
---|---|
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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 obfuscated_file_system_file_util_ = | 135 obfuscated_file_system_file_util_ = |
136 new ObfuscatedFileSystemFileUtil(data_dir_.path(), | 136 new ObfuscatedFileSystemFileUtil(data_dir_.path(), |
137 new FileSystemFileUtil()); | 137 new FileSystemFileUtil()); |
138 test_helper_.SetUp(data_dir_.path(), | 138 test_helper_.SetUp(data_dir_.path(), |
139 false, // incognito | 139 false, // incognito |
140 false, // unlimited quota | 140 false, // unlimited quota |
141 NULL, // quota::QuotaManagerProxy | 141 NULL, // quota::QuotaManagerProxy |
142 obfuscated_file_system_file_util_.get()); | 142 obfuscated_file_system_file_util_.get()); |
143 } | 143 } |
144 | 144 |
145 FileSystemOperationContext* NewContext() { | 145 FileSystemOperationContext* NewContext(FileSystemTestOriginHelper* helper) { |
146 FileSystemOperationContext* context = test_helper_.NewOperationContext(); | 146 FileSystemOperationContext* context; |
147 if (helper) | |
148 context = helper->NewOperationContext(); | |
149 else | |
150 context = test_helper_.NewOperationContext(); | |
151 context->set_allowed_bytes_growth(1024); // Big enough for all tests. | |
147 return context; | 152 return context; |
148 } | 153 } |
149 | 154 |
155 // This can only be used after SetUp has run and created data_dir_ and | |
156 // obfuscated_file_system_file_util_. | |
157 // Use this for tests which need to run in multiple origins; we need a test | |
158 // helper per origin. | |
159 FileSystemTestOriginHelper* NewHelper( | |
160 const GURL& origin, fileapi::FileSystemType type) { | |
161 FileSystemTestOriginHelper* helper = | |
162 new FileSystemTestOriginHelper(origin, type); | |
163 helper->SetUp(data_dir_.path(), | |
164 false, // incognito | |
165 false, // unlimited quota | |
166 NULL, // quota::QuotaManagerProxy | |
167 obfuscated_file_system_file_util_.get()); | |
168 return helper; | |
169 } | |
170 | |
150 ObfuscatedFileSystemFileUtil* ofsfu() { | 171 ObfuscatedFileSystemFileUtil* ofsfu() { |
151 return obfuscated_file_system_file_util_.get(); | 172 return obfuscated_file_system_file_util_.get(); |
152 } | 173 } |
153 | 174 |
154 const FilePath& test_directory() const { | 175 const FilePath& test_directory() const { |
155 return data_dir_.path(); | 176 return data_dir_.path(); |
156 } | 177 } |
157 | 178 |
158 const GURL& origin_url() const { | 179 const GURL& origin_url() const { |
159 return origin_; | 180 return origin_; |
160 } | 181 } |
161 | 182 |
162 fileapi::FileSystemType type() const { | 183 fileapi::FileSystemType type() const { |
163 return type_; | 184 return type_; |
164 } | 185 } |
165 | 186 |
166 void CheckFileAndCloseHandle( | 187 void CheckFileAndCloseHandle( |
167 const FilePath& virtual_path, PlatformFile file_handle) { | 188 const FilePath& virtual_path, PlatformFile file_handle) { |
168 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 189 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
169 FilePath local_path; | 190 FilePath local_path; |
170 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( | 191 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( |
171 context.get(), virtual_path, &local_path)); | 192 context.get(), virtual_path, &local_path)); |
172 | 193 |
173 base::PlatformFileInfo file_info0; | 194 base::PlatformFileInfo file_info0; |
174 FilePath data_path; | 195 FilePath data_path; |
175 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 196 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
176 context.get(), virtual_path, &file_info0, &data_path)); | 197 context.get(), virtual_path, &file_info0, &data_path)); |
177 EXPECT_EQ(data_path, local_path); | 198 EXPECT_EQ(data_path, local_path); |
178 EXPECT_TRUE(FileExists(data_path)); | 199 EXPECT_TRUE(FileExists(data_path)); |
(...skipping 12 matching lines...) Expand all Loading... | |
191 &error); | 212 &error); |
192 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); | 213 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); |
193 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 214 ASSERT_EQ(base::PLATFORM_FILE_OK, error); |
194 EXPECT_FALSE(created); | 215 EXPECT_FALSE(created); |
195 } | 216 } |
196 ASSERT_EQ(length, base::WritePlatformFile(file_handle, 0, data, length)); | 217 ASSERT_EQ(length, base::WritePlatformFile(file_handle, 0, data, length)); |
197 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 218 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); |
198 | 219 |
199 base::PlatformFileInfo file_info1; | 220 base::PlatformFileInfo file_info1; |
200 EXPECT_EQ(length, GetSize(data_path)); | 221 EXPECT_EQ(length, GetSize(data_path)); |
201 context.reset(NewContext()); | 222 context.reset(NewContext(NULL)); |
202 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 223 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
203 context.get(), virtual_path, &file_info1, &data_path)); | 224 context.get(), virtual_path, &file_info1, &data_path)); |
204 EXPECT_EQ(data_path, local_path); | 225 EXPECT_EQ(data_path, local_path); |
205 | 226 |
206 EXPECT_FALSE(file_info0.is_directory); | 227 EXPECT_FALSE(file_info0.is_directory); |
207 EXPECT_FALSE(file_info1.is_directory); | 228 EXPECT_FALSE(file_info1.is_directory); |
208 EXPECT_FALSE(file_info0.is_symbolic_link); | 229 EXPECT_FALSE(file_info0.is_symbolic_link); |
209 EXPECT_FALSE(file_info1.is_symbolic_link); | 230 EXPECT_FALSE(file_info1.is_symbolic_link); |
210 EXPECT_EQ(0, file_info0.size); | 231 EXPECT_EQ(0, file_info0.size); |
211 EXPECT_EQ(length, file_info1.size); | 232 EXPECT_EQ(length, file_info1.size); |
212 EXPECT_LE(file_info0.last_modified, file_info1.last_modified); | 233 EXPECT_LE(file_info0.last_modified, file_info1.last_modified); |
213 | 234 |
214 context.reset(NewContext()); | 235 context.reset(NewContext(NULL)); |
215 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( | 236 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( |
216 context.get(), virtual_path, length * 2)); | 237 context.get(), virtual_path, length * 2)); |
217 EXPECT_EQ(length * 2, GetSize(data_path)); | 238 EXPECT_EQ(length * 2, GetSize(data_path)); |
218 | 239 |
219 context.reset(NewContext()); | 240 context.reset(NewContext(NULL)); |
220 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( | 241 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( |
221 context.get(), virtual_path, 1)); | 242 context.get(), virtual_path, 1)); |
222 EXPECT_EQ(1, GetSize(data_path)); | 243 EXPECT_EQ(1, GetSize(data_path)); |
223 } | 244 } |
224 | 245 |
225 void ValidateTestDirectory( | 246 void ValidateTestDirectory( |
226 const FilePath& root_path, | 247 const FilePath& root_path, |
227 const std::set<FilePath::StringType>& files, | 248 const std::set<FilePath::StringType>& files, |
228 const std::set<FilePath::StringType>& directories) { | 249 const std::set<FilePath::StringType>& directories) { |
229 scoped_ptr<FileSystemOperationContext> context; | 250 scoped_ptr<FileSystemOperationContext> context; |
230 std::set<FilePath::StringType>::const_iterator iter; | 251 std::set<FilePath::StringType>::const_iterator iter; |
231 for (iter = files.begin(); iter != files.end(); ++iter) { | 252 for (iter = files.begin(); iter != files.end(); ++iter) { |
232 bool created = true; | 253 bool created = true; |
233 context.reset(NewContext()); | 254 context.reset(NewContext(NULL)); |
234 ASSERT_EQ(base::PLATFORM_FILE_OK, | 255 ASSERT_EQ(base::PLATFORM_FILE_OK, |
235 ofsfu()->EnsureFileExists( | 256 ofsfu()->EnsureFileExists( |
236 context.get(), root_path.Append(*iter), | 257 context.get(), root_path.Append(*iter), |
237 &created)); | 258 &created)); |
238 ASSERT_FALSE(created); | 259 ASSERT_FALSE(created); |
239 } | 260 } |
240 for (iter = directories.begin(); iter != directories.end(); ++iter) { | 261 for (iter = directories.begin(); iter != directories.end(); ++iter) { |
241 context.reset(NewContext()); | 262 context.reset(NewContext(NULL)); |
242 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), | 263 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), |
243 root_path.Append(*iter))); | 264 root_path.Append(*iter))); |
244 } | 265 } |
245 } | 266 } |
246 | 267 |
247 void FillTestDirectory( | 268 void FillTestDirectory( |
248 const FilePath& root_path, | 269 const FilePath& root_path, |
249 std::set<FilePath::StringType>* files, | 270 std::set<FilePath::StringType>* files, |
250 std::set<FilePath::StringType>* directories) { | 271 std::set<FilePath::StringType>* directories) { |
251 scoped_ptr<FileSystemOperationContext> context; | 272 scoped_ptr<FileSystemOperationContext> context; |
252 context.reset(NewContext()); | 273 context.reset(NewContext(NULL)); |
253 std::vector<base::FileUtilProxy::Entry> entries; | 274 std::vector<base::FileUtilProxy::Entry> entries; |
254 EXPECT_EQ(base::PLATFORM_FILE_OK, | 275 EXPECT_EQ(base::PLATFORM_FILE_OK, |
255 ofsfu()->ReadDirectory(context.get(), root_path, &entries)); | 276 ofsfu()->ReadDirectory(context.get(), root_path, &entries)); |
256 EXPECT_EQ(0UL, entries.size()); | 277 EXPECT_EQ(0UL, entries.size()); |
257 | 278 |
258 files->clear(); | 279 files->clear(); |
259 files->insert(FILE_PATH_LITERAL("first")); | 280 files->insert(FILE_PATH_LITERAL("first")); |
260 files->insert(FILE_PATH_LITERAL("second")); | 281 files->insert(FILE_PATH_LITERAL("second")); |
261 files->insert(FILE_PATH_LITERAL("third")); | 282 files->insert(FILE_PATH_LITERAL("third")); |
262 directories->clear(); | 283 directories->clear(); |
263 directories->insert(FILE_PATH_LITERAL("fourth")); | 284 directories->insert(FILE_PATH_LITERAL("fourth")); |
264 directories->insert(FILE_PATH_LITERAL("fifth")); | 285 directories->insert(FILE_PATH_LITERAL("fifth")); |
265 directories->insert(FILE_PATH_LITERAL("sixth")); | 286 directories->insert(FILE_PATH_LITERAL("sixth")); |
266 std::set<FilePath::StringType>::iterator iter; | 287 std::set<FilePath::StringType>::iterator iter; |
267 for (iter = files->begin(); iter != files->end(); ++iter) { | 288 for (iter = files->begin(); iter != files->end(); ++iter) { |
268 bool created = false; | 289 bool created = false; |
269 context.reset(NewContext()); | 290 context.reset(NewContext(NULL)); |
270 ASSERT_EQ(base::PLATFORM_FILE_OK, | 291 ASSERT_EQ(base::PLATFORM_FILE_OK, |
271 ofsfu()->EnsureFileExists( | 292 ofsfu()->EnsureFileExists( |
272 context.get(), root_path.Append(*iter), &created)); | 293 context.get(), root_path.Append(*iter), &created)); |
273 ASSERT_TRUE(created); | 294 ASSERT_TRUE(created); |
274 } | 295 } |
275 for (iter = directories->begin(); iter != directories->end(); ++iter) { | 296 for (iter = directories->begin(); iter != directories->end(); ++iter) { |
276 bool exclusive = true; | 297 bool exclusive = true; |
277 bool recursive = false; | 298 bool recursive = false; |
278 context.reset(NewContext()); | 299 context.reset(NewContext(NULL)); |
279 EXPECT_EQ(base::PLATFORM_FILE_OK, | 300 EXPECT_EQ(base::PLATFORM_FILE_OK, |
280 ofsfu()->CreateDirectory( | 301 ofsfu()->CreateDirectory( |
281 context.get(), root_path.Append(*iter), exclusive, recursive)); | 302 context.get(), root_path.Append(*iter), exclusive, recursive)); |
282 } | 303 } |
283 ValidateTestDirectory(root_path, *files, *directories); | 304 ValidateTestDirectory(root_path, *files, *directories); |
284 } | 305 } |
285 | 306 |
286 void TestReadDirectoryHelper(const FilePath& root_path) { | 307 void TestReadDirectoryHelper(const FilePath& root_path) { |
287 std::set<FilePath::StringType> files; | 308 std::set<FilePath::StringType> files; |
288 std::set<FilePath::StringType> directories; | 309 std::set<FilePath::StringType> directories; |
289 FillTestDirectory(root_path, &files, &directories); | 310 FillTestDirectory(root_path, &files, &directories); |
290 | 311 |
291 scoped_ptr<FileSystemOperationContext> context; | 312 scoped_ptr<FileSystemOperationContext> context; |
292 std::vector<base::FileUtilProxy::Entry> entries; | 313 std::vector<base::FileUtilProxy::Entry> entries; |
293 context.reset(NewContext()); | 314 context.reset(NewContext(NULL)); |
294 EXPECT_EQ(base::PLATFORM_FILE_OK, | 315 EXPECT_EQ(base::PLATFORM_FILE_OK, |
295 ofsfu()->ReadDirectory(context.get(), root_path, &entries)); | 316 ofsfu()->ReadDirectory(context.get(), root_path, &entries)); |
296 std::vector<base::FileUtilProxy::Entry>::iterator entry_iter; | 317 std::vector<base::FileUtilProxy::Entry>::iterator entry_iter; |
297 EXPECT_EQ(files.size() + directories.size(), entries.size()); | 318 EXPECT_EQ(files.size() + directories.size(), entries.size()); |
298 for (entry_iter = entries.begin(); entry_iter != entries.end(); | 319 for (entry_iter = entries.begin(); entry_iter != entries.end(); |
299 ++entry_iter) { | 320 ++entry_iter) { |
300 const base::FileUtilProxy::Entry& entry = *entry_iter; | 321 const base::FileUtilProxy::Entry& entry = *entry_iter; |
301 std::set<FilePath::StringType>::iterator iter = files.find(entry.name); | 322 std::set<FilePath::StringType>::iterator iter = files.find(entry.name); |
302 if (iter != files.end()) { | 323 if (iter != files.end()) { |
303 EXPECT_FALSE(entry.is_directory); | 324 EXPECT_FALSE(entry.is_directory); |
304 files.erase(iter); | 325 files.erase(iter); |
305 continue; | 326 continue; |
306 } | 327 } |
307 iter = directories.find(entry.name); | 328 iter = directories.find(entry.name); |
308 EXPECT_FALSE(directories.end() == iter); | 329 EXPECT_FALSE(directories.end() == iter); |
309 EXPECT_TRUE(entry.is_directory); | 330 EXPECT_TRUE(entry.is_directory); |
310 directories.erase(iter); | 331 directories.erase(iter); |
311 } | 332 } |
312 } | 333 } |
313 | 334 |
314 void TestTouchHelper(const FilePath& path) { | 335 void TestTouchHelper(const FilePath& path) { |
315 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. | 336 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. |
316 base::Time last_modified_time = base::Time::Now(); | 337 base::Time last_modified_time = base::Time::Now(); |
317 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 338 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
318 EXPECT_EQ(base::PLATFORM_FILE_OK, | 339 EXPECT_EQ(base::PLATFORM_FILE_OK, |
319 ofsfu()->Touch( | 340 ofsfu()->Touch( |
320 context.get(), path, last_access_time, last_modified_time)); | 341 context.get(), path, last_access_time, last_modified_time)); |
321 FilePath local_path; | 342 FilePath local_path; |
322 base::PlatformFileInfo file_info; | 343 base::PlatformFileInfo file_info; |
323 context.reset(NewContext()); | 344 context.reset(NewContext(NULL)); |
324 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 345 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
325 context.get(), path, &file_info, &local_path)); | 346 context.get(), path, &file_info, &local_path)); |
326 // We compare as time_t here to lower our resolution, to avoid false | 347 // We compare as time_t here to lower our resolution, to avoid false |
327 // negatives caused by conversion to the local filesystem's native | 348 // negatives caused by conversion to the local filesystem's native |
328 // representation and back. | 349 // representation and back. |
329 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); | 350 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); |
330 | 351 |
331 context.reset(NewContext()); | 352 context.reset(NewContext(NULL)); |
332 last_modified_time += base::TimeDelta::FromHours(1); | 353 last_modified_time += base::TimeDelta::FromHours(1); |
333 EXPECT_EQ(base::PLATFORM_FILE_OK, | 354 EXPECT_EQ(base::PLATFORM_FILE_OK, |
334 ofsfu()->Touch( | 355 ofsfu()->Touch( |
335 context.get(), path, last_access_time, last_modified_time)); | 356 context.get(), path, last_access_time, last_modified_time)); |
336 context.reset(NewContext()); | 357 context.reset(NewContext(NULL)); |
337 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 358 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
338 context.get(), path, &file_info, &local_path)); | 359 context.get(), path, &file_info, &local_path)); |
339 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); | 360 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); |
340 } | 361 } |
341 | 362 |
342 void TestCopyInForeignFileHelper(bool overwrite) { | 363 void TestCopyInForeignFileHelper(bool overwrite) { |
343 ScopedTempDir source_dir; | 364 ScopedTempDir source_dir; |
344 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); | 365 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); |
345 FilePath root_path = source_dir.path(); | 366 FilePath root_path = source_dir.path(); |
346 FilePath src_path = root_path.AppendASCII("file_name"); | 367 FilePath src_path = root_path.AppendASCII("file_name"); |
347 FilePath dest_path(FILE_PATH_LITERAL("new file")); | 368 FilePath dest_path(FILE_PATH_LITERAL("new file")); |
348 int64 src_file_length = 87; | 369 int64 src_file_length = 87; |
349 | 370 |
350 base::PlatformFileError error_code; | 371 base::PlatformFileError error_code; |
351 bool created = false; | 372 bool created = false; |
352 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; | 373 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; |
353 base::PlatformFile file_handle = | 374 base::PlatformFile file_handle = |
354 base::CreatePlatformFile( | 375 base::CreatePlatformFile( |
355 src_path, file_flags, &created, &error_code); | 376 src_path, file_flags, &created, &error_code); |
356 EXPECT_TRUE(created); | 377 EXPECT_TRUE(created); |
357 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); | 378 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); |
358 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); | 379 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); |
359 ASSERT_TRUE(base::TruncatePlatformFile(file_handle, src_file_length)); | 380 ASSERT_TRUE(base::TruncatePlatformFile(file_handle, src_file_length)); |
360 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 381 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); |
361 | 382 |
362 scoped_ptr<FileSystemOperationContext> context; | 383 scoped_ptr<FileSystemOperationContext> context; |
363 | 384 |
364 if (overwrite) { | 385 if (overwrite) { |
365 context.reset(NewContext()); | 386 context.reset(NewContext(NULL)); |
366 EXPECT_EQ(base::PLATFORM_FILE_OK, | 387 EXPECT_EQ(base::PLATFORM_FILE_OK, |
367 ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); | 388 ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); |
368 EXPECT_TRUE(created); | 389 EXPECT_TRUE(created); |
369 } | 390 } |
370 | 391 |
371 context.reset(NewContext()); | 392 context.reset(NewContext(NULL)); |
372 EXPECT_EQ(base::PLATFORM_FILE_OK, | 393 EXPECT_EQ(base::PLATFORM_FILE_OK, |
373 ofsfu()->CopyInForeignFile(context.get(), src_path, dest_path)); | 394 ofsfu()->CopyInForeignFile(context.get(), src_path, dest_path)); |
374 context.reset(NewContext()); | 395 context.reset(NewContext(NULL)); |
375 EXPECT_TRUE(ofsfu()->PathExists(context.get(), dest_path)); | 396 EXPECT_TRUE(ofsfu()->PathExists(context.get(), dest_path)); |
376 context.reset(NewContext()); | 397 context.reset(NewContext(NULL)); |
377 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 398 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
378 context.reset(NewContext()); | 399 context.reset(NewContext(NULL)); |
379 base::PlatformFileInfo file_info; | 400 base::PlatformFileInfo file_info; |
380 FilePath data_path; | 401 FilePath data_path; |
381 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 402 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
382 context.get(), dest_path, &file_info, &data_path)); | 403 context.get(), dest_path, &file_info, &data_path)); |
383 EXPECT_NE(data_path, src_path); | 404 EXPECT_NE(data_path, src_path); |
384 EXPECT_TRUE(FileExists(data_path)); | 405 EXPECT_TRUE(FileExists(data_path)); |
385 EXPECT_EQ(src_file_length, GetSize(data_path)); | 406 EXPECT_EQ(src_file_length, GetSize(data_path)); |
386 | 407 |
387 EXPECT_EQ(base::PLATFORM_FILE_OK, | 408 EXPECT_EQ(base::PLATFORM_FILE_OK, |
388 ofsfu()->DeleteFile(context.get(), dest_path)); | 409 ofsfu()->DeleteFile(context.get(), dest_path)); |
389 } | 410 } |
390 | 411 |
391 private: | 412 private: |
392 ScopedTempDir data_dir_; | 413 ScopedTempDir data_dir_; |
393 scoped_refptr<ObfuscatedFileSystemFileUtil> obfuscated_file_system_file_util_; | 414 scoped_refptr<ObfuscatedFileSystemFileUtil> obfuscated_file_system_file_util_; |
394 GURL origin_; | 415 GURL origin_; |
395 fileapi::FileSystemType type_; | 416 fileapi::FileSystemType type_; |
396 FileSystemTestOriginHelper test_helper_; | 417 FileSystemTestOriginHelper test_helper_; |
397 | 418 |
398 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtilTest); | 419 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtilTest); |
399 }; | 420 }; |
400 | 421 |
401 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) { | 422 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) { |
Dai Mikurube (NOT FULLTIME)
2011/08/12 05:17:54
We should have a quota testing code for every oper
ericu
2011/08/16 21:16:31
Done.
| |
402 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; | 423 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; |
403 bool created; | 424 bool created; |
404 FilePath path = UTF8ToFilePath("fake/file"); | 425 FilePath path = UTF8ToFilePath("fake/file"); |
405 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 426 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
406 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; | 427 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; |
407 | 428 |
408 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 429 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
409 ofsfu()->CreateOrOpen( | 430 ofsfu()->CreateOrOpen( |
410 context.get(), path, file_flags, &file_handle, | 431 context.get(), path, file_flags, &file_handle, |
411 &created)); | 432 &created)); |
412 | 433 |
413 context.reset(NewContext()); | 434 context.reset(NewContext(NULL)); |
414 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 435 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
415 ofsfu()->DeleteFile(context.get(), path)); | 436 ofsfu()->DeleteFile(context.get(), path)); |
416 | 437 |
417 path = UTF8ToFilePath("test file"); | 438 path = UTF8ToFilePath("test file"); |
418 | 439 |
419 context.reset(NewContext()); | 440 context.reset(NewContext(NULL)); |
420 ASSERT_EQ(base::PLATFORM_FILE_OK, | 441 ASSERT_EQ(base::PLATFORM_FILE_OK, |
421 ofsfu()->CreateOrOpen( | 442 ofsfu()->CreateOrOpen( |
422 context.get(), path, file_flags, &file_handle, &created)); | 443 context.get(), path, file_flags, &file_handle, &created)); |
423 ASSERT_TRUE(created); | 444 ASSERT_TRUE(created); |
424 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); | 445 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); |
425 | 446 |
426 CheckFileAndCloseHandle(path, file_handle); | 447 CheckFileAndCloseHandle(path, file_handle); |
427 | 448 |
428 context.reset(NewContext()); | 449 context.reset(NewContext(NULL)); |
429 FilePath local_path; | 450 FilePath local_path; |
430 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( | 451 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( |
431 context.get(), path, &local_path)); | 452 context.get(), path, &local_path)); |
432 EXPECT_TRUE(file_util::PathExists(local_path)); | 453 EXPECT_TRUE(file_util::PathExists(local_path)); |
433 | 454 |
434 context.reset(NewContext()); | 455 context.reset(NewContext(NULL)); |
435 EXPECT_EQ(base::PLATFORM_FILE_OK, | 456 EXPECT_EQ(base::PLATFORM_FILE_OK, |
436 ofsfu()->DeleteFile(context.get(), path)); | 457 ofsfu()->DeleteFile(context.get(), path)); |
437 EXPECT_FALSE(file_util::PathExists(local_path)); | 458 EXPECT_FALSE(file_util::PathExists(local_path)); |
438 | 459 |
439 context.reset(NewContext()); | 460 context.reset(NewContext(NULL)); |
440 bool exclusive = true; | 461 bool exclusive = true; |
441 bool recursive = true; | 462 bool recursive = true; |
442 FilePath directory_path = UTF8ToFilePath("series/of/directories"); | 463 FilePath directory_path = UTF8ToFilePath("series/of/directories"); |
443 path = directory_path.AppendASCII("file name"); | 464 path = directory_path.AppendASCII("file name"); |
444 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 465 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
445 context.get(), directory_path, exclusive, recursive)); | 466 context.get(), directory_path, exclusive, recursive)); |
446 | 467 |
447 context.reset(NewContext()); | 468 context.reset(NewContext(NULL)); |
448 file_handle = base::kInvalidPlatformFileValue; | 469 file_handle = base::kInvalidPlatformFileValue; |
449 ASSERT_EQ(base::PLATFORM_FILE_OK, | 470 ASSERT_EQ(base::PLATFORM_FILE_OK, |
450 ofsfu()->CreateOrOpen( | 471 ofsfu()->CreateOrOpen( |
451 context.get(), path, file_flags, &file_handle, &created)); | 472 context.get(), path, file_flags, &file_handle, &created)); |
452 ASSERT_TRUE(created); | 473 ASSERT_TRUE(created); |
453 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); | 474 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); |
454 | 475 |
455 CheckFileAndCloseHandle(path, file_handle); | 476 CheckFileAndCloseHandle(path, file_handle); |
456 | 477 |
457 context.reset(NewContext()); | 478 context.reset(NewContext(NULL)); |
458 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( | 479 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( |
459 context.get(), path, &local_path)); | 480 context.get(), path, &local_path)); |
460 EXPECT_TRUE(file_util::PathExists(local_path)); | 481 EXPECT_TRUE(file_util::PathExists(local_path)); |
461 | 482 |
462 context.reset(NewContext()); | 483 context.reset(NewContext(NULL)); |
463 EXPECT_EQ(base::PLATFORM_FILE_OK, | 484 EXPECT_EQ(base::PLATFORM_FILE_OK, |
464 ofsfu()->DeleteFile(context.get(), path)); | 485 ofsfu()->DeleteFile(context.get(), path)); |
465 EXPECT_FALSE(file_util::PathExists(local_path)); | 486 EXPECT_FALSE(file_util::PathExists(local_path)); |
466 } | 487 } |
467 | 488 |
468 TEST_F(ObfuscatedFileSystemFileUtilTest, TestTruncate) { | 489 TEST_F(ObfuscatedFileSystemFileUtilTest, TestTruncate) { |
469 bool created = false; | 490 bool created = false; |
470 FilePath path = UTF8ToFilePath("file"); | 491 FilePath path = UTF8ToFilePath("file"); |
471 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 492 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
472 | 493 |
473 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 494 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
474 ofsfu()->Truncate(context.get(), path, 4)); | 495 ofsfu()->Truncate(context.get(), path, 4)); |
475 | 496 |
476 context.reset(NewContext()); | 497 context.reset(NewContext(NULL)); |
477 ASSERT_EQ(base::PLATFORM_FILE_OK, | 498 ASSERT_EQ(base::PLATFORM_FILE_OK, |
478 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 499 ofsfu()->EnsureFileExists(context.get(), path, &created)); |
479 ASSERT_TRUE(created); | 500 ASSERT_TRUE(created); |
480 | 501 |
481 context.reset(NewContext()); | 502 context.reset(NewContext(NULL)); |
482 FilePath local_path; | 503 FilePath local_path; |
483 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( | 504 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( |
484 context.get(), path, &local_path)); | 505 context.get(), path, &local_path)); |
485 EXPECT_EQ(0, GetSize(local_path)); | 506 EXPECT_EQ(0, GetSize(local_path)); |
486 | 507 |
487 context.reset(NewContext()); | 508 context.reset(NewContext(NULL)); |
488 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( | 509 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( |
489 context.get(), path, 10)); | 510 context.get(), path, 10)); |
490 EXPECT_EQ(10, GetSize(local_path)); | 511 EXPECT_EQ(10, GetSize(local_path)); |
491 | 512 |
492 context.reset(NewContext()); | 513 context.reset(NewContext(NULL)); |
493 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( | 514 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( |
494 context.get(), path, 1)); | 515 context.get(), path, 1)); |
495 EXPECT_EQ(1, GetSize(local_path)); | 516 EXPECT_EQ(1, GetSize(local_path)); |
496 | 517 |
497 context.reset(NewContext()); | 518 context.reset(NewContext(NULL)); |
498 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 519 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
499 context.reset(NewContext()); | 520 context.reset(NewContext(NULL)); |
500 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 521 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
501 } | 522 } |
502 | 523 |
503 TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnsureFileExists) { | 524 TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnsureFileExists) { |
504 FilePath path = UTF8ToFilePath("fake/file"); | 525 FilePath path = UTF8ToFilePath("fake/file"); |
505 bool created = false; | 526 bool created = false; |
506 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 527 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
507 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 528 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
508 ofsfu()->EnsureFileExists( | 529 ofsfu()->EnsureFileExists( |
509 context.get(), path, &created)); | 530 context.get(), path, &created)); |
510 | 531 |
511 context.reset(NewContext()); | 532 context.reset(NewContext(NULL)); |
512 path = UTF8ToFilePath("test file"); | 533 path = UTF8ToFilePath("test file"); |
513 created = false; | 534 created = false; |
514 ASSERT_EQ(base::PLATFORM_FILE_OK, | 535 ASSERT_EQ(base::PLATFORM_FILE_OK, |
515 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 536 ofsfu()->EnsureFileExists(context.get(), path, &created)); |
516 ASSERT_TRUE(created); | 537 ASSERT_TRUE(created); |
517 | 538 |
518 CheckFileAndCloseHandle(path, base::kInvalidPlatformFileValue); | 539 CheckFileAndCloseHandle(path, base::kInvalidPlatformFileValue); |
519 | 540 |
520 context.reset(NewContext()); | 541 context.reset(NewContext(NULL)); |
521 ASSERT_EQ(base::PLATFORM_FILE_OK, | 542 ASSERT_EQ(base::PLATFORM_FILE_OK, |
522 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 543 ofsfu()->EnsureFileExists(context.get(), path, &created)); |
523 ASSERT_FALSE(created); | 544 ASSERT_FALSE(created); |
524 | 545 |
525 // Also test in a subdirectory. | 546 // Also test in a subdirectory. |
526 path = UTF8ToFilePath("path/to/file.txt"); | 547 path = UTF8ToFilePath("path/to/file.txt"); |
527 context.reset(NewContext()); | 548 context.reset(NewContext(NULL)); |
528 bool exclusive = true; | 549 bool exclusive = true; |
529 bool recursive = true; | 550 bool recursive = true; |
530 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 551 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
531 context.get(), path.DirName(), exclusive, recursive)); | 552 context.get(), path.DirName(), exclusive, recursive)); |
532 | 553 |
533 context.reset(NewContext()); | 554 context.reset(NewContext(NULL)); |
534 ASSERT_EQ(base::PLATFORM_FILE_OK, | 555 ASSERT_EQ(base::PLATFORM_FILE_OK, |
535 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 556 ofsfu()->EnsureFileExists(context.get(), path, &created)); |
536 ASSERT_TRUE(created); | 557 ASSERT_TRUE(created); |
537 context.reset(NewContext()); | 558 context.reset(NewContext(NULL)); |
538 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 559 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
539 context.reset(NewContext()); | 560 context.reset(NewContext(NULL)); |
540 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 561 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
541 } | 562 } |
542 | 563 |
543 TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { | 564 TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { |
544 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 565 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
545 | 566 |
546 bool exclusive = false; | 567 bool exclusive = false; |
547 bool recursive = false; | 568 bool recursive = false; |
548 FilePath path = UTF8ToFilePath("foo/bar"); | 569 FilePath path = UTF8ToFilePath("foo/bar"); |
549 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->CreateDirectory( | 570 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->CreateDirectory( |
550 context.get(), path, exclusive, recursive)); | 571 context.get(), path, exclusive, recursive)); |
551 | 572 |
552 context.reset(NewContext()); | 573 context.reset(NewContext(NULL)); |
553 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 574 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
554 ofsfu()->DeleteSingleDirectory(context.get(), path)); | 575 ofsfu()->DeleteSingleDirectory(context.get(), path)); |
555 | 576 |
556 FilePath root = UTF8ToFilePath(""); | 577 FilePath root = UTF8ToFilePath(""); |
557 context.reset(NewContext()); | 578 context.reset(NewContext(NULL)); |
558 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 579 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
559 context.reset(NewContext()); | 580 context.reset(NewContext(NULL)); |
560 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); | 581 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); |
561 context.reset(NewContext()); | 582 context.reset(NewContext(NULL)); |
562 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), root)); | 583 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), root)); |
563 | 584 |
564 context.reset(NewContext()); | 585 context.reset(NewContext(NULL)); |
565 exclusive = false; | 586 exclusive = false; |
566 recursive = true; | 587 recursive = true; |
567 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 588 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
568 context.get(), path, exclusive, recursive)); | 589 context.get(), path, exclusive, recursive)); |
569 | 590 |
570 context.reset(NewContext()); | 591 context.reset(NewContext(NULL)); |
571 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); | 592 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); |
572 context.reset(NewContext()); | 593 context.reset(NewContext(NULL)); |
573 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 594 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
574 context.reset(NewContext()); | 595 context.reset(NewContext(NULL)); |
575 EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), root)); | 596 EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), root)); |
576 context.reset(NewContext()); | 597 context.reset(NewContext(NULL)); |
577 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path.DirName())); | 598 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path.DirName())); |
578 context.reset(NewContext()); | 599 context.reset(NewContext(NULL)); |
579 EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), path.DirName())); | 600 EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), path.DirName())); |
580 | 601 |
581 // Can't remove a non-empty directory. | 602 // Can't remove a non-empty directory. |
582 context.reset(NewContext()); | 603 context.reset(NewContext(NULL)); |
583 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, | 604 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, |
584 ofsfu()->DeleteSingleDirectory(context.get(), path.DirName())); | 605 ofsfu()->DeleteSingleDirectory(context.get(), path.DirName())); |
585 | 606 |
586 base::PlatformFileInfo file_info; | 607 base::PlatformFileInfo file_info; |
587 FilePath local_path; | 608 FilePath local_path; |
588 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 609 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
589 context.get(), path, &file_info, &local_path)); | 610 context.get(), path, &file_info, &local_path)); |
590 EXPECT_TRUE(local_path.empty()); | 611 EXPECT_TRUE(local_path.empty()); |
591 EXPECT_TRUE(file_info.is_directory); | 612 EXPECT_TRUE(file_info.is_directory); |
592 EXPECT_FALSE(file_info.is_symbolic_link); | 613 EXPECT_FALSE(file_info.is_symbolic_link); |
593 | 614 |
594 // Same create again should succeed, since exclusive is false. | 615 // Same create again should succeed, since exclusive is false. |
595 context.reset(NewContext()); | 616 context.reset(NewContext(NULL)); |
596 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 617 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
597 context.get(), path, exclusive, recursive)); | 618 context.get(), path, exclusive, recursive)); |
598 | 619 |
599 exclusive = true; | 620 exclusive = true; |
600 recursive = true; | 621 recursive = true; |
601 context.reset(NewContext()); | 622 context.reset(NewContext(NULL)); |
602 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( | 623 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( |
603 context.get(), path, exclusive, recursive)); | 624 context.get(), path, exclusive, recursive)); |
604 | 625 |
605 context.reset(NewContext()); | 626 context.reset(NewContext(NULL)); |
606 EXPECT_EQ(base::PLATFORM_FILE_OK, | 627 EXPECT_EQ(base::PLATFORM_FILE_OK, |
607 ofsfu()->DeleteSingleDirectory(context.get(), path)); | 628 ofsfu()->DeleteSingleDirectory(context.get(), path)); |
608 | 629 |
609 path = UTF8ToFilePath("foo/bop"); | 630 path = UTF8ToFilePath("foo/bop"); |
610 | 631 |
611 context.reset(NewContext()); | 632 context.reset(NewContext(NULL)); |
612 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 633 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
613 context.reset(NewContext()); | 634 context.reset(NewContext(NULL)); |
614 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); | 635 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); |
615 context.reset(NewContext()); | 636 context.reset(NewContext(NULL)); |
616 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); | 637 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); |
617 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( | 638 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( |
618 context.get(), path, &file_info, &local_path)); | 639 context.get(), path, &file_info, &local_path)); |
619 | 640 |
620 exclusive = true; | 641 exclusive = true; |
621 recursive = false; | 642 recursive = false; |
622 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 643 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
623 context.get(), path, exclusive, recursive)); | 644 context.get(), path, exclusive, recursive)); |
624 | 645 |
625 context.reset(NewContext()); | 646 context.reset(NewContext(NULL)); |
626 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); | 647 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); |
627 context.reset(NewContext()); | 648 context.reset(NewContext(NULL)); |
628 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 649 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
629 | 650 |
630 exclusive = true; | 651 exclusive = true; |
631 recursive = false; | 652 recursive = false; |
632 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( | 653 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( |
633 context.get(), path, exclusive, recursive)); | 654 context.get(), path, exclusive, recursive)); |
634 | 655 |
635 exclusive = true; | 656 exclusive = true; |
636 recursive = false; | 657 recursive = false; |
637 path = UTF8ToFilePath("foo"); | 658 path = UTF8ToFilePath("foo"); |
638 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( | 659 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( |
639 context.get(), path, exclusive, recursive)); | 660 context.get(), path, exclusive, recursive)); |
640 | 661 |
641 path = UTF8ToFilePath("blah"); | 662 path = UTF8ToFilePath("blah"); |
642 | 663 |
643 context.reset(NewContext()); | 664 context.reset(NewContext(NULL)); |
644 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 665 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
645 context.reset(NewContext()); | 666 context.reset(NewContext(NULL)); |
646 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); | 667 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); |
647 | 668 |
648 exclusive = true; | 669 exclusive = true; |
649 recursive = false; | 670 recursive = false; |
650 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 671 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
651 context.get(), path, exclusive, recursive)); | 672 context.get(), path, exclusive, recursive)); |
652 | 673 |
653 context.reset(NewContext()); | 674 context.reset(NewContext(NULL)); |
654 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); | 675 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); |
655 context.reset(NewContext()); | 676 context.reset(NewContext(NULL)); |
656 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 677 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
657 | 678 |
658 exclusive = true; | 679 exclusive = true; |
659 recursive = false; | 680 recursive = false; |
660 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( | 681 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( |
661 context.get(), path, exclusive, recursive)); | 682 context.get(), path, exclusive, recursive)); |
662 } | 683 } |
663 | 684 |
664 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectory) { | 685 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectory) { |
665 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 686 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
666 bool exclusive = true; | 687 bool exclusive = true; |
667 bool recursive = true; | 688 bool recursive = true; |
668 FilePath path = UTF8ToFilePath("directory/to/use"); | 689 FilePath path = UTF8ToFilePath("directory/to/use"); |
669 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 690 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
670 context.get(), path, exclusive, recursive)); | 691 context.get(), path, exclusive, recursive)); |
671 TestReadDirectoryHelper(path); | 692 TestReadDirectoryHelper(path); |
672 } | 693 } |
673 | 694 |
674 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithSlash) { | 695 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithSlash) { |
675 TestReadDirectoryHelper(UTF8ToFilePath("")); | 696 TestReadDirectoryHelper(UTF8ToFilePath("")); |
676 } | 697 } |
677 | 698 |
678 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithEmptyString) { | 699 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithEmptyString) { |
679 TestReadDirectoryHelper(UTF8ToFilePath("/")); | 700 TestReadDirectoryHelper(UTF8ToFilePath("/")); |
680 } | 701 } |
681 | 702 |
682 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectoryOnFile) { | 703 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectoryOnFile) { |
683 FilePath path = UTF8ToFilePath("file"); | 704 FilePath path = UTF8ToFilePath("file"); |
684 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 705 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
685 | 706 |
686 bool created = false; | 707 bool created = false; |
687 ASSERT_EQ(base::PLATFORM_FILE_OK, | 708 ASSERT_EQ(base::PLATFORM_FILE_OK, |
688 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 709 ofsfu()->EnsureFileExists(context.get(), path, &created)); |
689 ASSERT_TRUE(created); | 710 ASSERT_TRUE(created); |
690 | 711 |
691 context.reset(NewContext()); | 712 context.reset(NewContext(NULL)); |
692 std::vector<base::FileUtilProxy::Entry> entries; | 713 std::vector<base::FileUtilProxy::Entry> entries; |
693 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 714 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
694 ofsfu()->ReadDirectory(context.get(), path, &entries)); | 715 ofsfu()->ReadDirectory(context.get(), path, &entries)); |
695 | 716 |
696 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); | 717 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); |
697 } | 718 } |
698 | 719 |
699 TEST_F(ObfuscatedFileSystemFileUtilTest, TestTouch) { | 720 TEST_F(ObfuscatedFileSystemFileUtilTest, TestTouch) { |
700 FilePath path = UTF8ToFilePath("fake/file"); | 721 FilePath path = UTF8ToFilePath("fake/file"); |
701 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. | 722 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. |
702 base::Time last_modified_time = base::Time::Now(); | 723 base::Time last_modified_time = base::Time::Now(); |
703 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 724 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
704 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 725 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
705 ofsfu()->Touch( | 726 ofsfu()->Touch( |
706 context.get(), path, last_access_time, last_modified_time)); | 727 context.get(), path, last_access_time, last_modified_time)); |
707 | 728 |
708 // Touch will create a file if it's not there but its parent is. | 729 // Touch will create a file if it's not there but its parent is. |
709 path = UTF8ToFilePath("file name"); | 730 path = UTF8ToFilePath("file name"); |
710 TestTouchHelper(path); | 731 TestTouchHelper(path); |
711 | 732 |
712 bool exclusive = true; | 733 bool exclusive = true; |
713 bool recursive = true; | 734 bool recursive = true; |
714 path = UTF8ToFilePath("directory/to/use"); | 735 path = UTF8ToFilePath("directory/to/use"); |
715 context.reset(NewContext()); | 736 context.reset(NewContext(NULL)); |
716 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 737 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
717 context.get(), path, exclusive, recursive)); | 738 context.get(), path, exclusive, recursive)); |
718 TestTouchHelper(path); | 739 TestTouchHelper(path); |
719 } | 740 } |
720 | 741 |
742 TEST_F(ObfuscatedFileSystemFileUtilTest, TestPathQuotas) { | |
743 FilePath path = UTF8ToFilePath("fake/file"); | |
744 base::Time last_access_time = base::Time::Now(); | |
745 base::Time last_modified_time = base::Time::Now(); | |
746 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | |
747 | |
748 // Touch will create a file if it's not there but its parent is. | |
749 path = UTF8ToFilePath("file name"); | |
750 context->set_allowed_bytes_growth(5); | |
751 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, | |
752 ofsfu()->Touch( | |
753 context.get(), path, last_access_time, last_modified_time)); | |
754 context->set_allowed_bytes_growth(1024); | |
755 EXPECT_EQ(base::PLATFORM_FILE_OK, | |
756 ofsfu()->Touch( | |
757 context.get(), path, last_access_time, last_modified_time)); | |
758 int64 path_cost = ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path); | |
759 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); | |
760 | |
761 context->set_allowed_bytes_growth(1024); | |
762 bool exclusive = true; | |
763 bool recursive = true; | |
764 path = UTF8ToFilePath("directory/to/use"); | |
765 std::vector<FilePath::StringType> components; | |
766 path.GetComponents(&components); | |
767 path_cost = 0; | |
768 for (std::vector<FilePath::StringType>::iterator iter = components.begin(); | |
769 iter != components.end(); ++iter) { | |
kinuko
2011/08/15 03:42:34
nit: indent
ericu
2011/08/15 23:47:10
4 spaces at a line wrap, two spaces for the interi
| |
770 path_cost += ObfuscatedFileSystemFileUtil::ComputeFilePathCost( | |
771 FilePath(*iter)); | |
772 } | |
773 context.reset(NewContext(NULL)); | |
774 context->set_allowed_bytes_growth(1024); | |
775 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | |
776 context.get(), path, exclusive, recursive)); | |
777 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); | |
778 } | |
779 | |
721 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileNotFound) { | 780 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileNotFound) { |
722 FilePath source_path = UTF8ToFilePath("path0.txt"); | 781 FilePath source_path = UTF8ToFilePath("path0.txt"); |
723 FilePath dest_path = UTF8ToFilePath("path1.txt"); | 782 FilePath dest_path = UTF8ToFilePath("path1.txt"); |
724 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 783 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
725 | 784 |
726 bool is_copy_not_move = false; | 785 bool is_copy_not_move = false; |
727 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 786 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
728 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, | 787 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
729 is_copy_not_move)); | 788 is_copy_not_move)); |
730 context.reset(NewContext()); | 789 context.reset(NewContext(NULL)); |
731 is_copy_not_move = true; | 790 is_copy_not_move = true; |
732 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 791 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
733 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, | 792 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
734 is_copy_not_move)); | 793 is_copy_not_move)); |
735 source_path = UTF8ToFilePath("dir/dir/file"); | 794 source_path = UTF8ToFilePath("dir/dir/file"); |
736 bool exclusive = true; | 795 bool exclusive = true; |
737 bool recursive = true; | 796 bool recursive = true; |
738 context.reset(NewContext()); | 797 context.reset(NewContext(NULL)); |
739 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 798 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
740 context.get(), source_path.DirName(), exclusive, recursive)); | 799 context.get(), source_path.DirName(), exclusive, recursive)); |
741 is_copy_not_move = false; | 800 is_copy_not_move = false; |
742 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 801 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
743 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, | 802 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
744 is_copy_not_move)); | 803 is_copy_not_move)); |
745 context.reset(NewContext()); | 804 context.reset(NewContext(NULL)); |
746 is_copy_not_move = true; | 805 is_copy_not_move = true; |
747 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 806 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
748 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, | 807 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
749 is_copy_not_move)); | 808 is_copy_not_move)); |
750 } | 809 } |
751 | 810 |
752 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileSuccess) { | 811 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileSuccess) { |
753 const int64 kSourceLength = 5; | 812 const int64 kSourceLength = 5; |
754 const int64 kDestLength = 50; | 813 const int64 kDestLength = 50; |
755 | 814 |
756 for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) { | 815 for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) { |
757 SCOPED_TRACE(testing::Message() << "kCopyMoveTestCase " << i); | 816 SCOPED_TRACE(testing::Message() << "kCopyMoveTestCase " << i); |
758 const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i]; | 817 const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i]; |
759 SCOPED_TRACE(testing::Message() << "\t is_copy_not_move " << | 818 SCOPED_TRACE(testing::Message() << "\t is_copy_not_move " << |
760 test_case.is_copy_not_move); | 819 test_case.is_copy_not_move); |
761 SCOPED_TRACE(testing::Message() << "\t source_path " << | 820 SCOPED_TRACE(testing::Message() << "\t source_path " << |
762 test_case.source_path); | 821 test_case.source_path); |
763 SCOPED_TRACE(testing::Message() << "\t dest_path " << | 822 SCOPED_TRACE(testing::Message() << "\t dest_path " << |
764 test_case.dest_path); | 823 test_case.dest_path); |
765 SCOPED_TRACE(testing::Message() << "\t cause_overwrite " << | 824 SCOPED_TRACE(testing::Message() << "\t cause_overwrite " << |
766 test_case.cause_overwrite); | 825 test_case.cause_overwrite); |
767 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 826 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
768 | 827 |
769 bool exclusive = false; | 828 bool exclusive = false; |
770 bool recursive = true; | 829 bool recursive = true; |
771 FilePath source_path = UTF8ToFilePath(test_case.source_path); | 830 FilePath source_path = UTF8ToFilePath(test_case.source_path); |
772 FilePath dest_path = UTF8ToFilePath(test_case.dest_path); | 831 FilePath dest_path = UTF8ToFilePath(test_case.dest_path); |
773 | 832 |
774 context.reset(NewContext()); | 833 context.reset(NewContext(NULL)); |
775 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 834 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
776 context.get(), source_path.DirName(), exclusive, recursive)); | 835 context.get(), source_path.DirName(), exclusive, recursive)); |
777 context.reset(NewContext()); | 836 context.reset(NewContext(NULL)); |
778 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 837 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
779 context.get(), dest_path.DirName(), exclusive, recursive)); | 838 context.get(), dest_path.DirName(), exclusive, recursive)); |
780 | 839 |
781 bool created = false; | 840 bool created = false; |
782 context.reset(NewContext()); | 841 context.reset(NewContext(NULL)); |
783 ASSERT_EQ(base::PLATFORM_FILE_OK, | 842 ASSERT_EQ(base::PLATFORM_FILE_OK, |
784 ofsfu()->EnsureFileExists(context.get(), source_path, &created)); | 843 ofsfu()->EnsureFileExists(context.get(), source_path, &created)); |
785 ASSERT_TRUE(created); | 844 ASSERT_TRUE(created); |
786 context.reset(NewContext()); | 845 context.reset(NewContext(NULL)); |
787 ASSERT_EQ(base::PLATFORM_FILE_OK, | 846 ASSERT_EQ(base::PLATFORM_FILE_OK, |
788 ofsfu()->Truncate(context.get(), source_path, kSourceLength)); | 847 ofsfu()->Truncate(context.get(), source_path, kSourceLength)); |
789 | 848 |
790 if (test_case.cause_overwrite) { | 849 if (test_case.cause_overwrite) { |
791 context.reset(NewContext()); | 850 context.reset(NewContext(NULL)); |
792 created = false; | 851 created = false; |
793 ASSERT_EQ(base::PLATFORM_FILE_OK, | 852 ASSERT_EQ(base::PLATFORM_FILE_OK, |
794 ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); | 853 ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); |
795 ASSERT_TRUE(created); | 854 ASSERT_TRUE(created); |
796 context.reset(NewContext()); | 855 context.reset(NewContext(NULL)); |
797 ASSERT_EQ(base::PLATFORM_FILE_OK, | 856 ASSERT_EQ(base::PLATFORM_FILE_OK, |
798 ofsfu()->Truncate(context.get(), dest_path, kDestLength)); | 857 ofsfu()->Truncate(context.get(), dest_path, kDestLength)); |
799 } | 858 } |
800 | 859 |
801 context.reset(NewContext()); | 860 context.reset(NewContext(NULL)); |
802 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CopyOrMoveFile(context.get(), | 861 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CopyOrMoveFile(context.get(), |
803 source_path, dest_path, test_case.is_copy_not_move)); | 862 source_path, dest_path, test_case.is_copy_not_move)); |
804 if (test_case.is_copy_not_move) { | 863 if (test_case.is_copy_not_move) { |
805 base::PlatformFileInfo file_info; | 864 base::PlatformFileInfo file_info; |
806 FilePath local_path; | 865 FilePath local_path; |
807 context.reset(NewContext()); | 866 context.reset(NewContext(NULL)); |
808 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 867 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
809 context.get(), source_path, &file_info, &local_path)); | 868 context.get(), source_path, &file_info, &local_path)); |
810 EXPECT_EQ(kSourceLength, file_info.size); | 869 EXPECT_EQ(kSourceLength, file_info.size); |
811 EXPECT_EQ(base::PLATFORM_FILE_OK, | 870 EXPECT_EQ(base::PLATFORM_FILE_OK, |
812 ofsfu()->DeleteFile(context.get(), source_path)); | 871 ofsfu()->DeleteFile(context.get(), source_path)); |
813 } else { | 872 } else { |
814 base::PlatformFileInfo file_info; | 873 base::PlatformFileInfo file_info; |
815 FilePath local_path; | 874 FilePath local_path; |
816 context.reset(NewContext()); | 875 context.reset(NewContext(NULL)); |
817 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( | 876 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( |
818 context.get(), source_path, &file_info, &local_path)); | 877 context.get(), source_path, &file_info, &local_path)); |
819 } | 878 } |
820 base::PlatformFileInfo file_info; | 879 base::PlatformFileInfo file_info; |
821 FilePath local_path; | 880 FilePath local_path; |
822 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 881 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
823 context.get(), dest_path, &file_info, &local_path)); | 882 context.get(), dest_path, &file_info, &local_path)); |
824 EXPECT_EQ(kSourceLength, file_info.size); | 883 EXPECT_EQ(kSourceLength, file_info.size); |
825 | 884 |
826 EXPECT_EQ(base::PLATFORM_FILE_OK, | 885 EXPECT_EQ(base::PLATFORM_FILE_OK, |
827 ofsfu()->DeleteFile(context.get(), dest_path)); | 886 ofsfu()->DeleteFile(context.get(), dest_path)); |
828 } | 887 } |
829 } | 888 } |
830 | 889 |
831 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyInForeignFile) { | 890 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyInForeignFile) { |
832 TestCopyInForeignFileHelper(false /* overwrite */); | 891 TestCopyInForeignFileHelper(false /* overwrite */); |
833 TestCopyInForeignFileHelper(true /* overwrite */); | 892 TestCopyInForeignFileHelper(true /* overwrite */); |
834 } | 893 } |
835 | 894 |
836 TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnumerator) { | 895 TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnumerator) { |
837 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 896 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
838 FilePath src_path = UTF8ToFilePath("source dir"); | 897 FilePath src_path = UTF8ToFilePath("source dir"); |
839 bool exclusive = true; | 898 bool exclusive = true; |
840 bool recursive = false; | 899 bool recursive = false; |
841 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 900 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
842 context.get(), src_path, exclusive, recursive)); | 901 context.get(), src_path, exclusive, recursive)); |
843 | 902 |
844 std::set<FilePath::StringType> files; | 903 std::set<FilePath::StringType> files; |
845 std::set<FilePath::StringType> directories; | 904 std::set<FilePath::StringType> directories; |
846 FillTestDirectory(src_path, &files, &directories); | 905 FillTestDirectory(src_path, &files, &directories); |
847 | 906 |
848 FilePath dest_path = UTF8ToFilePath("destination dir"); | 907 FilePath dest_path = UTF8ToFilePath("destination dir"); |
849 | 908 |
850 context.reset(NewContext()); | 909 context.reset(NewContext(NULL)); |
851 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 910 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
852 context.reset(NewContext()); | 911 context.reset(NewContext(NULL)); |
853 ASSERT_EQ(base::PLATFORM_FILE_OK, | 912 ASSERT_EQ(base::PLATFORM_FILE_OK, |
854 ofsfu()->Copy(context.get(), src_path, dest_path)); | 913 ofsfu()->Copy(context.get(), src_path, dest_path)); |
855 | 914 |
856 ValidateTestDirectory(dest_path, files, directories); | 915 ValidateTestDirectory(dest_path, files, directories); |
857 context.reset(NewContext()); | 916 context.reset(NewContext(NULL)); |
858 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), src_path)); | 917 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), src_path)); |
859 context.reset(NewContext()); | 918 context.reset(NewContext(NULL)); |
860 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 919 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
861 context.reset(NewContext()); | 920 context.reset(NewContext(NULL)); |
862 recursive = true; | 921 recursive = true; |
863 ASSERT_EQ(base::PLATFORM_FILE_OK, | 922 ASSERT_EQ(base::PLATFORM_FILE_OK, |
864 ofsfu()->Delete(context.get(), dest_path, recursive)); | 923 ofsfu()->Delete(context.get(), dest_path, recursive)); |
865 context.reset(NewContext()); | 924 context.reset(NewContext(NULL)); |
866 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 925 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
867 } | 926 } |
868 | 927 |
869 TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) { | 928 TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) { |
870 ScopedTempDir source_dir; | 929 ScopedTempDir source_dir; |
871 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); | 930 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); |
872 FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn"); | 931 FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn"); |
873 ASSERT_TRUE(file_util::CreateDirectory(root_path)); | 932 ASSERT_TRUE(file_util::CreateDirectory(root_path)); |
874 | 933 |
875 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { | 934 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { |
(...skipping 24 matching lines...) Expand all Loading... | |
900 FilePath new_root = | 959 FilePath new_root = |
901 test_directory().AppendASCII("000").Append( | 960 test_directory().AppendASCII("000").Append( |
902 ofsfu()->GetDirectoryNameForType(type())).AppendASCII("Legacy"); | 961 ofsfu()->GetDirectoryNameForType(type())).AppendASCII("Legacy"); |
903 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { | 962 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { |
904 SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i); | 963 SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i); |
905 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; | 964 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; |
906 FilePath local_data_path = new_root.Append(test_case.path); | 965 FilePath local_data_path = new_root.Append(test_case.path); |
907 #if defined(OS_WIN) | 966 #if defined(OS_WIN) |
908 local_data_path = local_data_path.NormalizeWindowsPathSeparators(); | 967 local_data_path = local_data_path.NormalizeWindowsPathSeparators(); |
909 #endif | 968 #endif |
910 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 969 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
911 base::PlatformFileInfo ofsfu_file_info; | 970 base::PlatformFileInfo ofsfu_file_info; |
912 FilePath data_path; | 971 FilePath data_path; |
913 SCOPED_TRACE(testing::Message() << "Path is " << test_case.path); | 972 SCOPED_TRACE(testing::Message() << "Path is " << test_case.path); |
914 EXPECT_EQ(base::PLATFORM_FILE_OK, | 973 EXPECT_EQ(base::PLATFORM_FILE_OK, |
915 ofsfu()->GetFileInfo(context.get(), FilePath(test_case.path), | 974 ofsfu()->GetFileInfo(context.get(), FilePath(test_case.path), |
916 &ofsfu_file_info, &data_path)); | 975 &ofsfu_file_info, &data_path)); |
917 if (test_case.is_directory) { | 976 if (test_case.is_directory) { |
918 EXPECT_TRUE(ofsfu_file_info.is_directory); | 977 EXPECT_TRUE(ofsfu_file_info.is_directory); |
919 } else { | 978 } else { |
920 base::PlatformFileInfo platform_file_info; | 979 base::PlatformFileInfo platform_file_info; |
921 SCOPED_TRACE(testing::Message() << "local_data_path is " << | 980 SCOPED_TRACE(testing::Message() << "local_data_path is " << |
922 local_data_path.value()); | 981 local_data_path.value()); |
923 SCOPED_TRACE(testing::Message() << "data_path is " << data_path.value()); | 982 SCOPED_TRACE(testing::Message() << "data_path is " << data_path.value()); |
924 ASSERT_TRUE(file_util::GetFileInfo(local_data_path, &platform_file_info)); | 983 ASSERT_TRUE(file_util::GetFileInfo(local_data_path, &platform_file_info)); |
925 EXPECT_EQ(test_case.data_file_size, platform_file_info.size); | 984 EXPECT_EQ(test_case.data_file_size, platform_file_info.size); |
926 EXPECT_FALSE(platform_file_info.is_directory); | 985 EXPECT_FALSE(platform_file_info.is_directory); |
927 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 986 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
928 EXPECT_EQ(local_data_path, data_path); | 987 EXPECT_EQ(local_data_path, data_path); |
929 EXPECT_EQ(platform_file_info.size, ofsfu_file_info.size); | 988 EXPECT_EQ(platform_file_info.size, ofsfu_file_info.size); |
930 EXPECT_FALSE(ofsfu_file_info.is_directory); | 989 EXPECT_FALSE(ofsfu_file_info.is_directory); |
931 } | 990 } |
932 } | 991 } |
933 } | 992 } |
934 | 993 |
935 TEST_F(ObfuscatedFileSystemFileUtilTest, TestOriginEnumerator) { | 994 TEST_F(ObfuscatedFileSystemFileUtilTest, TestOriginEnumerator) { |
936 scoped_ptr<ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator> | 995 scoped_ptr<ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator> |
937 enumerator(ofsfu()->CreateOriginEnumerator()); | 996 enumerator(ofsfu()->CreateOriginEnumerator()); |
938 EXPECT_TRUE(enumerator.get()); | 997 EXPECT_TRUE(enumerator.get()); |
939 EXPECT_EQ(GURL(), enumerator->Next()); | 998 EXPECT_EQ(GURL(), enumerator->Next()); |
940 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypeTemporary)); | 999 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypeTemporary)); |
941 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypePersistent)); | 1000 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypePersistent)); |
942 | 1001 |
943 std::set<GURL> origins_expected; | 1002 std::set<GURL> origins_expected; |
944 | 1003 |
945 for (size_t i = 0; i < arraysize(kOriginEnumerationTestRecords); ++i) { | 1004 for (size_t i = 0; i < arraysize(kOriginEnumerationTestRecords); ++i) { |
946 SCOPED_TRACE(testing::Message() << | 1005 SCOPED_TRACE(testing::Message() << |
947 "Validating kOriginEnumerationTestRecords " << i); | 1006 "Validating kOriginEnumerationTestRecords " << i); |
948 const OriginEnumerationTestRecord& record = | 1007 const OriginEnumerationTestRecord& record = |
949 kOriginEnumerationTestRecords[i]; | 1008 kOriginEnumerationTestRecords[i]; |
950 GURL origin_url(record.origin_url); | 1009 GURL origin_url(record.origin_url); |
951 origins_expected.insert(origin_url); | 1010 origins_expected.insert(origin_url); |
952 if (record.has_temporary) { | 1011 if (record.has_temporary) { |
953 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 1012 scoped_ptr<FileSystemTestOriginHelper> helper( |
1013 NewHelper(origin_url, kFileSystemTypeTemporary)); | |
1014 scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); | |
954 context->set_src_origin_url(origin_url); | 1015 context->set_src_origin_url(origin_url); |
955 context->set_src_type(kFileSystemTypeTemporary); | 1016 context->set_src_type(kFileSystemTypeTemporary); |
956 bool created = false; | 1017 bool created = false; |
957 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1018 ASSERT_EQ(base::PLATFORM_FILE_OK, |
958 ofsfu()->EnsureFileExists(context.get(), | 1019 ofsfu()->EnsureFileExists(context.get(), |
959 FilePath().AppendASCII("file"), &created)); | 1020 FilePath().AppendASCII("file"), &created)); |
960 EXPECT_TRUE(created); | 1021 EXPECT_TRUE(created); |
961 } | 1022 } |
962 if (record.has_persistent) { | 1023 if (record.has_persistent) { |
963 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 1024 scoped_ptr<FileSystemTestOriginHelper> helper( |
1025 NewHelper(origin_url, kFileSystemTypePersistent)); | |
1026 scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); | |
964 context->set_src_origin_url(origin_url); | 1027 context->set_src_origin_url(origin_url); |
965 context->set_src_type(kFileSystemTypePersistent); | 1028 context->set_src_type(kFileSystemTypePersistent); |
966 bool created = false; | 1029 bool created = false; |
967 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1030 ASSERT_EQ(base::PLATFORM_FILE_OK, |
968 ofsfu()->EnsureFileExists(context.get(), | 1031 ofsfu()->EnsureFileExists(context.get(), |
969 FilePath().AppendASCII("file"), &created)); | 1032 FilePath().AppendASCII("file"), &created)); |
970 EXPECT_TRUE(created); | 1033 EXPECT_TRUE(created); |
971 } | 1034 } |
972 } | 1035 } |
973 enumerator.reset(ofsfu()->CreateOriginEnumerator()); | 1036 enumerator.reset(ofsfu()->CreateOriginEnumerator()); |
(...skipping 18 matching lines...) Expand all Loading... | |
992 } | 1055 } |
993 EXPECT_TRUE(found); | 1056 EXPECT_TRUE(found); |
994 } | 1057 } |
995 | 1058 |
996 std::set<GURL> diff; | 1059 std::set<GURL> diff; |
997 std::set_symmetric_difference(origins_expected.begin(), | 1060 std::set_symmetric_difference(origins_expected.begin(), |
998 origins_expected.end(), origins_found.begin(), origins_found.end(), | 1061 origins_expected.end(), origins_found.begin(), origins_found.end(), |
999 inserter(diff, diff.begin())); | 1062 inserter(diff, diff.begin())); |
1000 EXPECT_TRUE(diff.empty()); | 1063 EXPECT_TRUE(diff.empty()); |
1001 } | 1064 } |
OLD | NEW |