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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/url_request/url_request_unittest.h" 5 #include "net/url_request/url_request_unittest.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 (int) r.status().status() << ", os error: " << r.status().os_error(); 170 (int) r.status().status() << ", os error: " << r.status().os_error();
171 171
172 EXPECT_FALSE(d.received_data_before_response()); 172 EXPECT_FALSE(d.received_data_before_response());
173 EXPECT_EQ(uploadBytes, d.data_received()); 173 EXPECT_EQ(uploadBytes, d.data_received());
174 EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize), 0); 174 EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize), 0);
175 EXPECT_EQ(d.data_received().compare(uploadBytes), 0); 175 EXPECT_EQ(d.data_received().compare(uploadBytes), 0);
176 } 176 }
177 delete[] uploadBytes; 177 delete[] uploadBytes;
178 } 178 }
179 179
180 void AddChunksToUpload(TestURLRequest* r) {
181 r->AppendChunkToUpload("a", 1);
182 r->AppendChunkToUpload("bcd", 3);
183 r->AppendChunkToUpload("this is a longer chunk than before.", 35);
184 r->AppendChunkToUpload("\r\n\r\n", 4);
185 r->AppendChunkToUpload("0", 1);
186 r->AppendChunkToUpload("2323", 4);
187 r->MarkEndOfChunks();
188 }
189
190 void VerifyReceivedDataMatchesChunks(TestURLRequest* r, TestDelegate* d) {
191 // This should match the chunks sent by AddChunksToUpload().
192 const char* expected_data =
193 "abcdthis is a longer chunk than before.\r\n\r\n02323";
194
195 ASSERT_EQ(1, d->response_started_count()) << "request failed: " <<
196 (int) r->status().status() << ", os error: " << r->status().os_error();
197
198 EXPECT_FALSE(d->received_data_before_response());
199
200 ASSERT_EQ(strlen(expected_data), static_cast<size_t>(d->bytes_received()));
201 EXPECT_EQ(0, memcmp(d->data_received().c_str(), expected_data,
202 strlen(expected_data)));
203 }
204
180 net::TestServer test_server_; 205 net::TestServer test_server_;
181 }; 206 };
182 207
183 // In this unit test, we're using the HTTPTestServer as a proxy server and 208 // In this unit test, we're using the HTTPTestServer as a proxy server and
184 // issuing a CONNECT request with the magic host name "www.redirect.com". 209 // issuing a CONNECT request with the magic host name "www.redirect.com".
185 // The HTTPTestServer will return a 302 response, which we should not 210 // The HTTPTestServer will return a 302 response, which we should not
186 // follow. 211 // follow.
187 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { 212 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) {
188 ASSERT_TRUE(test_server_.Start()); 213 ASSERT_TRUE(test_server_.Start());
189 214
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << 657 ASSERT_EQ(1, d.response_started_count()) << "request failed: " <<
633 (int) r.status().status() << ", os error: " << r.status().os_error(); 658 (int) r.status().status() << ", os error: " << r.status().os_error();
634 659
635 EXPECT_FALSE(d.received_data_before_response()); 660 EXPECT_FALSE(d.received_data_before_response());
636 661
637 ASSERT_EQ(size, d.bytes_received()); 662 ASSERT_EQ(size, d.bytes_received());
638 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); 663 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size));
639 } 664 }
640 } 665 }
641 666
667 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) {
668 ASSERT_TRUE(test_server_.Start());
669
670 TestDelegate d;
671 {
672 TestURLRequest r(test_server_.GetURL("echo"), &d);
673 r.EnableChunkedUpload();
674 r.set_method("POST");
675 AddChunksToUpload(&r);
676 r.Start();
677 EXPECT_TRUE(r.is_pending());
678
679 MessageLoop::current()->Run();
680
681 VerifyReceivedDataMatchesChunks(&r, &d);
682 }
683 }
684
685 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) {
686 ASSERT_TRUE(test_server_.Start());
687
688 TestDelegate d;
689 {
690 TestURLRequest r(test_server_.GetURL("echo"), &d);
691 r.EnableChunkedUpload();
692 r.set_method("POST");
693 r.Start();
694 EXPECT_TRUE(r.is_pending());
695
696 MessageLoop::current()->RunAllPending();
697 AddChunksToUpload(&r);
698 MessageLoop::current()->Run();
699
700 VerifyReceivedDataMatchesChunks(&r, &d);
701 }
702 }
703
642 TEST_F(URLRequestTest, AboutBlankTest) { 704 TEST_F(URLRequestTest, AboutBlankTest) {
643 TestDelegate d; 705 TestDelegate d;
644 { 706 {
645 TestURLRequest r(GURL("about:blank"), &d); 707 TestURLRequest r(GURL("about:blank"), &d);
646 708
647 r.Start(); 709 r.Start();
648 EXPECT_TRUE(r.is_pending()); 710 EXPECT_TRUE(r.is_pending());
649 711
650 MessageLoop::current()->Run(); 712 MessageLoop::current()->Run();
651 713
(...skipping 2016 matching lines...) Expand 10 before | Expand all | Expand 10 after
2668 net::HttpRequestHeaders headers; 2730 net::HttpRequestHeaders headers;
2669 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); 2731 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)");
2670 req.SetExtraRequestHeaders(headers); 2732 req.SetExtraRequestHeaders(headers);
2671 req.Start(); 2733 req.Start();
2672 MessageLoop::current()->Run(); 2734 MessageLoop::current()->Run();
2673 // If the net tests are being run with ChromeFrame then we need to allow for 2735 // If the net tests are being run with ChromeFrame then we need to allow for
2674 // the 'chromeframe' suffix which is added to the user agent in outgoing HTTP 2736 // the 'chromeframe' suffix which is added to the user agent in outgoing HTTP
2675 // requests. 2737 // requests.
2676 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode)", true)); 2738 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode)", true));
2677 } 2739 }
OLDNEW
« 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