Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: webkit/blob/blob_url_request_job_unittest.cc

Issue 6612051: In BlobURLRequestJob, open files asynchronously to avoid blocking the IO thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Properly handle multiple calls to ReadRawData and add a test for that case Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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;
jianli 2011/03/10 22:50:42 Might be more efficient to call reserve to preallo
adamk 2011/03/10 23:06:12 Seems slightly like overkill for a unittest, but I
293 for (int i = 0; i < kBufferSize * 5; ++i)
294 large_data.append(1, static_cast<char>(i % 256));
295 ASSERT_EQ(static_cast<int>(large_data.size()),
296 file_util::WriteFile(large_temp_file, large_data.data(),
297 large_data.size()));
298 blob_data->AppendFile(large_temp_file, 0, -1, base::Time());
299 TestSuccessRequest(blob_data, large_data);
300 }
301
286 void TestGetNonExistentFileRequest() { 302 void TestGetNonExistentFileRequest() {
287 FilePath non_existent_file = 303 FilePath non_existent_file =
288 temp_file1_.InsertBeforeExtension(FILE_PATH_LITERAL("-na")); 304 temp_file1_.InsertBeforeExtension(FILE_PATH_LITERAL("-na"));
289 scoped_refptr<BlobData> blob_data(new BlobData()); 305 scoped_refptr<BlobData> blob_data(new BlobData());
290 blob_data->AppendFile(non_existent_file, 0, -1, base::Time()); 306 blob_data->AppendFile(non_existent_file, 0, -1, base::Time());
291 TestErrorRequest(blob_data, 404); 307 TestErrorRequest(blob_data, 404);
292 } 308 }
293 309
294 void TestGetChangedFileRequest() { 310 void TestGetChangedFileRequest() {
295 scoped_refptr<BlobData> blob_data(new BlobData()); 311 scoped_refptr<BlobData> blob_data(new BlobData());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 BlobURLRequestJob* BlobURLRequestJobTest::blob_url_request_job_ = NULL; 418 BlobURLRequestJob* BlobURLRequestJobTest::blob_url_request_job_ = NULL;
403 419
404 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) { 420 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) {
405 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSimpleDataRequest); 421 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSimpleDataRequest);
406 } 422 }
407 423
408 TEST_F(BlobURLRequestJobTest, TestGetSimpleFileRequest) { 424 TEST_F(BlobURLRequestJobTest, TestGetSimpleFileRequest) {
409 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSimpleFileRequest); 425 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSimpleFileRequest);
410 } 426 }
411 427
428 TEST_F(BlobURLRequestJobTest, TestGetLargeFileRequest) {
429 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetLargeFileRequest);
430 }
431
412 TEST_F(BlobURLRequestJobTest, TestGetSlicedDataRequest) { 432 TEST_F(BlobURLRequestJobTest, TestGetSlicedDataRequest) {
413 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSlicedDataRequest); 433 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSlicedDataRequest);
414 } 434 }
415 435
416 TEST_F(BlobURLRequestJobTest, TestGetSlicedFileRequest) { 436 TEST_F(BlobURLRequestJobTest, TestGetSlicedFileRequest) {
417 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSlicedFileRequest); 437 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetSlicedFileRequest);
418 } 438 }
419 439
420 TEST_F(BlobURLRequestJobTest, TestGetNonExistentFileRequest) { 440 TEST_F(BlobURLRequestJobTest, TestGetNonExistentFileRequest) {
421 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetNonExistentFileRequest); 441 RunTestOnIOThread(&BlobURLRequestJobTest::TestGetNonExistentFileRequest);
(...skipping 18 matching lines...) Expand all
440 460
441 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) { 461 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) {
442 RunTestOnIOThread(&BlobURLRequestJobTest::TestExtraHeaders); 462 RunTestOnIOThread(&BlobURLRequestJobTest::TestExtraHeaders);
443 } 463 }
444 464
445 } // namespace webkit_blob 465 } // namespace webkit_blob
446 466
447 // BlobURLRequestJobTest is expected to always live longer than the 467 // BlobURLRequestJobTest is expected to always live longer than the
448 // runnable methods. This lets us call NewRunnableMethod on its instances. 468 // runnable methods. This lets us call NewRunnableMethod on its instances.
449 DISABLE_RUNNABLE_METHOD_REFCOUNT(webkit_blob::BlobURLRequestJobTest); 469 DISABLE_RUNNABLE_METHOD_REFCOUNT(webkit_blob::BlobURLRequestJobTest);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698