| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/platform_file.h" | 7 #include "base/platform_file.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "webkit/chromeos/fileapi/memory_file_util.h" | 10 #include "webkit/chromeos/fileapi/memory_file_util.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 const FilePath::CharType kRootPath[] = "/mnt/memory"; | 13 const base::FilePath::CharType kRootPath[] = "/mnt/memory"; |
| 14 const char kTestString[] = "A test string. A test string."; | 14 const char kTestString[] = "A test string. A test string."; |
| 15 const char kTestStringLength = arraysize(kTestString) - 1; | 15 const char kTestStringLength = arraysize(kTestString) - 1; |
| 16 } // namespace | 16 } // namespace |
| 17 | 17 |
| 18 namespace fileapi { | 18 namespace fileapi { |
| 19 | 19 |
| 20 // This test is actually testing MemoryFileUtil — an async in-memory file | 20 // This test is actually testing MemoryFileUtil — an async in-memory file |
| 21 // system, based on FileUtilAsync. | 21 // system, based on FileUtilAsync. |
| 22 class MemoryFileUtilTest : public testing::Test { | 22 class MemoryFileUtilTest : public testing::Test { |
| 23 public: | 23 public: |
| 24 MemoryFileUtilTest() : max_request_id_(0) { | 24 MemoryFileUtilTest() : max_request_id_(0) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 ~MemoryFileUtilTest() { | 27 ~MemoryFileUtilTest() { |
| 28 for (std::map<int, CallbackStatus>::iterator iter = status_map_.begin(); | 28 for (std::map<int, CallbackStatus>::iterator iter = status_map_.begin(); |
| 29 iter != status_map_.end(); | 29 iter != status_map_.end(); |
| 30 ++iter) { | 30 ++iter) { |
| 31 delete iter->second.file_stream; | 31 delete iter->second.file_stream; |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 void SetUp() { | 35 void SetUp() { |
| 36 file_util_.reset(new MemoryFileUtil(FilePath(kRootPath))); | 36 file_util_.reset(new MemoryFileUtil(base::FilePath(kRootPath))); |
| 37 } | 37 } |
| 38 | 38 |
| 39 MemoryFileUtil* file_util() { | 39 MemoryFileUtil* file_util() { |
| 40 return file_util_.get(); | 40 return file_util_.get(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 enum CallbackType { | 43 enum CallbackType { |
| 44 CALLBACK_TYPE_ERROR, | 44 CALLBACK_TYPE_ERROR, |
| 45 CALLBACK_TYPE_STATUS, | 45 CALLBACK_TYPE_STATUS, |
| 46 CALLBACK_TYPE_GET_FILE_INFO, | 46 CALLBACK_TYPE_GET_FILE_INFO, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 request_id); | 98 request_id); |
| 99 } | 99 } |
| 100 | 100 |
| 101 FileUtilAsync::ReadDirectoryCallback GetReadDirectoryCallback( | 101 FileUtilAsync::ReadDirectoryCallback GetReadDirectoryCallback( |
| 102 int request_id) { | 102 int request_id) { |
| 103 return base::Bind(&MemoryFileUtilTest::ReadDirectoryCallback, | 103 return base::Bind(&MemoryFileUtilTest::ReadDirectoryCallback, |
| 104 base::Unretained(this), | 104 base::Unretained(this), |
| 105 request_id); | 105 request_id); |
| 106 } | 106 } |
| 107 | 107 |
| 108 int CreateEmptyFile(const FilePath& file_path) { | 108 int CreateEmptyFile(const base::FilePath& file_path) { |
| 109 int request_id = GetNextRequestId(); | 109 int request_id = GetNextRequestId(); |
| 110 file_util_->Create(file_path, GetStatusCallback(request_id)); | 110 file_util_->Create(file_path, GetStatusCallback(request_id)); |
| 111 return request_id; | 111 return request_id; |
| 112 } | 112 } |
| 113 | 113 |
| 114 int CreateNonEmptyFile(const FilePath& file_path, | 114 int CreateNonEmptyFile(const base::FilePath& file_path, |
| 115 const char* data, | 115 const char* data, |
| 116 int length) { | 116 int length) { |
| 117 int request_id = GetNextRequestId(); | 117 int request_id = GetNextRequestId(); |
| 118 file_util_->Open( | 118 file_util_->Open( |
| 119 file_path, | 119 file_path, |
| 120 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, | 120 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, |
| 121 base::Bind(&MemoryFileUtilTest::WriteToOpenedFile, | 121 base::Bind(&MemoryFileUtilTest::WriteToOpenedFile, |
| 122 base::Unretained(this), | 122 base::Unretained(this), |
| 123 request_id, data, length)); | 123 request_id, data, length)); |
| 124 return request_id; | 124 return request_id; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 227 |
| 228 scoped_ptr<MemoryFileUtil> file_util_; | 228 scoped_ptr<MemoryFileUtil> file_util_; |
| 229 std::map<int, CallbackStatus> status_map_; | 229 std::map<int, CallbackStatus> status_map_; |
| 230 int max_request_id_; | 230 int max_request_id_; |
| 231 | 231 |
| 232 DISALLOW_COPY_AND_ASSIGN(MemoryFileUtilTest); | 232 DISALLOW_COPY_AND_ASSIGN(MemoryFileUtilTest); |
| 233 }; | 233 }; |
| 234 | 234 |
| 235 TEST_F(MemoryFileUtilTest, TestCreateGetFileInfo) { | 235 TEST_F(MemoryFileUtilTest, TestCreateGetFileInfo) { |
| 236 const int request_id1 = GetNextRequestId(); | 236 const int request_id1 = GetNextRequestId(); |
| 237 file_util()->GetFileInfo(FilePath("/mnt/memory/test.txt"), | 237 file_util()->GetFileInfo(base::FilePath("/mnt/memory/test.txt"), |
| 238 GetGetFileInfoCallback(request_id1)); | 238 GetGetFileInfoCallback(request_id1)); |
| 239 | 239 |
| 240 // In case the file system is truely asynchronous, RunAllPending is not | 240 // In case the file system is truely asynchronous, RunAllPending is not |
| 241 // enough to wait for answer. In that case the thread should be blocked | 241 // enough to wait for answer. In that case the thread should be blocked |
| 242 // until the callback is called (ex. use Run() instead here, and call | 242 // until the callback is called (ex. use Run() instead here, and call |
| 243 // Quit() from callback). | 243 // Quit() from callback). |
| 244 MessageLoop::current()->RunUntilIdle(); | 244 MessageLoop::current()->RunUntilIdle(); |
| 245 | 245 |
| 246 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id1)); | 246 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id1)); |
| 247 CallbackStatus status = GetStatus(request_id1); | 247 CallbackStatus status = GetStatus(request_id1); |
| 248 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status.result); | 248 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status.result); |
| 249 | 249 |
| 250 base::Time start_create = base::Time::Now(); | 250 base::Time start_create = base::Time::Now(); |
| 251 | 251 |
| 252 const int request_id2 = GetNextRequestId(); | 252 const int request_id2 = GetNextRequestId(); |
| 253 file_util()->Create(FilePath("/mnt/memory/test.txt"), | 253 file_util()->Create(base::FilePath("/mnt/memory/test.txt"), |
| 254 GetStatusCallback(request_id2)); | 254 GetStatusCallback(request_id2)); |
| 255 MessageLoop::current()->RunUntilIdle(); | 255 MessageLoop::current()->RunUntilIdle(); |
| 256 ASSERT_EQ(CALLBACK_TYPE_STATUS, GetStatusType(request_id2)); | 256 ASSERT_EQ(CALLBACK_TYPE_STATUS, GetStatusType(request_id2)); |
| 257 status = GetStatus(request_id2); | 257 status = GetStatus(request_id2); |
| 258 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 258 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 259 | 259 |
| 260 const int request_id3 = GetNextRequestId(); | 260 const int request_id3 = GetNextRequestId(); |
| 261 file_util()->GetFileInfo(FilePath("/mnt/memory/test.txt"), | 261 file_util()->GetFileInfo(base::FilePath("/mnt/memory/test.txt"), |
| 262 GetGetFileInfoCallback(request_id3)); | 262 GetGetFileInfoCallback(request_id3)); |
| 263 MessageLoop::current()->RunUntilIdle(); | 263 MessageLoop::current()->RunUntilIdle(); |
| 264 | 264 |
| 265 base::Time end_create = base::Time::Now(); | 265 base::Time end_create = base::Time::Now(); |
| 266 | 266 |
| 267 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id3)); | 267 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id3)); |
| 268 status = GetStatus(request_id3); | 268 status = GetStatus(request_id3); |
| 269 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 269 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 270 ASSERT_EQ(0, status.file_info.size); | 270 ASSERT_EQ(0, status.file_info.size); |
| 271 ASSERT_FALSE(status.file_info.is_directory); | 271 ASSERT_FALSE(status.file_info.is_directory); |
| 272 ASSERT_FALSE(status.file_info.is_symbolic_link); | 272 ASSERT_FALSE(status.file_info.is_symbolic_link); |
| 273 ASSERT_GE(status.file_info.last_modified, start_create); | 273 ASSERT_GE(status.file_info.last_modified, start_create); |
| 274 ASSERT_LE(status.file_info.last_modified, end_create); | 274 ASSERT_LE(status.file_info.last_modified, end_create); |
| 275 ASSERT_GE(status.file_info.creation_time, start_create); | 275 ASSERT_GE(status.file_info.creation_time, start_create); |
| 276 ASSERT_LE(status.file_info.creation_time, end_create); | 276 ASSERT_LE(status.file_info.creation_time, end_create); |
| 277 } | 277 } |
| 278 | 278 |
| 279 TEST_F(MemoryFileUtilTest, TestReadWrite) { | 279 TEST_F(MemoryFileUtilTest, TestReadWrite) { |
| 280 // Check that the file does not exist. | 280 // Check that the file does not exist. |
| 281 | 281 |
| 282 const int request_id1 = GetNextRequestId(); | 282 const int request_id1 = GetNextRequestId(); |
| 283 file_util()->GetFileInfo(FilePath("/mnt/memory/test1.txt"), | 283 file_util()->GetFileInfo(base::FilePath("/mnt/memory/test1.txt"), |
| 284 GetGetFileInfoCallback(request_id1)); | 284 GetGetFileInfoCallback(request_id1)); |
| 285 | 285 |
| 286 MessageLoop::current()->RunUntilIdle(); | 286 MessageLoop::current()->RunUntilIdle(); |
| 287 | 287 |
| 288 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id1)); | 288 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id1)); |
| 289 CallbackStatus status = GetStatus(request_id1); | 289 CallbackStatus status = GetStatus(request_id1); |
| 290 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status.result); | 290 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status.result); |
| 291 | 291 |
| 292 // Create & open file for writing. | 292 // Create & open file for writing. |
| 293 | 293 |
| 294 base::Time start_create = base::Time::Now(); | 294 base::Time start_create = base::Time::Now(); |
| 295 const int request_id2 = GetNextRequestId(); | 295 const int request_id2 = GetNextRequestId(); |
| 296 file_util()->Open(FilePath("/mnt/memory/test1.txt"), | 296 file_util()->Open(base::FilePath("/mnt/memory/test1.txt"), |
| 297 base::PLATFORM_FILE_CREATE_ALWAYS | | 297 base::PLATFORM_FILE_CREATE_ALWAYS | |
| 298 base::PLATFORM_FILE_WRITE, | 298 base::PLATFORM_FILE_WRITE, |
| 299 GetOpenCallback(request_id2)); | 299 GetOpenCallback(request_id2)); |
| 300 MessageLoop::current()->RunUntilIdle(); | 300 MessageLoop::current()->RunUntilIdle(); |
| 301 | 301 |
| 302 base::Time end_create = base::Time::Now(); | 302 base::Time end_create = base::Time::Now(); |
| 303 | 303 |
| 304 ASSERT_EQ(CALLBACK_TYPE_OPEN, GetStatusType(request_id2)); | 304 ASSERT_EQ(CALLBACK_TYPE_OPEN, GetStatusType(request_id2)); |
| 305 status = GetStatus(request_id2); | 305 status = GetStatus(request_id2); |
| 306 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 306 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 307 | 307 |
| 308 AsyncFileStream* write_file_stream = status.file_stream; | 308 AsyncFileStream* write_file_stream = status.file_stream; |
| 309 | 309 |
| 310 // Check that file was created and has 0 size. | 310 // Check that file was created and has 0 size. |
| 311 | 311 |
| 312 const int request_id3 = GetNextRequestId(); | 312 const int request_id3 = GetNextRequestId(); |
| 313 file_util()->GetFileInfo(FilePath("/mnt/memory/test1.txt"), | 313 file_util()->GetFileInfo(base::FilePath("/mnt/memory/test1.txt"), |
| 314 GetGetFileInfoCallback(request_id3)); | 314 GetGetFileInfoCallback(request_id3)); |
| 315 MessageLoop::current()->RunUntilIdle(); | 315 MessageLoop::current()->RunUntilIdle(); |
| 316 | 316 |
| 317 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id3)); | 317 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id3)); |
| 318 status = GetStatus(request_id3); | 318 status = GetStatus(request_id3); |
| 319 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 319 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 320 ASSERT_EQ(0, status.file_info.size); | 320 ASSERT_EQ(0, status.file_info.size); |
| 321 ASSERT_FALSE(status.file_info.is_directory); | 321 ASSERT_FALSE(status.file_info.is_directory); |
| 322 ASSERT_FALSE(status.file_info.is_symbolic_link); | 322 ASSERT_FALSE(status.file_info.is_symbolic_link); |
| 323 ASSERT_GE(status.file_info.last_modified, start_create); | 323 ASSERT_GE(status.file_info.last_modified, start_create); |
| 324 ASSERT_LE(status.file_info.last_modified, end_create); | 324 ASSERT_LE(status.file_info.last_modified, end_create); |
| 325 | 325 |
| 326 // Write 10 bytes to file. | 326 // Write 10 bytes to file. |
| 327 | 327 |
| 328 const int request_id4 = GetNextRequestId(); | 328 const int request_id4 = GetNextRequestId(); |
| 329 base::Time start_write = base::Time::Now(); | 329 base::Time start_write = base::Time::Now(); |
| 330 write_file_stream->Write(kTestString, 10, | 330 write_file_stream->Write(kTestString, 10, |
| 331 GetReadWriteCallback(request_id4)); | 331 GetReadWriteCallback(request_id4)); |
| 332 MessageLoop::current()->RunUntilIdle(); | 332 MessageLoop::current()->RunUntilIdle(); |
| 333 base::Time end_write = base::Time::Now(); | 333 base::Time end_write = base::Time::Now(); |
| 334 | 334 |
| 335 ASSERT_EQ(CALLBACK_TYPE_READ_WRITE, GetStatusType(request_id4)); | 335 ASSERT_EQ(CALLBACK_TYPE_READ_WRITE, GetStatusType(request_id4)); |
| 336 status = GetStatus(request_id4); | 336 status = GetStatus(request_id4); |
| 337 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 337 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 338 ASSERT_EQ(10, status.length); | 338 ASSERT_EQ(10, status.length); |
| 339 | 339 |
| 340 // Check that the file has now size 10 and correct modification time. | 340 // Check that the file has now size 10 and correct modification time. |
| 341 | 341 |
| 342 const int request_id5 = GetNextRequestId(); | 342 const int request_id5 = GetNextRequestId(); |
| 343 file_util()->GetFileInfo(FilePath("/mnt/memory/test1.txt"), | 343 file_util()->GetFileInfo(base::FilePath("/mnt/memory/test1.txt"), |
| 344 GetGetFileInfoCallback(request_id5)); | 344 GetGetFileInfoCallback(request_id5)); |
| 345 MessageLoop::current()->RunUntilIdle(); | 345 MessageLoop::current()->RunUntilIdle(); |
| 346 | 346 |
| 347 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id5)); | 347 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id5)); |
| 348 status = GetStatus(request_id5); | 348 status = GetStatus(request_id5); |
| 349 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 349 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 350 ASSERT_EQ(10, status.file_info.size); | 350 ASSERT_EQ(10, status.file_info.size); |
| 351 ASSERT_GE(status.file_info.last_modified, start_write); | 351 ASSERT_GE(status.file_info.last_modified, start_write); |
| 352 ASSERT_LE(status.file_info.last_modified, end_write); | 352 ASSERT_LE(status.file_info.last_modified, end_write); |
| 353 | 353 |
| 354 // Write the rest of the string to file. | 354 // Write the rest of the string to file. |
| 355 | 355 |
| 356 const int request_id6 = GetNextRequestId(); | 356 const int request_id6 = GetNextRequestId(); |
| 357 start_write = base::Time::Now(); | 357 start_write = base::Time::Now(); |
| 358 write_file_stream->Write(kTestString + 10, | 358 write_file_stream->Write(kTestString + 10, |
| 359 kTestStringLength - 10, | 359 kTestStringLength - 10, |
| 360 GetReadWriteCallback(request_id6)); | 360 GetReadWriteCallback(request_id6)); |
| 361 MessageLoop::current()->RunUntilIdle(); | 361 MessageLoop::current()->RunUntilIdle(); |
| 362 end_write = base::Time::Now(); | 362 end_write = base::Time::Now(); |
| 363 | 363 |
| 364 ASSERT_EQ(CALLBACK_TYPE_READ_WRITE, GetStatusType(request_id6)); | 364 ASSERT_EQ(CALLBACK_TYPE_READ_WRITE, GetStatusType(request_id6)); |
| 365 status = GetStatus(request_id6); | 365 status = GetStatus(request_id6); |
| 366 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 366 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 367 ASSERT_EQ(static_cast<int64>(kTestStringLength) - 10, status.length); | 367 ASSERT_EQ(static_cast<int64>(kTestStringLength) - 10, status.length); |
| 368 | 368 |
| 369 // Check the file size & modification time. | 369 // Check the file size & modification time. |
| 370 | 370 |
| 371 const int request_id7 = GetNextRequestId(); | 371 const int request_id7 = GetNextRequestId(); |
| 372 file_util()->GetFileInfo(FilePath("/mnt/memory/test1.txt"), | 372 file_util()->GetFileInfo(base::FilePath("/mnt/memory/test1.txt"), |
| 373 GetGetFileInfoCallback(request_id7)); | 373 GetGetFileInfoCallback(request_id7)); |
| 374 MessageLoop::current()->RunUntilIdle(); | 374 MessageLoop::current()->RunUntilIdle(); |
| 375 | 375 |
| 376 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id7)); | 376 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id7)); |
| 377 status = GetStatus(request_id7); | 377 status = GetStatus(request_id7); |
| 378 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 378 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 379 ASSERT_EQ(static_cast<int64>(kTestStringLength), status.file_info.size); | 379 ASSERT_EQ(static_cast<int64>(kTestStringLength), status.file_info.size); |
| 380 ASSERT_GE(status.file_info.last_modified, start_write); | 380 ASSERT_GE(status.file_info.last_modified, start_write); |
| 381 ASSERT_LE(status.file_info.last_modified, end_write); | 381 ASSERT_LE(status.file_info.last_modified, end_write); |
| 382 | 382 |
| 383 // Open file for reading. | 383 // Open file for reading. |
| 384 | 384 |
| 385 const int request_id8 = GetNextRequestId(); | 385 const int request_id8 = GetNextRequestId(); |
| 386 file_util()->Open(FilePath("/mnt/memory/test1.txt"), | 386 file_util()->Open(base::FilePath("/mnt/memory/test1.txt"), |
| 387 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, | 387 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, |
| 388 GetOpenCallback(request_id8)); | 388 GetOpenCallback(request_id8)); |
| 389 MessageLoop::current()->RunUntilIdle(); | 389 MessageLoop::current()->RunUntilIdle(); |
| 390 | 390 |
| 391 ASSERT_EQ(CALLBACK_TYPE_OPEN, GetStatusType(request_id8)); | 391 ASSERT_EQ(CALLBACK_TYPE_OPEN, GetStatusType(request_id8)); |
| 392 status = GetStatus(request_id8); | 392 status = GetStatus(request_id8); |
| 393 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 393 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 394 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 394 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 395 | 395 |
| 396 AsyncFileStream* read_file_stream = status.file_stream; | 396 AsyncFileStream* read_file_stream = status.file_stream; |
| 397 | 397 |
| 398 // Read the whole file | 398 // Read the whole file |
| 399 char buffer[1024]; | 399 char buffer[1024]; |
| 400 const int request_id9 = GetNextRequestId(); | 400 const int request_id9 = GetNextRequestId(); |
| 401 read_file_stream->Read(buffer, 1023, GetReadWriteCallback(request_id9)); | 401 read_file_stream->Read(buffer, 1023, GetReadWriteCallback(request_id9)); |
| 402 MessageLoop::current()->RunUntilIdle(); | 402 MessageLoop::current()->RunUntilIdle(); |
| 403 | 403 |
| 404 ASSERT_EQ(CALLBACK_TYPE_READ_WRITE, GetStatusType(request_id9)); | 404 ASSERT_EQ(CALLBACK_TYPE_READ_WRITE, GetStatusType(request_id9)); |
| 405 status = GetStatus(request_id9); | 405 status = GetStatus(request_id9); |
| 406 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 406 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 407 ASSERT_EQ(static_cast<int64>(kTestStringLength), status.length); | 407 ASSERT_EQ(static_cast<int64>(kTestStringLength), status.length); |
| 408 | 408 |
| 409 buffer[status.length] = '\0'; | 409 buffer[status.length] = '\0'; |
| 410 std::string result_string(buffer); | 410 std::string result_string(buffer); |
| 411 ASSERT_EQ(kTestString, result_string); | 411 ASSERT_EQ(kTestString, result_string); |
| 412 | 412 |
| 413 // Check that size & modification time have not changed. | 413 // Check that size & modification time have not changed. |
| 414 | 414 |
| 415 const int request_id10 = GetNextRequestId(); | 415 const int request_id10 = GetNextRequestId(); |
| 416 file_util()->GetFileInfo(FilePath("/mnt/memory/test1.txt"), | 416 file_util()->GetFileInfo(base::FilePath("/mnt/memory/test1.txt"), |
| 417 GetGetFileInfoCallback(request_id10)); | 417 GetGetFileInfoCallback(request_id10)); |
| 418 MessageLoop::current()->RunUntilIdle(); | 418 MessageLoop::current()->RunUntilIdle(); |
| 419 | 419 |
| 420 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id10)); | 420 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id10)); |
| 421 status = GetStatus(request_id10); | 421 status = GetStatus(request_id10); |
| 422 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 422 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 423 ASSERT_EQ(static_cast<int64>(kTestStringLength), status.file_info.size); | 423 ASSERT_EQ(static_cast<int64>(kTestStringLength), status.file_info.size); |
| 424 ASSERT_GE(status.file_info.last_modified, start_write); | 424 ASSERT_GE(status.file_info.last_modified, start_write); |
| 425 ASSERT_LE(status.file_info.last_modified, end_write); | 425 ASSERT_LE(status.file_info.last_modified, end_write); |
| 426 | 426 |
| 427 // Open once more for writing. | 427 // Open once more for writing. |
| 428 | 428 |
| 429 const int request_id11 = GetNextRequestId(); | 429 const int request_id11 = GetNextRequestId(); |
| 430 file_util()->Open(FilePath("/mnt/memory/test1.txt"), | 430 file_util()->Open(base::FilePath("/mnt/memory/test1.txt"), |
| 431 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, | 431 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, |
| 432 GetOpenCallback(request_id11)); | 432 GetOpenCallback(request_id11)); |
| 433 MessageLoop::current()->RunUntilIdle(); | 433 MessageLoop::current()->RunUntilIdle(); |
| 434 | 434 |
| 435 ASSERT_EQ(CALLBACK_TYPE_OPEN, GetStatusType(request_id11)); | 435 ASSERT_EQ(CALLBACK_TYPE_OPEN, GetStatusType(request_id11)); |
| 436 status = GetStatus(request_id11); | 436 status = GetStatus(request_id11); |
| 437 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 437 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 438 | 438 |
| 439 AsyncFileStream* write_file_stream2 = status.file_stream; | 439 AsyncFileStream* write_file_stream2 = status.file_stream; |
| 440 | 440 |
| 441 // Check that the size has not changed. | 441 // Check that the size has not changed. |
| 442 | 442 |
| 443 const int request_id12 = GetNextRequestId(); | 443 const int request_id12 = GetNextRequestId(); |
| 444 file_util()->GetFileInfo(FilePath("/mnt/memory/test1.txt"), | 444 file_util()->GetFileInfo(base::FilePath("/mnt/memory/test1.txt"), |
| 445 GetGetFileInfoCallback(request_id12)); | 445 GetGetFileInfoCallback(request_id12)); |
| 446 MessageLoop::current()->RunUntilIdle(); | 446 MessageLoop::current()->RunUntilIdle(); |
| 447 | 447 |
| 448 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id12)); | 448 ASSERT_EQ(CALLBACK_TYPE_GET_FILE_INFO, GetStatusType(request_id12)); |
| 449 status = GetStatus(request_id12); | 449 status = GetStatus(request_id12); |
| 450 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 450 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 451 ASSERT_EQ(static_cast<int64>(kTestStringLength), status.file_info.size); | 451 ASSERT_EQ(static_cast<int64>(kTestStringLength), status.file_info.size); |
| 452 | 452 |
| 453 // Seek beyond the end of file. Should return error. | 453 // Seek beyond the end of file. Should return error. |
| 454 | 454 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 482 kTestStringLength, | 482 kTestStringLength, |
| 483 GetReadWriteCallback(request_id16)); | 483 GetReadWriteCallback(request_id16)); |
| 484 MessageLoop::current()->RunUntilIdle(); | 484 MessageLoop::current()->RunUntilIdle(); |
| 485 status = GetStatus(request_id16); | 485 status = GetStatus(request_id16); |
| 486 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 486 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 487 ASSERT_EQ(static_cast<int64>(kTestStringLength), status.length); | 487 ASSERT_EQ(static_cast<int64>(kTestStringLength), status.length); |
| 488 | 488 |
| 489 // Check size. | 489 // Check size. |
| 490 | 490 |
| 491 const int request_id17 = GetNextRequestId(); | 491 const int request_id17 = GetNextRequestId(); |
| 492 file_util()->GetFileInfo(FilePath("/mnt/memory/test1.txt"), | 492 file_util()->GetFileInfo(base::FilePath("/mnt/memory/test1.txt"), |
| 493 GetGetFileInfoCallback(request_id17)); | 493 GetGetFileInfoCallback(request_id17)); |
| 494 MessageLoop::current()->RunUntilIdle(); | 494 MessageLoop::current()->RunUntilIdle(); |
| 495 status = GetStatus(request_id17); | 495 status = GetStatus(request_id17); |
| 496 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); | 496 ASSERT_EQ(base::PLATFORM_FILE_OK, status.result); |
| 497 ASSERT_EQ(static_cast<int64>(kTestStringLength) + 10, | 497 ASSERT_EQ(static_cast<int64>(kTestStringLength) + 10, |
| 498 status.file_info.size); | 498 status.file_info.size); |
| 499 | 499 |
| 500 // Read from 10th byte. | 500 // Read from 10th byte. |
| 501 const int request_id18 = GetNextRequestId(); | 501 const int request_id18 = GetNextRequestId(); |
| 502 read_file_stream->Seek(10, GetStatusCallback(request_id18)); | 502 read_file_stream->Seek(10, GetStatusCallback(request_id18)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 524 // /mnt/memory/b/e 0 | 524 // /mnt/memory/b/e 0 |
| 525 // /mnt/memory/b/f kTestStringLength | 525 // /mnt/memory/b/f kTestStringLength |
| 526 // /mnt/memory/b/g/ | 526 // /mnt/memory/b/g/ |
| 527 // /mnt/memory/b/g/h 0 | 527 // /mnt/memory/b/g/h 0 |
| 528 // /mnt/memory/b/i kTestStringLength | 528 // /mnt/memory/b/i kTestStringLength |
| 529 // /mnt/memory/c/ | 529 // /mnt/memory/c/ |
| 530 // /mnt/memory/longer_file_name.txt kTestStringLength | 530 // /mnt/memory/longer_file_name.txt kTestStringLength |
| 531 TEST_F(MemoryFileUtilTest, TestDirectoryOperations) { | 531 TEST_F(MemoryFileUtilTest, TestDirectoryOperations) { |
| 532 // Check the directory is empty. | 532 // Check the directory is empty. |
| 533 const int request_id0 = GetNextRequestId(); | 533 const int request_id0 = GetNextRequestId(); |
| 534 file_util()->ReadDirectory(FilePath("/mnt/memory/"), | 534 file_util()->ReadDirectory(base::FilePath("/mnt/memory/"), |
| 535 GetReadDirectoryCallback(request_id0)); | 535 GetReadDirectoryCallback(request_id0)); |
| 536 | 536 |
| 537 MessageLoop::current()->RunUntilIdle(); | 537 MessageLoop::current()->RunUntilIdle(); |
| 538 | 538 |
| 539 ASSERT_EQ(CALLBACK_TYPE_READ_DIRECTORY, GetStatusType(request_id0)); | 539 ASSERT_EQ(CALLBACK_TYPE_READ_DIRECTORY, GetStatusType(request_id0)); |
| 540 CallbackStatus& status = GetStatus(request_id0); | 540 CallbackStatus& status = GetStatus(request_id0); |
| 541 ASSERT_TRUE(status.completed); | 541 ASSERT_TRUE(status.completed); |
| 542 ASSERT_FALSE(status.called_after_completed); | 542 ASSERT_FALSE(status.called_after_completed); |
| 543 ASSERT_EQ(1, status.called); | 543 ASSERT_EQ(1, status.called); |
| 544 ASSERT_EQ(0u, status.entries.size()); | 544 ASSERT_EQ(0u, status.entries.size()); |
| 545 | 545 |
| 546 // Create /mnt/memory/a, /mnt/memory/b/, /mnt/memory/longer_file_name.txt, | 546 // Create /mnt/memory/a, /mnt/memory/b/, /mnt/memory/longer_file_name.txt, |
| 547 // /mnt/memory/c/ asyncronously (i.e. we do not wait for each operation to | 547 // /mnt/memory/c/ asyncronously (i.e. we do not wait for each operation to |
| 548 // complete before starting the next one. | 548 // complete before starting the next one. |
| 549 | 549 |
| 550 base::Time start_create = base::Time::Now(); | 550 base::Time start_create = base::Time::Now(); |
| 551 CreateEmptyFile(FilePath("/mnt/memory/a")); | 551 CreateEmptyFile(base::FilePath("/mnt/memory/a")); |
| 552 | 552 |
| 553 int request_id1 = GetNextRequestId(); | 553 int request_id1 = GetNextRequestId(); |
| 554 file_util()->CreateDirectory(FilePath("/mnt/memory/b"), | 554 file_util()->CreateDirectory(base::FilePath("/mnt/memory/b"), |
| 555 GetStatusCallback(request_id1)); | 555 GetStatusCallback(request_id1)); |
| 556 | 556 |
| 557 CreateNonEmptyFile(FilePath("/mnt/memory/longer_file_name.txt"), | 557 CreateNonEmptyFile(base::FilePath("/mnt/memory/longer_file_name.txt"), |
| 558 kTestString, | 558 kTestString, |
| 559 kTestStringLength); | 559 kTestStringLength); |
| 560 | 560 |
| 561 int request_id2 = GetNextRequestId(); | 561 int request_id2 = GetNextRequestId(); |
| 562 file_util()->CreateDirectory(FilePath("/mnt/memory/c"), | 562 file_util()->CreateDirectory(base::FilePath("/mnt/memory/c"), |
| 563 GetStatusCallback(request_id2)); | 563 GetStatusCallback(request_id2)); |
| 564 | 564 |
| 565 MessageLoop::current()->RunUntilIdle(); | 565 MessageLoop::current()->RunUntilIdle(); |
| 566 base::Time end_create = base::Time::Now(); | 566 base::Time end_create = base::Time::Now(); |
| 567 | 567 |
| 568 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); | 568 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); |
| 569 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id2).result); | 569 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id2).result); |
| 570 | 570 |
| 571 // ReadDirectory /mnt/memory, /mnt/memory/a (not a dir), /mnt/memory/b/, | 571 // ReadDirectory /mnt/memory, /mnt/memory/a (not a dir), /mnt/memory/b/, |
| 572 // /mnt/memory/d (not found) | 572 // /mnt/memory/d (not found) |
| 573 | 573 |
| 574 set_read_directory_buffer_size(5); // Should complete in one go. | 574 set_read_directory_buffer_size(5); // Should complete in one go. |
| 575 | 575 |
| 576 request_id1 = GetNextRequestId(); | 576 request_id1 = GetNextRequestId(); |
| 577 file_util()->ReadDirectory(FilePath("/mnt/memory"), | 577 file_util()->ReadDirectory(base::FilePath("/mnt/memory"), |
| 578 GetReadDirectoryCallback(request_id1)); | 578 GetReadDirectoryCallback(request_id1)); |
| 579 request_id2 = GetNextRequestId(); | 579 request_id2 = GetNextRequestId(); |
| 580 file_util()->ReadDirectory(FilePath("/mnt/memory/a"), | 580 file_util()->ReadDirectory(base::FilePath("/mnt/memory/a"), |
| 581 GetReadDirectoryCallback(request_id2)); | 581 GetReadDirectoryCallback(request_id2)); |
| 582 const int request_id3 = GetNextRequestId(); | 582 const int request_id3 = GetNextRequestId(); |
| 583 file_util()->ReadDirectory(FilePath("/mnt/memory/b/"), | 583 file_util()->ReadDirectory(base::FilePath("/mnt/memory/b/"), |
| 584 GetReadDirectoryCallback(request_id3)); | 584 GetReadDirectoryCallback(request_id3)); |
| 585 const int request_id4 = GetNextRequestId(); | 585 const int request_id4 = GetNextRequestId(); |
| 586 file_util()->ReadDirectory(FilePath("/mnt/memory/d/"), | 586 file_util()->ReadDirectory(base::FilePath("/mnt/memory/d/"), |
| 587 GetReadDirectoryCallback(request_id4)); | 587 GetReadDirectoryCallback(request_id4)); |
| 588 | 588 |
| 589 MessageLoop::current()->RunUntilIdle(); | 589 MessageLoop::current()->RunUntilIdle(); |
| 590 | 590 |
| 591 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); | 591 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); |
| 592 status = GetStatus(request_id1); | 592 status = GetStatus(request_id1); |
| 593 ASSERT_TRUE(status.completed); | 593 ASSERT_TRUE(status.completed); |
| 594 ASSERT_FALSE(status.called_after_completed); | 594 ASSERT_FALSE(status.called_after_completed); |
| 595 ASSERT_EQ(1, status.called); // Because the number of entries < 5. | 595 ASSERT_EQ(1, status.called); // Because the number of entries < 5. |
| 596 ASSERT_EQ(4u, status.entries.size()); | 596 ASSERT_EQ(4u, status.entries.size()); |
| 597 | 597 |
| 598 std::set<FilePath::StringType> seen; | 598 std::set<base::FilePath::StringType> seen; |
| 599 | 599 |
| 600 for (FileUtilAsync::FileList::const_iterator it = status.entries.begin(); | 600 for (FileUtilAsync::FileList::const_iterator it = status.entries.begin(); |
| 601 it != status.entries.end(); | 601 it != status.entries.end(); |
| 602 ++it) { | 602 ++it) { |
| 603 ASSERT_LE(start_create, it->last_modified_time); | 603 ASSERT_LE(start_create, it->last_modified_time); |
| 604 ASSERT_GE(end_create, it->last_modified_time); | 604 ASSERT_GE(end_create, it->last_modified_time); |
| 605 | 605 |
| 606 ASSERT_EQ(seen.end(), seen.find(it->name)); | 606 ASSERT_EQ(seen.end(), seen.find(it->name)); |
| 607 seen.insert(it->name); | 607 seen.insert(it->name); |
| 608 | 608 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 637 // /mnt/memory/b/c kTestStringLength | 637 // /mnt/memory/b/c kTestStringLength |
| 638 // /mnt/memory/b/d/ | 638 // /mnt/memory/b/d/ |
| 639 // /mnt/memory/b/e 0 | 639 // /mnt/memory/b/e 0 |
| 640 // /mnt/memory/b/f kTestStringLength | 640 // /mnt/memory/b/f kTestStringLength |
| 641 // /mnt/memory/b/g/ | 641 // /mnt/memory/b/g/ |
| 642 // /mnt/memory/b/i kTestStringLength | 642 // /mnt/memory/b/i kTestStringLength |
| 643 // | 643 // |
| 644 // /mnt/memory/b/g/h 0 | 644 // /mnt/memory/b/g/h 0 |
| 645 | 645 |
| 646 start_create = base::Time::Now(); | 646 start_create = base::Time::Now(); |
| 647 CreateNonEmptyFile(FilePath("/mnt/memory/b/c"), | 647 CreateNonEmptyFile(base::FilePath("/mnt/memory/b/c"), |
| 648 kTestString, | 648 kTestString, |
| 649 kTestStringLength); | 649 kTestStringLength); |
| 650 request_id1 = GetNextRequestId(); | 650 request_id1 = GetNextRequestId(); |
| 651 file_util()->CreateDirectory(FilePath("/mnt/memory/b/d"), | 651 file_util()->CreateDirectory(base::FilePath("/mnt/memory/b/d"), |
| 652 GetStatusCallback(request_id1)); | 652 GetStatusCallback(request_id1)); |
| 653 CreateEmptyFile(FilePath("/mnt/memory/b/e")); | 653 CreateEmptyFile(base::FilePath("/mnt/memory/b/e")); |
| 654 CreateNonEmptyFile(FilePath("/mnt/memory/b/f"), | 654 CreateNonEmptyFile(base::FilePath("/mnt/memory/b/f"), |
| 655 kTestString, | 655 kTestString, |
| 656 kTestStringLength); | 656 kTestStringLength); |
| 657 request_id2 = GetNextRequestId(); | 657 request_id2 = GetNextRequestId(); |
| 658 file_util()->CreateDirectory(FilePath("/mnt/memory/b/g"), | 658 file_util()->CreateDirectory(base::FilePath("/mnt/memory/b/g"), |
| 659 GetStatusCallback(request_id1)); | 659 GetStatusCallback(request_id1)); |
| 660 CreateNonEmptyFile(FilePath("/mnt/memory/b/i"), | 660 CreateNonEmptyFile(base::FilePath("/mnt/memory/b/i"), |
| 661 kTestString, | 661 kTestString, |
| 662 kTestStringLength); | 662 kTestStringLength); |
| 663 | 663 |
| 664 MessageLoop::current()->RunUntilIdle(); | 664 MessageLoop::current()->RunUntilIdle(); |
| 665 | 665 |
| 666 CreateEmptyFile(FilePath("/mnt/memory/b/g/h")); | 666 CreateEmptyFile(base::FilePath("/mnt/memory/b/g/h")); |
| 667 | 667 |
| 668 MessageLoop::current()->RunUntilIdle(); | 668 MessageLoop::current()->RunUntilIdle(); |
| 669 end_create = base::Time::Now(); | 669 end_create = base::Time::Now(); |
| 670 | 670 |
| 671 // Read /mnt/memory and check that the number of entries is unchanged. | 671 // Read /mnt/memory and check that the number of entries is unchanged. |
| 672 | 672 |
| 673 request_id1 = GetNextRequestId(); | 673 request_id1 = GetNextRequestId(); |
| 674 file_util()->ReadDirectory(FilePath("/mnt/memory"), | 674 file_util()->ReadDirectory(base::FilePath("/mnt/memory"), |
| 675 GetReadDirectoryCallback(request_id1)); | 675 GetReadDirectoryCallback(request_id1)); |
| 676 | 676 |
| 677 MessageLoop::current()->RunUntilIdle(); | 677 MessageLoop::current()->RunUntilIdle(); |
| 678 | 678 |
| 679 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); | 679 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); |
| 680 status = GetStatus(request_id1); | 680 status = GetStatus(request_id1); |
| 681 ASSERT_TRUE(status.completed); | 681 ASSERT_TRUE(status.completed); |
| 682 ASSERT_FALSE(status.called_after_completed); | 682 ASSERT_FALSE(status.called_after_completed); |
| 683 ASSERT_EQ(1, status.called); // Because the number of entries < 5. | 683 ASSERT_EQ(1, status.called); // Because the number of entries < 5. |
| 684 ASSERT_EQ(4u, status.entries.size()); | 684 ASSERT_EQ(4u, status.entries.size()); |
| 685 | 685 |
| 686 // Read /mnt/memory/b | 686 // Read /mnt/memory/b |
| 687 | 687 |
| 688 request_id1 = GetNextRequestId(); | 688 request_id1 = GetNextRequestId(); |
| 689 file_util()->ReadDirectory(FilePath("/mnt/memory/b"), | 689 file_util()->ReadDirectory(base::FilePath("/mnt/memory/b"), |
| 690 GetReadDirectoryCallback(request_id1)); | 690 GetReadDirectoryCallback(request_id1)); |
| 691 | 691 |
| 692 MessageLoop::current()->RunUntilIdle(); | 692 MessageLoop::current()->RunUntilIdle(); |
| 693 | 693 |
| 694 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); | 694 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); |
| 695 status = GetStatus(request_id1); | 695 status = GetStatus(request_id1); |
| 696 ASSERT_TRUE(status.completed); | 696 ASSERT_TRUE(status.completed); |
| 697 ASSERT_FALSE(status.called_after_completed); | 697 ASSERT_FALSE(status.called_after_completed); |
| 698 ASSERT_EQ(2, status.called); // Because the number of entries > 5. | 698 ASSERT_EQ(2, status.called); // Because the number of entries > 5. |
| 699 ASSERT_EQ(6u, status.entries.size()); | 699 ASSERT_EQ(6u, status.entries.size()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 ASSERT_EQ(static_cast<int64>(kTestStringLength), it->size); | 734 ASSERT_EQ(static_cast<int64>(kTestStringLength), it->size); |
| 735 } else { | 735 } else { |
| 736 LOG(ERROR) << "Unexpected file: " << it->name; | 736 LOG(ERROR) << "Unexpected file: " << it->name; |
| 737 ASSERT_TRUE(false); | 737 ASSERT_TRUE(false); |
| 738 } | 738 } |
| 739 } | 739 } |
| 740 | 740 |
| 741 // Remove single file: /mnt/memory/b/f | 741 // Remove single file: /mnt/memory/b/f |
| 742 | 742 |
| 743 request_id1 = GetNextRequestId(); | 743 request_id1 = GetNextRequestId(); |
| 744 file_util()->Remove(FilePath("/mnt/memory/b/f"), false /* recursive */, | 744 file_util()->Remove(base::FilePath("/mnt/memory/b/f"), false /* recursive */, |
| 745 GetStatusCallback(request_id1)); | 745 GetStatusCallback(request_id1)); |
| 746 MessageLoop::current()->RunUntilIdle(); | 746 MessageLoop::current()->RunUntilIdle(); |
| 747 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); | 747 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); |
| 748 | 748 |
| 749 // Check the number of files in b/ | 749 // Check the number of files in b/ |
| 750 | 750 |
| 751 request_id1 = GetNextRequestId(); | 751 request_id1 = GetNextRequestId(); |
| 752 file_util()->ReadDirectory(FilePath("/mnt/memory/b"), | 752 file_util()->ReadDirectory(base::FilePath("/mnt/memory/b"), |
| 753 GetReadDirectoryCallback(request_id1)); | 753 GetReadDirectoryCallback(request_id1)); |
| 754 | 754 |
| 755 MessageLoop::current()->RunUntilIdle(); | 755 MessageLoop::current()->RunUntilIdle(); |
| 756 | 756 |
| 757 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); | 757 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); |
| 758 status = GetStatus(request_id1); | 758 status = GetStatus(request_id1); |
| 759 ASSERT_TRUE(status.completed); | 759 ASSERT_TRUE(status.completed); |
| 760 ASSERT_FALSE(status.called_after_completed); | 760 ASSERT_FALSE(status.called_after_completed); |
| 761 ASSERT_EQ(5u, status.entries.size()); | 761 ASSERT_EQ(5u, status.entries.size()); |
| 762 | 762 |
| 763 // Try remove /mnt/memory/b non-recursively (error) | 763 // Try remove /mnt/memory/b non-recursively (error) |
| 764 | 764 |
| 765 request_id1 = GetNextRequestId(); | 765 request_id1 = GetNextRequestId(); |
| 766 file_util()->Remove(FilePath("/mnt/memory/b"), false /* recursive */, | 766 file_util()->Remove(base::FilePath("/mnt/memory/b"), false /* recursive */, |
| 767 GetStatusCallback(request_id1)); | 767 GetStatusCallback(request_id1)); |
| 768 MessageLoop::current()->RunUntilIdle(); | 768 MessageLoop::current()->RunUntilIdle(); |
| 769 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, | 769 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, |
| 770 GetStatus(request_id1).result); | 770 GetStatus(request_id1).result); |
| 771 | 771 |
| 772 // Non-recursively remove empty directory. | 772 // Non-recursively remove empty directory. |
| 773 | 773 |
| 774 request_id1 = GetNextRequestId(); | 774 request_id1 = GetNextRequestId(); |
| 775 file_util()->Remove(FilePath("/mnt/memory/b/d"), false /* recursive */, | 775 file_util()->Remove(base::FilePath("/mnt/memory/b/d"), false /* recursive */, |
| 776 GetStatusCallback(request_id1)); | 776 GetStatusCallback(request_id1)); |
| 777 MessageLoop::current()->RunUntilIdle(); | 777 MessageLoop::current()->RunUntilIdle(); |
| 778 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); | 778 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); |
| 779 | 779 |
| 780 request_id1 = GetNextRequestId(); | 780 request_id1 = GetNextRequestId(); |
| 781 file_util()->GetFileInfo(FilePath("/mnt/memory/b/d"), | 781 file_util()->GetFileInfo(base::FilePath("/mnt/memory/b/d"), |
| 782 GetGetFileInfoCallback(request_id1)); | 782 GetGetFileInfoCallback(request_id1)); |
| 783 MessageLoop::current()->RunUntilIdle(); | 783 MessageLoop::current()->RunUntilIdle(); |
| 784 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, GetStatus(request_id1).result); | 784 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, GetStatus(request_id1).result); |
| 785 | 785 |
| 786 // Remove /mnt/memory/b recursively. | 786 // Remove /mnt/memory/b recursively. |
| 787 | 787 |
| 788 request_id1 = GetNextRequestId(); | 788 request_id1 = GetNextRequestId(); |
| 789 file_util()->Remove(FilePath("/mnt/memory/b"), true /* recursive */, | 789 file_util()->Remove(base::FilePath("/mnt/memory/b"), true /* recursive */, |
| 790 GetStatusCallback(request_id1)); | 790 GetStatusCallback(request_id1)); |
| 791 MessageLoop::current()->RunUntilIdle(); | 791 MessageLoop::current()->RunUntilIdle(); |
| 792 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); | 792 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); |
| 793 | 793 |
| 794 // ReadDirectory /mnt/memory/b -> not found | 794 // ReadDirectory /mnt/memory/b -> not found |
| 795 | 795 |
| 796 request_id1 = GetNextRequestId(); | 796 request_id1 = GetNextRequestId(); |
| 797 file_util()->ReadDirectory(FilePath("/mnt/memory/b"), | 797 file_util()->ReadDirectory(base::FilePath("/mnt/memory/b"), |
| 798 GetReadDirectoryCallback(request_id1)); | 798 GetReadDirectoryCallback(request_id1)); |
| 799 MessageLoop::current()->RunUntilIdle(); | 799 MessageLoop::current()->RunUntilIdle(); |
| 800 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, GetStatus(request_id1).result); | 800 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, GetStatus(request_id1).result); |
| 801 | 801 |
| 802 // ReadDirectory /mnt/memory | 802 // ReadDirectory /mnt/memory |
| 803 | 803 |
| 804 request_id1 = GetNextRequestId(); | 804 request_id1 = GetNextRequestId(); |
| 805 file_util()->ReadDirectory(FilePath("/mnt/memory"), | 805 file_util()->ReadDirectory(base::FilePath("/mnt/memory"), |
| 806 GetReadDirectoryCallback(request_id1)); | 806 GetReadDirectoryCallback(request_id1)); |
| 807 | 807 |
| 808 MessageLoop::current()->RunUntilIdle(); | 808 MessageLoop::current()->RunUntilIdle(); |
| 809 | 809 |
| 810 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); | 810 ASSERT_EQ(base::PLATFORM_FILE_OK, GetStatus(request_id1).result); |
| 811 status = GetStatus(request_id1); | 811 status = GetStatus(request_id1); |
| 812 ASSERT_TRUE(status.completed); | 812 ASSERT_TRUE(status.completed); |
| 813 ASSERT_FALSE(status.called_after_completed); | 813 ASSERT_FALSE(status.called_after_completed); |
| 814 ASSERT_EQ(3u, status.entries.size()); | 814 ASSERT_EQ(3u, status.entries.size()); |
| 815 | 815 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 830 ASSERT_FALSE(it->is_directory); | 830 ASSERT_FALSE(it->is_directory); |
| 831 ASSERT_EQ(static_cast<int64>(kTestStringLength), it->size); | 831 ASSERT_EQ(static_cast<int64>(kTestStringLength), it->size); |
| 832 } else { | 832 } else { |
| 833 LOG(ERROR) << "Unexpected file: " << it->name; | 833 LOG(ERROR) << "Unexpected file: " << it->name; |
| 834 ASSERT_TRUE(false); | 834 ASSERT_TRUE(false); |
| 835 } | 835 } |
| 836 } | 836 } |
| 837 } | 837 } |
| 838 | 838 |
| 839 } // namespace fileapi | 839 } // namespace fileapi |
| OLD | NEW |