Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_testing_dev.h" | 11 #include "ppapi/c/dev/ppb_testing_dev.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedCrossOriginRequest, filter); | 110 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedCrossOriginRequest, filter); |
| 111 RUN_TEST_FORCEASYNC_AND_NOT(TrustedCrossOriginRequest, filter); | 111 RUN_TEST_FORCEASYNC_AND_NOT(TrustedCrossOriginRequest, filter); |
| 112 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedJavascriptURLRestriction, filter); | 112 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedJavascriptURLRestriction, filter); |
| 113 RUN_TEST_FORCEASYNC_AND_NOT(TrustedJavascriptURLRestriction, filter); | 113 RUN_TEST_FORCEASYNC_AND_NOT(TrustedJavascriptURLRestriction, filter); |
| 114 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedHttpRequests, filter); | 114 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedHttpRequests, filter); |
| 115 RUN_TEST_FORCEASYNC_AND_NOT(TrustedHttpRequests, filter); | 115 RUN_TEST_FORCEASYNC_AND_NOT(TrustedHttpRequests, filter); |
| 116 RUN_TEST_FORCEASYNC_AND_NOT(FollowURLRedirect, filter); | 116 RUN_TEST_FORCEASYNC_AND_NOT(FollowURLRedirect, filter); |
| 117 RUN_TEST_FORCEASYNC_AND_NOT(AuditURLRedirect, filter); | 117 RUN_TEST_FORCEASYNC_AND_NOT(AuditURLRedirect, filter); |
| 118 RUN_TEST_FORCEASYNC_AND_NOT(AbortCalls, filter); | 118 RUN_TEST_FORCEASYNC_AND_NOT(AbortCalls, filter); |
| 119 RUN_TEST_FORCEASYNC_AND_NOT(UntendedLoad, filter); | 119 RUN_TEST_FORCEASYNC_AND_NOT(UntendedLoad, filter); |
| 120 RUN_TEST_FORCEASYNC_AND_NOT(PrefetchBufferThreshold, filter); | |
| 120 } | 121 } |
| 121 | 122 |
| 122 std::string TestURLLoader::ReadEntireFile(pp::FileIO* file_io, | 123 std::string TestURLLoader::ReadEntireFile(pp::FileIO* file_io, |
| 123 std::string* data) { | 124 std::string* data) { |
| 124 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 125 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 125 char buf[256]; | 126 char buf[256]; |
| 126 int64_t offset = 0; | 127 int64_t offset = 0; |
| 127 | 128 |
| 128 for (;;) { | 129 for (;;) { |
| 129 int32_t rv = file_io->Read(offset, buf, sizeof(buf), callback); | 130 int32_t rv = file_io->Read(offset, buf, sizeof(buf), callback); |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 864 std::string body; | 865 std::string body; |
| 865 std::string error = ReadEntireResponseBody(&loader, &body); | 866 std::string error = ReadEntireResponseBody(&loader, &body); |
| 866 if (!error.empty()) | 867 if (!error.empty()) |
| 867 return error; | 868 return error; |
| 868 if (body != "hello\n") | 869 if (body != "hello\n") |
| 869 return ReportError("Couldn't read data", rv); | 870 return ReportError("Couldn't read data", rv); |
| 870 | 871 |
| 871 PASS(); | 872 PASS(); |
| 872 } | 873 } |
| 873 | 874 |
| 875 int32_t TestURLLoader::OpenWithPrefetchBufferThreshold(int32_t lower, | |
| 876 int32_t upper) { | |
| 877 pp::URLRequestInfo request(instance_); | |
| 878 request.SetURL("test_url_loader_data/hello.txt"); | |
| 879 request.SetPrefetchBufferLowerThreshold(lower); | |
| 880 request.SetPrefetchBufferUpperThreshold(upper); | |
| 881 | |
| 882 int32_t rv = OpenUntrusted(request); | |
|
Jay Civelli
2012/01/17 17:31:12
Nit: why not returning without the use of the loca
| |
| 883 return rv; | |
| 884 } | |
| 885 | |
| 886 std::string TestURLLoader::TestPrefetchBufferThreshold() { | |
| 887 int32_t rv = OpenWithPrefetchBufferThreshold(-1, 1); | |
| 888 if (rv != PP_ERROR_FAILED) { | |
| 889 return ReportError("The prefetch limits contained a negative value but " | |
| 890 "the URLLoader did not fail.", rv); | |
| 891 } | |
| 892 | |
| 893 rv = OpenWithPrefetchBufferThreshold(0, 1); | |
| 894 if (rv != PP_OK) { | |
| 895 return ReportError("The prefetch buffer limits were legal values but " | |
| 896 "the URLLoader failed.", rv); | |
| 897 } | |
| 898 | |
| 899 rv = OpenWithPrefetchBufferThreshold(1000, 1); | |
| 900 if (rv != PP_ERROR_FAILED) { | |
| 901 return ReportError("The lower buffer value was higher than the upper but " | |
| 902 "the URLLoader did not fail.", rv); | |
| 903 } | |
| 904 | |
| 905 PASS(); | |
| 906 } | |
| 907 | |
| 874 // TODO(viettrungluu): Add tests for Get{Upload,Download}Progress, Close | 908 // TODO(viettrungluu): Add tests for Get{Upload,Download}Progress, Close |
| 875 // (including abort tests if applicable). | 909 // (including abort tests if applicable). |
| 876 | 910 |
| OLD | NEW |