summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-23 16:09:41 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-23 16:09:41 +0000
commiteb834fb878a343d3ff67ba087e783a6e796d6fd5 (patch)
tree1c730e3d447ec4bee84b402ad98a5518fe46172e /net
parent596284a3e66f287144f397cc733ca32447f92df9 (diff)
downloadchromium_src-eb834fb878a343d3ff67ba087e783a6e796d6fd5.zip
chromium_src-eb834fb878a343d3ff67ba087e783a6e796d6fd5.tar.gz
chromium_src-eb834fb878a343d3ff67ba087e783a6e796d6fd5.tar.bz2
Fixes ChromeFrame net tests which run the URLRequest unit tests by launching IE and having it issue
the corresponding HTTP requests via automation. Fixes as below:- 1. The DefaultAcceptCharset and DefaultAcceptLanguage tests were failing because the URL request automation job would only read the extra headers from the request. These tests set these headers in the URLRequestContext. We needed to mimic the functionality in the URLRequestHttpJob to add in these headers if they were not already present. As part of this I moved the AppendHeaderIfMissing function from url_request_http_job.cc to HttpUtil as it is needed by the automation job as well. 2. The OverrideAcceptLanguage and OverrideAcceptCharset tests started failing in chrome frame net tests after the fixes to get the default versions of these tests to pass. These tests basically pass in the Accept-Language and Accept-Charset headers and expect the same values to be echoed back. IE ends up caching the responses from the default versions of these tests and thus echoes back the old response which causes these tests to fail. I tried passing in the no-cache header from our HTTP server for the EchoHeader tests but this did not work. To fix this we now pass in the echoheaderoverride parameter for the OverrideAcceptLanguage and OverrideAcceptCharset tests. The HTTP server has been updated to support this. 3. NotifyDone can be called on the job if the original request was redirected. Added a check for whether NotifyDone was already called on the job in URLRequestAutomationJob Review URL: http://codereview.chromium.org/322004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29895 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/http/http_util.cc10
-rw-r--r--net/http/http_util.h6
-rw-r--r--net/tools/testserver/testserver.py18
-rw-r--r--net/url_request/url_request_http_job.cc24
-rw-r--r--net/url_request/url_request_unittest.cc6
5 files changed, 43 insertions, 21 deletions
diff --git a/net/http/http_util.cc b/net/http/http_util.cc
index 72c7737e..5ea46d0 100644
--- a/net/http/http_util.cc
+++ b/net/http/http_util.cc
@@ -596,6 +596,16 @@ std::string HttpUtil::GenerateAcceptCharsetHeader(const std::string& charset) {
return charset_with_q;
}
+void HttpUtil::AppendHeaderIfMissing(const char* header_name,
+ const std::string& header_value,
+ std::string* headers) {
+ if (header_value.empty())
+ return;
+ if (net::HttpUtil::HasHeader(*headers, header_name))
+ return;
+ *headers += std::string(header_name) + ": " + header_value + "\r\n";
+}
+
// BNF from section 4.2 of RFC 2616:
//
// message-header = field-name ":" [ field-value ]
diff --git a/net/http/http_util.h b/net/http/http_util.h
index a3b0def..c630cfe 100644
--- a/net/http/http_util.h
+++ b/net/http/http_util.h
@@ -144,6 +144,12 @@ class HttpUtil {
// 'euc-jp,utf-8;q=0.7,*;q=0.3'.
static std::string GenerateAcceptCharsetHeader(const std::string& charset);
+ // Helper. If |*headers| already contains |header_name| do nothing,
+ // otherwise add <header_name> ": " <header_value> to the end of the list.
+ static void AppendHeaderIfMissing(const char* header_name,
+ const std::string& header_value,
+ std::string* headers);
+
// Used to iterate over the name/value pairs of HTTP headers. To iterate
// over the values in a multi-value header, use ValuesIterator.
// See AssembleRawHeaders for joining line continuations (this iterator
diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py
index b80a939..98d5bbc 100644
--- a/net/tools/testserver/testserver.py
+++ b/net/tools/testserver/testserver.py
@@ -113,6 +113,7 @@ class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.DownloadHandler,
self.DownloadFinishHandler,
self.EchoHeader,
+ self.EchoHeaderOverride,
self.EchoAllHandler,
self.FileHandler,
self.RealFileWithCommonHeaderHandler,
@@ -408,8 +409,23 @@ class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def EchoHeader(self):
"""This handler echoes back the value of a specific request header."""
+ """The only difference between this function and the EchoHeaderOverride"""
+ """function is in the parameter being passed to the helper function"""
+ return self.EchoHeaderHelper("/echoheader")
- if not self._ShouldHandleRequest("/echoheader"):
+ def EchoHeaderOverride(self):
+ """This handler echoes back the value of a specific request header."""
+ """The UrlRequest unit tests also execute for ChromeFrame which uses"""
+ """IE to issue HTTP requests using the host network stack."""
+ """The Accept and Charset tests which expect the server to echo back"""
+ """the corresponding headers fail here as IE returns cached responses"""
+ """The EchoHeaderOverride parameter is an easy way to ensure that IE"""
+ """treats this request as a new request and does not cache it."""
+ return self.EchoHeaderHelper("/echoheaderoverride")
+
+ def EchoHeaderHelper(self, echo_header):
+ """This function echoes back the value of the request header passed in."""
+ if not self._ShouldHandleRequest(echo_header):
return False
query_char = self.path.find('?')
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index aa75574..84d5709 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -584,18 +584,6 @@ void URLRequestHttpJob::StartTransaction() {
this, &URLRequestHttpJob::OnStartCompleted, rv));
}
-// Helper. If |*headers| already contains |header_name| do nothing,
-// otherwise add <header_name> ": " <header_value> to the end of the list.
-static void AppendHeaderIfMissing(const char* header_name,
- const std::string& header_value,
- std::string* headers) {
- if (header_value.empty())
- return;
- if (net::HttpUtil::HasHeader(*headers, header_name))
- return;
- *headers += std::string(header_name) + ": " + header_value + "\r\n";
-}
-
void URLRequestHttpJob::AddExtraHeaders() {
// TODO(jar): Consider optimizing away SDCH advertising bytes when the URL is
// probably an img or such (and SDCH encoding is not likely).
@@ -655,12 +643,12 @@ void URLRequestHttpJob::AddExtraHeaders() {
// Only add default Accept-Language and Accept-Charset if the request
// didn't have them specified.
- AppendHeaderIfMissing("Accept-Language",
- context->accept_language(),
- &request_info_.extra_headers);
- AppendHeaderIfMissing("Accept-Charset",
- context->accept_charset(),
- &request_info_.extra_headers);
+ net::HttpUtil::AppendHeaderIfMissing("Accept-Language",
+ context->accept_language(),
+ &request_info_.extra_headers);
+ net::HttpUtil::AppendHeaderIfMissing("Accept-Charset",
+ context->accept_charset(),
+ &request_info_.extra_headers);
}
}
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 0693ac1..6aee61a 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -2177,7 +2177,8 @@ TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) {
TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) {
ASSERT_TRUE(NULL != server_.get());
TestDelegate d;
- TestURLRequest req(server_->TestServerPage("echoheader?Accept-Language"), &d);
+ TestURLRequest
+ req(server_->TestServerPage("echoheaderoverride?Accept-Language"), &d);
req.set_context(new URLRequestTestContext());
req.SetExtraRequestHeaders("Accept-Language: ru");
req.Start();
@@ -2201,7 +2202,8 @@ TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) {
TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) {
ASSERT_TRUE(NULL != server_.get());
TestDelegate d;
- TestURLRequest req(server_->TestServerPage("echoheader?Accept-Charset"), &d);
+ TestURLRequest
+ req(server_->TestServerPage("echoheaderoverride?Accept-Charset"), &d);
req.set_context(new URLRequestTestContext());
req.SetExtraRequestHeaders("Accept-Charset: koi-8r");
req.Start();