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

Side by Side Diff: webkit/plugins/ppapi/url_request_info_unittest.cc

Issue 10913257: Convert url request info to new proxy API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 3 months 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "ppapi/thunk/thunk.h"
6 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
10 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
11 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
12 #include "webkit/plugins/ppapi/ppapi_unittest.h"
13 #include "webkit/user_agent/user_agent.h"
14 #include "webkit/user_agent/user_agent_util.h"
15
16 using WebKit::WebCString;
17 using WebKit::WebFrame;
18 using WebKit::WebFrameClient;
19 using WebKit::WebString;
20 using WebKit::WebView;
21 using WebKit::WebURL;
22 using WebKit::WebURLRequest;
23
24 namespace {
25
26 bool IsExpected(const WebCString& web_string, const char* expected) {
27 const char* result = web_string.data();
28 return strcmp(result, expected) == 0;
29 }
30
31 bool IsExpected(const WebString& web_string, const char* expected) {
32 return IsExpected(web_string.utf8(), expected);
33 }
34
35 bool IsNullOrEmpty(const WebString& web_string) {
36 return web_string.isNull() || web_string.isEmpty();
37 }
38
39 // The base class destructor is protected, so derive.
40 class TestWebFrameClient : public WebFrameClient {
41 };
42
43 } // namespace
44
45 namespace webkit {
46 namespace ppapi {
47
48 class URLRequestInfoTest : public PpapiUnittest {
49 public:
50 URLRequestInfoTest() {
51 }
52
53 virtual void SetUp() {
54 PpapiUnittest::SetUp();
55
56 // Must be after our base class's SetUp for the instance to be valid.
57 info_ = new PPB_URLRequestInfo_Impl(instance()->pp_instance(),
58 ::ppapi::PPB_URLRequestInfo_Data());
59 }
60
61 static void SetUpTestCase() {
62 webkit_glue::SetUserAgent(webkit_glue::BuildUserAgentFromProduct(
63 "TestShell/0.0.0.0"), false);
64 web_view_ = WebView::create(NULL);
65 web_view_->initializeMainFrame(&web_frame_client_);
66 WebURL web_url(GURL(""));
67 WebURLRequest url_request;
68 url_request.initialize();
69 url_request.setURL(web_url);
70 frame_ = web_view_->mainFrame();
71 frame_->loadRequest(url_request);
72 }
73
74 static void TearDownTestCase() {
75 web_view_->close();
76 }
77
78 bool GetDownloadToFile() {
79 WebURLRequest web_request;
80 if (!info_->ToWebURLRequest(frame_, &web_request))
81 return false;
82 return web_request.downloadToFile();
83 }
84
85 WebCString GetURL() {
86 WebURLRequest web_request;
87 if (!info_->ToWebURLRequest(frame_, &web_request))
88 return WebCString();
89 return web_request.url().spec();
90 }
91
92 WebString GetMethod() {
93 WebURLRequest web_request;
94 if (!info_->ToWebURLRequest(frame_, &web_request))
95 return WebString();
96 return web_request.httpMethod();
97 }
98
99 WebString GetHeaderValue(const char* field) {
100 WebURLRequest web_request;
101 if (!info_->ToWebURLRequest(frame_, &web_request))
102 return WebString();
103 return web_request.httpHeaderField(WebString::fromUTF8(field));
104 }
105
106 bool SetBooleanProperty(PP_URLRequestProperty prop, bool b) {
107 return info_->SetBooleanProperty(prop, b);
108 }
109 bool SetStringProperty(PP_URLRequestProperty prop, const std::string& s) {
110 return info_->SetStringProperty(prop, s);
111 }
112
113 scoped_refptr<PPB_URLRequestInfo_Impl> info_;
114
115 static TestWebFrameClient web_frame_client_;
116 static WebView* web_view_;
117 static WebFrame* frame_;
118 };
119
120 TestWebFrameClient URLRequestInfoTest::web_frame_client_;
121 WebView* URLRequestInfoTest::web_view_;
122 WebFrame* URLRequestInfoTest::frame_;
123
124 TEST_F(URLRequestInfoTest, GetInterface) {
125 const PPB_URLRequestInfo* request_info =
126 ::ppapi::thunk::GetPPB_URLRequestInfo_1_0_Thunk();
127 EXPECT_TRUE(request_info);
128 EXPECT_TRUE(request_info->Create);
129 EXPECT_TRUE(request_info->IsURLRequestInfo);
130 EXPECT_TRUE(request_info->SetProperty);
131 EXPECT_TRUE(request_info->AppendDataToBody);
132 EXPECT_TRUE(request_info->AppendFileToBody);
133 }
134
135 TEST_F(URLRequestInfoTest, AsURLRequestInfo) {
136 EXPECT_EQ(info_, info_->AsPPB_URLRequestInfo_API());
137 }
138
139 TEST_F(URLRequestInfoTest, StreamToFile) {
140 SetStringProperty(PP_URLREQUESTPROPERTY_URL, "http://www.google.com");
141
142 EXPECT_FALSE(GetDownloadToFile());
143
144 EXPECT_TRUE(SetBooleanProperty(
145 PP_URLREQUESTPROPERTY_STREAMTOFILE, true));
146 EXPECT_TRUE(GetDownloadToFile());
147
148 EXPECT_TRUE(SetBooleanProperty(
149 PP_URLREQUESTPROPERTY_STREAMTOFILE, false));
150 EXPECT_FALSE(GetDownloadToFile());
151 }
152
153 TEST_F(URLRequestInfoTest, FollowRedirects) {
154 EXPECT_TRUE(info_->GetData().follow_redirects);
155
156 EXPECT_TRUE(SetBooleanProperty(
157 PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS, false));
158 EXPECT_FALSE(info_->GetData().follow_redirects);
159
160 EXPECT_TRUE(SetBooleanProperty(
161 PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS, true));
162 EXPECT_TRUE(info_->GetData().follow_redirects);
163 }
164
165 TEST_F(URLRequestInfoTest, RecordDownloadProgress) {
166 EXPECT_FALSE(info_->GetData().record_download_progress);
167
168 EXPECT_TRUE(SetBooleanProperty(
169 PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS, true));
170 EXPECT_TRUE(info_->GetData().record_download_progress);
171
172 EXPECT_TRUE(SetBooleanProperty(
173 PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS, false));
174 EXPECT_FALSE(info_->GetData().record_download_progress);
175 }
176
177 TEST_F(URLRequestInfoTest, RecordUploadProgress) {
178 EXPECT_FALSE(info_->GetData().record_upload_progress);
179
180 EXPECT_TRUE(SetBooleanProperty(
181 PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS, true));
182 EXPECT_TRUE(info_->GetData().record_upload_progress);
183
184 EXPECT_TRUE(SetBooleanProperty(
185 PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS, false));
186 EXPECT_FALSE(info_->GetData().record_upload_progress);
187 }
188
189 TEST_F(URLRequestInfoTest, AllowCrossOriginRequests) {
190 EXPECT_FALSE(info_->GetData().allow_cross_origin_requests);
191
192 EXPECT_TRUE(SetBooleanProperty(
193 PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS, true));
194 EXPECT_TRUE(info_->GetData().allow_cross_origin_requests);
195
196 EXPECT_TRUE(SetBooleanProperty(
197 PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS, false));
198 EXPECT_FALSE(info_->GetData().allow_cross_origin_requests);
199 }
200
201 TEST_F(URLRequestInfoTest, AllowCredentials) {
202 EXPECT_FALSE(info_->GetData().allow_credentials);
203
204 EXPECT_TRUE(SetBooleanProperty(
205 PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS, true));
206 EXPECT_TRUE(info_->GetData().allow_credentials);
207
208 EXPECT_TRUE(SetBooleanProperty(
209 PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS, false));
210 EXPECT_FALSE(info_->GetData().allow_credentials);
211 }
212
213 TEST_F(URLRequestInfoTest, SetURL) {
214 // Test default URL is "about:blank".
215 EXPECT_TRUE(IsExpected(GetURL(), "about:blank"));
216
217 const char* url = "http://www.google.com/";
218 EXPECT_TRUE(SetStringProperty(
219 PP_URLREQUESTPROPERTY_URL, url));
220 EXPECT_TRUE(IsExpected(GetURL(), url));
221 }
222
223 TEST_F(URLRequestInfoTest, JavascriptURL) {
224 const char* url = "javascript:foo = bar";
225 EXPECT_FALSE(info_->RequiresUniversalAccess());
226 SetStringProperty(PP_URLREQUESTPROPERTY_URL, url);
227 EXPECT_TRUE(info_->RequiresUniversalAccess());
228 }
229
230 TEST_F(URLRequestInfoTest, SetMethod) {
231 // Test default method is "GET".
232 EXPECT_TRUE(IsExpected(GetMethod(), "GET"));
233 EXPECT_TRUE(SetStringProperty(
234 PP_URLREQUESTPROPERTY_METHOD, "POST"));
235 EXPECT_TRUE(IsExpected(GetMethod(), "POST"));
236 }
237
238 TEST_F(URLRequestInfoTest, SetHeaders) {
239 // Test default header field.
240 EXPECT_TRUE(IsExpected(
241 GetHeaderValue("foo"), ""));
242 // Test that we can set a header field.
243 EXPECT_TRUE(SetStringProperty(
244 PP_URLREQUESTPROPERTY_HEADERS, "foo: bar"));
245 EXPECT_TRUE(IsExpected(
246 GetHeaderValue("foo"), "bar"));
247 // Test that we can set multiple header fields using \n delimiter.
248 EXPECT_TRUE(SetStringProperty(
249 PP_URLREQUESTPROPERTY_HEADERS, "foo: bar\nbar: baz"));
250 EXPECT_TRUE(IsExpected(
251 GetHeaderValue("foo"), "bar"));
252 EXPECT_TRUE(IsExpected(
253 GetHeaderValue("bar"), "baz"));
254 }
255
256 // TODO(bbudge) Unit tests for AppendDataToBody, AppendFileToBody.
257
258 } // namespace ppapi
259 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/resource_creation_impl.cc ('k') | webkit/plugins/ppapi/url_request_info_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698