OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 "chrome/test/webdriver/http_response.h" | |
6 #include "testing/gtest/include/gtest/gtest.h" | |
7 | |
8 namespace webdriver { | |
9 | |
10 namespace { | |
11 | |
12 void ExpectHeaderValue(const HttpResponse& response, const std::string& name, | |
13 const std::string& expected_value) { | |
14 std::string actual_value; | |
15 EXPECT_TRUE(response.GetHeader(name, &actual_value)); | |
16 EXPECT_EQ(expected_value, actual_value); | |
17 } | |
18 | |
19 } // namespace | |
20 | |
21 TEST(HttpResponseTest, AddingHeaders) { | |
22 HttpResponse response; | |
23 | |
24 response.AddHeader("FOO", "a"); | |
25 ExpectHeaderValue(response, "foo", "a"); | |
26 | |
27 // Headers should be case insensitive. | |
28 response.AddHeader("fOo", "b,c"); | |
29 response.AddHeader("FoO", "d"); | |
30 ExpectHeaderValue(response, "foo", "a,b,c,d"); | |
31 } | |
32 | |
33 TEST(HttpResponseTest, RemovingHeaders) { | |
34 HttpResponse response; | |
35 | |
36 ASSERT_FALSE(response.RemoveHeader("I-Am-Not-There")); | |
37 | |
38 ASSERT_FALSE(response.GetHeader("foo", NULL)); | |
39 response.AddHeader("foo", "bar"); | |
40 ASSERT_TRUE(response.GetHeader("foo", NULL)); | |
41 ASSERT_TRUE(response.RemoveHeader("foo")); | |
42 ASSERT_FALSE(response.GetHeader("foo", NULL)); | |
43 } | |
44 | |
45 TEST(HttpResponseTest, CanClearAllHeaders) { | |
46 HttpResponse response; | |
47 response.AddHeader("food", "cheese"); | |
48 response.AddHeader("color", "red"); | |
49 | |
50 ExpectHeaderValue(response, "food", "cheese"); | |
51 ExpectHeaderValue(response, "color", "red"); | |
52 | |
53 response.ClearHeaders(); | |
54 EXPECT_FALSE(response.GetHeader("food", NULL)); | |
55 EXPECT_FALSE(response.GetHeader("color", NULL)); | |
56 } | |
57 | |
58 TEST(HttpResponseTest, CanSetMimeType) { | |
59 HttpResponse response; | |
60 | |
61 response.SetMimeType("application/json"); | |
62 ExpectHeaderValue(response, "content-type", "application/json"); | |
63 | |
64 response.SetMimeType("text/html"); | |
65 ExpectHeaderValue(response, "content-type", "text/html"); | |
66 } | |
67 | |
68 TEST(HttpResponseTest, GetData) { | |
69 HttpResponse response; | |
70 response.set_body("my body"); | |
71 std::string data; | |
72 response.GetData(&data); | |
73 const char* expected = | |
74 "HTTP/1.1 200 OK\r\n" | |
75 "content-length:7\r\n" | |
76 "\r\n" | |
77 "my body"; | |
78 ASSERT_STREQ(expected, data.c_str()); | |
79 } | |
80 | |
81 } // namespace webdriver | |
OLD | NEW |