Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: webkit/plugins/npapi/webplugin_impl_unittest.cc

Issue 6012002: Move the NPAPI files from webkit/glue/plugins to webkit/plugins/npapi and put... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/npapi/webplugin_impl.cc ('k') | webkit/plugins/npapi/webplugin_page_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/glue/plugins/webplugin_impl.h" 10 #include "webkit/plugins/npapi/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 using webkit_glue::WebPluginImpl; 15
16 namespace webkit {
17 namespace npapi {
16 18
17 namespace { 19 namespace {
18 20
19 class WebPluginImplTest : public testing::Test { 21 std::string GetHeader(const WebURLRequest& request, const char* name) {
20 };
21
22 }
23
24 static std::string GetHeader(const WebURLRequest& request, const char* name) {
25 std::string result; 22 std::string result;
26 TrimWhitespace( 23 TrimWhitespace(
27 request.httpHeaderField(WebString::fromUTF8(name)).utf8(), 24 request.httpHeaderField(WebString::fromUTF8(name)).utf8(),
28 TRIM_ALL, 25 TRIM_ALL,
29 &result); 26 &result);
30 return result; 27 return result;
31 } 28 }
32 29
33 static std::string GetBodyText(const WebURLRequest& request) { 30 std::string GetBodyText(const WebURLRequest& request) {
34 const WebHTTPBody& body = request.httpBody(); 31 const WebHTTPBody& body = request.httpBody();
35 if (body.isNull()) 32 if (body.isNull())
36 return std::string(); 33 return std::string();
37 34
38 std::string result; 35 std::string result;
39 size_t i = 0; 36 size_t i = 0;
40 WebHTTPBody::Element element; 37 WebHTTPBody::Element element;
41 while (body.elementAt(i++, element)) { 38 while (body.elementAt(i++, element)) {
42 if (element.type == WebHTTPBody::Element::TypeData) { 39 if (element.type == WebHTTPBody::Element::TypeData) {
43 result.append(element.data.data(), element.data.size()); 40 result.append(element.data.data(), element.data.size());
44 } else { 41 } else {
45 NOTREACHED() << "unexpected element type encountered!"; 42 NOTREACHED() << "unexpected element type encountered!";
46 } 43 }
47 } 44 }
48 return result; 45 return result;
49 } 46 }
50 47
48 } // namespace
49
51 // The Host functions for NPN_PostURL and NPN_PostURLNotify 50 // The Host functions for NPN_PostURL and NPN_PostURLNotify
52 // need to parse out some HTTP headers. Make sure it works 51 // need to parse out some HTTP headers. Make sure it works
53 // with the following tests 52 // with the following tests
54 53
55 TEST(WebPluginImplTest, PostParserSimple) { 54 TEST(WebPluginImplTest, PostParserSimple) {
56 // Test a simple case with headers & data 55 // Test a simple case with headers & data
57 const char *ex1 = "foo: bar\nContent-length: 10\n\nabcdefghij"; 56 const char *ex1 = "foo: bar\nContent-length: 10\n\nabcdefghij";
58 WebURLRequest request; 57 WebURLRequest request;
59 request.initialize(); 58 request.initialize();
60 bool rv = WebPluginImpl::SetPostData(&request, ex1, 59 bool rv = WebPluginImpl::SetPostData(&request, ex1,
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 EXPECT_EQ(0U, GetHeader(request, "bar").length()); 222 EXPECT_EQ(0U, GetHeader(request, "bar").length());
224 EXPECT_EQ(0U, GetHeader(request, "Content-length").length()); 223 EXPECT_EQ(0U, GetHeader(request, "Content-length").length());
225 224
226 std::string body = GetBodyText(request); 225 std::string body = GetBodyText(request);
227 226
228 EXPECT_EQ(0xF0, (unsigned char)body[0]); 227 EXPECT_EQ(0xF0, (unsigned char)body[0]);
229 EXPECT_EQ(0xFF, (unsigned char)body[1]); 228 EXPECT_EQ(0xFF, (unsigned char)body[1]);
230 EXPECT_EQ(0xFF, (unsigned char)body[2]); 229 EXPECT_EQ(0xFF, (unsigned char)body[2]);
231 EXPECT_EQ(0xFF, (unsigned char)body[3]); 230 EXPECT_EQ(0xFF, (unsigned char)body[3]);
232 } 231 }
232
233 } // namespace npapi
234 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/webplugin_impl.cc ('k') | webkit/plugins/npapi/webplugin_page_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698