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 4637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4648 path = path.Append(FILE_PATH_LITERAL("net")); | 4648 path = path.Append(FILE_PATH_LITERAL("net")); |
4649 path = path.Append(FILE_PATH_LITERAL("data")); | 4649 path = path.Append(FILE_PATH_LITERAL("data")); |
4650 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 4650 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
4651 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 4651 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
4652 element_readers.push_back( | 4652 element_readers.push_back( |
4653 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 4653 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
4654 path, | 4654 path, |
4655 0, | 4655 0, |
4656 kuint64max, | 4656 kuint64max, |
4657 base::Time())); | 4657 base::Time())); |
4658 | |
4659 // This file should just be ignored in the upload stream. | |
4660 element_readers.push_back(new UploadFileElementReader( | |
4661 base::MessageLoopProxy::current().get(), | |
4662 base::FilePath(FILE_PATH_LITERAL( | |
4663 "c:\\path\\to\\non\\existant\\file.randomness.12345")), | |
4664 0, | |
4665 kuint64max, | |
4666 base::Time())); | |
4667 r.set_upload(make_scoped_ptr( | 4658 r.set_upload(make_scoped_ptr( |
4668 new UploadDataStream(element_readers.Pass(), 0))); | 4659 new UploadDataStream(element_readers.Pass(), 0))); |
4669 | 4660 |
4670 r.Start(); | 4661 r.Start(); |
4671 EXPECT_TRUE(r.is_pending()); | 4662 EXPECT_TRUE(r.is_pending()); |
4672 | 4663 |
4673 base::RunLoop().Run(); | 4664 base::RunLoop().Run(); |
4674 | 4665 |
4675 int64 size = 0; | 4666 int64 size = 0; |
4676 ASSERT_EQ(true, file_util::GetFileSize(path, &size)); | 4667 ASSERT_EQ(true, file_util::GetFileSize(path, &size)); |
4677 scoped_ptr<char[]> buf(new char[size]); | 4668 scoped_ptr<char[]> buf(new char[size]); |
4678 | 4669 |
4679 ASSERT_EQ(size, file_util::ReadFile(path, buf.get(), size)); | 4670 ASSERT_EQ(size, file_util::ReadFile(path, buf.get(), size)); |
4680 | 4671 |
4681 ASSERT_EQ(1, d.response_started_count()) | 4672 ASSERT_EQ(1, d.response_started_count()) |
4682 << "request failed: " << r.status().status() | 4673 << "request failed: " << r.status().status() |
4683 << ", error: " << r.status().error(); | 4674 << ", error: " << r.status().error(); |
4684 | 4675 |
4685 EXPECT_FALSE(d.received_data_before_response()); | 4676 EXPECT_FALSE(d.received_data_before_response()); |
4686 | 4677 |
4687 EXPECT_EQ(size, d.bytes_received()); | 4678 EXPECT_EQ(size, d.bytes_received()); |
4688 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); | 4679 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); |
4689 } | 4680 } |
4690 } | 4681 } |
4691 | 4682 |
4683 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { | |
4684 ASSERT_TRUE(test_server_.Start()); | |
4685 | |
4686 TestDelegate d; | |
4687 { | |
4688 URLRequest r(test_server_.GetURL("echo"), DEFAULT_PRIORITY, | |
4689 &d, &default_context_); | |
4690 r.set_method("POST"); | |
4691 | |
4692 ScopedVector<UploadElementReader> element_readers; | |
4693 | |
4694 element_readers.push_back(new UploadFileElementReader( | |
4695 base::MessageLoopProxy::current().get(), | |
4696 base::FilePath(FILE_PATH_LITERAL( | |
4697 "c:\\path\\to\\non\\existant\\file.randomness.12345")), | |
4698 0, | |
4699 kuint64max, | |
4700 base::Time())); | |
4701 r.set_upload(make_scoped_ptr( | |
4702 new UploadDataStream(element_readers.Pass(), 0))); | |
4703 | |
4704 r.Start(); | |
4705 EXPECT_TRUE(r.is_pending()); | |
4706 | |
4707 base::RunLoop().Run(); | |
4708 | |
4709 #if defined(CHROME_FRAME_NET_TESTS) | |
hashimoto
2013/11/08 04:59:08
How about having a TODO to remove this "if defined
tzik
2013/11/11 04:03:04
Done.
I filed a bug and added a comment with a lin
| |
4710 EXPECT_FALSE(d.request_failed()); | |
4711 EXPECT_FALSE(d.received_data_before_response()); | |
4712 EXPECT_EQ(0, d.bytes_received()); | |
4713 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | |
4714 EXPECT_EQ(OK, r.status().error()); | |
4715 #else | |
4716 EXPECT_TRUE(d.request_failed()); | |
4717 EXPECT_FALSE(d.received_data_before_response()); | |
4718 EXPECT_EQ(0, d.bytes_received()); | |
4719 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | |
4720 EXPECT_EQ(ERR_FILE_NOT_FOUND, r.status().error()); | |
4721 #endif // defined(CHROME_FRAME_NET_TESTS) | |
4722 } | |
4723 } | |
4724 | |
4692 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { | 4725 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { |
4693 ASSERT_TRUE(test_server_.Start()); | 4726 ASSERT_TRUE(test_server_.Start()); |
4694 | 4727 |
4695 TestDelegate d; | 4728 TestDelegate d; |
4696 { | 4729 { |
4697 URLRequest r( | 4730 URLRequest r( |
4698 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); | 4731 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); |
4699 r.EnableChunkedUpload(); | 4732 r.EnableChunkedUpload(); |
4700 r.set_method("POST"); | 4733 r.set_method("POST"); |
4701 AddChunksToUpload(&r); | 4734 AddChunksToUpload(&r); |
(...skipping 2544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7246 | 7279 |
7247 EXPECT_FALSE(r.is_pending()); | 7280 EXPECT_FALSE(r.is_pending()); |
7248 EXPECT_EQ(1, d->response_started_count()); | 7281 EXPECT_EQ(1, d->response_started_count()); |
7249 EXPECT_FALSE(d->received_data_before_response()); | 7282 EXPECT_FALSE(d->received_data_before_response()); |
7250 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7283 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
7251 } | 7284 } |
7252 } | 7285 } |
7253 #endif // !defined(DISABLE_FTP_SUPPORT) | 7286 #endif // !defined(DISABLE_FTP_SUPPORT) |
7254 | 7287 |
7255 } // namespace net | 7288 } // namespace net |
OLD | NEW |