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.
4
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"
8
9namespace net {
10
11TEST(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());
15}
16
17TEST(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());
22}
23
24TEST(HttpServerResponseInfoTest, Body) {
25  HttpServerResponseInfo response;
26  ASSERT_EQ(std::string(), response.body());
27  response.SetBody("body", "type");
28  ASSERT_EQ("body", response.body());
29  ASSERT_EQ(
30      "HTTP/1.1 200 OK\r\nContent-Length:4\r\nContent-Type:type\r\n\r\nbody",
31      response.Serialize());
32}
33
34TEST(HttpServerResponseInfoTest, CreateFor404) {
35  HttpServerResponseInfo response = HttpServerResponseInfo::CreateFor404();
36  ASSERT_EQ(
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());
40}
41
42TEST(HttpServerResponseInfoTest, CreateFor500) {
43  HttpServerResponseInfo response =
44      HttpServerResponseInfo::CreateFor500("mess");
45  ASSERT_EQ(
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());
49}
50
51}  // namespace net
52