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 "net/proxy/proxy_script_fetcher.h" | 5 #include "net/proxy/proxy_script_fetcher.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
11 #include "net/base/ssl_config_service_defaults.h" | 11 #include "net/base/ssl_config_service_defaults.h" |
12 #include "net/base/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
13 #include "net/disk_cache/disk_cache.h" | 13 #include "net/disk_cache/disk_cache.h" |
14 #include "net/http/http_cache.h" | 14 #include "net/http/http_cache.h" |
15 #include "net/url_request/url_request_unittest.h" | 15 #include "net/url_request/url_request_unittest.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "testing/platform_test.h" | 17 #include "testing/platform_test.h" |
18 | 18 |
19 // TODO(eroman): | 19 // TODO(eroman): |
20 // - Test canceling an outstanding request. | 20 // - Test canceling an outstanding request. |
21 // - Test deleting ProxyScriptFetcher while a request is in progress. | 21 // - Test deleting ProxyScriptFetcher while a request is in progress. |
22 | 22 |
23 const wchar_t kDocRoot[] = L"net/data/proxy_script_fetcher_unittest"; | 23 const wchar_t kDocRoot[] = L"net/data/proxy_script_fetcher_unittest"; |
24 | 24 |
25 struct FetchResult { | 25 struct FetchResult { |
26 int code; | 26 int code; |
27 std::string bytes; | 27 string16 text; |
28 }; | 28 }; |
29 | 29 |
30 // A non-mock URL request which can access http:// and file:// urls. | 30 // A non-mock URL request which can access http:// and file:// urls. |
31 class RequestContext : public URLRequestContext { | 31 class RequestContext : public URLRequestContext { |
32 public: | 32 public: |
33 RequestContext() { | 33 RequestContext() { |
34 net::ProxyConfig no_proxy; | 34 net::ProxyConfig no_proxy; |
35 host_resolver_ = net::CreateSystemHostResolver(); | 35 host_resolver_ = net::CreateSystemHostResolver(); |
36 proxy_service_ = net::ProxyService::CreateFixed(no_proxy); | 36 proxy_service_ = net::ProxyService::CreateFixed(no_proxy); |
37 ssl_config_service_ = new net::SSLConfigServiceDefaults; | 37 ssl_config_service_ = new net::SSLConfigServiceDefaults; |
(...skipping 25 matching lines...) Expand all Loading... |
63 } | 63 } |
64 | 64 |
65 typedef PlatformTest ProxyScriptFetcherTest; | 65 typedef PlatformTest ProxyScriptFetcherTest; |
66 | 66 |
67 TEST_F(ProxyScriptFetcherTest, FileUrl) { | 67 TEST_F(ProxyScriptFetcherTest, FileUrl) { |
68 scoped_refptr<URLRequestContext> context = new RequestContext; | 68 scoped_refptr<URLRequestContext> context = new RequestContext; |
69 scoped_ptr<ProxyScriptFetcher> pac_fetcher( | 69 scoped_ptr<ProxyScriptFetcher> pac_fetcher( |
70 ProxyScriptFetcher::Create(context)); | 70 ProxyScriptFetcher::Create(context)); |
71 | 71 |
72 { // Fetch a non-existent file. | 72 { // Fetch a non-existent file. |
73 std::string bytes; | 73 string16 text; |
74 TestCompletionCallback callback; | 74 TestCompletionCallback callback; |
75 int result = pac_fetcher->Fetch(GetTestFileUrl("does-not-exist"), | 75 int result = pac_fetcher->Fetch(GetTestFileUrl("does-not-exist"), |
76 &bytes, &callback); | 76 &text, &callback); |
77 EXPECT_EQ(ERR_IO_PENDING, result); | 77 EXPECT_EQ(ERR_IO_PENDING, result); |
78 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); | 78 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); |
79 EXPECT_TRUE(bytes.empty()); | 79 EXPECT_TRUE(text.empty()); |
80 } | 80 } |
81 { // Fetch a file that exists. | 81 { // Fetch a file that exists. |
82 std::string bytes; | 82 string16 text; |
83 TestCompletionCallback callback; | 83 TestCompletionCallback callback; |
84 int result = pac_fetcher->Fetch(GetTestFileUrl("pac.txt"), | 84 int result = pac_fetcher->Fetch(GetTestFileUrl("pac.txt"), |
85 &bytes, &callback); | 85 &text, &callback); |
86 EXPECT_EQ(ERR_IO_PENDING, result); | 86 EXPECT_EQ(ERR_IO_PENDING, result); |
87 EXPECT_EQ(OK, callback.WaitForResult()); | 87 EXPECT_EQ(OK, callback.WaitForResult()); |
88 EXPECT_EQ("-pac.txt-\n", bytes); | 88 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 // Note that all mime types are allowed for PAC file, to be consistent | 92 // Note that all mime types are allowed for PAC file, to be consistent |
93 // with other browsers. | 93 // with other browsers. |
94 TEST_F(ProxyScriptFetcherTest, HttpMimeType) { | 94 TEST_F(ProxyScriptFetcherTest, HttpMimeType) { |
95 scoped_refptr<HTTPTestServer> server = | 95 scoped_refptr<HTTPTestServer> server = |
96 HTTPTestServer::CreateServer(kDocRoot, NULL); | 96 HTTPTestServer::CreateServer(kDocRoot, NULL); |
97 ASSERT_TRUE(NULL != server.get()); | 97 ASSERT_TRUE(NULL != server.get()); |
98 scoped_refptr<URLRequestContext> context = new RequestContext; | 98 scoped_refptr<URLRequestContext> context = new RequestContext; |
99 scoped_ptr<ProxyScriptFetcher> pac_fetcher( | 99 scoped_ptr<ProxyScriptFetcher> pac_fetcher( |
100 ProxyScriptFetcher::Create(context)); | 100 ProxyScriptFetcher::Create(context)); |
101 | 101 |
102 { // Fetch a PAC with mime type "text/plain" | 102 { // Fetch a PAC with mime type "text/plain" |
103 GURL url = server->TestServerPage("files/pac.txt"); | 103 GURL url = server->TestServerPage("files/pac.txt"); |
104 std::string bytes; | 104 string16 text; |
105 TestCompletionCallback callback; | 105 TestCompletionCallback callback; |
106 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 106 int result = pac_fetcher->Fetch(url, &text, &callback); |
107 EXPECT_EQ(ERR_IO_PENDING, result); | 107 EXPECT_EQ(ERR_IO_PENDING, result); |
108 EXPECT_EQ(OK, callback.WaitForResult()); | 108 EXPECT_EQ(OK, callback.WaitForResult()); |
109 EXPECT_EQ("-pac.txt-\n", bytes); | 109 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); |
110 } | 110 } |
111 { // Fetch a PAC with mime type "text/html" | 111 { // Fetch a PAC with mime type "text/html" |
112 GURL url = server->TestServerPage("files/pac.html"); | 112 GURL url = server->TestServerPage("files/pac.html"); |
113 std::string bytes; | 113 string16 text; |
114 TestCompletionCallback callback; | 114 TestCompletionCallback callback; |
115 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 115 int result = pac_fetcher->Fetch(url, &text, &callback); |
116 EXPECT_EQ(ERR_IO_PENDING, result); | 116 EXPECT_EQ(ERR_IO_PENDING, result); |
117 EXPECT_EQ(OK, callback.WaitForResult()); | 117 EXPECT_EQ(OK, callback.WaitForResult()); |
118 EXPECT_EQ("-pac.html-\n", bytes); | 118 EXPECT_EQ(ASCIIToUTF16("-pac.html-\n"), text); |
119 } | 119 } |
120 { // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig" | 120 { // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig" |
121 GURL url = server->TestServerPage("files/pac.nsproxy"); | 121 GURL url = server->TestServerPage("files/pac.nsproxy"); |
122 std::string bytes; | 122 string16 text; |
123 TestCompletionCallback callback; | 123 TestCompletionCallback callback; |
124 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 124 int result = pac_fetcher->Fetch(url, &text, &callback); |
125 EXPECT_EQ(ERR_IO_PENDING, result); | 125 EXPECT_EQ(ERR_IO_PENDING, result); |
126 EXPECT_EQ(OK, callback.WaitForResult()); | 126 EXPECT_EQ(OK, callback.WaitForResult()); |
127 EXPECT_EQ("-pac.nsproxy-\n", bytes); | 127 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 TEST_F(ProxyScriptFetcherTest, HttpStatusCode) { | 131 TEST_F(ProxyScriptFetcherTest, HttpStatusCode) { |
132 scoped_refptr<HTTPTestServer> server = | 132 scoped_refptr<HTTPTestServer> server = |
133 HTTPTestServer::CreateServer(kDocRoot, NULL); | 133 HTTPTestServer::CreateServer(kDocRoot, NULL); |
134 ASSERT_TRUE(NULL != server.get()); | 134 ASSERT_TRUE(NULL != server.get()); |
135 scoped_refptr<URLRequestContext> context = new RequestContext; | 135 scoped_refptr<URLRequestContext> context = new RequestContext; |
136 scoped_ptr<ProxyScriptFetcher> pac_fetcher( | 136 scoped_ptr<ProxyScriptFetcher> pac_fetcher( |
137 ProxyScriptFetcher::Create(context)); | 137 ProxyScriptFetcher::Create(context)); |
138 | 138 |
139 { // Fetch a PAC which gives a 500 -- FAIL | 139 { // Fetch a PAC which gives a 500 -- FAIL |
140 GURL url = server->TestServerPage("files/500.pac"); | 140 GURL url = server->TestServerPage("files/500.pac"); |
141 std::string bytes; | 141 string16 text; |
142 TestCompletionCallback callback; | 142 TestCompletionCallback callback; |
143 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 143 int result = pac_fetcher->Fetch(url, &text, &callback); |
144 EXPECT_EQ(ERR_IO_PENDING, result); | 144 EXPECT_EQ(ERR_IO_PENDING, result); |
145 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); | 145 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); |
146 EXPECT_TRUE(bytes.empty()); | 146 EXPECT_TRUE(text.empty()); |
147 } | 147 } |
148 { // Fetch a PAC which gives a 404 -- FAIL | 148 { // Fetch a PAC which gives a 404 -- FAIL |
149 GURL url = server->TestServerPage("files/404.pac"); | 149 GURL url = server->TestServerPage("files/404.pac"); |
150 std::string bytes; | 150 string16 text; |
151 TestCompletionCallback callback; | 151 TestCompletionCallback callback; |
152 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 152 int result = pac_fetcher->Fetch(url, &text, &callback); |
153 EXPECT_EQ(ERR_IO_PENDING, result); | 153 EXPECT_EQ(ERR_IO_PENDING, result); |
154 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); | 154 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); |
155 EXPECT_TRUE(bytes.empty()); | 155 EXPECT_TRUE(text.empty()); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 TEST_F(ProxyScriptFetcherTest, ContentDisposition) { | 159 TEST_F(ProxyScriptFetcherTest, ContentDisposition) { |
160 scoped_refptr<HTTPTestServer> server = | 160 scoped_refptr<HTTPTestServer> server = |
161 HTTPTestServer::CreateServer(kDocRoot, NULL); | 161 HTTPTestServer::CreateServer(kDocRoot, NULL); |
162 ASSERT_TRUE(NULL != server.get()); | 162 ASSERT_TRUE(NULL != server.get()); |
163 scoped_refptr<URLRequestContext> context = new RequestContext; | 163 scoped_refptr<URLRequestContext> context = new RequestContext; |
164 scoped_ptr<ProxyScriptFetcher> pac_fetcher( | 164 scoped_ptr<ProxyScriptFetcher> pac_fetcher( |
165 ProxyScriptFetcher::Create(context)); | 165 ProxyScriptFetcher::Create(context)); |
166 | 166 |
167 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should | 167 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should |
168 // have no effect. | 168 // have no effect. |
169 GURL url = server->TestServerPage("files/downloadable.pac"); | 169 GURL url = server->TestServerPage("files/downloadable.pac"); |
170 std::string bytes; | 170 string16 text; |
171 TestCompletionCallback callback; | 171 TestCompletionCallback callback; |
172 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 172 int result = pac_fetcher->Fetch(url, &text, &callback); |
173 EXPECT_EQ(ERR_IO_PENDING, result); | 173 EXPECT_EQ(ERR_IO_PENDING, result); |
174 EXPECT_EQ(OK, callback.WaitForResult()); | 174 EXPECT_EQ(OK, callback.WaitForResult()); |
175 EXPECT_EQ("-downloadable.pac-\n", bytes); | 175 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); |
176 } | 176 } |
177 | 177 |
178 TEST_F(ProxyScriptFetcherTest, NoCache) { | 178 TEST_F(ProxyScriptFetcherTest, NoCache) { |
179 scoped_refptr<HTTPTestServer> server = | 179 scoped_refptr<HTTPTestServer> server = |
180 HTTPTestServer::CreateServer(kDocRoot, NULL); | 180 HTTPTestServer::CreateServer(kDocRoot, NULL); |
181 ASSERT_TRUE(NULL != server.get()); | 181 ASSERT_TRUE(NULL != server.get()); |
182 scoped_refptr<URLRequestContext> context = new RequestContext; | 182 scoped_refptr<URLRequestContext> context = new RequestContext; |
183 scoped_ptr<ProxyScriptFetcher> pac_fetcher( | 183 scoped_ptr<ProxyScriptFetcher> pac_fetcher( |
184 ProxyScriptFetcher::Create(context)); | 184 ProxyScriptFetcher::Create(context)); |
185 | 185 |
186 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. | 186 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. |
187 GURL url = server->TestServerPage("files/cacheable_1hr.pac"); | 187 GURL url = server->TestServerPage("files/cacheable_1hr.pac"); |
188 { | 188 { |
189 std::string bytes; | 189 string16 text; |
190 TestCompletionCallback callback; | 190 TestCompletionCallback callback; |
191 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 191 int result = pac_fetcher->Fetch(url, &text, &callback); |
192 EXPECT_EQ(ERR_IO_PENDING, result); | 192 EXPECT_EQ(ERR_IO_PENDING, result); |
193 EXPECT_EQ(OK, callback.WaitForResult()); | 193 EXPECT_EQ(OK, callback.WaitForResult()); |
194 EXPECT_EQ("-cacheable_1hr.pac-\n", bytes); | 194 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); |
195 } | 195 } |
196 | 196 |
197 // Now kill the HTTP server. | 197 // Now kill the HTTP server. |
198 EXPECT_TRUE(server->Stop()); // Verify it shutdown synchronously. | 198 EXPECT_TRUE(server->Stop()); // Verify it shutdown synchronously. |
199 server = NULL; | 199 server = NULL; |
200 | 200 |
201 // Try to fetch the file again -- if should fail, since the server is not | 201 // Try to fetch the file again -- if should fail, since the server is not |
202 // running anymore. (If it were instead being loaded from cache, we would | 202 // running anymore. (If it were instead being loaded from cache, we would |
203 // get a success. | 203 // get a success. |
204 { | 204 { |
205 std::string bytes; | 205 string16 text; |
206 TestCompletionCallback callback; | 206 TestCompletionCallback callback; |
207 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 207 int result = pac_fetcher->Fetch(url, &text, &callback); |
208 EXPECT_EQ(ERR_IO_PENDING, result); | 208 EXPECT_EQ(ERR_IO_PENDING, result); |
209 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); | 209 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 TEST_F(ProxyScriptFetcherTest, TooLarge) { | 213 TEST_F(ProxyScriptFetcherTest, TooLarge) { |
214 scoped_refptr<HTTPTestServer> server = | 214 scoped_refptr<HTTPTestServer> server = |
215 HTTPTestServer::CreateServer(kDocRoot, NULL); | 215 HTTPTestServer::CreateServer(kDocRoot, NULL); |
216 ASSERT_TRUE(NULL != server.get()); | 216 ASSERT_TRUE(NULL != server.get()); |
217 scoped_refptr<URLRequestContext> context = new RequestContext; | 217 scoped_refptr<URLRequestContext> context = new RequestContext; |
218 scoped_ptr<ProxyScriptFetcher> pac_fetcher( | 218 scoped_ptr<ProxyScriptFetcher> pac_fetcher( |
219 ProxyScriptFetcher::Create(context)); | 219 ProxyScriptFetcher::Create(context)); |
220 | 220 |
221 // Set the maximum response size to 50 bytes. | 221 // Set the maximum response size to 50 bytes. |
222 int prev_size = ProxyScriptFetcher::SetSizeConstraintForUnittest(50); | 222 int prev_size = ProxyScriptFetcher::SetSizeConstraintForUnittest(50); |
223 | 223 |
224 // These two URLs are the same file, but are http:// vs file:// | 224 // These two URLs are the same file, but are http:// vs file:// |
225 GURL urls[] = { | 225 GURL urls[] = { |
226 server->TestServerPage("files/large-pac.nsproxy"), | 226 server->TestServerPage("files/large-pac.nsproxy"), |
227 GetTestFileUrl("large-pac.nsproxy") | 227 GetTestFileUrl("large-pac.nsproxy") |
228 }; | 228 }; |
229 | 229 |
230 // Try fetching URLs that are 101 bytes large. We should abort the request | 230 // Try fetching URLs that are 101 bytes large. We should abort the request |
231 // after 50 bytes have been read, and fail with a too large error. | 231 // after 50 bytes have been read, and fail with a too large error. |
232 for (size_t i = 0; i < arraysize(urls); ++i) { | 232 for (size_t i = 0; i < arraysize(urls); ++i) { |
233 const GURL& url = urls[i]; | 233 const GURL& url = urls[i]; |
234 std::string bytes; | 234 string16 text; |
235 TestCompletionCallback callback; | 235 TestCompletionCallback callback; |
236 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 236 int result = pac_fetcher->Fetch(url, &text, &callback); |
237 EXPECT_EQ(ERR_IO_PENDING, result); | 237 EXPECT_EQ(ERR_IO_PENDING, result); |
238 EXPECT_EQ(ERR_FILE_TOO_BIG, callback.WaitForResult()); | 238 EXPECT_EQ(ERR_FILE_TOO_BIG, callback.WaitForResult()); |
239 EXPECT_TRUE(bytes.empty()); | 239 EXPECT_TRUE(text.empty()); |
240 } | 240 } |
241 | 241 |
242 // Restore the original size bound. | 242 // Restore the original size bound. |
243 ProxyScriptFetcher::SetSizeConstraintForUnittest(prev_size); | 243 ProxyScriptFetcher::SetSizeConstraintForUnittest(prev_size); |
244 | 244 |
245 { // Make sure we can still fetch regular URLs. | 245 { // Make sure we can still fetch regular URLs. |
246 GURL url = server->TestServerPage("files/pac.nsproxy"); | 246 GURL url = server->TestServerPage("files/pac.nsproxy"); |
247 std::string bytes; | 247 string16 text; |
248 TestCompletionCallback callback; | 248 TestCompletionCallback callback; |
249 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 249 int result = pac_fetcher->Fetch(url, &text, &callback); |
250 EXPECT_EQ(ERR_IO_PENDING, result); | 250 EXPECT_EQ(ERR_IO_PENDING, result); |
251 EXPECT_EQ(OK, callback.WaitForResult()); | 251 EXPECT_EQ(OK, callback.WaitForResult()); |
252 EXPECT_EQ("-pac.nsproxy-\n", bytes); | 252 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 TEST_F(ProxyScriptFetcherTest, Hang) { | 256 TEST_F(ProxyScriptFetcherTest, Hang) { |
257 scoped_refptr<HTTPTestServer> server = | 257 scoped_refptr<HTTPTestServer> server = |
258 HTTPTestServer::CreateServer(kDocRoot, NULL); | 258 HTTPTestServer::CreateServer(kDocRoot, NULL); |
259 ASSERT_TRUE(NULL != server.get()); | 259 ASSERT_TRUE(NULL != server.get()); |
260 scoped_refptr<URLRequestContext> context = new RequestContext; | 260 scoped_refptr<URLRequestContext> context = new RequestContext; |
261 scoped_ptr<ProxyScriptFetcher> pac_fetcher( | 261 scoped_ptr<ProxyScriptFetcher> pac_fetcher( |
262 ProxyScriptFetcher::Create(context)); | 262 ProxyScriptFetcher::Create(context)); |
263 | 263 |
264 // Set the timeout period to 0.5 seconds. | 264 // Set the timeout period to 0.5 seconds. |
265 int prev_timeout = | 265 int prev_timeout = |
266 ProxyScriptFetcher::SetTimeoutConstraintForUnittest(500); | 266 ProxyScriptFetcher::SetTimeoutConstraintForUnittest(500); |
267 | 267 |
268 // Try fetching a URL which takes 1.2 seconds. We should abort the request | 268 // Try fetching a URL which takes 1.2 seconds. We should abort the request |
269 // after 500 ms, and fail with a timeout error. | 269 // after 500 ms, and fail with a timeout error. |
270 { GURL url = server->TestServerPage("slow/proxy.pac?1.2"); | 270 { GURL url = server->TestServerPage("slow/proxy.pac?1.2"); |
271 std::string bytes; | 271 string16 text; |
272 TestCompletionCallback callback; | 272 TestCompletionCallback callback; |
273 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 273 int result = pac_fetcher->Fetch(url, &text, &callback); |
274 EXPECT_EQ(ERR_IO_PENDING, result); | 274 EXPECT_EQ(ERR_IO_PENDING, result); |
275 EXPECT_EQ(ERR_TIMED_OUT, callback.WaitForResult()); | 275 EXPECT_EQ(ERR_TIMED_OUT, callback.WaitForResult()); |
276 EXPECT_TRUE(bytes.empty()); | 276 EXPECT_TRUE(text.empty()); |
277 } | 277 } |
278 | 278 |
279 // Restore the original timeout period. | 279 // Restore the original timeout period. |
280 ProxyScriptFetcher::SetTimeoutConstraintForUnittest(prev_timeout); | 280 ProxyScriptFetcher::SetTimeoutConstraintForUnittest(prev_timeout); |
281 | 281 |
282 { // Make sure we can still fetch regular URLs. | 282 { // Make sure we can still fetch regular URLs. |
283 GURL url = server->TestServerPage("files/pac.nsproxy"); | 283 GURL url = server->TestServerPage("files/pac.nsproxy"); |
284 std::string bytes; | 284 string16 text; |
285 TestCompletionCallback callback; | 285 TestCompletionCallback callback; |
286 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 286 int result = pac_fetcher->Fetch(url, &text, &callback); |
287 EXPECT_EQ(ERR_IO_PENDING, result); | 287 EXPECT_EQ(ERR_IO_PENDING, result); |
288 EXPECT_EQ(OK, callback.WaitForResult()); | 288 EXPECT_EQ(OK, callback.WaitForResult()); |
289 EXPECT_EQ("-pac.nsproxy-\n", bytes); | 289 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); |
290 } | 290 } |
291 } | 291 } |
292 | 292 |
293 // The ProxyScriptFetcher should decode any content-codings | 293 // The ProxyScriptFetcher should decode any content-codings |
294 // (like gzip, bzip, etc.), and apply any charset conversions to yield | 294 // (like gzip, bzip, etc.), and apply any charset conversions to yield |
295 // UTF8. | 295 // UTF8. |
296 TEST_F(ProxyScriptFetcherTest, Encodings) { | 296 TEST_F(ProxyScriptFetcherTest, Encodings) { |
297 scoped_refptr<HTTPTestServer> server = | 297 scoped_refptr<HTTPTestServer> server = |
298 HTTPTestServer::CreateServer(kDocRoot, NULL); | 298 HTTPTestServer::CreateServer(kDocRoot, NULL); |
299 ASSERT_TRUE(NULL != server.get()); | 299 ASSERT_TRUE(NULL != server.get()); |
300 scoped_refptr<URLRequestContext> context = new RequestContext; | 300 scoped_refptr<URLRequestContext> context = new RequestContext; |
301 scoped_ptr<ProxyScriptFetcher> pac_fetcher( | 301 scoped_ptr<ProxyScriptFetcher> pac_fetcher( |
302 ProxyScriptFetcher::Create(context)); | 302 ProxyScriptFetcher::Create(context)); |
303 | 303 |
304 // Test a response that is gzip-encoded -- should get inflated. | 304 // Test a response that is gzip-encoded -- should get inflated. |
305 { | 305 { |
306 GURL url = server->TestServerPage("files/gzipped_pac"); | 306 GURL url = server->TestServerPage("files/gzipped_pac"); |
307 std::string bytes; | 307 string16 text; |
308 TestCompletionCallback callback; | 308 TestCompletionCallback callback; |
309 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 309 int result = pac_fetcher->Fetch(url, &text, &callback); |
310 EXPECT_EQ(ERR_IO_PENDING, result); | 310 EXPECT_EQ(ERR_IO_PENDING, result); |
311 EXPECT_EQ(OK, callback.WaitForResult()); | 311 EXPECT_EQ(OK, callback.WaitForResult()); |
312 EXPECT_EQ("This data was gzipped.\n", bytes); | 312 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text); |
313 } | 313 } |
314 | 314 |
315 // Test a response that was served as UTF-16 (BE). It should | 315 // Test a response that was served as UTF-16 (BE). It should |
316 // be converted to UTF8. | 316 // be converted to UTF8. |
317 { | 317 { |
318 GURL url = server->TestServerPage("files/utf16be_pac"); | 318 GURL url = server->TestServerPage("files/utf16be_pac"); |
319 std::string bytes; | 319 string16 text; |
320 TestCompletionCallback callback; | 320 TestCompletionCallback callback; |
321 int result = pac_fetcher->Fetch(url, &bytes, &callback); | 321 int result = pac_fetcher->Fetch(url, &text, &callback); |
322 EXPECT_EQ(ERR_IO_PENDING, result); | 322 EXPECT_EQ(ERR_IO_PENDING, result); |
323 EXPECT_EQ(OK, callback.WaitForResult()); | 323 EXPECT_EQ(OK, callback.WaitForResult()); |
324 EXPECT_EQ("This was encoded as UTF-16BE.\n", bytes); | 324 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); |
325 } | 325 } |
326 } | 326 } |
327 | 327 |
328 } // namespace net | 328 } // namespace net |
OLD | NEW |