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