diff options
author | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-15 17:14:25 +0000 |
---|---|---|
committer | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-15 17:14:25 +0000 |
commit | 07d0f40abfdfbd9259db6e13622bb0ac49887a78 (patch) | |
tree | f5e6fb5006b2eeb6f1541442b35a8f27acfe2df8 /chrome/test/webdriver/http_response_unittest.cc | |
parent | 35d3e474ffdeb4c679188a590ae2fefbfcec8a78 (diff) | |
download | chromium_src-07d0f40abfdfbd9259db6e13622bb0ac49887a78.zip chromium_src-07d0f40abfdfbd9259db6e13622bb0ac49887a78.tar.gz chromium_src-07d0f40abfdfbd9259db6e13622bb0ac49887a78.tar.bz2 |
Encapsulate HTTP response logic in a single class and remove redundant SendHttp*
functions from dispatch.cc. Patch by jleyba@chromium.org. Original review at
http://codereview.chromium.org/6505003
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6526009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74961 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/webdriver/http_response_unittest.cc')
-rw-r--r-- | chrome/test/webdriver/http_response_unittest.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/chrome/test/webdriver/http_response_unittest.cc b/chrome/test/webdriver/http_response_unittest.cc new file mode 100644 index 0000000..71be83f --- /dev/null +++ b/chrome/test/webdriver/http_response_unittest.cc @@ -0,0 +1,89 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/webdriver/http_response.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace webdriver { + +namespace { + +void ExpectHeaderValue(const HttpResponse& response, const std::string& name, + const std::string& expected_value) { + std::string actual_value; + EXPECT_TRUE(response.GetHeader(name, &actual_value)); + EXPECT_EQ(expected_value, actual_value); +} + +} // namespace + +TEST(HttpResponseTest, AddingHeaders) { + HttpResponse response; + + response.AddHeader("FOO", "a"); + ExpectHeaderValue(response, "foo", "a"); + + // Headers should be case insensitive. + response.AddHeader("fOo", "b,c"); + response.AddHeader("FoO", "d"); + ExpectHeaderValue(response, "foo", "a,b,c,d"); +} + +TEST(HttpResponseTest, RemovingHeaders) { + HttpResponse response; + + ASSERT_FALSE(response.RemoveHeader("I-Am-Not-There")); + + ASSERT_FALSE(response.GetHeader("foo", NULL)); + response.AddHeader("foo", "bar"); + ASSERT_TRUE(response.GetHeader("foo", NULL)); + ASSERT_TRUE(response.RemoveHeader("foo")); + ASSERT_FALSE(response.GetHeader("foo", NULL)); +} + +TEST(HttpResponseTest, CanClearAllHeaders) { + HttpResponse response; + response.AddHeader("food", "cheese"); + response.AddHeader("color", "red"); + + ExpectHeaderValue(response, "food", "cheese"); + ExpectHeaderValue(response, "color", "red"); + + response.ClearHeaders(); + EXPECT_FALSE(response.GetHeader("food", NULL)); + EXPECT_FALSE(response.GetHeader("color", NULL)); +} + +TEST(HttpResponseTest, CanSetMimeType) { + HttpResponse response; + + response.SetMimeType("application/json"); + ExpectHeaderValue(response, "content-type", "application/json"); + + response.SetMimeType("text/html"); + ExpectHeaderValue(response, "content-type", "text/html"); +} + +TEST(HttpResponseTest, SetBody) { + HttpResponse response; + + std::string body("foo bar"); + response.SetBody(body); + ASSERT_EQ(body.length(), response.length()); + ASSERT_EQ(body, std::string(response.data(), response.length())); + + // Grow the response size. + body.append(" baz"); + response.SetBody(body); + ASSERT_EQ(body.length(), response.length()); + ASSERT_EQ(body, std::string(response.data(), response.length())); + + // Shrink the response size. + body = "small"; + response.SetBody(body); + ASSERT_EQ(body.length(), response.length()); + ASSERT_EQ(body, std::string(response.data(), response.length())); +} + +} // namespace webdriver |