| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <stack> | 5 #include <stack> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/message_loop_proxy.h" |
| 10 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
| 11 #include "base/task.h" | 12 #include "base/task.h" |
| 12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "base/ref_counted.h" | 15 #include "base/ref_counted.h" |
| 15 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
| 16 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 17 #include "net/base/file_stream.h" | 18 #include "net/base/file_stream.h" |
| 18 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
| 19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 return TestRequest("GET", net::HttpRequestHeaders(), blob_data); | 243 return TestRequest("GET", net::HttpRequestHeaders(), blob_data); |
| 243 } | 244 } |
| 244 | 245 |
| 245 void TestRequest(const std::string& method, | 246 void TestRequest(const std::string& method, |
| 246 const net::HttpRequestHeaders& extra_headers, | 247 const net::HttpRequestHeaders& extra_headers, |
| 247 BlobData* blob_data) { | 248 BlobData* blob_data) { |
| 248 // This test has async steps. | 249 // This test has async steps. |
| 249 request_.reset(new net::URLRequest(GURL("blob:blah"), | 250 request_.reset(new net::URLRequest(GURL("blob:blah"), |
| 250 url_request_delegate_.get())); | 251 url_request_delegate_.get())); |
| 251 request_->set_method(method); | 252 request_->set_method(method); |
| 252 blob_url_request_job_ = new BlobURLRequestJob(request_.get(), | 253 blob_url_request_job_ = new BlobURLRequestJob( |
| 253 blob_data, NULL); | 254 request_.get(), |
| 255 blob_data, |
| 256 base::MessageLoopProxy::CreateForCurrentThread()); |
| 254 | 257 |
| 255 // Start the request. | 258 // Start the request. |
| 256 if (!extra_headers.IsEmpty()) | 259 if (!extra_headers.IsEmpty()) |
| 257 request_->SetExtraRequestHeaders(extra_headers); | 260 request_->SetExtraRequestHeaders(extra_headers); |
| 258 request_->Start(); | 261 request_->Start(); |
| 259 | 262 |
| 260 // Completion is async. | 263 // Completion is async. |
| 261 } | 264 } |
| 262 | 265 |
| 263 void VerifyResponse() { | 266 void VerifyResponse() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 276 blob_data->AppendData(kTestData1); | 279 blob_data->AppendData(kTestData1); |
| 277 TestSuccessRequest(blob_data, kTestData1); | 280 TestSuccessRequest(blob_data, kTestData1); |
| 278 } | 281 } |
| 279 | 282 |
| 280 void TestGetSimpleFileRequest() { | 283 void TestGetSimpleFileRequest() { |
| 281 scoped_refptr<BlobData> blob_data(new BlobData()); | 284 scoped_refptr<BlobData> blob_data(new BlobData()); |
| 282 blob_data->AppendFile(temp_file1_, 0, -1, base::Time()); | 285 blob_data->AppendFile(temp_file1_, 0, -1, base::Time()); |
| 283 TestSuccessRequest(blob_data, kTestFileData1); | 286 TestSuccessRequest(blob_data, kTestFileData1); |
| 284 } | 287 } |
| 285 | 288 |
| 289 void TestGetLargeFileRequest() { |
| 290 scoped_refptr<BlobData> blob_data(new BlobData()); |
| 291 FilePath large_temp_file = temp_dir_.path().AppendASCII("LargeBlob.dat"); |
| 292 std::string large_data; |
| 293 large_data.reserve(kBufferSize * 5); |
| 294 for (int i = 0; i < kBufferSize * 5; ++i) |
| 295 large_data.append(1, static_cast<char>(i % 256)); |
| 296 ASSERT_EQ(static_cast<int>(large_data.size()), |
| 297 file_util::WriteFile(large_temp_file, large_data.data(), |
| 298 large_data.size())); |
| 299 blob_data->AppendFile(large_temp_file, 0, -1, base::Time()); |
| 300 TestSuccessRequest(blob_data, large_data); |
| 301 } |
| 302 |
| 286 void TestGetNonExistentFileRequest() { | 303 void TestGetNonExistentFileRequest() { |
| 287 FilePath non_existent_file = | 304 FilePath non_existent_file = |
| 288 temp_file1_.InsertBeforeExtension(FILE_PATH_LITERAL("-na")); | 305 temp_file1_.InsertBeforeExtension(FILE_PATH_LITERAL("-na")); |
| 289 scoped_refptr<BlobData> blob_data(new BlobData()); | 306 scoped_refptr<BlobData> blob_data(new BlobData()); |
| 290 blob_data->AppendFile(non_existent_file, 0, -1, base::Time()); | 307 blob_data->AppendFile(non_existent_file, 0, -1, base::Time()); |
| 291 TestErrorRequest(blob_data, 404); | 308 TestErrorRequest(blob_data, 404); |
| 292 } | 309 } |
| 293 | 310 |
| 294 void TestGetChangedFileRequest() { | 311 void TestGetChangedFileRequest() { |
| 295 scoped_refptr<BlobData> blob_data(new BlobData()); | 312 scoped_refptr<BlobData> blob_data(new BlobData()); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 BlobURLRequestJob* BlobURLRequestJobTest::blob_url_request_job_ = NULL; | 419 BlobURLRequestJob* BlobURLRequestJobTest::blob_url_request_job_ = NULL; |
| 403 | 420 |
| 404 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) { | 421 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) { |
| 405 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSimpleDataRequest); | 422 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSimpleDataRequest); |
| 406 } | 423 } |
| 407 | 424 |
| 408 TEST_F(BlobURLRequestJobTest, TestGetSimpleFileRequest) { | 425 TEST_F(BlobURLRequestJobTest, TestGetSimpleFileRequest) { |
| 409 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSimpleFileRequest); | 426 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSimpleFileRequest); |
| 410 } | 427 } |
| 411 | 428 |
| 429 TEST_F(BlobURLRequestJobTest, TestGetLargeFileRequest) { |
| 430 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetLargeFileRequest); |
| 431 } |
| 432 |
| 412 TEST_F(BlobURLRequestJobTest, TestGetSlicedDataRequest) { | 433 TEST_F(BlobURLRequestJobTest, TestGetSlicedDataRequest) { |
| 413 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSlicedDataRequest); | 434 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSlicedDataRequest); |
| 414 } | 435 } |
| 415 | 436 |
| 416 TEST_F(BlobURLRequestJobTest, TestGetSlicedFileRequest) { | 437 TEST_F(BlobURLRequestJobTest, TestGetSlicedFileRequest) { |
| 417 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSlicedFileRequest); | 438 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSlicedFileRequest); |
| 418 } | 439 } |
| 419 | 440 |
| 420 TEST_F(BlobURLRequestJobTest, TestGetNonExistentFileRequest) { | 441 TEST_F(BlobURLRequestJobTest, TestGetNonExistentFileRequest) { |
| 421 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetNonExistentFileRequest); | 442 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetNonExistentFileRequest); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 440 | 461 |
| 441 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) { | 462 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) { |
| 442 RunTestOnIOThread(&BlobURLRequestJobTest::TestExtraHeaders); | 463 RunTestOnIOThread(&BlobURLRequestJobTest::TestExtraHeaders); |
| 443 } | 464 } |
| 444 | 465 |
| 445 } // namespace webkit_blob | 466 } // namespace webkit_blob |
| 446 | 467 |
| 447 // BlobURLRequestJobTest is expected to always live longer than the | 468 // BlobURLRequestJobTest is expected to always live longer than the |
| 448 // runnable methods. This lets us call NewRunnableMethod on its instances. | 469 // runnable methods. This lets us call NewRunnableMethod on its instances. |
| 449 DISABLE_RUNNABLE_METHOD_REFCOUNT(webkit_blob::BlobURLRequestJobTest); | 470 DISABLE_RUNNABLE_METHOD_REFCOUNT(webkit_blob::BlobURLRequestJobTest); |
| OLD | NEW |