Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 std::string cross_origin_url = document_url.replace( | |
|
darin (slow to review)
2011/06/15 23:00:20
you might want to assert that thing you are replac
bbudge
2011/06/15 23:50:21
Done.
| |
| 285 components.host.begin, components.host.len, "localhost"); | |
| 286 | |
| 274 pp::URLRequestInfo request(instance_); | 287 pp::URLRequestInfo request(instance_); |
| 275 // Create a URL that will be considered to be a different origin. | 288 request.SetURL(cross_origin_url); |
| 276 request.SetURL("http://127.0.0.1/test_url_loader_data/hello.txt"); | |
| 277 request.SetAllowCrossOriginRequests(true); | 289 request.SetAllowCrossOriginRequests(true); |
| 278 | 290 |
| 279 TestCompletionCallback callback(instance_->pp_instance()); | 291 TestCompletionCallback callback(instance_->pp_instance()); |
| 280 | 292 |
| 281 pp::URLLoader loader(*instance_); | 293 pp::URLLoader loader(*instance_); |
| 282 int32_t rv = loader.Open(request, callback); | 294 int32_t rv = loader.Open(request, callback); |
| 283 if (rv == PP_ERROR_WOULDBLOCK) | 295 if (rv == PP_ERROR_WOULDBLOCK) |
| 284 rv = callback.WaitForResult(); | 296 rv = callback.WaitForResult(); |
| 285 | 297 |
| 286 // We expect success since we allowed a cross-origin request. | 298 // We expect success since we allowed a cross-origin request. |
| 287 if (rv == PP_ERROR_NOACCESS) | 299 if (rv != PP_OK) |
| 288 return ReportError("URLLoader::Open()", rv); | 300 return ReportError("URLLoader::Open()", rv); |
| 289 | 301 |
| 290 PASS(); | 302 PASS(); |
| 291 } | 303 } |
| 292 | 304 |
| 293 // This test should cause a redirect and ensure that the loader runs | 305 // This test should cause a redirect and ensure that the loader runs |
| 294 // the callback, rather than following the redirect. | 306 // the callback, rather than following the redirect. |
| 295 std::string TestURLLoader::TestAuditURLRedirect() { | 307 std::string TestURLLoader::TestAuditURLRedirect() { |
| 296 pp::URLRequestInfo request(instance_); | 308 pp::URLRequestInfo request(instance_); |
| 297 // This path will cause the server to return a 301 redirect. | 309 // This path will cause the server to return a 301 redirect. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 | 386 |
| 375 // TODO(viettrungluu): More abort tests (but add basic tests first). | 387 // TODO(viettrungluu): More abort tests (but add basic tests first). |
| 376 // Also test that Close() aborts properly. crbug.com/69457 | 388 // Also test that Close() aborts properly. crbug.com/69457 |
| 377 | 389 |
| 378 PASS(); | 390 PASS(); |
| 379 } | 391 } |
| 380 | 392 |
| 381 // TODO(viettrungluu): Add tests for FollowRedirect, | 393 // TODO(viettrungluu): Add tests for FollowRedirect, |
| 382 // Get{Upload,Download}Progress, Close (including abort tests if applicable). | 394 // Get{Upload,Download}Progress, Close (including abort tests if applicable). |
| 383 // TODO(darin): Add a test for GrantUniversalAccess. | 395 // TODO(darin): Add a test for GrantUniversalAccess. |
| OLD | NEW |