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

Unified Diff: net/url_request/url_request_unittest.cc

Issue 6134003: Prototype of chunked transfer encoded POST. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
« net/base/upload_data_stream.cc ('K') | « net/url_request/url_request.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_unittest.cc
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index f920fa4059184246e292a75dd217c0b152fb4e05..ce02eeddd901dc2f3fec5d57f1018848b0c7aa7c 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -177,6 +177,31 @@ class URLRequestTestHTTP : public URLRequestTest {
delete[] uploadBytes;
}
+ void AddChunksToUpload(TestURLRequest* r) {
+ r->AppendChunkToUpload("a", 1);
+ r->AppendChunkToUpload("bcd", 3);
+ r->AppendChunkToUpload("this is a longer chunk than before.", 35);
+ r->AppendChunkToUpload("\r\n\r\n", 4);
+ r->AppendChunkToUpload("0", 1);
+ r->AppendChunkToUpload("2323", 4);
+ r->MarkEndOfChunks();
+ }
+
+ void VerifyReceivedDataMatchesChunks(TestURLRequest* r, TestDelegate* d) {
+ // This should match the chunks sent by AddChunksToUpload().
+ const char* expected_data =
+ "abcdthis is a longer chunk than before.\r\n\r\n02323";
+
+ ASSERT_EQ(1, d->response_started_count()) << "request failed: " <<
+ (int) r->status().status() << ", os error: " << r->status().os_error();
+
+ EXPECT_FALSE(d->received_data_before_response());
+
+ ASSERT_EQ(strlen(expected_data), static_cast<size_t>(d->bytes_received()));
+ EXPECT_EQ(0, memcmp(d->data_received().c_str(), expected_data,
+ strlen(expected_data)));
+ }
+
net::TestServer test_server_;
};
@@ -639,6 +664,43 @@ TEST_F(URLRequestTestHTTP, PostFileTest) {
}
}
+TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) {
+ ASSERT_TRUE(test_server_.Start());
+
+ TestDelegate d;
+ {
+ TestURLRequest r(test_server_.GetURL("echo"), &d);
+ r.EnableChunkedUpload();
+ r.set_method("POST");
+ AddChunksToUpload(&r);
+ r.Start();
+ EXPECT_TRUE(r.is_pending());
+
+ MessageLoop::current()->Run();
+
+ VerifyReceivedDataMatchesChunks(&r, &d);
+ }
+}
+
+TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) {
+ ASSERT_TRUE(test_server_.Start());
+
+ TestDelegate d;
+ {
+ TestURLRequest r(test_server_.GetURL("echo"), &d);
+ r.EnableChunkedUpload();
+ r.set_method("POST");
+ r.Start();
+ EXPECT_TRUE(r.is_pending());
+
+ MessageLoop::current()->RunAllPending();
+ AddChunksToUpload(&r);
+ MessageLoop::current()->Run();
+
+ VerifyReceivedDataMatchesChunks(&r, &d);
+ }
+}
+
TEST_F(URLRequestTest, AboutBlankTest) {
TestDelegate d;
{
« net/base/upload_data_stream.cc ('K') | « net/url_request/url_request.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698