| 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 <stack> | 5 #include <stack> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
| 15 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
| 16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "base/time.h" | 18 #include "base/time.h" |
| 19 #include "net/base/file_stream.h" | 19 #include "net/base/file_stream.h" |
| 20 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
| 21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 22 #include "net/http/http_request_headers.h" | 22 #include "net/http/http_request_headers.h" |
| 23 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
| 24 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
| 25 #include "net/url_request/url_request_context.h" |
| 25 #include "net/url_request/url_request_error_job.h" | 26 #include "net/url_request/url_request_error_job.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "webkit/blob/blob_data.h" | 28 #include "webkit/blob/blob_data.h" |
| 28 #include "webkit/blob/blob_url_request_job.h" | 29 #include "webkit/blob/blob_url_request_job.h" |
| 29 | 30 |
| 30 namespace webkit_blob { | 31 namespace webkit_blob { |
| 31 | 32 |
| 32 static const int kBufferSize = 1024; | 33 static const int kBufferSize = 1024; |
| 33 static const char kTestData1[] = "Hello"; | 34 static const char kTestData1[] = "Hello"; |
| 34 static const char kTestData2[] = "Here it is data."; | 35 static const char kTestData2[] = "Here it is data."; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 expected_status_code_ = expected_status_code; | 236 expected_status_code_ = expected_status_code; |
| 236 expected_response_ = ""; | 237 expected_response_ = ""; |
| 237 return TestRequest("GET", net::HttpRequestHeaders(), blob_data); | 238 return TestRequest("GET", net::HttpRequestHeaders(), blob_data); |
| 238 } | 239 } |
| 239 | 240 |
| 240 void TestRequest(const std::string& method, | 241 void TestRequest(const std::string& method, |
| 241 const net::HttpRequestHeaders& extra_headers, | 242 const net::HttpRequestHeaders& extra_headers, |
| 242 BlobData* blob_data) { | 243 BlobData* blob_data) { |
| 243 // This test has async steps. | 244 // This test has async steps. |
| 244 request_.reset(new net::URLRequest(GURL("blob:blah"), | 245 request_.reset(new net::URLRequest(GURL("blob:blah"), |
| 245 url_request_delegate_.get())); | 246 url_request_delegate_.get(), |
| 247 &empty_context_)); |
| 246 request_->set_method(method); | 248 request_->set_method(method); |
| 247 blob_url_request_job_ = new BlobURLRequestJob( | 249 blob_url_request_job_ = new BlobURLRequestJob( |
| 248 request_.get(), | 250 request_.get(), |
| 249 blob_data, | 251 blob_data, |
| 250 base::MessageLoopProxy::current()); | 252 base::MessageLoopProxy::current()); |
| 251 | 253 |
| 252 // Start the request. | 254 // Start the request. |
| 253 if (!extra_headers.IsEmpty()) | 255 if (!extra_headers.IsEmpty()) |
| 254 request_->SetExtraRequestHeaders(extra_headers); | 256 request_->SetExtraRequestHeaders(extra_headers); |
| 255 request_->Start(); | 257 request_->Start(); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 ScopedTempDir temp_dir_; | 392 ScopedTempDir temp_dir_; |
| 391 FilePath temp_file1_; | 393 FilePath temp_file1_; |
| 392 FilePath temp_file2_; | 394 FilePath temp_file2_; |
| 393 base::Time temp_file_modification_time1_; | 395 base::Time temp_file_modification_time1_; |
| 394 base::Time temp_file_modification_time2_; | 396 base::Time temp_file_modification_time2_; |
| 395 scoped_ptr<base::Thread> io_thread_; | 397 scoped_ptr<base::Thread> io_thread_; |
| 396 static BlobURLRequestJob* blob_url_request_job_; | 398 static BlobURLRequestJob* blob_url_request_job_; |
| 397 | 399 |
| 398 scoped_ptr<base::WaitableEvent> test_finished_event_; | 400 scoped_ptr<base::WaitableEvent> test_finished_event_; |
| 399 std::stack<std::pair<base::Closure, bool> > task_stack_; | 401 std::stack<std::pair<base::Closure, bool> > task_stack_; |
| 402 net::URLRequestContext empty_context_; |
| 400 scoped_ptr<net::URLRequest> request_; | 403 scoped_ptr<net::URLRequest> request_; |
| 401 scoped_ptr<MockURLRequestDelegate> url_request_delegate_; | 404 scoped_ptr<MockURLRequestDelegate> url_request_delegate_; |
| 402 int expected_status_code_; | 405 int expected_status_code_; |
| 403 std::string expected_response_; | 406 std::string expected_response_; |
| 404 }; | 407 }; |
| 405 | 408 |
| 406 // static | 409 // static |
| 407 BlobURLRequestJob* BlobURLRequestJobTest::blob_url_request_job_ = NULL; | 410 BlobURLRequestJob* BlobURLRequestJobTest::blob_url_request_job_ = NULL; |
| 408 | 411 |
| 409 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) { | 412 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 444 |
| 442 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest2) { | 445 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest2) { |
| 443 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetRangeRequest2); | 446 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetRangeRequest2); |
| 444 } | 447 } |
| 445 | 448 |
| 446 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) { | 449 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) { |
| 447 RunTestOnIOThread(&BlobURLRequestJobTest::TestExtraHeaders); | 450 RunTestOnIOThread(&BlobURLRequestJobTest::TestExtraHeaders); |
| 448 } | 451 } |
| 449 | 452 |
| 450 } // namespace webkit_blob | 453 } // namespace webkit_blob |
| OLD | NEW |