1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/http/http_status_code.h"
6 #include "net/server/http_server_response_info.h"
7 #include "testing/gtest/include/gtest/gtest.h"
11 TEST(HttpServerResponseInfoTest
, StatusLine
) {
12 HttpServerResponseInfo response
;
13 ASSERT_EQ(HTTP_OK
, response
.status_code());
14 ASSERT_EQ("HTTP/1.1 200 OK\r\n\r\n", response
.Serialize());
17 TEST(HttpServerResponseInfoTest
, Headers
) {
18 HttpServerResponseInfo response
;
19 response
.AddHeader("A", "1");
20 response
.AddHeader("A", "2");
21 ASSERT_EQ("HTTP/1.1 200 OK\r\nA:1\r\nA:2\r\n\r\n", response
.Serialize());
24 TEST(HttpServerResponseInfoTest
, Body
) {
25 HttpServerResponseInfo response
;
26 ASSERT_EQ(std::string(), response
.body());
27 response
.SetBody("body", "type");
28 ASSERT_EQ("body", response
.body());
30 "HTTP/1.1 200 OK\r\nContent-Length:4\r\nContent-Type:type\r\n\r\nbody",
31 response
.Serialize());
34 TEST(HttpServerResponseInfoTest
, CreateFor404
) {
35 HttpServerResponseInfo response
= HttpServerResponseInfo::CreateFor404();
37 "HTTP/1.1 404 Not Found\r\n"
38 "Content-Length:0\r\nContent-Type:text/html\r\n\r\n",
39 response
.Serialize());
42 TEST(HttpServerResponseInfoTest
, CreateFor500
) {
43 HttpServerResponseInfo response
=
44 HttpServerResponseInfo::CreateFor500("mess");
46 "HTTP/1.1 500 Internal Server Error\r\n"
47 "Content-Length:4\r\nContent-Type:text/html\r\n\r\nmess",
48 response
.Serialize());