OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <map> | 5 #include <map> |
6 #include <queue> | 6 #include <queue> |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/files/file_enumerator.h" | 12 #include "base/files/file_enumerator.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/message_loop/message_loop_proxy.h" | 16 #include "base/message_loop/message_loop_proxy.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "content/public/test/async_file_test_helper.h" | 18 #include "content/public/test/async_file_test_helper.h" |
19 #include "content/public/test/test_file_system_context.h" | 19 #include "content/public/test/test_file_system_context.h" |
| 20 #include "content/test/fileapi_test_file_set.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "webkit/browser/fileapi/dragged_file_util.h" | 22 #include "webkit/browser/fileapi/dragged_file_util.h" |
22 #include "webkit/browser/fileapi/file_system_context.h" | 23 #include "webkit/browser/fileapi/file_system_context.h" |
23 #include "webkit/browser/fileapi/file_system_operation_context.h" | 24 #include "webkit/browser/fileapi/file_system_operation_context.h" |
24 #include "webkit/browser/fileapi/isolated_context.h" | 25 #include "webkit/browser/fileapi/isolated_context.h" |
25 #include "webkit/browser/fileapi/local_file_util.h" | 26 #include "webkit/browser/fileapi/local_file_util.h" |
26 #include "webkit/browser/fileapi/native_file_util.h" | 27 #include "webkit/browser/fileapi/native_file_util.h" |
27 #include "webkit/browser/fileapi/test_file_set.h" | |
28 | 28 |
29 using content::AsyncFileTestHelper; | 29 using content::AsyncFileTestHelper; |
30 using fileapi::FileSystemContext; | 30 using fileapi::FileSystemContext; |
31 using fileapi::FileSystemOperationContext; | 31 using fileapi::FileSystemOperationContext; |
32 using fileapi::FileSystemType; | 32 using fileapi::FileSystemType; |
33 using fileapi::FileSystemURL; | 33 using fileapi::FileSystemURL; |
34 | 34 |
35 namespace content { | 35 namespace content { |
36 | 36 |
37 namespace { | 37 namespace { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 return make_scoped_ptr( | 251 return make_scoped_ptr( |
252 new fileapi::FileSystemOperationContext(file_system_context())).Pass(); | 252 new fileapi::FileSystemOperationContext(file_system_context())).Pass(); |
253 } | 253 } |
254 | 254 |
255 | 255 |
256 private: | 256 private: |
257 void SimulateDropFiles() { | 257 void SimulateDropFiles() { |
258 size_t root_path_index = 0; | 258 size_t root_path_index = 0; |
259 | 259 |
260 fileapi::IsolatedContext::FileInfoSet toplevels; | 260 fileapi::IsolatedContext::FileInfoSet toplevels; |
261 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { | 261 for (size_t i = 0; i < kRegularFileSystemTestCaseSize; ++i) { |
262 const fileapi::test::TestCaseRecord& test_case = | 262 const FileSystemTestCaseRecord& test_case = |
263 fileapi::test::kRegularTestCases[i]; | 263 kRegularFileSystemTestCases[i]; |
264 base::FilePath path(test_case.path); | 264 base::FilePath path(test_case.path); |
265 base::FilePath toplevel = GetTopLevelPath(path); | 265 base::FilePath toplevel = GetTopLevelPath(path); |
266 | 266 |
267 // We create the test case files under one of the kRootPaths | 267 // We create the test case files under one of the kRootPaths |
268 // to simulate a drop with multiple directories. | 268 // to simulate a drop with multiple directories. |
269 if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) { | 269 if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) { |
270 base::FilePath root = root_path().Append( | 270 base::FilePath root = root_path().Append( |
271 kRootPaths[(root_path_index++) % arraysize(kRootPaths)]); | 271 kRootPaths[(root_path_index++) % arraysize(kRootPaths)]); |
272 toplevel_root_map_[toplevel] = root; | 272 toplevel_root_map_[toplevel] = root; |
273 toplevels.AddPath(root.Append(path), NULL); | 273 toplevels.AddPath(root.Append(path), NULL); |
274 } | 274 } |
275 | 275 |
276 fileapi::test::SetUpOneTestCase(toplevel_root_map_[toplevel], test_case); | 276 SetUpOneFileSystemTestCase(toplevel_root_map_[toplevel], test_case); |
277 } | 277 } |
278 | 278 |
279 // Register the toplevel entries. | 279 // Register the toplevel entries. |
280 filesystem_id_ = isolated_context()->RegisterDraggedFileSystem(toplevels); | 280 filesystem_id_ = isolated_context()->RegisterDraggedFileSystem(toplevels); |
281 } | 281 } |
282 | 282 |
283 base::ScopedTempDir data_dir_; | 283 base::ScopedTempDir data_dir_; |
284 base::ScopedTempDir partition_dir_; | 284 base::ScopedTempDir partition_dir_; |
285 base::MessageLoopForIO message_loop_; | 285 base::MessageLoopForIO message_loop_; |
286 std::string filesystem_id_; | 286 std::string filesystem_id_; |
287 scoped_refptr<FileSystemContext> file_system_context_; | 287 scoped_refptr<FileSystemContext> file_system_context_; |
288 std::map<base::FilePath, base::FilePath> toplevel_root_map_; | 288 std::map<base::FilePath, base::FilePath> toplevel_root_map_; |
289 scoped_ptr<fileapi::DraggedFileUtil> file_util_; | 289 scoped_ptr<fileapi::DraggedFileUtil> file_util_; |
290 DISALLOW_COPY_AND_ASSIGN(DraggedFileUtilTest); | 290 DISALLOW_COPY_AND_ASSIGN(DraggedFileUtilTest); |
291 }; | 291 }; |
292 | 292 |
293 TEST_F(DraggedFileUtilTest, BasicTest) { | 293 TEST_F(DraggedFileUtilTest, BasicTest) { |
294 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { | 294 for (size_t i = 0; i < kRegularFileSystemTestCaseSize; ++i) { |
295 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i); | 295 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i); |
296 const fileapi::test::TestCaseRecord& test_case = | 296 const FileSystemTestCaseRecord& test_case = |
297 fileapi::test::kRegularTestCases[i]; | 297 kRegularFileSystemTestCases[i]; |
298 | 298 |
299 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 299 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
300 | 300 |
301 // See if we can query the file info via the isolated FileUtil. | 301 // See if we can query the file info via the isolated FileUtil. |
302 // (This should succeed since we have registered all the top-level | 302 // (This should succeed since we have registered all the top-level |
303 // entries of the test cases in SetUp()) | 303 // entries of the test cases in SetUp()) |
304 base::File::Info info; | 304 base::File::Info info; |
305 base::FilePath platform_path; | 305 base::FilePath platform_path; |
306 FileSystemOperationContext context(file_system_context()); | 306 FileSystemOperationContext context(file_system_context()); |
307 ASSERT_EQ(base::File::FILE_OK, | 307 ASSERT_EQ(base::File::FILE_OK, |
308 file_util()->GetFileInfo(&context, url, &info, &platform_path)); | 308 file_util()->GetFileInfo(&context, url, &info, &platform_path)); |
309 | 309 |
310 // See if the obtained file info is correct. | 310 // See if the obtained file info is correct. |
311 if (!test_case.is_directory) | 311 if (!test_case.is_directory) |
312 ASSERT_EQ(test_case.data_file_size, info.size); | 312 ASSERT_EQ(test_case.data_file_size, info.size); |
313 ASSERT_EQ(test_case.is_directory, info.is_directory); | 313 ASSERT_EQ(test_case.is_directory, info.is_directory); |
314 ASSERT_EQ(GetTestCasePlatformPath(test_case.path), | 314 ASSERT_EQ(GetTestCasePlatformPath(test_case.path), |
315 platform_path.NormalizePathSeparators()); | 315 platform_path.NormalizePathSeparators()); |
316 } | 316 } |
317 } | 317 } |
318 | 318 |
319 TEST_F(DraggedFileUtilTest, UnregisteredPathsTest) { | 319 TEST_F(DraggedFileUtilTest, UnregisteredPathsTest) { |
320 static const fileapi::test::TestCaseRecord kUnregisteredCases[] = { | 320 static const FileSystemTestCaseRecord kUnregisteredCases[] = { |
321 {true, FILE_PATH_LITERAL("nonexistent"), 0}, | 321 {true, FILE_PATH_LITERAL("nonexistent"), 0}, |
322 {true, FILE_PATH_LITERAL("nonexistent/dir foo"), 0}, | 322 {true, FILE_PATH_LITERAL("nonexistent/dir foo"), 0}, |
323 {false, FILE_PATH_LITERAL("nonexistent/false"), 0}, | 323 {false, FILE_PATH_LITERAL("nonexistent/false"), 0}, |
324 {false, FILE_PATH_LITERAL("foo"), 30}, | 324 {false, FILE_PATH_LITERAL("foo"), 30}, |
325 {false, FILE_PATH_LITERAL("bar"), 20}, | 325 {false, FILE_PATH_LITERAL("bar"), 20}, |
326 }; | 326 }; |
327 | 327 |
328 for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) { | 328 for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) { |
329 SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i); | 329 SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i); |
330 const fileapi::test::TestCaseRecord& test_case = kUnregisteredCases[i]; | 330 const FileSystemTestCaseRecord& test_case = kUnregisteredCases[i]; |
331 | 331 |
332 // Prepare the test file/directory. | 332 // Prepare the test file/directory. |
333 SetUpOneTestCase(root_path(), test_case); | 333 SetUpOneFileSystemTestCase(root_path(), test_case); |
334 | 334 |
335 // Make sure regular GetFileInfo succeeds. | 335 // Make sure regular GetFileInfo succeeds. |
336 base::File::Info info; | 336 base::File::Info info; |
337 ASSERT_TRUE(base::GetFileInfo(root_path().Append(test_case.path), &info)); | 337 ASSERT_TRUE(base::GetFileInfo(root_path().Append(test_case.path), &info)); |
338 if (!test_case.is_directory) | 338 if (!test_case.is_directory) |
339 ASSERT_EQ(test_case.data_file_size, info.size); | 339 ASSERT_EQ(test_case.data_file_size, info.size); |
340 ASSERT_EQ(test_case.is_directory, info.is_directory); | 340 ASSERT_EQ(test_case.is_directory, info.is_directory); |
341 } | 341 } |
342 | 342 |
343 for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) { | 343 for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) { |
344 SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i); | 344 SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i); |
345 const fileapi::test::TestCaseRecord& test_case = kUnregisteredCases[i]; | 345 const FileSystemTestCaseRecord& test_case = kUnregisteredCases[i]; |
346 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 346 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
347 | 347 |
348 // We should not be able to get the valid URL for unregistered files. | 348 // We should not be able to get the valid URL for unregistered files. |
349 ASSERT_FALSE(url.is_valid()); | 349 ASSERT_FALSE(url.is_valid()); |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 TEST_F(DraggedFileUtilTest, ReadDirectoryTest) { | 353 TEST_F(DraggedFileUtilTest, ReadDirectoryTest) { |
354 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { | 354 for (size_t i = 0; i < kRegularFileSystemTestCaseSize; ++i) { |
355 const fileapi::test::TestCaseRecord& test_case = | 355 const FileSystemTestCaseRecord& test_case = |
356 fileapi::test::kRegularTestCases[i]; | 356 kRegularFileSystemTestCases[i]; |
357 if (!test_case.is_directory) | 357 if (!test_case.is_directory) |
358 continue; | 358 continue; |
359 | 359 |
360 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i | 360 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i |
361 << ": " << test_case.path); | 361 << ": " << test_case.path); |
362 | 362 |
363 // Read entries in the directory to construct the expected results map. | 363 // Read entries in the directory to construct the expected results map. |
364 typedef std::map<base::FilePath::StringType, fileapi::DirectoryEntry> | 364 typedef std::map<base::FilePath::StringType, fileapi::DirectoryEntry> |
365 EntryMap; | 365 EntryMap; |
366 EntryMap expected_entry_map; | 366 EntryMap expected_entry_map; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 EXPECT_EQ(found->second.name, entry.name); | 405 EXPECT_EQ(found->second.name, entry.name); |
406 EXPECT_EQ(found->second.is_directory, entry.is_directory); | 406 EXPECT_EQ(found->second.is_directory, entry.is_directory); |
407 EXPECT_EQ(found->second.size, entry.size); | 407 EXPECT_EQ(found->second.size, entry.size); |
408 EXPECT_EQ(found->second.last_modified_time.ToDoubleT(), | 408 EXPECT_EQ(found->second.last_modified_time.ToDoubleT(), |
409 entry.last_modified_time.ToDoubleT()); | 409 entry.last_modified_time.ToDoubleT()); |
410 } | 410 } |
411 } | 411 } |
412 } | 412 } |
413 | 413 |
414 TEST_F(DraggedFileUtilTest, GetLocalFilePathTest) { | 414 TEST_F(DraggedFileUtilTest, GetLocalFilePathTest) { |
415 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { | 415 for (size_t i = 0; i < kRegularFileSystemTestCaseSize; ++i) { |
416 const fileapi::test::TestCaseRecord& test_case = | 416 const FileSystemTestCaseRecord& test_case = |
417 fileapi::test::kRegularTestCases[i]; | 417 kRegularFileSystemTestCases[i]; |
418 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 418 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
419 | 419 |
420 FileSystemOperationContext context(file_system_context()); | 420 FileSystemOperationContext context(file_system_context()); |
421 | 421 |
422 base::FilePath local_file_path; | 422 base::FilePath local_file_path; |
423 EXPECT_EQ(base::File::FILE_OK, | 423 EXPECT_EQ(base::File::FILE_OK, |
424 file_util()->GetLocalFilePath(&context, url, &local_file_path)); | 424 file_util()->GetLocalFilePath(&context, url, &local_file_path)); |
425 EXPECT_EQ(GetTestCasePlatformPath(test_case.path).value(), | 425 EXPECT_EQ(GetTestCasePlatformPath(test_case.path).value(), |
426 local_file_path.value()); | 426 local_file_path.value()); |
427 } | 427 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 SCOPED_TRACE(testing::Message() << "Testing file copy " | 490 SCOPED_TRACE(testing::Message() << "Testing file copy " |
491 << src_url.path().value()); | 491 << src_url.path().value()); |
492 ASSERT_EQ(base::File::FILE_OK, | 492 ASSERT_EQ(base::File::FILE_OK, |
493 AsyncFileTestHelper::Copy(file_system_context(), | 493 AsyncFileTestHelper::Copy(file_system_context(), |
494 src_url, dest_url)); | 494 src_url, dest_url)); |
495 VerifyDirectoriesHaveSameContent(src_url, dest_url); | 495 VerifyDirectoriesHaveSameContent(src_url, dest_url); |
496 } | 496 } |
497 } | 497 } |
498 | 498 |
499 TEST_F(DraggedFileUtilTest, TouchTest) { | 499 TEST_F(DraggedFileUtilTest, TouchTest) { |
500 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { | 500 for (size_t i = 0; i < kRegularFileSystemTestCaseSize; ++i) { |
501 const fileapi::test::TestCaseRecord& test_case = | 501 const FileSystemTestCaseRecord& test_case = |
502 fileapi::test::kRegularTestCases[i]; | 502 kRegularFileSystemTestCases[i]; |
503 if (test_case.is_directory) | 503 if (test_case.is_directory) |
504 continue; | 504 continue; |
505 SCOPED_TRACE(testing::Message() << test_case.path); | 505 SCOPED_TRACE(testing::Message() << test_case.path); |
506 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 506 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
507 | 507 |
508 base::Time last_access_time = base::Time::FromTimeT(1000); | 508 base::Time last_access_time = base::Time::FromTimeT(1000); |
509 base::Time last_modified_time = base::Time::FromTimeT(2000); | 509 base::Time last_modified_time = base::Time::FromTimeT(2000); |
510 | 510 |
511 EXPECT_EQ(base::File::FILE_OK, | 511 EXPECT_EQ(base::File::FILE_OK, |
512 file_util()->Touch(GetOperationContext().get(), url, | 512 file_util()->Touch(GetOperationContext().get(), url, |
513 last_access_time, | 513 last_access_time, |
514 last_modified_time)); | 514 last_modified_time)); |
515 | 515 |
516 // Verification. | 516 // Verification. |
517 base::File::Info info; | 517 base::File::Info info; |
518 base::FilePath platform_path; | 518 base::FilePath platform_path; |
519 ASSERT_EQ(base::File::FILE_OK, | 519 ASSERT_EQ(base::File::FILE_OK, |
520 file_util()->GetFileInfo(GetOperationContext().get(), url, | 520 file_util()->GetFileInfo(GetOperationContext().get(), url, |
521 &info, &platform_path)); | 521 &info, &platform_path)); |
522 EXPECT_EQ(last_access_time.ToTimeT(), info.last_accessed.ToTimeT()); | 522 EXPECT_EQ(last_access_time.ToTimeT(), info.last_accessed.ToTimeT()); |
523 EXPECT_EQ(last_modified_time.ToTimeT(), info.last_modified.ToTimeT()); | 523 EXPECT_EQ(last_modified_time.ToTimeT(), info.last_modified.ToTimeT()); |
524 } | 524 } |
525 } | 525 } |
526 | 526 |
527 TEST_F(DraggedFileUtilTest, TruncateTest) { | 527 TEST_F(DraggedFileUtilTest, TruncateTest) { |
528 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { | 528 for (size_t i = 0; i < kRegularFileSystemTestCaseSize; ++i) { |
529 const fileapi::test::TestCaseRecord& test_case = | 529 const FileSystemTestCaseRecord& test_case = |
530 fileapi::test::kRegularTestCases[i]; | 530 kRegularFileSystemTestCases[i]; |
531 if (test_case.is_directory) | 531 if (test_case.is_directory) |
532 continue; | 532 continue; |
533 | 533 |
534 SCOPED_TRACE(testing::Message() << test_case.path); | 534 SCOPED_TRACE(testing::Message() << test_case.path); |
535 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 535 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
536 | 536 |
537 // Truncate to 0. | 537 // Truncate to 0. |
538 base::File::Info info; | 538 base::File::Info info; |
539 base::FilePath platform_path; | 539 base::FilePath platform_path; |
540 EXPECT_EQ(base::File::FILE_OK, | 540 EXPECT_EQ(base::File::FILE_OK, |
541 file_util()->Truncate(GetOperationContext().get(), url, 0)); | 541 file_util()->Truncate(GetOperationContext().get(), url, 0)); |
542 ASSERT_EQ(base::File::FILE_OK, | 542 ASSERT_EQ(base::File::FILE_OK, |
543 file_util()->GetFileInfo(GetOperationContext().get(), url, | 543 file_util()->GetFileInfo(GetOperationContext().get(), url, |
544 &info, &platform_path)); | 544 &info, &platform_path)); |
545 EXPECT_EQ(0, info.size); | 545 EXPECT_EQ(0, info.size); |
546 | 546 |
547 // Truncate (extend) to 999. | 547 // Truncate (extend) to 999. |
548 EXPECT_EQ(base::File::FILE_OK, | 548 EXPECT_EQ(base::File::FILE_OK, |
549 file_util()->Truncate(GetOperationContext().get(), url, 999)); | 549 file_util()->Truncate(GetOperationContext().get(), url, 999)); |
550 ASSERT_EQ(base::File::FILE_OK, | 550 ASSERT_EQ(base::File::FILE_OK, |
551 file_util()->GetFileInfo(GetOperationContext().get(), url, | 551 file_util()->GetFileInfo(GetOperationContext().get(), url, |
552 &info, &platform_path)); | 552 &info, &platform_path)); |
553 EXPECT_EQ(999, info.size); | 553 EXPECT_EQ(999, info.size); |
554 } | 554 } |
555 } | 555 } |
556 | 556 |
557 } // namespace content | 557 } // namespace content |
OLD | NEW |