| 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/test_file_system_context.h" | 18 #include "content/public/test/test_file_system_context.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "webkit/browser/fileapi/async_file_test_helper.h" | 20 #include "webkit/browser/fileapi/async_file_test_helper.h" |
| 21 #include "webkit/browser/fileapi/dragged_file_util.h" | 21 #include "webkit/browser/fileapi/dragged_file_util.h" |
| 22 #include "webkit/browser/fileapi/file_system_context.h" | 22 #include "webkit/browser/fileapi/file_system_context.h" |
| 23 #include "webkit/browser/fileapi/file_system_operation_context.h" | 23 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 24 #include "webkit/browser/fileapi/isolated_context.h" | 24 #include "webkit/browser/fileapi/isolated_context.h" |
| 25 #include "webkit/browser/fileapi/local_file_util.h" | 25 #include "webkit/browser/fileapi/local_file_util.h" |
| 26 #include "webkit/browser/fileapi/native_file_util.h" | 26 #include "webkit/browser/fileapi/native_file_util.h" |
| 27 #include "webkit/browser/fileapi/test_file_set.h" | 27 #include "webkit/browser/fileapi/test_file_set.h" |
| 28 | 28 |
| 29 namespace fileapi { | 29 using fileapi::AsyncFileTestHelper; |
| 30 using fileapi::FileSystemContext; |
| 31 using fileapi::FileSystemOperationContext; |
| 32 using fileapi::FileSystemType; |
| 33 using fileapi::FileSystemURL; |
| 34 |
| 35 namespace content { |
| 30 | 36 |
| 31 namespace { | 37 namespace { |
| 32 | 38 |
| 33 typedef AsyncFileTestHelper::FileEntryList FileEntryList; | 39 typedef AsyncFileTestHelper::FileEntryList FileEntryList; |
| 34 | 40 |
| 35 // Used in DraggedFileUtilTest::SimulateDropFiles(). | 41 // Used in DraggedFileUtilTest::SimulateDropFiles(). |
| 36 // Random root paths in which we create each file/directory of the | 42 // Random root paths in which we create each file/directory of the |
| 37 // RegularTestCases (so that we can simulate a drop with files/directories | 43 // RegularTestCases (so that we can simulate a drop with files/directories |
| 38 // from multiple directories). | 44 // from multiple directories). |
| 39 static const base::FilePath::CharType* kRootPaths[] = { | 45 static const base::FilePath::CharType* kRootPaths[] = { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 93 |
| 88 } // namespace | 94 } // namespace |
| 89 | 95 |
| 90 class DraggedFileUtilTest : public testing::Test { | 96 class DraggedFileUtilTest : public testing::Test { |
| 91 public: | 97 public: |
| 92 DraggedFileUtilTest() {} | 98 DraggedFileUtilTest() {} |
| 93 | 99 |
| 94 virtual void SetUp() { | 100 virtual void SetUp() { |
| 95 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 101 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 96 ASSERT_TRUE(partition_dir_.CreateUniqueTempDir()); | 102 ASSERT_TRUE(partition_dir_.CreateUniqueTempDir()); |
| 97 file_util_.reset(new DraggedFileUtil()); | 103 file_util_.reset(new fileapi::DraggedFileUtil()); |
| 98 | 104 |
| 99 // Register the files/directories of RegularTestCases (with random | 105 // Register the files/directories of RegularTestCases (with random |
| 100 // root paths) as dropped files. | 106 // root paths) as dropped files. |
| 101 SimulateDropFiles(); | 107 SimulateDropFiles(); |
| 102 | 108 |
| 103 file_system_context_ = CreateFileSystemContextForTesting( | 109 file_system_context_ = CreateFileSystemContextForTesting( |
| 104 NULL /* quota_manager */, | 110 NULL /* quota_manager */, |
| 105 partition_dir_.path()); | 111 partition_dir_.path()); |
| 106 | 112 |
| 107 isolated_context()->AddReference(filesystem_id_); | 113 isolated_context()->AddReference(filesystem_id_); |
| 108 } | 114 } |
| 109 | 115 |
| 110 virtual void TearDown() { | 116 virtual void TearDown() { |
| 111 isolated_context()->RemoveReference(filesystem_id_); | 117 isolated_context()->RemoveReference(filesystem_id_); |
| 112 } | 118 } |
| 113 | 119 |
| 114 protected: | 120 protected: |
| 115 IsolatedContext* isolated_context() const { | 121 fileapi::IsolatedContext* isolated_context() const { |
| 116 return IsolatedContext::GetInstance(); | 122 return fileapi::IsolatedContext::GetInstance(); |
| 117 } | 123 } |
| 118 const base::FilePath& root_path() const { | 124 const base::FilePath& root_path() const { |
| 119 return data_dir_.path(); | 125 return data_dir_.path(); |
| 120 } | 126 } |
| 121 FileSystemContext* file_system_context() const { | 127 FileSystemContext* file_system_context() const { |
| 122 return file_system_context_.get(); | 128 return file_system_context_.get(); |
| 123 } | 129 } |
| 124 FileSystemFileUtil* file_util() const { return file_util_.get(); } | 130 fileapi::FileSystemFileUtil* file_util() const { return file_util_.get(); } |
| 125 std::string filesystem_id() const { return filesystem_id_; } | 131 std::string filesystem_id() const { return filesystem_id_; } |
| 126 | 132 |
| 127 base::FilePath GetTestCasePlatformPath( | 133 base::FilePath GetTestCasePlatformPath( |
| 128 const base::FilePath::StringType& path) { | 134 const base::FilePath::StringType& path) { |
| 129 return toplevel_root_map_[GetTopLevelPath(base::FilePath(path))] | 135 return toplevel_root_map_[GetTopLevelPath(base::FilePath(path))] |
| 130 .Append(path).NormalizePathSeparators(); | 136 .Append(path).NormalizePathSeparators(); |
| 131 } | 137 } |
| 132 | 138 |
| 133 base::FilePath GetTestCaseLocalPath(const base::FilePath& path) { | 139 base::FilePath GetTestCaseLocalPath(const base::FilePath& path) { |
| 134 base::FilePath relative; | 140 base::FilePath relative; |
| 135 if (data_dir_.path().AppendRelativePath(path, &relative)) | 141 if (data_dir_.path().AppendRelativePath(path, &relative)) |
| 136 return relative; | 142 return relative; |
| 137 return path; | 143 return path; |
| 138 } | 144 } |
| 139 | 145 |
| 140 FileSystemURL GetFileSystemURL(const base::FilePath& path) const { | 146 FileSystemURL GetFileSystemURL(const base::FilePath& path) const { |
| 141 base::FilePath virtual_path = isolated_context()->CreateVirtualRootPath( | 147 base::FilePath virtual_path = isolated_context()->CreateVirtualRootPath( |
| 142 filesystem_id()).Append(path); | 148 filesystem_id()).Append(path); |
| 143 return file_system_context_->CreateCrackedFileSystemURL( | 149 return file_system_context_->CreateCrackedFileSystemURL( |
| 144 GURL("http://example.com"), | 150 GURL("http://example.com"), |
| 145 kFileSystemTypeIsolated, | 151 fileapi::kFileSystemTypeIsolated, |
| 146 virtual_path); | 152 virtual_path); |
| 147 } | 153 } |
| 148 | 154 |
| 149 FileSystemURL GetOtherFileSystemURL(const base::FilePath& path) const { | 155 FileSystemURL GetOtherFileSystemURL(const base::FilePath& path) const { |
| 150 return file_system_context()->CreateCrackedFileSystemURL( | 156 return file_system_context()->CreateCrackedFileSystemURL( |
| 151 GURL("http://example.com"), | 157 GURL("http://example.com"), |
| 152 kFileSystemTypeTemporary, | 158 fileapi::kFileSystemTypeTemporary, |
| 153 base::FilePath().AppendASCII("dest").Append(path)); | 159 base::FilePath().AppendASCII("dest").Append(path)); |
| 154 } | 160 } |
| 155 | 161 |
| 156 void VerifyFilesHaveSameContent(const FileSystemURL& url1, | 162 void VerifyFilesHaveSameContent(const FileSystemURL& url1, |
| 157 const FileSystemURL& url2) { | 163 const FileSystemURL& url2) { |
| 158 // Get the file info and the platform path for url1. | 164 // Get the file info and the platform path for url1. |
| 159 base::PlatformFileInfo info1; | 165 base::PlatformFileInfo info1; |
| 160 ASSERT_EQ(base::PLATFORM_FILE_OK, | 166 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 161 AsyncFileTestHelper::GetMetadata( | 167 AsyncFileTestHelper::GetMetadata( |
| 162 file_system_context(), url1, &info1)); | 168 file_system_context(), url1, &info1)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 IsDirectoryEmpty(file_system_context(), url2)); | 240 IsDirectoryEmpty(file_system_context(), url2)); |
| 235 continue; | 241 continue; |
| 236 } | 242 } |
| 237 base::FilePath relative = GetRelativeVirtualPath(root2, url2); | 243 base::FilePath relative = GetRelativeVirtualPath(root2, url2); |
| 238 EXPECT_TRUE(file_set1.find(relative) != file_set1.end()); | 244 EXPECT_TRUE(file_set1.find(relative) != file_set1.end()); |
| 239 VerifyFilesHaveSameContent(url1, url2); | 245 VerifyFilesHaveSameContent(url1, url2); |
| 240 } | 246 } |
| 241 } | 247 } |
| 242 } | 248 } |
| 243 | 249 |
| 244 scoped_ptr<FileSystemOperationContext> GetOperationContext() { | 250 scoped_ptr<fileapi::FileSystemOperationContext> GetOperationContext() { |
| 245 return make_scoped_ptr( | 251 return make_scoped_ptr( |
| 246 new FileSystemOperationContext(file_system_context())).Pass(); | 252 new fileapi::FileSystemOperationContext(file_system_context())).Pass(); |
| 247 } | 253 } |
| 248 | 254 |
| 249 | 255 |
| 250 private: | 256 private: |
| 251 void SimulateDropFiles() { | 257 void SimulateDropFiles() { |
| 252 size_t root_path_index = 0; | 258 size_t root_path_index = 0; |
| 253 | 259 |
| 254 IsolatedContext::FileInfoSet toplevels; | 260 fileapi::IsolatedContext::FileInfoSet toplevels; |
| 255 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 261 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { |
| 256 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 262 const fileapi::test::TestCaseRecord& test_case = |
| 263 fileapi::test::kRegularTestCases[i]; |
| 257 base::FilePath path(test_case.path); | 264 base::FilePath path(test_case.path); |
| 258 base::FilePath toplevel = GetTopLevelPath(path); | 265 base::FilePath toplevel = GetTopLevelPath(path); |
| 259 | 266 |
| 260 // We create the test case files under one of the kRootPaths | 267 // We create the test case files under one of the kRootPaths |
| 261 // to simulate a drop with multiple directories. | 268 // to simulate a drop with multiple directories. |
| 262 if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) { | 269 if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) { |
| 263 base::FilePath root = root_path().Append( | 270 base::FilePath root = root_path().Append( |
| 264 kRootPaths[(root_path_index++) % arraysize(kRootPaths)]); | 271 kRootPaths[(root_path_index++) % arraysize(kRootPaths)]); |
| 265 toplevel_root_map_[toplevel] = root; | 272 toplevel_root_map_[toplevel] = root; |
| 266 toplevels.AddPath(root.Append(path), NULL); | 273 toplevels.AddPath(root.Append(path), NULL); |
| 267 } | 274 } |
| 268 | 275 |
| 269 test::SetUpOneTestCase(toplevel_root_map_[toplevel], test_case); | 276 fileapi::test::SetUpOneTestCase(toplevel_root_map_[toplevel], test_case); |
| 270 } | 277 } |
| 271 | 278 |
| 272 // Register the toplevel entries. | 279 // Register the toplevel entries. |
| 273 filesystem_id_ = isolated_context()->RegisterDraggedFileSystem(toplevels); | 280 filesystem_id_ = isolated_context()->RegisterDraggedFileSystem(toplevels); |
| 274 } | 281 } |
| 275 | 282 |
| 276 base::ScopedTempDir data_dir_; | 283 base::ScopedTempDir data_dir_; |
| 277 base::ScopedTempDir partition_dir_; | 284 base::ScopedTempDir partition_dir_; |
| 278 base::MessageLoopForIO message_loop_; | 285 base::MessageLoopForIO message_loop_; |
| 279 std::string filesystem_id_; | 286 std::string filesystem_id_; |
| 280 scoped_refptr<FileSystemContext> file_system_context_; | 287 scoped_refptr<FileSystemContext> file_system_context_; |
| 281 std::map<base::FilePath, base::FilePath> toplevel_root_map_; | 288 std::map<base::FilePath, base::FilePath> toplevel_root_map_; |
| 282 scoped_ptr<DraggedFileUtil> file_util_; | 289 scoped_ptr<fileapi::DraggedFileUtil> file_util_; |
| 283 DISALLOW_COPY_AND_ASSIGN(DraggedFileUtilTest); | 290 DISALLOW_COPY_AND_ASSIGN(DraggedFileUtilTest); |
| 284 }; | 291 }; |
| 285 | 292 |
| 286 TEST_F(DraggedFileUtilTest, BasicTest) { | 293 TEST_F(DraggedFileUtilTest, BasicTest) { |
| 287 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 294 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { |
| 288 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i); | 295 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i); |
| 289 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 296 const fileapi::test::TestCaseRecord& test_case = |
| 297 fileapi::test::kRegularTestCases[i]; |
| 290 | 298 |
| 291 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 299 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
| 292 | 300 |
| 293 // 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. |
| 294 // (This should succeed since we have registered all the top-level | 302 // (This should succeed since we have registered all the top-level |
| 295 // entries of the test cases in SetUp()) | 303 // entries of the test cases in SetUp()) |
| 296 base::PlatformFileInfo info; | 304 base::PlatformFileInfo info; |
| 297 base::FilePath platform_path; | 305 base::FilePath platform_path; |
| 298 FileSystemOperationContext context(file_system_context()); | 306 FileSystemOperationContext context(file_system_context()); |
| 299 ASSERT_EQ(base::PLATFORM_FILE_OK, | 307 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 312 static const fileapi::test::TestCaseRecord kUnregisteredCases[] = { | 320 static const fileapi::test::TestCaseRecord kUnregisteredCases[] = { |
| 313 {true, FILE_PATH_LITERAL("nonexistent"), 0}, | 321 {true, FILE_PATH_LITERAL("nonexistent"), 0}, |
| 314 {true, FILE_PATH_LITERAL("nonexistent/dir foo"), 0}, | 322 {true, FILE_PATH_LITERAL("nonexistent/dir foo"), 0}, |
| 315 {false, FILE_PATH_LITERAL("nonexistent/false"), 0}, | 323 {false, FILE_PATH_LITERAL("nonexistent/false"), 0}, |
| 316 {false, FILE_PATH_LITERAL("foo"), 30}, | 324 {false, FILE_PATH_LITERAL("foo"), 30}, |
| 317 {false, FILE_PATH_LITERAL("bar"), 20}, | 325 {false, FILE_PATH_LITERAL("bar"), 20}, |
| 318 }; | 326 }; |
| 319 | 327 |
| 320 for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) { | 328 for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) { |
| 321 SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i); | 329 SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i); |
| 322 const test::TestCaseRecord& test_case = kUnregisteredCases[i]; | 330 const fileapi::test::TestCaseRecord& test_case = kUnregisteredCases[i]; |
| 323 | 331 |
| 324 // Prepare the test file/directory. | 332 // Prepare the test file/directory. |
| 325 SetUpOneTestCase(root_path(), test_case); | 333 SetUpOneTestCase(root_path(), test_case); |
| 326 | 334 |
| 327 // Make sure regular GetFileInfo succeeds. | 335 // Make sure regular GetFileInfo succeeds. |
| 328 base::File::Info info; | 336 base::File::Info info; |
| 329 ASSERT_TRUE(base::GetFileInfo(root_path().Append(test_case.path), &info)); | 337 ASSERT_TRUE(base::GetFileInfo(root_path().Append(test_case.path), &info)); |
| 330 if (!test_case.is_directory) | 338 if (!test_case.is_directory) |
| 331 ASSERT_EQ(test_case.data_file_size, info.size); | 339 ASSERT_EQ(test_case.data_file_size, info.size); |
| 332 ASSERT_EQ(test_case.is_directory, info.is_directory); | 340 ASSERT_EQ(test_case.is_directory, info.is_directory); |
| 333 } | 341 } |
| 334 | 342 |
| 335 for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) { | 343 for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) { |
| 336 SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i); | 344 SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i); |
| 337 const test::TestCaseRecord& test_case = kUnregisteredCases[i]; | 345 const fileapi::test::TestCaseRecord& test_case = kUnregisteredCases[i]; |
| 338 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 346 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
| 339 | 347 |
| 340 // 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. |
| 341 ASSERT_FALSE(url.is_valid()); | 349 ASSERT_FALSE(url.is_valid()); |
| 342 } | 350 } |
| 343 } | 351 } |
| 344 | 352 |
| 345 TEST_F(DraggedFileUtilTest, ReadDirectoryTest) { | 353 TEST_F(DraggedFileUtilTest, ReadDirectoryTest) { |
| 346 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 354 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { |
| 347 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 355 const fileapi::test::TestCaseRecord& test_case = |
| 356 fileapi::test::kRegularTestCases[i]; |
| 348 if (!test_case.is_directory) | 357 if (!test_case.is_directory) |
| 349 continue; | 358 continue; |
| 350 | 359 |
| 351 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i | 360 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i |
| 352 << ": " << test_case.path); | 361 << ": " << test_case.path); |
| 353 | 362 |
| 354 // Read entries in the directory to construct the expected results map. | 363 // Read entries in the directory to construct the expected results map. |
| 355 typedef std::map<base::FilePath::StringType, DirectoryEntry> EntryMap; | 364 typedef std::map<base::FilePath::StringType, fileapi::DirectoryEntry> |
| 365 EntryMap; |
| 356 EntryMap expected_entry_map; | 366 EntryMap expected_entry_map; |
| 357 | 367 |
| 358 base::FilePath dir_path = GetTestCasePlatformPath(test_case.path); | 368 base::FilePath dir_path = GetTestCasePlatformPath(test_case.path); |
| 359 base::FileEnumerator file_enum( | 369 base::FileEnumerator file_enum( |
| 360 dir_path, false /* not recursive */, | 370 dir_path, false /* not recursive */, |
| 361 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES); | 371 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES); |
| 362 base::FilePath current; | 372 base::FilePath current; |
| 363 while (!(current = file_enum.Next()).empty()) { | 373 while (!(current = file_enum.Next()).empty()) { |
| 364 base::FileEnumerator::FileInfo file_info = file_enum.GetInfo(); | 374 base::FileEnumerator::FileInfo file_info = file_enum.GetInfo(); |
| 365 DirectoryEntry entry; | 375 fileapi::DirectoryEntry entry; |
| 366 entry.is_directory = file_info.IsDirectory(); | 376 entry.is_directory = file_info.IsDirectory(); |
| 367 entry.name = current.BaseName().value(); | 377 entry.name = current.BaseName().value(); |
| 368 entry.size = file_info.GetSize(); | 378 entry.size = file_info.GetSize(); |
| 369 entry.last_modified_time = file_info.GetLastModifiedTime(); | 379 entry.last_modified_time = file_info.GetLastModifiedTime(); |
| 370 expected_entry_map[entry.name] = entry; | 380 expected_entry_map[entry.name] = entry; |
| 371 | 381 |
| 372 #if defined(OS_POSIX) | 382 #if defined(OS_POSIX) |
| 373 // Creates a symlink for each file/directory. | 383 // Creates a symlink for each file/directory. |
| 374 // They should be ignored by ReadDirectory, so we don't add them | 384 // They should be ignored by ReadDirectory, so we don't add them |
| 375 // to expected_entry_map. | 385 // to expected_entry_map. |
| 376 base::CreateSymbolicLink( | 386 base::CreateSymbolicLink( |
| 377 current, | 387 current, |
| 378 dir_path.Append(current.BaseName().AddExtension( | 388 dir_path.Append(current.BaseName().AddExtension( |
| 379 FILE_PATH_LITERAL("link")))); | 389 FILE_PATH_LITERAL("link")))); |
| 380 #endif | 390 #endif |
| 381 } | 391 } |
| 382 | 392 |
| 383 // Perform ReadDirectory in the isolated filesystem. | 393 // Perform ReadDirectory in the isolated filesystem. |
| 384 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 394 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
| 385 FileEntryList entries; | 395 FileEntryList entries; |
| 386 ASSERT_EQ(base::PLATFORM_FILE_OK, | 396 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 387 AsyncFileTestHelper::ReadDirectory( | 397 AsyncFileTestHelper::ReadDirectory( |
| 388 file_system_context(), url, &entries)); | 398 file_system_context(), url, &entries)); |
| 389 | 399 |
| 390 EXPECT_EQ(expected_entry_map.size(), entries.size()); | 400 EXPECT_EQ(expected_entry_map.size(), entries.size()); |
| 391 for (size_t i = 0; i < entries.size(); ++i) { | 401 for (size_t i = 0; i < entries.size(); ++i) { |
| 392 const DirectoryEntry& entry = entries[i]; | 402 const fileapi::DirectoryEntry& entry = entries[i]; |
| 393 EntryMap::iterator found = expected_entry_map.find(entry.name); | 403 EntryMap::iterator found = expected_entry_map.find(entry.name); |
| 394 EXPECT_TRUE(found != expected_entry_map.end()); | 404 EXPECT_TRUE(found != expected_entry_map.end()); |
| 395 EXPECT_EQ(found->second.name, entry.name); | 405 EXPECT_EQ(found->second.name, entry.name); |
| 396 EXPECT_EQ(found->second.is_directory, entry.is_directory); | 406 EXPECT_EQ(found->second.is_directory, entry.is_directory); |
| 397 EXPECT_EQ(found->second.size, entry.size); | 407 EXPECT_EQ(found->second.size, entry.size); |
| 398 EXPECT_EQ(found->second.last_modified_time.ToDoubleT(), | 408 EXPECT_EQ(found->second.last_modified_time.ToDoubleT(), |
| 399 entry.last_modified_time.ToDoubleT()); | 409 entry.last_modified_time.ToDoubleT()); |
| 400 } | 410 } |
| 401 } | 411 } |
| 402 } | 412 } |
| 403 | 413 |
| 404 TEST_F(DraggedFileUtilTest, GetLocalFilePathTest) { | 414 TEST_F(DraggedFileUtilTest, GetLocalFilePathTest) { |
| 405 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 415 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { |
| 406 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 416 const fileapi::test::TestCaseRecord& test_case = |
| 417 fileapi::test::kRegularTestCases[i]; |
| 407 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 418 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
| 408 | 419 |
| 409 FileSystemOperationContext context(file_system_context()); | 420 FileSystemOperationContext context(file_system_context()); |
| 410 | 421 |
| 411 base::FilePath local_file_path; | 422 base::FilePath local_file_path; |
| 412 EXPECT_EQ(base::PLATFORM_FILE_OK, | 423 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 413 file_util()->GetLocalFilePath(&context, url, &local_file_path)); | 424 file_util()->GetLocalFilePath(&context, url, &local_file_path)); |
| 414 EXPECT_EQ(GetTestCasePlatformPath(test_case.path).value(), | 425 EXPECT_EQ(GetTestCasePlatformPath(test_case.path).value(), |
| 415 local_file_path.value()); | 426 local_file_path.value()); |
| 416 } | 427 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 SCOPED_TRACE(testing::Message() << "Testing file copy " | 490 SCOPED_TRACE(testing::Message() << "Testing file copy " |
| 480 << src_url.path().value()); | 491 << src_url.path().value()); |
| 481 ASSERT_EQ(base::PLATFORM_FILE_OK, | 492 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 482 AsyncFileTestHelper::Copy(file_system_context(), | 493 AsyncFileTestHelper::Copy(file_system_context(), |
| 483 src_url, dest_url)); | 494 src_url, dest_url)); |
| 484 VerifyDirectoriesHaveSameContent(src_url, dest_url); | 495 VerifyDirectoriesHaveSameContent(src_url, dest_url); |
| 485 } | 496 } |
| 486 } | 497 } |
| 487 | 498 |
| 488 TEST_F(DraggedFileUtilTest, TouchTest) { | 499 TEST_F(DraggedFileUtilTest, TouchTest) { |
| 489 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 500 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { |
| 490 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 501 const fileapi::test::TestCaseRecord& test_case = |
| 502 fileapi::test::kRegularTestCases[i]; |
| 491 if (test_case.is_directory) | 503 if (test_case.is_directory) |
| 492 continue; | 504 continue; |
| 493 SCOPED_TRACE(testing::Message() << test_case.path); | 505 SCOPED_TRACE(testing::Message() << test_case.path); |
| 494 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 506 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
| 495 | 507 |
| 496 base::Time last_access_time = base::Time::FromTimeT(1000); | 508 base::Time last_access_time = base::Time::FromTimeT(1000); |
| 497 base::Time last_modified_time = base::Time::FromTimeT(2000); | 509 base::Time last_modified_time = base::Time::FromTimeT(2000); |
| 498 | 510 |
| 499 EXPECT_EQ(base::PLATFORM_FILE_OK, | 511 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 500 file_util()->Touch(GetOperationContext().get(), url, | 512 file_util()->Touch(GetOperationContext().get(), url, |
| 501 last_access_time, | 513 last_access_time, |
| 502 last_modified_time)); | 514 last_modified_time)); |
| 503 | 515 |
| 504 // Verification. | 516 // Verification. |
| 505 base::PlatformFileInfo info; | 517 base::PlatformFileInfo info; |
| 506 base::FilePath platform_path; | 518 base::FilePath platform_path; |
| 507 ASSERT_EQ(base::PLATFORM_FILE_OK, | 519 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 508 file_util()->GetFileInfo(GetOperationContext().get(), url, | 520 file_util()->GetFileInfo(GetOperationContext().get(), url, |
| 509 &info, &platform_path)); | 521 &info, &platform_path)); |
| 510 EXPECT_EQ(last_access_time.ToTimeT(), info.last_accessed.ToTimeT()); | 522 EXPECT_EQ(last_access_time.ToTimeT(), info.last_accessed.ToTimeT()); |
| 511 EXPECT_EQ(last_modified_time.ToTimeT(), info.last_modified.ToTimeT()); | 523 EXPECT_EQ(last_modified_time.ToTimeT(), info.last_modified.ToTimeT()); |
| 512 } | 524 } |
| 513 } | 525 } |
| 514 | 526 |
| 515 TEST_F(DraggedFileUtilTest, TruncateTest) { | 527 TEST_F(DraggedFileUtilTest, TruncateTest) { |
| 516 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 528 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { |
| 517 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 529 const fileapi::test::TestCaseRecord& test_case = |
| 530 fileapi::test::kRegularTestCases[i]; |
| 518 if (test_case.is_directory) | 531 if (test_case.is_directory) |
| 519 continue; | 532 continue; |
| 520 | 533 |
| 521 SCOPED_TRACE(testing::Message() << test_case.path); | 534 SCOPED_TRACE(testing::Message() << test_case.path); |
| 522 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 535 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
| 523 | 536 |
| 524 // Truncate to 0. | 537 // Truncate to 0. |
| 525 base::PlatformFileInfo info; | 538 base::PlatformFileInfo info; |
| 526 base::FilePath platform_path; | 539 base::FilePath platform_path; |
| 527 EXPECT_EQ(base::PLATFORM_FILE_OK, | 540 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 528 file_util()->Truncate(GetOperationContext().get(), url, 0)); | 541 file_util()->Truncate(GetOperationContext().get(), url, 0)); |
| 529 ASSERT_EQ(base::PLATFORM_FILE_OK, | 542 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 530 file_util()->GetFileInfo(GetOperationContext().get(), url, | 543 file_util()->GetFileInfo(GetOperationContext().get(), url, |
| 531 &info, &platform_path)); | 544 &info, &platform_path)); |
| 532 EXPECT_EQ(0, info.size); | 545 EXPECT_EQ(0, info.size); |
| 533 | 546 |
| 534 // Truncate (extend) to 999. | 547 // Truncate (extend) to 999. |
| 535 EXPECT_EQ(base::PLATFORM_FILE_OK, | 548 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 536 file_util()->Truncate(GetOperationContext().get(), url, 999)); | 549 file_util()->Truncate(GetOperationContext().get(), url, 999)); |
| 537 ASSERT_EQ(base::PLATFORM_FILE_OK, | 550 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 538 file_util()->GetFileInfo(GetOperationContext().get(), url, | 551 file_util()->GetFileInfo(GetOperationContext().get(), url, |
| 539 &info, &platform_path)); | 552 &info, &platform_path)); |
| 540 EXPECT_EQ(999, info.size); | 553 EXPECT_EQ(999, info.size); |
| 541 } | 554 } |
| 542 } | 555 } |
| 543 | 556 |
| 544 } // namespace fileapi | 557 } // namespace content |
| OLD | NEW |