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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 39203004: [Net] Fix error handling on wrong file in UploadData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « net/spdy/spdy_network_transaction_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // TODO(tzik): Remove this #if after we stop supporting Chrome Frame.
4710 // http://crbug.com/317432
4711 #if defined(CHROME_FRAME_NET_TESTS)
4712 EXPECT_FALSE(d.request_failed());
4713 EXPECT_FALSE(d.received_data_before_response());
4714 EXPECT_EQ(0, d.bytes_received());
4715 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
4716 EXPECT_EQ(OK, r.status().error());
4717 #else
4718 EXPECT_TRUE(d.request_failed());
4719 EXPECT_FALSE(d.received_data_before_response());
4720 EXPECT_EQ(0, d.bytes_received());
4721 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
4722 EXPECT_EQ(ERR_FILE_NOT_FOUND, r.status().error());
4723 #endif // defined(CHROME_FRAME_NET_TESTS)
4724 }
4725 }
4726
4692 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { 4727 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) {
4693 ASSERT_TRUE(test_server_.Start()); 4728 ASSERT_TRUE(test_server_.Start());
4694 4729
4695 TestDelegate d; 4730 TestDelegate d;
4696 { 4731 {
4697 URLRequest r( 4732 URLRequest r(
4698 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); 4733 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_);
4699 r.EnableChunkedUpload(); 4734 r.EnableChunkedUpload();
4700 r.set_method("POST"); 4735 r.set_method("POST");
4701 AddChunksToUpload(&r); 4736 AddChunksToUpload(&r);
(...skipping 2544 matching lines...) Expand 10 before | Expand all | Expand 10 after
7246 7281
7247 EXPECT_FALSE(r.is_pending()); 7282 EXPECT_FALSE(r.is_pending());
7248 EXPECT_EQ(1, d->response_started_count()); 7283 EXPECT_EQ(1, d->response_started_count());
7249 EXPECT_FALSE(d->received_data_before_response()); 7284 EXPECT_FALSE(d->received_data_before_response());
7250 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 7285 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
7251 } 7286 }
7252 } 7287 }
7253 #endif // !defined(DISABLE_FTP_SUPPORT) 7288 #endif // !defined(DISABLE_FTP_SUPPORT)
7254 7289
7255 } // namespace net 7290 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_network_transaction_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698