| 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 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // FileIO interface is not yet supported by ppapi/proxy. | 109 // FileIO interface is not yet supported by ppapi/proxy. |
| 110 if (!testing_interface_->IsOutOfProcess()) { | 110 if (!testing_interface_->IsOutOfProcess()) { |
| 111 RUN_TEST_FORCEASYNC_AND_NOT(BasicFilePOST, filter); | 111 RUN_TEST_FORCEASYNC_AND_NOT(BasicFilePOST, filter); |
| 112 RUN_TEST_FORCEASYNC_AND_NOT(BasicFileRangePOST, filter); | 112 RUN_TEST_FORCEASYNC_AND_NOT(BasicFileRangePOST, filter); |
| 113 } | 113 } |
| 114 RUN_TEST_FORCEASYNC_AND_NOT(CompoundBodyPOST, filter); | 114 RUN_TEST_FORCEASYNC_AND_NOT(CompoundBodyPOST, filter); |
| 115 RUN_TEST_FORCEASYNC_AND_NOT(EmptyDataPOST, filter); | 115 RUN_TEST_FORCEASYNC_AND_NOT(EmptyDataPOST, filter); |
| 116 RUN_TEST_FORCEASYNC_AND_NOT(BinaryDataPOST, filter); | 116 RUN_TEST_FORCEASYNC_AND_NOT(BinaryDataPOST, filter); |
| 117 RUN_TEST_FORCEASYNC_AND_NOT(CustomRequestHeader, filter); | 117 RUN_TEST_FORCEASYNC_AND_NOT(CustomRequestHeader, filter); |
| 118 RUN_TEST_FORCEASYNC_AND_NOT(FailsBogusContentLength, filter); | 118 RUN_TEST_FORCEASYNC_AND_NOT(FailsBogusContentLength, filter); |
| 119 // Disable portion of test which fails when the HTTP server's | 119 // TODO(bbudge) Enable these tests for NaCl when we have a way to get |
| 120 // data_dir is moved to PRODUCT_DIR. | 120 // the document URL. The PPAPI tests use PPB_URLUtil_Dev. |
| 121 // http://code.google.com/p/chromium/issues/detail?id=103690 | 121 #if !(defined __native_client__) |
| 122 // RUN_TEST_FORCEASYNC_AND_NOT(SameOriginRestriction, filter); | 122 RUN_TEST_FORCEASYNC_AND_NOT(SameOriginRestriction, filter); |
| 123 // RUN_TEST_FORCEASYNC_AND_NOT(CrossOriginRequest, filter); | 123 // Cross origin requests require the 'test_case.html.mock-http-headers' |
| 124 // file to be in the same directory as 'test_case.html', so that the test |
| 125 // server returns CORS response headers. |
| 126 RUN_TEST_FORCEASYNC_AND_NOT(CrossOriginRequest, filter); |
| 127 #endif |
| 124 RUN_TEST_FORCEASYNC_AND_NOT(JavascriptURLRestriction, filter); | 128 RUN_TEST_FORCEASYNC_AND_NOT(JavascriptURLRestriction, filter); |
| 125 RUN_TEST_FORCEASYNC_AND_NOT(MethodRestriction, filter); | 129 RUN_TEST_FORCEASYNC_AND_NOT(MethodRestriction, filter); |
| 126 RUN_TEST_FORCEASYNC_AND_NOT(HeaderRestriction, filter); | 130 RUN_TEST_FORCEASYNC_AND_NOT(HeaderRestriction, filter); |
| 127 RUN_TEST_FORCEASYNC_AND_NOT(CustomReferrer, filter); | 131 RUN_TEST_FORCEASYNC_AND_NOT(CustomReferrer, filter); |
| 128 RUN_TEST_FORCEASYNC_AND_NOT(CustomContentTransferEncoding, filter); | 132 RUN_TEST_FORCEASYNC_AND_NOT(CustomContentTransferEncoding, filter); |
| 129 RUN_TEST_FORCEASYNC_AND_NOT(StreamToFile, filter); | 133 RUN_TEST_FORCEASYNC_AND_NOT(StreamToFile, filter); |
| 130 RUN_TEST_FORCEASYNC_AND_NOT(AuditURLRedirect, filter); | 134 RUN_TEST_FORCEASYNC_AND_NOT(AuditURLRedirect, filter); |
| 131 RUN_TEST_FORCEASYNC_AND_NOT(AbortCalls, filter); | 135 RUN_TEST_FORCEASYNC_AND_NOT(AbortCalls, filter); |
| 132 RUN_TEST_FORCEASYNC_AND_NOT(UntendedLoad, filter); | 136 RUN_TEST_FORCEASYNC_AND_NOT(UntendedLoad, filter); |
| 133 } | 137 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 263 } |
| 260 | 264 |
| 261 std::string TestURLLoader::GetReachableCrossOriginURL() { | 265 std::string TestURLLoader::GetReachableCrossOriginURL() { |
| 262 // Get the document URL and use it to construct a URL that will be | 266 // Get the document URL and use it to construct a URL that will be |
| 263 // considered cross-origin by the WebKit access control code, and yet be | 267 // considered cross-origin by the WebKit access control code, and yet be |
| 264 // reachable by the test server. | 268 // reachable by the test server. |
| 265 PP_URLComponents_Dev components; | 269 PP_URLComponents_Dev components; |
| 266 pp::Var pp_document_url = pp::URLUtil_Dev::Get()->GetDocumentURL( | 270 pp::Var pp_document_url = pp::URLUtil_Dev::Get()->GetDocumentURL( |
| 267 *instance_, &components); | 271 *instance_, &components); |
| 268 std::string document_url = pp_document_url.AsString(); | 272 std::string document_url = pp_document_url.AsString(); |
| 269 // Replace "127.0.0.1" with "localhost". | 273 // Replace "127.0.0.1" with "localhost". Or vice versa. |
| 270 ASSERT_TRUE(document_url.find("127.0.0.1") != std::string::npos); | 274 bool changedHost = false; |
| 271 return document_url.replace( | 275 if (document_url.find("127.0.0.1") != std::string::npos) { |
| 272 components.host.begin, components.host.len, "localhost"); | 276 document_url.replace(components.host.begin, |
| 277 components.host.len, |
| 278 "localhost"); |
| 279 changedHost = true; |
| 280 } else if (document_url.find("localhost") != std::string::npos) { |
| 281 document_url.replace(components.host.begin, |
| 282 components.host.len, |
| 283 "127.0.0.1"); |
| 284 changedHost = true; |
| 285 } |
| 286 ASSERT_TRUE(changedHost); |
| 287 return document_url; |
| 273 } | 288 } |
| 274 | 289 |
| 275 int32_t TestURLLoader::OpenUntrusted(const std::string& method, | 290 int32_t TestURLLoader::OpenUntrusted(const std::string& method, |
| 276 const std::string& header) { | 291 const std::string& header) { |
| 277 pp::URLRequestInfo request(instance_); | 292 pp::URLRequestInfo request(instance_); |
| 278 request.SetURL("/echo"); | 293 request.SetURL("/echo"); |
| 279 request.SetMethod(method); | 294 request.SetMethod(method); |
| 280 request.SetHeaders(header); | 295 request.SetHeaders(header); |
| 281 | 296 |
| 282 return OpenUntrusted(request); | 297 return OpenUntrusted(request); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 pp::URLRequestInfo request(instance_); | 540 pp::URLRequestInfo request(instance_); |
| 526 std::string cross_origin_url = GetReachableCrossOriginURL(); | 541 std::string cross_origin_url = GetReachableCrossOriginURL(); |
| 527 request.SetURL(cross_origin_url); | 542 request.SetURL(cross_origin_url); |
| 528 request.SetAllowCrossOriginRequests(true); | 543 request.SetAllowCrossOriginRequests(true); |
| 529 | 544 |
| 530 int32_t rv; | 545 int32_t rv; |
| 531 rv = OpenUntrusted(request); | 546 rv = OpenUntrusted(request); |
| 532 if (rv != PP_OK) | 547 if (rv != PP_OK) |
| 533 return ReportError( | 548 return ReportError( |
| 534 "Untrusted, intended cross-origin request", rv); | 549 "Untrusted, intended cross-origin request", rv); |
| 550 #if !(defined __native_client__) |
| 535 rv = OpenTrusted(request); | 551 rv = OpenTrusted(request); |
| 536 if (rv != PP_OK) | 552 if (rv != PP_OK) |
| 537 return ReportError("Trusted cross-origin request", rv); | 553 return ReportError("Trusted cross-origin request", rv); |
| 554 #endif |
| 538 | 555 |
| 539 PASS(); | 556 PASS(); |
| 540 } | 557 } |
| 541 | 558 |
| 542 // Javascript URLs are only reachable by trusted loaders. | 559 // Javascript URLs are only reachable by trusted loaders. |
| 543 std::string TestURLLoader::TestJavascriptURLRestriction() { | 560 std::string TestURLLoader::TestJavascriptURLRestriction() { |
| 544 pp::URLRequestInfo request(instance_); | 561 pp::URLRequestInfo request(instance_); |
| 545 request.SetURL("javascript:foo = bar"); | 562 request.SetURL("javascript:foo = bar"); |
| 546 | 563 |
| 547 int32_t rv; | 564 int32_t rv; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 if (!error.empty()) | 821 if (!error.empty()) |
| 805 return error; | 822 return error; |
| 806 if (body != "hello\n") | 823 if (body != "hello\n") |
| 807 return ReportError("Couldn't read data", rv); | 824 return ReportError("Couldn't read data", rv); |
| 808 | 825 |
| 809 PASS(); | 826 PASS(); |
| 810 } | 827 } |
| 811 | 828 |
| 812 // TODO(viettrungluu): Add tests for FollowRedirect, | 829 // TODO(viettrungluu): Add tests for FollowRedirect, |
| 813 // Get{Upload,Download}Progress, Close (including abort tests if applicable). | 830 // Get{Upload,Download}Progress, Close (including abort tests if applicable). |
| OLD | NEW |