| 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 document_url = GetDocumentURL(instance_, &components); |
| 281 std::string cross_origin_url = document_url.AsString(); |
| 282 cross_origin_url.replace("127.0.0.1", "localhost"); |
| 283 |
| 274 pp::URLRequestInfo request(instance_); | 284 pp::URLRequestInfo request(instance_); |
| 275 // Create a URL that will be considered to be a different origin. | 285 request.SetURL(cross_origin_url); |
| 276 request.SetURL("http://127.0.0.1/test_url_loader_data/hello.txt"); | |
| 277 request.SetAllowCrossOriginRequests(true); | 286 request.SetAllowCrossOriginRequests(true); |
| 278 | 287 |
| 279 TestCompletionCallback callback(instance_->pp_instance()); | 288 TestCompletionCallback callback(instance_->pp_instance()); |
| 280 | 289 |
| 281 pp::URLLoader loader(*instance_); | 290 pp::URLLoader loader(*instance_); |
| 282 int32_t rv = loader.Open(request, callback); | 291 int32_t rv = loader.Open(request, callback); |
| 283 if (rv == PP_ERROR_WOULDBLOCK) | 292 if (rv == PP_ERROR_WOULDBLOCK) |
| 284 rv = callback.WaitForResult(); | 293 rv = callback.WaitForResult(); |
| 285 | 294 |
| 286 // We expect success since we allowed a cross-origin request. | 295 // We expect success since we allowed a cross-origin request. |
| 287 if (rv == PP_ERROR_NOACCESS) | 296 if (rv != PP_OK) |
| 288 return ReportError("URLLoader::Open()", rv); | 297 return ReportError("URLLoader::Open()", rv); |
| 289 | 298 |
| 290 PASS(); | 299 PASS(); |
| 291 } | 300 } |
| 292 | 301 |
| 293 // This test should cause a redirect and ensure that the loader runs | 302 // This test should cause a redirect and ensure that the loader runs |
| 294 // the callback, rather than following the redirect. | 303 // the callback, rather than following the redirect. |
| 295 std::string TestURLLoader::TestAuditURLRedirect() { | 304 std::string TestURLLoader::TestAuditURLRedirect() { |
| 296 pp::URLRequestInfo request(instance_); | 305 pp::URLRequestInfo request(instance_); |
| 297 // This path will cause the server to return a 301 redirect. | 306 // 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 | 383 |
| 375 // TODO(viettrungluu): More abort tests (but add basic tests first). | 384 // TODO(viettrungluu): More abort tests (but add basic tests first). |
| 376 // Also test that Close() aborts properly. crbug.com/69457 | 385 // Also test that Close() aborts properly. crbug.com/69457 |
| 377 | 386 |
| 378 PASS(); | 387 PASS(); |
| 379 } | 388 } |
| 380 | 389 |
| 381 // TODO(viettrungluu): Add tests for FollowRedirect, | 390 // TODO(viettrungluu): Add tests for FollowRedirect, |
| 382 // Get{Upload,Download}Progress, Close (including abort tests if applicable). | 391 // Get{Upload,Download}Progress, Close (including abort tests if applicable). |
| 383 // TODO(darin): Add a test for GrantUniversalAccess. | 392 // TODO(darin): Add a test for GrantUniversalAccess. |
| OLD | NEW |