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

Side by Side Diff: ppapi/tests/test_url_loader.cc

Issue 7046091: Fix problems with PPB_URLLoader_Impl and PPAPITests.URLLoader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ppapi/tests/test_url_loader.h" 5 #include "ppapi/tests/test_url_loader.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string.h> 8 #include <string.h>
9 #include <string> 9 #include <string>
10 10
11 #include "ppapi/c/dev/ppb_file_io_dev.h" 11 #include "ppapi/c/dev/ppb_file_io_dev.h"
12 #include "ppapi/c/dev/ppb_file_io_trusted_dev.h" 12 #include "ppapi/c/dev/ppb_file_io_trusted_dev.h"
13 #include "ppapi/c/dev/ppb_testing_dev.h" 13 #include "ppapi/c/dev/ppb_testing_dev.h"
14 #include "ppapi/c/dev/ppb_url_util_dev.h"
14 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/c/ppb_url_loader.h" 16 #include "ppapi/c/ppb_url_loader.h"
16 #include "ppapi/cpp/dev/file_io_dev.h" 17 #include "ppapi/cpp/dev/file_io_dev.h"
17 #include "ppapi/cpp/dev/file_ref_dev.h" 18 #include "ppapi/cpp/dev/file_ref_dev.h"
18 #include "ppapi/cpp/dev/file_system_dev.h" 19 #include "ppapi/cpp/dev/file_system_dev.h"
20 #include "ppapi/cpp/dev/url_util_dev.h"
19 #include "ppapi/cpp/instance.h" 21 #include "ppapi/cpp/instance.h"
20 #include "ppapi/cpp/module.h" 22 #include "ppapi/cpp/module.h"
21 #include "ppapi/cpp/url_loader.h" 23 #include "ppapi/cpp/url_loader.h"
22 #include "ppapi/cpp/url_request_info.h" 24 #include "ppapi/cpp/url_request_info.h"
23 #include "ppapi/cpp/url_response_info.h" 25 #include "ppapi/cpp/url_response_info.h"
24 #include "ppapi/tests/test_utils.h" 26 #include "ppapi/tests/test_utils.h"
25 #include "ppapi/tests/testing_instance.h" 27 #include "ppapi/tests/testing_instance.h"
26 28
27 REGISTER_TEST_CASE(URLLoader); 29 REGISTER_TEST_CASE(URLLoader);
28 30
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 return "URLLoader::Open() failed to block a cross-origin request."; 266 return "URLLoader::Open() failed to block a cross-origin request.";
265 } else { 267 } else {
266 return ReportError("URLLoader::Open()", rv); 268 return ReportError("URLLoader::Open()", rv);
267 } 269 }
268 } 270 }
269 271
270 PASS(); 272 PASS();
271 } 273 }
272 274
273 std::string TestURLLoader::TestCrossOriginRequest() { 275 std::string TestURLLoader::TestCrossOriginRequest() {
276 // Get the document URL and use it to construct a URL that will be
277 // considered cross-origin by the WebKit access control code, and yet be
278 // reachable by the test server.
279 PP_URLComponents_Dev components;
280 pp::Var pp_document_url = pp::URLUtil_Dev::Get()->GetDocumentURL(
281 *instance_, &components);
282 std::string document_url = pp_document_url.AsString();
283 // Replace "127.0.0.1" with "localhost".
284 if (document_url.find("127.0.0.1") == std::string::npos)
285 return "Can't construct a cross-origin URL";
286 std::string cross_origin_url = document_url.replace(
287 components.host.begin, components.host.len, "localhost");
288
274 pp::URLRequestInfo request(instance_); 289 pp::URLRequestInfo request(instance_);
275 // Create a URL that will be considered to be a different origin. 290 request.SetURL(cross_origin_url);
276 request.SetURL("http://127.0.0.1/test_url_loader_data/hello.txt");
277 request.SetAllowCrossOriginRequests(true); 291 request.SetAllowCrossOriginRequests(true);
278 292
279 TestCompletionCallback callback(instance_->pp_instance()); 293 TestCompletionCallback callback(instance_->pp_instance());
280 294
281 pp::URLLoader loader(*instance_); 295 pp::URLLoader loader(*instance_);
282 int32_t rv = loader.Open(request, callback); 296 int32_t rv = loader.Open(request, callback);
283 if (rv == PP_ERROR_WOULDBLOCK) 297 if (rv == PP_ERROR_WOULDBLOCK)
284 rv = callback.WaitForResult(); 298 rv = callback.WaitForResult();
285 299
286 // We expect success since we allowed a cross-origin request. 300 // We expect success since we allowed a cross-origin request.
287 if (rv == PP_ERROR_NOACCESS) 301 if (rv != PP_OK)
288 return ReportError("URLLoader::Open()", rv); 302 return ReportError("URLLoader::Open()", rv);
289 303
290 PASS(); 304 PASS();
291 } 305 }
292 306
293 // This test should cause a redirect and ensure that the loader runs 307 // This test should cause a redirect and ensure that the loader runs
294 // the callback, rather than following the redirect. 308 // the callback, rather than following the redirect.
295 std::string TestURLLoader::TestAuditURLRedirect() { 309 std::string TestURLLoader::TestAuditURLRedirect() {
296 pp::URLRequestInfo request(instance_); 310 pp::URLRequestInfo request(instance_);
297 // This path will cause the server to return a 301 redirect. 311 // This path will cause the server to return a 301 redirect.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 388
375 // TODO(viettrungluu): More abort tests (but add basic tests first). 389 // TODO(viettrungluu): More abort tests (but add basic tests first).
376 // Also test that Close() aborts properly. crbug.com/69457 390 // Also test that Close() aborts properly. crbug.com/69457
377 391
378 PASS(); 392 PASS();
379 } 393 }
380 394
381 // TODO(viettrungluu): Add tests for FollowRedirect, 395 // TODO(viettrungluu): Add tests for FollowRedirect,
382 // Get{Upload,Download}Progress, Close (including abort tests if applicable). 396 // Get{Upload,Download}Progress, Close (including abort tests if applicable).
383 // TODO(darin): Add a test for GrantUniversalAccess. 397 // TODO(darin): Add a test for GrantUniversalAccess.
OLDNEW
« no previous file with comments | « ppapi/tests/test_case.html.mock-http-headers ('k') | webkit/plugins/ppapi/ppb_url_loader_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698