| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.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" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 virtual void SetUp(); | 93 virtual void SetUp(); |
| 94 virtual void TearDown(); | 94 virtual void TearDown(); |
| 95 | 95 |
| 96 protected: | 96 protected: |
| 97 FileSystemURL URLForPath(const FilePath& path) const { | 97 FileSystemURL URLForPath(const FilePath& path) const { |
| 98 return test_helper_.CreateURL(path); | 98 return test_helper_.CreateURL(path); |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Callback function for recording test results. | 101 // Callback function for recording test results. |
| 102 FileSystemOperationInterface::WriteCallback RecordWriteCallback() { | 102 FileSystemOperation::WriteCallback RecordWriteCallback() { |
| 103 return base::Bind(&LocalFileSystemOperationWriteTest::DidWrite, | 103 return base::Bind(&LocalFileSystemOperationWriteTest::DidWrite, |
| 104 AsWeakPtr()); | 104 AsWeakPtr()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 FileSystemOperationInterface::StatusCallback RecordCancelCallback() { | 107 FileSystemOperation::StatusCallback RecordCancelCallback() { |
| 108 return base::Bind(&LocalFileSystemOperationWriteTest::DidCancel, | 108 return base::Bind(&LocalFileSystemOperationWriteTest::DidCancel, |
| 109 AsWeakPtr()); | 109 AsWeakPtr()); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void DidWrite(base::PlatformFileError status, int64 bytes, bool complete) { | 112 void DidWrite(base::PlatformFileError status, int64 bytes, bool complete) { |
| 113 if (status == base::PLATFORM_FILE_OK) { | 113 if (status == base::PLATFORM_FILE_OK) { |
| 114 add_bytes_written(bytes, complete); | 114 add_bytes_written(bytes, complete); |
| 115 if (complete) | 115 if (complete) |
| 116 MessageLoop::current()->Quit(); | 116 MessageLoop::current()->Quit(); |
| 117 } else { | 117 } else { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 350 |
| 351 TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelSuccessfulWrite) { | 351 TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelSuccessfulWrite) { |
| 352 GURL blob_url("blob:success"); | 352 GURL blob_url("blob:success"); |
| 353 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 353 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
| 354 blob_data->AppendData("Hello, world!\n"); | 354 blob_data->AppendData("Hello, world!\n"); |
| 355 | 355 |
| 356 TestURLRequestContext url_request_context; | 356 TestURLRequestContext url_request_context; |
| 357 url_request_context.blob_storage_controller()->AddFinishedBlob( | 357 url_request_context.blob_storage_controller()->AddFinishedBlob( |
| 358 blob_url, blob_data); | 358 blob_url, blob_data); |
| 359 | 359 |
| 360 FileSystemOperationInterface* write_operation = operation(); | 360 FileSystemOperation* write_operation = operation(); |
| 361 write_operation->Write(&url_request_context, URLForPath(virtual_path_), | 361 write_operation->Write(&url_request_context, URLForPath(virtual_path_), |
| 362 blob_url, 0, RecordWriteCallback()); | 362 blob_url, 0, RecordWriteCallback()); |
| 363 write_operation->Cancel(RecordCancelCallback()); | 363 write_operation->Cancel(RecordCancelCallback()); |
| 364 // We use RunAllPendings() instead of Run() here, because we won't dispatch | 364 // We use RunAllPendings() instead of Run() here, because we won't dispatch |
| 365 // callbacks after Cancel() is issued (so no chance to Quit) nor do we need | 365 // callbacks after Cancel() is issued (so no chance to Quit) nor do we need |
| 366 // to run another write cycle. | 366 // to run another write cycle. |
| 367 MessageLoop::current()->RunAllPending(); | 367 MessageLoop::current()->RunAllPending(); |
| 368 | 368 |
| 369 url_request_context.blob_storage_controller()->RemoveBlob(blob_url); | 369 url_request_context.blob_storage_controller()->RemoveBlob(blob_url); |
| 370 | 370 |
| 371 // Issued Cancel() before receiving any response from Write(), | 371 // Issued Cancel() before receiving any response from Write(), |
| 372 // so nothing should have happen. | 372 // so nothing should have happen. |
| 373 EXPECT_EQ(0, bytes_written()); | 373 EXPECT_EQ(0, bytes_written()); |
| 374 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, status()); | 374 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, status()); |
| 375 EXPECT_EQ(base::PLATFORM_FILE_OK, cancel_status()); | 375 EXPECT_EQ(base::PLATFORM_FILE_OK, cancel_status()); |
| 376 EXPECT_TRUE(complete()); | 376 EXPECT_TRUE(complete()); |
| 377 } | 377 } |
| 378 | 378 |
| 379 TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelFailingWrite) { | 379 TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelFailingWrite) { |
| 380 GURL blob_url("blob:writeinvalidfile"); | 380 GURL blob_url("blob:writeinvalidfile"); |
| 381 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 381 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
| 382 blob_data->AppendData("It\'ll not be written."); | 382 blob_data->AppendData("It\'ll not be written."); |
| 383 | 383 |
| 384 TestURLRequestContext url_request_context; | 384 TestURLRequestContext url_request_context; |
| 385 url_request_context.blob_storage_controller()->AddFinishedBlob( | 385 url_request_context.blob_storage_controller()->AddFinishedBlob( |
| 386 blob_url, blob_data); | 386 blob_url, blob_data); |
| 387 | 387 |
| 388 FileSystemOperationInterface* write_operation = operation(); | 388 FileSystemOperation* write_operation = operation(); |
| 389 write_operation->Write(&url_request_context, | 389 write_operation->Write(&url_request_context, |
| 390 URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))), | 390 URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))), |
| 391 blob_url, 0, RecordWriteCallback()); | 391 blob_url, 0, RecordWriteCallback()); |
| 392 write_operation->Cancel(RecordCancelCallback()); | 392 write_operation->Cancel(RecordCancelCallback()); |
| 393 // We use RunAllPendings() instead of Run() here, because we won't dispatch | 393 // We use RunAllPendings() instead of Run() here, because we won't dispatch |
| 394 // callbacks after Cancel() is issued (so no chance to Quit) nor do we need | 394 // callbacks after Cancel() is issued (so no chance to Quit) nor do we need |
| 395 // to run another write cycle. | 395 // to run another write cycle. |
| 396 MessageLoop::current()->RunAllPending(); | 396 MessageLoop::current()->RunAllPending(); |
| 397 | 397 |
| 398 url_request_context.blob_storage_controller()->RemoveBlob(blob_url); | 398 url_request_context.blob_storage_controller()->RemoveBlob(blob_url); |
| 399 | 399 |
| 400 // Issued Cancel() before receiving any response from Write(), | 400 // Issued Cancel() before receiving any response from Write(), |
| 401 // so nothing should have happen. | 401 // so nothing should have happen. |
| 402 EXPECT_EQ(0, bytes_written()); | 402 EXPECT_EQ(0, bytes_written()); |
| 403 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, status()); | 403 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, status()); |
| 404 EXPECT_EQ(base::PLATFORM_FILE_OK, cancel_status()); | 404 EXPECT_EQ(base::PLATFORM_FILE_OK, cancel_status()); |
| 405 EXPECT_TRUE(complete()); | 405 EXPECT_TRUE(complete()); |
| 406 } | 406 } |
| 407 | 407 |
| 408 // TODO(ericu,dmikurube,kinuko): Add more tests for cancel cases. | 408 // TODO(ericu,dmikurube,kinuko): Add more tests for cancel cases. |
| 409 | 409 |
| 410 } // namespace fileapi | 410 } // namespace fileapi |
| OLD | NEW |