| 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 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
| 12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 14 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 15 #include "net/url_request/url_request_context.h" |
| 15 #include "net/url_request/url_request_job.h" | 16 #include "net/url_request/url_request_job.h" |
| 16 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 17 #include "testing/platform_test.h" | 18 #include "testing/platform_test.h" |
| 18 #include "webkit/fileapi/file_system_context.h" | 19 #include "webkit/fileapi/file_system_context.h" |
| 19 #include "webkit/fileapi/file_system_operation.h" | 20 #include "webkit/fileapi/file_system_operation.h" |
| 20 #include "webkit/fileapi/file_system_test_helper.h" | 21 #include "webkit/fileapi/file_system_test_helper.h" |
| 21 #include "webkit/fileapi/file_writer_delegate.h" | 22 #include "webkit/fileapi/file_writer_delegate.h" |
| 22 #include "webkit/fileapi/sandbox_file_stream_writer.h" | 23 #include "webkit/fileapi/sandbox_file_stream_writer.h" |
| 23 | 24 |
| 24 namespace fileapi { | 25 namespace fileapi { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 110 } |
| 110 | 111 |
| 111 // Creates and sets up a FileWriterDelegate for writing the given |blob_url|, | 112 // Creates and sets up a FileWriterDelegate for writing the given |blob_url|, |
| 112 // and creates a new FileWriterDelegate for the file. | 113 // and creates a new FileWriterDelegate for the file. |
| 113 void PrepareForWrite(const GURL& blob_url, | 114 void PrepareForWrite(const GURL& blob_url, |
| 114 int64 offset, | 115 int64 offset, |
| 115 int64 allowed_growth) { | 116 int64 allowed_growth) { |
| 116 result_.reset(new Result()); | 117 result_.reset(new Result()); |
| 117 file_writer_delegate_.reset( | 118 file_writer_delegate_.reset( |
| 118 CreateWriterDelegate("test", offset, allowed_growth, result_.get())); | 119 CreateWriterDelegate("test", offset, allowed_growth, result_.get())); |
| 119 request_.reset(new net::URLRequest(blob_url, file_writer_delegate_.get())); | 120 request_.reset(new net::URLRequest(blob_url, |
| 121 file_writer_delegate_.get(), |
| 122 &empty_context_)); |
| 120 } | 123 } |
| 121 | 124 |
| 122 static net::URLRequest::ProtocolFactory Factory; | 125 static net::URLRequest::ProtocolFactory Factory; |
| 123 | 126 |
| 124 // This should be alive until the very end of this instance. | 127 // This should be alive until the very end of this instance. |
| 125 MessageLoop loop_; | 128 MessageLoop loop_; |
| 126 | 129 |
| 130 net::URLRequestContext empty_context_; |
| 127 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 131 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
| 128 scoped_ptr<net::URLRequest> request_; | 132 scoped_ptr<net::URLRequest> request_; |
| 129 scoped_ptr<Result> result_; | 133 scoped_ptr<Result> result_; |
| 130 FileSystemTestOriginHelper test_helper_; | 134 FileSystemTestOriginHelper test_helper_; |
| 131 | 135 |
| 132 ScopedTempDir dir_; | 136 ScopedTempDir dir_; |
| 133 | 137 |
| 134 static const char* content_; | 138 static const char* content_; |
| 135 }; | 139 }; |
| 136 | 140 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 const GURL kBlobURL("blob:nolimitconcurrent"); | 339 const GURL kBlobURL("blob:nolimitconcurrent"); |
| 336 const GURL kBlobURL2("blob:nolimitconcurrent2"); | 340 const GURL kBlobURL2("blob:nolimitconcurrent2"); |
| 337 content_ = kData; | 341 content_ = kData; |
| 338 | 342 |
| 339 PrepareForWrite(kBlobURL, 0, quota::QuotaManager::kNoLimit); | 343 PrepareForWrite(kBlobURL, 0, quota::QuotaManager::kNoLimit); |
| 340 | 344 |
| 341 // Credate another FileWriterDelegate for concurrent write. | 345 // Credate another FileWriterDelegate for concurrent write. |
| 342 result2.reset(new Result()); | 346 result2.reset(new Result()); |
| 343 file_writer_delegate2.reset(CreateWriterDelegate( | 347 file_writer_delegate2.reset(CreateWriterDelegate( |
| 344 "test2", 0, quota::QuotaManager::kNoLimit, result2.get())); | 348 "test2", 0, quota::QuotaManager::kNoLimit, result2.get())); |
| 345 request2.reset(new net::URLRequest(kBlobURL2, file_writer_delegate2.get())); | 349 request2.reset(new net::URLRequest(kBlobURL2, |
| 350 file_writer_delegate2.get(), |
| 351 &empty_context_)); |
| 346 | 352 |
| 347 ASSERT_EQ(0, test_helper_.GetCachedOriginUsage()); | 353 ASSERT_EQ(0, test_helper_.GetCachedOriginUsage()); |
| 348 file_writer_delegate_->Start(request_.Pass()); | 354 file_writer_delegate_->Start(request_.Pass()); |
| 349 file_writer_delegate2->Start(request2.Pass()); | 355 file_writer_delegate2->Start(request2.Pass()); |
| 350 MessageLoop::current()->Run(); | 356 MessageLoop::current()->Run(); |
| 351 if (!result_->complete() || !result2->complete()) | 357 if (!result_->complete() || !result2->complete()) |
| 352 MessageLoop::current()->Run(); | 358 MessageLoop::current()->Run(); |
| 353 | 359 |
| 354 ASSERT_TRUE(result_->complete()); | 360 ASSERT_TRUE(result_->complete()); |
| 355 ASSERT_TRUE(result2->complete()); | 361 ASSERT_TRUE(result2->complete()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 file_writer_delegate_.reset(); | 459 file_writer_delegate_.reset(); |
| 454 | 460 |
| 455 EXPECT_EQ(pre_write_usage + allowed_growth, | 461 EXPECT_EQ(pre_write_usage + allowed_growth, |
| 456 test_helper_.GetCachedOriginUsage()); | 462 test_helper_.GetCachedOriginUsage()); |
| 457 EXPECT_EQ(ComputeCurrentOriginUsage(), test_helper_.GetCachedOriginUsage()); | 463 EXPECT_EQ(ComputeCurrentOriginUsage(), test_helper_.GetCachedOriginUsage()); |
| 458 EXPECT_EQ(kOverlap + allowed_growth, result_->bytes_written()); | 464 EXPECT_EQ(kOverlap + allowed_growth, result_->bytes_written()); |
| 459 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, result_->status()); | 465 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, result_->status()); |
| 460 } | 466 } |
| 461 | 467 |
| 462 } // namespace fileapi | 468 } // namespace fileapi |
| OLD | NEW |