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(NegativePrefetchBufferThreshold, filter); | |
| 121 RUN_TEST_FORCEASYNC_AND_NOT(LegalPrefetchBufferThreshold, filter); | |
| 122 RUN_TEST_FORCEASYNC_AND_NOT(InvertedPrefetchBufferThreshold, filter); | |
| 120 } | 123 } |
| 121 | 124 |
| 122 std::string TestURLLoader::ReadEntireFile(pp::FileIO* file_io, | 125 std::string TestURLLoader::ReadEntireFile(pp::FileIO* file_io, |
| 123 std::string* data) { | 126 std::string* data) { |
| 124 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 127 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 125 char buf[256]; | 128 char buf[256]; |
| 126 int64_t offset = 0; | 129 int64_t offset = 0; |
| 127 | 130 |
| 128 for (;;) { | 131 for (;;) { |
| 129 int32_t rv = file_io->Read(offset, buf, sizeof(buf), callback); | 132 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; | 867 std::string body; |
| 865 std::string error = ReadEntireResponseBody(&loader, &body); | 868 std::string error = ReadEntireResponseBody(&loader, &body); |
| 866 if (!error.empty()) | 869 if (!error.empty()) |
| 867 return error; | 870 return error; |
| 868 if (body != "hello\n") | 871 if (body != "hello\n") |
| 869 return ReportError("Couldn't read data", rv); | 872 return ReportError("Couldn't read data", rv); |
| 870 | 873 |
| 871 PASS(); | 874 PASS(); |
| 872 } | 875 } |
| 873 | 876 |
| 877 int32_t TestURLLoader::OpenWithPrefetchBufferThreshold(int32_t lower, | |
| 878 int32_t upper) { | |
| 879 pp::URLRequestInfo request(instance_); | |
| 880 request.SetURL("test_url_loader_data/hello.txt"); | |
| 881 request.SetPrefetchBufferLowerThreshold(lower); | |
| 882 request.SetPrefetchBufferUpperThreshold(upper); | |
| 883 | |
| 884 int32_t rv = OpenUntrusted(request); | |
| 885 return rv; | |
| 886 } | |
| 887 | |
| 888 std::string TestURLLoader::TestNegativePrefetchBufferThreshold() { | |
| 889 int32_t rv = OpenWithPrefetchBufferThreshold(-1, 1); | |
| 890 if (rv != PP_ERROR_FAILED) { | |
| 891 return ReportError("The prefetch limits contained a negative value but " | |
| 892 "the URLLoader did not fail.", rv); | |
| 893 } | |
| 894 | |
| 895 PASS(); | |
| 896 } | |
| 897 | |
| 898 std::string TestURLLoader::TestLegalPrefetchBufferThreshold() { | |
| 899 int32_t rv = OpenWithPrefetchBufferThreshold(0, 1); | |
| 900 if (rv != PP_OK) { | |
| 901 return ReportError("The prefetch buffer limits were legal values but " | |
| 902 "the URLLoader failed.", rv); | |
| 903 } | |
| 904 | |
| 905 PASS(); | |
| 906 } | |
| 907 | |
| 908 std::string TestURLLoader::TestInvertedPrefetchBufferThreshold() { | |
| 909 int32_t rv = OpenWithPrefetchBufferThreshold(1000, 1); | |
| 910 if (rv != PP_ERROR_FAILED) { | |
| 911 return ReportError("The lower buffer value was higher than the upper but " | |
| 912 "the URLLoader did not fail.", rv); | |
| 913 } | |
| 914 | |
|
dmichael (off chromium)
2012/01/13 17:46:02
I think it would make sense to collapse these in t
| |
| 915 PASS(); | |
| 916 } | |
| 917 | |
| 874 // TODO(viettrungluu): Add tests for Get{Upload,Download}Progress, Close | 918 // TODO(viettrungluu): Add tests for Get{Upload,Download}Progress, Close |
| 875 // (including abort tests if applicable). | 919 // (including abort tests if applicable). |
| 876 | 920 |
| OLD | NEW |