| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
| 12 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "webkit/fileapi/async_file_test_helper.h" |
| 15 #include "webkit/fileapi/file_system_context.h" | 16 #include "webkit/fileapi/file_system_context.h" |
| 16 #include "webkit/fileapi/file_system_file_util.h" | 17 #include "webkit/fileapi/file_system_file_util.h" |
| 17 #include "webkit/fileapi/file_system_operation_context.h" | 18 #include "webkit/fileapi/file_system_operation_context.h" |
| 18 #include "webkit/fileapi/file_system_types.h" | 19 #include "webkit/fileapi/file_system_types.h" |
| 19 #include "webkit/fileapi/local_file_system_test_helper.h" | 20 #include "webkit/fileapi/local_file_system_test_helper.h" |
| 20 #include "webkit/fileapi/local_file_util.h" | 21 #include "webkit/fileapi/local_file_util.h" |
| 21 #include "webkit/fileapi/native_file_util.h" | 22 #include "webkit/fileapi/native_file_util.h" |
| 22 | 23 |
| 23 namespace fileapi { | 24 namespace fileapi { |
| 24 | 25 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 88 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| 88 return FileUtil()->EnsureFileExists( | 89 return FileUtil()->EnsureFileExists( |
| 89 context.get(), | 90 context.get(), |
| 90 Path(file_name), created); | 91 Path(file_name), created); |
| 91 } | 92 } |
| 92 | 93 |
| 93 const LocalFileSystemTestOriginHelper& test_helper() const { | 94 const LocalFileSystemTestOriginHelper& test_helper() const { |
| 94 return test_helper_; | 95 return test_helper_; |
| 95 } | 96 } |
| 96 | 97 |
| 98 FileSystemContext* file_system_context() { |
| 99 return test_helper_.file_system_context(); |
| 100 } |
| 101 |
| 97 private: | 102 private: |
| 98 scoped_ptr<LocalFileUtil> local_file_util_; | 103 scoped_ptr<LocalFileUtil> local_file_util_; |
| 99 base::ScopedTempDir data_dir_; | 104 base::ScopedTempDir data_dir_; |
| 100 MessageLoop message_loop_; | 105 MessageLoop message_loop_; |
| 101 LocalFileSystemTestOriginHelper test_helper_; | 106 LocalFileSystemTestOriginHelper test_helper_; |
| 102 | 107 |
| 103 DISALLOW_COPY_AND_ASSIGN(LocalFileUtilTest); | 108 DISALLOW_COPY_AND_ASSIGN(LocalFileUtilTest); |
| 104 }; | 109 }; |
| 105 | 110 |
| 106 TEST_F(LocalFileUtilTest, CreateAndClose) { | 111 TEST_F(LocalFileUtilTest, CreateAndClose) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 ASSERT_TRUE(created); | 216 ASSERT_TRUE(created); |
| 212 | 217 |
| 213 scoped_ptr<FileSystemOperationContext> context; | 218 scoped_ptr<FileSystemOperationContext> context; |
| 214 context.reset(NewContext()); | 219 context.reset(NewContext()); |
| 215 ASSERT_EQ(base::PLATFORM_FILE_OK, | 220 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 216 FileUtil()->Truncate(context.get(), Path(from_file), 1020)); | 221 FileUtil()->Truncate(context.get(), Path(from_file), 1020)); |
| 217 | 222 |
| 218 EXPECT_TRUE(FileExists(from_file)); | 223 EXPECT_TRUE(FileExists(from_file)); |
| 219 EXPECT_EQ(1020, GetSize(from_file)); | 224 EXPECT_EQ(1020, GetSize(from_file)); |
| 220 | 225 |
| 221 context.reset(NewContext()); | |
| 222 ASSERT_EQ(base::PLATFORM_FILE_OK, | 226 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 223 test_helper().SameFileUtilCopy(context.get(), | 227 AsyncFileTestHelper::Copy(file_system_context(), |
| 224 Path(from_file), Path(to_file1))); | 228 Path(from_file), Path(to_file1))); |
| 225 | 229 |
| 226 context.reset(NewContext()); | 230 context.reset(NewContext()); |
| 227 ASSERT_EQ(base::PLATFORM_FILE_OK, | 231 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 228 test_helper().SameFileUtilCopy(context.get(), | 232 AsyncFileTestHelper::Copy(file_system_context(), |
| 229 Path(from_file), Path(to_file2))); | 233 Path(from_file), Path(to_file2))); |
| 230 | 234 |
| 231 EXPECT_TRUE(FileExists(from_file)); | 235 EXPECT_TRUE(FileExists(from_file)); |
| 232 EXPECT_EQ(1020, GetSize(from_file)); | 236 EXPECT_EQ(1020, GetSize(from_file)); |
| 233 EXPECT_TRUE(FileExists(to_file1)); | 237 EXPECT_TRUE(FileExists(to_file1)); |
| 234 EXPECT_EQ(1020, GetSize(to_file1)); | 238 EXPECT_EQ(1020, GetSize(to_file1)); |
| 235 EXPECT_TRUE(FileExists(to_file2)); | 239 EXPECT_TRUE(FileExists(to_file2)); |
| 236 EXPECT_EQ(1020, GetSize(to_file2)); | 240 EXPECT_EQ(1020, GetSize(to_file2)); |
| 237 } | 241 } |
| 238 | 242 |
| 239 TEST_F(LocalFileUtilTest, CopyDirectory) { | 243 TEST_F(LocalFileUtilTest, CopyDirectory) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 254 ASSERT_EQ(base::PLATFORM_FILE_OK, | 258 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 255 FileUtil()->Truncate(context.get(), Path(from_file), 1020)); | 259 FileUtil()->Truncate(context.get(), Path(from_file), 1020)); |
| 256 | 260 |
| 257 EXPECT_TRUE(DirectoryExists(from_dir)); | 261 EXPECT_TRUE(DirectoryExists(from_dir)); |
| 258 EXPECT_TRUE(FileExists(from_file)); | 262 EXPECT_TRUE(FileExists(from_file)); |
| 259 EXPECT_EQ(1020, GetSize(from_file)); | 263 EXPECT_EQ(1020, GetSize(from_file)); |
| 260 EXPECT_FALSE(DirectoryExists(to_dir)); | 264 EXPECT_FALSE(DirectoryExists(to_dir)); |
| 261 | 265 |
| 262 context.reset(NewContext()); | 266 context.reset(NewContext()); |
| 263 ASSERT_EQ(base::PLATFORM_FILE_OK, | 267 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 264 test_helper().SameFileUtilCopy(context.get(), | 268 AsyncFileTestHelper::Copy(file_system_context(), |
| 265 Path(from_dir), Path(to_dir))); | 269 Path(from_dir), Path(to_dir))); |
| 266 | 270 |
| 267 EXPECT_TRUE(DirectoryExists(from_dir)); | 271 EXPECT_TRUE(DirectoryExists(from_dir)); |
| 268 EXPECT_TRUE(FileExists(from_file)); | 272 EXPECT_TRUE(FileExists(from_file)); |
| 269 EXPECT_EQ(1020, GetSize(from_file)); | 273 EXPECT_EQ(1020, GetSize(from_file)); |
| 270 EXPECT_TRUE(DirectoryExists(to_dir)); | 274 EXPECT_TRUE(DirectoryExists(to_dir)); |
| 271 EXPECT_TRUE(FileExists(to_file)); | 275 EXPECT_TRUE(FileExists(to_file)); |
| 272 EXPECT_EQ(1020, GetSize(to_file)); | 276 EXPECT_EQ(1020, GetSize(to_file)); |
| 273 } | 277 } |
| 274 | 278 |
| 275 TEST_F(LocalFileUtilTest, MoveFile) { | 279 TEST_F(LocalFileUtilTest, MoveFile) { |
| 276 const char *from_file = "fromfile"; | 280 const char *from_file = "fromfile"; |
| 277 const char *to_file = "tofile"; | 281 const char *to_file = "tofile"; |
| 278 bool created; | 282 bool created; |
| 279 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created)); | 283 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created)); |
| 280 ASSERT_TRUE(created); | 284 ASSERT_TRUE(created); |
| 281 scoped_ptr<FileSystemOperationContext> context; | 285 scoped_ptr<FileSystemOperationContext> context; |
| 282 | 286 |
| 283 context.reset(NewContext()); | 287 context.reset(NewContext()); |
| 284 ASSERT_EQ(base::PLATFORM_FILE_OK, | 288 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 285 FileUtil()->Truncate(context.get(), Path(from_file), 1020)); | 289 FileUtil()->Truncate(context.get(), Path(from_file), 1020)); |
| 286 | 290 |
| 287 EXPECT_TRUE(FileExists(from_file)); | 291 EXPECT_TRUE(FileExists(from_file)); |
| 288 EXPECT_EQ(1020, GetSize(from_file)); | 292 EXPECT_EQ(1020, GetSize(from_file)); |
| 289 | 293 |
| 290 context.reset(NewContext()); | 294 context.reset(NewContext()); |
| 291 ASSERT_EQ(base::PLATFORM_FILE_OK, | 295 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 292 test_helper().SameFileUtilMove(context.get(), | 296 AsyncFileTestHelper::Move(file_system_context(), |
| 293 Path(from_file), Path(to_file))); | 297 Path(from_file), Path(to_file))); |
| 294 | 298 |
| 295 EXPECT_FALSE(FileExists(from_file)); | 299 EXPECT_FALSE(FileExists(from_file)); |
| 296 EXPECT_TRUE(FileExists(to_file)); | 300 EXPECT_TRUE(FileExists(to_file)); |
| 297 EXPECT_EQ(1020, GetSize(to_file)); | 301 EXPECT_EQ(1020, GetSize(to_file)); |
| 298 } | 302 } |
| 299 | 303 |
| 300 TEST_F(LocalFileUtilTest, MoveDirectory) { | 304 TEST_F(LocalFileUtilTest, MoveDirectory) { |
| 301 const char *from_dir = "fromdir"; | 305 const char *from_dir = "fromdir"; |
| 302 const char *from_file = "fromdir/fromfile"; | 306 const char *from_file = "fromdir/fromfile"; |
| 303 const char *to_dir = "todir"; | 307 const char *to_dir = "todir"; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 315 ASSERT_EQ(base::PLATFORM_FILE_OK, | 319 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 316 FileUtil()->Truncate(context.get(), Path(from_file), 1020)); | 320 FileUtil()->Truncate(context.get(), Path(from_file), 1020)); |
| 317 | 321 |
| 318 EXPECT_TRUE(DirectoryExists(from_dir)); | 322 EXPECT_TRUE(DirectoryExists(from_dir)); |
| 319 EXPECT_TRUE(FileExists(from_file)); | 323 EXPECT_TRUE(FileExists(from_file)); |
| 320 EXPECT_EQ(1020, GetSize(from_file)); | 324 EXPECT_EQ(1020, GetSize(from_file)); |
| 321 EXPECT_FALSE(DirectoryExists(to_dir)); | 325 EXPECT_FALSE(DirectoryExists(to_dir)); |
| 322 | 326 |
| 323 context.reset(NewContext()); | 327 context.reset(NewContext()); |
| 324 ASSERT_EQ(base::PLATFORM_FILE_OK, | 328 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 325 test_helper().SameFileUtilMove(context.get(), | 329 AsyncFileTestHelper::Move(file_system_context(), |
| 326 Path(from_dir), Path(to_dir))); | 330 Path(from_dir), Path(to_dir))); |
| 327 | 331 |
| 328 EXPECT_FALSE(DirectoryExists(from_dir)); | 332 EXPECT_FALSE(DirectoryExists(from_dir)); |
| 329 EXPECT_TRUE(DirectoryExists(to_dir)); | 333 EXPECT_TRUE(DirectoryExists(to_dir)); |
| 330 EXPECT_TRUE(FileExists(to_file)); | 334 EXPECT_TRUE(FileExists(to_file)); |
| 331 EXPECT_EQ(1020, GetSize(to_file)); | 335 EXPECT_EQ(1020, GetSize(to_file)); |
| 332 } | 336 } |
| 333 | 337 |
| 334 } // namespace fileapi | 338 } // namespace fileapi |
| OLD | NEW |