| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/string_util.h" | 5 #include "base/string_util.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" | 7 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" |
| 8 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 8 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 9 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
| 10 #include "webkit/plugins/npapi/webplugin_impl.h" | 10 #include "webkit/glue/plugins/webplugin_impl.h" |
| 11 | 11 |
| 12 using WebKit::WebHTTPBody; | 12 using WebKit::WebHTTPBody; |
| 13 using WebKit::WebString; | 13 using WebKit::WebString; |
| 14 using WebKit::WebURLRequest; | 14 using WebKit::WebURLRequest; |
| 15 | 15 using webkit_glue::WebPluginImpl; |
| 16 namespace webkit { | |
| 17 namespace npapi { | |
| 18 | 16 |
| 19 namespace { | 17 namespace { |
| 20 | 18 |
| 21 std::string GetHeader(const WebURLRequest& request, const char* name) { | 19 class WebPluginImplTest : public testing::Test { |
| 20 }; |
| 21 |
| 22 } |
| 23 |
| 24 static std::string GetHeader(const WebURLRequest& request, const char* name) { |
| 22 std::string result; | 25 std::string result; |
| 23 TrimWhitespace( | 26 TrimWhitespace( |
| 24 request.httpHeaderField(WebString::fromUTF8(name)).utf8(), | 27 request.httpHeaderField(WebString::fromUTF8(name)).utf8(), |
| 25 TRIM_ALL, | 28 TRIM_ALL, |
| 26 &result); | 29 &result); |
| 27 return result; | 30 return result; |
| 28 } | 31 } |
| 29 | 32 |
| 30 std::string GetBodyText(const WebURLRequest& request) { | 33 static std::string GetBodyText(const WebURLRequest& request) { |
| 31 const WebHTTPBody& body = request.httpBody(); | 34 const WebHTTPBody& body = request.httpBody(); |
| 32 if (body.isNull()) | 35 if (body.isNull()) |
| 33 return std::string(); | 36 return std::string(); |
| 34 | 37 |
| 35 std::string result; | 38 std::string result; |
| 36 size_t i = 0; | 39 size_t i = 0; |
| 37 WebHTTPBody::Element element; | 40 WebHTTPBody::Element element; |
| 38 while (body.elementAt(i++, element)) { | 41 while (body.elementAt(i++, element)) { |
| 39 if (element.type == WebHTTPBody::Element::TypeData) { | 42 if (element.type == WebHTTPBody::Element::TypeData) { |
| 40 result.append(element.data.data(), element.data.size()); | 43 result.append(element.data.data(), element.data.size()); |
| 41 } else { | 44 } else { |
| 42 NOTREACHED() << "unexpected element type encountered!"; | 45 NOTREACHED() << "unexpected element type encountered!"; |
| 43 } | 46 } |
| 44 } | 47 } |
| 45 return result; | 48 return result; |
| 46 } | 49 } |
| 47 | 50 |
| 48 } // namespace | |
| 49 | |
| 50 // The Host functions for NPN_PostURL and NPN_PostURLNotify | 51 // The Host functions for NPN_PostURL and NPN_PostURLNotify |
| 51 // need to parse out some HTTP headers. Make sure it works | 52 // need to parse out some HTTP headers. Make sure it works |
| 52 // with the following tests | 53 // with the following tests |
| 53 | 54 |
| 54 TEST(WebPluginImplTest, PostParserSimple) { | 55 TEST(WebPluginImplTest, PostParserSimple) { |
| 55 // Test a simple case with headers & data | 56 // Test a simple case with headers & data |
| 56 const char *ex1 = "foo: bar\nContent-length: 10\n\nabcdefghij"; | 57 const char *ex1 = "foo: bar\nContent-length: 10\n\nabcdefghij"; |
| 57 WebURLRequest request; | 58 WebURLRequest request; |
| 58 request.initialize(); | 59 request.initialize(); |
| 59 bool rv = WebPluginImpl::SetPostData(&request, ex1, | 60 bool rv = WebPluginImpl::SetPostData(&request, ex1, |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 EXPECT_EQ(0U, GetHeader(request, "bar").length()); | 223 EXPECT_EQ(0U, GetHeader(request, "bar").length()); |
| 223 EXPECT_EQ(0U, GetHeader(request, "Content-length").length()); | 224 EXPECT_EQ(0U, GetHeader(request, "Content-length").length()); |
| 224 | 225 |
| 225 std::string body = GetBodyText(request); | 226 std::string body = GetBodyText(request); |
| 226 | 227 |
| 227 EXPECT_EQ(0xF0, (unsigned char)body[0]); | 228 EXPECT_EQ(0xF0, (unsigned char)body[0]); |
| 228 EXPECT_EQ(0xFF, (unsigned char)body[1]); | 229 EXPECT_EQ(0xFF, (unsigned char)body[1]); |
| 229 EXPECT_EQ(0xFF, (unsigned char)body[2]); | 230 EXPECT_EQ(0xFF, (unsigned char)body[2]); |
| 230 EXPECT_EQ(0xFF, (unsigned char)body[3]); | 231 EXPECT_EQ(0xFF, (unsigned char)body[3]); |
| 231 } | 232 } |
| 232 | |
| 233 } // namespace npapi | |
| 234 } // namespace webkit | |
| OLD | NEW |