OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
6 #include "content/public/common/user_agent.h" | 6 #include "content/public/common/user_agent.h" |
7 #include "content/public/test/render_view_test.h" | 7 #include "content/public/test/render_view_test.h" |
8 #include "content/renderer/pepper/url_request_info_util.h" | 8 #include "content/renderer/pepper/url_request_info_util.h" |
9 #include "ppapi/proxy/connection.h" | 9 #include "ppapi/proxy/connection.h" |
10 #include "ppapi/proxy/url_request_info_resource.h" | 10 #include "ppapi/proxy/url_request_info_resource.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 bool IsExpected(const WebCString& web_string, const char* expected) { | 35 bool IsExpected(const WebCString& web_string, const char* expected) { |
36 const char* result = web_string.data(); | 36 const char* result = web_string.data(); |
37 return strcmp(result, expected) == 0; | 37 return strcmp(result, expected) == 0; |
38 } | 38 } |
39 | 39 |
40 bool IsExpected(const WebString& web_string, const char* expected) { | 40 bool IsExpected(const WebString& web_string, const char* expected) { |
41 return IsExpected(web_string.utf8(), expected); | 41 return IsExpected(web_string.utf8(), expected); |
42 } | 42 } |
43 | 43 |
44 // The base class destructor is protected, so derive. | 44 // The base class destructor is protected, so derive. |
45 class TestWebFrameClient : public WebFrameClient { | 45 class TestWebFrameClient : public WebFrameClient {}; |
46 }; | |
47 | 46 |
48 } // namespace | 47 } // namespace |
49 | 48 |
50 using ppapi::proxy::URLRequestInfoResource; | 49 using ppapi::proxy::URLRequestInfoResource; |
51 using ppapi::URLRequestInfoData; | 50 using ppapi::URLRequestInfoData; |
52 | 51 |
53 namespace content { | 52 namespace content { |
54 | 53 |
55 class URLRequestInfoTest : public RenderViewTest { | 54 class URLRequestInfoTest : public RenderViewTest { |
56 public: | 55 public: |
57 URLRequestInfoTest() : pp_instance_(1234) { | 56 URLRequestInfoTest() : pp_instance_(1234) {} |
58 } | |
59 | 57 |
60 virtual void SetUp() OVERRIDE { | 58 virtual void SetUp() OVERRIDE { |
61 RenderViewTest::SetUp(); | 59 RenderViewTest::SetUp(); |
62 ppapi::ProxyLock::DisableLockingOnThreadForTest(); | 60 ppapi::ProxyLock::DisableLockingOnThreadForTest(); |
63 | 61 |
64 test_globals_.GetResourceTracker()->DidCreateInstance(pp_instance_); | 62 test_globals_.GetResourceTracker()->DidCreateInstance(pp_instance_); |
65 | 63 |
66 // This resource doesn't do IPC, so a null connection is fine. | 64 // This resource doesn't do IPC, so a null connection is fine. |
67 info_ = new URLRequestInfoResource(ppapi::proxy::Connection(), | 65 info_ = new URLRequestInfoResource( |
68 pp_instance_, | 66 ppapi::proxy::Connection(), pp_instance_, URLRequestInfoData()); |
69 URLRequestInfoData()); | |
70 } | 67 } |
71 | 68 |
72 virtual void TearDown() OVERRIDE { | 69 virtual void TearDown() OVERRIDE { |
73 test_globals_.GetResourceTracker()->DidDeleteInstance(pp_instance_); | 70 test_globals_.GetResourceTracker()->DidDeleteInstance(pp_instance_); |
74 RenderViewTest::TearDown(); | 71 RenderViewTest::TearDown(); |
75 } | 72 } |
76 | 73 |
77 bool GetDownloadToFile() { | 74 bool GetDownloadToFile() { |
78 WebURLRequest web_request; | 75 WebURLRequest web_request; |
79 URLRequestInfoData data = info_->GetData(); | 76 URLRequestInfoData data = info_->GetData(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 131 |
135 TEST_F(URLRequestInfoTest, AsURLRequestInfo) { | 132 TEST_F(URLRequestInfoTest, AsURLRequestInfo) { |
136 EXPECT_EQ(info_, info_->AsPPB_URLRequestInfo_API()); | 133 EXPECT_EQ(info_, info_->AsPPB_URLRequestInfo_API()); |
137 } | 134 } |
138 | 135 |
139 TEST_F(URLRequestInfoTest, StreamToFile) { | 136 TEST_F(URLRequestInfoTest, StreamToFile) { |
140 SetStringProperty(PP_URLREQUESTPROPERTY_URL, "http://www.google.com"); | 137 SetStringProperty(PP_URLREQUESTPROPERTY_URL, "http://www.google.com"); |
141 | 138 |
142 EXPECT_FALSE(GetDownloadToFile()); | 139 EXPECT_FALSE(GetDownloadToFile()); |
143 | 140 |
144 EXPECT_TRUE(SetBooleanProperty( | 141 EXPECT_TRUE(SetBooleanProperty(PP_URLREQUESTPROPERTY_STREAMTOFILE, true)); |
145 PP_URLREQUESTPROPERTY_STREAMTOFILE, true)); | |
146 EXPECT_TRUE(GetDownloadToFile()); | 142 EXPECT_TRUE(GetDownloadToFile()); |
147 | 143 |
148 EXPECT_TRUE(SetBooleanProperty( | 144 EXPECT_TRUE(SetBooleanProperty(PP_URLREQUESTPROPERTY_STREAMTOFILE, false)); |
149 PP_URLREQUESTPROPERTY_STREAMTOFILE, false)); | |
150 EXPECT_FALSE(GetDownloadToFile()); | 145 EXPECT_FALSE(GetDownloadToFile()); |
151 } | 146 } |
152 | 147 |
153 TEST_F(URLRequestInfoTest, FollowRedirects) { | 148 TEST_F(URLRequestInfoTest, FollowRedirects) { |
154 EXPECT_TRUE(info_->GetData().follow_redirects); | 149 EXPECT_TRUE(info_->GetData().follow_redirects); |
155 | 150 |
156 EXPECT_TRUE(SetBooleanProperty( | 151 EXPECT_TRUE(SetBooleanProperty(PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS, false)); |
157 PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS, false)); | |
158 EXPECT_FALSE(info_->GetData().follow_redirects); | 152 EXPECT_FALSE(info_->GetData().follow_redirects); |
159 | 153 |
160 EXPECT_TRUE(SetBooleanProperty( | 154 EXPECT_TRUE(SetBooleanProperty(PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS, true)); |
161 PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS, true)); | |
162 EXPECT_TRUE(info_->GetData().follow_redirects); | 155 EXPECT_TRUE(info_->GetData().follow_redirects); |
163 } | 156 } |
164 | 157 |
165 TEST_F(URLRequestInfoTest, RecordDownloadProgress) { | 158 TEST_F(URLRequestInfoTest, RecordDownloadProgress) { |
166 EXPECT_FALSE(info_->GetData().record_download_progress); | 159 EXPECT_FALSE(info_->GetData().record_download_progress); |
167 | 160 |
168 EXPECT_TRUE(SetBooleanProperty( | 161 EXPECT_TRUE( |
169 PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS, true)); | 162 SetBooleanProperty(PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS, true)); |
170 EXPECT_TRUE(info_->GetData().record_download_progress); | 163 EXPECT_TRUE(info_->GetData().record_download_progress); |
171 | 164 |
172 EXPECT_TRUE(SetBooleanProperty( | 165 EXPECT_TRUE( |
173 PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS, false)); | 166 SetBooleanProperty(PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS, false)); |
174 EXPECT_FALSE(info_->GetData().record_download_progress); | 167 EXPECT_FALSE(info_->GetData().record_download_progress); |
175 } | 168 } |
176 | 169 |
177 TEST_F(URLRequestInfoTest, RecordUploadProgress) { | 170 TEST_F(URLRequestInfoTest, RecordUploadProgress) { |
178 EXPECT_FALSE(info_->GetData().record_upload_progress); | 171 EXPECT_FALSE(info_->GetData().record_upload_progress); |
179 | 172 |
180 EXPECT_TRUE(SetBooleanProperty( | 173 EXPECT_TRUE( |
181 PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS, true)); | 174 SetBooleanProperty(PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS, true)); |
182 EXPECT_TRUE(info_->GetData().record_upload_progress); | 175 EXPECT_TRUE(info_->GetData().record_upload_progress); |
183 | 176 |
184 EXPECT_TRUE(SetBooleanProperty( | 177 EXPECT_TRUE( |
185 PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS, false)); | 178 SetBooleanProperty(PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS, false)); |
186 EXPECT_FALSE(info_->GetData().record_upload_progress); | 179 EXPECT_FALSE(info_->GetData().record_upload_progress); |
187 } | 180 } |
188 | 181 |
189 TEST_F(URLRequestInfoTest, AllowCrossOriginRequests) { | 182 TEST_F(URLRequestInfoTest, AllowCrossOriginRequests) { |
190 EXPECT_FALSE(info_->GetData().allow_cross_origin_requests); | 183 EXPECT_FALSE(info_->GetData().allow_cross_origin_requests); |
191 | 184 |
192 EXPECT_TRUE(SetBooleanProperty( | 185 EXPECT_TRUE( |
193 PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS, true)); | 186 SetBooleanProperty(PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS, true)); |
194 EXPECT_TRUE(info_->GetData().allow_cross_origin_requests); | 187 EXPECT_TRUE(info_->GetData().allow_cross_origin_requests); |
195 | 188 |
196 EXPECT_TRUE(SetBooleanProperty( | 189 EXPECT_TRUE(SetBooleanProperty(PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS, |
197 PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS, false)); | 190 false)); |
198 EXPECT_FALSE(info_->GetData().allow_cross_origin_requests); | 191 EXPECT_FALSE(info_->GetData().allow_cross_origin_requests); |
199 } | 192 } |
200 | 193 |
201 TEST_F(URLRequestInfoTest, AllowCredentials) { | 194 TEST_F(URLRequestInfoTest, AllowCredentials) { |
202 EXPECT_FALSE(info_->GetData().allow_credentials); | 195 EXPECT_FALSE(info_->GetData().allow_credentials); |
203 | 196 |
204 EXPECT_TRUE(SetBooleanProperty( | 197 EXPECT_TRUE(SetBooleanProperty(PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS, true)); |
205 PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS, true)); | |
206 EXPECT_TRUE(info_->GetData().allow_credentials); | 198 EXPECT_TRUE(info_->GetData().allow_credentials); |
207 | 199 |
208 EXPECT_TRUE(SetBooleanProperty( | 200 EXPECT_TRUE( |
209 PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS, false)); | 201 SetBooleanProperty(PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS, false)); |
210 EXPECT_FALSE(info_->GetData().allow_credentials); | 202 EXPECT_FALSE(info_->GetData().allow_credentials); |
211 } | 203 } |
212 | 204 |
213 TEST_F(URLRequestInfoTest, SetURL) { | 205 TEST_F(URLRequestInfoTest, SetURL) { |
214 const char* url = "http://www.google.com/"; | 206 const char* url = "http://www.google.com/"; |
215 EXPECT_TRUE(SetStringProperty( | 207 EXPECT_TRUE(SetStringProperty(PP_URLREQUESTPROPERTY_URL, url)); |
216 PP_URLREQUESTPROPERTY_URL, url)); | |
217 EXPECT_TRUE(IsExpected(GetURL(), url)); | 208 EXPECT_TRUE(IsExpected(GetURL(), url)); |
218 } | 209 } |
219 | 210 |
220 TEST_F(URLRequestInfoTest, JavascriptURL) { | 211 TEST_F(URLRequestInfoTest, JavascriptURL) { |
221 const char* url = "javascript:foo = bar"; | 212 const char* url = "javascript:foo = bar"; |
222 EXPECT_FALSE(URLRequestRequiresUniversalAccess(info_->GetData())); | 213 EXPECT_FALSE(URLRequestRequiresUniversalAccess(info_->GetData())); |
223 SetStringProperty(PP_URLREQUESTPROPERTY_URL, url); | 214 SetStringProperty(PP_URLREQUESTPROPERTY_URL, url); |
224 EXPECT_TRUE(URLRequestRequiresUniversalAccess(info_->GetData())); | 215 EXPECT_TRUE(URLRequestRequiresUniversalAccess(info_->GetData())); |
225 } | 216 } |
226 | 217 |
227 TEST_F(URLRequestInfoTest, SetMethod) { | 218 TEST_F(URLRequestInfoTest, SetMethod) { |
228 // Test default method is "GET". | 219 // Test default method is "GET". |
229 EXPECT_TRUE(IsExpected(GetMethod(), "GET")); | 220 EXPECT_TRUE(IsExpected(GetMethod(), "GET")); |
230 EXPECT_TRUE(SetStringProperty( | 221 EXPECT_TRUE(SetStringProperty(PP_URLREQUESTPROPERTY_METHOD, "POST")); |
231 PP_URLREQUESTPROPERTY_METHOD, "POST")); | |
232 EXPECT_TRUE(IsExpected(GetMethod(), "POST")); | 222 EXPECT_TRUE(IsExpected(GetMethod(), "POST")); |
233 } | 223 } |
234 | 224 |
235 TEST_F(URLRequestInfoTest, SetHeaders) { | 225 TEST_F(URLRequestInfoTest, SetHeaders) { |
236 // Test default header field. | 226 // Test default header field. |
237 EXPECT_TRUE(IsExpected( | 227 EXPECT_TRUE(IsExpected(GetHeaderValue("foo"), "")); |
238 GetHeaderValue("foo"), "")); | |
239 // Test that we can set a header field. | 228 // Test that we can set a header field. |
240 EXPECT_TRUE(SetStringProperty( | 229 EXPECT_TRUE(SetStringProperty(PP_URLREQUESTPROPERTY_HEADERS, "foo: bar")); |
241 PP_URLREQUESTPROPERTY_HEADERS, "foo: bar")); | 230 EXPECT_TRUE(IsExpected(GetHeaderValue("foo"), "bar")); |
242 EXPECT_TRUE(IsExpected( | |
243 GetHeaderValue("foo"), "bar")); | |
244 // Test that we can set multiple header fields using \n delimiter. | 231 // Test that we can set multiple header fields using \n delimiter. |
245 EXPECT_TRUE(SetStringProperty( | 232 EXPECT_TRUE( |
246 PP_URLREQUESTPROPERTY_HEADERS, "foo: bar\nbar: baz")); | 233 SetStringProperty(PP_URLREQUESTPROPERTY_HEADERS, "foo: bar\nbar: baz")); |
247 EXPECT_TRUE(IsExpected( | 234 EXPECT_TRUE(IsExpected(GetHeaderValue("foo"), "bar")); |
248 GetHeaderValue("foo"), "bar")); | 235 EXPECT_TRUE(IsExpected(GetHeaderValue("bar"), "baz")); |
249 EXPECT_TRUE(IsExpected( | |
250 GetHeaderValue("bar"), "baz")); | |
251 } | 236 } |
252 | 237 |
253 // TODO(bbudge) Unit tests for AppendDataToBody, AppendFileToBody. | 238 // TODO(bbudge) Unit tests for AppendDataToBody, AppendFileToBody. |
254 | 239 |
255 } // namespace content | 240 } // namespace content |
OLD | NEW |