summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-13 22:24:11 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-13 22:24:11 +0000
commitda5de3c98d0613411df3acb9b692fa200e51dcfb (patch)
tree9be45a808f145fd814012754520333a1dd29d255
parent3134ccf847a577918717e664f4c8b4359b71c57c (diff)
downloadchromium_src-da5de3c98d0613411df3acb9b692fa200e51dcfb.zip
chromium_src-da5de3c98d0613411df3acb9b692fa200e51dcfb.tar.gz
chromium_src-da5de3c98d0613411df3acb9b692fa200e51dcfb.tar.bz2
Add unit test for HttpResponseHeaders::GetStatusText()
Review URL: http://codereview.chromium.org/2822 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2173 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/http/http_response_headers.cc18
-rw-r--r--net/http/http_response_headers_unittest.cc30
2 files changed, 38 insertions, 10 deletions
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index ba96476..604a522 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -199,7 +199,7 @@ void HttpResponseHeaders::Parse(const string& raw_input) {
// has_headers = true, if there is any data following the status line.
// Used by ParseStatusLine() to decide if a HTTP/0.9 is really a HTTP/1.0.
bool has_headers = line_end != raw_input.end() &&
- (line_end + 1) != raw_input.end() && *(line_end + 1) != '\0';
+ (line_end + 1) != raw_input.end() && *(line_end + 1) != '\0';
ParseStatusLine(line_begin, line_end, has_headers);
if (line_end == raw_input.end()) {
@@ -316,8 +316,6 @@ string HttpResponseHeaders::GetStatusLine() const {
}
std::string HttpResponseHeaders::GetStatusText() const {
- // TODO(eroman): this needs a unit test.
-
// GetStatusLine() is already normalized, so it has the format:
// <http_version> SP <response_code> SP <status_text>
std::string status_text = GetStatusLine();
@@ -480,14 +478,14 @@ void HttpResponseHeaders::ParseStatusLine(string::const_iterator line_begin,
if (p == code) {
DLOG(INFO) << "missing response status number; assuming 200";
- raw_headers_.append(" 200 ");
+ raw_headers_.append(" 200 OK");
response_code_ = 200;
- } else {
- raw_headers_.push_back(' ');
- raw_headers_.append(code, p);
- raw_headers_.push_back(' ');
- response_code_ = static_cast<int>(StringToInt64(string(code, p)));
- }
+ return;
+ }
+ raw_headers_.push_back(' ');
+ raw_headers_.append(code, p);
+ raw_headers_.push_back(' ');
+ response_code_ = static_cast<int>(StringToInt64(string(code, p)));
// Skip whitespace.
while (*p == ' ')
diff --git a/net/http/http_response_headers_unittest.cc b/net/http/http_response_headers_unittest.cc
index f02cd7f..6159e93 100644
--- a/net/http/http_response_headers_unittest.cc
+++ b/net/http/http_response_headers_unittest.cc
@@ -1041,3 +1041,33 @@ TEST(HttpResponseHeadersTest, IsKeepAlive) {
}
}
+TEST(HttpResponseHeadersTest, GetStatusText) {
+ std::string headers("HTTP/1.1 404 Not Found");
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers);
+ EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText());
+}
+
+TEST(HttpResponseHeadersTest, GetStatusTextMissing) {
+ std::string headers("HTTP/1.1 404");
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers);
+ // Since the status line gets normalized, we have OK
+ EXPECT_EQ(std::string("OK"), parsed->GetStatusText());
+}
+
+TEST(HttpResponseHeadersTest, GetStatusTextMultiSpace) {
+ std::string headers("HTTP/1.0 404 Not Found");
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers);
+ EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText());
+}
+
+TEST(HttpResponseHeadersTest, GetStatusBadStatusLine) {
+ std::string headers("Foo bar.");
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers);
+ // The bad status line would have gotten rewritten as
+ // HTTP/1.0 200 OK.
+ EXPECT_EQ(std::string("OK"), parsed->GetStatusText());
+}