OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/webdriver/http_response.h" | 5 #include "chrome/test/webdriver/http_response.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 namespace webdriver { | 8 namespace webdriver { |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 TEST(HttpResponseTest, CanSetMimeType) { | 58 TEST(HttpResponseTest, CanSetMimeType) { |
59 HttpResponse response; | 59 HttpResponse response; |
60 | 60 |
61 response.SetMimeType("application/json"); | 61 response.SetMimeType("application/json"); |
62 ExpectHeaderValue(response, "content-type", "application/json"); | 62 ExpectHeaderValue(response, "content-type", "application/json"); |
63 | 63 |
64 response.SetMimeType("text/html"); | 64 response.SetMimeType("text/html"); |
65 ExpectHeaderValue(response, "content-type", "text/html"); | 65 ExpectHeaderValue(response, "content-type", "text/html"); |
66 } | 66 } |
67 | 67 |
68 TEST(HttpResponseTest, SetBody) { | 68 TEST(HttpResponseTest, GetData) { |
69 HttpResponse response; | 69 HttpResponse response; |
70 | 70 response.set_body("my body"); |
71 std::string body("foo bar"); | 71 std::string data; |
72 response.SetBody(body); | 72 response.GetData(&data); |
73 ASSERT_EQ(body.length(), response.length()); | 73 const char* expected = |
74 ASSERT_EQ(body, std::string(response.data(), response.length())); | 74 "HTTP/1.1 200 OK\r\n" |
75 | 75 "content-length:7\r\n" |
76 // Grow the response size. | 76 "\r\n" |
77 body.append(" baz"); | 77 "my body"; |
78 response.SetBody(body); | 78 ASSERT_STREQ(expected, data.c_str()); |
79 ASSERT_EQ(body.length(), response.length()); | |
80 ASSERT_EQ(body, std::string(response.data(), response.length())); | |
81 | |
82 // Shrink the response size. | |
83 body = "small"; | |
84 response.SetBody(body); | |
85 ASSERT_EQ(body.length(), response.length()); | |
86 ASSERT_EQ(body, std::string(response.data(), response.length())); | |
87 } | 79 } |
88 | 80 |
89 } // namespace webdriver | 81 } // namespace webdriver |
OLD | NEW |