http_server_response_info_unittest.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "net/http/http_status_code.h"
  5. #include "net/server/http_server_response_info.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace net {
  8. TEST(HttpServerResponseInfoTest, StatusLine) {
  9. HttpServerResponseInfo response;
  10. ASSERT_EQ(HTTP_OK, response.status_code());
  11. ASSERT_EQ("HTTP/1.1 200 OK\r\n\r\n", response.Serialize());
  12. }
  13. TEST(HttpServerResponseInfoTest, Headers) {
  14. HttpServerResponseInfo response;
  15. response.AddHeader("A", "1");
  16. response.AddHeader("A", "2");
  17. ASSERT_EQ("HTTP/1.1 200 OK\r\nA:1\r\nA:2\r\n\r\n", response.Serialize());
  18. }
  19. TEST(HttpServerResponseInfoTest, Body) {
  20. HttpServerResponseInfo response;
  21. ASSERT_EQ(std::string(), response.body());
  22. response.SetBody("body", "type");
  23. ASSERT_EQ("body", response.body());
  24. ASSERT_EQ(
  25. "HTTP/1.1 200 OK\r\nContent-Length:4\r\nContent-Type:type\r\n\r\nbody",
  26. response.Serialize());
  27. }
  28. TEST(HttpServerResponseInfoTest, CreateFor404) {
  29. HttpServerResponseInfo response = HttpServerResponseInfo::CreateFor404();
  30. ASSERT_EQ(
  31. "HTTP/1.1 404 Not Found\r\n"
  32. "Content-Length:0\r\nContent-Type:text/html\r\n\r\n",
  33. response.Serialize());
  34. }
  35. TEST(HttpServerResponseInfoTest, CreateFor500) {
  36. HttpServerResponseInfo response =
  37. HttpServerResponseInfo::CreateFor500("mess");
  38. ASSERT_EQ(
  39. "HTTP/1.1 500 Internal Server Error\r\n"
  40. "Content-Length:4\r\nContent-Type:text/html\r\n\r\nmess",
  41. response.Serialize());
  42. }
  43. } // namespace net