| 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/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 EXPECT_EQ(request_->response_headers()->response_code(), | 264 EXPECT_EQ(request_->response_headers()->response_code(), |
| 265 expected_status_code_); | 265 expected_status_code_); |
| 266 EXPECT_STREQ(url_request_delegate_->response_data().c_str(), | 266 EXPECT_STREQ(url_request_delegate_->response_data().c_str(), |
| 267 expected_response_.c_str()); | 267 expected_response_.c_str()); |
| 268 TestFinished(); | 268 TestFinished(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 // Test Cases --------------------------------------------------------------- | 271 // Test Cases --------------------------------------------------------------- |
| 272 | 272 |
| 273 void TestGetSimpleDataRequest() { | 273 void TestGetSimpleDataRequest() { |
| 274 scoped_refptr<BlobData> blob_data = new BlobData(); | 274 scoped_refptr<BlobData> blob_data(new BlobData()); |
| 275 blob_data->AppendData(kTestData1); | 275 blob_data->AppendData(kTestData1); |
| 276 TestSuccessRequest(blob_data, kTestData1); | 276 TestSuccessRequest(blob_data, kTestData1); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void TestGetSimpleFileRequest() { | 279 void TestGetSimpleFileRequest() { |
| 280 scoped_refptr<BlobData> blob_data = new BlobData(); | 280 scoped_refptr<BlobData> blob_data(new BlobData()); |
| 281 blob_data->AppendFile(temp_file1_, 0, -1, base::Time()); | 281 blob_data->AppendFile(temp_file1_, 0, -1, base::Time()); |
| 282 TestSuccessRequest(blob_data, kTestFileData1); | 282 TestSuccessRequest(blob_data, kTestFileData1); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void TestGetNonExistentFileRequest() { | 285 void TestGetNonExistentFileRequest() { |
| 286 FilePath non_existent_file = | 286 FilePath non_existent_file = |
| 287 temp_file1_.InsertBeforeExtension(FILE_PATH_LITERAL("-na")); | 287 temp_file1_.InsertBeforeExtension(FILE_PATH_LITERAL("-na")); |
| 288 scoped_refptr<BlobData> blob_data = new BlobData(); | 288 scoped_refptr<BlobData> blob_data(new BlobData()); |
| 289 blob_data->AppendFile(non_existent_file, 0, -1, base::Time()); | 289 blob_data->AppendFile(non_existent_file, 0, -1, base::Time()); |
| 290 TestErrorRequest(blob_data, 404); | 290 TestErrorRequest(blob_data, 404); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void TestGetChangedFileRequest() { | 293 void TestGetChangedFileRequest() { |
| 294 scoped_refptr<BlobData> blob_data = new BlobData(); | 294 scoped_refptr<BlobData> blob_data(new BlobData()); |
| 295 base::Time old_time = | 295 base::Time old_time = |
| 296 temp_file_modification_time1_ - base::TimeDelta::FromSeconds(10); | 296 temp_file_modification_time1_ - base::TimeDelta::FromSeconds(10); |
| 297 blob_data->AppendFile(temp_file1_, 0, 3, old_time); | 297 blob_data->AppendFile(temp_file1_, 0, 3, old_time); |
| 298 TestErrorRequest(blob_data, 404); | 298 TestErrorRequest(blob_data, 404); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void TestGetSlicedDataRequest() { | 301 void TestGetSlicedDataRequest() { |
| 302 scoped_refptr<BlobData> blob_data = new BlobData(); | 302 scoped_refptr<BlobData> blob_data(new BlobData()); |
| 303 blob_data->AppendData(kTestData2, 2, 4); | 303 blob_data->AppendData(kTestData2, 2, 4); |
| 304 std::string result(kTestData2 + 2, 4); | 304 std::string result(kTestData2 + 2, 4); |
| 305 TestSuccessRequest(blob_data, result); | 305 TestSuccessRequest(blob_data, result); |
| 306 } | 306 } |
| 307 | 307 |
| 308 void TestGetSlicedFileRequest() { | 308 void TestGetSlicedFileRequest() { |
| 309 scoped_refptr<BlobData> blob_data = new BlobData(); | 309 scoped_refptr<BlobData> blob_data(new BlobData()); |
| 310 blob_data->AppendFile(temp_file1_, 2, 4, temp_file_modification_time1_); | 310 blob_data->AppendFile(temp_file1_, 2, 4, temp_file_modification_time1_); |
| 311 std::string result(kTestFileData1 + 2, 4); | 311 std::string result(kTestFileData1 + 2, 4); |
| 312 TestSuccessRequest(blob_data, result); | 312 TestSuccessRequest(blob_data, result); |
| 313 } | 313 } |
| 314 | 314 |
| 315 scoped_refptr<BlobData> BuildComplicatedData(std::string* expected_result) { | 315 scoped_refptr<BlobData> BuildComplicatedData(std::string* expected_result) { |
| 316 scoped_refptr<BlobData> blob_data = new BlobData(); | 316 scoped_refptr<BlobData> blob_data(new BlobData()); |
| 317 blob_data->AppendData(kTestData1, 1, 2); | 317 blob_data->AppendData(kTestData1, 1, 2); |
| 318 blob_data->AppendFile(temp_file1_, 2, 3, temp_file_modification_time1_); | 318 blob_data->AppendFile(temp_file1_, 2, 3, temp_file_modification_time1_); |
| 319 blob_data->AppendData(kTestData2, 3, 4); | 319 blob_data->AppendData(kTestData2, 3, 4); |
| 320 blob_data->AppendFile(temp_file2_, 4, 5, temp_file_modification_time2_); | 320 blob_data->AppendFile(temp_file2_, 4, 5, temp_file_modification_time2_); |
| 321 *expected_result = std::string(kTestData1 + 1, 2); | 321 *expected_result = std::string(kTestData1 + 1, 2); |
| 322 *expected_result += std::string(kTestFileData1 + 2, 3); | 322 *expected_result += std::string(kTestFileData1 + 2, 3); |
| 323 *expected_result += std::string(kTestData2 + 3, 4); | 323 *expected_result += std::string(kTestData2 + 3, 4); |
| 324 *expected_result += std::string(kTestFileData2 + 4, 5); | 324 *expected_result += std::string(kTestFileData2 + 4, 5); |
| 325 return blob_data; | 325 return blob_data; |
| 326 } | 326 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 349 net::HttpRequestHeaders extra_headers; | 349 net::HttpRequestHeaders extra_headers; |
| 350 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, "bytes=-10"); | 350 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, "bytes=-10"); |
| 351 PushNextTask(NewRunnableMethod( | 351 PushNextTask(NewRunnableMethod( |
| 352 this, &BlobURLRequestJobTest::VerifyResponse)); | 352 this, &BlobURLRequestJobTest::VerifyResponse)); |
| 353 expected_status_code_ = 206; | 353 expected_status_code_ = 206; |
| 354 expected_response_ = result.substr(result.length() - 10); | 354 expected_response_ = result.substr(result.length() - 10); |
| 355 return TestRequest("GET", extra_headers, blob_data); | 355 return TestRequest("GET", extra_headers, blob_data); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void TestExtraHeaders() { | 358 void TestExtraHeaders() { |
| 359 scoped_refptr<BlobData> blob_data = new BlobData(); | 359 scoped_refptr<BlobData> blob_data(new BlobData()); |
| 360 blob_data->set_content_type(kTestContentType); | 360 blob_data->set_content_type(kTestContentType); |
| 361 blob_data->set_content_disposition(kTestContentDisposition); | 361 blob_data->set_content_disposition(kTestContentDisposition); |
| 362 blob_data->AppendData(kTestData1); | 362 blob_data->AppendData(kTestData1); |
| 363 PushNextTask(NewRunnableMethod( | 363 PushNextTask(NewRunnableMethod( |
| 364 this, &BlobURLRequestJobTest::VerifyResponseForTestExtraHeaders)); | 364 this, &BlobURLRequestJobTest::VerifyResponseForTestExtraHeaders)); |
| 365 TestRequest("GET", net::HttpRequestHeaders(), blob_data); | 365 TestRequest("GET", net::HttpRequestHeaders(), blob_data); |
| 366 } | 366 } |
| 367 | 367 |
| 368 void VerifyResponseForTestExtraHeaders() { | 368 void VerifyResponseForTestExtraHeaders() { |
| 369 EXPECT_TRUE(request_->status().is_success()); | 369 EXPECT_TRUE(request_->status().is_success()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 439 |
| 440 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) { | 440 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) { |
| 441 RunTestOnIOThread(&BlobURLRequestJobTest::TestExtraHeaders); | 441 RunTestOnIOThread(&BlobURLRequestJobTest::TestExtraHeaders); |
| 442 } | 442 } |
| 443 | 443 |
| 444 } // namespace webkit_blob | 444 } // namespace webkit_blob |
| 445 | 445 |
| 446 // BlobURLRequestJobTest is expected to always live longer than the | 446 // BlobURLRequestJobTest is expected to always live longer than the |
| 447 // runnable methods. This lets us call NewRunnableMethod on its instances. | 447 // runnable methods. This lets us call NewRunnableMethod on its instances. |
| 448 DISABLE_RUNNABLE_METHOD_REFCOUNT(webkit_blob::BlobURLRequestJobTest); | 448 DISABLE_RUNNABLE_METHOD_REFCOUNT(webkit_blob::BlobURLRequestJobTest); |
| OLD | NEW |