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