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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #endif | 10 #endif |
(...skipping 4454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4465 path = path.Append(FILE_PATH_LITERAL("net")); | 4465 path = path.Append(FILE_PATH_LITERAL("net")); |
4466 path = path.Append(FILE_PATH_LITERAL("data")); | 4466 path = path.Append(FILE_PATH_LITERAL("data")); |
4467 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 4467 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
4468 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 4468 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
4469 element_readers.push_back( | 4469 element_readers.push_back( |
4470 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 4470 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
4471 path, | 4471 path, |
4472 0, | 4472 0, |
4473 kuint64max, | 4473 kuint64max, |
4474 base::Time())); | 4474 base::Time())); |
4475 | |
4476 // This file should just be ignored in the upload stream. | |
4477 element_readers.push_back(new UploadFileElementReader( | |
4478 base::MessageLoopProxy::current().get(), | |
4479 base::FilePath(FILE_PATH_LITERAL( | |
4480 "c:\\path\\to\\non\\existant\\file.randomness.12345")), | |
4481 0, | |
4482 kuint64max, | |
4483 base::Time())); | |
4484 r.set_upload(make_scoped_ptr( | 4475 r.set_upload(make_scoped_ptr( |
4485 new UploadDataStream(element_readers.Pass(), 0))); | 4476 new UploadDataStream(element_readers.Pass(), 0))); |
4486 | 4477 |
4487 r.Start(); | 4478 r.Start(); |
4488 EXPECT_TRUE(r.is_pending()); | 4479 EXPECT_TRUE(r.is_pending()); |
4489 | 4480 |
4490 base::RunLoop().Run(); | 4481 base::RunLoop().Run(); |
4491 | 4482 |
4492 int64 size = 0; | 4483 int64 size = 0; |
4493 ASSERT_EQ(true, file_util::GetFileSize(path, &size)); | 4484 ASSERT_EQ(true, file_util::GetFileSize(path, &size)); |
4494 scoped_ptr<char[]> buf(new char[size]); | 4485 scoped_ptr<char[]> buf(new char[size]); |
4495 | 4486 |
4496 ASSERT_EQ(size, file_util::ReadFile(path, buf.get(), size)); | 4487 ASSERT_EQ(size, file_util::ReadFile(path, buf.get(), size)); |
4497 | 4488 |
4498 ASSERT_EQ(1, d.response_started_count()) | 4489 ASSERT_EQ(1, d.response_started_count()) |
4499 << "request failed: " << r.status().status() | 4490 << "request failed: " << r.status().status() |
4500 << ", error: " << r.status().error(); | 4491 << ", error: " << r.status().error(); |
4501 | 4492 |
4502 EXPECT_FALSE(d.received_data_before_response()); | 4493 EXPECT_FALSE(d.received_data_before_response()); |
4503 | 4494 |
4504 EXPECT_EQ(size, d.bytes_received()); | 4495 EXPECT_EQ(size, d.bytes_received()); |
4505 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); | 4496 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); |
4506 } | 4497 } |
4507 } | 4498 } |
4508 | 4499 |
4500 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { | |
4501 ASSERT_TRUE(test_server_.Start()); | |
4502 | |
4503 TestDelegate d; | |
4504 { | |
4505 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | |
4506 r.set_method("POST"); | |
4507 | |
4508 base::FilePath dir; | |
4509 PathService::Get(base::DIR_EXE, &dir); | |
4510 file_util::SetCurrentDirectory(dir); | |
4511 | |
4512 ScopedVector<UploadElementReader> element_readers; | |
4513 | |
4514 element_readers.push_back(new UploadFileElementReader( | |
4515 base::MessageLoopProxy::current().get(), | |
4516 base::FilePath(FILE_PATH_LITERAL( | |
4517 "c:\\path\\to\\non\\existant\\file.randomness.12345")), | |
4518 0, | |
4519 kuint64max, | |
4520 base::Time())); | |
4521 r.set_upload(make_scoped_ptr( | |
4522 new UploadDataStream(element_readers.Pass(), 0))); | |
4523 | |
4524 r.Start(); | |
4525 EXPECT_TRUE(r.is_pending()); | |
4526 | |
4527 base::RunLoop().Run(); | |
4528 | |
4529 EXPECT_TRUE(d.request_failed()); | |
4530 EXPECT_FALSE(d.received_data_before_response()); | |
4531 EXPECT_EQ(0, d.bytes_received()); | |
hashimoto
2013/10/29 04:08:59
How about having checks for r.status().status() an
tzik
2013/10/29 06:06:19
The request should be aborted before it set status
hashimoto
2013/10/29 06:55:26
Really? In my local environment, FAILED/ERR_FILE_N
tzik
2013/10/31 12:19:28
Sorry, right it is.
My build might be from another
| |
4532 } | |
4533 } | |
4534 | |
4509 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { | 4535 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { |
4510 ASSERT_TRUE(test_server_.Start()); | 4536 ASSERT_TRUE(test_server_.Start()); |
4511 | 4537 |
4512 TestDelegate d; | 4538 TestDelegate d; |
4513 { | 4539 { |
4514 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 4540 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
4515 r.EnableChunkedUpload(); | 4541 r.EnableChunkedUpload(); |
4516 r.set_method("POST"); | 4542 r.set_method("POST"); |
4517 AddChunksToUpload(&r); | 4543 AddChunksToUpload(&r); |
4518 r.Start(); | 4544 r.Start(); |
(...skipping 2447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6966 | 6992 |
6967 EXPECT_FALSE(r.is_pending()); | 6993 EXPECT_FALSE(r.is_pending()); |
6968 EXPECT_EQ(1, d->response_started_count()); | 6994 EXPECT_EQ(1, d->response_started_count()); |
6969 EXPECT_FALSE(d->received_data_before_response()); | 6995 EXPECT_FALSE(d->received_data_before_response()); |
6970 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 6996 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
6971 } | 6997 } |
6972 } | 6998 } |
6973 #endif // !defined(DISABLE_FTP_SUPPORT) | 6999 #endif // !defined(DISABLE_FTP_SUPPORT) |
6974 | 7000 |
6975 } // namespace net | 7001 } // namespace net |
OLD | NEW |